webrtc视频捕获模块
webrtc
的video_capture
模块为我们在不同端设备上采集视频提供了一个跨平台封装的视频采集功能,该模块支持android
、ios
、linux
、mac
和windows
各操作平台下的视频采集,在不同端设备上开发视频直播的时候,也可以使用该模块进行视频采集。
视频采集模块的库头文件webrtc/modules/video_capture/include/video_capture.h
如下所示:
/* * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * 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_INCLUDE_VIDEO_CAPTURE_H_ #define WEBRTC_MODULES_VIDEO_CAPTURE_INCLUDE_VIDEO_CAPTURE_H_ #include "webrtc/modules/interface/module.h" #include "webrtc/modules/video_capture/include/video_capture_defines.h" namespace webrtc { class VideoCaptureModule: public RefCountedModule { public: // Interface for receiving information about available camera devices. class DeviceInfo { public: virtual uint32_t NumberOfDevices() = 0; // Returns the available capture devices. // deviceNumber - Index of capture device. // deviceNameUTF8 - Friendly name of the capture device. // deviceUniqueIdUTF8 - Unique name of the capture device if it exist. // Otherwise same as deviceNameUTF8. // productUniqueIdUTF8 - Unique product id if it exist. // Null terminated otherwise. virtual int32_t GetDeviceName( uint32_t deviceNumber, char* deviceNameUTF8, uint32_t deviceNameLength, char* deviceUniqueIdUTF8, uint32_t deviceUniqueIdUTF8Length, char* productUniqueIdUTF8 = 0, uint32_t productUniqueIdUTF8Length = 0) = 0; // Returns the number of capabilities this device. virtual int32_t NumberOfCapabilities( const char* deviceUniqueIdUTF8) = 0; // Gets the capabilities of the named device. virtual int32_t GetCapability( const char* deviceUniqueIdUTF8, const uint32_t deviceCapabilityNumber, VideoCaptureCapability& capability) = 0; // Gets clockwise angle the captured frames should be rotated in order // to be displayed correctly on a normally rotated display. virtual int32_t GetOrientation( const char* deviceUniqueIdUTF8, VideoCaptureRotation& orientation) = 0; // Gets the capability that best matches the requested width, height and // frame rate. // Returns the deviceCapabilityNumber on success. virtual int32_t GetBestMatchedCapability( const char* deviceUniqueIdUTF8, const VideoCaptureCapability& requested, VideoCaptureCapability& resulting) = 0; // Display OS /capture device specific settings dialog virtual int32_t DisplayCaptureSettingsDialogBox( const char* deviceUniqueIdUTF8, const char* dialogTitleUTF8, void* parentWindow, uint32_t positionX, uint32_t positionY) = 0; virtual ~DeviceInfo() {} }; class VideoCaptureEncodeInterface { public: virtual int32_t ConfigureEncoder(const VideoCodec& codec, uint32_t maxPayloadSize) = 0; // Inform the encoder about the new target bit rate. // - newBitRate : New target bit rate in Kbit/s. // - frameRate : The target frame rate. virtual int32_t SetRates(int32_t newBitRate, int32_t frameRate) = 0; // Inform the encoder about the packet loss and the round-trip time. // - packetLoss : Fraction lost // (loss rate in percent = 100 * packetLoss / 255). // - rtt : Round-trip time in milliseconds. virtual int32_t SetChannelParameters(uint32_t packetLoss, int64_t rtt) = 0; // Encode the next frame as key frame. virtual int32_t EncodeFrameType(const FrameType type) = 0; protected: virtual ~VideoCaptureEncodeInterface() { } }; // Register capture data callback virtual void RegisterCaptureDataCallback( VideoCaptureDataCallback& dataCallback) = 0; // Remove capture data callback virtual void DeRegisterCaptureDataCallback() = 0; // Register capture callback. virtual void RegisterCaptureCallback(VideoCaptureFeedBack& callBack) = 0; // Remove capture callback. virtual void DeRegisterCaptureCallback() = 0; // Start capture device virtual int32_t StartCapture( const VideoCaptureCapability& capability) = 0; virtual int32_t StopCapture() = 0; // Returns the name of the device used by this module. virtual const char* CurrentDeviceName() const = 0; // Returns true if the capture device is running virtual bool CaptureStarted() = 0; // Gets the current configuration. virtual int32_t CaptureSettings(VideoCaptureCapability& settings) = 0; virtual void SetCaptureDelay(int32_t delayMS) = 0; // Returns the current CaptureDelay. Only valid when the camera is running. virtual int32_t CaptureDelay() = 0; // Set the rotation of the captured frames. // If the rotation is set to the same as returned by // DeviceInfo::GetOrientation the captured frames are // displayed correctly if rendered. virtual int32_t SetCaptureRotation(VideoCaptureRotation rotation) = 0; // Gets a pointer to an encode interface if the capture device supports the // requested type and size. NULL otherwise. virtual VideoCaptureEncodeInterface* GetEncodeInterface( const VideoCodec& codec) = 0; virtual void EnableFrameRateCallback(const bool enable) = 0; virtual void EnableNoPictureAlarm(const bool enable) = 0; protected: virtual ~VideoCaptureModule() {}; }; } // namespace webrtc #endif // WEBRTC_MODULES_VIDEO_CAPTURE_INCLUDE_VIDEO_CAPTURE_H_
其中包括一个设备信息类(class DeviceInfo
)和一个采集视频的编码接口类(class VideoCaptureEncodeInterface
),class DeviceInfo
是用来管理处理视频设备信息,而class VideoCaptureEncodeInterface
是用来配置采集的帧编码格式信息。
类VideoCaptureModule
中的函数virtual int32_t StartCapture(const VideoCaptureCapability& capability) = 0;
用于启动采集视频,而virtual int32_t StopCapture() = 0;
用于停止采集视频。
可以看到该模块采用了策略的适配器模式,提供视频采集的基本函数,封装了几个端的视频采集方式。关于该模块的单独使用,可以参考test
下对应的文件。
参考文章
webrtc之视频捕获模块--video_capture
WebRTC手记之本地视频采集
WebRTC手记之WebRtcVideoEngine2模块
相关推荐
zhuiyuanqingya 2020-03-27
GimmeS 2020-02-18
yunjinwang 2020-02-09
biaobro 2020-01-11
yunjinwang 2019-12-09
yunjinwang 2013-07-09
zhuiyuanqingya 2019-11-16
TopsLuo 2019-11-16
sapliang 2019-11-10
yunjinwang 2014-06-04
biaobro 2019-11-04
neteaseim 2019-11-04
neteaseim 2019-11-03
leodengzx 2019-10-25
zhuiyuanqingya 2019-10-23
biaobro 2015-08-27
zhuiyuanqingya 2019-09-08
铁锚的CSDN 2019-09-08
zhuiyuanqingya 2013-11-08