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 "content/browser/renderer_host/media/video_capture_controller.h" | 5 #include "content/browser/renderer_host/media/video_capture_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/browser/renderer_host/media/media_stream_manager.h" | 10 #include "content/browser/renderer_host/media/media_stream_manager.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 uint8* target = static_cast<uint8*>(dib->memory()); | 281 uint8* target = static_cast<uint8*>(dib->memory()); |
282 CHECK(dib->created_size() >= static_cast<size_t> (frame_info_.width * | 282 CHECK(dib->created_size() >= static_cast<size_t> (frame_info_.width * |
283 frame_info_.height * 3) / | 283 frame_info_.height * 3) / |
284 2); | 284 2); |
285 uint8* yplane = target; | 285 uint8* yplane = target; |
286 uint8* uplane = target + frame_info_.width * frame_info_.height; | 286 uint8* uplane = target + frame_info_.width * frame_info_.height; |
287 uint8* vplane = uplane + (frame_info_.width * frame_info_.height) / 4; | 287 uint8* vplane = uplane + (frame_info_.width * frame_info_.height) / 4; |
288 | 288 |
289 // Do color conversion from the camera format to I420. | 289 // Do color conversion from the camera format to I420. |
290 switch (frame_info_.color) { | 290 switch (frame_info_.color) { |
291 case media::VideoCaptureDevice::kColorUnknown: // Color format not set. | 291 case media::VideoCaptureCapability::kColorUnknown: // Color format not set. |
292 break; | 292 break; |
293 case media::VideoCaptureDevice::kI420: { | 293 case media::VideoCaptureCapability::kI420: { |
294 memcpy(target, data, (frame_info_.width * frame_info_.height * 3) / 2); | 294 memcpy(target, data, (frame_info_.width * frame_info_.height * 3) / 2); |
295 break; | 295 break; |
296 } | 296 } |
297 case media::VideoCaptureDevice::kYV12: { | 297 case media::VideoCaptureCapability::kYV12: { |
298 const uint8* ptr = data; | 298 const uint8* ptr = data; |
299 memcpy(yplane, ptr, (frame_info_.width * frame_info_.height)); | 299 memcpy(yplane, ptr, (frame_info_.width * frame_info_.height)); |
300 ptr += frame_info_.width * frame_info_.height; | 300 ptr += frame_info_.width * frame_info_.height; |
301 memcpy(vplane, ptr, (frame_info_.width * frame_info_.height) >> 2); | 301 memcpy(vplane, ptr, (frame_info_.width * frame_info_.height) >> 2); |
302 ptr += (frame_info_.width * frame_info_.height) >> 2; | 302 ptr += (frame_info_.width * frame_info_.height) >> 2; |
303 memcpy(uplane, ptr, (frame_info_.width * frame_info_.height) >> 2); | 303 memcpy(uplane, ptr, (frame_info_.width * frame_info_.height) >> 2); |
304 break; | 304 break; |
305 } | 305 } |
306 case media::VideoCaptureDevice::kNV21: { | 306 case media::VideoCaptureCapability::kNV21: { |
307 media::ConvertNV21ToYUV(data, yplane, uplane, vplane, frame_info_.width, | 307 media::ConvertNV21ToYUV(data, yplane, uplane, vplane, frame_info_.width, |
308 frame_info_.height); | 308 frame_info_.height); |
309 break; | 309 break; |
310 } | 310 } |
311 case media::VideoCaptureDevice::kYUY2: { | 311 case media::VideoCaptureCapability::kYUY2: { |
312 media::ConvertYUY2ToYUV(data, yplane, uplane, vplane, frame_info_.width, | 312 media::ConvertYUY2ToYUV(data, yplane, uplane, vplane, frame_info_.width, |
313 frame_info_.height); | 313 frame_info_.height); |
314 break; | 314 break; |
315 } | 315 } |
316 case media::VideoCaptureDevice::kRGB24: { | 316 case media::VideoCaptureCapability::kRGB24: { |
317 int ystride = frame_info_.width; | 317 int ystride = frame_info_.width; |
318 int uvstride = frame_info_.width / 2; | 318 int uvstride = frame_info_.width / 2; |
319 #if defined(OS_WIN) // RGB on Windows start at the bottom line. | 319 #if defined(OS_WIN) // RGB on Windows start at the bottom line. |
320 int rgb_stride = -3 * frame_info_.width; | 320 int rgb_stride = -3 * frame_info_.width; |
321 const uint8* rgb_src = data + 3 * frame_info_.width * | 321 const uint8* rgb_src = data + 3 * frame_info_.width * |
322 (frame_info_.height -1); | 322 (frame_info_.height -1); |
323 #else | 323 #else |
324 int rgb_stride = 3 * frame_info_.width; | 324 int rgb_stride = 3 * frame_info_.width; |
325 const uint8* rgb_src = data; | 325 const uint8* rgb_src = data; |
326 #endif | 326 #endif |
327 media::ConvertRGB24ToYUV(rgb_src, yplane, uplane, vplane, | 327 media::ConvertRGB24ToYUV(rgb_src, yplane, uplane, vplane, |
328 frame_info_.width, frame_info_.height, | 328 frame_info_.width, frame_info_.height, |
329 rgb_stride, ystride, uvstride); | 329 rgb_stride, ystride, uvstride); |
330 break; | 330 break; |
331 } | 331 } |
332 case media::VideoCaptureDevice::kARGB: { | 332 case media::VideoCaptureCapability::kARGB: { |
333 media::ConvertRGB32ToYUV(data, yplane, uplane, vplane, frame_info_.width, | 333 media::ConvertRGB32ToYUV(data, yplane, uplane, vplane, frame_info_.width, |
334 frame_info_.height, frame_info_.width * 4, | 334 frame_info_.height, frame_info_.width * 4, |
335 frame_info_.width, frame_info_.width / 2); | 335 frame_info_.width, frame_info_.width / 2); |
336 break; | 336 break; |
337 } | 337 } |
338 default: | 338 default: |
339 NOTREACHED(); | 339 NOTREACHED(); |
340 } | 340 } |
341 | 341 |
342 BrowserThread::PostTask(BrowserThread::IO, | 342 BrowserThread::PostTask(BrowserThread::IO, |
343 FROM_HERE, | 343 FROM_HERE, |
344 base::Bind(&VideoCaptureController::DoIncomingCapturedFrameOnIOThread, | 344 base::Bind(&VideoCaptureController::DoIncomingCapturedFrameOnIOThread, |
345 this, buffer_id, timestamp)); | 345 this, buffer_id, timestamp)); |
346 } | 346 } |
347 | 347 |
348 void VideoCaptureController::OnError() { | 348 void VideoCaptureController::OnError() { |
349 video_capture_manager_->Error(current_params_.session_id); | 349 video_capture_manager_->Error(current_params_.session_id); |
350 BrowserThread::PostTask(BrowserThread::IO, | 350 BrowserThread::PostTask(BrowserThread::IO, |
351 FROM_HERE, | 351 FROM_HERE, |
352 base::Bind(&VideoCaptureController::DoErrorOnIOThread, this)); | 352 base::Bind(&VideoCaptureController::DoErrorOnIOThread, this)); |
353 } | 353 } |
354 | 354 |
355 void VideoCaptureController::OnFrameInfo( | 355 void VideoCaptureController::OnFrameInfo( |
356 const media::VideoCaptureDevice::Capability& info) { | 356 const media::VideoCaptureCapability& info) { |
357 frame_info_= info; | 357 frame_info_= info; |
358 BrowserThread::PostTask(BrowserThread::IO, | 358 BrowserThread::PostTask(BrowserThread::IO, |
359 FROM_HERE, | 359 FROM_HERE, |
360 base::Bind(&VideoCaptureController::DoFrameInfoOnIOThread, | 360 base::Bind(&VideoCaptureController::DoFrameInfoOnIOThread, |
361 this, info)); | 361 this, info)); |
362 } | 362 } |
363 | 363 |
364 void VideoCaptureController::DoIncomingCapturedFrameOnIOThread( | 364 void VideoCaptureController::DoIncomingCapturedFrameOnIOThread( |
365 int buffer_id, base::Time timestamp) { | 365 int buffer_id, base::Time timestamp) { |
366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
(...skipping 25 matching lines...) Expand all Loading... |
392 client_it != controller_clients_.end(); client_it++) { | 392 client_it != controller_clients_.end(); client_it++) { |
393 (*client_it)->event_handler->OnError((*client_it)->controller_id); | 393 (*client_it)->event_handler->OnError((*client_it)->controller_id); |
394 } | 394 } |
395 for (client_it = pending_clients_.begin(); | 395 for (client_it = pending_clients_.begin(); |
396 client_it != pending_clients_.end(); client_it++) { | 396 client_it != pending_clients_.end(); client_it++) { |
397 (*client_it)->event_handler->OnError((*client_it)->controller_id); | 397 (*client_it)->event_handler->OnError((*client_it)->controller_id); |
398 } | 398 } |
399 } | 399 } |
400 | 400 |
401 void VideoCaptureController::DoFrameInfoOnIOThread( | 401 void VideoCaptureController::DoFrameInfoOnIOThread( |
402 const media::VideoCaptureDevice::Capability info) { | 402 const media::VideoCaptureCapability info) { |
403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
404 DCHECK(owned_dibs_.empty()) | 404 DCHECK(owned_dibs_.empty()) |
405 << "Device is restarted without releasing shared memory."; | 405 << "Device is restarted without releasing shared memory."; |
406 | 406 |
407 bool frames_created = true; | 407 bool frames_created = true; |
408 const size_t needed_size = (info.width * info.height * 3) / 2; | 408 const size_t needed_size = (info.width * info.height * 3) / 2; |
409 { | 409 { |
410 base::AutoLock lock(lock_); | 410 base::AutoLock lock(lock_); |
411 for (size_t i = 1; i <= kNoOfDIBS; ++i) { | 411 for (size_t i = 1; i <= kNoOfDIBS; ++i) { |
412 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 412 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 } | 538 } |
539 | 539 |
540 void VideoCaptureController::DoDeviceStoppedOnIOThread() { | 540 void VideoCaptureController::DoDeviceStoppedOnIOThread() { |
541 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 541 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
542 device_in_use_ = false; | 542 device_in_use_ = false; |
543 if (state_ == video_capture::kStopping) { | 543 if (state_ == video_capture::kStopping) { |
544 PostStopping(); | 544 PostStopping(); |
545 } | 545 } |
546 } | 546 } |
547 | 547 |
OLD | NEW |