Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: media/base/pipeline.cc

Issue 740663002: Relanding 'Ignore seek operations to the current time in pause state' patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplified GetMediaTime() as per review Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/base/pipeline_unittest.cc » ('j') | media/base/pipeline_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
22 #include "media/base/media_switches.h" 22 #include "media/base/media_switches.h"
23 #include "media/base/renderer.h" 23 #include "media/base/renderer.h"
24 #include "media/base/text_renderer.h" 24 #include "media/base/text_renderer.h"
25 #include "media/base/text_track_config.h" 25 #include "media/base/text_track_config.h"
26 #include "media/base/video_decoder_config.h" 26 #include "media/base/video_decoder_config.h"
27 27
28 using base::TimeDelta; 28 using base::TimeDelta;
29 29
30 namespace media { 30 namespace media {
31 31
32 // TODO(sriram): There are cases where current time falls short of duration
33 // by a few milliseconds. This is a workaround till we find the actual fix and
34 // 250ms is chosen here as it is the max time between timeupdate events.
35 const int kCurrTimeErrorInMillisecondsOnPlaybackEnd = 250;
Srirama 2014/12/02 11:16:29 Do we need this, or can i directly use 250 below?
DaleCurtis 2014/12/02 18:14:05 Since you only have one usage, it's fine to inline
Srirama 2014/12/03 14:43:02 Done.
36
32 Pipeline::Pipeline( 37 Pipeline::Pipeline(
33 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 38 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
34 MediaLog* media_log) 39 MediaLog* media_log)
35 : task_runner_(task_runner), 40 : task_runner_(task_runner),
36 media_log_(media_log), 41 media_log_(media_log),
37 running_(false), 42 running_(false),
38 did_loading_progress_(false), 43 did_loading_progress_(false),
39 volume_(1.0f), 44 volume_(1.0f),
40 playback_rate_(0.0f), 45 playback_rate_(0.0f),
41 status_(PIPELINE_OK), 46 status_(PIPELINE_OK),
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 base::Bind( 160 base::Bind(
156 &Pipeline::VolumeChangedTask, weak_factory_.GetWeakPtr(), volume)); 161 &Pipeline::VolumeChangedTask, weak_factory_.GetWeakPtr(), volume));
157 } 162 }
158 } 163 }
159 164
160 TimeDelta Pipeline::GetMediaTime() const { 165 TimeDelta Pipeline::GetMediaTime() const {
161 base::AutoLock auto_lock(lock_); 166 base::AutoLock auto_lock(lock_);
162 if (!renderer_) 167 if (!renderer_)
163 return TimeDelta(); 168 return TimeDelta();
164 169
170 // TODO(sriram): In some cases GetMediaTime() returns a value few
171 // milliseconds less than duration, even though playback has ended.
165 TimeDelta media_time = renderer_->GetMediaTime(); 172 TimeDelta media_time = renderer_->GetMediaTime();
173 if (renderer_ended_)
174 return duration_;
175
166 return std::min(media_time, duration_); 176 return std::min(media_time, duration_);
167 } 177 }
168 178
169 Ranges<TimeDelta> Pipeline::GetBufferedTimeRanges() const { 179 Ranges<TimeDelta> Pipeline::GetBufferedTimeRanges() const {
170 base::AutoLock auto_lock(lock_); 180 base::AutoLock auto_lock(lock_);
171 return buffered_time_ranges_; 181 return buffered_time_ranges_;
172 } 182 }
173 183
174 TimeDelta Pipeline::GetMediaDuration() const { 184 TimeDelta Pipeline::GetMediaDuration() const {
175 base::AutoLock auto_lock(lock_); 185 base::AutoLock auto_lock(lock_);
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 637
628 void Pipeline::RunEndedCallbackIfNeeded() { 638 void Pipeline::RunEndedCallbackIfNeeded() {
629 DCHECK(task_runner_->BelongsToCurrentThread()); 639 DCHECK(task_runner_->BelongsToCurrentThread());
630 640
631 if (renderer_ && !renderer_ended_) 641 if (renderer_ && !renderer_ended_)
632 return; 642 return;
633 643
634 if (text_renderer_ && text_renderer_->HasTracks() && !text_renderer_ended_) 644 if (text_renderer_ && text_renderer_->HasTracks() && !text_renderer_ended_)
635 return; 645 return;
636 646
647 // Correct the duration if current time is less
648 TimeDelta media_time = renderer_->GetMediaTime();
649 if (media_time < duration_) {
650 if ((duration_ - media_time).InMilliseconds() >
651 kCurrTimeErrorInMillisecondsOnPlaybackEnd)
DaleCurtis 2014/12/02 18:14:05 You don't need the media_time < duration_ check si
Srirama 2014/12/03 14:43:02 Removed the condition but not inlined the function
652 SetDuration(media_time);
653 }
654
637 DCHECK_EQ(status_, PIPELINE_OK); 655 DCHECK_EQ(status_, PIPELINE_OK);
638 ended_cb_.Run(); 656 ended_cb_.Run();
639 } 657 }
640 658
641 scoped_ptr<TextRenderer> Pipeline::CreateTextRenderer() { 659 scoped_ptr<TextRenderer> Pipeline::CreateTextRenderer() {
642 DCHECK(task_runner_->BelongsToCurrentThread()); 660 DCHECK(task_runner_->BelongsToCurrentThread());
643 661
644 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 662 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
645 if (!cmd_line->HasSwitch(switches::kEnableInbandTextTracks)) 663 if (!cmd_line->HasSwitch(switches::kEnableInbandTextTracks))
646 return scoped_ptr<media::TextRenderer>(); 664 return scoped_ptr<media::TextRenderer>();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 metadata_cb_.Run(metadata); 731 metadata_cb_.Run(metadata);
714 } 732 }
715 733
716 void Pipeline::BufferingStateChanged(BufferingState new_buffering_state) { 734 void Pipeline::BufferingStateChanged(BufferingState new_buffering_state) {
717 DVLOG(1) << __FUNCTION__ << "(" << new_buffering_state << ") "; 735 DVLOG(1) << __FUNCTION__ << "(" << new_buffering_state << ") ";
718 DCHECK(task_runner_->BelongsToCurrentThread()); 736 DCHECK(task_runner_->BelongsToCurrentThread());
719 buffering_state_cb_.Run(new_buffering_state); 737 buffering_state_cb_.Run(new_buffering_state);
720 } 738 }
721 739
722 } // namespace media 740 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/pipeline_unittest.cc » ('j') | media/base/pipeline_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698