webrtc视频引擎之 vedio_capture_module介绍

  此部分为webrtc采集视频图像之用,源码结构如下:

  

  如上代码结构:

         1,能直接看到的代码,是视频采集适配源码,用于不同平台的适配;

         2,文件夹android为采集android设备的视频信息;

         3,文件夹 ios为采集ios设备的视频信息;

         4,文件夹linux为采集linux设备的视频信息;

         5,文件夹mac为采集mac设备的视频信息;

         6,文件夹windows为采集Windows设备的视频信息;


以下为视频采集模块的接口类:

   主要的接口如Create函数,传入一个视频设备创建一个视频捕获实例;

         StartCapture函数启动视频采集;

          StopCapture函数停止视频采集;

         IncomingFrame/IncomingI420VideoFrame 函数为采集帧回调函数,当开始采集视频的时候,采集到的每一帧的数据将通过该函数回调出来;根据你需要选择你的回调。

    

class VideoCaptureImpl: public VideoCaptureModule, public VideoCaptureExternal
{
public:

    /*
     *   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
     */
    static VideoCaptureModule* Create(const int32_t id,
                                      const char* deviceUniqueIdUTF8);

    /*
     *   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.
     */
    static VideoCaptureModule* Create(const int32_t id,
                                      VideoCaptureExternal*& externalCapture);

    static DeviceInfo* CreateDeviceInfo(const int32_t id);

    // Helpers for converting between (integral) degrees and
    // VideoCaptureRotation values.  Return 0 on success.
    static int32_t RotationFromDegrees(int degrees,
                                       VideoCaptureRotation* rotation);
    static int32_t RotationInDegrees(VideoCaptureRotation rotation,
                                     int* degrees);

    // Implements Module declared functions.
    virtual int32_t ChangeUniqueId(const int32_t id);

    //Call backs
    virtual int32_t RegisterCaptureDataCallback(VideoCaptureDataCallback& dataCallback);
    virtual int32_t DeRegisterCaptureDataCallback();
    virtual int32_t RegisterCaptureCallback(VideoCaptureFeedBack& callBack);
    virtual int32_t DeRegisterCaptureCallback();

    virtual int32_t SetCaptureDelay(int32_t delayMS);
    virtual int32_t CaptureDelay();
    virtual int32_t SetCaptureRotation(VideoCaptureRotation rotation);

    virtual int32_t EnableFrameRateCallback(const bool enable);
    virtual int32_t EnableNoPictureAlarm(const bool enable);

    virtual const char* CurrentDeviceName() const;

    // Module handling
    virtual int32_t TimeUntilNextProcess();
    virtual int32_t Process();

    // Implement VideoCaptureExternal
    // |capture_time| must be specified in the NTP time format in milliseconds.
    virtual int32_t <span style="color:#ff0000;">IncomingFrame</span>(uint8_t* videoFrame,
                                  int32_t videoFrameLength,
                                  const VideoCaptureCapability& frameInfo,
                                  int64_t captureTime = 0);

    virtual int32_t IncomingI420VideoFrame(I420VideoFrame* video_frame,
                                           int64_t captureTime = 0);

    // Platform dependent
    virtual int32_t <span style="color:#ff0000;">StartCapture</span>(const VideoCaptureCapability& capability)
    {
        _requestedCapability = capability;
        return -1;
    }
    virtual int32_t <span style="color:#ff0000;">StopCapture</span>()   { return -1; }
    virtual bool CaptureStarted() {return false; }
    virtual int32_t CaptureSettings(VideoCaptureCapability& /*settings*/)
    { return -1; }
    VideoCaptureEncodeInterface* GetEncodeInterface(const VideoCodec& /*codec*/)
    { return NULL; }

protected:
    VideoCaptureImpl(const int32_t id);
    virtual ~VideoCaptureImpl();
    int32_t DeliverCapturedFrame(I420VideoFrame& captureFrame,
                                 int64_t capture_time);

    int32_t _id; // Module ID
    char* _deviceUniqueId; // current Device unique name;
    CriticalSectionWrapper& _apiCs;
    int32_t _captureDelay; // Current capture delay. May be changed of platform dependent parts.
    VideoCaptureCapability _requestedCapability; // Should be set by platform dependent code in StartCapture.
private:
    void UpdateFrameCount();
    uint32_t CalculateFrameRate(const TickTime& now);

    CriticalSectionWrapper& _callBackCs;

    TickTime _lastProcessTime; // last time the module process function was called.
    TickTime _lastFrameRateCallbackTime; // last time the frame rate callback function was called.
    bool _frameRateCallBack; // true if EnableFrameRateCallback
    bool _noPictureAlarmCallBack; //true if EnableNoPictureAlarm
    VideoCaptureAlarm _captureAlarm; // current value of the noPictureAlarm

    int32_t _setCaptureDelay; // The currently used capture delay
    VideoCaptureDataCallback* _dataCallBack;
    VideoCaptureFeedBack* _captureCallBack;

    TickTime _lastProcessFrameCount;
    TickTime _incomingFrameTimes[kFrameRateCountHistorySize];// timestamp for local captured frames
    VideoRotationMode _rotateFrame; //Set if the frame should be rotated by the capture module.

    I420VideoFrame _captureFrame;
    VideoFrame _capture_encoded_frame;

    // Used to make sure incoming timestamp is increasing for every frame.
    int64_t last_capture_time_;

    // Delta used for translating between NTP and internal timestamps.
    const int64_t delta_ntp_internal_ms_;
};

其实对于专业要求不高的开发者,直接调用这些接口就可以实现视频的采集, 当然如果你对视频采集的专业性要求非常高,可能需要你去专门去研究针对每种设备的采集实现也就是上图中的几种设备的采集源码。现在直播这么火热,又是移动互联网时代,有兴趣的可以多研究研究android和IOS视频采集的方式。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值