diff options
Diffstat (limited to 'gst/id3tag')
-rw-r--r-- | gst/id3tag/Makefile.am | 6 | ||||
-rw-r--r-- | gst/id3tag/gstid3mux.c (renamed from gst/id3tag/gstid3tag.c) | 66 | ||||
-rw-r--r-- | gst/id3tag/gstid3mux.h (renamed from gst/id3tag/gstid3tag.h) | 36 | ||||
-rw-r--r-- | gst/id3tag/gsttagmux.c | 10 | ||||
-rw-r--r-- | gst/id3tag/id3tag.c | 46 | ||||
-rw-r--r-- | gst/id3tag/id3tag.h | 4 |
6 files changed, 92 insertions, 76 deletions
diff --git a/gst/id3tag/Makefile.am b/gst/id3tag/Makefile.am index 9595be0f..108a227b 100644 --- a/gst/id3tag/Makefile.am +++ b/gst/id3tag/Makefile.am @@ -1,9 +1,9 @@ plugin_LTLIBRARIES = libgstid3tag.la libgstid3tag_la_SOURCES = \ + gstid3mux.c \ gsttagmux.c \ - id3tag.c \ - gstid3tag.c + id3tag.c libgstid3tag_la_CFLAGS = \ $(GST_PLUGINS_BASE_CFLAGS) \ @@ -16,4 +16,4 @@ libgstid3tag_la_LIBADD = \ libgstid3tag_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstid3tag_la_LIBTOOLFLAGS = --tag=disable-static -noinst_HEADERS = gstid3tag.h id3tag.h gsttagmux.h +noinst_HEADERS = gstid3mux.h gsttagmux.h id3tag.h diff --git a/gst/id3tag/gstid3tag.c b/gst/id3tag/gstid3mux.c index 9c8072c0..b13bfb58 100644 --- a/gst/id3tag/gstid3tag.c +++ b/gst/id3tag/gstid3mux.c @@ -21,12 +21,12 @@ */ /** - * SECTION:element-id3tag + * SECTION:element-id3mux * @see_also: #GstID3Demux, #GstTagSetter * * This element adds ID3v2 tags to the beginning of a stream, and ID3v1 tags * to the end. - * + * * It defaults to writing ID3 version 2.3.0 tags (since those are the most * widely supported), but can optionally write version 2.4.0 tags. * @@ -37,7 +37,7 @@ * <refsect2> * <title>Example pipelines</title> * |[ - * gst-launch -v filesrc location=foo.ogg ! decodebin ! audioconvert ! lame ! id3tag ! filesink location=foo.mp3 + * gst-launch -v filesrc location=foo.ogg ! decodebin ! audioconvert ! lame ! id3mux ! filesink location=foo.mp3 * ]| A pipeline that transcodes a file from Ogg/Vorbis to mp3 format with * ID3 tags that contain the same metadata as the the Ogg/Vorbis file. * Make sure the Ogg/Vorbis file actually has comments to preserve. @@ -51,13 +51,13 @@ #include <config.h> #endif -#include "gstid3tag.h" +#include "gstid3mux.h" #include <gst/tag/tag.h> #include <string.h> -GST_DEBUG_CATEGORY (gst_id3_tag_debug); -#define GST_CAT_DEFAULT gst_id3_tag_debug +GST_DEBUG_CATEGORY (gst_id3_mux_debug); +#define GST_CAT_DEFAULT gst_id3_mux_debug enum { @@ -67,7 +67,7 @@ enum ARG_V2_MAJOR_VERSION }; -#define DEFAULT_WRITE_V1 TRUE +#define DEFAULT_WRITE_V1 FALSE #define DEFAULT_WRITE_V2 TRUE #define DEFAULT_V2_MAJOR_VERSION 3 @@ -76,20 +76,20 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_ALWAYS, GST_STATIC_CAPS ("application/x-id3")); -GST_BOILERPLATE (GstId3Tag, gst_id3_tag, GstTagMux, GST_TYPE_TAG_MUX); +GST_BOILERPLATE (GstId3Mux, gst_id3_mux, GstTagMux, GST_TYPE_TAG_MUX); -static GstBuffer *gst_id3_tag_render_v2_tag (GstTagMux * mux, +static GstBuffer *gst_id3_mux_render_v2_tag (GstTagMux * mux, GstTagList * taglist); -static GstBuffer *gst_id3_tag_render_v1_tag (GstTagMux * mux, +static GstBuffer *gst_id3_mux_render_v1_tag (GstTagMux * mux, GstTagList * taglist); -static void gst_id3_tag_set_property (GObject * object, guint prop_id, +static void gst_id3_mux_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); -static void gst_id3_tag_get_property (GObject * object, guint prop_id, +static void gst_id3_mux_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static void -gst_id3_tag_base_init (gpointer g_class) +gst_id3_mux_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); @@ -101,18 +101,15 @@ gst_id3_tag_base_init (gpointer g_class) "Adds an ID3v2 header and ID3v1 footer to a file", "Michael Smith <msmith@songbirdnest.com>, " "Tim-Philipp Müller <tim centricular net>"); - - GST_DEBUG_CATEGORY_INIT (gst_id3_tag_debug, "id3tag", 0, - "ID3 v1 and v2 tag muxer"); } static void -gst_id3_tag_class_init (GstId3TagClass * klass) +gst_id3_mux_class_init (GstId3MuxClass * klass) { GObjectClass *gobject_class = (GObjectClass *) klass; - gobject_class->set_property = gst_id3_tag_set_property; - gobject_class->get_property = gst_id3_tag_get_property; + gobject_class->set_property = gst_id3_mux_set_property; + gobject_class->get_property = gst_id3_mux_get_property; g_object_class_install_property (gobject_class, ARG_WRITE_V1, g_param_spec_boolean ("write-v1", "Write id3v1 tag", @@ -131,13 +128,13 @@ gst_id3_tag_class_init (GstId3TagClass * klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); GST_TAG_MUX_CLASS (klass)->render_start_tag = - GST_DEBUG_FUNCPTR (gst_id3_tag_render_v2_tag); + GST_DEBUG_FUNCPTR (gst_id3_mux_render_v2_tag); - GST_TAG_MUX_CLASS (klass)->render_end_tag = gst_id3_tag_render_v1_tag; + GST_TAG_MUX_CLASS (klass)->render_end_tag = gst_id3_mux_render_v1_tag; } static void -gst_id3_tag_init (GstId3Tag * id3mux, GstId3TagClass * id3mux_class) +gst_id3_mux_init (GstId3Mux * id3mux, GstId3MuxClass * id3mux_class) { id3mux->write_v1 = DEFAULT_WRITE_V1; id3mux->write_v2 = DEFAULT_WRITE_V2; @@ -146,10 +143,10 @@ gst_id3_tag_init (GstId3Tag * id3mux, GstId3TagClass * id3mux_class) } static void -gst_id3_tag_set_property (GObject * object, guint prop_id, +gst_id3_mux_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { - GstId3Tag *mux = GST_ID3TAG (object); + GstId3Mux *mux = GST_ID3_MUX (object); switch (prop_id) { case ARG_WRITE_V1: @@ -168,10 +165,10 @@ gst_id3_tag_set_property (GObject * object, guint prop_id, } static void -gst_id3_tag_get_property (GObject * object, guint prop_id, +gst_id3_mux_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { - GstId3Tag *mux = GST_ID3TAG (object); + GstId3Mux *mux = GST_ID3_MUX (object); switch (prop_id) { case ARG_WRITE_V1: @@ -190,23 +187,23 @@ gst_id3_tag_get_property (GObject * object, guint prop_id, } static GstBuffer * -gst_id3_tag_render_v2_tag (GstTagMux * mux, GstTagList * taglist) +gst_id3_mux_render_v2_tag (GstTagMux * mux, GstTagList * taglist) { - GstId3Tag *id3mux = GST_ID3TAG (mux); + GstId3Mux *id3mux = GST_ID3_MUX (mux); if (id3mux->write_v2) - return gst_id3mux_render_v2_tag (mux, taglist, id3mux->v2_major_version); + return id3_mux_render_v2_tag (mux, taglist, id3mux->v2_major_version); else return NULL; } static GstBuffer * -gst_id3_tag_render_v1_tag (GstTagMux * mux, GstTagList * taglist) +gst_id3_mux_render_v1_tag (GstTagMux * mux, GstTagList * taglist) { - GstId3Tag *id3mux = GST_ID3TAG (mux); + GstId3Mux *id3mux = GST_ID3_MUX (mux); if (id3mux->write_v1) - return gst_id3mux_render_v1_tag (mux, taglist); + return id3_mux_render_v1_tag (mux, taglist); else return NULL; } @@ -214,7 +211,10 @@ gst_id3_tag_render_v1_tag (GstTagMux * mux, GstTagList * taglist) static gboolean plugin_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "id3tag", GST_RANK_NONE, GST_TYPE_ID3TAG)) + GST_DEBUG_CATEGORY_INIT (gst_id3_mux_debug, "id3mux", 0, + "ID3 v1 and v2 tag muxer"); + + if (!gst_element_register (plugin, "id3mux", GST_RANK_NONE, GST_TYPE_ID3_MUX)) return FALSE; gst_tag_register_musicbrainz_tags (); diff --git a/gst/id3tag/gstid3tag.h b/gst/id3tag/gstid3mux.h index a9a1ad1c..eb5aa050 100644 --- a/gst/id3tag/gstid3tag.h +++ b/gst/id3tag/gstid3mux.h @@ -20,18 +20,18 @@ * Boston, MA 02111-1307, USA. */ -#ifndef GST_ID3TAG_H -#define GST_ID3TAG_H +#ifndef GST_ID3_MUX_H +#define GST_ID3_MUX_H #include "gsttagmux.h" #include "id3tag.h" G_BEGIN_DECLS -typedef struct _GstId3Tag GstId3Tag; -typedef struct _GstId3TagClass GstId3TagClass; +typedef struct _GstId3Mux GstId3Mux; +typedef struct _GstId3MuxClass GstId3MuxClass; -struct _GstId3Tag { +struct _GstId3Mux { GstTagMux tagmux; gboolean write_v1; @@ -40,24 +40,24 @@ struct _GstId3Tag { gint v2_major_version; }; -struct _GstId3TagClass { +struct _GstId3MuxClass { GstTagMuxClass tagmux_class; }; -#define GST_TYPE_ID3TAG \ - (gst_id3_tag_get_type()) -#define GST_ID3TAG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ID3TAG,GstId3Tag)) -#define GST_ID3TAG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ID3TAG,GstId3TagClass)) -#define GST_IS_ID3TAG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ID3TAG)) -#define GST_IS_ID3TAG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ID3TAG)) +#define GST_TYPE_ID3_MUX \ + (gst_id3_mux_get_type()) +#define GST_ID3_MUX(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ID3_MUX,GstId3Mux)) +#define GST_ID3_MUX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ID3_MUX,GstId3MuxClass)) +#define GST_IS_ID3_MUX(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ID3_MUX)) +#define GST_IS_ID3_MUX_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ID3_MUX)) -GType gst_id3_tag_get_type (void); +GType gst_id3_mux_get_type (void); G_END_DECLS -#endif /* GST_ID3TAG_H */ +#endif /* GST_ID3_MUX_H */ diff --git a/gst/id3tag/gsttagmux.c b/gst/id3tag/gsttagmux.c index 3b7ff119..4aafb96d 100644 --- a/gst/id3tag/gsttagmux.c +++ b/gst/id3tag/gsttagmux.c @@ -57,10 +57,10 @@ gst_tag_mux_iface_init (GType tag_type) /* make sure to register a less generic type so we can easily move this * GstTagMux base class into -base without causing GType name conflicts */ -typedef GstTagMux GstId3TagMux; -typedef GstTagMuxClass GstId3TagMuxClass; +typedef GstTagMux GstId3BaseMux; +typedef GstTagMuxClass GstId3BaseMuxClass; -GST_BOILERPLATE_FULL (GstId3TagMux, gst_tag_mux, +GST_BOILERPLATE_FULL (GstId3BaseMux, gst_tag_mux, GstElement, GST_TYPE_ELEMENT, gst_tag_mux_iface_init); @@ -100,8 +100,8 @@ gst_tag_mux_base_init (gpointer g_class) gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_tag_mux_sink_template)); - GST_DEBUG_CATEGORY_INIT (gst_tag_mux_debug, "tagmux", 0, - "tag muxer base class"); + GST_DEBUG_CATEGORY_INIT (gst_tag_mux_debug, "id3basemux", 0, + "tag muxer base class for Id3Mux"); } static void diff --git a/gst/id3tag/id3tag.c b/gst/id3tag/id3tag.c index a39e2a8e..dd7bb04f 100644 --- a/gst/id3tag/id3tag.c +++ b/gst/id3tag/id3tag.c @@ -25,8 +25,8 @@ #include <gst/tag/tag.h> -GST_DEBUG_CATEGORY_EXTERN (gst_id3_tag_debug); -#define GST_CAT_DEFAULT gst_id3_tag_debug +GST_DEBUG_CATEGORY_EXTERN (gst_id3_mux_debug); +#define GST_CAT_DEFAULT gst_id3_mux_debug #define ID3V2_APIC_PICTURE_OTHER 0 #define ID3V2_APIC_PICTURE_FILE_ICON 1 @@ -1024,7 +1024,7 @@ foreach_add_tag (const GstTagList * list, const gchar * tag, gpointer userdata) } GstBuffer * -gst_id3mux_render_v2_tag (GstTagMux * mux, GstTagList * taglist, int version) +id3_mux_render_v2_tag (GstTagMux * mux, GstTagList * taglist, int version) { GstId3v2Tag tag; GstBuffer *buf; @@ -1062,17 +1062,17 @@ gst_id3mux_render_v2_tag (GstTagMux * mux, GstTagList * taglist, int version) #define ID3_V1_TAG_SIZE 128 typedef void (*GstId3v1WriteFunc) (const GstTagList * list, - const gchar * gst_tag, guint8 * dst, int len); + const gchar * gst_tag, guint8 * dst, int len, gboolean * wrote_tag); static void latin1_convert (const GstTagList * list, const gchar * tag, - guint8 * dst, int maxlen) + guint8 * dst, int maxlen, gboolean * wrote_tag) { gchar *str; gsize len; gchar *latin1; - if (!gst_tag_list_get_string (list, tag, &str)) + if (!gst_tag_list_get_string (list, tag, &str) || str == NULL) return; /* Convert to Latin-1 (ISO-8859-1), replacing unrepresentable characters @@ -1080,9 +1080,10 @@ latin1_convert (const GstTagList * list, const gchar * tag, latin1 = g_convert_with_fallback (str, -1, "ISO-8859-1", "UTF-8", "?", NULL, &len, NULL); - if (latin1) { + if (latin1 != NULL && *latin1 != '\0') { len = MIN (len, maxlen); memcpy (dst, latin1, len); + *wrote_tag = TRUE; g_free (latin1); } @@ -1091,7 +1092,7 @@ latin1_convert (const GstTagList * list, const gchar * tag, static void date_v1_convert (const GstTagList * list, const gchar * tag, - guint8 * dst, int maxlen) + guint8 * dst, int maxlen, gboolean * wrote_tag) { GDate *date; @@ -1102,6 +1103,7 @@ date_v1_convert (const GstTagList * list, const gchar * tag, if (year > 500 && year < 2100) { gchar str[5]; g_snprintf (str, 5, "%.4u", year); + *wrote_tag = TRUE; memcpy (dst, str, 4); } else { GST_WARNING ("invalid year %u, skipping", year); @@ -1113,14 +1115,14 @@ date_v1_convert (const GstTagList * list, const gchar * tag, static void genre_v1_convert (const GstTagList * list, const gchar * tag, - guint8 * dst, int maxlen) + guint8 * dst, int maxlen, gboolean * wrote_tag) { gchar *str; int genreidx = -1; guint i, max; /* We only support one genre */ - if (!gst_tag_list_get_string_index (list, tag, 0, &str)) + if (!gst_tag_list_get_string_index (list, tag, 0, &str) || str == NULL) return; max = gst_tag_id3_genre_count (); @@ -1133,15 +1135,17 @@ genre_v1_convert (const GstTagList * list, const gchar * tag, } } - if (genreidx >= 0 && genreidx <= 127) + if (genreidx >= 0 && genreidx <= 127) { *dst = (guint8) genreidx; + *wrote_tag = TRUE; + } g_free (str); } static void track_number_convert (const GstTagList * list, const gchar * tag, - guint8 * dst, int maxlen) + guint8 * dst, int maxlen, gboolean * wrote_tag) { guint tracknum; @@ -1149,8 +1153,10 @@ track_number_convert (const GstTagList * list, const gchar * tag, if (!gst_tag_list_get_uint_index (list, tag, 0, &tracknum)) return; - if (tracknum <= 127) + if (tracknum <= 127) { *dst = (guint8) tracknum; + *wrote_tag = TRUE; + } } static const struct @@ -1172,10 +1178,11 @@ static const struct }; GstBuffer * -gst_id3mux_render_v1_tag (GstTagMux * mux, GstTagList * taglist) +id3_mux_render_v1_tag (GstTagMux * mux, GstTagList * taglist) { GstBuffer *buf = gst_buffer_new_and_alloc (ID3_V1_TAG_SIZE); guint8 *data = GST_BUFFER_DATA (buf); + gboolean wrote_tag = FALSE; int i; memset (data, 0, ID3_V1_TAG_SIZE); @@ -1184,9 +1191,18 @@ gst_id3mux_render_v1_tag (GstTagMux * mux, GstTagList * taglist) data[1] = 'A'; data[2] = 'G'; + /* Genre #0 stands for 'Blues', so init genre field to an invalid number */ + data[127] = 255; + for (i = 0; i < G_N_ELEMENTS (v1_funcs); i++) { v1_funcs[i].func (taglist, v1_funcs[i].gst_tag, data + v1_funcs[i].offset, - v1_funcs[i].length); + v1_funcs[i].length, &wrote_tag); + } + + if (!wrote_tag) { + GST_WARNING_OBJECT (mux, "no ID3v1 tag written (no suitable tags found)"); + gst_buffer_unref (buf); + return NULL; } gst_buffer_set_caps (buf, GST_PAD_CAPS (mux->srcpad)); diff --git a/gst/id3tag/id3tag.h b/gst/id3tag/id3tag.h index 1fb59376..d5504969 100644 --- a/gst/id3tag/id3tag.h +++ b/gst/id3tag/id3tag.h @@ -24,9 +24,9 @@ G_BEGIN_DECLS #define ID3_VERSION_2_3 3 #define ID3_VERSION_2_4 4 -GstBuffer * gst_id3mux_render_v2_tag (GstTagMux * mux, GstTagList * taglist, +GstBuffer * id3_mux_render_v2_tag (GstTagMux * mux, GstTagList * taglist, int version); -GstBuffer * gst_id3mux_render_v1_tag (GstTagMux * mux, GstTagList * taglist); +GstBuffer * id3_mux_render_v1_tag (GstTagMux * mux, GstTagList * taglist); G_END_DECLS |