blob: 197bfd387cdc72d8a44c227aeccff355086aba65 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org1745e932012-03-01 16:30:40 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
12#define MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
14/*
15 * video_capture_impl.h
16 */
17
Yves Gerey3e707812018-11-28 16:47:49 +010018#include <stddef.h>
19#include <stdint.h>
20
Mirko Bonadeid9708072019-01-25 20:26:48 +010021#include "api/scoped_refptr.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "api/video/video_frame.h"
Yves Gerey3e707812018-11-28 16:47:49 +010023#include "api/video/video_rotation.h"
24#include "api/video/video_sink_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "modules/video_capture/video_capture.h"
26#include "modules/video_capture/video_capture_config.h"
Yves Gerey3e707812018-11-28 16:47:49 +010027#include "modules/video_capture/video_capture_defines.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "rtc_base/critical_section.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000029
Yves Gerey665174f2018-06-19 15:03:05 +020030namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000031
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000032namespace videocapturemodule {
niklase@google.com470e71d2011-07-07 08:21:25 +000033// Class definitions
Niels Möller85818772019-04-09 08:24:58 +020034class VideoCaptureImpl : public VideoCaptureModule {
Yves Gerey665174f2018-06-19 15:03:05 +020035 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.com470e71d2011-07-07 08:21:25 +000045
Yves Gerey665174f2018-06-19 15:03:05 +020046 static DeviceInfo* CreateDeviceInfo();
niklase@google.com470e71d2011-07-07 08:21:25 +000047
Yves Gerey665174f2018-06-19 15:03:05 +020048 // 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.org0cc68dc2011-09-12 08:53:36 +000052
Yves Gerey665174f2018-06-19 15:03:05 +020053 // Call backs
54 void RegisterCaptureDataCallback(
55 rtc::VideoSinkInterface<VideoFrame>* dataCallback) override;
56 void DeRegisterCaptureDataCallback() override;
fischman@webrtc.org4e65e072013-10-03 18:23:13 +000057
Yves Gerey665174f2018-06-19 15:03:05 +020058 int32_t SetCaptureRotation(VideoRotation rotation) override;
59 bool SetApplyRotation(bool enable) override;
Mirko Bonadei5aec1f62018-08-29 13:27:15 +020060 bool GetApplyRotation() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
Yves Gerey665174f2018-06-19 15:03:05 +020062 const char* CurrentDeviceName() const override;
niklase@google.com470e71d2011-07-07 08:21:25 +000063
Yves Gerey665174f2018-06-19 15:03:05 +020064 // |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öller85818772019-04-09 08:24:58 +020068 int64_t captureTime = 0);
niklase@google.com470e71d2011-07-07 08:21:25 +000069
Yves Gerey665174f2018-06-19 15:03:05 +020070 // Platform dependent
Mirko Bonadei5aec1f62018-08-29 13:27:15 +020071 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.org2ffb1492013-11-22 13:10:13 +000075
Yves Gerey665174f2018-06-19 15:03:05 +020076 protected:
77 VideoCaptureImpl();
Mirko Bonadei5aec1f62018-08-29 13:27:15 +020078 ~VideoCaptureImpl() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000079
Yves Gerey665174f2018-06-19 15:03:05 +020080 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öller85818772019-04-09 08:24:58 +020088 int32_t DeliverCapturedFrame(VideoFrame& captureFrame);
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000089
Yves Gerey665174f2018-06-19 15:03:05 +020090 // 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.com470e71d2011-07-07 08:21:25 +000094
Yves Gerey665174f2018-06-19 15:03:05 +020095 rtc::VideoSinkInterface<VideoFrame>* _dataCallBack;
niklase@google.com470e71d2011-07-07 08:21:25 +000096
Yves Gerey665174f2018-06-19 15:03:05 +020097 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.com470e71d2011-07-07 08:21:25 +0000102
Yves Gerey665174f2018-06-19 15:03:05 +0200103 // Indicate whether rotation should be applied before delivered externally.
104 bool apply_rotation_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105};
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000106} // namespace videocapturemodule
107} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200108#endif // MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_