Chromium Code Reviews| Index: media/video/capture/fake_capture_video_decoder.cc |
| =================================================================== |
| --- media/video/capture/fake_capture_video_decoder.cc (revision 0) |
| +++ media/video/capture/fake_capture_video_decoder.cc (revision 0) |
| @@ -0,0 +1,171 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/video/capture/fake_capture_video_decoder.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/message_loop.h" |
| +#include "media/base/demuxer_stream.h" |
| +#include "media/base/filter_host.h" |
| +#include "media/base/limits.h" |
| +#include "media/base/video_util.h" |
| + |
| +namespace media { |
| + |
| +FakeCaptureVideoDecoder::FakeCaptureVideoDecoder( |
| + base::MessageLoopProxy* message_loop_proxy, |
| + const VideoCapture::VideoCaptureCapability& capability) |
|
scherkus (not reviewing)
2011/12/21 20:26:45
if you passed in a gfx::Rect and base::TimeDelta f
wjia(left Chromium)
2012/01/03 17:08:12
Done.
|
| + : message_loop_proxy_(message_loop_proxy), |
| + capability_(capability), |
|
scherkus (not reviewing)
2011/12/21 20:26:45
this isn't used -- remove?
wjia(left Chromium)
2012/01/03 17:08:12
Done.
|
| + natural_size_(capability.width, capability.height), |
| + state_(kUnInitialized) { |
| + int64 interval = 33; |
| + if (capability.max_fps > 0) { |
| + interval = (1000 + capability.max_fps - 1) / capability.max_fps; |
| + } |
| + frame_interval_ms_ = base::TimeDelta::FromMilliseconds(interval); |
|
scherkus (not reviewing)
2011/12/21 20:26:45
nit: why not name this duration?
also ms suffix i
wjia(left Chromium)
2012/01/03 17:08:12
Done.
|
| +} |
| + |
| +FakeCaptureVideoDecoder::~FakeCaptureVideoDecoder() {} |
| + |
| +void FakeCaptureVideoDecoder::Initialize( |
| + DemuxerStream* demuxer_stream, |
| + const PipelineStatusCB& filter_callback, |
| + const StatisticsCallback& stat_callback) { |
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&FakeCaptureVideoDecoder::InitializeOnDecoderThread, |
| + this, make_scoped_refptr(demuxer_stream), |
| + filter_callback, stat_callback)); |
| +} |
| + |
| +void FakeCaptureVideoDecoder::Read(const ReadCB& callback) { |
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&FakeCaptureVideoDecoder::ReadOnDecoderThread, |
| + this, callback)); |
| +} |
| + |
| +const gfx::Size& FakeCaptureVideoDecoder::natural_size() { |
| + return natural_size_; |
| +} |
| + |
| +void FakeCaptureVideoDecoder::Pause(const base::Closure& callback) { |
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&FakeCaptureVideoDecoder::PauseOnDecoderThread, |
| + this, callback)); |
| +} |
| + |
| +void FakeCaptureVideoDecoder::Flush(const base::Closure& callback) { |
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&FakeCaptureVideoDecoder::FlushOnDecoderThread, |
| + this, callback)); |
| +} |
| + |
| +void FakeCaptureVideoDecoder::Stop(const base::Closure& callback) { |
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&FakeCaptureVideoDecoder::StopOnDecoderThread, |
| + this, callback)); |
| +} |
| + |
| +void FakeCaptureVideoDecoder::Seek(base::TimeDelta time, |
| + const FilterStatusCB& cb) { |
| + message_loop_proxy_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&FakeCaptureVideoDecoder::SeekOnDecoderThread, |
| + this, time, cb)); |
| +} |
| + |
| +void FakeCaptureVideoDecoder::InitializeOnDecoderThread( |
| + DemuxerStream* demuxer_stream, |
| + const PipelineStatusCB& filter_callback, |
| + const StatisticsCallback& stat_callback) { |
| + DVLOG(1) << "InitializeOnDecoderThread"; |
| + DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| + |
| + statistics_callback_ = stat_callback; |
|
scherkus (not reviewing)
2011/12/21 20:26:45
if you're not using this you don't have to save it
wjia(left Chromium)
2012/01/03 17:08:12
Done.
|
| + filter_callback.Run(PIPELINE_OK); |
| + state_ = kNormal; |
| +} |
| + |
| +void FakeCaptureVideoDecoder::ReadOnDecoderThread(const ReadCB& callback) { |
| + DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| + CHECK(read_cb_.is_null()); |
| + read_cb_ = callback; |
| + GenerateFrameOnDecoderThread(); |
|
scherkus (not reviewing)
2011/12/21 20:26:45
don't even bother saving the callback -- just gene
wjia(left Chromium)
2012/01/03 17:08:12
Done.
|
| +} |
| + |
| +void FakeCaptureVideoDecoder::PauseOnDecoderThread( |
|
scherkus (not reviewing)
2011/12/21 20:26:45
you shouldn't have to do anything on Pause() -- de
wjia(left Chromium)
2012/01/03 17:08:12
Done.
|
| + const base::Closure& callback) { |
| + DVLOG(1) << "PauseOnDecoderThread"; |
| + DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| + state_ = kPaused; |
| + VideoDecoder::Pause(callback); |
| +} |
| + |
| +void FakeCaptureVideoDecoder::FlushOnDecoderThread( |
|
scherkus (not reviewing)
2011/12/21 20:26:45
you shouldn't have to do anything on Flush() -- de
wjia(left Chromium)
2012/01/03 17:08:12
Done.
|
| + const base::Closure& callback) { |
| + DVLOG(1) << "FlushOnDecoderThread"; |
| + DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| + if (!read_cb_.is_null()) { |
| + scoped_refptr<VideoFrame> video_frame = |
| + VideoFrame::CreateBlackFrame(natural_size_.width(), |
| + natural_size_.height()); |
| + DeliverFrame(video_frame); |
| + } |
| + VideoDecoder::Flush(callback); |
| +} |
| + |
| +void FakeCaptureVideoDecoder::StopOnDecoderThread( |
| + const base::Closure& callback) { |
| + DVLOG(1) << "StopOnDecoderThread"; |
| + DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| + state_ = kStopped; |
| + VideoDecoder::Stop(callback); |
|
scherkus (not reviewing)
2011/12/21 20:26:45
just run the callback yourself :)
wjia(left Chromium)
2012/01/03 17:08:12
Done.
|
| +} |
| + |
| +void FakeCaptureVideoDecoder::SeekOnDecoderThread( |
|
scherkus (not reviewing)
2011/12/21 20:26:45
you shouldn't have to do anything on Seek() -- del
wjia(left Chromium)
2012/01/03 17:08:12
Done.
|
| + base::TimeDelta time, const FilterStatusCB& cb) { |
| + DVLOG(1) << "SeekOnDecoderThread"; |
| + DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| + |
| + cb.Run(PIPELINE_OK); |
| + state_ = kNormal; |
| + host()->SetNaturalVideoSize(natural_size_); |
|
scherkus (not reviewing)
2011/12/21 20:26:45
this shouldn't be needed as VideoRendererBase call
wjia(left Chromium)
2012/01/03 17:08:12
Done.
|
| + GenerateFrameOnDecoderThread(); |
| +} |
| + |
| +void FakeCaptureVideoDecoder::GenerateFrameOnDecoderThread() { |
| + DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| + |
| + if (read_cb_.is_null() || kNormal != state_) |
| + return; |
| + |
| + // Always allocate a new frame. |
| + // |
| + // TODO(scherkus): migrate this to proper buffer recycling. |
| + scoped_refptr<VideoFrame> video_frame = |
| + VideoFrame::CreateFrame(VideoFrame::YV12, |
| + natural_size_.width(), |
| + natural_size_.height(), |
| + base::TimeDelta(), |
|
scherkus (not reviewing)
2011/12/21 20:26:45
every timestamp is zero?
wjia(left Chromium)
2012/01/03 17:08:12
I thought frame_duration is good enough. current_t
|
| + frame_interval_ms_); |
| + |
| + // TODO(wjia): set pixel data to pre-defined patterns if it's desired to |
| + // verify frame content. |
| + DeliverFrame(video_frame); |
| +} |
| + |
| +void FakeCaptureVideoDecoder::DeliverFrame( |
| + const scoped_refptr<VideoFrame>& video_frame) { |
| + // Reset the callback before running to protect against reentrancy. |
| + ReadCB read_cb = read_cb_; |
| + read_cb_.Reset(); |
| + read_cb.Run(video_frame); |
| +} |
| + |
| +} // namespace media |
| Property changes on: media/video/capture/fake_capture_video_decoder.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |