Chromium Code Reviews| Index: chromecast/media/cma/base/decoder_config_adapter.cc |
| diff --git a/chromecast/media/cma/base/decoder_config_adapter.cc b/chromecast/media/cma/base/decoder_config_adapter.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f65e682e7b984053e1ac6b459c1d2a3af1dadc98 |
| --- /dev/null |
| +++ b/chromecast/media/cma/base/decoder_config_adapter.cc |
| @@ -0,0 +1,147 @@ |
| +// Copyright 2015 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/base/decoder_config_adapter.h" |
| + |
| +#include "base/logging.h" |
| +#include "media/base/channel_layout.h" |
| + |
| +namespace { |
| + |
| +// Maximum audio bytes per sample. |
| +static int kMaxBytesPerSample = 4; |
| + |
| +// Maximum audio sampling rate. |
| +static int kMaxSampleRate = 192000; |
| + |
| +} |
| + |
| +namespace chromecast { |
| +namespace media { |
| + |
| +// static |
| +Codec DecoderConfigAdapter::ToCodec(const ::media::AudioCodec audio_codec) { |
| + switch (audio_codec) { |
| + case ::media::kCodecAAC: |
| + return kCodecAAC; |
| + case ::media::kCodecMP3: |
| + return kCodecMP3; |
| + case ::media::kCodecPCM: |
| + return kCodecPCM; |
| + case ::media::kCodecPCM_S16BE: |
| + return kCodecPCM_S16BE; |
| + case ::media::kCodecVorbis: |
| + return kCodecVorbis; |
| + default: |
| + NOTREACHED(); |
|
gunsch
2015/04/17 01:38:51
NOTREACHED is generally considered fatal. Is there
erickung1
2015/04/29 08:52:20
Done. Idea is to notify that the codec is unsuppor
|
| + break; |
| + } |
| + return kUnknownCodec; |
| +} |
| + |
| +// static |
| +Codec DecoderConfigAdapter::ToCodec(const ::media::VideoCodec video_codec) { |
| + switch (video_codec) { |
| + case ::media::kCodecH264: |
| + return kCodecH264; |
| + case ::media::kCodecVP8: |
| + return kCodecVP8; |
| + case ::media::kCodecVP9: |
| + return kCodecVP9; |
| + default: |
| + NOTREACHED(); |
| + break; |
| + } |
| + return kUnknownCodec; |
| +} |
| + |
| +// static |
| +Profile DecoderConfigAdapter::ToProfile( |
| + const ::media::VideoCodecProfile codec_profile) { |
| + switch(codec_profile) { |
| + case ::media::H264PROFILE_BASELINE: |
| + return kH264Baseline; |
| + case ::media::H264PROFILE_MAIN: |
| + return kH264Main; |
| + case ::media::H264PROFILE_EXTENDED: |
| + return kH264Extended; |
| + case ::media::H264PROFILE_HIGH: |
| + return kH264High; |
| + case ::media::H264PROFILE_HIGH10PROFILE: |
| + return kH264High10; |
| + case ::media::H264PROFILE_HIGH422PROFILE: |
| + return kH264High422; |
| + case ::media::H264PROFILE_HIGH444PREDICTIVEPROFILE: |
| + return kH264High444Predictive; |
| + case ::media::H264PROFILE_SCALABLEBASELINE: |
| + return kH264ScalabBaseline; |
| + case ::media::H264PROFILE_SCALABLEHIGH: |
| + return kH264ScalableHigh; |
| + case ::media::H264PROFILE_STEREOHIGH: |
| + return kH264Stereohigh; |
| + case ::media::H264PROFILE_MULTIVIEWHIGH: |
| + return kH264MultiviewHigh; |
| + case ::media::VP8PROFILE_ANY: |
| + return kVP8ProfileAny; |
| + case ::media::VP9PROFILE_ANY: |
| + return kVP9ProfileAny; |
| + default: |
| + NOTREACHED(); |
| + } |
| + return kCodecProfileUnknown; |
| +} |
| + |
| +// static |
| +DecoderConfig DecoderConfigAdapter::ToDecoderConfig( |
| + const ::media::AudioDecoderConfig& config) { |
| + DecoderConfig decoder_config; |
| + if (!config.IsValidConfig()) { |
| + return decoder_config; |
|
gunsch
2015/04/17 02:21:26
I wonder if this would be an appropriate place to
erickung1
2015/04/29 08:52:20
The idea of this util function is to
1. convert f
|
| + } |
| + |
| + decoder_config.codec = DecoderConfigAdapter::ToCodec(config.codec()); |
| + decoder_config.profile = kCodecProfileUnknown; |
| + decoder_config.bytes_per_channel = config.bytes_per_channel(); |
| + decoder_config.channel_number = |
| + ::media::ChannelLayoutToChannelCount(config.channel_layout()), |
| + decoder_config.samples_per_second = config.samples_per_second(); |
| + decoder_config.extra_data.assign( |
| + config.extra_data(), config.extra_data() + config.extra_data_size()); |
| + decoder_config.is_encrypted = config.is_encrypted(); |
| + decoder_config.is_valid_config = |
| + decoder_config.codec >= kAudioCodecMin && |
| + decoder_config.codec <= kAudioCodecMax && |
| + decoder_config.channel_number > 0 && |
| + decoder_config.bytes_per_channel > 0 && |
| + decoder_config.bytes_per_channel <= kMaxBytesPerSample && |
| + decoder_config.samples_per_second > 0 && |
| + decoder_config.samples_per_second <= kMaxSampleRate; |
| + |
| + return decoder_config; |
| +} |
| + |
| +// static |
| +DecoderConfig DecoderConfigAdapter::ToDecoderConfig( |
| + const ::media::VideoDecoderConfig& config) { |
| + DecoderConfig decoder_config; |
| + if (!config.IsValidConfig()) { |
| + return decoder_config; |
| + } |
| + |
| + decoder_config.codec = DecoderConfigAdapter::ToCodec(config.codec()); |
| + decoder_config.profile = DecoderConfigAdapter::ToProfile(config.profile()); |
| + decoder_config.bytes_per_channel = -1; |
| + decoder_config.channel_number = -1; |
| + decoder_config.samples_per_second = -1; |
| + decoder_config.extra_data.assign( |
| + config.extra_data(), config.extra_data()+config.extra_data_size()); |
| + decoder_config.is_encrypted = config.is_encrypted(); |
| + decoder_config.is_valid_config = |
| + decoder_config.codec >= kVideoCodecMin && |
| + decoder_config.codec <= kVideoCodecMax;; |
| + return decoder_config; |
| +} |
| + |
| +} // namespace media |
| +} // namespace chromecast |