網(wǎng)站建設(shè)需要什么格式的圖片推廣軟件賺錢違法嗎
The chain function
鏈函數(shù)是所有數(shù)據(jù)處理都在其中進(jìn)行的函數(shù)。在簡單過濾器的情況下(本節(jié)示例的情況),_chain()函數(shù)大多是線性函數(shù)——因此對于每個(gè)傳入的緩沖區(qū),也將輸出一個(gè)緩沖區(qū)。下面是一個(gè)非常簡單的chain函數(shù)的實(shí)現(xiàn):
static GstFlowReturn gst_my_filter_chain (GstPad *pad,GstObject *parent,GstBuffer *buf);[..]static void
gst_my_filter_init (GstMyFilter * filter)
{
[..]/* configure chain function on the pad before adding* the pad to the element */gst_pad_set_chain_function (filter->sinkpad,gst_my_filter_chain);
[..]
}static GstFlowReturn
gst_my_filter_chain (GstPad *pad,GstObject *parent,GstBuffer *buf)
{GstMyFilter *filter = GST_MY_FILTER (parent);if (!filter->silent)g_print ("Have data of size %" G_GSIZE_FORMAT" bytes!\n",gst_buffer_get_size (buf));return gst_pad_push (filter->srcpad, buf);
}
顯然,上面的代碼沒什么用。你通常會在那里處理數(shù)據(jù),而不是打印出數(shù)據(jù)所在的位置。但請記住,緩沖區(qū)并不總是可寫的。
在更高級的元素(進(jìn)行事件處理的元素)中,你可能需要另外指定一個(gè)事件處理函數(shù),在發(fā)送流事件時(shí)調(diào)用該函數(shù)(如caps、end-of-stream、newsegment、tags等)。
static void
gst_my_filter_init (GstMyFilter * filter)
{
[..]gst_pad_set_event_function (filter->sinkpad,gst_my_filter_sink_event);
[..]
}static gboolean
gst_my_filter_sink_event (GstPad *pad,GstObject *parent,GstEvent *event)
{GstMyFilter *filter = GST_MY_FILTER (parent);switch (GST_EVENT_TYPE (event)) {case GST_EVENT_CAPS:/* we should handle the format here */break;case GST_EVENT_EOS:/* end-of-stream, we should close down all stream leftovers here */gst_my_filter_stop_processing (filter);break;default:break;}return gst_pad_event_default (pad, parent, event);
}static GstFlowReturn
gst_my_filter_chain (GstPad *pad,GstObject *parent,GstBuffer *buf)
{GstMyFilter *filter = GST_MY_FILTER (parent);GstBuffer *outbuf;outbuf = gst_my_filter_process_data (filter, buf);gst_buffer_unref (buf);if (!outbuf) {/* something went wrong - signal an error */GST_ELEMENT_ERROR (GST_ELEMENT (filter), STREAM, FAILED, (NULL), (NULL));return GST_FLOW_ERROR;}return gst_pad_push (filter->srcpad, outbuf);
}
在某些情況下,元素還可以控制輸入數(shù)據(jù)速率。在這種情況下,你可能想寫一個(gè)所謂的基于循環(huán)的元素。源元素(只有源source pads)也可以是基于get-based的元素。這些概念將在本指南的高級部分和專門討論源source pads的部分中進(jìn)行解釋。
The event function
event函數(shù)會通知你datastream中發(fā)生的特殊事件(例如caps、end-of-stream、newsegment、tags等)。事件可以upstream和downstream傳遞,所以你可以通過sink pad和source pad接收它們。
下面是一個(gè)非常簡單的事件函數(shù),我們將其安裝在元素的sink pads上。
static gboolean gst_my_filter_sink_event (GstPad *pad,GstObject *parent,GstEvent *event);[..]static void
gst_my_filter_init (GstMyFilter * filter)
{
[..]/* configure event function on the pad before adding* the pad to the element */gst_pad_set_event_function (filter->sinkpad,gst_my_filter_sink_event);
[..]
}static gboolean
gst_my_filter_sink_event (GstPad *pad,GstObject *parent,GstEvent *event)
{gboolean ret;GstMyFilter *filter = GST_MY_FILTER (parent);switch (GST_EVENT_TYPE (event)) {case GST_EVENT_CAPS:/* we should handle the format here *//* push the event downstream */ret = gst_pad_push_event (filter->srcpad, event);break;case GST_EVENT_EOS:/* end-of-stream, we should close down all stream leftovers here */gst_my_filter_stop_processing (filter);ret = gst_pad_event_default (pad, parent, event);break;default:/* just call the default handler */ret = gst_pad_event_default (pad, parent, event);break;}return ret;
}
對于未知事件,最好調(diào)用默認(rèn)的事件處理程序gst_pad_event_default()。根據(jù)事件類型,默認(rèn)處理程序?qū)⑥D(zhuǎn)發(fā)事件或簡單地取消引用它。默認(rèn)情況下,CAPS事件是不轉(zhuǎn)發(fā)的,因此我們需要在事件處理程序中執(zhí)行此操作。
The query function
通過query函數(shù),元素將收到查詢,并必須響應(yīng)查詢。這些查詢包括位置、持續(xù)時(shí)間等,還包括元素支持的格式和調(diào)度模式。查詢可以在上游和下游傳輸,所以你可以在sink pad和source pad上接收它們。
下面是我們在元素的source pad上安裝的一個(gè)非常簡單的查詢函數(shù)。
static gboolean gst_my_filter_src_query (GstPad *pad,GstObject *parent,GstQuery *query);[..]static void
gst_my_filter_init (GstMyFilter * filter)
{
[..]/* configure event function on the pad before adding* the pad to the element */gst_pad_set_query_function (filter->srcpad,gst_my_filter_src_query);
[..]
}static gboolean
gst_my_filter_src_query (GstPad *pad,GstObject *parent,GstQuery *query)
{gboolean ret;GstMyFilter *filter = GST_MY_FILTER (parent);switch (GST_QUERY_TYPE (query)) {case GST_QUERY_POSITION:/* we should report the current position */[...]break;case GST_QUERY_DURATION:/* we should report the duration here */[...]break;case GST_QUERY_CAPS:/* we should report the supported caps here */[...]break;default:/* just call the default handler */ret = gst_pad_query_default (pad, parent, query);break;}return ret;
}
對于未知的查詢,最好調(diào)用默認(rèn)的查詢處理程序gst_pad_query_default()。根據(jù)查詢類型,默認(rèn)處理程序?qū)⑥D(zhuǎn)發(fā)查詢或簡單地取消引用它。