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