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 MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_
6 #define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "media/base/audio_decoder.h"
14 #include "media/base/demuxer_stream.h"
15 #include "media/base/sample_format.h"
16 #include "media/ffmpeg/ffmpeg_deleters.h"
18 struct AVCodecContext
;
22 class SingleThreadTaskRunner
;
27 class AudioDiscardHelper
;
30 class MEDIA_EXPORT FFmpegAudioDecoder
: public AudioDecoder
{
32 explicit FFmpegAudioDecoder(
33 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
);
34 virtual ~FFmpegAudioDecoder();
36 // AudioDecoder implementation.
37 virtual void Initialize(const AudioDecoderConfig
& config
,
38 const PipelineStatusCB
& status_cb
) OVERRIDE
;
39 virtual void Decode(const scoped_refptr
<DecoderBuffer
>& buffer
,
40 const DecodeCB
& decode_cb
) OVERRIDE
;
41 virtual scoped_refptr
<AudioBuffer
> GetDecodeOutput() OVERRIDE
;
42 virtual void Reset(const base::Closure
& closure
) OVERRIDE
;
43 virtual void Stop() OVERRIDE
;
54 // Reset decoder and call |reset_cb_|.
57 // Handles decoding an unencrypted encoded buffer.
58 void DecodeBuffer(const scoped_refptr
<DecoderBuffer
>& buffer
,
59 const DecodeCB
& decode_cb
);
60 bool FFmpegDecode(const scoped_refptr
<DecoderBuffer
>& buffer
);
62 // Handles (re-)initializing the decoder with a (new) config.
63 // Returns true if initialization was successful.
64 bool ConfigureDecoder();
66 // Releases resources associated with |codec_context_| and |av_frame_|
67 // and resets them to NULL.
68 void ReleaseFFmpegResources();
69 void ResetTimestampState();
71 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
75 // FFmpeg structures owned by this object.
76 scoped_ptr
<AVCodecContext
, ScopedPtrAVFreeContext
> codec_context_
;
77 scoped_ptr
<AVFrame
, ScopedPtrAVFreeFrame
> av_frame_
;
79 AudioDecoderConfig config_
;
81 // AVSampleFormat initially requested; not Chrome's SampleFormat.
82 int av_sample_format_
;
84 scoped_ptr
<AudioDiscardHelper
> discard_helper_
;
86 // Since multiple frames may be decoded from the same packet we need to queue
88 std::list
<scoped_refptr
<AudioBuffer
> > queued_audio_
;
90 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder
);
95 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_