2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/audio_stream_info.h"
|
2013-09-24 04:17:12 +00:00
|
|
|
|
2016-05-05 22:26:48 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/logging.h"
|
|
|
|
#include "packager/base/strings/string_number_conversions.h"
|
|
|
|
#include "packager/base/strings/stringprintf.h"
|
|
|
|
#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";
|
2016-01-08 23:56:33 +00:00
|
|
|
case kCodecOpus:
|
|
|
|
return "Opus";
|
|
|
|
case kCodecVorbis:
|
|
|
|
return "Vorbis";
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-07-27 00:51:08 +00:00
|
|
|
AudioStreamInfo::AudioStreamInfo(
|
|
|
|
int track_id, uint32_t time_scale, uint64_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 {
|
2016-05-05 22:26:48 +00:00
|
|
|
std::string str = base::StringPrintf(
|
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) {
|
2016-06-01 23:28:56 +00:00
|
|
|
base::StringAppendF(&str, " seek_preroll_ns: %" PRIu64 "\n",
|
2016-05-05 22:26:48 +00:00
|
|
|
seek_preroll_ns_);
|
|
|
|
}
|
|
|
|
if (codec_delay_ns_ != 0) {
|
2016-06-01 23:28:56 +00:00
|
|
|
base::StringAppendF(&str, " codec_delay_ns: %" PRIu64 "\n",
|
2016-05-05 22:26:48 +00:00
|
|
|
codec_delay_ns_);
|
|
|
|
}
|
|
|
|
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 kCodecVorbis:
|
|
|
|
return "vorbis";
|
|
|
|
case kCodecOpus:
|
|
|
|
return "opus";
|
|
|
|
case kCodecAAC:
|
|
|
|
return "mp4a.40." + base::UintToString(audio_object_type);
|
2015-12-07 19:56:07 +00:00
|
|
|
case kCodecDTSC:
|
|
|
|
return "dtsc";
|
|
|
|
case kCodecDTSH:
|
|
|
|
return "dtsh";
|
|
|
|
case kCodecDTSL:
|
|
|
|
return "dtsl";
|
|
|
|
case kCodecDTSE:
|
|
|
|
return "dtse";
|
|
|
|
case kCodecDTSP:
|
|
|
|
return "dts+";
|
|
|
|
case kCodecDTSM:
|
|
|
|
return "dts-";
|
2016-01-08 23:56:33 +00:00
|
|
|
case kCodecAC3:
|
|
|
|
return "ac-3";
|
2016-01-15 21:40:44 +00:00
|
|
|
case kCodecEAC3:
|
|
|
|
return "ec-3";
|
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
|