diff --git a/README.md b/README.md index 76892dceae..b6c30e9697 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Shaka Packager supports: | VP9 | I / O | I / O | - | - | - | | AV1 | I / O | I / O | - | - | - | | AAC | I / O | - | I / O | I | O | - | MP3 | - | - | I / O | - | O | + | MP3 | O | - | I / O | - | O | | Dolby AC3 | I / O | - | I / O | - | O | | Dolby EAC3 | I / O | - | O | - | O | | DTS | I / O | - | - | - | - | diff --git a/packager/media/codecs/es_descriptor.cc b/packager/media/codecs/es_descriptor.cc index 7d385a5f83..639ce4b5c2 100644 --- a/packager/media/codecs/es_descriptor.cc +++ b/packager/media/codecs/es_descriptor.cc @@ -167,13 +167,17 @@ void DecoderConfigDescriptor::WriteInternal(BufferWriter* writer) { writer->AppendNBytes(buffer_size_db_, 3); writer->AppendInt(max_bitrate_); writer->AppendInt(avg_bitrate_); - decoder_specific_info_descriptor_.Write(writer); + + if (!decoder_specific_info_descriptor_.data().empty()) + decoder_specific_info_descriptor_.Write(writer); } size_t DecoderConfigDescriptor::ComputeDataSize() { // object_type (1 byte), stream_type (1 byte), decoding_buffer_size (3 bytes), // max_bitrate (4 bytes), avg_bitrate (4 bytes). const size_t data_size_without_children = 1 + 1 + 3 + 4 + 4; + if (decoder_specific_info_descriptor_.data().empty()) + return data_size_without_children; return data_size_without_children + decoder_specific_info_descriptor_.ComputeSize(); } diff --git a/packager/media/codecs/es_descriptor.h b/packager/media/codecs/es_descriptor.h index 7f402e7230..e4caaf2b72 100644 --- a/packager/media/codecs/es_descriptor.h +++ b/packager/media/codecs/es_descriptor.h @@ -22,6 +22,8 @@ enum class ObjectType : uint8_t { kForbidden = 0, kISO_14496_3 = 0x40, // MPEG4 AAC kISO_13818_7_AAC_LC = 0x67, // MPEG2 AAC-LC + kISO_13818_3_MPEG1 = 0x69, // MPEG1 ISO/IEC 13818-3, 16,22.05,24kHz + kISO_11172_3_MPEG1 = 0x6B, // MPEG1 ISO/IEC 11172-3, 32,44.1,48kHz kDTSC = 0xA9, // DTS Coherent Acoustics audio kDTSE = 0xAC, // DTS Express low bit rate audio kDTSH = 0xAA, // DTS-HD High Resolution Audio diff --git a/packager/media/formats/mp4/mp4_muxer.cc b/packager/media/formats/mp4/mp4_muxer.cc index 4778bbfcf2..336f13a039 100644 --- a/packager/media/formats/mp4/mp4_muxer.cc +++ b/packager/media/formats/mp4/mp4_muxer.cc @@ -67,6 +67,7 @@ FourCC CodecToFourCC(Codec codec, H26xStreamFormat h26x_stream_format) { case kCodecVP9: return FOURCC_vp09; case kCodecAAC: + case kCodecMP3: return FOURCC_mp4a; case kCodecAC3: return FOURCC_ac_3; @@ -487,6 +488,25 @@ bool MP4Muxer::GenerateAudioTrak(const AudioStreamInfo* audio_info, case kCodecFlac: 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(); + if (samplerate < 32000) + decoder_config->set_object_type(ObjectType::kISO_13818_3_MPEG1); + else + decoder_config->set_object_type(ObjectType::kISO_11172_3_MPEG1); + decoder_config->set_max_bitrate(audio_info->max_bitrate()); + decoder_config->set_avg_bitrate(audio_info->avg_bitrate()); + + // For values of DecoderConfigDescriptor.objectTypeIndication + // that refer to streams complying with ISO/IEC 11172-3 or + // ISO/IEC 13818-3 the decoder specific information is empty + // since all necessary data is contained in the bitstream frames + // itself. + break; + } case kCodecOpus: audio.dops.opus_identification_header = audio_info->codec_config(); break;