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