| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_device_client.h" | 5 #include "content/browser/renderer_host/media/video_capture_device_client.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 media::VideoPixelStorage pixel_storage) { | 263 media::VideoPixelStorage pixel_storage) { |
| 264 DCHECK_GT(frame_size.width(), 0); | 264 DCHECK_GT(frame_size.width(), 0); |
| 265 DCHECK_GT(frame_size.height(), 0); | 265 DCHECK_GT(frame_size.height(), 0); |
| 266 // Currently, only I420 pixel format is supported. | 266 // Currently, only I420 pixel format is supported. |
| 267 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); | 267 DCHECK_EQ(media::PIXEL_FORMAT_I420, pixel_format); |
| 268 | 268 |
| 269 // TODO(mcasas): For PIXEL_STORAGE_GPUMEMORYBUFFER, find a way to indicate if | 269 // TODO(mcasas): For PIXEL_STORAGE_GPUMEMORYBUFFER, find a way to indicate if |
| 270 // it's a ShMem GMB or a DmaBuf GMB. | 270 // it's a ShMem GMB or a DmaBuf GMB. |
| 271 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; | 271 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; |
| 272 const int buffer_id = buffer_pool_->ReserveForProducer( | 272 const int buffer_id = buffer_pool_->ReserveForProducer( |
| 273 pixel_format, pixel_storage, frame_size, &buffer_id_to_drop); | 273 frame_size, pixel_format, pixel_storage, &buffer_id_to_drop); |
| 274 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | |
| 275 return NULL; | |
| 276 | |
| 277 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> output_buffer( | |
| 278 new AutoReleaseBuffer(buffer_pool_, buffer_id)); | |
| 279 | |
| 280 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) { | 274 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) { |
| 281 BrowserThread::PostTask(BrowserThread::IO, | 275 BrowserThread::PostTask(BrowserThread::IO, |
| 282 FROM_HERE, | 276 FROM_HERE, |
| 283 base::Bind(&VideoCaptureController::DoBufferDestroyedOnIOThread, | 277 base::Bind(&VideoCaptureController::DoBufferDestroyedOnIOThread, |
| 284 controller_, buffer_id_to_drop)); | 278 controller_, buffer_id_to_drop)); |
| 285 } | 279 } |
| 286 | 280 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| 287 return output_buffer; | 281 return nullptr; |
| 282 return make_scoped_ptr<Buffer>( |
| 283 new AutoReleaseBuffer(buffer_pool_, buffer_id)); |
| 288 } | 284 } |
| 289 | 285 |
| 290 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( | 286 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( |
| 291 scoped_ptr<Buffer> buffer, | 287 scoped_ptr<Buffer> buffer, |
| 292 const VideoCaptureFormat& frame_format, | 288 const VideoCaptureFormat& frame_format, |
| 293 const base::TimeTicks& timestamp) { | 289 const base::TimeTicks& timestamp) { |
| 294 // Currently, only I420 pixel format is supported. | 290 // Currently, only I420 pixel format is supported. |
| 295 DCHECK_EQ(media::PIXEL_FORMAT_I420, frame_format.pixel_format); | 291 DCHECK_EQ(media::PIXEL_FORMAT_I420, frame_format.pixel_format); |
| 296 | 292 |
| 297 scoped_refptr<VideoFrame> frame; | 293 scoped_refptr<VideoFrame> frame; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 BrowserThread::IO, | 329 BrowserThread::IO, |
| 334 FROM_HERE, | 330 FROM_HERE, |
| 335 base::Bind( | 331 base::Bind( |
| 336 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, | 332 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, |
| 337 controller_, | 333 controller_, |
| 338 base::Passed(&buffer), | 334 base::Passed(&buffer), |
| 339 frame, | 335 frame, |
| 340 timestamp)); | 336 timestamp)); |
| 341 } | 337 } |
| 342 | 338 |
| 339 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> |
| 340 VideoCaptureDeviceClient::ResurrectLastOutputBuffer( |
| 341 const gfx::Size& dimensions, |
| 342 media::VideoPixelFormat format, |
| 343 media::VideoPixelStorage storage) { |
| 344 const int buffer_id = |
| 345 buffer_pool_->ResurrectLastForProducer(dimensions, format, storage); |
| 346 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
| 347 return nullptr; |
| 348 return make_scoped_ptr<Buffer>( |
| 349 new AutoReleaseBuffer(buffer_pool_, buffer_id)); |
| 350 } |
| 351 |
| 343 void VideoCaptureDeviceClient::OnError( | 352 void VideoCaptureDeviceClient::OnError( |
| 344 const tracked_objects::Location& from_here, | 353 const tracked_objects::Location& from_here, |
| 345 const std::string& reason) { | 354 const std::string& reason) { |
| 346 const std::string log_message = base::StringPrintf( | 355 const std::string log_message = base::StringPrintf( |
| 347 "error@ %s, %s, OS message: %s", from_here.ToString().c_str(), | 356 "error@ %s, %s, OS message: %s", from_here.ToString().c_str(), |
| 348 reason.c_str(), | 357 reason.c_str(), |
| 349 logging::SystemErrorCodeToString(logging::GetLastSystemErrorCode()) | 358 logging::SystemErrorCodeToString(logging::GetLastSystemErrorCode()) |
| 350 .c_str()); | 359 .c_str()); |
| 351 DLOG(ERROR) << log_message; | 360 DLOG(ERROR) << log_message; |
| 352 OnLog(log_message); | 361 OnLog(log_message); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane)); | 415 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane)); |
| 407 *v_plane_data = | 416 *v_plane_data = |
| 408 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane)); | 417 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane)); |
| 409 return buffer; | 418 return buffer; |
| 410 } | 419 } |
| 411 NOTREACHED(); | 420 NOTREACHED(); |
| 412 return scoped_ptr<Buffer>(); | 421 return scoped_ptr<Buffer>(); |
| 413 } | 422 } |
| 414 | 423 |
| 415 } // namespace content | 424 } // namespace content |
| OLD | NEW |