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

Side by Side Diff: media/video/capture/linux/video_capture_device_linux.cc

Issue 1008343006: Increase VIDIOC_REQBUFS count from 2 to 4 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/video/capture/linux/video_capture_device_linux.h" 5 #include "media/video/capture/linux/video_capture_device_linux.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <poll.h> 9 #include <poll.h>
10 #if defined(OS_OPENBSD) 10 #if defined(OS_OPENBSD)
(...skipping 11 matching lines...) Expand all
22 #include "base/files/file_enumerator.h" 22 #include "base/files/file_enumerator.h"
23 #include "base/files/scoped_file.h" 23 #include "base/files/scoped_file.h"
24 #include "base/posix/eintr_wrapper.h" 24 #include "base/posix/eintr_wrapper.h"
25 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
26 26
27 namespace media { 27 namespace media {
28 28
29 #define GET_V4L2_FOURCC_CHAR(a, index) ((char)( ((a) >> (8 * index)) & 0xff)) 29 #define GET_V4L2_FOURCC_CHAR(a, index) ((char)( ((a) >> (8 * index)) & 0xff))
30 30
31 // Max number of video buffers VideoCaptureDeviceLinux can allocate. 31 // Max number of video buffers VideoCaptureDeviceLinux can allocate.
32 const uint32 kMaxVideoBuffers = 2; 32 const uint32 kMaxVideoBuffers = 4;
Pawel Osciak 2015/03/18 11:17:02 s/kMaxVideoBuffers/kNumVideoBuffers/
33 // Timeout in milliseconds v4l2_thread_ blocks waiting for a frame from the hw. 33 // Timeout in milliseconds v4l2_thread_ blocks waiting for a frame from the hw.
34 enum { kCaptureTimeoutMs = 200 }; 34 enum { kCaptureTimeoutMs = 200 };
35 // The number of continuous timeouts tolerated before treated as error. 35 // The number of continuous timeouts tolerated before treated as error.
36 enum { kContinuousTimeoutLimit = 10 }; 36 enum { kContinuousTimeoutLimit = 10 };
37 // MJPEG is preferred if the width or height is larger than this. 37 // MJPEG is preferred if the width or height is larger than this.
38 enum { kMjpegWidth = 640 }; 38 enum { kMjpegWidth = 640 };
39 enum { kMjpegHeight = 480 }; 39 enum { kMjpegHeight = 480 };
40 // Typical framerate, in fps 40 // Typical framerate, in fps
41 enum { kTypicalFramerate = 30 }; 41 enum { kTypicalFramerate = 30 };
42 42
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 bool VideoCaptureDeviceLinux::V4L2CaptureDelegate::AllocateVideoBuffers() { 462 bool VideoCaptureDeviceLinux::V4L2CaptureDelegate::AllocateVideoBuffers() {
463 v4l2_requestbuffers r_buffer = {}; 463 v4l2_requestbuffers r_buffer = {};
464 r_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 464 r_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
465 r_buffer.memory = V4L2_MEMORY_MMAP; 465 r_buffer.memory = V4L2_MEMORY_MMAP;
466 r_buffer.count = kMaxVideoBuffers; 466 r_buffer.count = kMaxVideoBuffers;
467 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_REQBUFS, &r_buffer)) < 0) { 467 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_REQBUFS, &r_buffer)) < 0) {
468 DLOG(ERROR) << "Error requesting MMAP buffers from V4L2"; 468 DLOG(ERROR) << "Error requesting MMAP buffers from V4L2";
469 return false; 469 return false;
470 } 470 }
471 DCHECK_EQ(r_buffer.count, kMaxVideoBuffers); 471 DCHECK_EQ(r_buffer.count, kMaxVideoBuffers);
472 r_buffer.count = std::min(r_buffer.count, kMaxVideoBuffers); 472 r_buffer.count = std::min(r_buffer.count, kMaxVideoBuffers);
Pawel Osciak 2015/03/18 11:17:02 This isn't right. The device is free to allocate m
Justin Chuang 2015/03/18 11:18:52 Would you like to do it in this CL or refactor in
473 buffer_pool_size_ = r_buffer.count; 473 buffer_pool_size_ = r_buffer.count;
474 buffer_pool_ = new Buffer[buffer_pool_size_]; 474 buffer_pool_ = new Buffer[buffer_pool_size_];
475 for (unsigned int i = 0; i < r_buffer.count; ++i) { 475 for (unsigned int i = 0; i < r_buffer.count; ++i) {
476 v4l2_buffer buffer = {}; 476 v4l2_buffer buffer = {};
477 buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 477 buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
478 buffer.memory = V4L2_MEMORY_MMAP; 478 buffer.memory = V4L2_MEMORY_MMAP;
479 buffer.index = i; 479 buffer.index = i;
480 buffer.length = 1; 480 buffer.length = 1;
481 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QUERYBUF, &buffer)) < 0) { 481 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QUERYBUF, &buffer)) < 0) {
482 DLOG(ERROR) << "Error querying status of a MMAP V4L2 buffer"; 482 DLOG(ERROR) << "Error querying status of a MMAP V4L2 buffer";
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 524 }
525 525
526 void VideoCaptureDeviceLinux::V4L2CaptureDelegate::SetErrorState( 526 void VideoCaptureDeviceLinux::V4L2CaptureDelegate::SetErrorState(
527 const std::string& reason) { 527 const std::string& reason) {
528 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); 528 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
529 is_capturing_ = false; 529 is_capturing_ = false;
530 client_->OnError(reason); 530 client_->OnError(reason);
531 } 531 }
532 532
533 } // namespace media 533 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698