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 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 18 | #include <stddef.h> |
| 19 | #include <stdint.h> |
| 20 | |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 21 | #include "api/scoped_refptr.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "api/video/video_frame.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 23 | #include "api/video/video_rotation.h" |
| 24 | #include "api/video/video_sink_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "modules/video_capture/video_capture.h" |
| 26 | #include "modules/video_capture/video_capture_config.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 27 | #include "modules/video_capture/video_capture_defines.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "rtc_base/critical_section.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 30 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 32 | namespace videocapturemodule { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | // Class definitions |
Niels Möller | 8581877 | 2019-04-09 08:24:58 +0200 | [diff] [blame] | 34 | class VideoCaptureImpl : public VideoCaptureModule { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 35 | public: |
| 36 | /* |
| 37 | * Create a video capture module object |
| 38 | * |
| 39 | * id - unique identifier of this video capture module object |
| 40 | * deviceUniqueIdUTF8 - name of the device. Available names can be found by |
| 41 | * using GetDeviceName |
| 42 | */ |
| 43 | static rtc::scoped_refptr<VideoCaptureModule> Create( |
| 44 | const char* deviceUniqueIdUTF8); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 46 | static DeviceInfo* CreateDeviceInfo(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 48 | // Helpers for converting between (integral) degrees and |
| 49 | // VideoRotation values. Return 0 on success. |
| 50 | static int32_t RotationFromDegrees(int degrees, VideoRotation* rotation); |
| 51 | static int32_t RotationInDegrees(VideoRotation rotation, int* degrees); |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 52 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 53 | // Call backs |
| 54 | void RegisterCaptureDataCallback( |
| 55 | rtc::VideoSinkInterface<VideoFrame>* dataCallback) override; |
| 56 | void DeRegisterCaptureDataCallback() override; |
fischman@webrtc.org | 4e65e07 | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 57 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 58 | int32_t SetCaptureRotation(VideoRotation rotation) override; |
| 59 | bool SetApplyRotation(bool enable) override; |
Mirko Bonadei | 5aec1f6 | 2018-08-29 13:27:15 +0200 | [diff] [blame] | 60 | bool GetApplyRotation() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 62 | const char* CurrentDeviceName() const override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 64 | // |capture_time| must be specified in NTP time format in milliseconds. |
| 65 | int32_t IncomingFrame(uint8_t* videoFrame, |
| 66 | size_t videoFrameLength, |
| 67 | const VideoCaptureCapability& frameInfo, |
Niels Möller | 8581877 | 2019-04-09 08:24:58 +0200 | [diff] [blame] | 68 | int64_t captureTime = 0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 70 | // Platform dependent |
Mirko Bonadei | 5aec1f6 | 2018-08-29 13:27:15 +0200 | [diff] [blame] | 71 | int32_t StartCapture(const VideoCaptureCapability& capability) override; |
| 72 | int32_t StopCapture() override; |
| 73 | bool CaptureStarted() override; |
| 74 | int32_t CaptureSettings(VideoCaptureCapability& /*settings*/) override; |
pbos@webrtc.org | 2ffb149 | 2013-11-22 13:10:13 +0000 | [diff] [blame] | 75 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 76 | protected: |
| 77 | VideoCaptureImpl(); |
Mirko Bonadei | 5aec1f6 | 2018-08-29 13:27:15 +0200 | [diff] [blame] | 78 | ~VideoCaptureImpl() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 80 | char* _deviceUniqueId; // current Device unique name; |
| 81 | rtc::CriticalSection _apiCs; |
| 82 | VideoCaptureCapability _requestedCapability; // Should be set by platform |
| 83 | // dependent code in |
| 84 | // StartCapture. |
| 85 | private: |
| 86 | void UpdateFrameCount(); |
| 87 | uint32_t CalculateFrameRate(int64_t now_ns); |
Niels Möller | 8581877 | 2019-04-09 08:24:58 +0200 | [diff] [blame] | 88 | int32_t DeliverCapturedFrame(VideoFrame& captureFrame); |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 89 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 90 | // last time the module process function was called. |
| 91 | int64_t _lastProcessTimeNanos; |
| 92 | // last time the frame rate callback function was called. |
| 93 | int64_t _lastFrameRateCallbackTimeNanos; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 95 | rtc::VideoSinkInterface<VideoFrame>* _dataCallBack; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 97 | int64_t _lastProcessFrameTimeNanos; |
| 98 | // timestamp for local captured frames |
| 99 | int64_t _incomingFrameTimesNanos[kFrameRateCountHistorySize]; |
| 100 | VideoRotation _rotateFrame; // Set if the frame should be rotated by the |
| 101 | // capture module. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 103 | // Indicate whether rotation should be applied before delivered externally. |
| 104 | bool apply_rotation_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | }; |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 106 | } // namespace videocapturemodule |
| 107 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 108 | #endif // MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_ |