-
Notifications
You must be signed in to change notification settings - Fork 364
feat: Support ISO/IEC 23008-12 AMD2 boxes #513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
y-guyon
wants to merge
2
commits into
gpac:main
Choose a base branch
from
y-guyon:amd2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import type { MultiBufferStream } from '#/buffer'; | ||
|
||
/** | ||
* BitStream is a class that acts as a MultiBufferStream wrapper for parsing individual bits | ||
*/ | ||
export class BitStream { | ||
// The last byte read from the stream. | ||
last_byte: number; | ||
// If not zero, number of most significant bits already read in last_byte. | ||
num_bits_read_in_last_byte: number; | ||
|
||
constructor(readonly stream: MultiBufferStream) { | ||
this.last_byte = 0; | ||
this.num_bits_read_in_last_byte = 0; | ||
} | ||
|
||
/** | ||
* Reads bits with or without byte alignment and potentially across multiple bytes. | ||
* The bits are read in the earliest byte first, and most significant bits in a byte first. | ||
* @param num_bits Number of bits to read. | ||
* @return An unsigned integer whose binary representation is the big-endian read bits. | ||
*/ | ||
read(num_bits: number) { | ||
if (num_bits > 32) { | ||
throw new Error('BitStream.read: Unsupported number of bits.'); | ||
} | ||
let remaining_num_bits = num_bits; | ||
let value = 0; | ||
while (remaining_num_bits !== 0) { | ||
if (this.num_bits_read_in_last_byte === 0) { | ||
this.last_byte = this.stream.readUint8(); | ||
} | ||
// Number of bits among remaining_num_bits that can be read in the last_byte. | ||
const num_read_bits = Math.min(8 - this.num_bits_read_in_last_byte, remaining_num_bits); | ||
// Read the most significant bits first. | ||
const read_bits = | ||
(this.last_byte >> (8 - this.num_bits_read_in_last_byte - num_read_bits)) & | ||
((1 << num_read_bits) - 1); | ||
value = (value << num_read_bits) | read_bits; | ||
this.num_bits_read_in_last_byte = (this.num_bits_read_in_last_byte + num_read_bits) % 8; | ||
remaining_num_bits -= num_read_bits; | ||
} | ||
return value; | ||
} | ||
|
||
/** | ||
* Reads one bit. | ||
* @return The read bit. | ||
*/ | ||
bool() { | ||
return this.read(1) === 1; | ||
} | ||
|
||
/** | ||
* Reads a potentially unaligned four-character code. | ||
* @return The read big-endian 4CC. | ||
*/ | ||
four_cc() { | ||
return String.fromCharCode(this.read(8), this.read(8), this.read(8), this.read(8)); | ||
} | ||
|
||
/** | ||
* Reads up to seven bits until byte alignment. The read bits must be zeros. | ||
*/ | ||
pad_with_zeros() { | ||
if ( | ||
this.num_bits_read_in_last_byte !== 0 && | ||
this.read(8 - this.num_bits_read_in_last_byte) !== 0 | ||
) { | ||
throw new Error('BitStream.padding: Bits were not all set to zero.'); | ||
} | ||
} | ||
|
||
/** | ||
* Reads a potentially unaligned 8-bit unsigned int from the underlying MultiBufferStream. | ||
* @return The read big-endian number. | ||
*/ | ||
readUint8() { | ||
return this.read(8); | ||
} | ||
|
||
/** | ||
* Reads a potentially unaligned 16-bit unsigned int from the underlying MultiBufferStream. | ||
* @return The read big-endian number. | ||
*/ | ||
readUint16() { | ||
return this.read(16); | ||
} | ||
|
||
/** | ||
* Reads a potentially unaligned 32-bit unsigned int from the underlying MultiBufferStream. | ||
* @return The read big-endian number. | ||
*/ | ||
readUint32() { | ||
return this.read(32); | ||
} | ||
|
||
/** | ||
* Reads a potentially unaligned 32-bit signed int from the underlying MultiBufferStream. | ||
* @return The read big-endian number. | ||
*/ | ||
readInt32() { | ||
return this.read(1) ? this.read(31) - Math.pow(2, 31) : this.read(31); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Box } from '#/box'; | ||
import type { MultiBufferStream } from '#/buffer'; | ||
import type { BitStream } from '#/bitstream'; | ||
|
||
export class amveBox extends Box { | ||
static override readonly fourcc = 'amve' as const; | ||
box_name = 'AmbientViewingEnvironmentBox' as const; | ||
|
||
ambient_illuminance: number; | ||
ambient_light_x: number; | ||
ambient_light_y: number; | ||
|
||
parse(stream: MultiBufferStream | BitStream) { | ||
this.ambient_illuminance = stream.readUint32(); | ||
this.ambient_light_x = stream.readUint16(); | ||
this.ambient_light_y = stream.readUint16(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Box } from '#/box'; | ||
import type { MultiBufferStream } from '#/buffer'; | ||
import type { BitStream } from '#/bitstream'; | ||
|
||
export class cclvBox extends Box { | ||
static override readonly fourcc = 'cclv' as const; | ||
box_name = 'ContentColourVolumeBox' as const; | ||
|
||
ccv_primaries_x: Array<number>; | ||
ccv_primaries_y: Array<number>; | ||
ccv_min_luminance_value: number; | ||
ccv_max_luminance_value: number; | ||
ccv_avg_luminance_value: number; | ||
|
||
parse(stream: MultiBufferStream | BitStream) { | ||
const flags = stream.readUint8(); | ||
const ccv_primaries_present_flag = flags & 0x10; | ||
const ccv_min_luminance_value_present_flag = flags & 0x08; | ||
const ccv_max_luminance_value_present_flag = flags & 0x04; | ||
const ccv_avg_luminance_value_present_flag = flags & 0x02; | ||
|
||
if (ccv_primaries_present_flag) { | ||
this.ccv_primaries_x = new Array<number>(3); | ||
this.ccv_primaries_y = new Array<number>(3); | ||
for (let c = 0; c < 3; c++) { | ||
this.ccv_primaries_x[c] = stream.readInt32(); | ||
this.ccv_primaries_y[c] = stream.readInt32(); | ||
} | ||
} | ||
if (ccv_min_luminance_value_present_flag) { | ||
this.ccv_min_luminance_value = stream.readUint32(); | ||
} | ||
if (ccv_max_luminance_value_present_flag) { | ||
this.ccv_max_luminance_value = stream.readUint32(); | ||
} | ||
if (ccv_avg_luminance_value_present_flag) { | ||
this.ccv_avg_luminance_value = stream.readUint32(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.