• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef MEDIA_BASE_AUDIO_DECODER_CONFIG_H_
6 #define MEDIA_BASE_AUDIO_DECODER_CONFIG_H_
7 
8 #include <vector>
9 
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"
15 
16 namespace media {
17 
18 enum AudioCodec {
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,
23   kCodecAAC,
24   kCodecMP3,
25   kCodecPCM,
26   kCodecVorbis,
27   kCodecFLAC,
28   kCodecAMR_NB,
29   kCodecAMR_WB,
30   kCodecPCM_MULAW,
31   kCodecGSM_MS,
32   kCodecPCM_S16BE,
33   kCodecPCM_S24BE,
34   kCodecOpus,
35   kCodecEAC3,
36   kCodecPCM_ALAW,
37   // DO NOT ADD RANDOM AUDIO CODECS!
38   //
39   // The only acceptable time to add a new codec is if there is production code
40   // that uses said codec in the same CL.
41 
42   // Must always be last!
43   kAudioCodecMax
44 };
45 
46 // TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of
47 // |bits_per_channel|, we should switch over since bits are generally confusing
48 // to work with.
49 class MEDIA_EXPORT AudioDecoderConfig {
50  public:
51   // Constructs an uninitialized object. Clients should call Initialize() with
52   // appropriate values before using.
53   AudioDecoderConfig();
54 
55   // Constructs an initialized object. It is acceptable to pass in NULL for
56   // |extra_data|, otherwise the memory is copied.
57   AudioDecoderConfig(AudioCodec codec, SampleFormat sample_format,
58                      ChannelLayout channel_layout, int samples_per_second,
59                      const uint8* extra_data, size_t extra_data_size,
60                      bool is_encrypted);
61 
62   ~AudioDecoderConfig();
63 
64   // Resets the internal state of this object.
65   void Initialize(AudioCodec codec, SampleFormat sample_format,
66                   ChannelLayout channel_layout, int samples_per_second,
67                   const uint8* extra_data, size_t extra_data_size,
68                   bool is_encrypted, bool record_stats,
69                   base::TimeDelta seek_preroll,
70                   base::TimeDelta codec_delay);
71 
72   // Returns true if this object has appropriate configuration values, false
73   // otherwise.
74   bool IsValidConfig() const;
75 
76   // Returns true if all fields in |config| match this config.
77   // Note: The contents of |extra_data_| are compared not the raw pointers.
78   bool Matches(const AudioDecoderConfig& config) const;
79 
codec()80   AudioCodec codec() const { return codec_; }
bits_per_channel()81   int bits_per_channel() const { return bytes_per_channel_ * 8; }
bytes_per_channel()82   int bytes_per_channel() const { return bytes_per_channel_; }
channel_layout()83   ChannelLayout channel_layout() const { return channel_layout_; }
samples_per_second()84   int samples_per_second() const { return samples_per_second_; }
sample_format()85   SampleFormat sample_format() const { return sample_format_; }
bytes_per_frame()86   int bytes_per_frame() const { return bytes_per_frame_; }
seek_preroll()87   base::TimeDelta seek_preroll() const { return seek_preroll_; }
codec_delay()88   base::TimeDelta codec_delay() const { return codec_delay_; }
89 
90   // Optional byte data required to initialize audio decoders such as Vorbis
91   // codebooks.
extra_data()92   const uint8* extra_data() const {
93     return extra_data_.empty() ? NULL : &extra_data_[0];
94   }
extra_data_size()95   size_t extra_data_size() const { return extra_data_.size(); }
96 
97   // Whether the audio stream is potentially encrypted.
98   // Note that in a potentially encrypted audio stream, individual buffers
99   // can be encrypted or not encrypted.
is_encrypted()100   bool is_encrypted() const { return is_encrypted_; }
101 
102  private:
103   AudioCodec codec_;
104   SampleFormat sample_format_;
105   int bytes_per_channel_;
106   ChannelLayout channel_layout_;
107   int samples_per_second_;
108   int bytes_per_frame_;
109   std::vector<uint8> extra_data_;
110   bool is_encrypted_;
111 
112   // |seek_preroll_| is the duration of the data that the decoder must decode
113   // before the decoded data is valid.
114   base::TimeDelta seek_preroll_;
115 
116   // |codec_delay_| is the overall delay overhead added by the codec while
117   // encoding. This value should be subtracted from each block's timestamp to
118   // get the actual timestamp.
119   base::TimeDelta codec_delay_;
120 
121   // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
122   // generated copy constructor and assignment operator. Since the extra data is
123   // typically small, the performance impact is minimal.
124 };
125 
126 }  // namespace media
127 
128 #endif  // MEDIA_BASE_AUDIO_DECODER_CONFIG_H_
129