| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/callback.h" | 5 #include "base/callback.h" |
| 6 #include "media/base/buffers.h" | 6 #include "media/base/buffers.h" |
| 7 #include "media/base/filter_host.h" | 7 #include "media/base/filter_host.h" |
| 8 #include "media/base/video_frame_impl.h" | 8 #include "media/base/video_frame.h" |
| 9 #include "media/filters/video_renderer_base.h" | 9 #include "media/filters/video_renderer_base.h" |
| 10 | 10 |
| 11 namespace media { | 11 namespace media { |
| 12 | 12 |
| 13 // Limit our read ahead to three frames. One frame is typically in flux at all | 13 // Limit our read ahead to three frames. One frame is typically in flux at all |
| 14 // times, as in frame n is discarded at the top of ThreadMain() while frame | 14 // times, as in frame n is discarded at the top of ThreadMain() while frame |
| 15 // (n + kMaxFrames) is being asynchronously fetched. The remaining two frames | 15 // (n + kMaxFrames) is being asynchronously fetched. The remaining two frames |
| 16 // allow us to advance the current frame as well as read the timestamp of the | 16 // allow us to advance the current frame as well as read the timestamp of the |
| 17 // following frame for more accurate timing. | 17 // following frame for more accurate timing. |
| 18 // | 18 // |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // TODO(scherkus): do we trust subclasses not to do something silly while | 150 // TODO(scherkus): do we trust subclasses not to do something silly while |
| 151 // we're holding the lock? | 151 // we're holding the lock? |
| 152 if (!OnInitialize(decoder)) { | 152 if (!OnInitialize(decoder)) { |
| 153 host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); | 153 host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 154 callback->Run(); | 154 callback->Run(); |
| 155 return; | 155 return; |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Create a black frame so clients have something to render before we finish | 158 // Create a black frame so clients have something to render before we finish |
| 159 // prerolling. | 159 // prerolling. |
| 160 VideoFrameImpl::CreateBlackFrame(width_, height_, ¤t_frame_); | 160 VideoFrame::CreateBlackFrame(width_, height_, ¤t_frame_); |
| 161 | 161 |
| 162 // We're all good! Consider ourselves paused (ThreadMain() should never | 162 // We're all good! Consider ourselves paused (ThreadMain() should never |
| 163 // see us in the kUninitialized state). | 163 // see us in the kUninitialized state). |
| 164 state_ = kPaused; | 164 state_ = kPaused; |
| 165 | 165 |
| 166 // Create our video thread. | 166 // Create our video thread. |
| 167 if (!PlatformThread::Create(0, this, &thread_)) { | 167 if (!PlatformThread::Create(0, this, &thread_)) { |
| 168 NOTREACHED() << "Video thread creation failed"; | 168 NOTREACHED() << "Video thread creation failed"; |
| 169 host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); | 169 host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 170 callback->Run(); | 170 callback->Run(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 frame_available_.Signal(); | 315 frame_available_.Signal(); |
| 316 | 316 |
| 317 // Check for our preroll complete condition. | 317 // Check for our preroll complete condition. |
| 318 if (state_ == kSeeking) { | 318 if (state_ == kSeeking) { |
| 319 DCHECK(seek_callback_.get()); | 319 DCHECK(seek_callback_.get()); |
| 320 if (frames_.size() == kMaxFrames) { | 320 if (frames_.size() == kMaxFrames) { |
| 321 // We're paused, so make sure we update |current_frame_| to represent | 321 // We're paused, so make sure we update |current_frame_| to represent |
| 322 // our new location. | 322 // our new location. |
| 323 state_ = kPaused; | 323 state_ = kPaused; |
| 324 if (frames_.front()->IsEndOfStream()) { | 324 if (frames_.front()->IsEndOfStream()) { |
| 325 VideoFrameImpl::CreateBlackFrame(width_, height_, ¤t_frame_); | 325 VideoFrame::CreateBlackFrame(width_, height_, ¤t_frame_); |
| 326 } else { | 326 } else { |
| 327 current_frame_ = frames_.front(); | 327 current_frame_ = frames_.front(); |
| 328 } | 328 } |
| 329 | 329 |
| 330 // Because we might remain paused (i.e., we were not playing before we | 330 // Because we might remain paused (i.e., we were not playing before we |
| 331 // received a seek), we can't rely on ThreadMain() to notify the subclass | 331 // received a seek), we can't rely on ThreadMain() to notify the subclass |
| 332 // the frame has been updated. | 332 // the frame has been updated. |
| 333 DCHECK(current_frame_); | 333 DCHECK(current_frame_); |
| 334 OnFrameAvailable(); | 334 OnFrameAvailable(); |
| 335 | 335 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 previous_time_ = now; | 376 previous_time_ = now; |
| 377 } | 377 } |
| 378 | 378 |
| 379 // Scale our sleep based on the playback rate. | 379 // Scale our sleep based on the playback rate. |
| 380 // TODO(scherkus): floating point badness and degrade gracefully. | 380 // TODO(scherkus): floating point badness and degrade gracefully. |
| 381 return base::TimeDelta::FromMicroseconds( | 381 return base::TimeDelta::FromMicroseconds( |
| 382 static_cast<int64>(sleep.InMicroseconds() / playback_rate)); | 382 static_cast<int64>(sleep.InMicroseconds() / playback_rate)); |
| 383 } | 383 } |
| 384 | 384 |
| 385 } // namespace media | 385 } // namespace media |
| OLD | NEW |