]> git.0d.be Git - empathy.git/blob - libempathy/empathy-tp-call.c
add myself to AUTHORS
[empathy.git] / libempathy / empathy-tp-call.c
1 /*
2  * Copyright (C) 2007 Elliot Fairweather
3  * Copyright (C) 2007-2008 Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * Authors: Elliot Fairweather <elliot.fairweather@collabora.co.uk>
20  *          Xavier Claessens <xclaesse@gmail.com>
21  */
22
23 #include <string.h>
24
25 #include <telepathy-glib/proxy-subclass.h>
26 #include <telepathy-glib/dbus.h>
27 #include <telepathy-glib/interfaces.h>
28
29 #include "empathy-tp-call.h"
30 #include "empathy-tp-contact-factory.h"
31 #include "empathy-utils.h"
32 #include "empathy-marshal.h"
33
34 #define DEBUG_FLAG EMPATHY_DEBUG_TP
35 #include "empathy-debug.h"
36
37 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpCall)
38 typedef struct
39 {
40   gboolean dispose_has_run;
41   TpChannel *channel;
42   EmpathyContact *contact;
43   gboolean is_incoming;
44   guint status;
45
46   EmpathyTpCallStream *audio;
47   EmpathyTpCallStream *video;
48 } EmpathyTpCallPriv;
49
50 /* signal enum */
51 enum {
52   AUDIO_STREAM_ERROR,
53   VIDEO_STREAM_ERROR,
54   LAST_SIGNAL
55 };
56
57 static guint signals[LAST_SIGNAL] = {0};
58
59 enum
60 {
61   PROP_0,
62   PROP_CHANNEL,
63   PROP_CONTACT,
64   PROP_IS_INCOMING,
65   PROP_STATUS,
66   PROP_AUDIO_STREAM,
67   PROP_VIDEO_STREAM
68 };
69
70 G_DEFINE_TYPE (EmpathyTpCall, empathy_tp_call, G_TYPE_OBJECT)
71
72 static void
73 tp_call_add_stream (EmpathyTpCall *call,
74                     guint stream_id,
75                     guint contact_handle,
76                     guint stream_type,
77                     guint stream_state,
78                     guint stream_direction)
79 {
80   EmpathyTpCallPriv *priv = GET_PRIV (call);
81
82   switch (stream_type)
83     {
84       case TP_MEDIA_STREAM_TYPE_AUDIO:
85         DEBUG ("Audio stream - id: %d, state: %d, direction: %d",
86             stream_id, stream_state, stream_direction);
87         priv->audio->exists = TRUE;
88         priv->audio->id = stream_id;
89         priv->audio->state = stream_state;
90         priv->audio->direction = stream_direction;
91         g_object_notify (G_OBJECT (call), "audio-stream");
92         break;
93       case TP_MEDIA_STREAM_TYPE_VIDEO:
94         DEBUG ("Video stream - id: %d, state: %d, direction: %d",
95             stream_id, stream_state, stream_direction);
96         priv->video->exists = TRUE;
97         priv->video->id = stream_id;
98         priv->video->state = stream_state;
99         priv->video->direction = stream_direction;
100         g_object_notify (G_OBJECT (call), "video-stream");
101         break;
102       default:
103         DEBUG ("Unknown stream type: %d", stream_type);
104     }
105 }
106
107 static void
108 tp_call_stream_added_cb (TpChannel *channel,
109                          guint stream_id,
110                          guint contact_handle,
111                          guint stream_type,
112                          gpointer user_data,
113                          GObject *call)
114 {
115   DEBUG ("Stream added - stream id: %d, contact handle: %d, stream type: %d",
116       stream_id, contact_handle, stream_type);
117
118   tp_call_add_stream (EMPATHY_TP_CALL (call), stream_id, contact_handle,
119       stream_type, TP_MEDIA_STREAM_STATE_DISCONNECTED,
120       TP_MEDIA_STREAM_DIRECTION_NONE);
121 }
122
123 static void
124 tp_call_stream_removed_cb (TpChannel *channel,
125                            guint stream_id,
126                            gpointer user_data,
127                            GObject *call)
128 {
129   EmpathyTpCallPriv *priv = GET_PRIV (call);
130
131   DEBUG ("Stream removed - stream id: %d", stream_id);
132
133   if (stream_id == priv->audio->id)
134     {
135       priv->audio->exists = FALSE;
136       g_object_notify (call, "audio-stream");
137     }
138   else if (stream_id == priv->video->id)
139     {
140       priv->video->exists = FALSE;
141       g_object_notify (call, "video-stream");
142     }
143 }
144
145 static void
146 tp_call_stream_state_changed_cb (TpChannel *proxy,
147                                  guint stream_id,
148                                  guint stream_state,
149                                  gpointer user_data,
150                                  GObject *call)
151 {
152   EmpathyTpCallPriv *priv = GET_PRIV (call);
153
154   DEBUG ("Stream state changed - stream id: %d, state state: %d",
155       stream_id, stream_state);
156
157   if (stream_id == priv->audio->id)
158     {
159       priv->audio->state = stream_state;
160       g_object_notify (call, "audio-stream");
161     }
162   else if (stream_id == priv->video->id)
163     {
164       priv->video->state = stream_state;
165       g_object_notify (call, "video-stream");
166     }
167 }
168
169 static void
170 tp_call_stream_direction_changed_cb (TpChannel *channel,
171                                      guint stream_id,
172                                      guint stream_direction,
173                                      guint pending_flags,
174                                      gpointer user_data,
175                                      GObject *call)
176 {
177   EmpathyTpCallPriv *priv = GET_PRIV (call);
178
179   DEBUG ("Stream direction changed - stream: %d, direction: %d",
180       stream_id, stream_direction);
181
182   if (stream_id == priv->audio->id)
183     {
184       priv->audio->direction = stream_direction;
185       g_object_notify (call, "audio-stream");
186     }
187   else if (stream_id == priv->video->id)
188     {
189       priv->video->direction = stream_direction;
190       g_object_notify (call, "video-stream");
191     }
192 }
193
194 static void
195 tp_call_request_streams_cb (TpChannel *channel,
196                             const GPtrArray *streams,
197                             const GError *error,
198                             gpointer user_data,
199                             GObject *call)
200 {
201   guint i;
202
203   if (error)
204     {
205       DEBUG ("Error requesting streams: %s", error->message);
206       return;
207     }
208
209   for (i = 0; i < streams->len; i++)
210     {
211       GValueArray *values;
212       guint stream_id;
213       guint contact_handle;
214       guint stream_type;
215       guint stream_state;
216       guint stream_direction;
217
218       values = g_ptr_array_index (streams, i);
219       stream_id = g_value_get_uint (g_value_array_get_nth (values, 0));
220       contact_handle = g_value_get_uint (g_value_array_get_nth (values, 1));
221       stream_type = g_value_get_uint (g_value_array_get_nth (values, 2));
222       stream_state = g_value_get_uint (g_value_array_get_nth (values, 3));
223       stream_direction = g_value_get_uint (g_value_array_get_nth (values, 4));
224
225       tp_call_add_stream (EMPATHY_TP_CALL (call), stream_id, contact_handle,
226           stream_type, stream_state, stream_direction);
227   }
228 }
229
230 static void
231 tp_call_request_streams_for_capabilities (EmpathyTpCall *call,
232                                           EmpathyCapabilities capabilities)
233 {
234   EmpathyTpCallPriv *priv = GET_PRIV (call);
235   GArray *stream_types;
236   guint handle;
237   guint stream_type;
238
239   if (capabilities == EMPATHY_CAPABILITIES_UNKNOWN)
240       capabilities = EMPATHY_CAPABILITIES_AUDIO | EMPATHY_CAPABILITIES_VIDEO;
241
242   DEBUG ("Requesting new stream for capabilities %d",
243       capabilities);
244
245   stream_types = g_array_new (FALSE, FALSE, sizeof (guint));
246   handle = empathy_contact_get_handle (priv->contact);
247
248   if (capabilities & EMPATHY_CAPABILITIES_AUDIO)
249     {
250       stream_type = TP_MEDIA_STREAM_TYPE_AUDIO;
251       g_array_append_val (stream_types, stream_type);
252     }
253   if (capabilities & EMPATHY_CAPABILITIES_VIDEO)
254     {
255       stream_type = TP_MEDIA_STREAM_TYPE_VIDEO;
256       g_array_append_val (stream_types, stream_type);
257     }
258
259   tp_cli_channel_type_streamed_media_call_request_streams (priv->channel, -1,
260       handle, stream_types, tp_call_request_streams_cb, NULL, NULL,
261       G_OBJECT (call));
262
263   g_array_free (stream_types, TRUE);
264 }
265
266 static void
267 tp_call_got_contact_cb (EmpathyTpContactFactory *factory,
268                         EmpathyContact          *contact,
269                         const GError            *error,
270                         gpointer                 user_data,
271                         GObject                 *call)
272 {
273   EmpathyTpCallPriv *priv = GET_PRIV (call);
274
275   if (error)
276     {
277       DEBUG ("Error: %s", error->message);
278       return;
279     }
280
281   priv->contact = g_object_ref (contact);
282   priv->is_incoming = TRUE;
283   priv->status = EMPATHY_TP_CALL_STATUS_PENDING;
284   g_object_notify (G_OBJECT (call), "is-incoming");
285   g_object_notify (G_OBJECT (call), "contact");
286   g_object_notify (G_OBJECT (call), "status");
287 }
288
289 static void
290 tp_call_update_status (EmpathyTpCall *call)
291 {
292   EmpathyTpCallPriv *priv = GET_PRIV (call);
293   TpHandle self_handle;
294   const TpIntSet *set;
295   TpIntSetIter iter;
296
297   g_object_ref (call);
298
299   self_handle = tp_channel_group_get_self_handle (priv->channel);
300   set = tp_channel_group_get_members (priv->channel);
301   tp_intset_iter_init (&iter, set);
302   while (tp_intset_iter_next (&iter))
303     {
304       if (priv->contact == NULL && iter.element != self_handle)
305         {
306           EmpathyTpContactFactory *factory;
307           TpConnection *connection;
308
309           /* We found the remote contact */
310           connection = tp_channel_borrow_connection (priv->channel);
311           factory = empathy_tp_contact_factory_dup_singleton (connection);
312           empathy_tp_contact_factory_get_from_handle (factory, iter.element,
313               tp_call_got_contact_cb, NULL, NULL, G_OBJECT (call));
314           g_object_unref (factory);
315         }
316
317       if (priv->status == EMPATHY_TP_CALL_STATUS_PENDING &&
318           ((priv->is_incoming && iter.element == self_handle) ||
319            (!priv->is_incoming && iter.element != self_handle)))
320         {
321           priv->status = EMPATHY_TP_CALL_STATUS_ACCEPTED;
322           g_object_notify (G_OBJECT (call), "status");
323         }
324     }
325
326   g_object_unref (call);
327 }
328
329 void
330 empathy_tp_call_to (EmpathyTpCall *call, EmpathyContact *contact,
331   gboolean audio, gboolean video)
332 {
333   EmpathyTpCallPriv *priv = GET_PRIV (call);
334   EmpathyCapabilities capabilities = 0;
335
336   g_assert (audio || video);
337
338   priv->contact = g_object_ref (contact);
339   priv->is_incoming = FALSE;
340   priv->status = EMPATHY_TP_CALL_STATUS_PENDING;
341   g_object_notify (G_OBJECT (call), "is-incoming");
342   g_object_notify (G_OBJECT (call), "contact");
343   g_object_notify (G_OBJECT (call), "status");
344
345   if (video)
346     capabilities |= EMPATHY_CAPABILITIES_VIDEO;
347   if (audio)
348     capabilities |= EMPATHY_CAPABILITIES_AUDIO;
349
350   tp_call_request_streams_for_capabilities (call, capabilities);
351 }
352
353 static void
354 tp_call_channel_invalidated_cb (TpChannel     *channel,
355                                 GQuark         domain,
356                                 gint           code,
357                                 gchar         *message,
358                                 EmpathyTpCall *call)
359 {
360   EmpathyTpCallPriv *priv = GET_PRIV (call);
361
362   DEBUG ("Channel invalidated: %s", message);
363   priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
364   g_object_notify (G_OBJECT (call), "status");
365 }
366
367 static void
368 tp_call_async_cb (TpProxy *proxy,
369                   const GError *error,
370                   gpointer user_data,
371                   GObject *call)
372 {
373   if (error)
374       DEBUG ("Error %s: %s", (gchar *) user_data, error->message);
375 }
376
377 static void
378 tp_call_stream_error_cb (TpChannel *channel,
379     guint stream_id,
380     guint error_code,
381     const gchar *msg,
382     gpointer user_data,
383     GObject *call)
384 {
385   EmpathyTpCall *self = EMPATHY_TP_CALL (call);
386   EmpathyTpCallPriv *priv = GET_PRIV (self);
387
388   DEBUG ("Stream error on stream %u: %s (code: %u)", stream_id, msg,
389       error_code);
390
391   if (priv->audio->id == stream_id)
392     {
393       g_signal_emit (call, signals[AUDIO_STREAM_ERROR], 0, error_code, msg);
394     }
395   else if (priv->video->id == stream_id)
396     {
397       g_signal_emit (call, signals[VIDEO_STREAM_ERROR], 0, error_code, msg);
398     }
399   else
400     {
401       DEBUG ("Unknown stream id: %u", stream_id);
402     }
403 }
404
405 static GObject *
406 tp_call_constructor (GType type,
407                      guint n_construct_params,
408                      GObjectConstructParam *construct_params)
409 {
410   GObject *object;
411   EmpathyTpCall *call;
412   EmpathyTpCallPriv *priv;
413
414   object = G_OBJECT_CLASS (empathy_tp_call_parent_class)->constructor (type,
415       n_construct_params, construct_params);
416
417   call = EMPATHY_TP_CALL (object);
418   priv = GET_PRIV (call);
419
420   /* Setup streamed media channel */
421   g_signal_connect (priv->channel, "invalidated",
422       G_CALLBACK (tp_call_channel_invalidated_cb), call);
423   tp_cli_channel_type_streamed_media_connect_to_stream_added (priv->channel,
424       tp_call_stream_added_cb, NULL, NULL, G_OBJECT (call), NULL);
425   tp_cli_channel_type_streamed_media_connect_to_stream_removed (priv->channel,
426       tp_call_stream_removed_cb, NULL, NULL, G_OBJECT (call), NULL);
427   tp_cli_channel_type_streamed_media_connect_to_stream_state_changed (priv->channel,
428       tp_call_stream_state_changed_cb, NULL, NULL, G_OBJECT (call), NULL);
429   tp_cli_channel_type_streamed_media_connect_to_stream_direction_changed (priv->channel,
430       tp_call_stream_direction_changed_cb, NULL, NULL, G_OBJECT (call), NULL);
431   tp_cli_channel_type_streamed_media_connect_to_stream_error (priv->channel,
432       tp_call_stream_error_cb, NULL, NULL, G_OBJECT (call), NULL);
433   tp_cli_channel_type_streamed_media_call_list_streams (priv->channel, -1,
434       tp_call_request_streams_cb, NULL, NULL, G_OBJECT (call));
435
436   /* Update status when members changes */
437   tp_call_update_status (call);
438   g_signal_connect_swapped (priv->channel, "group-members-changed",
439       G_CALLBACK (tp_call_update_status), call);
440
441   return object;
442 }
443 static void
444 tp_call_dispose (GObject *object)
445 {
446   EmpathyTpCallPriv *priv = GET_PRIV (object);
447
448   DEBUG ("Disposing: %p, %d", object, priv->dispose_has_run);
449
450   if (priv->dispose_has_run)
451     return;
452
453   priv->dispose_has_run = TRUE;
454
455   if (priv->channel != NULL)
456     {
457       g_signal_handlers_disconnect_by_func (priv->channel,
458         tp_call_channel_invalidated_cb, object);
459
460       g_object_unref (priv->channel);
461       priv->channel = NULL;
462     }
463
464   if (priv->contact != NULL)
465       g_object_unref (priv->contact);
466
467   if (G_OBJECT_CLASS (empathy_tp_call_parent_class)->dispose)
468     G_OBJECT_CLASS (empathy_tp_call_parent_class)->dispose (object);
469 }
470
471 static void
472 tp_call_finalize (GObject *object)
473 {
474   EmpathyTpCallPriv *priv = GET_PRIV (object);
475
476   DEBUG ("Finalizing: %p", object);
477
478   g_slice_free (EmpathyTpCallStream, priv->audio);
479   g_slice_free (EmpathyTpCallStream, priv->video);
480
481   (G_OBJECT_CLASS (empathy_tp_call_parent_class)->finalize) (object);
482 }
483
484 static void
485 tp_call_set_property (GObject *object,
486                       guint prop_id,
487                       const GValue *value,
488                       GParamSpec *pspec)
489 {
490   EmpathyTpCallPriv *priv = GET_PRIV (object);
491
492   switch (prop_id)
493     {
494     case PROP_CHANNEL:
495       priv->channel = g_value_dup_object (value);
496       break;
497     default:
498       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
499       break;
500   }
501 }
502
503 static void
504 tp_call_get_property (GObject *object,
505                       guint prop_id,
506                       GValue *value,
507                       GParamSpec *pspec)
508 {
509   EmpathyTpCallPriv *priv = GET_PRIV (object);
510
511   switch (prop_id)
512     {
513     case PROP_CHANNEL:
514       g_value_set_object (value, priv->channel);
515       break;
516     case PROP_CONTACT:
517       g_value_set_object (value, priv->contact);
518       break;
519     case PROP_IS_INCOMING:
520       g_value_set_boolean (value, priv->is_incoming);
521       break;
522     case PROP_STATUS:
523       g_value_set_uint (value, priv->status);
524       break;
525     case PROP_AUDIO_STREAM:
526       g_value_set_pointer (value, priv->audio);
527       break;
528     case PROP_VIDEO_STREAM:
529       g_value_set_pointer (value, priv->video);
530       break;
531     default:
532       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
533       break;
534   }
535 }
536
537 static void
538 empathy_tp_call_class_init (EmpathyTpCallClass *klass)
539 {
540   GObjectClass *object_class = G_OBJECT_CLASS (klass);
541
542   object_class->constructor = tp_call_constructor;
543   object_class->dispose = tp_call_dispose;
544   object_class->finalize = tp_call_finalize;
545   object_class->set_property = tp_call_set_property;
546   object_class->get_property = tp_call_get_property;
547
548   g_type_class_add_private (klass, sizeof (EmpathyTpCallPriv));
549
550   g_object_class_install_property (object_class, PROP_CHANNEL,
551       g_param_spec_object ("channel", "channel", "channel",
552       TP_TYPE_CHANNEL,
553       G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
554       G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
555   g_object_class_install_property (object_class, PROP_CONTACT,
556       g_param_spec_object ("contact", "Call contact", "Call contact",
557       EMPATHY_TYPE_CONTACT,
558       G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
559   g_object_class_install_property (object_class, PROP_IS_INCOMING,
560       g_param_spec_boolean ("is-incoming", "Is media stream incoming",
561       "Is media stream incoming", FALSE, G_PARAM_READABLE |
562       G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
563   g_object_class_install_property (object_class, PROP_STATUS,
564       g_param_spec_uint ("status", "Call status",
565       "Call status", 0, 255, 0, G_PARAM_READABLE | G_PARAM_STATIC_NICK |
566       G_PARAM_STATIC_BLURB));
567   g_object_class_install_property (object_class, PROP_AUDIO_STREAM,
568       g_param_spec_pointer ("audio-stream", "Audio stream data",
569       "Audio stream data",
570       G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
571   g_object_class_install_property (object_class, PROP_VIDEO_STREAM,
572       g_param_spec_pointer ("video-stream", "Video stream data",
573       "Video stream data",
574       G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
575
576   signals[AUDIO_STREAM_ERROR] =
577     g_signal_new ("audio-stream-error",
578       G_TYPE_FROM_CLASS (klass),
579       G_SIGNAL_RUN_LAST, 0,
580       NULL, NULL,
581       _empathy_marshal_VOID__UINT_STRING,
582       G_TYPE_NONE,
583       2, G_TYPE_UINT, G_TYPE_STRING);
584
585   signals[VIDEO_STREAM_ERROR] =
586     g_signal_new ("video-stream-error",
587       G_TYPE_FROM_CLASS (klass),
588       G_SIGNAL_RUN_LAST, 0,
589       NULL, NULL,
590       _empathy_marshal_VOID__UINT_STRING,
591       G_TYPE_NONE,
592       2, G_TYPE_UINT, G_TYPE_STRING);
593 }
594
595 static void
596 empathy_tp_call_init (EmpathyTpCall *call)
597 {
598   EmpathyTpCallPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (call,
599     EMPATHY_TYPE_TP_CALL, EmpathyTpCallPriv);
600
601   call->priv = priv;
602   priv->status = EMPATHY_TP_CALL_STATUS_READYING;
603   priv->contact = NULL;
604   priv->audio = g_slice_new0 (EmpathyTpCallStream);
605   priv->video = g_slice_new0 (EmpathyTpCallStream);
606   priv->audio->exists = FALSE;
607   priv->video->exists = FALSE;
608 }
609
610 EmpathyTpCall *
611 empathy_tp_call_new (TpChannel *channel)
612 {
613   g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);
614
615   return g_object_new (EMPATHY_TYPE_TP_CALL,
616       "channel", channel,
617       NULL);
618 }
619
620 void
621 empathy_tp_call_accept_incoming_call (EmpathyTpCall *call)
622 {
623   EmpathyTpCallPriv *priv = GET_PRIV (call);
624   TpHandle self_handle;
625   GArray handles = {(gchar *) &self_handle, 1};
626
627   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
628   g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_PENDING);
629   g_return_if_fail (priv->is_incoming);
630
631   DEBUG ("Accepting incoming call");
632
633   self_handle = tp_channel_group_get_self_handle (priv->channel);
634   tp_cli_channel_interface_group_call_add_members (priv->channel, -1,
635       &handles, NULL, NULL, NULL, NULL, NULL);
636 }
637
638 void
639 empathy_tp_call_close (EmpathyTpCall *call)
640 {
641   EmpathyTpCallPriv *priv = GET_PRIV (call);
642
643   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
644
645   if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
646       return;
647
648   DEBUG ("Closing channel");
649
650   tp_cli_channel_call_close (priv->channel, -1,
651       NULL, NULL, NULL, NULL);
652
653   priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
654   g_object_notify (G_OBJECT (call), "status");
655 }
656
657 void
658 empathy_tp_call_request_video_stream_direction (EmpathyTpCall *call,
659                                                 gboolean is_sending)
660 {
661   EmpathyTpCallPriv *priv = GET_PRIV (call);
662   guint new_direction;
663
664   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
665   g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_ACCEPTED);
666
667   DEBUG ("Requesting video stream direction - is_sending: %d", is_sending);
668
669   if (!priv->video->exists)
670     {
671       if (is_sending)
672           tp_call_request_streams_for_capabilities (call,
673               EMPATHY_CAPABILITIES_VIDEO);
674       return;
675     }
676
677   if (is_sending)
678       new_direction = priv->video->direction | TP_MEDIA_STREAM_DIRECTION_SEND;
679   else
680       new_direction = priv->video->direction & ~TP_MEDIA_STREAM_DIRECTION_SEND;
681
682   tp_cli_channel_type_streamed_media_call_request_stream_direction (priv->channel,
683       -1, priv->video->id, new_direction,
684       (tp_cli_channel_type_streamed_media_callback_for_request_stream_direction)
685       tp_call_async_cb, NULL, NULL, G_OBJECT (call));
686 }
687
688 void
689 empathy_tp_call_start_tone (EmpathyTpCall *call, TpDTMFEvent event)
690 {
691   EmpathyTpCallPriv *priv = GET_PRIV (call);
692
693   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
694   g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_ACCEPTED);
695
696   if (!priv->audio->exists)
697       return;
698
699   tp_cli_channel_interface_dtmf_call_start_tone (priv->channel, -1,
700       priv->audio->id, event,
701       (tp_cli_channel_interface_dtmf_callback_for_start_tone) tp_call_async_cb,
702       "starting tone", NULL, G_OBJECT (call));
703 }
704
705 void
706 empathy_tp_call_stop_tone (EmpathyTpCall *call)
707 {
708   EmpathyTpCallPriv *priv = GET_PRIV (call);
709
710   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
711   g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_ACCEPTED);
712
713   if (!priv->audio->exists)
714       return;
715
716   tp_cli_channel_interface_dtmf_call_stop_tone (priv->channel, -1,
717       priv->audio->id,
718       (tp_cli_channel_interface_dtmf_callback_for_stop_tone) tp_call_async_cb,
719       "stoping tone", NULL, G_OBJECT (call));
720 }
721
722 gboolean
723 empathy_tp_call_has_dtmf (EmpathyTpCall *call)
724 {
725   EmpathyTpCallPriv *priv = GET_PRIV (call);
726
727   g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), FALSE);
728
729   return tp_proxy_has_interface_by_id (priv->channel,
730       TP_IFACE_QUARK_CHANNEL_INTERFACE_DTMF);
731 }
732
733 /**
734  * empathy_tp_call_is_receiving_video:
735  * @call: the call
736  *
737  * Indicates if the call is receiving video or not.
738  *
739  * Returns: %TRUE if the call is currently receiving video, %FALSE otherwise.
740  */
741 gboolean
742 empathy_tp_call_is_receiving_video (EmpathyTpCall *call)
743 {
744   EmpathyTpCallPriv *priv = GET_PRIV (call);
745
746   g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), FALSE);
747
748   if (!priv->video->exists)
749     return FALSE;
750
751   return priv->video->direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE ?
752       TRUE : FALSE;
753 }
754
755 /**
756  * empathy_tp_call_is_sending_video:
757  * @call: the call
758  *
759  * Indicates if the call is sending video or not.
760  *
761  * Returns: %TRUE if the call is currently sending video, %FALSE otherwise.
762  */
763 gboolean
764 empathy_tp_call_is_sending_video (EmpathyTpCall *call)
765 {
766   EmpathyTpCallPriv *priv = GET_PRIV (call);
767
768   g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), FALSE);
769
770   if (!priv->video->exists)
771     return FALSE;
772
773   return priv->video->direction & TP_MEDIA_STREAM_DIRECTION_SEND ?
774       TRUE : FALSE;
775 }
776
777 const gchar *
778 empathy_tp_call_get_connection_manager (EmpathyTpCall *self)
779 {
780   EmpathyTpCallPriv *priv = GET_PRIV (self);
781   TpConnection *conn;
782   TpAccount *account;
783
784   if (priv->channel == NULL)
785     return NULL;
786
787   conn = tp_channel_borrow_connection (priv->channel);
788   if (conn == NULL)
789     return NULL;
790
791   account = empathy_get_account_for_connection (conn);
792   if (account == NULL)
793     return NULL;
794
795   return tp_account_get_connection_manager (account);
796 }