Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / cdm / ppapi / external_clear_key / ffmpeg_cdm_audio_decoder.h
blobe32b227fb95ad34de5eae67886d495a0d7f023de
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_EXTERNAL_CLEAR_KEY_FFMPEG_CDM_AUDIO_DECODER_H_
6 #define MEDIA_CDM_PPAPI_EXTERNAL_CLEAR_KEY_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/external_clear_key/clear_key_cdm_common.h"
15 #include "media/ffmpeg/ffmpeg_deleters.h"
17 struct AVCodecContext;
18 struct AVFrame;
20 namespace media {
21 class AudioBus;
22 class AudioTimestampHelper;
25 namespace media {
26 // TODO(xhwang): This class is partially cloned from FFmpegAudioDecoder. When
27 // FFmpegAudioDecoder is updated, it's a pain to keep this class in sync with
28 // FFmpegAudioDecoder. We need a long term sustainable solution for this. See
29 // http://crbug.com/169203
30 class FFmpegCdmAudioDecoder {
31 public:
32 explicit FFmpegCdmAudioDecoder(ClearKeyCdmHost* host);
33 ~FFmpegCdmAudioDecoder();
34 bool Initialize(const cdm::AudioDecoderConfig& config);
35 void Deinitialize();
36 void Reset();
38 // Returns true when |config| is a valid audio decoder configuration.
39 static bool IsValidConfig(const cdm::AudioDecoderConfig& config);
41 // Decodes |compressed_buffer|. Returns |cdm::kSuccess| after storing
42 // output in |decoded_frames| when output is available. Returns
43 // |cdm::kNeedMoreData| when |compressed_frame| does not produce output.
44 // Returns |cdm::kDecodeError| when decoding fails.
46 // A null |compressed_buffer| will attempt to flush the decoder of any
47 // remaining frames. |compressed_buffer_size| and |timestamp| are ignored.
48 cdm::Status DecodeBuffer(const uint8_t* compressed_buffer,
49 int32_t compressed_buffer_size,
50 int64_t timestamp,
51 cdm::AudioFrames* decoded_frames);
53 private:
54 void ResetTimestampState();
55 void ReleaseFFmpegResources();
57 base::TimeDelta GetNextOutputTimestamp() const;
59 void SerializeInt64(int64_t value);
61 bool is_initialized_;
63 ClearKeyCdmHost* const host_;
65 // FFmpeg structures owned by this object.
66 scoped_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context_;
67 scoped_ptr<AVFrame, ScopedPtrAVFreeFrame> av_frame_;
69 // Audio format.
70 int samples_per_second_;
71 int channels_;
73 // AVSampleFormat initially requested; not Chrome's SampleFormat.
74 int av_sample_format_;
76 // Used for computing output timestamps.
77 scoped_ptr<AudioTimestampHelper> output_timestamp_helper_;
78 int bytes_per_frame_;
79 base::TimeDelta last_input_timestamp_;
81 // Number of output sample bytes to drop before generating output buffers.
82 // This is required for handling negative timestamps when decoding Vorbis
83 // audio, for example.
84 int output_bytes_to_drop_;
86 typedef std::vector<uint8_t> SerializedAudioFrames;
87 SerializedAudioFrames serialized_audio_frames_;
89 DISALLOW_COPY_AND_ASSIGN(FFmpegCdmAudioDecoder);
92 } // namespace media
94 #endif // MEDIA_CDM_PPAPI_EXTERNAL_CLEAR_KEY_FFMPEG_CDM_AUDIO_DECODER_H_