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

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

Issue 1090273006: Revert of VideoCapture: add support for GpuMemoryBuffer allocation and lifetime mgmt in VideoCaptureBufferPool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 capture_format_.frame_rate = 30.0; 94 capture_format_.frame_rate = 30.0;
95 if (params.requested_format.frame_size.width() > 1280) 95 if (params.requested_format.frame_size.width() > 1280)
96 capture_format_.frame_size.SetSize(1920, 1080); 96 capture_format_.frame_size.SetSize(1920, 1080);
97 else if (params.requested_format.frame_size.width() > 640) 97 else if (params.requested_format.frame_size.width() > 640)
98 capture_format_.frame_size.SetSize(1280, 720); 98 capture_format_.frame_size.SetSize(1280, 720);
99 else if (params.requested_format.frame_size.width() > 320) 99 else if (params.requested_format.frame_size.width() > 320)
100 capture_format_.frame_size.SetSize(640, 480); 100 capture_format_.frame_size.SetSize(640, 480);
101 else 101 else
102 capture_format_.frame_size.SetSize(320, 240); 102 capture_format_.frame_size.SetSize(320, 240);
103 103
104 if (device_type_ == USING_OWN_BUFFERS || 104 switch (device_type_) {
105 device_type_ == USING_OWN_BUFFERS_TRIPLANAR) { 105 case USING_OWN_BUFFERS:
106 fake_frame_.reset(new uint8[VideoFrame::AllocationSize( 106 fake_frame_.reset(new uint8[VideoFrame::AllocationSize(
107 VideoFrame::I420, capture_format_.frame_size)]); 107 VideoFrame::I420, capture_format_.frame_size)]);
108 BeepAndScheduleNextCapture( 108 BeepAndScheduleNextCapture(
109 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, 109 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers,
110 weak_factory_.GetWeakPtr())); 110 weak_factory_.GetWeakPtr()));
111 } else if (device_type_ == USING_CLIENT_BUFFERS_I420 || 111 break;
112 device_type_ == USING_CLIENT_BUFFERS_GPU) { 112 case USING_CLIENT_BUFFERS:
113 DVLOG(1) << "starting with " << (device_type_ == USING_CLIENT_BUFFERS_I420 113 BeepAndScheduleNextCapture(
114 ? "Client buffers" 114 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers,
115 : "GpuMemoryBuffers"); 115 weak_factory_.GetWeakPtr()));
116 BeepAndScheduleNextCapture(base::Bind( 116 break;
117 &FakeVideoCaptureDevice::CaptureUsingClientBuffers, 117 case USING_GPU_MEMORY_BUFFERS:
118 weak_factory_.GetWeakPtr(), (device_type_ == USING_CLIENT_BUFFERS_I420 118 BeepAndScheduleNextCapture(
119 ? PIXEL_FORMAT_I420 119 base::Bind(&FakeVideoCaptureDevice::CaptureUsingGpuMemoryBuffers,
120 : PIXEL_FORMAT_GPUMEMORYBUFFER))); 120 weak_factory_.GetWeakPtr()));
121 } else { 121 break;
122 client_->OnError("Unknown Fake Video Capture Device type."); 122 default:
123 client_->OnError("Unknown Fake Video Capture Device type.");
123 } 124 }
124 } 125 }
125 126
126 void FakeVideoCaptureDevice::StopAndDeAllocate() { 127 void FakeVideoCaptureDevice::StopAndDeAllocate() {
127 DCHECK(thread_checker_.CalledOnValidThread()); 128 DCHECK(thread_checker_.CalledOnValidThread());
128 client_.reset(); 129 client_.reset();
129 } 130 }
130 131
131 void FakeVideoCaptureDevice::CaptureUsingOwnBuffers() { 132 void FakeVideoCaptureDevice::CaptureUsingOwnBuffers() {
132 DCHECK(thread_checker_.CalledOnValidThread()); 133 DCHECK(thread_checker_.CalledOnValidThread());
133 const size_t frame_size = capture_format_.ImageAllocationSize(); 134 const size_t frame_size =
135 VideoFrame::AllocationSize(VideoFrame::I420, capture_format_.frame_size);
134 memset(fake_frame_.get(), 0, frame_size); 136 memset(fake_frame_.get(), 0, frame_size);
135 137
136 DrawPacman(false /* use_argb */, 138 DrawPacman(false /* use_argb */,
137 fake_frame_.get(), 139 fake_frame_.get(),
138 frame_count_, 140 frame_count_,
139 kFakeCapturePeriodMs, 141 kFakeCapturePeriodMs,
140 capture_format_.frame_size); 142 capture_format_.frame_size);
141 143
142 // Give the captured frame to the client. 144 // Give the captured frame to the client.
143 if (device_type_ == USING_OWN_BUFFERS) { 145 client_->OnIncomingCapturedData(fake_frame_.get(),
144 client_->OnIncomingCapturedData(fake_frame_.get(), 146 frame_size,
145 frame_size, 147 capture_format_,
146 capture_format_, 148 0,
147 0 /* rotation */, 149 base::TimeTicks::Now());
148 base::TimeTicks::Now());
149 } else if (device_type_ == USING_OWN_BUFFERS_TRIPLANAR) {
150 client_->OnIncomingCapturedYuvData(
151 fake_frame_.get(),
152 fake_frame_.get() + capture_format_.frame_size.GetArea(),
153 fake_frame_.get() + capture_format_.frame_size.GetArea() * 5 / 4,
154 capture_format_.frame_size.width(),
155 capture_format_.frame_size.width() / 2,
156 capture_format_.frame_size.width() / 2,
157 capture_format_,
158 0 /* rotation */,
159 base::TimeTicks::Now());
160 }
161 BeepAndScheduleNextCapture( 150 BeepAndScheduleNextCapture(
162 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, 151 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers,
163 weak_factory_.GetWeakPtr())); 152 weak_factory_.GetWeakPtr()));
164 } 153 }
165 154
166 void FakeVideoCaptureDevice::CaptureUsingClientBuffers( 155 void FakeVideoCaptureDevice::CaptureUsingClientBuffers() {
167 VideoPixelFormat pixel_format) {
168 DCHECK(thread_checker_.CalledOnValidThread()); 156 DCHECK(thread_checker_.CalledOnValidThread());
169 157
170 scoped_ptr<VideoCaptureDevice::Client::Buffer> capture_buffer( 158 const scoped_refptr<VideoCaptureDevice::Client::Buffer> capture_buffer =
171 client_->ReserveOutputBuffer(pixel_format, capture_format_.frame_size)); 159 client_->ReserveOutputBuffer(capture_format_.pixel_format,
160 capture_format_.frame_size);
172 DLOG_IF(ERROR, !capture_buffer) << "Couldn't allocate Capture Buffer"; 161 DLOG_IF(ERROR, !capture_buffer) << "Couldn't allocate Capture Buffer";
162 if (!capture_buffer)
163 return;
173 164
174 if (capture_buffer.get()) { 165 uint8_t* const data_ptr = static_cast<uint8_t*>(capture_buffer->data());
175 uint8_t* const data_ptr = static_cast<uint8_t*>(capture_buffer->data()); 166 memset(data_ptr, 0, capture_buffer->size());
176 DCHECK(data_ptr) << "Buffer has NO backing memory"; 167 DCHECK(data_ptr) << "Buffer has NO backing memory";
177 memset(data_ptr, 0, capture_buffer->size());
178 168
179 DrawPacman( 169 DrawPacman(false /* use_argb */,
180 (pixel_format == media::PIXEL_FORMAT_GPUMEMORYBUFFER), /* use_argb */ 170 data_ptr,
181 data_ptr, 171 frame_count_,
182 frame_count_, 172 kFakeCapturePeriodMs,
183 kFakeCapturePeriodMs, 173 capture_format_.frame_size);
184 capture_format_.frame_size);
185 174
186 // Give the captured frame to the client. 175 scoped_refptr<VideoFrame> video_frame =
187 const VideoCaptureFormat format(capture_format_.frame_size, 176 VideoFrame::WrapExternalPackedMemory(
188 capture_format_.frame_rate, 177 VideoFrame::I420,
189 pixel_format); 178 capture_format_.frame_size,
190 client_->OnIncomingCapturedBuffer(capture_buffer.Pass(), format, 179 gfx::Rect(capture_format_.frame_size),
191 base::TimeTicks::Now()); 180 capture_format_.frame_size,
192 } 181 static_cast<uint8*>(capture_buffer->data()),
182 capture_buffer->size(),
183 base::SharedMemory::NULLHandle(),
184 0,
185 base::TimeDelta(),
186 base::Closure());
193 187
188 // Give the captured frame to the client.
189 client_->OnIncomingCapturedVideoFrame(capture_buffer,
190 video_frame,
191 base::TimeTicks::Now());
194 BeepAndScheduleNextCapture( 192 BeepAndScheduleNextCapture(
195 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers, 193 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers,
196 weak_factory_.GetWeakPtr(), pixel_format)); 194 weak_factory_.GetWeakPtr()));
195 }
196
197 void FakeVideoCaptureDevice::CaptureUsingGpuMemoryBuffers() {
198 DCHECK(thread_checker_.CalledOnValidThread());
199
200 NOTIMPLEMENTED();
197 } 201 }
198 202
199 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture( 203 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture(
200 const base::Closure& next_capture) { 204 const base::Closure& next_capture) {
201 // Generate a synchronized beep sound every so many frames. 205 // Generate a synchronized beep sound every so many frames.
202 if (frame_count_++ % kFakeCaptureBeepCycle == 0) 206 if (frame_count_++ % kFakeCaptureBeepCycle == 0)
203 FakeAudioInputStream::BeepOnce(); 207 FakeAudioInputStream::BeepOnce();
204 208
205 // Reschedule next CaptureTask. 209 // Reschedule next CaptureTask.
206 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, next_capture, 210 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, next_capture,
207 base::TimeDelta::FromMilliseconds(kFakeCapturePeriodMs)); 211 base::TimeDelta::FromMilliseconds(kFakeCapturePeriodMs));
208 } 212 }
209 213
210 } // namespace media 214 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/fake_video_capture_device.h ('k') | media/video/capture/fake_video_capture_device_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698