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 _do_init(type) \
68 static const GInterfaceInfo tag_setter_info = { \
73 g_type_add_interface_static (type, GST_TYPE_TAG_SETTER, \
77 GST_BOILERPLATE_FULL (GstVorbisTag, gst_vorbis_tag, GstVorbisParse,
78 GST_TYPE_VORBIS_PARSE, _do_init);
82 gst_vorbis_tag_base_init (gpointer g_class)
84 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
86 gst_element_class_set_details_simple (element_class,
87 "VorbisTag", "Formatter/Metadata",
88 "Retags vorbis streams", "James Livingston <doclivingston@gmail.com>");
92 gst_vorbis_tag_class_init (GstVorbisTagClass * klass)
94 GstVorbisParseClass *vorbisparse_class = GST_VORBIS_PARSE_CLASS (klass);
96 vorbisparse_class->parse_packet = gst_vorbis_tag_parse_packet;
100 gst_vorbis_tag_init (GstVorbisTag * tagger, GstVorbisTagClass * g_class)
107 gst_vorbis_tag_parse_packet (GstVorbisParse * parse, GstBuffer * buffer)
109 GstTagList *old_tags, *new_tags;
110 const GstTagList *user_tags;
111 GstVorbisTag *tagger;
112 gchar *encoder = NULL;
115 /* just pass everything except the comments packet */
116 if (GST_BUFFER_SIZE (buffer) >= 1 && GST_BUFFER_DATA (buffer)[0] != 0x03) {
117 return GST_VORBIS_PARSE_CLASS (parent_class)->parse_packet (parse, buffer);
120 tagger = GST_VORBIS_TAG (parse);
123 gst_tag_list_from_vorbiscomment_buffer (buffer, (guint8 *) "\003vorbis",
125 user_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (tagger));
127 /* build new tag list */
128 new_tags = gst_tag_list_merge (user_tags, old_tags,
129 gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (tagger)));
130 gst_tag_list_free (old_tags);
133 gst_tag_list_to_vorbiscomment_buffer (new_tags, (guint8 *) "\003vorbis",
135 gst_buffer_copy_metadata (new_buf, buffer, GST_BUFFER_COPY_TIMESTAMPS);
137 gst_tag_list_free (new_tags);
139 gst_buffer_unref (buffer);
141 return GST_VORBIS_PARSE_CLASS (parent_class)->parse_packet (parse, new_buf);