gstreamer的collectpad源码分析Word下载.docx
- 文档编号:22061219
- 上传时间:2023-02-02
- 格式:DOCX
- 页数:29
- 大小:125.64KB
gstreamer的collectpad源码分析Word下载.docx
《gstreamer的collectpad源码分析Word下载.docx》由会员分享,可在线阅读,更多相关《gstreamer的collectpad源码分析Word下载.docx(29页珍藏版)》请在冰豆网上搜索。
GstObjectobject;
/*<
public>
*//*withLOCKand/orSTREAM_LOCK*/
/*所有PAD的集合。
/*
*GstCollectData:
*@collect:
owner#GstCollectPads
*@pad:
#GstPadmanagedbythisdata
*@buffer:
currentlyqueuedbuffer.
*@pos:
positioninthebuffer
*@segment:
lastsegmentreceived.
*@dts:
thesignedversionoftheDTSconvertedtorunningtime.Toaccess
*thismemeber,use%GST_COLLECT_PADS_DTSmacro.(Since1.6)
*Structureusedbythecollect_pads.
struct_GstCollectData
{
/*withSTREAM_LOCKof@collect*/
/*指向回collectpad。
GstCollectPads*collect;
GstPad*pad;
GstBuffer*buffer;
guintpos;
GstSegmentsegment;
private>
*/
/*state:
bitfieldforeasierextension;
*eos,flushing,new_segment,waiting*/
GstCollectPadsStateFlagsstate;
GstCollectDataPrivate*priv;
union{
struct{
gint64dts;
}abi;
gpointer_gst_reserved[GST_PADDING];
}ABI;
};
GSList*data;
/*listofCollectDataitems*/
GRecMutexstream_lock;
/*usedtoserializecollectionamongseveralstreams*/
GstCollectPadsPrivate*priv;
};
4.代码分析:
4.1主入口函数:
主入口函数gst_collect_pads_chain,不同pad工作于不同线程中。
代码分析如下:
/*Foreachbufferwereceivewecheckifourcollectedconditionisreached
*andifsowecallthecollectedfunction.Whenthisisdonewecheckif
*datahasbeenunqueued.Ifdataisstillqueuedwewaitholdingthestream
*locktomakesurenoEOSeventcanhappenwhilewearereadytobe
*collected
staticGstFlowReturn
gst_collect_pads_chain(GstPad*pad,GstObject*parent,GstBuffer*buffer)
{
GstCollectData*data;
GstCollectPads*pads;
GstFlowReturnret;
GstBuffer**buffer_p;
guint32cookie;
GST_DEBUG("
Gotbufferforpad%s:
%s"
GST_DEBUG_PAD_NAME(pad));
/*somemagictogetthemanagingcollect_pads*/
GST_OBJECT_LOCK(pad);
data=(GstCollectData*)gst_pad_get_element_private(pad);
if(G_UNLIKELY(data==NULL))
gotono_data;
ref_data(data);
GST_OBJECT_UNLOCK(pad);
pads=data->
collect;
GST_COLLECT_PADS_STREAM_LOCK(pads);
/*状态判断。
/*ifnotstarted,bailout*/
if(G_UNLIKELY(!
pads->
priv->
started))
gotonot_started;
/*checkifthispadisflushing*/
if(G_UNLIKELY(GST_COLLECT_PADS_STATE_IS_SET(data,
GST_COLLECT_PADS_STATE_FLUSHING)))
gotoflushing;
/*padwasEOS,wecanrefusethisdata*/
GST_COLLECT_PADS_STATE_EOS)))
gotoeos;
/*seeifweneedtoclip*/
/*数据前处理。
if(pads->
clip_func){
GstBuffer*outbuf=NULL;
ret=
pads->
clip_func(pads,data,buffer,&
outbuf,
clip_user_data);
buffer=outbuf;
if(G_UNLIKELY(outbuf==NULL))
gotoclipped;
if(G_UNLIKELY(ret==GST_FLOW_EOS))
elseif(G_UNLIKELY(ret!
=GST_FLOW_OK))
gotoerror;
}
GST_DEBUG_OBJECT(pads,"
Queuingbuffer%pforpad%s:
buffer,
GST_DEBUG_PAD_NAME(pad));
/*Onemorepadhasdataqueued*/
//如果当前collectpad处于WAITING状态会将queuedpads增加
if(GST_COLLECT_PADS_STATE_IS_SET(data,GST_COLLECT_PADS_STATE_WAITING))
queuedpads++;
buffer_p=&
data->
buffer;
gst_buffer_replace(buffer_p,buffer);
/*updatesegmentlastpositionifinTIME*/
/*更新当前pad上对应的时间信息,后续用于重新计算等待状态需要用到。
if(G_LIKELY(data->
segment.format==GST_FORMAT_TIME)){
GstClockTimetimestamp;
timestamp=GST_BUFFER_DTS_OR_PTS(buffer);
if(GST_CLOCK_TIME_IS_VALID(timestamp))
data->
segment.position=timestamp;
/*Whilewehavedataqueuedonthispadtrytocollectstuff*/
do{
/*Checkifourcollectedconditionismatchedandcallthecollected
*functionifitis*/
/*主要处理函数,判断收集条件是否满足,后续分析。
ret=gst_collect_pads_check_collected(pads);
/*whenanerroroccurs,wewanttoreportthisbacktothecallerASAP
*withouthavingtoblockifthebufferwasnotpopped*/
/*数据流处理异常,进入异常处理分支。
if(G_UNLIKELY(ret!
/*datawasconsumed,wecanexitandacceptnewdata*/
/*当buffer在check_collected函数中被消费,会在其中减少引用次数,释放buffer。
*数据被处理后退出循环,等待下一次buffer到来调用chain函数。
if(data->
buffer==NULL)
break;
/*数据未被处理,未满足数据收集条件,本pad对应线程将进行唤醒等待。
/*Havingthe_INITheremeanswedon'
tcareaboutanybroadcastuptohere
*(mostofwhichoccurwithSTREAM_LOCKheld,socouldnothavehappened
*anyway).Wedocareaboute.g.aremoveinitiatedbroadcastasofthis
*point.Puttingitherealsomakesthisthreadignoresanyevtitraised
*itself(asisausualWAITsemantic).
GST_COLLECT_PADS_EVT_INIT(cookie);
/*padcouldberemovedandre-added*/
unref_data(data);
if(G_UNLIKELY((data=gst_pad_get_element_private(pad))==NULL))
gotopad_removed;
Pad%s:
%shasabufferqueued,waiting"
/*waittobecollected,thismusthappenfromanotherthreadtriggered
*bythe_chainfunctionofanotherpad.Wereleasethelocksowe
*cangetstoppedorflushedaswell.WecanhowevernotgetEOS
*becausewestillholdtheSTREAM_LOCK.
/*等待条件变量被唤醒。
GST_COLLECT_PADS_STREAM_UNLOCK(pads);
GST_COLLECT_PADS_EVT_WAIT(pads,cookie);
%sresuming"
/*唤醒后的状态判断。
/*afterasignal,wecouldbestopped*/
while(data->
buffer!
=NULL);
unlock_done:
/*dataisdefinitelyNULLifpad_removedgotowasrun.*/
if(data)
if(buffer)
gst_buffer_unref(buffer);
returnret;
/*异常状态处理。
pad_removed:
GST_WARNING("
%sgotremovedfromcollectpads"
GST_OBJECT_NAME(pad));
ret=GST_FLOW_NOT_LINKED;
gotounlock_done;
/*ERRORS*/
no_data:
returnGST_FLOW_NOT_LINKED;
not_started:
notstarted"
);
gst_collect_pads_clear(pads,data);
ret=GST_FLOW_FLUSHING;
flushing:
pad%s:
%sisflushing"
eos:
/*weshouldnotpostanerrorforthis,justinformupstreamthat
*wedon'
texpectanythinganymore*/
%siseos"
ret=GST_FLOW_EOS;
clipped:
clippedbufferonpad%s:
ret=GST_FLOW_OK;
error:
/*weprinttheerror,theelementshouldpostareasonableerror
*messageforfatalerrors*/
collectfailed,reason%d(%s)"
ret,gst_flow_get_name(ret));
}
4.2框架上的收集条件判断
在check函数,首先对collectpads上面的pad状态进行检查,只有当有数据的pads和总的pads数满足一定条件时候,才会执行第二重的收集条件判断。
函数为gst_collect_pads_check_collected,代码分析如下:
gst_collect_pads_check_collected(GstCollectPads*pads)
GstFlowReturnflow_ret=GST_FLOW_OK;
GstCollectPadsFunctionfunc;
gpointeruser_data;
g_return_val_if_fail(GST_IS_COLLECT_PADS(pads),GST_FLOW_ERROR);
/*获取回调数据。
GST_OBJECT_LOCK(pads);
func=pads->
func;
user_data=pads->
user_data;
GST_OBJECT_UNLOCK(pads);
g_return_val_if_fail(pads->
func!
=NULL,GST_FLOW_NOT_SUPPORTED);
/*checkfornewpads,updatestatsetc..*/
/*主要是对等待唤醒的pad的cookie进行校验。
gst_collect_pads_check_pads(pads);
/*所有pad都是EOS状态。
直接处理剩余的所有数据。
if(G_UNLIKELY(pads->
eospads==pads->
numpads)){
/*IfallourpadsareEOSjustcollectoncetolettheelement
*doitsfinalEOShandling.*/
Allactivepads(%d)areEOS,calling%s"
numpads,GST_DEBUG_FUNCPTR_NAME(func));
if(G_UNLIKELY(g_atomic_int_compare_and_exchange(&
seeking,
TRUE,FALSE))){
GST_INFO_OBJECT(pads,"
finishedseeking"
flow_ret=func(pads,user_data);
}w
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- gstreamer collectpad 源码 分析