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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 base::AutoLock auto_lock(lock_); | 149 base::AutoLock auto_lock(lock_); |
150 volume_ = volume; | 150 volume_ = volume; |
151 if (running_) { | 151 if (running_) { |
152 task_runner_->PostTask(FROM_HERE, base::Bind( | 152 task_runner_->PostTask(FROM_HERE, base::Bind( |
153 &Pipeline::VolumeChangedTask, base::Unretained(this), volume)); | 153 &Pipeline::VolumeChangedTask, base::Unretained(this), volume)); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 TimeDelta Pipeline::GetMediaTime() const { | 157 TimeDelta Pipeline::GetMediaTime() const { |
158 base::AutoLock auto_lock(lock_); | 158 base::AutoLock auto_lock(lock_); |
159 return clock_->Elapsed(); | 159 return std::min(clock_->Elapsed(), duration_); |
160 } | 160 } |
161 | 161 |
162 Ranges<TimeDelta> Pipeline::GetBufferedTimeRanges() const { | 162 Ranges<TimeDelta> Pipeline::GetBufferedTimeRanges() const { |
163 base::AutoLock auto_lock(lock_); | 163 base::AutoLock auto_lock(lock_); |
164 return buffered_time_ranges_; | 164 return buffered_time_ranges_; |
165 } | 165 } |
166 | 166 |
167 TimeDelta Pipeline::GetMediaDuration() const { | 167 TimeDelta Pipeline::GetMediaDuration() const { |
168 base::AutoLock auto_lock(lock_); | 168 base::AutoLock auto_lock(lock_); |
169 return clock_->Duration(); | 169 return duration_; |
170 } | 170 } |
171 | 171 |
172 bool Pipeline::DidLoadingProgress() { | 172 bool Pipeline::DidLoadingProgress() { |
173 base::AutoLock auto_lock(lock_); | 173 base::AutoLock auto_lock(lock_); |
174 bool ret = did_loading_progress_; | 174 bool ret = did_loading_progress_; |
175 did_loading_progress_ = false; | 175 did_loading_progress_ = false; |
176 return ret; | 176 return ret; |
177 } | 177 } |
178 | 178 |
179 PipelineStatistics Pipeline::GetStatistics() const { | 179 PipelineStatistics Pipeline::GetStatistics() const { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 317 } |
318 | 318 |
319 void Pipeline::SetDuration(TimeDelta duration) { | 319 void Pipeline::SetDuration(TimeDelta duration) { |
320 DCHECK(IsRunning()); | 320 DCHECK(IsRunning()); |
321 media_log_->AddEvent( | 321 media_log_->AddEvent( |
322 media_log_->CreateTimeEvent( | 322 media_log_->CreateTimeEvent( |
323 MediaLogEvent::DURATION_SET, "duration", duration)); | 323 MediaLogEvent::DURATION_SET, "duration", duration)); |
324 UMA_HISTOGRAM_LONG_TIMES("Media.Duration", duration); | 324 UMA_HISTOGRAM_LONG_TIMES("Media.Duration", duration); |
325 | 325 |
326 base::AutoLock auto_lock(lock_); | 326 base::AutoLock auto_lock(lock_); |
327 clock_->SetDuration(duration); | 327 duration_ = duration; |
328 if (!duration_change_cb_.is_null()) | 328 if (!duration_change_cb_.is_null()) |
329 duration_change_cb_.Run(); | 329 duration_change_cb_.Run(); |
330 } | 330 } |
331 | 331 |
332 void Pipeline::OnStateTransition(PipelineStatus status) { | 332 void Pipeline::OnStateTransition(PipelineStatus status) { |
333 // Force post to process state transitions after current execution frame. | 333 // Force post to process state transitions after current execution frame. |
334 task_runner_->PostTask(FROM_HERE, base::Bind( | 334 task_runner_->PostTask(FROM_HERE, base::Bind( |
335 &Pipeline::StateTransitionTask, base::Unretained(this), status)); | 335 &Pipeline::StateTransitionTask, base::Unretained(this), status)); |
336 } | 336 } |
337 | 337 |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 | 700 |
701 if (state_ != kPlaying) | 701 if (state_ != kPlaying) |
702 return; | 702 return; |
703 | 703 |
704 DCHECK(!audio_ended_); | 704 DCHECK(!audio_ended_); |
705 audio_ended_ = true; | 705 audio_ended_ = true; |
706 | 706 |
707 // Start clock since there is no more audio to trigger clock updates. | 707 // Start clock since there is no more audio to trigger clock updates. |
708 { | 708 { |
709 base::AutoLock auto_lock(lock_); | 709 base::AutoLock auto_lock(lock_); |
710 clock_->SetMaxTime(clock_->Duration()); | 710 clock_->SetMaxTime(duration_); |
711 StartClockIfWaitingForTimeUpdate_Locked(); | 711 StartClockIfWaitingForTimeUpdate_Locked(); |
712 } | 712 } |
713 | 713 |
714 RunEndedCallbackIfNeeded(); | 714 RunEndedCallbackIfNeeded(); |
715 } | 715 } |
716 | 716 |
717 void Pipeline::DoVideoRendererEnded() { | 717 void Pipeline::DoVideoRendererEnded() { |
718 DCHECK(task_runner_->BelongsToCurrentThread()); | 718 DCHECK(task_runner_->BelongsToCurrentThread()); |
719 | 719 |
720 if (state_ != kPlaying) | 720 if (state_ != kPlaying) |
(...skipping 25 matching lines...) Expand all Loading... |
746 | 746 |
747 if (video_renderer_ && !video_ended_) | 747 if (video_renderer_ && !video_ended_) |
748 return; | 748 return; |
749 | 749 |
750 if (text_renderer_ && text_renderer_->HasTracks() && !text_ended_) | 750 if (text_renderer_ && text_renderer_->HasTracks() && !text_ended_) |
751 return; | 751 return; |
752 | 752 |
753 { | 753 { |
754 base::AutoLock auto_lock(lock_); | 754 base::AutoLock auto_lock(lock_); |
755 PauseClockAndStopRendering_Locked(); | 755 PauseClockAndStopRendering_Locked(); |
756 clock_->SetTime(clock_->Duration(), clock_->Duration()); | 756 clock_->SetTime(duration_, duration_); |
757 } | 757 } |
758 | 758 |
759 DCHECK_EQ(status_, PIPELINE_OK); | 759 DCHECK_EQ(status_, PIPELINE_OK); |
760 ended_cb_.Run(); | 760 ended_cb_.Run(); |
761 } | 761 } |
762 | 762 |
763 void Pipeline::AddTextStreamTask(DemuxerStream* text_stream, | 763 void Pipeline::AddTextStreamTask(DemuxerStream* text_stream, |
764 const TextTrackConfig& config) { | 764 const TextTrackConfig& config) { |
765 DCHECK(task_runner_->BelongsToCurrentThread()); | 765 DCHECK(task_runner_->BelongsToCurrentThread()); |
766 // TODO(matthewjheaney): fix up text_ended_ when text stream | 766 // TODO(matthewjheaney): fix up text_ended_ when text stream |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 | 876 |
877 if (audio_renderer_) { | 877 if (audio_renderer_) { |
878 // We use audio stream to update the clock. So if there is such a | 878 // We use audio stream to update the clock. So if there is such a |
879 // stream, we pause the clock until we receive a valid timestamp. | 879 // stream, we pause the clock until we receive a valid timestamp. |
880 base::AutoLock auto_lock(lock_); | 880 base::AutoLock auto_lock(lock_); |
881 clock_state_ = CLOCK_WAITING_FOR_AUDIO_TIME_UPDATE; | 881 clock_state_ = CLOCK_WAITING_FOR_AUDIO_TIME_UPDATE; |
882 audio_renderer_->StartRendering(); | 882 audio_renderer_->StartRendering(); |
883 } else { | 883 } else { |
884 base::AutoLock auto_lock(lock_); | 884 base::AutoLock auto_lock(lock_); |
885 clock_state_ = CLOCK_PLAYING; | 885 clock_state_ = CLOCK_PLAYING; |
886 clock_->SetMaxTime(clock_->Duration()); | 886 clock_->SetMaxTime(duration_); |
887 clock_->Play(); | 887 clock_->Play(); |
888 } | 888 } |
889 } | 889 } |
890 | 890 |
891 void Pipeline::PauseClockAndStopRendering_Locked() { | 891 void Pipeline::PauseClockAndStopRendering_Locked() { |
892 lock_.AssertAcquired(); | 892 lock_.AssertAcquired(); |
893 switch (clock_state_) { | 893 switch (clock_state_) { |
894 case CLOCK_PAUSED: | 894 case CLOCK_PAUSED: |
895 return; | 895 return; |
896 | 896 |
(...skipping 14 matching lines...) Expand all Loading... |
911 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { | 911 void Pipeline::StartClockIfWaitingForTimeUpdate_Locked() { |
912 lock_.AssertAcquired(); | 912 lock_.AssertAcquired(); |
913 if (clock_state_ != CLOCK_WAITING_FOR_AUDIO_TIME_UPDATE) | 913 if (clock_state_ != CLOCK_WAITING_FOR_AUDIO_TIME_UPDATE) |
914 return; | 914 return; |
915 | 915 |
916 clock_state_ = CLOCK_PLAYING; | 916 clock_state_ = CLOCK_PLAYING; |
917 clock_->Play(); | 917 clock_->Play(); |
918 } | 918 } |
919 | 919 |
920 } // namespace media | 920 } // namespace media |
OLD | NEW |