Skip to content

Commit

Permalink
Implement IAMF v1.0.0 errata changes (#3336)
Browse files Browse the repository at this point in the history
Updates the IAMF mp4 parsing implementation to support v1.0.0-errata.
Streams configured with the original v1.0.0 spec are no longer
supported.

Changes are pulled from Chromium. Original CL descriptions follow:

Update IAMF mp4 parsing implementation

Updates the IAMF parsing implemenation to parse the IA Configuration Box
defined in the IAMF v1.0.0-errata specification.


https://aomediacodec.github.io/iamf/v1.0.0-errata.html#iaconfigurationbox-section

Bug: b/340618404
Change-Id: I1467e60928ac28e0ead4a9e0f3857b6c5540c7e7
Reviewed-on:
https://chromium-review.googlesource.com/c/chromium/src/+/5550540
Reviewed-by: Mark Foltz <[email protected]>
Commit-Queue: Austin Osagie <[email protected]>
Reviewed-by: Dale Curtis <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1304144}

Parse IAMF 'iacb' atom correctly

1. Fixes an error in a previous change that parses the iamf atom instead
   of the iacb atom. Now, the iacb atom is properly read.

2. Removes an early return after parsing the IA Configuration Box.

3. Checks for the ENCA fourcc for encrypted stream support

Bug: b/340618404
Change-Id: I61d8c8c2758c9181b40ff6e99da24c790b202687
Reviewed-on:
https://chromium-review.googlesource.com/c/chromium/src/+/5559111
Commit-Queue: Austin Osagie <[email protected]>
Reviewed-by: Mark Foltz <[email protected]>
Reviewed-by: Dale Curtis <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1322448}
  • Loading branch information
osagie98 authored Jul 11, 2024
1 parent b3f1f6d commit 7142929
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
36 changes: 24 additions & 12 deletions media/formats/mp4/box_definitions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1580,15 +1580,27 @@ IamfSpecificBox::IamfSpecificBox(const IamfSpecificBox& other) = default;
IamfSpecificBox::~IamfSpecificBox() = default;

FourCC IamfSpecificBox::BoxType() const {
return FOURCC_IAMF;
return FOURCC_IACB;
}

