Removed unused VideoCaptureCapability parameters.
[chromium-blink-merge.git] / media / cdm / ppapi / ffmpeg_cdm_audio_decoder.h
blob6e170ad4a82addab7d19fb59e0446c32a966ce4b
1 // Copyright 2013 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_CDM_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_
6 #define MEDIA_CDM_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
14 #include "media/cdm/ppapi/api/content_decryption_module.h"
16 struct AVCodecContext;
17 struct AVFrame;
19 namespace media {
20 class AudioBus;
21 class AudioTimestampHelper;
22 class ScopedPtrAVFreeContext;
23 class ScopedPtrAVFreeFrame;
26 namespace media {
27 // TODO(xhwang): This class is partially cloned from FFmpegAudioDecoder. When
28 // FFmpegAudioDecoder is updated, it's a pain to keep this class in sync with
29 // FFmpegAudioDecoder. We need a long term sustainable solution for this. See
30 // http://crbug.com/169203
31 class FFmpegCdmAudioDecoder {
32 public:
33 explicit FFmpegCdmAudioDecoder(cdm::Host* host);
34 ~FFmpegCdmAudioDecoder();
35 bool Initialize(const cdm::AudioDecoderConfig& config);
36 void Deinitialize();
37 void Reset();
39 // Returns true when |config| is a valid audio decoder configuration.
40 static bool IsValidConfig(const cdm::AudioDecoderConfig& config);
42 // Decodes |compressed_buffer|. Returns |cdm::kSuccess| after storing
43 // output in |decoded_frames| when output is available. Returns
44 // |cdm::kNeedMoreData| when |compressed_frame| does not produce output.
45 // Returns |cdm::kDecodeError| when decoding fails.
47 // A null |compressed_buffer| will attempt to flush the decoder of any
48 // remaining frames. |compressed_buffer_size| and |timestamp| are ignored.
49 cdm::Status DecodeBuffer(const uint8_t* compressed_buffer,
50 int32_t compressed_buffer_size,
51 int64_t timestamp,
52 cdm::AudioFrames* decoded_frames);
54 private:
55 void ResetTimestampState();
56 void ReleaseFFmpegResources();
58 base::TimeDelta GetNextOutputTimestamp() const;
60 void SerializeInt64(int64_t value);
62 bool is_initialized_;
64 cdm::Host* const host_;
66 // FFmpeg structures owned by this object.
67 scoped_ptr_malloc<AVCodecContext, ScopedPtrAVFreeContext> codec_context_;
68 scoped_ptr_malloc<AVFrame, ScopedPtrAVFreeFrame> av_frame_;
70 // Audio format.
71 int samples_per_second_;
72 int channels_;
74 // AVSampleFormat initially requested; not Chrome's SampleFormat.
75 int av_sample_format_;
77 // Used for computing output timestamps.
78 scoped_ptr<AudioTimestampHelper> output_timestamp_helper_;
79 int bytes_per_frame_;
80 base::TimeDelta last_input_timestamp_;
82 // Number of output sample bytes to drop before generating output buffers.
83 // This is required for handling negative timestamps when decoding Vorbis
84 // audio, for example.
85 int output_bytes_to_drop_;
87 typedef std::vector<uint8_t> SerializedAudioFrames;
88 SerializedAudioFrames serialized_audio_frames_;
90 DISALLOW_COPY_AND_ASSIGN(FFmpegCdmAudioDecoder);
93 } // namespace media
95 #endif // MEDIA_CDM_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_