mad: build the mad plugin even if libid3tag is not available

ID3 tags are usually handled by id3demux, and should be handled
by id3demux. Tag handling in mad based on libid3tag is very basic
and mostly unnecessary really, so just build this plugin without
ID3 tag support if libid3tag is not available.
This commit is contained in:
Tim-Philipp Müller 2011-03-11 17:45:37 +00:00
parent 253afc02c9
commit 65565c8a1e
3 changed files with 60 additions and 46 deletions

View file

@ -326,20 +326,23 @@ AG_GST_CHECK_FEATURE(MAD, [mad mp3 decoder], mad, [
])
fi
dnl check with pkg-config first
AG_GST_PKG_CHECK_MODULES(MAD, mad >= 0.15)
MAD_LIBS="$MAD_LIBS $ID3TAG_LIBS"
if test "x$HAVE_MAD" = "xno"; then
dnl fall back to oldskool detection
AC_CHECK_HEADER(mad.h, [
AC_CHECK_LIB(mad, mad_decoder_finish,
HAVE_MAD="yes" MAD_LIBS="-lmad $ID3TAG_LIBS")
])
fi
if test "x$HAVE_ID3TAG" = "xyes"; then
dnl check with pkg-config first
AG_GST_PKG_CHECK_MODULES(MAD, mad >= 0.15)
MAD_LIBS="$MAD_LIBS $ID3TAG_LIBS"
if test "x$HAVE_MAD" = "xno"; then
dnl fall back to oldskool detection
AC_CHECK_HEADER(mad.h, [
AC_CHECK_LIB(mad, mad_decoder_finish,
HAVE_MAD="yes" MAD_LIBS="-lmad $ID3TAG_LIBS")
])
fi
AC_DEFINE(HAVE_ID3TAG, 1, [defined if libid3tag is available])
else
HAVE_MAD="no"
AC_MSG_WARN([libid3tag not available, cannot build MAD MP3 decoder plugin])
AC_MSG_WARN([libid3tag not available, MAD MP3 decoder will be built without
ID3 tag reading support (which is not a problem, since ID3
tags are usually handled by id3demux)])
fi
])
AC_SUBST(MAD_LIBS)

View file

@ -40,6 +40,10 @@
#include "gstmad.h"
#include <gst/audio/audio.h>
#ifdef HAVE_ID3TAG
#include <id3tag.h>
#endif
enum
{
ARG_0,
@ -103,7 +107,9 @@ static GstStateChangeReturn gst_mad_change_state (GstElement * element,
static void gst_mad_set_index (GstElement * element, GstIndex * index);
static GstIndex *gst_mad_get_index (GstElement * element);
#ifdef HAVE_ID3TAG
static GstTagList *gst_mad_id3_to_tag_list (const struct id3_tag *tag);
#endif
GST_BOILERPLATE (GstMad, gst_mad, GstElement, GST_TYPE_ELEMENT);
@ -1514,50 +1520,54 @@ gst_mad_chain (GstPad * pad, GstBuffer * buffer)
goto end;
} else if (mad->stream.error == MAD_ERROR_LOSTSYNC) {
/* lost sync, force a resync */
signed long tagsize;
GST_INFO ("recoverable lost sync error");
tagsize = id3_tag_query (mad->stream.this_frame,
mad->stream.bufend - mad->stream.this_frame);
#ifdef HAVE_ID3TAG
{
signed long tagsize;
if (tagsize > mad->tempsize) {
GST_INFO ("mad: got partial id3 tag in buffer, skipping");
} else if (tagsize > 0) {
struct id3_tag *tag;
id3_byte_t const *data;
tagsize = id3_tag_query (mad->stream.this_frame,
mad->stream.bufend - mad->stream.this_frame);
GST_INFO ("mad: got ID3 tag size %ld", tagsize);
if (tagsize > mad->tempsize) {
GST_INFO ("mad: got partial id3 tag in buffer, skipping");
} else if (tagsize > 0) {
struct id3_tag *tag;
id3_byte_t const *data;
data = mad->stream.this_frame;
GST_INFO ("mad: got ID3 tag size %ld", tagsize);
/* mad has moved the pointer to the next frame over the start of the
* id3 tags, so we need to flush one byte less than the tagsize */
mad_stream_skip (&mad->stream, tagsize - 1);
data = mad->stream.this_frame;
tag = id3_tag_parse (data, tagsize);
if (tag) {
GstTagList *list;
/* mad has moved the pointer to the next frame over the start of the
* id3 tags, so we need to flush one byte less than the tagsize */
mad_stream_skip (&mad->stream, tagsize - 1);
list = gst_mad_id3_to_tag_list (tag);
id3_tag_delete (tag);
GST_DEBUG ("found tag");
gst_element_post_message (GST_ELEMENT (mad),
gst_message_new_tag (GST_OBJECT (mad),
gst_tag_list_copy (list)));
if (mad->tags) {
gst_tag_list_insert (mad->tags, list, GST_TAG_MERGE_PREPEND);
} else {
mad->tags = gst_tag_list_copy (list);
tag = id3_tag_parse (data, tagsize);
if (tag) {
GstTagList *list;
list = gst_mad_id3_to_tag_list (tag);
id3_tag_delete (tag);
GST_DEBUG ("found tag");
gst_element_post_message (GST_ELEMENT (mad),
gst_message_new_tag (GST_OBJECT (mad),
gst_tag_list_copy (list)));
if (mad->tags) {
gst_tag_list_insert (mad->tags, list, GST_TAG_MERGE_PREPEND);
} else {
mad->tags = gst_tag_list_copy (list);
}
if (mad->need_newsegment)
mad->pending_events =
g_list_append (mad->pending_events,
gst_event_new_tag (list));
else
gst_pad_push_event (mad->srcpad, gst_event_new_tag (list));
}
if (mad->need_newsegment)
mad->pending_events =
g_list_append (mad->pending_events,
gst_event_new_tag (list));
else
gst_pad_push_event (mad->srcpad, gst_event_new_tag (list));
}
}
#endif /* HAVE_ID3TAG */
}
mad_frame_mute (&mad->frame);
@ -1902,6 +1912,7 @@ gst_mad_change_state (GstElement * element, GstStateChange transition)
return ret;
}
#ifdef HAVE_ID3TAG
/* id3 tag helper (FIXME: why does mad parse id3 tags at all? It shouldn't) */
static GstTagList *
gst_mad_id3_to_tag_list (const struct id3_tag *tag)
@ -2075,6 +2086,7 @@ gst_mad_id3_to_tag_list (const struct id3_tag *tag)
return tag_list;
}
#endif /* HAVE_ID3TAG */
/* plugin initialisation */

View file

@ -24,7 +24,6 @@
#include <gst/gst.h>
#include <gst/tag/tag.h>
#include <mad.h>
#include <id3tag.h>
G_BEGIN_DECLS