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

Side by Side Diff: media/renderers/video_renderer_impl.cc

Issue 1247973002: Fix race condition when accessing time_progressing_. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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/renderers/video_renderer_impl.h" 5 #include "media/renderers/video_renderer_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 // Due to how the |algorithm_| holds frames, this should never be null if 207 // Due to how the |algorithm_| holds frames, this should never be null if
208 // we've had a proper startup sequence. 208 // we've had a proper startup sequence.
209 DCHECK(result); 209 DCHECK(result);
210 210
211 // Declare HAVE_NOTHING if we reach a state where we can't progress playback 211 // Declare HAVE_NOTHING if we reach a state where we can't progress playback
212 // any further. We don't want to do this if we've already done so, reached 212 // any further. We don't want to do this if we've already done so, reached
213 // end of stream, or have frames available. We also don't want to do this in 213 // end of stream, or have frames available. We also don't want to do this in
214 // background rendering mode unless this isn't the first background render 214 // background rendering mode unless this isn't the first background render
215 // tick and we haven't seen any decoded frames since the last one. 215 // tick and we haven't seen any decoded frames since the last one.
216 const size_t effective_frames = MaybeFireEndedCallback(); 216 const size_t effective_frames =
217 MaybeFireEndedCallback(!render_first_frame_and_stop_);
xhwang 2015/07/21 21:01:38 Can you explain a little bit more how "inverse of
DaleCurtis 2015/07/22 00:44:43 Done.
217 if (buffering_state_ == BUFFERING_HAVE_ENOUGH && !received_end_of_stream_ && 218 if (buffering_state_ == BUFFERING_HAVE_ENOUGH && !received_end_of_stream_ &&
218 !effective_frames && (!background_rendering || 219 !effective_frames && (!background_rendering ||
219 (!frames_decoded_ && was_background_rendering_))) { 220 (!frames_decoded_ && was_background_rendering_))) {
220 // Do not set |buffering_state_| here as the lock in FrameReady() may be 221 // Do not set |buffering_state_| here as the lock in FrameReady() may be
221 // held already and it fire the state changes in the wrong order. 222 // held already and it fire the state changes in the wrong order.
222 task_runner_->PostTask( 223 task_runner_->PostTask(
223 FROM_HERE, base::Bind(&VideoRendererImpl::TransitionToHaveNothing, 224 FROM_HERE, base::Bind(&VideoRendererImpl::TransitionToHaveNothing,
224 weak_factory_.GetWeakPtr())); 225 weak_factory_.GetWeakPtr()));
225 } 226 }
226 227
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 DCHECK_EQ(status, VideoFrameStream::DEMUXER_READ_ABORTED); 490 DCHECK_EQ(status, VideoFrameStream::DEMUXER_READ_ABORTED);
490 return; 491 return;
491 } 492 }
492 493
493 if (frame->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)) { 494 if (frame->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)) {
494 DCHECK(!received_end_of_stream_); 495 DCHECK(!received_end_of_stream_);
495 received_end_of_stream_ = true; 496 received_end_of_stream_ = true;
496 497
497 // See if we can fire EOS immediately instead of waiting for Render(). 498 // See if we can fire EOS immediately instead of waiting for Render().
498 if (use_new_video_renderering_path_) 499 if (use_new_video_renderering_path_)
499 MaybeFireEndedCallback(); 500 MaybeFireEndedCallback(time_progressing_);
500 } else { 501 } else {
501 // Maintain the latest frame decoded so the correct frame is displayed 502 // Maintain the latest frame decoded so the correct frame is displayed
502 // after prerolling has completed. 503 // after prerolling has completed.
503 if (frame->timestamp() <= start_timestamp_) { 504 if (frame->timestamp() <= start_timestamp_) {
504 if (use_new_video_renderering_path_) 505 if (use_new_video_renderering_path_)
505 algorithm_->Reset(); 506 algorithm_->Reset();
506 ready_frames_.clear(); 507 ready_frames_.clear();
507 } 508 }
508 AddReadyFrame_Locked(frame); 509 AddReadyFrame_Locked(frame);
509 } 510 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 } 702 }
702 703
703 if (wait_duration > base::TimeDelta()) 704 if (wait_duration > base::TimeDelta())
704 frame_available_.TimedWait(wait_duration); 705 frame_available_.TimedWait(wait_duration);
705 } 706 }
706 707
707 void VideoRendererImpl::MaybeStopSinkAfterFirstPaint() { 708 void VideoRendererImpl::MaybeStopSinkAfterFirstPaint() {
708 DCHECK(task_runner_->BelongsToCurrentThread()); 709 DCHECK(task_runner_->BelongsToCurrentThread());
709 DCHECK(use_new_video_renderering_path_); 710 DCHECK(use_new_video_renderering_path_);
710 711
711 {
712 base::AutoLock auto_lock(lock_);
713 render_first_frame_and_stop_ = false;
714 }
715
716 if (!time_progressing_ && sink_started_) 712 if (!time_progressing_ && sink_started_)
717 StopSink(); 713 StopSink();
714
715 base::AutoLock auto_lock(lock_);
716 render_first_frame_and_stop_ = false;
718 } 717 }
719 718
720 bool VideoRendererImpl::HaveReachedBufferingCap() { 719 bool VideoRendererImpl::HaveReachedBufferingCap() {
721 DCHECK(task_runner_->BelongsToCurrentThread()); 720 DCHECK(task_runner_->BelongsToCurrentThread());
722 const size_t kMaxVideoFrames = limits::kMaxVideoFrames; 721 const size_t kMaxVideoFrames = limits::kMaxVideoFrames;
723 722
724 if (use_new_video_renderering_path_) { 723 if (use_new_video_renderering_path_) {
725 // When the display rate is less than the frame rate, the effective frames 724 // When the display rate is less than the frame rate, the effective frames
726 // queued may be much smaller than the actual number of frames queued. Here 725 // queued may be much smaller than the actual number of frames queued. Here
727 // we ensure that frames_queued() doesn't get excessive. 726 // we ensure that frames_queued() doesn't get excessive.
(...skipping 13 matching lines...) Expand all
741 } 740 }
742 741
743 void VideoRendererImpl::StopSink() { 742 void VideoRendererImpl::StopSink() {
744 DCHECK(task_runner_->BelongsToCurrentThread()); 743 DCHECK(task_runner_->BelongsToCurrentThread());
745 sink_->Stop(); 744 sink_->Stop();
746 algorithm_->set_time_stopped(); 745 algorithm_->set_time_stopped();
747 sink_started_ = false; 746 sink_started_ = false;
748 was_background_rendering_ = false; 747 was_background_rendering_ = false;
749 } 748 }
750 749
751 size_t VideoRendererImpl::MaybeFireEndedCallback() { 750 size_t VideoRendererImpl::MaybeFireEndedCallback(bool time_progressing) {
xhwang 2015/07/21 21:01:38 This must be called under the lock, append _Locked
DaleCurtis 2015/07/22 00:44:43 Done.
752 // If there's only one frame in the video or Render() was never called, the 751 // If there's only one frame in the video or Render() was never called, the
753 // algorithm will have one frame linger indefinitely. So in cases where the 752 // algorithm will have one frame linger indefinitely. So in cases where the
754 // frame duration is unknown and we've received EOS, fire it once we get down 753 // frame duration is unknown and we've received EOS, fire it once we get down
755 // to a single frame. 754 // to a single frame.
756 const size_t effective_frames = algorithm_->EffectiveFramesQueued(); 755 const size_t effective_frames = algorithm_->EffectiveFramesQueued();
757 756
758 // Don't fire ended if we haven't received EOS or have already done so. 757 // Don't fire ended if we haven't received EOS or have already done so.
759 if (!received_end_of_stream_ || rendered_end_of_stream_) 758 if (!received_end_of_stream_ || rendered_end_of_stream_)
760 return effective_frames; 759 return effective_frames;
761 760
762 // Don't fire ended if time isn't moving and we have frames. 761 // Don't fire ended if time isn't moving and we have frames.
763 if (!time_progressing_ && algorithm_->frames_queued()) 762 if (!time_progressing && algorithm_->frames_queued())
764 return effective_frames; 763 return effective_frames;
765 764
766 // Fire ended if we have no more effective frames or only ever had one frame. 765 // Fire ended if we have no more effective frames or only ever had one frame.
767 if (!effective_frames || 766 if (!effective_frames ||
768 (algorithm_->frames_queued() == 1u && 767 (algorithm_->frames_queued() == 1u &&
769 algorithm_->average_frame_duration() == base::TimeDelta())) { 768 algorithm_->average_frame_duration() == base::TimeDelta())) {
770 rendered_end_of_stream_ = true; 769 rendered_end_of_stream_ = true;
771 task_runner_->PostTask(FROM_HERE, ended_cb_); 770 task_runner_->PostTask(FROM_HERE, ended_cb_);
772 } 771 }
773 772
774 return effective_frames; 773 return effective_frames;
775 } 774 }
776 775
777 base::TimeTicks VideoRendererImpl::ConvertMediaTimestamp( 776 base::TimeTicks VideoRendererImpl::ConvertMediaTimestamp(
778 base::TimeDelta media_time) { 777 base::TimeDelta media_time) {
779 std::vector<base::TimeDelta> media_times(1, media_time); 778 std::vector<base::TimeDelta> media_times(1, media_time);
780 std::vector<base::TimeTicks> wall_clock_times; 779 std::vector<base::TimeTicks> wall_clock_times;
781 if (!wall_clock_time_cb_.Run(media_times, &wall_clock_times)) 780 if (!wall_clock_time_cb_.Run(media_times, &wall_clock_times))
782 return base::TimeTicks(); 781 return base::TimeTicks();
783 return wall_clock_times[0]; 782 return wall_clock_times[0];
784 } 783 }
785 784
786 } // namespace media 785 } // namespace media
OLDNEW
« media/renderers/video_renderer_impl.h ('K') | « media/renderers/video_renderer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698