본문 바로가기
MultiMedia Framework/GStreamer

Capabilities의 사용 용도

by 유주원 2013. 7. 30.

Capabilities(짧게 앞으로는 cap) 는 pad에서 지원하고 있는 데이터의 type에 대해 기술하고 있다. 

그렇다면 이러한 cap을 과연 어떤 용도로 사용하게 될까?

해당 메뉴얼에서는 크게 4가지의 사용 방법을 제시하고 있다.


Autoplugging

- element가 자동으로 cap이 지원하는 pad를 연결할 수 있도록 하는 autoplugging을 지원한다. 


Compatibility detection

- 두 개의 pads가 서로 연결되어 있다고 한다면, GStreamer는 해당 pads가 동일한 미디어 타입을 지원하는 지를 검증할 수 있다.

- cap을 통해 해당 검증을 가능케 해준다.


Metadata

- pad로부터 cap 정보를 읽음으로써, application은 현재 pad에 흐르고 있는 미디어 타입에 대한 정보를 제공할 수 있다.

- pad는 하나 이상의 cap을 가지고 있으며, cap 역시 하나 이상의 GstStructure 집합을 가지고 있다.

- 각각의 GstStructure는 field 이름과(e.g. "width") type으로(e.g. G_TYPE_INT or GST_TYPE_INT_RANGE) 구성된 배열 형태로 구성되어 있다.

- application은 cap 집합에 대해 query를 보냄으로써 property 각각에 대한 값을 가져올 수 있다.

- gst_caps_get_structure()를 사용하여 cap으로부터 구조체를 가져올 수 있으며, gst_caps_get_size()를 통해 구조체의 개수를 알 수 있다.


static void read_video_props(GstCaps *caps)

{

gint width, height;

const GstStructure* str;

g_return_if_fail(gst_caps_is_fixed(caps));

str = gst_caps_get_structure(caps, 0);

if(!gst_structure_get_int(str, "width", &width) || !(gst_structure_get_int(str, "height", &height)){

g_print("No width/height available\n");

return;

}

g_print("The video size of this set of capabilities is %dx%d\n", width, height);

}


Filtering

- application은 현재 pad에 동작하는 미디어에 대해 제한을 걸기 위한 용도로 cap을 사용할 수 있다.

- 예를 들어 application은 video size를 설정하기 위해 "filtered caps"을 사용할 수 있다.

- 개발자는 pipeline에 capsfilter element를 삽입하고, "caps" property를 설정함으로써 caps를 필터링할 수 있다. 

- 물론 capsfilter를 사용하기 위해서는 자신만의 GstCaps를 만들어야 하며, 주로 gst_caps_new_simple()을 사용하여 GstCaps를 생성한다.

- Caps filter는 대부분 audioconvert, audioresample 등과 같은 converter element 뒤에 위치하게 된다. 


static gboolean link_elements_with_filter(GstElement *element1, GstElement *elements)

{

gboolean link_ok;

GstCaps* caps;

caps = gst_caps_new_simple("video/x-raw-yuv", 

"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('I', '4', '2', '0'),

"width", G_TYPE_INT, 384,

"height", G_TYPE_INT, 288,

"framerate", G_TYPE_FRACTION, 25 ,1,

NULL);

link_ok = gst_element_link_filtered(element1, element2, caps);

gst_caps_unref(caps);

if(!link_ok){

g_warning("Failed to link element1 and element2!");

}

return link_ok;

}


- 위 코드는 element1과 element2 사이에 흐르는 video 데이터의 format과 width, height, framerate를 조절하게 해주는 역할을 한다.

- gst_element_link_filtered() 함수는 자동으로 capsfilter element를 생성해주고, 두 개의 element 사이에 연결까지 해주는 함수이다.

- 보다 정교하게 cap에 대한 설정이 필요할 시에는 gst_caps_new_full() 함수를 사용하여 구현하면 된다.


static gboolean link_elements_with_filter(GstElement* element1, GstElement* element2)

{

gboolean link_ok;

GstCaps* caps;

caps = gst_caps_new_full(gst_structure_new("video/x-raw-yuv",

"width", G_TYPE_INT, 384,

"height", G_TYPE_INT, 288,

"framerate", GST_TYPE_FRACTION, 25, 1,

NULL),

gst_structure_new("video/x-raw-rgb",

"width", G_TYPE_INT, 384,

"height", G_TYPE_INT, 288,

"framerate", GST_TYPE_FRACTION, 25, 1,

NULL),

NULL);

link_ok = gst_element_link_filtered(element1, element2, caps);

gst_cpas_unref(caps);

if(!link_ok){

g_warning("Failed to link element1 and element2!");

}

return link_ok;

}


- GstStructure와 GstCaps에 대한 보다 자세한 API는 아래 url을 참고하면 된다.

http://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/GstStructure.html

http://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/GstCaps.html