static void
update_candidates (EmpathyCallHandler *self,
    FsCandidate *remote_candidate,
    FsCandidate *local_candidate,
    FsStream *stream)
{
  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
  FsSession *session;
  FsMediaType type;

  if (stream == NULL)
    return;

  g_object_get (stream, "session", &session, NULL);
  if (session == NULL)
    return;

  g_object_get (session, "media-type", &type, NULL);

  if (type == FS_MEDIA_TYPE_AUDIO)
    {
      if (remote_candidate != NULL)
        {
          fs_candidate_destroy (priv->audio_remote_candidate);
          priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
          g_object_notify (G_OBJECT (self), "audio-remote-candidate");
        }

      if (local_candidate != NULL)
        {
          fs_candidate_destroy (priv->audio_local_candidate);
          priv->audio_local_candidate = fs_candidate_copy (local_candidate);
          g_object_notify (G_OBJECT (self), "audio-local-candidate");
        }

      g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
          FS_MEDIA_TYPE_AUDIO);
    }
  else if (type == FS_MEDIA_TYPE_VIDEO)
    {
      if (remote_candidate != NULL)
        {
          fs_candidate_destroy (priv->video_remote_candidate);
          priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
          g_object_notify (G_OBJECT (self), "video-remote-candidate");
        }

      if (local_candidate != NULL)
        {
          fs_candidate_destroy (priv->video_local_candidate);
          priv->video_local_candidate = fs_candidate_copy (local_candidate);
          g_object_notify (G_OBJECT (self), "video-local-candidate");
        }

      g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
          FS_MEDIA_TYPE_VIDEO);
    }

  g_object_unref (session);
}
Beispiel #2
0
/**
 * fs_candidate_list_copy:
 * @candidate_list: A GList of #FsCandidate
 *
 * Copies a GList of #FsCandidate and its contents
 *
 * Returns: a new GList of #FsCandidate
 */
