blob: da5d60d713696e045838306ed7e93e07caf7659a [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
11#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
12#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_
13
14/*
15 * video_capture_impl.h
16 */
17
18#include "video_capture.h"
19#include "video_capture_config.h"
20#include "tick_util.h"
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000021#include "common_video/interface/i420_video_frame.h"
andrew@webrtc.orgc1354bd2012-07-27 18:21:16 +000022#include "common_video/libyuv/include/webrtc_libyuv.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24namespace webrtc
25{
26class CriticalSectionWrapper;
27
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000028namespace videocapturemodule {
niklase@google.com470e71d2011-07-07 08:21:25 +000029// Class definitions
30class VideoCaptureImpl: public VideoCaptureModule, public VideoCaptureExternal
31{
32public:
33
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000034 /*
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 */
40 static VideoCaptureModule* Create(const WebRtc_Word32 id,
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000041 const char* deviceUniqueIdUTF8);
niklase@google.com470e71d2011-07-07 08:21:25 +000042
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000043 /*
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 */
niklase@google.com470e71d2011-07-07 08:21:25 +000049 static VideoCaptureModule* Create(const WebRtc_Word32 id,
50 VideoCaptureExternal*& externalCapture);
51
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000052 static DeviceInfo* CreateDeviceInfo(const WebRtc_Word32 id);
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000053
niklase@google.com470e71d2011-07-07 08:21:25 +000054 // Implements Module declared functions.
55 virtual WebRtc_Word32 ChangeUniqueId(const WebRtc_Word32 id);
56
niklase@google.com470e71d2011-07-07 08:21:25 +000057 //Call backs
58 virtual WebRtc_Word32 RegisterCaptureDataCallback(VideoCaptureDataCallback& dataCallback);
59 virtual WebRtc_Word32 DeRegisterCaptureDataCallback();
60 virtual WebRtc_Word32 RegisterCaptureCallback(VideoCaptureFeedBack& callBack);
61 virtual WebRtc_Word32 DeRegisterCaptureCallback();
62
niklase@google.com470e71d2011-07-07 08:21:25 +000063 virtual WebRtc_Word32 SetCaptureDelay(WebRtc_Word32 delayMS);
64 virtual WebRtc_Word32 CaptureDelay();
65 virtual WebRtc_Word32 SetCaptureRotation(VideoCaptureRotation rotation);
66
67 virtual WebRtc_Word32 EnableFrameRateCallback(const bool enable);
68 virtual WebRtc_Word32 EnableNoPictureAlarm(const bool enable);
69
leozwang@webrtc.org1745e932012-03-01 16:30:40 +000070 virtual const char* CurrentDeviceName() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000071
72 // Module handling
73 virtual WebRtc_Word32 TimeUntilNextProcess();
74 virtual WebRtc_Word32 Process();
75
76 // Implement VideoCaptureExternal
77 virtual WebRtc_Word32 IncomingFrame(WebRtc_UWord8* videoFrame,
78 WebRtc_Word32 videoFrameLength,
79 const VideoCaptureCapability& frameInfo,
80 WebRtc_Word64 captureTime = 0);
wu@webrtc.orgf10ea312011-10-14 17:16:04 +000081 virtual WebRtc_Word32 IncomingFrameI420(
82 const VideoFrameI420& video_frame,
83 WebRtc_Word64 captureTime = 0);
84
niklase@google.com470e71d2011-07-07 08:21:25 +000085 // Platform dependent
86 virtual WebRtc_Word32 StartCapture(const VideoCaptureCapability& capability)
87 {
88 _requestedCapability = capability;
89 return -1;
90 }
91 virtual WebRtc_Word32 StopCapture() { return -1; }
92 virtual bool CaptureStarted() {return false; }
93 virtual WebRtc_Word32 CaptureSettings(VideoCaptureCapability& /*settings*/)
94 { return -1; }
95 VideoCaptureEncodeInterface* GetEncodeInterface(const VideoCodec& /*codec*/)
96 { return NULL; }
97
98protected:
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +000099 VideoCaptureImpl(const WebRtc_Word32 id);
100 virtual ~VideoCaptureImpl();
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +0000101 WebRtc_Word32 DeliverCapturedFrame(I420VideoFrame& captureFrame,
mikhal@webrtc.orge83d3112012-10-29 15:59:40 +0000102 WebRtc_Word64 capture_time);
mikhal@webrtc.orgac993fe2012-11-07 17:18:04 +0000103 WebRtc_Word32 DeliverEncodedCapturedFrame(VideoFrame& captureFrame,
104 WebRtc_Word64 capture_time,
105 VideoCodecType codec_type);
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000106
niklase@google.com470e71d2011-07-07 08:21:25 +0000107 WebRtc_Word32 _id; // Module ID
leozwang@webrtc.org1745e932012-03-01 16:30:40 +0000108 char* _deviceUniqueId; // current Device unique name;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109 CriticalSectionWrapper& _apiCs;
110 WebRtc_Word32 _captureDelay; // Current capture delay. May be changed of platform dependent parts.
111 VideoCaptureCapability _requestedCapability; // Should be set by platform dependent code in StartCapture.
112private:
113 void UpdateFrameCount();
114 WebRtc_UWord32 CalculateFrameRate(const TickTime& now);
115
116 CriticalSectionWrapper& _callBackCs;
117
118 TickTime _lastProcessTime; // last time the module process function was called.
119 TickTime _lastFrameRateCallbackTime; // last time the frame rate callback function was called.
120 bool _frameRateCallBack; // true if EnableFrameRateCallback
121 bool _noPictureAlarmCallBack; //true if EnableNoPictureAlarm
122 VideoCaptureAlarm _captureAlarm; // current value of the noPictureAlarm
123
124 WebRtc_Word32 _setCaptureDelay; // The currently used capture delay
125 VideoCaptureDataCallback* _dataCallBack;
126 VideoCaptureFeedBack* _captureCallBack;
127
niklase@google.com470e71d2011-07-07 08:21:25 +0000128 TickTime _lastProcessFrameCount;
129 TickTime _incomingFrameTimes[kFrameRateCountHistorySize];// timestamp for local captured frames
130 VideoRotationMode _rotateFrame; //Set if the frame should be rotated by the capture module.
131
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +0000132 I420VideoFrame _captureFrame;
mikhal@webrtc.org80f14d22012-10-11 15:03:53 +0000133 VideoFrame _capture_encoded_frame;
mflodman@webrtc.org29d75b32011-11-01 17:10:49 +0000134
135 // Used to make sure incoming timestamp is increasing for every frame.
136 WebRtc_Word64 last_capture_time_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000137};
perkj@webrtc.org0cc68dc2011-09-12 08:53:36 +0000138} // namespace videocapturemodule
niklase@google.com470e71d2011-07-07 08:21:25 +0000139} //namespace webrtc
140#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_