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

Side by Side Diff: media/blink/webmediaplayer_impl.cc

Issue 2581533002: MSE: Fix logic bugs with high precision duration (Closed)
Patch Set: Feedback Created 3 years, 11 months 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/filters/chunk_demuxer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 707
708 return seeking_; 708 return seeking_;
709 } 709 }
710 710
711 double WebMediaPlayerImpl::duration() const { 711 double WebMediaPlayerImpl::duration() const {
712 DCHECK(main_task_runner_->BelongsToCurrentThread()); 712 DCHECK(main_task_runner_->BelongsToCurrentThread());
713 713
714 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) 714 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
715 return std::numeric_limits<double>::quiet_NaN(); 715 return std::numeric_limits<double>::quiet_NaN();
716 716
717 return GetPipelineDuration(); 717 // Use duration from ChunkDemuxer when present. MSE allows users to specify
718 // duration as a double. This propagates to the rest of the pipeline as a
719 // TimeDelta with potentially reduced precision (limited to Microseconds).
720 // ChunkDemuxer returns the full-precision user-specified double. This ensures
721 // users can "get" the exact duration they "set".
722 if (chunk_demuxer_)
723 return chunk_demuxer_->GetDuration();
724
725 base::TimeDelta pipeline_duration = pipeline_.GetMediaDuration();
726 return pipeline_duration == kInfiniteDuration
727 ? std::numeric_limits<double>::infinity()
728 : pipeline_duration.InSecondsF();
718 } 729 }
719 730
720 double WebMediaPlayerImpl::timelineOffset() const { 731 double WebMediaPlayerImpl::timelineOffset() const {
721 DCHECK(main_task_runner_->BelongsToCurrentThread()); 732 DCHECK(main_task_runner_->BelongsToCurrentThread());
722 733
723 if (pipeline_metadata_.timeline_offset.is_null()) 734 if (pipeline_metadata_.timeline_offset.is_null())
724 return std::numeric_limits<double>::quiet_NaN(); 735 return std::numeric_limits<double>::quiet_NaN();
725 736
726 return pipeline_metadata_.timeline_offset.ToJsTime(); 737 return pipeline_metadata_.timeline_offset.ToJsTime();
727 } 738 }
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 highest_ready_state_ = std::max(highest_ready_state_, ready_state_); 1727 highest_ready_state_ = std::max(highest_ready_state_, ready_state_);
1717 1728
1718 // Always notify to ensure client has the latest value. 1729 // Always notify to ensure client has the latest value.
1719 client_->readyStateChanged(); 1730 client_->readyStateChanged();
1720 } 1731 }
1721 1732
1722 blink::WebAudioSourceProvider* WebMediaPlayerImpl::getAudioSourceProvider() { 1733 blink::WebAudioSourceProvider* WebMediaPlayerImpl::getAudioSourceProvider() {
1723 return audio_source_provider_.get(); 1734 return audio_source_provider_.get();
1724 } 1735 }
1725 1736
1726 double WebMediaPlayerImpl::GetPipelineDuration() const {
1727 base::TimeDelta duration = pipeline_.GetMediaDuration();
1728
1729 // Return positive infinity if the resource is unbounded.
1730 // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom- media-duration
1731 if (duration == kInfiniteDuration)
1732 return std::numeric_limits<double>::infinity();
1733
1734 return duration.InSecondsF();
1735 }
1736
1737 static void GetCurrentFrameAndSignal( 1737 static void GetCurrentFrameAndSignal(
1738 VideoFrameCompositor* compositor, 1738 VideoFrameCompositor* compositor,
1739 scoped_refptr<VideoFrame>* video_frame_out, 1739 scoped_refptr<VideoFrame>* video_frame_out,
1740 base::WaitableEvent* event) { 1740 base::WaitableEvent* event) {
1741 TRACE_EVENT0("media", "GetCurrentFrameAndSignal"); 1741 TRACE_EVENT0("media", "GetCurrentFrameAndSignal");
1742 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale(); 1742 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale();
1743 event->Signal(); 1743 event->Signal();
1744 } 1744 }
1745 1745
1746 scoped_refptr<VideoFrame> 1746 scoped_refptr<VideoFrame>
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 bool WebMediaPlayerImpl::ShouldPauseWhenHidden() const { 2085 bool WebMediaPlayerImpl::ShouldPauseWhenHidden() const {
2086 #if defined(OS_ANDROID) // WMPI_CAST 2086 #if defined(OS_ANDROID) // WMPI_CAST
2087 if (isRemote()) 2087 if (isRemote())
2088 return false; 2088 return false;
2089 #endif // defined(OS_ANDROID) // WMPI_CAST 2089 #endif // defined(OS_ANDROID) // WMPI_CAST
2090 2090
2091 return hasVideo() && !hasAudio(); 2091 return hasVideo() && !hasAudio();
2092 } 2092 }
2093 2093
2094 } // namespace media 2094 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/filters/chunk_demuxer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698