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 WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_
6 #define WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time.h"
13 #include "base/compiler_specific.h"
14 #include "webkit/media/crypto/ppapi/cdm/content_decryption_module.h"
16 struct AVCodecContext
;
21 class AudioTimestampHelper
;
24 namespace webkit_media
{
26 // TODO(xhwang): This class is partially cloned from media::FFmpegAudioDecoder.
27 // When media::FFmpegAudioDecoder is updated, it's a pain to keep this class
28 // in sync with media::FFmpegAudioDecoder. We need a long term sustainable
29 // solution for this. See http://crbug.com/169203
30 class FFmpegCdmAudioDecoder
{
32 explicit FFmpegCdmAudioDecoder(cdm::Host
* host
);
33 ~FFmpegCdmAudioDecoder();
34 bool Initialize(const cdm::AudioDecoderConfig
& config
);
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
,
51 cdm::AudioFrames
* decoded_frames
);
54 void ResetTimestampState();
55 void ReleaseFFmpegResources();
57 base::TimeDelta
GetNextOutputTimestamp() const;
59 void SerializeInt64(int64_t value
);
63 cdm::Host
* const host_
;
65 // FFmpeg structures owned by this object.
66 AVCodecContext
* codec_context_
;
70 int bits_per_channel_
;
71 int samples_per_second_
;
74 // AVSampleFormat initially requested; not Chrome's SampleFormat.
75 int av_sample_format_
;
77 // Used for computing output timestamps.
78 scoped_ptr
<media::AudioTimestampHelper
> output_timestamp_helper_
;
80 base::TimeDelta last_input_timestamp_
;
82 // We may need to convert the audio data coming out of FFmpeg from planar
84 scoped_ptr
<media::AudioBus
> converter_bus_
;
86 // Number of output sample bytes to drop before generating output buffers.
87 // This is required for handling negative timestamps when decoding Vorbis
88 // audio, for example.
89 int output_bytes_to_drop_
;
91 typedef std::vector
<uint8_t> SerializedAudioFrames
;
92 SerializedAudioFrames serialized_audio_frames_
;
94 DISALLOW_COPY_AND_ASSIGN(FFmpegCdmAudioDecoder
);
97 } // namespace webkit_media
99 #endif // WEBKIT_MEDIA_CRYPTO_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_