[empathy: 4/8] Better implemented empathy_tp_call_is_receiving_video and empathy_tp_call_is_sending_video.



commit c65de38d223ada5dfcf2d74b25a6af520143f3c5
Author: Jonathan Tellier <jonathan tellier gmail com>
Date:   Wed Jun 10 15:36:01 2009 -0400

    Better implemented empathy_tp_call_is_receiving_video and empathy_tp_call_is_sending_video.
    Removed the "video-stream-changed" from EmpathyCallHandler
    Corrected gtk-doc in EmpathyCallHandler.
    empathy_call_window_stup_video_preview now checks the status of the
    video_tee and the video_preview.
    empathy_call_window_sink_added_cb does not automatically starts the
    preview.

 libempathy/empathy-call-handler.c |   28 +-------
 libempathy/empathy-tp-call.c      |    6 +-
 src/empathy-call-window.c         |  125 +++++++++++++++++++++---------------
 3 files changed, 78 insertions(+), 81 deletions(-)
---
diff --git a/libempathy/empathy-call-handler.c b/libempathy/empathy-call-handler.c
index e5203f5..bbc1f9a 100644
--- a/libempathy/empathy-call-handler.c
+++ b/libempathy/empathy-call-handler.c
@@ -43,7 +43,6 @@ enum {
   SINK_PAD_ADDED,
   REQUEST_RESOURCE,
   CLOSED,
-  VIDEO_STREAM_CHANGED,
   LAST_SIGNAL
 };
 
@@ -72,13 +71,6 @@ typedef struct {
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
 
 static void
-empathy_call_handler_call_video_stream_cb (EmpathyTpCall *call,
-    GParamSpec *property, EmpathyCallHandler *self)
-{
-  g_signal_emit (G_OBJECT (self), signals[VIDEO_STREAM_CHANGED], 0);
-}
-
-static void
 empathy_call_handler_dispose (GObject *object)
 {
   EmpathyCallHandlerPriv *priv = GET_PRIV (object);
@@ -101,8 +93,6 @@ empathy_call_handler_dispose (GObject *object)
   if (priv->call != NULL)
     {
       empathy_tp_call_close (priv->call);
-      g_signal_handlers_disconnect_by_func (priv->call,
-          empathy_call_handler_call_video_stream_cb, object);
       g_object_unref (priv->call);
     }
 
@@ -272,13 +262,6 @@ empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
       g_cclosure_marshal_VOID__VOID,
       G_TYPE_NONE,
       0);
-
-  signals[VIDEO_STREAM_CHANGED] =
-    g_signal_new ("video-stream-changed", G_TYPE_FROM_CLASS (klass),
-      G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-      g_cclosure_marshal_VOID__VOID,
-      G_TYPE_NONE,
-      0);
 }
 
 /**
@@ -531,9 +514,6 @@ empathy_call_handler_request_cb (EmpathyDispatchOperation *operation,
 
   g_object_ref (priv->call);
 
-  g_signal_connect (priv->call, "notify::video-stream",
-      G_CALLBACK (empathy_call_handler_call_video_stream_cb), self);
-
   empathy_call_handler_start_tpfs (self);
 
   empathy_tp_call_to (priv->call, priv->contact,
@@ -556,8 +536,6 @@ empathy_call_handler_start_call (EmpathyCallHandler *handler)
   if (priv->call != NULL)
     {
       empathy_call_handler_start_tpfs (handler);
-      g_signal_connect (priv->call, "notify::video-stream",
-          G_CALLBACK (empathy_call_handler_call_video_stream_cb), handler);
       empathy_tp_call_accept_incoming_call (priv->call);
       return;
     }
@@ -623,10 +601,10 @@ empathy_call_handler_stop_call (EmpathyCallHandler *handler)
  * empathy_call_handler_has_initial_video:
  * @handler: an #EmpathyCallHandler
  *
- * Determines if the call managed by this #EmpathyCallHandler was created as
- * a video conversation.
+ * Return %TRUE if the call managed by this #EmpathyCallHandler was
+ * created with video enabled
  *
- * Return value: TRUE if the call was created as a video conversation.
+ * Return value: %TRUE if the call was created as a video conversation.
  */
 gboolean
 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
diff --git a/libempathy/empathy-tp-call.c b/libempathy/empathy-tp-call.c
index bf3fe77..a672d8a 100644
--- a/libempathy/empathy-tp-call.c
+++ b/libempathy/empathy-tp-call.c
@@ -687,8 +687,7 @@ empathy_tp_call_is_receiving_video (EmpathyTpCall *call)
 
   g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), FALSE);
 
