summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier CrĂȘte <olivier.crete@collabora.co.uk>2010-04-09 19:49:44 (GMT)
committerOlivier CrĂȘte <olivier.crete@collabora.co.uk>2010-09-09 08:18:59 (GMT)
commit52cf35fbe185896fb2f5f7cb2bddfe51db089b15 (patch)
treee5377ced464925444eb89016305e3306ec73c253
parent2f31a37c69719a653a72e851e503264eda81c68d (diff)
downloadtelepathy-stream-engine-52cf35fbe185896fb2f5f7cb2bddfe51db089b15.tar.gz
telepathy-stream-engine-52cf35fbe185896fb2f5f7cb2bddfe51db089b15.tar.xz
Create/remove video source when starting/stopping
-rw-r--r--src/tp-stream-engine.c73
1 files changed, 37 insertions, 36 deletions
diff --git a/src/tp-stream-engine.c b/src/tp-stream-engine.c
index 7e91400..65444b1 100644
--- a/src/tp-stream-engine.c
+++ b/src/tp-stream-engine.c
@@ -75,10 +75,11 @@ static void setup_realtime_thread (pthread_t thread, pid_t tid);
static void low_prio_thread (pthread_t thread, pid_t tid);
-static void
-update_video_src_caps (TpStreamEngine *self, TfStream *forcedstream,
+static void update_video_src_caps (TpStreamEngine *self, TfStream *forcedstream,
gboolean force_send);
+static GstElement *make_video_src (TpStreamEngine *self);
+
static void
register_dbus_signal_marshallers()
{
@@ -172,7 +173,6 @@ struct _TpStreamEnginePrivate
FsElementAddedNotifier *notifier;
- gboolean video_source_started;
gint video_source_use_count;
gboolean failcount;
@@ -462,12 +462,9 @@ tp_stream_engine_dispose (GObject *object)
* if it fails or is async, it will crash on the following
* unref anyways
*/
- gst_element_set_state (priv->videosrc, GST_STATE_NULL);
gst_element_set_state (priv->pipeline, GST_STATE_NULL);
- gst_object_unref (priv->videosrc);
gst_object_unref (priv->pipeline);
priv->pipeline = NULL;
- priv->videosrc = NULL;
}
if (priv->notifier)
@@ -521,39 +518,46 @@ static gboolean
tp_stream_engine_start_video_source (TpStreamEngine *self)
{
GstStateChangeReturn state_ret;
+ GstElement *videosrc;
- if (self->priv->video_source_started)
+ if (self->priv->videosrc)
return TRUE;
+ videosrc = make_video_src (self);
+
g_debug ("Starting video source");
- if (!gst_bin_add (GST_BIN (self->priv->pipeline), self->priv->videosrc))
+ if (!gst_bin_add (GST_BIN (self->priv->pipeline), videosrc))
{
g_warning ("Could not add videosrc to pipeline");
+ gst_object_unref (videosrc);
return FALSE;
}
- if (!gst_element_link (self->priv->videosrc, self->priv->capsfilter))
+ if (!gst_element_link (videosrc, self->priv->capsfilter))
{
g_warning ("Could not link videosrc to capsfilter");
- gst_bin_remove (GST_BIN (self->priv->pipeline), self->priv->videosrc);
- return FALSE;
+ goto error;
}
- state_ret = gst_element_set_state (self->priv->videosrc, GST_STATE_PLAYING);
+ state_ret = gst_element_set_state (videosrc, GST_STATE_PLAYING);
if (state_ret == GST_STATE_CHANGE_FAILURE)
{
g_warning ("Error starting the video source");
- gst_bin_remove (GST_BIN (self->priv->pipeline), self->priv->videosrc);
- gst_element_set_state (self->priv->videosrc, GST_STATE_NULL);
- return FALSE;
- }
- else
- {
- self->priv->video_source_started = TRUE;
- return TRUE;
+ goto error;
+
}
+
+ self->priv->videosrc = videosrc;
+ return TRUE;
+
+ error:
+ gst_element_set_locked_state (videosrc, TRUE);
+ gst_element_set_state (videosrc, GST_STATE_NULL);
+ gst_bin_remove (GST_BIN (self->priv->pipeline), videosrc);
+
+ return FALSE;
}
@@ -574,22 +578,30 @@ static void
tp_stream_engine_stop_video_source (TpStreamEngine *self)
{
GstStateChangeReturn state_ret;
+ GstElement *videosrc;
- if (!self->priv->video_source_started)
+ if (!self->priv->videosrc)
return;
- self->priv->video_source_started = FALSE;
+
+ videosrc = self->priv->videosrc;
+ self->priv->videosrc = NULL;
g_debug ("Stopping video source");
- if (!gst_bin_remove (GST_BIN (self->priv->pipeline), self->priv->videosrc))
+ gst_object_ref (videosrc);
+
+ if (!gst_bin_remove (GST_BIN (self->priv->pipeline), videosrc))
g_warning ("Could not remove video src from pipeline");
- state_ret = gst_element_set_state (self->priv->videosrc, GST_STATE_NULL);
+ gst_element_set_locked_state (videosrc, TRUE);
+ state_ret = gst_element_set_state (videosrc, GST_STATE_NULL);
if (state_ret == GST_STATE_CHANGE_FAILURE)
g_error ("Error stopping the video source");
else if (state_ret == GST_STATE_CHANGE_ASYNC)
g_debug ("Stopping video src async??");
+
+ gst_object_unref (videosrc);
}
@@ -657,7 +669,7 @@ update_video_src_caps (TpStreamEngine *self, TfStream *forcedstream,
gst_caps_unref (caps);
- if (self->priv->videosrc && self->priv->video_source_use_count)
+ if (self->priv->video_source_use_count)
if (!tp_stream_engine_start_video_source (self))
g_warning ("Could not start video source");
}
@@ -1287,8 +1299,6 @@ restart_pipeline (gpointer data)
ret = gst_element_set_state (self->priv->pipeline, GST_STATE_NULL);
g_assert (ret != GST_STATE_CHANGE_FAILURE);
- ret = gst_element_set_state (self->priv->videosrc, GST_STATE_NULL);
- g_assert (ret != GST_STATE_CHANGE_FAILURE);
g_mutex_lock (self->priv->mutex);
try_stop_again:
@@ -1315,12 +1325,6 @@ restart_pipeline (gpointer data)
ret = gst_element_set_state (self->priv->pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE)
goto fail;
- if (self->priv->video_source_use_count)
- {
- ret = gst_element_set_state (self->priv->videosrc, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE)
- goto fail;
- }
g_mutex_lock (self->priv->mutex);
try_start_again:
@@ -1649,9 +1653,6 @@ _build_base_video_elements (TpStreamEngine *self)
GstElement *capsfilter;
gboolean ret;
- priv->videosrc = make_video_src (self);
- gst_element_set_locked_state (priv->videosrc, TRUE);
- gst_object_ref (priv->videosrc);
tee = gst_element_factory_make ("tee", "videotee");
g_assert (tee);