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

Side by Side Diff: media/filters/video_renderer_base.cc

Issue 9700006: Move VideoDecoder out of media pipeline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and a small fix Created 8 years, 9 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 | Annotate | Revision Log
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/threading/platform_thread.h" 7 #include "base/threading/platform_thread.h"
8 #include "media/base/buffers.h" 8 #include "media/base/buffers.h"
9 #include "media/base/filter_host.h" 9 #include "media/base/filter_host.h"
10 #include "media/base/limits.h" 10 #include "media/base/limits.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 void VideoRendererBase::Pause(const base::Closure& callback) { 45 void VideoRendererBase::Pause(const base::Closure& callback) {
46 base::AutoLock auto_lock(lock_); 46 base::AutoLock auto_lock(lock_);
47 DCHECK(state_ != kUninitialized || state_ == kError); 47 DCHECK(state_ != kUninitialized || state_ == kError);
48 state_ = kPaused; 48 state_ = kPaused;
49 callback.Run(); 49 callback.Run();
50 } 50 }
51 51
52 void VideoRendererBase::Flush(const base::Closure& callback) { 52 void VideoRendererBase::Flush(const base::Closure& callback) {
53 base::AutoLock auto_lock(lock_); 53 base::AutoLock auto_lock(lock_);
54 DCHECK_EQ(state_, kPaused); 54 DCHECK_EQ(state_, kPaused);
55 flush_callback_ = callback; 55 flush_callback_ = callback;
Ami GONE FROM CHROMIUM 2012/03/14 20:05:01 I'm surprised you didn't rename this :)
xhwang 2012/03/14 22:28:41 Doh! Done. Probably rename all seek_callback, play
56 state_ = kFlushing; 56 state_ = kFlushing;
57 57
58 AttemptFlush_Locked(); 58 AttemptFlush_Locked();
59 } 59 }
60 60
61 void VideoRendererBase::Stop(const base::Closure& callback) { 61 void VideoRendererBase::Stop(const base::Closure& callback) {
62 if (state_ == kStopped) {
63 callback.Run();
64 return;
65 }
66
62 base::PlatformThreadHandle thread_to_join = base::kNullThreadHandle; 67 base::PlatformThreadHandle thread_to_join = base::kNullThreadHandle;
63 { 68 {
64 base::AutoLock auto_lock(lock_); 69 base::AutoLock auto_lock(lock_);
65 state_ = kStopped; 70 state_ = kStopped;
66 71
67 statistics_cb_.Reset(); 72 statistics_cb_.Reset();
68 video_time_cb_.Reset(); 73 video_time_cb_.Reset();
69 if (!pending_paint_ && !pending_paint_with_last_available_) 74 if (!pending_paint_ && !pending_paint_with_last_available_)
70 DoStopOrError_Locked(); 75 DoStopOrError_Locked();
71 76
72 // Clean up our thread if present. 77 // Clean up our thread if present.
73 if (thread_ != base::kNullThreadHandle) { 78 if (thread_ != base::kNullThreadHandle) {
74 // Signal the thread since it's possible to get stopped with the video 79 // Signal the thread since it's possible to get stopped with the video
75 // thread waiting for a read to complete. 80 // thread waiting for a read to complete.
76 frame_available_.Signal(); 81 frame_available_.Signal();
77 thread_to_join = thread_; 82 thread_to_join = thread_;
78 thread_ = base::kNullThreadHandle; 83 thread_ = base::kNullThreadHandle;
79 } 84 }
80 } 85 }
81 if (thread_to_join != base::kNullThreadHandle) 86 if (thread_to_join != base::kNullThreadHandle)
82 base::PlatformThread::Join(thread_to_join); 87 base::PlatformThread::Join(thread_to_join);
83 88
84 callback.Run(); 89 decoder_->Stop(callback);
85 } 90 }
86 91
87 void VideoRendererBase::SetPlaybackRate(float playback_rate) { 92 void VideoRendererBase::SetPlaybackRate(float playback_rate) {
88 base::AutoLock auto_lock(lock_); 93 base::AutoLock auto_lock(lock_);
89 playback_rate_ = playback_rate; 94 playback_rate_ = playback_rate;
90 } 95 }
91 96
92 void VideoRendererBase::Seek(base::TimeDelta time, const FilterStatusCB& cb) { 97 void VideoRendererBase::Seek(base::TimeDelta time, const FilterStatusCB& cb) {
93 base::AutoLock auto_lock(lock_); 98 base::AutoLock auto_lock(lock_);
94 DCHECK_EQ(state_, kFlushed) << "Must flush prior to seeking."; 99 DCHECK_EQ(state_, kFlushed) << "Must flush prior to seeking.";
95 DCHECK(!cb.is_null()); 100 DCHECK(!cb.is_null());
96 DCHECK(seek_cb_.is_null()); 101 DCHECK(seek_cb_.is_null());
97 102
98 state_ = kSeeking; 103 state_ = kSeeking;
99 seek_cb_ = cb; 104 seek_cb_ = cb;
100 seek_timestamp_ = time; 105 seek_timestamp_ = time;
101 AttemptRead_Locked(); 106 AttemptRead_Locked();
102 } 107 }
103 108
104 void VideoRendererBase::Initialize(VideoDecoder* decoder, 109 void VideoRendererBase::Initialize(const scoped_refptr<VideoDecoder>& decoder,
105 const PipelineStatusCB& pipeline_status_cb, 110 const PipelineStatusCB& pipeline_status_cb,
106 const StatisticsCB& statistics_cb, 111 const StatisticsCB& statistics_cb,
107 const VideoTimeCB& video_time_cb) { 112 const VideoTimeCB& video_time_cb) {
108 base::AutoLock auto_lock(lock_); 113 base::AutoLock auto_lock(lock_);
109 DCHECK(decoder); 114 DCHECK(decoder);
110 DCHECK(!pipeline_status_cb.is_null()); 115 DCHECK(!pipeline_status_cb.is_null());
111 DCHECK(!statistics_cb.is_null()); 116 DCHECK(!statistics_cb.is_null());
112 DCHECK(!video_time_cb.is_null()); 117 DCHECK(!video_time_cb.is_null());
113 DCHECK_EQ(kUninitialized, state_); 118 DCHECK_EQ(kUninitialized, state_);
114 decoder_ = decoder; 119 decoder_ = decoder;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 void VideoRendererBase::AttemptFlush_Locked() { 450 void VideoRendererBase::AttemptFlush_Locked() {
446 lock_.AssertAcquired(); 451 lock_.AssertAcquired();
447 DCHECK_EQ(kFlushing, state_); 452 DCHECK_EQ(kFlushing, state_);
448 453
449 // Get rid of any ready frames. 454 // Get rid of any ready frames.
450 ready_frames_.clear(); 455 ready_frames_.clear();
451 456
452 if (!pending_paint_ && !pending_read_) { 457 if (!pending_paint_ && !pending_read_) {
453 state_ = kFlushed; 458 state_ = kFlushed;
454 current_frame_ = NULL; 459 current_frame_ = NULL;
455 ResetAndRunCB(&flush_callback_); 460 decoder_->Flush(flush_callback_);
Ami GONE FROM CHROMIUM 2012/03/14 20:05:01 This change is unsafe if flushing the decoder caus
xhwang 2012/03/14 22:28:41 Done.
461 flush_callback_.Reset();
456 } 462 }
457 } 463 }
458 464
459 base::TimeDelta VideoRendererBase::CalculateSleepDuration( 465 base::TimeDelta VideoRendererBase::CalculateSleepDuration(
460 const scoped_refptr<VideoFrame>& next_frame, 466 const scoped_refptr<VideoFrame>& next_frame,
461 float playback_rate) { 467 float playback_rate) {
462 // Determine the current and next presentation timestamps. 468 // Determine the current and next presentation timestamps.
463 base::TimeDelta now = host()->GetTime(); 469 base::TimeDelta now = host()->GetTime();
464 base::TimeDelta this_pts = current_frame_->GetTimestamp(); 470 base::TimeDelta this_pts = current_frame_->GetTimestamp();
465 base::TimeDelta next_pts; 471 base::TimeDelta next_pts;
(...skipping 20 matching lines...) Expand all
486 492
487 int VideoRendererBase::NumFrames_Locked() const { 493 int VideoRendererBase::NumFrames_Locked() const {
488 lock_.AssertAcquired(); 494 lock_.AssertAcquired();
489 int outstanding_frames = 495 int outstanding_frames =
490 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) + 496 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) +
491 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0); 497 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0);
492 return ready_frames_.size() + outstanding_frames; 498 return ready_frames_.size() + outstanding_frames;
493 } 499 }
494 500
495 } // namespace media 501 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698