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
|
|
|
|
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
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-09-24 04:17:12 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-03-05 23:15:22 +00:00
|
|
|
namespace {
|
|
|
|
std::string AudioCodecToString(AudioCodec audio_codec) {
|
|
|
|
switch (audio_codec) {
|
|
|
|
case kCodecAAC:
|
|
|
|
return "AAC";
|
|
|
|
case kCodecMP3:
|
|
|
|
return "MP3";
|
|
|
|
case kCodecPCM:
|
|
|
|
return "PCM";
|
|
|
|
case kCodecVorbis:
|
|
|
|
return "Vorbis";
|
|
|
|
case kCodecFLAC:
|
|
|
|
return "FLAC";
|
|
|
|
case kCodecAMR_NB:
|
|
|
|
return "AMR_NB";
|
|
|
|
case kCodecAMR_WB:
|
|
|
|
return "AMR_WB";
|
|
|
|
case kCodecPCM_MULAW:
|
|
|
|
return "PCM_MULAW";
|
|
|
|
case kCodecGSM_MS:
|
|
|
|
return "GSM_MS";
|
|
|
|
case kCodecPCM_S16BE:
|
|
|
|
return "PCM_S16BE";
|
|
|
|
case kCodecPCM_S24BE:
|
|
|
|
return "PCM_S24BE";
|
|
|
|
case kCodecOpus:
|
|
|
|
return "Opus";
|
|
|
|
case kCodecEAC3:
|
|
|
|
return "EAC3";
|
|
|
|
default:
|
|
|
|
NOTIMPLEMENTED() << "Unknown Audio Codec: " << audio_codec;
|
|
|
|
return "UnknownAudioCodec";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-09-24 04:17:12 +00:00
|
|
|
AudioStreamInfo::AudioStreamInfo(int track_id,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t time_scale,
|
|
|
|
uint64_t duration,
|
2013-09-24 04:17:12 +00:00
|
|
|
AudioCodec codec,
|
2013-10-14 20:55:48 +00:00
|
|
|
const std::string& codec_string,
|
|
|
|
const std::string& language,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint8_t sample_bits,
|
|
|
|
uint8_t num_channels,
|
|
|
|
uint32_t sampling_frequency,
|
|
|
|
const uint8_t* extra_data,
|
2013-09-24 04:17:12 +00:00
|
|
|
size_t extra_data_size,
|
|
|
|
bool is_encrypted)
|
|
|
|
: StreamInfo(kStreamAudio,
|
|
|
|
track_id,
|
|
|
|
time_scale,
|
2013-10-14 20:55:48 +00:00
|
|
|
duration,
|
|
|
|
codec_string,
|
|
|
|
language,
|
2013-09-24 04:17:12 +00:00
|
|
|
extra_data,
|
|
|
|
extra_data_size,
|
|
|
|
is_encrypted),
|
|
|
|
codec_(codec),
|
2013-10-14 20:55:48 +00:00
|
|
|
sample_bits_(sample_bits),
|
2013-09-24 04:17:12 +00:00
|
|
|
num_channels_(num_channels),
|
2014-09-30 21:52:21 +00:00
|
|
|
sampling_frequency_(sampling_frequency) {
|
|
|
|
}
|
2013-09-24 04:17:12 +00:00
|
|
|
|
|
|
|
AudioStreamInfo::~AudioStreamInfo() {}
|
|
|
|
|
|
|
|
bool AudioStreamInfo::IsValidConfig() const {
|
|
|
|
return codec_ != kUnknownAudioCodec && num_channels_ != 0 &&
|
2013-10-14 20:55:48 +00:00
|
|
|
num_channels_ <= limits::kMaxChannels && sample_bits_ > 0 &&
|
|
|
|
sample_bits_ <= limits::kMaxBitsPerSample &&
|
|
|
|
sampling_frequency_ > 0 &&
|
|
|
|
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 {
|
2014-03-05 23:15:22 +00:00
|
|
|
return base::StringPrintf(
|
|
|
|
"%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",
|
|
|
|
StreamInfo::ToString().c_str(), AudioCodecToString(codec_).c_str(),
|
|
|
|
sample_bits_, num_channels_, sampling_frequency_, language().c_str());
|
2013-09-24 04:17:12 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 20:55:48 +00:00
|
|
|
std::string AudioStreamInfo::GetCodecString(AudioCodec 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);
|
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
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|