2022-08-26 15:44:59 +00:00
|
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
|
//
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
|
#include <packager/media/base/audio_stream_info.h>
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
2023-10-11 08:49:50 +00:00
|
|
|
|
#include <cinttypes>
|
2016-05-05 22:26:48 +00:00
|
|
|
|
|
2023-10-13 19:42:47 +00:00
|
|
|
|
#include <absl/log/log.h>
|
2023-10-09 23:21:41 +00:00
|
|
|
|
#include <absl/strings/str_format.h>
|
2023-10-11 08:49:50 +00:00
|
|
|
|
|
2023-10-14 16:36:01 +00:00
|
|
|
|
#include <packager/macros/compiler.h>
|
|
|
|
|
#include <packager/macros/logging.h>
|
2023-10-10 23:51:11 +00:00
|
|
|
|
#include <packager/media/base/limits.h>
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
|
namespace shaka {
|
2013-09-24 04:17:12 +00:00
|
|
|
|
namespace media {
|
|
|
|
|
|
2014-03-05 23:15:22 +00:00
|
|
|
|
namespace {
|
2016-07-27 00:51:08 +00:00
|
|
|
|
std::string AudioCodecToString(Codec codec) {
|
|
|
|
|
switch (codec) {
|
2014-03-05 23:15:22 +00:00
|
|
|
|
case kCodecAAC:
|
|
|
|
|
return "AAC";
|
2016-01-08 23:56:33 +00:00
|
|
|
|
case kCodecAC3:
|
|
|
|
|
return "AC3";
|
2015-12-07 19:56:07 +00:00
|
|
|
|
case kCodecDTSC:
|
|
|
|
|
return "DTSC";
|
2016-01-08 23:56:33 +00:00
|
|
|
|
case kCodecDTSE:
|
|
|
|
|
return "DTSE";
|
2015-12-07 19:56:07 +00:00
|
|
|
|
case kCodecDTSH:
|
|
|
|
|
return "DTSH";
|
|
|
|
|
case kCodecDTSL:
|
|
|
|
|
return "DTSL";
|
|
|
|
|
case kCodecDTSM:
|
|
|
|
|
return "DTS-";
|
2016-01-08 23:56:33 +00:00
|
|
|
|
case kCodecDTSP:
|
|
|
|
|
return "DTS+";
|
2016-01-15 21:40:44 +00:00
|
|
|
|
case kCodecEAC3:
|
|
|
|
|
return "EAC3";
|
2020-07-04 21:55:28 +00:00
|
|
|
|
case kCodecAC4:
|
|
|
|
|
return "AC4";
|
2018-04-25 18:27:53 +00:00
|
|
|
|
case kCodecFlac:
|
|
|
|
|
return "FLAC";
|
2016-01-08 23:56:33 +00:00
|
|
|
|
case kCodecOpus:
|
|
|
|
|
return "Opus";
|
|
|
|
|
case kCodecVorbis:
|
|
|
|
|
return "Vorbis";
|
2020-06-03 00:32:19 +00:00
|
|
|
|
case kCodecMP3:
|
|
|
|
|
return "MP3";
|
2014-03-05 23:15:22 +00:00
|
|
|
|
default:
|
2016-07-27 00:51:08 +00:00
|
|
|
|
NOTIMPLEMENTED() << "Unknown Audio Codec: " << codec;
|
|
|
|
|
return "UnknownCodec";
|
2014-03-05 23:15:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-30 06:10:53 +00:00
|
|
|
|
|
|
|
|
|
FourCC CodecToFourCC(Codec codec) {
|
|
|
|
|
switch (codec) {
|
|
|
|
|
case kCodecMha1:
|
|
|
|
|
return FOURCC_mha1;
|
|
|
|
|
case kCodecMhm1:
|
|
|
|
|
return FOURCC_mhm1;
|
|
|
|
|
default:
|
|
|
|
|
return FOURCC_NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-05 23:15:22 +00:00
|
|
|
|
} // namespace
|
|
|
|
|
|
2021-08-04 18:56:44 +00:00
|
|
|
|
AudioStreamInfo::AudioStreamInfo(int track_id,
|
|
|
|
|
int32_t time_scale,
|
|
|
|
|
int64_t duration,
|
|
|
|
|
Codec codec,
|
|
|
|
|
const std::string& codec_string,
|
|
|
|
|
const uint8_t* codec_config,
|
|
|
|
|
size_t codec_config_size,
|
|
|
|
|
uint8_t sample_bits,
|
|
|
|
|
uint8_t num_channels,
|
|
|
|
|
uint32_t sampling_frequency,
|
|
|
|
|
uint64_t seek_preroll_ns,
|
|
|
|
|
uint64_t codec_delay_ns,
|
|
|
|
|
uint32_t max_bitrate,
|
|
|
|
|
uint32_t avg_bitrate,
|
|
|
|
|
const std::string& language,
|
|
|
|
|
bool is_encrypted)
|
|
|
|
|
: StreamInfo(kStreamAudio,
|
|
|
|
|
track_id,
|
|
|
|
|
time_scale,
|
|
|
|
|
duration,
|
|
|
|
|
codec,
|
|
|
|
|
codec_string,
|
|
|
|
|
codec_config,
|
|
|
|
|
codec_config_size,
|
|
|
|
|
language,
|
2013-09-24 04:17:12 +00:00
|
|
|
|
is_encrypted),
|
2013-10-14 20:55:48 +00:00
|
|
|
|
sample_bits_(sample_bits),
|
2013-09-24 04:17:12 +00:00
|
|
|
|
num_channels_(num_channels),
|
2016-01-04 18:57:05 +00:00
|
|
|
|
sampling_frequency_(sampling_frequency),
|
2016-05-05 22:26:48 +00:00
|
|
|
|
seek_preroll_ns_(seek_preroll_ns),
|
|
|
|
|
codec_delay_ns_(codec_delay_ns),
|
2016-01-04 18:57:05 +00:00
|
|
|
|
max_bitrate_(max_bitrate),
|
|
|
|
|
avg_bitrate_(avg_bitrate) {}
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
|
|
|
|
AudioStreamInfo::~AudioStreamInfo() {}
|
|
|
|
|
|
|
|
|
|
bool AudioStreamInfo::IsValidConfig() const {
|
2016-07-27 00:51:08 +00:00
|
|
|
|
return codec() != kUnknownCodec && num_channels_ != 0 &&
|
2013-10-14 20:55:48 +00:00
|
|
|
|
num_channels_ <= limits::kMaxChannels && sample_bits_ > 0 &&
|
2016-07-27 00:51:08 +00:00
|
|
|
|
sample_bits_ <= limits::kMaxBitsPerSample && sampling_frequency_ > 0 &&
|
2013-10-14 20:55:48 +00:00
|
|
|
|
sampling_frequency_ <= limits::kMaxSampleRate;
|
2013-09-24 04:17:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-14 20:55:48 +00:00
|
|
|
|
std::string AudioStreamInfo::ToString() const {
|
2022-11-04 22:46:41 +00:00
|
|
|
|
std::string str = absl::StrFormat(
|
2014-03-05 23:15:22 +00:00
|
|
|
|
"%s codec: %s\n sample_bits: %d\n num_channels: %d\n "
|
2015-09-25 22:48:18 +00:00
|
|
|
|
"sampling_frequency: %d\n language: %s\n",
|
2016-07-27 00:51:08 +00:00
|
|
|
|
StreamInfo::ToString().c_str(), AudioCodecToString(codec()).c_str(),
|
2015-09-25 22:48:18 +00:00
|
|
|
|
sample_bits_, num_channels_, sampling_frequency_, language().c_str());
|
2016-05-05 22:26:48 +00:00
|
|
|
|
if (seek_preroll_ns_ != 0) {
|
2022-11-04 22:46:41 +00:00
|
|
|
|
absl::StrAppendFormat(&str, " seek_preroll_ns: %" PRIu64 "\n",
|
|
|
|
|
seek_preroll_ns_);
|
2016-05-05 22:26:48 +00:00
|
|
|
|
}
|
|
|
|
|
if (codec_delay_ns_ != 0) {
|
2022-11-04 22:46:41 +00:00
|
|
|
|
absl::StrAppendFormat(&str, " codec_delay_ns: %" PRIu64 "\n",
|
|
|
|
|
codec_delay_ns_);
|
2016-05-05 22:26:48 +00:00
|
|
|
|
}
|
|
|
|
|
return str;
|
2013-09-24 04:17:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-12 17:24:24 +00:00
|
|
|
|
std::unique_ptr<StreamInfo> AudioStreamInfo::Clone() const {
|
|
|
|
|
return std::unique_ptr<StreamInfo>(new AudioStreamInfo(*this));
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-27 00:51:08 +00:00
|
|
|
|
std::string AudioStreamInfo::GetCodecString(Codec codec,
|
2014-09-30 21:52:21 +00:00
|
|
|
|
uint8_t audio_object_type) {
|
2013-10-14 20:55:48 +00:00
|
|
|
|
switch (codec) {
|
|
|
|
|
case kCodecAAC:
|
2022-11-04 22:46:41 +00:00
|
|
|
|
return "mp4a.40." + absl::StrFormat("%hhu", audio_object_type);
|
2018-04-25 18:27:53 +00:00
|
|
|
|
case kCodecAC3:
|
|
|
|
|
return "ac-3";
|
2015-12-07 19:56:07 +00:00
|
|
|
|
case kCodecDTSC:
|
|
|
|
|
return "dtsc";
|
2018-04-25 18:27:53 +00:00
|
|
|
|
case kCodecDTSE:
|
|
|
|
|
return "dtse";
|
2015-12-07 19:56:07 +00:00
|
|
|
|
case kCodecDTSH:
|
|
|
|
|
return "dtsh";
|
|
|
|
|
case kCodecDTSL:
|
|
|
|
|
return "dtsl";
|
|
|
|
|
case kCodecDTSM:
|
|
|
|
|
return "dts-";
|
2018-04-25 18:27:53 +00:00
|
|
|
|
case kCodecDTSP:
|
|
|
|
|
return "dts+";
|
2016-01-15 21:40:44 +00:00
|
|
|
|
case kCodecEAC3:
|
|
|
|
|
return "ec-3";
|
2020-07-04 21:55:28 +00:00
|
|
|
|
case kCodecAC4:
|
|
|
|
|
// ETSI TS 103 190-2 Digital Audio Compression (AC-4) Standard; Part 2:
|
|
|
|
|
// Immersive and personalized audio E.13. audio_object_type is composed of
|
|
|
|
|
// bitstream_version (3bits), presentation_version (2bits) and
|
|
|
|
|
// mdcompat (3bits).
|
2022-11-04 22:46:41 +00:00
|
|
|
|
return absl::StrFormat(
|
|
|
|
|
"ac-4.%02d.%02d.%02d", (audio_object_type & 0xE0) >> 5,
|
|
|
|
|
(audio_object_type & 0x18) >> 3, audio_object_type & 0x7);
|
2018-04-25 18:27:53 +00:00
|
|
|
|
case kCodecFlac:
|
|
|
|
|
return "flac";
|
|
|
|
|
case kCodecOpus:
|
|
|
|
|
return "opus";
|
2020-06-03 00:32:19 +00:00
|
|
|
|
case kCodecMP3:
|
|
|
|
|
return "mp3";
|
2018-04-25 18:27:53 +00:00
|
|
|
|
case kCodecVorbis:
|
|
|
|
|
return "vorbis";
|
2021-06-30 06:10:53 +00:00
|
|
|
|
case kCodecMha1:
|
|
|
|
|
case kCodecMhm1:
|
|
|
|
|
// The signalling of the codecs parameters is according to RFC6381 [11]
|
|
|
|
|
// and ISO/IEC 23008-3 clause 21 [7].
|
|
|
|
|
// The value consists of the following two parts separated by a dot:
|
|
|
|
|
// - the sample entry 4CC code ('mha1', 'mha2', 'mhm1', 'mhm2')
|
|
|
|
|
// - ‘0x’ followed by the hex value of the profile-levelid, as defined
|
|
|
|
|
// in in ISO/IEC 23008-3 [7]
|
2022-11-04 22:46:41 +00:00
|
|
|
|
return absl::StrFormat("%s.0x%02x",
|
|
|
|
|
FourCCToString(CodecToFourCC(codec)).c_str(),
|
|
|
|
|
audio_object_type);
|
2014-01-16 00:52:07 +00:00
|
|
|
|
default:
|
|
|
|
|
NOTIMPLEMENTED() << "Codec: " << codec;
|
|
|
|
|
return "unknown";
|
2013-10-14 20:55:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
|
} // namespace shaka
|