GList *
fs_candidate_list_copy (const GList *candidate_list)
{
  GList *copy = NULL;
  const GList *lp;
  FsCandidate *cand;

  for (lp = candidate_list; lp; lp = g_list_next (lp)) {
    cand = (FsCandidate *) lp->data;
    /* prepend then reverse the list for efficiency */
    copy = g_list_prepend (copy, fs_candidate_copy (cand));
  }
  copy= g_list_reverse (copy);
  return copy;
}
Beispiel #3
0
static void
_new_local_candidate (FsStreamTransmitter *st, FsCandidate *candidate,
  gpointer user_data)
{
  GST_DEBUG ("Has local candidate %s:%u of type %d",
    candidate->ip, candidate->port, candidate->type);

  ts_fail_if (candidate == NULL, "Passed NULL candidate");
  ts_fail_unless (candidate->ip != NULL, "Null IP in candidate");
  ts_fail_if (candidate->port == 0, "Candidate has port 0");
  ts_fail_unless (candidate->proto == FS_NETWORK_PROTOCOL_UDP,
    "Protocol is not UDP");
  ts_fail_if (candidate->foundation == NULL,
      "Candidate doenst have a foundation");
  ts_fail_if (candidate->component_id == 0, "Component id is 0");
  if (candidate->type == FS_CANDIDATE_TYPE_HOST)
  {
    ts_fail_if (candidate->base_ip != NULL, "Host candidate has a base ip");
    ts_fail_if (candidate->base_port != 0, "Host candidate has a base port");
  }
  else
  {
    ts_fail_if (candidate->base_ip == NULL, "Candidate doesnt have a base ip");
    ts_fail_if (candidate->base_port == 0, "Candidate doesnt have a base port");
  }
  ts_fail_if (candidate->username == NULL, "Candidate doenst have a username");
  ts_fail_if (candidate->password == NULL, "Candidate doenst have a password");

  GST_DEBUG ("New local candidate %s:%d of type %d for component %d",
    candidate->ip, candidate->port, candidate->type, candidate->component_id);
  GST_DEBUG ("username: %s password: %s", candidate->username,
      candidate->password);

  if (is_address_local)
    ts_fail_unless (!strcmp (candidate->ip, "127.0.0.1"));

  g_object_set_data (G_OBJECT (st), "candidates",
      g_list_append (g_object_get_data (G_OBJECT (st), "candidates"),
          fs_candidate_copy (candidate)));
}
Beispiel #4
0
static void
multicast_init (struct SimpleTestStream *st, guint confid, guint streamid)
{
  GList *candidates = NULL;
  FsCandidate *cand;
  GError *error = NULL;

  cand = fs_candidate_new ("1", FS_COMPONENT_RTP,
      FS_CANDIDATE_TYPE_MULTICAST, FS_NETWORK_PROTOCOL_UDP, "224.0.0.11",
      2324);
  cand->ttl = 1;
  candidates = g_list_prepend (candidates, cand);

  cand = fs_candidate_copy (cand);
  cand->component_id = FS_COMPONENT_RTCP;
  cand->port = 2325;
  candidates = g_list_prepend (candidates, cand);


  ts_fail_unless (fs_stream_force_remote_candidates (st->stream, candidates,
          &error), "Error %s", error ? error->message : "No GError");

  fs_candidate_list_destroy (candidates);
}
gboolean
fs_rawudp_component_set_remote_candidate (FsRawUdpComponent *self,
    FsCandidate *candidate,
    GError **error)
{
  FsCandidate *old_candidate = NULL;
  gboolean sending;
  GInetAddress *addr;

  if (candidate->component_id != self->priv->component)
  {
    g_set_error (error, FS_ERROR, FS_ERROR_INTERNAL,
        "Remote candidate routed to wrong component (%d->%d)",
        candidate->component_id,
        self->priv->component);
    return FALSE;
  }

  addr = g_inet_address_new_from_string (candidate->ip);
  if (addr == NULL)
  {
    g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
        "Invalid address passed: %s", candidate->ip);
    return FALSE;
  }

  FS_RAWUDP_COMPONENT_LOCK (self);

  if (!self->priv->udpport)
  {
    g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
        "Can't call set_remote_candidate after the thread has been stopped");
    FS_RAWUDP_COMPONENT_UNLOCK (self);
    g_object_unref (addr);
    return FALSE;
  }

  if (self->priv->remote_candidate)
    fs_rawudp_transmitter_udpport_remove_known_address (self->priv->udpport,
        self->priv->remote_address, remote_is_unique_cb, self);

  old_candidate = self->priv->remote_candidate;
  self->priv->remote_candidate = fs_candidate_copy (candidate);
  sending = self->priv->sending;

  g_clear_object (&self->priv->remote_address);

  self->priv->remote_address = g_inet_socket_address_new (addr,
      candidate->port);
  g_object_unref (addr);

  self->priv->remote_is_unique =
    fs_rawudp_transmitter_udpport_add_known_address (self->priv->udpport,
        self->priv->remote_address, remote_is_unique_cb, self);

  FS_RAWUDP_COMPONENT_UNLOCK (self);

  if (sending)
    fs_rawudp_transmitter_udpport_add_dest (self->priv->udpport,
        candidate->ip, candidate->port);
  else
    fs_rawudp_transmitter_udpport_add_recvonly_dest (self->priv->udpport,
        candidate->ip, candidate->port);

  if (old_candidate)
  {
    if (sending)
      fs_rawudp_transmitter_udpport_remove_dest (self->priv->udpport,
          old_candidate->ip,
          old_candidate->port);
    else
      fs_rawudp_transmitter_udpport_remove_recvonly_dest (self->priv->udpport,
          candidate->ip,
          candidate->port);
    fs_candidate_destroy (old_candidate);
  }

  fs_rawudp_component_maybe_new_active_candidate_pair (self);

  return TRUE;
}
static void
fs_rawudp_component_set_property (GObject *object,
    guint prop_id,
    const GValue *value,
    GParamSpec *pspec)
{
  FsRawUdpComponent *self = FS_RAWUDP_COMPONENT (object);

  switch (prop_id)
  {
    case PROP_COMPONENT:
      self->priv->component = g_value_get_uint (value);
      break;
    case PROP_SENDING:
      {
        gboolean sending, old_sending;
        FsCandidate *candidate = NULL;

        g_return_if_fail (self->priv->udpport);


        FS_RAWUDP_COMPONENT_LOCK (self);
        old_sending = self->priv->sending;
        sending = self->priv->sending = g_value_get_boolean (value);
        if (self->priv->remote_candidate)
          candidate = fs_candidate_copy (self->priv->remote_candidate);
        FS_RAWUDP_COMPONENT_UNLOCK (self);

        if (sending != old_sending && candidate)
        {
          if (sending)
          {
            fs_rawudp_transmitter_udpport_remove_recvonly_dest (
                self->priv->udpport, candidate->ip, candidate->port);
            fs_rawudp_transmitter_udpport_add_dest (self->priv->udpport,
                candidate->ip, candidate->port);
          }
          else
          {
            fs_rawudp_transmitter_udpport_remove_dest (self->priv->udpport,
                candidate->ip, candidate->port);
            fs_rawudp_transmitter_udpport_add_recvonly_dest (
                self->priv->udpport, candidate->ip, candidate->port);
          }
        }
        if (candidate)
          fs_candidate_destroy (candidate);
      }
      break;
    case PROP_IP:
      g_free (self->priv->ip);
      self->priv->ip = g_value_dup_string (value);
      break;
    case PROP_PORT:
      self->priv->port = g_value_get_uint (value);
      break;
    case PROP_STUN_IP:
      g_free (self->priv->stun_ip);
      self->priv->stun_ip = g_value_dup_string (value);
      break;
    case PROP_STUN_PORT:
      self->priv->stun_port = g_value_get_uint (value);
      break;
    case PROP_STUN_TIMEOUT:
      self->priv->stun_timeout = g_value_get_uint (value);
      break;
    case PROP_TRANSMITTER:
      self->priv->transmitter = g_value_dup_object (value);
      break;
    case PROP_FORCED_CANDIDATE:
      FS_RAWUDP_COMPONENT_LOCK (self);
      if (self->priv->local_forced_candidate)
        GST_WARNING ("Tried to reset a forced candidate");
      else
        self->priv->local_forced_candidate = g_value_dup_boxed (value);
      FS_RAWUDP_COMPONENT_UNLOCK (self);
      break;
    case PROP_ASSOCIATE_ON_SOURCE:
      self->priv->associate_on_source = g_value_get_boolean (value);
      break;
#ifdef HAVE_GUPNP
    case PROP_UPNP_MAPPING:
      self->priv->upnp_mapping = g_value_get_boolean (value);
      break;
    case PROP_UPNP_DISCOVERY:
      self->priv->upnp_discovery = g_value_get_boolean (value);
      break;
    case PROP_UPNP_MAPPING_TIMEOUT:
      self->priv->upnp_mapping_timeout = g_value_get_uint (value);
      break;
    case PROP_UPNP_DISCOVERY_TIMEOUT:
      self->priv->upnp_discovery_timeout = g_value_get_uint (value);
      break;
    case PROP_UPNP_IGD:
      self->priv->upnp_igd = g_value_dup_object (value);
      break;
#endif
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}