gstreamer/examples/test-mp4.c

134 lines
3.9 KiB
C
Raw Normal View History

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
/* 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;
GstRTSPMountPoints *mounts;
GstRTSPMediaFactory *factory;
gchar *str;
2008-10-09 12:29:12 +00:00
gst_init (&argc, &argv);
if (argc < 2) {
2012-10-27 09:53:51 +00:00
g_message ("usage: %s <filename.mp4>", argv[0]);
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 ();
/* 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);
2010-12-11 09:49:30 +00:00
str = g_strdup_printf ("( "
"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]);
/* 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 ();
gst_rtsp_media_factory_set_launch (factory, str);
g_signal_connect (factory, "media-configure", (GCallback) media_configure_cb,
factory);
g_free (str);
/* 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);
2008-10-09 12:29:12 +00:00
/* attach the server to the default maincontext */
gst_rtsp_server_attach (server, NULL);
/* start serving */
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;
}