| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 : VideoCaptureImpl(), | 44 : VideoCaptureImpl(), |
| 45 _captureCritSect(CriticalSectionWrapper::CreateCriticalSection()), | 45 _captureCritSect(CriticalSectionWrapper::CreateCriticalSection()), |
| 46 _deviceId(-1), | 46 _deviceId(-1), |
| 47 _deviceFd(-1), | 47 _deviceFd(-1), |
| 48 _buffersAllocatedByDevice(-1), | 48 _buffersAllocatedByDevice(-1), |
| 49 _currentWidth(-1), | 49 _currentWidth(-1), |
| 50 _currentHeight(-1), | 50 _currentHeight(-1), |
| 51 _currentFrameRate(-1), | 51 _currentFrameRate(-1), |
| 52 _captureStarted(false), | 52 _captureStarted(false), |
| 53 _captureVideoType(kVideoI420), | 53 _captureVideoType(kVideoI420), |
| 54 _pool(NULL) | 54 _pool(nullptr) {} |
| 55 { | |
| 56 } | |
| 57 | 55 |
| 58 int32_t VideoCaptureModuleV4L2::Init(const char* deviceUniqueIdUTF8) | 56 int32_t VideoCaptureModuleV4L2::Init(const char* deviceUniqueIdUTF8) |
| 59 { | 57 { |
| 60 int len = strlen((const char*) deviceUniqueIdUTF8); | 58 int len = strlen((const char*) deviceUniqueIdUTF8); |
| 61 _deviceUniqueId = new (std::nothrow) char[len + 1]; | 59 _deviceUniqueId = new (std::nothrow) char[len + 1]; |
| 62 if (_deviceUniqueId) | 60 if (_deviceUniqueId) |
| 63 { | 61 { |
| 64 memcpy(_deviceUniqueId, deviceUniqueIdUTF8, len + 1); | 62 memcpy(_deviceUniqueId, deviceUniqueIdUTF8, len + 1); |
| 65 } | 63 } |
| 66 | 64 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 memset(&buffer, 0, sizeof(v4l2_buffer)); | 347 memset(&buffer, 0, sizeof(v4l2_buffer)); |
| 350 buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | 348 buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 351 buffer.memory = V4L2_MEMORY_MMAP; | 349 buffer.memory = V4L2_MEMORY_MMAP; |
| 352 buffer.index = i; | 350 buffer.index = i; |
| 353 | 351 |
| 354 if (ioctl(_deviceFd, VIDIOC_QUERYBUF, &buffer) < 0) | 352 if (ioctl(_deviceFd, VIDIOC_QUERYBUF, &buffer) < 0) |
| 355 { | 353 { |
| 356 return false; | 354 return false; |
| 357 } | 355 } |
| 358 | 356 |
| 359 _pool[i].start = mmap(NULL, buffer.length, PROT_READ | PROT_WRITE, MAP_S
HARED, | 357 _pool[i].start = mmap(nullptr, buffer.length, PROT_READ | PROT_WRITE, |
| 360 _deviceFd, buffer.m.offset); | 358 MAP_SHARED, _deviceFd, buffer.m.offset); |
| 361 | 359 |
| 362 if (MAP_FAILED == _pool[i].start) | 360 if (MAP_FAILED == _pool[i].start) |
| 363 { | 361 { |
| 364 for (unsigned int j = 0; j < i; j++) | 362 for (unsigned int j = 0; j < i; j++) |
| 365 munmap(_pool[j].start, _pool[j].length); | 363 munmap(_pool[j].start, _pool[j].length); |
| 366 return false; | 364 return false; |
| 367 } | 365 } |
| 368 | 366 |
| 369 _pool[i].length = buffer.length; | 367 _pool[i].length = buffer.length; |
| 370 | 368 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 fd_set rSet; | 409 fd_set rSet; |
| 412 struct timeval timeout; | 410 struct timeval timeout; |
| 413 | 411 |
| 414 _captureCritSect->Enter(); | 412 _captureCritSect->Enter(); |
| 415 | 413 |
| 416 FD_ZERO(&rSet); | 414 FD_ZERO(&rSet); |
| 417 FD_SET(_deviceFd, &rSet); | 415 FD_SET(_deviceFd, &rSet); |
| 418 timeout.tv_sec = 1; | 416 timeout.tv_sec = 1; |
| 419 timeout.tv_usec = 0; | 417 timeout.tv_usec = 0; |
| 420 | 418 |
| 421 retVal = select(_deviceFd + 1, &rSet, NULL, NULL, &timeout); | 419 retVal = select(_deviceFd + 1, &rSet, nullptr, nullptr, &timeout); |
| 422 if (retVal < 0 && errno != EINTR) // continue if interrupted | 420 if (retVal < 0 && errno != EINTR) // continue if interrupted |
| 423 { | 421 { |
| 424 // select failed | 422 // select failed |
| 425 _captureCritSect->Leave(); | 423 _captureCritSect->Leave(); |
| 426 return false; | 424 return false; |
| 427 } | 425 } |
| 428 else if (retVal == 0) | 426 else if (retVal == 0) |
| 429 { | 427 { |
| 430 // select timed out | 428 // select timed out |
| 431 _captureCritSect->Leave(); | 429 _captureCritSect->Leave(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 { | 477 { |
| 480 settings.width = _currentWidth; | 478 settings.width = _currentWidth; |
| 481 settings.height = _currentHeight; | 479 settings.height = _currentHeight; |
| 482 settings.maxFPS = _currentFrameRate; | 480 settings.maxFPS = _currentFrameRate; |
| 483 settings.rawType=_captureVideoType; | 481 settings.rawType=_captureVideoType; |
| 484 | 482 |
| 485 return 0; | 483 return 0; |
| 486 } | 484 } |
| 487 } // namespace videocapturemodule | 485 } // namespace videocapturemodule |
| 488 } // namespace webrtc | 486 } // namespace webrtc |
| OLD | NEW |