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/base/pipeline.h" | 5 #include "media/base/pipeline.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 return; | 182 return; |
183 | 183 |
184 base::AutoLock auto_lock(lock_); | 184 base::AutoLock auto_lock(lock_); |
185 volume_ = volume; | 185 volume_ = volume; |
186 if (running_ && !tearing_down_) { | 186 if (running_ && !tearing_down_) { |
187 message_loop_->PostTask(FROM_HERE, base::Bind( | 187 message_loop_->PostTask(FROM_HERE, base::Bind( |
188 &Pipeline::VolumeChangedTask, this, volume)); | 188 &Pipeline::VolumeChangedTask, this, volume)); |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 Preload Pipeline::GetPreload() const { | |
193 base::AutoLock auto_lock(lock_); | |
194 return preload_; | |
195 } | |
196 | |
197 void Pipeline::SetPreload(Preload preload) { | |
198 base::AutoLock auto_lock(lock_); | |
199 preload_ = preload; | |
200 if (running_ && !tearing_down_) { | |
201 message_loop_->PostTask(FROM_HERE, base::Bind( | |
202 &Pipeline::PreloadChangedTask, this, preload)); | |
203 } | |
204 } | |
205 | |
206 base::TimeDelta Pipeline::GetCurrentTime() const { | 192 base::TimeDelta Pipeline::GetCurrentTime() const { |
207 base::AutoLock auto_lock(lock_); | 193 base::AutoLock auto_lock(lock_); |
208 return GetCurrentTime_Locked(); | 194 return GetCurrentTime_Locked(); |
209 } | 195 } |
210 | 196 |
211 base::TimeDelta Pipeline::GetCurrentTime_Locked() const { | 197 base::TimeDelta Pipeline::GetCurrentTime_Locked() const { |
212 lock_.AssertAcquired(); | 198 lock_.AssertAcquired(); |
213 return clock_->Elapsed(); | 199 return clock_->Elapsed(); |
214 } | 200 } |
215 | 201 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 tearing_down_ = false; | 302 tearing_down_ = false; |
317 error_caused_teardown_ = false; | 303 error_caused_teardown_ = false; |
318 playback_rate_change_pending_ = false; | 304 playback_rate_change_pending_ = false; |
319 buffered_time_ = kZero; | 305 buffered_time_ = kZero; |
320 buffered_bytes_ = 0; | 306 buffered_bytes_ = 0; |
321 streaming_ = false; | 307 streaming_ = false; |
322 local_source_ = false; | 308 local_source_ = false; |
323 total_bytes_ = 0; | 309 total_bytes_ = 0; |
324 natural_size_.SetSize(0, 0); | 310 natural_size_.SetSize(0, 0); |
325 volume_ = 1.0f; | 311 volume_ = 1.0f; |
326 preload_ = AUTO; | |
327 playback_rate_ = 0.0f; | 312 playback_rate_ = 0.0f; |
328 pending_playback_rate_ = 0.0f; | 313 pending_playback_rate_ = 0.0f; |
329 status_ = PIPELINE_OK; | 314 status_ = PIPELINE_OK; |
330 has_audio_ = false; | 315 has_audio_ = false; |
331 has_video_ = false; | 316 has_video_ = false; |
332 waiting_for_clock_update_ = false; | 317 waiting_for_clock_update_ = false; |
333 audio_disabled_ = false; | 318 audio_disabled_ = false; |
334 clock_->Reset(); | 319 clock_->Reset(); |
335 download_rate_monitor_.Reset(); | 320 download_rate_monitor_.Reset(); |
336 } | 321 } |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 | 702 |
718 if (audio_disabled_) { | 703 if (audio_disabled_) { |
719 // Audio was disabled at some point during initialization. Notify | 704 // Audio was disabled at some point during initialization. Notify |
720 // the pipeline filter now that it has been initialized. | 705 // the pipeline filter now that it has been initialized. |
721 demuxer_->OnAudioRendererDisabled(); | 706 demuxer_->OnAudioRendererDisabled(); |
722 pipeline_filter_->OnAudioRendererDisabled(); | 707 pipeline_filter_->OnAudioRendererDisabled(); |
723 } | 708 } |
724 | 709 |
725 // Initialization was successful, we are now considered paused, so it's safe | 710 // Initialization was successful, we are now considered paused, so it's safe |
726 // to set the initial playback rate and volume. | 711 // to set the initial playback rate and volume. |
727 PreloadChangedTask(GetPreload()); | |
728 PlaybackRateChangedTask(GetPlaybackRate()); | 712 PlaybackRateChangedTask(GetPlaybackRate()); |
729 VolumeChangedTask(GetVolume()); | 713 VolumeChangedTask(GetVolume()); |
730 | 714 |
731 // Fire the seek request to get the filters to preroll. | 715 // Fire the seek request to get the filters to preroll. |
732 seek_pending_ = true; | 716 seek_pending_ = true; |
733 SetState(kSeeking); | 717 SetState(kSeeking); |
734 seek_timestamp_ = demuxer_->GetStartTime(); | 718 seek_timestamp_ = demuxer_->GetStartTime(); |
735 DoSeek(seek_timestamp_); | 719 DoSeek(seek_timestamp_); |
736 } | 720 } |
737 } | 721 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 | 819 |
836 void Pipeline::VolumeChangedTask(float volume) { | 820 void Pipeline::VolumeChangedTask(float volume) { |
837 DCHECK_EQ(MessageLoop::current(), message_loop_); | 821 DCHECK_EQ(MessageLoop::current(), message_loop_); |
838 if (!running_ || tearing_down_) | 822 if (!running_ || tearing_down_) |
839 return; | 823 return; |
840 | 824 |
841 if (audio_renderer_) | 825 if (audio_renderer_) |
842 audio_renderer_->SetVolume(volume); | 826 audio_renderer_->SetVolume(volume); |
843 } | 827 } |
844 | 828 |
845 void Pipeline::PreloadChangedTask(Preload preload) { | |
846 DCHECK_EQ(MessageLoop::current(), message_loop_); | |
847 if (!running_ || tearing_down_) | |
848 return; | |
849 | |
850 if (demuxer_) | |
851 demuxer_->SetPreload(preload); | |
852 } | |
853 | |
854 void Pipeline::SeekTask(base::TimeDelta time, | 829 void Pipeline::SeekTask(base::TimeDelta time, |
855 const PipelineStatusCB& seek_cb) { | 830 const PipelineStatusCB& seek_cb) { |
856 DCHECK_EQ(MessageLoop::current(), message_loop_); | 831 DCHECK_EQ(MessageLoop::current(), message_loop_); |
857 DCHECK(!IsPipelineStopPending()); | 832 DCHECK(!IsPipelineStopPending()); |
858 | 833 |
859 // Suppress seeking if we're not fully started. | 834 // Suppress seeking if we're not fully started. |
860 if (state_ != kStarted && state_ != kEnded) { | 835 if (state_ != kStarted && state_ != kEnded) { |
861 // TODO(scherkus): should we run the callback? I'm tempted to say the API | 836 // TODO(scherkus): should we run the callback? I'm tempted to say the API |
862 // will only execute the first Seek() request. | 837 // will only execute the first Seek() request. |
863 VLOG(1) << "Media pipeline has not started, ignoring seek to " | 838 VLOG(1) << "Media pipeline has not started, ignoring seek to " |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { | 1385 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { |
1411 lock_.AssertAcquired(); | 1386 lock_.AssertAcquired(); |
1412 if (!waiting_for_clock_update_) | 1387 if (!waiting_for_clock_update_) |
1413 return; | 1388 return; |
1414 | 1389 |
1415 waiting_for_clock_update_ = false; | 1390 waiting_for_clock_update_ = false; |
1416 clock_->Play(); | 1391 clock_->Play(); |
1417 } | 1392 } |
1418 | 1393 |
1419 } // namespace media | 1394 } // namespace media |
OLD | NEW |