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

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

Issue 8351045: Change DemuxerStream::ReadCallback to use ref-counted buffers. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: forgot some &s Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/demuxer.h" 10 #include "media/base/demuxer.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 243 }
244 244
245 void FFmpegAudioDecoder::ReadFromDemuxerStream() { 245 void FFmpegAudioDecoder::ReadFromDemuxerStream() {
246 DCHECK(!output_buffers_.empty()) 246 DCHECK(!output_buffers_.empty())
247 << "Reads should only occur if there are output buffers."; 247 << "Reads should only occur if there are output buffers.";
248 248
249 pending_reads_++; 249 pending_reads_++;
250 demuxer_stream_->Read(base::Bind(&FFmpegAudioDecoder::DecodeBuffer, this)); 250 demuxer_stream_->Read(base::Bind(&FFmpegAudioDecoder::DecodeBuffer, this));
251 } 251 }
252 252
253 void FFmpegAudioDecoder::DecodeBuffer(Buffer* buffer) { 253 void FFmpegAudioDecoder::DecodeBuffer(const scoped_refptr<Buffer>& buffer) {
254 // TODO(scherkus): change DemuxerStream::Read() to use scoped_refptr<> for
255 // callback.
256 scoped_refptr<Buffer> ref_buffer(buffer);
257 message_loop_->PostTask( 254 message_loop_->PostTask(
258 FROM_HERE, 255 FROM_HERE,
259 base::Bind(&FFmpegAudioDecoder::DoDecodeBuffer, this, ref_buffer)); 256 base::Bind(&FFmpegAudioDecoder::DoDecodeBuffer, this, buffer));
260 } 257 }
261 258
262 void FFmpegAudioDecoder::UpdateDurationAndTimestamp( 259 void FFmpegAudioDecoder::UpdateDurationAndTimestamp(
263 const Buffer* input, 260 const Buffer* input,
264 DataBuffer* output) { 261 DataBuffer* output) {
265 // Always calculate duration based on the actual number of samples decoded. 262 // Always calculate duration based on the actual number of samples decoded.
266 base::TimeDelta duration = CalculateDuration(output->GetDataSize()); 263 base::TimeDelta duration = CalculateDuration(output->GetDataSize());
267 output->SetDuration(duration); 264 output->SetDuration(duration);
268 265
269 // Use the incoming timestamp if it's valid. 266 // Use the incoming timestamp if it's valid.
(...skipping 13 matching lines...) Expand all
283 280
284 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(int size) { 281 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(int size) {
285 int64 denominator = ChannelLayoutToChannelCount(channel_layout_) * 282 int64 denominator = ChannelLayoutToChannelCount(channel_layout_) *
286 bits_per_channel_ / 8 * samples_per_second_; 283 bits_per_channel_ / 8 * samples_per_second_;
287 double microseconds = size / 284 double microseconds = size /
288 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); 285 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond));
289 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); 286 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds));
290 } 287 }
291 288
292 } // namespace media 289 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698