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

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

Issue 2581533002: MSE: Fix logic bugs with high precision duration (Closed)
Patch Set: Created 4 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/filters/chunk_demuxer.cc » ('j') | media/filters/chunk_demuxer.cc » ('J')
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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 689
690 return seeking_; 690 return seeking_;
691 } 691 }
692 692
693 double WebMediaPlayerImpl::duration() const { 693 double WebMediaPlayerImpl::duration() const {
694 DCHECK(main_task_runner_->BelongsToCurrentThread()); 694 DCHECK(main_task_runner_->BelongsToCurrentThread());
695 695
696 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) 696 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing)
697 return std::numeric_limits<double>::quiet_NaN(); 697 return std::numeric_limits<double>::quiet_NaN();
698 698
699 return GetPipelineDuration(); 699 // Use duration from ChunkDemuxer when present. MSE allows users to specify
700 // duration as a double. This propagates to the rest of the pipeline as a
701 // TimeDelta with potentially reduced precision (limited to Microseconds).
702 // ChunkDemuxer returns the full-precision user-specified double. This ensures
703 // users can "get" the exact duration they "set".
704 if (chunk_demuxer_) {
705 return chunk_demuxer_->GetDuration();
wolenetz 2016/12/16 00:56:51 Is WMPI::duration() ever queried in a code path wh
chcunningham 2017/01/03 17:48:05 Not that I'm aware of. I did some searching and co
706 }
mlamouri (slow - plz ping) 2016/12/15 10:20:51 style: no { }
chcunningham 2017/01/03 17:48:05 Done.
707
708 base::TimeDelta pipeline_duration = pipeline_.GetMediaDuration();
709 return (pipeline_duration == kInfiniteDuration)
mlamouri (slow - plz ping) 2016/12/15 10:20:51 nit: () are not needed
chcunningham 2017/01/03 17:48:05 Done.
710 ? std::numeric_limits<double>::infinity()
711 : pipeline_duration.InSecondsF();
700 } 712 }
701 713
702 double WebMediaPlayerImpl::timelineOffset() const { 714 double WebMediaPlayerImpl::timelineOffset() const {
703 DCHECK(main_task_runner_->BelongsToCurrentThread()); 715 DCHECK(main_task_runner_->BelongsToCurrentThread());
704 716
705 if (pipeline_metadata_.timeline_offset.is_null()) 717 if (pipeline_metadata_.timeline_offset.is_null())
706 return std::numeric_limits<double>::quiet_NaN(); 718 return std::numeric_limits<double>::quiet_NaN();
707 719
708 return pipeline_metadata_.timeline_offset.ToJsTime(); 720 return pipeline_metadata_.timeline_offset.ToJsTime();
709 } 721 }
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 highest_ready_state_ = std::max(highest_ready_state_, ready_state_); 1664 highest_ready_state_ = std::max(highest_ready_state_, ready_state_);
1653 1665
1654 // Always notify to ensure client has the latest value. 1666 // Always notify to ensure client has the latest value.
1655 client_->readyStateChanged(); 1667 client_->readyStateChanged();
1656 } 1668 }
1657 1669
1658 blink::WebAudioSourceProvider* WebMediaPlayerImpl::getAudioSourceProvider() { 1670 blink::WebAudioSourceProvider* WebMediaPlayerImpl::getAudioSourceProvider() {
1659 return audio_source_provider_.get(); 1671 return audio_source_provider_.get();
1660 } 1672 }
1661 1673
1662 double WebMediaPlayerImpl::GetPipelineDuration() const {
1663 base::TimeDelta duration = pipeline_.GetMediaDuration();
1664
1665 // Return positive infinity if the resource is unbounded.
1666 // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom- media-duration
1667 if (duration == kInfiniteDuration)
1668 return std::numeric_limits<double>::infinity();
1669
1670 return duration.InSecondsF();
1671 }
1672
1673 static void GetCurrentFrameAndSignal( 1674 static void GetCurrentFrameAndSignal(
1674 VideoFrameCompositor* compositor, 1675 VideoFrameCompositor* compositor,
1675 scoped_refptr<VideoFrame>* video_frame_out, 1676 scoped_refptr<VideoFrame>* video_frame_out,
1676 base::WaitableEvent* event) { 1677 base::WaitableEvent* event) {
1677 TRACE_EVENT0("media", "GetCurrentFrameAndSignal"); 1678 TRACE_EVENT0("media", "GetCurrentFrameAndSignal");
1678 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale(); 1679 *video_frame_out = compositor->GetCurrentFrameAndUpdateIfStale();
1679 event->Signal(); 1680 event->Signal();
1680 } 1681 }
1681 1682
1682 scoped_refptr<VideoFrame> 1683 scoped_refptr<VideoFrame>
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 watch_time_reporter_->OnShown(); 1981 watch_time_reporter_->OnShown();
1981 } 1982 }
1982 1983
1983 bool WebMediaPlayerImpl::IsHidden() const { 1984 bool WebMediaPlayerImpl::IsHidden() const {
1984 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1985 DCHECK(main_task_runner_->BelongsToCurrentThread());
1985 1986
1986 return delegate_ && delegate_->IsHidden(); 1987 return delegate_ && delegate_->IsHidden();
1987 } 1988 }
1988 1989
1989 } // namespace media 1990 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/filters/chunk_demuxer.cc » ('j') | media/filters/chunk_demuxer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698