OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_base.h" | 5 #include "media/filters/audio_renderer_base.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "media/base/filter_host.h" | 10 #include "media/base/filter_host.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 delete callback; | 60 delete callback; |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 void AudioRendererBase::Seek(base::TimeDelta time, FilterCallback* callback) { | 64 void AudioRendererBase::Seek(base::TimeDelta time, FilterCallback* callback) { |
65 AutoLock auto_lock(lock_); | 65 AutoLock auto_lock(lock_); |
66 DCHECK_EQ(kPaused, state_); | 66 DCHECK_EQ(kPaused, state_); |
67 DCHECK_EQ(0u, pending_reads_) << "Pending reads should have completed"; | 67 DCHECK_EQ(0u, pending_reads_) << "Pending reads should have completed"; |
68 state_ = kSeeking; | 68 state_ = kSeeking; |
69 seek_callback_.reset(callback); | 69 seek_callback_.reset(callback); |
| 70 seek_timestamp_ = time; |
70 | 71 |
71 // Throw away everything and schedule our reads. | 72 // Throw away everything and schedule our reads. |
72 last_fill_buffer_time_ = base::TimeDelta(); | 73 last_fill_buffer_time_ = base::TimeDelta(); |
73 recieved_end_of_stream_ = false; | 74 recieved_end_of_stream_ = false; |
74 rendered_end_of_stream_ = false; | 75 rendered_end_of_stream_ = false; |
75 | 76 |
76 // |algorithm_| will request more reads. | 77 // |algorithm_| will request more reads. |
77 algorithm_->FlushBuffers(); | 78 algorithm_->FlushBuffers(); |
78 } | 79 } |
79 | 80 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 DCHECK_GT(pending_reads_, 0u); | 141 DCHECK_GT(pending_reads_, 0u); |
141 --pending_reads_; | 142 --pending_reads_; |
142 | 143 |
143 // TODO(scherkus): this happens due to a race, primarily because Stop() is a | 144 // TODO(scherkus): this happens due to a race, primarily because Stop() is a |
144 // synchronous call when it should be asynchronous and accept a callback. | 145 // synchronous call when it should be asynchronous and accept a callback. |
145 // Refer to http://crbug.com/16059 | 146 // Refer to http://crbug.com/16059 |
146 if (state_ == kStopped) { | 147 if (state_ == kStopped) { |
147 return; | 148 return; |
148 } | 149 } |
149 | 150 |
150 // Don't enqueue an end-of-stream buffer because it has no data. | 151 // Don't enqueue an end-of-stream buffer because it has no data, otherwise |
| 152 // discard decoded audio data until we reach our desired seek timestamp. |
151 if (buffer_in->IsEndOfStream()) { | 153 if (buffer_in->IsEndOfStream()) { |
152 recieved_end_of_stream_ = true; | 154 recieved_end_of_stream_ = true; |
| 155 } else if (state_ == kSeeking && !buffer_in->IsEndOfStream() && |
| 156 (buffer_in->GetTimestamp() + buffer_in->GetDuration()) < |
| 157 seek_timestamp_) { |
| 158 ScheduleRead_Locked(); |
153 } else { | 159 } else { |
154 // Note: Calling this may schedule more reads. | 160 // Note: Calling this may schedule more reads. |
155 algorithm_->EnqueueBuffer(buffer_in); | 161 algorithm_->EnqueueBuffer(buffer_in); |
156 } | 162 } |
157 | 163 |
158 // Check for our preroll complete condition. | 164 // Check for our preroll complete condition. |
159 if (state_ == kSeeking) { | 165 if (state_ == kSeeking) { |
160 DCHECK(seek_callback_.get()); | 166 DCHECK(seek_callback_.get()); |
161 if (algorithm_->IsQueueFull() || recieved_end_of_stream_) { | 167 if (algorithm_->IsQueueFull() || recieved_end_of_stream_) { |
162 // Transition into paused whether we have data in |algorithm_| or not. | 168 // Transition into paused whether we have data in |algorithm_| or not. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 266 |
261 void AudioRendererBase::SetPlaybackRate(float playback_rate) { | 267 void AudioRendererBase::SetPlaybackRate(float playback_rate) { |
262 algorithm_->set_playback_rate(playback_rate); | 268 algorithm_->set_playback_rate(playback_rate); |
263 } | 269 } |
264 | 270 |
265 float AudioRendererBase::GetPlaybackRate() { | 271 float AudioRendererBase::GetPlaybackRate() { |
266 return algorithm_->playback_rate(); | 272 return algorithm_->playback_rate(); |
267 } | 273 } |
268 | 274 |
269 } // namespace media | 275 } // namespace media |
OLD | NEW |