Chromium Code Reviews| 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 #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 "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" | 
| 9 #include "base/location.h" | 9 #include "base/location.h" | 
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" | 
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 } | 182 } | 
| 183 | 183 | 
| 184 base::ResetAndReturn(&read_cb_).Run( | 184 base::ResetAndReturn(&read_cb_).Run( | 
| 185 queued_audio_.front().status, queued_audio_.front().buffer); | 185 queued_audio_.front().status, queued_audio_.front().buffer); | 
| 186 queued_audio_.pop_front(); | 186 queued_audio_.pop_front(); | 
| 187 } | 187 } | 
| 188 | 188 | 
| 189 void FFmpegAudioDecoder::DoDecodeBuffer( | 189 void FFmpegAudioDecoder::DoDecodeBuffer( | 
| 190 DemuxerStream::Status status, | 190 DemuxerStream::Status status, | 
| 191 const scoped_refptr<DecoderBuffer>& input) { | 191 const scoped_refptr<DecoderBuffer>& input) { | 
| 192 DCHECK(message_loop_->BelongsToCurrentThread()); | 192 if (!message_loop_->BelongsToCurrentThread()) { | 
| 193 message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 194 &FFmpegAudioDecoder::DoDecodeBuffer, this, status, input)); | |
| 195 return; | |
| 196 } | |
| 197 | |
| 193 DCHECK(!read_cb_.is_null()); | 198 DCHECK(!read_cb_.is_null()); | 
| 194 DCHECK(queued_audio_.empty()); | 199 DCHECK(queued_audio_.empty()); | 
| 195 | 200 | 
| 196 if (status != DemuxerStream::kOk) { | 201 if (status != DemuxerStream::kOk) { | 
| 197 DCHECK(!input); | 202 DCHECK(!input); | 
| 198 // TODO(acolwell): Add support for reinitializing the decoder when | 203 // TODO(acolwell): Add support for reinitializing the decoder when | 
| 199 // |status| == kConfigChanged. For now we just trigger a decode error. | 204 // |status| == kConfigChanged. For now we just trigger a decode error. | 
| 200 AudioDecoder::Status decoder_status = | 205 AudioDecoder::Status decoder_status = | 
| 201 (status == DemuxerStream::kAborted) ? kAborted : kDecodeError; | 206 (status == DemuxerStream::kAborted) ? kAborted : kDecodeError; | 
| 202 base::ResetAndReturn(&read_cb_).Run(decoder_status, NULL); | 207 base::ResetAndReturn(&read_cb_).Run(decoder_status, NULL); | 
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 | 363 | 
| 359 // Execute callback to return the first frame we decoded. | 364 // Execute callback to return the first frame we decoded. | 
| 360 base::ResetAndReturn(&read_cb_).Run( | 365 base::ResetAndReturn(&read_cb_).Run( | 
| 361 queued_audio_.front().status, queued_audio_.front().buffer); | 366 queued_audio_.front().status, queued_audio_.front().buffer); | 
| 362 queued_audio_.pop_front(); | 367 queued_audio_.pop_front(); | 
| 363 } | 368 } | 
| 364 | 369 | 
| 365 void FFmpegAudioDecoder::ReadFromDemuxerStream() { | 370 void FFmpegAudioDecoder::ReadFromDemuxerStream() { | 
| 366 DCHECK(!read_cb_.is_null()); | 371 DCHECK(!read_cb_.is_null()); | 
| 367 | 372 | 
| 368 demuxer_stream_->Read(base::Bind(&FFmpegAudioDecoder::DecodeBuffer, this)); | 373 demuxer_stream_->Read(base::Bind(&FFmpegAudioDecoder::DoDecodeBuffer, this)); | 
| 369 } | |
| 370 | |
| 371 void FFmpegAudioDecoder::DecodeBuffer( | |
| 372 DemuxerStream::Status status, | |
| 373 const scoped_refptr<DecoderBuffer>& buffer) { | |
| 374 DCHECK_EQ(status != DemuxerStream::kOk, !buffer) << status; | |
| 
 
xhwang
2012/11/20 17:54:34
Do you want to keep this check?
 
scherkus (not reviewing)
2012/11/20 19:16:07
Done.
 
 | |
| 375 | |
| 376 // TODO(scherkus): fix FFmpegDemuxerStream::Read() to not execute our read | |
| 377 // callback on the same execution stack so we can get rid of forced task post. | |
| 378 message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 379 &FFmpegAudioDecoder::DoDecodeBuffer, this, status, buffer)); | |
| 380 } | 374 } | 
| 381 | 375 | 
| 382 base::TimeDelta FFmpegAudioDecoder::GetNextOutputTimestamp() const { | 376 base::TimeDelta FFmpegAudioDecoder::GetNextOutputTimestamp() const { | 
| 383 DCHECK(output_timestamp_base_ != kNoTimestamp()); | 377 DCHECK(output_timestamp_base_ != kNoTimestamp()); | 
| 384 double decoded_us = (total_frames_decoded_ / samples_per_second_) * | 378 double decoded_us = (total_frames_decoded_ / samples_per_second_) * | 
| 385 base::Time::kMicrosecondsPerSecond; | 379 base::Time::kMicrosecondsPerSecond; | 
| 386 return output_timestamp_base_ + base::TimeDelta::FromMicroseconds(decoded_us); | 380 return output_timestamp_base_ + base::TimeDelta::FromMicroseconds(decoded_us); | 
| 387 } | 381 } | 
| 382 | |
| 388 } // namespace media | 383 } // namespace media | 
| OLD | NEW |