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

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

Issue 10447035: Introducing DecoderBuffer and general Buffer cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Buffer Bonanza! Created 8 years, 6 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_config.h" 8 #include "media/base/audio_decoder_config.h"
9 #include "media/base/data_buffer.h" 9 #include "media/base/data_buffer.h"
10 #include "media/base/decoder_buffer.h"
10 #include "media/base/demuxer.h" 11 #include "media/base/demuxer.h"
11 #include "media/base/pipeline.h" 12 #include "media/base/pipeline.h"
12 #include "media/ffmpeg/ffmpeg_common.h" 13 #include "media/ffmpeg/ffmpeg_common.h"
13 14
14 namespace media { 15 namespace media {
15 16
16 // Returns true if the decode result was an error. 17 // Returns true if the decode result was an error.
17 static bool IsErrorResult(int result, int decoded_size) { 18 static bool IsErrorResult(int result, int decoded_size) {
18 return result < 0 || 19 return result < 0 ||
19 decoded_size < 0 || 20 decoded_size < 0 ||
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 162
162 void FFmpegAudioDecoder::DoRead(const ReadCB& read_cb) { 163 void FFmpegAudioDecoder::DoRead(const ReadCB& read_cb) {
163 DCHECK_EQ(MessageLoop::current(), message_loop_); 164 DCHECK_EQ(MessageLoop::current(), message_loop_);
164 DCHECK(!read_cb.is_null()); 165 DCHECK(!read_cb.is_null());
165 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; 166 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported.";
166 167
167 read_cb_ = read_cb; 168 read_cb_ = read_cb;
168 ReadFromDemuxerStream(); 169 ReadFromDemuxerStream();
169 } 170 }
170 171
171 void FFmpegAudioDecoder::DoDecodeBuffer(const scoped_refptr<Buffer>& input) { 172 void FFmpegAudioDecoder::DoDecodeBuffer(
173 const scoped_refptr<DecoderBuffer>& input) {
172 DCHECK_EQ(MessageLoop::current(), message_loop_); 174 DCHECK_EQ(MessageLoop::current(), message_loop_);
173 DCHECK(!read_cb_.is_null()); 175 DCHECK(!read_cb_.is_null());
174 176
175 if (!input) { 177 if (!input) {
176 // DemuxeStream::Read() was aborted so we abort the decoder's pending read. 178 // DemuxeStream::Read() was aborted so we abort the decoder's pending read.
177 DeliverSamples(NULL); 179 DeliverSamples(NULL);
178 return; 180 return;
179 } 181 }
180 182
181 // FFmpeg tends to seek Ogg audio streams in the middle of nowhere, giving us 183 // FFmpeg tends to seek Ogg audio streams in the middle of nowhere, giving us
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 ReadFromDemuxerStream(); 251 ReadFromDemuxerStream();
250 } 252 }
251 } 253 }
252 254
253 void FFmpegAudioDecoder::ReadFromDemuxerStream() { 255 void FFmpegAudioDecoder::ReadFromDemuxerStream() {
254 DCHECK(!read_cb_.is_null()); 256 DCHECK(!read_cb_.is_null());
255 257
256 demuxer_stream_->Read(base::Bind(&FFmpegAudioDecoder::DecodeBuffer, this)); 258 demuxer_stream_->Read(base::Bind(&FFmpegAudioDecoder::DecodeBuffer, this));
257 } 259 }
258 260
259 void FFmpegAudioDecoder::DecodeBuffer(const scoped_refptr<Buffer>& buffer) { 261 void FFmpegAudioDecoder::DecodeBuffer(
262 const scoped_refptr<DecoderBuffer>& buffer) {
260 // TODO(scherkus): fix FFmpegDemuxerStream::Read() to not execute our read 263 // TODO(scherkus): fix FFmpegDemuxerStream::Read() to not execute our read
261 // callback on the same execution stack so we can get rid of forced task post. 264 // callback on the same execution stack so we can get rid of forced task post.
262 message_loop_->PostTask(FROM_HERE, base::Bind( 265 message_loop_->PostTask(FROM_HERE, base::Bind(
263 &FFmpegAudioDecoder::DoDecodeBuffer, this, buffer)); 266 &FFmpegAudioDecoder::DoDecodeBuffer, this, buffer));
264 } 267 }
265 268
266 void FFmpegAudioDecoder::UpdateDurationAndTimestamp( 269 void FFmpegAudioDecoder::UpdateDurationAndTimestamp(
267 const Buffer* input, 270 const Buffer* input,
268 DataBuffer* output) { 271 DataBuffer* output) {
269 // Always calculate duration based on the actual number of samples decoded. 272 // Always calculate duration based on the actual number of samples decoded.
(...skipping 24 matching lines...) Expand all
294 } 297 }
295 298
296 void FFmpegAudioDecoder::DeliverSamples(const scoped_refptr<Buffer>& samples) { 299 void FFmpegAudioDecoder::DeliverSamples(const scoped_refptr<Buffer>& samples) {
297 // Reset the callback before running to protect against reentrancy. 300 // Reset the callback before running to protect against reentrancy.
298 ReadCB read_cb = read_cb_; 301 ReadCB read_cb = read_cb_;
299 read_cb_.Reset(); 302 read_cb_.Reset();
300 read_cb.Run(samples); 303 read_cb.Run(samples);
301 } 304 }
302 305
303 } // namespace media 306 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698