OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // TODO(scherkus): clean up PipelineImpl... too many crazy function names, | 5 // TODO(scherkus): clean up PipelineImpl... too many crazy function names, |
6 // potential deadlocks, etc... | 6 // potential deadlocks, etc... |
7 | 7 |
8 #include "media/base/pipeline_impl.h" | 8 #include "media/base/pipeline_impl.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 351 } |
352 | 352 |
353 void PipelineImpl::ResetState() { | 353 void PipelineImpl::ResetState() { |
354 base::AutoLock auto_lock(lock_); | 354 base::AutoLock auto_lock(lock_); |
355 const base::TimeDelta kZero; | 355 const base::TimeDelta kZero; |
356 running_ = false; | 356 running_ = false; |
357 stop_pending_ = false; | 357 stop_pending_ = false; |
358 seek_pending_ = false; | 358 seek_pending_ = false; |
359 tearing_down_ = false; | 359 tearing_down_ = false; |
360 error_caused_teardown_ = false; | 360 error_caused_teardown_ = false; |
| 361 playback_rate_change_pending_ = false; |
361 duration_ = kZero; | 362 duration_ = kZero; |
362 buffered_time_ = kZero; | 363 buffered_time_ = kZero; |
363 buffered_bytes_ = 0; | 364 buffered_bytes_ = 0; |
364 streaming_ = false; | 365 streaming_ = false; |
365 loaded_ = false; | 366 loaded_ = false; |
366 total_bytes_ = 0; | 367 total_bytes_ = 0; |
367 video_width_ = 0; | 368 video_width_ = 0; |
368 video_height_ = 0; | 369 video_height_ = 0; |
369 volume_ = 1.0f; | 370 volume_ = 1.0f; |
370 preload_ = AUTO; | 371 preload_ = AUTO; |
371 playback_rate_ = 0.0f; | 372 playback_rate_ = 0.0f; |
| 373 pending_playback_rate_ = 0.0f; |
372 status_ = PIPELINE_OK; | 374 status_ = PIPELINE_OK; |
373 has_audio_ = false; | 375 has_audio_ = false; |
374 has_video_ = false; | 376 has_video_ = false; |
375 waiting_for_clock_update_ = false; | 377 waiting_for_clock_update_ = false; |
376 audio_disabled_ = false; | 378 audio_disabled_ = false; |
377 clock_->SetTime(kZero); | 379 clock_->SetTime(kZero); |
378 } | 380 } |
379 | 381 |
380 void PipelineImpl::set_state(State next_state) { | 382 void PipelineImpl::set_state(State next_state) { |
381 state_ = next_state; | 383 state_ = next_state; |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 // it runs after any pending callbacks that are already queued. | 775 // it runs after any pending callbacks that are already queued. |
774 // |tearing_down_| is set early here to make sure that pending callbacks | 776 // |tearing_down_| is set early here to make sure that pending callbacks |
775 // don't modify the state before TeadDownPipeline() can run. | 777 // don't modify the state before TeadDownPipeline() can run. |
776 tearing_down_ = true; | 778 tearing_down_ = true; |
777 message_loop_->PostTask(FROM_HERE, | 779 message_loop_->PostTask(FROM_HERE, |
778 NewRunnableMethod(this, &PipelineImpl::TearDownPipeline)); | 780 NewRunnableMethod(this, &PipelineImpl::TearDownPipeline)); |
779 } | 781 } |
780 | 782 |
781 void PipelineImpl::PlaybackRateChangedTask(float playback_rate) { | 783 void PipelineImpl::PlaybackRateChangedTask(float playback_rate) { |
782 DCHECK_EQ(MessageLoop::current(), message_loop_); | 784 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 785 |
| 786 // Suppress rate change until after seeking. |
| 787 if (IsPipelineSeeking()) { |
| 788 pending_playback_rate_ = playback_rate; |
| 789 playback_rate_change_pending_ = true; |
| 790 return; |
| 791 } |
| 792 |
783 { | 793 { |
784 base::AutoLock auto_lock(lock_); | 794 base::AutoLock auto_lock(lock_); |
785 clock_->SetPlaybackRate(playback_rate); | 795 clock_->SetPlaybackRate(playback_rate); |
786 } | 796 } |
787 | 797 |
788 // Notify |pipeline_filter_| if it has been initialized. If initialization | 798 // Notify |pipeline_filter_| if it has been initialized. If initialization |
789 // hasn't completed yet, the playback rate will be set when initialization | 799 // hasn't completed yet, the playback rate will be set when initialization |
790 // completes. | 800 // completes. |
791 if (pipeline_filter_) { | 801 if (pipeline_filter_) { |
792 pipeline_filter_->SetPlaybackRate(playback_rate); | 802 pipeline_filter_->SetPlaybackRate(playback_rate); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 } else { | 962 } else { |
953 NOTREACHED() << "Unexpected state: " << state_; | 963 NOTREACHED() << "Unexpected state: " << state_; |
954 } | 964 } |
955 } else if (state_ == kStarted) { | 965 } else if (state_ == kStarted) { |
956 FinishInitialization(); | 966 FinishInitialization(); |
957 | 967 |
958 // Finally, reset our seeking timestamp back to zero. | 968 // Finally, reset our seeking timestamp back to zero. |
959 seek_timestamp_ = base::TimeDelta(); | 969 seek_timestamp_ = base::TimeDelta(); |
960 seek_pending_ = false; | 970 seek_pending_ = false; |
961 | 971 |
| 972 // If a playback rate change was requested during a seek, do it now that |
| 973 // the seek has compelted. |
| 974 if (playback_rate_change_pending_) { |
| 975 playback_rate_change_pending_ = false; |
| 976 PlaybackRateChangedTask(pending_playback_rate_); |
| 977 } |
| 978 |
962 base::AutoLock auto_lock(lock_); | 979 base::AutoLock auto_lock(lock_); |
963 // We use audio stream to update the clock. So if there is such a stream, | 980 // We use audio stream to update the clock. So if there is such a stream, |
964 // we pause the clock until we receive a valid timestamp. | 981 // we pause the clock until we receive a valid timestamp. |
965 waiting_for_clock_update_ = has_audio_; | 982 waiting_for_clock_update_ = has_audio_; |
966 if (!waiting_for_clock_update_) | 983 if (!waiting_for_clock_update_) |
967 clock_->Play(); | 984 clock_->Play(); |
968 | 985 |
969 if (IsPipelineStopPending()) { | 986 if (IsPipelineStopPending()) { |
970 // We had a pending stop request need to be honored right now. | 987 // We had a pending stop request need to be honored right now. |
971 TearDownPipeline(); | 988 TearDownPipeline(); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 case kStopping: | 1273 case kStopping: |
1257 case kStopped: | 1274 case kStopped: |
1258 NOTREACHED() << "Unexpected state for teardown: " << state_; | 1275 NOTREACHED() << "Unexpected state for teardown: " << state_; |
1259 break; | 1276 break; |
1260 // default: intentionally left out to force new states to cause compiler | 1277 // default: intentionally left out to force new states to cause compiler |
1261 // errors. | 1278 // errors. |
1262 }; | 1279 }; |
1263 } | 1280 } |
1264 | 1281 |
1265 } // namespace media | 1282 } // namespace media |
OLD | NEW |