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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 base::Bind( | 155 base::Bind( |
156 &Pipeline::VolumeChangedTask, weak_factory_.GetWeakPtr(), volume)); | 156 &Pipeline::VolumeChangedTask, weak_factory_.GetWeakPtr(), volume)); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 TimeDelta Pipeline::GetMediaTime() const { | 160 TimeDelta Pipeline::GetMediaTime() const { |
161 base::AutoLock auto_lock(lock_); | 161 base::AutoLock auto_lock(lock_); |
162 if (!renderer_) | 162 if (!renderer_) |
163 return TimeDelta(); | 163 return TimeDelta(); |
164 | 164 |
| 165 // TODO(sriram): In some cases GetMediaTime() returns a value few |
| 166 // milliseconds less than duration, even though playback has ended |
| 167 // http://crbug.com/438581 |
165 TimeDelta media_time = renderer_->GetMediaTime(); | 168 TimeDelta media_time = renderer_->GetMediaTime(); |
| 169 if (renderer_ended_) |
| 170 return duration_; |
| 171 |
166 return std::min(media_time, duration_); | 172 return std::min(media_time, duration_); |
167 } | 173 } |
168 | 174 |
169 Ranges<TimeDelta> Pipeline::GetBufferedTimeRanges() const { | 175 Ranges<TimeDelta> Pipeline::GetBufferedTimeRanges() const { |
170 base::AutoLock auto_lock(lock_); | 176 base::AutoLock auto_lock(lock_); |
171 return buffered_time_ranges_; | 177 return buffered_time_ranges_; |
172 } | 178 } |
173 | 179 |
174 TimeDelta Pipeline::GetMediaDuration() const { | 180 TimeDelta Pipeline::GetMediaDuration() const { |
175 base::AutoLock auto_lock(lock_); | 181 base::AutoLock auto_lock(lock_); |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 633 |
628 void Pipeline::RunEndedCallbackIfNeeded() { | 634 void Pipeline::RunEndedCallbackIfNeeded() { |
629 DCHECK(task_runner_->BelongsToCurrentThread()); | 635 DCHECK(task_runner_->BelongsToCurrentThread()); |
630 | 636 |
631 if (renderer_ && !renderer_ended_) | 637 if (renderer_ && !renderer_ended_) |
632 return; | 638 return; |
633 | 639 |
634 if (text_renderer_ && text_renderer_->HasTracks() && !text_renderer_ended_) | 640 if (text_renderer_ && text_renderer_->HasTracks() && !text_renderer_ended_) |
635 return; | 641 return; |
636 | 642 |
| 643 // Correct the duration against current time if it turns out that |
| 644 // the initially reported duration is wrong |
| 645 // TODO(sriram): There are cases where duration is correct and current time |
| 646 // falls short of duration by a few milliseconds. This is a workaround |
| 647 // till we find the actual fix and 250ms is chosen here as it is |
| 648 // the max time between timeupdate events (http://crbug.com/438581). |
| 649 TimeDelta media_time = renderer_->GetMediaTime(); |
| 650 if ((duration_ - media_time).InMilliseconds() > 250) |
| 651 SetDuration(media_time); |
| 652 |
637 DCHECK_EQ(status_, PIPELINE_OK); | 653 DCHECK_EQ(status_, PIPELINE_OK); |
638 ended_cb_.Run(); | 654 ended_cb_.Run(); |
639 } | 655 } |
640 | 656 |
641 scoped_ptr<TextRenderer> Pipeline::CreateTextRenderer() { | 657 scoped_ptr<TextRenderer> Pipeline::CreateTextRenderer() { |
642 DCHECK(task_runner_->BelongsToCurrentThread()); | 658 DCHECK(task_runner_->BelongsToCurrentThread()); |
643 | 659 |
644 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 660 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
645 if (!cmd_line->HasSwitch(switches::kEnableInbandTextTracks)) | 661 if (!cmd_line->HasSwitch(switches::kEnableInbandTextTracks)) |
646 return scoped_ptr<media::TextRenderer>(); | 662 return scoped_ptr<media::TextRenderer>(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 metadata_cb_.Run(metadata); | 729 metadata_cb_.Run(metadata); |
714 } | 730 } |
715 | 731 |
716 void Pipeline::BufferingStateChanged(BufferingState new_buffering_state) { | 732 void Pipeline::BufferingStateChanged(BufferingState new_buffering_state) { |
717 DVLOG(1) << __FUNCTION__ << "(" << new_buffering_state << ") "; | 733 DVLOG(1) << __FUNCTION__ << "(" << new_buffering_state << ") "; |
718 DCHECK(task_runner_->BelongsToCurrentThread()); | 734 DCHECK(task_runner_->BelongsToCurrentThread()); |
719 buffering_state_cb_.Run(new_buffering_state); | 735 buffering_state_cb_.Run(new_buffering_state); |
720 } | 736 } |
721 | 737 |
722 } // namespace media | 738 } // namespace media |
OLD | NEW |