| 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::VideoFrame::kColorUnknown: // Color format not set. |
| 292 break; | 292 break; |
| 293 case media::VideoCaptureDevice::kI420: { | 293 case media::VideoFrame::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::kYUY2: { | 297 case media::VideoFrame::kYUY2: { |
| 298 media::ConvertYUY2ToYUV(data, yplane, uplane, vplane, frame_info_.width, | 298 media::ConvertYUY2ToYUV(data, yplane, uplane, vplane, frame_info_.width, |
| 299 frame_info_.height); | 299 frame_info_.height); |
| 300 break; | 300 break; |
| 301 } | 301 } |
| 302 case media::VideoCaptureDevice::kRGB24: { | 302 case media::VideoFrame::kRGB24: { |
| 303 int ystride = frame_info_.width; | 303 int ystride = frame_info_.width; |
| 304 int uvstride = frame_info_.width / 2; | 304 int uvstride = frame_info_.width / 2; |
| 305 #if defined(OS_WIN) // RGB on Windows start at the bottom line. | 305 #if defined(OS_WIN) // RGB on Windows start at the bottom line. |
| 306 int rgb_stride = -3 * frame_info_.width; | 306 int rgb_stride = -3 * frame_info_.width; |
| 307 const uint8* rgb_src = data + 3 * frame_info_.width * | 307 const uint8* rgb_src = data + 3 * frame_info_.width * |
| 308 (frame_info_.height -1); | 308 (frame_info_.height -1); |
| 309 #else | 309 #else |
| 310 int rgb_stride = 3 * frame_info_.width; | 310 int rgb_stride = 3 * frame_info_.width; |
| 311 const uint8* rgb_src = data; | 311 const uint8* rgb_src = data; |
| 312 #endif | 312 #endif |
| 313 media::ConvertRGB24ToYUV(rgb_src, yplane, uplane, vplane, | 313 media::ConvertRGB24ToYUV(rgb_src, yplane, uplane, vplane, |
| 314 frame_info_.width, frame_info_.height, | 314 frame_info_.width, frame_info_.height, |
| 315 rgb_stride, ystride, uvstride); | 315 rgb_stride, ystride, uvstride); |
| 316 break; | 316 break; |
| 317 } | 317 } |
| 318 case media::VideoCaptureDevice::kARGB: { | 318 case media::VideoFrame::kARGB: { |
| 319 media::ConvertRGB32ToYUV(data, yplane, uplane, vplane, frame_info_.width, | 319 media::ConvertRGB32ToYUV(data, yplane, uplane, vplane, frame_info_.width, |
| 320 frame_info_.height, frame_info_.width * 4, | 320 frame_info_.height, frame_info_.width * 4, |
| 321 frame_info_.width, frame_info_.width / 2); | 321 frame_info_.width, frame_info_.width / 2); |
| 322 break; | 322 break; |
| 323 } | 323 } |
| 324 default: | 324 default: |
| 325 NOTREACHED(); | 325 NOTREACHED(); |
| 326 } | 326 } |
| 327 | 327 |
| 328 BrowserThread::PostTask(BrowserThread::IO, | 328 BrowserThread::PostTask(BrowserThread::IO, |
| 329 FROM_HERE, | 329 FROM_HERE, |
| 330 base::Bind(&VideoCaptureController::DoIncomingCapturedFrameOnIOThread, | 330 base::Bind(&VideoCaptureController::DoIncomingCapturedFrameOnIOThread, |
| 331 this, buffer_id, timestamp)); | 331 this, buffer_id, timestamp)); |
| 332 } | 332 } |
| 333 | 333 |
| 334 void VideoCaptureController::OnError() { | 334 void VideoCaptureController::OnError() { |
| 335 video_capture_manager_->Error(current_params_.session_id); | 335 video_capture_manager_->Error(current_params_.session_id); |
| 336 BrowserThread::PostTask(BrowserThread::IO, | 336 BrowserThread::PostTask(BrowserThread::IO, |
| 337 FROM_HERE, | 337 FROM_HERE, |
| 338 base::Bind(&VideoCaptureController::DoErrorOnIOThread, this)); | 338 base::Bind(&VideoCaptureController::DoErrorOnIOThread, this)); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void VideoCaptureController::OnFrameInfo( | 341 void VideoCaptureController::OnFrameInfo( |
| 342 const media::VideoCaptureDevice::Capability& info) { | 342 const media::VideoCaptureCapability& info) { |
| 343 frame_info_= info; | 343 frame_info_= info; |
| 344 BrowserThread::PostTask(BrowserThread::IO, | 344 BrowserThread::PostTask(BrowserThread::IO, |
| 345 FROM_HERE, | 345 FROM_HERE, |
| 346 base::Bind(&VideoCaptureController::DoFrameInfoOnIOThread, | 346 base::Bind(&VideoCaptureController::DoFrameInfoOnIOThread, |
| 347 this, info)); | 347 this, info)); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void VideoCaptureController::DoIncomingCapturedFrameOnIOThread( | 350 void VideoCaptureController::DoIncomingCapturedFrameOnIOThread( |
| 351 int buffer_id, base::Time timestamp) { | 351 int buffer_id, base::Time timestamp) { |
| 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 378 client_it != controller_clients_.end(); client_it++) { | 378 client_it != controller_clients_.end(); client_it++) { |
| 379 (*client_it)->event_handler->OnError((*client_it)->controller_id); | 379 (*client_it)->event_handler->OnError((*client_it)->controller_id); |
| 380 } | 380 } |
| 381 for (client_it = pending_clients_.begin(); | 381 for (client_it = pending_clients_.begin(); |
| 382 client_it != pending_clients_.end(); client_it++) { | 382 client_it != pending_clients_.end(); client_it++) { |
| 383 (*client_it)->event_handler->OnError((*client_it)->controller_id); | 383 (*client_it)->event_handler->OnError((*client_it)->controller_id); |
| 384 } | 384 } |
| 385 } | 385 } |
| 386 | 386 |
| 387 void VideoCaptureController::DoFrameInfoOnIOThread( | 387 void VideoCaptureController::DoFrameInfoOnIOThread( |
| 388 const media::VideoCaptureDevice::Capability info) { | 388 const media::VideoCaptureCapability info) { |
| 389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 390 DCHECK(owned_dibs_.empty()) | 390 DCHECK(owned_dibs_.empty()) |
| 391 << "Device is restarted without releasing shared memory."; | 391 << "Device is restarted without releasing shared memory."; |
| 392 | 392 |
| 393 bool frames_created = true; | 393 bool frames_created = true; |
| 394 const size_t needed_size = (info.width * info.height * 3) / 2; | 394 const size_t needed_size = (info.width * info.height * 3) / 2; |
| 395 { | 395 { |
| 396 base::AutoLock lock(lock_); | 396 base::AutoLock lock(lock_); |
| 397 for (size_t i = 1; i <= kNoOfDIBS; ++i) { | 397 for (size_t i = 1; i <= kNoOfDIBS; ++i) { |
| 398 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 398 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 } | 524 } |
| 525 | 525 |
| 526 void VideoCaptureController::DoDeviceStoppedOnIOThread() { | 526 void VideoCaptureController::DoDeviceStoppedOnIOThread() { |
| 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 528 device_in_use_ = false; | 528 device_in_use_ = false; |
| 529 if (state_ == video_capture::kStopping) { | 529 if (state_ == video_capture::kStopping) { |
| 530 PostStopping(); | 530 PostStopping(); |
| 531 } | 531 } |
| 532 } | 532 } |
| 533 | 533 |
| OLD | NEW |