summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@gmail.com>2001-05-25 00:09:10 +0000
committerWim Taymans <wim.taymans@gmail.com>2001-05-25 00:09:10 +0000
commita74b02deb87f4bbeede70b91bacd14045e4d8bad (patch)
tree42b94425de84b3ec2ef2bfdfb24b6b451bae5334
parent31750806b2975ad549d219802d85b9a86f6e392e (diff)
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.
-rw-r--r--gstplay/gstmediaplay.c11
-rw-r--r--gstplay/gstplay.c151
-rw-r--r--gstplay/gstplayprivate.h5
3 files changed, 88 insertions, 79 deletions
diff --git a/gstplay/gstmediaplay.c b/gstplay/gstmediaplay.c
index 84e2c0f894..e42cc3bfc8 100644
--- a/gstplay/gstmediaplay.c
+++ b/gstplay/gstmediaplay.c
@@ -39,12 +39,11 @@ target_drag_data_received (GtkWidget *widget,
guint time,
GstMediaPlay *play)
{
- if (strstr (data->data, "file:")) {
- g_print ("Got: %s\n", &data->data[5]);
- gdk_threads_leave ();
- gst_media_play_start_uri (play, g_strchomp (&data->data[5]));
- gdk_threads_enter ();
- }
+ g_print ("Got: %s\n", data->data);
+ gdk_threads_leave ();
+ gst_media_play_start_uri (play, g_strchomp (data->data));
+ gdk_threads_enter ();
+
}
static GtkTargetEntry target_table[] = {
diff --git a/gstplay/gstplay.c b/gstplay/gstplay.c
index 94df848f04..f2b2be119b 100644
--- a/gstplay/gstplay.c
+++ b/gstplay/gstplay.c
@@ -118,10 +118,8 @@ gst_play_init (GstPlay *play)
play->priv = priv;
/* create a new bin to hold the elements */
- priv->thread = gst_thread_new ("main_thread");
- g_assert (priv->thread != NULL);
- priv->bin = gst_bin_new ("main_bin");
- g_assert (priv->bin != NULL);
+ priv->pipeline = gst_pipeline_new ("main_pipeline");
+ g_assert (priv->pipeline != NULL);
priv->audio_element = gst_elementfactory_make ("osssink", "play_audio");
g_return_if_fail (priv->audio_element != NULL);
@@ -165,6 +163,12 @@ gst_play_new ()
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
gst_play_eos (GstElement *element,
GstPlay *play)
@@ -273,53 +277,68 @@ gst_play_object_added (GstAutoplug* autoplug, GstObject *object, GstPlay *play)
}
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;
+
+ 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");
- *(gboolean *)data = TRUE;
+ gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
}
-static GstCaps*
-gst_play_typefind (GstBin *bin, GstElement *element)
+static void
+gst_play_have_type (GstElement *sink, GstCaps *caps, GstPlay *play)
{
- gboolean found = FALSE;
- GstElement *typefind;
- GstCaps *caps = NULL;
+ GstPlayPrivate *priv;
+ GstElement *new_element;
+ GstAutoplug *autoplug;
+
+ GST_DEBUG (0,"GstPipeline: play have type\n");
+
+ priv = (GstPlayPrivate *)play->priv;
- GST_DEBUG (0, "GstPipeline: typefind for element \"%s\" %p\n",
- GST_ELEMENT_NAME (element), &found);
+ gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
- typefind = gst_elementfactory_make ("typefind", "typefind");
- g_return_val_if_fail (typefind != NULL, FALSE);
+ gst_element_disconnect (priv->cache, "src", priv->typefind, "sink");
+ gst_bin_remove (GST_BIN (priv->pipeline), priv->typefind);
- gtk_signal_connect (GTK_OBJECT (typefind), "have_type",
- GTK_SIGNAL_FUNC (gst_play_have_type), &found);
+ autoplug = gst_autoplugfactory_make ("staticrender");
+ g_assert (autoplug != NULL);
- gst_pad_connect (gst_element_get_pad (element, "src"),
- gst_element_get_pad (typefind, "sink"));
+ gtk_signal_connect (GTK_OBJECT (autoplug), "new_object", gst_play_object_added, play);
- gst_bin_add (bin, typefind);
+ new_element = gst_autoplug_to_renderers (autoplug,
+ caps,
+ priv->video_element,
+ priv->audio_element,
+ NULL);
- gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
+ if (!new_element) {
+ // FIXME, signal a suitable error
+ return;
+ }
- // push a buffer... the have_type signal handler will set the found flag
- gst_bin_iterate (bin);
+ gst_element_set_name (new_element, "new_element");
- gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
+ gst_bin_add (GST_BIN (priv->pipeline), new_element);
- if (found) {
- caps = gst_util_get_pointer_arg (GTK_OBJECT (typefind), "caps");
+ gtk_object_set (GTK_OBJECT (priv->cache), "reset", TRUE, NULL);
- gst_pad_set_caps (gst_element_get_pad (element, "src"), caps);
- }
+ gst_element_connect (priv->cache, "src", new_element, "sink");
- gst_pad_disconnect (gst_element_get_pad (element, "src"),
- gst_element_get_pad (typefind, "sink"));
- gst_bin_remove (bin, typefind);
- gst_object_unref (GST_OBJECT (typefind));
+ gtk_signal_connect (GTK_OBJECT (priv->pipeline), "eos", GTK_SIGNAL_FUNC (gst_play_eos), play);
- return caps;
+ gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
}
static gboolean
@@ -349,9 +368,6 @@ GstPlayReturn
gst_play_set_uri (GstPlay *play, const guchar *uri)
{
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 (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->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->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);
- gst_bin_add (GST_BIN (priv->bin), priv->src);
-
- src_caps = gst_play_typefind (GST_BIN (priv->bin), priv->src);
-
- if (!src_caps) {
- return GST_PLAY_UNKNOWN_MEDIA;
- }
-
- autoplug = gst_autoplugfactory_make ("staticrender");
- g_assert (autoplug != NULL);
-
- gtk_signal_connect (GTK_OBJECT (autoplug), "new_object", gst_play_object_added, play);
- new_element = gst_autoplug_to_renderers (autoplug,
- gst_pad_get_caps (gst_element_get_pad (priv->src, "src")),
- priv->video_element,
- priv->audio_element,
- NULL);
+ priv->cache = gst_elementfactory_make ("autoplugcache", "cache");
+ g_return_val_if_fail (priv->cache != NULL, GST_PLAY_CANNOT_PLAY);
- if (!new_element) {
- return GST_PLAY_CANNOT_PLAY;
- }
+ gtk_signal_connect (GTK_OBJECT (priv->cache), "cache_empty",
+ GTK_SIGNAL_FUNC (gst_play_cache_empty), play);
- gst_bin_remove (GST_BIN (priv->bin), priv->src);
- gst_bin_add (GST_BIN (priv->thread), priv->src);
+ priv->typefind = gst_elementfactory_make ("typefind", "typefind");
+ 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);
- gst_bin_add (GST_BIN (priv->bin), new_element);
- gst_element_connect (priv->src, "src", new_element, "sink");
+ gst_bin_add (GST_BIN (priv->pipeline), priv->src);
+ gst_bin_add (GST_BIN (priv->pipeline), priv->cache);
+ gst_bin_add (GST_BIN (priv->pipeline), priv->typefind);
- gst_bin_add (GST_BIN (priv->thread), priv->bin);
- gtk_signal_connect (GTK_OBJECT (priv->thread), "eos", GTK_SIGNAL_FUNC (gst_play_eos), play);
+ gst_element_connect (priv->src, "src", priv->cache, "sink");
+ gst_element_connect (priv->cache, "src", priv->typefind, "sink");
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_STOPPED)
- gst_element_set_state (GST_ELEMENT (priv->thread),GST_STATE_READY);
- gst_element_set_state (GST_ELEMENT (priv->thread),GST_STATE_PLAYING);
+ gst_element_set_state (GST_ELEMENT (priv->pipeline),GST_STATE_READY);
+ gst_element_set_state (GST_ELEMENT (priv->pipeline),GST_STATE_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],
play->state);
@@ -470,9 +477,10 @@ gst_play_pause (GstPlay *play)
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;
+ g_idle_remove_by_data (priv->pipeline);
gtk_signal_emit (GTK_OBJECT (play), gst_play_signals[SIGNAL_STATE_CHANGED],
play->state);
@@ -491,11 +499,12 @@ gst_play_stop (GstPlay *play)
priv = (GstPlayPrivate *)play->priv;
// 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);
- //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;
+ g_idle_remove_by_data (priv->pipeline);
gtk_signal_emit (GTK_OBJECT (play), gst_play_signals[SIGNAL_STATE_CHANGED],
play->state);
@@ -653,7 +662,7 @@ gst_play_get_pipeline (GstPlay *play)
priv = (GstPlayPrivate *)play->priv;
- return GST_ELEMENT (priv->bin);
+ return GST_ELEMENT (priv->pipeline);
}
static void
diff --git a/gstplay/gstplayprivate.h b/gstplay/gstplayprivate.h
index 763f80af16..2b80f179a5 100644
--- a/gstplay/gstplayprivate.h
+++ b/gstplay/gstplayprivate.h
@@ -6,12 +6,13 @@
typedef struct _GstPlayPrivate GstPlayPrivate;
struct _GstPlayPrivate {
- GstElement *thread;
- GstElement *bin;
+ GstElement *pipeline;
GstElement *video_element, *audio_element;
GstElement *video_show;
GtkWidget *video_widget;
GstElement *src;
+ GstElement *cache;
+ GstElement *typefind;
guchar *uri;
gboolean muted;