static void
gst_rtsp_media_factory_get_property (GObject * object, guint propid,
    GValue * value, GParamSpec * pspec)
{
  GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (object);

  switch (propid) {
    case PROP_LAUNCH:
      g_value_take_string (value, gst_rtsp_media_factory_get_launch (factory));
      break;
    case PROP_SHARED:
      g_value_set_boolean (value, gst_rtsp_media_factory_is_shared (factory));
      break;
    case PROP_EOS_SHUTDOWN:
      g_value_set_boolean (value,
          gst_rtsp_media_factory_is_eos_shutdown (factory));
      break;
    case PROP_PROTOCOLS:
      g_value_set_flags (value, gst_rtsp_media_factory_get_protocols (factory));
      break;
    case PROP_BUFFER_SIZE:
      g_value_set_uint (value,
          gst_rtsp_media_factory_get_buffer_size (factory));
      break;
    case PROP_MULTICAST_GROUP:
      g_value_take_string (value,
          gst_rtsp_media_factory_get_multicast_group (factory));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
  }
}
Esempio n. 2
0
static void
add_rtsp_uri (SnraManager * manager, guint resource_id,
    const gchar * source_uri)
{
  GstRTSPMediaMapping *mapping;
  GstRTSPMediaFactoryURI *factory;
  gchar *rtsp_uri = g_strdup_printf ("/resource/%u", resource_id);

  mapping = gst_rtsp_server_get_media_mapping (manager->rtsp);
  factory = gst_rtsp_media_factory_uri_new ();
  /* Set up the URI, and set as shared (all viewers see the same stream) */
  gst_rtsp_media_factory_uri_set_uri (factory, source_uri);
  gst_rtsp_media_factory_set_shared (GST_RTSP_MEDIA_FACTORY (factory), TRUE);
  g_signal_connect (factory, "media-constructed",
      G_CALLBACK (new_stream_constructed_cb), manager);
  /* attach the test factory to the test url */
  gst_rtsp_media_mapping_add_factory (mapping, rtsp_uri,
      GST_RTSP_MEDIA_FACTORY (factory));
  g_object_unref (mapping);

  g_free (rtsp_uri);
}
static void
gst_rtsp_media_factory_set_property (GObject * object, guint propid,
    const GValue * value, GParamSpec * pspec)
{
  GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (object);

  switch (propid) {
    case PROP_LAUNCH:
      gst_rtsp_media_factory_set_launch (factory, g_value_get_string (value));
      break;
    case PROP_SHARED:
      gst_rtsp_media_factory_set_shared (factory, g_value_get_boolean (value));
      break;
    case PROP_SUSPEND_MODE:
      gst_rtsp_media_factory_set_suspend_mode (factory,
          g_value_get_enum (value));
      break;
    case PROP_EOS_SHUTDOWN:
      gst_rtsp_media_factory_set_eos_shutdown (factory,
          g_value_get_boolean (value));
      break;
    case PROP_PROFILES:
      gst_rtsp_media_factory_set_profiles (factory, g_value_get_flags (value));
      break;
    case PROP_PROTOCOLS:
      gst_rtsp_media_factory_set_protocols (factory, g_value_get_flags (value));
      break;
    case PROP_BUFFER_SIZE:
      gst_rtsp_media_factory_set_buffer_size (factory,
          g_value_get_uint (value));
      break;
    case PROP_LATENCY:
      gst_rtsp_media_factory_set_latency (factory, g_value_get_uint (value));
      break;
    case PROP_TRANSPORT_MODE:
      gst_rtsp_media_factory_set_transport_mode (factory,
          g_value_get_flags (value));
      break;
    case PROP_STOP_ON_DISCONNECT:
      gst_rtsp_media_factory_set_stop_on_disconnect (factory,
          g_value_get_boolean (value));
      break;
    case PROP_CLOCK:
      gst_rtsp_media_factory_set_clock (factory, g_value_get_object (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
  }
}
static void
gst_rtsp_media_factory_finalize (GObject * obj)
{
  GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (obj);

  g_hash_table_unref (factory->medias);
  g_mutex_clear (&factory->medias_lock);
  g_free (factory->launch);
  g_free (factory->multicast_group);
  g_mutex_clear (&factory->lock);
  if (factory->auth)
    g_object_unref (factory->auth);

  G_OBJECT_CLASS (gst_rtsp_media_factory_parent_class)->finalize (obj);
}
static void
gst_rtsp_media_factory_finalize (GObject * obj)
{
  GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (obj);
  GstRTSPMediaFactoryPrivate *priv = factory->priv;

  if (priv->permissions)
    gst_rtsp_permissions_unref (priv->permissions);
  g_hash_table_unref (priv->medias);
  g_mutex_clear (&priv->medias_lock);
  g_free (priv->launch);
  g_mutex_clear (&priv->lock);
  if (priv->pool)
    g_object_unref (priv->pool);

  G_OBJECT_CLASS (gst_rtsp_media_factory_parent_class)->finalize (obj);
}
Esempio n. 6
0
int
main (int argc, char *argv[])
{
  GMainLoop *loop;
  GstRTSPServer *server;
  GstRTSPMountPoints *mounts;
  GstRTSPMediaFactory *factory;

  gst_init (&argc, &argv);

  if (argc < 1) {
    g_print ("usage: %s [portnum] \n"
        "example: %s 8555 \n"
        "Pipeline is fixed. Default port 8554\n",
        argv[0], argv[0]);
    return -1;
  }

  loop = g_main_loop_new (NULL, FALSE);

  //global_clock = gst_system_clock_obtain ();
  //gst_net_time_provider_new (global_clock, "0.0.0.0", 8554);

  
  /* create a server instance */
  server = gst_rtsp_server_new ();
  
  gint * portnum;
  portnum = malloc(sizeof(gint));
  *portnum = 8554;
  if (argc == 2)
  {
    /* set server listening port*/
    gst_rtsp_server_set_service (server,argv[1]);
    *portnum = atoi(argv[1]);  
  }
  
  
  /* callback for clients */
  g_signal_connect (server, "client-connected", G_CALLBACK (client_connection), portnum);
  

  /* get the mount points for this server, every server has a default object
   * that be used to map uri mount points to media factories */
  mounts = gst_rtsp_server_get_mount_points (server);

  /* make a media factory for a test stream. The default media factory can use
   * gst-launch syntax to create pipelines.
   * any launch line works as long as it contains elements named pay%d. Each
   * element with pay%d names will be a stream */
  factory = test_rtsp_media_factory_new ();
  gst_rtsp_media_factory_set_launch (factory,
      "appsrc name=mysrc ! videoconvert ! x264enc tune=\"zerolatency\" ! rtph264pay pt=96 ! rtpatimetimestamp name=pay0 ntp-offset=0");

  g_signal_connect (factory, "media-configure", (GCallback) media_configure,
      NULL);      
      
  gst_rtsp_media_factory_set_shared (GST_RTSP_MEDIA_FACTORY (factory), TRUE);
  gst_rtsp_media_factory_set_media_gtype (GST_RTSP_MEDIA_FACTORY (factory),
      TEST_TYPE_RTSP_MEDIA);

  /* attach the test factory to the /test url */
  gst_rtsp_mount_points_add_factory (mounts, "/test", factory);

  /* don't need the ref to the mapper anymore */
  g_object_unref (mounts);

  /* attach the server to the default maincontext */
  gst_rtsp_server_attach (server, NULL);

  /* start serving */
  if (argc < 2)
    g_print ("stream ready at rtsp://127.0.0.1:8554/test\n");
  else
  {
    g_print ("stream ready at rtsp://127.0.0.1:");
    g_print (argv[1]);
    g_print ("/test\n");
  }
  g_main_loop_run (loop);

  return 0;
}
Esempio n. 7
0
int
main(int argc, char **argv)
{
  GMainLoop *loop;
  GstRTSPServer *server;
  GstRTSPMediaMapping *mapping;
  GstRTSPCamMediaFactory *factory;
  GstRTSPUrl *local_url;
  GOptionContext *ctx;
  GOptionGroup *gst_group;
  gboolean res;
  GError *error = NULL;

  g_type_init ();
  g_thread_init (NULL);

  ctx = g_option_context_new ("rtsp://host:port/path");
  g_option_context_add_main_entries (ctx, option_entries, NULL);
  gst_group = gst_init_get_option_group ();
  g_option_context_add_group (ctx, gst_group);
  res = g_option_context_parse (ctx, &argc, &argv, &error);
  g_option_context_free (ctx);

  gst_init (&argc, &argv);

  if (!res) {
    g_printerr ("command line error: %s\n", error->message);
    g_error_free (error);

    return 1;
  }

  if (gst_rtsp_url_parse (argc != 2 ? "rtsp://127.0.0.1:8554/test" : argv[1], &local_url) != GST_RTSP_OK) {
    g_printerr ("invalid rtsp url\n");

    return 1;
  }

  loop = g_main_loop_new (NULL, FALSE);

  server = gst_rtsp_server_new ();

  factory = gst_rtsp_cam_media_factory_new ();
  g_object_set (factory, "video-device", video_device,
      "video", !no_video,
      "video-width", video_width,
      "video-height", video_height,
      "video-codec", video_codec,
      "video-framerate", fps_n, fps_d,
      "audio", !no_audio,
      "audio-device", audio_device,
      "audio-codec", audio_codec,
      NULL);

  gst_rtsp_media_factory_set_shared (GST_RTSP_MEDIA_FACTORY (factory), TRUE);
  mapping = gst_rtsp_server_get_media_mapping (server);
  gst_rtsp_media_mapping_add_factory (mapping, local_url->abspath,
      GST_RTSP_MEDIA_FACTORY (factory));
  g_object_unref (mapping);

  gst_rtsp_url_free (local_url);

  gst_rtsp_server_attach (server, NULL);

  g_timeout_add_seconds (5, (GSourceFunc) timeout, server);
  /* start serving */
  g_main_loop_run (loop);

  return 0;
}
Esempio n. 8
0
/* ============================================================================
 * @Function: 	 rtspmodule_init
 * @Description: Initialize GST Application interface.
 * ============================================================================
 */
int rtspmodule_init (struct rtspmodule_arguments *arg)
{
	guint major, minor, micro, nano;
	GstBus  *bus;

	/* Settings - Encoder and Streaming */
	arguments.width = arg->width;
	arguments.height = arg->height;
	arguments.gfps = arg->gfps;
	arguments.gbitrate = arg->gbitrate;
	arguments.gmtu = arg->gmtu;
	arguments.vsrc = arg->vsrc;
	arguments.vencoder = g_strdup(arg->vencoder);
	arguments.rtpencoder = arg->rtpencoder;

	/* GSTAPP Setup */
	gst_init(NULL, NULL);

	gst_version(&major, &minor, &micro, &nano);
	g_print("..This program is linked against GStreamer %d.%d.%d\n", major, minor, micro);

	loop = g_main_loop_new(NULL, FALSE);

	datasize = arguments.height * arguments.width * 4;
	databuffer = gst_buffer_new_and_alloc (datasize);
	inputdatabuffer = malloc ((sizeof(char))*datasize);

	pipeline = construct_app_pipeline();
	if ( !pipeline ) {
		g_printerr("Failed to construct pipeline\n");
		return -1;
	}
	g_print("..GSTAPP Pipeline Setup... \n");

	/* we add a message handler */
	bus = gst_pipeline_get_bus(GST_PIPELINE (pipeline));
	gst_bus_add_watch(bus, bus_watch, loop);
	gst_object_unref(bus);

	/* create a server instance */
  	server = gst_rtsp_server_new ();

  	/* get the mapping for this server, every server has a default mapper object
   	* that be used to map uri mount points to media factories */
  	mapping = gst_rtsp_server_get_media_mapping (server);

	/* make a media factory for a test stream.
	* The default media factory can use
   	* gst-launch syntax to create pipelines.
   	* any launch line works as long as it contains elements
	* named pay%d. Each element with pay%d names will be a stream */
  	//factory = gst_rtsp_media_factory_new ();
    	factory = GST_RTSP_MEDIA_FACTORY(gst_rtsp_media_factory_custom_new());

  	// allow multiple clients to see the same video
  	gst_rtsp_media_factory_set_shared (factory, TRUE);
    	g_object_set(factory, "bin", pipeline, NULL);

  	/* attach the test factory to the /test url */
  	gst_rtsp_media_mapping_add_factory (mapping, "/bbwatch", factory);
  	/* don't need the ref to the mapping anymore */
  	g_object_unref (mapping);
  	/* attach the server to the default maincontext */
  	gst_rtsp_server_attach (server, NULL);
	 /* add a timeout for the session cleanup */
  	g_timeout_add_seconds (2, (GSourceFunc) cleanup_timeout, server);
	g_print("..GST Pipeline Initialized ...\n");
	
	return 0;
}