| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/media_codec_audio_decoder.h" | 5 #include "media/filters/android/media_codec_audio_decoder.h" |
| 6 | 6 |
| 7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "media/base/android/media_codec_bridge_impl.h" | 12 #include "media/base/android/media_codec_bridge_impl.h" |
| 13 #include "media/base/audio_buffer.h" | |
| 14 #include "media/base/audio_timestamp_helper.h" | 13 #include "media/base/audio_timestamp_helper.h" |
| 15 #include "media/base/bind_to_current_loop.h" | 14 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/base/timestamp_constants.h" | 15 #include "media/base/timestamp_constants.h" |
| 17 | 16 |
| 18 namespace media { | 17 namespace media { |
| 19 | 18 |
| 20 MediaCodecAudioDecoder::MediaCodecAudioDecoder( | 19 MediaCodecAudioDecoder::MediaCodecAudioDecoder( |
| 21 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 20 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 22 : task_runner_(task_runner), | 21 : task_runner_(task_runner), |
| 23 state_(STATE_UNINITIALIZED), | 22 state_(STATE_UNINITIALIZED), |
| 24 channel_count_(0), | 23 channel_count_(0), |
| 25 channel_layout_(CHANNEL_LAYOUT_NONE), | 24 channel_layout_(CHANNEL_LAYOUT_NONE), |
| 26 sample_rate_(0), | 25 sample_rate_(0), |
| 27 media_drm_bridge_cdm_context_(nullptr), | 26 media_drm_bridge_cdm_context_(nullptr), |
| 28 cdm_registration_id_(0), | 27 cdm_registration_id_(0), |
| 28 pool_(new AudioBufferMemoryPool()), |
| 29 weak_factory_(this) { | 29 weak_factory_(this) { |
| 30 DVLOG(1) << __func__; | 30 DVLOG(1) << __func__; |
| 31 } | 31 } |
| 32 | 32 |
| 33 MediaCodecAudioDecoder::~MediaCodecAudioDecoder() { | 33 MediaCodecAudioDecoder::~MediaCodecAudioDecoder() { |
| 34 DVLOG(1) << __func__; | 34 DVLOG(1) << __func__; |
| 35 | 35 |
| 36 codec_loop_.reset(); | 36 codec_loop_.reset(); |
| 37 | 37 |
| 38 if (media_drm_bridge_cdm_context_) { | 38 if (media_drm_bridge_cdm_context_) { |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 356 |
| 357 // For proper |frame_count| calculation we need to use the actual number | 357 // For proper |frame_count| calculation we need to use the actual number |
| 358 // of channels which can be different from |config_| value. | 358 // of channels which can be different from |config_| value. |
| 359 DCHECK_GT(channel_count_, 0); | 359 DCHECK_GT(channel_count_, 0); |
| 360 | 360 |
| 361 // Android MediaCodec can only output 16bit PCM audio. | 361 // Android MediaCodec can only output 16bit PCM audio. |
| 362 const int bytes_per_frame = sizeof(uint16_t) * channel_count_; | 362 const int bytes_per_frame = sizeof(uint16_t) * channel_count_; |
| 363 const size_t frame_count = out.size / bytes_per_frame; | 363 const size_t frame_count = out.size / bytes_per_frame; |
| 364 | 364 |
| 365 // Create AudioOutput buffer based on current parameters. | 365 // Create AudioOutput buffer based on current parameters. |
| 366 scoped_refptr<AudioBuffer> audio_buffer = | 366 scoped_refptr<AudioBuffer> audio_buffer = AudioBuffer::CreateBuffer( |
| 367 AudioBuffer::CreateBuffer(kSampleFormatS16, channel_layout_, | 367 kSampleFormatS16, channel_layout_, channel_count_, sample_rate_, |
| 368 channel_count_, sample_rate_, frame_count); | 368 frame_count, pool_); |
| 369 | 369 |
| 370 // Copy data into AudioBuffer. | 370 // Copy data into AudioBuffer. |
| 371 CHECK_LE(out.size, audio_buffer->data_size()); | 371 CHECK_LE(out.size, audio_buffer->data_size()); |
| 372 | 372 |
| 373 MediaCodecStatus status = media_codec->CopyFromOutputBuffer( | 373 MediaCodecStatus status = media_codec->CopyFromOutputBuffer( |
| 374 out.index, out.offset, audio_buffer->channel_data()[0], out.size); | 374 out.index, out.offset, audio_buffer->channel_data()[0], out.size); |
| 375 | 375 |
| 376 // Release MediaCodec output buffer. | 376 // Release MediaCodec output buffer. |
| 377 media_codec->ReleaseOutputBuffer(out.index, false); | 377 media_codec->ReleaseOutputBuffer(out.index, false); |
| 378 | 378 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 RETURN_STRING(STATE_READY); | 467 RETURN_STRING(STATE_READY); |
| 468 RETURN_STRING(STATE_ERROR); | 468 RETURN_STRING(STATE_ERROR); |
| 469 } | 469 } |
| 470 NOTREACHED() << "Unknown state " << state; | 470 NOTREACHED() << "Unknown state " << state; |
| 471 return nullptr; | 471 return nullptr; |
| 472 } | 472 } |
| 473 | 473 |
| 474 #undef RETURN_STRING | 474 #undef RETURN_STRING |
| 475 | 475 |
| 476 } // namespace media | 476 } // namespace media |
| OLD | NEW |