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

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

Issue 7461016: Replace VideoDecoder::media_format() with significantly simpler width()/height() methods. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: fixes Created 9 years, 5 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
« 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) 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/callback.h" 9 #include "media/base/callback.h"
10 #include "media/base/filter_host.h" 10 #include "media/base/filter_host.h"
(...skipping 10 matching lines...) Expand all
21 // audio renderer to catch up faster. A lower value will be a smoother frame 21 // audio renderer to catch up faster. A lower value will be a smoother frame
22 // rate, but results in the video being out of sync for longer. 22 // rate, but results in the video being out of sync for longer.
23 static const int64 kMaxSleepMilliseconds = 60; 23 static const int64 kMaxSleepMilliseconds = 60;
24 24
25 // The number of milliseconds to idle when we do not have anything to do. 25 // The number of milliseconds to idle when we do not have anything to do.
26 // Nothing special about the value, other than we're being more OS-friendly 26 // Nothing special about the value, other than we're being more OS-friendly
27 // than sleeping for 1 millisecond. 27 // than sleeping for 1 millisecond.
28 static const int kIdleMilliseconds = 10; 28 static const int kIdleMilliseconds = 10;
29 29
30 VideoRendererBase::VideoRendererBase() 30 VideoRendererBase::VideoRendererBase()
31 : width_(0), 31 : frame_available_(&lock_),
32 height_(0),
33 surface_format_(VideoFrame::INVALID),
34 frame_available_(&lock_),
35 state_(kUninitialized), 32 state_(kUninitialized),
36 thread_(base::kNullThreadHandle), 33 thread_(base::kNullThreadHandle),
37 pending_reads_(0), 34 pending_reads_(0),
38 pending_paint_(false), 35 pending_paint_(false),
39 pending_paint_with_last_available_(false), 36 pending_paint_with_last_available_(false),
40 playback_rate_(0) { 37 playback_rate_(0) {
41 } 38 }
42 39
43 VideoRendererBase::~VideoRendererBase() { 40 VideoRendererBase::~VideoRendererBase() {
44 base::AutoLock auto_lock(lock_); 41 base::AutoLock auto_lock(lock_);
45 DCHECK(state_ == kUninitialized || state_ == kStopped); 42 DCHECK(state_ == kUninitialized || state_ == kStopped);
46 } 43 }
47 44
48 // static
49 bool VideoRendererBase::ParseMediaFormat(
50 const MediaFormat& media_format,
51 VideoFrame::Format* surface_format_out,
52 int* width_out, int* height_out) {
53 int surface_format;
54 if (!media_format.GetAsInteger(MediaFormat::kSurfaceFormat, &surface_format))
55 return false;
56 if (surface_format_out)
57 *surface_format_out = static_cast<VideoFrame::Format>(surface_format);
58
59 int width, height;
60 if (!media_format.GetAsInteger(MediaFormat::kWidth, &width))
61 return false;
62 if (!media_format.GetAsInteger(MediaFormat::kHeight, &height))
63 return false;
64 if (width_out) *width_out = width;
65 if (height_out) *height_out = height;
66 return true;
67 }
68
69 void VideoRendererBase::Play(FilterCallback* callback) { 45 void VideoRendererBase::Play(FilterCallback* callback) {
70 base::AutoLock auto_lock(lock_); 46 base::AutoLock auto_lock(lock_);
71 DCHECK_EQ(kPrerolled, state_); 47 DCHECK_EQ(kPrerolled, state_);
72 scoped_ptr<FilterCallback> c(callback); 48 scoped_ptr<FilterCallback> c(callback);
73 state_ = kPlaying; 49 state_ = kPlaying;
74 callback->Run(); 50 callback->Run();
75 } 51 }
76 52
77 void VideoRendererBase::Pause(FilterCallback* callback) { 53 void VideoRendererBase::Pause(FilterCallback* callback) {
78 base::AutoLock auto_lock(lock_); 54 base::AutoLock auto_lock(lock_);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 decoder_ = decoder; 142 decoder_ = decoder;
167 AutoCallbackRunner done_runner(callback); 143 AutoCallbackRunner done_runner(callback);
168 144
169 statistics_callback_.reset(stats_callback); 145 statistics_callback_.reset(stats_callback);
170 146
171 decoder_->set_consume_video_frame_callback( 147 decoder_->set_consume_video_frame_callback(
172 base::Bind(&VideoRendererBase::ConsumeVideoFrame, 148 base::Bind(&VideoRendererBase::ConsumeVideoFrame,
173 base::Unretained(this))); 149 base::Unretained(this)));
174 150
175 // Notify the pipeline of the video dimensions. 151 // Notify the pipeline of the video dimensions.
176 if (!ParseMediaFormat(decoder->media_format(), 152 host()->SetVideoSize(decoder_->width(), decoder_->height());
177 &surface_format_,
178 &width_, &height_)) {
179 EnterErrorState_Locked(PIPELINE_ERROR_INITIALIZATION_FAILED);
180 return;
181 }
182 host()->SetVideoSize(width_, height_);
183 153
184 // Initialize the subclass. 154 // Initialize the subclass.
185 // TODO(scherkus): do we trust subclasses not to do something silly while 155 // TODO(scherkus): do we trust subclasses not to do something silly while
186 // we're holding the lock? 156 // we're holding the lock?
187 if (!OnInitialize(decoder)) { 157 if (!OnInitialize(decoder)) {
188 EnterErrorState_Locked(PIPELINE_ERROR_INITIALIZATION_FAILED); 158 EnterErrorState_Locked(PIPELINE_ERROR_INITIALIZATION_FAILED);
189 return; 159 return;
190 } 160 }
191 161
192 // We're all good! Consider ourselves flushed. (ThreadMain() should never 162 // We're all good! Consider ourselves flushed. (ThreadMain() should never
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 } else if (state_ == kFlushing && pending_reads_ == 0 && !pending_paint_) { 442 } else if (state_ == kFlushing && pending_reads_ == 0 && !pending_paint_) {
473 OnFlushDone(); 443 OnFlushDone();
474 } 444 }
475 445
476 if (new_frame_available) { 446 if (new_frame_available) {
477 base::AutoUnlock auto_unlock(lock_); 447 base::AutoUnlock auto_unlock(lock_);
478 OnFrameAvailable(); 448 OnFrameAvailable();
479 } 449 }
480 } 450 }
481 451
482 VideoDecoder* VideoRendererBase::GetDecoder() {
483 return decoder_.get();
484 }
485
486 void VideoRendererBase::ReadInput(scoped_refptr<VideoFrame> frame) { 452 void VideoRendererBase::ReadInput(scoped_refptr<VideoFrame> frame) {
487 // We should never return empty frames or EOS frame. 453 // We should never return empty frames or EOS frame.
488 DCHECK(frame.get() && !frame->IsEndOfStream()); 454 DCHECK(frame.get() && !frame->IsEndOfStream());
489 455
490 decoder_->ProduceVideoFrame(frame); 456 decoder_->ProduceVideoFrame(frame);
491 ++pending_reads_; 457 ++pending_reads_;
492 } 458 }
493 459
494 void VideoRendererBase::ScheduleRead_Locked() { 460 void VideoRendererBase::ScheduleRead_Locked() {
495 lock_.AssertAcquired(); 461 lock_.AssertAcquired();
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 void VideoRendererBase::DoStopOrErrorFlush_Locked() { 591 void VideoRendererBase::DoStopOrErrorFlush_Locked() {
626 DCHECK(!pending_paint_); 592 DCHECK(!pending_paint_);
627 DCHECK(!pending_paint_with_last_available_); 593 DCHECK(!pending_paint_with_last_available_);
628 lock_.AssertAcquired(); 594 lock_.AssertAcquired();
629 FlushBuffers(); 595 FlushBuffers();
630 last_available_frame_ = NULL; 596 last_available_frame_ = NULL;
631 DCHECK_EQ(pending_reads_, 0); 597 DCHECK_EQ(pending_reads_, 0);
632 } 598 }
633 599
634 } // namespace media 600 } // 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