gstfilesrc源文件.docx

上传人:b****8 文档编号:30540223 上传时间:2023-08-16 格式:DOCX 页数:41 大小:26.04KB
下载 相关 举报
gstfilesrc源文件.docx_第1页
第1页 / 共41页
gstfilesrc源文件.docx_第2页
第2页 / 共41页
gstfilesrc源文件.docx_第3页
第3页 / 共41页
gstfilesrc源文件.docx_第4页
第4页 / 共41页
gstfilesrc源文件.docx_第5页
第5页 / 共41页
点击查看更多>>
下载资源
资源描述

gstfilesrc源文件.docx

《gstfilesrc源文件.docx》由会员分享,可在线阅读,更多相关《gstfilesrc源文件.docx(41页珍藏版)》请在冰豆网上搜索。

gstfilesrc源文件.docx

gstfilesrc源文件

/*GStreamer

*Copyright(C)1999,2000ErikWalthinsen

*2000,2005WimTaymans

*

*gstfilesrc.c:

*

*Thislibraryisfreesoftware;youcanredistributeitand/or

*modifyitunderthetermsoftheGNULibraryGeneralPublic

*LicenseaspublishedbytheFreeSoftwareFoundation;either

*version2oftheLicense,or(atyouroption)anylaterversion.

*

*Thislibraryisdistributedinthehopethatitwillbeuseful,

*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof

*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.SeetheGNU

*LibraryGeneralPublicLicenseformoredetails.

*

*YoushouldhavereceivedacopyoftheGNULibraryGeneralPublic

*Licensealongwiththislibrary;ifnot,writetothe

*FreeSoftwareFoundation,Inc.,59TemplePlace-Suite330,

*Boston,MA02111-1307,USA.

*/

/**

*SECTION:

element-filesrc

*@see_also:

#GstFileSrc

*

*Readdatafromafileinthelocalfilesystem.

*/

#ifdefHAVE_CONFIG_H

#include"config.h"

#endif

#include

#include"gstfilesrc.h"

#include

#include

#ifdefG_OS_WIN32

#include/*lseek,open,close,read*/

/*Onwin32,stat*defaultto32bit;weneedthe64-bit

*variants,soexplicitlydefineitthatway.*/

#definestat__stat64

#definefstat_fstat64

#undeflseek

#definelseek_lseeki64

#undefoff_t

#defineoff_tguint64

/*Preventstat.hfromdefiningthestat*functionsas

*_stat*,sincewe'reexplicitlyoverridingthat*/

#undef_INC_STAT_INL

#endif

#include

#include

#ifdefHAVE_UNISTD_H

#include

#endif

#ifdefHAVE_MMAP

#include

#endif

#include

#include

#include"../../gst/gst-i18n-lib.h"

staticGstStaticPadTemplatesrctemplate=GST_STATIC_PAD_TEMPLATE("src",

GST_PAD_SRC,

GST_PAD_ALWAYS,

GST_STATIC_CAPS_ANY);

/*FIXMEweshouldbeusingglibforthis*/

#ifndefS_ISREG

#defineS_ISREG(mode)((mode)&_S_IFREG)

#endif

#ifndefS_ISDIR

#defineS_ISDIR(mode)((mode)&_S_IFDIR)

#endif

#ifndefS_ISSOCK

#defineS_ISSOCK(x)(0)

#endif

#ifndefO_BINARY

#defineO_BINARY(0)

#endif

/*Copyofglib'sg_openduetowin32libc/cross-DLLbrokenness:

wecan't

*usethe'filedescriptor'openedinglib(andreturnedfromthisfunction)

*inthislibrary,astheymayhaveunrelatedCruntimes.*/

int

gst_open(constgchar*filename,intflags,intmode)

{

#ifdefG_OS_WIN32

wchar_t*wfilename=g_utf8_to_utf16(filename,-1,NULL,NULL,NULL);

intretval;

intsave_errno;

if(wfilename==NULL){

errno=EINVAL;

return-1;

}

retval=_wopen(wfilename,flags,mode);

save_errno=errno;

g_free(wfilename);

errno=save_errno;

returnretval;

#else

returnopen(filename,flags,mode);

#endif

}

 

