|
OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/video/capture/fake_capture_video_decoder.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/message_loop.h" | |
9 #include "media/base/demuxer_stream.h" | |
10 #include "media/base/filter_host.h" | |
11 #include "media/base/limits.h" | |
12 #include "media/base/video_util.h" | |
13 | |
14 namespace media { | |
15 | |
16 FakeCaptureVideoDecoder::FakeCaptureVideoDecoder( | |
17 base::MessageLoopProxy* message_loop_proxy, | |
18 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.
| |
19 : message_loop_proxy_(message_loop_proxy), | |
20 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.
| |
21 natural_size_(capability.width, capability.height), | |
22 state_(kUnInitialized) { | |
23 int64 interval = 33; | |
24 if (capability.max_fps > 0) { | |
25 interval = (1000 + capability.max_fps - 1) / capability.max_fps; | |
26 } | |
27 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.
| |
28 } | |
29 | |
30 FakeCaptureVideoDecoder::~FakeCaptureVideoDecoder() {} | |
31 | |
32 void FakeCaptureVideoDecoder::Initialize( | |
33 DemuxerStream* demuxer_stream, | |
34 const PipelineStatusCB& filter_callback, | |
35 const StatisticsCallback& stat_callback) { | |
36 message_loop_proxy_->PostTask( | |
37 FROM_HERE, | |
38 base::Bind(&FakeCaptureVideoDecoder::InitializeOnDecoderThread, | |
39 this, make_scoped_refptr(demuxer_stream), | |
40 filter_callback, stat_callback)); | |
41 } | |
42 | |
43 void FakeCaptureVideoDecoder::Read(const ReadCB& callback) { | |
44 message_loop_proxy_->PostTask( | |
45 FROM_HERE, | |
46 base::Bind(&FakeCaptureVideoDecoder::ReadOnDecoderThread, | |
47 this, callback)); | |
48 } | |
49 | |
50 const gfx::Size& FakeCaptureVideoDecoder::natural_size() { | |
51 return natural_size_; | |
52 } | |
53 | |
54 void FakeCaptureVideoDecoder::Pause(const base::Closure& callback) { | |
55 message_loop_proxy_->PostTask( | |
56 FROM_HERE, | |
57 base::Bind(&FakeCaptureVideoDecoder::PauseOnDecoderThread, | |
58 this, callback)); | |
59 } | |
60 | |
61 void FakeCaptureVideoDecoder::Flush(const base::Closure& callback) { | |
62 message_loop_proxy_->PostTask( | |
63 FROM_HERE, | |
64 base::Bind(&FakeCaptureVideoDecoder::FlushOnDecoderThread, | |
65 this, callback)); | |
66 } | |
67 | |
68 void FakeCaptureVideoDecoder::Stop(const base::Closure& callback) { | |
69 message_loop_proxy_->PostTask( | |
70 FROM_HERE, | |
71 base::Bind(&FakeCaptureVideoDecoder::StopOnDecoderThread, | |
72 this, callback)); | |
73 } | |
74 | |
75 void FakeCaptureVideoDecoder::Seek(base::TimeDelta time, | |
76 const FilterStatusCB& cb) { | |
77 message_loop_proxy_->PostTask( | |
78 FROM_HERE, | |
79 base::Bind(&FakeCaptureVideoDecoder::SeekOnDecoderThread, | |
80 this, time, cb)); | |
81 } | |
82 | |
83 void FakeCaptureVideoDecoder::InitializeOnDecoderThread( | |
84 DemuxerStream* demuxer_stream, | |
85 const PipelineStatusCB& filter_callback, | |
86 const StatisticsCallback& stat_callback) { | |
87 DVLOG(1) << "InitializeOnDecoderThread"; | |
88 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | |
89 | |
90 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.
| |
91 filter_callback.Run(PIPELINE_OK); | |
92 state_ = kNormal; | |
93 } | |
94 | |
95 void FakeCaptureVideoDecoder::ReadOnDecoderThread(const ReadCB& callback) { | |
96 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | |
97 CHECK(read_cb_.is_null()); | |
98 read_cb_ = callback; | |
99 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.
| |
100 } | |
101 | |
102 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.
| |
103 const base::Closure& callback) { | |
104 DVLOG(1) << "PauseOnDecoderThread"; | |
105 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | |
106 state_ = kPaused; | |
107 VideoDecoder::Pause(callback); | |
108 } | |
109 | |
110 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.
| |
111 const base::Closure& callback) { | |
112 DVLOG(1) << "FlushOnDecoderThread"; | |
113 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | |
114 if (!read_cb_.is_null()) { | |
115 scoped_refptr<VideoFrame> video_frame = | |
116 VideoFrame::CreateBlackFrame(natural_size_.width(), | |
117 natural_size_.height()); | |
118 DeliverFrame(video_frame); | |
119 } | |
120 VideoDecoder::Flush(callback); | |
121 } | |
122 | |
123 void FakeCaptureVideoDecoder::StopOnDecoderThread( | |
124 const base::Closure& callback) { | |
125 DVLOG(1) << "StopOnDecoderThread"; | |
126 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | |
127 state_ = kStopped; | |
128 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.
| |
129 } | |
130 | |
131 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.
| |
132 base::TimeDelta time, const FilterStatusCB& cb) { | |
133 DVLOG(1) << "SeekOnDecoderThread"; | |
134 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | |
135 | |
136 cb.Run(PIPELINE_OK); | |
137 state_ = kNormal; | |
138 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.
| |
139 GenerateFrameOnDecoderThread(); | |
140 } | |
141 | |
142 void FakeCaptureVideoDecoder::GenerateFrameOnDecoderThread() { | |
143 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | |
144 | |
145 if (read_cb_.is_null() || kNormal != state_) | |
146 return; | |
147 | |
148 // Always allocate a new frame. | |
149 // | |
150 // TODO(scherkus): migrate this to proper buffer recycling. | |
151 scoped_refptr<VideoFrame> video_frame = | |
152 VideoFrame::CreateFrame(VideoFrame::YV12, | |
153 natural_size_.width(), | |
154 natural_size_.height(), | |
155 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
| |
156 frame_interval_ms_); | |
157 | |
158 // TODO(wjia): set pixel data to pre-defined patterns if it's desired to | |
159 // verify frame content. | |
160 DeliverFrame(video_frame); | |
161 } | |
162 | |
163 void FakeCaptureVideoDecoder::DeliverFrame( | |
164 const scoped_refptr<VideoFrame>& video_frame) { | |
165 // Reset the callback before running to protect against reentrancy. | |
166 ReadCB read_cb = read_cb_; | |
167 read_cb_.Reset(); | |
168 read_cb.Run(video_frame); | |
169 } | |
170 | |
171 } // namespace media | |
OLD | NEW |