-
Notifications
You must be signed in to change notification settings - Fork 64
Parse ESDS. #38
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
Parse ESDS. #38
Conversation
Structure of ESDS: ESDS box | |- ES descriptor |- 3 bytes extension (optional) |- 1 byte length |- 2 bytes ES ID |- 1 byte stream priority and flags |- stream dependency (optional, depends on flags) | |- 2 bytes |- url (optional, depends on flags) | |- 1 byte length | |- x bytes, x is the length | |- Decoder Config descriptior |- 3 bytes extension (optional) |- 1 byte length |- 1 byte object profile indicator We need to get object profile indicator for the codec type.
We also want to get the "real" sample rate out of the ESDS to fix issue #30, but that can be done separately to this PR. |
Ok, I'll address issue #30 later. Do we also need to parse ESDS in VideoSampleEntry? |
Probably not at this stage. libstagefright only parses it to extract accurate audio metadata; for video it's just exporting the entire ESDS as a binary blob without inspecting it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, a few comments to address.
let esds_array = try!(read_buf(src, esds_size as usize)); | ||
|
||
// clone a esds cursor for parsing. | ||
let esds = &mut Cursor::new(esds_array.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than cloning the data, share it by creating the Cursor with a ref. You just need to arrange for the Cursor to goe out of scope before you try to move esds_array into EsDescriptor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -1398,7 +1471,8 @@ fn read_audio_sample_entry<T: Read>(src: &mut BMFFBox<T>, track: &mut Track) -> | |||
} | |||
|
|||
let esds = try!(read_esds(&mut b)); | |||
codec_specific = Some(esds); | |||
track.codec_type = esds.audio_codec; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, set track.codec_type and codec_specific in the same order in each of the branches - right now there's a mix of both variants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -23,6 +24,10 @@ mod tests; | |||
// Arbitrary buffer size limit used for raw read_bufs on a box. | |||
const BUF_SIZE_LIMIT: u64 = 1024 * 1024; | |||
|
|||
// Tags for elementary stream description | |||
const ESDESCR_TAG: u8 = 0x03; | |||
const DECODER_CONFIG_TAG: u8 = 0x04; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are only used inside read_esds
, so move them into the scope of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
#[allow(non_camel_case_types)] | ||
#[derive(Debug, Clone)] | ||
pub enum AudioCodecSpecific { | ||
ES_Descriptor(Vec<u8>), | ||
EsDescriptor(EsDescriptor), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the name ES_Descriptor to match the spec reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
let esds_extend = try!(esds.read_u8()); | ||
// extension tag start from 0x80. | ||
if esds_extend >= 0x80 { | ||
// skip remains extension and length. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
let esds_flags = try!(esds.read_u8()); | ||
|
||
// Stream dependnecy flag, first bit from left most. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
// Url flag, second bit from left most. | ||
if esds_flags & 0x40 > 0 { | ||
// Skip uninteresting fields. | ||
let skip_es_len = try!(esds.read_u8()) + 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be safer to make skip_es_len a usize and cast the result of the read before adding to avoid potential overflows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Great, thanks! |
Structure of ESDS:
ESDS box
|
|- ES descriptor
| |- 3 bytes extension (optional)
| |- 1 byte length
| |- 2 bytes ES ID
| |- 1 byte stream priority and flags
| |- stream dependency (optional, depends on flags)
| | |- 2 bytes
| |- url (optional, depends on flags)
| | |- 1 byte length
| | |- x bytes, x is the length
| |
| |- Decoder Config descriptior
| |- 3 bytes extension (optional)
| |- 1 byte length
| |- 1 byte object profile indicator
We need to get object profile indicator for the codec type.