/**********************************************************************

*GStreamerDefaultFileSource

*TheoryofOperation

*

*Update:

seeGstFileSrc:

use-mmappropertydocumentationbelow

*forwhyuseofmmap()isdisabledbydefault.

*

*Thissourceusesmmap

(2)toefficientlyloaddatafromafile.

*Todothiswithoutseriouslypollutingtheapplications'memory

*space,itmustdosoinsmallerchunks,say1-4MBatatime.

*Buffersarethensubdividedfromthesemmap'dchunks,todirectly

*makeuseofthemmap.

*

*Tohandlerefcountingsothatthemmapcanbefreedattheappropriate

*time,abufferwillbecreatedforeachmmap'dregion,andallnew

*bufferswillbesub-buffersofthistop-levelbuffer.Astheyare

*freed,therefcountgoesdownonthemmap'dbufferanditsfree()

*functioniscalled,whichwillcallmunmap

(2)onitself.

*

*Ifabufferhappenstocrosstheboundariesofanmmap'dregion,we

*havetodecidewhetherit'smoreefficienttocopythedataintoa

*newbuffer,ormmap()justthatbuffer.Therewillhavetobea

*breakpointsizetodeterminewhichwillbedone.Themmap()size

*hasalottodowiththisaswell,becauseyouendupindouble-

*jeopardy:

thelargertheoutgoingbuffer,themoredatatocopywhen

*itoverlaps,*and*themorefrequentlyyou'llhavebuffersthat*do*

*overlap.

*

*Seekingisanothertrickyaspecttodoefficiently.Theinitial

*implementationofthissourcewon'tmakeuseofthesefeatures,however.

*Theissueisthatifanapplicationseeksbackwardsinafile,*and*

*thatregionofthefileiscoveredbyanmmapthathasn'tbeenfully

*deallocated,wereallyshouldre-useit.Butkeepingtrackofthese

*regionsistrickybecausewehavetolockthestructurethatholds

*them.Weneedtosettleonalockingprimitive(GMutexseemstobe

*areallygoodoption...),thenwecandothat.

*/

 

GST_DEBUG_CATEGORY_STATIC(gst_file_src_debug);

#defineGST_CAT_DEFAULTgst_file_src_debug

/*FileSrcsignalsandargs*/

enum

{

/*FILLME*/

LAST_SIGNAL

};

#defineDEFAULT_BLOCKSIZE4*1024

#defineDEFAULT_MMAPSIZE4*1024*1024

#defineDEFAULT_TOUCHTRUE

#defineDEFAULT_USEMMAPFALSE

#defineDEFAULT_SEQUENTIALFALSE

enum

{

ARG_0,

ARG_LOCATION,

ARG_FD,

ARG_MMAPSIZE,

ARG_SEQUENTIAL,

ARG_TOUCH,

ARG_USEMMAP

};

staticvoidgst_file_src_finalize(GObject*object);

//设置属性的虚函数

staticvoidgst_file_src_set_property(GObject*object,guintprop_id,

constGValue*value,GParamSpec*pspec);

//获取属性的虚函数

staticvoidgst_file_src_get_property(GObject*object,guintprop_id,

GValue*value,GParamSpec*pspec);

staticgbooleangst_file_src_start(GstBaseSrc*basesrc);

staticgbooleangst_file_src_stop(GstBaseSrc*basesrc);

staticgbooleangst_file_src_is_seekable(GstBaseSrc*src);

staticgbooleangst_file_src_get_size(GstBaseSrc*src,guint64*size);

staticGstFlowReturngst_file_src_create(GstBaseSrc*src,guint64offset,

guintlength,GstBuffer**buffer);

staticgbooleangst_file_src_query(GstBaseSrc*src,GstQuery*query);

staticvoidgst_file_src_uri_handler_init(gpointerg_iface,

gpointeriface_data);

staticvoid

_do_init(GTypefilesrc_type)

{

staticconstGInterfaceInfourihandler_info={

gst_file_src_uri_handler_init,

NULL,

NULL

};

g_type_add_interface_static(filesrc_type,GST_TYPE_URI_HANDLER,

&urihandler_info);

GST_DEBUG_CATEGORY_INIT(gst_file_src_debug,"filesrc",0,"filesrcelement");

}

