| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 demuxer_stream_->Read(base::Bind( | 137 demuxer_stream_->Read(base::Bind( |
| 138 &FFmpegAudioDecoder::BufferReady, weak_this_)); | 138 &FFmpegAudioDecoder::BufferReady, weak_this_)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void FFmpegAudioDecoder::BufferReady( | 141 void FFmpegAudioDecoder::BufferReady( |
| 142 DemuxerStream::Status status, | 142 DemuxerStream::Status status, |
| 143 const scoped_refptr<DecoderBuffer>& input) { | 143 const scoped_refptr<DecoderBuffer>& input) { |
| 144 DCHECK(message_loop_->BelongsToCurrentThread()); | 144 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 145 DCHECK(!read_cb_.is_null()); | 145 DCHECK(!read_cb_.is_null()); |
| 146 DCHECK(queued_audio_.empty()); | 146 DCHECK(queued_audio_.empty()); |
| 147 DCHECK_EQ(status != DemuxerStream::kOk, !input) << status; | 147 DCHECK_EQ(status != DemuxerStream::kOk, !input.get()) << status; |
| 148 | 148 |
| 149 if (status == DemuxerStream::kAborted) { | 149 if (status == DemuxerStream::kAborted) { |
| 150 DCHECK(!input); | 150 DCHECK(!input.get()); |
| 151 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 151 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 | 154 |
| 155 if (status == DemuxerStream::kConfigChanged) { | 155 if (status == DemuxerStream::kConfigChanged) { |
| 156 DCHECK(!input); | 156 DCHECK(!input.get()); |
| 157 | 157 |
| 158 // Send a "end of stream" buffer to the decode loop | 158 // Send a "end of stream" buffer to the decode loop |
| 159 // to output any remaining data still in the decoder. | 159 // to output any remaining data still in the decoder. |
| 160 RunDecodeLoop(DecoderBuffer::CreateEOSBuffer(), true); | 160 RunDecodeLoop(DecoderBuffer::CreateEOSBuffer(), true); |
| 161 | 161 |
| 162 DVLOG(1) << "Config changed."; | 162 DVLOG(1) << "Config changed."; |
| 163 | 163 |
| 164 if (!ConfigureDecoder()) { | 164 if (!ConfigureDecoder()) { |
| 165 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); | 165 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); |
| 166 return; | 166 return; |
| 167 } | 167 } |
| 168 | 168 |
| 169 ResetTimestampState(); | 169 ResetTimestampState(); |
| 170 | 170 |
| 171 if (queued_audio_.empty()) { | 171 if (queued_audio_.empty()) { |
| 172 ReadFromDemuxerStream(); | 172 ReadFromDemuxerStream(); |
| 173 return; | 173 return; |
| 174 } | 174 } |
| 175 | 175 |
| 176 base::ResetAndReturn(&read_cb_).Run( | 176 base::ResetAndReturn(&read_cb_).Run( |
| 177 queued_audio_.front().status, queued_audio_.front().buffer); | 177 queued_audio_.front().status, queued_audio_.front().buffer); |
| 178 queued_audio_.pop_front(); | 178 queued_audio_.pop_front(); |
| 179 return; | 179 return; |
| 180 } | 180 } |
| 181 | 181 |
| 182 DCHECK_EQ(status, DemuxerStream::kOk); | 182 DCHECK_EQ(status, DemuxerStream::kOk); |
| 183 DCHECK(input); | 183 DCHECK(input.get()); |
| 184 | 184 |
| 185 // Make sure we are notified if http://crbug.com/49709 returns. Issue also | 185 // Make sure we are notified if http://crbug.com/49709 returns. Issue also |
| 186 // occurs with some damaged files. | 186 // occurs with some damaged files. |
| 187 if (!input->IsEndOfStream() && input->GetTimestamp() == kNoTimestamp() && | 187 if (!input->IsEndOfStream() && input->GetTimestamp() == kNoTimestamp() && |
| 188 output_timestamp_helper_->base_timestamp() == kNoTimestamp()) { | 188 output_timestamp_helper_->base_timestamp() == kNoTimestamp()) { |
| 189 DVLOG(1) << "Received a buffer without timestamps!"; | 189 DVLOG(1) << "Received a buffer without timestamps!"; |
| 190 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); | 190 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 | 193 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 output->SetTimestamp(output_timestamp_helper_->GetTimestamp()); | 484 output->SetTimestamp(output_timestamp_helper_->GetTimestamp()); |
| 485 output->SetDuration( | 485 output->SetDuration( |
| 486 output_timestamp_helper_->GetDuration(decoded_audio_size)); | 486 output_timestamp_helper_->GetDuration(decoded_audio_size)); |
| 487 output_timestamp_helper_->AddBytes(decoded_audio_size); | 487 output_timestamp_helper_->AddBytes(decoded_audio_size); |
| 488 } else if (IsEndOfStream(result, decoded_audio_size, input) && | 488 } else if (IsEndOfStream(result, decoded_audio_size, input) && |
| 489 !skip_eos_append) { | 489 !skip_eos_append) { |
| 490 DCHECK_EQ(packet.size, 0); | 490 DCHECK_EQ(packet.size, 0); |
| 491 output = DataBuffer::CreateEOSBuffer(); | 491 output = DataBuffer::CreateEOSBuffer(); |
| 492 } | 492 } |
| 493 | 493 |
| 494 if (output) { | 494 if (output.get()) { |
| 495 QueuedAudioBuffer queue_entry = { kOk, output }; | 495 QueuedAudioBuffer queue_entry = { kOk, output }; |
| 496 queued_audio_.push_back(queue_entry); | 496 queued_audio_.push_back(queue_entry); |
| 497 } | 497 } |
| 498 | 498 |
| 499 // Decoding finished successfully, update statistics. | 499 // Decoding finished successfully, update statistics. |
| 500 if (result > 0) { | 500 if (result > 0) { |
| 501 PipelineStatistics statistics; | 501 PipelineStatistics statistics; |
| 502 statistics.audio_bytes_decoded = result; | 502 statistics.audio_bytes_decoded = result; |
| 503 statistics_cb_.Run(statistics); | 503 statistics_cb_.Run(statistics); |
| 504 } | 504 } |
| 505 } while (packet.size > 0); | 505 } while (packet.size > 0); |
| 506 } | 506 } |
| 507 | 507 |
| 508 } // namespace media | 508 } // namespace media |
| OLD | NEW |