OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 5 #ifndef MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
6 #define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 6 #define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { | 31 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { |
32 public: | 32 public: |
33 FFmpegAudioDecoder( | 33 FFmpegAudioDecoder( |
34 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 34 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
35 const LogCB& log_cb); | 35 const LogCB& log_cb); |
36 virtual ~FFmpegAudioDecoder(); | 36 virtual ~FFmpegAudioDecoder(); |
37 | 37 |
38 // AudioDecoder implementation. | 38 // AudioDecoder implementation. |
39 virtual void Initialize(const AudioDecoderConfig& config, | 39 virtual void Initialize(const AudioDecoderConfig& config, |
40 const PipelineStatusCB& status_cb, | 40 const PipelineStatusCB& status_cb) OVERRIDE; |
41 const OutputCB& output_cb) OVERRIDE; | |
42 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 41 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
43 const DecodeCB& decode_cb) OVERRIDE; | 42 const DecodeCB& decode_cb) OVERRIDE; |
| 43 virtual scoped_refptr<AudioBuffer> GetDecodeOutput() OVERRIDE; |
44 virtual void Reset(const base::Closure& closure) OVERRIDE; | 44 virtual void Reset(const base::Closure& closure) OVERRIDE; |
45 virtual void Stop() OVERRIDE; | 45 virtual void Stop() OVERRIDE; |
46 | 46 |
47 private: | 47 private: |
48 enum DecoderState { | 48 enum DecoderState { |
49 kUninitialized, | 49 kUninitialized, |
50 kNormal, | 50 kNormal, |
| 51 kFlushCodec, |
51 kDecodeFinished, | 52 kDecodeFinished, |
52 kError | 53 kError |
53 }; | 54 }; |
54 | 55 |
55 // Reset decoder and call |reset_cb_|. | 56 // Reset decoder and call |reset_cb_|. |
56 void DoReset(); | 57 void DoReset(); |
57 | 58 |
58 // Handles decoding an unencrypted encoded buffer. | 59 // Handles decoding an unencrypted encoded buffer. |
59 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer, | 60 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer, |
60 const DecodeCB& decode_cb); | 61 const DecodeCB& decode_cb); |
61 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer); | 62 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer); |
62 | 63 |
63 // Handles (re-)initializing the decoder with a (new) config. | 64 // Handles (re-)initializing the decoder with a (new) config. |
64 // Returns true if initialization was successful. | 65 // Returns true if initialization was successful. |
65 bool ConfigureDecoder(); | 66 bool ConfigureDecoder(); |
66 | 67 |
67 // Releases resources associated with |codec_context_| and |av_frame_| | 68 // Releases resources associated with |codec_context_| and |av_frame_| |
68 // and resets them to NULL. | 69 // and resets them to NULL. |
69 void ReleaseFFmpegResources(); | 70 void ReleaseFFmpegResources(); |
70 void ResetTimestampState(); | 71 void ResetTimestampState(); |
71 | 72 |
72 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 73 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
73 | 74 |
74 OutputCB output_cb_; | |
75 | |
76 DecoderState state_; | 75 DecoderState state_; |
77 | 76 |
78 // FFmpeg structures owned by this object. | 77 // FFmpeg structures owned by this object. |
79 scoped_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context_; | 78 scoped_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context_; |
80 scoped_ptr<AVFrame, ScopedPtrAVFreeFrame> av_frame_; | 79 scoped_ptr<AVFrame, ScopedPtrAVFreeFrame> av_frame_; |
81 | 80 |
82 AudioDecoderConfig config_; | 81 AudioDecoderConfig config_; |
83 | 82 |
84 // AVSampleFormat initially requested; not Chrome's SampleFormat. | 83 // AVSampleFormat initially requested; not Chrome's SampleFormat. |
85 int av_sample_format_; | 84 int av_sample_format_; |
86 | 85 |
87 scoped_ptr<AudioDiscardHelper> discard_helper_; | 86 scoped_ptr<AudioDiscardHelper> discard_helper_; |
88 | 87 |
| 88 // Since multiple frames may be decoded from the same packet we need to queue |
| 89 // them up. |
| 90 std::list<scoped_refptr<AudioBuffer> > queued_audio_; |
| 91 |
89 LogCB log_cb_; | 92 LogCB log_cb_; |
90 | 93 |
91 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); | 94 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); |
92 }; | 95 }; |
93 | 96 |
94 } // namespace media | 97 } // namespace media |
95 | 98 |
96 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 99 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
OLD | NEW |