| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 190 } |
| 191 | 191 |
| 192 void Pipeline::SetState(State next_state) { | 192 void Pipeline::SetState(State next_state) { |
| 193 if (state_ != kPlaying && next_state == kPlaying && | 193 if (state_ != kPlaying && next_state == kPlaying && |
| 194 !creation_time_.is_null()) { | 194 !creation_time_.is_null()) { |
| 195 UMA_HISTOGRAM_TIMES("Media.TimeToPipelineStarted", | 195 UMA_HISTOGRAM_TIMES("Media.TimeToPipelineStarted", |
| 196 default_tick_clock_.NowTicks() - creation_time_); | 196 default_tick_clock_.NowTicks() - creation_time_); |
| 197 creation_time_ = base::TimeTicks(); | 197 creation_time_ = base::TimeTicks(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 DVLOG(1) << GetStateString(state_) << " -> " << GetStateString(next_state); | 200 DVLOG(2) << GetStateString(state_) << " -> " << GetStateString(next_state); |
| 201 | 201 |
| 202 state_ = next_state; | 202 state_ = next_state; |
| 203 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(next_state)); | 203 media_log_->AddEvent(media_log_->CreatePipelineStateChangedEvent(next_state)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 #define RETURN_STRING(state) case state: return #state; | 206 #define RETURN_STRING(state) case state: return #state; |
| 207 | 207 |
| 208 const char* Pipeline::GetStateString(State state) { | 208 const char* Pipeline::GetStateString(State state) { |
| 209 switch (state) { | 209 switch (state) { |
| 210 RETURN_STRING(kCreated); | 210 RETURN_STRING(kCreated); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 } | 476 } |
| 477 | 477 |
| 478 void Pipeline::DoSeek( | 478 void Pipeline::DoSeek( |
| 479 base::TimeDelta seek_timestamp, | 479 base::TimeDelta seek_timestamp, |
| 480 const PipelineStatusCB& done_cb) { | 480 const PipelineStatusCB& done_cb) { |
| 481 DCHECK(task_runner_->BelongsToCurrentThread()); | 481 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 482 DCHECK(!pending_callbacks_.get()); | 482 DCHECK(!pending_callbacks_.get()); |
| 483 SerialRunner::Queue bound_fns; | 483 SerialRunner::Queue bound_fns; |
| 484 | 484 |
| 485 // Pause. | 485 // Pause. |
| 486 if (audio_renderer_) { |
| 487 bound_fns.Push(base::Bind( |
| 488 &AudioRenderer::Pause, base::Unretained(audio_renderer_.get()))); |
| 489 } |
| 486 if (text_renderer_) { | 490 if (text_renderer_) { |
| 487 bound_fns.Push(base::Bind( | 491 bound_fns.Push(base::Bind( |
| 488 &TextRenderer::Pause, base::Unretained(text_renderer_.get()))); | 492 &TextRenderer::Pause, base::Unretained(text_renderer_.get()))); |
| 489 } | 493 } |
| 490 | 494 |
| 491 // Flush. | 495 // Flush. |
| 492 if (audio_renderer_) { | 496 if (audio_renderer_) { |
| 493 bound_fns.Push(base::Bind( | 497 bound_fns.Push(base::Bind( |
| 494 &AudioRenderer::Flush, base::Unretained(audio_renderer_.get()))); | 498 &AudioRenderer::Flush, base::Unretained(audio_renderer_.get()))); |
| 495 | 499 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 | 750 |
| 747 SetState(kSeeking); | 751 SetState(kSeeking); |
| 748 base::TimeDelta seek_timestamp = std::max(time, demuxer_->GetStartTime()); | 752 base::TimeDelta seek_timestamp = std::max(time, demuxer_->GetStartTime()); |
| 749 seek_cb_ = seek_cb; | 753 seek_cb_ = seek_cb; |
| 750 audio_ended_ = false; | 754 audio_ended_ = false; |
| 751 video_ended_ = false; | 755 video_ended_ = false; |
| 752 text_ended_ = false; | 756 text_ended_ = false; |
| 753 | 757 |
| 754 // Kick off seeking! | 758 // Kick off seeking! |
| 755 { | 759 { |
| 756 if (audio_renderer_) | |
| 757 audio_renderer_->StopRendering(); | |
| 758 | |
| 759 base::AutoLock auto_lock(lock_); | 760 base::AutoLock auto_lock(lock_); |
| 760 if (clock_->IsPlaying()) | 761 if (clock_->IsPlaying()) |
| 761 clock_->Pause(); | 762 clock_->Pause(); |
| 762 clock_->SetTime(seek_timestamp, seek_timestamp); | 763 clock_->SetTime(seek_timestamp, seek_timestamp); |
| 763 } | 764 } |
| 764 DoSeek(seek_timestamp, base::Bind( | 765 DoSeek(seek_timestamp, base::Bind( |
| 765 &Pipeline::OnStateTransition, base::Unretained(this))); | 766 &Pipeline::OnStateTransition, base::Unretained(this))); |
| 766 } | 767 } |
| 767 | 768 |
| 768 void Pipeline::DoAudioRendererEnded() { | 769 void Pipeline::DoAudioRendererEnded() { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 if (state_ != kPlaying) | 921 if (state_ != kPlaying) |
| 921 return false; | 922 return false; |
| 922 if (audio_renderer_ && audio_buffering_state_ != BUFFERING_HAVE_ENOUGH) | 923 if (audio_renderer_ && audio_buffering_state_ != BUFFERING_HAVE_ENOUGH) |
| 923 return true; | 924 return true; |
| 924 if (video_renderer_ && video_buffering_state_ != BUFFERING_HAVE_ENOUGH) | 925 if (video_renderer_ && video_buffering_state_ != BUFFERING_HAVE_ENOUGH) |
| 925 return true; | 926 return true; |
| 926 return false; | 927 return false; |
| 927 } | 928 } |
| 928 | 929 |
| 929 void Pipeline::StartWaitingForEnoughData() { | 930 void Pipeline::StartWaitingForEnoughData() { |
| 930 DVLOG(1) << __FUNCTION__; | |
| 931 DCHECK_EQ(state_, kPlaying); | 931 DCHECK_EQ(state_, kPlaying); |
| 932 DCHECK(WaitingForEnoughData()); | 932 DCHECK(WaitingForEnoughData()); |
| 933 | 933 |
| 934 if (audio_renderer_) | 934 if (audio_renderer_) |
| 935 audio_renderer_->StopRendering(); | 935 audio_renderer_->Pause(); |
| 936 | 936 |
| 937 base::AutoLock auto_lock(lock_); | 937 base::AutoLock auto_lock(lock_); |
| 938 clock_->Pause(); | 938 clock_->Pause(); |
| 939 } | 939 } |
| 940 | 940 |
| 941 void Pipeline::StartPlayback() { | 941 void Pipeline::StartPlayback() { |
| 942 DVLOG(1) << __FUNCTION__; | |
| 943 DCHECK_EQ(state_, kPlaying); | 942 DCHECK_EQ(state_, kPlaying); |
| 944 DCHECK(!WaitingForEnoughData()); | 943 DCHECK(!WaitingForEnoughData()); |
| 945 | 944 |
| 946 if (audio_renderer_) { | 945 if (audio_renderer_) { |
| 946 audio_renderer_->Play(); |
| 947 |
| 948 base::AutoLock auto_lock(lock_); |
| 947 // We use audio stream to update the clock. So if there is such a | 949 // We use audio stream to update the clock. So if there is such a |
| 948 // stream, we pause the clock until we receive a valid timestamp. | 950 // stream, we pause the clock until we receive a valid timestamp. |
| 949 base::AutoLock auto_lock(lock_); | |
| 950 waiting_for_clock_update_ = true; | 951 waiting_for_clock_update_ = true; |
| 951 audio_renderer_->StartRendering(); | |
| 952 } else { | 952 } else { |
| 953 base::AutoLock auto_lock(lock_); | 953 base::AutoLock auto_lock(lock_); |
| 954 DCHECK(!waiting_for_clock_update_); | |
| 955 clock_->SetMaxTime(clock_->Duration()); | 954 clock_->SetMaxTime(clock_->Duration()); |
| 956 clock_->Play(); | 955 clock_->Play(); |
| 957 } | 956 } |
| 958 | 957 |
| 959 preroll_completed_cb_.Run(); | 958 preroll_completed_cb_.Run(); |
| 960 if (!seek_cb_.is_null()) | 959 if (!seek_cb_.is_null()) |
| 961 base::ResetAndReturn(&seek_cb_).Run(PIPELINE_OK); | 960 base::ResetAndReturn(&seek_cb_).Run(PIPELINE_OK); |
| 962 } | 961 } |
| 963 | 962 |
| 964 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { | 963 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { |
| 965 lock_.AssertAcquired(); | 964 lock_.AssertAcquired(); |
| 966 if (!waiting_for_clock_update_) | 965 if (!waiting_for_clock_update_) |
| 967 return; | 966 return; |
| 968 | 967 |
| 969 waiting_for_clock_update_ = false; | 968 waiting_for_clock_update_ = false; |
| 970 clock_->Play(); | 969 clock_->Play(); |
| 971 } | 970 } |
| 972 | 971 |
| 973 } // namespace media | 972 } // namespace media |
| OLD | NEW |