Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: media/video/capture/fake_video_capture_device.cc

Issue 1179323002: Video Capture: extract storage info from pixel format in VideoCaptureFormat. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hubbe@s comments and minor rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 DCHECK_EQ(capture_buffer->GetType(), gfx::SHARED_MEMORY_BUFFER); 188 DCHECK_EQ(capture_buffer->GetType(), gfx::SHARED_MEMORY_BUFFER);
183 memset(data_ptr, 0, capture_buffer->size()); 189 memset(data_ptr, 0, capture_buffer->size());
184 190
185 DrawPacman( 191 DrawPacman((pixel_format == media::PIXEL_FORMAT_ARGB), /* use_argb */
186 (pixel_format == media::PIXEL_FORMAT_GPUMEMORYBUFFER), /* use_argb */ 192 data_ptr,
187 data_ptr, 193 frame_count_,
188 frame_count_, 194 kFakeCapturePeriodMs,
189 kFakeCapturePeriodMs, 195 capture_format_.frame_size);
190 capture_format_.frame_size);
191 196
192 // Give the captured frame to the client. 197 // Give the captured frame to the client.
193 const VideoCaptureFormat format(capture_format_.frame_size, 198 const VideoCaptureFormat format(capture_format_.frame_size,
194 capture_format_.frame_rate, 199 capture_format_.frame_rate,
195 pixel_format); 200 pixel_format,
201 pixel_storage);
196 client_->OnIncomingCapturedBuffer(capture_buffer.Pass(), format, 202 client_->OnIncomingCapturedBuffer(capture_buffer.Pass(), format,
197 base::TimeTicks::Now()); 203 base::TimeTicks::Now());
198 } 204 }
199 205
200 BeepAndScheduleNextCapture( 206 BeepAndScheduleNextCapture(
201 expected_execution_time, 207 expected_execution_time,
202 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers, 208 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers,
203 weak_factory_.GetWeakPtr(), pixel_format)); 209 weak_factory_.GetWeakPtr(), pixel_format, pixel_storage));
204 } 210 }
205 211
206 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture( 212 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture(
207 base::TimeTicks expected_execution_time, 213 base::TimeTicks expected_execution_time,
208 const base::Callback<void(base::TimeTicks)>& next_capture) { 214 const base::Callback<void(base::TimeTicks)>& next_capture) {
209 // Generate a synchronized beep sound every so many frames. 215 // Generate a synchronized beep sound every so many frames.
210 if (frame_count_++ % kFakeCaptureBeepCycle == 0) 216 if (frame_count_++ % kFakeCaptureBeepCycle == 0)
211 FakeAudioInputStream::BeepOnce(); 217 FakeAudioInputStream::BeepOnce();
212 218
213 // Reschedule next CaptureTask. 219 // Reschedule next CaptureTask.
214 const base::TimeTicks current_time = base::TimeTicks::Now(); 220 const base::TimeTicks current_time = base::TimeTicks::Now();
215 const base::TimeDelta frame_interval = 221 const base::TimeDelta frame_interval =
216 base::TimeDelta::FromMilliseconds(kFakeCapturePeriodMs); 222 base::TimeDelta::FromMilliseconds(kFakeCapturePeriodMs);
217 // Don't accumulate any debt if we are lagging behind - just post the next 223 // Don't accumulate any debt if we are lagging behind - just post the next
218 // frame immediately and continue as normal. 224 // frame immediately and continue as normal.
219 const base::TimeTicks next_execution_time = 225 const base::TimeTicks next_execution_time =
220 std::max(current_time, expected_execution_time + frame_interval); 226 std::max(current_time, expected_execution_time + frame_interval);
221 const base::TimeDelta delay = next_execution_time - current_time; 227 const base::TimeDelta delay = next_execution_time - current_time;
222 base::MessageLoop::current()->PostDelayedTask( 228 base::MessageLoop::current()->PostDelayedTask(
223 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); 229 FROM_HERE, base::Bind(next_capture, next_execution_time), delay);
224 } 230 }
225 231
226 } // namespace media 232 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698