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

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

Issue 9325044: Remove AudioDecoder from the Filter heirarchy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved audio_decoder_ out of Pipeline; AudioRendererBase is in charge of it now. Created 8 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 | Annotate | Revision Log
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 #include "media/filters/ffmpeg_audio_decoder.h" 5 #include "media/filters/ffmpeg_audio_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "media/base/audio_decoder.h"
scherkus (not reviewing) 2012/02/06 21:04:04 this is in .h
Ami GONE FROM CHROMIUM 2012/02/06 21:38:48 Done.
8 #include "media/base/audio_decoder_config.h" 9 #include "media/base/audio_decoder_config.h"
9 #include "media/base/data_buffer.h" 10 #include "media/base/data_buffer.h"
10 #include "media/base/demuxer.h" 11 #include "media/base/demuxer.h"
11 #include "media/base/filter_host.h"
12 #include "media/base/pipeline.h" 12 #include "media/base/pipeline.h"
13 #include "media/ffmpeg/ffmpeg_common.h" 13 #include "media/ffmpeg/ffmpeg_common.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 // Returns true if the decode result was an error. 17 // Returns true if the decode result was an error.
18 static bool IsErrorResult(int result, int decoded_size) { 18 static bool IsErrorResult(int result, int decoded_size) {
19 return result < 0 || 19 return result < 0 ||
20 decoded_size < 0 || 20 decoded_size < 0 ||
21 decoded_size > AVCODEC_MAX_AUDIO_FRAME_SIZE; 21 decoded_size > AVCODEC_MAX_AUDIO_FRAME_SIZE;
(...skipping 30 matching lines...) Expand all
52 bits_per_channel_(0), 52 bits_per_channel_(0),
53 channel_layout_(CHANNEL_LAYOUT_NONE), 53 channel_layout_(CHANNEL_LAYOUT_NONE),
54 samples_per_second_(0), 54 samples_per_second_(0),
55 decoded_audio_size_(AVCODEC_MAX_AUDIO_FRAME_SIZE), 55 decoded_audio_size_(AVCODEC_MAX_AUDIO_FRAME_SIZE),
56 decoded_audio_(static_cast<uint8*>(av_malloc(decoded_audio_size_))) { 56 decoded_audio_(static_cast<uint8*>(av_malloc(decoded_audio_size_))) {
57 } 57 }
58 58
59 FFmpegAudioDecoder::~FFmpegAudioDecoder() { 59 FFmpegAudioDecoder::~FFmpegAudioDecoder() {
60 av_free(decoded_audio_); 60 av_free(decoded_audio_);
61 61
62 // XXX: should we require Stop() to be called? this might end up getting 62 // TODO(scherkus): should we require Stop() to be called? this might end up
63 // called on a random thread due to refcounting. 63 // getting called on a random thread due to refcounting.
64 if (codec_context_) { 64 if (codec_context_) {
65 av_free(codec_context_->extradata); 65 av_free(codec_context_->extradata);
66 avcodec_close(codec_context_); 66 avcodec_close(codec_context_);
67 av_free(codec_context_); 67 av_free(codec_context_);
68 } 68 }
69 } 69 }
70 70
71 void FFmpegAudioDecoder::Flush(const base::Closure& callback) {
72 message_loop_->PostTask(
73 FROM_HERE,
74 base::Bind(&FFmpegAudioDecoder::DoFlush, this, callback));
75 }
76
77 void FFmpegAudioDecoder::Initialize( 71 void FFmpegAudioDecoder::Initialize(
78 DemuxerStream* stream, 72 const scoped_refptr<DemuxerStream> stream,
79 const PipelineStatusCB& callback, 73 const PipelineStatusCB& callback,
80 const StatisticsCallback& stats_callback) { 74 const StatisticsCallback& stats_callback) {
81 // TODO(scherkus): change Initialize() signature to pass |stream| as a
82 // scoped_refptr<>.
83 scoped_refptr<DemuxerStream> ref_stream(stream);
84 message_loop_->PostTask( 75 message_loop_->PostTask(
85 FROM_HERE, 76 FROM_HERE,
86 base::Bind(&FFmpegAudioDecoder::DoInitialize, this, 77 base::Bind(&FFmpegAudioDecoder::DoInitialize, this,
87 ref_stream, callback, stats_callback)); 78 stream, callback, stats_callback));
88 } 79 }
89 80
90 void FFmpegAudioDecoder::Read(const ReadCB& callback) { 81 void FFmpegAudioDecoder::Read(const ReadCB& callback) {
91 // Complete operation asynchronously on different stack of execution as per 82 // Complete operation asynchronously on different stack of execution as per
92 // the API contract of AudioDecoder::Read() 83 // the API contract of AudioDecoder::Read()
93 message_loop_->PostTask(FROM_HERE, base::Bind( 84 message_loop_->PostTask(FROM_HERE, base::Bind(
94 &FFmpegAudioDecoder::DoRead, this, callback)); 85 &FFmpegAudioDecoder::DoRead, this, callback));
95 } 86 }
96 87
97 int FFmpegAudioDecoder::bits_per_channel() { 88 int FFmpegAudioDecoder::bits_per_channel() {
98 return bits_per_channel_; 89 return bits_per_channel_;
99 } 90 }
100 91
101 ChannelLayout FFmpegAudioDecoder::channel_layout() { 92 ChannelLayout FFmpegAudioDecoder::channel_layout() {
102 return channel_layout_; 93 return channel_layout_;
103 } 94 }
104 95
105 int FFmpegAudioDecoder::samples_per_second() { 96 int FFmpegAudioDecoder::samples_per_second() {
106 return samples_per_second_; 97 return samples_per_second_;
107 } 98 }
108 99
100 void FFmpegAudioDecoder::Reset(const base::Closure& closure) {
101 message_loop_->PostTask(FROM_HERE, base::Bind(
102 &FFmpegAudioDecoder::DoReset, this, closure));
103 }
104
109 void FFmpegAudioDecoder::DoInitialize( 105 void FFmpegAudioDecoder::DoInitialize(
110 const scoped_refptr<DemuxerStream>& stream, 106 const scoped_refptr<DemuxerStream>& stream,
111 const PipelineStatusCB& callback, 107 const PipelineStatusCB& callback,
112 const StatisticsCallback& stats_callback) { 108 const StatisticsCallback& stats_callback) {
113 demuxer_stream_ = stream; 109 demuxer_stream_ = stream;
114 const AudioDecoderConfig& config = stream->audio_decoder_config(); 110 const AudioDecoderConfig& config = stream->audio_decoder_config();
115 stats_callback_ = stats_callback; 111 stats_callback_ = stats_callback;
116 112
117 // TODO(scherkus): this check should go in Pipeline prior to creating 113 // TODO(scherkus): this check should go in Pipeline prior to creating
118 // decoder objects. 114 // decoder objects.
(...skipping 22 matching lines...) Expand all
141 } 137 }
142 138
143 // Success! 139 // Success!
144 bits_per_channel_ = config.bits_per_channel(); 140 bits_per_channel_ = config.bits_per_channel();
145 channel_layout_ = config.channel_layout(); 141 channel_layout_ = config.channel_layout();
146 samples_per_second_ = config.samples_per_second(); 142 samples_per_second_ = config.samples_per_second();
147 143
148 callback.Run(PIPELINE_OK); 144 callback.Run(PIPELINE_OK);
149 } 145 }
150 146
151 void FFmpegAudioDecoder::DoFlush(const base::Closure& callback) { 147 void FFmpegAudioDecoder::DoReset(const base::Closure& closure) {
152 avcodec_flush_buffers(codec_context_); 148 avcodec_flush_buffers(codec_context_);
153 estimated_next_timestamp_ = kNoTimestamp(); 149 estimated_next_timestamp_ = kNoTimestamp();
154 callback.Run(); 150 closure.Run();
155 } 151 }
156 152
157 void FFmpegAudioDecoder::DoRead(const ReadCB& callback) { 153 void FFmpegAudioDecoder::DoRead(const ReadCB& callback) {
158 DCHECK_EQ(MessageLoop::current(), message_loop_); 154 DCHECK_EQ(MessageLoop::current(), message_loop_);
159 DCHECK(!callback.is_null()); 155 DCHECK(!callback.is_null());
160 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; 156 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported.";
161 157
162 read_cb_ = callback; 158 read_cb_ = callback;
163 ReadFromDemuxerStream(); 159 ReadFromDemuxerStream();
164 } 160 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 285 }
290 286
291 void FFmpegAudioDecoder::DeliverSamples(const scoped_refptr<Buffer>& samples) { 287 void FFmpegAudioDecoder::DeliverSamples(const scoped_refptr<Buffer>& samples) {
292 // Reset the callback before running to protect against reentrancy. 288 // Reset the callback before running to protect against reentrancy.
293 ReadCB read_cb = read_cb_; 289 ReadCB read_cb = read_cb_;
294 read_cb_.Reset(); 290 read_cb_.Reset();
295 read_cb.Run(samples); 291 read_cb.Run(samples);
296 } 292 }
297 293
298 } // namespace media 294 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698