| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 pending_read_(false), | 56 pending_read_(false), |
| 57 received_end_of_stream_(false), | 57 received_end_of_stream_(false), |
| 58 rendered_end_of_stream_(false), | 58 rendered_end_of_stream_(false), |
| 59 is_suspending_(false), | 59 is_suspending_(false), |
| 60 weak_factory_(this) { | 60 weak_factory_(this) { |
| 61 audio_buffer_stream_->set_splice_observer(base::Bind( | 61 audio_buffer_stream_->set_splice_observer(base::Bind( |
| 62 &AudioRendererImpl::OnNewSpliceBuffer, weak_factory_.GetWeakPtr())); | 62 &AudioRendererImpl::OnNewSpliceBuffer, weak_factory_.GetWeakPtr())); |
| 63 audio_buffer_stream_->set_config_change_observer(base::Bind( | 63 audio_buffer_stream_->set_config_change_observer(base::Bind( |
| 64 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); | 64 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); |
| 65 | 65 |
| 66 // Suspend and resume work differently on Android and are handled at a higher | |
| 67 // level than here. OnSuspend() notifications will be delivered a few seconds | |
| 68 // after an application is backgrounded, even if it should still be playing. | |
| 69 // See http://crbug.com/623066 for more details. | |
| 70 #if !defined(OS_ANDROID) | |
| 71 // Tests may not have a power monitor. | 66 // Tests may not have a power monitor. |
| 72 base::PowerMonitor* monitor = base::PowerMonitor::Get(); | 67 base::PowerMonitor* monitor = base::PowerMonitor::Get(); |
| 73 if (!monitor) | 68 if (!monitor) |
| 74 return; | 69 return; |
| 75 | 70 |
| 76 // PowerObserver's must be added and removed from the same thread, but we | 71 // PowerObserver's must be added and removed from the same thread, but we |
| 77 // won't remove the observer until we're destructed on |task_runner_| so we | 72 // won't remove the observer until we're destructed on |task_runner_| so we |
| 78 // must post it here if we're on the wrong thread. | 73 // must post it here if we're on the wrong thread. |
| 79 if (task_runner_->BelongsToCurrentThread()) { | 74 if (task_runner_->BelongsToCurrentThread()) { |
| 80 monitor->AddObserver(this); | 75 monitor->AddObserver(this); |
| 81 } else { | 76 } else { |
| 82 // Safe to post this without a WeakPtr because this class must be destructed | 77 // Safe to post this without a WeakPtr because this class must be destructed |
| 83 // on the same thread and construction has not completed yet. | 78 // on the same thread and construction has not completed yet. |
| 84 task_runner_->PostTask(FROM_HERE, | 79 task_runner_->PostTask(FROM_HERE, |
| 85 base::Bind(&base::PowerMonitor::AddObserver, | 80 base::Bind(&base::PowerMonitor::AddObserver, |
| 86 base::Unretained(monitor), this)); | 81 base::Unretained(monitor), this)); |
| 87 } | 82 } |
| 88 #endif | 83 |
| 89 // Do not add anything below this line since the above actions are only safe | 84 // Do not add anything below this line since the above actions are only safe |
| 90 // as the last lines of the constructor. | 85 // as the last lines of the constructor. |
| 91 } | 86 } |
| 92 | 87 |
| 93 AudioRendererImpl::~AudioRendererImpl() { | 88 AudioRendererImpl::~AudioRendererImpl() { |
| 94 DVLOG(1) << __func__; | 89 DVLOG(1) << __func__; |
| 95 DCHECK(task_runner_->BelongsToCurrentThread()); | 90 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 96 #if !defined(OS_ANDROID) | |
| 97 if (base::PowerMonitor::Get()) | 91 if (base::PowerMonitor::Get()) |
| 98 base::PowerMonitor::Get()->RemoveObserver(this); | 92 base::PowerMonitor::Get()->RemoveObserver(this); |
| 99 #endif | |
| 100 | 93 |
| 101 // If Render() is in progress, this call will wait for Render() to finish. | 94 // If Render() is in progress, this call will wait for Render() to finish. |
| 102 // After this call, the |sink_| will not call back into |this| anymore. | 95 // After this call, the |sink_| will not call back into |this| anymore. |
| 103 sink_->Stop(); | 96 sink_->Stop(); |
| 104 | 97 |
| 105 if (!init_cb_.is_null()) | 98 if (!init_cb_.is_null()) |
| 106 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); | 99 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); |
| 107 } | 100 } |
| 108 | 101 |
| 109 void AudioRendererImpl::StartTicking() { | 102 void AudioRendererImpl::StartTicking() { |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 DCHECK_NE(buffering_state_, buffering_state); | 961 DCHECK_NE(buffering_state_, buffering_state); |
| 969 lock_.AssertAcquired(); | 962 lock_.AssertAcquired(); |
| 970 buffering_state_ = buffering_state; | 963 buffering_state_ = buffering_state; |
| 971 | 964 |
| 972 task_runner_->PostTask( | 965 task_runner_->PostTask( |
| 973 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, | 966 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, |
| 974 weak_factory_.GetWeakPtr(), buffering_state_)); | 967 weak_factory_.GetWeakPtr(), buffering_state_)); |
| 975 } | 968 } |
| 976 | 969 |
| 977 } // namespace media | 970 } // namespace media |
| OLD | NEW |