avimux: rework _request_new_pad to handle explict req-pad-names

Don't ignore explicit pad-names. Rearrange the code and the error handling a
bit. Add a FIXME-0.11 for the bad pad-names.
This commit is contained in:
Stefan Kost 2011-02-16 17:06:51 +02:00
parent 4f78d85707
commit 1e034cb01f

View file

@ -61,6 +61,7 @@
#endif #endif
#include "gst/gst-i18n-plugin.h" #include "gst/gst-i18n-plugin.h"
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -964,6 +965,10 @@ gst_avi_mux_request_new_pad (GstElement * element,
GstPad *newpad; GstPad *newpad;
GstAviPad *avipad; GstAviPad *avipad;
GstElementClass *klass; GstElementClass *klass;
gchar *name = NULL;
const gchar *pad_name = NULL;
GstPadSetCapsFunction setcapsfunc = NULL;
gint pad_id;
g_return_val_if_fail (templ != NULL, NULL); g_return_val_if_fail (templ != NULL, NULL);
@ -978,22 +983,23 @@ gst_avi_mux_request_new_pad (GstElement * element,
klass = GST_ELEMENT_GET_CLASS (element); klass = GST_ELEMENT_GET_CLASS (element);
if (templ == gst_element_class_get_pad_template (klass, "audio_%d")) { /* FIXME-0.11: use %d instead of %02d for pad_names */
gchar *name;
/* setup pad */ if (templ == gst_element_class_get_pad_template (klass, "audio_%d")) {
name = g_strdup_printf ("audio_%02d", avimux->audio_pads); /* don't mix named and unnamed pads, if the pad already exists we fail when
GST_DEBUG_OBJECT (avimux, "adding new pad: %s", name); * trying to add it */
newpad = gst_pad_new_from_template (templ, name); if (req_name != NULL && sscanf (req_name, "audio_%02d", &pad_id) == 1) {
g_free (name); pad_name = req_name;
gst_pad_set_setcaps_function (newpad, } else {
GST_DEBUG_FUNCPTR (gst_avi_mux_audsink_set_caps)); name = g_strdup_printf ("audio_%02d", avimux->audio_pads++);
pad_name = name;
}
setcapsfunc = GST_DEBUG_FUNCPTR (gst_avi_mux_audsink_set_caps);
/* init pad specific data */ /* init pad specific data */
avipad = g_malloc0 (sizeof (GstAviAudioPad)); avipad = g_malloc0 (sizeof (GstAviAudioPad));
avipad->is_video = FALSE; avipad->is_video = FALSE;
avipad->hdr.type = GST_MAKE_FOURCC ('a', 'u', 'd', 's'); avipad->hdr.type = GST_MAKE_FOURCC ('a', 'u', 'd', 's');
avimux->audio_pads++;
/* audio goes last */ /* audio goes last */
avimux->sinkpads = g_slist_append (avimux->sinkpads, avipad); avimux->sinkpads = g_slist_append (avimux->sinkpads, avipad);
} else if (templ == gst_element_class_get_pad_template (klass, "video_%d")) { } else if (templ == gst_element_class_get_pad_template (klass, "video_%d")) {
@ -1001,23 +1007,27 @@ gst_avi_mux_request_new_pad (GstElement * element,
* some video info goes in a single avi header -and therefore mux struct- * some video info goes in a single avi header -and therefore mux struct-
* so video restricted to one stream */ * so video restricted to one stream */
if (avimux->video_pads > 0) if (avimux->video_pads > 0)
return NULL; goto too_many_video_pads;
/* setup pad */ /* setup pad */
GST_DEBUG_OBJECT (avimux, "adding new pad: video_00"); pad_name = "video_00";
newpad = gst_pad_new_from_template (templ, "video_00"); avimux->video_pads++;
gst_pad_set_setcaps_function (newpad, setcapsfunc = GST_DEBUG_FUNCPTR (gst_avi_mux_vidsink_set_caps);
GST_DEBUG_FUNCPTR (gst_avi_mux_vidsink_set_caps));
avipad = g_malloc0 (sizeof (GstAviVideoPad));
/* init pad specific data */ /* init pad specific data */
avipad = g_malloc0 (sizeof (GstAviVideoPad));
avipad->is_video = TRUE; avipad->is_video = TRUE;
avipad->hdr.type = GST_MAKE_FOURCC ('v', 'i', 'd', 's'); avipad->hdr.type = GST_MAKE_FOURCC ('v', 'i', 'd', 's');
avimux->video_pads++;
/* video goes first */ /* video goes first */
avimux->sinkpads = g_slist_prepend (avimux->sinkpads, avipad); avimux->sinkpads = g_slist_prepend (avimux->sinkpads, avipad);
} else } else
goto wrong_template; goto wrong_template;
newpad = gst_pad_new_from_template (templ, pad_name);
gst_pad_set_setcaps_function (newpad, setcapsfunc);
g_free (name);
avipad->collect = gst_collect_pads_add_pad (avimux->collect, avipad->collect = gst_collect_pads_add_pad (avimux->collect,
newpad, sizeof (GstAviCollectData)); newpad, sizeof (GstAviCollectData));
((GstAviCollectData *) (avipad->collect))->avipad = avipad; ((GstAviCollectData *) (avipad->collect))->avipad = avipad;
@ -1028,7 +1038,10 @@ gst_avi_mux_request_new_pad (GstElement * element,
gst_pad_set_event_function (newpad, gst_pad_set_event_function (newpad,
GST_DEBUG_FUNCPTR (gst_avi_mux_handle_event)); GST_DEBUG_FUNCPTR (gst_avi_mux_handle_event));
gst_element_add_pad (element, newpad); if (!gst_element_add_pad (element, newpad))
goto pad_add_failed;
GST_DEBUG_OBJECT (newpad, "Added new request pad");
return newpad; return newpad;
@ -1048,6 +1061,17 @@ wrong_template:
g_warning ("avimux: this is not our template!\n"); g_warning ("avimux: this is not our template!\n");
return NULL; return NULL;
} }
too_many_video_pads:
{
GST_WARNING_OBJECT (avimux, "Can only have one video stream");
return NULL;
}
pad_add_failed:
{
GST_WARNING_OBJECT (avimux, "Adding the new pad '%s' failed", pad_name);
gst_object_unref (newpad);
return NULL;
}
} }
static void static void