first pass at making this work again needs quite a lot of cleanups

Original commit message from CVS:
first pass at making this work again
needs quite a lot of cleanups
This commit is contained in:
Thomas Vander Stichele 2004-03-06 20:15:17 +00:00
parent fe6bf805dc
commit a11cf2ec0a
6 changed files with 361 additions and 105 deletions

View file

@ -1,3 +1,23 @@
2004-03-06 Thomas Vander Stichele <thomas at apestaart dot org>
* gst-libs/gst/media-info/media-info-priv.c: (have_type_callback),
(deep_notify_callback), (tag_flag_score), (found_tag_callback),
(error_callback), (gmi_reset), (gmi_seek_to_track),
(gmi_get_decoder), (gmi_set_mime), (gmip_find_type_pre),
(gmip_find_type_post), (gmip_find_stream_post),
(gmip_find_track_streaminfo_post):
* gst-libs/gst/media-info/media-info-priv.h:
* gst-libs/gst/media-info/media-info-test.c: (print_tag),
(info_print), (main):
* gst-libs/gst/media-info/media-info.c:
(gst_media_info_error_create), (gst_media_info_error_element),
(gst_media_info_instance_init), (gst_media_info_get_property),
(gst_media_info_new), (gst_media_info_set_source),
(gst_media_info_read_idler), (gst_media_info_read):
* gst-libs/gst/media-info/media-info.h:
first pass at making this work again. This seems to work on
tagged ogg/vorbis and mp3 files.
2004-03-06 Benjamin Otte <otte@gnome.org>
* ext/mad/gstid3tag.c: (gst_id3_tag_chain):

View file

