1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/base/audio_decoder_config.h"
7 #include "base/logging.h"
8 #include "media/base/limits.h"
12 AudioDecoderConfig::AudioDecoderConfig()
13 : codec_(kUnknownAudioCodec
),
14 sample_format_(kUnknownSampleFormat
),
15 bytes_per_channel_(0),
16 channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED
),
17 samples_per_second_(0),
23 AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec
,
24 SampleFormat sample_format
,
25 ChannelLayout channel_layout
,
26 int samples_per_second
,
27 const uint8
* extra_data
,
28 size_t extra_data_size
,
30 Initialize(codec
, sample_format
, channel_layout
, samples_per_second
,
31 extra_data
, extra_data_size
, is_encrypted
, base::TimeDelta(), 0);
34 void AudioDecoderConfig::Initialize(AudioCodec codec
,
35 SampleFormat sample_format
,
36 ChannelLayout channel_layout
,
37 int samples_per_second
,
38 const uint8
* extra_data
,
39 size_t extra_data_size
,
41 base::TimeDelta seek_preroll
,
43 CHECK((extra_data_size
!= 0) == (extra_data
!= NULL
));
46 channel_layout_
= channel_layout
;
47 samples_per_second_
= samples_per_second
;
48 sample_format_
= sample_format
;
49 bytes_per_channel_
= SampleFormatToBytesPerChannel(sample_format
);
50 extra_data_
.assign(extra_data
, extra_data
+ extra_data_size
);
51 is_encrypted_
= is_encrypted
;
52 seek_preroll_
= seek_preroll
;
53 codec_delay_
= codec_delay
;
55 int channels
= ChannelLayoutToChannelCount(channel_layout_
);
56 bytes_per_frame_
= channels
* bytes_per_channel_
;
59 AudioDecoderConfig::~AudioDecoderConfig() {}
61 bool AudioDecoderConfig::IsValidConfig() const {
62 return codec_
!= kUnknownAudioCodec
&&
63 channel_layout_
!= CHANNEL_LAYOUT_UNSUPPORTED
&&
64 bytes_per_channel_
> 0 &&
65 bytes_per_channel_
<= limits::kMaxBytesPerSample
&&
66 samples_per_second_
> 0 &&
67 samples_per_second_
<= limits::kMaxSampleRate
&&
68 sample_format_
!= kUnknownSampleFormat
&&
69 seek_preroll_
>= base::TimeDelta() &&
73 bool AudioDecoderConfig::Matches(const AudioDecoderConfig
& config
) const {
74 return ((codec() == config
.codec()) &&
75 (bytes_per_channel() == config
.bytes_per_channel()) &&
76 (channel_layout() == config
.channel_layout()) &&
77 (samples_per_second() == config
.samples_per_second()) &&
78 (extra_data_size() == config
.extra_data_size()) &&
79 (!extra_data() || !memcmp(extra_data(), config
.extra_data(),
80 extra_data_size())) &&
81 (is_encrypted() == config
.is_encrypted()) &&
82 (sample_format() == config
.sample_format()) &&
83 (seek_preroll() == config
.seek_preroll()) &&
84 (codec_delay() == config
.codec_delay()));
87 std::string
AudioDecoderConfig::AsHumanReadableString() const {
89 s
<< "codec: " << GetHumanReadableCodecName()
90 << " bytes_per_channel: " << bytes_per_channel()
91 << " channel_layout: " << channel_layout()
92 << " samples_per_second: " << samples_per_second()
93 << " sample_format: " << sample_format()
94 << " bytes_per_frame: " << bytes_per_frame()
95 << " seek_preroll: " << seek_preroll().InMilliseconds() << "ms"
96 << " codec_delay: " << codec_delay()
97 << " has extra data? " << (extra_data() ? "true" : "false")
98 << " encrypted? " << (is_encrypted() ? "true" : "false");
102 // These names come from src/third_party/ffmpeg/libavcodec/codec_desc.c
103 std::string
AudioDecoderConfig::GetHumanReadableCodecName() const {
105 case kUnknownAudioCodec
:
112 case kCodecPCM_S16BE
:
113 case kCodecPCM_S24BE
:
127 case kCodecPCM_MULAW
: