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 27 matching lines...) Expand all Loading... |
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, |
41 const OutputCB& output_cb) OVERRIDE; | 41 const OutputCB& output_cb) OVERRIDE; |
42 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 42 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
43 const DecodeCB& decode_cb) OVERRIDE; | 43 const DecodeCB& decode_cb) 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 // There are four states the decoder can be in: |
| 49 // |
| 50 // - kUninitialized: The decoder is not initialized. |
| 51 // - kNormal: This is the normal state. The decoder is idle and ready to |
| 52 // decode input buffers, or is decoding an input buffer. |
| 53 // - kDecodeFinished: EOS buffer received, codec flushed and decode finished. |
| 54 // No further Decode() call should be made. |
| 55 // - kError: Unexpected error happened. |
| 56 // |
| 57 // These are the possible state transitions. |
| 58 // |
| 59 // kUninitialized -> kNormal: |
| 60 // The decoder is successfully initialized and is ready to decode buffers. |
| 61 // kNormal -> kDecodeFinished: |
| 62 // When buffer->end_of_stream() is true and avcodec_decode_audio4() |
| 63 // returns 0 data. |
| 64 // kNormal -> kError: |
| 65 // A decoding error occurs and decoding needs to stop. |
| 66 // (any state) -> kNormal: |
| 67 // Any time Reset() is called. |
48 enum DecoderState { | 68 enum DecoderState { |
49 kUninitialized, | 69 kUninitialized, |
50 kNormal, | 70 kNormal, |
51 kDecodeFinished, | 71 kDecodeFinished, |
52 kError | 72 kError |
53 }; | 73 }; |
54 | 74 |
55 // Reset decoder and call |reset_cb_|. | 75 // Reset decoder and call |reset_cb_|. |
56 void DoReset(); | 76 void DoReset(); |
57 | 77 |
58 // Handles decoding an unencrypted encoded buffer. | 78 // Handles decoding an unencrypted encoded buffer. |
59 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer, | 79 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer, |
60 const DecodeCB& decode_cb); | 80 const DecodeCB& decode_cb); |
61 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer); | 81 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer, |
| 82 bool* has_produced_frame); |
62 | 83 |
63 // Handles (re-)initializing the decoder with a (new) config. | 84 // Handles (re-)initializing the decoder with a (new) config. |
64 // Returns true if initialization was successful. | 85 // Returns true if initialization was successful. |
65 bool ConfigureDecoder(); | 86 bool ConfigureDecoder(); |
66 | 87 |
67 // Releases resources associated with |codec_context_| and |av_frame_| | 88 // Releases resources associated with |codec_context_| and |av_frame_| |
68 // and resets them to NULL. | 89 // and resets them to NULL. |
69 void ReleaseFFmpegResources(); | 90 void ReleaseFFmpegResources(); |
70 void ResetTimestampState(); | 91 void ResetTimestampState(); |
71 | 92 |
(...skipping 15 matching lines...) Expand all Loading... |
87 scoped_ptr<AudioDiscardHelper> discard_helper_; | 108 scoped_ptr<AudioDiscardHelper> discard_helper_; |
88 | 109 |
89 LogCB log_cb_; | 110 LogCB log_cb_; |
90 | 111 |
91 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); | 112 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); |
92 }; | 113 }; |
93 | 114 |
94 } // namespace media | 115 } // namespace media |
95 | 116 |
96 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 117 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
OLD | NEW |