mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
stream: Add functions to get rtp and rtcp sockets
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=710100
This commit is contained in:
parent
d443f8546b
commit
8d5ce0d4ee
5 changed files with 184 additions and 0 deletions
|
@ -522,6 +522,9 @@ gst_rtsp_stream_recv_rtp
|
||||||
|
|
||||||
gst_rtsp_stream_add_transport
|
gst_rtsp_stream_add_transport
|
||||||
gst_rtsp_stream_remove_transport
|
gst_rtsp_stream_remove_transport
|
||||||
|
|
||||||
|
gst_rtsp_stream_get_rtp_socket
|
||||||
|
gst_rtsp_stream_get_rtcp_socket
|
||||||
<SUBSECTION Standard>
|
<SUBSECTION Standard>
|
||||||
GST_RTSP_STREAM_CAST
|
GST_RTSP_STREAM_CAST
|
||||||
GST_RTSP_STREAM_CLASS_CAST
|
GST_RTSP_STREAM_CLASS_CAST
|
||||||
|
|
|
@ -1996,3 +1996,71 @@ gst_rtsp_stream_remove_transport (GstRTSPStream * stream,
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_rtsp_stream_get_rtp_socket:
|
||||||
|
* @stream: a #GstRTSPStream
|
||||||
|
* @family: the socket family
|
||||||
|
*
|
||||||
|
* Get the RTP socket from @stream for a @family.
|
||||||
|
*
|
||||||
|
* @stream must be joined to a bin.
|
||||||
|
*
|
||||||
|
* Returns: the RTP socket or %NULL if no socket could be allocated for @family.
|
||||||
|
* Unref after usage
|
||||||
|
*/
|
||||||
|
GSocket *
|
||||||
|
gst_rtsp_stream_get_rtp_socket (GstRTSPStream * stream, GSocketFamily family)
|
||||||
|
{
|
||||||
|
GstRTSPStreamPrivate *priv = GST_RTSP_STREAM_GET_PRIVATE (stream);
|
||||||
|
GSocket *socket;
|
||||||
|
gchar *name;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
||||||
|
g_return_val_if_fail (family == G_SOCKET_FAMILY_IPV4 ||
|
||||||
|
family == G_SOCKET_FAMILY_IPV6, NULL);
|
||||||
|
g_return_val_if_fail (priv->udpsink[0], NULL);
|
||||||
|
|
||||||
|
if (family == G_SOCKET_FAMILY_IPV6)
|
||||||
|
name = "socket-v6";
|
||||||
|
else
|
||||||
|
name = "socket";
|
||||||
|
|
||||||
|
g_object_get (priv->udpsink[0], name, &socket, NULL);
|
||||||
|
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_rtsp_stream_get_rtcp_socket:
|
||||||
|
* @stream: a #GstRTSPStream
|
||||||
|
* @family: the socket family
|
||||||
|
*
|
||||||
|
* Get the RTCP socket from @stream for a @family.
|
||||||
|
*
|
||||||
|
* @stream must be joined to a bin.
|
||||||
|
*
|
||||||
|
* Returns: the RTCP socket or %NULL if no socket could be allocated for
|
||||||
|
* @family. Unref after usage
|
||||||
|
*/
|
||||||
|
GSocket *
|
||||||
|
gst_rtsp_stream_get_rtcp_socket (GstRTSPStream * stream, GSocketFamily family)
|
||||||
|
{
|
||||||
|
GstRTSPStreamPrivate *priv = GST_RTSP_STREAM_GET_PRIVATE (stream);
|
||||||
|
GSocket *socket;
|
||||||
|
gchar *name;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
||||||
|
g_return_val_if_fail (family == G_SOCKET_FAMILY_IPV4 ||
|
||||||
|
family == G_SOCKET_FAMILY_IPV6, NULL);
|
||||||
|
g_return_val_if_fail (priv->udpsink[1], NULL);
|
||||||
|
|
||||||
|
if (family == G_SOCKET_FAMILY_IPV6)
|
||||||
|
name = "socket-v6";
|
||||||
|
else
|
||||||
|
name = "socket";
|
||||||
|
|
||||||
|
g_object_get (priv->udpsink[1], name, &socket, NULL);
|
||||||
|
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
|
|
@ -122,6 +122,11 @@ gboolean gst_rtsp_stream_add_transport (GstRTSPStream *stream,
|
||||||
gboolean gst_rtsp_stream_remove_transport (GstRTSPStream *stream,
|
gboolean gst_rtsp_stream_remove_transport (GstRTSPStream *stream,
|
||||||
GstRTSPStreamTransport *trans);
|
GstRTSPStreamTransport *trans);
|
||||||
|
|
||||||
|
GSocket * gst_rtsp_stream_get_rtp_socket (GstRTSPStream *stream,
|
||||||
|
GSocketFamily family);
|
||||||
|
GSocket * gst_rtsp_stream_get_rtcp_socket (GstRTSPStream *stream,
|
||||||
|
GSocketFamily family);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_RTSP_STREAM_H__ */
|
#endif /* __GST_RTSP_STREAM_H__ */
|
||||||
|
|
|
@ -31,6 +31,7 @@ check_PROGRAMS = \
|
||||||
gst/mountpoints \
|
gst/mountpoints \
|
||||||
gst/mediafactory \
|
gst/mediafactory \
|
||||||
gst/media \
|
gst/media \
|
||||||
|
gst/stream \
|
||||||
gst/addresspool \
|
gst/addresspool \
|
||||||
gst/threadpool \
|
gst/threadpool \
|
||||||
gst/permissions \
|
gst/permissions \
|
||||||
|
|
107
tests/check/gst/stream.c
Normal file
107
tests/check/gst/stream.c
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
/* GStreamer
|
||||||
|
* Copyright (C) 2013 Axis Communications AB <dev-gstreamer at axis dot 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., 51 Franklin St, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gst/check/gstcheck.h>
|
||||||
|
|
||||||
|
#include <rtsp-stream.h>
|
||||||
|
|
||||||
|
GST_START_TEST (test_get_sockets)
|
||||||
|
{
|
||||||
|
GstPad *srcpad;
|
||||||
|
GstElement *pay;
|
||||||
|
GstRTSPStream *stream;
|
||||||
|
GstBin *bin;
|
||||||
|
GstElement *rtpbin;
|
||||||
|
GSocket *socket;
|
||||||
|
gboolean have_ipv4;
|
||||||
|
gboolean have_ipv6;
|
||||||
|
|
||||||
|
srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
|
||||||
|
fail_unless (srcpad != NULL);
|
||||||
|
gst_pad_set_active (srcpad, TRUE);
|
||||||
|
pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
|
||||||
|
fail_unless (pay != NULL);
|
||||||
|
stream = gst_rtsp_stream_new (0, pay, srcpad);
|
||||||
|
fail_unless (stream != NULL);
|
||||||
|
gst_object_unref (pay);
|
||||||
|
gst_object_unref (srcpad);
|
||||||
|
rtpbin = gst_element_factory_make ("rtpbin", "testrtpbin");
|
||||||
|
fail_unless (rtpbin != NULL);
|
||||||
|
bin = GST_BIN (gst_bin_new ("testbin"));
|
||||||
|
fail_unless (bin != NULL);
|
||||||
|
fail_unless (gst_bin_add (bin, rtpbin));
|
||||||
|
|
||||||
|
fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL));
|
||||||
|
|
||||||
|
socket = gst_rtsp_stream_get_rtp_socket (stream, G_SOCKET_FAMILY_IPV4);
|
||||||
|
have_ipv4 = (socket != NULL);
|
||||||
|
if (have_ipv4) {
|
||||||
|
fail_unless (g_socket_get_fd (socket) >= 0);
|
||||||
|
g_object_unref (socket);
|
||||||
|
}
|
||||||
|
|
||||||
|
socket = gst_rtsp_stream_get_rtcp_socket (stream, G_SOCKET_FAMILY_IPV4);
|
||||||
|
if (have_ipv4) {
|
||||||
|
fail_unless (socket != NULL);
|
||||||
|
fail_unless (g_socket_get_fd (socket) >= 0);
|
||||||
|
g_object_unref (socket);
|
||||||
|
} else {
|
||||||
|
fail_unless (socket == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
socket = gst_rtsp_stream_get_rtp_socket (stream, G_SOCKET_FAMILY_IPV6);
|
||||||
|
have_ipv6 = (socket != NULL);
|
||||||
|
if (have_ipv6) {
|
||||||
|
fail_unless (g_socket_get_fd (socket) >= 0);
|
||||||
|
g_object_unref (socket);
|
||||||
|
}
|
||||||
|
|
||||||
|
socket = gst_rtsp_stream_get_rtcp_socket (stream, G_SOCKET_FAMILY_IPV6);
|
||||||
|
if (have_ipv6) {
|
||||||
|
fail_unless (socket != NULL);
|
||||||
|
fail_unless (g_socket_get_fd (socket) >= 0);
|
||||||
|
g_object_unref (socket);
|
||||||
|
} else {
|
||||||
|
fail_unless (socket == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check that at least one family is available */
|
||||||
|
fail_unless (have_ipv4 || have_ipv6);
|
||||||
|
|
||||||
|
fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin));
|
||||||
|
|
||||||
|
gst_object_unref (bin);
|
||||||
|
gst_object_unref (stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
|
static Suite *
|
||||||
|
rtspstream_suite (void)
|
||||||
|
{
|
||||||
|
Suite *s = suite_create ("rtspstream");
|
||||||
|
TCase *tc = tcase_create ("general");
|
||||||
|
|
||||||
|
suite_add_tcase (s, tc);
|
||||||
|
tcase_add_test (tc, test_get_sockets);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_CHECK_MAIN (rtspstream);
|
Loading…
Reference in a new issue