summaryrefslogtreecommitdiffstats
path: root/ext/speex/gstspeexenc.c
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.net>2005-10-13 18:59:35 +0000
committerTim-Philipp Müller <tim@centricular.net>2005-10-13 18:59:35 +0000
commitfb495736bc531080df1a7874d7ef3b94679d25a9 (patch)
tree313627553a53ffcf2a1674a59068b70f3f33be0a /ext/speex/gstspeexenc.c
parent1eb3b76e8b5dd365502e4ecf3d373e23c3c11aff (diff)
ext/speex/gstspeexenc.c: Fix handling of GST_TAG_DATE, which is now of GST_TYPE_DATE; use GST_READ_UINT32_LE() and fr...
Original commit message from CVS: * ext/speex/gstspeexenc.c: (gst_speexenc_get_tag_value), (comment_init), (comment_add): Fix handling of GST_TAG_DATE, which is now of GST_TYPE_DATE; use GST_READ_UINT32_LE() and friends rather than the private implementation of those same macros.
Diffstat (limited to 'ext/speex/gstspeexenc.c')
-rw-r--r--ext/speex/gstspeexenc.c68
1 files changed, 31 insertions, 37 deletions
diff --git a/ext/speex/gstspeexenc.c b/ext/speex/gstspeexenc.c
index fe3afe64..8825c742 100644
--- a/ext/speex/gstspeexenc.c
+++ b/ext/speex/gstspeexenc.c
@@ -514,15 +514,20 @@ gst_speexenc_init (GstSpeexEnc * speexenc)
}
+/* FIXME: why are we not using the from/to vorbiscomment
+ * functions that are in -lgsttagedit-0.9 here? */
+
static gchar *
gst_speexenc_get_tag_value (const GstTagList * list, const gchar * tag,
int index)
{
+ GType tag_type;
gchar *speexvalue = NULL;
- if (tag == NULL) {
+ if (tag == NULL)
return NULL;
- }
+
+ tag_type = gst_tag_get_type (tag);
/* get tag name right */
if ((strcmp (tag, GST_TAG_TRACK_NUMBER) == 0)
@@ -531,24 +536,26 @@ gst_speexenc_get_tag_value (const GstTagList * list, const gchar * tag,
|| (strcmp (tag, GST_TAG_ALBUM_VOLUME_COUNT) == 0)) {
guint track_no;
- if (!gst_tag_list_get_uint_index (list, tag, index, &track_no))
- g_assert_not_reached ();
- speexvalue = g_strdup_printf ("%u", track_no);
- } else if (strcmp (tag, GST_TAG_DATE) == 0) {
+ if (gst_tag_list_get_uint_index (list, tag, index, &track_no)) {
+ speexvalue = g_strdup_printf ("%u", track_no);
+ } else {
+ GST_WARNING ("Failed to extract int tag %d for '%s'", index, tag);
+ }
+ } else if (tag_type == GST_TYPE_DATE) {
/* FIXME: how are dates represented in speex files? */
GDate *date;
- guint u;
-
- if (!gst_tag_list_get_uint_index (list, tag, index, &u))
- g_assert_not_reached ();
- date = g_date_new_julian (u);
- speexvalue =
- g_strdup_printf ("%04d-%02d-%02d", (gint) g_date_get_year (date),
- (gint) g_date_get_month (date), (gint) g_date_get_day (date));
- g_date_free (date);
- } else if (gst_tag_get_type (tag) == G_TYPE_STRING) {
+
+ if (gst_tag_list_get_date_index (list, tag, index, &date)) {
+ speexvalue =
+ g_strdup_printf ("%04d-%02d-%02d", (gint) g_date_get_year (date),
+ (gint) g_date_get_month (date), (gint) g_date_get_day (date));
+ g_date_free (date);
+ } else {
+ GST_WARNING ("Failed to extract date tag %d for '%s'", index, tag);
+ }
+ } else if (tag_type == G_TYPE_STRING) {
if (!gst_tag_list_get_string_index (list, tag, index, &speexvalue))
- g_assert_not_reached ();
+ GST_WARNING ("Failed to extract string tag %d for '%s'", index, tag);
}
return speexvalue;
@@ -573,16 +580,6 @@ gst_speexenc_get_tag_value (const GstTagList * list, const gchar * tag,
*
* If you have troubles, please write to ymnk@jcraft.com.
*/
-#define readint(buf, base) (((buf[base+3]<<24) & 0xff000000)| \
- ((buf[base+2]<<16) & 0xff0000)| \
- ((buf[base+1]<< 8) & 0xff00)| \
- (buf[base ] & 0xff))
-#define writeint(buf, base, val) do{ buf[base+3] = ((val)>>24) & 0xff; \
- buf[base+2] = ((val)>>16) & 0xff; \
- buf[base+1] = ((val)>> 8) & 0xff; \
- buf[base ] = (val) & 0xff; \
- }while(0)
-
static void
comment_init (guint8 ** comments, int *length, char *vendor_string)
{
@@ -591,9 +588,9 @@ comment_init (guint8 ** comments, int *length, char *vendor_string)
int len = 4 + vendor_length + 4;
guint8 *p = g_malloc (len);
- writeint (p, 0, vendor_length);
- memcpy (p + 4, (guint8 *) vendor_string, vendor_length);
- writeint (p, 4 + vendor_length, user_comment_list_length);
+ GST_WRITE_UINT32_LE (p, vendor_length);
+ memcpy (p + 4, vendor_string, vendor_length);
+ GST_WRITE_UINT32_LE (p + 4 + vendor_length, user_comment_list_length);
*length = len;
*comments = p;
}
@@ -601,27 +598,24 @@ static void
comment_add (guint8 ** comments, int *length, const char *tag, char *val)
{
guint8 *p = *comments;
- int vendor_length = readint (p, 0);
- int user_comment_list_length = readint (p, 4 + vendor_length);
+ int vendor_length = GST_READ_UINT32_LE (p);
+ int user_comment_list_length = GST_READ_UINT32_LE (p + 4 + vendor_length);
int tag_len = (tag ? strlen (tag) : 0);
int val_len = strlen (val);
int len = (*length) + 4 + tag_len + val_len;
p = g_realloc (p, len);
- writeint (p, *length, tag_len + val_len); /* length of comment */
+ GST_WRITE_UINT32_LE (p + *length, tag_len + val_len); /* length of comment */
if (tag)
memcpy (p + *length + 4, (guint8 *) tag, tag_len); /* comment */
memcpy (p + *length + 4 + tag_len, val, val_len); /* comment */
- writeint (p, 4 + vendor_length, user_comment_list_length + 1);
+ GST_WRITE_UINT32_LE (p + 4 + vendor_length, user_comment_list_length + 1);
*comments = p;
*length = len;
}
-#undef readint
-#undef writeint
-
static void
gst_speexenc_metadata_set1 (const GstTagList * list, const gchar * tag,
gpointer speexenc)