| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chromecast/media/cma/backend/alsa/audio_decoder_alsa.h" | 5 #include "chromecast/media/cma/backend/alsa/audio_decoder_alsa.h" |
| 6 | 6 |
| 7 #include <time.h> | 7 #include <time.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| 11 | 11 |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "chromecast/base/task_runner_impl.h" | 16 #include "chromecast/base/task_runner_impl.h" |
| 17 #include "chromecast/media/cma/backend/alsa/media_pipeline_backend_alsa.h" | 17 #include "chromecast/media/cma/backend/alsa/media_pipeline_backend_alsa.h" |
| 18 #include "chromecast/media/cma/base/decoder_buffer_adapter.h" | 18 #include "chromecast/media/cma/base/decoder_buffer_adapter.h" |
| 19 #include "chromecast/media/cma/base/decoder_buffer_base.h" | 19 #include "chromecast/media/cma/base/decoder_buffer_base.h" |
| 20 #include "chromecast/public/media/cast_decoder_buffer.h" | 20 #include "chromecast/public/media/cast_decoder_buffer.h" |
| 21 #include "media/base/audio_buffer.h" | |
| 22 #include "media/base/audio_bus.h" | 21 #include "media/base/audio_bus.h" |
| 23 #include "media/base/channel_layout.h" | 22 #include "media/base/channel_layout.h" |
| 24 #include "media/base/decoder_buffer.h" | 23 #include "media/base/decoder_buffer.h" |
| 25 #include "media/base/sample_format.h" | 24 #include "media/base/sample_format.h" |
| 26 #include "media/filters/audio_renderer_algorithm.h" | 25 #include "media/filters/audio_renderer_algorithm.h" |
| 27 | 26 |
| 28 #define TRACE_FUNCTION_ENTRY0() TRACE_EVENT0("cma", __FUNCTION__) | 27 #define TRACE_FUNCTION_ENTRY0() TRACE_EVENT0("cma", __FUNCTION__) |
| 29 | 28 |
| 30 #define TRACE_FUNCTION_ENTRY1(arg1) \ | 29 #define TRACE_FUNCTION_ENTRY1(arg1) \ |
| 31 TRACE_EVENT1("cma", __FUNCTION__, #arg1, arg1) | 30 TRACE_EVENT1("cma", __FUNCTION__, #arg1, arg1) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 delegate_(nullptr), | 64 delegate_(nullptr), |
| 66 pending_buffer_complete_(false), | 65 pending_buffer_complete_(false), |
| 67 got_eos_(false), | 66 got_eos_(false), |
| 68 pushed_eos_(false), | 67 pushed_eos_(false), |
| 69 mixer_error_(false), | 68 mixer_error_(false), |
| 70 rate_shifter_output_( | 69 rate_shifter_output_( |
| 71 ::media::AudioBus::Create(kNumChannels, kDefaultFramesPerBuffer)), | 70 ::media::AudioBus::Create(kNumChannels, kDefaultFramesPerBuffer)), |
| 72 current_pts_(kInvalidTimestamp), | 71 current_pts_(kInvalidTimestamp), |
| 73 pending_output_frames_(kNoPendingOutput), | 72 pending_output_frames_(kNoPendingOutput), |
| 74 volume_multiplier_(1.0f), | 73 volume_multiplier_(1.0f), |
| 74 pool_(new ::media::AudioBufferMemoryPool()), |
| 75 weak_factory_(this) { | 75 weak_factory_(this) { |
| 76 TRACE_FUNCTION_ENTRY0(); | 76 TRACE_FUNCTION_ENTRY0(); |
| 77 DCHECK(backend_); | 77 DCHECK(backend_); |
| 78 DCHECK(task_runner_.get()); | 78 DCHECK(task_runner_.get()); |
| 79 DCHECK(task_runner_->BelongsToCurrentThread()); | 79 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 AudioDecoderAlsa::~AudioDecoderAlsa() { | 82 AudioDecoderAlsa::~AudioDecoderAlsa() { |
| 83 TRACE_FUNCTION_ENTRY0(); | 83 TRACE_FUNCTION_ENTRY0(); |
| 84 DCHECK(task_runner_->BelongsToCurrentThread()); | 84 DCHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 return; | 373 return; |
| 374 } | 374 } |
| 375 | 375 |
| 376 // Otherwise, queue data into the rate shifter, and then try to push the | 376 // Otherwise, queue data into the rate shifter, and then try to push the |
| 377 // rate-shifted data. | 377 // rate-shifted data. |
| 378 const uint8_t* channels[kNumChannels] = { | 378 const uint8_t* channels[kNumChannels] = { |
| 379 decoded->data(), decoded->data() + input_frames * sizeof(float)}; | 379 decoded->data(), decoded->data() + input_frames * sizeof(float)}; |
| 380 scoped_refptr<::media::AudioBuffer> buffer = ::media::AudioBuffer::CopyFrom( | 380 scoped_refptr<::media::AudioBuffer> buffer = ::media::AudioBuffer::CopyFrom( |
| 381 ::media::kSampleFormatPlanarF32, ::media::CHANNEL_LAYOUT_STEREO, | 381 ::media::kSampleFormatPlanarF32, ::media::CHANNEL_LAYOUT_STEREO, |
| 382 kNumChannels, config_.samples_per_second, input_frames, channels, | 382 kNumChannels, config_.samples_per_second, input_frames, channels, |
| 383 base::TimeDelta()); | 383 base::TimeDelta(), pool_); |
| 384 rate_shifter_->EnqueueBuffer(buffer); | 384 rate_shifter_->EnqueueBuffer(buffer); |
| 385 rate_shifter_info_.back().input_frames += input_frames; | 385 rate_shifter_info_.back().input_frames += input_frames; |
| 386 } | 386 } |
| 387 | 387 |
| 388 PushRateShifted(); | 388 PushRateShifted(); |
| 389 DCHECK(!rate_shifter_info_.empty()); | 389 DCHECK(!rate_shifter_info_.empty()); |
| 390 CheckBufferComplete(); | 390 CheckBufferComplete(); |
| 391 } | 391 } |
| 392 | 392 |
| 393 void AudioDecoderAlsa::CheckBufferComplete() { | 393 void AudioDecoderAlsa::CheckBufferComplete() { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 TRACE_FUNCTION_ENTRY0(); | 538 TRACE_FUNCTION_ENTRY0(); |
| 539 DCHECK(task_runner_->BelongsToCurrentThread()); | 539 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 540 if (error != MixerError::kInputIgnored) | 540 if (error != MixerError::kInputIgnored) |
| 541 LOG(ERROR) << "Mixer error occurred."; | 541 LOG(ERROR) << "Mixer error occurred."; |
| 542 mixer_error_ = true; | 542 mixer_error_ = true; |
| 543 delegate_->OnDecoderError(); | 543 delegate_->OnDecoderError(); |
| 544 } | 544 } |
| 545 | 545 |
| 546 } // namespace media | 546 } // namespace media |
| 547 } // namespace chromecast | 547 } // namespace chromecast |
| OLD | NEW |