Skip to content

Parse codec specific descriptor to retrieve audio sample rate #39

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 21, 2016

Conversation

alfredoyang
Copy link
Contributor

No description provided.

@alfredoyang
Copy link
Contributor Author

This is for #30.

Copy link
Contributor

@rillian rillian left a comment

Choose a reason for hiding this comment

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

Some style comments. Otherwise looks fine.

(*info).sample_rate = rate;
},
_ => {},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

match is good to show handling of all branches, or when yielding a value for assignment. For something like this if let is shorter, since the _ => {} clause is equivalent to an omitted empty else clause.

// An ESDS value overrides the track sample rate.
if let Some(rate) = v.audio_sample_rate {
    (*info)sample_rate = rate;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for suggestion. Fixed.

return Err(Error::Unsupported("fail to parse ES descriptor"));
}

let esds_extend = try!(esds.read_u8());
let mut esds_end: u64 = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than turning off the warning with #[allow(unused_assignments)], you can avoid it with an if expression like a ternary in C. I'm not sure this is actually easier to read, but avoiding the mut is more natural in rust, I think.

let esds_extend = try!(esds.read_u8());
// extension tag starts from 0x80.
let esds_end = if esds_extend >= 0x80 {
    // skip remaining extension.
    try!(skip(esds, 2));
    esds.position() + try!(esds.read_u8()) as u64
} else {
    esds.position() + esds_extend as u64
};
try!(skip(esds, 2));

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.

if dcds != DECODER_CONFIG_TAG {
return Err(Error::Unsupported("fail to parse decoder config descriptor"));
if esds_end > esds.position() {
next_tag = try!(esds.read_u8());
Copy link
Contributor

Choose a reason for hiding this comment

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

Since these uses of next_tag start with a fresh assignment within a block, please drop the mut keyword from the outer declaration and use a fresh let here and below. Rust will not warn about the shadowing, and using a local in each block reduces the amount of code which must be understood at once.

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.

Copy link
Contributor

@rillian rillian left a comment

Choose a reason for hiding this comment

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

Thanks!

@rillian rillian merged commit b0e9ae7 into mozilla:master Oct 21, 2016
@kinetiknz kinetiknz mentioned this pull request Oct 29, 2020
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