2006-02-06 10:56:07 +00:00
|
|
|
/* GStreamer APEv1/2 tag reader
|
|
|
|
* Copyright (C) 2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
|
|
|
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-apedemux
|
|
|
|
* @short_description: reads tag information from APE tag data blocks and
|
|
|
|
* outputs them as GStreamer tag messages and events.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <para>
|
|
|
|
* apedemux accepts data streams with APE tags at the start or at the end
|
|
|
|
* (or both). The mime type of the data between the tag blocks is detected
|
|
|
|
* using typefind functions, and the appropriate output mime type set on
|
|
|
|
* outgoing buffers.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* The element is only able to read APE tags at the end of a stream from
|
|
|
|
* a seekable stream, ie. when get_range mode is supported by the upstream
|
|
|
|
* elements. If get_range operation is available, apedemux makes it available
|
|
|
|
* downstream. This means that elements which require get_range mode, such as
|
|
|
|
* wavparse or musepackdec, can operate on files containing APE tag
|
|
|
|
* information.
|
|
|
|
* </para>
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* <para>
|
|
|
|
* <programlisting>
|
|
|
|
* gst-launch -t filesrc location=file.mpc ! apedemux ! fakesink
|
|
|
|
* </programlisting>
|
|
|
|
* This pipeline should read any available APE tag information and output it.
|
|
|
|
* The contents of the file inside the APE tag regions should be detected, and
|
|
|
|
* the appropriate mime type set on buffers produced from apedemux.
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/gst-i18n-plugin.h>
|
|
|
|
|
|
|
|
#include "gstapedemux.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define APE_VERSION_MAJOR(ver) ((ver)/1000)
|
|
|
|
|
2006-05-28 14:38:11 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (apedemux_debug);
|
2006-02-06 10:56:07 +00:00
|
|
|
#define GST_CAT_DEFAULT (apedemux_debug)
|
|
|
|
|
Define GstElementDetails as const and also static (when defined as global)
Original commit message from CVS:
* ext/aalib/gstaasink.c:
* ext/annodex/gstcmmldec.c:
* ext/annodex/gstcmmlenc.c:
* ext/cairo/gsttextoverlay.c:
* ext/cairo/gsttimeoverlay.c:
* ext/cdio/gstcdiocddasrc.c:
* ext/dv/gstdvdec.c:
* ext/dv/gstdvdemux.c:
* ext/esd/esdmon.c:
* ext/esd/esdsink.c:
* ext/flac/gstflacenc.c:
* ext/flac/gstflactag.c:
* ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_base_init):
* ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init):
* ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init):
* ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init):
* ext/gdk_pixbuf/pixbufscale.c:
* ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init):
* ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init):
* ext/jpeg/gstjpegdec.c:
* ext/jpeg/gstjpegenc.c:
* ext/jpeg/gstsmokedec.c:
* ext/jpeg/gstsmokeenc.c:
* ext/libcaca/gstcacasink.c:
* ext/libmng/gstmngdec.c:
* ext/libmng/gstmngenc.c:
* ext/libpng/gstpngdec.c:
* ext/libpng/gstpngenc.c:
* ext/mikmod/gstmikmod.c:
* ext/raw1394/gstdv1394src.c:
* ext/shout2/gstshout2.c: (gst_shout2send_init):
* ext/shout2/gstshout2.h:
* ext/speex/gstspeexdec.c:
* ext/speex/gstspeexenc.c:
* gst/alpha/gstalpha.c:
* gst/alpha/gstalphacolor.c:
* gst/apetag/gstapedemux.c:
* gst/auparse/gstauparse.c:
* gst/autodetect/gstautoaudiosink.c:
(gst_auto_audio_sink_base_init):
* gst/autodetect/gstautovideosink.c:
(gst_auto_video_sink_base_init):
* gst/avi/gstavidemux.c: (gst_avi_demux_base_init):
* gst/avi/gstavimux.c: (gst_avimux_base_init):
* gst/cutter/gstcutter.c:
* gst/debug/breakmydata.c:
* gst/debug/efence.c:
* gst/debug/gstnavigationtest.c:
* gst/debug/gstnavseek.c:
* gst/debug/negotiation.c:
* gst/debug/progressreport.c:
* gst/debug/testplugin.c:
* gst/effectv/gstaging.c:
* gst/effectv/gstdice.c:
* gst/effectv/gstedge.c:
* gst/effectv/gstquark.c:
* gst/effectv/gstrev.c:
* gst/effectv/gstshagadelic.c:
* gst/effectv/gstvertigo.c:
* gst/effectv/gstwarp.c:
* gst/flx/gstflxdec.c:
* gst/goom/gstgoom.c:
* gst/icydemux/gsticydemux.c:
* gst/id3demux/gstid3demux.c:
* gst/interleave/deinterleave.c:
* gst/interleave/interleave.c:
* gst/law/alaw-decode.c: (gst_alawdec_base_init):
* gst/law/alaw-encode.c: (gst_alawenc_base_init):
* gst/law/mulaw-decode.c: (gst_mulawdec_base_init):
* gst/law/mulaw-encode.c: (gst_mulawenc_base_init):
* gst/level/gstlevel.c:
* gst/matroska/matroska-demux.c: (gst_matroska_demux_base_init):
* gst/matroska/matroska-mux.c: (gst_matroska_mux_base_init):
* gst/median/gstmedian.c:
* gst/monoscope/gstmonoscope.c:
* gst/multipart/multipartdemux.c:
* gst/multipart/multipartmux.c:
* gst/oldcore/gstaggregator.c:
* gst/oldcore/gstfdsink.c:
* gst/oldcore/gstmd5sink.c:
* gst/oldcore/gstmultifilesrc.c:
* gst/oldcore/gstpipefilter.c:
* gst/oldcore/gstshaper.c:
* gst/oldcore/gststatistics.c:
* gst/rtp/gstasteriskh263.c:
* gst/rtp/gstrtpL16depay.c:
* gst/rtp/gstrtpL16pay.c:
* gst/rtp/gstrtpamrdepay.c:
* gst/rtp/gstrtpamrpay.c:
* gst/rtp/gstrtpdepay.c:
* gst/rtp/gstrtpgsmpay.c:
* gst/rtp/gstrtph263pay.c:
* gst/rtp/gstrtph263pdepay.c:
* gst/rtp/gstrtph263ppay.c:
* gst/rtp/gstrtpilbcdepay.c:
* gst/rtp/gstrtpmp4gpay.c:
* gst/rtp/gstrtpmp4vdepay.c:
* gst/rtp/gstrtpmp4vpay.c:
* gst/rtp/gstrtpmpadepay.c:
* gst/rtp/gstrtpmpapay.c:
* gst/rtp/gstrtppcmadepay.c:
* gst/rtp/gstrtppcmapay.c:
* gst/rtp/gstrtppcmudepay.c:
* gst/rtp/gstrtppcmupay.c:
* gst/rtp/gstrtpspeexdepay.c:
* gst/rtp/gstrtpspeexpay.c:
* gst/rtsp/gstrtpdec.c:
* gst/rtsp/gstrtspsrc.c:
* gst/smpte/gstsmpte.c:
* gst/udp/gstdynudpsink.c:
* gst/udp/gstmultiudpsink.c:
* gst/udp/gstudpsink.c:
* gst/udp/gstudpsrc.c:
* gst/videobox/gstvideobox.c:
* gst/videofilter/gstgamma.c: (gst_gamma_base_init):
* gst/videofilter/gstvideobalance.c:
* gst/videofilter/gstvideoflip.c:
* gst/videofilter/gstvideotemplate.c:
(gst_videotemplate_base_init):
* gst/videomixer/videomixer.c:
* gst/wavparse/gstwavparse.c: (gst_wavparse_base_init),
(gst_wavparse_class_init), (gst_wavparse_dispose),
(gst_wavparse_reset), (gst_wavparse_init),
(gst_wavparse_perform_seek), (gst_wavparse_peek_chunk_info),
(gst_wavparse_peek_chunk), (gst_wavparse_stream_headers),
(gst_wavparse_parse_stream_init), (gst_wavparse_send_event),
(gst_wavparse_add_src_pad), (gst_wavparse_stream_data),
(gst_wavparse_chain), (gst_wavparse_srcpad_event),
(gst_wavparse_sink_activate), (gst_wavparse_sink_activate_pull),
(gst_wavparse_change_state):
* gst/wavparse/gstwavparse.h:
* sys/oss/gstossmixerelement.c:
* sys/oss/gstosssink.c:
* sys/oss/gstosssrc.c:
* sys/osxaudio/gstosxaudioelement.c:
* sys/osxaudio/gstosxaudiosink.c:
* sys/osxaudio/gstosxaudiosrc.c:
* sys/sunaudio/gstsunaudiomixer.c:
* sys/sunaudio/gstsunaudiosink.c:
Define GstElementDetails as const and also static (when defined as
global)
2006-04-25 21:39:46 +00:00
|
|
|
static const GstElementDetails gst_ape_demux_details =
|
2006-02-06 10:56:07 +00:00
|
|
|
GST_ELEMENT_DETAILS ("APE tag demuxer",
|
|
|
|
"Codec/Demuxer/Metadata",
|
|
|
|
"Read and output APE tags while demuxing the contents",
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>, "
|
|
|
|
"Tim-Philipp Müller <tim centricular net>");
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-apetag")
|
|
|
|
);
|
|
|
|
|
|
|
|
static gboolean gst_ape_demux_identify_tag (GstTagDemux * demux,
|
|
|
|
GstBuffer * buffer, gboolean start_tag, guint * tag_size);
|
|
|
|
static GstTagDemuxResult gst_ape_demux_parse_tag (GstTagDemux * demux,
|
|
|
|
GstBuffer * buffer, gboolean start_tag, guint * tag_size,
|
|
|
|
GstTagList ** tags);
|
|
|
|
|
2006-05-06 00:14:09 +00:00
|
|
|
GST_BOILERPLATE (GstApeDemux, gst_ape_demux, GstTagDemux, GST_TYPE_TAG_DEMUX);
|
2006-02-06 10:56:07 +00:00
|
|
|
|
2006-05-06 00:14:09 +00:00
|
|
|
static void
|
|
|
|
gst_ape_demux_base_init (gpointer klass)
|
2006-02-06 10:56:07 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sink_factory));
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_ape_demux_details);
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (apedemux_debug, "apedemux", 0,
|
|
|
|
"GStreamer APE tag demuxer");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ape_demux_class_init (GstApeDemuxClass * klass)
|
|
|
|
{
|
|
|
|
GstTagDemuxClass *tagdemux_class;
|
|
|
|
|
|
|
|
tagdemux_class = GST_TAG_DEMUX_CLASS (klass);
|
|
|
|
|
|
|
|
tagdemux_class->identify_tag = GST_DEBUG_FUNCPTR (gst_ape_demux_identify_tag);
|
|
|
|
tagdemux_class->parse_tag = GST_DEBUG_FUNCPTR (gst_ape_demux_parse_tag);
|
2007-10-06 15:13:09 +00:00
|
|
|
|
|
|
|
/* no need for a merge function, the default behaviour to prefer start
|
|
|
|
* tags (APEv2) over end tags (usually APEv1, but could theoretically also
|
|
|
|
* be APEv2) is fine */
|
|
|
|
|
|
|
|
tagdemux_class->min_start_size = 32;
|
|
|
|
tagdemux_class->min_end_size = 32;
|
2006-02-06 10:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ape_demux_init (GstApeDemux * apedemux, GstApeDemuxClass * gclass)
|
|
|
|
{
|
2007-10-06 15:13:09 +00:00
|
|
|
/* nothing to do here */
|
2006-02-06 10:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct _GstApeDemuxTagTableEntry
|
|
|
|
{
|
|
|
|
const gchar *ape_tag;
|
|
|
|
const gchar *gst_tag;
|
|
|
|
} tag_table[] = {
|
|
|
|
{
|
|
|
|
"replaygain_track_gain", GST_TAG_TRACK_GAIN}, {
|
|
|
|
"replaygain_track_peak", GST_TAG_TRACK_PEAK}, {
|
|
|
|
"replaygain_album_gain", GST_TAG_ALBUM_GAIN}, {
|
|
|
|
"replaygain_album_peak", GST_TAG_ALBUM_PEAK}, {
|
|
|
|
"title", GST_TAG_TITLE}, {
|
|
|
|
"artist", GST_TAG_ARTIST}, {
|
|
|
|
"album", GST_TAG_ALBUM}, {
|
2007-09-25 19:09:33 +00:00
|
|
|
"composer", GST_TAG_COMPOSER}, {
|
2006-02-06 10:56:07 +00:00
|
|
|
"comment", GST_TAG_COMMENT}, {
|
|
|
|
"comments", GST_TAG_COMMENT}, {
|
|
|
|
"copyright", GST_TAG_COPYRIGHT}, {
|
|
|
|
"genre", GST_TAG_GENRE}, {
|
|
|
|
"isrc", GST_TAG_ISRC}, {
|
2006-10-04 10:24:49 +00:00
|
|
|
"disc", GST_TAG_ALBUM_VOLUME_NUMBER}, {
|
|
|
|
"disk", GST_TAG_ALBUM_VOLUME_NUMBER}, {
|
|
|
|
"discnumber", GST_TAG_ALBUM_VOLUME_NUMBER}, {
|
|
|
|
"disknumber", GST_TAG_ALBUM_VOLUME_NUMBER}, {
|
2006-02-06 10:56:07 +00:00
|
|
|
"track", GST_TAG_TRACK_NUMBER}, {
|
2006-10-04 10:24:49 +00:00
|
|
|
"tracknumber", GST_TAG_TRACK_NUMBER}, {
|
2006-05-28 14:38:11 +00:00
|
|
|
"year", GST_TAG_DATE}, {
|
|
|
|
"file", GST_TAG_LOCATION}
|
2006-02-06 10:56:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
ape_demux_get_gst_tag_from_tag (const gchar * ape_tag,
|
|
|
|
const gchar ** gst_tag, GType * gst_tag_type)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (tag_table); ++i) {
|
|
|
|
if (g_ascii_strcasecmp (tag_table[i].ape_tag, ape_tag) == 0) {
|
|
|
|
*gst_tag = tag_table[i].gst_tag;
|
|
|
|
*gst_tag_type = gst_tag_get_type (tag_table[i].gst_tag);
|
2006-05-28 14:38:11 +00:00
|
|
|
GST_LOG ("Mapped APE tag '%s' to GStreamer tag '%s'", ape_tag, *gst_tag);
|
2006-02-06 10:56:07 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_WARNING ("Could not map APE tag '%s' to a GStreamer tag", ape_tag);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstTagList *
|
|
|
|
ape_demux_parse_tags (const guint8 * data, gint size)
|
|
|
|
{
|
|
|
|
GstTagList *taglist = gst_tag_list_new ();
|
|
|
|
gboolean have_tag = FALSE;
|
|
|
|
|
|
|
|
GST_LOG ("Reading tags from chunk of size %u bytes", size);
|
|
|
|
|
|
|
|
/* get rid of header/footer */
|
|
|
|
if (size >= 32 && memcmp (data, "APETAGEX", 8) == 0) {
|
|
|
|
data += 32;
|
|
|
|
size -= 32;
|
|
|
|
}
|
|
|
|
if (size > 32 && memcmp (data + size - 32, "APETAGEX", 8) == 0) {
|
|
|
|
size -= 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read actual tags - at least 10 bytes for tag header */
|
|
|
|
while (size >= 10) {
|
|
|
|
guint len, n = 8;
|
|
|
|
gchar *tag, *val;
|
|
|
|
const gchar *gst_tag;
|
|
|
|
GType gst_tag_type;
|
|
|
|
|
|
|
|
/* find tag type and size */
|
|
|
|
len = GST_READ_UINT32_LE (data);
|
|
|
|
while (n < size && data[n] != 0x0)
|
|
|
|
n++;
|
|
|
|
if (n == size)
|
|
|
|
break;
|
|
|
|
g_assert (data[n] == 0x0);
|
|
|
|
n++;
|
|
|
|
if (size - n < len)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* read */
|
|
|
|
tag = g_strndup ((gchar *) data + 8, n - 9);
|
|
|
|
val = g_strndup ((gchar *) data + n, len);
|
|
|
|
|
2006-10-04 10:24:49 +00:00
|
|
|
/* special-case 'media' tag, could be e.g. "CD 1/2" */
|
|
|
|
if (g_ascii_strcasecmp (tag, "media") == 0) {
|
|
|
|
gchar *sp, *sp2;
|
|
|
|
|
|
|
|
g_free (tag);
|
|
|
|
tag = g_strdup ("discnumber");
|
|
|
|
/* get rid of the medium in front */
|
|
|
|
sp = strchr (val, ' ');
|
|
|
|
while (sp != NULL && (sp2 = strchr (sp + 1, ' ')) != NULL)
|
|
|
|
sp = sp2;
|
|
|
|
if (sp) {
|
|
|
|
g_memmove (val, sp + 1, strlen (sp + 1) + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-06 10:56:07 +00:00
|
|
|
if (ape_demux_get_gst_tag_from_tag (tag, &gst_tag, &gst_tag_type)) {
|
|
|
|
GValue v = { 0, };
|
|
|
|
|
|
|
|
switch (gst_tag_type) {
|
2006-05-28 14:38:11 +00:00
|
|
|
case G_TYPE_INT:{
|
|
|
|
gint v_int;
|
|
|
|
|
|
|
|
if (sscanf (val, "%d", &v_int) == 1) {
|
|
|
|
g_value_init (&v, G_TYPE_INT);
|
|
|
|
g_value_set_int (&v, v_int);
|
|
|
|
}
|
2006-02-06 10:56:07 +00:00
|
|
|
break;
|
2006-05-28 14:38:11 +00:00
|
|
|
}
|
|
|
|
case G_TYPE_UINT:{
|
|
|
|
guint v_uint, count;
|
|
|
|
|
|
|
|
if (strcmp (gst_tag, GST_TAG_TRACK_NUMBER) == 0) {
|
|
|
|
gint dummy;
|
|
|
|
|
|
|
|
if (sscanf (val, "%u", &v_uint) == 1 && v_uint > 0) {
|
|
|
|
g_value_init (&v, G_TYPE_UINT);
|
|
|
|
g_value_set_uint (&v, v_uint);
|
|
|
|
}
|
2006-10-04 10:24:49 +00:00
|
|
|
GST_LOG ("checking for track count: %s", val);
|
2006-05-28 14:38:11 +00:00
|
|
|
/* might be 0/N or -1/N to specify that there is only a count */
|
|
|
|
if (sscanf (val, "%d/%u", &dummy, &count) == 2 && count > 0) {
|
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND,
|
|
|
|
GST_TAG_TRACK_COUNT, count, NULL);
|
|
|
|
}
|
2006-10-04 10:24:49 +00:00
|
|
|
} else if (strcmp (gst_tag, GST_TAG_ALBUM_VOLUME_NUMBER) == 0) {
|
|
|
|
gint dummy;
|
|
|
|
|
|
|
|
if (sscanf (val, "%u", &v_uint) == 1 && v_uint > 0) {
|
|
|
|
g_value_init (&v, G_TYPE_UINT);
|
|
|
|
g_value_set_uint (&v, v_uint);
|
|
|
|
}
|
|
|
|
GST_LOG ("checking for volume count: %s", val);
|
|
|
|
/* might be 0/N or -1/N to specify that there is only a count */
|
|
|
|
if (sscanf (val, "%d/%u", &dummy, &count) == 2 && count > 0) {
|
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND,
|
|
|
|
GST_TAG_ALBUM_VOLUME_COUNT, count, NULL);
|
|
|
|
}
|
2006-05-28 14:38:11 +00:00
|
|
|
} else if (sscanf (val, "%u", &v_uint) == 1) {
|
|
|
|
g_value_init (&v, G_TYPE_UINT);
|
|
|
|
g_value_set_uint (&v, v_uint);
|
|
|
|
}
|
2006-02-06 10:56:07 +00:00
|
|
|
break;
|
2006-05-28 14:38:11 +00:00
|
|
|
}
|
|
|
|
case G_TYPE_STRING:{
|
2006-02-06 10:56:07 +00:00
|
|
|
g_value_init (&v, G_TYPE_STRING);
|
|
|
|
g_value_set_string (&v, val);
|
|
|
|
break;
|
2006-05-28 14:38:11 +00:00
|
|
|
}
|
|
|
|
case G_TYPE_DOUBLE:{
|
|
|
|
gdouble v_double;
|
2006-12-06 13:16:59 +00:00
|
|
|
gchar *endptr;
|
2006-05-28 14:38:11 +00:00
|
|
|
|
2006-12-09 19:27:28 +00:00
|
|
|
/* floating point strings can be "4,123" or "4.123" depending on
|
|
|
|
* the locale. We need to be able to parse and read either version
|
|
|
|
* no matter what our current locale is */
|
|
|
|
g_strdelimit (val, ",", '.');
|
|
|
|
v_double = g_ascii_strtod (val, &endptr);
|
2006-12-06 13:16:59 +00:00
|
|
|
if (endptr != val) {
|
2006-05-28 14:38:11 +00:00
|
|
|
g_value_init (&v, G_TYPE_DOUBLE);
|
|
|
|
g_value_set_double (&v, v_double);
|
|
|
|
}
|
2006-12-06 13:16:59 +00:00
|
|
|
|
2006-02-06 10:56:07 +00:00
|
|
|
break;
|
2006-05-28 14:38:11 +00:00
|
|
|
}
|
2006-02-06 10:56:07 +00:00
|
|
|
default:{
|
|
|
|
if (gst_tag_type == GST_TYPE_DATE) {
|
2006-05-28 14:38:11 +00:00
|
|
|
gint v_int;
|
|
|
|
|
|
|
|
if (sscanf (val, "%d", &v_int) == 1) {
|
|
|
|
GDate *date = g_date_new_dmy (1, 1, v_int);
|
2006-02-06 10:56:07 +00:00
|
|
|
|
2006-05-28 14:38:11 +00:00
|
|
|
g_value_init (&v, GST_TYPE_DATE);
|
|
|
|
gst_value_set_date (&v, date);
|
|
|
|
g_date_free (date);
|
|
|
|
}
|
2006-02-06 10:56:07 +00:00
|
|
|
} else {
|
|
|
|
GST_WARNING ("Unhandled tag type '%s' for tag '%s'",
|
|
|
|
g_type_name (gst_tag_type), gst_tag);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (G_VALUE_TYPE (&v) != 0) {
|
|
|
|
gst_tag_list_add_values (taglist, GST_TAG_MERGE_APPEND,
|
|
|
|
gst_tag, &v, NULL);
|
|
|
|
g_value_unset (&v);
|
|
|
|
have_tag = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GST_DEBUG ("Read tag %s: %s", tag, val);
|
|
|
|
g_free (tag);
|
|
|
|
g_free (val);
|
|
|
|
|
|
|
|
/* move data pointer */
|
|
|
|
size -= len + n;
|
|
|
|
data += len + n;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("Taglist: %" GST_PTR_FORMAT, taglist);
|
|
|
|
return taglist;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_ape_demux_identify_tag (GstTagDemux * demux, GstBuffer * buffer,
|
|
|
|
gboolean start_tag, guint * tag_size)
|
|
|
|
{
|
|
|
|
if (memcmp (GST_BUFFER_DATA (buffer), "APETAGEX", 8) != 0) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "No APETAGEX marker at %s - not an APE file",
|
|
|
|
(start_tag) ? "start" : "end");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*tag_size = GST_READ_UINT32_LE (GST_BUFFER_DATA (buffer) + 12);
|
|
|
|
|
|
|
|
/* size is without header, so add 32 to account for that */
|
|
|
|
*tag_size += 32;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstTagDemuxResult
|
|
|
|
gst_ape_demux_parse_tag (GstTagDemux * demux, GstBuffer * buffer,
|
|
|
|
gboolean start_tag, guint * tag_size, GstTagList ** tags)
|
|
|
|
{
|
|
|
|
const guint8 *data;
|
|
|
|
const guint8 *footer;
|
|
|
|
gboolean have_header;
|
|
|
|
gboolean end_tag = !start_tag;
|
|
|
|
guint version, footer_size;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (demux, "Parsing buffer of size %u", GST_BUFFER_SIZE (buffer));
|
|
|
|
|
|
|
|
data = GST_BUFFER_DATA (buffer);
|
|
|
|
footer = GST_BUFFER_DATA (buffer) + GST_BUFFER_SIZE (buffer) - 32;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (demux, "Checking for footer at offset 0x%04x",
|
|
|
|
(guint) (footer - data));
|
|
|
|
if (footer > data && memcmp (footer, "APETAGEX", 8) == 0) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Found footer");
|
|
|
|
footer_size = 32;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (demux, "No footer");
|
|
|
|
footer_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* APE tags at the end must have a footer */
|
|
|
|
if (end_tag && footer_size == 0) {
|
|
|
|
GST_WARNING_OBJECT (demux, "Tag at end of file without footer!");
|
|
|
|
return GST_TAG_DEMUX_RESULT_BROKEN_TAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't trust the header/footer flags, better detect them ourselves */
|
|
|
|
have_header = (memcmp (data, "APETAGEX", 8) == 0);
|
|
|
|
|
|
|
|
if (start_tag && !have_header) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Tag at beginning of file without header!");
|
|
|
|
return GST_TAG_DEMUX_RESULT_BROKEN_TAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end_tag && !have_header) {
|
|
|
|
GST_DEBUG_OBJECT (demux, "Tag at end of file has no header (APEv1)");
|
|
|
|
*tag_size -= 32; /* adjust tag size */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_header) {
|
|
|
|
version = GST_READ_UINT32_LE (data + 8);
|
|
|
|
} else {
|
|
|
|
version = GST_READ_UINT32_LE (footer + 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip header */
|
|
|
|
if (have_header) {
|
|
|
|
data += 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (demux, "APE tag with version %u, size %u at offset 0x%08"
|
|
|
|
G_GINT64_MODIFIER "x", version, *tag_size,
|
|
|
|
GST_BUFFER_OFFSET (buffer) + ((have_header) ? 0 : 32));
|
|
|
|
|
|
|
|
if (APE_VERSION_MAJOR (version) != 1 && APE_VERSION_MAJOR (version) != 2) {
|
|
|
|
GST_WARNING ("APE tag is version %u.%03u, but decoder only supports "
|
|
|
|
"v1 or v2. Ignoring.", APE_VERSION_MAJOR (version), version % 1000);
|
|
|
|
return GST_TAG_DEMUX_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*tags = ape_demux_parse_tags (data, *tag_size - footer_size);
|
|
|
|
|
|
|
|
return GST_TAG_DEMUX_RESULT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
return gst_element_register (plugin, "apedemux",
|
|
|
|
GST_RANK_PRIMARY, GST_TYPE_APE_DEMUX);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"apetag",
|
|
|
|
"APEv1/2 tag reader",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|