this should more or less work correctly.

Original commit message from CVS:
this should more or less work correctly.
This commit is contained in:
Thomas Vander Stichele 2004-03-07 20:51:10 +00:00
parent 3abd8a559e
commit a9cf545d20
8 changed files with 194 additions and 251 deletions

View file

@ -1,3 +1,20 @@
2004-03-07 Thomas Vander Stichele <thomas at apestaart dot org>
* gst-libs/Makefile.am:
* gst-libs/gst/media-info/Makefile.am:
* gst-libs/gst/media-info/media-info-priv.c: (found_tag_callback),
(error_callback), (gst_media_info_error_create),
(gst_media_info_error_element), (gmip_init), (gmip_reset),
(gmi_clear_decoder), (gmip_find_type_pre), (gmip_find_type):
* gst-libs/gst/media-info/media-info-priv.h:
* gst-libs/gst/media-info/media-info-test.c: (main):
* gst-libs/gst/media-info/media-info.c: (gst_media_info_init),
(gst_media_info_class_init), (gst_media_info_instance_init),
(gst_media_info_set_source), (gst_media_info_read_with_idler),
(gst_media_info_read_idler), (gst_media_info_read):
* gst-libs/gst/media-info/media-info.h:
fixed, should work now
2004-03-07 Christian Schaller <Uraeus@gnome.org> 2004-03-07 Christian Schaller <Uraeus@gnome.org>
* ext/nas/nassink.c: * ext/nas/nassink.c:

View file

@ -1,3 +1,3 @@
SUBDIRS = gst ext SUBDIRS = gst ext
DIST_SUBDIRS= gst ext DIST_SUBDIRS = gst ext

View file

@ -2,12 +2,12 @@ lib_LTLIBRARIES = libgstmedia-info-@GST_MAJORMINOR@.la
libgstmedia_info_@GST_MAJORMINOR@_la_SOURCES = media-info.c media-info-priv.c libgstmedia_info_@GST_MAJORMINOR@_la_SOURCES = media-info.c media-info-priv.c
libincludedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/media-info
libinclude_HEADERS = media-info.h
libgstmedia_info_@GST_MAJORMINOR@_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGIN_CFLAGS) libgstmedia_info_@GST_MAJORMINOR@_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGIN_CFLAGS)
libgstmedia_info_@GST_MAJORMINOR@_la_LIBADD = $(GST_LIBS) $(GST_PLUGIN_LIBS) libgstmedia_info_@GST_MAJORMINOR@_la_LIBADD = $(GST_LIBS) $(GST_PLUGIN_LIBS)
libincludedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/media-info
libinclude_HEADERS = media-info.h
noinst_PROGRAMS = media-info-test noinst_PROGRAMS = media-info-test
noinst_HEADERS = media-info-priv.h noinst_HEADERS = media-info-priv.h

View file

