체인 함수는 모든 데이터 처리가 이루어지는 함수입니다. 간단한 필터의 경우 _chain() 함수는 대부분 선형 함수입니다. 즉, 들어오는 버퍼마다 하나의 버퍼도 나갑니다. 아래는 체인 함수의 매우 간단한 구현입니다.
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);
}
분명히 위의 내용은 별로 유용하지 않습니다. 데이터가 들어 왔다고 출력하는 대신, 일반적으로 그곳에서 데이터를 처리합니다. 그러나 버퍼가 항상 쓰기 가능한 것은 아니라는 점을 기억하세요.
더 고급 element (이벤트 처리를 하는 element)에서는 스트림 이벤트가 전송될 때 호출되는 이벤트 처리 함수를 추가로 지정할 수 있습니다 (예: 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);
}
어떤 경우에는 element가 입력 데이터 속도를 제어하는 것도 유용할 수 있습니다. 그런 경우 소위 loop-based element를 작성하고 싶을 것입니다. Source element (source pad만 있음)도 get-based element가 될 수 있습니다. 이러한 개념은 이 가이드의 고급 섹션과 source pad를 구체적으로 설명하는 섹션에서 설명합니다.
원문: The chain function (gstreamer.freedesktop.org)
The chain function
The chain function The chain function is the function in which all data processing takes place. In the case of a simple filter, _chain () functions are mostly linear functions - so for each incoming buffer, one buffer will go out, too. Below is a very simp
gstreamer.freedesktop.org
'IT와 개발 > GStreamer Study' 카테고리의 다른 글
The query function (3) | 2024.09.20 |
---|---|
The event function (0) | 2024.09.13 |
Specifying the pads (1) | 2024.08.30 |
Constructing the Boilerplate (0) | 2024.08.23 |
Plugin Writer's Guide: Foundations (0) | 2024.08.16 |