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/filters/audio_renderer_impl.h" | 5 #include "media/filters/audio_renderer_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 audio_buffer_stream_.set_config_change_observer(base::Bind( | 66 audio_buffer_stream_.set_config_change_observer(base::Bind( |
67 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); | 67 &AudioRendererImpl::OnConfigChange, weak_factory_.GetWeakPtr())); |
68 } | 68 } |
69 | 69 |
70 AudioRendererImpl::~AudioRendererImpl() { | 70 AudioRendererImpl::~AudioRendererImpl() { |
71 // Stop() should have been called and |algorithm_| should have been destroyed. | 71 // Stop() should have been called and |algorithm_| should have been destroyed. |
72 DCHECK(state_ == kUninitialized || state_ == kStopped); | 72 DCHECK(state_ == kUninitialized || state_ == kStopped); |
73 DCHECK(!algorithm_.get()); | 73 DCHECK(!algorithm_.get()); |
74 } | 74 } |
75 | 75 |
76 void AudioRendererImpl::Play(const base::Closure& callback) { | 76 void AudioRendererImpl::Play() { |
77 DCHECK(task_runner_->BelongsToCurrentThread()); | 77 DCHECK(task_runner_->BelongsToCurrentThread()); |
78 | 78 |
79 base::AutoLock auto_lock(lock_); | 79 base::AutoLock auto_lock(lock_); |
80 DCHECK_EQ(state_, kPaused); | 80 DCHECK_EQ(state_, kPaused); |
81 ChangeState_Locked(kPlaying); | 81 ChangeState_Locked(kPlaying); |
82 callback.Run(); | |
83 earliest_end_time_ = now_cb_.Run(); | 82 earliest_end_time_ = now_cb_.Run(); |
84 | 83 |
85 if (algorithm_->playback_rate() != 0) | 84 if (algorithm_->playback_rate() != 0) |
86 DoPlay_Locked(); | 85 DoPlay_Locked(); |
87 else | 86 else |
88 DCHECK(!sink_playing_); | 87 DCHECK(!sink_playing_); |
89 } | 88 } |
90 | 89 |
91 void AudioRendererImpl::DoPlay_Locked() { | 90 void AudioRendererImpl::DoPlay_Locked() { |
92 DCHECK(task_runner_->BelongsToCurrentThread()); | 91 DCHECK(task_runner_->BelongsToCurrentThread()); |
93 lock_.AssertAcquired(); | 92 lock_.AssertAcquired(); |
94 earliest_end_time_ = now_cb_.Run(); | 93 earliest_end_time_ = now_cb_.Run(); |
95 | 94 |
96 if ((state_ == kPlaying || state_ == kRebuffering || state_ == kUnderflow) && | 95 if ((state_ == kPlaying || state_ == kRebuffering || state_ == kUnderflow) && |
97 !sink_playing_) { | 96 !sink_playing_) { |
98 { | 97 { |
99 base::AutoUnlock auto_unlock(lock_); | 98 base::AutoUnlock auto_unlock(lock_); |
100 sink_->Play(); | 99 sink_->Play(); |
101 } | 100 } |
102 | 101 |
103 sink_playing_ = true; | 102 sink_playing_ = true; |
104 } | 103 } |
105 } | 104 } |
106 | 105 |
107 void AudioRendererImpl::Pause(const base::Closure& callback) { | 106 void AudioRendererImpl::Pause() { |
108 DCHECK(task_runner_->BelongsToCurrentThread()); | 107 DCHECK(task_runner_->BelongsToCurrentThread()); |
109 | 108 |
110 base::AutoLock auto_lock(lock_); | 109 base::AutoLock auto_lock(lock_); |
111 DCHECK(state_ == kPlaying || state_ == kUnderflow || | 110 DCHECK(state_ == kPlaying || state_ == kUnderflow || |
112 state_ == kRebuffering) << "state_ == " << state_; | 111 state_ == kRebuffering) << "state_ == " << state_; |
113 ChangeState_Locked(kPaused); | 112 ChangeState_Locked(kPaused); |
114 | 113 |
115 DoPause_Locked(); | 114 DoPause_Locked(); |
116 | |
117 callback.Run(); | |
118 } | 115 } |
119 | 116 |
120 void AudioRendererImpl::DoPause_Locked() { | 117 void AudioRendererImpl::DoPause_Locked() { |
121 DCHECK(task_runner_->BelongsToCurrentThread()); | 118 DCHECK(task_runner_->BelongsToCurrentThread()); |
122 lock_.AssertAcquired(); | 119 lock_.AssertAcquired(); |
123 | 120 |
124 if (sink_playing_) { | 121 if (sink_playing_) { |
125 { | 122 { |
126 base::AutoUnlock auto_unlock(lock_); | 123 base::AutoUnlock auto_unlock(lock_); |
127 sink_->Pause(); | 124 sink_->Pause(); |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 DCHECK(expecting_config_changes_); | 744 DCHECK(expecting_config_changes_); |
748 buffer_converter_->ResetTimestampState(); | 745 buffer_converter_->ResetTimestampState(); |
749 // Drain flushed buffers from the converter so the AudioSplicer receives all | 746 // Drain flushed buffers from the converter so the AudioSplicer receives all |
750 // data ahead of any OnNewSpliceBuffer() calls. Since discontinuities should | 747 // data ahead of any OnNewSpliceBuffer() calls. Since discontinuities should |
751 // only appear after config changes, AddInput() should never fail here. | 748 // only appear after config changes, AddInput() should never fail here. |
752 while (buffer_converter_->HasNextBuffer()) | 749 while (buffer_converter_->HasNextBuffer()) |
753 CHECK(splicer_->AddInput(buffer_converter_->GetNextBuffer())); | 750 CHECK(splicer_->AddInput(buffer_converter_->GetNextBuffer())); |
754 } | 751 } |
755 | 752 |
756 } // namespace media | 753 } // namespace media |
OLD | NEW |