Skip to content

Commit

Permalink
Always set ES_ID to 0 when writing ES Descriptor in mp4 (#798)
Browse files Browse the repository at this point in the history
Required by ISO/IEC 14496-14:2018 and ISO/IEC 23000-19:2018.

Issue #755.
  • Loading branch information
koln67 authored Jul 15, 2020
1 parent db5413e commit a8ea7fd
Show file tree
Hide file tree
Showing 74 changed files with 64 additions and 65 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
<AdaptationSet id="1" contentType="video" maxWidth="1280" maxHeight="720" frameRate="30000/1001" subsegmentAlignment="true" par="16:9">
<SupplementalProperty schemeIdUri="urn:mpeg:dash:adaptation-set-switching:2016" value="0"/>
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"/>
<Representation id="1" bandwidth="2627285" codecs="avc1.64001f" mimeType="video/mp4" sar="1:1" width="1280" height="720">
<BaseURL>bear-1280x720-video.mp4</BaseURL>
<SegmentBase indexRange="858-925" timescale="30000">
<Initialization range="0-857"/>
</SegmentBase>
</Representation>
<Representation id="2" bandwidth="973483" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1" width="640" height="360">
<Representation id="1" bandwidth="973483" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1" width="640" height="360">
<BaseURL>bear-640x360-video.mp4</BaseURL>
<SegmentBase indexRange="859-926" timescale="30000">
<Initialization range="0-858"/>
</SegmentBase>
</Representation>
<Representation id="2" bandwidth="2627285" codecs="avc1.64001f" mimeType="video/mp4" sar="1:1" width="1280" height="720">
<BaseURL>bear-1280x720-video.mp4</BaseURL>
<SegmentBase indexRange="858-925" timescale="30000">
<Initialization range="0-857"/>
</SegmentBase>
</Representation>
</AdaptationSet>
<AdaptationSet id="2" contentType="audio" subsegmentAlignment="true">
<Representation id="3" bandwidth="133334" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100">
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified packager/app/test/testdata/audio-video/bear-640x360-audio.mp4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified packager/app/test/testdata/encryption/bear-640x360-audio.mp4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
<ContentProtection schemeIdUri="urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b">
<cenc:pssh>AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA==</cenc:pssh>
</ContentProtection>
<Representation id="0" bandwidth="2632184" codecs="avc1.64001f" mimeType="video/mp4" sar="1:1" width="1280" height="720">
<SegmentTemplate timescale="30000" initialization="bear-1280x720-video-init.mp4" media="bear-1280x720-video-$Number$.m4s" startNumber="1">
<Representation id="0" bandwidth="978382" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1" width="640" height="360">
<SegmentTemplate timescale="30000" initialization="bear-640x360-video-init.mp4" media="bear-640x360-video-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="30030" r="1"/>
<S t="60060" d="22022"/>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
<Representation id="1" bandwidth="978382" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1" width="640" height="360">
<SegmentTemplate timescale="30000" initialization="bear-640x360-video-init.mp4" media="bear-640x360-video-$Number$.m4s" startNumber="1">
<Representation id="1" bandwidth="383593" codecs="avc1.64000d" mimeType="video/mp4" sar="1:1" width="320" height="180">
<SegmentTemplate timescale="30000" initialization="bear-320x180-video-init.mp4" media="bear-320x180-video-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="30030" r="1"/>
<S t="60060" d="22022"/>
<S t="60060" d="23023"/>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
<Representation id="2" bandwidth="383593" codecs="avc1.64000d" mimeType="video/mp4" sar="1:1" width="320" height="180">
<SegmentTemplate timescale="30000" initialization="bear-320x180-video-init.mp4" media="bear-320x180-video-$Number$.m4s" startNumber="1">
<Representation id="2" bandwidth="2632184" codecs="avc1.64001f" mimeType="video/mp4" sar="1:1" width="1280" height="720">
<SegmentTemplate timescale="30000" initialization="bear-1280x720-video-init.mp4" media="bear-1280x720-video-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="30030" r="1"/>
<S t="60060" d="23023"/>
<S t="60060" d="22022"/>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
Expand All @@ -39,7 +39,7 @@
</ContentProtection>
<Representation id="3" bandwidth="134272" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<SegmentTemplate timescale="44100" initialization="bear-1280x720-audio-init.mp4" media="bear-1280x720-audio-$Number$.m4s" startNumber="1">
<SegmentTemplate timescale="44100" initialization="bear-640x360-audio-init.mp4" media="bear-640x360-audio-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="45056"/>
<S t="45056" d="44032"/>
Expand All @@ -49,7 +49,7 @@
</Representation>
<Representation id="4" bandwidth="134272" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<SegmentTemplate timescale="44100" initialization="bear-640x360-audio-init.mp4" media="bear-640x360-audio-$Number$.m4s" startNumber="1">
<SegmentTemplate timescale="44100" initialization="bear-1280x720-audio-init.mp4" media="bear-1280x720-audio-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="45056"/>
<S t="45056" d="44032"/>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
38 changes: 19 additions & 19 deletions packager/app/test/testdata/vtt-text-to-mp4-with-ad-cues/output.mpd
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
<!--Generated with https://github.com/google/shaka-packager version <tag>-<hash>-<test>-->
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd" profiles="urn:mpeg:dash:profile:isoff-live:2011" minBufferTime="PT2S" type="static" mediaPresentationDuration="PT2.7360668182373047S">
<Period id="0" duration="PT2.002S">
<AdaptationSet id="0" contentType="text" segmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="0" bandwidth="1912" codecs="wvtt" mimeType="application/mp4">
<SegmentTemplate timescale="1000" initialization="bear-english-text-init.mp4" media="bear-english-text-$Number$.m4s" startNumber="1">
<AdaptationSet id="0" contentType="video" width="640" height="360" frameRate="30000/1001" segmentAlignment="true" par="16:9">
<Representation id="0" bandwidth="974122" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1">
<SegmentTemplate timescale="30000" initialization="bear-640x360-video-init.mp4" media="bear-640x360-video-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="1000" r="1"/>
<S t="2000" d="1"/>
<S t="0" d="30030" r="1"/>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
</AdaptationSet>
<AdaptationSet id="1" contentType="video" width="640" height="360" frameRate="30000/1001" segmentAlignment="true" par="16:9">
<Representation id="1" bandwidth="974122" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1">
<SegmentTemplate timescale="30000" initialization="bear-640x360-video-init.mp4" media="bear-640x360-video-$Number$.m4s" startNumber="1">
<AdaptationSet id="1" contentType="text" segmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="1" bandwidth="1912" codecs="wvtt" mimeType="application/mp4">
<SegmentTemplate timescale="1000" initialization="bear-english-text-init.mp4" media="bear-english-text-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="30030" r="1"/>
<S t="0" d="1000" r="1"/>
<S t="2000" d="1"/>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
Expand All @@ -35,21 +35,21 @@
</AdaptationSet>
</Period>
<Period id="1" duration="PT.7340666666666671S">
<AdaptationSet id="0" contentType="text" segmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="0" bandwidth="2024" codecs="wvtt" mimeType="application/mp4">
<SegmentTemplate timescale="1000" presentationTimeOffset="2001" initialization="bear-english-text-init.mp4" media="bear-english-text-$Number$.m4s" startNumber="4">
<AdaptationSet id="0" contentType="video" width="640" height="360" frameRate="30000/1001" segmentAlignment="true" par="16:9">
<Representation id="0" bandwidth="869044" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1">
<SegmentTemplate timescale="30000" presentationTimeOffset="60059" initialization="bear-640x360-video-init.mp4" media="bear-640x360-video-$Number$.m4s" startNumber="3">
<SegmentTimeline>
<S t="2001" d="1000" r="2"/>
<S t="60060" d="22022"/>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
</AdaptationSet>
<AdaptationSet id="1" contentType="video" width="640" height="360" frameRate="30000/1001" segmentAlignment="true" par="16:9">
<Representation id="1" bandwidth="869044" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1">
<SegmentTemplate timescale="30000" presentationTimeOffset="60059" initialization="bear-640x360-video-init.mp4" media="bear-640x360-video-$Number$.m4s" startNumber="3">
<AdaptationSet id="1" contentType="text" segmentAlignment="true">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="subtitle"/>
<Representation id="1" bandwidth="2024" codecs="wvtt" mimeType="application/mp4">
<SegmentTemplate timescale="1000" presentationTimeOffset="2001" initialization="bear-english-text-init.mp4" media="bear-english-text-$Number$.m4s" startNumber="4">
<SegmentTimeline>
<S t="60060" d="22022"/>
<S t="2001" d="1000" r="2"/>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified packager/app/test/testdata/wvm-input/bear-multi-configs-1.mp4
Binary file not shown.
Binary file modified packager/app/test/testdata/wvm-input/bear-multi-configs-3.mp4
Binary file not shown.
5 changes: 4 additions & 1 deletion packager/media/codecs/es_descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ bool ESDescriptor::ReadData(BitReader* reader) {
void ESDescriptor::WriteInternal(BufferWriter* writer) {
WriteHeader(writer);

writer->AppendInt(esid_);
// According to ISO/IEC 14496-14:2018 Section 4.1.2,
// ES_ID is set to 0 when stored
const uint16_t kEsid = 0;
writer->AppendInt(kEsid);
const uint8_t kNoEsFlags = 0;
writer->AppendInt(kNoEsFlags);

Expand Down
1 change: 0 additions & 1 deletion packager/media/codecs/es_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ class ESDescriptor : public BaseDescriptor {
ESDescriptor() : BaseDescriptor(DescriptorTag::kES) {}

uint16_t esid() const { return esid_; }
void set_esid(uint16_t esid) { esid_ = esid; }

const DecoderConfigDescriptor& decoder_config_descriptor() const {
return decoder_config_descriptor_;
Expand Down
17 changes: 15 additions & 2 deletions packager/media/codecs/es_descriptor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST(ESDescriptorTest, SingleByteLengthTest) {
// ESDescriptor tag with one byte size.
0x03, 0x19,
// ESDescriptor fields.
0x00, 0x01, 0x00,
0x00, 0x00, 0x00,
// DecoderConfigDescriptor tag with one byte size.
0x04, 0x11,
// Object Type.
Expand Down Expand Up @@ -56,6 +56,19 @@ TEST(ESDescriptorTest, SingleByteLengthTest) {
EXPECT_THAT(
std::vector<uint8_t>(writer.Buffer(), writer.Buffer() + writer.Size()),
ElementsAreArray(kBuffer));

EXPECT_EQ(0u, es_desc.esid());
const size_t kEsIdOffset = 3;
const uint8_t kEsId = 5;
data[kEsIdOffset] = kEsId;
ASSERT_TRUE(es_desc.Parse(data));
EXPECT_EQ(kEsId, es_desc.esid());

writer.Clear();
es_desc.Write(&writer);
EXPECT_THAT(
std::vector<uint8_t>(writer.Buffer(), writer.Buffer() + writer.Size()),
ElementsAreArray(kBuffer));
}

TEST(ESDescriptorTest, NonAACTest) {
Expand All @@ -64,7 +77,7 @@ TEST(ESDescriptorTest, NonAACTest) {
// ESDescriptor tag with one byte size.
0x03, 0x19,
// ESDescriptor fields.
0x00, 0x01, 0x00,
0x00, 0x00, 0x00,
// DecoderConfigDescriptor tag with one byte size.
0x04, 0x11,
// Object Type.
Expand Down
5 changes: 0 additions & 5 deletions packager/media/formats/mp4/box_definitions_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ class BoxDefinitionsTestGeneral : public testing::Test {

void Fill(ElementaryStreamDescriptor* esds) {
const uint8_t kDecoderSpecificInfo[] = {18, 16};
esds->es_descriptor.set_esid(1);
esds->es_descriptor.mutable_decoder_config_descriptor()->set_object_type(
ObjectType::kISO_14496_3);
std::vector<uint8_t> decoder_specific_info(
Expand All @@ -394,10 +393,6 @@ class BoxDefinitionsTestGeneral : public testing::Test {
->set_data(decoder_specific_info);
}

void Modify(ElementaryStreamDescriptor* esds) {
esds->es_descriptor.set_esid(2);
}

void Fill(DTSSpecific* ddts) {
const uint8_t kDdtsExtraData[] = {0xe4, 0x7c, 0, 4, 0, 0x0f, 0};
ddts->max_bitrate = 768000;
Expand Down
17 changes: 6 additions & 11 deletions packager/media/formats/mp4/mp4_muxer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ Status MP4Muxer::DelayInitializeMuxer() {
switch (stream->stream_type()) {
case kStreamVideo:
generate_trak_result = GenerateVideoTrak(
static_cast<const VideoStreamInfo*>(stream), &trak, i + 1);
static_cast<const VideoStreamInfo*>(stream), &trak);
break;
case kStreamAudio:
generate_trak_result = GenerateAudioTrak(
static_cast<const AudioStreamInfo*>(stream), &trak, i + 1);
static_cast<const AudioStreamInfo*>(stream), &trak);
break;
case kStreamText:
generate_trak_result = GenerateTextTrak(
static_cast<const TextStreamInfo*>(stream), &trak, i + 1);
static_cast<const TextStreamInfo*>(stream), &trak);
break;
default:
NOTIMPLEMENTED() << "Not implemented for stream type: "
Expand Down Expand Up @@ -395,8 +395,7 @@ void MP4Muxer::InitializeTrak(const StreamInfo* info, Track* trak) {
}

bool MP4Muxer::GenerateVideoTrak(const VideoStreamInfo* video_info,
Track* trak,
uint32_t track_id) {
Track* trak) {
InitializeTrak(video_info, trak);

// width and height specify the track's visual presentation size as
Expand Down Expand Up @@ -449,8 +448,7 @@ bool MP4Muxer::GenerateVideoTrak(const VideoStreamInfo* video_info,
}

bool MP4Muxer::GenerateAudioTrak(const AudioStreamInfo* audio_info,
Track* trak,
uint32_t track_id) {
Track* trak) {
InitializeTrak(audio_info, trak);

trak->header.volume = 0x100;
Expand All @@ -460,7 +458,6 @@ bool MP4Muxer::GenerateAudioTrak(const AudioStreamInfo* audio_info,
CodecToFourCC(audio_info->codec(), H26xStreamFormat::kUnSpecified);
switch(audio_info->codec()){
case kCodecAAC: {
audio.esds.es_descriptor.set_esid(track_id);
DecoderConfigDescriptor* decoder_config =
audio.esds.es_descriptor.mutable_decoder_config_descriptor();
decoder_config->set_object_type(ObjectType::kISO_14496_3); // MPEG4 AAC.
Expand Down Expand Up @@ -494,7 +491,6 @@ bool MP4Muxer::GenerateAudioTrak(const AudioStreamInfo* audio_info,
audio.dfla.data = audio_info->codec_config();
break;
case kCodecMP3: {
audio.esds.es_descriptor.set_esid(track_id);
DecoderConfigDescriptor* decoder_config =
audio.esds.es_descriptor.mutable_decoder_config_descriptor();
uint32_t samplerate = audio_info->sampling_frequency();
Expand Down Expand Up @@ -567,8 +563,7 @@ bool MP4Muxer::GenerateAudioTrak(const AudioStreamInfo* audio_info,
}

bool MP4Muxer::GenerateTextTrak(const TextStreamInfo* text_info,
Track* trak,
uint32_t track_id) {
Track* trak) {
InitializeTrak(text_info, trak);

if (text_info->codec_string() == "wvtt") {
Expand Down
12 changes: 3 additions & 9 deletions packager/media/formats/mp4/mp4_muxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ class MP4Muxer : public Muxer {

// Generate Audio/Video Track box.
void InitializeTrak(const StreamInfo* info, Track* trak);
bool GenerateAudioTrak(const AudioStreamInfo* audio_info,
Track* trak,
uint32_t track_id);
bool GenerateVideoTrak(const VideoStreamInfo* video_info,
Track* trak,
uint32_t track_id);
bool GenerateTextTrak(const TextStreamInfo* video_info,
Track* trak,
uint32_t track_id);
bool GenerateAudioTrak(const AudioStreamInfo* audio_info, Track* trak);
bool GenerateVideoTrak(const VideoStreamInfo* video_info, Track* trak);
bool GenerateTextTrak(const TextStreamInfo* video_info, Track* trak);

// Gets |start| and |end| initialization range. Returns true if there is an
// init range and sets start-end byte-range-spec specified in RFC2616.
Expand Down

0 comments on commit a8ea7fd

Please sign in to comment.