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
|
|
|
|
|
|
|
#include "media/base/audio_stream_info.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
2014-01-16 00:52:07 +00:00
|
|
|
#include "base/logging.h"
|
2013-10-14 20:55:48 +00:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2013-09-24 04:17:12 +00:00
|
|
|
#include "media/base/limits.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
|
|
|
|
AudioStreamInfo::AudioStreamInfo(int track_id,
|
2013-10-14 20:55:48 +00:00
|
|
|
uint32 time_scale,
|
|
|
|
uint64 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,
|
|
|
|
uint8 sample_bits,
|
|
|
|
uint8 num_channels,
|
|
|
|
uint32 sampling_frequency,
|
2013-09-24 04:17:12 +00:00
|
|
|
const uint8* extra_data,
|
|
|
|
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),
|
2013-10-14 20:55:48 +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 {
|
2013-09-24 04:17:12 +00:00
|
|
|
std::ostringstream s;
|
|
|
|
s << "codec: " << codec_
|
2013-10-14 20:55:48 +00:00
|
|
|
<< " sample_bits: " << static_cast<int>(sample_bits_)
|
|
|
|
<< " num_channels: " << static_cast<int>(num_channels_)
|
|
|
|
<< " sampling_frequency: " << sampling_frequency_
|
2013-09-24 04:17:12 +00:00
|
|
|
<< " " << StreamInfo::ToString();
|
|
|
|
return s.str();
|
|
|
|
}
|
|
|
|
|
2013-10-14 20:55:48 +00:00
|
|
|
std::string AudioStreamInfo::GetCodecString(AudioCodec codec,
|
|
|
|
uint8 audio_object_type) {
|
|
|
|
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
|