Esempio n. 1
0
static gboolean
set_the_candidates (gpointer user_data)
{
  FsStreamTransmitter *st = FS_STREAM_TRANSMITTER (user_data);
  GList *candidates = g_object_get_data (G_OBJECT (st), "candidates-set");
  gboolean ret;
  GError *error = NULL;

  if (!candidates)
  {
    g_debug ("Skipping libnice check because it found NO local candidates");
    g_atomic_int_set(&running, FALSE);
    g_main_loop_quit (loop);
    return FALSE;
  }

  if (force_candidates)
  {
    GList *item = NULL;
    GList *next = NULL;
    GList *new_list = NULL;
    for (item = candidates; item; item = next)
    {
      FsCandidate *cand = item->data;
      GList *item2 = NULL;
      next = g_list_next (item);

      for (item2 = new_list; item2; item2 = g_list_next (item2))
      {
        FsCandidate *cand2 = item2->data;
        if (cand2->component_id == cand->component_id)
          break;
      }
      if (!item2)
      {
        candidates = g_list_remove (candidates, cand);
        new_list = g_list_append (new_list, cand);
      }
    }

    ret = fs_stream_transmitter_force_remote_candidates (st, new_list, &error);

    fs_candidate_list_destroy (new_list);
  }
  else
  {
    ret = fs_stream_transmitter_add_remote_candidates (st, candidates, &error);
  }

  if (error)
    ts_fail ("Error while adding candidate: (%s:%d) %s",
        g_quark_to_string (error->domain), error->code, error->message);

  ts_fail_unless (ret == TRUE, "No detailed error setting remote_candidate");

  fs_candidate_list_destroy (candidates);

  return FALSE;
}
Esempio n. 2
0
static void
skipped_cb (GObject *istream, GAsyncResult *result, gpointer user_data)
{
  TestSession *ses = user_data;
  FsCandidate *cand;
  GList *cands = NULL;
  GError *error = NULL;
  gboolean res;

  cand = fs_candidate_new ("", FS_COMPONENT_RTP,
      FS_CANDIDATE_TYPE_HOST, FS_NETWORK_PROTOCOL_UDP, ses->send_socket, 0);
  cand->username = g_strdup (ses->recv_socket);
  cands = g_list_prepend (NULL, cand);

  res = fs_stream_force_remote_candidates (ses->stream, cands, &error);
  print_error (error);
  g_assert (res);

  fs_candidate_list_destroy (cands);
}
Esempio n. 3
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);
}
Esempio n. 4
0
static void
one_way (GCallback havedata_handler, gpointer data)
{
  FsParticipant *participant = NULL;
  GError *error = NULL;
  gint port = 0;
  GstElement *recv_pipeline;
  GList *candidates = NULL;
  GstBus *bus = NULL;

  dtmf_id = 105;
  digit = 0;
  sending = FALSE;
  received = FALSE;
  ready_to_send = FALSE;

  loop = g_main_loop_new (NULL, FALSE);

  dat = setup_simple_conference (1, "fsrtpconference", "tester@123445");

  bus = gst_element_get_bus (dat->pipeline);
  gst_bus_add_watch (bus, _bus_callback, dat);
  gst_object_unref (bus);

  g_idle_add (_start_pipeline, dat);

  participant = fs_conference_new_participant (
      FS_CONFERENCE (dat->conference), "*****@*****.**", &error);
  if (error)
    ts_fail ("Error while creating new participant (%d): %s",
        error->code, error->message);
  ts_fail_if (dat->session == NULL,
      "Could not make participant, but no GError!");

  stream = fs_session_new_stream (dat->session, participant,
      FS_DIRECTION_SEND, "rawudp", 0, NULL, &error);
  if (error)
    ts_fail ("Error while creating new stream (%d): %s",
        error->code, error->message);
  ts_fail_if (stream == NULL, "Could not make stream, but no GError!");

  recv_pipeline = build_recv_pipeline (havedata_handler, NULL, &port);

  GST_DEBUG ("port is %d", port);

  candidates = g_list_prepend (NULL,
      fs_candidate_new ("1", FS_COMPONENT_RTP, FS_CANDIDATE_TYPE_HOST,
          FS_NETWORK_PROTOCOL_UDP, "127.0.0.1", port));
  ts_fail_unless (fs_stream_set_remote_candidates (stream, candidates, &error),
      "Could not set remote candidate");
  fs_candidate_list_destroy (candidates);

  set_codecs (dat, stream);

  setup_fakesrc (dat);

  g_main_loop_run (loop);

  gst_element_set_state (dat->pipeline, GST_STATE_NULL);
  gst_element_set_state (recv_pipeline, GST_STATE_NULL);

  cleanup_simple_conference (dat);
  gst_object_unref (recv_pipeline);

  g_main_loop_unref (loop);
}
Esempio n. 5
0
static gboolean
set_the_candidates (gpointer user_data)
{
    FsStreamTransmitter *st = FS_STREAM_TRANSMITTER (user_data);
    GList *candidates = g_object_get_data (G_OBJECT (st), "candidates-set");
    gboolean ret;
    GError *error = NULL;

    if (!candidates)
    {
        g_debug ("Skipping libnice check because it found NO local candidates");
        g_atomic_int_set(&running, FALSE);
        g_main_loop_quit (loop);
        return FALSE;
    }

    if (force_candidates)
    {
        GList *item = NULL;
        GList *next = NULL;
        GList *new_list = NULL;
        for (item = candidates; item; item = next)
        {
            FsCandidate *cand = item->data;
            GList *item2 = NULL;

            next = g_list_next (item);

            if (cand->type != FS_CANDIDATE_TYPE_HOST)
                continue;
            if (cand->component_id != 1)
                continue;

            for (item2 = candidates; item2; item2 = g_list_next (item2))
            {
                FsCandidate *cand2 = item2->data;
                if (cand2->component_id == 2 &&
                        !strcmp (cand->foundation, cand2->foundation))
                {
                    new_list = g_list_append (new_list, cand);
                    new_list = g_list_append (new_list, cand2);
                    goto got_candidates;
                }
            }
        }

        ts_fail ("Could not find two matching host candidates???");

got_candidates:
        ts_fail_unless (g_list_length (new_list) == 2);
        ret = fs_stream_transmitter_force_remote_candidates (st, new_list, &error);
    }
    else
    {
        ret = fs_stream_transmitter_add_remote_candidates (st, candidates, &error);
    }

    if (error)
        ts_fail ("Error while adding candidate: (%s:%d) %s",
                 g_quark_to_string (error->domain), error->code, error->message);

    ts_fail_unless (ret == TRUE, "No detailed error setting remote_candidate");

    fs_candidate_list_destroy (candidates);

    return FALSE;
}
Esempio n. 6
0
static TestSession*
add_audio_session (GstElement *pipeline, FsConference *conf, guint id,
    FsParticipant *part, guint localport, const gchar *remoteip,
    guint remoteport)
{
  TestSession *ses = g_slice_new0 (TestSession);
  GError *error = NULL;
  GstPad *pad = NULL, *pad2 = NULL;
  GstElement *src = NULL;
  GList *cands = NULL;
  GList *codecs = NULL;
  GParameter param = {0};
  gboolean res;

  ses->session = fs_conference_new_session (conf, FS_MEDIA_TYPE_AUDIO, &error);
  print_error (error);
  g_assert (ses->session);

  g_object_get (ses->session, "sink-pad", &pad, NULL);

  if (g_getenv ("AUDIOSRC"))
    src = gst_parse_bin_from_description (g_getenv ("AUDIOSRC"), TRUE,
        &error);
  else
    src = gst_parse_bin_from_description (DEFAULT_AUDIOSRC, TRUE,
        &error);
  print_error (error);
  g_assert (src);

  g_assert (gst_bin_add (GST_BIN (pipeline), src));

  pad2 = gst_element_get_static_pad (src, "src");
  g_assert (pad2);

  g_assert (GST_PAD_LINK_SUCCESSFUL (gst_pad_link (pad2, pad)));

  gst_object_unref (pad2);
  gst_object_unref (pad);


  cands = g_list_prepend (NULL, fs_candidate_new ("", FS_COMPONENT_RTP,
          FS_CANDIDATE_TYPE_HOST, FS_NETWORK_PROTOCOL_UDP, NULL, localport));

  param.name = "preferred-local-candidates";
  g_value_init (&param.value, FS_TYPE_CANDIDATE_LIST);
  g_value_take_boxed (&param.value, cands);

  ses->stream = fs_session_new_stream (ses->session, part, FS_DIRECTION_BOTH,
      "rawudp", 1, &param, &error);
  print_error (error);
  g_assert (ses->stream);

  g_value_unset (&param.value);

  g_signal_connect (ses->stream, "src-pad-added",
      G_CALLBACK (src_pad_added_cb), pipeline);

  cands = g_list_prepend (NULL, fs_candidate_new ("", FS_COMPONENT_RTP,
          FS_CANDIDATE_TYPE_HOST, FS_NETWORK_PROTOCOL_UDP, remoteip,
          remoteport));

  res = fs_stream_set_remote_candidates (ses->stream, cands, &error);
  print_error (error);
  g_assert (res);

  fs_candidate_list_destroy (cands);

  codecs = g_list_prepend (NULL,
      fs_codec_new (FS_CODEC_ID_ANY, "PCMA", FS_MEDIA_TYPE_AUDIO, 0));
  codecs = g_list_prepend (codecs,
      fs_codec_new (FS_CODEC_ID_ANY, "PCMU", FS_MEDIA_TYPE_AUDIO, 0));

  res = fs_session_set_codec_preferences (ses->session, codecs, &error);
  print_error (error);
  fs_codec_list_destroy (codecs);


  g_object_get (ses->session, "codecs", &codecs, NULL);
  res = fs_stream_set_remote_codecs (ses->stream, codecs, &error);
  print_error (error);
  g_assert (res);

  return ses;
}
Esempio n. 7
0
static void
run_shm_transmitter_test (gint flags)
{
  GError *error = NULL;
  FsTransmitter *trans;
  FsStreamTransmitter *st;
  GstBus *bus = NULL;
  GParameter params[1];
  GList *local_cands = NULL;
  GstStateChangeReturn ret;
  FsCandidate *cand;
  GList *remote_cands = NULL;
  int param_count = 0;
  gint bus_source;

  done = FALSE;
  connected_count = 0;
  g_cond_init (&cond);
  g_mutex_init (&test_mutex);

  buffer_count[0] = 0;
  buffer_count[1] = 0;
  received_known[0] = 0;
  received_known[1] = 0;

  got_candidates[0] = FALSE;
  got_candidates[1] = FALSE;
  got_prepared[0] = FALSE;
  got_prepared[1] = FALSE;

  if (unlink ("/tmp/src1") < 0 && errno != ENOENT)
    fail ("Could not unlink /tmp/src1: %s", strerror (errno));
  if (unlink ("/tmp/src2") < 0 && errno != ENOENT)
    fail ("Could not unlink /tmp/src2: %s", strerror (errno));


  local_cands = g_list_append (local_cands, fs_candidate_new (NULL, 1,
          FS_CANDIDATE_TYPE_HOST, FS_NETWORK_PROTOCOL_UDP, "/tmp/src1", 0));
  local_cands = g_list_append (local_cands, fs_candidate_new (NULL, 2,
          FS_CANDIDATE_TYPE_HOST, FS_NETWORK_PROTOCOL_UDP, "/tmp/src2", 0));

  if (flags & FLAG_LOCAL_CANDIDATES)
  {
    memset (params, 0, sizeof (GParameter));

    params[0].name = "preferred-local-candidates";
    g_value_init (&params[0].value, FS_TYPE_CANDIDATE_LIST);
    g_value_take_boxed (&params[0].value, local_cands);

    param_count = 1;
  }


  associate_on_source = !(flags & FLAG_NO_SOURCE);

  if ((flags & FLAG_NOT_SENDING) && (flags & FLAG_RECVONLY_FILTER))
  {
    buffer_count[0] = 20;
    received_known[0] = 20;
  }

  trans = fs_transmitter_new ("shm", 2, 0, &error);

  if (error)
    ts_fail ("Error creating transmitter: (%s:%d) %s",
      g_quark_to_string (error->domain), error->code, error->message);
  ts_fail_if (trans == NULL, "No transmitter create, yet error is still NULL");
  g_clear_error (&error);

  if (flags & FLAG_RECVONLY_FILTER)
    ts_fail_unless (g_signal_connect (trans, "get-recvonly-filter",
            G_CALLBACK (get_recvonly_filter), NULL));


  pipeline = setup_pipeline (trans, G_CALLBACK (_handoff_handler));

  bus = gst_element_get_bus (pipeline);
  bus_source = gst_bus_add_watch (bus, bus_error_callback, NULL);

  gst_bus_enable_sync_message_emission (bus);
  g_signal_connect (bus, "sync-message::error",
      G_CALLBACK (sync_error_handler), NULL);

  gst_object_unref (bus);

  st = fs_transmitter_new_stream_transmitter (trans, NULL,
      param_count, params, &error);

  if (param_count)
    g_value_unset (&params[0].value);

  if (error)
    ts_fail ("Error creating stream transmitter: (%s:%d) %s",
        g_quark_to_string (error->domain), error->code, error->message);
  ts_fail_if (st == NULL, "No stream transmitter created, yet error is NULL");
  g_clear_error (&error);

  g_object_set (st, "sending", !(flags & FLAG_NOT_SENDING), NULL);

  ts_fail_unless (g_signal_connect (st, "new-local-candidate",
      G_CALLBACK (_new_local_candidate), trans),
    "Could not connect new-local-candidate signal");
  ts_fail_unless (g_signal_connect (st, "local-candidates-prepared",
      G_CALLBACK (_candidate_prepared), NULL),
    "Could not connect local-candidates-prepared signal");
  ts_fail_unless (g_signal_connect (st, "error",
      G_CALLBACK (stream_transmitter_error), NULL),
    "Could not connect error signal");
  ts_fail_unless (g_signal_connect (st, "known-source-packet-received",
      G_CALLBACK (_known_source_packet_received), NULL),
    "Could not connect known-source-packet-received signal");
  ts_fail_unless (g_signal_connect (st, "state-changed",
      G_CALLBACK (_state_changed), NULL),
    "Could not connect state-changed signal");

  if (!fs_stream_transmitter_gather_local_candidates (st, &error))
  {
    if (error)
      ts_fail ("Could not start gathering local candidates (%s:%d) %s",
          g_quark_to_string (error->domain), error->code, error->message);
    else
      ts_fail ("Could not start gathering candidates"
          " (without a specified error)");
  }
  else
  {
    ts_fail_unless (error == NULL);
  }
  g_clear_error (&error);

  ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
  ts_fail_if (ret == GST_STATE_CHANGE_FAILURE,
      "Could not set the pipeline to playing");

  if (!(flags & FLAG_LOCAL_CANDIDATES))
  {
    ret = fs_stream_transmitter_force_remote_candidates (st, local_cands,
        &error);
    fs_candidate_list_destroy (local_cands);
    if (error)
      ts_fail ("Error while adding candidate: (%s:%d) %s",
          g_quark_to_string (error->domain), error->code, error->message);
    ts_fail_unless (ret == TRUE, "No detailed error from add_remote_candidate");
  }
  else
  {
    ts_fail_unless (error == NULL);
  }
  g_clear_error (&error);

  cand = fs_candidate_new (NULL, 1,
          FS_CANDIDATE_TYPE_HOST, FS_NETWORK_PROTOCOL_UDP, NULL, 0);
  cand->username = g_strdup ("/tmp/src1");
  remote_cands = g_list_prepend (remote_cands, cand);
  cand = fs_candidate_new (NULL, 2,
          FS_CANDIDATE_TYPE_HOST, FS_NETWORK_PROTOCOL_UDP, NULL, 0);
  cand->username = g_strdup ("/tmp/src2");
  remote_cands = g_list_prepend (remote_cands, cand);
  ret = fs_stream_transmitter_force_remote_candidates (st, remote_cands, &error);
  fs_candidate_list_destroy (remote_cands);
  if (error)
    ts_fail ("Error while adding candidate: (%s:%d) %s",
      g_quark_to_string (error->domain), error->code, error->message);
  ts_fail_unless (ret == TRUE, "No detailed error from add_remote_candidate");
  g_clear_error (&error);

  g_mutex_lock (&test_mutex);
  while (connected_count < 2)
    g_cond_wait (&cond, &test_mutex);
  g_mutex_unlock (&test_mutex);

  setup_fakesrc (trans, pipeline, 1);
  setup_fakesrc (trans, pipeline, 2);

  g_mutex_lock (&test_mutex);
  while (!done)
    g_cond_wait (&cond, &test_mutex);
  g_mutex_unlock (&test_mutex);

  fail_unless (got_prepared[0] == TRUE);
  fail_unless (got_prepared[1] == TRUE);
  fail_unless (got_candidates[0] == TRUE);
  fail_unless (got_candidates[1] == TRUE);

  gst_element_set_state (pipeline, GST_STATE_NULL);

  if (st)
  {
    fs_stream_transmitter_stop (st);
    g_object_unref (st);
  }

  g_object_unref (trans);

  g_source_remove (bus_source);
  gst_object_unref (pipeline);

  g_cond_clear (&cond);
  g_mutex_clear (&test_mutex);
}
Esempio n. 8
0
static void
run_multicast_transmitter_test (gint n_parameters, GParameter *params)
{
    GError *error = NULL;
    FsTransmitter *trans;
    FsStreamTransmitter *st;
    FsCandidate *tmpcand = NULL;
    GList *candidates = NULL;
    GstBus *bus = NULL;

    loop = g_main_loop_new (NULL, FALSE);
    trans = fs_transmitter_new ("multicast", 2, &error);

    if (error) {
        ts_fail ("Error creating transmitter: (%s:%d) %s",
                 g_quark_to_string (error->domain), error->code, error->message);
    }

    ts_fail_if (trans == NULL, "No transmitter create, yet error is still NULL");

    pipeline = setup_pipeline (trans, G_CALLBACK (_handoff_handler));

    st = fs_transmitter_new_stream_transmitter (trans, NULL, n_parameters, params,
            &error);

    if (error) {
        ts_fail ("Error creating stream transmitter: (%s:%d) %s",
                 g_quark_to_string (error->domain), error->code, error->message);
    }

    ts_fail_if (st == NULL, "No stream transmitter created, yet error is NULL");

    bus = gst_element_get_bus (pipeline);
    gst_bus_add_watch (bus, bus_error_callback, NULL);
    gst_object_unref (bus);

    ts_fail_unless (g_signal_connect (st, "new-active-candidate-pair",
                                      G_CALLBACK (_new_active_candidate_pair), trans),
                    "Coult not connect new-active-candidate-pair signal");
    ts_fail_unless (g_signal_connect (st, "error",
                                      G_CALLBACK (stream_transmitter_error), NULL),
                    "Could not connect error signal");

    g_idle_add (_start_pipeline, pipeline);

    tmpcand = fs_candidate_new ("L1", FS_COMPONENT_RTP,
                                FS_CANDIDATE_TYPE_MULTICAST, FS_NETWORK_PROTOCOL_UDP,
                                "224.0.0.110", 2322);
    tmpcand->ttl = 1;

    candidates = g_list_prepend (candidates, tmpcand);

    tmpcand = fs_candidate_new ("L2", FS_COMPONENT_RTCP,
                                FS_CANDIDATE_TYPE_MULTICAST, FS_NETWORK_PROTOCOL_UDP,
                                "224.0.0.110", 2323);
    tmpcand->ttl = 1;

    candidates = g_list_prepend (candidates, tmpcand);

    if (!fs_stream_transmitter_set_remote_candidates (st, candidates, &error))
        ts_fail ("Error setting the remote candidates: %p %s", error,
                 error ? error->message : "NO ERROR SET");
    ts_fail_unless (error == NULL, "Error is not null after successful candidate"
                    " addition");

    fs_candidate_list_destroy (candidates);

    g_main_run (loop);

    g_object_unref (st);

    g_object_unref (trans);

    gst_element_set_state (pipeline, GST_STATE_NULL);

    gst_object_unref (pipeline);

    g_main_loop_unref (loop);
}