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

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

Issue 2581533002: MSE: Fix logic bugs with high precision duration (Closed)
Patch Set: Fix failing test 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
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 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 696
697 return seeking_; 697 return seeking_;
698 } 698 }
699 699
700 double WebMediaPlayerImpl::duration() const { 700 double WebMediaPlayerImpl::duration() const {
701 DCHECK(main_task_runner_->BelongsToCurrentThread()); 701 DCHECK(main_task_runner_->BelongsToCurrentThread());
702 702
703 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) 703 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
704 return std::numeric_limits<double>::quiet_NaN(); 704 return std::numeric_limits<double>::quiet_NaN();
705 705
706 return GetPipelineDuration(); 706 // Use duration from ChunkDemuxer when present. MSE allows users to specify
707 // duration as a double. This propagates to the rest of the pipeline as a
708 // TimeDelta with potentially reduced precision (limited to Microseconds).
709 // ChunkDemuxer returns the full-precision user-specified double. This ensures
710 // users can "get" the exact duration they "set".
711 if (chunk_demuxer_)
712 return chunk_demuxer_->GetDuration();
713
714 base::TimeDelta pipeline_duration = pipeline_.GetMediaDuration();
715 return pipeline_duration == kInfiniteDuration
716 ? std::numeric_limits<double>::infinity()
717 : pipeline_duration.InSecondsF();
707 } 718 }
708 719
709 double WebMediaPlayerImpl::timelineOffset() const { 720 double WebMediaPlayerImpl::timelineOffset() const {
710 DCHECK(main_task_runner_->BelongsToCurrentThread()); 721 DCHECK(main_task_runner_->BelongsToCurrentThread());
711 722
712 if (pipeline_metadata_.timeline_offset.is_null()) 723 if (pipeline_metadata_.timeline_offset.is_null())
713 return std::numeric_limits<double>::quiet_NaN(); 724 return std::numeric_limits<double>::quiet_NaN();
714 725
715 return pipeline_metadata_.timeline_offset.ToJsTime(); 726 return pipeline_metadata_.timeline_offset.ToJsTime();
716 } 727 }
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 highest_ready_state_ = std::max(highest_ready_state_, ready_state_); 1670 highest_ready_state_ = std::max(highest_ready_state_, ready_state_);
1660 1671
1661 // Always notify to ensure client has the latest value. 1672 // Always notify to ensure client has the latest value.
1662 client_->readyStateChanged(); 1673 client_->readyStateChanged();
1663 } 1674 }
1664 1675
1665 blink::WebAudioSourceProvider* WebMediaPlayerImpl::getAudioSourceProvider() { 1676 blink::WebAudioSourceProvider* WebMediaPlayerImpl::getAudioSourceProvider() {
1666 return audio_source_provider_.get(); 1677 return audio_source_provider_.get();
1667 } 1678 }
1668 1679
1669 double WebMediaPlayerImpl::GetPipelineDuration() const {
1670 base::TimeDelta duration = pipeline_.GetMediaDuration();
1671
1672 // Return positive infinity if the resource is unbounded.
1673 // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom- media-duration
1674 if (duration == kInfiniteDuration)
1675 return std::numeric_limits<double>::infinity();
1676
1677 return duration.InSecondsF();
1678 }
1679
1680 static void GetCurrentFrameAndSignal( 1680 static void GetCurrentFrameAndSignal(
1681 VideoFrameCompositor* compositor, 1681 VideoFrameCompositor* compositor,
1682 scoped_refptr<VideoFrame>* video_frame_out, 1682 scoped_refptr<VideoFrame>* video_frame_out,
1683 base::WaitableEvent* event) { 1683 base::WaitableEvent* event) {
1684 TRACE_EVENT0("media", "GetCurrentFrameAndSignal"); 1684 TRACE_EVENT0("media", "GetCurrentFrameAndSignal");
1685 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale(); 1685 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale();
1686 event->Signal(); 1686 event->Signal();
1687 } 1687 }
1688 1688
1689 scoped_refptr<VideoFrame> 1689 scoped_refptr<VideoFrame>
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 return delegate_ && delegate_->IsHidden(); 2011 return delegate_ && delegate_->IsHidden();
2012 } 2012 }
2013 2013
2014 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { 2014 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) {
2015 DCHECK(main_task_runner_->BelongsToCurrentThread()); 2015 DCHECK(main_task_runner_->BelongsToCurrentThread());
2016 2016
2017 client_->activateViewportIntersectionMonitoring(activate); 2017 client_->activateViewportIntersectionMonitoring(activate);
2018 } 2018 }
2019 2019
2020 } // namespace media 2020 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/filters/chunk_demuxer.cc » ('j') | third_party/WebKit/Source/core/html/HTMLMediaElement.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698