2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-03-01 16:30:40 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
|
|
|
|
|
#define MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* video_capture_impl.h
|
|
|
|
|
*/
|
|
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2019-01-25 20:26:48 +01:00
|
|
|
#include "api/scoped_refptr.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video/video_frame.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "api/video/video_rotation.h"
|
|
|
|
|
#include "api/video/video_sink_interface.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_capture/video_capture.h"
|
|
|
|
|
#include "modules/video_capture/video_capture_config.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "modules/video_capture/video_capture_defines.h"
|
2020-07-13 13:09:15 +02:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2011-09-12 08:53:36 +00:00
|
|
|
namespace videocapturemodule {
|
2011-07-07 08:21:25 +00:00
|
|
|
// Class definitions
|
2019-04-09 08:24:58 +02:00
|
|
|
class VideoCaptureImpl : public VideoCaptureModule {
|
2011-07-07 08:21:25 +00:00
|
|
|
public:
|
2011-09-12 08:53:36 +00:00
|
|
|
/*
|
|
|
|
|
* Create a video capture module object
|
|
|
|
|
*
|
|
|
|
|
* id - unique identifier of this video capture module object
|
|
|
|
|
* deviceUniqueIdUTF8 - name of the device. Available names can be found by
|
|
|
|
|
* using GetDeviceName
|
|
|
|
|
*/
|
2016-03-21 16:44:31 +01:00
|
|
|
static rtc::scoped_refptr<VideoCaptureModule> Create(
|
|
|
|
|
const char* deviceUniqueIdUTF8);
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2016-12-12 00:22:56 -08:00
|
|
|
static DeviceInfo* CreateDeviceInfo();
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2013-10-03 18:23:13 +00:00
|
|
|
// Helpers for converting between (integral) degrees and
|
2015-02-13 14:31:26 +00:00
|
|
|
// VideoRotation values. Return 0 on success.
|
|
|
|
|
static int32_t RotationFromDegrees(int degrees, VideoRotation* rotation);
|
|
|
|
|
static int32_t RotationInDegrees(VideoRotation rotation, int* degrees);
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// Call backs
|
2016-12-12 00:22:56 -08:00
|
|
|
void RegisterCaptureDataCallback(
|
|
|
|
|
rtc::VideoSinkInterface<VideoFrame>* dataCallback) override;
|
|
|
|
|
void DeRegisterCaptureDataCallback() override;
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2016-12-12 00:22:56 -08:00
|
|
|
int32_t SetCaptureRotation(VideoRotation rotation) override;
|
|
|
|
|
bool SetApplyRotation(bool enable) override;
|
2018-08-29 13:27:15 +02:00
|
|
|
bool GetApplyRotation() override;
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2016-12-12 00:22:56 -08:00
|
|
|
const char* CurrentDeviceName() const override;
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2021-07-28 20:35:21 +02:00
|
|
|
// `capture_time` must be specified in NTP time format in milliseconds.
|
2016-12-12 00:22:56 -08:00
|
|
|
int32_t IncomingFrame(uint8_t* videoFrame,
|
|
|
|
|
size_t videoFrameLength,
|
|
|
|
|
const VideoCaptureCapability& frameInfo,
|
2019-04-09 08:24:58 +02:00
|
|
|
int64_t captureTime = 0);
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// Platform dependent
|
2018-08-29 13:27:15 +02:00
|
|
|
int32_t StartCapture(const VideoCaptureCapability& capability) override;
|
|
|
|
|
int32_t StopCapture() override;
|
|
|
|
|
bool CaptureStarted() override;
|
|
|
|
|
int32_t CaptureSettings(VideoCaptureCapability& /*settings*/) override;
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
protected:
|
2016-12-12 00:22:56 -08:00
|
|
|
VideoCaptureImpl();
|
2018-08-29 13:27:15 +02:00
|
|
|
~VideoCaptureImpl() override;
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2012-03-01 16:30:40 +00:00
|
|
|
char* _deviceUniqueId; // current Device unique name;
|
2020-07-13 13:09:15 +02:00
|
|
|
Mutex api_lock_;
|
2011-07-07 08:21:25 +00:00
|
|
|
VideoCaptureCapability _requestedCapability; // Should be set by platform
|
|
|
|
|
// dependent code in
|
|
|
|
|
// StartCapture.
|
|
|
|
|
private:
|
|
|
|
|
void UpdateFrameCount();
|
2016-05-10 16:31:47 +02:00
|
|
|
uint32_t CalculateFrameRate(int64_t now_ns);
|
2019-04-09 08:24:58 +02:00
|
|
|
int32_t DeliverCapturedFrame(VideoFrame& captureFrame);
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2016-05-10 16:31:47 +02:00
|
|
|
// last time the module process function was called.
|
|
|
|
|
int64_t _lastProcessTimeNanos;
|
|
|
|
|
// last time the frame rate callback function was called.
|
|
|
|
|
int64_t _lastFrameRateCallbackTimeNanos;
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2016-12-12 00:22:56 -08:00
|
|
|
rtc::VideoSinkInterface<VideoFrame>* _dataCallBack;
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2016-05-10 16:31:47 +02:00
|
|
|
int64_t _lastProcessFrameTimeNanos;
|
|
|
|
|
// timestamp for local captured frames
|
|
|
|
|
int64_t _incomingFrameTimesNanos[kFrameRateCountHistorySize];
|
2015-03-09 17:07:31 +00:00
|
|
|
VideoRotation _rotateFrame; // Set if the frame should be rotated by the
|
|
|
|
|
// capture module.
|
2018-06-19 15:03:05 +02:00
|
|
|
|
2015-02-11 18:37:54 +00:00
|
|
|
// Indicate whether rotation should be applied before delivered externally.
|
|
|
|
|
bool apply_rotation_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace videocapturemodule
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
|