From 1a9f0541be419798eacc6fedf50cadadebca352b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 16 Aug 2017 21:33:17 +0300 Subject: [PATCH] Use gst_element_get_request_pad() instead of doing it complicated by first getting the pad template Also use the correct pad template name for tee in the docs so that it actually works. --- examples/tutorials/basic-tutorial-7.c | 6 ++--- examples/tutorials/basic-tutorial-8.c | 8 +++--- .../multithreading-and-pad-availability.md | 26 +++++++------------ .../basic/short-cutting-the-pipeline.md | 8 +++--- 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/examples/tutorials/basic-tutorial-7.c b/examples/tutorials/basic-tutorial-7.c index 6edb3c153c..79bd4b7629 100644 --- a/examples/tutorials/basic-tutorial-7.c +++ b/examples/tutorials/basic-tutorial-7.c @@ -5,7 +5,6 @@ int main(int argc, char *argv[]) { GstElement *video_queue, *visual, *video_convert, *video_sink; GstBus *bus; GstMessage *msg; - GstPadTemplate *tee_src_pad_template; GstPad *tee_audio_pad, *tee_video_pad; GstPad *queue_audio_pad, *queue_video_pad; @@ -49,11 +48,10 @@ int main(int argc, char *argv[]) { } /* Manually link the Tee, which has "Request" pads */ - tee_src_pad_template = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (tee), "src_%u"); - tee_audio_pad = gst_element_request_pad (tee, tee_src_pad_template, NULL, NULL); + tee_audio_pad = gst_element_get_request_pad (tee, "src_%u"); g_print ("Obtained request pad %s for audio branch.\n", gst_pad_get_name (tee_audio_pad)); queue_audio_pad = gst_element_get_static_pad (audio_queue, "sink"); - tee_video_pad = gst_element_request_pad (tee, tee_src_pad_template, NULL, NULL); + tee_video_pad = gst_element_get_request_pad (tee, "src_%u"); g_print ("Obtained request pad %s for video branch.\n", gst_pad_get_name (tee_video_pad)); queue_video_pad = gst_element_get_static_pad (video_queue, "sink"); if (gst_pad_link (tee_audio_pad, queue_audio_pad) != GST_PAD_LINK_OK || diff --git a/examples/tutorials/basic-tutorial-8.c b/examples/tutorials/basic-tutorial-8.c index 1ab3bf664a..f7649c2538 100644 --- a/examples/tutorials/basic-tutorial-8.c +++ b/examples/tutorials/basic-tutorial-8.c @@ -118,7 +118,6 @@ static void error_cb (GstBus *bus, GstMessage *msg, CustomData *data) { int main(int argc, char *argv[]) { CustomData data; - GstPadTemplate *tee_src_pad_template; GstPad *tee_audio_pad, *tee_video_pad, *tee_app_pad; GstPad *queue_audio_pad, *queue_video_pad, *queue_app_pad; GstAudioInfo info; @@ -187,14 +186,13 @@ int main(int argc, char *argv[]) { } /* Manually link the Tee, which has "Request" pads */ - tee_src_pad_template = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (data.tee), "src_%u"); - tee_audio_pad = gst_element_request_pad (data.tee, tee_src_pad_template, NULL, NULL); + tee_audio_pad = gst_element_get_request_pad (data.tee, "src_%u"); g_print ("Obtained request pad %s for audio branch.\n", gst_pad_get_name (tee_audio_pad)); queue_audio_pad = gst_element_get_static_pad (data.audio_queue, "sink"); - tee_video_pad = gst_element_request_pad (data.tee, tee_src_pad_template, NULL, NULL); + tee_video_pad = gst_element_get_request_pad (data.tee, "src_%u"); g_print ("Obtained request pad %s for video branch.\n", gst_pad_get_name (tee_video_pad)); queue_video_pad = gst_element_get_static_pad (data.video_queue, "sink"); - tee_app_pad = gst_element_request_pad (data.tee, tee_src_pad_template, NULL, NULL); + tee_app_pad = gst_element_get_request_pad (data.tee, "src_%u"); g_print ("Obtained request pad %s for app branch.\n", gst_pad_get_name (tee_app_pad)); queue_app_pad = gst_element_get_static_pad (data.app_queue, "sink"); if (gst_pad_link (tee_audio_pad, queue_audio_pad) != GST_PAD_LINK_OK || diff --git a/markdown/tutorials/basic/multithreading-and-pad-availability.md b/markdown/tutorials/basic/multithreading-and-pad-availability.md index 3b53541e71..5f5232bb78 100644 --- a/markdown/tutorials/basic/multithreading-and-pad-availability.md +++ b/markdown/tutorials/basic/multithreading-and-pad-availability.md @@ -92,7 +92,6 @@ int main(int argc, char *argv[]) { GstElement *video_queue, *visual, *video_convert, *video_sink; GstBus *bus; GstMessage *msg; - GstPadTemplate *tee_src_pad_template; GstPad *tee_audio_pad, *tee_video_pad; GstPad *queue_audio_pad, *queue_video_pad; @@ -136,11 +135,10 @@ int main(int argc, char *argv[]) { } /* Manually link the Tee, which has "Request" pads */ - tee_src_pad_template = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (tee), "src_%d"); - tee_audio_pad = gst_element_request_pad (tee, tee_src_pad_template, NULL, NULL); + tee_audio_pad = gst_element_get_request_pad (tee, "src_%u"); g_print ("Obtained request pad %s for audio branch.\n", gst_pad_get_name (tee_audio_pad)); queue_audio_pad = gst_element_get_static_pad (audio_queue, "sink"); - tee_video_pad = gst_element_request_pad (tee, tee_src_pad_template, NULL, NULL); + tee_video_pad = gst_element_get_request_pad (tee, "src_%u"); g_print ("Obtained request pad %s for video branch.\n", gst_pad_get_name (tee_video_pad)); queue_video_pad = gst_element_get_static_pad (video_queue, "sink"); if (gst_pad_link (tee_audio_pad, queue_audio_pad) != GST_PAD_LINK_OK || @@ -257,11 +255,10 @@ comment says). ``` c /* Manually link the Tee, which has "Request" pads */ -tee_src_pad_template = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (tee), "src_%d"); -tee_audio_pad = gst_element_request_pad (tee, tee_src_pad_template, NULL, NULL); +tee_audio_pad = gst_element_get_request_pad (tee, "src_%u"); g_print ("Obtained request pad %s for audio branch.\n", gst_pad_get_name (tee_audio_pad)); queue_audio_pad = gst_element_get_static_pad (audio_queue, "sink"); -tee_video_pad = gst_element_request_pad (tee, tee_src_pad_template, NULL, NULL); +tee_video_pad = gst_element_get_request_pad (tee, "src_%u"); g_print ("Obtained request pad %s for video branch.\n", gst_pad_get_name (tee_video_pad)); queue_video_pad = gst_element_get_static_pad (video_queue, "sink"); if (gst_pad_link (tee_audio_pad, queue_audio_pad) != GST_PAD_LINK_OK || @@ -276,15 +273,12 @@ gst_object_unref (queue_video_pad); To link Request Pads, they need to be obtained by “requesting” them to the element. An element might be able to produce different kinds of -Request Pads, so, when requesting them, the desired Pad Template must be -provided. Pad templates are obtained with -`gst_element_class_get_pad_template()` and are identified by their name. +Request Pads, so, when requesting them, the desired Pad Template name must be +provided. In the documentation for the `tee` element we see that it has two pad -templates named “sink” (for its sink Pads) and “src_%d” (for the Request -Pads). - -Once we have the Pad template, we request two Pads from the tee (for the -audio and video branches) with `gst_element_request_pad()`. +templates named “sink” (for its sink Pads) and “src_%u” (for the Request +Pads). We request two Pads from the tee (for the +audio and video branches) with `gst_element_get_request_pad()`. We then obtain the Pads from the downstream elements to which these Request Pads need to be linked. These are normal Always Pads, so we @@ -320,7 +314,7 @@ it still needs to be unreferenced (freed) with `gst_object_unref()`. `queue` elements. - What is a Request Pad and how to link elements with request pads, - with `gst_element_class_get_pad_template()`, `gst_element_request_pad()`, `gst_pad_link()` and + with `gst_element_get_request_pad()`, `gst_pad_link()` and `gst_element_release_request_pad()`. - How to have the same stream available in different branches by using diff --git a/markdown/tutorials/basic/short-cutting-the-pipeline.md b/markdown/tutorials/basic/short-cutting-the-pipeline.md index c40fbb261f..377959891c 100644 --- a/markdown/tutorials/basic/short-cutting-the-pipeline.md +++ b/markdown/tutorials/basic/short-cutting-the-pipeline.md @@ -210,7 +210,6 @@ static void error_cb (GstBus *bus, GstMessage *msg, CustomData *data) { int main(int argc, char *argv[]) { CustomData data; - GstPadTemplate *tee_src_pad_template; GstPad *tee_audio_pad, *tee_video_pad, *tee_app_pad; GstPad *queue_audio_pad, *queue_video_pad, *queue_app_pad; GstAudioInfo info; @@ -280,14 +279,13 @@ int main(int argc, char *argv[]) { } /* Manually link the Tee, which has "Request" pads */ - tee_src_pad_template = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (data.tee), "src_%d"); - tee_audio_pad = gst_element_request_pad (data.tee, tee_src_pad_template, NULL, NULL); + tee_audio_pad = gst_element_get_request_pad (data.tee, "src_%u"); g_print ("Obtained request pad %s for audio branch.\n", gst_pad_get_name (tee_audio_pad)); queue_audio_pad = gst_element_get_static_pad (data.audio_queue, "sink"); - tee_video_pad = gst_element_request_pad (data.tee, tee_src_pad_template, NULL, NULL); + tee_video_pad = gst_element_get_request_pad (data.tee, "src_%u"); g_print ("Obtained request pad %s for video branch.\n", gst_pad_get_name (tee_video_pad)); queue_video_pad = gst_element_get_static_pad (data.video_queue, "sink"); - tee_app_pad = gst_element_request_pad (data.tee, tee_src_pad_template, NULL, NULL); + tee_app_pad = gst_element_get_request_pad (data.tee, "src_%u"); g_print ("Obtained request pad %s for app branch.\n", gst_pad_get_name (tee_app_pad)); queue_app_pad = gst_element_get_static_pad (data.app_queue, "sink"); if (gst_pad_link (tee_audio_pad, queue_audio_pad) != GST_PAD_LINK_OK ||