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/opus_audio_decoder.h" | 5 #include "media/filters/opus_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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 void OpusAudioDecoder::ReadFromDemuxerStream() { | 322 void OpusAudioDecoder::ReadFromDemuxerStream() { |
323 DCHECK(!read_cb_.is_null()); | 323 DCHECK(!read_cb_.is_null()); |
324 demuxer_stream_->Read(base::Bind(&OpusAudioDecoder::BufferReady, weak_this_)); | 324 demuxer_stream_->Read(base::Bind(&OpusAudioDecoder::BufferReady, weak_this_)); |
325 } | 325 } |
326 | 326 |
327 void OpusAudioDecoder::BufferReady( | 327 void OpusAudioDecoder::BufferReady( |
328 DemuxerStream::Status status, | 328 DemuxerStream::Status status, |
329 const scoped_refptr<DecoderBuffer>& input) { | 329 const scoped_refptr<DecoderBuffer>& input) { |
330 DCHECK(message_loop_->BelongsToCurrentThread()); | 330 DCHECK(message_loop_->BelongsToCurrentThread()); |
331 DCHECK(!read_cb_.is_null()); | 331 DCHECK(!read_cb_.is_null()); |
332 DCHECK_EQ(status != DemuxerStream::kOk, !input) << status; | 332 DCHECK_EQ(status != DemuxerStream::kOk, !input.get()) << status; |
333 | 333 |
334 if (status == DemuxerStream::kAborted) { | 334 if (status == DemuxerStream::kAborted) { |
335 DCHECK(!input); | 335 DCHECK(!input.get()); |
336 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 336 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
337 return; | 337 return; |
338 } | 338 } |
339 | 339 |
340 if (status == DemuxerStream::kConfigChanged) { | 340 if (status == DemuxerStream::kConfigChanged) { |
341 DCHECK(!input); | 341 DCHECK(!input.get()); |
342 DVLOG(1) << "Config changed."; | 342 DVLOG(1) << "Config changed."; |
343 | 343 |
344 if (!ConfigureDecoder()) { | 344 if (!ConfigureDecoder()) { |
345 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); | 345 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); |
346 return; | 346 return; |
347 } | 347 } |
348 | 348 |
349 ResetTimestampState(); | 349 ResetTimestampState(); |
350 ReadFromDemuxerStream(); | 350 ReadFromDemuxerStream(); |
351 return; | 351 return; |
352 } | 352 } |
353 | 353 |
354 DCHECK_EQ(status, DemuxerStream::kOk); | 354 DCHECK_EQ(status, DemuxerStream::kOk); |
355 DCHECK(input); | 355 DCHECK(input.get()); |
356 | 356 |
357 // Libopus does not buffer output. Decoding is complete when an end of stream | 357 // Libopus does not buffer output. Decoding is complete when an end of stream |
358 // input buffer is received. | 358 // input buffer is received. |
359 if (input->IsEndOfStream()) { | 359 if (input->IsEndOfStream()) { |
360 base::ResetAndReturn(&read_cb_).Run(kOk, DataBuffer::CreateEOSBuffer()); | 360 base::ResetAndReturn(&read_cb_).Run(kOk, DataBuffer::CreateEOSBuffer()); |
361 return; | 361 return; |
362 } | 362 } |
363 | 363 |
364 // Make sure we are notified if http://crbug.com/49709 returns. Issue also | 364 // Make sure we are notified if http://crbug.com/49709 returns. Issue also |
365 // occurs with some damaged files. | 365 // occurs with some damaged files. |
(...skipping 17 matching lines...) Expand all Loading... |
383 | 383 |
384 last_input_timestamp_ = input->GetTimestamp(); | 384 last_input_timestamp_ = input->GetTimestamp(); |
385 | 385 |
386 scoped_refptr<DataBuffer> output_buffer; | 386 scoped_refptr<DataBuffer> output_buffer; |
387 | 387 |
388 if (!Decode(input, &output_buffer)) { | 388 if (!Decode(input, &output_buffer)) { |
389 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); | 389 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); |
390 return; | 390 return; |
391 } | 391 } |
392 | 392 |
393 if (output_buffer) { | 393 if (output_buffer.get()) { |
394 // Execute callback to return the decoded audio. | 394 // Execute callback to return the decoded audio. |
395 base::ResetAndReturn(&read_cb_).Run(kOk, output_buffer); | 395 base::ResetAndReturn(&read_cb_).Run(kOk, output_buffer); |
396 } else { | 396 } else { |
397 // We exhausted the input data, but it wasn't enough for a frame. Ask for | 397 // We exhausted the input data, but it wasn't enough for a frame. Ask for |
398 // more data in order to fulfill this read. | 398 // more data in order to fulfill this read. |
399 ReadFromDemuxerStream(); | 399 ReadFromDemuxerStream(); |
400 } | 400 } |
401 } | 401 } |
402 | 402 |
403 bool OpusAudioDecoder::ConfigureDecoder() { | 403 bool OpusAudioDecoder::ConfigureDecoder() { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 559 |
560 // Decoding finished successfully, update statistics. | 560 // Decoding finished successfully, update statistics. |
561 PipelineStatistics statistics; | 561 PipelineStatistics statistics; |
562 statistics.audio_bytes_decoded = decoded_audio_size; | 562 statistics.audio_bytes_decoded = decoded_audio_size; |
563 statistics_cb_.Run(statistics); | 563 statistics_cb_.Run(statistics); |
564 | 564 |
565 return true; | 565 return true; |
566 } | 566 } |
567 | 567 |
568 } // namespace media | 568 } // namespace media |
OLD | NEW |