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 #ifndef MEDIA_BASE_AUDIO_DECODER_CONFIG_H_
6 #define MEDIA_BASE_AUDIO_DECODER_CONFIG_H_
10 #include "base/basictypes.h"
11 #include "base/time/time.h"
12 #include "media/base/channel_layout.h"
13 #include "media/base/media_export.h"
14 #include "media/base/sample_format.h"
19 // These values are histogrammed over time; do not change their ordinal
20 // values. When deleting a codec replace it with a dummy value; when adding a
21 // codec, do so at the bottom before kAudioCodecMax.
22 kUnknownAudioCodec
= 0,
36 // DO NOT ADD RANDOM AUDIO CODECS!
38 // The only acceptable time to add a new codec is if there is production code
39 // that uses said codec in the same CL.
41 // Must always be last!
45 // TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of
46 // |bits_per_channel|, we should switch over since bits are generally confusing
48 class MEDIA_EXPORT AudioDecoderConfig
{
50 // Constructs an uninitialized object. Clients should call Initialize() with
51 // appropriate values before using.
54 // Constructs an initialized object. It is acceptable to pass in NULL for
55 // |extra_data|, otherwise the memory is copied.
56 AudioDecoderConfig(AudioCodec codec
, SampleFormat sample_format
,
57 ChannelLayout channel_layout
, int samples_per_second
,
58 const uint8
* extra_data
, size_t extra_data_size
,
61 ~AudioDecoderConfig();
63 // Resets the internal state of this object.
64 void Initialize(AudioCodec codec
, SampleFormat sample_format
,
65 ChannelLayout channel_layout
, int samples_per_second
,
66 const uint8
* extra_data
, size_t extra_data_size
,
67 bool is_encrypted
, bool record_stats
,
68 base::TimeDelta seek_preroll
,
69 base::TimeDelta codec_delay
);
71 // Returns true if this object has appropriate configuration values, false
73 bool IsValidConfig() const;
75 // Returns true if all fields in |config| match this config.
76 // Note: The contents of |extra_data_| are compared not the raw pointers.
77 bool Matches(const AudioDecoderConfig
& config
) const;
79 AudioCodec
codec() const { return codec_
; }
80 int bits_per_channel() const { return bytes_per_channel_
* 8; }
81 int bytes_per_channel() const { return bytes_per_channel_
; }
82 ChannelLayout
channel_layout() const { return channel_layout_
; }
83 int samples_per_second() const { return samples_per_second_
; }
84 SampleFormat
sample_format() const { return sample_format_
; }
85 int bytes_per_frame() const { return bytes_per_frame_
; }
86 base::TimeDelta
seek_preroll() const { return seek_preroll_
; }
87 base::TimeDelta
codec_delay() const { return codec_delay_
; }
89 // Optional byte data required to initialize audio decoders such as Vorbis
91 const uint8
* extra_data() const {
92 return extra_data_
.empty() ? NULL
: &extra_data_
[0];
94 size_t extra_data_size() const { return extra_data_
.size(); }
96 // Whether the audio stream is potentially encrypted.
97 // Note that in a potentially encrypted audio stream, individual buffers
98 // can be encrypted or not encrypted.
99 bool is_encrypted() const { return is_encrypted_
; }
103 SampleFormat sample_format_
;
104 int bytes_per_channel_
;
105 ChannelLayout channel_layout_
;
106 int samples_per_second_
;
107 int bytes_per_frame_
;
108 std::vector
<uint8
> extra_data_
;
111 // |seek_preroll_| is the duration of the data that the decoder must decode
112 // before the decoded data is valid.
113 base::TimeDelta seek_preroll_
;
115 // |codec_delay_| is the overall delay overhead added by the codec while
116 // encoding. This value should be subtracted from each block's timestamp to
117 // get the actual timestamp.
118 base::TimeDelta codec_delay_
;
120 // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
121 // generated copy constructor and assignment operator. Since the extra data is
122 // typically small, the performance impact is minimal.
127 #endif // MEDIA_BASE_AUDIO_DECODER_CONFIG_H_