-  return priv->video->direction == TP_MEDIA_STREAM_DIRECTION_RECEIVE ||
-            priv->video->direction == TP_MEDIA_STREAM_DIRECTION_BIDIRECTIONAL;
+  return priv->video->direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE;
 }
 
 /**
@@ -706,6 +705,5 @@ empathy_tp_call_is_sending_video (EmpathyTpCall *call)
 
   g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), FALSE);
 
-  return priv->video->direction == TP_MEDIA_STREAM_DIRECTION_SEND ||
-            priv->video->direction == TP_MEDIA_STREAM_DIRECTION_BIDIRECTIONAL;
+  return priv->video->direction & TP_MEDIA_STREAM_DIRECTION_SEND;
 }
diff --git a/src/empathy-call-window.c b/src/empathy-call-window.c
index c1728f8..7bf9c5d 100644
--- a/src/empathy-call-window.c
+++ b/src/empathy-call-window.c
@@ -604,32 +604,36 @@ empathy_call_window_setup_self_frame (GstBus *bus, EmpathyCallWindow *self)
 static void
 empathy_call_window_setup_video_preview (EmpathyCallWindow *window)
 {
-  GstElement *preview;
   EmpathyCallWindowPriv *priv = GET_PRIV (window);
-  GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
-
-  priv->video_tee = gst_element_factory_make ("tee", NULL);
-  gst_object_ref (priv->video_tee);
-  gst_object_sink (priv->video_tee);
-
-  priv->video_preview = empathy_video_widget_new_with_size (bus,
-      SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
-  g_object_set (priv->video_preview, "sync", FALSE, "async", TRUE, NULL);
-  gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
-      priv->video_preview, TRUE, TRUE, 0);
 
-  g_object_unref (bus);
-
-  preview = empathy_video_widget_get_element (
-      EMPATHY_VIDEO_WIDGET (priv->video_preview));
-  gst_bin_add_many (GST_BIN (priv->pipeline), priv->video_input,
-      priv->video_tee, preview, NULL);
-  gst_element_link_many (priv->video_input, priv->video_tee,
-      preview, NULL);
-
-  gst_element_set_state (preview, GST_STATE_PLAYING);
-  gst_element_set_state (priv->video_input, GST_STATE_PLAYING);
-  gst_element_set_state (priv->video_tee, GST_STATE_PLAYING);
+  if (priv->video_tee == NULL && priv->video_preview == NULL)
+    {
+      GstElement *preview;
+      GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
+
+      priv->video_tee = gst_element_factory_make ("tee", NULL);
+      gst_object_ref (priv->video_tee);
+      gst_object_sink (priv->video_tee);
+
+      priv->video_preview = empathy_video_widget_new_with_size (bus,
+          SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
+      g_object_set (priv->video_preview, "sync", FALSE, "async", TRUE, NULL);
+      gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
+          priv->video_preview, TRUE, TRUE, 0);
+
+      preview = empathy_video_widget_get_element (
+          EMPATHY_VIDEO_WIDGET (priv->video_preview));
+      gst_bin_add_many (GST_BIN (priv->pipeline), priv->video_input,
+          priv->video_tee, preview, NULL);
+      gst_element_link_many (priv->video_input, priv->video_tee,
+          preview, NULL);
+
+      g_object_unref (bus);
+
+      gst_element_set_state (preview, GST_STATE_PLAYING);
+      gst_element_set_state (priv->video_input, GST_STATE_PLAYING);
+      gst_element_set_state (priv->video_tee, GST_STATE_PLAYING);
+    }
 }
 
 static void
@@ -980,9 +984,17 @@ empathy_call_window_class_init (
 
 }
 
+static void
+empathy_call_window_video_stream_changed_cb (EmpathyTpCall *call,
+    GParamSpec *property, EmpathyCallWindow *self)
+{
+  empathy_call_window_update_avatars_visibility (call, self);
+}
+
 void
 empathy_call_window_dispose (GObject *object)
 {
+  EmpathyTpCall *call;
   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
   EmpathyCallWindowPriv *priv = GET_PRIV (self);
 
@@ -991,6 +1003,16 @@ empathy_call_window_dispose (GObject *object)
 
   priv->dispose_has_run = TRUE;
 
+  g_object_get (priv->handler, "tp-call", &call, NULL);
+
+  if (call != NULL)
+    {
+      g_signal_handlers_disconnect_by_func (call,
+        empathy_call_window_video_stream_changed_cb, object);
+    }
+
+  g_object_unref (call);
+
   if (priv->handler != NULL)
     g_object_unref (priv->handler);
 
@@ -1111,6 +1133,8 @@ empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
     {
       priv->liveadder = NULL;
       priv->funnel = NULL;
+      priv->video_preview = NULL;
+      priv->video_tee = NULL;
       g_object_unref (priv->pipeline);
       priv->pipeline = NULL;
 
@@ -1257,6 +1281,9 @@ empathy_call_window_connected (gpointer user_data)
 
   g_object_get (priv->handler, "tp-call", &call, NULL);
 
+  g_signal_connect (call, "notify::video-stream",
+    G_CALLBACK (empathy_call_window_video_stream_changed_cb), self);
+
   if (empathy_tp_call_has_dtmf (call))
     gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
 
@@ -1356,16 +1383,26 @@ empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
       case TP_MEDIA_STREAM_TYPE_VIDEO:
         if (priv->video_input != NULL)
           {
-            if (priv->video_tee == NULL)
-              empathy_call_window_setup_video_preview (self);
+            EmpathyTpCall *call;
+            g_object_get (priv->handler, "tp-call", &call, NULL);
 
-            gtk_toggle_action_set_active (
-                GTK_TOGGLE_ACTION (priv->show_preview),TRUE);
-            gtk_widget_show (priv->video_preview);
-            gtk_widget_hide (priv->self_user_avatar_widget);
+            if (empathy_tp_call_is_sending_video (call))
+              {
+                empathy_call_window_setup_video_preview (self);
+
+                gtk_toggle_action_set_active (
+                    GTK_TOGGLE_ACTION (priv->show_preview),TRUE);
+                gtk_widget_show (priv->video_preview);
+                gtk_widget_hide (priv->self_user_avatar_widget);
+              }
 
-            pad = gst_element_get_request_pad (priv->video_tee, "src%d");
-            gst_pad_link (pad, sink);
+            g_object_unref (call);
+
+            if (priv->video_tee != NULL)
+              {
+                pad = gst_element_get_request_pad (priv->video_tee, "src%d");
+                gst_pad_link (pad, sink);
+              }
           }
         break;
       default:
@@ -1527,26 +1564,15 @@ empathy_call_window_update_avatars_visibility (EmpathyTpCall *call,
         }
       else
         {
-          gtk_widget_hide (priv->video_preview);
+          if (priv->video_preview != NULL)
+            gtk_widget_hide (priv->video_preview);
+
           gtk_widget_show (priv->self_user_avatar_widget);
         }
     }
 }
 
 static void
-empathy_call_window_video_stream_changed_cb (EmpathyCallHandler *handler,
-    EmpathyCallWindow *window)
-{
-  EmpathyTpCall *call;
-  EmpathyCallWindowPriv *priv = GET_PRIV (window);
-
-  g_object_get (priv->handler, "tp-call", &call, NULL);
-
-  empathy_call_window_update_avatars_visibility (call, window);
-  g_object_unref (call);
-}
-
-static void
 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
 {
   EmpathyCallWindowPriv *priv = GET_PRIV (window);
@@ -1561,8 +1587,6 @@ empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
     G_CALLBACK (empathy_call_window_src_added_cb), window);
   g_signal_connect (priv->handler, "sink-pad-added",
     G_CALLBACK (empathy_call_window_sink_added_cb), window);
-  g_signal_connect (priv->handler, "video-stream-changed",
-    G_CALLBACK (empathy_call_window_video_stream_changed_cb), window);
 
   gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
 }
@@ -1726,9 +1750,7 @@ empathy_call_window_set_send_video (EmpathyCallWindow *window,
      default. */
   if (send)
     {
-      if (priv->video_preview == NULL)
-        empathy_call_window_setup_video_preview (window);
-
+      empathy_call_window_setup_video_preview (window);
       gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (priv->show_preview),
           TRUE);
     }
@@ -1857,7 +1879,6 @@ empathy_call_window_restart_call (EmpathyCallWindow *window)
 
   empathy_call_window_setup_remote_frame (bus, window);
   empathy_call_window_setup_self_frame (bus, window);
-  empathy_call_window_setup_video_preview (window);
 
   g_object_unref (bus);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]