GST_BOILERPLATE_FULL(GstFileSrc,gst_file_src,GstBaseSrc,GST_TYPE_BASE_SRC,

_do_init);

//初始化类结构,定义父类,定义类成员(子类),类详细信息。

//元件细节在_base_init()函数中被注册到插件中

//:

_base_init()用来在创建每个新的子类时,初始化类和子类的属性

staticvoid

gst_file_src_base_init(gpointerg_class)

{

GstElementClass*gstelement_class=GST_ELEMENT_CLASS(g_class);

gst_element_class_set_details_simple(gstelement_class,

"FileSource",

"Source/File",

"Readfromarbitrarypointinafile",

"ErikWalthinsen");

//将pad模板注册到element中

gst_element_class_add_pad_template(gstelement_class,

gst_static_pad_template_get(&srctemplate));

}

 

//定义类成员变量:

1、定义信号及其响应函数;2、定义虚函数等等。

//_class_init()用来对类进行初始化(指定类的信号,参数和虚函数,设定全局状态),该初始化过程只进行一次

staticvoid

gst_file_src_class_init(GstFileSrcClass*klass)

{

GObjectClass*gobject_class;

GstBaseSrcClass*gstbasesrc_class;

gobject_class=G_OBJECT_CLASS(klass);

gstbasesrc_class=GST_BASE_SRC_CLASS(klass);

gobject_class->set_property=gst_file_src_set_property;

gobject_class->get_property=gst_file_src_get_property;

g_object_class_install_property(gobject_class,ARG_FD,

g_param_spec_int("fd","File-descriptor",

"File-descriptorforthefilebeingmmap()d",0,G_MAXINT,0,

G_PARAM_READABLE|G_PARAM_STATIC_STRINGS));

g_object_class_install_property(gobject_class,ARG_LOCATION,

g_param_spec_string("location","FileLocation",

"Locationofthefiletoread",NULL,

G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|

GST_PARAM_MUTABLE_READY));

g_object_class_install_property(gobject_class,ARG_MMAPSIZE,

g_param_spec_ulong("mmapsize","mmap()BlockSize",

"Sizeinbytesofmmap()dregions",0,G_MAXULONG,DEFAULT_MMAPSIZE,

G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|

GST_PARAM_MUTABLE_PLAYING));

g_object_class_install_property(gobject_class,ARG_TOUCH,

g_param_spec_boolean("touch","Touchmappedregionreaddata",

"Touchmmappeddataregionstoforcethemtobereadfromdisk",

DEFAULT_TOUCH,

G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|

GST_PARAM_MUTABLE_PLAYING));

/**

*GstFileSrc:

use-mmap

*

*Whethertousemmap().SettoTRUEtoforceuseofmmap()insteadof

*read()forreadingdata.

*

*Useofmmap()isdisabledbydefaultsincewithmmap()therearea

*numberofoccasionswheretheprocess/applicationwillbenotifiedof

*readerrorsviaaSIGBUSsignalfromthekernel,whichwillleadto

*theapplicationbeingkilledifnothandledbytheapplication.This

*issomethingthatisdifficulttoworkaroundforalibrarylike

*GStreamer,henceuseofmmap()isdisabledbydefault.Saiderrors

*canoccurforexamplewhenanexternaldevice(e.g.anexternalhard

*driveoraportablemusicplayer)areunpluggedwhileinuse,orwhen

*aCD/DVDmediumcannotbebereadbecausethemediumisscratchedor

*otherwisedamaged.

*

**/

g_object_class_install_property(gobject_class,ARG_USEMMAP,

g_param_spec_boolean("use-mmap","Usemmaptoreaddata",

"Whethertousemmap()insteadofread()",

DEFAULT_USEMMAP,G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|

GST_PARAM_MUTABLE_READY));

g_object_class_install_property(gobject_class,ARG_SEQUENTIAL,

g_param_spec_boolean("sequential","Optimiseforsequentialmmapaccess",

"Whethertousemadvisetohinttothekernelthataccessto"

"mmappageswillbesequential",

DEFAULT_SEQUENTIAL,G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|

GST_PARAM_MUTABLE_PLAYING));

gobj

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1