Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
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_
8 #include <vector>
10 #include "mp4_demuxer/basictypes.h"
11 #include "mp4_demuxer/channel_layout.h"
13 namespace mp4_demuxer {
15 enum AudioCodec {
16 // These values are histogrammed over time; do not change their ordinal
17 // values. When deleting a codec replace it with a dummy value; when adding a
18 // codec, do so at the bottom before kAudioCodecMax.
19 kUnknownAudioCodec = 0,
20 kCodecAAC,
21 kCodecMP3,
22 kCodecPCM,
23 kCodecVorbis,
24 kCodecFLAC,
25 kCodecAMR_NB,
26 kCodecAMR_WB,
27 kCodecPCM_MULAW,
28 kCodecGSM_MS,
29 kCodecPCM_S16BE,
30 kCodecPCM_S24BE,
31 kCodecOpus,
32 // DO NOT ADD RANDOM AUDIO CODECS!
33 //
34 // The only acceptable time to add a new codec is if there is production code
35 // that uses said codec in the same CL.
37 // Must always be last!
38 kAudioCodecMax
39 };
41 enum SampleFormat {
42 // These values are histogrammed over time; do not change their ordinal
43 // values. When deleting a sample format replace it with a dummy value; when
44 // adding a sample format, do so at the bottom before kSampleFormatMax.
45 kUnknownSampleFormat = 0,
46 kSampleFormatU8, // Unsigned 8-bit w/ bias of 128.
47 kSampleFormatS16, // Signed 16-bit.
48 kSampleFormatS32, // Signed 32-bit.
49 kSampleFormatF32, // Float 32-bit.
50 kSampleFormatPlanarS16, // Signed 16-bit planar.
51 kSampleFormatPlanarF32, // Float 32-bit planar.
53 // Must always be last!
54 kSampleFormatMax
55 };
57 // TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of
58 // |bits_per_channel|, we should switch over since bits are generally confusing
59 // to work with.
60 class AudioDecoderConfig {
61 public:
62 // Constructs an uninitialized object. Clients should call Initialize() with
63 // appropriate values before using.
64 AudioDecoderConfig();
66 // Constructs an initialized object. It is acceptable to pass in NULL for
67 // |extra_data|, otherwise the memory is copied.
68 AudioDecoderConfig(AudioCodec codec, SampleFormat sample_format,
69 ChannelLayout channel_layout, int samples_per_second,
70 const uint8_t* extra_data, size_t extra_data_size,
71 bool is_encrypted);
73 ~AudioDecoderConfig();
75 // Resets the internal state of this object.
76 void Initialize(AudioCodec codec, SampleFormat sample_format,
77 ChannelLayout channel_layout, int samples_per_second,
78 const uint8_t* extra_data, size_t extra_data_size,
79 bool is_encrypted);
81 // Returns true if this object has appropriate configuration values, false
82 // otherwise.
83 bool IsValidConfig() const;
85 // Returns true if all fields in |config| match this config.
86 // Note: The contents of |extra_data_| are compared not the raw pointers.
87 bool Matches(const AudioDecoderConfig& config) const;
89 AudioCodec codec() const { return codec_; }
90 int bits_per_channel() const { return bits_per_channel_; }
91 ChannelLayout channel_layout() const { return channel_layout_; }
92 int samples_per_second() const { return samples_per_second_; }
93 SampleFormat sample_format() const { return sample_format_; }
94 int bytes_per_frame() const { return bytes_per_frame_; }
96 // Optional byte data required to initialize audio decoders such as Vorbis
97 // codebooks.
98 const uint8_t* extra_data() const {
99 return extra_data_.empty() ? NULL : &extra_data_[0];
100 }
101 size_t extra_data_size() const { return extra_data_.size(); }
103 // Whether the audio stream is potentially encrypted.
104 // Note that in a potentially encrypted audio stream, individual buffers
105 // can be encrypted or not encrypted.
106 bool is_encrypted() const { return is_encrypted_; }
108 std::string AsHumanReadableString() const;
110 private:
111 AudioCodec codec_;
112 SampleFormat sample_format_;
113 int bits_per_channel_;
114 ChannelLayout channel_layout_;
115 int samples_per_second_;
116 int bytes_per_frame_;
117 std::vector<uint8_t> extra_data_;
118 bool is_encrypted_;
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.
123 };
125 } // namespace mp4_demuxer
127 #endif // MEDIA_BASE_AUDIO_DECODER_CONFIG_H_