| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 14 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
| 15 #include "base/synchronization/condition_variable.h" | 16 #include "base/synchronization/condition_variable.h" |
| 16 #include "media/filters/rtc_video_decoder.h" | 17 #include "media/filters/rtc_video_decoder.h" |
| 17 #include "media/base/clock.h" | 18 #include "media/base/clock.h" |
| 18 #include "media/base/filter_collection.h" | 19 #include "media/base/filter_collection.h" |
| 19 #include "media/base/media_format.h" | 20 #include "media/base/media_format.h" |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 message_loop_->PostTask(FROM_HERE, | 569 message_loop_->PostTask(FROM_HERE, |
| 569 NewRunnableMethod(this, &PipelineImpl::InitializeTask)); | 570 NewRunnableMethod(this, &PipelineImpl::InitializeTask)); |
| 570 } | 571 } |
| 571 | 572 |
| 572 // Called from any thread. | 573 // Called from any thread. |
| 573 void PipelineImpl::OnFilterStateTransition() { | 574 void PipelineImpl::OnFilterStateTransition() { |
| 574 message_loop_->PostTask(FROM_HERE, | 575 message_loop_->PostTask(FROM_HERE, |
| 575 NewRunnableMethod(this, &PipelineImpl::FilterStateTransitionTask)); | 576 NewRunnableMethod(this, &PipelineImpl::FilterStateTransitionTask)); |
| 576 } | 577 } |
| 577 | 578 |
| 579 // Called from any thread. |
| 580 // This method makes the FilterStatusCB behave like a FilterCallback. It |
| 581 // makes it look like a host()->SetError() call followed by a call to |
| 582 // OnFilterStateTransition() when errors occur. |
| 583 // |
| 584 // TODO: Revisit this code when SetError() is removed from FilterHost and |
| 585 // all the FilterCallbacks are converted to FilterStatusCB. |
| 586 void PipelineImpl::OnFilterStateTransitionWithStatus(PipelineStatus status) { |
| 587 if (status != PIPELINE_OK) |
| 588 SetError(status); |
| 589 OnFilterStateTransition(); |
| 590 } |
| 591 |
| 578 void PipelineImpl::OnTeardownStateTransition() { | 592 void PipelineImpl::OnTeardownStateTransition() { |
| 579 message_loop_->PostTask(FROM_HERE, | 593 message_loop_->PostTask(FROM_HERE, |
| 580 NewRunnableMethod(this, &PipelineImpl::TeardownStateTransitionTask)); | 594 NewRunnableMethod(this, &PipelineImpl::TeardownStateTransitionTask)); |
| 581 } | 595 } |
| 582 | 596 |
| 583 // Called from any thread. | 597 // Called from any thread. |
| 584 void PipelineImpl::OnUpdateStatistics(const PipelineStatistics& stats) { | 598 void PipelineImpl::OnUpdateStatistics(const PipelineStatistics& stats) { |
| 585 base::AutoLock auto_lock(lock_); | 599 base::AutoLock auto_lock(lock_); |
| 586 statistics_.audio_bytes_decoded += stats.audio_bytes_decoded; | 600 statistics_.audio_bytes_decoded += stats.audio_bytes_decoded; |
| 587 statistics_.video_bytes_decoded += stats.video_bytes_decoded; | 601 statistics_.video_bytes_decoded += stats.video_bytes_decoded; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 // Initialization was successful, we are now considered paused, so it's safe | 717 // Initialization was successful, we are now considered paused, so it's safe |
| 704 // to set the initial playback rate and volume. | 718 // to set the initial playback rate and volume. |
| 705 PreloadChangedTask(GetPreload()); | 719 PreloadChangedTask(GetPreload()); |
| 706 PlaybackRateChangedTask(GetPlaybackRate()); | 720 PlaybackRateChangedTask(GetPlaybackRate()); |
| 707 VolumeChangedTask(GetVolume()); | 721 VolumeChangedTask(GetVolume()); |
| 708 | 722 |
| 709 // Fire the seek request to get the filters to preroll. | 723 // Fire the seek request to get the filters to preroll. |
| 710 seek_pending_ = true; | 724 seek_pending_ = true; |
| 711 set_state(kSeeking); | 725 set_state(kSeeking); |
| 712 seek_timestamp_ = base::TimeDelta(); | 726 seek_timestamp_ = base::TimeDelta(); |
| 713 pipeline_filter_->Seek(seek_timestamp_, | 727 pipeline_filter_->Seek( |
| 714 NewCallback(this, &PipelineImpl::OnFilterStateTransition)); | 728 seek_timestamp_, |
| 729 base::Bind(&PipelineImpl::OnFilterStateTransitionWithStatus, this)); |
| 715 } | 730 } |
| 716 } | 731 } |
| 717 | 732 |
| 718 // This method is called as a result of the client calling Pipeline::Stop() or | 733 // This method is called as a result of the client calling Pipeline::Stop() or |
| 719 // as the result of an error condition. | 734 // as the result of an error condition. |
| 720 // We stop the filters in the reverse order. | 735 // We stop the filters in the reverse order. |
| 721 // | 736 // |
| 722 // TODO(scherkus): beware! this can get posted multiple times since we post | 737 // TODO(scherkus): beware! this can get posted multiple times since we post |
| 723 // Stop() tasks even if we've already stopped. Perhaps this should no-op for | 738 // Stop() tasks even if we've already stopped. Perhaps this should no-op for |
| 724 // additional calls, however most of this logic will be changing. | 739 // additional calls, however most of this logic will be changing. |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 // Carry out the action for the current state. | 960 // Carry out the action for the current state. |
| 946 if (TransientState(state_)) { | 961 if (TransientState(state_)) { |
| 947 if (state_ == kPausing) { | 962 if (state_ == kPausing) { |
| 948 pipeline_filter_->Pause( | 963 pipeline_filter_->Pause( |
| 949 NewCallback(this, &PipelineImpl::OnFilterStateTransition)); | 964 NewCallback(this, &PipelineImpl::OnFilterStateTransition)); |
| 950 } else if (state_ == kFlushing) { | 965 } else if (state_ == kFlushing) { |
| 951 pipeline_filter_->Flush( | 966 pipeline_filter_->Flush( |
| 952 NewCallback(this, &PipelineImpl::OnFilterStateTransition)); | 967 NewCallback(this, &PipelineImpl::OnFilterStateTransition)); |
| 953 } else if (state_ == kSeeking) { | 968 } else if (state_ == kSeeking) { |
| 954 pipeline_filter_->Seek(seek_timestamp_, | 969 pipeline_filter_->Seek(seek_timestamp_, |
| 955 NewCallback(this, &PipelineImpl::OnFilterStateTransition)); | 970 base::Bind(&PipelineImpl::OnFilterStateTransitionWithStatus, this)); |
| 956 } else if (state_ == kStarting) { | 971 } else if (state_ == kStarting) { |
| 957 pipeline_filter_->Play( | 972 pipeline_filter_->Play( |
| 958 NewCallback(this, &PipelineImpl::OnFilterStateTransition)); | 973 NewCallback(this, &PipelineImpl::OnFilterStateTransition)); |
| 959 } else if (state_ == kStopping) { | 974 } else if (state_ == kStopping) { |
| 960 pipeline_filter_->Stop( | 975 pipeline_filter_->Stop( |
| 961 NewCallback(this, &PipelineImpl::OnFilterStateTransition)); | 976 NewCallback(this, &PipelineImpl::OnFilterStateTransition)); |
| 962 } else { | 977 } else { |
| 963 NOTREACHED() << "Unexpected state: " << state_; | 978 NOTREACHED() << "Unexpected state: " << state_; |
| 964 } | 979 } |
| 965 } else if (state_ == kStarted) { | 980 } else if (state_ == kStarted) { |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 case kStopping: | 1288 case kStopping: |
| 1274 case kStopped: | 1289 case kStopped: |
| 1275 NOTREACHED() << "Unexpected state for teardown: " << state_; | 1290 NOTREACHED() << "Unexpected state for teardown: " << state_; |
| 1276 break; | 1291 break; |
| 1277 // default: intentionally left out to force new states to cause compiler | 1292 // default: intentionally left out to force new states to cause compiler |
| 1278 // errors. | 1293 // errors. |
| 1279 }; | 1294 }; |
| 1280 } | 1295 } |
| 1281 | 1296 |
| 1282 } // namespace media | 1297 } // namespace media |
| OLD | NEW |