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

Side by Side Diff: content/renderer/media/video_capture_impl.cc

Issue 68503005: Reorganize media::VideoCapture* types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a7375761 Rebase. Created 7 years, 1 month 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 | Annotate | Revision Log
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 "content/renderer/media/video_capture_impl.h" 5 #include "content/renderer/media/video_capture_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/child/child_process.h" 9 #include "content/child/child_process.h"
10 #include "content/common/media/video_capture_messages.h" 10 #include "content/common/media/video_capture_messages.h"
11 #include "media/base/bind_to_loop.h" 11 #include "media/base/bind_to_loop.h"
12 #include "media/base/limits.h" 12 #include "media/base/limits.h"
13 #include "media/base/video_frame.h"
13 14
14 namespace content { 15 namespace content {
15 16
16 class VideoCaptureImpl::ClientBuffer 17 class VideoCaptureImpl::ClientBuffer
17 : public base::RefCountedThreadSafe<ClientBuffer> { 18 : public base::RefCountedThreadSafe<ClientBuffer> {
18 public: 19 public:
19 ClientBuffer(scoped_ptr<base::SharedMemory> buffer, 20 ClientBuffer(scoped_ptr<base::SharedMemory> buffer,
20 size_t buffer_size) 21 size_t buffer_size)
21 : buffer(buffer.Pass()), 22 : buffer(buffer.Pass()),
22 buffer_size(buffer_size) {} 23 buffer_size(buffer_size) {}
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 clients_.find(handler) != clients_.end() ) { 153 clients_.find(handler) != clients_.end() ) {
153 // This client has started. 154 // This client has started.
154 } else if (!device_id_) { 155 } else if (!device_id_) {
155 clients_pending_on_filter_[handler] = params; 156 clients_pending_on_filter_[handler] = params;
156 } else { 157 } else {
157 handler->OnStarted(this); 158 handler->OnStarted(this);
158 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { 159 if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
159 clients_[handler] = params; 160 clients_[handler] = params;
160 } else if (state_ == VIDEO_CAPTURE_STATE_STOPPING) { 161 } else if (state_ == VIDEO_CAPTURE_STATE_STOPPING) {
161 clients_pending_on_restart_[handler] = params; 162 clients_pending_on_restart_[handler] = params;
162 DVLOG(1) << "StartCapture: Got new resolution (" 163 DVLOG(1) << "StartCapture: Got new resolution "
163 << params.requested_format.width << ", " 164 << params.requested_format.frame_size.ToString()
164 << params.requested_format.height << ") " 165 << " during stopping.";
165 << ", during stopping.";
166 } else { 166 } else {
167 DCHECK_EQ(params.session_id, 0); 167 DCHECK_EQ(params.session_id, 0);
168 // TODO(sheu): Allowing resolution change will require that all
169 // outstanding clients of a capture session support resolution change.
170 DCHECK(!params.allow_resolution_change);
168 clients_[handler] = params; 171 clients_[handler] = params;
169 DCHECK_EQ(1ul, clients_.size()); 172 DCHECK_EQ(1ul, clients_.size());
170 params_ = params; 173 params_ = params;
171 params_.session_id = session_id_; 174 params_.session_id = session_id_;
172 if (params_.requested_format.frame_rate > 175 if (params_.requested_format.frame_rate >
173 media::limits::kMaxFramesPerSecond) { 176 media::limits::kMaxFramesPerSecond) {
174 params_.requested_format.frame_rate = 177 params_.requested_format.frame_rate =
175 media::limits::kMaxFramesPerSecond; 178 media::limits::kMaxFramesPerSecond;
176 } 179 }
177 DVLOG(1) << "StartCapture: starting with first resolution (" 180 DVLOG(1) << "StartCapture: starting with first resolution "
178 << params_.requested_format.width << "," 181 << params_.requested_format.frame_size.ToString();
179 << params_.requested_format.height << ")";
180 182
181 StartCaptureInternal(); 183 StartCaptureInternal();
182 } 184 }
183 } 185 }
184 } 186 }
185 187
186 void VideoCaptureImpl::DoStopCaptureOnCaptureThread( 188 void VideoCaptureImpl::DoStopCaptureOnCaptureThread(
187 media::VideoCapture::EventHandler* handler) { 189 media::VideoCapture::EventHandler* handler) {
188 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 190 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
189 191
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 base::Time timestamp, 247 base::Time timestamp,
246 const media::VideoCaptureFormat& format) { 248 const media::VideoCaptureFormat& format) {
247 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 249 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
248 250
249 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { 251 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) {
250 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); 252 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id));
251 return; 253 return;
252 } 254 }
253 255
254 last_frame_format_ = format; 256 last_frame_format_ = format;
255 gfx::Size size(format.width, format.height);
256 257
257 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); 258 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id);
258 DCHECK(iter != client_buffers_.end()); 259 DCHECK(iter != client_buffers_.end());
259 scoped_refptr<ClientBuffer> buffer = iter->second; 260 scoped_refptr<ClientBuffer> buffer = iter->second;
260 scoped_refptr<media::VideoFrame> frame = 261 scoped_refptr<media::VideoFrame> frame =
261 media::VideoFrame::WrapExternalPackedMemory( 262 media::VideoFrame::WrapExternalPackedMemory(
262 media::VideoFrame::I420, 263 media::VideoFrame::I420,
263 size, 264 last_frame_format_.frame_size,
264 gfx::Rect(size), 265 gfx::Rect(last_frame_format_.frame_size),
265 size, 266 last_frame_format_.frame_size,
266 reinterpret_cast<uint8*>(buffer->buffer->memory()), 267 reinterpret_cast<uint8*>(buffer->buffer->memory()),
267 buffer->buffer_size, 268 buffer->buffer_size,
268 buffer->buffer->handle(), 269 buffer->buffer->handle(),
269 // TODO(sheu): convert VideoCaptureMessageFilter::Delegate to use 270 // TODO(sheu): convert VideoCaptureMessageFilter::Delegate to use
270 // base::TimeTicks instead of base::Time. http://crbug.com/249215 271 // base::TimeTicks instead of base::Time. http://crbug.com/249215
271 timestamp - base::Time::UnixEpoch(), 272 timestamp - base::Time::UnixEpoch(),
272 media::BindToLoop( 273 media::BindToLoop(
273 capture_message_loop_proxy_, 274 capture_message_loop_proxy_,
274 base::Bind( 275 base::Bind(
275 &VideoCaptureImpl::DoClientBufferFinishedOnCaptureThread, 276 &VideoCaptureImpl::DoClientBufferFinishedOnCaptureThread,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 354
354 suspended_ = suspend; 355 suspended_ = suspend;
355 } 356 }
356 357
357 void VideoCaptureImpl::StopDevice() { 358 void VideoCaptureImpl::StopDevice() {
358 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 359 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
359 360
360 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { 361 if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
361 state_ = VIDEO_CAPTURE_STATE_STOPPING; 362 state_ = VIDEO_CAPTURE_STATE_STOPPING;
362 Send(new VideoCaptureHostMsg_Stop(device_id_)); 363 Send(new VideoCaptureHostMsg_Stop(device_id_));
363 params_.requested_format.width = params_.requested_format.height = 0; 364 params_.requested_format.frame_size.SetSize(0, 0);
364 } 365 }
365 } 366 }
366 367
367 void VideoCaptureImpl::RestartCapture() { 368 void VideoCaptureImpl::RestartCapture() {
368 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 369 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
369 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPED); 370 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPED);
370 371
371 int width = 0; 372 int width = 0;
372 int height = 0; 373 int height = 0;
373 for (ClientInfo::iterator it = clients_.begin(); 374 for (ClientInfo::iterator it = clients_.begin();
374 it != clients_.end(); ++it) { 375 it != clients_.end(); ++it) {
375 width = std::max(width, it->second.requested_format.width); 376 width = std::max(width, it->second.requested_format.frame_size.width());
376 height = std::max(height, it->second.requested_format.height); 377 height = std::max(height, it->second.requested_format.frame_size.height());
377 } 378 }
378 for (ClientInfo::iterator it = clients_pending_on_restart_.begin(); 379 for (ClientInfo::iterator it = clients_pending_on_restart_.begin();
379 it != clients_pending_on_restart_.end(); ) { 380 it != clients_pending_on_restart_.end(); ) {
380 width = std::max(width, it->second.requested_format.width); 381 width = std::max(width, it->second.requested_format.frame_size.width());
381 height = std::max(height, it->second.requested_format.height); 382 height = std::max(height, it->second.requested_format.frame_size.height());
382 clients_[it->first] = it->second; 383 clients_[it->first] = it->second;
383 clients_pending_on_restart_.erase(it++); 384 clients_pending_on_restart_.erase(it++);
384 } 385 }
385 params_.requested_format.width = width; 386 params_.requested_format.frame_size.SetSize(width, height);
386 params_.requested_format.height = height; 387 DVLOG(1) << "RestartCapture, "
387 DVLOG(1) << "RestartCapture, " << params_.requested_format.width << ", " 388 << params_.requested_format.frame_size.ToString();
388 << params_.requested_format.height;
389 StartCaptureInternal(); 389 StartCaptureInternal();
390 } 390 }
391 391
392 void VideoCaptureImpl::StartCaptureInternal() { 392 void VideoCaptureImpl::StartCaptureInternal() {
393 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 393 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
394 DCHECK(device_id_); 394 DCHECK(device_id_);
395 395
396 Send(new VideoCaptureHostMsg_Start(device_id_, params_)); 396 Send(new VideoCaptureHostMsg_Start(device_id_, params_));
397 state_ = VIDEO_CAPTURE_STATE_STARTED; 397 state_ = VIDEO_CAPTURE_STATE_STARTED;
398 } 398 }
(...skipping 25 matching lines...) Expand all
424 if (it != clients->end()) { 424 if (it != clients->end()) {
425 handler->OnStopped(this); 425 handler->OnStopped(this);
426 handler->OnRemoved(this); 426 handler->OnRemoved(this);
427 clients->erase(it); 427 clients->erase(it);
428 found = true; 428 found = true;
429 } 429 }
430 return found; 430 return found;
431 } 431 }
432 432
433 } // namespace content 433 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698