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

Side by Side Diff: content/browser/renderer_host/media/video_capture_controller.cc

Issue 617093003: Add MediaStreamSource frame rate calculation to the tracker. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding type name. Fixing IPC type problem. Created 6 years, 2 months 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
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/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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 private: 173 private:
174 scoped_refptr<Buffer> DoReserveOutputBuffer(media::VideoFrame::Format format, 174 scoped_refptr<Buffer> DoReserveOutputBuffer(media::VideoFrame::Format format,
175 const gfx::Size& dimensions); 175 const gfx::Size& dimensions);
176 176
177 // The controller to which we post events. 177 // The controller to which we post events.
178 const base::WeakPtr<VideoCaptureController> controller_; 178 const base::WeakPtr<VideoCaptureController> controller_;
179 179
180 // The pool of shared-memory buffers used for capturing. 180 // The pool of shared-memory buffers used for capturing.
181 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_; 181 const scoped_refptr<VideoCaptureBufferPool> buffer_pool_;
182
183 // Number of frames dropped due to that no shared buffers are available.
184 int frames_dropped_;
182 }; 185 };
183 186
184 VideoCaptureController::VideoCaptureController(int max_buffers) 187 VideoCaptureController::VideoCaptureController(int max_buffers)
185 : buffer_pool_(new VideoCaptureBufferPool(max_buffers)), 188 : buffer_pool_(new VideoCaptureBufferPool(max_buffers)),
186 state_(VIDEO_CAPTURE_STATE_STARTED), 189 state_(VIDEO_CAPTURE_STATE_STARTED),
187 frame_received_(false), 190 frame_received_(false),
188 weak_ptr_factory_(this) { 191 weak_ptr_factory_(this) {
189 } 192 }
190 193
191 VideoCaptureController::VideoCaptureDeviceClient::VideoCaptureDeviceClient( 194 VideoCaptureController::VideoCaptureDeviceClient::VideoCaptureDeviceClient(
192 const base::WeakPtr<VideoCaptureController>& controller, 195 const base::WeakPtr<VideoCaptureController>& controller,
193 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool) 196 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool)
194 : controller_(controller), buffer_pool_(buffer_pool) {} 197 : controller_(controller), buffer_pool_(buffer_pool), frames_dropped_(0) {}
195 198
196 VideoCaptureController::VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {} 199 VideoCaptureController::VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {}
197 200
198 base::WeakPtr<VideoCaptureController> VideoCaptureController::GetWeakPtr() { 201 base::WeakPtr<VideoCaptureController> VideoCaptureController::GetWeakPtr() {
199 return weak_ptr_factory_.GetWeakPtr(); 202 return weak_ptr_factory_.GetWeakPtr();
200 } 203 }
201 204
202 scoped_ptr<media::VideoCaptureDevice::Client> 205 scoped_ptr<media::VideoCaptureDevice::Client>
203 VideoCaptureController::NewDeviceClient() { 206 VideoCaptureController::NewDeviceClient() {
204 scoped_ptr<media::VideoCaptureDevice::Client> result( 207 scoped_ptr<media::VideoCaptureDevice::Client> result(
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (!media::VideoFrame::IsValidConfig(media::VideoFrame::I420, 361 if (!media::VideoFrame::IsValidConfig(media::VideoFrame::I420,
359 dimensions, 362 dimensions,
360 gfx::Rect(dimensions), 363 gfx::Rect(dimensions),
361 dimensions)) { 364 dimensions)) {
362 return; 365 return;
363 } 366 }
364 367
365 scoped_refptr<Buffer> buffer = 368 scoped_refptr<Buffer> buffer =
366 DoReserveOutputBuffer(media::VideoFrame::I420, dimensions); 369 DoReserveOutputBuffer(media::VideoFrame::I420, dimensions);
367 370
368 if (!buffer.get()) 371 if (!buffer.get()) {
372 ++frames_dropped_;
369 return; 373 return;
374 }
375
370 uint8* yplane = NULL; 376 uint8* yplane = NULL;
371 bool flip = false; 377 bool flip = false;
372 yplane = reinterpret_cast<uint8*>(buffer->data()); 378 yplane = reinterpret_cast<uint8*>(buffer->data());
373 uint8* uplane = 379 uint8* uplane =
374 yplane + 380 yplane +
375 media::VideoFrame::PlaneAllocationSize( 381 media::VideoFrame::PlaneAllocationSize(
376 media::VideoFrame::I420, media::VideoFrame::kYPlane, dimensions); 382 media::VideoFrame::I420, media::VideoFrame::kYPlane, dimensions);
377 uint8* vplane = 383 uint8* vplane =
378 uplane + 384 uplane +
379 media::VideoFrame::PlaneAllocationSize( 385 media::VideoFrame::PlaneAllocationSize(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 yplane, 467 yplane,
462 media::VideoFrame::AllocationSize(media::VideoFrame::I420, 468 media::VideoFrame::AllocationSize(media::VideoFrame::I420,
463 dimensions), 469 dimensions),
464 base::SharedMemory::NULLHandle(), 470 base::SharedMemory::NULLHandle(),
465 base::TimeDelta(), 471 base::TimeDelta(),
466 base::Closure()); 472 base::Closure());
467 DCHECK(frame.get()); 473 DCHECK(frame.get());
468 474
469 VideoCaptureFormat format( 475 VideoCaptureFormat format(
470 dimensions, frame_format.frame_rate, media::PIXEL_FORMAT_I420); 476 dimensions, frame_format.frame_rate, media::PIXEL_FORMAT_I420);
477 format.number_of_dropped_frames = frames_dropped_;
471 BrowserThread::PostTask( 478 BrowserThread::PostTask(
472 BrowserThread::IO, 479 BrowserThread::IO,
473 FROM_HERE, 480 FROM_HERE,
474 base::Bind( 481 base::Bind(
475 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, 482 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread,
476 controller_, 483 controller_,
477 buffer, 484 buffer,
478 format, 485 format,
479 frame, 486 frame,
480 timestamp)); 487 timestamp));
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 } 690 }
684 return NULL; 691 return NULL;
685 } 692 }
686 693
687 int VideoCaptureController::GetClientCount() { 694 int VideoCaptureController::GetClientCount() {
688 DCHECK_CURRENTLY_ON(BrowserThread::IO); 695 DCHECK_CURRENTLY_ON(BrowserThread::IO);
689 return controller_clients_.size(); 696 return controller_clients_.size();
690 } 697 }
691 698
692 } // namespace content 699 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698