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_
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
;
21 class AudioTimestampHelper
;
22 class ScopedPtrAVFreeContext
;
23 class ScopedPtrAVFreeFrame
;
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
{
33 explicit FFmpegCdmAudioDecoder(cdm::Host
* host
);
34 ~FFmpegCdmAudioDecoder();
35 bool Initialize(const cdm::AudioDecoderConfig
& config
);
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
,
52 cdm::AudioFrames
* decoded_frames
);
55 void ResetTimestampState();
56 void ReleaseFFmpegResources();
58 base::TimeDelta
GetNextOutputTimestamp() const;
60 void SerializeInt64(int64_t value
);
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_
;
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
<AudioTimestampHelper
> output_timestamp_helper_
;
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
);
95 #endif // MEDIA_CDM_PPAPI_FFMPEG_CDM_AUDIO_DECODER_H_