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

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

Issue 2101022: refactoring decoder interface (Closed)
Patch Set: q Created 10 years, 6 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
« no previous file with comments | « media/filters/video_renderer_base.h ('k') | media/filters/video_renderer_base_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.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
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 void VideoRendererBase::Initialize(VideoDecoder* decoder, 140 void VideoRendererBase::Initialize(VideoDecoder* decoder,
141 FilterCallback* callback) { 141 FilterCallback* callback) {
142 AutoLock auto_lock(lock_); 142 AutoLock auto_lock(lock_);
143 DCHECK(decoder); 143 DCHECK(decoder);
144 DCHECK(callback); 144 DCHECK(callback);
145 DCHECK_EQ(kUninitialized, state_); 145 DCHECK_EQ(kUninitialized, state_);
146 decoder_ = decoder; 146 decoder_ = decoder;
147 scoped_ptr<FilterCallback> c(callback); 147 scoped_ptr<FilterCallback> c(callback);
148 148
149 decoder_->set_fill_buffer_done_callback(
150 NewCallback(this, &VideoRendererBase::OnFillBufferDone));
149 // Notify the pipeline of the video dimensions. 151 // Notify the pipeline of the video dimensions.
150 if (!ParseMediaFormat(decoder->media_format(), &width_, &height_, 152 if (!ParseMediaFormat(decoder->media_format(), &width_, &height_,
151 &uses_egl_image_)) { 153 &uses_egl_image_)) {
152 host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); 154 host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED);
153 callback->Run(); 155 callback->Run();
154 return; 156 return;
155 } 157 }
156 host()->SetVideoSize(width_, height_); 158 host()->SetVideoSize(width_, height_);
157 159
158 // Initialize the subclass. 160 // Initialize the subclass.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 307
306 void VideoRendererBase::GetCurrentFrame(scoped_refptr<VideoFrame>* frame_out) { 308 void VideoRendererBase::GetCurrentFrame(scoped_refptr<VideoFrame>* frame_out) {
307 AutoLock auto_lock(lock_); 309 AutoLock auto_lock(lock_);
308 // We should have initialized and have the current frame. 310 // We should have initialized and have the current frame.
309 DCHECK(state_ == kPaused || state_ == kSeeking || state_ == kPlaying || 311 DCHECK(state_ == kPaused || state_ == kSeeking || state_ == kPlaying ||
310 state_ == kEnded); 312 state_ == kEnded);
311 DCHECK(current_frame_); 313 DCHECK(current_frame_);
312 *frame_out = current_frame_; 314 *frame_out = current_frame_;
313 } 315 }
314 316
315 void VideoRendererBase::OnReadComplete(VideoFrame* frame) { 317 void VideoRendererBase::OnFillBufferDone(scoped_refptr<VideoFrame> frame) {
316 AutoLock auto_lock(lock_); 318 AutoLock auto_lock(lock_);
317 319
318 // TODO(ajwong): Work around cause we don't synchronize on stop. Correct 320 // TODO(ajwong): Work around cause we don't synchronize on stop. Correct
319 // fix is to resolve http://crbug.com/16059. 321 // fix is to resolve http://crbug.com/16059.
320 if (state_ == kStopped) { 322 if (state_ == kStopped) {
321 return; 323 return;
322 } 324 }
323 325
324 DCHECK(state_ == kPaused || state_ == kSeeking || state_ == kPlaying || 326 DCHECK(state_ == kPaused || state_ == kSeeking || state_ == kPlaying ||
325 state_ == kEnded); 327 state_ == kEnded);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 pause_callback_.reset(); 362 pause_callback_.reset();
361 } 363 }
362 } 364 }
363 } 365 }
364 366
365 void VideoRendererBase::ScheduleRead_Locked() { 367 void VideoRendererBase::ScheduleRead_Locked() {
366 lock_.AssertAcquired(); 368 lock_.AssertAcquired();
367 DCHECK_NE(kEnded, state_); 369 DCHECK_NE(kEnded, state_);
368 DCHECK_LT(pending_reads_, kMaxFrames); 370 DCHECK_LT(pending_reads_, kMaxFrames);
369 ++pending_reads_; 371 ++pending_reads_;
370 decoder_->Read(NewCallback(this, &VideoRendererBase::OnReadComplete)); 372 // TODO(jiesun): We use dummy buffer to feed decoder to let decoder to
373 // provide buffer pools. In the future, we may want to implement real
374 // buffer pool to recycle buffers.
375 scoped_refptr<VideoFrame> video_frame;
376 decoder_->FillThisBuffer(video_frame);
371 } 377 }
372 378
373 base::TimeDelta VideoRendererBase::CalculateSleepDuration( 379 base::TimeDelta VideoRendererBase::CalculateSleepDuration(
374 VideoFrame* next_frame, float playback_rate) { 380 VideoFrame* next_frame, float playback_rate) {
375 // Determine the current and next presentation timestamps. 381 // Determine the current and next presentation timestamps.
376 base::TimeDelta now = host()->GetTime(); 382 base::TimeDelta now = host()->GetTime();
377 base::TimeDelta this_pts = current_frame_->GetTimestamp(); 383 base::TimeDelta this_pts = current_frame_->GetTimestamp();
378 base::TimeDelta next_pts; 384 base::TimeDelta next_pts;
379 if (next_frame) { 385 if (next_frame) {
380 next_pts = next_frame->GetTimestamp(); 386 next_pts = next_frame->GetTimestamp();
(...skipping 12 matching lines...) Expand all
393 previous_time_ = now; 399 previous_time_ = now;
394 } 400 }
395 401
396 // Scale our sleep based on the playback rate. 402 // Scale our sleep based on the playback rate.
397 // TODO(scherkus): floating point badness and degrade gracefully. 403 // TODO(scherkus): floating point badness and degrade gracefully.
398 return base::TimeDelta::FromMicroseconds( 404 return base::TimeDelta::FromMicroseconds(
399 static_cast<int64>(sleep.InMicroseconds() / playback_rate)); 405 static_cast<int64>(sleep.InMicroseconds() / playback_rate));
400 } 406 }
401 407
402 } // namespace media 408 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/video_renderer_base.h ('k') | media/filters/video_renderer_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698