OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 20 matching lines...) Expand all Loading... |
31 state_(kUninitialized), | 31 state_(kUninitialized), |
32 thread_(base::kNullThreadHandle), | 32 thread_(base::kNullThreadHandle), |
33 pending_reads_(0), | 33 pending_reads_(0), |
34 pending_paint_(false), | 34 pending_paint_(false), |
35 pending_paint_with_last_available_(false), | 35 pending_paint_with_last_available_(false), |
36 playback_rate_(0) { | 36 playback_rate_(0) { |
37 } | 37 } |
38 | 38 |
39 VideoRendererBase::~VideoRendererBase() { | 39 VideoRendererBase::~VideoRendererBase() { |
40 base::AutoLock auto_lock(lock_); | 40 base::AutoLock auto_lock(lock_); |
41 DCHECK(state_ == kUninitialized || state_ == kStopped); | 41 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_; |
42 } | 42 } |
43 | 43 |
44 void VideoRendererBase::Play(const base::Closure& callback) { | 44 void VideoRendererBase::Play(const base::Closure& callback) { |
45 base::AutoLock auto_lock(lock_); | 45 base::AutoLock auto_lock(lock_); |
46 DCHECK_EQ(kPrerolled, state_); | 46 DCHECK_EQ(kPrerolled, state_); |
47 state_ = kPlaying; | 47 state_ = kPlaying; |
48 callback.Run(); | 48 callback.Run(); |
49 } | 49 } |
50 | 50 |
51 void VideoRendererBase::Pause(const base::Closure& callback) { | 51 void VideoRendererBase::Pause(const base::Closure& callback) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 // Signal the subclass we're stopping. | 89 // Signal the subclass we're stopping. |
90 OnStop(callback); | 90 OnStop(callback); |
91 } | 91 } |
92 | 92 |
93 void VideoRendererBase::SetPlaybackRate(float playback_rate) { | 93 void VideoRendererBase::SetPlaybackRate(float playback_rate) { |
94 base::AutoLock auto_lock(lock_); | 94 base::AutoLock auto_lock(lock_); |
95 playback_rate_ = playback_rate; | 95 playback_rate_ = playback_rate; |
96 } | 96 } |
97 | 97 |
98 void VideoRendererBase::Seek(base::TimeDelta time, const FilterStatusCB& cb) { | 98 void VideoRendererBase::Seek(base::TimeDelta time, const FilterStatusCB& cb) { |
99 bool run_callback = false; | 99 bool run_callback = false; |
100 | 100 |
101 { | 101 { |
102 base::AutoLock auto_lock(lock_); | 102 base::AutoLock auto_lock(lock_); |
103 // There is a race condition between filters to receive SeekTask(). | 103 // There is a race condition between filters to receive SeekTask(). |
104 // It turns out we could receive buffer from decoder before seek() | 104 // It turns out we could receive buffer from decoder before seek() |
105 // is called on us. so we do the following: | 105 // is called on us. so we do the following: |
106 // kFlushed => ( Receive first buffer or Seek() ) => kSeeking and | 106 // kFlushed => ( Receive first buffer or Seek() ) => kSeeking and |
107 // kSeeking => ( Receive enough buffers) => kPrerolled. ) | 107 // kSeeking => ( Receive enough buffers) => kPrerolled. ) |
108 DCHECK(state_ == kPrerolled || state_ == kFlushed || state_ == kSeeking); | 108 DCHECK(state_ == kPrerolled || state_ == kFlushed || state_ == kSeeking); |
109 DCHECK(!cb.is_null()); | 109 DCHECK(!cb.is_null()); |
110 DCHECK(seek_cb_.is_null()); | 110 DCHECK(seek_cb_.is_null()); |
111 | 111 |
112 if (state_ == kPrerolled) { | 112 if (state_ == kPrerolled) { |
113 // Already get enough buffers from decoder. | 113 // Already get enough buffers from decoder. |
114 run_callback = true; | 114 run_callback = true; |
115 | |
116 } else { | 115 } else { |
117 // Otherwise we are either kFlushed or kSeeking, but without enough | 116 // Otherwise we are either kFlushed or kSeeking, but without enough |
118 // buffers we should save the callback function and call it later. | 117 // buffers we should save the callback function and call it later. |
119 state_ = kSeeking; | 118 state_ = kSeeking; |
120 seek_cb_ = cb; | 119 seek_cb_ = cb; |
121 } | 120 } |
122 | 121 |
123 seek_timestamp_ = time; | 122 seek_timestamp_ = time; |
124 ScheduleRead_Locked(); | 123 ScheduleRead_Locked(); |
125 } | 124 } |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 void VideoRendererBase::DoStopOrErrorFlush_Locked() { | 589 void VideoRendererBase::DoStopOrErrorFlush_Locked() { |
591 DCHECK(!pending_paint_); | 590 DCHECK(!pending_paint_); |
592 DCHECK(!pending_paint_with_last_available_); | 591 DCHECK(!pending_paint_with_last_available_); |
593 lock_.AssertAcquired(); | 592 lock_.AssertAcquired(); |
594 FlushBuffers_Locked(); | 593 FlushBuffers_Locked(); |
595 last_available_frame_ = NULL; | 594 last_available_frame_ = NULL; |
596 DCHECK_EQ(pending_reads_, 0); | 595 DCHECK_EQ(pending_reads_, 0); |
597 } | 596 } |
598 | 597 |
599 } // namespace media | 598 } // namespace media |
OLD | NEW |