Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: media/renderers/audio_renderer_impl.cc

Issue 2098703005: Restrict OnSuspend() restrictions for audio to non-Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)
66 // Tests may not have a power monitor. 71 // Tests may not have a power monitor.
67 base::PowerMonitor* monitor = base::PowerMonitor::Get(); 72 base::PowerMonitor* monitor = base::PowerMonitor::Get();
68 if (!monitor) 73 if (!monitor)
69 return; 74 return;
70 75
71 // PowerObserver's must be added and removed from the same thread, but we 76 // PowerObserver's must be added and removed from the same thread, but we
72 // won't remove the observer until we're destructed on |task_runner_| so we 77 // won't remove the observer until we're destructed on |task_runner_| so we
73 // must post it here if we're on the wrong thread. 78 // must post it here if we're on the wrong thread.
74 if (task_runner_->BelongsToCurrentThread()) { 79 if (task_runner_->BelongsToCurrentThread()) {
75 monitor->AddObserver(this); 80 monitor->AddObserver(this);
76 } else { 81 } else {
77 // Safe to post this without a WeakPtr because this class must be destructed 82 // Safe to post this without a WeakPtr because this class must be destructed
78 // on the same thread and construction has not completed yet. 83 // on the same thread and construction has not completed yet.
79 task_runner_->PostTask(FROM_HERE, 84 task_runner_->PostTask(FROM_HERE,
80 base::Bind(&base::PowerMonitor::AddObserver, 85 base::Bind(&base::PowerMonitor::AddObserver,
81 base::Unretained(monitor), this)); 86 base::Unretained(monitor), this));
82 } 87 }
88 #endif
83 // Do not add anything below this line since the above actions are only safe 89 // Do not add anything below this line since the above actions are only safe
84 // as the last lines of the constructor. 90 // as the last lines of the constructor.
85 } 91 }
86 92
87 AudioRendererImpl::~AudioRendererImpl() { 93 AudioRendererImpl::~AudioRendererImpl() {
88 DVLOG(1) << __FUNCTION__; 94 DVLOG(1) << __FUNCTION__;
89 DCHECK(task_runner_->BelongsToCurrentThread()); 95 DCHECK(task_runner_->BelongsToCurrentThread());
96 #if !defined(OS_ANDROID)
90 if (base::PowerMonitor::Get()) 97 if (base::PowerMonitor::Get())
91 base::PowerMonitor::Get()->RemoveObserver(this); 98 base::PowerMonitor::Get()->RemoveObserver(this);
99 #endif
92 100
93 // If Render() is in progress, this call will wait for Render() to finish. 101 // 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. 102 // After this call, the |sink_| will not call back into |this| anymore.
95 sink_->Stop(); 103 sink_->Stop();
96 104
97 if (!init_cb_.is_null()) 105 if (!init_cb_.is_null())
98 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); 106 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT);
99 } 107 }
100 108
101 void AudioRendererImpl::StartTicking() { 109 void AudioRendererImpl::StartTicking() {
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 DCHECK_NE(buffering_state_, buffering_state); 967 DCHECK_NE(buffering_state_, buffering_state);
960 lock_.AssertAcquired(); 968 lock_.AssertAcquired();
961 buffering_state_ = buffering_state; 969 buffering_state_ = buffering_state;
962 970
963 task_runner_->PostTask( 971 task_runner_->PostTask(
964 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, 972 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange,
965 weak_factory_.GetWeakPtr(), buffering_state_)); 973 weak_factory_.GetWeakPtr(), buffering_state_));
966 } 974 }
967 975
968 } // namespace media 976 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698