2008-10-09 12:29:12 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:14:25 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2009-01-08 12:18:55 +00:00
|
|
|
#include <gst/rtsp-server/rtsp-server.h>
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2014-09-15 14:54:05 +00:00
|
|
|
/* called when a stream has received an RTCP packet from the client */
|
|
|
|
static void
|
|
|
|
on_ssrc_active (GObject * session, GObject * source, GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstStructure *stats;
|
|
|
|
|
|
|
|
GST_INFO ("source %p in session %p is active", source, session);
|
|
|
|
|
|
|
|
g_object_get (source, "stats", &stats, NULL);
|
|
|
|
if (stats) {
|
|
|
|
gchar *sstr;
|
|
|
|
|
|
|
|
sstr = gst_structure_to_string (stats);
|
|
|
|
g_print ("structure: %s\n", sstr);
|
|
|
|
g_free (sstr);
|
|
|
|
|
|
|
|
gst_structure_free (stats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* signal callback when the media is prepared for streaming. We can get the
|
|
|
|
* session manager for each of the streams and connect to some signals. */
|
|
|
|
static void
|
|
|
|
media_prepared_cb (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
guint i, n_streams;
|
|
|
|
|
|
|
|
n_streams = gst_rtsp_media_n_streams (media);
|
|
|
|
|
|
|
|
GST_INFO ("media %p is prepared and has %u streams", media, n_streams);
|
|
|
|
|
|
|
|
for (i = 0; i < n_streams; i++) {
|
|
|
|
GstRTSPStream *stream;
|
|
|
|
GObject *session;
|
|
|
|
|
|
|
|
stream = gst_rtsp_media_get_stream (media, i);
|
|
|
|
if (stream == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
session = gst_rtsp_stream_get_rtpsession (stream);
|
|
|
|
GST_INFO ("watching session %p on stream %u", session, i);
|
|
|
|
|
|
|
|
g_signal_connect (session, "on-ssrc-active",
|
|
|
|
(GCallback) on_ssrc_active, media);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
media_configure_cb (GstRTSPMediaFactory * factory, GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
/* connect our prepared signal so that we can see when this media is
|
|
|
|
* prepared for streaming */
|
|
|
|
g_signal_connect (media, "prepared", (GCallback) media_prepared_cb, factory);
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GMainLoop *loop;
|
|
|
|
GstRTSPServer *server;
|
2012-11-26 11:34:05 +00:00
|
|
|
GstRTSPMountPoints *mounts;
|
2009-01-22 14:33:29 +00:00
|
|
|
GstRTSPMediaFactory *factory;
|
2009-01-29 12:31:27 +00:00
|
|
|
gchar *str;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
if (argc < 2) {
|
2012-10-27 09:53:51 +00:00
|
|
|
g_message ("usage: %s <filename.mp4>", argv[0]);
|
2009-01-29 12:31:27 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
|
|
/* create a server instance */
|
|
|
|
server = gst_rtsp_server_new ();
|
|
|
|
|
2012-11-26 11:34:05 +00:00
|
|
|
/* get the mount points for this server, every server has a default object
|
2009-01-22 14:33:29 +00:00
|
|
|
* that be used to map uri mount points to media factories */
|
2012-11-26 11:34:05 +00:00
|
|
|
mounts = gst_rtsp_server_get_mount_points (server);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
2010-12-11 09:49:30 +00:00
|
|
|
str = g_strdup_printf ("( "
|
2009-01-29 12:31:27 +00:00
|
|
|
"filesrc location=%s ! qtdemux name=d "
|
2010-12-11 09:49:30 +00:00
|
|
|
"d. ! queue ! rtph264pay pt=96 name=pay0 "
|
|
|
|
"d. ! queue ! rtpmp4apay pt=97 name=pay1 " ")", argv[1]);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-01-22 15:54:07 +00:00
|
|
|
/* 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
|
2009-01-22 14:33:29 +00:00
|
|
|
* element with pay%d names will be a stream */
|
2009-01-22 15:54:07 +00:00
|
|
|
factory = gst_rtsp_media_factory_new ();
|
2009-01-29 12:31:27 +00:00
|
|
|
gst_rtsp_media_factory_set_launch (factory, str);
|
2014-09-15 14:54:05 +00:00
|
|
|
g_signal_connect (factory, "media-configure", (GCallback) media_configure_cb,
|
|
|
|
factory);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_free (str);
|
|
|
|
|
2009-01-22 15:54:07 +00:00
|
|
|
/* attach the test factory to the /test url */
|
2012-11-26 11:34:05 +00:00
|
|
|
gst_rtsp_mount_points_add_factory (mounts, "/test", factory);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
|
|
|
/* don't need the ref to the mapper anymore */
|
2012-11-26 11:34:05 +00:00
|
|
|
g_object_unref (mounts);
|
2009-01-22 14:33:29 +00:00
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/* attach the server to the default maincontext */
|
|
|
|
gst_rtsp_server_attach (server, NULL);
|
|
|
|
|
2009-01-22 14:33:29 +00:00
|
|
|
/* start serving */
|
2014-07-03 18:52:42 +00:00
|
|
|
g_print ("stream ready at rtsp://127.0.0.1:8554/test\n");
|
2008-10-09 12:29:12 +00:00
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|