Commit f9cc8827 authored by Jonathan Matthew's avatar Jonathan Matthew 🕳

metadata: don't use id3demux when tagging tagless mp3 files (bug #628254)

If the input file doesn't have ID3 tags already, linking id3demux into the
pipeline will fail.  When the detected media type is something other than
application/x-id3, we just link the id3 muxer in directly.
parent 73f96e01
...@@ -145,26 +145,59 @@ id3_tagger (GstElement *pipeline, GstElement *link_to, GstTagList *tags) ...@@ -145,26 +145,59 @@ id3_tagger (GstElement *pipeline, GstElement *link_to, GstTagList *tags)
{ {
GstElement *demux = NULL; GstElement *demux = NULL;
GstElement *mux = NULL; GstElement *mux = NULL;
GstPad *link_src = NULL;
GstStructure *link_type;
/* TODO use new id3tag element here; not sure what name it'll end up with though */ /* TODO use new id3tag element here once it's in gst-plugins-good */
demux = gst_element_factory_make ("id3demux", NULL);
mux = gst_element_factory_make ("id3v2mux", NULL); mux = gst_element_factory_make ("id3v2mux", NULL);
if (demux == NULL || mux == NULL) if (mux == NULL) {
goto error; return NULL;
gst_bin_add_many (GST_BIN (pipeline), demux, mux, NULL); /* if the input stream doesn't contain id3 tags already, we can just link the
if (!gst_element_link (link_to, demux)) * tag writer to it and we're done.
link_src = gst_element_get_static_pad (link_to, "src");
if (link_src == NULL) {
rb_debug ("couldn't get src pad to link to?");
goto error; goto error;
g_signal_connect (demux, "pad-added", (GCallback)id3_pad_added_cb, mux); link_type = gst_caps_get_structure (GST_PAD_CAPS (link_src), 0);
gst_element_set_state (demux, GST_STATE_PAUSED); if (gst_structure_has_name (link_type, "application/x-id3") == FALSE) {
gst_element_set_state (mux, GST_STATE_PAUSED); rb_debug ("input file has no tags, plugging id3 muxer directly");
gst_bin_add (GST_BIN (pipeline), mux);
if (!gst_element_link (link_to, mux)) {
gst_bin_remove (GST_BIN (pipeline), mux);
goto error;
} else {
rb_debug ("input file already has tags, using id3demux first");
demux = gst_element_factory_make ("id3demux", NULL);
if (demux == NULL)
goto error;
gst_bin_add_many (GST_BIN (pipeline), demux, mux, NULL);
if (!gst_element_link (link_to, demux)) {
gst_bin_remove_many (GST_BIN (pipeline), demux, mux, NULL);
goto error;
g_signal_connect (demux, "pad-added", (GCallback)id3_pad_added_cb, mux);
gst_element_set_state (demux, GST_STATE_PAUSED);
gst_element_set_state (mux, GST_STATE_PAUSED);
gst_tag_setter_merge_tags (GST_TAG_SETTER (mux), tags, GST_TAG_MERGE_REPLACE_ALL); gst_tag_setter_merge_tags (GST_TAG_SETTER (mux), tags, GST_TAG_MERGE_REPLACE_ALL);
return mux; return mux;
error: error:
g_object_unref (demux); if (link_src != NULL) {
gst_object_unref (link_src);
if (demux != NULL) {
g_object_unref (demux);
g_object_unref (mux); g_object_unref (mux);
return NULL; return NULL;
} }
...@@ -1029,7 +1062,7 @@ rb_metadata_save (RBMetaData *md, const char *uri, GError **error) ...@@ -1029,7 +1062,7 @@ rb_metadata_save (RBMetaData *md, const char *uri, GError **error)
source = gst_element_make_from_uri (GST_URI_SRC, uri, "urisrc"); source = gst_element_make_from_uri (GST_URI_SRC, uri, "urisrc");
if (source == NULL) { if (source == NULL) {
plugin_name = "urisrc"; plugin_name = "urisrc";
goto missing_plugin; goto missing_plugin;
} }
gst_bin_add (GST_BIN (pipeline), source); gst_bin_add (GST_BIN (pipeline), source);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment