int main (int argc, char *argv[])
{
  ServerData app;
  GError *error           = NULL;
  GOptionContext *context = NULL;
  GstBus *bus             = NULL;
  int error_flag          = 0;

  GOptionEntry entries [] =
  {
    { "interface", 'i', 0, G_OPTION_ARG_STRING, &net_if, 
      "network interface", NULL},
    { "port", 'p', 0, G_OPTION_ARG_INT, &port, 
      "port number", NULL },
    { "fileuri", 'f', 0, G_OPTION_ARG_STRING, &uri, 
      "URI to stream", "URI (<protocol>://<location>)"},
    { NULL }
  };

  context = g_option_context_new ("- simple tcp streaming server");
  g_option_context_add_main_entries (context, entries, NULL);

  if (!g_option_context_parse (context, &argc, &argv, &error))
  {
    fprintf (stderr, "option parsing failed: %s\n", error->message);
    error_flag = 1;
  }
  
  error_flag = check_args ();

  if (error_flag)
  {
    fprintf (stderr, "Exiting...\n");
    return EXIT_FAILURE;
  }

  addr = if_addr (net_if);
  if (addr == NULL)
  {
    fprintf (stderr, "There is no ip address bound to the interface %s\n", 
        net_if);
    return EXIT_FAILURE;
  }
  
  error_flag =  init (&app);
  if (!error_flag)
    error_flag = set_links (&app);
  
  if (error_flag)
  {
    fprintf (stderr, "Exiting...\n");
    return EXIT_FAILURE;
  }

  g_object_set (GST_OBJECT (app.source), "uri", uri, NULL);
  g_object_set (GST_OBJECT (app.muxer), "streamable", TRUE, NULL);
  g_object_set (GST_OBJECT (app.sink), "host", addr, NULL); 
  g_object_set (GST_OBJECT (app.sink), "port", port, NULL); 

  g_signal_connect (app.source, "pad-added", G_CALLBACK (pad_added), &app);
  
  
  bus = gst_pipeline_get_bus (GST_PIPELINE (app.pipeline));
  gst_bus_add_watch (bus, bus_call, &app);

  fprintf (stdout, "Preparing the streaming of: %s\n"
      "Network Interface: %s\n"
      "Server IP: %s\n"
      "Server port: %d\n", uri, net_if, addr, port);
  
  fprintf (stdout, "Press 'q' to stop streaming and quit\n");
  free (addr);

  gst_element_set_state (GST_ELEMENT (app.pipeline), GST_STATE_PLAYING);
  g_main_loop_run (app.loop);
  
  gst_element_set_state (GST_ELEMENT (app.pipeline), GST_STATE_NULL);
  
  gst_object_unref (GST_OBJECT(bus));
  gst_object_unref (GST_OBJECT (app.pipeline));

  fprintf (stdout, "All done\n");
  return EXIT_SUCCESS;
}
Exemplo n.º 2
0
void
ACE_SOCK_Dgram_Mcast::dump (void) const
{
#if defined (ACE_HAS_DUMP)
  ACE_TRACE ("ACE_SOCK_Dgram_Mcast::dump");

  ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));

# if defined (ACE_SOCK_DGRAM_MCAST_DUMPABLE)
  ACE_TCHAR addr_string[MAXNAMELEN + 1];

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\nOptions: bindaddr=%s, nulliface=%s\n"),
              ACE_BIT_ENABLED (this->opts_, OPT_BINDADDR_YES) ?
                ACE_TEXT ("<Bound>") : ACE_TEXT ("<Not Bound>"),
              ACE_BIT_ENABLED (this->opts_, OPT_NULLIFACE_ALL) ?
                ACE_TEXT ("<All Ifaces>") : ACE_TEXT ("<Default Iface>")));

  // Show default send addr, port#, and interface.
  ACE_SDM_helpers::addr_to_string (this->send_addr_, addr_string,
                                   sizeof addr_string, 0);
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Send addr=%s iface=%s\n"),
              addr_string,
              this->send_net_if_ ? this->send_net_if_
                                 : ACE_TEXT ("<default>")));

  // Show list of subscribed addresses.
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Subscription list:\n")));

  ACE_MT (ACE_GUARD (ACE_SDM_LOCK, guard, this->subscription_list_lock_));
  subscription_list_iter_t  iter (this->subscription_list_);
  for ( ; !iter.done (); iter.advance ())
    {
      ACE_TCHAR iface_string[MAXNAMELEN + 1];
      ip_mreq *pm = iter.next ();

      // Get subscribed address (w/out port# info - not relevant).
      ACE_INET_Addr ip_addr (static_cast<u_short> (0),
                             ACE_NTOHL (pm->IMR_MULTIADDR.s_addr));
      ACE_SDM_helpers::addr_to_string (ip_addr, addr_string,
                                       sizeof addr_string, 1);

      // Get interface address/specification.
      ACE_INET_Addr if_addr (static_cast<u_short> (0),
                             ACE_NTOHL (pm->imr_interface.s_addr));
      ACE_SDM_helpers::addr_to_string (if_addr, iface_string,
                                       sizeof iface_string, 1);
      if (ACE_OS::strcmp (iface_string, ACE_TEXT ("0.0.0.0")) == 0)
        // Receives on system default iface. (Note that null_iface_opt_
        // option processing has already occurred.)
        ACE_OS::strcpy (iface_string, ACE_TEXT ("<default>"));

      // Dump info.
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("\taddr=%s iface=%s\n"),
                  addr_string,
                  iface_string));
    }
# endif /* ACE_SOCK_DGRAM_MCAST_DUMPABLE */
  ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
#endif /* ACE_HAS_DUMP */
}