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