@ -80,9 +80,36 @@ gmi_track_new (void)
static void
have_type_callback (GstElement *typefind, guint probability, GstCaps *type, GstMediaInfoPriv *priv)
{
g_print ("DEBUG: have_type: caps %p\n", type);
GstStructure *str;
const gchar *mime;
priv->type = gst_caps_copy (type);
/* FIXME: make sure we _free these somewhere */
str = gst_caps_get_structure (type, 0);
mime = gst_structure_get_name (str);
GST_DEBUG ("caps %p, mime %s", type, mime);
/* FIXME: this code doesn't yet work, test it later */
#ifdef DONTWORK
if (strcmp (mime, "application/x-id3") == 0)
{
/* dig a little deeper */
GST_DEBUG ("dealing with id3, digging deeper");
gst_element_set_state (priv->pipeline, GST_STATE_READY);
gst_element_unlink (priv->source, priv->typefind);
g_assert (priv->decontainer == NULL);
priv->decontainer = gst_element_factory_make ("id3tag", "decontainer");
gst_bin_add (GST_BIN (priv->pipeline), priv->decontainer);
if (priv->decontainer == NULL)
/* FIXME: signal error */
g_warning ("Couldn't create id3tag");
if (!gst_element_link_many (priv->source, priv->decontainer, priv->typefind, NULL));
g_warning ("Couldn't link in id3tag");
if (gst_element_set_state (priv->pipeline, GST_STATE_PLAYING)
== GST_STATE_FAILURE)
g_warning ("Couldn't set to playing");
}
#endif
}
void
@ -94,26 +121,21 @@ deep_notify_callback (GObject *object, GstObject *origin,
/* we only care about pad notifies */
if (!GST_IS_PAD (origin)) return;
/*
GST_DEBUG ("DEBUG: deep_notify: have notify of %s from object %s:%s !",
pspec->name, gst_element_get_name (gst_pad_get_parent (GST_PAD (origin))),
gst_object_get_name (origin));
if (strcmp (pspec->name, "metadata") == 0)
{
GST_DEBUG ("DEBUG: deep_notify: have metadata !");
g_value_init (&value, pspec->value_type);
g_object_get_property (G_OBJECT (origin), pspec->name, &value);
priv->metadata = g_value_peek_pointer (&value);
}
*/
else if (strcmp (pspec->name, "caps") == 0)
{
/* check if we're getting it from the source we want it from */
if (GST_IS_PAD (origin) && GST_PAD (origin) == priv->decoder_pad)
/* check if we're getting it from fakesink */
if (GST_IS_PAD (origin) && GST_PAD_PARENT (origin) == priv->fakesink)
{
GST_DEBUG ("DEBUG: deep_notify: have caps on decoder_pad !");
GST_DEBUG ("have caps on fakesink pad !");
g_value_init (&value, pspec->value_type);
g_object_get_property (G_OBJECT (origin), pspec->name, &value);
priv->format = g_value_peek_pointer (&value);
GST_DEBUG ("caps: %" GST_PTR_FORMAT, priv->format);
}
else GST_DEBUG ("ignoring caps on object %s:%s",
gst_object_get_name (gst_object_get_parent (origin)),
@ -123,14 +145,57 @@ deep_notify_callback (GObject *object, GstObject *origin,
{
/* we REALLY ignore offsets, we hate them */
}
else if (strcmp (pspec->name, "streaminfo") == 0)
//else GST_DEBUG ("ignoring notify of %s", pspec->name);
}
typedef struct {
guint meta;
guint encoded;
} TagFlagScore;
static void
tag_flag_score (const GstTagList *list, const gchar *tag, gpointer user_data)
{
TagFlagScore *score = (TagFlagScore *) user_data;
GstTagFlag flag;
flag = gst_tag_get_flag (tag);
if (flag == GST_TAG_FLAG_META) score->meta++;
if (flag == GST_TAG_FLAG_ENCODED) score->encoded++;
}
void
found_tag_callback (GObject *pipeline, GstElement *source, GstTagList *tags, GstMediaInfoPriv *priv)
{
TagFlagScore score;
score.meta = 0;
score.encoded = 0;
g_print ("FOUND TAG : found by element \"%s\".\n",
GST_STR_NULL (GST_ELEMENT_NAME (source)));
/* decide if it's likely to be metadata or streaminfo */
/* FIXME: this is a hack, there must be a better way,
but as long as elements can report both mixed we need to do this */
gst_tag_list_foreach (tags, tag_flag_score, &score);
if (score.meta > score.encoded)
{
GST_DEBUG ("deep_notify: have streaminfo !");
g_value_init (&value, pspec->value_type);
g_object_get_property (G_OBJECT (origin), pspec->name, &value);
priv->streaminfo = g_value_peek_pointer (&value);
GST_DEBUG ("found tags from decoder, adding them as metadata");
priv->metadata = gst_tag_list_copy (tags);
}
else GST_DEBUG ("ignoring notify of %s", pspec->name);
else
{
GST_DEBUG ("found tags, adding them as streaminfo");
priv->streaminfo = gst_tag_list_copy (tags);
}
}
void
error_callback (GObject *element, GstElement *source, GError *error, gchar *debug)
{
g_print ("ERROR: %s\n", error->message);
}
/* helpers */
@ -151,7 +216,7 @@ gmi_reset (GstMediaInfo *info)
if (priv->metadata)
{
GMI_DEBUG ("unreffing priv->metadata, error before this ?\n");
gst_caps_free (priv->metadata);
gst_tag_list_free (priv->metadata);
priv->metadata = NULL;
}
if (priv->stream)
@ -202,20 +267,22 @@ gmi_seek_to_track (GstMediaInfo *info, long track)
/* clear structs because of the seek */
if (priv->metadata)
{
gst_caps_free (priv->metadata);
gst_tag_list_free (priv->metadata);
priv->metadata = NULL;
}
if (priv->streaminfo)
{
gst_caps_free (priv->streaminfo);
gst_tag_list_free (priv->streaminfo);
priv->streaminfo = NULL;
}
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)
{
@ -234,6 +301,7 @@ gmi_get_decoder (GstMediaInfo *info, const char *mime)
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)
@ -303,6 +371,72 @@ gmi_clear_decoder (GstMediaInfo *info)
info->priv->decoder = NULL;
}
}
#endif
/* set the mime type on the media info getter */
gboolean
gmi_set_mime (GstMediaInfo *info, const char *mime)
{
gchar *desc = NULL;
GError *error = NULL;
GstMediaInfoPriv *priv = info->priv;
/* FIXME: please figure out proper mp3 mimetypes */
if ((strcmp (mime, "application/x-ogg") == 0) ||
(strcmp (mime, "application/ogg") == 0))
desc = g_strdup_printf ("%s name=source ! oggdemux ! vorbisdec name=decoder ! audioconvert ! audio/x-raw-int ! fakesink name=sink", priv->source_name);
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))
desc = g_strdup_printf ("%s name=source ! id3tag ! mad name=decoder ! audio/x-raw-int ! fakesink name=sink", priv->source_name);
else if (strcmp (mime, "application/x-flac") == 0)
desc = g_strdup_printf ("%s name=source ! flac name=decoder ! audio/x-raw-int ! fakesink name=sink", priv->source_name);
else if (strcmp (mime, "audio/x-wav") == 0)
desc = g_strdup_printf ("%s ! wavparse name=decoder ! audio/x-raw-int ! fakesink name=sink", priv->source_name);
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)
desc = g_strdup_printf ("%s name=source ! modplug name=decoder ! audio/x-raw-int ! fakesink name=sink", priv->source_name);
GST_DEBUG ("using description %s", desc);
priv->pipeline_desc = desc;
priv->pipeline = gst_parse_launch (desc, &error);
if (error)
{
g_warning ("Error parsing pipeline description: %s\n", error->message);
g_error_free (error);
return FALSE;
}
/* get a bunch of elements from the bin */
priv->source = gst_bin_get_by_name (GST_BIN (priv->pipeline), "source");
g_assert (GST_IS_ELEMENT (priv->source));
g_object_set (G_OBJECT (priv->source), "location", priv->location, NULL);
priv->decoder = gst_bin_get_by_name (GST_BIN (priv->pipeline), "decoder");
g_assert (GST_IS_ELEMENT (priv->decoder));
priv->fakesink = gst_bin_get_by_name (GST_BIN (priv->pipeline), "sink");
g_assert (GST_IS_ELEMENT (priv->fakesink));
/* get the "source " source pad */
priv->source_pad = gst_element_get_pad (priv->source, "src");
g_assert (GST_IS_PAD (priv->source_pad));
/* get the "decoder" source pad */
priv->decoder_pad = gst_element_get_pad (priv->decoder, "src");
g_assert (GST_IS_PAD (priv->decoder_pad));
GST_DEBUG ("decoder pad: %s:%s", gst_object_get_name (gst_object_get_parent (GST_OBJECT (priv->decoder_pad))), gst_pad_get_name (priv->decoder_pad));
/* attach notify handler */
g_signal_connect (G_OBJECT (info->priv->pipeline), "deep_notify",
G_CALLBACK (deep_notify_callback), info->priv);
g_signal_connect (G_OBJECT (info->priv->pipeline), "found-tag", G_CALLBACK (found_tag_callback), info->priv);
g_signal_connect (G_OBJECT (info->priv->pipeline), "error",
G_CALLBACK (error_callback), info->priv);
return TRUE;
}
/****
* typefind functions
@ -321,6 +455,9 @@ gmip_find_type_pre (GstMediaInfoPriv *priv)
priv->type = NULL;
}
g_assert (priv);
g_assert (priv->source);
GST_DEBUG ("gmip_find_type_pre: start");
/* find out type */
/* FIXME: we could move caps for typefind out of struct and
@ -338,6 +475,7 @@ gmip_find_type_pre (GstMediaInfoPriv *priv)
g_warning ("Couldn't set to play");
return FALSE;
}
GST_DEBUG ("moving to STATE_TYPEFIND\n");
priv->state = GST_MEDIA_INFO_STATE_TYPEFIND;
return TRUE;
}
@ -348,7 +486,16 @@ gmip_find_type_post (GstMediaInfoPriv *priv)
{
/*clear up typefind */
gst_element_set_state (priv->pipeline, GST_STATE_READY);
gst_element_unlink (priv->source, priv->typefind);
if (priv->decontainer)
{
gst_element_unlink (priv->source, priv->decontainer);
gst_element_unlink (priv->decontainer, priv->typefind);
gst_bin_remove (GST_BIN (priv->pipeline), priv->decontainer);
}
else
{
gst_element_unlink (priv->source, priv->typefind);
}
gst_bin_remove (GST_BIN (priv->pipeline), priv->typefind);
if (priv->type == NULL)
@ -356,6 +503,7 @@ gmip_find_type_post (GstMediaInfoPriv *priv)
g_warning ("iteration ended, type not found !\n");
return FALSE;
}
GST_DEBUG ("moving to STATE_STREAM\n");
priv->state = GST_MEDIA_INFO_STATE_STREAM;
return TRUE;
}
@ -450,6 +598,7 @@ gmip_find_stream_post (GstMediaInfoPriv *priv)
formats++;
}
if (stream->length_tracks == 0) stream->length_tracks = 1;
/* now get number of bytes from the sink pad to get the bitrate */
format = GST_FORMAT_BYTES;
g_assert (GST_IS_PAD (priv->source_pad));
@ -465,6 +614,7 @@ gmip_find_stream_post (GstMediaInfoPriv *priv)
double bits = bytes * 8;
stream->bitrate = (long) (bits / seconds);
}
GST_DEBUG ("moving to STATE_METADATA\n");
priv->state = GST_MEDIA_INFO_STATE_METADATA; /* metadata of first track */
return TRUE;
}
@ -537,7 +687,7 @@ gmip_find_track_metadata (GstMediaInfoPriv *priv)
}
/* find streaminfo found by decoder and store in priv->streaminfo */
/* FIXME: this is an exact copy, so reuse this functioin instead */
/* FIXME: this is an exact copy, so reuse this function instead */
gboolean
gmip_find_track_streaminfo_pre (GstMediaInfoPriv *priv)
{
@ -590,8 +740,8 @@ gmip_find_track_streaminfo_post (GstMediaInfoPriv *priv)
value_end -= value_start;
/* FIXME: check units; this is in seconds */
gst_caps_set_simple (priv->streaminfo,
"length", G_TYPE_INT, (int) (value_end / 1E6), NULL);
gst_tag_list_add (priv->streaminfo, GST_TAG_MERGE_REPLACE,
GST_TAG_DURATION, (int) (value_end / 1E6), NULL);
}
}
}

