OLD | NEW |
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 DCHECK(!cb.is_null()); | 93 DCHECK(!cb.is_null()); |
94 DCHECK(seek_cb_.is_null()); | 94 DCHECK(seek_cb_.is_null()); |
95 | 95 |
96 state_ = kSeeking; | 96 state_ = kSeeking; |
97 seek_cb_ = cb; | 97 seek_cb_ = cb; |
98 seek_timestamp_ = time; | 98 seek_timestamp_ = time; |
99 AttemptRead_Locked(); | 99 AttemptRead_Locked(); |
100 } | 100 } |
101 | 101 |
102 void VideoRendererBase::Initialize(VideoDecoder* decoder, | 102 void VideoRendererBase::Initialize(VideoDecoder* decoder, |
103 const base::Closure& callback, | 103 const PipelineStatusCB& callback, |
104 const StatisticsCallback& stats_callback) { | 104 const StatisticsCallback& stats_callback) { |
105 base::AutoLock auto_lock(lock_); | 105 base::AutoLock auto_lock(lock_); |
106 DCHECK(decoder); | 106 DCHECK(decoder); |
107 DCHECK(!callback.is_null()); | 107 DCHECK(!callback.is_null()); |
108 DCHECK(!stats_callback.is_null()); | 108 DCHECK(!stats_callback.is_null()); |
109 DCHECK_EQ(kUninitialized, state_); | 109 DCHECK_EQ(kUninitialized, state_); |
110 decoder_ = decoder; | 110 decoder_ = decoder; |
111 | 111 |
112 statistics_callback_ = stats_callback; | 112 statistics_callback_ = stats_callback; |
113 | 113 |
114 // Notify the pipeline of the video dimensions. | 114 // Notify the pipeline of the video dimensions. |
115 host()->SetNaturalVideoSize(decoder_->natural_size()); | 115 host()->SetNaturalVideoSize(decoder_->natural_size()); |
116 | 116 |
117 // We're all good! Consider ourselves flushed. (ThreadMain() should never | 117 // We're all good! Consider ourselves flushed. (ThreadMain() should never |
118 // see us in the kUninitialized state). | 118 // see us in the kUninitialized state). |
119 // Since we had an initial Seek, we consider ourself flushed, because we | 119 // Since we had an initial Seek, we consider ourself flushed, because we |
120 // have not populated any buffers yet. | 120 // have not populated any buffers yet. |
121 state_ = kFlushed; | 121 state_ = kFlushed; |
122 | 122 |
123 set_opaque_cb_.Run(!decoder->HasAlpha()); | 123 set_opaque_cb_.Run(!decoder->HasAlpha()); |
124 set_opaque_cb_.Reset(); | 124 set_opaque_cb_.Reset(); |
125 | 125 |
126 // Create our video thread. | 126 // Create our video thread. |
127 if (!base::PlatformThread::Create(0, this, &thread_)) { | 127 if (!base::PlatformThread::Create(0, this, &thread_)) { |
128 NOTREACHED() << "Video thread creation failed"; | 128 NOTREACHED() << "Video thread creation failed"; |
129 state_ = kError; | 129 state_ = kError; |
130 host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); | 130 callback.Run(PIPELINE_ERROR_INITIALIZATION_FAILED); |
131 callback.Run(); | |
132 return; | 131 return; |
133 } | 132 } |
134 | 133 |
135 #if defined(OS_WIN) | 134 #if defined(OS_WIN) |
136 // Bump up our priority so our sleeping is more accurate. | 135 // Bump up our priority so our sleeping is more accurate. |
137 // TODO(scherkus): find out if this is necessary, but it seems to help. | 136 // TODO(scherkus): find out if this is necessary, but it seems to help. |
138 ::SetThreadPriority(thread_, THREAD_PRIORITY_ABOVE_NORMAL); | 137 ::SetThreadPriority(thread_, THREAD_PRIORITY_ABOVE_NORMAL); |
139 #endif // defined(OS_WIN) | 138 #endif // defined(OS_WIN) |
140 callback.Run(); | 139 callback.Run(PIPELINE_OK); |
141 } | 140 } |
142 | 141 |
143 bool VideoRendererBase::HasEnded() { | 142 bool VideoRendererBase::HasEnded() { |
144 base::AutoLock auto_lock(lock_); | 143 base::AutoLock auto_lock(lock_); |
145 return state_ == kEnded; | 144 return state_ == kEnded; |
146 } | 145 } |
147 | 146 |
148 // PlatformThread::Delegate implementation. | 147 // PlatformThread::Delegate implementation. |
149 void VideoRendererBase::ThreadMain() { | 148 void VideoRendererBase::ThreadMain() { |
150 base::PlatformThread::SetName("CrVideoRenderer"); | 149 base::PlatformThread::SetName("CrVideoRenderer"); |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 479 |
481 int VideoRendererBase::NumFrames_Locked() const { | 480 int VideoRendererBase::NumFrames_Locked() const { |
482 lock_.AssertAcquired(); | 481 lock_.AssertAcquired(); |
483 int outstanding_frames = | 482 int outstanding_frames = |
484 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) + | 483 (current_frame_ ? 1 : 0) + (last_available_frame_ ? 1 : 0) + |
485 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0); | 484 (current_frame_ && (current_frame_ == last_available_frame_) ? -1 : 0); |
486 return ready_frames_.size() + outstanding_frames; | 485 return ready_frames_.size() + outstanding_frames; |
487 } | 486 } |
488 | 487 |
489 } // namespace media | 488 } // namespace media |
OLD | NEW |