2012-10-25 19:29:58 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:14:25 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2012-10-25 19:29:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <gst/app/gstappsrc.h>
|
|
|
|
#include <gst/app/gstappsink.h>
|
|
|
|
|
|
|
|
#include "rtsp-stream-transport.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_stream_transport_debug);
|
|
|
|
#define GST_CAT_DEFAULT rtsp_stream_transport_debug
|
|
|
|
|
|
|
|
static void gst_rtsp_stream_transport_finalize (GObject * obj);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstRTSPStreamTransport, gst_rtsp_stream_transport,
|
|
|
|
G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_stream_transport_class_init (GstRTSPStreamTransportClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_rtsp_stream_transport_finalize;
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (rtsp_stream_transport_debug, "rtspmediatransport",
|
|
|
|
0, "GstRTSPStreamTransport");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_stream_transport_init (GstRTSPStreamTransport * trans)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_stream_transport_finalize (GObject * obj)
|
|
|
|
{
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
trans = GST_RTSP_STREAM_TRANSPORT (obj);
|
|
|
|
|
|
|
|
/* remove callbacks now */
|
|
|
|
gst_rtsp_stream_transport_set_callbacks (trans, NULL, NULL, NULL, NULL);
|
|
|
|
gst_rtsp_stream_transport_set_keepalive (trans, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (trans->transport)
|
|
|
|
gst_rtsp_transport_free (trans->transport);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (trans->rtpsource)
|
|
|
|
g_object_set_qdata (trans->rtpsource, ssrc_stream_map_key, NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_rtsp_stream_transport_parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_transport_new:
|
|
|
|
* @stream: a #GstRTSPStream
|
2012-10-27 22:23:57 +00:00
|
|
|
* @tr: (transfer full): a GstRTSPTransport
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2012-10-27 21:49:24 +00:00
|
|
|
* Create a new #GstRTSPStreamTransport that can be used to manage
|
2012-10-27 22:23:57 +00:00
|
|
|
* @stream with transport @tr.
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
|
|
|
* Returns: a new #GstRTSPStreamTransport
|
|
|
|
*/
|
|
|
|
GstRTSPStreamTransport *
|
2012-11-15 15:18:29 +00:00
|
|
|
gst_rtsp_stream_transport_new (GstRTSPStream * stream, GstRTSPTransport * tr)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
2012-10-27 22:23:57 +00:00
|
|
|
g_return_val_if_fail (tr != NULL, NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
trans = g_object_new (GST_TYPE_RTSP_STREAM_TRANSPORT, NULL);
|
|
|
|
trans->stream = stream;
|
2012-10-27 22:23:57 +00:00
|
|
|
trans->transport = tr;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
return trans;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_transport_set_callbacks:
|
|
|
|
* @trans: a #GstRTSPStreamTransport
|
|
|
|
* @send_rtp: (scope notified): a callback called when RTP should be sent
|
|
|
|
* @send_rtcp: (scope notified): a callback called when RTCP should be sent
|
|
|
|
* @user_data: user data passed to callbacks
|
|
|
|
* @notify: called with the user_data when no longer needed.
|
|
|
|
*
|
|
|
|
* Install callbacks that will be called when data for a stream should be sent
|
|
|
|
* to a client. This is usually used when sending RTP/RTCP over TCP.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_transport_set_callbacks (GstRTSPStreamTransport * trans,
|
|
|
|
GstRTSPSendFunc send_rtp, GstRTSPSendFunc send_rtcp,
|
|
|
|
gpointer user_data, GDestroyNotify notify)
|
|
|
|
{
|
|
|
|
trans->send_rtp = send_rtp;
|
|
|
|
trans->send_rtcp = send_rtcp;
|
|
|
|
if (trans->notify)
|
|
|
|
trans->notify (trans->user_data);
|
|
|
|
trans->user_data = user_data;
|
|
|
|
trans->notify = notify;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_transport_set_keepalive:
|
|
|
|
* @trans: a #GstRTSPStreamTransport
|
|
|
|
* @keep_alive: a callback called when the receiver is active
|
|
|
|
* @user_data: user data passed to callback
|
|
|
|
* @notify: called with the user_data when no longer needed.
|
|
|
|
*
|
|
|
|
* Install callbacks that will be called when RTCP packets are received from the
|
|
|
|
* receiver of @trans.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_transport_set_keepalive (GstRTSPStreamTransport * trans,
|
|
|
|
GstRTSPKeepAliveFunc keep_alive, gpointer user_data, GDestroyNotify notify)
|
|
|
|
{
|
|
|
|
trans->keep_alive = keep_alive;
|
|
|
|
if (trans->ka_notify)
|
|
|
|
trans->ka_notify (trans->ka_user_data);
|
|
|
|
trans->ka_user_data = user_data;
|
|
|
|
trans->ka_notify = notify;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_transport_set_transport:
|
|
|
|
* @trans: a #GstRTSPStreamTransport
|
2012-10-27 22:23:57 +00:00
|
|
|
* @tr: (transfer full): a client #GstRTSPTransport
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2012-11-15 15:18:29 +00:00
|
|
|
* Set @tr as the client transport. This function takes ownership of the
|
|
|
|
* passed @tr.
|
2012-10-25 19:29:58 +00:00
|
|
|
*/
|
2012-10-27 21:49:24 +00:00
|
|
|
void
|
2012-10-25 19:29:58 +00:00
|
|
|
gst_rtsp_stream_transport_set_transport (GstRTSPStreamTransport * trans,
|
2012-11-15 15:18:29 +00:00
|
|
|
GstRTSPTransport * tr)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
2012-10-27 21:49:24 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
|
2012-10-27 22:23:57 +00:00
|
|
|
g_return_if_fail (tr != NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
/* keep track of the transports in the stream. */
|
|
|
|
if (trans->transport)
|
|
|
|
gst_rtsp_transport_free (trans->transport);
|
2012-10-27 22:23:57 +00:00
|
|
|
trans->transport = tr;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2012-11-12 16:06:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_transport_send_rtp:
|
|
|
|
* @trans: a #GstRTSPStreamTransport
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
*
|
|
|
|
* Send @buffer to the installed RTP callback for @trans.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_transport_send_rtp (GstRTSPStreamTransport * trans,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
if (trans->send_rtp)
|
|
|
|
res =
|
|
|
|
trans->send_rtp (buffer, trans->transport->interleaved.min,
|
|
|
|
trans->user_data);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_transport_send_rtcp:
|
|
|
|
* @trans: a #GstRTSPStreamTransport
|
|
|
|
* @buffer: a #GstBuffer
|
|
|
|
*
|
|
|
|
* Send @buffer to the installed RTCP callback for @trans.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_transport_send_rtcp (GstRTSPStreamTransport * trans,
|
|
|
|
GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
if (trans->send_rtcp)
|
|
|
|
res =
|
|
|
|
trans->send_rtcp (buffer, trans->transport->interleaved.max,
|
|
|
|
trans->user_data);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2012-11-12 16:11:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_transport_keep_alive:
|
|
|
|
* @trans: a #GstRTSPStreamTransport
|
|
|
|
*
|
|
|
|
* Signal the installed keep_alive callback for @trans.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_transport_keep_alive (GstRTSPStreamTransport * trans)
|
|
|
|
{
|
|
|
|
if (trans->keep_alive)
|
|
|
|
trans->keep_alive (trans->ka_user_data);
|
|
|
|
}
|