| Index: chromecast/media/cma/public/audio_config.cc
|
| diff --git a/chromecast/media/cma/public/audio_config.cc b/chromecast/media/cma/public/audio_config.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..78a21c8747eb04c4abbe4b6fcb1d3ad1473108f5
|
| --- /dev/null
|
| +++ b/chromecast/media/cma/public/audio_config.cc
|
| @@ -0,0 +1,201 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chromecast/media/cma/public/audio_config.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "media/base/audio_decoder_config.h"
|
| +
|
| +// Make sure the enum values of media::AudioCodec and
|
| +// chromecast::media::AudioConfig::Codec are matched.
|
| +#define STATIC_ASSERT_ENUM_MATCH_CODEC(name) \
|
| + static_assert( \
|
| + ::media::name == static_cast< ::media::AudioCodec>( \
|
| + chromecast::media::AudioConfig::name), \
|
| + #name " value must match in media and chromecast::media::AudioConfig.")
|
| +
|
| +// Make sure the enum values of media::ChannelLayout and
|
| +// chromecast::media::AudioConfig::ChannelLayout are matched.
|
| +#define STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(name) \
|
| + static_assert( \
|
| + ::media::name == static_cast< ::media::ChannelLayout>( \
|
| + chromecast::media::AudioConfig::name), \
|
| + #name " value must match in media and chromecast::media::AudioConfig.")
|
| +
|
| +namespace {
|
| +
|
| +// Maximum audio bytes per sample.
|
| +static int kMaxBytesPerSample = 4;
|
| +
|
| +// Maximum audio sampling rate.
|
| +static int kMaxSampleRate = 192000;
|
| +
|
| +} // namespace
|
| +
|
| +namespace chromecast {
|
| +namespace media {
|
| +
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kUnknownAudioCodec);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecAAC);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecMP3);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecPCM);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecVorbis);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecFLAC);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecAMR_NB);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecAMR_WB);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecPCM_MULAW);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecGSM_MS);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecPCM_S16BE);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecPCM_S24BE);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecOpus);
|
| +// STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecEAC3);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecPCM_ALAW);
|
| +STATIC_ASSERT_ENUM_MATCH_CODEC(kCodecALAC);
|
| +
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_NONE);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_UNSUPPORTED);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_MONO);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_STEREO);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_2_1);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_SURROUND);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_4_0);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_2_2);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_QUAD);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_5_0);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_5_1);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_5_0_BACK);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_5_1_BACK);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_7_0);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_7_1);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_7_1_WIDE);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_STEREO_DOWNMIX);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_2POINT1);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_3_1);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_4_1);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_6_0);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_6_0_FRONT);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_HEXAGONAL);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_6_1);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_6_1_BACK);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_6_1_FRONT);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_7_0_FRONT);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_7_1_WIDE_BACK);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_OCTAGONAL);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_DISCRETE);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC);
|
| +STATIC_ASSERT_ENUM_MATCH_CHANNEL_LAYOUT(CHANNEL_LAYOUT_4_1_QUAD_SIDE);
|
| +
|
| +AudioConfig::AudioConfig()
|
| + : codec_(kUnknownAudioCodec),
|
| + channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED),
|
| + channel_number_(0),
|
| + bytes_per_channel_(0),
|
| + samples_per_second_(0),
|
| + is_encrypted_(false) {}
|
| +
|
| +AudioConfig::AudioConfig(Codec codec,
|
| + ChannelLayout channel_layout,
|
| + int channel_number,
|
| + int bytes_per_channel,
|
| + int samples_per_second,
|
| + const uint8* extra_data,
|
| + size_t extra_data_size,
|
| + bool is_encrypted) {
|
| + Initialize(codec, channel_layout, channel_number,
|
| + bytes_per_channel, samples_per_second,
|
| + extra_data, extra_data_size, is_encrypted);
|
| +}
|
| +
|
| +void AudioConfig::Initialize(Codec codec,
|
| + ChannelLayout channel_layout,
|
| + int channel_number,
|
| + int bytes_per_channel,
|
| + int samples_per_second,
|
| + const uint8* extra_data,
|
| + size_t extra_data_size,
|
| + bool is_encrypted) {
|
| + DCHECK((extra_data_size != 0) == (extra_data != NULL));
|
| +
|
| + codec_ = codec;
|
| + channel_layout_ = channel_layout;
|
| + channel_number_ = channel_number;
|
| + bytes_per_channel_ = bytes_per_channel;
|
| + samples_per_second_ = samples_per_second;
|
| + extra_data_.assign(extra_data, extra_data + extra_data_size);
|
| + is_encrypted_ = is_encrypted;
|
| +}
|
| +
|
| +AudioConfig::~AudioConfig() {}
|
| +
|
| +bool AudioConfig::IsValidConfig() const {
|
| + return codec_ != kUnknownAudioCodec &&
|
| + channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED &&
|
| + bytes_per_channel_ > 0 &&
|
| + bytes_per_channel_ <= kMaxBytesPerSample &&
|
| + samples_per_second_ > 0 &&
|
| + samples_per_second_ <= kMaxSampleRate;
|
| +}
|
| +
|
| +bool AudioConfig::Matches(const AudioConfig& config) const {
|
| + return ((codec() == config.codec()) &&
|
| + (bytes_per_channel() == config.bytes_per_channel()) &&
|
| + (channel_number() == config.channel_number()) &&
|
| + (channel_layout() == config.channel_layout()) &&
|
| + (samples_per_second() == config.samples_per_second()) &&
|
| + (extra_data_size() == config.extra_data_size()) &&
|
| + (!extra_data() || !memcmp(extra_data(), config.extra_data(),
|
| + extra_data_size())) &&
|
| + (is_encrypted() == config.is_encrypted()));
|
| +}
|
| +
|
| +std::string AudioConfig::AsHumanReadableString() const {
|
| + std::ostringstream s;
|
| + s << "codec: " << GetHumanReadableCodecName()
|
| + << " bytes_per_channel: " << bytes_per_channel()
|
| + << " channel_layout: " << channel_layout()
|
| + << " channel_number: " << channel_number()
|
| + << " samples_per_second: " << samples_per_second()
|
| + << " has extra data? " << (extra_data() ? "true" : "false")
|
| + << " encrypted? " << (is_encrypted() ? "true" : "false");
|
| + return s.str();
|
| +}
|
| +
|
| +// These names come from src/third_party/ffmpeg/libavcodec/codec_desc.c
|
| +std::string AudioConfig::GetHumanReadableCodecName() const {
|
| + switch (codec()) {
|
| + case kUnknownAudioCodec:
|
| + return "unknown";
|
| + case kCodecAAC:
|
| + return "aac";
|
| + case kCodecMP3:
|
| + return "mp3";
|
| + case kCodecPCM:
|
| + case kCodecPCM_S16BE:
|
| + case kCodecPCM_S24BE:
|
| + return "pcm";
|
| + case kCodecVorbis:
|
| + return "vorbis";
|
| + case kCodecFLAC:
|
| + return "flac";
|
| + case kCodecAMR_NB:
|
| + return "amr_nb";
|
| + case kCodecAMR_WB:
|
| + return "amr_wb";
|
| + case kCodecGSM_MS:
|
| + return "gsm_ms";
|
| + case kCodecPCM_ALAW:
|
| + return "pcm_alaw";
|
| + case kCodecPCM_MULAW:
|
| + return "pcm_mulaw";
|
| + case kCodecOpus:
|
| + return "opus";
|
| + case kCodecALAC:
|
| + return "alac";
|
| + }
|
| + NOTREACHED();
|
| + return "";
|
| +}
|
| +
|
| +} // namespace media
|
| +} // namespace chromecast
|
|
|