使用Gstreamer 作為數(shù)據(jù)源輸出視頻數(shù)據(jù) IV Source接口

作為virtual camera程序,gstreamer部分需要向directshow部分提供媒體數(shù)據(jù)和媒體類型信息,所以我們需要兩類接口:

  1. 作為媒體信息接口
    作為媒體信息接口,我們需要提供足夠的信息,以方便directshow用戶創(chuàng)建source的output pin,信息包含的內(nèi)容如下,可參考 使用Gstreamer 作為數(shù)據(jù)源輸出視頻數(shù)據(jù) II 媒體類型信息:
    video/x-raw,width=1280,height=720,format=YUY2,framerate=(fraction)30/1
    我們自定義一個(gè)結(jié)構(gòu)體,VcamMediaInfo, 將包含以上信息,并使用c語(yǔ)言的類型作為屬性類型,方便directshow程序集成:
struct _VcamMediaInfo {
    char* type;
    long  width;
    long  height;
    long  framerate;
};

void  vcam_source_get_mediatype(VcamSource* self, VcamMediaInfo* info);

_VcamMediaInfo 包含了所有的媒體類型信息, vcam_source_get_mediatype用來返回當(dāng)前source支持的媒體類型,這個(gè)接口比較簡(jiǎn)單,僅支持返回一個(gè)具體媒體類型和格式信息。

  1. 數(shù)據(jù)接口
    數(shù)據(jù)接口主要用于在directshow filter 在fillbuffer的時(shí)候獲取數(shù)據(jù),GstSample 封裝的東西比較多,它包含了數(shù)據(jù),類型,時(shí)間以及其它任意數(shù)據(jù);對(duì)我們來說,我們現(xiàn)在之關(guān)系數(shù)據(jù),所以我們將GstMemory作為返回的數(shù)據(jù)容器:
void  vcam_source_get_mediatype(VcamSource* self, VcamMediaInfo* info);

void  vcam_source_pull_sample(VcamSource* self, GstSample* sample);

void  vcam_source_pull_preroll(VcamSource* self, GstSample* sample);

void  vcam_source_pull_sample2(VcamSource* self, GstMemory* mem); //返回gstMemory

void  vcam_source_pull_preroll2(VcamSource* self, GstMemory* mem);  //返回gstMemory

為了能夠被c++程序調(diào)用,我們需要通過extern c 來開發(fā)source的頭文件,最終得到得頭文件如下:

#ifndef VCAM_SOURCE_H
#define VCAM_SOURCE_H

#ifdef __cplusplus             
extern "C" {
#endif
#include <gst/gst.h>  //包含gst 頭文件,方便調(diào)用gstmemory及方法

#define VCAM_TYPE_SOURCE (vcam_source_get_type())
G_DECLARE_DERIVABLE_TYPE(VcamSource, vcam_source, VCAM, SOURCE, GObject)

typedef struct _VcamSourcePrivate VcamSourcePrivate;

struct _VcamSourceClass {
    GObjectClass parent_class;
    gshort(*start)(VcamSource* self);
};

typedef struct _VcamMediaInfo  VcamMediaInfo;

struct _VcamMediaInfo {
    char* type;
    long  width;
    long  height;
    long  framerate;
};
gshort vcam_source_start(VcamSource* self);

void  vcam_source_get_mediatype(VcamSource* self, VcamMediaInfo* info);

void  vcam_source_pull_sample(VcamSource* self, GstSample* sample);

void  vcam_source_pull_preroll(VcamSource* self, GstSample* sample);

void  vcam_source_pull_sample2(VcamSource* self, GstMemory* mem);

void  vcam_source_pull_preroll2(VcamSource* self, GstMemory* mem);

#ifdef __cplusplus
}
#endif


#endif /* __VCAM_SOURCE_H__ */
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容