View file

@ -63,26 +63,25 @@ typedef enum
/* private structure */
struct GstMediaInfoPriv
{
GstElement *pipeline;
GstElement *typefind;
GstCaps *type;
GstPad *decoder_pad; /* pad for querying decoded caps */
GstPad *source_pad; /* pad for querying encoded caps */
GstCaps *format;
GstCaps *metadata;
GstTagList *metadata;
gint metadata_iters;
GstCaps *streaminfo;
GstTagList *streaminfo;
GstElement *decoder; /* will be != NULL during collection */
GstElement *pipeline; /* will be != NULL during collection */
gchar *pipeline_desc; /* will be != NULL during collection */
GstElement *fakesink; /* so we can get caps from the
decoder sink pad */
gchar *source_element; /* type of element used as source */
gchar *source_name; /* type of element used as source */
GstElement *source;
GHashTable *decoders; /* a table of decoder GstElements */
GstPad *source_pad; /* pad for querying encoded caps */
GstElement *decoder;
GstPad *decoder_pad; /* pad for querying decoded caps */
GstElement *decontainer; /* element to typefind in containers */
GstMediaInfoState state; /* current state of state machine */
gchar *location; /* location set on the info object */
@ -92,6 +91,8 @@ struct GstMediaInfoPriv
GstMediaInfoStream *stream; /* total stream properties */
char *cache; /* location of cache */
GError *error; /* error for creation problems */
};
/* declarations */
@ -106,16 +107,15 @@ void gmi_reset (GstMediaInfo *info);
gboolean gmi_seek_to_track (GstMediaInfo *info,
long track);
GstElement * gmi_get_decoder (GstMediaInfo *info,
gboolean gmi_set_mime (GstMediaInfo *info,
const char *mime);
void gmi_set_decoder (GstMediaInfo *info,
GstElement *decoder);
void gmi_clear_decoder (GstMediaInfo *info);
void deep_notify_callback (GObject *object,
GstObject *origin,
GParamSpec *pspec,
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);
gboolean gmip_find_type_pre (GstMediaInfoPriv *priv);
gboolean gmip_find_type_post (GstMediaInfoPriv *priv);

View file

@ -4,6 +4,33 @@
#include <string.h>
#include "media-info.h"
static void
print_tag (const GstTagList *list, const gchar *tag, gpointer unused)
{
gint i, count;
count = gst_tag_list_get_tag_size (list, tag);
for (i = 0; i < count; i++) {
gchar *str;
if (gst_tag_get_type (tag) == G_TYPE_STRING) {
g_assert (gst_tag_list_get_string_index (list, tag, i, &str));
} else {
str = g_strdup_value_contents (
gst_tag_list_get_value_index (list, tag, i));
}
if (i == 0) {
g_print ("%15s: %s\n", gst_tag_get_nick (tag), str);
} else {
g_print (" : %s\n", str);
}
g_free (str);
}
}
static void
info_print (GstMediaInfoStream *stream)
{
@ -27,9 +54,12 @@ info_print (GstMediaInfoStream *stream)
g_print ("- track %d\n", i);
track = (GstMediaInfoTrack *) p->data;
g_print (" - metadata:\n");
g_print ("%s\n", gst_caps_to_string (track->metadata));
if (track->metadata)
gst_tag_list_foreach (track->metadata, print_tag, NULL);
else
g_print (" (none found)\n");
g_print (" - streaminfo:\n");
g_print ("%s\n", gst_caps_to_string (track->streaminfo));
gst_tag_list_foreach (track->streaminfo, print_tag, NULL);
g_print (" - format:\n");
g_print ("%s\n", gst_caps_to_string (track->format));
p = p->next;
@ -41,14 +71,29 @@ main (int argc, char *argv[])
{
GstMediaInfo *info;
GstMediaInfoStream *stream = NULL;
GError *error = NULL;
gint i;
g_assert (argc > 1);
gst_init (&argc, &argv);
gst_media_info_init ();
gst_init (&argc, &argv);
info = gst_media_info_new (&error);
if (error != NULL)
{
g_print ("Error creating media-info object: %s\n", error->message);
g_error_free (error);
return -1;
}
g_assert (G_IS_OBJECT (info));
if (!gst_media_info_set_source (info, "gnomevfssrc"))
{
g_print ("Could not set gnomevfssrc as a source\n");
return -1;
}
info = g_object_new (GST_MEDIA_INFO_TYPE, NULL);
g_print ("stream: %p, &stream: %p\n", stream, &stream);
for (i = 1; i < argc; ++i)
{

View file

@ -1,5 +1,5 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
/* GStreamer media-info library
* Copyright (C) 2003,2004 Thomas Vander Stichele <thomas@apestaart.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -48,15 +48,16 @@ enum
static guint gst_media_info_signals[LAST_SIGNAL] = { 0 };
/* GError stuff */
/*
* all GError stuff
*/
enum
{
MEDIA_INFO_ERROR_FILE
};
*/
/* GError quark stuff */
/*
static GQuark
gst_media_info_error_quark (void)
{
@ -65,7 +66,53 @@ gst_media_info_error_quark (void)
quark = g_quark_from_static_string ("gst-media-info-error-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
*/
@ -78,6 +125,8 @@ enum
static GObjectClass *parent_class = NULL;
GST_DEBUG_CATEGORY (gst_media_info_debug);
/* initialize the media-info library */
void
gst_media_info_init (void)
{
@ -145,53 +194,35 @@ gst_media_info_class_init (GstMediaInfoClass *klass)
static void
gst_media_info_instance_init (GstMediaInfo *info)
{
GstElement *source;
GError **error;
info->priv = g_new0 (GstMediaInfoPriv, 1);
error = &info->priv->error;
info->priv->pipeline = gst_pipeline_new ("media-info");
/* create the typefind element and make sure it stays around by reffing */
info->priv->typefind = gst_element_factory_make ("typefind", "typefind");
if (!GST_IS_ELEMENT (info->priv->typefind))
g_error ("Cannot create typefind element !");
GST_MEDIA_INFO_MAKE_OR_ERROR (info->priv->typefind, "typefind", "typefind", error);
gst_object_ref (GST_OBJECT (info->priv->typefind));
/* create the fakesink element and make sure it stays around by reffing */
info->priv->fakesink = gst_element_factory_make ("fakesink", "fakesink");
if (!GST_IS_ELEMENT (info->priv->fakesink))
g_error ("Cannot create fakesink element !");
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;
/* use gnomevfssrc by default */
source = gst_element_factory_make ("gnomevfssrc", "source");
if (GST_IS_ELEMENT (source))
{
info->priv->source = source;
info->priv->source_element = g_strdup ("gnomevfssrc");
gst_bin_add (GST_BIN (info->priv->pipeline), info->priv->source);
}
else
{
info->priv->source = NULL;
info->priv->source_element = NULL;
}
info->priv->location = NULL;
info->priv->decoder = 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;
/* set up decoder hash table */
info->priv->decoders = g_hash_table_new (g_str_hash, g_str_equal);
/* attach notify handler */
g_signal_connect (G_OBJECT (info->priv->pipeline), "deep_notify",
G_CALLBACK (deep_notify_callback), info->priv);
info->priv->error = NULL;
}
/* get/set */
@ -204,7 +235,7 @@ gst_media_info_get_property (GObject *object, guint prop_id,
switch (prop_id)
{
case PROP_SOURCE:
g_value_set_string (value, info->priv->source_element);
g_value_set_string (value, info->priv->source_name);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -213,12 +244,24 @@ gst_media_info_get_property (GObject *object, guint prop_id,
}
GstMediaInfo *
gst_media_info_new (const gchar *source_element)
gst_media_info_new (GError **error)
{
GstMediaInfo *info = g_object_new (GST_MEDIA_INFO_TYPE, NULL);
if (source_element)
g_object_set (G_OBJECT (info), "source", source_element);
if (info->priv->error)
{
if (error)
{
*error = info->priv->error;
info->priv->error = NULL;
}
else
{
g_warning ("Error creating GstMediaInfo object.\n%s",
info->priv->error->message);
g_error_free (info->priv->error);
}
}
return info;
}
@ -237,16 +280,16 @@ gst_media_info_set_source (GstMediaInfo *info, const char *source)
{
/* this also unrefs the element */
gst_bin_remove (GST_BIN (info->priv->pipeline), info->priv->source);
if (info->priv->source_element)
if (info->priv->source_name)
{
g_free (info->priv->source_element);
info->priv->source_element = NULL;
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_element = g_strdup (source);
info->priv->source_name = g_strdup (source);
return TRUE;
}
@ -275,26 +318,27 @@ gst_media_info_read_with_idler (GstMediaInfo *info, const char *location,
gboolean
gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp)
{
GstMediaInfoPriv *priv ;
GstMediaInfoPriv *priv;
/* if it's NULL then we're sure something went wrong higher up) */
if (info == NULL) return FALSE;
priv = info->priv;
g_assert (streamp != NULL);
g_assert (priv);
switch (priv->state)
{
case GST_MEDIA_INFO_STATE_NULL:
/* need to find type */
GST_DEBUG ("idler: NULL, need to find type");
GST_DEBUG ("idler: NULL, need to find type, priv %p", priv);
return gmip_find_type_pre (priv);
case GST_MEDIA_INFO_STATE_TYPEFIND:
{
gchar *mime;
GstElement *decoder;
GST_DEBUG ("STATE_TYPEFIND");
GST_LOG ("STATE_TYPEFIND");
if ((priv->type == NULL) && gst_bin_iterate (GST_BIN (priv->pipeline)))
{
GST_DEBUG ("iterating while in STATE_TYPEFIND");
@ -313,24 +357,22 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp)
mime = g_strdup (gst_structure_get_name (
gst_caps_get_structure(priv->type, 0)));
GST_DEBUG ("found out mime type: %s", mime);
decoder = gmi_get_decoder (info, mime);
if (decoder == NULL)
if (!gmi_set_mime (info, mime))
{
/* FIXME: pop up error */
GST_DEBUG ("no decoder found for mime %s", mime);
GST_DEBUG ("no decoder pipeline found for mime %s", mime);
return FALSE;
}
priv->stream = gmi_stream_new ();
GST_DEBUG ("new stream: %p", priv->stream);
priv->stream->mime = mime;
priv->stream->path = priv->location;
gmi_set_decoder (info, decoder);
gmip_find_stream_pre (priv);
}
case GST_MEDIA_INFO_STATE_STREAM:
{
GST_DEBUG ("STATE_STREAM");
GST_LOG ("STATE_STREAM");
if ((priv->format == NULL) && gst_bin_iterate (GST_BIN (priv->pipeline)))
{
GMI_DEBUG("?");
@ -368,7 +410,7 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp)
}
GST_DEBUG ("found metadata of track %ld", priv->current_track_num);
if (!gmip_find_track_metadata_post (priv)) return FALSE;
GST_DEBUG ("METADATA: going to STREAMINFO");
GST_DEBUG ("METADATA: going to STREAMINFO\n");
priv->state = GST_MEDIA_INFO_STATE_STREAMINFO;
return gmip_find_track_streaminfo_pre (priv);
}
@ -430,7 +472,6 @@ gst_media_info_read_idler (GstMediaInfo *info, GstMediaInfoStream **streamp)
*streamp = priv->stream;
priv->stream = NULL;
GST_DEBUG ("TOTALLY DONE, setting pointer *streamp to %p", *streamp);
gmi_clear_decoder (info);
return TRUE;
}
case GST_MEDIA_INFO_STATE_DONE:
@ -464,8 +505,8 @@ gst_media_info_read (GstMediaInfo *info, const char *location, guint16 flags)
gst_caps_get_structure(priv->type, 0)));
GST_DEBUG ("mime type: %s", mime);
/* c) figure out decoder */
decoder = gmi_get_decoder (info, mime);
/* c) figure out decoding pipeline */
//FIXMEdecoder = gmi_get_pipeline_description (info, mime);
g_print ("DEBUG: using decoder %s\n", gst_element_get_name (decoder));
/* if it's NULL, then that's a sign we can't decode it */
@ -481,7 +522,8 @@ gst_media_info_read (GstMediaInfo *info, const char *location, guint16 flags)
priv->stream->path = priv->location;
/* install this decoder in the pipeline */
gmi_set_decoder (info, decoder);
//FIXME: use new systemgmi_set_decoder (info, decoder);
/* collect total stream properties */
/* d) get all stream properties */
@ -509,8 +551,6 @@ gst_media_info_read (GstMediaInfo *info, const char *location, guint16 flags)
priv->current_track = NULL;
}
/* f) clear decoder */
gmi_clear_decoder (info);
/* please return it */
stream = priv->stream;
priv->stream = NULL;

View file

@ -43,7 +43,7 @@ struct _GstMediaInfoClass
GObjectClass parent_class;
/* signals */
void (*media_info_signal) (GstMediaInfo *gst_media_info);
void (*media_info_signal) (GstMediaInfo *gst_media_info);
gpointer _gst_reserved[GST_PADDING];
};
@ -68,8 +68,8 @@ typedef struct
* or one of a set of sequentially muxed streams */
typedef struct
{
GstCaps *metadata; /* changeable metadata or tags */
GstCaps *streaminfo; /* codec property stuff */
GstTagList *metadata; /* changeable metadata or tags */
GstTagList *streaminfo; /* codec property stuff */
GstCaps *format; /* properties of the logical stream */
guint64 length_time;
@ -102,8 +102,9 @@ typedef struct
void gst_media_info_init (void);
GType gst_media_info_get_type (void);
GstMediaInfo * gst_media_info_new (const char *source_element);
GstMediaInfo * gst_media_info_new (GError **error);
gboolean gst_media_info_set_source (GstMediaInfo *info, const char *source);
void gst_media_info_read_with_idler (GstMediaInfo *media_info,
const char *location,
guint16 GST_MEDIA_INFO_FLAGS);