2 * Copyright (C) 2006 James Livingston <doclivingston@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * SECTION:element-vorbistag
22 * @see_also: #oggdemux, #oggmux, #vorbisparse, #GstTagSetter
24 * The vorbistags element can change the tag contained within a raw
25 * vorbis stream. Specifically, it modifies the comments header packet
26 * of the vorbis stream.
28 * The element will also process the stream as the #vorbisparse element does
29 * so it can be used when remuxing an Ogg Vorbis stream, without additional
32 * Applications can set the tags to write using the #GstTagSetter interface.
33 * Tags contained withing the vorbis bitstream will be picked up
34 * automatically (and merged according to the merge mode set via the tag
38 * <title>Example pipelines</title>
40 * gst-launch -v filesrc location=foo.ogg ! oggdemux ! vorbistag ! oggmux ! filesink location=bar.ogg
41 * ]| This element is not useful with gst-launch, because it does not support
42 * setting the tags on a #GstTagSetter interface. Conceptually, the element
43 * will usually be used in this order though.
52 #include <gst/tag/tag.h>
53 #include <gst/gsttagsetter.h>
55 #include <vorbis/codec.h>
57 #include "gstvorbistag.h"
60 GST_DEBUG_CATEGORY_EXTERN (vorbisparse_debug);
61 #define GST_CAT_DEFAULT vorbisparse_debug
63 static GstFlowReturn gst_vorbis_tag_parse_packet (GstVorbisParse * parse,
66 #define gst_vorbis_tag_parent_class parent_class
67 G_DEFINE_TYPE_WITH_CODE (GstVorbisTag, gst_vorbis_tag,
68 GST_TYPE_VORBIS_PARSE, G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL));
71 gst_vorbis_tag_class_init (GstVorbisTagClass * klass)
73 GstVorbisParseClass *vorbisparse_class = GST_VORBIS_PARSE_CLASS (klass);
74 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
76 gst_element_class_set_static_metadata (element_class,
77 "VorbisTag", "Formatter/Metadata",
78 "Retags vorbis streams", "James Livingston <doclivingston@gmail.com>");
80 vorbisparse_class->parse_packet = gst_vorbis_tag_parse_packet;
84 gst_vorbis_tag_init (GstVorbisTag * tagger)
91 gst_vorbis_tag_parse_packet (GstVorbisParse * parse, GstBuffer * buffer)
93 GstTagList *old_tags, *new_tags;
94 const GstTagList *user_tags;
96 gchar *encoder = NULL;
99 gboolean do_parse = FALSE;
101 gst_buffer_map (buffer, &map, GST_MAP_READ);
102 /* just pass everything except the comments packet */
103 if (map.size >= 1 && map.data[0] != 0x03)
105 gst_buffer_unmap (buffer, &map);
108 return GST_VORBIS_PARSE_CLASS (parent_class)->parse_packet (parse, buffer);
111 tagger = GST_VORBIS_TAG (parse);
114 gst_tag_list_from_vorbiscomment_buffer (buffer, (guint8 *) "\003vorbis",
116 user_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (tagger));
118 /* build new tag list */
119 new_tags = gst_tag_list_merge (user_tags, old_tags,
120 gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (tagger)));
121 gst_tag_list_free (old_tags);
124 gst_tag_list_to_vorbiscomment_buffer (new_tags, (guint8 *) "\003vorbis",
126 gst_buffer_copy_into (new_buf, buffer, GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
128 gst_tag_list_free (new_tags);
130 gst_buffer_unref (buffer);
132 return GST_VORBIS_PARSE_CLASS (parent_class)->parse_packet (parse, new_buf);