@ -171,8 +171,7 @@ found_tag_callback (GObject *pipeline, GstElement *source, GstTagList *tags, Gst
score.meta = 0; score.meta = 0;
score.encoded = 0; score.encoded = 0;
g_print ("FOUND TAG : found by element \"%s\".\n", GST_DEBUG ("element %s found tag", GST_STR_NULL (GST_ELEMENT_NAME (source)));
GST_STR_NULL (GST_ELEMENT_NAME (source)));
/* decide if it's likely to be metadata or streaminfo */ /* decide if it's likely to be metadata or streaminfo */
/* FIXME: this is a hack, there must be a better way, /* FIXME: this is a hack, there must be a better way,
@ -193,46 +192,111 @@ found_tag_callback (GObject *pipeline, GstElement *source, GstTagList *tags, Gst
} }
void void
error_callback (GObject *element, GstElement *source, GError *error, gchar *debug) error_callback (GObject *element, GstElement *source, GError *error, gchar *debug, GstMediaInfoPriv *priv)
{ {
g_print ("ERROR: %s\n", error->message); g_print ("ERROR: %s\n", error->message);
g_error_free (error);
} }
/* helpers */ /* helpers */
/* reset info to a state where it can be used to query for media info /* General GError creation */
* clear caps, metadata, and so on */ static void
void gst_media_info_error_create (GError **error, const gchar *message)
gmi_reset (GstMediaInfo *info)
{ {
GstMediaInfoPriv *priv = info->priv; /* check if caller wanted an error reported */
/* clear out some stuff */ if (error == NULL)
if (priv->format) return;
{
GMI_DEBUG ("unreffing priv->format, error before this ?\n"); *error = g_error_new (GST_MEDIA_INFO_ERROR, 0, message);
gst_caps_free (priv->format); return;
priv->format = NULL; }
}
if (priv->metadata) /* GError creation when element is missing */
{ static void
GMI_DEBUG ("unreffing priv->metadata, error before this ?\n"); gst_media_info_error_element (const gchar *element, GError **error)
gst_tag_list_free (priv->metadata); {
priv->metadata = NULL; gchar *message;
}
message = g_strdup_printf ("The %s element could not be found. "
"This element is essential for reading. "
"Please install the right plug-in and verify "
"that it works by running 'gst-inspect %s'",
element, element);
gst_media_info_error_create (error, message);
g_free (message);
return;
}
/* initialise priv; done the first time */
void
gmip_init (GstMediaInfoPriv *priv, GError **error)
{
#define GST_MEDIA_INFO_MAKE_OR_ERROR(el, factory, name, error) \
G_STMT_START { \
el = gst_element_factory_make (factory, name); \
if (!GST_IS_ELEMENT (el)) \
{ \
gst_media_info_error_element (factory, error); \
return; \
} \
} G_STMT_END
/* create the typefind element and make sure it stays around by reffing */
GST_MEDIA_INFO_MAKE_OR_ERROR (priv->typefind, "typefind", "typefind", error);
gst_object_ref (GST_OBJECT (priv->typefind));
/* create the fakesink element and make sure it stays around by reffing */
GST_MEDIA_INFO_MAKE_OR_ERROR (priv->fakesink, "fakesink", "fakesink", error);
gst_object_ref (GST_OBJECT (priv->fakesink));
/* source element for media info reading */
priv->source = NULL;
priv->source_name = NULL;
}
/* called at the beginning of each use cycle */
/* reset info to a state where it can be used to query for media info */
void
gmip_reset (GstMediaInfoPriv *priv)
{
#define STRING_RESET(string) \
G_STMT_START { \
if (string) g_free (string); \
string = NULL; \
} G_STMT_END
STRING_RESET(priv->pipeline_desc);
STRING_RESET(priv->location);
#undef STRING_RESET
#define CAPS_RESET(target) \
G_STMT_START { \
if (target) gst_caps_free (target); \
target = NULL; \
} G_STMT_END
CAPS_RESET(priv->type);
CAPS_RESET(priv->format);
#undef CAPS_RESET
#define TAGS_RESET(target) \
G_STMT_START { \
if (target) \
gst_tag_list_free (target); \
target = NULL; \
} G_STMT_END
TAGS_RESET(priv->metadata);
TAGS_RESET(priv->streaminfo);
#undef TAGS_RESET
if (priv->stream) if (priv->stream)
{ {
GMI_DEBUG ("freeing priv->stream, error before this ?\n"); gmi_stream_free (priv->stream);
g_free (priv->stream);
priv->stream = NULL; priv->stream = NULL;
} }
if (priv->location)
{
GMI_DEBUG ("freeing priv->location, error before this ?\n");
g_free (priv->location);
priv->location = NULL;
}
priv->flags = 0; priv->flags = 0;
priv->state = GST_MEDIA_INFO_STATE_NULL; priv->state = GST_MEDIA_INFO_STATE_NULL;
priv->error = NULL;
} }
/* seek to a track and reset metadata and streaminfo structs */ /* seek to a track and reset metadata and streaminfo structs */
@ -278,101 +342,6 @@ gmi_seek_to_track (GstMediaInfo *info, long track)
return TRUE; return TRUE;
} }
#ifdef REMOVEME
/* create a good decoder for this mime type */
/* FIXME: maybe make this more generic with a type, so it can be used
* for taggers and other things as well */
/* FIXME: deprecated, we work with pipelines now */
GstElement *
gmi_get_decoder (GstMediaInfo *info, const char *mime)
{
GstElement *decoder;
gchar *factory = NULL;
/* check if we have an active codec element in the hash table for this */
decoder = g_hash_table_lookup (info->priv->decoders, mime);
if (decoder == NULL)
{
GST_DEBUG ("no decoder in table, inserting one");
/* FIXME: please figure out proper mp3 mimetypes */
if ((strcmp (mime, "application/x-ogg") == 0) ||
(strcmp (mime, "application/ogg") == 0))
factory = g_strdup ("vorbisfile");
else if ((strcmp (mime, "audio/mpeg") == 0) ||
(strcmp (mime, "audio/x-mp3") == 0) ||
(strcmp (mime, "audio/mp3") == 0) ||
(strcmp (mime, "application/x-id3") == 0) ||
(strcmp (mime, "audio/x-id3") == 0))
factory = g_strdup ("mad");
else if (strcmp (mime, "application/x-flac") == 0)
factory = g_strdup ("flacdec");
else if (strcmp (mime, "audio/x-wav") == 0)
factory = g_strdup ("wavparse");
else if (strcmp (mime, "audio/x-mod") == 0 ||
strcmp (mime, "audio/x-s3m") == 0 ||
strcmp (mime, "audio/x-xm") == 0 ||
strcmp (mime, "audio/x-it") == 0)
factory = g_strdup ("modplug");
if (factory == NULL)
return NULL;
GST_DEBUG ("using factory %s", factory);
decoder = gst_element_factory_make (factory, "decoder");
g_free (factory);
if (decoder)
{
g_hash_table_insert (info->priv->decoders, g_strdup (mime), decoder);
/* ref it so we don't lose it when removing from bin */
g_object_ref (GST_OBJECT (decoder));
}
}
return decoder;
}
/* set the decoder to be used for decoding
* install callback handlers
*/
void
gmi_set_decoder (GstMediaInfo *info, GstElement *decoder)
{
GstMediaInfoPriv *priv = info->priv;
/* set up pipeline and connect signal handlers */
priv->decoder = decoder;
gst_bin_add (GST_BIN (priv->pipeline), decoder);
gst_bin_add (GST_BIN (priv->pipeline), priv->fakesink);
if (!gst_element_link (priv->source, decoder))
g_warning ("Couldn't connect source and decoder\n");
if (!gst_element_link (priv->decoder, priv->fakesink))
g_warning ("Couldn't connect decoder and fakesink\n");
/* FIXME: we should be connecting to ALL possible src pads */
if (!(priv->decoder_pad = gst_element_get_pad (decoder, "src")))
g_warning ("Couldn't get decoder pad\n");
if (!(priv->source_pad = gst_element_get_pad (priv->source, "src")))
g_warning ("Couldn't get source pad\n");
}
/* clear the decoder (if it was set)
*/
void
gmi_clear_decoder (GstMediaInfo *info)
{
if (info->priv->decoder)
{
/* clear up decoder */
/* FIXME: shouldn't need to set state here */
gst_element_set_state (info->priv->pipeline, GST_STATE_READY);
gst_element_unlink (info->priv->source, info->priv->decoder);
gst_element_unlink (info->priv->decoder, info->priv->fakesink);
gst_bin_remove (GST_BIN (info->priv->pipeline), info->priv->decoder);
gst_bin_remove (GST_BIN (info->priv->pipeline), info->priv->fakesink);
info->priv->decoder = NULL;
}
}
#endif
/* set the mime type on the media info getter */ /* set the mime type on the media info getter */
gboolean gboolean
gmi_set_mime (GstMediaInfo *info, const char *mime) gmi_set_mime (GstMediaInfo *info, const char *mime)
@ -437,6 +406,17 @@ gmi_set_mime (GstMediaInfo *info, const char *mime)
return TRUE; return TRUE;
} }
/* clear the decoding pipeline */
void
gmi_clear_decoder (GstMediaInfo *info)
{
if (info->priv->pipeline)
{
GST_DEBUG("Unreffing pipeline");
gst_object_unref (GST_OBJECT (info->priv->pipeline));
}
info->priv->pipeline = NULL;
}
/**** /****
* typefind functions * typefind functions
@ -446,25 +426,26 @@ gmi_set_mime (GstMediaInfo *info, const char *mime)
/* prepare for typefind, move from NULL to TYPEFIND */ /* prepare for typefind, move from NULL to TYPEFIND */
gboolean gboolean
gmip_find_type_pre (GstMediaInfoPriv *priv) gmip_find_type_pre (GstMediaInfoPriv *priv, GError **error)
{ {
/* clear vars that need clearing */ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (priv->type)
{
gst_caps_free (priv->type);
priv->type = NULL;
}
g_assert (priv);
g_assert (priv->source);
GST_DEBUG ("gmip_find_type_pre: start"); GST_DEBUG ("gmip_find_type_pre: start");
/* find out type */ /* find out type */
/* FIXME: we could move caps for typefind out of struct and /* FIXME: we could move caps for typefind out of struct and
* just use it through this function only */ * just use it through this function only */
priv->pipeline = gst_pipeline_new ("pipeline-typefind");
if (!GST_IS_PIPELINE (priv->pipeline))
{
gst_media_info_error_create (error, "Internal GStreamer error.");
return FALSE;
}
gst_bin_add (GST_BIN (priv->pipeline), priv->typefind); gst_bin_add (GST_BIN (priv->pipeline), priv->typefind);
GST_MEDIA_INFO_MAKE_OR_ERROR (priv->source, priv->source_name, "source",
error);
g_object_set (G_OBJECT (priv->source), "location", priv->location, NULL); g_object_set (G_OBJECT (priv->source), "location", priv->location, NULL);
gst_bin_add (GST_BIN (priv->pipeline), priv->source);
if (!gst_element_link (priv->source, priv->typefind)) if (!gst_element_link (priv->source, priv->typefind))
g_warning ("Couldn't connect source and typefind\n"); g_warning ("Couldn't connect source and typefind\n");
g_signal_connect (G_OBJECT (priv->typefind), "have-type", g_signal_connect (G_OBJECT (priv->typefind), "have-type",
@ -510,9 +491,9 @@ gmip_find_type_post (GstMediaInfoPriv *priv)
/* complete version */ /* complete version */
gboolean gboolean
gmip_find_type (GstMediaInfoPriv *priv) gmip_find_type (GstMediaInfoPriv *priv, GError ** error)
{ {
if (!gmip_find_type_pre (priv)) if (!gmip_find_type_pre (priv, error))
return FALSE; return FALSE;
GST_DEBUG ("gmip_find_type: iterating"); GST_DEBUG ("gmip_find_type: iterating");
while ((priv->type == NULL) && while ((priv->type == NULL) &&

View file

@ -28,7 +28,7 @@
GST_DEBUG_CATEGORY_EXTERN (gst_media_info_debug); GST_DEBUG_CATEGORY_EXTERN (gst_media_info_debug);
#define GST_CAT_DEFAULT gst_media_info_debug #define GST_CAT_DEFAULT gst_media_info_debug
#define DEBUG //#define DEBUG
#ifdef DEBUG #ifdef DEBUG
static gboolean _gmi_debug = TRUE; static gboolean _gmi_debug = TRUE;
#else #else
@ -115,11 +115,11 @@ void deep_notify_callback (GObject *object,
GParamSpec *pspec, GParamSpec *pspec,
GstMediaInfoPriv *priv); GstMediaInfoPriv *priv);
void found_tag_callback (GObject *pipeline, GstElement *source, GstTagList *tags, GstMediaInfoPriv *priv); void found_tag_callback (GObject *pipeline, GstElement *source, GstTagList *tags, GstMediaInfoPriv *priv);
void error_callback (GObject *element, GstElement *source, GError *error, gchar *debug); void error_callback (GObject *element, GstElement *source, GError *error, gchar *debug, GstMediaInfoPriv *priv);
gboolean gmip_find_type_pre (GstMediaInfoPriv *priv); gboolean gmip_find_type_pre (GstMediaInfoPriv *priv, GError **error);
gboolean gmip_find_type_post (GstMediaInfoPriv *priv); gboolean gmip_find_type_post (GstMediaInfoPriv *priv);
gboolean gmip_find_type (GstMediaInfoPriv *priv); gboolean gmip_find_type (GstMediaInfoPriv *priv, GError **error);
gboolean gmip_find_stream_pre (GstMediaInfoPriv *priv); gboolean gmip_find_stream_pre (GstMediaInfoPriv *priv);
gboolean gmip_find_stream_post (GstMediaInfoPriv *priv); gboolean gmip_find_stream_post (GstMediaInfoPriv *priv);
gboolean gmip_find_stream (GstMediaInfoPriv *priv); gboolean gmip_find_stream (GstMediaInfoPriv *priv);

View file

@ -88,9 +88,11 @@ main (int argc, char *argv[])
} }
g_assert (G_IS_OBJECT (info)); g_assert (G_IS_OBJECT (info));
if (!gst_media_info_set_source (info, "gnomevfssrc")) if (!gst_media_info_set_source (info, "gnomevfssrc", &error))
{ {
g_print ("Could not set gnomevfssrc as a source\n"); g_print ("Could not set gnomevfssrc as a source\n");
g_print ("reason: %s\n", error->message);
g_error_free (error);
return -1; return -1;
} }
@ -101,11 +103,16 @@ main (int argc, char *argv[])
/* /*
stream = gst_media_info_read (info, argv[i], GST_MEDIA_INFO_ALL); stream = gst_media_info_read (info, argv[i], GST_MEDIA_INFO_ALL);
*/ */
gst_media_info_read_with_idler (info, argv[i], GST_MEDIA_INFO_ALL); gst_media_info_read_with_idler (info, argv[i], GST_MEDIA_INFO_ALL, &error);
while (gst_media_info_read_idler (info, &stream) && stream == NULL) while (gst_media_info_read_idler (info, &stream, &error) && stream == NULL)
/* keep idling */ g_print ("+"); /* keep idling */ g_print ("+");
g_print ("\nFILE: %s\n", argv[i]); g_print ("\nFILE: %s\n", argv[i]);
g_print ("stream: %p, &stream: %p\n", stream, &stream); g_print ("stream: %p, &stream: %p\n", stream, &stream);
if (error)
{
g_print ("Error reading media info: %s\n", error->message);
g_error_free (error);
}
if (stream) if (stream)
info_print (stream); info_print (stream);
else else

View file

@ -25,6 +25,7 @@
#include <string.h> #include <string.h>
#include "media-info.h" #include "media-info.h"
#include "media-info-priv.h" #include "media-info-priv.h"
#include "media-info-marshal.h"
static void gst_media_info_class_init (GstMediaInfoClass *klass); static void gst_media_info_class_init (GstMediaInfoClass *klass);
static void gst_media_info_instance_init (GstMediaInfo *info); static void gst_media_info_instance_init (GstMediaInfo *info);
@ -34,6 +35,8 @@ static void gst_media_info_get_property (GObject *object, guint prop_id,
GParamSpec *pspec); GParamSpec *pspec);
static gboolean _media_info_inited = FALSE;
/* FIXME: this is a lousy hack that needs to go */ /* FIXME: this is a lousy hack that needs to go */
#define MAX_METADATA_ITERS 5 #define MAX_METADATA_ITERS 5
@ -58,7 +61,7 @@ enum
}; };
/* GError quark stuff */ /* GError quark stuff */
static GQuark GQuark
gst_media_info_error_quark (void) gst_media_info_error_quark (void)
{ {
static GQuark quark = 0; static GQuark quark = 0;
@ -67,52 +70,6 @@ gst_media_info_error_quark (void)
return quark; return quark;
} }
/* General GError creation */
static void
gst_media_info_error_create (GError **error, const gchar *message)
{
/* check if caller wanted an error reported */
if (error == NULL)
return;
*error = g_error_new (GST_MEDIA_INFO_ERROR, 0, message);
return;
}
/* GError creation when element is missing */
static void
gst_media_info_error_element (const gchar *element, GError **error)
{
gchar *message;
message = g_strdup_printf ("The %s element could not be found. "
"This element is essential for reading. "
"Please install the right plug-in and verify "
"that it works by running 'gst-inspect %s'",
element, element);
gst_media_info_error_create (error, message);
g_free (message);
return;
}
/* used from the instance_init function to report errors */
#define GST_MEDIA_INFO_MAKE_OR_ERROR(el, factory, name, error) \
G_STMT_START { \
el = gst_element_factory_make (factory, name); \
if (!GST_IS_ELEMENT (el)) \
{ \
gst_media_info_error_element (factory, error); \
return; \
} \
} G_STMT_END
#define GST_MEDIA_INFO_ERROR_RETURN(error, message) \
G_STMT_START { \
gst_media_info_error_create (error, message); \
return FALSE; \
} G_STMT_END
/* /*
* GObject type stuff * GObject type stuff
*/ */
@ -130,10 +87,13 @@ GST_DEBUG_CATEGORY (gst_media_info_debug);
void void
gst_media_info_init (void) gst_media_info_init (void)
{ {
if (_media_info_inited) return;
/* register our debugging category */ /* register our debugging category */
GST_DEBUG_CATEGORY_INIT (gst_media_info_debug, "GST_MEDIA_INFO", 0, GST_DEBUG_CATEGORY_INIT (gst_media_info_debug, "GST_MEDIA_INFO", 0,
"GStreamer media-info library"); "GStreamer media-info library");
GST_DEBUG ("Initialized media-info library"); GST_DEBUG ("Initialized media-info library");
_media_info_inited = TRUE;
} }
GType GType
@ -184,10 +144,10 @@ gst_media_info_class_init (GstMediaInfoClass *klass)
gst_media_info_signals [MEDIA_INFO_SIGNAL] = gst_media_info_signals [MEDIA_INFO_SIGNAL] =
g_signal_new ("media-info", g_signal_new ("media-info",
G_TYPE_FROM_CLASS (klass), G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstMediaInfoClass, media_info_signal), G_STRUCT_OFFSET (GstMediaInfoClass, media_info_signal),
NULL, NULL, NULL, NULL,
gst_marshal_VOID__VOID, gst_media_info_marshal_VOID__VOID,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
} }
@ -199,30 +159,10 @@ gst_media_info_instance_init (GstMediaInfo *info)
info->priv = g_new0 (GstMediaInfoPriv, 1); info->priv = g_new0 (GstMediaInfoPriv, 1);
error = &info->priv->error; error = &info->priv->error;
info->priv->pipeline = gst_pipeline_new ("media-info"); if (!_media_info_inited) { gst_media_info_init (); }
/* create the typefind element and make sure it stays around by reffing */ gmip_init (info->priv);
GST_MEDIA_INFO_MAKE_OR_ERROR (info->priv->typefind, "typefind", "typefind", error); gmip_reset (info->priv);
gst_object_ref (GST_OBJECT (info->priv->typefind));
/* create the fakesink element and make sure it stays around by reffing */
GST_MEDIA_INFO_MAKE_OR_ERROR (info->priv->fakesink, "fakesink", "fakesink", error);
gst_object_ref (GST_OBJECT (info->priv->fakesink));
/* source element for media info reading */
info->priv->source = NULL;
info->priv->source_name = NULL;
info->priv->location = NULL;
info->priv->type = NULL;
info->priv->format = NULL;
info->priv->metadata = NULL;
info->priv->pipeline_desc = NULL;
/* clear result pointers */
info->priv->stream = NULL;
info->priv->error = NULL;
} }
/* get/set */ /* get/set */
@ -269,28 +209,9 @@ gst_media_info_new (GError **error)
* public methods * public methods
*/ */
gboolean gboolean
gst_media_info_set_source (GstMediaInfo *info, const char *source) gst_media_info_set_source (GstMediaInfo *info, const char *source, GError **error)
{ {
GstElement *src;
src = gst_element_factory_make (source, "new-source");
if (!GST_IS_ELEMENT (src))
return FALSE;
if (info->priv->source)
{
/* this also unrefs the element */
gst_bin_remove (GST_BIN (info->priv->pipeline), info->priv->source);
if (info->priv->source_name)
{
g_free (info->priv->source_name);
info->priv->source_name = NULL;
}
}
g_object_set (G_OBJECT (src), "name", "source", NULL);
gst_bin_add (GST_BIN (info->priv->pipeline), src);
info->priv->source = src;
info->priv->source_name = g_strdup (source); info->priv->source_name = g_strdup (source);
return TRUE; return TRUE;
} }
@ -302,11 +223,11 @@ gst_media_info_set_source (GstMediaInfo *info, const char *source)
*/ */
void void
gst_media_info_read_with_idler (GstMediaInfo *info, const char *location, gst_media_info_read_with_idler (GstMediaInfo *info, const char *location,
guint16 flags) guint16 flags, GError **error)
{ {
GstMediaInfoPriv *priv = info->priv; GstMediaInfoPriv *priv = info->priv;
gmi_reset (info); /* reset all structs */ gmip_reset (info->priv); /* reset all structs */
priv->location = g_strdup (location); priv->location = g_strdup (location);
priv->flags = flags; priv->flags = flags;
} }
@ -316,11 +237,13 @@ gst_media_info_read_with_idler (GstMediaInfo *info, const char *location,
* returns: TRUE if it was able to idle, FALSE if there was an error * returns: TRUE if it was able to idle, FALSE if there was an error
*/ */
gboolean gboolean
gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp) gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp, GError **error)
{ {
GstMediaInfoPriv *priv; GstMediaInfoPriv *priv;
/* if it's NULL then we're sure something went wrong higher up) */ /* if it's NULL then we're sure something went wrong higher up) */
if (info == NULL) return FALSE; if (info == NULL) return FALSE;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
priv = info->priv; priv = info->priv;
@ -330,9 +253,17 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp)
switch (priv->state) switch (priv->state)
{ {
case GST_MEDIA_INFO_STATE_NULL: case GST_MEDIA_INFO_STATE_NULL:
/* make sure we have a source */
if (!priv->source_name)
{
*error = g_error_new (GST_MEDIA_INFO_ERROR, 0,
"No source set on media info.");
return FALSE;
}
/* need to find type */ /* need to find type */
GST_DEBUG ("idler: NULL, need to find type, priv %p", priv); GST_DEBUG ("idler: NULL, need to find type, priv %p", priv);
return gmip_find_type_pre (priv); return gmip_find_type_pre (priv, error);
case GST_MEDIA_INFO_STATE_TYPEFIND: case GST_MEDIA_INFO_STATE_TYPEFIND:
{ {
@ -469,9 +400,10 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp)
return TRUE; return TRUE;
} }
priv->state = GST_MEDIA_INFO_STATE_DONE; priv->state = GST_MEDIA_INFO_STATE_DONE;
gmi_clear_decoder (info);
GST_DEBUG ("TOTALLY DONE, setting pointer *streamp to %p", *streamp);
*streamp = priv->stream; *streamp = priv->stream;
priv->stream = NULL; priv->stream = NULL;
GST_DEBUG ("TOTALLY DONE, setting pointer *streamp to %p", *streamp);
return TRUE; return TRUE;
} }
case GST_MEDIA_INFO_STATE_DONE: case GST_MEDIA_INFO_STATE_DONE:
@ -486,7 +418,7 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp)
* read all possible info from the file pointed to by location * read all possible info from the file pointed to by location
* use flags to limit the type of information searched for */ * use flags to limit the type of information searched for */
GstMediaInfoStream * GstMediaInfoStream *
gst_media_info_read (GstMediaInfo *info, const char *location, guint16 flags) gst_media_info_read (GstMediaInfo *info, const char *location, guint16 flags, GError **error)
{ {
GstMediaInfoPriv *priv = info->priv; GstMediaInfoPriv *priv = info->priv;
GstMediaInfoStream *stream = NULL; GstMediaInfoStream *stream = NULL;
@ -495,11 +427,11 @@ gst_media_info_read (GstMediaInfo *info, const char *location, guint16 flags)
int i; int i;
GST_DEBUG ("DEBUG: gst_media_info_read: start"); GST_DEBUG ("DEBUG: gst_media_info_read: start");
gmi_reset (info); /* reset all structs */ gmip_reset (info->priv); /* reset all structs */
priv->location = g_strdup (location); priv->location = g_strdup (location);
priv->flags = flags; priv->flags = flags;
if (!gmip_find_type (priv)) return NULL; if (!gmip_find_type (priv, error)) return NULL;
mime = g_strdup (gst_structure_get_name ( mime = g_strdup (gst_structure_get_name (
gst_caps_get_structure(priv->type, 0))); gst_caps_get_structure(priv->type, 0)));

View file

@ -44,6 +44,7 @@ struct _GstMediaInfoClass
/* signals */ /* signals */
void (*media_info_signal) (GstMediaInfo *gst_media_info); void (*media_info_signal) (GstMediaInfo *gst_media_info);
void (*error_signal) (GstMediaInfo *gst_media_info, GError *error, const gchar *debug);
gpointer _gst_reserved[GST_PADDING]; gpointer _gst_reserved[GST_PADDING];
}; };
@ -104,16 +105,21 @@ GType gst_media_info_get_type (void);
GstMediaInfo * gst_media_info_new (GError **error); GstMediaInfo * gst_media_info_new (GError **error);
gboolean gst_media_info_set_source (GstMediaInfo *info, const char *source); gboolean gst_media_info_set_source (GstMediaInfo *info,
const char *source,
GError **error);
void gst_media_info_read_with_idler (GstMediaInfo *media_info, void gst_media_info_read_with_idler (GstMediaInfo *media_info,
const char *location, const char *location,
guint16 GST_MEDIA_INFO_FLAGS); guint16 GST_MEDIA_INFO_FLAGS,
GError **error);
gboolean gst_media_info_read_idler (GstMediaInfo *media_info, gboolean gst_media_info_read_idler (GstMediaInfo *media_info,
GstMediaInfoStream **streamp); GstMediaInfoStream **streamp,
GError **error);
GstMediaInfoStream * GstMediaInfoStream *
gst_media_info_read (GstMediaInfo *media_info, gst_media_info_read (GstMediaInfo *media_info,
const char *location, const char *location,
guint16 GST_MEDIA_INFO_FLAGS); guint16 GST_MEDIA_INFO_FLAGS,
GError **error);
gboolean gst_media_info_read_many (GstMediaInfo *media_info, gboolean gst_media_info_read_many (GstMediaInfo *media_info,
GList *locations, GList *locations,
guint16 GST_MEDIA_INFO_FLAGS, guint16 GST_MEDIA_INFO_FLAGS,