| 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/renderers/audio_renderer_impl.h" | 5 #include "media/renderers/audio_renderer_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 AudioRendererImpl::~AudioRendererImpl() { | 87 AudioRendererImpl::~AudioRendererImpl() { |
| 88 DVLOG(1) << __func__; | 88 DVLOG(1) << __func__; |
| 89 DCHECK(task_runner_->BelongsToCurrentThread()); | 89 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 90 if (base::PowerMonitor::Get()) | 90 if (base::PowerMonitor::Get()) |
| 91 base::PowerMonitor::Get()->RemoveObserver(this); | 91 base::PowerMonitor::Get()->RemoveObserver(this); |
| 92 | 92 |
| 93 // If Render() is in progress, this call will wait for Render() to finish. | 93 // If Render() is in progress, this call will wait for Render() to finish. |
| 94 // After this call, the |sink_| will not call back into |this| anymore. | 94 // After this call, the |sink_| will not call back into |this| anymore. |
| 95 sink_->Stop(); | 95 sink_->Stop(); |
| 96 | 96 |
| 97 // Trying to track down AudioClock crash, http://crbug.com/674856. If the sink |
| 98 // hasn't truly stopped above we will fail to acquire the lock. The sink must |
| 99 // be stopped to avoid destroying the AudioClock while its still being used. |
| 100 CHECK(lock_.Try()); |
| 101 lock_.Release(); |
| 102 |
| 97 if (!init_cb_.is_null()) | 103 if (!init_cb_.is_null()) |
| 98 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); | 104 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); |
| 99 } | 105 } |
| 100 | 106 |
| 101 void AudioRendererImpl::StartTicking() { | 107 void AudioRendererImpl::StartTicking() { |
| 102 DVLOG(1) << __func__; | 108 DVLOG(1) << __func__; |
| 103 DCHECK(task_runner_->BelongsToCurrentThread()); | 109 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 104 | 110 |
| 105 base::AutoLock auto_lock(lock_); | 111 base::AutoLock auto_lock(lock_); |
| 106 | 112 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 const PipelineStatusCB& init_cb) { | 336 const PipelineStatusCB& init_cb) { |
| 331 DVLOG(1) << __func__; | 337 DVLOG(1) << __func__; |
| 332 DCHECK(task_runner_->BelongsToCurrentThread()); | 338 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 333 DCHECK(client); | 339 DCHECK(client); |
| 334 DCHECK(stream); | 340 DCHECK(stream); |
| 335 DCHECK_EQ(stream->type(), DemuxerStream::AUDIO); | 341 DCHECK_EQ(stream->type(), DemuxerStream::AUDIO); |
| 336 DCHECK(!init_cb.is_null()); | 342 DCHECK(!init_cb.is_null()); |
| 337 DCHECK_EQ(kUninitialized, state_); | 343 DCHECK_EQ(kUninitialized, state_); |
| 338 DCHECK(sink_.get()); | 344 DCHECK(sink_.get()); |
| 339 | 345 |
| 346 // Trying to track down AudioClock crash, http://crbug.com/674856. |
| 347 // AudioRenderImpl should only be initialized once to avoid destroying |
| 348 // AudioClock while the audio thread is still using it. |
| 349 CHECK_EQ(audio_clock_.get(), nullptr); |
| 350 |
| 340 state_ = kInitializing; | 351 state_ = kInitializing; |
| 341 client_ = client; | 352 client_ = client; |
| 342 | 353 |
| 343 // Always post |init_cb_| because |this| could be destroyed if initialization | 354 // Always post |init_cb_| because |this| could be destroyed if initialization |
| 344 // failed. | 355 // failed. |
| 345 init_cb_ = BindToCurrentLoop(init_cb); | 356 init_cb_ = BindToCurrentLoop(init_cb); |
| 346 | 357 |
| 347 auto output_device_info = sink_->GetOutputDeviceInfo(); | 358 auto output_device_info = sink_->GetOutputDeviceInfo(); |
| 348 const AudioParameters& hw_params = output_device_info.output_params(); | 359 const AudioParameters& hw_params = output_device_info.output_params(); |
| 349 expecting_config_changes_ = stream->SupportsConfigChanges(); | 360 expecting_config_changes_ = stream->SupportsConfigChanges(); |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 // All channels with a zero mix are muted and can be ignored. | 999 // All channels with a zero mix are muted and can be ignored. |
| 989 std::vector<bool> channel_mask(audio_parameters_.channels(), false); | 1000 std::vector<bool> channel_mask(audio_parameters_.channels(), false); |
| 990 for (size_t ch = 0; ch < matrix.size(); ++ch) { | 1001 for (size_t ch = 0; ch < matrix.size(); ++ch) { |
| 991 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(), | 1002 channel_mask[ch] = std::any_of(matrix[ch].begin(), matrix[ch].end(), |
| 992 [](float mix) { return !!mix; }); | 1003 [](float mix) { return !!mix; }); |
| 993 } | 1004 } |
| 994 algorithm_->SetChannelMask(std::move(channel_mask)); | 1005 algorithm_->SetChannelMask(std::move(channel_mask)); |
| 995 } | 1006 } |
| 996 | 1007 |
| 997 } // namespace media | 1008 } // namespace media |
| OLD | NEW |