niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 1745e93 | 2012-03-01 16:30:40 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_ |
| 12 | #define MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
| 14 | /* |
| 15 | * video_capture_impl.h |
| 16 | */ |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "api/video/video_frame.h" |
| 19 | #include "common_video/libyuv/include/webrtc_libyuv.h" |
| 20 | #include "modules/video_capture/video_capture.h" |
| 21 | #include "modules/video_capture/video_capture_config.h" |
| 22 | #include "rtc_base/criticalsection.h" |
| 23 | #include "rtc_base/scoped_ref_ptr.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
| 25 | namespace webrtc |
| 26 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 28 | namespace videocapturemodule { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | // Class definitions |
| 30 | class VideoCaptureImpl: public VideoCaptureModule, public VideoCaptureExternal |
| 31 | { |
| 32 | public: |
| 33 | |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 34 | /* |
| 35 | * Create a video capture module object |
| 36 | * |
| 37 | * id - unique identifier of this video capture module object |
| 38 | * deviceUniqueIdUTF8 - name of the device. Available names can be found by using GetDeviceName |
| 39 | */ |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 40 | static rtc::scoped_refptr<VideoCaptureModule> Create( |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 41 | const char* deviceUniqueIdUTF8); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 43 | /* |
| 44 | * Create a video capture module object used for external capture. |
| 45 | * |
| 46 | * id - unique identifier of this video capture module object |
| 47 | * externalCapture - [out] interface to call when a new frame is captured. |
| 48 | */ |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 49 | static rtc::scoped_refptr<VideoCaptureModule> Create( |
Peter Boström | 1d19441 | 2016-03-21 16:44:31 +0100 | [diff] [blame] | 50 | VideoCaptureExternal*& externalCapture); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 52 | static DeviceInfo* CreateDeviceInfo(); |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 53 | |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 54 | // Helpers for converting between (integral) degrees and |
guoweis@webrtc.org | 5a7dc39 | 2015-02-13 14:31:26 +0000 | [diff] [blame] | 55 | // VideoRotation values. Return 0 on success. |
| 56 | static int32_t RotationFromDegrees(int degrees, VideoRotation* rotation); |
| 57 | static int32_t RotationInDegrees(VideoRotation rotation, int* degrees); |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 58 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | //Call backs |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 60 | void RegisterCaptureDataCallback( |
| 61 | rtc::VideoSinkInterface<VideoFrame>* dataCallback) override; |
| 62 | void DeRegisterCaptureDataCallback() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 64 | int32_t SetCaptureRotation(VideoRotation rotation) override; |
| 65 | bool SetApplyRotation(bool enable) override; |
| 66 | bool GetApplyRotation() override { |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 67 | return apply_rotation_; |
| 68 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 70 | const char* CurrentDeviceName() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | |
| 72 | // Implement VideoCaptureExternal |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 73 | // |capture_time| must be specified in NTP time format in milliseconds. |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 74 | int32_t IncomingFrame(uint8_t* videoFrame, |
| 75 | size_t videoFrameLength, |
| 76 | const VideoCaptureCapability& frameInfo, |
| 77 | int64_t captureTime = 0) override; |
pbos@webrtc.org | 2ffb149 | 2013-11-22 13:10:13 +0000 | [diff] [blame] | 78 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | // Platform dependent |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 80 | int32_t StartCapture(const VideoCaptureCapability& capability) override |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | { |
| 82 | _requestedCapability = capability; |
| 83 | return -1; |
| 84 | } |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 85 | int32_t StopCapture() override { return -1; } |
| 86 | bool CaptureStarted() override {return false; } |
| 87 | int32_t CaptureSettings(VideoCaptureCapability& /*settings*/) override |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 88 | { return -1; } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
| 90 | protected: |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 91 | VideoCaptureImpl(); |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 92 | virtual ~VideoCaptureImpl(); |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 93 | int32_t DeliverCapturedFrame(VideoFrame& captureFrame); |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 94 | |
leozwang@webrtc.org | 1745e93 | 2012-03-01 16:30:40 +0000 | [diff] [blame] | 95 | char* _deviceUniqueId; // current Device unique name; |
kthelgason | ff046c7 | 2017-03-31 02:03:55 -0700 | [diff] [blame] | 96 | rtc::CriticalSection _apiCs; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | VideoCaptureCapability _requestedCapability; // Should be set by platform dependent code in StartCapture. |
| 98 | private: |
| 99 | void UpdateFrameCount(); |
Niels Möller | d28db7f | 2016-05-10 16:31:47 +0200 | [diff] [blame] | 100 | uint32_t CalculateFrameRate(int64_t now_ns); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | |
Niels Möller | d28db7f | 2016-05-10 16:31:47 +0200 | [diff] [blame] | 102 | // last time the module process function was called. |
| 103 | int64_t _lastProcessTimeNanos; |
| 104 | // last time the frame rate callback function was called. |
| 105 | int64_t _lastFrameRateCallbackTimeNanos; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 107 | rtc::VideoSinkInterface<VideoFrame>* _dataCallBack; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
Niels Möller | d28db7f | 2016-05-10 16:31:47 +0200 | [diff] [blame] | 109 | int64_t _lastProcessFrameTimeNanos; |
| 110 | // timestamp for local captured frames |
| 111 | int64_t _incomingFrameTimesNanos[kFrameRateCountHistorySize]; |
guoweis@webrtc.org | 59140d6 | 2015-03-09 17:07:31 +0000 | [diff] [blame] | 112 | VideoRotation _rotateFrame; // Set if the frame should be rotated by the |
| 113 | // capture module. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 115 | // Indicate whether rotation should be applied before delivered externally. |
| 116 | bool apply_rotation_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | }; |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 118 | } // namespace videocapturemodule |
| 119 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 120 | #endif // MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_ |