OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/video/capture/fake_video_capture_device.h" | 5 #include "media/video/capture/fake_video_capture_device.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 capture_format_.frame_size.SetSize(1920, 1080); | 95 capture_format_.frame_size.SetSize(1920, 1080); |
96 else if (params.requested_format.frame_size.width() > 640) | 96 else if (params.requested_format.frame_size.width() > 640) |
97 capture_format_.frame_size.SetSize(1280, 720); | 97 capture_format_.frame_size.SetSize(1280, 720); |
98 else if (params.requested_format.frame_size.width() > 320) | 98 else if (params.requested_format.frame_size.width() > 320) |
99 capture_format_.frame_size.SetSize(640, 480); | 99 capture_format_.frame_size.SetSize(640, 480); |
100 else | 100 else |
101 capture_format_.frame_size.SetSize(320, 240); | 101 capture_format_.frame_size.SetSize(320, 240); |
102 | 102 |
103 if (device_type_ == USING_OWN_BUFFERS || | 103 if (device_type_ == USING_OWN_BUFFERS || |
104 device_type_ == USING_OWN_BUFFERS_TRIPLANAR) { | 104 device_type_ == USING_OWN_BUFFERS_TRIPLANAR) { |
105 capture_format_.pixel_storage = PIXEL_STORAGE_CPU; | |
106 fake_frame_.reset(new uint8[VideoFrame::AllocationSize( | 105 fake_frame_.reset(new uint8[VideoFrame::AllocationSize( |
107 VideoFrame::I420, capture_format_.frame_size)]); | 106 VideoFrame::I420, capture_format_.frame_size)]); |
108 BeepAndScheduleNextCapture( | 107 BeepAndScheduleNextCapture( |
109 base::TimeTicks::Now(), | 108 base::TimeTicks::Now(), |
110 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, | 109 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, |
111 weak_factory_.GetWeakPtr())); | 110 weak_factory_.GetWeakPtr())); |
112 } else if (device_type_ == USING_CLIENT_BUFFERS_I420 || | 111 } else if (device_type_ == USING_CLIENT_BUFFERS_I420 || |
113 device_type_ == USING_CLIENT_BUFFERS_GPU) { | 112 device_type_ == USING_CLIENT_BUFFERS_GPU) { |
114 DVLOG(1) << "starting with " << (device_type_ == USING_CLIENT_BUFFERS_I420 | 113 DVLOG(1) << "starting with " << (device_type_ == USING_CLIENT_BUFFERS_I420 |
115 ? "Client buffers" | 114 ? "Client buffers" |
116 : "GpuMemoryBuffers"); | 115 : "GpuMemoryBuffers"); |
117 BeepAndScheduleNextCapture( | 116 BeepAndScheduleNextCapture( |
118 base::TimeTicks::Now(), | 117 base::TimeTicks::Now(), |
119 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers, | 118 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers, |
120 weak_factory_.GetWeakPtr(), | 119 weak_factory_.GetWeakPtr(), |
121 (device_type_ == USING_CLIENT_BUFFERS_I420 | 120 (device_type_ == USING_CLIENT_BUFFERS_I420 |
122 ? PIXEL_FORMAT_I420 | 121 ? PIXEL_FORMAT_I420 |
123 : PIXEL_FORMAT_ARGB), | 122 : PIXEL_FORMAT_GPUMEMORYBUFFER))); |
124 (device_type_ == USING_CLIENT_BUFFERS_GPU | |
125 ? PIXEL_STORAGE_GPUMEMORYBUFFER | |
126 : PIXEL_STORAGE_CPU))); | |
127 } else { | 123 } else { |
128 client_->OnError("Unknown Fake Video Capture Device type."); | 124 client_->OnError("Unknown Fake Video Capture Device type."); |
129 } | 125 } |
130 } | 126 } |
131 | 127 |
132 void FakeVideoCaptureDevice::StopAndDeAllocate() { | 128 void FakeVideoCaptureDevice::StopAndDeAllocate() { |
133 DCHECK(thread_checker_.CalledOnValidThread()); | 129 DCHECK(thread_checker_.CalledOnValidThread()); |
134 client_.reset(); | 130 client_.reset(); |
135 } | 131 } |
136 | 132 |
(...skipping 29 matching lines...) Expand all Loading... |
166 base::TimeTicks::Now()); | 162 base::TimeTicks::Now()); |
167 } | 163 } |
168 BeepAndScheduleNextCapture( | 164 BeepAndScheduleNextCapture( |
169 expected_execution_time, | 165 expected_execution_time, |
170 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, | 166 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, |
171 weak_factory_.GetWeakPtr())); | 167 weak_factory_.GetWeakPtr())); |
172 } | 168 } |
173 | 169 |
174 void FakeVideoCaptureDevice::CaptureUsingClientBuffers( | 170 void FakeVideoCaptureDevice::CaptureUsingClientBuffers( |
175 VideoPixelFormat pixel_format, | 171 VideoPixelFormat pixel_format, |
176 VideoPixelStorage pixel_storage, | |
177 base::TimeTicks expected_execution_time) { | 172 base::TimeTicks expected_execution_time) { |
178 DCHECK(thread_checker_.CalledOnValidThread()); | 173 DCHECK(thread_checker_.CalledOnValidThread()); |
179 | 174 |
180 scoped_ptr<VideoCaptureDevice::Client::Buffer> capture_buffer( | 175 scoped_ptr<VideoCaptureDevice::Client::Buffer> capture_buffer( |
181 client_->ReserveOutputBuffer(capture_format_.frame_size, pixel_format, | 176 client_->ReserveOutputBuffer(pixel_format, capture_format_.frame_size)); |
182 pixel_storage)); | |
183 DLOG_IF(ERROR, !capture_buffer) << "Couldn't allocate Capture Buffer"; | 177 DLOG_IF(ERROR, !capture_buffer) << "Couldn't allocate Capture Buffer"; |
184 | 178 |
185 if (capture_buffer.get()) { | 179 if (capture_buffer.get()) { |
186 uint8_t* const data_ptr = static_cast<uint8_t*>(capture_buffer->data()); | 180 uint8_t* const data_ptr = static_cast<uint8_t*>(capture_buffer->data()); |
187 DCHECK(data_ptr) << "Buffer has NO backing memory"; | 181 DCHECK(data_ptr) << "Buffer has NO backing memory"; |
188 memset(data_ptr, 0, capture_buffer->size()); | 182 memset(data_ptr, 0, capture_buffer->size()); |
189 | 183 |
190 DrawPacman((pixel_format == media::PIXEL_FORMAT_ARGB), /* use_argb */ | 184 DrawPacman( |
191 data_ptr, | 185 (pixel_format == media::PIXEL_FORMAT_GPUMEMORYBUFFER), /* use_argb */ |
192 frame_count_, | 186 data_ptr, |
193 kFakeCapturePeriodMs, | 187 frame_count_, |
194 capture_format_.frame_size); | 188 kFakeCapturePeriodMs, |
| 189 capture_format_.frame_size); |
195 | 190 |
196 // Give the captured frame to the client. | 191 // Give the captured frame to the client. |
197 const VideoCaptureFormat format(capture_format_.frame_size, | 192 const VideoCaptureFormat format(capture_format_.frame_size, |
198 capture_format_.frame_rate, | 193 capture_format_.frame_rate, |
199 pixel_format, | 194 pixel_format); |
200 pixel_storage); | |
201 client_->OnIncomingCapturedBuffer(capture_buffer.Pass(), format, | 195 client_->OnIncomingCapturedBuffer(capture_buffer.Pass(), format, |
202 base::TimeTicks::Now()); | 196 base::TimeTicks::Now()); |
203 } | 197 } |
204 | 198 |
205 BeepAndScheduleNextCapture( | 199 BeepAndScheduleNextCapture( |
206 expected_execution_time, | 200 expected_execution_time, |
207 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers, | 201 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers, |
208 weak_factory_.GetWeakPtr(), pixel_format, pixel_storage)); | 202 weak_factory_.GetWeakPtr(), pixel_format)); |
209 } | 203 } |
210 | 204 |
211 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture( | 205 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture( |
212 base::TimeTicks expected_execution_time, | 206 base::TimeTicks expected_execution_time, |
213 const base::Callback<void(base::TimeTicks)>& next_capture) { | 207 const base::Callback<void(base::TimeTicks)>& next_capture) { |
214 // Generate a synchronized beep sound every so many frames. | 208 // Generate a synchronized beep sound every so many frames. |
215 if (frame_count_++ % kFakeCaptureBeepCycle == 0) | 209 if (frame_count_++ % kFakeCaptureBeepCycle == 0) |
216 FakeAudioInputStream::BeepOnce(); | 210 FakeAudioInputStream::BeepOnce(); |
217 | 211 |
218 // Reschedule next CaptureTask. | 212 // Reschedule next CaptureTask. |
219 const base::TimeTicks current_time = base::TimeTicks::Now(); | 213 const base::TimeTicks current_time = base::TimeTicks::Now(); |
220 const base::TimeDelta frame_interval = | 214 const base::TimeDelta frame_interval = |
221 base::TimeDelta::FromMilliseconds(kFakeCapturePeriodMs); | 215 base::TimeDelta::FromMilliseconds(kFakeCapturePeriodMs); |
222 // Don't accumulate any debt if we are lagging behind - just post the next | 216 // Don't accumulate any debt if we are lagging behind - just post the next |
223 // frame immediately and continue as normal. | 217 // frame immediately and continue as normal. |
224 const base::TimeTicks next_execution_time = | 218 const base::TimeTicks next_execution_time = |
225 std::max(current_time, expected_execution_time + frame_interval); | 219 std::max(current_time, expected_execution_time + frame_interval); |
226 const base::TimeDelta delay = next_execution_time - current_time; | 220 const base::TimeDelta delay = next_execution_time - current_time; |
227 base::MessageLoop::current()->PostDelayedTask( | 221 base::MessageLoop::current()->PostDelayedTask( |
228 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); | 222 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); |
229 } | 223 } |
230 | 224 |
231 } // namespace media | 225 } // namespace media |
OLD | NEW |