Exemplo n.º 1
0
void
client_connection (GstRTSPServer *gstrtspserver,
               GstRTSPClient *arg1,
               gpointer       user_data)
{
  GstRTSPConnection * conn = (GstRTSPConnection*) gst_rtsp_client_get_connection (arg1);
  g_print ("Local ip %s\n",
        gst_rtsp_connection_get_ip (conn));

  gint * port = (gint*) user_data;

  g_print ("Port %d\n", *port);  

  if (global_clock == NULL) {
    g_print ("No clocks already available\n");
  } else {
    g_print ("A clock was present, unref it!.\n");
  }

  global_clock = gst_net_client_clock_new ("net_clock", gst_rtsp_connection_get_ip (conn), 8554, 0);

  if (global_clock == NULL) {
    g_print ("Failed to create net clock client for %s:%d\n",
        "192.168.0.1", 8554);
    return;
  }

  g_print ("Waiting clock...");
  /* Wait for the clock to stabilise */
  gst_clock_wait_for_sync (global_clock, GST_CLOCK_TIME_NONE);

  g_print ("Synked!\n");        
}
Exemplo n.º 2
0
void cmd_do_clock(gchar **arg_strv, gint arg_num)
{
  g_print ("%s %s %s %s\n", __func__, arg_strv[0], arg_strv[1], arg_strv[2]);
  client_clock = gst_net_client_clock_new (NULL, arg_strv[1], atoi(arg_strv[2]), 0);
  g_usleep (G_USEC_PER_SEC / 2);

  gst_pipeline_use_clock (GST_PIPELINE (gst_data.playbin), client_clock);
  //gst_element_set_start_time (gst_data.playbin, GST_CLOCK_TIME_NONE);
  //gst_pipeline_set_latency (GST_PIPELINE (gst_data.playbin), GST_SECOND / 2);
}
gint
main (gint argc, gchar * argv[])
{
  GMainLoop *loop;
  gchar *host;
  guint16 port;
  GstClock *client_clock;
  GstBus *bus;

  gst_init (&argc, &argv);

  if (argc < 3) {
    g_print ("Usage: netclock-client <host> <port>\n");
    return 1;
  }

  host = argv[1];
  port = atoi (argv[2]);

  client_clock = gst_net_client_clock_new (NULL, host, port, 0);
  if (client_clock == NULL) {
    g_printerr ("Failed to create network clock client\n");
    return 1;
  }

  bus = gst_bus_new ();
  gst_bus_add_watch (bus, (GstBusFunc) handle_bus_message, client_clock);
  g_object_set (G_OBJECT (client_clock), "bus", bus, NULL);

  loop = g_main_loop_new (NULL, FALSE);

  g_main_loop_run (loop);

  /* cleanup */
  g_main_loop_unref (loop);
  g_object_unref (client_clock);

  return 0;
}
Exemplo n.º 4
0
int main(int argc, char *argv[]) {
  GMainLoop *main_loop;
  GstClock *client_clock, *tmp_clock;
  GstNetTimeProvider *prov_clock;
  guint16 clock_port;
  GstClockTime base_time;

  /* Initialize GStreamer */
  gst_init (&argc, &argv);

  prov_clock = create_net_clock (&clock_port);
  client_clock = gst_net_client_clock_new (NULL, "127.0.0.1", clock_port, 0);

  /* Wait 0.5 seconds for the clock to stabilise */
  g_usleep (G_USEC_PER_SEC / 2);
  base_time = share_base_time (clock_port, prov_clock);

  /* Create the elements */
  playbin = gst_element_factory_make ("playbin", "playbin");
  g_object_set (playbin, "uri", "file:///home/luisbg/samples/big_buck_bunny_1080p_h264.mov", NULL);

  gst_pipeline_use_clock (GST_PIPELINE (playbin), client_clock);
  gst_element_set_base_time (playbin, base_time);
  gst_element_set_start_time (playbin, GST_CLOCK_TIME_NONE);
  gst_pipeline_set_latency (GST_PIPELINE (playbin), GST_SECOND / 2);

  gst_element_set_state (playbin, GST_STATE_PLAYING);

  /* Create a GLib Main Loop and set it to run */
  main_loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (main_loop);

  /* Free resources */
  g_main_loop_unref (main_loop);
  gst_element_set_state (playbin, GST_STATE_NULL);
  gst_object_unref (playbin);
  return 0;
}
Exemplo n.º 5
0
static void
handle_enrol_message (SnraClient * client, GstStructure * s)
{
  int clock_port;
  gint64 tmp;
  GstClockTime cur_time;
  gchar *server_ip_str = NULL;
  gdouble new_vol;

  if (!snra_json_structure_get_int (s, "clock-port", &clock_port))
    return;                     /* Invalid message */

  if (!snra_json_structure_get_int64 (s, "current-time", &tmp))
    return;                     /* Invalid message */
  cur_time = (GstClockTime) (tmp);

  if (snra_json_structure_get_double (s, "volume-level", &new_vol)) {
    if (client->player == NULL)
      construct_player (client);

    if (client->player) {
      //g_print ("New volume %g\n", new_vol);
      g_object_set (G_OBJECT (client->player), "volume", new_vol,
          "mute", (gboolean) (new_vol == 0.0), NULL);
    }
  }

  snra_json_structure_get_boolean (s, "enabled", &client->enabled);
  snra_json_structure_get_boolean (s, "paused", &client->paused);

#if GLIB_CHECK_VERSION(2,22,0)
  {
    GResolver *resolver = g_resolver_get_default ();
    GList *names;

    if (resolver == NULL)
      return;

    names =
        g_resolver_lookup_by_name (resolver, client->connected_server, NULL,
        NULL);
    if (names) {
      server_ip_str = g_inet_address_to_string ((GInetAddress *) (names->data));
      g_resolver_free_addresses (names);
    }
    g_object_unref (resolver);
  }
#else
  {
    struct addrinfo *names = NULL;
    if (getaddrinfo (client->connected_server, NULL, NULL, &names))
      return;
    if (names) {
      char hbuf[NI_MAXHOST];
      if (getnameinfo (names->ai_addr, names->ai_addrlen,
              hbuf, sizeof (hbuf), NULL, 0, NI_NUMERICHOST) == 0) {
        server_ip_str = g_strdup (hbuf);
      }
      freeaddrinfo (names);
    }
  }
#endif
  if (server_ip_str) {
    g_print ("Creating net clock at %s:%d time %" GST_TIME_FORMAT "\n",
        server_ip_str, clock_port, GST_TIME_ARGS (cur_time));
    if (client->net_clock)
      gst_object_unref (client->net_clock);
    client->net_clock = gst_net_client_clock_new ("net_clock", server_ip_str,
        clock_port, cur_time);
    g_free (server_ip_str);
  }
}