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

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

Issue 1016773002: MJPEG acceleration for video capture using VAAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix many thread issues Created 5 years, 8 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 "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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } 318 }
319 319
320 // Set capture framerate in the form of capture interval. 320 // Set capture framerate in the form of capture interval.
321 v4l2_streamparm streamparm = {}; 321 v4l2_streamparm streamparm = {};
322 streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 322 streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
323 // The following line checks that the driver knows about framerate get/set. 323 // The following line checks that the driver knows about framerate get/set.
324 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_PARM, &streamparm)) >= 0) { 324 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_G_PARM, &streamparm)) >= 0) {
325 // Now check if the device is able to accept a capture framerate set. 325 // Now check if the device is able to accept a capture framerate set.
326 if (streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) { 326 if (streamparm.parm.capture.capability & V4L2_CAP_TIMEPERFRAME) {
327 // |frame_rate| is float, approximate by a fraction. 327 // |frame_rate| is float, approximate by a fraction.
328 LOG(ERROR) << " frame_rate = " << frame_rate;
328 streamparm.parm.capture.timeperframe.numerator = 329 streamparm.parm.capture.timeperframe.numerator =
329 media::kFrameRatePrecision; 330 media::kFrameRatePrecision;
330 streamparm.parm.capture.timeperframe.denominator = (frame_rate) ? 331 streamparm.parm.capture.timeperframe.denominator = (frame_rate) ?
331 (frame_rate * media::kFrameRatePrecision) : 332 (frame_rate * media::kFrameRatePrecision) :
332 (kTypicalFramerate * media::kFrameRatePrecision); 333 (kTypicalFramerate * media::kFrameRatePrecision);
333 334
334 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_PARM, &streamparm)) < 335 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_S_PARM, &streamparm)) <
335 0) { 336 0) {
336 SetErrorState("Failed to set camera framerate"); 337 SetErrorState("Failed to set camera framerate");
337 return; 338 return;
338 } 339 }
339 DVLOG(2) << "Actual camera driverframerate: " 340 DVLOG(2) << "Actual camera driverframerate: "
340 << streamparm.parm.capture.timeperframe.denominator << "/" 341 << streamparm.parm.capture.timeperframe.denominator << "/"
341 << streamparm.parm.capture.timeperframe.numerator; 342 << streamparm.parm.capture.timeperframe.numerator;
343 LOG(ERROR) << "Actual camera driverframerate: "
344 << streamparm.parm.capture.timeperframe.denominator << "/"
345 << streamparm.parm.capture.timeperframe.numerator;
342 } 346 }
343 } 347 }
344 // TODO(mcasas): what should be done if the camera driver does not allow 348 // TODO(mcasas): what should be done if the camera driver does not allow
345 // framerate configuration, or the actual one is different from the desired? 349 // framerate configuration, or the actual one is different from the desired?
346 350
347 // Set anti-banding/anti-flicker to 50/60Hz. May fail due to not supported 351 // Set anti-banding/anti-flicker to 50/60Hz. May fail due to not supported
348 // operation (|errno| == EINVAL in this case) or plain failure. 352 // operation (|errno| == EINVAL in this case) or plain failure.
349 if ((power_line_frequency_ == kPowerLine50Hz) || 353 if ((power_line_frequency_ == kPowerLine50Hz) ||
350 (power_line_frequency_ == kPowerLine60Hz)) { 354 (power_line_frequency_ == kPowerLine60Hz)) {
351 struct v4l2_control control = {}; 355 struct v4l2_control control = {};
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 client_.reset(); 405 client_.reset();
402 } 406 }
403 407
404 void VideoCaptureDeviceLinux::V4L2CaptureDelegate::SetRotation(int rotation) { 408 void VideoCaptureDeviceLinux::V4L2CaptureDelegate::SetRotation(int rotation) {
405 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); 409 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
406 DCHECK(rotation >= 0 && rotation < 360 && rotation % 90 == 0); 410 DCHECK(rotation >= 0 && rotation < 360 && rotation % 90 == 0);
407 rotation_ = rotation; 411 rotation_ = rotation;
408 } 412 }
409 413
410 void VideoCaptureDeviceLinux::V4L2CaptureDelegate::DoCapture() { 414 void VideoCaptureDeviceLinux::V4L2CaptureDelegate::DoCapture() {
415 DVLOG(3) << __func__;
411 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); 416 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
412 if (!is_capturing_) 417 if (!is_capturing_)
413 return; 418 return;
414 419
415 pollfd device_pfd = {}; 420 pollfd device_pfd = {};
416 device_pfd.fd = device_fd_.get(); 421 device_pfd.fd = device_fd_.get();
417 device_pfd.events = POLLIN; 422 device_pfd.events = POLLIN;
418 const int result = HANDLE_EINTR(poll(&device_pfd, 1, kCaptureTimeoutMs)); 423 const int result = HANDLE_EINTR(poll(&device_pfd, 1, kCaptureTimeoutMs));
419 if (result < 0) { 424 if (result < 0) {
420 SetErrorState("Poll failed"); 425 SetErrorState("Poll failed");
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 529 }
525 530
526 void VideoCaptureDeviceLinux::V4L2CaptureDelegate::SetErrorState( 531 void VideoCaptureDeviceLinux::V4L2CaptureDelegate::SetErrorState(
527 const std::string& reason) { 532 const std::string& reason) {
528 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); 533 DCHECK(v4l2_task_runner_->BelongsToCurrentThread());
529 is_capturing_ = false; 534 is_capturing_ = false;
530 client_->OnError(reason); 535 client_->OnError(reason);
531 } 536 }
532 537
533 } // namespace media 538 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698