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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
#include <string.h>
|
2010-08-09 19:56:23 +00:00
|
|
|
#include <stdlib.h>
|
2009-05-26 17:01:10 +00:00
|
|
|
|
2009-04-14 21:38:58 +00:00
|
|
|
#include <gst/app/gstappsrc.h>
|
|
|
|
#include <gst/app/gstappsink.h>
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
#include "rtsp-media.h"
|
|
|
|
|
2011-08-16 11:25:16 +00:00
|
|
|
#define DEFAULT_SHARED FALSE
|
|
|
|
#define DEFAULT_REUSABLE FALSE
|
|
|
|
#define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_TCP
|
2010-03-19 17:03:40 +00:00
|
|
|
//#define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP_MCAST
|
2011-08-16 11:25:16 +00:00
|
|
|
#define DEFAULT_EOS_SHUTDOWN FALSE
|
|
|
|
#define DEFAULT_BUFFER_SIZE 0x80000
|
|
|
|
#define DEFAULT_MULTICAST_GROUP "224.2.0.1"
|
2009-01-29 16:20:27 +00:00
|
|
|
|
2009-05-27 09:15:22 +00:00
|
|
|
/* define to dump received RTCP packets */
|
|
|
|
#undef DUMP_STATS
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_SHARED,
|
2009-04-03 20:22:30 +00:00
|
|
|
PROP_REUSABLE,
|
2010-03-19 14:15:29 +00:00
|
|
|
PROP_PROTOCOLS,
|
2010-08-20 16:17:08 +00:00
|
|
|
PROP_EOS_SHUTDOWN,
|
2011-01-31 16:28:22 +00:00
|
|
|
PROP_BUFFER_SIZE,
|
2011-08-16 11:25:16 +00:00
|
|
|
PROP_MULTICAST_GROUP,
|
2009-01-29 16:20:27 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
2009-04-03 20:45:57 +00:00
|
|
|
enum
|
|
|
|
{
|
2010-12-13 15:58:36 +00:00
|
|
|
SIGNAL_PREPARED,
|
2009-04-03 20:45:57 +00:00
|
|
|
SIGNAL_UNPREPARED,
|
2010-12-28 17:34:10 +00:00
|
|
|
SIGNAL_NEW_STATE,
|
2009-04-03 20:45:57 +00:00
|
|
|
SIGNAL_LAST
|
|
|
|
};
|
|
|
|
|
2011-01-12 17:14:48 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_media_debug);
|
2009-11-21 18:20:23 +00:00
|
|
|
#define GST_CAT_DEFAULT rtsp_media_debug
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
static GQuark ssrc_stream_map_key;
|
|
|
|
|
2010-03-05 15:20:08 +00:00
|
|
|
static void gst_rtsp_media_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtsp_media_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
2009-01-22 16:58:19 +00:00
|
|
|
static void gst_rtsp_media_finalize (GObject * obj);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2010-03-05 15:20:08 +00:00
|
|
|
static gpointer do_loop (GstRTSPMediaClass * klass);
|
|
|
|
static gboolean default_handle_message (GstRTSPMedia * media,
|
|
|
|
GstMessage * message);
|
|
|
|
static gboolean default_unprepare (GstRTSPMedia * media);
|
|
|
|
static void unlock_streams (GstRTSPMedia * media);
|
2009-02-13 15:39:36 +00:00
|
|
|
|
2009-04-03 20:45:57 +00:00
|
|
|
static guint gst_rtsp_media_signals[SIGNAL_LAST] = { 0 };
|
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
G_DEFINE_TYPE (GstRTSPMedia, gst_rtsp_media, G_TYPE_OBJECT);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
static void
|
2009-01-22 16:58:19 +00:00
|
|
|
gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2009-02-13 15:39:36 +00:00
|
|
|
GError *error = NULL;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
gobject_class->get_property = gst_rtsp_media_get_property;
|
|
|
|
gobject_class->set_property = gst_rtsp_media_set_property;
|
2009-01-22 16:58:19 +00:00
|
|
|
gobject_class->finalize = gst_rtsp_media_finalize;
|
2009-01-29 16:20:27 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SHARED,
|
2010-03-05 15:20:08 +00:00
|
|
|
g_param_spec_boolean ("shared", "Shared",
|
|
|
|
"If this media pipeline can be shared", DEFAULT_SHARED,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-02-13 15:39:36 +00:00
|
|
|
|
2009-04-03 20:22:30 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_REUSABLE,
|
|
|
|
g_param_spec_boolean ("reusable", "Reusable",
|
|
|
|
"If this media pipeline can be reused after an unprepare",
|
|
|
|
DEFAULT_REUSABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-03-19 14:15:29 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
|
|
|
|
g_param_spec_flags ("protocols", "Protocols",
|
|
|
|
"Allowed lower transport protocols", GST_TYPE_RTSP_LOWER_TRANS,
|
|
|
|
DEFAULT_PROTOCOLS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-08-20 16:17:08 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_EOS_SHUTDOWN,
|
|
|
|
g_param_spec_boolean ("eos-shutdown", "EOS Shutdown",
|
|
|
|
"Send an EOS event to the pipeline before unpreparing",
|
|
|
|
DEFAULT_EOS_SHUTDOWN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-01-31 16:28:22 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_BUFFER_SIZE,
|
|
|
|
g_param_spec_uint ("buffer-size", "Buffer Size",
|
|
|
|
"The kernel UDP buffer size to use", 0, G_MAXUINT,
|
|
|
|
DEFAULT_BUFFER_SIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-08-16 11:25:16 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MULTICAST_GROUP,
|
|
|
|
g_param_spec_string ("multicast-group", "Multicast Group",
|
|
|
|
"The Multicast group to send media to",
|
|
|
|
DEFAULT_MULTICAST_GROUP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-12-13 15:58:36 +00:00
|
|
|
gst_rtsp_media_signals[SIGNAL_PREPARED] =
|
|
|
|
g_signal_new ("prepared", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstRTSPMediaClass, prepared), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
|
|
|
|
|
2009-04-03 20:45:57 +00:00
|
|
|
gst_rtsp_media_signals[SIGNAL_UNPREPARED] =
|
|
|
|
g_signal_new ("unprepared", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstRTSPMediaClass, unprepared), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
|
|
|
|
|
2010-12-28 17:34:10 +00:00
|
|
|
gst_rtsp_media_signals[SIGNAL_NEW_STATE] =
|
|
|
|
g_signal_new ("new-state", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstRTSPMediaClass, new_state), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 0, G_TYPE_INT);
|
|
|
|
|
2009-02-13 15:39:36 +00:00
|
|
|
klass->context = g_main_context_new ();
|
|
|
|
klass->loop = g_main_loop_new (klass->context, TRUE);
|
|
|
|
|
2011-01-13 17:57:15 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (rtsp_media_debug, "rtspmedia", 0, "GstRTSPMedia");
|
|
|
|
|
2009-02-13 15:39:36 +00:00
|
|
|
klass->thread = g_thread_create ((GThreadFunc) do_loop, klass, TRUE, &error);
|
|
|
|
if (error != NULL) {
|
|
|
|
g_critical ("could not start bus thread: %s", error->message);
|
|
|
|
}
|
|
|
|
klass->handle_message = default_handle_message;
|
2009-06-12 16:05:30 +00:00
|
|
|
klass->unprepare = default_unprepare;
|
2009-05-26 17:01:10 +00:00
|
|
|
|
|
|
|
ssrc_stream_map_key = g_quark_from_static_string ("GstRTSPServer.stream");
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-01-22 16:58:19 +00:00
|
|
|
gst_rtsp_media_init (GstRTSPMedia * media)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2009-01-22 16:58:19 +00:00
|
|
|
media->streams = g_array_new (FALSE, TRUE, sizeof (GstRTSPMediaStream *));
|
2010-03-05 16:51:26 +00:00
|
|
|
media->lock = g_mutex_new ();
|
|
|
|
media->cond = g_cond_new ();
|
2010-03-19 14:15:29 +00:00
|
|
|
|
|
|
|
media->shared = DEFAULT_SHARED;
|
|
|
|
media->reusable = DEFAULT_REUSABLE;
|
|
|
|
media->protocols = DEFAULT_PROTOCOLS;
|
2010-08-20 16:17:08 +00:00
|
|
|
media->eos_shutdown = DEFAULT_EOS_SHUTDOWN;
|
2011-01-31 16:28:22 +00:00
|
|
|
media->buffer_size = DEFAULT_BUFFER_SIZE;
|
2011-08-16 11:25:16 +00:00
|
|
|
media->multicast_group = g_strdup (DEFAULT_MULTICAST_GROUP);
|
2010-08-20 11:19:56 +00:00
|
|
|
}
|
|
|
|
|
2010-08-24 14:47:30 +00:00
|
|
|
void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_media_trans_cleanup (GstRTSPMediaTrans * trans)
|
2010-08-24 14:47:30 +00:00
|
|
|
{
|
|
|
|
if (trans->transport) {
|
|
|
|
gst_rtsp_transport_free (trans->transport);
|
|
|
|
trans->transport = NULL;
|
|
|
|
}
|
|
|
|
if (trans->rtpsource) {
|
|
|
|
g_object_set_qdata (trans->rtpsource, ssrc_stream_map_key, NULL);
|
|
|
|
trans->rtpsource = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_stream_free (GstRTSPMediaStream * stream)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2009-02-13 18:54:18 +00:00
|
|
|
if (stream->session)
|
|
|
|
g_object_unref (stream->session);
|
|
|
|
|
2009-01-30 15:24:10 +00:00
|
|
|
if (stream->caps)
|
|
|
|
gst_caps_unref (stream->caps);
|
|
|
|
|
2009-06-04 17:20:26 +00:00
|
|
|
if (stream->send_rtp_sink)
|
|
|
|
gst_object_unref (stream->send_rtp_sink);
|
|
|
|
if (stream->send_rtp_src)
|
|
|
|
gst_object_unref (stream->send_rtp_src);
|
|
|
|
if (stream->send_rtcp_src)
|
|
|
|
gst_object_unref (stream->send_rtcp_src);
|
|
|
|
if (stream->recv_rtcp_sink)
|
|
|
|
gst_object_unref (stream->recv_rtcp_sink);
|
|
|
|
if (stream->recv_rtp_sink)
|
|
|
|
gst_object_unref (stream->recv_rtp_sink);
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
g_list_free (stream->transports);
|
|
|
|
|
2009-01-30 15:24:10 +00:00
|
|
|
g_free (stream);
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-01-22 16:58:19 +00:00
|
|
|
gst_rtsp_media_finalize (GObject * obj)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2009-01-22 16:58:19 +00:00
|
|
|
GstRTSPMedia *media;
|
2008-10-09 12:29:12 +00:00
|
|
|
guint i;
|
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
media = GST_RTSP_MEDIA (obj);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("finalize media %p", media);
|
2009-06-14 21:12:13 +00:00
|
|
|
|
2009-03-04 15:33:59 +00:00
|
|
|
if (media->pipeline) {
|
2009-03-13 14:57:42 +00:00
|
|
|
unlock_streams (media);
|
2009-03-04 15:33:59 +00:00
|
|
|
gst_element_set_state (media->pipeline, GST_STATE_NULL);
|
|
|
|
gst_object_unref (media->pipeline);
|
|
|
|
}
|
2009-06-14 21:12:13 +00:00
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
for (i = 0; i < media->streams->len; i++) {
|
2008-10-09 12:29:12 +00:00
|
|
|
GstRTSPMediaStream *stream;
|
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
stream = g_array_index (media->streams, GstRTSPMediaStream *, i);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
gst_rtsp_media_stream_free (stream);
|
|
|
|
}
|
2009-01-22 16:58:19 +00:00
|
|
|
g_array_free (media->streams, TRUE);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
g_list_foreach (media->dynamic, (GFunc) gst_object_unref, NULL);
|
|
|
|
g_list_free (media->dynamic);
|
|
|
|
|
2009-02-13 15:39:36 +00:00
|
|
|
if (media->source) {
|
|
|
|
g_source_destroy (media->source);
|
|
|
|
g_source_unref (media->source);
|
|
|
|
}
|
2011-08-16 11:25:16 +00:00
|
|
|
g_free (media->multicast_group);
|
2010-03-05 16:51:26 +00:00
|
|
|
g_mutex_free (media->lock);
|
|
|
|
g_cond_free (media->cond);
|
2009-02-13 15:39:36 +00:00
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
G_OBJECT_CLASS (gst_rtsp_media_parent_class)->finalize (obj);
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2009-01-29 16:20:27 +00:00
|
|
|
{
|
|
|
|
GstRTSPMedia *media = GST_RTSP_MEDIA (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_SHARED:
|
|
|
|
g_value_set_boolean (value, gst_rtsp_media_is_shared (media));
|
|
|
|
break;
|
2009-04-03 20:22:30 +00:00
|
|
|
case PROP_REUSABLE:
|
|
|
|
g_value_set_boolean (value, gst_rtsp_media_is_reusable (media));
|
|
|
|
break;
|
2010-03-19 14:15:29 +00:00
|
|
|
case PROP_PROTOCOLS:
|
|
|
|
g_value_set_flags (value, gst_rtsp_media_get_protocols (media));
|
|
|
|
break;
|
2010-08-20 16:17:08 +00:00
|
|
|
case PROP_EOS_SHUTDOWN:
|
|
|
|
g_value_set_boolean (value, gst_rtsp_media_is_eos_shutdown (media));
|
|
|
|
break;
|
2011-01-31 16:28:22 +00:00
|
|
|
case PROP_BUFFER_SIZE:
|
|
|
|
g_value_set_uint (value, gst_rtsp_media_get_buffer_size (media));
|
|
|
|
break;
|
2011-08-16 11:25:16 +00:00
|
|
|
case PROP_MULTICAST_GROUP:
|
|
|
|
g_value_take_string (value, gst_rtsp_media_get_multicast_group (media));
|
|
|
|
break;
|
2009-01-29 16:20:27 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2009-01-29 16:20:27 +00:00
|
|
|
{
|
|
|
|
GstRTSPMedia *media = GST_RTSP_MEDIA (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_SHARED:
|
|
|
|
gst_rtsp_media_set_shared (media, g_value_get_boolean (value));
|
|
|
|
break;
|
2009-04-03 20:22:30 +00:00
|
|
|
case PROP_REUSABLE:
|
|
|
|
gst_rtsp_media_set_reusable (media, g_value_get_boolean (value));
|
|
|
|
break;
|
2010-03-19 14:15:29 +00:00
|
|
|
case PROP_PROTOCOLS:
|
|
|
|
gst_rtsp_media_set_protocols (media, g_value_get_flags (value));
|
|
|
|
break;
|
2010-08-20 16:17:08 +00:00
|
|
|
case PROP_EOS_SHUTDOWN:
|
|
|
|
gst_rtsp_media_set_eos_shutdown (media, g_value_get_boolean (value));
|
|
|
|
break;
|
2011-01-31 16:28:22 +00:00
|
|
|
case PROP_BUFFER_SIZE:
|
|
|
|
gst_rtsp_media_set_buffer_size (media, g_value_get_uint (value));
|
|
|
|
break;
|
2011-08-16 11:25:16 +00:00
|
|
|
case PROP_MULTICAST_GROUP:
|
|
|
|
gst_rtsp_media_set_multicast_group (media, g_value_get_string (value));
|
|
|
|
break;
|
2009-01-29 16:20:27 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-13 15:39:36 +00:00
|
|
|
static gpointer
|
2010-03-05 15:20:08 +00:00
|
|
|
do_loop (GstRTSPMediaClass * klass)
|
2009-02-13 15:39:36 +00:00
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("enter mainloop");
|
2009-02-13 15:39:36 +00:00
|
|
|
g_main_loop_run (klass->loop);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("exit mainloop");
|
2009-02-13 15:39:36 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-12 19:32:14 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
collect_media_stats (GstRTSPMedia * media)
|
2009-03-12 19:32:14 +00:00
|
|
|
{
|
|
|
|
gint64 position, duration;
|
|
|
|
|
|
|
|
media->range.unit = GST_RTSP_RANGE_NPT;
|
|
|
|
|
|
|
|
if (media->is_live) {
|
|
|
|
media->range.min.type = GST_RTSP_TIME_NOW;
|
|
|
|
media->range.min.seconds = -1;
|
|
|
|
media->range.max.type = GST_RTSP_TIME_END;
|
|
|
|
media->range.max.seconds = -1;
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2009-03-12 19:32:14 +00:00
|
|
|
/* get the position */
|
2011-08-04 06:59:17 +00:00
|
|
|
if (!gst_element_query_position (media->pipeline, GST_FORMAT_TIME,
|
|
|
|
&position)) {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("position query failed");
|
2009-03-12 19:32:14 +00:00
|
|
|
position = 0;
|
2009-03-13 14:57:42 +00:00
|
|
|
}
|
2009-03-12 19:32:14 +00:00
|
|
|
|
|
|
|
/* get the duration */
|
2011-08-04 06:59:17 +00:00
|
|
|
if (!gst_element_query_duration (media->pipeline, GST_FORMAT_TIME,
|
|
|
|
&duration)) {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("duration query failed");
|
2009-03-12 19:32:14 +00:00
|
|
|
duration = -1;
|
2009-03-13 14:57:42 +00:00
|
|
|
}
|
|
|
|
|
2010-03-05 15:20:08 +00:00
|
|
|
GST_INFO ("stats: position %" GST_TIME_FORMAT ", duration %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (position), GST_TIME_ARGS (duration));
|
2009-03-12 19:32:14 +00:00
|
|
|
|
2010-12-28 17:35:01 +00:00
|
|
|
if (position == -1) {
|
2009-03-12 19:32:14 +00:00
|
|
|
media->range.min.type = GST_RTSP_TIME_NOW;
|
|
|
|
media->range.min.seconds = -1;
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2009-03-12 19:32:14 +00:00
|
|
|
media->range.min.type = GST_RTSP_TIME_SECONDS;
|
2010-03-05 15:20:08 +00:00
|
|
|
media->range.min.seconds = ((gdouble) position) / GST_SECOND;
|
2009-03-12 19:32:14 +00:00
|
|
|
}
|
|
|
|
if (duration == -1) {
|
|
|
|
media->range.max.type = GST_RTSP_TIME_END;
|
|
|
|
media->range.max.seconds = -1;
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2009-03-12 19:32:14 +00:00
|
|
|
media->range.max.type = GST_RTSP_TIME_SECONDS;
|
2010-03-05 15:20:08 +00:00
|
|
|
media->range.max.seconds = ((gdouble) duration) / GST_SECOND;
|
2009-03-12 19:32:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_new:
|
|
|
|
*
|
|
|
|
* Create a new #GstRTSPMedia instance. The #GstRTSPMedia object contains the
|
|
|
|
* element to produde RTP data for one or more related (audio/video/..)
|
|
|
|
* streams.
|
|
|
|
*
|
|
|
|
* Returns: a new #GstRTSPMedia object.
|
|
|
|
*/
|
|
|
|
GstRTSPMedia *
|
|
|
|
gst_rtsp_media_new (void)
|
|
|
|
{
|
|
|
|
GstRTSPMedia *result;
|
|
|
|
|
|
|
|
result = g_object_new (GST_TYPE_RTSP_MEDIA, NULL);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_shared:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @shared: the new value
|
|
|
|
*
|
|
|
|
* Set or unset if the pipeline for @media can be shared will multiple clients.
|
|
|
|
* When @shared is %TRUE, client requests for this media will share the media
|
|
|
|
* pipeline.
|
|
|
|
*/
|
|
|
|
void
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_set_shared (GstRTSPMedia * media, gboolean shared)
|
2009-01-29 16:20:27 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
media->shared = shared;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_is_shared:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Check if the pipeline for @media can be shared between multiple clients.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the media can be shared between clients.
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_is_shared (GstRTSPMedia * media)
|
2009-01-29 16:20:27 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
|
|
|
return media->shared;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-04-03 20:22:30 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_reusable:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @reusable: the new value
|
|
|
|
*
|
|
|
|
* Set or unset if the pipeline for @media can be reused after the pipeline has
|
|
|
|
* been unprepared.
|
|
|
|
*/
|
|
|
|
void
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_set_reusable (GstRTSPMedia * media, gboolean reusable)
|
2009-04-03 20:22:30 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
media->reusable = reusable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_is_reusable:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Check if the pipeline for @media can be reused after an unprepare.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the media can be reused
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_is_reusable (GstRTSPMedia * media)
|
2009-04-03 20:22:30 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
|
|
|
return media->reusable;
|
|
|
|
}
|
|
|
|
|
2010-03-19 14:15:29 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_protocols:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @protocols: the new flags
|
|
|
|
*
|
|
|
|
* Configure the allowed lower transport for @media.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_set_protocols (GstRTSPMedia * media, GstRTSPLowerTrans protocols)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
media->protocols = protocols;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_protocols:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the allowed protocols of @media.
|
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPLowerTrans
|
|
|
|
*/
|
|
|
|
GstRTSPLowerTrans
|
|
|
|
gst_rtsp_media_get_protocols (GstRTSPMedia * media)
|
|
|
|
{
|
2010-12-11 09:48:42 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media),
|
|
|
|
GST_RTSP_LOWER_TRANS_UNKNOWN);
|
2010-03-19 14:15:29 +00:00
|
|
|
|
|
|
|
return media->protocols;
|
|
|
|
}
|
|
|
|
|
2010-08-20 16:17:08 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_eos_shutdown:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @eos_shutdown: the new value
|
|
|
|
*
|
|
|
|
* Set or unset if an EOS event will be sent to the pipeline for @media before
|
|
|
|
* it is unprepared.
|
|
|
|
*/
|
|
|
|
void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_media_set_eos_shutdown (GstRTSPMedia * media, gboolean eos_shutdown)
|
2010-08-20 16:17:08 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
media->eos_shutdown = eos_shutdown;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_is_eos_shutdown:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Check if the pipeline for @media will send an EOS down the pipeline before
|
|
|
|
* unpreparing.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the media will send EOS before unpreparing.
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_media_is_eos_shutdown (GstRTSPMedia * media)
|
2010-08-20 16:17:08 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
|
|
|
return media->eos_shutdown;
|
|
|
|
}
|
|
|
|
|
2011-01-31 16:28:22 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_buffer_size:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @size: the new value
|
|
|
|
*
|
|
|
|
* Set the kernel UDP buffer size.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_set_buffer_size (GstRTSPMedia * media, guint size)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
media->buffer_size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_buffer_size:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the kernel UDP buffer size.
|
|
|
|
*
|
|
|
|
* Returns: the kernel UDP buffer size.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_media_get_buffer_size (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
|
|
|
|
return media->buffer_size;
|
|
|
|
}
|
|
|
|
|
2011-08-16 11:25:16 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_multicast_group:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @mc: the new multicast group
|
|
|
|
*
|
|
|
|
* Set the multicast group that media from @media will be streamed to.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_set_multicast_group (GstRTSPMedia * media, const gchar * mc)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
g_mutex_lock (media->lock);
|
|
|
|
g_free (media->multicast_group);
|
|
|
|
media->multicast_group = g_strdup (mc);
|
|
|
|
g_mutex_unlock (media->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_multicast_group:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the multicast group that media from @media will be streamed to.
|
|
|
|
*
|
|
|
|
* Returns: the multicast group
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gst_rtsp_media_get_multicast_group (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
gchar *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
|
|
|
|
|
|
|
g_mutex_lock (media->lock);
|
|
|
|
result = g_strdup (media->multicast_group);
|
|
|
|
g_mutex_unlock (media->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-01-12 12:57:09 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_set_auth:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @auth: a #GstRTSPAuth
|
|
|
|
*
|
|
|
|
* configure @auth to be used as the authentication manager of @media.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_media_set_auth (GstRTSPMedia * media, GstRTSPAuth * auth)
|
|
|
|
{
|
|
|
|
GstRTSPAuth *old;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
|
|
|
|
|
|
|
old = media->auth;
|
|
|
|
|
|
|
|
if (old != auth) {
|
|
|
|
if (auth)
|
|
|
|
g_object_ref (auth);
|
|
|
|
media->auth = auth;
|
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_auth:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPAuth used as the authentication manager of @media.
|
|
|
|
*
|
|
|
|
* Returns: the #GstRTSPAuth of @media. g_object_unref() after
|
|
|
|
* usage.
|
|
|
|
*/
|
|
|
|
GstRTSPAuth *
|
|
|
|
gst_rtsp_media_get_auth (GstRTSPMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPAuth *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
|
|
|
|
|
|
|
if ((result = media->auth))
|
|
|
|
g_object_ref (result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-09 12:29:12 +00:00
|
|
|
/**
|
2009-01-22 16:58:19 +00:00
|
|
|
* gst_rtsp_media_n_streams:
|
|
|
|
* @media: a #GstRTSPMedia
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
2009-01-22 16:58:19 +00:00
|
|
|
* Get the number of streams in this media.
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
|
|
|
* Returns: The number of streams.
|
|
|
|
*/
|
|
|
|
guint
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_n_streams (GstRTSPMedia * media)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
2009-01-22 16:58:19 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), 0);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
return media->streams->len;
|
2008-10-09 12:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-22 16:58:19 +00:00
|
|
|
* gst_rtsp_media_get_stream:
|
|
|
|
* @media: a #GstRTSPMedia
|
2008-10-09 12:29:12 +00:00
|
|
|
* @idx: the stream index
|
|
|
|
*
|
2009-01-22 16:58:19 +00:00
|
|
|
* Retrieve the stream with index @idx from @media.
|
2008-10-09 12:29:12 +00:00
|
|
|
*
|
2009-01-30 15:24:10 +00:00
|
|
|
* Returns: the #GstRTSPMediaStream at index @idx or %NULL when a stream with
|
|
|
|
* that index did not exist.
|
2008-10-09 12:29:12 +00:00
|
|
|
*/
|
|
|
|
GstRTSPMediaStream *
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_get_stream (GstRTSPMedia * media, guint idx)
|
2008-10-09 12:29:12 +00:00
|
|
|
{
|
|
|
|
GstRTSPMediaStream *res;
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2009-01-22 16:58:19 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
2008-10-09 12:29:12 +00:00
|
|
|
|
2009-01-30 15:24:10 +00:00
|
|
|
if (idx < media->streams->len)
|
|
|
|
res = g_array_index (media->streams, GstRTSPMediaStream *, idx);
|
|
|
|
else
|
|
|
|
res = NULL;
|
2008-10-09 12:29:12 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-12-28 17:35:01 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_get_range_string:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
* @play: for the PLAY request
|
|
|
|
*
|
|
|
|
* Get the current range as a string.
|
|
|
|
*
|
|
|
|
* Returns: The range as a string, g_free() after usage.
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gst_rtsp_media_get_range_string (GstRTSPMedia * media, gboolean play)
|
|
|
|
{
|
|
|
|
gchar *result;
|
|
|
|
GstRTSPTimeRange range;
|
|
|
|
|
|
|
|
/* make copy */
|
|
|
|
range = media->range;
|
|
|
|
|
|
|
|
if (!play && media->active > 0) {
|
|
|
|
range.min.type = GST_RTSP_TIME_NOW;
|
|
|
|
range.min.seconds = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = gst_rtsp_range_to_string (&range);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-03-12 19:32:14 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_seek:
|
2010-12-11 09:48:25 +00:00
|
|
|
* @media: a #GstRTSPMedia
|
2009-03-12 19:32:14 +00:00
|
|
|
* @range: a #GstRTSPTimeRange
|
|
|
|
*
|
|
|
|
* Seek the pipeline to @range.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_seek (GstRTSPMedia * media, GstRTSPTimeRange * range)
|
2009-03-12 19:32:14 +00:00
|
|
|
{
|
|
|
|
GstSeekFlags flags;
|
|
|
|
gboolean res;
|
|
|
|
gint64 start, stop;
|
|
|
|
GstSeekType start_type, stop_type;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
g_return_val_if_fail (range != NULL, FALSE);
|
|
|
|
|
|
|
|
if (range->unit != GST_RTSP_RANGE_NPT)
|
|
|
|
goto not_supported;
|
|
|
|
|
|
|
|
/* depends on the current playing state of the pipeline. We might need to
|
|
|
|
* queue this until we get EOS. */
|
2009-04-29 15:24:46 +00:00
|
|
|
flags = GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_KEY_UNIT;
|
2009-03-12 19:32:14 +00:00
|
|
|
|
|
|
|
start_type = stop_type = GST_SEEK_TYPE_NONE;
|
|
|
|
|
|
|
|
switch (range->min.type) {
|
|
|
|
case GST_RTSP_TIME_NOW:
|
|
|
|
start = -1;
|
|
|
|
break;
|
|
|
|
case GST_RTSP_TIME_SECONDS:
|
2009-03-13 14:57:42 +00:00
|
|
|
/* only seek when something changed */
|
|
|
|
if (media->range.min.seconds == range->min.seconds) {
|
|
|
|
start = -1;
|
|
|
|
} else {
|
|
|
|
start = range->min.seconds * GST_SECOND;
|
|
|
|
start_type = GST_SEEK_TYPE_SET;
|
|
|
|
}
|
2009-03-12 19:32:14 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_TIME_END:
|
|
|
|
default:
|
|
|
|
goto weird_type;
|
|
|
|
}
|
|
|
|
switch (range->max.type) {
|
|
|
|
case GST_RTSP_TIME_SECONDS:
|
2009-03-13 14:57:42 +00:00
|
|
|
/* only seek when something changed */
|
|
|
|
if (media->range.max.seconds == range->max.seconds) {
|
|
|
|
stop = -1;
|
|
|
|
} else {
|
|
|
|
stop = range->max.seconds * GST_SECOND;
|
|
|
|
stop_type = GST_SEEK_TYPE_SET;
|
|
|
|
}
|
2009-03-12 19:32:14 +00:00
|
|
|
break;
|
|
|
|
case GST_RTSP_TIME_END:
|
|
|
|
stop = -1;
|
|
|
|
stop_type = GST_SEEK_TYPE_SET;
|
|
|
|
break;
|
|
|
|
case GST_RTSP_TIME_NOW:
|
|
|
|
default:
|
|
|
|
goto weird_type;
|
|
|
|
}
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2009-03-12 19:32:14 +00:00
|
|
|
if (start != -1 || stop != -1) {
|
2010-03-05 15:20:08 +00:00
|
|
|
GST_INFO ("seeking to %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (start), GST_TIME_ARGS (stop));
|
2009-03-12 19:32:14 +00:00
|
|
|
|
|
|
|
res = gst_element_seek (media->pipeline, 1.0, GST_FORMAT_TIME,
|
2010-03-05 12:28:58 +00:00
|
|
|
flags, start_type, start, stop_type, stop);
|
2009-03-12 19:32:14 +00:00
|
|
|
|
|
|
|
/* and block for the seek to complete */
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("done seeking %d", res);
|
2009-03-13 14:57:42 +00:00
|
|
|
gst_element_get_state (media->pipeline, NULL, NULL, -1);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("prerolled again");
|
2010-03-05 18:08:08 +00:00
|
|
|
|
|
|
|
collect_media_stats (media);
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("no seek needed");
|
2009-03-12 19:32:14 +00:00
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
not_supported:
|
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_WARNING ("seek unit %d not supported", range->unit);
|
2009-03-12 19:32:14 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
weird_type:
|
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_WARNING ("weird range type %d not supported", range->min.type);
|
2009-03-12 19:32:14 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_stream_rtp:
|
|
|
|
* @stream: a #GstRTSPMediaStream
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
*
|
|
|
|
* Handle an RTP buffer for the stream. This method is usually called when a
|
|
|
|
* message has been received from a client using the TCP transport.
|
|
|
|
*
|
2009-04-14 21:38:58 +00:00
|
|
|
* This function takes ownership of @buffer.
|
|
|
|
*
|
2009-03-11 15:45:12 +00:00
|
|
|
* Returns: a GstFlowReturn.
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_stream_rtp (GstRTSPMediaStream * stream, GstBuffer * buffer)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
2009-04-14 21:38:58 +00:00
|
|
|
ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (stream->appsrc[0]), buffer);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_stream_rtcp:
|
|
|
|
* @stream: a #GstRTSPMediaStream
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
*
|
|
|
|
* Handle an RTCP buffer for the stream. This method is usually called when a
|
|
|
|
* message has been received from a client using the TCP transport.
|
|
|
|
*
|
2009-04-14 21:38:58 +00:00
|
|
|
* This function takes ownership of @buffer.
|
|
|
|
*
|
2009-03-11 15:45:12 +00:00
|
|
|
* Returns: a GstFlowReturn.
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_stream_rtcp (GstRTSPMediaStream * stream, GstBuffer * buffer)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
2009-04-14 21:38:58 +00:00
|
|
|
ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (stream->appsrc[1]), buffer);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-04-14 21:38:58 +00:00
|
|
|
return ret;
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* Allocate the udp ports and sockets */
|
|
|
|
static gboolean
|
2010-03-16 17:37:18 +00:00
|
|
|
alloc_udp_ports (GstRTSPMedia * media, GstRTSPMediaStream * stream)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
GstElement *udpsrc0, *udpsrc1;
|
|
|
|
GstElement *udpsink0, *udpsink1;
|
|
|
|
gint tmp_rtp, tmp_rtcp;
|
|
|
|
guint count;
|
|
|
|
gint rtpport, rtcpport, sockfd;
|
2010-03-10 10:45:06 +00:00
|
|
|
const gchar *host;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
udpsrc0 = NULL;
|
|
|
|
udpsrc1 = NULL;
|
|
|
|
udpsink0 = NULL;
|
|
|
|
udpsink1 = NULL;
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
/* Start with random port */
|
|
|
|
tmp_rtp = 0;
|
|
|
|
|
2010-03-16 17:37:18 +00:00
|
|
|
if (media->is_ipv6)
|
2010-03-10 10:45:06 +00:00
|
|
|
host = "udp://[::0]";
|
|
|
|
else
|
|
|
|
host = "udp://0.0.0.0";
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* try to allocate 2 UDP ports, the RTP port should be an even
|
|
|
|
* number and the RTCP port should be the next (uneven) port */
|
|
|
|
again:
|
2010-03-10 10:45:06 +00:00
|
|
|
udpsrc0 = gst_element_make_from_uri (GST_URI_SRC, host, NULL);
|
2009-01-29 12:31:27 +00:00
|
|
|
if (udpsrc0 == NULL)
|
|
|
|
goto no_udp_protocol;
|
|
|
|
g_object_set (G_OBJECT (udpsrc0), "port", tmp_rtp, NULL);
|
|
|
|
|
|
|
|
ret = gst_element_set_state (udpsrc0, GST_STATE_PAUSED);
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE) {
|
|
|
|
if (tmp_rtp != 0) {
|
|
|
|
tmp_rtp += 2;
|
|
|
|
if (++count > 20)
|
|
|
|
goto no_ports;
|
|
|
|
|
|
|
|
gst_element_set_state (udpsrc0, GST_STATE_NULL);
|
|
|
|
gst_object_unref (udpsrc0);
|
|
|
|
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
goto no_udp_protocol;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (udpsrc0), "port", &tmp_rtp, NULL);
|
|
|
|
|
|
|
|
/* check if port is even */
|
|
|
|
if ((tmp_rtp & 1) != 0) {
|
|
|
|
/* port not even, close and allocate another */
|
|
|
|
if (++count > 20)
|
|
|
|
goto no_ports;
|
|
|
|
|
|
|
|
gst_element_set_state (udpsrc0, GST_STATE_NULL);
|
|
|
|
gst_object_unref (udpsrc0);
|
|
|
|
|
|
|
|
tmp_rtp++;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate port+1 for RTCP now */
|
2010-03-10 10:45:06 +00:00
|
|
|
udpsrc1 = gst_element_make_from_uri (GST_URI_SRC, host, NULL);
|
2009-01-29 12:31:27 +00:00
|
|
|
if (udpsrc1 == NULL)
|
|
|
|
goto no_udp_rtcp_protocol;
|
|
|
|
|
|
|
|
/* set port */
|
|
|
|
tmp_rtcp = tmp_rtp + 1;
|
|
|
|
g_object_set (G_OBJECT (udpsrc1), "port", tmp_rtcp, NULL);
|
|
|
|
|
|
|
|
ret = gst_element_set_state (udpsrc1, GST_STATE_PAUSED);
|
|
|
|
/* tmp_rtcp port is busy already : retry to make rtp/rtcp pair */
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE) {
|
|
|
|
|
|
|
|
if (++count > 20)
|
|
|
|
goto no_ports;
|
|
|
|
|
|
|
|
gst_element_set_state (udpsrc0, GST_STATE_NULL);
|
|
|
|
gst_object_unref (udpsrc0);
|
|
|
|
|
|
|
|
gst_element_set_state (udpsrc1, GST_STATE_NULL);
|
|
|
|
gst_object_unref (udpsrc1);
|
|
|
|
|
|
|
|
tmp_rtp += 2;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* all fine, do port check */
|
|
|
|
g_object_get (G_OBJECT (udpsrc0), "port", &rtpport, NULL);
|
|
|
|
g_object_get (G_OBJECT (udpsrc1), "port", &rtcpport, NULL);
|
|
|
|
|
|
|
|
/* this should not happen... */
|
|
|
|
if (rtpport != tmp_rtp || rtcpport != tmp_rtcp)
|
|
|
|
goto port_error;
|
|
|
|
|
|
|
|
udpsink0 = gst_element_factory_make ("multiudpsink", NULL);
|
|
|
|
if (!udpsink0)
|
|
|
|
goto no_udp_protocol;
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (udpsrc0), "sock", &sockfd, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink0), "sockfd", sockfd, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink0), "closefd", FALSE, NULL);
|
|
|
|
|
|
|
|
udpsink1 = gst_element_factory_make ("multiudpsink", NULL);
|
|
|
|
if (!udpsink1)
|
|
|
|
goto no_udp_protocol;
|
|
|
|
|
2010-12-11 09:48:42 +00:00
|
|
|
if (g_object_class_find_property (G_OBJECT_GET_CLASS (udpsink0),
|
|
|
|
"send-duplicates")) {
|
2010-08-20 13:58:39 +00:00
|
|
|
g_object_set (G_OBJECT (udpsink0), "send-duplicates", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "send-duplicates", FALSE, NULL);
|
2010-12-11 09:48:42 +00:00
|
|
|
} else {
|
2011-02-02 14:30:45 +00:00
|
|
|
g_warning
|
|
|
|
("old multiudpsink version found without send-duplicates property");
|
2010-08-20 13:58:39 +00:00
|
|
|
}
|
|
|
|
|
2011-01-05 11:06:23 +00:00
|
|
|
if (g_object_class_find_property (G_OBJECT_GET_CLASS (udpsink0),
|
|
|
|
"buffer-size")) {
|
2011-01-31 16:28:22 +00:00
|
|
|
g_object_set (G_OBJECT (udpsink0), "buffer-size", media->buffer_size, NULL);
|
2011-01-05 11:06:23 +00:00
|
|
|
} else {
|
|
|
|
GST_WARNING ("multiudpsink version found without buffer-size property");
|
2010-08-20 13:58:39 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
g_object_get (G_OBJECT (udpsrc1), "sock", &sockfd, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "sockfd", sockfd, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "closefd", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "sync", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "async", FALSE, NULL);
|
|
|
|
|
2010-03-05 12:28:58 +00:00
|
|
|
g_object_set (G_OBJECT (udpsink0), "auto-multicast", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink0), "loop", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "auto-multicast", FALSE, NULL);
|
|
|
|
g_object_set (G_OBJECT (udpsink1), "loop", FALSE, NULL);
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* we keep these elements, we configure all in configure_transport when the
|
|
|
|
* server told us to really use the UDP ports. */
|
2009-01-30 15:24:10 +00:00
|
|
|
stream->udpsrc[0] = udpsrc0;
|
|
|
|
stream->udpsrc[1] = udpsrc1;
|
|
|
|
stream->udpsink[0] = udpsink0;
|
|
|
|
stream->udpsink[1] = udpsink1;
|
2009-01-29 12:31:27 +00:00
|
|
|
stream->server_port.min = rtpport;
|
|
|
|
stream->server_port.max = rtcpport;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_udp_protocol:
|
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
no_ports:
|
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
no_udp_rtcp_protocol:
|
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
port_error:
|
|
|
|
{
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
cleanup:
|
|
|
|
{
|
|
|
|
if (udpsrc0) {
|
|
|
|
gst_element_set_state (udpsrc0, GST_STATE_NULL);
|
|
|
|
gst_object_unref (udpsrc0);
|
|
|
|
}
|
|
|
|
if (udpsrc1) {
|
|
|
|
gst_element_set_state (udpsrc1, GST_STATE_NULL);
|
|
|
|
gst_object_unref (udpsrc1);
|
|
|
|
}
|
|
|
|
if (udpsink0) {
|
|
|
|
gst_element_set_state (udpsink0, GST_STATE_NULL);
|
|
|
|
gst_object_unref (udpsink0);
|
|
|
|
}
|
|
|
|
if (udpsink1) {
|
|
|
|
gst_element_set_state (udpsink1, GST_STATE_NULL);
|
|
|
|
gst_object_unref (udpsink1);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-24 14:47:30 +00:00
|
|
|
/* executed from streaming thread */
|
2009-01-29 12:31:27 +00:00
|
|
|
static void
|
|
|
|
caps_notify (GstPad * pad, GParamSpec * unused, GstRTSPMediaStream * stream)
|
|
|
|
{
|
|
|
|
gchar *capsstr;
|
2009-03-06 18:34:14 +00:00
|
|
|
GstCaps *newcaps, *oldcaps;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2011-05-17 07:48:13 +00:00
|
|
|
newcaps = gst_pad_get_current_caps (pad);
|
2009-03-06 18:34:14 +00:00
|
|
|
|
|
|
|
oldcaps = stream->caps;
|
|
|
|
stream->caps = newcaps;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-03-06 18:34:14 +00:00
|
|
|
if (oldcaps)
|
|
|
|
gst_caps_unref (oldcaps);
|
|
|
|
|
|
|
|
capsstr = gst_caps_to_string (newcaps);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("stream %p received caps %p, %s", stream, newcaps, capsstr);
|
2009-01-29 12:31:27 +00:00
|
|
|
g_free (capsstr);
|
|
|
|
}
|
|
|
|
|
2009-05-26 09:42:41 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
dump_structure (const GstStructure * s)
|
2009-05-26 09:42:41 +00:00
|
|
|
{
|
|
|
|
gchar *sstr;
|
|
|
|
|
|
|
|
sstr = gst_structure_to_string (s);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("structure: %s", sstr);
|
2009-05-26 09:42:41 +00:00
|
|
|
g_free (sstr);
|
|
|
|
}
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
static GstRTSPMediaTrans *
|
2010-03-05 15:20:08 +00:00
|
|
|
find_transport (GstRTSPMediaStream * stream, const gchar * rtcp_from)
|
2009-05-26 17:01:10 +00:00
|
|
|
{
|
|
|
|
GList *walk;
|
|
|
|
GstRTSPMediaTrans *result = NULL;
|
2009-05-26 17:05:07 +00:00
|
|
|
const gchar *tmp;
|
|
|
|
gchar *dest;
|
2009-05-26 17:01:10 +00:00
|
|
|
guint port;
|
|
|
|
|
|
|
|
if (rtcp_from == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2009-05-26 17:05:07 +00:00
|
|
|
tmp = g_strrstr (rtcp_from, ":");
|
|
|
|
if (tmp == NULL)
|
2009-05-26 17:01:10 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-05-26 17:05:07 +00:00
|
|
|
port = atoi (tmp + 1);
|
|
|
|
dest = g_strndup (rtcp_from, tmp - rtcp_from);
|
2009-05-26 17:01:10 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("finding %s:%d", dest, port);
|
2009-05-26 17:01:10 +00:00
|
|
|
|
|
|
|
for (walk = stream->transports; walk; walk = g_list_next (walk)) {
|
|
|
|
GstRTSPMediaTrans *trans = walk->data;
|
|
|
|
gint min, max;
|
|
|
|
|
|
|
|
min = trans->transport->client_port.min;
|
|
|
|
max = trans->transport->client_port.max;
|
|
|
|
|
2010-03-05 15:20:08 +00:00
|
|
|
if ((strcmp (trans->transport->destination, dest) == 0) && (min == port
|
|
|
|
|| max == port)) {
|
2009-05-26 17:01:10 +00:00
|
|
|
result = trans;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-05-26 17:05:07 +00:00
|
|
|
g_free (dest);
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-02-13 18:54:18 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
on_new_ssrc (GObject * session, GObject * source, GstRTSPMediaStream * stream)
|
2009-02-13 18:54:18 +00:00
|
|
|
{
|
2009-05-26 17:01:10 +00:00
|
|
|
GstStructure *stats;
|
|
|
|
GstRTSPMediaTrans *trans;
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("%p: new source %p", stream, source);
|
2009-05-26 17:01:10 +00:00
|
|
|
|
|
|
|
/* see if we have a stream to match with the origin of the RTCP packet */
|
|
|
|
trans = g_object_get_qdata (source, ssrc_stream_map_key);
|
|
|
|
if (trans == NULL) {
|
|
|
|
g_object_get (source, "stats", &stats, NULL);
|
|
|
|
if (stats) {
|
|
|
|
const gchar *rtcp_from;
|
|
|
|
|
2009-05-26 17:20:07 +00:00
|
|
|
dump_structure (stats);
|
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
rtcp_from = gst_structure_get_string (stats, "rtcp-from");
|
|
|
|
if ((trans = find_transport (stream, rtcp_from))) {
|
2010-03-05 15:20:08 +00:00
|
|
|
GST_INFO ("%p: found transport %p for source %p", stream, trans,
|
|
|
|
source);
|
2009-05-26 17:20:07 +00:00
|
|
|
|
2010-03-05 12:28:58 +00:00
|
|
|
/* keep ref to the source */
|
|
|
|
trans->rtpsource = source;
|
2009-05-26 17:20:07 +00:00
|
|
|
|
2009-05-26 17:01:10 +00:00
|
|
|
g_object_set_qdata (source, ssrc_stream_map_key, trans);
|
|
|
|
}
|
2009-05-26 17:20:07 +00:00
|
|
|
gst_structure_free (stats);
|
2009-05-26 17:01:10 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("%p: source %p for transport %p", stream, source, trans);
|
2009-05-26 17:01:10 +00:00
|
|
|
}
|
2009-02-13 18:54:18 +00:00
|
|
|
}
|
|
|
|
|
2009-05-26 09:42:41 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
on_ssrc_sdes (GObject * session, GObject * source, GstRTSPMediaStream * stream)
|
2009-05-26 09:42:41 +00:00
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("%p: new SDES %p", stream, source);
|
2009-05-26 09:42:41 +00:00
|
|
|
}
|
|
|
|
|
2009-02-13 18:54:18 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
on_ssrc_active (GObject * session, GObject * source,
|
|
|
|
GstRTSPMediaStream * stream)
|
2009-02-13 18:54:18 +00:00
|
|
|
{
|
2009-05-26 17:01:10 +00:00
|
|
|
GstRTSPMediaTrans *trans;
|
|
|
|
|
|
|
|
trans = g_object_get_qdata (source, ssrc_stream_map_key);
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("%p: source %p in transport %p is active", stream, source, trans);
|
2009-05-26 17:01:10 +00:00
|
|
|
|
2009-05-26 17:20:07 +00:00
|
|
|
if (trans && trans->keep_alive)
|
2009-05-26 17:01:10 +00:00
|
|
|
trans->keep_alive (trans->ka_user_data);
|
2009-05-27 09:15:22 +00:00
|
|
|
|
|
|
|
#ifdef DUMP_STATS
|
|
|
|
{
|
|
|
|
GstStructure *stats;
|
|
|
|
g_object_get (source, "stats", &stats, NULL);
|
|
|
|
if (stats) {
|
|
|
|
dump_structure (stats);
|
|
|
|
gst_structure_free (stats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-02-13 18:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
on_bye_ssrc (GObject * session, GObject * source, GstRTSPMediaStream * stream)
|
2009-02-13 18:54:18 +00:00
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("%p: source %p bye", stream, source);
|
2009-02-13 18:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
on_bye_timeout (GObject * session, GObject * source,
|
|
|
|
GstRTSPMediaStream * stream)
|
2009-02-13 18:54:18 +00:00
|
|
|
{
|
2009-05-26 17:20:07 +00:00
|
|
|
GstRTSPMediaTrans *trans;
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("%p: source %p bye timeout", stream, source);
|
2009-05-26 17:20:07 +00:00
|
|
|
|
|
|
|
if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
|
|
|
|
trans->rtpsource = NULL;
|
|
|
|
trans->timeout = TRUE;
|
|
|
|
}
|
2009-02-13 18:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
on_timeout (GObject * session, GObject * source, GstRTSPMediaStream * stream)
|
2009-02-13 18:54:18 +00:00
|
|
|
{
|
2009-05-26 17:20:07 +00:00
|
|
|
GstRTSPMediaTrans *trans;
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("%p: source %p timeout", stream, source);
|
2009-05-26 17:20:07 +00:00
|
|
|
|
|
|
|
if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
|
|
|
|
trans->rtpsource = NULL;
|
|
|
|
trans->timeout = TRUE;
|
|
|
|
}
|
2009-02-13 18:54:18 +00:00
|
|
|
}
|
|
|
|
|
2009-04-14 21:38:58 +00:00
|
|
|
static GstFlowReturn
|
2010-03-05 15:20:08 +00:00
|
|
|
handle_new_buffer (GstAppSink * sink, gpointer user_data)
|
2009-03-11 15:45:12 +00:00
|
|
|
{
|
|
|
|
GList *walk;
|
|
|
|
GstBuffer *buffer;
|
2009-04-14 21:38:58 +00:00
|
|
|
GstRTSPMediaStream *stream;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-04-14 21:38:58 +00:00
|
|
|
buffer = gst_app_sink_pull_buffer (sink);
|
2009-03-11 15:45:12 +00:00
|
|
|
if (!buffer)
|
2009-04-14 21:38:58 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
stream = (GstRTSPMediaStream *) user_data;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
for (walk = stream->transports; walk; walk = g_list_next (walk)) {
|
|
|
|
GstRTSPMediaTrans *tr = (GstRTSPMediaTrans *) walk->data;
|
|
|
|
|
2009-04-14 21:38:58 +00:00
|
|
|
if (GST_ELEMENT_CAST (sink) == stream->appsink[0]) {
|
2010-03-05 15:20:08 +00:00
|
|
|
if (tr->send_rtp)
|
2009-03-11 15:45:12 +00:00
|
|
|
tr->send_rtp (buffer, tr->transport->interleaved.min, tr->user_data);
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
|
|
|
if (tr->send_rtcp)
|
2009-03-11 15:45:12 +00:00
|
|
|
tr->send_rtcp (buffer, tr->transport->interleaved.max, tr->user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_buffer_unref (buffer);
|
2009-04-14 21:38:58 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-29 15:26:41 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
handle_new_buffer_list (GstAppSink * sink, gpointer user_data)
|
|
|
|
{
|
|
|
|
GList *walk;
|
|
|
|
GstBufferList *blist;
|
|
|
|
GstRTSPMediaStream *stream;
|
|
|
|
|
|
|
|
blist = gst_app_sink_pull_buffer_list (sink);
|
|
|
|
if (!blist)
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
stream = (GstRTSPMediaStream *) user_data;
|
|
|
|
|
|
|
|
for (walk = stream->transports; walk; walk = g_list_next (walk)) {
|
|
|
|
GstRTSPMediaTrans *tr = (GstRTSPMediaTrans *) walk->data;
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CAST (sink) == stream->appsink[0]) {
|
|
|
|
if (tr->send_rtp_list)
|
|
|
|
tr->send_rtp_list (blist, tr->transport->interleaved.min,
|
|
|
|
tr->user_data);
|
|
|
|
} else {
|
|
|
|
if (tr->send_rtcp_list)
|
|
|
|
tr->send_rtcp_list (blist, tr->transport->interleaved.max,
|
|
|
|
tr->user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_buffer_list_unref (blist);
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2009-04-14 21:38:58 +00:00
|
|
|
static GstAppSinkCallbacks sink_cb = {
|
2010-03-05 15:20:08 +00:00
|
|
|
NULL, /* not interested in EOS */
|
|
|
|
NULL, /* not interested in preroll buffers */
|
2010-12-29 15:26:41 +00:00
|
|
|
handle_new_buffer,
|
|
|
|
handle_new_buffer_list
|
2009-04-14 21:38:58 +00:00
|
|
|
};
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* prepare the pipeline objects to handle @stream in @media */
|
|
|
|
static gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
setup_stream (GstRTSPMediaStream * stream, guint idx, GstRTSPMedia * media)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
|
|
|
gchar *name;
|
2009-03-11 15:45:12 +00:00
|
|
|
GstPad *pad, *teepad, *selpad;
|
|
|
|
GstPadLinkReturn ret;
|
|
|
|
gint i;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* allocate udp ports, we will have 4 of them, 2 for receiving RTP/RTCP and 2
|
|
|
|
* for sending RTP/RTCP. The sender and receiver ports are shared between the
|
|
|
|
* elements */
|
2010-03-16 17:37:18 +00:00
|
|
|
if (!alloc_udp_ports (media, stream))
|
2009-03-11 15:45:12 +00:00
|
|
|
return FALSE;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* add the ports to the pipeline */
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
gst_bin_add (GST_BIN_CAST (media->pipeline), stream->udpsink[i]);
|
|
|
|
gst_bin_add (GST_BIN_CAST (media->pipeline), stream->udpsrc[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create elements for the TCP transfer */
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
stream->appsrc[i] = gst_element_factory_make ("appsrc", NULL);
|
|
|
|
stream->appsink[i] = gst_element_factory_make ("appsink", NULL);
|
|
|
|
g_object_set (stream->appsink[i], "async", FALSE, "sync", FALSE, NULL);
|
2009-04-14 21:38:58 +00:00
|
|
|
g_object_set (stream->appsink[i], "emit-signals", FALSE, NULL);
|
2009-03-11 15:45:12 +00:00
|
|
|
g_object_set (stream->appsink[i], "preroll-queue-len", 1, NULL);
|
|
|
|
gst_bin_add (GST_BIN_CAST (media->pipeline), stream->appsink[i]);
|
|
|
|
gst_bin_add (GST_BIN_CAST (media->pipeline), stream->appsrc[i]);
|
2009-04-14 21:38:58 +00:00
|
|
|
gst_app_sink_set_callbacks (GST_APP_SINK_CAST (stream->appsink[i]),
|
2010-03-05 15:20:08 +00:00
|
|
|
&sink_cb, stream, NULL);
|
2009-03-11 15:45:12 +00:00
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
/* hook up the stream to the RTP session elements. */
|
2009-01-30 13:53:28 +00:00
|
|
|
name = g_strdup_printf ("send_rtp_sink_%d", idx);
|
2009-01-29 12:31:27 +00:00
|
|
|
stream->send_rtp_sink = gst_element_get_request_pad (media->rtpbin, name);
|
|
|
|
g_free (name);
|
2009-01-30 13:53:28 +00:00
|
|
|
name = g_strdup_printf ("send_rtp_src_%d", idx);
|
2009-01-29 12:31:27 +00:00
|
|
|
stream->send_rtp_src = gst_element_get_static_pad (media->rtpbin, name);
|
|
|
|
g_free (name);
|
2009-01-30 13:53:28 +00:00
|
|
|
name = g_strdup_printf ("send_rtcp_src_%d", idx);
|
2009-01-29 12:31:27 +00:00
|
|
|
stream->send_rtcp_src = gst_element_get_request_pad (media->rtpbin, name);
|
|
|
|
g_free (name);
|
2009-01-30 13:53:28 +00:00
|
|
|
name = g_strdup_printf ("recv_rtcp_sink_%d", idx);
|
2009-01-29 12:31:27 +00:00
|
|
|
stream->recv_rtcp_sink = gst_element_get_request_pad (media->rtpbin, name);
|
|
|
|
g_free (name);
|
2009-05-15 15:58:44 +00:00
|
|
|
name = g_strdup_printf ("recv_rtp_sink_%d", idx);
|
|
|
|
stream->recv_rtp_sink = gst_element_get_request_pad (media->rtpbin, name);
|
|
|
|
g_free (name);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-02-13 18:54:18 +00:00
|
|
|
/* get the session */
|
|
|
|
g_signal_emit_by_name (media->rtpbin, "get-internal-session", idx,
|
2010-03-05 15:20:08 +00:00
|
|
|
&stream->session);
|
2009-02-13 18:54:18 +00:00
|
|
|
|
|
|
|
g_signal_connect (stream->session, "on-new-ssrc", (GCallback) on_new_ssrc,
|
2009-05-26 17:01:10 +00:00
|
|
|
stream);
|
2009-05-26 09:42:41 +00:00
|
|
|
g_signal_connect (stream->session, "on-ssrc-sdes", (GCallback) on_ssrc_sdes,
|
2009-05-26 17:01:10 +00:00
|
|
|
stream);
|
2010-03-05 15:20:08 +00:00
|
|
|
g_signal_connect (stream->session, "on-ssrc-active",
|
|
|
|
(GCallback) on_ssrc_active, stream);
|
2009-02-13 18:54:18 +00:00
|
|
|
g_signal_connect (stream->session, "on-bye-ssrc", (GCallback) on_bye_ssrc,
|
2009-05-26 17:01:10 +00:00
|
|
|
stream);
|
2010-03-05 15:20:08 +00:00
|
|
|
g_signal_connect (stream->session, "on-bye-timeout",
|
|
|
|
(GCallback) on_bye_timeout, stream);
|
2009-02-13 18:54:18 +00:00
|
|
|
g_signal_connect (stream->session, "on-timeout", (GCallback) on_timeout,
|
2009-05-26 17:01:10 +00:00
|
|
|
stream);
|
2009-02-13 18:54:18 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* link the RTP pad to the session manager */
|
2009-03-11 15:45:12 +00:00
|
|
|
ret = gst_pad_link (stream->srcpad, stream->send_rtp_sink);
|
|
|
|
if (ret != GST_PAD_LINK_OK)
|
|
|
|
goto link_failed;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* make tee for RTP and link to stream */
|
2009-05-24 17:34:52 +00:00
|
|
|
stream->tee[0] = gst_element_factory_make ("tee", NULL);
|
|
|
|
gst_bin_add (GST_BIN_CAST (media->pipeline), stream->tee[0]);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
pad = gst_element_get_static_pad (stream->tee[0], "sink");
|
2009-01-29 12:31:27 +00:00
|
|
|
gst_pad_link (stream->send_rtp_src, pad);
|
|
|
|
gst_object_unref (pad);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
/* link RTP sink, we're pretty sure this will work. */
|
2009-05-24 17:34:52 +00:00
|
|
|
teepad = gst_element_get_request_pad (stream->tee[0], "src%d");
|
2009-03-11 15:45:12 +00:00
|
|
|
pad = gst_element_get_static_pad (stream->udpsink[0], "sink");
|
|
|
|
gst_pad_link (teepad, pad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (teepad);
|
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
teepad = gst_element_get_request_pad (stream->tee[0], "src%d");
|
2009-03-11 15:45:12 +00:00
|
|
|
pad = gst_element_get_static_pad (stream->appsink[0], "sink");
|
|
|
|
gst_pad_link (teepad, pad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (teepad);
|
|
|
|
|
|
|
|
/* make tee for RTCP */
|
2009-05-24 17:34:52 +00:00
|
|
|
stream->tee[1] = gst_element_factory_make ("tee", NULL);
|
|
|
|
gst_bin_add (GST_BIN_CAST (media->pipeline), stream->tee[1]);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
pad = gst_element_get_static_pad (stream->tee[1], "sink");
|
2009-01-29 12:31:27 +00:00
|
|
|
gst_pad_link (stream->send_rtcp_src, pad);
|
|
|
|
gst_object_unref (pad);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
/* link RTCP elements */
|
2009-05-24 17:34:52 +00:00
|
|
|
teepad = gst_element_get_request_pad (stream->tee[1], "src%d");
|
2009-03-11 15:45:12 +00:00
|
|
|
pad = gst_element_get_static_pad (stream->udpsink[1], "sink");
|
|
|
|
gst_pad_link (teepad, pad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (teepad);
|
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
teepad = gst_element_get_request_pad (stream->tee[1], "src%d");
|
2009-03-11 15:45:12 +00:00
|
|
|
pad = gst_element_get_static_pad (stream->appsink[1], "sink");
|
|
|
|
gst_pad_link (teepad, pad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (teepad);
|
|
|
|
|
2009-05-15 15:58:44 +00:00
|
|
|
/* make selector for the RTP receivers */
|
2011-04-26 17:22:50 +00:00
|
|
|
stream->selector[0] = gst_element_factory_make ("funnel", NULL);
|
2009-05-15 15:58:44 +00:00
|
|
|
gst_bin_add (GST_BIN_CAST (media->pipeline), stream->selector[0]);
|
|
|
|
|
|
|
|
pad = gst_element_get_static_pad (stream->selector[0], "src");
|
|
|
|
gst_pad_link (pad, stream->recv_rtp_sink);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
|
|
|
selpad = gst_element_get_request_pad (stream->selector[0], "sink%d");
|
|
|
|
pad = gst_element_get_static_pad (stream->udpsrc[0], "src");
|
|
|
|
gst_pad_link (pad, selpad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (selpad);
|
|
|
|
|
|
|
|
selpad = gst_element_get_request_pad (stream->selector[0], "sink%d");
|
|
|
|
pad = gst_element_get_static_pad (stream->appsrc[0], "src");
|
|
|
|
gst_pad_link (pad, selpad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (selpad);
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* make selector for the RTCP receivers */
|
2011-04-26 17:22:50 +00:00
|
|
|
stream->selector[1] = gst_element_factory_make ("funnel", NULL);
|
2009-05-15 15:58:44 +00:00
|
|
|
gst_bin_add (GST_BIN_CAST (media->pipeline), stream->selector[1]);
|
2009-03-11 15:45:12 +00:00
|
|
|
|
2009-05-15 15:58:44 +00:00
|
|
|
pad = gst_element_get_static_pad (stream->selector[1], "src");
|
2009-01-29 12:31:27 +00:00
|
|
|
gst_pad_link (pad, stream->recv_rtcp_sink);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
2009-05-15 15:58:44 +00:00
|
|
|
selpad = gst_element_get_request_pad (stream->selector[1], "sink%d");
|
2009-03-11 15:45:12 +00:00
|
|
|
pad = gst_element_get_static_pad (stream->udpsrc[1], "src");
|
|
|
|
gst_pad_link (pad, selpad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (selpad);
|
|
|
|
|
2009-05-15 15:58:44 +00:00
|
|
|
selpad = gst_element_get_request_pad (stream->selector[1], "sink%d");
|
2009-03-11 15:45:12 +00:00
|
|
|
pad = gst_element_get_static_pad (stream->appsrc[1], "src");
|
|
|
|
gst_pad_link (pad, selpad);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (selpad);
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* we set and keep these to playing so that they don't cause NO_PREROLL return
|
|
|
|
* values */
|
|
|
|
gst_element_set_state (stream->udpsrc[0], GST_STATE_PLAYING);
|
|
|
|
gst_element_set_state (stream->udpsrc[1], GST_STATE_PLAYING);
|
|
|
|
gst_element_set_locked_state (stream->udpsrc[0], TRUE);
|
|
|
|
gst_element_set_locked_state (stream->udpsrc[1], TRUE);
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/* be notified of caps changes */
|
|
|
|
stream->caps_sig = g_signal_connect (stream->send_rtp_sink, "notify::caps",
|
2010-03-05 15:20:08 +00:00
|
|
|
(GCallback) caps_notify, stream);
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
stream->prepared = TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
2009-03-11 15:45:12 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
link_failed:
|
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_WARNING ("failed to link stream %d", idx);
|
2009-03-11 15:45:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2009-02-13 15:39:36 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
unlock_streams (GstRTSPMedia * media)
|
2009-02-13 15:39:36 +00:00
|
|
|
{
|
|
|
|
guint i, n_streams;
|
|
|
|
|
|
|
|
/* unlock the udp src elements */
|
|
|
|
n_streams = gst_rtsp_media_n_streams (media);
|
|
|
|
for (i = 0; i < n_streams; i++) {
|
|
|
|
GstRTSPMediaStream *stream;
|
|
|
|
|
|
|
|
stream = gst_rtsp_media_get_stream (media, i);
|
|
|
|
|
|
|
|
gst_element_set_locked_state (stream->udpsrc[0], FALSE);
|
|
|
|
gst_element_set_locked_state (stream->udpsrc[1], FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-05 16:51:26 +00:00
|
|
|
static void
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_media_set_status (GstRTSPMedia * media, GstRTSPMediaStatus status)
|
2010-03-05 16:51:26 +00:00
|
|
|
{
|
|
|
|
g_mutex_lock (media->lock);
|
|
|
|
/* never overwrite the error status */
|
|
|
|
if (media->status != GST_RTSP_MEDIA_STATUS_ERROR)
|
|
|
|
media->status = status;
|
|
|
|
GST_DEBUG ("setting new status to %d", status);
|
|
|
|
g_cond_broadcast (media->cond);
|
|
|
|
g_mutex_unlock (media->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPMediaStatus
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_rtsp_media_get_status (GstRTSPMedia * media)
|
2010-03-05 16:51:26 +00:00
|
|
|
{
|
|
|
|
GstRTSPMediaStatus result;
|
2010-03-05 17:23:18 +00:00
|
|
|
GTimeVal timeout;
|
2010-03-05 16:51:26 +00:00
|
|
|
|
|
|
|
g_mutex_lock (media->lock);
|
2010-03-05 17:23:18 +00:00
|
|
|
g_get_current_time (&timeout);
|
|
|
|
g_time_val_add (&timeout, 20 * G_USEC_PER_SEC);
|
2010-03-05 16:51:26 +00:00
|
|
|
/* while we are preparing, wait */
|
|
|
|
while (media->status == GST_RTSP_MEDIA_STATUS_PREPARING) {
|
|
|
|
GST_DEBUG ("waiting for status change");
|
2010-03-05 17:23:18 +00:00
|
|
|
if (!g_cond_timed_wait (media->cond, media->lock, &timeout)) {
|
|
|
|
GST_DEBUG ("timeout, assuming error status");
|
|
|
|
media->status = GST_RTSP_MEDIA_STATUS_ERROR;
|
|
|
|
}
|
2010-03-05 16:51:26 +00:00
|
|
|
}
|
|
|
|
/* could be success or error */
|
|
|
|
result = media->status;
|
|
|
|
GST_DEBUG ("got status %d", result);
|
|
|
|
g_mutex_unlock (media->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-02-13 15:39:36 +00:00
|
|
|
static gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
default_handle_message (GstRTSPMedia * media, GstMessage * message)
|
2009-02-13 15:39:36 +00:00
|
|
|
{
|
|
|
|
GstMessageType type;
|
|
|
|
|
|
|
|
type = GST_MESSAGE_TYPE (message);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case GST_MESSAGE_STATE_CHANGED:
|
|
|
|
break;
|
|
|
|
case GST_MESSAGE_BUFFERING:
|
|
|
|
{
|
|
|
|
gint percent;
|
|
|
|
|
|
|
|
gst_message_parse_buffering (message, &percent);
|
|
|
|
|
|
|
|
/* no state management needed for live pipelines */
|
|
|
|
if (media->is_live)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (percent == 100) {
|
|
|
|
/* a 100% message means buffering is done */
|
|
|
|
media->buffering = FALSE;
|
|
|
|
/* if the desired state is playing, go back */
|
|
|
|
if (media->target_state == GST_STATE_PLAYING) {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("Buffering done, setting pipeline to PLAYING");
|
2009-02-13 15:39:36 +00:00
|
|
|
gst_element_set_state (media->pipeline, GST_STATE_PLAYING);
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("Buffering done");
|
2010-03-05 12:28:58 +00:00
|
|
|
}
|
2009-02-13 15:39:36 +00:00
|
|
|
} else {
|
|
|
|
/* buffering busy */
|
|
|
|
if (media->buffering == FALSE) {
|
2010-03-05 12:28:58 +00:00
|
|
|
if (media->target_state == GST_STATE_PLAYING) {
|
2009-02-13 15:39:36 +00:00
|
|
|
/* we were not buffering but PLAYING, PAUSE the pipeline. */
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("Buffering, setting pipeline to PAUSED ...");
|
2009-02-13 15:39:36 +00:00
|
|
|
gst_element_set_state (media->pipeline, GST_STATE_PAUSED);
|
2010-03-05 15:20:08 +00:00
|
|
|
} else {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("Buffering ...");
|
2010-03-05 12:28:58 +00:00
|
|
|
}
|
2009-02-13 15:39:36 +00:00
|
|
|
}
|
|
|
|
media->buffering = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_MESSAGE_LATENCY:
|
|
|
|
{
|
|
|
|
gst_bin_recalculate_latency (GST_BIN_CAST (media->pipeline));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_MESSAGE_ERROR:
|
|
|
|
{
|
|
|
|
GError *gerror;
|
|
|
|
gchar *debug;
|
|
|
|
|
|
|
|
gst_message_parse_error (message, &gerror, &debug);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_WARNING ("%p: got error %s (%s)", media, gerror->message, debug);
|
2009-02-13 15:39:36 +00:00
|
|
|
g_error_free (gerror);
|
|
|
|
g_free (debug);
|
2010-03-05 16:51:26 +00:00
|
|
|
|
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_ERROR);
|
2009-02-13 15:39:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-03-11 15:45:12 +00:00
|
|
|
case GST_MESSAGE_WARNING:
|
|
|
|
{
|
|
|
|
GError *gerror;
|
|
|
|
gchar *debug;
|
|
|
|
|
|
|
|
gst_message_parse_warning (message, &gerror, &debug);
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_WARNING ("%p: got warning %s (%s)", media, gerror->message, debug);
|
2009-03-11 15:45:12 +00:00
|
|
|
g_error_free (gerror);
|
|
|
|
g_free (debug);
|
|
|
|
break;
|
|
|
|
}
|
2009-05-26 09:42:41 +00:00
|
|
|
case GST_MESSAGE_ELEMENT:
|
|
|
|
break;
|
2009-06-04 16:32:15 +00:00
|
|
|
case GST_MESSAGE_STREAM_STATUS:
|
|
|
|
break;
|
2010-03-05 16:51:26 +00:00
|
|
|
case GST_MESSAGE_ASYNC_DONE:
|
2010-12-11 16:31:44 +00:00
|
|
|
if (!media->adding) {
|
|
|
|
/* when we are dynamically adding pads, the addition of the udpsrc will
|
|
|
|
* temporarily produce ASYNC_DONE messages. We have to ignore them and
|
|
|
|
* wait for the final ASYNC_DONE after everything prerolled */
|
|
|
|
GST_INFO ("%p: got ASYNC_DONE", media);
|
|
|
|
collect_media_stats (media);
|
|
|
|
|
|
|
|
gst_rtsp_media_set_status (media, GST_RTSP_MEDIA_STATUS_PREPARED);
|
|
|
|
} else {
|
|
|
|
GST_INFO ("%p: ignoring ASYNC_DONE", media);
|
|
|
|
}
|
2010-03-05 16:51:26 +00:00
|
|
|
break;
|
2010-08-20 16:17:08 +00:00
|
|
|
case GST_MESSAGE_EOS:
|
|
|
|
GST_INFO ("%p: got EOS", media);
|
|
|
|
if (media->eos_pending) {
|
|
|
|
GST_DEBUG ("shutting down after EOS");
|
|
|
|
gst_element_set_state (media->pipeline, GST_STATE_NULL);
|
|
|
|
media->eos_pending = FALSE;
|
|
|
|
g_object_unref (media);
|
|
|
|
}
|
|
|
|
break;
|
2009-02-13 15:39:36 +00:00
|
|
|
default:
|
2010-03-05 15:20:08 +00:00
|
|
|
GST_INFO ("%p: got message type %s", media,
|
|
|
|
gst_message_type_get_name (type));
|
2009-02-13 15:39:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
bus_message (GstBus * bus, GstMessage * message, GstRTSPMedia * media)
|
2009-02-13 15:39:36 +00:00
|
|
|
{
|
|
|
|
GstRTSPMediaClass *klass;
|
|
|
|
gboolean ret;
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2009-02-13 15:39:36 +00:00
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
|
|
|
|
if (klass->handle_message)
|
|
|
|
ret = klass->handle_message (media, message);
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-24 14:47:30 +00:00
|
|
|
/* called from streaming threads */
|
2009-05-24 17:34:52 +00:00
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
pad_added_cb (GstElement * element, GstPad * pad, GstRTSPMedia * media)
|
2009-05-24 17:34:52 +00:00
|
|
|
{
|
|
|
|
GstRTSPMediaStream *stream;
|
|
|
|
gchar *name;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
i = media->streams->len + 1;
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("pad added %s:%s, stream %d", GST_DEBUG_PAD_NAME (pad), i);
|
2009-05-24 17:34:52 +00:00
|
|
|
|
|
|
|
stream = g_new0 (GstRTSPMediaStream, 1);
|
|
|
|
stream->payloader = element;
|
|
|
|
|
|
|
|
name = g_strdup_printf ("dynpay%d", i);
|
|
|
|
|
2010-12-11 16:31:44 +00:00
|
|
|
media->adding = TRUE;
|
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
/* ghost the pad of the payloader to the element */
|
|
|
|
stream->srcpad = gst_ghost_pad_new (name, pad);
|
|
|
|
gst_pad_set_active (stream->srcpad, TRUE);
|
|
|
|
gst_element_add_pad (media->element, stream->srcpad);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
/* add stream now */
|
|
|
|
g_array_append_val (media->streams, stream);
|
|
|
|
|
|
|
|
setup_stream (stream, i, media);
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
gst_element_set_state (stream->udpsink[i], GST_STATE_PAUSED);
|
|
|
|
gst_element_set_state (stream->appsink[i], GST_STATE_PAUSED);
|
|
|
|
gst_element_set_state (stream->tee[i], GST_STATE_PAUSED);
|
|
|
|
gst_element_set_state (stream->selector[i], GST_STATE_PAUSED);
|
|
|
|
gst_element_set_state (stream->appsrc[i], GST_STATE_PAUSED);
|
|
|
|
}
|
2010-12-11 16:31:44 +00:00
|
|
|
media->adding = FALSE;
|
2009-05-24 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-05 15:20:08 +00:00
|
|
|
no_more_pads_cb (GstElement * element, GstRTSPMedia * media)
|
2009-05-24 17:34:52 +00:00
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("no more pads");
|
2009-05-24 17:34:52 +00:00
|
|
|
if (media->fakesink) {
|
|
|
|
gst_object_ref (media->fakesink);
|
|
|
|
gst_bin_remove (GST_BIN (media->pipeline), media->fakesink);
|
|
|
|
gst_element_set_state (media->fakesink, GST_STATE_NULL);
|
|
|
|
gst_object_unref (media->fakesink);
|
|
|
|
media->fakesink = NULL;
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("removed fakesink");
|
2009-05-24 17:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_prepare:
|
2010-12-11 09:48:25 +00:00
|
|
|
* @media: a #GstRTSPMedia
|
2009-01-29 12:31:27 +00:00
|
|
|
*
|
|
|
|
* Prepare @media for streaming. This function will create the pipeline and
|
|
|
|
* other objects to manage the streaming.
|
|
|
|
*
|
2009-03-11 15:45:12 +00:00
|
|
|
* It will preroll the pipeline and collect vital information about the streams
|
|
|
|
* such as the duration.
|
|
|
|
*
|
2009-01-29 12:31:27 +00:00
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_prepare (GstRTSPMedia * media)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
|
|
|
GstStateChangeReturn ret;
|
2010-03-05 16:51:26 +00:00
|
|
|
GstRTSPMediaStatus status;
|
2009-01-29 12:31:27 +00:00
|
|
|
guint i, n_streams;
|
2009-02-13 15:39:36 +00:00
|
|
|
GstRTSPMediaClass *klass;
|
|
|
|
GstBus *bus;
|
2009-05-24 17:34:52 +00:00
|
|
|
GList *walk;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2010-03-05 16:51:26 +00:00
|
|
|
if (media->status == GST_RTSP_MEDIA_STATUS_PREPARED)
|
2009-01-29 12:31:27 +00:00
|
|
|
goto was_prepared;
|
|
|
|
|
2009-04-03 20:22:30 +00:00
|
|
|
if (!media->reusable && media->reused)
|
|
|
|
goto is_reused;
|
|
|
|
|
2010-12-06 18:29:53 +00:00
|
|
|
media->rtpbin = gst_element_factory_make ("gstrtpbin", NULL);
|
|
|
|
if (media->rtpbin == NULL)
|
|
|
|
goto no_gstrtpbin;
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("preparing media %p", media);
|
2009-01-29 16:20:27 +00:00
|
|
|
|
2010-03-05 12:28:58 +00:00
|
|
|
/* reset some variables */
|
|
|
|
media->is_live = FALSE;
|
|
|
|
media->buffering = FALSE;
|
2010-03-05 16:51:26 +00:00
|
|
|
/* we're preparing now */
|
|
|
|
media->status = GST_RTSP_MEDIA_STATUS_PREPARING;
|
2010-03-05 12:28:58 +00:00
|
|
|
|
2009-02-13 15:39:36 +00:00
|
|
|
bus = gst_pipeline_get_bus (GST_PIPELINE_CAST (media->pipeline));
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-03-04 15:33:59 +00:00
|
|
|
/* add the pipeline bus to our custom mainloop */
|
|
|
|
media->source = gst_bus_create_watch (bus);
|
|
|
|
gst_object_unref (bus);
|
|
|
|
|
|
|
|
g_source_set_callback (media->source, (GSourceFunc) bus_message, media, NULL);
|
|
|
|
|
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
media->id = g_source_attach (media->source, klass->context);
|
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
/* add stuff to the bin */
|
2009-01-29 12:31:27 +00:00
|
|
|
gst_bin_add (GST_BIN (media->pipeline), media->rtpbin);
|
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
/* link streams we already have, other streams might appear when we have
|
|
|
|
* dynamic elements */
|
2009-01-29 12:31:27 +00:00
|
|
|
n_streams = gst_rtsp_media_n_streams (media);
|
|
|
|
for (i = 0; i < n_streams; i++) {
|
|
|
|
GstRTSPMediaStream *stream;
|
|
|
|
|
|
|
|
stream = gst_rtsp_media_get_stream (media, i);
|
|
|
|
|
2009-01-30 13:53:28 +00:00
|
|
|
setup_stream (stream, i, media);
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
for (walk = media->dynamic; walk; walk = g_list_next (walk)) {
|
|
|
|
GstElement *elem = walk->data;
|
|
|
|
|
2010-12-11 16:31:44 +00:00
|
|
|
GST_INFO ("adding callbacks for dynamic element %p", elem);
|
|
|
|
|
2009-05-24 17:34:52 +00:00
|
|
|
g_signal_connect (elem, "pad-added", (GCallback) pad_added_cb, media);
|
|
|
|
g_signal_connect (elem, "no-more-pads", (GCallback) no_more_pads_cb, media);
|
|
|
|
|
2010-03-05 12:28:58 +00:00
|
|
|
/* we add a fakesink here in order to make the state change async. We remove
|
|
|
|
* the fakesink again in the no-more-pads callback. */
|
2009-05-24 17:34:52 +00:00
|
|
|
media->fakesink = gst_element_factory_make ("fakesink", "fakesink");
|
|
|
|
gst_bin_add (GST_BIN (media->pipeline), media->fakesink);
|
|
|
|
}
|
|
|
|
|
2010-03-05 12:28:58 +00:00
|
|
|
GST_INFO ("setting pipeline to PAUSED for media %p", media);
|
2009-01-29 12:31:27 +00:00
|
|
|
/* first go to PAUSED */
|
|
|
|
ret = gst_element_set_state (media->pipeline, GST_STATE_PAUSED);
|
2009-02-13 15:39:36 +00:00
|
|
|
media->target_state = GST_STATE_PAUSED;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case GST_STATE_CHANGE_SUCCESS:
|
2010-03-05 12:28:58 +00:00
|
|
|
GST_INFO ("SUCCESS state change for media %p", media);
|
2009-01-29 12:31:27 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_ASYNC:
|
2010-03-05 12:28:58 +00:00
|
|
|
GST_INFO ("ASYNC state change for media %p", media);
|
2009-01-29 12:31:27 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_NO_PREROLL:
|
|
|
|
/* we need to go to PLAYING */
|
2010-03-05 12:28:58 +00:00
|
|
|
GST_INFO ("NO_PREROLL state change: live media %p", media);
|
2009-02-13 15:39:36 +00:00
|
|
|
media->is_live = TRUE;
|
2009-01-29 12:31:27 +00:00
|
|
|
ret = gst_element_set_state (media->pipeline, GST_STATE_PLAYING);
|
2009-03-11 15:45:12 +00:00
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
goto state_failed;
|
2009-01-29 12:31:27 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_FAILURE:
|
|
|
|
goto state_failed;
|
|
|
|
}
|
|
|
|
|
2009-01-29 16:20:27 +00:00
|
|
|
/* now wait for all pads to be prerolled */
|
2010-03-05 16:51:26 +00:00
|
|
|
status = gst_rtsp_media_get_status (media);
|
|
|
|
if (status == GST_RTSP_MEDIA_STATUS_ERROR)
|
2009-03-11 15:45:12 +00:00
|
|
|
goto state_failed;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2010-12-13 15:58:36 +00:00
|
|
|
g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_PREPARED], 0, NULL);
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("object %p is prerolled", media);
|
2009-01-30 10:06:31 +00:00
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* OK */
|
|
|
|
was_prepared:
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/* ERRORS */
|
2010-03-09 09:27:38 +00:00
|
|
|
is_reused:
|
|
|
|
{
|
|
|
|
GST_WARNING ("can not reuse media %p", media);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-12-06 18:29:53 +00:00
|
|
|
no_gstrtpbin:
|
|
|
|
{
|
|
|
|
GST_WARNING ("no gstrtpbin element");
|
|
|
|
g_warning ("failed to create element 'gstrtpbin', check your installation");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
state_failed:
|
|
|
|
{
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_WARNING ("failed to preroll pipeline");
|
2009-03-11 15:45:12 +00:00
|
|
|
unlock_streams (media);
|
2009-02-13 15:39:36 +00:00
|
|
|
gst_element_set_state (media->pipeline, GST_STATE_NULL);
|
2010-03-09 09:27:38 +00:00
|
|
|
gst_rtsp_media_unprepare (media);
|
2009-04-03 20:22:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_media_unprepare:
|
2010-12-11 09:48:25 +00:00
|
|
|
* @media: a #GstRTSPMedia
|
2009-04-03 20:22:30 +00:00
|
|
|
*
|
|
|
|
* Unprepare @media. After this call, the media should be prepared again before
|
|
|
|
* it can be used again. If the media is set to be non-reusable, a new instance
|
|
|
|
* must be created.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_unprepare (GstRTSPMedia * media)
|
2009-04-03 20:22:30 +00:00
|
|
|
{
|
2009-06-12 16:05:30 +00:00
|
|
|
GstRTSPMediaClass *klass;
|
|
|
|
gboolean success;
|
|
|
|
|
2010-03-05 16:51:26 +00:00
|
|
|
if (media->status == GST_RTSP_MEDIA_STATUS_UNPREPARED)
|
2009-04-03 20:22:30 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("unprepare media %p", media);
|
2009-04-21 20:23:54 +00:00
|
|
|
media->target_state = GST_STATE_NULL;
|
2009-06-12 16:05:30 +00:00
|
|
|
|
|
|
|
klass = GST_RTSP_MEDIA_GET_CLASS (media);
|
|
|
|
if (klass->unprepare)
|
|
|
|
success = klass->unprepare (media);
|
|
|
|
else
|
|
|
|
success = TRUE;
|
2009-04-21 20:44:05 +00:00
|
|
|
|
2010-03-05 16:51:26 +00:00
|
|
|
media->status = GST_RTSP_MEDIA_STATUS_UNPREPARED;
|
2009-04-21 20:44:05 +00:00
|
|
|
media->reused = TRUE;
|
|
|
|
|
|
|
|
/* when the media is not reusable, this will effectively unref the media and
|
|
|
|
* recreate it */
|
|
|
|
g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_UNPREPARED], 0, NULL);
|
2009-04-21 20:23:54 +00:00
|
|
|
|
2009-06-12 16:05:30 +00:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
default_unprepare (GstRTSPMedia * media)
|
2009-06-18 14:05:18 +00:00
|
|
|
{
|
2010-08-20 16:17:08 +00:00
|
|
|
if (media->eos_shutdown) {
|
|
|
|
GST_DEBUG ("sending EOS for shutdown");
|
|
|
|
/* ref so that we don't disappear */
|
|
|
|
g_object_ref (media);
|
|
|
|
media->eos_pending = TRUE;
|
2010-12-11 09:48:42 +00:00
|
|
|
gst_element_send_event (media->pipeline, gst_event_new_eos ());
|
2010-08-20 16:17:08 +00:00
|
|
|
/* we need to go to playing again for the EOS to propagate, normally in this
|
|
|
|
* state, nothing is receiving data from us anymore so this is ok. */
|
|
|
|
gst_element_set_state (media->pipeline, GST_STATE_PLAYING);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("shutting down");
|
|
|
|
gst_element_set_state (media->pipeline, GST_STATE_NULL);
|
|
|
|
}
|
2009-04-03 20:22:30 +00:00
|
|
|
return TRUE;
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 11:09:12 +00:00
|
|
|
static void
|
2010-12-11 09:48:42 +00:00
|
|
|
add_udp_destination (GstRTSPMedia * media, GstRTSPMediaStream * stream,
|
|
|
|
gchar * dest, gint min, gint max)
|
2010-08-20 11:09:12 +00:00
|
|
|
{
|
2011-02-02 14:30:45 +00:00
|
|
|
GST_INFO ("adding %s:%d-%d", dest, min, max);
|
|
|
|
g_signal_emit_by_name (stream->udpsink[0], "add", dest, min, NULL);
|
|
|
|
g_signal_emit_by_name (stream->udpsink[1], "add", dest, max, NULL);
|
2010-08-20 11:09:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-11 09:48:42 +00:00
|
|
|
remove_udp_destination (GstRTSPMedia * media, GstRTSPMediaStream * stream,
|
|
|
|
gchar * dest, gint min, gint max)
|
2010-08-20 11:09:12 +00:00
|
|
|
{
|
2011-02-02 14:30:45 +00:00
|
|
|
GST_INFO ("removing %s:%d-%d", dest, min, max);
|
|
|
|
g_signal_emit_by_name (stream->udpsink[0], "remove", dest, min, NULL);
|
|
|
|
g_signal_emit_by_name (stream->udpsink[1], "remove", dest, max, NULL);
|
2010-08-20 11:09:12 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 12:31:27 +00:00
|
|
|
/**
|
2009-03-11 15:45:12 +00:00
|
|
|
* gst_rtsp_media_set_state:
|
2009-01-29 12:31:27 +00:00
|
|
|
* @media: a #GstRTSPMedia
|
2009-03-11 15:45:12 +00:00
|
|
|
* @state: the target state of the media
|
2010-12-11 09:48:25 +00:00
|
|
|
* @transports: a #GArray of #GstRTSPMediaTrans pointers
|
2009-01-29 12:31:27 +00:00
|
|
|
*
|
2009-03-11 15:45:12 +00:00
|
|
|
* Set the state of @media to @state and for the transports in @transports.
|
2009-01-29 12:31:27 +00:00
|
|
|
*
|
2009-02-03 18:32:38 +00:00
|
|
|
* Returns: %TRUE on success.
|
2009-01-29 12:31:27 +00:00
|
|
|
*/
|
2009-02-03 18:32:38 +00:00
|
|
|
gboolean
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_set_state (GstRTSPMedia * media, GstState state,
|
|
|
|
GArray * transports)
|
2009-01-29 12:31:27 +00:00
|
|
|
{
|
2009-02-03 18:32:38 +00:00
|
|
|
gint i;
|
2009-04-03 17:44:37 +00:00
|
|
|
gboolean add, remove, do_state;
|
2009-04-03 20:22:30 +00:00
|
|
|
gint old_active;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), FALSE);
|
|
|
|
g_return_val_if_fail (transports != NULL, FALSE);
|
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
/* NULL and READY are the same */
|
|
|
|
if (state == GST_STATE_READY)
|
|
|
|
state = GST_STATE_NULL;
|
2009-02-13 18:54:18 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
add = remove = FALSE;
|
2009-02-03 18:32:38 +00:00
|
|
|
|
2010-03-05 15:20:08 +00:00
|
|
|
GST_INFO ("going to state %s media %p", gst_element_state_get_name (state),
|
|
|
|
media);
|
2009-05-26 09:42:41 +00:00
|
|
|
|
2009-03-11 15:45:12 +00:00
|
|
|
switch (state) {
|
|
|
|
case GST_STATE_NULL:
|
2009-03-13 14:57:42 +00:00
|
|
|
/* unlock the streams so that they follow the state changes from now on */
|
|
|
|
unlock_streams (media);
|
2009-05-26 09:42:41 +00:00
|
|
|
/* fallthrough */
|
2009-03-11 15:45:12 +00:00
|
|
|
case GST_STATE_PAUSED:
|
2009-04-03 20:22:30 +00:00
|
|
|
/* we're going from PLAYING to PAUSED, READY or NULL, remove */
|
2009-03-11 15:45:12 +00:00
|
|
|
if (media->target_state == GST_STATE_PLAYING)
|
2010-03-05 12:28:58 +00:00
|
|
|
remove = TRUE;
|
2009-03-11 15:45:12 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING:
|
|
|
|
/* we're going to PLAYING, add */
|
|
|
|
add = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-02-03 18:32:38 +00:00
|
|
|
}
|
2009-04-03 20:22:30 +00:00
|
|
|
old_active = media->active;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
for (i = 0; i < transports->len; i++) {
|
|
|
|
GstRTSPMediaTrans *tr;
|
|
|
|
GstRTSPMediaStream *stream;
|
|
|
|
GstRTSPTransport *trans;
|
|
|
|
|
|
|
|
/* we need a non-NULL entry in the array */
|
|
|
|
tr = g_array_index (transports, GstRTSPMediaTrans *, i);
|
|
|
|
if (tr == NULL)
|
|
|
|
continue;
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
/* we need a transport */
|
|
|
|
if (!(trans = tr->transport))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* get the stream and add the destinations */
|
|
|
|
stream = gst_rtsp_media_get_stream (media, tr->idx);
|
2009-03-06 18:34:14 +00:00
|
|
|
switch (trans->lower_transport) {
|
|
|
|
case GST_RTSP_LOWER_TRANS_UDP:
|
|
|
|
case GST_RTSP_LOWER_TRANS_UDP_MCAST:
|
2009-04-03 20:22:30 +00:00
|
|
|
{
|
2010-03-05 12:28:58 +00:00
|
|
|
gchar *dest;
|
|
|
|
gint min, max;
|
|
|
|
|
|
|
|
dest = trans->destination;
|
|
|
|
if (trans->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
|
|
|
|
min = trans->port.min;
|
|
|
|
max = trans->port.max;
|
|
|
|
} else {
|
|
|
|
min = trans->client_port.min;
|
|
|
|
max = trans->client_port.max;
|
|
|
|
}
|
2009-04-03 20:22:30 +00:00
|
|
|
|
2010-03-05 12:28:58 +00:00
|
|
|
if (add && !tr->active) {
|
2010-08-20 11:09:12 +00:00
|
|
|
add_udp_destination (media, stream, dest, min, max);
|
2010-03-05 12:28:58 +00:00
|
|
|
stream->transports = g_list_prepend (stream->transports, tr);
|
|
|
|
tr->active = TRUE;
|
|
|
|
media->active++;
|
|
|
|
} else if (remove && tr->active) {
|
2010-08-20 11:09:12 +00:00
|
|
|
remove_udp_destination (media, stream, dest, min, max);
|
2010-03-05 12:28:58 +00:00
|
|
|
stream->transports = g_list_remove (stream->transports, tr);
|
|
|
|
tr->active = FALSE;
|
|
|
|
media->active--;
|
|
|
|
}
|
2009-03-06 18:34:14 +00:00
|
|
|
break;
|
2009-04-03 20:22:30 +00:00
|
|
|
}
|
2009-03-06 18:34:14 +00:00
|
|
|
case GST_RTSP_LOWER_TRANS_TCP:
|
2010-03-05 12:28:58 +00:00
|
|
|
if (add && !tr->active) {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("adding TCP %s", trans->destination);
|
2010-03-05 12:28:58 +00:00
|
|
|
stream->transports = g_list_prepend (stream->transports, tr);
|
|
|
|
tr->active = TRUE;
|
|
|
|
media->active++;
|
|
|
|
} else if (remove && tr->active) {
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("removing TCP %s", trans->destination);
|
2010-03-05 12:28:58 +00:00
|
|
|
stream->transports = g_list_remove (stream->transports, tr);
|
|
|
|
tr->active = FALSE;
|
|
|
|
media->active--;
|
|
|
|
}
|
2009-03-06 18:34:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("Unknown transport %d", trans->lower_transport);
|
2009-03-06 18:34:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-03 18:32:38 +00:00
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-04-03 17:44:37 +00:00
|
|
|
/* we just added the first media, do the playing state change */
|
2009-04-03 20:22:30 +00:00
|
|
|
if (old_active == 0 && add)
|
2009-04-03 17:44:37 +00:00
|
|
|
do_state = TRUE;
|
|
|
|
/* if we have no more active media, do the downward state changes */
|
|
|
|
else if (media->active == 0)
|
|
|
|
do_state = TRUE;
|
|
|
|
else
|
|
|
|
do_state = FALSE;
|
|
|
|
|
2010-12-28 17:34:10 +00:00
|
|
|
GST_INFO ("state %d active %d media %p do_state %d", state, media->active,
|
|
|
|
media, do_state);
|
2009-04-03 17:44:37 +00:00
|
|
|
|
2010-12-28 17:34:10 +00:00
|
|
|
if (media->target_state != state) {
|
|
|
|
if (do_state) {
|
|
|
|
if (state == GST_STATE_NULL) {
|
|
|
|
gst_rtsp_media_unprepare (media);
|
|
|
|
} else {
|
|
|
|
GST_INFO ("state %s media %p", gst_element_state_get_name (state),
|
|
|
|
media);
|
|
|
|
media->target_state = state;
|
2011-07-20 15:16:42 +00:00
|
|
|
gst_element_set_state (media->pipeline, state);
|
2010-12-28 17:34:10 +00:00
|
|
|
}
|
2009-04-03 20:22:30 +00:00
|
|
|
}
|
2010-12-28 17:34:10 +00:00
|
|
|
g_signal_emit (media, gst_rtsp_media_signals[SIGNAL_NEW_STATE], 0, state,
|
|
|
|
NULL);
|
2009-04-03 17:44:37 +00:00
|
|
|
}
|
2009-01-29 12:31:27 +00:00
|
|
|
|
2009-03-13 14:57:42 +00:00
|
|
|
/* remember where we are */
|
2010-12-12 14:48:47 +00:00
|
|
|
if (state == GST_STATE_PAUSED || old_active != media->active)
|
2009-03-13 14:57:42 +00:00
|
|
|
collect_media_stats (media);
|
|
|
|
|
2009-02-03 18:32:38 +00:00
|
|
|
return TRUE;
|
2009-01-29 12:31:27 +00:00
|
|
|
}
|
|
|
|
|
2009-09-11 11:52:27 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_media_remove_elements:
|
|
|
|
* @media: a #GstRTSPMedia
|
|
|
|
*
|
|
|
|
* Remove all elements and the pipeline controlled by @media.
|
|
|
|
*/
|
2009-06-13 12:38:20 +00:00
|
|
|
void
|
2010-03-05 15:20:08 +00:00
|
|
|
gst_rtsp_media_remove_elements (GstRTSPMedia * media)
|
2009-06-13 12:38:20 +00:00
|
|
|
{
|
2009-06-13 14:05:02 +00:00
|
|
|
gint i, j;
|
2009-06-13 12:38:20 +00:00
|
|
|
|
|
|
|
unlock_streams (media);
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2009-06-13 12:38:20 +00:00
|
|
|
for (i = 0; i < media->streams->len; i++) {
|
|
|
|
GstRTSPMediaStream *stream;
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2009-11-21 18:20:23 +00:00
|
|
|
GST_INFO ("Removing elements of stream %d from pipeline", i);
|
2009-06-13 12:38:20 +00:00
|
|
|
|
|
|
|
stream = g_array_index (media->streams, GstRTSPMediaStream *, i);
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2009-06-13 12:38:20 +00:00
|
|
|
gst_pad_unlink (stream->srcpad, stream->send_rtp_sink);
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2009-10-09 21:08:18 +00:00
|
|
|
g_signal_handler_disconnect (stream->send_rtp_sink, stream->caps_sig);
|
|
|
|
|
2009-06-13 14:05:02 +00:00
|
|
|
for (j = 0; j < 2; j++) {
|
|
|
|
gst_element_set_state (stream->udpsrc[j], GST_STATE_NULL);
|
|
|
|
gst_element_set_state (stream->udpsink[j], GST_STATE_NULL);
|
|
|
|
gst_element_set_state (stream->appsrc[j], GST_STATE_NULL);
|
|
|
|
gst_element_set_state (stream->appsink[j], GST_STATE_NULL);
|
|
|
|
gst_element_set_state (stream->tee[j], GST_STATE_NULL);
|
|
|
|
gst_element_set_state (stream->selector[j], GST_STATE_NULL);
|
2010-03-05 15:20:08 +00:00
|
|
|
|
2009-06-13 14:05:02 +00:00
|
|
|
gst_bin_remove (GST_BIN (media->pipeline), stream->udpsrc[j]);
|
|
|
|
gst_bin_remove (GST_BIN (media->pipeline), stream->udpsink[j]);
|
|
|
|
gst_bin_remove (GST_BIN (media->pipeline), stream->appsrc[j]);
|
|
|
|
gst_bin_remove (GST_BIN (media->pipeline), stream->appsink[j]);
|
|
|
|
gst_bin_remove (GST_BIN (media->pipeline), stream->tee[j]);
|
|
|
|
gst_bin_remove (GST_BIN (media->pipeline), stream->selector[j]);
|
|
|
|
}
|
2009-10-09 21:08:18 +00:00
|
|
|
if (stream->caps)
|
|
|
|
gst_caps_unref (stream->caps);
|
2009-06-14 21:12:13 +00:00
|
|
|
stream->caps = NULL;
|
2009-06-13 12:38:20 +00:00
|
|
|
gst_rtsp_media_stream_free (stream);
|
|
|
|
}
|
|
|
|
g_array_remove_range (media->streams, 0, media->streams->len);
|
2009-10-09 21:08:18 +00:00
|
|
|
|
2009-06-13 12:38:20 +00:00
|
|
|
gst_element_set_state (media->rtpbin, GST_STATE_NULL);
|
|
|
|
gst_bin_remove (GST_BIN (media->pipeline), media->rtpbin);
|
2009-06-14 21:12:13 +00:00
|
|
|
|
|
|
|
gst_object_unref (media->pipeline);
|
|
|
|
media->pipeline = NULL;
|
2009-06-13 12:38:20 +00:00
|
|
|
}
|