2012-10-25 19:29:58 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
|
2015-01-09 11:40:47 +00:00
|
|
|
* Copyright (C) 2015 Centricular Ltd
|
|
|
|
* Author: Sebastian Dröge <sebastian@centricular.com>
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2012-10-25 19:29:58 +00:00
|
|
|
*/
|
2013-07-11 14:57:14 +00:00
|
|
|
/**
|
|
|
|
* SECTION:rtsp-session-media
|
|
|
|
* @short_description: Media managed in a session
|
|
|
|
* @see_also: #GstRTSPMedia, #GstRTSPSession
|
|
|
|
*
|
2013-07-16 10:32:51 +00:00
|
|
|
* The #GstRTSPSessionMedia object manages a #GstRTSPMedia with a given path.
|
|
|
|
*
|
|
|
|
* With gst_rtsp_session_media_get_transport() and
|
|
|
|
* gst_rtsp_session_media_set_transport() the transports of a #GstRTSPStream of
|
|
|
|
* the managed #GstRTSPMedia can be retrieved and configured.
|
|
|
|
*
|
|
|
|
* Use gst_rtsp_session_media_set_state() to control the media state and
|
|
|
|
* transports.
|
|
|
|
*
|
|
|
|
* Last reviewed on 2013-07-16 (1.0.0)
|
2013-07-11 14:57:14 +00:00
|
|
|
*/
|
2018-09-24 08:36:21 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2013-07-11 14:57:14 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "rtsp-session.h"
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
struct _GstRTSPSessionMediaPrivate
|
|
|
|
{
|
|
|
|
GMutex lock;
|
2013-07-03 10:37:48 +00:00
|
|
|
gchar *path; /* unmutable */
|
|
|
|
gint path_len; /* unmutable */
|
2013-02-18 19:59:58 +00:00
|
|
|
GstRTSPMedia *media; /* unmutable */
|
|
|
|
GstRTSPState state; /* protected by lock */
|
|
|
|
guint counter; /* protected by lock */
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2013-02-18 19:59:58 +00:00
|
|
|
GPtrArray *transports; /* protected by lock */
|
2012-11-29 10:11:05 +00:00
|
|
|
};
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_session_media_debug);
|
|
|
|
#define GST_CAT_DEFAULT rtsp_session_media_debug
|
|
|
|
|
|
|
|
static void gst_rtsp_session_media_finalize (GObject * obj);
|
|
|
|
|
2018-06-24 10:44:26 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GstRTSPSessionMedia, gst_rtsp_session_media,
|
|
|
|
G_TYPE_OBJECT);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_session_media_class_init (GstRTSPSessionMediaClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_rtsp_session_media_finalize;
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (rtsp_session_media_debug, "rtspsessionmedia", 0,
|
|
|
|
"GstRTSPSessionMedia");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_session_media_init (GstRTSPSessionMedia * media)
|
|
|
|
{
|
2018-06-24 10:44:26 +00:00
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2018-06-24 10:44:26 +00:00
|
|
|
media->priv = priv = gst_rtsp_session_media_get_instance_private (media);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
g_mutex_init (&priv->lock);
|
|
|
|
priv->state = GST_RTSP_STATE_INIT;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_session_media_finalize (GObject * obj)
|
|
|
|
{
|
|
|
|
GstRTSPSessionMedia *media;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
media = GST_RTSP_SESSION_MEDIA (obj);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
GST_INFO ("free session media %p", media);
|
|
|
|
|
|
|
|
gst_rtsp_session_media_set_state (media, GST_STATE_NULL);
|
|
|
|
|
2014-10-23 10:54:03 +00:00
|
|
|
gst_rtsp_media_unprepare (priv->media);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_ptr_array_unref (priv->transports);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-07-03 10:37:48 +00:00
|
|
|
g_free (priv->path);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_object_unref (priv->media);
|
|
|
|
g_mutex_clear (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_rtsp_session_media_parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_session_media (gpointer data)
|
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
g_object_unref (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_session_media_new:
|
2013-07-03 10:37:48 +00:00
|
|
|
* @path: the path
|
2014-03-23 20:24:48 +00:00
|
|
|
* @media: (transfer full): the #GstRTSPMedia
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2013-11-22 02:10:01 +00:00
|
|
|
* Create a new #GstRTSPSessionMedia that manages the streams
|
2013-07-03 10:37:48 +00:00
|
|
|
* in @media for @path. @media should be prepared.
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
|
|
|
* Ownership is taken of @media.
|
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: (transfer full): a new #GstRTSPSessionMedia.
|
2012-10-25 19:29:58 +00:00
|
|
|
*/
|
|
|
|
GstRTSPSessionMedia *
|
2013-07-03 10:37:48 +00:00
|
|
|
gst_rtsp_session_media_new (const gchar * path, GstRTSPMedia * media)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPSessionMedia *result;
|
|
|
|
guint n_streams;
|
2013-11-28 13:10:19 +00:00
|
|
|
GstRTSPMediaStatus status;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-07-03 10:37:48 +00:00
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
|
2015-01-09 11:40:47 +00:00
|
|
|
|
2013-11-28 13:10:19 +00:00
|
|
|
status = gst_rtsp_media_get_status (media);
|
|
|
|
g_return_val_if_fail (status == GST_RTSP_MEDIA_STATUS_PREPARED || status ==
|
|
|
|
GST_RTSP_MEDIA_STATUS_SUSPENDED, NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
result = g_object_new (GST_TYPE_RTSP_SESSION_MEDIA, NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = result->priv;
|
|
|
|
|
2013-07-03 10:37:48 +00:00
|
|
|
priv->path = g_strdup (path);
|
|
|
|
priv->path_len = strlen (path);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->media = media;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
/* prealloc the streams now, filled with NULL */
|
|
|
|
n_streams = gst_rtsp_media_n_streams (media);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->transports = g_ptr_array_new_full (n_streams, free_session_media);
|
|
|
|
g_ptr_array_set_size (priv->transports, n_streams);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/**
|
2013-07-03 10:37:48 +00:00
|
|
|
* gst_rtsp_session_media_matches:
|
2012-11-29 10:11:05 +00:00
|
|
|
* @media: a #GstRTSPSessionMedia
|
2013-07-03 10:37:48 +00:00
|
|
|
* @path: a path
|
2013-10-12 21:56:00 +00:00
|
|
|
* @matched: (out): the amount of matched characters of @path
|
2012-11-29 10:11:05 +00:00
|
|
|
*
|
2013-07-03 10:37:48 +00:00
|
|
|
* Check if the path of @media matches @path. It @path matches, the amount of
|
|
|
|
* matched characters is returned in @matched.
|
2012-11-29 10:11:05 +00:00
|
|
|
*
|
2013-07-03 10:37:48 +00:00
|
|
|
* Returns: %TRUE when @path matches the path of @media.
|
2012-11-29 10:11:05 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2013-07-03 10:37:48 +00:00
|
|
|
gst_rtsp_session_media_matches (GstRTSPSessionMedia * media,
|
|
|
|
const gchar * path, gint * matched)
|
2012-11-29 10:11:05 +00:00
|
|
|
{
|
2013-07-03 10:37:48 +00:00
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
|
|
|
gint len;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), FALSE);
|
2013-07-03 10:37:48 +00:00
|
|
|
g_return_val_if_fail (path != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (matched != NULL, FALSE);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
len = strlen (path);
|
|
|
|
|
|
|
|
/* path needs to be smaller than the media path */
|
|
|
|
if (len < priv->path_len)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-11-05 21:02:49 +00:00
|
|
|
/* special case when "/" is the entire path */
|
|
|
|
if (priv->path_len == 1 && priv->path[0] == '/' && path[0] == '/') {
|
|
|
|
*matched = 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-07-03 10:37:48 +00:00
|
|
|
/* if media path is larger, it there should be a / following the path */
|
|
|
|
if (len > priv->path_len && path[priv->path_len] != '/')
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*matched = priv->path_len;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2013-07-03 10:37:48 +00:00
|
|
|
return strncmp (path, priv->path, priv->path_len) == 0;
|
2012-11-29 10:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_session_media_get_media:
|
|
|
|
* @media: a #GstRTSPSessionMedia
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPMedia that was used when constructing @media
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer none) (nullable): the #GstRTSPMedia of @media.
|
|
|
|
* Remains valid as long as @media is valid.
|
2012-11-29 10:11:05 +00:00
|
|
|
*/
|
|
|
|
GstRTSPMedia *
|
|
|
|
gst_rtsp_session_media_get_media (GstRTSPSessionMedia * media)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), NULL);
|
|
|
|
|
|
|
|
return media->priv->media;
|
|
|
|
}
|
|
|
|
|
2013-04-12 10:34:38 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_media_get_base_time:
|
|
|
|
* @media: a #GstRTSPSessionMedia
|
|
|
|
*
|
|
|
|
* Get the base_time of the #GstRTSPMedia in @media
|
|
|
|
*
|
|
|
|
* Returns: the base_time of the media.
|
|
|
|
*/
|
|
|
|
GstClockTime
|
|
|
|
gst_rtsp_session_media_get_base_time (GstRTSPSessionMedia * media)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), GST_CLOCK_TIME_NONE);
|
|
|
|
|
|
|
|
return gst_rtsp_media_get_base_time (media->priv->media);
|
|
|
|
}
|
|
|
|
|
2013-12-26 14:41:14 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_media_get_rtpinfo:
|
|
|
|
* @media: a #GstRTSPSessionMedia
|
|
|
|
*
|
|
|
|
* Retrieve the RTP-Info header string for all streams in @media
|
|
|
|
* with configured transports.
|
|
|
|
*
|
2014-06-11 23:38:36 +00:00
|
|
|
* Returns: (transfer full) (nullable): The RTP-Info as a string or
|
|
|
|
* %NULL when no RTP-Info could be generated, g_free() after usage.
|
2013-12-26 14:41:14 +00:00
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gst_rtsp_session_media_get_rtpinfo (GstRTSPSessionMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
|
|
|
GString *rtpinfo = NULL;
|
|
|
|
GstRTSPStreamTransport *transport;
|
2013-12-26 15:28:59 +00:00
|
|
|
GstRTSPStream *stream;
|
2013-12-26 14:41:14 +00:00
|
|
|
guint i, n_streams;
|
2013-12-26 15:28:59 +00:00
|
|
|
GstClockTime earliest = GST_CLOCK_TIME_NONE;
|
2013-12-26 14:41:14 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), NULL);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
|
2013-12-26 15:28:59 +00:00
|
|
|
if (gst_rtsp_media_get_status (priv->media) != GST_RTSP_MEDIA_STATUS_PREPARED)
|
|
|
|
goto not_prepared;
|
|
|
|
|
2013-12-26 14:41:14 +00:00
|
|
|
n_streams = priv->transports->len;
|
|
|
|
|
2013-12-26 15:28:59 +00:00
|
|
|
/* first step, take lowest running-time from all streams */
|
|
|
|
GST_LOG_OBJECT (media, "determining start time among %d transports",
|
|
|
|
n_streams);
|
|
|
|
|
|
|
|
for (i = 0; i < n_streams; i++) {
|
|
|
|
GstClockTime running_time;
|
|
|
|
|
|
|
|
transport = g_ptr_array_index (priv->transports, i);
|
|
|
|
if (transport == NULL) {
|
|
|
|
GST_DEBUG_OBJECT (media, "ignoring unconfigured transport %d", i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = gst_rtsp_stream_transport_get_stream (transport);
|
2018-06-05 06:44:44 +00:00
|
|
|
if (!gst_rtsp_stream_is_sender (stream))
|
|
|
|
continue;
|
2013-12-26 16:02:50 +00:00
|
|
|
if (!gst_rtsp_stream_get_rtpinfo (stream, NULL, NULL, NULL, &running_time))
|
2013-12-26 15:28:59 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (media, "running time of %d stream: %" GST_TIME_FORMAT, i,
|
|
|
|
GST_TIME_ARGS (running_time));
|
|
|
|
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (earliest)) {
|
|
|
|
earliest = running_time;
|
|
|
|
} else {
|
|
|
|
earliest = MIN (earliest, running_time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (media, "media start time: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (earliest));
|
|
|
|
|
|
|
|
/* next step, scale all rtptime of all streams to lowest running-time */
|
2013-12-26 14:41:14 +00:00
|
|
|
GST_LOG_OBJECT (media, "collecting RTP info for %d transports", n_streams);
|
|
|
|
|
|
|
|
for (i = 0; i < n_streams; i++) {
|
|
|
|
gchar *stream_rtpinfo;
|
|
|
|
|
|
|
|
transport = g_ptr_array_index (priv->transports, i);
|
|
|
|
if (transport == NULL) {
|
|
|
|
GST_DEBUG_OBJECT (media, "ignoring unconfigured transport %d", i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-12-26 15:28:59 +00:00
|
|
|
stream_rtpinfo =
|
|
|
|
gst_rtsp_stream_transport_get_rtpinfo (transport, earliest);
|
2014-02-07 15:39:49 +00:00
|
|
|
if (stream_rtpinfo == NULL) {
|
|
|
|
GST_DEBUG_OBJECT (media, "ignoring unknown RTPInfo %d", i);
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-26 14:41:14 +00:00
|
|
|
|
|
|
|
if (rtpinfo == NULL)
|
|
|
|
rtpinfo = g_string_new ("");
|
|
|
|
else
|
|
|
|
g_string_append (rtpinfo, ", ");
|
|
|
|
|
|
|
|
g_string_append (rtpinfo, stream_rtpinfo);
|
|
|
|
g_free (stream_rtpinfo);
|
|
|
|
}
|
2014-02-07 15:39:49 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2013-12-26 14:41:14 +00:00
|
|
|
|
|
|
|
if (rtpinfo == NULL) {
|
2014-02-07 15:39:49 +00:00
|
|
|
GST_WARNING_OBJECT (media, "RTP info is empty");
|
|
|
|
return NULL;
|
2013-12-26 14:41:14 +00:00
|
|
|
}
|
|
|
|
return g_string_free (rtpinfo, FALSE);
|
|
|
|
|
|
|
|
/* ERRORS */
|
2013-12-26 15:28:59 +00:00
|
|
|
not_prepared:
|
|
|
|
{
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
GST_ERROR_OBJECT (media, "media was not prepared");
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-12-26 14:41:14 +00:00
|
|
|
}
|
|
|
|
|
2012-10-27 22:23:57 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_media_set_transport:
|
|
|
|
* @media: a #GstRTSPSessionMedia
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-03-23 20:24:48 +00:00
|
|
|
* @tr: (transfer full): a #GstRTSPTransport
|
2012-10-27 22:23:57 +00:00
|
|
|
*
|
|
|
|
* Configure the transport for @stream to @tr in @media.
|
|
|
|
*
|
2012-10-28 12:48:44 +00:00
|
|
|
* Returns: (transfer none): the new or updated #GstRTSPStreamTransport for @stream.
|
2012-10-27 22:23:57 +00:00
|
|
|
*/
|
|
|
|
GstRTSPStreamTransport *
|
|
|
|
gst_rtsp_session_media_set_transport (GstRTSPSessionMedia * media,
|
2012-11-15 15:18:29 +00:00
|
|
|
GstRTSPStream * stream, GstRTSPTransport * tr)
|
2012-10-27 22:23:57 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
2012-10-27 22:23:57 +00:00
|
|
|
GstRTSPStreamTransport *result;
|
2012-11-29 10:11:05 +00:00
|
|
|
guint idx;
|
2012-10-27 22:23:57 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_return_val_if_fail (tr != NULL, NULL);
|
|
|
|
priv = media->priv;
|
|
|
|
idx = gst_rtsp_stream_get_index (stream);
|
|
|
|
g_return_val_if_fail (idx < priv->transports->len, NULL);
|
2012-10-27 22:23:57 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
result = g_ptr_array_index (priv->transports, idx);
|
2012-10-27 22:23:57 +00:00
|
|
|
if (result == NULL) {
|
2012-11-15 15:18:29 +00:00
|
|
|
result = gst_rtsp_stream_transport_new (stream, tr);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_ptr_array_index (priv->transports, idx) = result;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-27 22:23:57 +00:00
|
|
|
} else {
|
2012-11-15 15:18:29 +00:00
|
|
|
gst_rtsp_stream_transport_set_transport (result, tr);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-27 22:23:57 +00:00
|
|
|
}
|
2012-11-12 15:51:03 +00:00
|
|
|
|
2012-10-27 22:23:57 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_media_get_transport:
|
|
|
|
* @media: a #GstRTSPSessionMedia
|
|
|
|
* @idx: the stream index
|
|
|
|
*
|
2012-10-27 22:23:57 +00:00
|
|
|
* Get a previously created #GstRTSPStreamTransport for the stream at @idx.
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer none) (nullable): a #GstRTSPStreamTransport that is
|
|
|
|
* valid until the session of @media is unreffed.
|
2012-10-25 19:29:58 +00:00
|
|
|
*/
|
|
|
|
GstRTSPStreamTransport *
|
|
|
|
gst_rtsp_session_media_get_transport (GstRTSPSessionMedia * media, guint idx)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStreamTransport *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
g_return_val_if_fail (idx < priv->transports->len, NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
result = g_ptr_array_index (priv->transports, idx);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-10-16 09:35:10 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_media_get_transports:
|
|
|
|
* @media: a #GstRTSPSessionMedia
|
|
|
|
*
|
|
|
|
* Get a list of all available #GstRTSPStreamTransport in this session.
|
|
|
|
*
|
2017-12-07 15:08:29 +00:00
|
|
|
* Returns: (transfer full) (element-type GstRTSPStreamTransport): a
|
|
|
|
* list of #GstRTSPStreamTransport, g_ptr_array_unref () after usage.
|
2019-04-23 12:01:32 +00:00
|
|
|
*
|
|
|
|
* Since: 1.14
|
2017-10-16 09:35:10 +00:00
|
|
|
*/
|
|
|
|
GPtrArray *
|
|
|
|
gst_rtsp_session_media_get_transports (GstRTSPSessionMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
|
|
|
GPtrArray *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), NULL);
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
result = g_ptr_array_ref (priv->transports);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2017-11-21 08:53:08 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_session_media_alloc_channels:
|
|
|
|
* @media: a #GstRTSPSessionMedia
|
2014-03-23 20:24:48 +00:00
|
|
|
* @range: (out): a #GstRTSPRange
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
|
|
|
* Fill @range with the next available min and max channels for
|
|
|
|
* interleaved transport.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_session_media_alloc_channels (GstRTSPSessionMedia * media,
|
|
|
|
GstRTSPRange * range)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
range->min = priv->counter++;
|
|
|
|
range->max = priv->counter++;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_session_media_set_state:
|
|
|
|
* @media: a #GstRTSPSessionMedia
|
|
|
|
* @state: the new state
|
|
|
|
*
|
|
|
|
* Tell the media object @media to change to @state.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_session_media_set_state (GstRTSPSessionMedia * media, GstState state)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
ret = gst_rtsp_media_set_state (priv->media, state, priv->transports);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_session_media_set_rtsp_state:
|
|
|
|
* @media: a #GstRTSPSessionMedia
|
|
|
|
* @state: a #GstRTSPState
|
|
|
|
*
|
|
|
|
* Set the RTSP state of @media to @state.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_session_media_set_rtsp_state (GstRTSPSessionMedia * media,
|
|
|
|
GstRTSPState state)
|
|
|
|
{
|
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_SESSION_MEDIA (media));
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->state = state;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-11 10:18:26 +00:00
|
|
|
* gst_rtsp_session_media_get_rtsp_state:
|
2012-11-29 10:11:05 +00:00
|
|
|
* @media: a #GstRTSPSessionMedia
|
|
|
|
*
|
|
|
|
* Get the current RTSP state of @media.
|
|
|
|
*
|
|
|
|
* Returns: the current RTSP state of @media.
|
|
|
|
*/
|
|
|
|
GstRTSPState
|
|
|
|
gst_rtsp_session_media_get_rtsp_state (GstRTSPSessionMedia * media)
|
|
|
|
{
|
|
|
|
GstRTSPSessionMediaPrivate *priv;
|
|
|
|
GstRTSPState ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media),
|
|
|
|
GST_RTSP_STATE_INVALID);
|
|
|
|
|
|
|
|
priv = media->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
ret = priv->state;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|