static void
test_gupnp_simple_igd_thread (void)
{
  GUPnPSimpleIgdThread *igd = gupnp_simple_igd_thread_new ();
  GMainContext *mainctx = g_main_context_new ();

  run_gupnp_simple_igd_test (mainctx, GUPNP_SIMPLE_IGD (igd), INTERNAL_PORT);
  g_object_unref (igd);
  g_main_context_unref (mainctx);
}
static void
test_gupnp_simple_igd_dispose_removes_thread (void)
{
  GUPnPSimpleIgdThread *igd = gupnp_simple_igd_thread_new ();
  GMainContext *mainctx = g_main_context_new ();

  dispose_removes = TRUE;
  run_gupnp_simple_igd_test (mainctx, GUPNP_SIMPLE_IGD (igd), INTERNAL_PORT);
  dispose_removes = FALSE;
  g_main_context_unref (mainctx);
}
Example #3
0
void
fs_rawudp_component_stop (FsRawUdpComponent *self)
{
  UdpPort *udpport = NULL;

  FS_RAWUDP_COMPONENT_LOCK (self);
  if (self->priv->stun_timeout_thread != NULL)
  {
    fs_rawudp_component_stop_stun_locked (self);
    FS_RAWUDP_COMPONENT_UNLOCK (self);
    g_thread_join (self->priv->stun_timeout_thread);
    FS_RAWUDP_COMPONENT_LOCK (self);

    self->priv->stun_timeout_thread = NULL;
  }

  udpport = self->priv->udpport;
  self->priv->udpport = NULL;

  if (udpport)
  {
#ifdef HAVE_GUPNP

    fs_rawudp_component_stop_upnp_discovery_locked (self);

    if (self->priv->upnp_igd  &&
        (self->priv->upnp_mapping || self->priv->upnp_discovery))
    {
      gupnp_simple_igd_remove_port (GUPNP_SIMPLE_IGD (self->priv->upnp_igd),
          "UDP", fs_rawudp_transmitter_udpport_get_port (udpport));
    }
#endif

    if (self->priv->buffer_recv_id)
    {
      fs_rawudp_transmitter_udpport_disconnect_recv (
          udpport,
          self->priv->buffer_recv_id);
      self->priv->buffer_recv_id = 0;
    }

    if (self->priv->remote_candidate)
    {
      if (self->priv->sending)
        fs_rawudp_transmitter_udpport_remove_dest (udpport,
            self->priv->remote_candidate->ip,
            self->priv->remote_candidate->port);
      else
        fs_rawudp_transmitter_udpport_remove_recvonly_dest (udpport,
            self->priv->remote_candidate->ip,
            self->priv->remote_candidate->port);


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

    FS_RAWUDP_COMPONENT_UNLOCK (self);

    fs_rawudp_transmitter_put_udpport (self->priv->transmitter, udpport);
  }
  else
    FS_RAWUDP_COMPONENT_UNLOCK (self);
}
Example #4
0
gboolean
fs_rawudp_component_gather_local_candidates (FsRawUdpComponent *self,
    GError **error)
{
  if (self->priv->gathered)
  {
    g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
        "Call gather local candidates twice on the same component");
    return FALSE;
  }

  if (!self->priv->udpport)
  {   g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
        "You can not call gather_local_candidate() after the stream has"
        " been stopped");
    return FALSE;
  }

#ifdef HAVE_GUPNP

  if (self->priv->upnp_igd  &&
      (self->priv->upnp_mapping || self->priv->upnp_discovery))
  {
    guint port;
    GList *ips;

    port = fs_rawudp_transmitter_udpport_get_port (self->priv->udpport);

    ips = nice_interfaces_get_local_ips (FALSE);
    ips = filter_ips (ips, TRUE, FALSE);

    if (ips)
    {
      gchar *ip = g_list_first (ips)->data;
      GMainContext *ctx;

      if (self->priv->upnp_discovery)
      {
        FS_RAWUDP_COMPONENT_LOCK (self);
        self->priv->upnp_signal_id = g_signal_connect (self->priv->upnp_igd,
            "mapped-external-port",
            G_CALLBACK (_upnp_mapped_external_port), self);
        FS_RAWUDP_COMPONENT_UNLOCK (self);
      }

      GST_DEBUG ("Doing UPnP Discovery for local ip:%s port:%u", ip, port);

      gupnp_simple_igd_add_port (GUPNP_SIMPLE_IGD (self->priv->upnp_igd),
          "UDP", port, ip, port, self->priv->upnp_mapping_timeout,
          "Farstream Raw UDP transmitter " PACKAGE_VERSION);


      if (self->priv->upnp_discovery)
      {
        FS_RAWUDP_COMPONENT_LOCK (self);
        self->priv->upnp_discovery_timeout_src = g_timeout_source_new_seconds (
            self->priv->upnp_discovery_timeout);
        g_source_set_callback (self->priv->upnp_discovery_timeout_src,
            _upnp_discovery_timeout, self, NULL);
        g_object_get (self->priv->upnp_igd, "main-context", &ctx, NULL);
        g_source_attach (self->priv->upnp_discovery_timeout_src, ctx);
        FS_RAWUDP_COMPONENT_UNLOCK (self);
      }
    }
    else
    {
      FS_RAWUDP_COMPONENT_LOCK (self);
      fs_rawudp_component_stop_upnp_discovery_locked (self);
      FS_RAWUDP_COMPONENT_UNLOCK (self);
    }

    /* free list of ips */
    g_list_foreach (ips, (GFunc) g_free, NULL);
    g_list_free (ips);

  }
#endif

  if (self->priv->stun_ip)
    return fs_rawudp_component_start_stun (self, error);
#ifdef HAVE_GUPNP
  else if (!self->priv->upnp_signal_id)
    return fs_rawudp_component_emit_local_candidates (self, error);
  else
    return TRUE;
#else
  else
    return fs_rawudp_component_emit_local_candidates (self, error);