Fixed the media player so that it works with incsched.

Original commit message from CVS:
Fixed the media player so that it works with incsched.
Removed the thread and add the _iterate to the g_idle_loop, this makes the
GUI very cluncky but is needed because we cannot chance the state of a thread
inside the threads context yet.
This commit is contained in:
Wim Taymans 2001-05-25 00:09:10 +00:00
parent 31750806b2
commit a74b02deb8
3 changed files with 89 additions and 80 deletions

View file

@ -39,12 +39,11 @@ target_drag_data_received (GtkWidget *widget,
guint time, guint time,
GstMediaPlay *play) GstMediaPlay *play)
{ {
if (strstr (data->data, "file:")) { g_print ("Got: %s\n", data->data);
g_print ("Got: %s\n", &data->data[5]); gdk_threads_leave ();
gdk_threads_leave (); gst_media_play_start_uri (play, g_strchomp (data->data));
gst_media_play_start_uri (play, g_strchomp (&data->data[5])); gdk_threads_enter ();
gdk_threads_enter ();
}
} }
static GtkTargetEntry target_table[] = { static GtkTargetEntry target_table[] = {

View file

@ -118,10 +118,8 @@ gst_play_init (GstPlay *play)
play->priv = priv; play->priv = priv;
/* create a new bin to hold the elements */ /* create a new bin to hold the elements */
priv->thread = gst_thread_new ("main_thread"); priv->pipeline = gst_pipeline_new ("main_pipeline");
g_assert (priv->thread != NULL); g_assert (priv->pipeline != NULL);
priv->bin = gst_bin_new ("main_bin");
g_assert (priv->bin != NULL);
priv->audio_element = gst_elementfactory_make ("osssink", "play_audio"); priv->audio_element = gst_elementfactory_make ("osssink", "play_audio");
g_return_if_fail (priv->audio_element != NULL); g_return_if_fail (priv->audio_element != NULL);
@ -165,6 +163,12 @@ gst_play_new ()
return GST_PLAY (gtk_type_new (GST_TYPE_PLAY)); return GST_PLAY (gtk_type_new (GST_TYPE_PLAY));
} }
static gboolean
gst_play_idle_func (gpointer data)
{
return gst_bin_iterate (GST_BIN (data));
}
static void static void
gst_play_eos (GstElement *element, gst_play_eos (GstElement *element,
GstPlay *play) GstPlay *play)
@ -273,53 +277,68 @@ gst_play_object_added (GstAutoplug* autoplug, GstObject *object, GstPlay *play)
} }
static void static void
gst_play_have_type (GstElement *sink, GstElement *sink2, gpointer data) gst_play_cache_empty (GstElement *element, GstPlay *play)
{ {
GST_DEBUG (0,"GstPipeline: play have type %p\n", (gboolean *)data); GstPlayPrivate *priv;
GstElement *new_element;
*(gboolean *)data = TRUE; priv = (GstPlayPrivate *)play->priv;
gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
new_element = gst_bin_get_by_name (GST_BIN (priv->pipeline), "new_element");
gst_element_disconnect (priv->src, "src", priv->cache, "sink");
gst_element_disconnect (priv->cache, "src", new_element, "sink");
gst_bin_remove (GST_BIN (priv->pipeline), priv->cache);
gst_element_connect (priv->src, "src", new_element, "sink");
gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
} }
static GstCaps* static void
gst_play_typefind (GstBin *bin, GstElement *element) gst_play_have_type (GstElement *sink, GstCaps *caps, GstPlay *play)
{ {
gboolean found = FALSE; GstPlayPrivate *priv;
GstElement *typefind; GstElement *new_element;
GstCaps *caps = NULL; GstAutoplug *autoplug;
GST_DEBUG (0, "GstPipeline: typefind for element \"%s\" %p\n", GST_DEBUG (0,"GstPipeline: play have type\n");
GST_ELEMENT_NAME (element), &found);
typefind = gst_elementfactory_make ("typefind", "typefind"); priv = (GstPlayPrivate *)play->priv;
g_return_val_if_fail (typefind != NULL, FALSE);
gtk_signal_connect (GTK_OBJECT (typefind), "have_type", gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
GTK_SIGNAL_FUNC (gst_play_have_type), &found);
gst_pad_connect (gst_element_get_pad (element, "src"), gst_element_disconnect (priv->cache, "src", priv->typefind, "sink");
gst_element_get_pad (typefind, "sink")); gst_bin_remove (GST_BIN (priv->pipeline), priv->typefind);
gst_bin_add (bin, typefind); autoplug = gst_autoplugfactory_make ("staticrender");
g_assert (autoplug != NULL);
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING); gtk_signal_connect (GTK_OBJECT (autoplug), "new_object", gst_play_object_added, play);
// push a buffer... the have_type signal handler will set the found flag new_element = gst_autoplug_to_renderers (autoplug,
gst_bin_iterate (bin); caps,
priv->video_element,
priv->audio_element,
NULL);
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL); if (!new_element) {
// FIXME, signal a suitable error
if (found) { return;
caps = gst_util_get_pointer_arg (GTK_OBJECT (typefind), "caps");
gst_pad_set_caps (gst_element_get_pad (element, "src"), caps);
} }
gst_pad_disconnect (gst_element_get_pad (element, "src"), gst_element_set_name (new_element, "new_element");
gst_element_get_pad (typefind, "sink"));
gst_bin_remove (bin, typefind);
gst_object_unref (GST_OBJECT (typefind));
return caps; gst_bin_add (GST_BIN (priv->pipeline), new_element);
gtk_object_set (GTK_OBJECT (priv->cache), "reset", TRUE, NULL);
gst_element_connect (priv->cache, "src", new_element, "sink");
gtk_signal_connect (GTK_OBJECT (priv->pipeline), "eos", GTK_SIGNAL_FUNC (gst_play_eos), play);
gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
} }
static gboolean static gboolean
@ -349,9 +368,6 @@ GstPlayReturn
gst_play_set_uri (GstPlay *play, const guchar *uri) gst_play_set_uri (GstPlay *play, const guchar *uri)
{ {
GstPlayPrivate *priv; GstPlayPrivate *priv;
GstCaps *src_caps;
GstElement *new_element;
GstAutoplug *autoplug;
g_return_val_if_fail (play != NULL, GST_PLAY_ERROR); g_return_val_if_fail (play != NULL, GST_PLAY_ERROR);
g_return_val_if_fail (GST_IS_PLAY (play), GST_PLAY_ERROR); g_return_val_if_fail (GST_IS_PLAY (play), GST_PLAY_ERROR);
@ -364,45 +380,35 @@ gst_play_set_uri (GstPlay *play, const guchar *uri)
priv->uri = g_strdup (uri); priv->uri = g_strdup (uri);
priv->src = gst_elementfactory_make ("disksrc", "disk_src"); priv->src = gst_elementfactory_make ("gnomevfssrc", "srcelement");
if (priv->src == NULL) {
priv->src = gst_elementfactory_make ("disksrc", "srcelement");
}
//priv->src = gst_elementfactory_make ("dvdsrc", "disk_src"); //priv->src = gst_elementfactory_make ("dvdsrc", "disk_src");
priv->offset_element = priv->src; priv->offset_element = priv->src;
g_return_val_if_fail (priv->src != NULL, GST_PLAY_CANNOT_PLAY);
g_return_val_if_fail (priv->src != NULL, -1);
gtk_object_set (GTK_OBJECT (priv->src), "location", uri, NULL); gtk_object_set (GTK_OBJECT (priv->src), "location", uri, NULL);
gst_bin_add (GST_BIN (priv->bin), priv->src);
src_caps = gst_play_typefind (GST_BIN (priv->bin), priv->src); priv->cache = gst_elementfactory_make ("autoplugcache", "cache");
g_return_val_if_fail (priv->cache != NULL, GST_PLAY_CANNOT_PLAY);
if (!src_caps) { gtk_signal_connect (GTK_OBJECT (priv->cache), "cache_empty",
return GST_PLAY_UNKNOWN_MEDIA; GTK_SIGNAL_FUNC (gst_play_cache_empty), play);
}
autoplug = gst_autoplugfactory_make ("staticrender"); priv->typefind = gst_elementfactory_make ("typefind", "typefind");
g_assert (autoplug != NULL); g_return_val_if_fail (priv->typefind != NULL, GST_PLAY_CANNOT_PLAY);
gtk_signal_connect (GTK_OBJECT (priv->typefind), "have_type",
GTK_SIGNAL_FUNC (gst_play_have_type), play);
gtk_signal_connect (GTK_OBJECT (autoplug), "new_object", gst_play_object_added, play);
new_element = gst_autoplug_to_renderers (autoplug, gst_bin_add (GST_BIN (priv->pipeline), priv->src);
gst_pad_get_caps (gst_element_get_pad (priv->src, "src")), gst_bin_add (GST_BIN (priv->pipeline), priv->cache);
priv->video_element, gst_bin_add (GST_BIN (priv->pipeline), priv->typefind);
priv->audio_element,
NULL);
if (!new_element) { gst_element_connect (priv->src, "src", priv->cache, "sink");
return GST_PLAY_CANNOT_PLAY; gst_element_connect (priv->cache, "src", priv->typefind, "sink");
}
gst_bin_remove (GST_BIN (priv->bin), priv->src);
gst_bin_add (GST_BIN (priv->thread), priv->src);
gst_bin_add (GST_BIN (priv->bin), new_element);
gst_element_connect (priv->src, "src", new_element, "sink");
gst_bin_add (GST_BIN (priv->thread), priv->bin);
gtk_signal_connect (GTK_OBJECT (priv->thread), "eos", GTK_SIGNAL_FUNC (gst_play_eos), play);
return GST_PLAY_OK; return GST_PLAY_OK;
} }
@ -449,10 +455,11 @@ gst_play_play (GstPlay *play)
if (play->state == GST_PLAY_PLAYING) return; if (play->state == GST_PLAY_PLAYING) return;
if (play->state == GST_PLAY_STOPPED) if (play->state == GST_PLAY_STOPPED)
gst_element_set_state (GST_ELEMENT (priv->thread),GST_STATE_READY); gst_element_set_state (GST_ELEMENT (priv->pipeline),GST_STATE_READY);
gst_element_set_state (GST_ELEMENT (priv->thread),GST_STATE_PLAYING); gst_element_set_state (GST_ELEMENT (priv->pipeline),GST_STATE_PLAYING);
play->state = GST_PLAY_PLAYING; play->state = GST_PLAY_PLAYING;
gtk_idle_add (gst_play_idle_func, priv->pipeline);
gtk_signal_emit (GTK_OBJECT (play), gst_play_signals[SIGNAL_STATE_CHANGED], gtk_signal_emit (GTK_OBJECT (play), gst_play_signals[SIGNAL_STATE_CHANGED],
play->state); play->state);
@ -470,9 +477,10 @@ gst_play_pause (GstPlay *play)
if (play->state != GST_PLAY_PLAYING) return; if (play->state != GST_PLAY_PLAYING) return;
gst_element_set_state (GST_ELEMENT (priv->thread),GST_STATE_PAUSED); gst_element_set_state (GST_ELEMENT (priv->pipeline),GST_STATE_PAUSED);
play->state = GST_PLAY_PAUSED; play->state = GST_PLAY_PAUSED;
g_idle_remove_by_data (priv->pipeline);
gtk_signal_emit (GTK_OBJECT (play), gst_play_signals[SIGNAL_STATE_CHANGED], gtk_signal_emit (GTK_OBJECT (play), gst_play_signals[SIGNAL_STATE_CHANGED],
play->state); play->state);
@ -491,11 +499,12 @@ gst_play_stop (GstPlay *play)
priv = (GstPlayPrivate *)play->priv; priv = (GstPlayPrivate *)play->priv;
// FIXME until state changes are handled properly // FIXME until state changes are handled properly
gst_element_set_state (GST_ELEMENT (priv->thread),GST_STATE_READY); gst_element_set_state (GST_ELEMENT (priv->pipeline),GST_STATE_READY);
gtk_object_set (GTK_OBJECT (priv->src),"offset",0,NULL); gtk_object_set (GTK_OBJECT (priv->src),"offset",0,NULL);
//gst_element_set_state (GST_ELEMENT (priv->thread),GST_STATE_NULL); //gst_element_set_state (GST_ELEMENT (priv->pipeline),GST_STATE_NULL);
play->state = GST_PLAY_STOPPED; play->state = GST_PLAY_STOPPED;
g_idle_remove_by_data (priv->pipeline);
gtk_signal_emit (GTK_OBJECT (play), gst_play_signals[SIGNAL_STATE_CHANGED], gtk_signal_emit (GTK_OBJECT (play), gst_play_signals[SIGNAL_STATE_CHANGED],
play->state); play->state);
@ -653,7 +662,7 @@ gst_play_get_pipeline (GstPlay *play)
priv = (GstPlayPrivate *)play->priv; priv = (GstPlayPrivate *)play->priv;
return GST_ELEMENT (priv->bin); return GST_ELEMENT (priv->pipeline);
} }
static void static void

View file

@ -6,12 +6,13 @@
typedef struct _GstPlayPrivate GstPlayPrivate; typedef struct _GstPlayPrivate GstPlayPrivate;
struct _GstPlayPrivate { struct _GstPlayPrivate {
GstElement *thread; GstElement *pipeline;
GstElement *bin;
GstElement *video_element, *audio_element; GstElement *video_element, *audio_element;
GstElement *video_show; GstElement *video_show;
GtkWidget *video_widget; GtkWidget *video_widget;
GstElement *src; GstElement *src;
GstElement *cache;
GstElement *typefind;
guchar *uri; guchar *uri;
gboolean muted; gboolean muted;