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 | |
| 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.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 21 | #include "common_video/interface/i420_video_frame.h" |
andrew@webrtc.org | c1354bd | 2012-07-27 18:21:16 +0000 | [diff] [blame] | 22 | #include "common_video/libyuv/include/webrtc_libyuv.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc |
| 25 | { |
| 26 | class CriticalSectionWrapper; |
| 27 | |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 28 | namespace videocapturemodule { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | // Class definitions |
| 30 | class VideoCaptureImpl: public VideoCaptureModule, public VideoCaptureExternal |
| 31 | { |
| 32 | public: |
| 33 | |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 34 | /* |
| 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 | */ |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 40 | static VideoCaptureModule* Create(const int32_t id, |
leozwang@webrtc.org | 1745e93 | 2012-03-01 16:30:40 +0000 | [diff] [blame] | 41 | const char* deviceUniqueIdUTF8); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 43 | /* |
| 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 | */ |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 49 | static VideoCaptureModule* Create(const int32_t id, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | VideoCaptureExternal*& externalCapture); |
| 51 | |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 52 | static DeviceInfo* CreateDeviceInfo(const int32_t id); |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 53 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | // Implements Module declared functions. |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 55 | virtual int32_t ChangeUniqueId(const int32_t id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | //Call backs |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 58 | virtual int32_t RegisterCaptureDataCallback(VideoCaptureDataCallback& dataCallback); |
| 59 | virtual int32_t DeRegisterCaptureDataCallback(); |
| 60 | virtual int32_t RegisterCaptureCallback(VideoCaptureFeedBack& callBack); |
| 61 | virtual int32_t DeRegisterCaptureCallback(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 63 | virtual int32_t SetCaptureDelay(int32_t delayMS); |
| 64 | virtual int32_t CaptureDelay(); |
| 65 | virtual int32_t SetCaptureRotation(VideoCaptureRotation rotation); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 67 | virtual int32_t EnableFrameRateCallback(const bool enable); |
| 68 | virtual int32_t EnableNoPictureAlarm(const bool enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
leozwang@webrtc.org | 1745e93 | 2012-03-01 16:30:40 +0000 | [diff] [blame] | 70 | virtual const char* CurrentDeviceName() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 71 | |
| 72 | // Module handling |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 73 | virtual int32_t TimeUntilNextProcess(); |
| 74 | virtual int32_t Process(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
| 76 | // Implement VideoCaptureExternal |
stefan@webrtc.org | b8e7f4c | 2013-04-12 11:56:23 +0000 | [diff] [blame] | 77 | // |capture_time| must be specified in the NTP time format in milliseconds. |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 78 | virtual int32_t IncomingFrame(uint8_t* videoFrame, |
| 79 | int32_t videoFrameLength, |
| 80 | const VideoCaptureCapability& frameInfo, |
| 81 | int64_t captureTime = 0); |
| 82 | virtual int32_t IncomingFrameI420( |
wu@webrtc.org | f10ea31 | 2011-10-14 17:16:04 +0000 | [diff] [blame] | 83 | const VideoFrameI420& video_frame, |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 84 | int64_t captureTime = 0); |
wu@webrtc.org | f10ea31 | 2011-10-14 17:16:04 +0000 | [diff] [blame] | 85 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | // Platform dependent |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 87 | virtual int32_t StartCapture(const VideoCaptureCapability& capability) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 88 | { |
| 89 | _requestedCapability = capability; |
| 90 | return -1; |
| 91 | } |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 92 | virtual int32_t StopCapture() { return -1; } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | virtual bool CaptureStarted() {return false; } |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 94 | virtual int32_t CaptureSettings(VideoCaptureCapability& /*settings*/) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | { return -1; } |
| 96 | VideoCaptureEncodeInterface* GetEncodeInterface(const VideoCodec& /*codec*/) |
| 97 | { return NULL; } |
| 98 | |
| 99 | protected: |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 100 | VideoCaptureImpl(const int32_t id); |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 101 | virtual ~VideoCaptureImpl(); |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 102 | int32_t DeliverCapturedFrame(I420VideoFrame& captureFrame, |
| 103 | int64_t capture_time); |
| 104 | int32_t DeliverEncodedCapturedFrame(VideoFrame& captureFrame, |
| 105 | int64_t capture_time, |
| 106 | VideoCodecType codec_type); |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 107 | |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 108 | int32_t _id; // Module ID |
leozwang@webrtc.org | 1745e93 | 2012-03-01 16:30:40 +0000 | [diff] [blame] | 109 | char* _deviceUniqueId; // current Device unique name; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | CriticalSectionWrapper& _apiCs; |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 111 | int32_t _captureDelay; // Current capture delay. May be changed of platform dependent parts. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 112 | VideoCaptureCapability _requestedCapability; // Should be set by platform dependent code in StartCapture. |
| 113 | private: |
| 114 | void UpdateFrameCount(); |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 115 | uint32_t CalculateFrameRate(const TickTime& now); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
| 117 | CriticalSectionWrapper& _callBackCs; |
| 118 | |
| 119 | TickTime _lastProcessTime; // last time the module process function was called. |
| 120 | TickTime _lastFrameRateCallbackTime; // last time the frame rate callback function was called. |
| 121 | bool _frameRateCallBack; // true if EnableFrameRateCallback |
| 122 | bool _noPictureAlarmCallBack; //true if EnableNoPictureAlarm |
| 123 | VideoCaptureAlarm _captureAlarm; // current value of the noPictureAlarm |
| 124 | |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 125 | int32_t _setCaptureDelay; // The currently used capture delay |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 126 | VideoCaptureDataCallback* _dataCallBack; |
| 127 | VideoCaptureFeedBack* _captureCallBack; |
| 128 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | TickTime _lastProcessFrameCount; |
| 130 | TickTime _incomingFrameTimes[kFrameRateCountHistorySize];// timestamp for local captured frames |
| 131 | VideoRotationMode _rotateFrame; //Set if the frame should be rotated by the capture module. |
| 132 | |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 133 | I420VideoFrame _captureFrame; |
mikhal@webrtc.org | 80f14d2 | 2012-10-11 15:03:53 +0000 | [diff] [blame] | 134 | VideoFrame _capture_encoded_frame; |
mflodman@webrtc.org | 29d75b3 | 2011-11-01 17:10:49 +0000 | [diff] [blame] | 135 | |
| 136 | // Used to make sure incoming timestamp is increasing for every frame. |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 137 | int64_t last_capture_time_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | }; |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 139 | } // namespace videocapturemodule |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 140 | } //namespace webrtc |
| 141 | #endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_VIDEO_CAPTURE_IMPL_H_ |