Skip to content

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

Merged
merged 2 commits into from
Oct 13, 2016
Merged

Parse ESDS. #38

merged 2 commits into from
Oct 13, 2016

Conversation

alfredoyang
Copy link
Contributor

@alfredoyang alfredoyang commented Oct 13, 2016

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.

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.
@kinetiknz
Copy link
Collaborator

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.

@alfredoyang
Copy link
Contributor Author

Ok, I'll address issue #30 later. Do we also need to parse ESDS in VideoSampleEntry?

@kinetiknz
Copy link
Collaborator

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.

Copy link
Collaborator

@kinetiknz kinetiknz left a 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());
Copy link
Collaborator

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.

Copy link
Contributor Author

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;
Copy link
Collaborator

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.

Copy link
Contributor Author

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;
Copy link
Collaborator

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.

Copy link
Contributor Author

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),
Copy link
Collaborator

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.

Copy link
Contributor Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remaining

Copy link
Contributor Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependency

Copy link
Contributor Author

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;
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@kinetiknz kinetiknz merged commit db0506f into mozilla:master Oct 13, 2016
@kinetiknz
Copy link
Collaborator

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants