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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
|
|
|
|
|
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* video_capture_impl.h
|
|
|
|
|
*/
|
|
|
|
|
|
2017-01-10 07:44:26 -08:00
|
|
|
#include "webrtc/api/video/video_frame.h"
|
2013-07-12 10:03:52 +00:00
|
|
|
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
|
2015-11-12 12:46:09 +01:00
|
|
|
#include "webrtc/modules/video_capture/video_capture.h"
|
2013-07-12 10:03:52 +00:00
|
|
|
#include "webrtc/modules/video_capture/video_capture_config.h"
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/rtc_base/criticalsection.h"
|
|
|
|
|
#include "webrtc/rtc_base/scoped_ref_ptr.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
|
|
|
|
|
class VideoCaptureImpl: public VideoCaptureModule, public VideoCaptureExternal
|
|
|
|
|
{
|
|
|
|
|
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);
|
2011-09-12 08:53:36 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Create a video capture module object used for external capture.
|
|
|
|
|
*
|
|
|
|
|
* id - unique identifier of this video capture module object
|
|
|
|
|
* externalCapture - [out] interface to call when a new frame is captured.
|
|
|
|
|
*/
|
2016-03-21 16:44:31 +01:00
|
|
|
static rtc::scoped_refptr<VideoCaptureModule> Create(
|
|
|
|
|
VideoCaptureExternal*& externalCapture);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-12-12 00:22:56 -08:00
|
|
|
static DeviceInfo* CreateDeviceInfo();
|
2011-09-12 08:53:36 +00: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);
|
2013-10-03 18:23:13 +00: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;
|
|
|
|
|
|
|
|
|
|
int32_t SetCaptureRotation(VideoRotation rotation) override;
|
|
|
|
|
bool SetApplyRotation(bool enable) override;
|
|
|
|
|
bool GetApplyRotation() override {
|
2015-02-11 18:37:54 +00:00
|
|
|
return apply_rotation_;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-12-12 00:22:56 -08:00
|
|
|
const char* CurrentDeviceName() const override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Implement VideoCaptureExternal
|
2015-03-18 09:51:05 +00: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,
|
|
|
|
|
int64_t captureTime = 0) override;
|
2013-11-22 13:10:13 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// Platform dependent
|
2016-12-12 00:22:56 -08:00
|
|
|
int32_t StartCapture(const VideoCaptureCapability& capability) override
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
_requestedCapability = capability;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2016-12-12 00:22:56 -08:00
|
|
|
int32_t StopCapture() override { return -1; }
|
|
|
|
|
bool CaptureStarted() override {return false; }
|
|
|
|
|
int32_t CaptureSettings(VideoCaptureCapability& /*settings*/) override
|
2011-07-07 08:21:25 +00:00
|
|
|
{ return -1; }
|
|
|
|
|
|
|
|
|
|
protected:
|
2016-12-12 00:22:56 -08:00
|
|
|
VideoCaptureImpl();
|
2011-09-12 08:53:36 +00:00
|
|
|
virtual ~VideoCaptureImpl();
|
2015-05-29 17:21:40 -07:00
|
|
|
int32_t DeliverCapturedFrame(VideoFrame& captureFrame);
|
2011-09-12 08:53:36 +00:00
|
|
|
|
2012-03-01 16:30:40 +00:00
|
|
|
char* _deviceUniqueId; // current Device unique name;
|
2017-03-31 02:03:55 -07:00
|
|
|
rtc::CriticalSection _apiCs;
|
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);
|
2011-07-07 08:21:25 +00: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;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-12-12 00:22:56 -08:00
|
|
|
rtc::VideoSinkInterface<VideoFrame>* _dataCallBack;
|
2011-07-07 08:21:25 +00: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.
|
2011-07-07 08:21:25 +00: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
|
2011-07-07 08:21:25 +00:00
|
|
|
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
|