Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1283)

Side by Side Diff: media/filters/ffmpeg_audio_decoder.h

Issue 141243003: Add AudioBufferStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@decoderstream_rebased
Patch Set: add TODOs Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
30 class ScopedPtrAVFreeContext; 30 class ScopedPtrAVFreeContext;
31 class ScopedPtrAVFreeFrame; 31 class ScopedPtrAVFreeFrame;
32 32
33 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { 33 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder {
34 public: 34 public:
35 explicit FFmpegAudioDecoder( 35 explicit FFmpegAudioDecoder(
36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); 36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
37 virtual ~FFmpegAudioDecoder(); 37 virtual ~FFmpegAudioDecoder();
38 38
39 // AudioDecoder implementation. 39 // AudioDecoder implementation.
40 virtual void Initialize(DemuxerStream* stream, 40 virtual void Initialize(const AudioDecoderConfig& config,
41 const PipelineStatusCB& status_cb, 41 const PipelineStatusCB& status_cb) OVERRIDE;
42 const StatisticsCB& statistics_cb) OVERRIDE; 42 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer,
43 virtual void Read(const ReadCB& read_cb) OVERRIDE; 43 const DecodeCB& decode_cb) OVERRIDE;
44 virtual int bits_per_channel() OVERRIDE; 44 virtual int bits_per_channel() OVERRIDE;
45 virtual ChannelLayout channel_layout() OVERRIDE; 45 virtual ChannelLayout channel_layout() OVERRIDE;
46 virtual int samples_per_second() OVERRIDE; 46 virtual int samples_per_second() OVERRIDE;
47 virtual void Reset(const base::Closure& closure) OVERRIDE; 47 virtual void Reset(const base::Closure& closure) OVERRIDE;
48 virtual void Stop(const base::Closure& closure) OVERRIDE; 48 virtual void Stop(const base::Closure& closure) OVERRIDE;
49 virtual bool HasQueuedData() const OVERRIDE;
49 50
50 // Callback called from within FFmpeg to allocate a buffer based on 51 // Callback called from within FFmpeg to allocate a buffer based on
51 // the dimensions of |codec_context|. See AVCodecContext.get_buffer2 52 // the dimensions of |codec_context|. See AVCodecContext.get_buffer2
52 // documentation inside FFmpeg. 53 // documentation inside FFmpeg.
53 int GetAudioBuffer(AVCodecContext* codec, AVFrame* frame, int flags); 54 int GetAudioBuffer(AVCodecContext* codec, AVFrame* frame, int flags);
54 55
55 private: 56 private:
56 void DoStop(); 57
58 enum DecoderState {
59 kUninitialized,
60 kNormal,
61 kFlushCodec,
62 kDecodeFinished,
63 kError
64 };
65
66 // Reset decoder and call |reset_cb_|.
57 void DoReset(); 67 void DoReset();
58 68
59 // Reads from the demuxer stream with corresponding callback method. 69 // Handles decoding an unencrypted encoded buffer.
60 void ReadFromDemuxerStream(); 70 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer);
61 void BufferReady(DemuxerStream::Status status, 71 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer);
62 const scoped_refptr<DecoderBuffer>& input);
63 72
73 // Handles (re-)initializing the decoder with a (new) config.
74 // Returns true if initialization was successful.
64 bool ConfigureDecoder(); 75 bool ConfigureDecoder();
76
77 // Releases resources associated with |codec_context_| and |av_frame_|
78 // and resets them to NULL.
65 void ReleaseFFmpegResources(); 79 void ReleaseFFmpegResources();
66 void ResetTimestampState(); 80 void ResetTimestampState();
67 void RunDecodeLoop(const scoped_refptr<DecoderBuffer>& input,
68 bool skip_eos_append);
69 81
70 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 82 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
71 base::WeakPtrFactory<FFmpegAudioDecoder> weak_factory_; 83 base::WeakPtrFactory<FFmpegAudioDecoder> weak_factory_;
72 base::WeakPtr<FFmpegAudioDecoder> weak_this_; 84 base::WeakPtr<FFmpegAudioDecoder> weak_this_;
73 85
74 DemuxerStream* demuxer_stream_; 86 DecoderState state_;
75 StatisticsCB statistics_cb_; 87
88 DecodeCB decode_cb_;
89 base::Closure reset_cb_;
90
91 // FFmpeg structures owned by this object.
76 scoped_ptr_malloc<AVCodecContext, ScopedPtrAVFreeContext> codec_context_; 92 scoped_ptr_malloc<AVCodecContext, ScopedPtrAVFreeContext> codec_context_;
93 scoped_ptr_malloc<AVFrame, ScopedPtrAVFreeFrame> av_frame_;
77 94
78 // Decoded audio format. 95 // Decoded audio format.
79 int bytes_per_channel_; 96 int bytes_per_channel_;
80 ChannelLayout channel_layout_; 97 ChannelLayout channel_layout_;
81 int channels_; 98 int channels_;
82 int samples_per_second_; 99 int samples_per_second_;
83 100
84 // AVSampleFormat initially requested; not Chrome's SampleFormat. 101 // AVSampleFormat initially requested; not Chrome's SampleFormat.
85 int av_sample_format_; 102 int av_sample_format_;
86 SampleFormat sample_format_; 103 SampleFormat sample_format_;
87 104
105
106 AudioDecoderConfig config_;
107
88 // Used for computing output timestamps. 108 // Used for computing output timestamps.
89 scoped_ptr<AudioTimestampHelper> output_timestamp_helper_; 109 scoped_ptr<AudioTimestampHelper> output_timestamp_helper_;
90 base::TimeDelta last_input_timestamp_; 110 base::TimeDelta last_input_timestamp_;
91 111
92 // Number of frames to drop before generating output buffers. 112 // Number of frames to drop before generating output buffers.
93 int output_frames_to_drop_; 113 int output_frames_to_drop_;
94 114
95 // Holds decoded audio.
96 scoped_ptr_malloc<AVFrame, ScopedPtrAVFreeFrame> av_frame_;
97
98 ReadCB read_cb_;
99 base::Closure stop_cb_;
100 base::Closure reset_cb_;
101
102 // Since multiple frames may be decoded from the same packet we need to queue 115 // Since multiple frames may be decoded from the same packet we need to queue
103 // them up and hand them out as we receive Read() calls. 116 // them up and hand them out as we receive Read() calls.
104 std::list<QueuedAudioBuffer> queued_audio_; 117 std::list<QueuedAudioBuffer> queued_audio_;
105 118
106 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); 119 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder);
107 }; 120 };
108 121
109 } // namespace media 122 } // namespace media
110 123
111 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ 124 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698