| 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 <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 copy_of_metadata.reset(metadata->DeepCopy()); | 321 copy_of_metadata.reset(metadata->DeepCopy()); |
| 322 | 322 |
| 323 if (frame->HasTextures()) { | 323 if (frame->HasTextures()) { |
| 324 DCHECK(frame->coded_size() == frame->visible_rect().size()) | 324 DCHECK(frame->coded_size() == frame->visible_rect().size()) |
| 325 << "Textures are always supposed to be tightly packed."; | 325 << "Textures are always supposed to be tightly packed."; |
| 326 DCHECK_EQ(1u, VideoFrame::NumPlanes(frame->format())); | 326 DCHECK_EQ(1u, VideoFrame::NumPlanes(frame->format())); |
| 327 client->event_handler->OnMailboxBufferReady( | 327 client->event_handler->OnMailboxBufferReady( |
| 328 client->controller_id, buffer_id, frame->mailbox_holder(0), | 328 client->controller_id, buffer_id, frame->mailbox_holder(0), |
| 329 frame->coded_size(), timestamp, copy_of_metadata.Pass()); | 329 frame->coded_size(), timestamp, copy_of_metadata.Pass()); |
| 330 } else if (frame->format() == media::VideoFrame::I420) { | 330 } else if (frame->format() == media::VideoFrame::I420) { |
| 331 bool is_new_buffer = client->known_buffers.insert(buffer_id).second; | 331 DCHECK(frame->IsMappable()); |
| 332 const bool is_new_buffer = |
| 333 client->known_buffers.insert(buffer_id).second; |
| 332 if (is_new_buffer) { | 334 if (is_new_buffer) { |
| 333 // On the first use of a buffer on a client, share the memory handle. | 335 // On the first use of a buffer on a client, share the memory handle. |
| 334 size_t memory_size = 0; | 336 size_t memory_size = 0; |
| 335 base::SharedMemoryHandle remote_handle = buffer_pool_->ShareToProcess( | 337 base::SharedMemoryHandle remote_handle = buffer_pool_->ShareToProcess( |
| 336 buffer_id, client->render_process_handle, &memory_size); | 338 buffer_id, client->render_process_handle, &memory_size); |
| 337 client->event_handler->OnBufferCreated( | 339 client->event_handler->OnBufferCreated( |
| 338 client->controller_id, remote_handle, memory_size, buffer_id); | 340 client->controller_id, remote_handle, memory_size, buffer_id); |
| 339 } | 341 } |
| 340 | 342 |
| 341 client->event_handler->OnBufferReady( | 343 client->event_handler->OnBufferReady( |
| 342 client->controller_id, buffer_id, frame->coded_size(), | 344 client->controller_id, buffer_id, frame->coded_size(), |
| 343 frame->visible_rect(), timestamp, copy_of_metadata.Pass()); | 345 frame->visible_rect(), timestamp, copy_of_metadata.Pass()); |
| 344 } else { | 346 } else { |
| 345 // VideoFrame format not supported. | 347 // VideoFrame format not supported. |
| 346 NOTREACHED() << media::VideoFrame::FormatToString(frame->format()); | 348 NOTREACHED() << media::VideoFrame::FormatToString(frame->format()); |
| 347 break; | 349 break; |
| 348 } | 350 } |
| 349 | 351 |
| 350 bool inserted = | 352 const bool inserted = |
| 351 client->active_buffers.insert(std::make_pair(buffer_id, frame)) | 353 client->active_buffers.insert(std::make_pair(buffer_id, frame)) |
| 352 .second; | 354 .second; |
| 353 DCHECK(inserted) << "Unexpected duplicate buffer: " << buffer_id; | 355 DCHECK(inserted) << "Unexpected duplicate buffer: " << buffer_id; |
| 354 count++; | 356 count++; |
| 355 } | 357 } |
| 356 } | 358 } |
| 357 | 359 |
| 358 if (!has_received_frames_) { | 360 if (!has_received_frames_) { |
| 359 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Width", | 361 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Width", |
| 360 frame->visible_rect().width()); | 362 frame->visible_rect().width()); |
| 361 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Height", | 363 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Height", |
| 362 frame->visible_rect().height()); | 364 frame->visible_rect().height()); |
| 363 UMA_HISTOGRAM_ASPECT_RATIO("Media.VideoCapture.AspectRatio", | 365 UMA_HISTOGRAM_ASPECT_RATIO("Media.VideoCapture.AspectRatio", |
| 364 frame->visible_rect().width(), | 366 frame->visible_rect().width(), |
| 365 frame->visible_rect().height()); | 367 frame->visible_rect().height()); |
| 366 double frame_rate; | 368 double frame_rate = 0.0f; |
| 367 if (!frame->metadata()->GetDouble(media::VideoFrameMetadata::FRAME_RATE, | 369 if (!frame->metadata()->GetDouble(media::VideoFrameMetadata::FRAME_RATE, |
| 368 &frame_rate)) | 370 &frame_rate)) { |
| 369 frame_rate = video_capture_format_.frame_rate; | 371 frame_rate = video_capture_format_.frame_rate; |
| 372 } |
| 370 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.FrameRate", frame_rate); | 373 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.FrameRate", frame_rate); |
| 371 has_received_frames_ = true; | 374 has_received_frames_ = true; |
| 372 } | 375 } |
| 373 | 376 |
| 374 buffer_pool_->HoldForConsumers(buffer_id, count); | 377 buffer_pool_->HoldForConsumers(buffer_id, count); |
| 375 } | 378 } |
| 376 | 379 |
| 377 void VideoCaptureController::DoErrorOnIOThread() { | 380 void VideoCaptureController::DoErrorOnIOThread() { |
| 378 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 381 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 379 state_ = VIDEO_CAPTURE_STATE_ERROR; | 382 state_ = VIDEO_CAPTURE_STATE_ERROR; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 438 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 436 int active_client_count = 0; | 439 int active_client_count = 0; |
| 437 for (ControllerClient* client : controller_clients_) { | 440 for (ControllerClient* client : controller_clients_) { |
| 438 if (!client->paused) | 441 if (!client->paused) |
| 439 ++active_client_count; | 442 ++active_client_count; |
| 440 } | 443 } |
| 441 return active_client_count; | 444 return active_client_count; |
| 442 } | 445 } |
| 443 | 446 |
| 444 } // namespace content | 447 } // namespace content |
| OLD | NEW |