bool IamfSpecificBox::Parse(BoxReader* reader) {
const int obu_bitstream_size = reader->box_size() - reader->pos();
uint8_t configuration_version;
RCHECK(reader->Read1(&configuration_version));
RCHECK(configuration_version == 0x01);

uint32_t config_obus_size;
RCHECK(ReadLeb128Value(reader, &config_obus_size));

#if defined(STARBOARD)
const uint8_t* buf = reader->buffer() + reader->pos();
ia_descriptors.assign(buf, buf + obu_bitstream_size);
ia_descriptors.assign(buf, buf + config_obus_size);
#else // defined(STARBOARD)
base::span<const uint8_t> buffer =
reader->buffer().subspan(reader->pos(), config_obus_size);
ia_descriptors.assign(buffer.begin(), buffer.end());
#endif // defined(STARBOARD)

RCHECK(reader->SkipBytes(obu_bitstream_size));
RCHECK(reader->SkipBytes(config_obus_size));

BufferReader config_reader(ia_descriptors.data(), ia_descriptors.size());

Expand Down Expand Up @@ -1706,14 +1718,6 @@ bool AudioSampleEntry::Parse(BoxReader* reader) {
// Convert from 16.16 fixed point to integer
samplerate >>= 16;

#if BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)
if (format == FOURCC_IAMF) {
RCHECK_MEDIA_LOGGED(iamf.Parse(reader), reader->media_log(),
"Failure parsing IamfSpecificBox (iamf)");
return true;
}
#endif // BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)

RCHECK(reader->ScanChildren());
if (format == FOURCC_ENCA) {
// Continue scanning until a recognized protection scheme is found, or until
Expand Down Expand Up @@ -1759,6 +1763,14 @@ bool AudioSampleEntry::Parse(BoxReader* reader) {
}
#endif // BUILDFLAG(ENABLE_PLATFORM_AC3_EAC3_AUDIO)

#if BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)
if (format == FOURCC_IAMF ||
(format == FOURCC_ENCA && sinf.format.format == FOURCC_IAMF)) {
RCHECK_MEDIA_LOGGED(reader->ReadChild(&iacb), reader->media_log(),
"Failure parsing IamfSpecificBox (iacb)");
}
#endif // BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)

// Read the FLACSpecificBox, even if CENC is signalled.
if (format == FOURCC_FLAC ||
(format == FOURCC_ENCA && sinf.format.format == FOURCC_FLAC)) {
Expand Down
2 changes: 1 addition & 1 deletion media/formats/mp4/box_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ struct MEDIA_EXPORT AudioSampleEntry : Box {
EC3SpecificBox eac3;
#endif // BUILDFLAG(ENABLE_PLATFORM_AC3_EAC3_AUDIO)
#if BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)
IamfSpecificBox iamf;
IamfSpecificBox iacb;
#endif // BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)
};

Expand Down
1 change: 1 addition & 0 deletions media/formats/mp4/fourccs.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ enum FourCC {
FOURCC_HVCC = 0x68766343,
#endif
#if BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)
FOURCC_IACB = 0x69616362,
FOURCC_IAMF = 0x69616d66,
#endif // BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)
FOURCC_ID32 = 0x49443332,
Expand Down
16 changes: 8 additions & 8 deletions media/formats/mp4/mp4_stream_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ bool MP4StreamParser::ParseMoov(BoxReader* reader) {
}

codec = AudioCodec::kIAMF;
profile = entry.iamf.profile == 0 ? AudioCodecProfile::kIAMF_SIMPLE
profile = entry.iacb.profile == 0 ? AudioCodecProfile::kIAMF_SIMPLE
: AudioCodecProfile::kIAMF_BASE;
// The correct values for the channel layout and sample rate can
// be parsed from the descriptor bitstream prepended to each sample.
Expand Down Expand Up @@ -863,18 +863,18 @@ bool MP4StreamParser::PrepareAACBuffer(

#if BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)
bool MP4StreamParser::PrependIADescriptors(
const IamfSpecificBox& iamf_box,
const IamfSpecificBox& iacb,
std::vector<uint8_t>* frame_buf,
std::vector<SubsampleEntry>* subsamples) const {
// Prepend the IA Descriptors to every IA Sample.
frame_buf->insert(frame_buf->begin(), iamf_box.ia_descriptors.begin(),
iamf_box.ia_descriptors.end());
frame_buf->insert(frame_buf->begin(), iacb.ia_descriptors.begin(),
iacb.ia_descriptors.end());
size_t descriptors_size = iacb.ia_descriptors.size();
if (subsamples->empty()) {
subsamples->push_back(
SubsampleEntry(iamf_box.ia_descriptors.size(),
frame_buf->size() - iamf_box.ia_descriptors.size()));
SubsampleEntry(descriptors_size, frame_buf->size() - descriptors_size));
} else {
(*subsamples)[0].clear_bytes += iamf_box.ia_descriptors.size();
(*subsamples)[0].clear_bytes += descriptors_size;
}

return true;
Expand Down Expand Up @@ -1053,7 +1053,7 @@ ParseResult MP4StreamParser::EnqueueSample(BufferQueueMap* buffers) {
} else {
#if BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)
if (runs_->audio_description().format == FOURCC_IAMF) {
if (!PrependIADescriptors(runs_->audio_description().iamf, &frame_buf,
if (!PrependIADescriptors(runs_->audio_description().iacb, &frame_buf,
&subsamples)) {
MEDIA_LOG(ERROR, media_log_)
<< "Failed to prepare IA sample for decode";
Expand Down
2 changes: 1 addition & 1 deletion media/formats/mp4/mp4_stream_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MEDIA_EXPORT MP4StreamParser : public StreamParser {
std::vector<SubsampleEntry>* subsamples) const;
#endif
#if BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)
bool PrependIADescriptors(const IamfSpecificBox& iamf_box,
bool PrependIADescriptors(const IamfSpecificBox& iacb,
std::vector<uint8_t>* frame_buf,
std::vector<SubsampleEntry>* subsamples) const;
#endif // BUILDFLAG(ENABLE_PLATFORM_IAMF_AUDIO)
Expand Down

0 comments on commit 7142929

Please sign in to comment.