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-stream
|
|
|
|
* @short_description: A media stream
|
|
|
|
* @see_also: #GstRTSPMedia
|
|
|
|
*
|
2013-07-16 10:32:51 +00:00
|
|
|
* The #GstRTSPStream object manages the data transport for one stream. It
|
|
|
|
* is created from a payloader element and a source pad that produce the RTP
|
|
|
|
* packets for the stream.
|
|
|
|
*
|
|
|
|
* With gst_rtsp_stream_join_bin() the streaming elements are added to the bin
|
|
|
|
* and rtpbin. gst_rtsp_stream_leave_bin() removes the elements again.
|
|
|
|
*
|
|
|
|
* The #GstRTSPStream will use the configured addresspool, as set with
|
|
|
|
* gst_rtsp_stream_set_address_pool(), to allocate multicast addresses for the
|
|
|
|
* stream. With gst_rtsp_stream_get_multicast_address() you can get the
|
|
|
|
* configured address.
|
|
|
|
*
|
|
|
|
* With gst_rtsp_stream_get_server_port () you can get the port that the server
|
|
|
|
* will use to receive RTCP. This is the part that the clients will use to send
|
|
|
|
* RTCP to.
|
|
|
|
*
|
|
|
|
* With gst_rtsp_stream_add_transport() destinations can be added where the
|
|
|
|
* stream should be sent to. Use gst_rtsp_stream_remove_transport() to remove
|
|
|
|
* the destination again.
|
|
|
|
*
|
2019-10-15 17:08:32 +00:00
|
|
|
* Each #GstRTSPStreamTransport spawns one queue that will serve as a backlog of a
|
|
|
|
* controllable maximum size when the reflux from the TCP connection's backpressure
|
|
|
|
* starts spilling all over.
|
|
|
|
*
|
|
|
|
* Unlike the backlog in rtspconnection, which we have decided should only contain
|
|
|
|
* at most one RTP and one RTCP data message in order to allow control messages to
|
|
|
|
* go through unobstructed, this backlog only consists of data messages, allowing
|
|
|
|
* us to fill it up without concern.
|
|
|
|
*
|
|
|
|
* When multiple TCP transports exist, for example in the context of a shared media,
|
|
|
|
* we only pop samples from our appsinks when at least one of the transports doesn't
|
|
|
|
* experience back pressure: this allows us to pace our sample popping to the speed
|
|
|
|
* of the fastest client.
|
|
|
|
*
|
|
|
|
* When a sample is popped, it is either sent directly on transports that don't
|
|
|
|
* experience backpressure, or queued on the transport's backlog otherwise. Samples
|
|
|
|
* are then popped from that backlog when the transport reports it has sent the message.
|
|
|
|
*
|
|
|
|
* Once the backlog reaches an overly large duration, the transport is dropped as
|
|
|
|
* the client was deemed too slow.
|
2013-07-11 14:57:14 +00:00
|
|
|
*/
|
2018-09-24 08:36:21 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2013-07-03 13:13:45 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
|
|
|
#include <gst/app/gstappsrc.h>
|
|
|
|
#include <gst/app/gstappsink.h>
|
|
|
|
|
2015-03-09 15:00:07 +00:00
|
|
|
#include <gst/rtp/gstrtpbuffer.h>
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
#include "rtsp-stream.h"
|
2019-10-15 17:08:32 +00:00
|
|
|
#include "rtsp-server-internal.h"
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
struct _GstRTSPStreamPrivate
|
|
|
|
{
|
|
|
|
GMutex lock;
|
|
|
|
guint idx;
|
2015-01-09 11:40:47 +00:00
|
|
|
/* Only one pad is ever set */
|
|
|
|
GstPad *srcpad, *sinkpad;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstElement *payloader;
|
|
|
|
guint buffer_size;
|
2015-12-30 16:39:05 +00:00
|
|
|
GstBin *joined_bin;
|
2015-11-16 14:12:28 +00:00
|
|
|
|
|
|
|
/* TRUE if this stream is running on
|
|
|
|
* the client side of an RTSP link (for RECORD) */
|
|
|
|
gboolean client_side;
|
2013-07-02 12:44:35 +00:00
|
|
|
gchar *control;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2017-10-23 07:49:09 +00:00
|
|
|
/* TRUE if stream is complete. This means that the receiver and the sender
|
|
|
|
* parts are present in the stream. */
|
|
|
|
gboolean is_complete;
|
2014-01-07 11:21:09 +00:00
|
|
|
GstRTSPProfile profiles;
|
2018-03-21 09:56:51 +00:00
|
|
|
GstRTSPLowerTrans allowed_protocols;
|
|
|
|
GstRTSPLowerTrans configured_protocols;
|
2013-08-16 14:08:43 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/* pads on the rtpbin */
|
|
|
|
GstPad *send_rtp_sink;
|
2015-01-09 11:40:47 +00:00
|
|
|
GstPad *recv_rtp_src;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstPad *recv_sink[2];
|
|
|
|
GstPad *send_src[2];
|
|
|
|
|
|
|
|
/* the RTPSession object */
|
|
|
|
GObject *session;
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
/* SRTP encoder/decoder */
|
|
|
|
GstElement *srtpenc;
|
|
|
|
GstElement *srtpdec;
|
2014-04-02 10:36:16 +00:00
|
|
|
GHashTable *keys;
|
2014-03-13 16:35:21 +00:00
|
|
|
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
/* for UDP unicast */
|
2016-07-21 00:09:57 +00:00
|
|
|
GstElement *udpsrc_v4[2];
|
|
|
|
GstElement *udpsrc_v6[2];
|
2015-02-12 09:46:28 +00:00
|
|
|
GstElement *udpqueue[2];
|
2012-11-29 10:11:05 +00:00
|
|
|
GstElement *udpsink[2];
|
2017-10-17 08:44:33 +00:00
|
|
|
GSocket *socket_v4[2];
|
|
|
|
GSocket *socket_v6[2];
|
2013-05-30 06:07:48 +00:00
|
|
|
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
/* for UDP multicast */
|
|
|
|
GstElement *mcast_udpsrc_v4[2];
|
|
|
|
GstElement *mcast_udpsrc_v6[2];
|
|
|
|
GstElement *mcast_udpqueue[2];
|
|
|
|
GstElement *mcast_udpsink[2];
|
2017-10-17 08:44:33 +00:00
|
|
|
GSocket *mcast_socket_v4[2];
|
|
|
|
GSocket *mcast_socket_v6[2];
|
2018-07-26 10:01:16 +00:00
|
|
|
GList *mcast_clients;
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/* for TCP transport */
|
|
|
|
GstElement *appsrc[2];
|
2015-01-16 19:48:42 +00:00
|
|
|
GstClockTime appsrc_base_time[2];
|
2012-11-29 10:11:05 +00:00
|
|
|
GstElement *appqueue[2];
|
|
|
|
GstElement *appsink[2];
|
|
|
|
|
|
|
|
GstElement *tee[2];
|
|
|
|
GstElement *funnel[2];
|
|
|
|
|
2014-11-26 14:12:36 +00:00
|
|
|
/* retransmission */
|
|
|
|
GstElement *rtxsend;
|
2018-03-29 20:49:26 +00:00
|
|
|
GstElement *rtxreceive;
|
2014-11-26 14:12:36 +00:00
|
|
|
guint rtx_pt;
|
|
|
|
GstClockTime rtx_time;
|
|
|
|
|
2019-04-04 22:48:07 +00:00
|
|
|
/* rate control */
|
|
|
|
gboolean do_rate_control;
|
|
|
|
|
2018-04-02 20:49:35 +00:00
|
|
|
/* Forward Error Correction with RFC 5109 */
|
|
|
|
GstElement *ulpfec_decoder;
|
|
|
|
GstElement *ulpfec_encoder;
|
|
|
|
guint ulpfec_pt;
|
|
|
|
gboolean ulpfec_enabled;
|
|
|
|
guint ulpfec_percentage;
|
|
|
|
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
/* pool used to manage unicast and multicast addresses */
|
|
|
|
GstRTSPAddressPool *pool;
|
2013-05-30 06:07:48 +00:00
|
|
|
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
/* unicast server addr/port */
|
|
|
|
GstRTSPAddress *server_addr_v4;
|
2013-05-30 06:07:48 +00:00
|
|
|
GstRTSPAddress *server_addr_v6;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
/* multicast addresses */
|
2016-07-20 19:35:44 +00:00
|
|
|
GstRTSPAddress *mcast_addr_v4;
|
|
|
|
GstRTSPAddress *mcast_addr_v6;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2016-03-02 17:42:13 +00:00
|
|
|
gchar *multicast_iface;
|
2018-07-24 07:35:46 +00:00
|
|
|
guint max_mcast_ttl;
|
2018-09-06 14:17:33 +00:00
|
|
|
gboolean bind_mcast_address;
|
2016-03-02 17:42:13 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/* the caps of the stream */
|
|
|
|
gulong caps_sig;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
/* transports we stream to */
|
|
|
|
guint n_active;
|
|
|
|
GList *transports;
|
2014-07-10 09:32:20 +00:00
|
|
|
guint transports_cookie;
|
2019-10-07 10:13:47 +00:00
|
|
|
GPtrArray *tr_cache;
|
|
|
|
guint tr_cache_cookie;
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
guint n_tcp_transports;
|
|
|
|
gboolean have_buffer[2];
|
2015-01-30 11:50:20 +00:00
|
|
|
|
2013-06-24 08:43:59 +00:00
|
|
|
gint dscp_qos;
|
2013-11-28 12:42:21 +00:00
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
/* Sending logic for TCP */
|
|
|
|
GThread *send_thread;
|
|
|
|
GCond send_cond;
|
|
|
|
GMutex send_lock;
|
|
|
|
/* @send_lock is released when pushing data out, we use
|
|
|
|
* a cookie to decide whether we should wait on @send_cond
|
|
|
|
* before checking the transports' backlogs again
|
|
|
|
*/
|
|
|
|
guint send_cookie;
|
|
|
|
/* Used to control shutdown of @send_thread */
|
|
|
|
gboolean continue_sending;
|
|
|
|
|
2013-11-28 12:42:21 +00:00
|
|
|
/* stream blocking */
|
2016-11-21 12:29:56 +00:00
|
|
|
gulong blocked_id[2];
|
2013-11-28 12:42:21 +00:00
|
|
|
gboolean blocking;
|
2015-01-09 11:40:47 +00:00
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
/* current stream postion */
|
|
|
|
GstClockTime position;
|
|
|
|
|
2015-01-09 11:40:47 +00:00
|
|
|
/* pt->caps map for RECORD streams */
|
|
|
|
GHashTable *ptmap;
|
2015-12-30 16:39:05 +00:00
|
|
|
|
|
|
|
GstRTSPPublishClockMode publish_clock_mode;
|
2019-01-16 11:59:11 +00:00
|
|
|
GThreadPool *send_pool;
|
2020-10-05 22:04:17 +00:00
|
|
|
|
|
|
|
/* Used to provide accurate rtpinfo when the stream is blocking */
|
|
|
|
gboolean blocked_buffer;
|
|
|
|
guint32 blocked_seqnum;
|
|
|
|
guint32 blocked_rtptime;
|
|
|
|
GstClockTime blocked_running_time;
|
2020-11-18 19:36:50 +00:00
|
|
|
gint blocked_clock_rate;
|
2020-09-04 19:14:35 +00:00
|
|
|
|
|
|
|
/* Whether we should send and receive RTCP */
|
|
|
|
gboolean enable_rtcp;
|
2021-07-05 09:54:18 +00:00
|
|
|
|
|
|
|
/* blocking early rtcp packets */
|
|
|
|
GstPad *block_early_rtcp_pad;
|
|
|
|
gulong block_early_rtcp_probe;
|
|
|
|
GstPad *block_early_rtcp_pad_ipv6;
|
|
|
|
gulong block_early_rtcp_probe_ipv6;
|
2023-06-26 06:25:36 +00:00
|
|
|
|
|
|
|
/* set to drop delta units in blocking pad */
|
|
|
|
gboolean drop_delta_units;
|
|
|
|
|
|
|
|
/* used to indicate that the drop probe has dropped a buffer and should be
|
|
|
|
* removed */
|
|
|
|
gboolean remove_drop_probe;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
};
|
|
|
|
|
2013-08-16 14:08:43 +00:00
|
|
|
#define DEFAULT_CONTROL NULL
|
2014-01-07 11:21:09 +00:00
|
|
|
#define DEFAULT_PROFILES GST_RTSP_PROFILE_AVP
|
2013-08-16 14:16:00 +00:00
|
|
|
#define DEFAULT_PROTOCOLS GST_RTSP_LOWER_TRANS_UDP | GST_RTSP_LOWER_TRANS_UDP_MCAST | \
|
|
|
|
GST_RTSP_LOWER_TRANS_TCP
|
2018-07-24 07:35:46 +00:00
|
|
|
#define DEFAULT_MAX_MCAST_TTL 255
|
2018-09-06 14:17:33 +00:00
|
|
|
#define DEFAULT_BIND_MCAST_ADDRESS FALSE
|
2019-04-04 22:48:07 +00:00
|
|
|
#define DEFAULT_DO_RATE_CONTROL TRUE
|
2020-09-04 19:14:35 +00:00
|
|
|
#define DEFAULT_ENABLE_RTCP TRUE
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2013-07-02 12:44:35 +00:00
|
|
|
PROP_CONTROL,
|
2014-01-07 11:21:09 +00:00
|
|
|
PROP_PROFILES,
|
2013-08-16 14:08:43 +00:00
|
|
|
PROP_PROTOCOLS,
|
2012-10-25 19:29:58 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_NEW_RTP_ENCODER,
|
|
|
|
SIGNAL_NEW_RTCP_ENCODER,
|
2017-02-01 08:44:50 +00:00
|
|
|
SIGNAL_NEW_RTP_RTCP_DECODER,
|
2014-05-16 01:15:04 +00:00
|
|
|
SIGNAL_LAST
|
|
|
|
};
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtsp_stream_debug);
|
|
|
|
#define GST_CAT_DEFAULT rtsp_stream_debug
|
|
|
|
|
|
|
|
static GQuark ssrc_stream_map_key;
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
static void gst_rtsp_stream_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtsp_stream_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
static void gst_rtsp_stream_finalize (GObject * obj);
|
|
|
|
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
static gboolean
|
|
|
|
update_transport (GstRTSPStream * stream, GstRTSPStreamTransport * trans,
|
|
|
|
gboolean add);
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
static guint gst_rtsp_stream_signals[SIGNAL_LAST] = { 0 };
|
|
|
|
|
2018-06-24 10:44:26 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GstRTSPStream, gst_rtsp_stream, G_TYPE_OBJECT);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_stream_class_init (GstRTSPStreamClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
gobject_class->get_property = gst_rtsp_stream_get_property;
|
|
|
|
gobject_class->set_property = gst_rtsp_stream_set_property;
|
2012-10-25 19:29:58 +00:00
|
|
|
gobject_class->finalize = gst_rtsp_stream_finalize;
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CONTROL,
|
|
|
|
g_param_spec_string ("control", "Control",
|
|
|
|
"The control string for this stream", DEFAULT_CONTROL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2014-01-07 11:21:09 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PROFILES,
|
|
|
|
g_param_spec_flags ("profiles", "Profiles",
|
|
|
|
"Allowed transfer profiles", GST_TYPE_RTSP_PROFILE,
|
|
|
|
DEFAULT_PROFILES, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2013-08-16 14:08:43 +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));
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
gst_rtsp_stream_signals[SIGNAL_NEW_RTP_ENCODER] =
|
|
|
|
g_signal_new ("new-rtp-encoder", G_TYPE_FROM_CLASS (klass),
|
2019-08-29 05:34:26 +00:00
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
|
2014-05-16 01:15:04 +00:00
|
|
|
|
|
|
|
gst_rtsp_stream_signals[SIGNAL_NEW_RTCP_ENCODER] =
|
|
|
|
g_signal_new ("new-rtcp-encoder", G_TYPE_FROM_CLASS (klass),
|
2019-08-29 05:34:26 +00:00
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
|
2014-05-16 01:15:04 +00:00
|
|
|
|
2017-02-01 08:44:50 +00:00
|
|
|
gst_rtsp_stream_signals[SIGNAL_NEW_RTP_RTCP_DECODER] =
|
|
|
|
g_signal_new ("new-rtp-rtcp-decoder", G_TYPE_FROM_CLASS (klass),
|
2019-08-29 05:34:26 +00:00
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
|
2017-02-01 08:44:50 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (rtsp_stream_debug, "rtspstream", 0, "GstRTSPStream");
|
|
|
|
|
|
|
|
ssrc_stream_map_key = g_quark_from_static_string ("GstRTSPServer.stream");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-13 10:14:49 +00:00
|
|
|
gst_rtsp_stream_init (GstRTSPStream * stream)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
2018-06-24 10:44:26 +00:00
|
|
|
GstRTSPStreamPrivate *priv = gst_rtsp_stream_get_instance_private (stream);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2012-11-28 11:40:18 +00:00
|
|
|
GST_DEBUG ("new stream %p", stream);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
stream->priv = priv;
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
priv->dscp_qos = -1;
|
|
|
|
priv->control = g_strdup (DEFAULT_CONTROL);
|
2014-01-07 11:21:09 +00:00
|
|
|
priv->profiles = DEFAULT_PROFILES;
|
2018-03-21 09:56:51 +00:00
|
|
|
priv->allowed_protocols = DEFAULT_PROTOCOLS;
|
|
|
|
priv->configured_protocols = 0;
|
2015-12-30 16:39:05 +00:00
|
|
|
priv->publish_clock_mode = GST_RTSP_PUBLISH_CLOCK_MODE_CLOCK;
|
2018-07-24 07:35:46 +00:00
|
|
|
priv->max_mcast_ttl = DEFAULT_MAX_MCAST_TTL;
|
2018-09-06 14:17:33 +00:00
|
|
|
priv->bind_mcast_address = DEFAULT_BIND_MCAST_ADDRESS;
|
2019-04-04 22:48:07 +00:00
|
|
|
priv->do_rate_control = DEFAULT_DO_RATE_CONTROL;
|
2020-09-04 19:14:35 +00:00
|
|
|
priv->enable_rtcp = DEFAULT_ENABLE_RTCP;
|
2013-06-24 08:43:59 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_init (&priv->lock);
|
2014-04-02 10:36:16 +00:00
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
priv->continue_sending = TRUE;
|
|
|
|
priv->send_cookie = 0;
|
|
|
|
g_cond_init (&priv->send_cond);
|
|
|
|
g_mutex_init (&priv->send_lock);
|
|
|
|
|
2014-04-02 10:36:16 +00:00
|
|
|
priv->keys = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
|
|
NULL, (GDestroyNotify) gst_caps_unref);
|
2015-01-09 11:40:47 +00:00
|
|
|
priv->ptmap = g_hash_table_new_full (NULL, NULL, NULL,
|
|
|
|
(GDestroyNotify) gst_caps_unref);
|
2019-01-16 11:59:11 +00:00
|
|
|
priv->send_pool = NULL;
|
2021-07-05 09:54:18 +00:00
|
|
|
priv->block_early_rtcp_pad = NULL;
|
|
|
|
priv->block_early_rtcp_probe = 0;
|
|
|
|
priv->block_early_rtcp_pad_ipv6 = NULL;
|
|
|
|
priv->block_early_rtcp_probe_ipv6 = 0;
|
2023-06-26 06:25:36 +00:00
|
|
|
priv->drop_delta_units = FALSE;
|
|
|
|
priv->remove_drop_probe = FALSE;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
2018-07-26 10:01:16 +00:00
|
|
|
typedef struct _UdpClientAddrInfo UdpClientAddrInfo;
|
|
|
|
|
|
|
|
struct _UdpClientAddrInfo
|
|
|
|
{
|
|
|
|
gchar *address;
|
|
|
|
guint rtp_port;
|
|
|
|
guint add_count; /* how often this address has been added */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_mcast_client (gpointer data)
|
|
|
|
{
|
|
|
|
UdpClientAddrInfo *client = data;
|
|
|
|
|
|
|
|
g_free (client->address);
|
|
|
|
g_free (client);
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
static void
|
|
|
|
gst_rtsp_stream_finalize (GObject * obj)
|
|
|
|
{
|
|
|
|
GstRTSPStream *stream;
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2017-10-23 07:49:09 +00:00
|
|
|
guint i;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
stream = GST_RTSP_STREAM (obj);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-28 11:40:18 +00:00
|
|
|
GST_DEBUG ("finalize stream %p", stream);
|
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
/* we really need to be unjoined now */
|
2016-07-14 15:10:31 +00:00
|
|
|
g_return_if_fail (priv->joined_bin == NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2019-01-16 11:59:11 +00:00
|
|
|
if (priv->send_pool)
|
|
|
|
g_thread_pool_free (priv->send_pool, TRUE, TRUE);
|
2016-07-20 19:35:44 +00:00
|
|
|
if (priv->mcast_addr_v4)
|
|
|
|
gst_rtsp_address_free (priv->mcast_addr_v4);
|
|
|
|
if (priv->mcast_addr_v6)
|
|
|
|
gst_rtsp_address_free (priv->mcast_addr_v6);
|
2013-05-30 06:07:48 +00:00
|
|
|
if (priv->server_addr_v4)
|
|
|
|
gst_rtsp_address_free (priv->server_addr_v4);
|
|
|
|
if (priv->server_addr_v6)
|
|
|
|
gst_rtsp_address_free (priv->server_addr_v6);
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->pool)
|
|
|
|
g_object_unref (priv->pool);
|
2014-11-26 14:12:36 +00:00
|
|
|
if (priv->rtxsend)
|
|
|
|
g_object_unref (priv->rtxsend);
|
2018-03-29 20:49:26 +00:00
|
|
|
if (priv->rtxreceive)
|
|
|
|
g_object_unref (priv->rtxreceive);
|
2018-04-02 20:49:35 +00:00
|
|
|
if (priv->ulpfec_encoder)
|
|
|
|
gst_object_unref (priv->ulpfec_encoder);
|
|
|
|
if (priv->ulpfec_decoder)
|
|
|
|
gst_object_unref (priv->ulpfec_decoder);
|
2014-11-26 14:12:36 +00:00
|
|
|
|
2017-10-23 07:49:09 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (priv->socket_v4[i])
|
|
|
|
g_object_unref (priv->socket_v4[i]);
|
|
|
|
if (priv->socket_v6[i])
|
|
|
|
g_object_unref (priv->socket_v6[i]);
|
|
|
|
if (priv->mcast_socket_v4[i])
|
|
|
|
g_object_unref (priv->mcast_socket_v4[i]);
|
|
|
|
if (priv->mcast_socket_v6[i])
|
|
|
|
g_object_unref (priv->mcast_socket_v6[i]);
|
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
|
2016-03-02 17:42:13 +00:00
|
|
|
g_free (priv->multicast_iface);
|
2018-07-26 10:01:16 +00:00
|
|
|
g_list_free_full (priv->mcast_clients, (GDestroyNotify) free_mcast_client);
|
2016-03-02 17:42:13 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_object_unref (priv->payloader);
|
2015-01-09 11:40:47 +00:00
|
|
|
if (priv->srcpad)
|
|
|
|
gst_object_unref (priv->srcpad);
|
|
|
|
if (priv->sinkpad)
|
|
|
|
gst_object_unref (priv->sinkpad);
|
2013-07-02 12:44:35 +00:00
|
|
|
g_free (priv->control);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_clear (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2014-04-02 10:36:16 +00:00
|
|
|
g_hash_table_unref (priv->keys);
|
2015-01-09 11:40:47 +00:00
|
|
|
g_hash_table_destroy (priv->ptmap);
|
2014-04-02 10:36:16 +00:00
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
g_mutex_clear (&priv->send_lock);
|
|
|
|
g_cond_clear (&priv->send_cond);
|
|
|
|
|
2021-07-05 09:54:18 +00:00
|
|
|
if (priv->block_early_rtcp_probe != 0) {
|
|
|
|
gst_pad_remove_probe
|
|
|
|
(priv->block_early_rtcp_pad, priv->block_early_rtcp_probe);
|
|
|
|
gst_object_unref (priv->block_early_rtcp_pad);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->block_early_rtcp_probe_ipv6 != 0) {
|
|
|
|
gst_pad_remove_probe
|
|
|
|
(priv->block_early_rtcp_pad_ipv6, priv->block_early_rtcp_probe_ipv6);
|
|
|
|
gst_object_unref (priv->block_early_rtcp_pad_ipv6);
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
G_OBJECT_CLASS (gst_rtsp_stream_parent_class)->finalize (obj);
|
|
|
|
}
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
static void
|
|
|
|
gst_rtsp_stream_get_property (GObject * object, guint propid,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRTSPStream *stream = GST_RTSP_STREAM (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_CONTROL:
|
|
|
|
g_value_take_string (value, gst_rtsp_stream_get_control (stream));
|
|
|
|
break;
|
2014-01-07 11:21:09 +00:00
|
|
|
case PROP_PROFILES:
|
|
|
|
g_value_set_flags (value, gst_rtsp_stream_get_profiles (stream));
|
|
|
|
break;
|
2013-08-16 14:08:43 +00:00
|
|
|
case PROP_PROTOCOLS:
|
|
|
|
g_value_set_flags (value, gst_rtsp_stream_get_protocols (stream));
|
|
|
|
break;
|
2013-07-02 12:44:35 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtsp_stream_set_property (GObject * object, guint propid,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRTSPStream *stream = GST_RTSP_STREAM (object);
|
|
|
|
|
|
|
|
switch (propid) {
|
|
|
|
case PROP_CONTROL:
|
|
|
|
gst_rtsp_stream_set_control (stream, g_value_get_string (value));
|
|
|
|
break;
|
2014-01-07 11:21:09 +00:00
|
|
|
case PROP_PROFILES:
|
|
|
|
gst_rtsp_stream_set_profiles (stream, g_value_get_flags (value));
|
|
|
|
break;
|
2013-08-16 14:08:43 +00:00
|
|
|
case PROP_PROTOCOLS:
|
|
|
|
gst_rtsp_stream_set_protocols (stream, g_value_get_flags (value));
|
|
|
|
break;
|
2013-07-02 12:44:35 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, propid, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_new:
|
|
|
|
* @idx: an index
|
2015-01-09 11:40:47 +00:00
|
|
|
* @pad: a #GstPad
|
2012-10-25 19:29:58 +00:00
|
|
|
* @payloader: a #GstElement
|
|
|
|
*
|
|
|
|
* Create a new media stream with index @idx that handles RTP data on
|
2015-01-09 11:40:47 +00:00
|
|
|
* @pad and has a payloader element @payloader if @pad is a source pad
|
|
|
|
* or a depayloader element @payloader if @pad is a sink pad.
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2014-03-23 20:24:48 +00:00
|
|
|
* Returns: (transfer full): a new #GstRTSPStream
|
2012-10-25 19:29:58 +00:00
|
|
|
*/
|
|
|
|
GstRTSPStream *
|
2015-01-09 11:40:47 +00:00
|
|
|
gst_rtsp_stream_new (guint idx, GstElement * payloader, GstPad * pad)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStream *stream;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_ELEMENT (payloader), NULL);
|
2015-01-09 11:40:47 +00:00
|
|
|
g_return_val_if_fail (GST_IS_PAD (pad), NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
stream = g_object_new (GST_TYPE_RTSP_STREAM, NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
priv->idx = idx;
|
|
|
|
priv->payloader = gst_object_ref (payloader);
|
2015-01-09 11:40:47 +00:00
|
|
|
if (GST_PAD_IS_SRC (pad))
|
|
|
|
priv->srcpad = gst_object_ref (pad);
|
|
|
|
else
|
|
|
|
priv->sinkpad = gst_object_ref (pad);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_index:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the stream index.
|
|
|
|
*
|
|
|
|
* Return: the stream index.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_stream_get_index (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
|
|
|
|
|
|
|
|
return stream->priv->idx;
|
|
|
|
}
|
|
|
|
|
2013-11-15 20:14:32 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_pt:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the stream payload type.
|
|
|
|
*
|
|
|
|
* Return: the stream payload type.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_stream_get_pt (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
guint pt;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (priv->payloader), "pt", &pt, NULL);
|
|
|
|
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
/**
|
2013-04-22 15:32:31 +00:00
|
|
|
* gst_rtsp_stream_get_srcpad:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the srcpad associated with @stream.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the srcpad. Unref after usage.
|
2013-04-22 15:32:31 +00:00
|
|
|
*/
|
|
|
|
GstPad *
|
|
|
|
gst_rtsp_stream_get_srcpad (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
2015-01-09 11:40:47 +00:00
|
|
|
if (!stream->priv->srcpad)
|
|
|
|
return NULL;
|
|
|
|
|
2013-04-22 15:32:31 +00:00
|
|
|
return gst_object_ref (stream->priv->srcpad);
|
|
|
|
}
|
|
|
|
|
2015-01-09 11:40:47 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_sinkpad:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the sinkpad associated with @stream.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the sinkpad. Unref after usage.
|
2015-01-09 11:40:47 +00:00
|
|
|
*/
|
|
|
|
GstPad *
|
|
|
|
gst_rtsp_stream_get_sinkpad (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
if (!stream->priv->sinkpad)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return gst_object_ref (stream->priv->sinkpad);
|
|
|
|
}
|
|
|
|
|
2013-07-02 12:44:35 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_control:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the control string to identify this stream.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the control string. g_free() after usage.
|
2013-07-02 12:44:35 +00:00
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gst_rtsp_stream_get_control (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gchar *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = g_strdup (priv->control)) == NULL)
|
2013-07-03 13:13:45 +00:00
|
|
|
result = g_strdup_printf ("stream=%u", priv->idx);
|
2013-07-02 12:44:35 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_control:
|
|
|
|
* @stream: a #GstRTSPStream
|
2018-02-09 23:07:25 +00:00
|
|
|
* @control: (nullable): a control string
|
2013-07-02 12:44:35 +00:00
|
|
|
*
|
|
|
|
* Set the control string in @stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_control (GstRTSPStream * stream, const gchar * control)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
g_free (priv->control);
|
|
|
|
priv->control = g_strdup (control);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
2013-07-03 13:13:45 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_has_control:
|
|
|
|
* @stream: a #GstRTSPStream
|
2018-02-09 23:07:25 +00:00
|
|
|
* @control: (nullable): a control string
|
2013-07-03 13:13:45 +00:00
|
|
|
*
|
|
|
|
* Check if @stream has the control string @control.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE is @stream has @control as the control string
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_has_control (GstRTSPStream * stream, const gchar * control)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (priv->control)
|
2013-10-01 11:15:19 +00:00
|
|
|
res = (g_strcmp0 (priv->control, control) == 0);
|
2013-07-03 13:13:45 +00:00
|
|
|
else {
|
|
|
|
guint streamid;
|
2013-12-19 13:26:34 +00:00
|
|
|
|
|
|
|
if (sscanf (control, "stream=%u", &streamid) > 0)
|
|
|
|
res = (streamid == priv->idx);
|
|
|
|
else
|
|
|
|
res = FALSE;
|
2013-07-03 13:13:45 +00:00
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-10-26 10:04:02 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_mtu:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @mtu: a new MTU
|
|
|
|
*
|
|
|
|
* Configure the mtu in the payloader of @stream to @mtu.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_mtu (GstRTSPStream * stream, guint mtu)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
2012-10-26 10:04:02 +00:00
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
2012-11-15 15:15:20 +00:00
|
|
|
GST_LOG_OBJECT (stream, "set MTU %u", mtu);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_object_set (G_OBJECT (priv->payloader), "mtu", mtu, NULL);
|
2012-10-26 10:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_mtu:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the configured MTU in the payloader of @stream.
|
|
|
|
*
|
|
|
|
* Returns: the MTU of the payloader.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_stream_get_mtu (GstRTSPStream * stream)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-26 10:04:02 +00:00
|
|
|
guint mtu;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (priv->payloader), "mtu", &mtu, NULL);
|
2012-10-26 10:04:02 +00:00
|
|
|
|
|
|
|
return mtu;
|
|
|
|
}
|
|
|
|
|
2013-06-24 08:43:59 +00:00
|
|
|
/* Update the dscp qos property on the udp sinks */
|
|
|
|
static void
|
2017-10-17 08:44:33 +00:00
|
|
|
update_dscp_qos (GstRTSPStream * stream, GstElement ** udpsink)
|
2013-06-24 08:43:59 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if (*udpsink) {
|
|
|
|
g_object_set (G_OBJECT (*udpsink), "qos-dscp", priv->dscp_qos, NULL);
|
2013-06-24 08:43:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_dscp_qos:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @dscp_qos: a new dscp qos value (0-63, or -1 to disable)
|
|
|
|
*
|
|
|
|
* Configure the dscp qos of the outgoing sockets to @dscp_qos.
|
|
|
|
*/
|
|
|
|
void
|
2013-06-24 18:41:27 +00:00
|
|
|
gst_rtsp_stream_set_dscp_qos (GstRTSPStream * stream, gint dscp_qos)
|
2013-06-24 08:43:59 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (stream, "set DSCP QoS %d", dscp_qos);
|
|
|
|
|
|
|
|
if (dscp_qos < -1 || dscp_qos > 63) {
|
|
|
|
GST_WARNING_OBJECT (stream, "trying to set illegal dscp qos %d", dscp_qos);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->dscp_qos = dscp_qos;
|
|
|
|
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
update_dscp_qos (stream, priv->udpsink);
|
2013-06-24 08:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_dscp_qos:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the configured DSCP QoS in of the outgoing sockets.
|
|
|
|
*
|
|
|
|
* Returns: the DSCP QoS value of the outgoing sockets, or -1 if disbled.
|
|
|
|
*/
|
|
|
|
gint
|
2013-06-24 18:41:27 +00:00
|
|
|
gst_rtsp_stream_get_dscp_qos (GstRTSPStream * stream)
|
2013-06-24 08:43:59 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
return priv->dscp_qos;
|
|
|
|
}
|
|
|
|
|
2014-01-07 11:14:15 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_is_transport_supported:
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-03-23 20:24:48 +00:00
|
|
|
* @transport: (transfer none): a #GstRTSPTransport
|
2014-01-07 11:14:15 +00:00
|
|
|
*
|
|
|
|
* Check if @transport can be handled by stream
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @transport can be handled by @stream.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_is_transport_supported (GstRTSPStream * stream,
|
|
|
|
GstRTSPTransport * transport)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
2014-01-07 14:28:05 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
2018-02-09 23:07:25 +00:00
|
|
|
g_return_val_if_fail (transport != NULL, FALSE);
|
2014-01-07 11:14:15 +00:00
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (transport->trans != GST_RTSP_TRANS_RTP)
|
|
|
|
goto unsupported_transmode;
|
|
|
|
|
2014-01-07 11:21:09 +00:00
|
|
|
if (!(transport->profile & priv->profiles))
|
2014-01-07 11:14:15 +00:00
|
|
|
goto unsupported_profile;
|
|
|
|
|
2018-03-21 09:56:51 +00:00
|
|
|
if (!(transport->lower_transport & priv->allowed_protocols))
|
2014-01-07 11:14:15 +00:00
|
|
|
goto unsupported_ltrans;
|
|
|
|
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
unsupported_transmode:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("unsupported transport mode %d", transport->trans);
|
2014-03-03 11:17:48 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2014-01-07 11:14:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
unsupported_profile:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("unsupported profile %d", transport->profile);
|
2014-03-03 11:17:48 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2014-01-07 11:14:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
unsupported_ltrans:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("unsupported lower transport %d", transport->lower_transport);
|
2014-03-03 11:17:48 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2014-01-07 11:14:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-07 11:21:09 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_profiles:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @profiles: the new profiles
|
|
|
|
*
|
|
|
|
* Configure the allowed profiles for @stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_profiles (GstRTSPStream * stream, GstRTSPProfile profiles)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->profiles = profiles;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_profiles:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the allowed profiles of @stream.
|
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPProfile
|
|
|
|
*/
|
|
|
|
GstRTSPProfile
|
|
|
|
gst_rtsp_stream_get_profiles (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstRTSPProfile res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_RTSP_PROFILE_UNKNOWN);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
res = priv->profiles;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-08-16 14:08:43 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_protocols:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @protocols: the new flags
|
|
|
|
*
|
|
|
|
* Configure the allowed lower transport for @stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_protocols (GstRTSPStream * stream,
|
|
|
|
GstRTSPLowerTrans protocols)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2018-03-21 09:56:51 +00:00
|
|
|
priv->allowed_protocols = protocols;
|
2013-08-16 14:08:43 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_protocols:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the allowed protocols of @stream.
|
|
|
|
*
|
|
|
|
* Returns: a #GstRTSPLowerTrans
|
|
|
|
*/
|
|
|
|
GstRTSPLowerTrans
|
|
|
|
gst_rtsp_stream_get_protocols (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstRTSPLowerTrans res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream),
|
|
|
|
GST_RTSP_LOWER_TRANS_UNKNOWN);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2018-03-21 09:56:51 +00:00
|
|
|
res = priv->allowed_protocols;
|
2013-08-16 14:08:43 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2013-06-24 08:43:59 +00:00
|
|
|
|
2012-11-15 14:36:21 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_address_pool:
|
|
|
|
* @stream: a #GstRTSPStream
|
2018-02-09 23:07:25 +00:00
|
|
|
* @pool: (transfer none) (nullable): a #GstRTSPAddressPool
|
2012-11-15 14:36:21 +00:00
|
|
|
*
|
|
|
|
* configure @pool to be used as the address pool of @stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_address_pool (GstRTSPStream * stream,
|
|
|
|
GstRTSPAddressPool * pool)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-11-15 14:36:21 +00:00
|
|
|
GstRTSPAddressPool *old;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
2012-11-15 15:15:20 +00:00
|
|
|
GST_LOG_OBJECT (stream, "set address pool %p", pool);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((old = priv->pool) != pool)
|
|
|
|
priv->pool = pool ? g_object_ref (pool) : NULL;
|
2012-11-15 14:36:21 +00:00
|
|
|
else
|
|
|
|
old = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-15 14:36:21 +00:00
|
|
|
|
|
|
|
if (old)
|
|
|
|
g_object_unref (old);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_address_pool:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the #GstRTSPAddressPool used as the address pool of @stream.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the #GstRTSPAddressPool of @stream.
|
|
|
|
* g_object_unref() after usage.
|
2012-11-15 14:36:21 +00:00
|
|
|
*/
|
|
|
|
GstRTSPAddressPool *
|
|
|
|
gst_rtsp_stream_get_address_pool (GstRTSPStream * stream)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-11-15 14:36:21 +00:00
|
|
|
GstRTSPAddressPool *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->pool))
|
2012-11-15 14:36:21 +00:00
|
|
|
g_object_ref (result);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-15 14:36:21 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-02 17:42:13 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_multicast_iface:
|
|
|
|
* @stream: a #GstRTSPStream
|
2018-02-09 23:07:25 +00:00
|
|
|
* @multicast_iface: (transfer none) (nullable): a multicast interface name
|
2016-03-02 17:42:13 +00:00
|
|
|
*
|
|
|
|
* configure @multicast_iface to be used for @stream.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_multicast_iface (GstRTSPStream * stream,
|
|
|
|
const gchar * multicast_iface)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gchar *old;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (stream, "set multicast iface %s",
|
|
|
|
GST_STR_NULL (multicast_iface));
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((old = priv->multicast_iface) != multicast_iface)
|
|
|
|
priv->multicast_iface = multicast_iface ? g_strdup (multicast_iface) : NULL;
|
|
|
|
else
|
|
|
|
old = NULL;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
if (old)
|
|
|
|
g_free (old);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_multicast_iface:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the multicast interface used for @stream.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the multicast interface for @stream.
|
|
|
|
* g_free() after usage.
|
2016-03-02 17:42:13 +00:00
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gst_rtsp_stream_get_multicast_iface (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gchar *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->multicast_iface))
|
|
|
|
result = g_strdup (result);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-09-07 15:44:34 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_multicast_address:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @family: the #GSocketFamily
|
|
|
|
*
|
|
|
|
* Get the multicast address of @stream for @family. The original
|
|
|
|
* #GstRTSPAddress is cached and copy is returned, so freeing the return value
|
|
|
|
* won't release the address from the pool.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): the #GstRTSPAddress of @stream
|
|
|
|
* or %NULL when no address could be allocated. gst_rtsp_address_free()
|
|
|
|
* after usage.
|
|
|
|
*/
|
|
|
|
GstRTSPAddress *
|
|
|
|
gst_rtsp_stream_get_multicast_address (GstRTSPStream * stream,
|
2013-07-01 14:46:07 +00:00
|
|
|
GSocketFamily family)
|
2012-11-15 14:36:21 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-11-15 14:36:21 +00:00
|
|
|
GstRTSPAddress *result;
|
2013-07-01 14:46:07 +00:00
|
|
|
GstRTSPAddress **addrp;
|
|
|
|
GstRTSPAddressFlags flags;
|
2012-11-15 14:36:21 +00:00
|
|
|
|
2016-09-07 15:44:34 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
2016-09-07 15:44:34 +00:00
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
|
2013-07-01 14:46:07 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV6) {
|
|
|
|
flags = GST_RTSP_ADDRESS_FLAG_IPV6;
|
2016-07-20 19:35:44 +00:00
|
|
|
addrp = &priv->mcast_addr_v6;
|
2013-07-01 14:46:07 +00:00
|
|
|
} else {
|
|
|
|
flags = GST_RTSP_ADDRESS_FLAG_IPV4;
|
2016-07-20 19:35:44 +00:00
|
|
|
addrp = &priv->mcast_addr_v4;
|
2013-07-01 14:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*addrp == NULL) {
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->pool == NULL)
|
2012-11-15 14:36:21 +00:00
|
|
|
goto no_pool;
|
|
|
|
|
2013-07-01 14:46:07 +00:00
|
|
|
flags |= GST_RTSP_ADDRESS_FLAG_EVEN_PORT | GST_RTSP_ADDRESS_FLAG_MULTICAST;
|
|
|
|
|
|
|
|
*addrp = gst_rtsp_address_pool_acquire_address (priv->pool, flags, 2);
|
|
|
|
if (*addrp == NULL)
|
2012-11-15 14:36:21 +00:00
|
|
|
goto no_address;
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
|
|
|
/* FIXME: Also reserve the same port with unicast ANY address, since that's
|
|
|
|
* where we are going to bind our socket. Probably loop until we find a port
|
|
|
|
* available in both mcast and unicast pools. Maybe GstRTSPAddressPool
|
|
|
|
* should do it for us when both GST_RTSP_ADDRESS_FLAG_MULTICAST and
|
|
|
|
* GST_RTSP_ADDRESS_FLAG_UNICAST are givent. */
|
2012-11-15 14:36:21 +00:00
|
|
|
}
|
2013-07-01 14:46:07 +00:00
|
|
|
result = gst_rtsp_address_copy (*addrp);
|
2012-11-15 14:36:21 +00:00
|
|
|
|
2016-09-07 15:44:34 +00:00
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
2012-11-15 14:36:21 +00:00
|
|
|
return result;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_pool:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "no address pool specified");
|
2016-09-07 15:44:34 +00:00
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
2012-11-15 14:36:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
no_address:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "failed to acquire address from pool");
|
2016-09-07 15:44:34 +00:00
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
2012-11-15 14:36:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 23:32:20 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_reserve_address:
|
|
|
|
* @stream: a #GstRTSPStream
|
2013-07-01 10:20:50 +00:00
|
|
|
* @address: an address
|
|
|
|
* @port: a port
|
|
|
|
* @n_ports: n_ports
|
|
|
|
* @ttl: a TTL
|
2013-02-13 23:32:20 +00:00
|
|
|
*
|
2016-07-21 03:05:09 +00:00
|
|
|
* Reserve @address and @port as the address and port of @stream. The original
|
|
|
|
* #GstRTSPAddress is cached and copy is returned, so freeing the return value
|
|
|
|
* won't release the address from the pool.
|
2013-02-13 23:32:20 +00:00
|
|
|
*
|
2014-06-11 23:38:36 +00:00
|
|
|
* Returns: (nullable): the #GstRTSPAddress of @stream or %NULL when
|
2019-01-29 13:42:35 +00:00
|
|
|
* the address could not be reserved. gst_rtsp_address_free() after
|
|
|
|
* usage.
|
2013-02-13 23:32:20 +00:00
|
|
|
*/
|
|
|
|
GstRTSPAddress *
|
|
|
|
gst_rtsp_stream_reserve_address (GstRTSPStream * stream,
|
|
|
|
const gchar * address, guint port, guint n_ports, guint ttl)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstRTSPAddress *result;
|
2013-07-01 14:46:07 +00:00
|
|
|
GInetAddress *addr;
|
|
|
|
GSocketFamily family;
|
|
|
|
GstRTSPAddress **addrp;
|
2013-02-13 23:32:20 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
g_return_val_if_fail (address != NULL, NULL);
|
|
|
|
g_return_val_if_fail (port > 0, NULL);
|
|
|
|
g_return_val_if_fail (n_ports > 0, NULL);
|
|
|
|
g_return_val_if_fail (ttl > 0, NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
2013-07-01 14:46:07 +00:00
|
|
|
addr = g_inet_address_new_from_string (address);
|
|
|
|
if (!addr) {
|
|
|
|
GST_ERROR ("failed to get inet addr from %s", address);
|
|
|
|
family = G_SOCKET_FAMILY_IPV4;
|
|
|
|
} else {
|
|
|
|
family = g_inet_address_get_family (addr);
|
|
|
|
g_object_unref (addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
2016-07-20 19:35:44 +00:00
|
|
|
addrp = &priv->mcast_addr_v6;
|
2014-03-14 18:03:24 +00:00
|
|
|
else
|
2016-07-20 19:35:44 +00:00
|
|
|
addrp = &priv->mcast_addr_v4;
|
2013-07-01 14:46:07 +00:00
|
|
|
|
2013-02-13 23:32:20 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-07-01 14:46:07 +00:00
|
|
|
if (*addrp == NULL) {
|
2013-09-24 15:30:18 +00:00
|
|
|
GstRTSPAddressPoolResult res;
|
|
|
|
|
2013-02-13 23:32:20 +00:00
|
|
|
if (priv->pool == NULL)
|
|
|
|
goto no_pool;
|
|
|
|
|
2013-09-24 15:30:18 +00:00
|
|
|
res = gst_rtsp_address_pool_reserve_address (priv->pool, address,
|
|
|
|
port, n_ports, ttl, addrp);
|
|
|
|
if (res != GST_RTSP_ADDRESS_POOL_OK)
|
2013-02-13 23:32:20 +00:00
|
|
|
goto no_address;
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
|
|
|
/* FIXME: Also reserve the same port with unicast ANY address, since that's
|
|
|
|
* where we are going to bind our socket. */
|
2013-02-13 23:32:20 +00:00
|
|
|
} else {
|
2016-09-06 16:15:23 +00:00
|
|
|
if (g_ascii_strcasecmp ((*addrp)->address, address) ||
|
2013-07-01 14:46:07 +00:00
|
|
|
(*addrp)->port != port || (*addrp)->n_ports != n_ports ||
|
|
|
|
(*addrp)->ttl != ttl)
|
2013-02-13 23:32:20 +00:00
|
|
|
goto different_address;
|
|
|
|
}
|
2013-07-01 14:46:07 +00:00
|
|
|
result = gst_rtsp_address_copy (*addrp);
|
2013-02-13 23:32:20 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_pool:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "no address pool specified");
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
no_address:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "failed to acquire address %s from pool",
|
|
|
|
address);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
different_address:
|
|
|
|
{
|
2016-09-06 16:15:23 +00:00
|
|
|
GST_ERROR_OBJECT (stream,
|
2016-09-07 14:21:09 +00:00
|
|
|
"address %s is not the same as %s that was already reserved",
|
2016-09-06 16:15:23 +00:00
|
|
|
address, (*addrp)->address);
|
2013-02-13 23:32:20 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-20 07:38:42 +00:00
|
|
|
/* must be called with lock */
|
2015-11-20 13:43:38 +00:00
|
|
|
static void
|
2017-10-17 08:44:33 +00:00
|
|
|
set_socket_for_udpsink (GstElement * udpsink, GSocket * socket,
|
|
|
|
GSocketFamily family)
|
2015-11-20 07:38:42 +00:00
|
|
|
{
|
|
|
|
const gchar *multisink_socket;
|
|
|
|
|
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
|
|
|
multisink_socket = "socket-v6";
|
|
|
|
else
|
|
|
|
multisink_socket = "socket";
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
g_object_set (G_OBJECT (udpsink), multisink_socket, socket, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called with lock */
|
|
|
|
static void
|
|
|
|
set_multicast_socket_for_udpsink (GstElement * udpsink, GSocket * socket,
|
|
|
|
GSocketFamily family, const gchar * multicast_iface,
|
2017-12-19 09:34:37 +00:00
|
|
|
const gchar * addr_str, gint port, gint mcast_ttl)
|
2017-10-17 08:44:33 +00:00
|
|
|
{
|
|
|
|
set_socket_for_udpsink (udpsink, socket, family);
|
|
|
|
|
|
|
|
if (multicast_iface) {
|
2017-12-19 09:34:37 +00:00
|
|
|
GST_INFO ("setting multicast-iface %s", multicast_iface);
|
2017-11-21 08:53:08 +00:00
|
|
|
g_object_set (G_OBJECT (udpsink), "multicast-iface", multicast_iface, NULL);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 09:34:37 +00:00
|
|
|
if (mcast_ttl > 0) {
|
|
|
|
GST_INFO ("setting ttl-mc %d", mcast_ttl);
|
|
|
|
g_object_set (G_OBJECT (udpsink), "ttl-mc", mcast_ttl, NULL);
|
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* must be called with lock */
|
|
|
|
static void
|
|
|
|
set_unicast_socket_for_udpsink (GstElement * udpsink, GSocket * socket,
|
|
|
|
GSocketFamily family)
|
|
|
|
{
|
|
|
|
set_socket_for_udpsink (udpsink, socket, family);
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint16
|
|
|
|
get_port_from_socket (GSocket * socket)
|
|
|
|
{
|
|
|
|
guint16 port;
|
|
|
|
GSocketAddress *sockaddr;
|
|
|
|
GError *err;
|
|
|
|
|
|
|
|
GST_DEBUG ("socket: %p", socket);
|
|
|
|
sockaddr = g_socket_get_local_address (socket, &err);
|
|
|
|
if (sockaddr == NULL || !G_IS_INET_SOCKET_ADDRESS (sockaddr)) {
|
|
|
|
g_clear_object (&sockaddr);
|
|
|
|
GST_ERROR ("failed to get sockaddr: %s", err->message);
|
|
|
|
g_error_free (err);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
port = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (sockaddr));
|
|
|
|
g_object_unref (sockaddr);
|
|
|
|
|
|
|
|
return port;
|
2015-11-20 13:43:38 +00:00
|
|
|
}
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
|
2015-11-20 13:43:38 +00:00
|
|
|
static gboolean
|
2017-10-17 08:44:33 +00:00
|
|
|
create_and_configure_udpsink (GstRTSPStream * stream, GstElement ** udpsink,
|
2017-11-21 08:53:08 +00:00
|
|
|
GSocket * socket_v4, GSocket * socket_v6, gboolean multicast,
|
2017-12-19 09:34:37 +00:00
|
|
|
gboolean is_rtp, gint mcast_ttl)
|
2015-11-20 13:43:38 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
*udpsink = gst_element_factory_make ("multiudpsink", NULL);
|
2015-11-20 07:38:42 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if (!*udpsink)
|
2015-11-20 07:38:42 +00:00
|
|
|
goto no_udp_protocol;
|
|
|
|
|
|
|
|
/* configure sinks */
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
g_object_set (G_OBJECT (*udpsink), "close-socket", FALSE, NULL);
|
2015-11-20 07:38:42 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
g_object_set (G_OBJECT (*udpsink), "send-duplicates", FALSE, NULL);
|
2015-11-20 07:38:42 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if (is_rtp)
|
|
|
|
g_object_set (G_OBJECT (*udpsink), "buffer-size", priv->buffer_size, NULL);
|
|
|
|
else
|
|
|
|
g_object_set (G_OBJECT (*udpsink), "sync", FALSE, NULL);
|
2015-11-20 07:38:42 +00:00
|
|
|
|
|
|
|
/* Needs to be async for RECORD streams, otherwise we will never go to
|
|
|
|
* PLAYING because the sinks will wait for data while the udpsrc can't
|
|
|
|
* provide data with timestamps in PAUSED. */
|
2017-10-17 08:44:33 +00:00
|
|
|
if (!is_rtp || priv->sinkpad)
|
|
|
|
g_object_set (G_OBJECT (*udpsink), "async", FALSE, NULL);
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if (multicast) {
|
|
|
|
/* join multicast group when adding clients, so we'll start receiving from it.
|
|
|
|
* We cannot rely on the udpsrc to join the group since its socket is always a
|
|
|
|
* local unicast one. */
|
|
|
|
g_object_set (G_OBJECT (*udpsink), "auto-multicast", TRUE, NULL);
|
2015-11-20 07:38:42 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
g_object_set (G_OBJECT (*udpsink), "loop", FALSE, NULL);
|
|
|
|
}
|
2015-11-20 07:38:42 +00:00
|
|
|
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
/* update the dscp qos field in the sinks */
|
|
|
|
update_dscp_qos (stream, udpsink);
|
2015-11-20 07:38:42 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if (priv->server_addr_v4) {
|
2017-11-21 08:53:08 +00:00
|
|
|
GST_DEBUG_OBJECT (stream, "udp IPv4, configure udpsinks");
|
|
|
|
set_unicast_socket_for_udpsink (*udpsink, socket_v4, G_SOCKET_FAMILY_IPV4);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->server_addr_v6) {
|
2017-11-21 08:53:08 +00:00
|
|
|
GST_DEBUG_OBJECT (stream, "udp IPv6, configure udpsinks");
|
|
|
|
set_unicast_socket_for_udpsink (*udpsink, socket_v6, G_SOCKET_FAMILY_IPV6);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (multicast) {
|
|
|
|
gint port;
|
|
|
|
if (priv->mcast_addr_v4) {
|
|
|
|
GST_DEBUG_OBJECT (stream, "mcast IPv4, configure udpsinks");
|
|
|
|
port = get_port_from_socket (socket_v4);
|
|
|
|
if (!port)
|
|
|
|
goto get_port_failed;
|
|
|
|
set_multicast_socket_for_udpsink (*udpsink, socket_v4,
|
2017-11-21 08:53:08 +00:00
|
|
|
G_SOCKET_FAMILY_IPV4, priv->multicast_iface,
|
2017-12-19 09:34:37 +00:00
|
|
|
priv->mcast_addr_v4->address, port, mcast_ttl);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->mcast_addr_v6) {
|
|
|
|
GST_DEBUG_OBJECT (stream, "mcast IPv6, configure udpsinks");
|
|
|
|
port = get_port_from_socket (socket_v6);
|
|
|
|
if (!port)
|
|
|
|
goto get_port_failed;
|
|
|
|
set_multicast_socket_for_udpsink (*udpsink, socket_v6,
|
2017-11-21 08:53:08 +00:00
|
|
|
G_SOCKET_FAMILY_IPV6, priv->multicast_iface,
|
2017-12-19 09:34:37 +00:00
|
|
|
priv->mcast_addr_v6->address, port, mcast_ttl);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-20 07:38:42 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_udp_protocol:
|
|
|
|
{
|
2017-10-17 08:44:33 +00:00
|
|
|
GST_ERROR_OBJECT (stream, "failed to create udpsink element");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
get_port_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "failed to get udp port");
|
2015-11-20 07:38:42 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-20 14:34:43 +00:00
|
|
|
/* must be called with lock */
|
|
|
|
static gboolean
|
2017-11-21 08:53:08 +00:00
|
|
|
create_and_configure_udpsource (GstElement ** udpsrc, GSocket * socket)
|
2015-11-20 14:34:43 +00:00
|
|
|
{
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
g_assert (socket != NULL);
|
2015-11-20 14:34:43 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
*udpsrc = gst_element_factory_make ("udpsrc", NULL);
|
|
|
|
if (*udpsrc == NULL)
|
2015-11-20 14:34:43 +00:00
|
|
|
goto error;
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
g_object_set (G_OBJECT (*udpsrc), "socket", socket, NULL);
|
2015-11-20 14:34:43 +00:00
|
|
|
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
/* The udpsrc cannot do the join because its socket is always a local unicast
|
|
|
|
* one. The udpsink sharing the same socket will do it for us. */
|
2017-10-17 08:44:33 +00:00
|
|
|
g_object_set (G_OBJECT (*udpsrc), "auto-multicast", FALSE, NULL);
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
g_object_set (G_OBJECT (*udpsrc), "loop", FALSE, NULL);
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
g_object_set (G_OBJECT (*udpsrc), "close-socket", FALSE, NULL);
|
2016-11-21 12:05:50 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
ret = gst_element_set_state (*udpsrc, GST_STATE_READY);
|
2015-11-20 14:34:43 +00:00
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error:
|
|
|
|
{
|
2017-10-17 08:44:33 +00:00
|
|
|
if (*udpsrc) {
|
|
|
|
gst_element_set_state (*udpsrc, GST_STATE_NULL);
|
|
|
|
g_clear_object (udpsrc);
|
2016-07-21 03:18:23 +00:00
|
|
|
}
|
2015-11-20 14:34:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
static gboolean
|
2015-11-20 07:38:42 +00:00
|
|
|
alloc_ports_one_family (GstRTSPStream * stream, GSocketFamily family,
|
2017-11-21 08:53:08 +00:00
|
|
|
GSocket * socket_out[2], GstRTSPAddress ** server_addr_out,
|
2018-02-23 13:34:32 +00:00
|
|
|
gboolean multicast, GstRTSPTransport * ct, gboolean use_transport_settings)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
2015-01-09 11:40:47 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2013-02-19 23:27:20 +00:00
|
|
|
GSocket *rtp_socket = NULL;
|
2018-02-23 13:34:32 +00:00
|
|
|
GSocket *rtcp_socket = NULL;
|
2012-10-25 19:29:58 +00:00
|
|
|
gint tmp_rtp, tmp_rtcp;
|
|
|
|
guint count;
|
2013-02-19 23:27:20 +00:00
|
|
|
GList *rejected_addresses = NULL;
|
|
|
|
GstRTSPAddress *addr = NULL;
|
|
|
|
GInetAddress *inetaddr = NULL;
|
|
|
|
GSocketAddress *rtp_sockaddr = NULL;
|
|
|
|
GSocketAddress *rtcp_sockaddr = NULL;
|
2016-03-02 09:48:49 +00:00
|
|
|
GstRTSPAddressPool *pool;
|
2018-02-23 13:34:32 +00:00
|
|
|
gboolean transport_settings_defined = FALSE;
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
2015-11-20 07:38:42 +00:00
|
|
|
pool = priv->pool;
|
2012-10-25 19:29:58 +00:00
|
|
|
count = 0;
|
|
|
|
|
|
|
|
/* Start with random port */
|
|
|
|
tmp_rtp = 0;
|
2020-09-04 19:14:35 +00:00
|
|
|
tmp_rtcp = 0;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2018-02-23 13:34:32 +00:00
|
|
|
if (use_transport_settings) {
|
|
|
|
if (!multicast)
|
|
|
|
goto no_mcast;
|
|
|
|
|
|
|
|
if (ct == NULL)
|
|
|
|
goto no_transport;
|
|
|
|
|
|
|
|
/* multicast and transport specific case */
|
|
|
|
if (ct->destination != NULL) {
|
|
|
|
tmp_rtp = ct->port.min;
|
|
|
|
tmp_rtcp = ct->port.max;
|
2018-09-06 14:17:33 +00:00
|
|
|
|
|
|
|
/* check if the provided address is a multicast address */
|
2018-02-23 13:34:32 +00:00
|
|
|
inetaddr = g_inet_address_new_from_string (ct->destination);
|
|
|
|
if (inetaddr == NULL)
|
|
|
|
goto destination_error;
|
|
|
|
if (!g_inet_address_get_is_multicast (inetaddr))
|
|
|
|
goto destination_no_mcast;
|
2018-09-06 14:17:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (!priv->bind_mcast_address) {
|
|
|
|
g_clear_object (&inetaddr);
|
|
|
|
inetaddr = g_inet_address_new_any (family);
|
|
|
|
}
|
2018-02-23 13:34:32 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "use transport settings");
|
|
|
|
transport_settings_defined = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-04 19:14:35 +00:00
|
|
|
if (priv->enable_rtcp) {
|
|
|
|
rtcp_socket = g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
|
|
|
|
G_SOCKET_PROTOCOL_UDP, NULL);
|
|
|
|
if (!rtcp_socket)
|
|
|
|
goto no_udp_protocol;
|
|
|
|
g_socket_set_multicast_loopback (rtcp_socket, FALSE);
|
|
|
|
}
|
2013-02-19 23:27:20 +00:00
|
|
|
|
2020-09-04 19:14:35 +00:00
|
|
|
/* try to allocate UDP ports, the RTP port should be an even
|
|
|
|
* number and the RTCP port (if enabled) should be the next (uneven) port */
|
2012-10-25 19:29:58 +00:00
|
|
|
again:
|
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
if (rtp_socket == NULL) {
|
|
|
|
rtp_socket = g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
|
|
|
|
G_SOCKET_PROTOCOL_UDP, NULL);
|
|
|
|
if (!rtp_socket)
|
|
|
|
goto no_udp_protocol;
|
2016-03-05 08:52:11 +00:00
|
|
|
g_socket_set_multicast_loopback (rtp_socket, FALSE);
|
2013-02-19 23:27:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 13:34:32 +00:00
|
|
|
if (!transport_settings_defined) {
|
|
|
|
if ((pool && gst_rtsp_address_pool_has_unicast_addresses (pool))
|
|
|
|
|| multicast) {
|
|
|
|
GstRTSPAddressFlags flags;
|
2016-02-23 13:59:32 +00:00
|
|
|
|
2022-09-02 13:31:54 +00:00
|
|
|
if (addr) {
|
|
|
|
g_assert (*server_addr_out == NULL);
|
2018-02-23 13:34:32 +00:00
|
|
|
rejected_addresses = g_list_prepend (rejected_addresses, addr);
|
2022-09-02 13:31:54 +00:00
|
|
|
}
|
2013-02-19 23:27:20 +00:00
|
|
|
|
2018-02-23 13:34:32 +00:00
|
|
|
if (!pool)
|
|
|
|
goto no_pool;
|
2016-09-05 15:04:50 +00:00
|
|
|
|
2018-02-23 13:34:32 +00:00
|
|
|
flags = GST_RTSP_ADDRESS_FLAG_EVEN_PORT;
|
|
|
|
if (multicast)
|
|
|
|
flags |= GST_RTSP_ADDRESS_FLAG_MULTICAST;
|
|
|
|
else
|
|
|
|
flags |= GST_RTSP_ADDRESS_FLAG_UNICAST;
|
2016-09-05 15:04:50 +00:00
|
|
|
|
2018-02-23 13:34:32 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
|
|
|
flags |= GST_RTSP_ADDRESS_FLAG_IPV6;
|
|
|
|
else
|
|
|
|
flags |= GST_RTSP_ADDRESS_FLAG_IPV4;
|
2013-02-19 23:27:20 +00:00
|
|
|
|
2019-01-29 13:42:35 +00:00
|
|
|
if (*server_addr_out)
|
|
|
|
addr = *server_addr_out;
|
|
|
|
else
|
2020-09-04 19:14:35 +00:00
|
|
|
addr = gst_rtsp_address_pool_acquire_address (pool, flags,
|
|
|
|
priv->enable_rtcp ? 2 : 1);
|
2013-02-19 23:27:20 +00:00
|
|
|
|
2018-02-23 13:34:32 +00:00
|
|
|
if (addr == NULL)
|
|
|
|
goto no_address;
|
2013-02-19 23:27:20 +00:00
|
|
|
|
2018-02-23 13:34:32 +00:00
|
|
|
tmp_rtp = addr->port;
|
2013-02-19 23:27:20 +00:00
|
|
|
|
2018-02-23 13:34:32 +00:00
|
|
|
g_clear_object (&inetaddr);
|
|
|
|
/* FIXME: Does it really work with the IP_MULTICAST_ALL socket option and
|
|
|
|
* socket control message set in udpsrc? */
|
2018-09-06 14:17:33 +00:00
|
|
|
if (priv->bind_mcast_address || !multicast)
|
2018-02-23 13:34:32 +00:00
|
|
|
inetaddr = g_inet_address_new_from_string (addr->address);
|
2018-09-06 14:17:33 +00:00
|
|
|
else
|
|
|
|
inetaddr = g_inet_address_new_any (family);
|
2018-02-23 13:34:32 +00:00
|
|
|
} else {
|
|
|
|
if (tmp_rtp != 0) {
|
|
|
|
tmp_rtp += 2;
|
|
|
|
if (++count > 20)
|
|
|
|
goto no_ports;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inetaddr == NULL)
|
|
|
|
inetaddr = g_inet_address_new_any (family);
|
2013-02-19 23:27:20 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
rtp_sockaddr = g_inet_socket_address_new (inetaddr, tmp_rtp);
|
|
|
|
if (!g_socket_bind (rtp_socket, rtp_sockaddr, FALSE, NULL)) {
|
2017-10-17 08:44:33 +00:00
|
|
|
GST_DEBUG_OBJECT (stream, "rtp bind() failed, will try again");
|
2013-02-19 23:27:20 +00:00
|
|
|
g_object_unref (rtp_sockaddr);
|
2022-09-02 13:31:54 +00:00
|
|
|
if (transport_settings_defined) {
|
2018-02-23 13:34:32 +00:00
|
|
|
goto transport_settings_error;
|
2022-09-02 13:31:54 +00:00
|
|
|
} else if (*server_addr_out && ((pool
|
|
|
|
&& gst_rtsp_address_pool_has_unicast_addresses (pool))
|
|
|
|
|| multicast)) {
|
|
|
|
goto no_address;
|
|
|
|
} else {
|
|
|
|
goto again;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2013-02-19 23:27:20 +00:00
|
|
|
g_object_unref (rtp_sockaddr);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
rtp_sockaddr = g_socket_get_local_address (rtp_socket, NULL);
|
|
|
|
if (rtp_sockaddr == NULL || !G_IS_INET_SOCKET_ADDRESS (rtp_sockaddr)) {
|
|
|
|
g_clear_object (&rtp_sockaddr);
|
|
|
|
goto socket_error;
|
|
|
|
}
|
|
|
|
|
2018-02-23 13:34:32 +00:00
|
|
|
if (!transport_settings_defined) {
|
|
|
|
tmp_rtp =
|
|
|
|
g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (rtp_sockaddr));
|
|
|
|
|
|
|
|
/* check if port is even. RFC 3550 encorages the use of an even/odd port
|
|
|
|
* pair, however it's not a strict requirement so this check is not done
|
|
|
|
* for the client selected ports. */
|
|
|
|
if ((tmp_rtp & 1) != 0) {
|
|
|
|
/* port not even, close and allocate another */
|
|
|
|
tmp_rtp++;
|
|
|
|
g_object_unref (rtp_sockaddr);
|
|
|
|
g_clear_object (&rtp_socket);
|
|
|
|
goto again;
|
|
|
|
}
|
2018-08-14 11:25:37 +00:00
|
|
|
}
|
2018-02-23 13:34:32 +00:00
|
|
|
g_object_unref (rtp_sockaddr);
|
2018-08-14 11:25:37 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/* set port */
|
2020-09-04 19:14:35 +00:00
|
|
|
if (priv->enable_rtcp) {
|
|
|
|
tmp_rtcp = tmp_rtp + 1;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2020-09-04 19:14:35 +00:00
|
|
|
rtcp_sockaddr = g_inet_socket_address_new (inetaddr, tmp_rtcp);
|
|
|
|
if (!g_socket_bind (rtcp_socket, rtcp_sockaddr, FALSE, NULL)) {
|
|
|
|
GST_DEBUG_OBJECT (stream, "rctp bind() failed, will try again");
|
|
|
|
g_object_unref (rtcp_sockaddr);
|
|
|
|
g_clear_object (&rtp_socket);
|
|
|
|
if (transport_settings_defined)
|
|
|
|
goto transport_settings_error;
|
|
|
|
goto again;
|
|
|
|
}
|
2013-02-19 23:27:20 +00:00
|
|
|
g_object_unref (rtcp_sockaddr);
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2016-09-05 15:04:50 +00:00
|
|
|
if (!addr) {
|
2023-01-24 20:13:50 +00:00
|
|
|
addr = g_new0 (GstRTSPAddress, 1);
|
2016-09-05 15:04:50 +00:00
|
|
|
addr->port = tmp_rtp;
|
|
|
|
addr->n_ports = 2;
|
2018-02-23 13:34:32 +00:00
|
|
|
if (transport_settings_defined)
|
|
|
|
addr->address = g_strdup (ct->destination);
|
|
|
|
else
|
|
|
|
addr->address = g_inet_address_to_string (inetaddr);
|
|
|
|
addr->ttl = ct->ttl;
|
2016-09-05 15:04:50 +00:00
|
|
|
}
|
|
|
|
|
2013-02-19 23:27:20 +00:00
|
|
|
g_clear_object (&inetaddr);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2018-07-25 13:33:18 +00:00
|
|
|
if (multicast && (ct->ttl > 0) && (ct->ttl <= priv->max_mcast_ttl)) {
|
|
|
|
GST_DEBUG ("setting mcast ttl to %d", ct->ttl);
|
|
|
|
g_socket_set_multicast_ttl (rtp_socket, ct->ttl);
|
2020-09-04 19:14:35 +00:00
|
|
|
if (rtcp_socket)
|
|
|
|
g_socket_set_multicast_ttl (rtcp_socket, ct->ttl);
|
2018-07-25 13:33:18 +00:00
|
|
|
}
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
socket_out[0] = rtp_socket;
|
|
|
|
socket_out[1] = rtcp_socket;
|
2013-05-30 06:07:48 +00:00
|
|
|
*server_addr_out = addr;
|
2016-09-05 15:04:50 +00:00
|
|
|
|
2020-09-04 19:14:35 +00:00
|
|
|
if (priv->enable_rtcp) {
|
|
|
|
GST_DEBUG_OBJECT (stream, "allocated address: %s and ports: %d, %d",
|
|
|
|
addr->address, tmp_rtp, tmp_rtcp);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (stream, "allocated address: %s and port: %d",
|
|
|
|
addr->address, tmp_rtp);
|
|
|
|
}
|
2013-02-19 23:27:20 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
g_list_free_full (rejected_addresses, (GDestroyNotify) gst_rtsp_address_free);
|
2013-02-19 23:27:20 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2018-02-23 13:34:32 +00:00
|
|
|
no_mcast:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "failed to allocate UDP ports: wrong transport");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
no_transport:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "failed to allocate UDP ports: no transport");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
destination_error:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream,
|
|
|
|
"failed to allocate UDP ports: destination error");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
destination_no_mcast:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream,
|
|
|
|
"failed to allocate UDP ports: destination not multicast address");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
no_udp_protocol:
|
|
|
|
{
|
rtsp-client: always allocate both IPV4 and IPV6 sockets
multiudpsink does not support setting the socket* properties
after it has started, which meant that rtsp-server could no
longer serve on both IPV4 and IPV6 sockets since the patches
from https://bugzilla.gnome.org/show_bug.cgi?id=757488 were
merged.
When first connecting an IPV6 client then an IPV4 client,
multiudpsink fell back to using the IPV6 socket.
When first connecting an IPV4 client, then an IPV6 client,
multiudpsink errored out, released the IPV4 socket, then
crashed when trying to send a message on NULL nevertheless,
that is however a separate issue.
This could probably be fixed by handling the setting of
sockets in multiudpsink after it has started, that will
however be a much more significant effort.
For now, this commit simply partially reverts the behaviour
of rtsp-stream: it will continue to only create the udpsinks
when needed, as was the case since the patches were merged,
it will however when creating them, always allocate both
sockets and set them on the sink before it starts, as was
the case prior to the patches.
Transport configuration will only error out if the allocation
of UDP sockets fails for the actual client's family, this
also downgrades the GST_ERRORs in alloc_ports_one_family
to GST_WARNINGs, as failing to allocate is no longer
necessarily fatal.
https://bugzilla.gnome.org/show_bug.cgi?id=796875
2018-07-25 17:54:55 +00:00
|
|
|
GST_WARNING_OBJECT (stream, "failed to allocate UDP ports: protocol error");
|
2012-10-25 19:29:58 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
no_pool:
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
rtsp-client: always allocate both IPV4 and IPV6 sockets
multiudpsink does not support setting the socket* properties
after it has started, which meant that rtsp-server could no
longer serve on both IPV4 and IPV6 sockets since the patches
from https://bugzilla.gnome.org/show_bug.cgi?id=757488 were
merged.
When first connecting an IPV6 client then an IPV4 client,
multiudpsink fell back to using the IPV6 socket.
When first connecting an IPV4 client, then an IPV6 client,
multiudpsink errored out, released the IPV4 socket, then
crashed when trying to send a message on NULL nevertheless,
that is however a separate issue.
This could probably be fixed by handling the setting of
sockets in multiudpsink after it has started, that will
however be a much more significant effort.
For now, this commit simply partially reverts the behaviour
of rtsp-stream: it will continue to only create the udpsinks
when needed, as was the case since the patches were merged,
it will however when creating them, always allocate both
sockets and set them on the sink before it starts, as was
the case prior to the patches.
Transport configuration will only error out if the allocation
of UDP sockets fails for the actual client's family, this
also downgrades the GST_ERRORs in alloc_ports_one_family
to GST_WARNINGs, as failing to allocate is no longer
necessarily fatal.
https://bugzilla.gnome.org/show_bug.cgi?id=796875
2018-07-25 17:54:55 +00:00
|
|
|
GST_WARNING_OBJECT (stream,
|
2017-11-21 08:53:08 +00:00
|
|
|
"failed to allocate UDP ports: no address pool specified");
|
2012-10-25 19:29:58 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
no_address:
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
rtsp-client: always allocate both IPV4 and IPV6 sockets
multiudpsink does not support setting the socket* properties
after it has started, which meant that rtsp-server could no
longer serve on both IPV4 and IPV6 sockets since the patches
from https://bugzilla.gnome.org/show_bug.cgi?id=757488 were
merged.
When first connecting an IPV6 client then an IPV4 client,
multiudpsink fell back to using the IPV6 socket.
When first connecting an IPV4 client, then an IPV6 client,
multiudpsink errored out, released the IPV4 socket, then
crashed when trying to send a message on NULL nevertheless,
that is however a separate issue.
This could probably be fixed by handling the setting of
sockets in multiudpsink after it has started, that will
however be a much more significant effort.
For now, this commit simply partially reverts the behaviour
of rtsp-stream: it will continue to only create the udpsinks
when needed, as was the case since the patches were merged,
it will however when creating them, always allocate both
sockets and set them on the sink before it starts, as was
the case prior to the patches.
Transport configuration will only error out if the allocation
of UDP sockets fails for the actual client's family, this
also downgrades the GST_ERRORs in alloc_ports_one_family
to GST_WARNINGs, as failing to allocate is no longer
necessarily fatal.
https://bugzilla.gnome.org/show_bug.cgi?id=796875
2018-07-25 17:54:55 +00:00
|
|
|
GST_WARNING_OBJECT (stream, "failed to acquire address from pool");
|
2017-10-17 08:44:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
no_ports:
|
|
|
|
{
|
rtsp-client: always allocate both IPV4 and IPV6 sockets
multiudpsink does not support setting the socket* properties
after it has started, which meant that rtsp-server could no
longer serve on both IPV4 and IPV6 sockets since the patches
from https://bugzilla.gnome.org/show_bug.cgi?id=757488 were
merged.
When first connecting an IPV6 client then an IPV4 client,
multiudpsink fell back to using the IPV6 socket.
When first connecting an IPV4 client, then an IPV6 client,
multiudpsink errored out, released the IPV4 socket, then
crashed when trying to send a message on NULL nevertheless,
that is however a separate issue.
This could probably be fixed by handling the setting of
sockets in multiudpsink after it has started, that will
however be a much more significant effort.
For now, this commit simply partially reverts the behaviour
of rtsp-stream: it will continue to only create the udpsinks
when needed, as was the case since the patches were merged,
it will however when creating them, always allocate both
sockets and set them on the sink before it starts, as was
the case prior to the patches.
Transport configuration will only error out if the allocation
of UDP sockets fails for the actual client's family, this
also downgrades the GST_ERRORs in alloc_ports_one_family
to GST_WARNINGs, as failing to allocate is no longer
necessarily fatal.
https://bugzilla.gnome.org/show_bug.cgi?id=796875
2018-07-25 17:54:55 +00:00
|
|
|
GST_WARNING_OBJECT (stream, "failed to allocate UDP ports: no ports");
|
2012-10-25 19:29:58 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2018-02-23 13:34:32 +00:00
|
|
|
transport_settings_error:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream,
|
|
|
|
"failed to allocate UDP ports with requested transport settings");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-02-19 23:27:20 +00:00
|
|
|
socket_error:
|
|
|
|
{
|
rtsp-client: always allocate both IPV4 and IPV6 sockets
multiudpsink does not support setting the socket* properties
after it has started, which meant that rtsp-server could no
longer serve on both IPV4 and IPV6 sockets since the patches
from https://bugzilla.gnome.org/show_bug.cgi?id=757488 were
merged.
When first connecting an IPV6 client then an IPV4 client,
multiudpsink fell back to using the IPV6 socket.
When first connecting an IPV4 client, then an IPV6 client,
multiudpsink errored out, released the IPV4 socket, then
crashed when trying to send a message on NULL nevertheless,
that is however a separate issue.
This could probably be fixed by handling the setting of
sockets in multiudpsink after it has started, that will
however be a much more significant effort.
For now, this commit simply partially reverts the behaviour
of rtsp-stream: it will continue to only create the udpsinks
when needed, as was the case since the patches were merged,
it will however when creating them, always allocate both
sockets and set them on the sink before it starts, as was
the case prior to the patches.
Transport configuration will only error out if the allocation
of UDP sockets fails for the actual client's family, this
also downgrades the GST_ERRORs in alloc_ports_one_family
to GST_WARNINGs, as failing to allocate is no longer
necessarily fatal.
https://bugzilla.gnome.org/show_bug.cgi?id=796875
2018-07-25 17:54:55 +00:00
|
|
|
GST_WARNING_OBJECT (stream, "failed to allocate UDP ports: socket error");
|
2013-02-19 23:27:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
cleanup:
|
|
|
|
{
|
2013-02-19 23:27:20 +00:00
|
|
|
if (inetaddr)
|
|
|
|
g_object_unref (inetaddr);
|
|
|
|
g_list_free_full (rejected_addresses,
|
|
|
|
(GDestroyNotify) gst_rtsp_address_free);
|
|
|
|
if (addr)
|
|
|
|
gst_rtsp_address_free (addr);
|
|
|
|
if (rtp_socket)
|
|
|
|
g_object_unref (rtp_socket);
|
|
|
|
if (rtcp_socket)
|
|
|
|
g_object_unref (rtcp_socket);
|
2012-10-25 19:29:58 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 10:01:16 +00:00
|
|
|
/* must be called with lock */
|
|
|
|
static gboolean
|
|
|
|
add_mcast_client_addr (GstRTSPStream * stream, const gchar * destination,
|
|
|
|
guint rtp_port, guint rtcp_port)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GList *walk;
|
|
|
|
UdpClientAddrInfo *client;
|
|
|
|
GInetAddress *inet;
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
if (destination == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
inet = g_inet_address_new_from_string (destination);
|
|
|
|
if (inet == NULL)
|
|
|
|
goto invalid_address;
|
|
|
|
|
|
|
|
if (!g_inet_address_get_is_multicast (inet)) {
|
|
|
|
g_object_unref (inet);
|
|
|
|
goto invalid_address;
|
|
|
|
}
|
|
|
|
g_object_unref (inet);
|
|
|
|
|
|
|
|
for (walk = priv->mcast_clients; walk; walk = g_list_next (walk)) {
|
|
|
|
UdpClientAddrInfo *cli = walk->data;
|
|
|
|
|
|
|
|
if ((g_strcmp0 (cli->address, destination) == 0) &&
|
|
|
|
(cli->rtp_port == rtp_port)) {
|
|
|
|
GST_DEBUG ("requested destination already exists: %s:%u-%u",
|
|
|
|
destination, rtp_port, rtcp_port);
|
|
|
|
cli->add_count++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
client = g_new0 (UdpClientAddrInfo, 1);
|
|
|
|
client->address = g_strdup (destination);
|
|
|
|
client->rtp_port = rtp_port;
|
|
|
|
client->add_count = 1;
|
|
|
|
priv->mcast_clients = g_list_prepend (priv->mcast_clients, client);
|
|
|
|
|
|
|
|
GST_DEBUG ("added mcast client %s:%u-%u", destination, rtp_port, rtcp_port);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
invalid_address:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (stream, "Multicast address is invalid: %s",
|
|
|
|
destination);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called with lock */
|
|
|
|
static gboolean
|
|
|
|
remove_mcast_client_addr (GstRTSPStream * stream, const gchar * destination,
|
|
|
|
guint rtp_port, guint rtcp_port)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GList *walk;
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
if (destination == NULL)
|
|
|
|
goto no_destination;
|
|
|
|
|
|
|
|
for (walk = priv->mcast_clients; walk; walk = g_list_next (walk)) {
|
|
|
|
UdpClientAddrInfo *cli = walk->data;
|
|
|
|
|
|
|
|
if ((g_strcmp0 (cli->address, destination) == 0) &&
|
|
|
|
(cli->rtp_port == rtp_port)) {
|
|
|
|
cli->add_count--;
|
|
|
|
|
|
|
|
if (!cli->add_count) {
|
|
|
|
priv->mcast_clients = g_list_remove (priv->mcast_clients, cli);
|
|
|
|
free_mcast_client (cli);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_WARNING_OBJECT (stream, "Address not found");
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
no_destination:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (stream, "No destination has been provided");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-23 13:59:32 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_allocate_udp_sockets:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @family: protocol family
|
2017-04-13 17:20:10 +00:00
|
|
|
* @transport: transport method
|
2017-12-07 15:08:29 +00:00
|
|
|
* @use_client_settings: Whether to use client settings or not
|
2016-02-23 13:59:32 +00:00
|
|
|
*
|
|
|
|
* Allocates RTP and RTCP ports.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the RTP and RTCP sockets have been succeccully allocated.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_allocate_udp_sockets (GstRTSPStream * stream,
|
2017-10-17 08:44:33 +00:00
|
|
|
GSocketFamily family, GstRTSPTransport * ct,
|
|
|
|
gboolean use_transport_settings)
|
2013-05-30 06:07:48 +00:00
|
|
|
{
|
2017-10-17 08:44:33 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
GstRTSPLowerTrans transport;
|
|
|
|
gboolean allocated = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
g_return_val_if_fail (ct != NULL, FALSE);
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
transport = ct->lower_transport;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
|
|
|
|
if (transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
|
2017-12-19 09:14:48 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV4 && priv->mcast_socket_v4[0])
|
2017-10-17 08:44:33 +00:00
|
|
|
allocated = TRUE;
|
2017-12-19 09:14:48 +00:00
|
|
|
else if (family == G_SOCKET_FAMILY_IPV6 && priv->mcast_socket_v6[0])
|
2017-10-17 08:44:33 +00:00
|
|
|
allocated = TRUE;
|
|
|
|
} else if (transport == GST_RTSP_LOWER_TRANS_UDP) {
|
2017-12-19 09:14:48 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV4 && priv->socket_v4[0])
|
2017-10-17 08:44:33 +00:00
|
|
|
allocated = TRUE;
|
2017-12-19 09:14:48 +00:00
|
|
|
else if (family == G_SOCKET_FAMILY_IPV6 && priv->socket_v6[0])
|
2017-10-17 08:44:33 +00:00
|
|
|
allocated = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allocated) {
|
2017-12-19 09:14:48 +00:00
|
|
|
GST_DEBUG_OBJECT (stream, "Allocated already");
|
2017-10-17 08:44:33 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (family == G_SOCKET_FAMILY_IPV4) {
|
|
|
|
/* IPv4 */
|
|
|
|
if (transport == GST_RTSP_LOWER_TRANS_UDP) {
|
|
|
|
/* UDP unicast */
|
|
|
|
GST_DEBUG_OBJECT (stream, "GST_RTSP_LOWER_TRANS_UDP, ipv4");
|
|
|
|
ret = alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV4,
|
2018-02-23 13:34:32 +00:00
|
|
|
priv->socket_v4, &priv->server_addr_v4, FALSE, ct, FALSE);
|
2017-10-17 08:44:33 +00:00
|
|
|
} else {
|
|
|
|
/* multicast */
|
|
|
|
GST_DEBUG_OBJECT (stream, "GST_RTSP_LOWER_TRANS_MCAST_UDP, ipv4");
|
|
|
|
ret = alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV4,
|
2018-02-23 13:34:32 +00:00
|
|
|
priv->mcast_socket_v4, &priv->mcast_addr_v4, TRUE, ct,
|
|
|
|
use_transport_settings);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* IPv6 */
|
|
|
|
if (transport == GST_RTSP_LOWER_TRANS_UDP) {
|
|
|
|
/* unicast */
|
|
|
|
GST_DEBUG_OBJECT (stream, "GST_RTSP_LOWER_TRANS_UDP, ipv6");
|
|
|
|
ret = alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV6,
|
2018-02-23 13:34:32 +00:00
|
|
|
priv->socket_v6, &priv->server_addr_v6, FALSE, ct, FALSE);
|
2017-10-17 08:44:33 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* multicast */
|
|
|
|
GST_DEBUG_OBJECT (stream, "GST_RTSP_LOWER_TRANS_MCAST_UDP, ipv6");
|
|
|
|
ret = alloc_ports_one_family (stream, G_SOCKET_FAMILY_IPV6,
|
2018-02-23 13:34:32 +00:00
|
|
|
priv->mcast_socket_v6, &priv->mcast_addr_v6, TRUE, ct,
|
|
|
|
use_transport_settings);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return ret;
|
2013-05-30 06:07:48 +00:00
|
|
|
}
|
|
|
|
|
2015-11-16 14:12:28 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_client_side:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @client_side: TRUE if this #GstRTSPStream is running on the 'client' side of
|
|
|
|
* an RTSP connection.
|
|
|
|
*
|
|
|
|
* Sets the #GstRTSPStream as a 'client side' stream - used for sending
|
|
|
|
* streams to an RTSP server via RECORD. This has the practical effect
|
|
|
|
* of changing which UDP port numbers are used when setting up the local
|
|
|
|
* side of the stream sending to be either the 'server' or 'client' pair
|
|
|
|
* of a configured UDP transport.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_client_side (GstRTSPStream * stream, gboolean client_side)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->client_side = client_side;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-10 14:22:54 +00:00
|
|
|
* gst_rtsp_stream_is_client_side:
|
2015-11-16 14:12:28 +00:00
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* See gst_rtsp_stream_set_client_side()
|
|
|
|
*
|
|
|
|
* Returns: TRUE if this #GstRTSPStream is client-side.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_is_client_side (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
ret = priv->client_side;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_server_port:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @server_port: (out): result server port
|
2013-07-11 10:18:26 +00:00
|
|
|
* @family: the port family to get
|
2012-11-29 10:11:05 +00:00
|
|
|
*
|
|
|
|
* Fill @server_port with the port pair used by the server. This function can
|
|
|
|
* only be called when @stream has been joined.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_get_server_port (GstRTSPStream * stream,
|
2013-05-30 06:07:48 +00:00
|
|
|
GstRTSPRange * server_port, GSocketFamily family)
|
2012-11-29 10:11:05 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
priv = stream->priv;
|
2016-07-14 15:10:31 +00:00
|
|
|
g_return_if_fail (priv->joined_bin != NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2017-01-09 13:12:05 +00:00
|
|
|
if (server_port) {
|
|
|
|
server_port->min = 0;
|
|
|
|
server_port->max = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2017-01-10 07:34:50 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV4) {
|
|
|
|
if (server_port && priv->server_addr_v4) {
|
2016-09-05 15:04:50 +00:00
|
|
|
server_port->min = priv->server_addr_v4->port;
|
2020-09-04 19:14:35 +00:00
|
|
|
if (priv->enable_rtcp) {
|
|
|
|
server_port->max =
|
|
|
|
priv->server_addr_v4->port + priv->server_addr_v4->n_ports - 1;
|
|
|
|
}
|
2016-09-05 15:04:50 +00:00
|
|
|
}
|
2013-05-30 06:07:48 +00:00
|
|
|
} else {
|
2017-01-09 13:12:05 +00:00
|
|
|
if (server_port && priv->server_addr_v6) {
|
2016-09-05 15:04:50 +00:00
|
|
|
server_port->min = priv->server_addr_v6->port;
|
2020-09-04 19:14:35 +00:00
|
|
|
if (priv->enable_rtcp) {
|
|
|
|
server_port->max =
|
|
|
|
priv->server_addr_v6->port + priv->server_addr_v6->n_ports - 1;
|
|
|
|
}
|
2016-09-05 15:04:50 +00:00
|
|
|
}
|
2013-05-30 06:07:48 +00:00
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
2013-06-24 18:41:27 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_rtpsession:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the RTP session of this stream.
|
|
|
|
*
|
2022-10-15 09:40:04 +00:00
|
|
|
* Returns: (transfer full) (nullable): The RTP session of this stream. Unref after usage.
|
2013-06-24 18:41:27 +00:00
|
|
|
*/
|
|
|
|
GObject *
|
|
|
|
gst_rtsp_stream_get_rtpsession (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GObject *session;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((session = priv->session))
|
|
|
|
g_object_ref (session);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2016-04-15 05:56:11 +00:00
|
|
|
/**
|
2017-04-13 17:20:10 +00:00
|
|
|
* gst_rtsp_stream_get_srtp_encoder:
|
2016-04-15 05:56:11 +00:00
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the SRTP encoder for this stream.
|
|
|
|
*
|
2022-10-15 09:40:04 +00:00
|
|
|
* Returns: (transfer full) (nullable): The SRTP encoder for this stream. Unref after usage.
|
2016-04-15 05:56:11 +00:00
|
|
|
*/
|
|
|
|
GstElement *
|
|
|
|
gst_rtsp_stream_get_srtp_encoder (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstElement *encoder;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((encoder = priv->srtpenc))
|
|
|
|
g_object_ref (encoder);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return encoder;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_ssrc:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @ssrc: (out): result ssrc
|
|
|
|
*
|
|
|
|
* Get the SSRC used by the RTP session of this stream. This function can only
|
|
|
|
* be called when @stream has been joined.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_get_ssrc (GstRTSPStream * stream, guint * ssrc)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
priv = stream->priv;
|
2016-07-14 15:10:31 +00:00
|
|
|
g_return_if_fail (priv->joined_bin != NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (ssrc && priv->session)
|
|
|
|
g_object_get (priv->session, "internal-ssrc", ssrc, NULL);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
2014-11-26 14:12:36 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_retransmission_time:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @time: a #GstClockTime
|
|
|
|
*
|
|
|
|
* Set the amount of time to store retransmission packets.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_retransmission_time (GstRTSPStream * stream,
|
|
|
|
GstClockTime time)
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (stream, "set retransmission time %" G_GUINT64_FORMAT, time);
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
stream->priv->rtx_time = time;
|
|
|
|
if (stream->priv->rtxsend)
|
|
|
|
g_object_set (stream->priv->rtxsend, "max-size-time",
|
|
|
|
GST_TIME_AS_MSECONDS (time), NULL);
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-08-31 12:48:34 +00:00
|
|
|
* gst_rtsp_stream_get_retransmission_time:
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-11-26 14:12:36 +00:00
|
|
|
*
|
|
|
|
* Get the amount of time to store retransmission data.
|
|
|
|
*
|
|
|
|
* Returns: the amount of time to store retransmission data.
|
|
|
|
*/
|
|
|
|
GstClockTime
|
|
|
|
gst_rtsp_stream_get_retransmission_time (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstClockTime ret;
|
|
|
|
|
2014-12-16 15:42:13 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
|
2014-11-26 14:12:36 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
ret = stream->priv->rtx_time;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-31 12:48:34 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_retransmission_pt:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @rtx_pt: a #guint
|
|
|
|
*
|
|
|
|
* Set the payload type (pt) for retransmission of this stream.
|
|
|
|
*/
|
2014-11-26 14:12:36 +00:00
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_retransmission_pt (GstRTSPStream * stream, guint rtx_pt)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "set retransmission pt %u", rtx_pt);
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
stream->priv->rtx_pt = rtx_pt;
|
|
|
|
if (stream->priv->rtxsend) {
|
|
|
|
guint pt = gst_rtsp_stream_get_pt (stream);
|
|
|
|
gchar *pt_s = g_strdup_printf ("%d", pt);
|
|
|
|
GstStructure *rtx_pt_map = gst_structure_new ("application/x-rtp-pt-map",
|
|
|
|
pt_s, G_TYPE_UINT, rtx_pt, NULL);
|
|
|
|
g_object_set (stream->priv->rtxsend, "payload-type-map", rtx_pt_map, NULL);
|
2014-12-16 15:46:15 +00:00
|
|
|
g_free (pt_s);
|
|
|
|
gst_structure_free (rtx_pt_map);
|
2014-11-26 14:12:36 +00:00
|
|
|
}
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
}
|
|
|
|
|
2015-08-31 12:48:34 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_retransmission_pt:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the payload-type used for retransmission of this stream
|
|
|
|
*
|
|
|
|
* Returns: The retransmission PT.
|
|
|
|
*/
|
2014-11-26 14:12:36 +00:00
|
|
|
guint
|
|
|
|
gst_rtsp_stream_get_retransmission_pt (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
guint rtx_pt;
|
|
|
|
|
2014-12-16 15:42:13 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
|
2014-11-26 14:12:36 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
rtx_pt = stream->priv->rtx_pt;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return rtx_pt;
|
|
|
|
}
|
|
|
|
|
2015-08-31 12:48:34 +00:00
|
|
|
/**
|
2015-09-17 19:07:34 +00:00
|
|
|
* gst_rtsp_stream_set_buffer_size:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @size: the buffer size
|
2015-08-31 12:48:34 +00:00
|
|
|
*
|
|
|
|
* Set the size of the UDP transmission buffer (in bytes)
|
|
|
|
* Needs to be set before the stream is joined to a bin.
|
|
|
|
*
|
2015-09-17 19:07:34 +00:00
|
|
|
* Since: 1.6
|
2015-08-31 12:48:34 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_buffer_size (GstRTSPStream * stream, guint size)
|
|
|
|
{
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
stream->priv->buffer_size = size;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-17 19:07:34 +00:00
|
|
|
* gst_rtsp_stream_get_buffer_size:
|
|
|
|
* @stream: a #GstRTSPStream
|
2015-08-31 12:48:34 +00:00
|
|
|
*
|
|
|
|
* Get the size of the UDP transmission buffer (in bytes)
|
|
|
|
*
|
|
|
|
* Returns: the size of the UDP TX buffer
|
2015-09-17 19:07:34 +00:00
|
|
|
*
|
|
|
|
* Since: 1.6
|
2015-08-31 12:48:34 +00:00
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_stream_get_buffer_size (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
guint buffer_size;
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
buffer_size = stream->priv->buffer_size;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return buffer_size;
|
|
|
|
}
|
|
|
|
|
2018-07-24 07:35:46 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_max_mcast_ttl:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @ttl: the new multicast ttl value
|
|
|
|
*
|
|
|
|
* Set the maximum time-to-live value of outgoing multicast packets.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the requested ttl has been set successfully.
|
|
|
|
*
|
2019-04-23 11:38:05 +00:00
|
|
|
* Since: 1.16
|
2018-07-24 07:35:46 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_set_max_mcast_ttl (GstRTSPStream * stream, guint ttl)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
if (ttl == 0 || ttl > DEFAULT_MAX_MCAST_TTL) {
|
|
|
|
GST_WARNING_OBJECT (stream, "The reqested mcast TTL value is not valid.");
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
stream->priv->max_mcast_ttl = ttl;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_max_mcast_ttl:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the the maximum time-to-live value of outgoing multicast packets.
|
|
|
|
*
|
|
|
|
* Returns: the maximum time-to-live value of outgoing multicast packets.
|
|
|
|
*
|
2019-04-23 11:38:05 +00:00
|
|
|
* Since: 1.16
|
2018-07-24 07:35:46 +00:00
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gst_rtsp_stream_get_max_mcast_ttl (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
guint ttl;
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
ttl = stream->priv->max_mcast_ttl;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return ttl;
|
|
|
|
}
|
|
|
|
|
2018-07-25 13:33:18 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_verify_mcast_ttl:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @ttl: a requested multicast ttl
|
|
|
|
*
|
|
|
|
* Check if the requested multicast ttl value is allowed.
|
|
|
|
*
|
|
|
|
* Returns: TRUE if the requested ttl value is allowed.
|
|
|
|
*
|
2019-04-23 11:38:05 +00:00
|
|
|
* Since: 1.16
|
2018-07-25 13:33:18 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_verify_mcast_ttl (GstRTSPStream * stream, guint ttl)
|
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
if ((ttl > 0) && (ttl <= stream->priv->max_mcast_ttl))
|
|
|
|
res = TRUE;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-09-06 14:17:33 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_bind_mcast_address:
|
|
|
|
* @stream: a #GstRTSPStream,
|
|
|
|
* @bind_mcast_addr: the new value
|
|
|
|
*
|
|
|
|
* Decide whether the multicast socket should be bound to a multicast address or
|
|
|
|
* INADDR_ANY.
|
2019-04-23 11:38:05 +00:00
|
|
|
*
|
|
|
|
* Since: 1.16
|
2018-09-06 14:17:33 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_bind_mcast_address (GstRTSPStream * stream,
|
|
|
|
gboolean bind_mcast_addr)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
stream->priv->bind_mcast_address = bind_mcast_addr;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_is_bind_mcast_address:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Check if multicast sockets are configured to be bound to multicast addresses.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if multicast sockets are configured to be bound to multicast addresses.
|
2019-04-23 11:38:05 +00:00
|
|
|
*
|
|
|
|
* Since: 1.16
|
2018-09-06 14:17:33 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_is_bind_mcast_address (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
result = stream->priv->bind_mcast_address;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-09-04 19:14:35 +00:00
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_enable_rtcp (GstRTSPStream * stream, gboolean enable)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
stream->priv->enable_rtcp = enable;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/* executed from streaming thread */
|
|
|
|
static void
|
|
|
|
caps_notify (GstPad * pad, GParamSpec * unused, GstRTSPStream * stream)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstCaps *newcaps, *oldcaps;
|
|
|
|
|
|
|
|
newcaps = gst_pad_get_current_caps (pad);
|
|
|
|
|
2012-11-13 10:14:49 +00:00
|
|
|
GST_INFO ("stream %p received caps %p, %" GST_PTR_FORMAT, stream, newcaps,
|
|
|
|
newcaps);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
oldcaps = priv->caps;
|
|
|
|
priv->caps = newcaps;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
if (oldcaps)
|
|
|
|
gst_caps_unref (oldcaps);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_structure (const GstStructure * s)
|
|
|
|
{
|
|
|
|
gchar *sstr;
|
|
|
|
|
|
|
|
sstr = gst_structure_to_string (s);
|
|
|
|
GST_INFO ("structure: %s", sstr);
|
|
|
|
g_free (sstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPStreamTransport *
|
|
|
|
find_transport (GstRTSPStream * stream, const gchar * rtcp_from)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GList *walk;
|
|
|
|
GstRTSPStreamTransport *result = NULL;
|
|
|
|
const gchar *tmp;
|
|
|
|
gchar *dest;
|
|
|
|
guint port;
|
|
|
|
|
|
|
|
if (rtcp_from == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tmp = g_strrstr (rtcp_from, ":");
|
|
|
|
if (tmp == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
port = atoi (tmp + 1);
|
|
|
|
dest = g_strndup (rtcp_from, tmp - rtcp_from);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("finding %s:%d in %d transports", dest, port,
|
2012-11-29 10:11:05 +00:00
|
|
|
g_list_length (priv->transports));
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
for (walk = priv->transports; walk; walk = g_list_next (walk)) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GstRTSPStreamTransport *trans = walk->data;
|
2012-11-29 10:11:05 +00:00
|
|
|
const GstRTSPTransport *tr;
|
2012-10-25 19:29:58 +00:00
|
|
|
gint min, max;
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
tr = gst_rtsp_stream_transport_get_transport (trans);
|
|
|
|
|
2015-11-16 14:12:28 +00:00
|
|
|
if (priv->client_side) {
|
|
|
|
/* In client side mode the 'destination' is the RTSP server, so send
|
|
|
|
* to those ports */
|
|
|
|
min = tr->server_port.min;
|
|
|
|
max = tr->server_port.max;
|
|
|
|
} else {
|
|
|
|
min = tr->client_port.min;
|
|
|
|
max = tr->client_port.max;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2016-09-07 14:16:19 +00:00
|
|
|
if ((g_ascii_strcasecmp (tr->destination, dest) == 0) &&
|
|
|
|
(min == port || max == port)) {
|
2012-10-25 19:29:58 +00:00
|
|
|
result = trans;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-05-30 04:49:20 +00:00
|
|
|
if (result)
|
|
|
|
g_object_ref (result);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
g_free (dest);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstRTSPStreamTransport *
|
|
|
|
check_transport (GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstStructure *stats;
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
dump_structure (stats);
|
|
|
|
|
|
|
|
rtcp_from = gst_structure_get_string (stats, "rtcp-from");
|
|
|
|
if ((trans = find_transport (stream, rtcp_from))) {
|
|
|
|
GST_INFO ("%p: found transport %p for source %p", stream, trans,
|
|
|
|
source);
|
2013-05-30 04:49:20 +00:00
|
|
|
g_object_set_qdata_full (source, ssrc_stream_map_key, trans,
|
|
|
|
g_object_unref);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
gst_structure_free (stats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return trans;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_new_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
GST_INFO ("%p: new source %p", stream, source);
|
|
|
|
|
|
|
|
trans = check_transport (source, stream);
|
|
|
|
|
|
|
|
if (trans)
|
|
|
|
GST_INFO ("%p: source %p for transport %p", stream, source, trans);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_ssrc_sdes (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GST_INFO ("%p: new SDES %p", stream, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_ssrc_active (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
trans = check_transport (source, stream);
|
|
|
|
|
2012-11-12 16:11:18 +00:00
|
|
|
if (trans) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("%p: source %p in transport %p is active", stream, source, trans);
|
2012-11-12 16:11:18 +00:00
|
|
|
gst_rtsp_stream_transport_keep_alive (trans);
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
#ifdef DUMP_STATS
|
|
|
|
{
|
|
|
|
GstStructure *stats;
|
|
|
|
g_object_get (source, "stats", &stats, NULL);
|
|
|
|
if (stats) {
|
|
|
|
dump_structure (stats);
|
|
|
|
gst_structure_free (stats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_bye_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GST_INFO ("%p: source %p bye", stream, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_bye_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
GST_INFO ("%p: source %p bye timeout", stream, source);
|
|
|
|
|
|
|
|
if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_stream_transport_set_timed_out (trans, TRUE);
|
2013-05-30 04:49:20 +00:00
|
|
|
g_object_set_qdata (source, ssrc_stream_map_key, NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_timeout (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamTransport *trans;
|
|
|
|
|
|
|
|
GST_INFO ("%p: source %p timeout", stream, source);
|
|
|
|
|
|
|
|
if ((trans = g_object_get_qdata (source, ssrc_stream_map_key))) {
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_rtsp_stream_transport_set_timed_out (trans, TRUE);
|
2013-05-30 04:49:20 +00:00
|
|
|
g_object_set_qdata (source, ssrc_stream_map_key, NULL);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 07:11:05 +00:00
|
|
|
static void
|
|
|
|
on_new_sender_ssrc (GObject * session, GObject * source, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GST_INFO ("%p: new sender source %p", stream, source);
|
|
|
|
#ifndef DUMP_STATS
|
|
|
|
{
|
|
|
|
GstStructure *stats;
|
|
|
|
g_object_get (source, "stats", &stats, NULL);
|
|
|
|
if (stats) {
|
|
|
|
dump_structure (stats);
|
|
|
|
gst_structure_free (stats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_sender_ssrc_active (GObject * session, GObject * source,
|
|
|
|
GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
#ifndef DUMP_STATS
|
|
|
|
{
|
|
|
|
GstStructure *stats;
|
|
|
|
g_object_get (source, "stats", &stats, NULL);
|
|
|
|
if (stats) {
|
|
|
|
dump_structure (stats);
|
|
|
|
gst_structure_free (stats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-13 13:20:17 +00:00
|
|
|
static void
|
2019-10-07 10:13:47 +00:00
|
|
|
clear_tr_cache (GstRTSPStreamPrivate * priv)
|
2014-03-13 13:20:17 +00:00
|
|
|
{
|
2019-10-07 10:13:47 +00:00
|
|
|
if (priv->tr_cache)
|
|
|
|
g_ptr_array_unref (priv->tr_cache);
|
|
|
|
priv->tr_cache = NULL;
|
2014-03-13 13:20:17 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 17:08:32 +00:00
|
|
|
/* With lock taken */
|
|
|
|
static gboolean
|
2020-01-09 13:10:44 +00:00
|
|
|
any_transport_ready (GstRTSPStream * stream, gboolean is_rtp)
|
2019-10-15 17:08:32 +00:00
|
|
|
{
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
GPtrArray *transports;
|
|
|
|
gint index;
|
|
|
|
|
|
|
|
transports = priv->tr_cache;
|
|
|
|
|
|
|
|
if (!transports)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
for (index = 0; index < transports->len; index++) {
|
|
|
|
GstRTSPStreamTransport *tr = g_ptr_array_index (transports, index);
|
2020-01-09 13:10:44 +00:00
|
|
|
if (!gst_rtsp_stream_transport_check_back_pressure (tr, is_rtp)) {
|
2019-10-15 17:08:32 +00:00
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called *without* priv->lock */
|
2020-02-14 13:59:43 +00:00
|
|
|
static gboolean
|
2019-10-15 17:08:32 +00:00
|
|
|
push_data (GstRTSPStream * stream, GstRTSPStreamTransport * trans,
|
|
|
|
GstBuffer * buffer, GstBufferList * buffer_list, gboolean is_rtp)
|
|
|
|
{
|
|
|
|
gboolean send_ret = TRUE;
|
|
|
|
|
|
|
|
if (is_rtp) {
|
|
|
|
if (buffer)
|
|
|
|
send_ret = gst_rtsp_stream_transport_send_rtp (trans, buffer);
|
|
|
|
if (buffer_list)
|
|
|
|
send_ret = gst_rtsp_stream_transport_send_rtp_list (trans, buffer_list);
|
|
|
|
} else {
|
|
|
|
if (buffer)
|
|
|
|
send_ret = gst_rtsp_stream_transport_send_rtcp (trans, buffer);
|
|
|
|
if (buffer_list)
|
|
|
|
send_ret = gst_rtsp_stream_transport_send_rtcp_list (trans, buffer_list);
|
|
|
|
}
|
|
|
|
|
2020-02-14 13:59:43 +00:00
|
|
|
return send_ret;
|
2019-10-15 17:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* With priv->lock */
|
|
|
|
static void
|
|
|
|
ensure_cached_transports (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
GList *walk;
|
|
|
|
|
|
|
|
if (priv->tr_cache_cookie != priv->transports_cookie) {
|
|
|
|
clear_tr_cache (priv);
|
|
|
|
priv->tr_cache =
|
|
|
|
g_ptr_array_new_full (priv->n_tcp_transports, g_object_unref);
|
|
|
|
|
|
|
|
for (walk = priv->transports; walk; walk = g_list_next (walk)) {
|
|
|
|
GstRTSPStreamTransport *tr = (GstRTSPStreamTransport *) walk->data;
|
|
|
|
const GstRTSPTransport *t = gst_rtsp_stream_transport_get_transport (tr);
|
|
|
|
|
|
|
|
if (t->lower_transport != GST_RTSP_LOWER_TRANS_TCP)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_ptr_array_add (priv->tr_cache, g_object_ref (tr));
|
|
|
|
}
|
|
|
|
priv->tr_cache_cookie = priv->transports_cookie;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
/* Must be called *without* priv->lock */
|
|
|
|
static void
|
|
|
|
check_transport_backlog (GstRTSPStream * stream, GstRTSPStreamTransport * trans)
|
|
|
|
{
|
2020-02-14 13:59:43 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
gboolean send_ret = TRUE;
|
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
gst_rtsp_stream_transport_lock_backlog (trans);
|
|
|
|
|
|
|
|
if (!gst_rtsp_stream_transport_backlog_is_empty (trans)) {
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstBufferList *buffer_list;
|
|
|
|
gboolean is_rtp;
|
|
|
|
gboolean popped;
|
|
|
|
|
2022-08-24 11:50:19 +00:00
|
|
|
is_rtp = gst_rtsp_stream_transport_backlog_peek_is_rtp (trans);
|
2020-02-06 21:46:18 +00:00
|
|
|
|
2022-08-24 11:50:19 +00:00
|
|
|
if (!gst_rtsp_stream_transport_check_back_pressure (trans, is_rtp)) {
|
|
|
|
popped =
|
|
|
|
gst_rtsp_stream_transport_backlog_pop (trans, &buffer, &buffer_list,
|
|
|
|
&is_rtp);
|
2020-02-06 21:46:18 +00:00
|
|
|
|
2022-08-24 11:50:19 +00:00
|
|
|
g_assert (popped == TRUE);
|
2020-02-06 21:46:18 +00:00
|
|
|
|
2022-08-24 11:50:19 +00:00
|
|
|
send_ret = push_data (stream, trans, buffer, buffer_list, is_rtp);
|
|
|
|
|
|
|
|
gst_clear_buffer (&buffer);
|
|
|
|
gst_clear_buffer_list (&buffer_list);
|
|
|
|
}
|
2020-02-06 21:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_rtsp_stream_transport_unlock_backlog (trans);
|
2020-02-14 13:59:43 +00:00
|
|
|
|
|
|
|
if (!send_ret) {
|
|
|
|
/* remove transport on send error */
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
update_transport (stream, trans, FALSE);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
2020-02-06 21:46:18 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 15:03:51 +00:00
|
|
|
/* Must be called with priv->lock */
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
static void
|
|
|
|
send_tcp_message (GstRTSPStream * stream, gint idx)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
GstAppSink *sink;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstSample *sample;
|
|
|
|
GstBuffer *buffer;
|
2018-06-27 10:17:07 +00:00
|
|
|
GstBufferList *buffer_list;
|
2014-03-13 13:20:17 +00:00
|
|
|
gboolean is_rtp;
|
2019-10-07 10:13:47 +00:00
|
|
|
GPtrArray *transports;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2019-10-15 17:08:32 +00:00
|
|
|
if (!priv->have_buffer[idx])
|
|
|
|
return;
|
|
|
|
|
|
|
|
ensure_cached_transports (stream);
|
|
|
|
|
2020-01-09 13:10:44 +00:00
|
|
|
is_rtp = (idx == 0);
|
|
|
|
|
|
|
|
if (!any_transport_ready (stream, is_rtp))
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
priv->have_buffer[idx] = FALSE;
|
|
|
|
|
|
|
|
if (priv->appsink[idx] == NULL) {
|
|
|
|
/* session expired */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sink = GST_APP_SINK (priv->appsink[idx]);
|
2012-10-25 19:29:58 +00:00
|
|
|
sample = gst_app_sink_pull_sample (sink);
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
if (!sample) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
buffer = gst_sample_get_buffer (sample);
|
2018-06-27 10:17:07 +00:00
|
|
|
buffer_list = gst_sample_get_buffer_list (sample);
|
|
|
|
|
2018-09-17 19:18:46 +00:00
|
|
|
/* We will get one message-sent notification per buffer or
|
|
|
|
* complete buffer-list. We handle each buffer-list as a unit */
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2019-10-07 10:13:47 +00:00
|
|
|
transports = priv->tr_cache;
|
2020-01-11 21:58:48 +00:00
|
|
|
if (transports)
|
|
|
|
g_ptr_array_ref (transports);
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
|
2019-10-07 10:13:47 +00:00
|
|
|
if (transports) {
|
2019-10-15 17:08:32 +00:00
|
|
|
gint index;
|
2018-06-27 10:17:07 +00:00
|
|
|
|
2019-10-15 17:08:32 +00:00
|
|
|
for (index = 0; index < transports->len; index++) {
|
|
|
|
GstRTSPStreamTransport *tr = g_ptr_array_index (transports, index);
|
2020-02-06 21:46:18 +00:00
|
|
|
GstBuffer *buf_ref = NULL;
|
|
|
|
GstBufferList *buflist_ref = NULL;
|
2019-10-15 17:08:32 +00:00
|
|
|
|
2020-02-05 19:28:19 +00:00
|
|
|
gst_rtsp_stream_transport_lock_backlog (tr);
|
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
if (buffer)
|
|
|
|
buf_ref = gst_buffer_ref (buffer);
|
|
|
|
if (buffer_list)
|
|
|
|
buflist_ref = gst_buffer_list_ref (buffer_list);
|
2019-10-15 17:08:32 +00:00
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
if (!gst_rtsp_stream_transport_backlog_push (tr,
|
|
|
|
buf_ref, buflist_ref, is_rtp)) {
|
|
|
|
GST_ERROR_OBJECT (stream,
|
|
|
|
"Dropping slow transport %" GST_PTR_FORMAT, tr);
|
|
|
|
update_transport (stream, tr, FALSE);
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
}
|
2020-02-05 19:28:19 +00:00
|
|
|
|
|
|
|
gst_rtsp_stream_transport_unlock_backlog (tr);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_sample_unref (sample);
|
2018-07-23 15:03:51 +00:00
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
if (transports) {
|
|
|
|
gint index;
|
|
|
|
|
|
|
|
for (index = 0; index < transports->len; index++) {
|
|
|
|
GstRTSPStreamTransport *tr = g_ptr_array_index (transports, index);
|
|
|
|
|
|
|
|
check_transport_backlog (stream, tr);
|
|
|
|
}
|
|
|
|
g_ptr_array_unref (transports);
|
|
|
|
}
|
|
|
|
|
2018-07-23 15:03:51 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
static gpointer
|
|
|
|
send_func (GstRTSPStream * stream)
|
2019-01-16 11:59:11 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
g_mutex_lock (&priv->send_lock);
|
|
|
|
|
2021-02-01 11:16:46 +00:00
|
|
|
while (priv->continue_sending) {
|
2020-02-06 21:46:18 +00:00
|
|
|
int i;
|
|
|
|
int idx = -1;
|
|
|
|
guint cookie;
|
|
|
|
|
|
|
|
cookie = priv->send_cookie;
|
|
|
|
g_mutex_unlock (&priv->send_lock);
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2019-10-15 17:08:32 +00:00
|
|
|
|
2019-01-16 11:59:11 +00:00
|
|
|
/* iterate from 1 and down, so we prioritize RTCP over RTP */
|
|
|
|
for (i = 1; i >= 0; i--) {
|
|
|
|
if (priv->have_buffer[i]) {
|
|
|
|
/* send message */
|
|
|
|
idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
if (idx != -1) {
|
2019-01-16 11:59:11 +00:00
|
|
|
send_tcp_message (stream, idx);
|
2020-02-06 21:46:18 +00:00
|
|
|
}
|
2019-01-16 11:59:11 +00:00
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->send_lock);
|
2021-02-01 11:16:46 +00:00
|
|
|
while (cookie == priv->send_cookie && priv->continue_sending) {
|
2020-02-06 21:46:18 +00:00
|
|
|
g_cond_wait (&priv->send_cond, &priv->send_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&priv->send_lock);
|
|
|
|
|
|
|
|
return NULL;
|
2019-01-16 11:59:11 +00:00
|
|
|
}
|
|
|
|
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
handle_new_sample (GstAppSink * sink, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPStream *stream = user_data;
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
if (GST_ELEMENT_CAST (sink) == priv->appsink[i]) {
|
|
|
|
priv->have_buffer[i] = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2020-02-06 21:46:18 +00:00
|
|
|
}
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
if (priv->send_thread == NULL) {
|
|
|
|
priv->send_thread = g_thread_new (NULL, (GThreadFunc) send_func, user_data);
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2018-07-23 15:03:51 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
g_mutex_lock (&priv->send_lock);
|
|
|
|
priv->send_cookie++;
|
|
|
|
g_cond_signal (&priv->send_cond);
|
|
|
|
g_mutex_unlock (&priv->send_lock);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstAppSinkCallbacks sink_cb = {
|
|
|
|
NULL, /* not interested in EOS */
|
|
|
|
NULL, /* not interested in preroll samples */
|
|
|
|
handle_new_sample,
|
|
|
|
};
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
static GstElement *
|
|
|
|
get_rtp_encoder (GstRTSPStream * stream, guint session)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
|
|
|
|
if (priv->srtpenc == NULL) {
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = g_strdup_printf ("srtpenc_%u", session);
|
|
|
|
priv->srtpenc = gst_element_factory_make ("srtpenc", name);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
g_object_set (priv->srtpenc, "random-key", TRUE, NULL);
|
|
|
|
}
|
|
|
|
return gst_object_ref (priv->srtpenc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElement *
|
|
|
|
request_rtp_encoder (GstElement * rtpbin, guint session, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2014-05-16 01:15:04 +00:00
|
|
|
GstElement *oldenc, *enc;
|
2014-03-13 16:35:21 +00:00
|
|
|
GstPad *pad;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
if (priv->idx != session)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "make RTP encoder for session %u", session);
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
oldenc = priv->srtpenc;
|
2014-03-13 16:35:21 +00:00
|
|
|
enc = get_rtp_encoder (stream, session);
|
|
|
|
name = g_strdup_printf ("rtp_sink_%d", session);
|
2021-04-21 08:43:41 +00:00
|
|
|
pad = gst_element_request_pad_simple (enc, name);
|
2014-03-13 16:35:21 +00:00
|
|
|
g_free (name);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
if (oldenc == NULL)
|
|
|
|
g_signal_emit (stream, gst_rtsp_stream_signals[SIGNAL_NEW_RTP_ENCODER], 0,
|
|
|
|
enc);
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
return enc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElement *
|
|
|
|
request_rtcp_encoder (GstElement * rtpbin, guint session,
|
|
|
|
GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2014-05-16 01:15:04 +00:00
|
|
|
GstElement *oldenc, *enc;
|
2014-03-13 16:35:21 +00:00
|
|
|
GstPad *pad;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
if (priv->idx != session)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "make RTCP encoder for session %u", session);
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
oldenc = priv->srtpenc;
|
2014-03-13 16:35:21 +00:00
|
|
|
enc = get_rtp_encoder (stream, session);
|
|
|
|
name = g_strdup_printf ("rtcp_sink_%d", session);
|
2021-04-21 08:43:41 +00:00
|
|
|
pad = gst_element_request_pad_simple (enc, name);
|
2014-03-13 16:35:21 +00:00
|
|
|
g_free (name);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
2014-05-16 01:15:04 +00:00
|
|
|
if (oldenc == NULL)
|
|
|
|
g_signal_emit (stream, gst_rtsp_stream_signals[SIGNAL_NEW_RTCP_ENCODER], 0,
|
|
|
|
enc);
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
return enc;
|
|
|
|
}
|
|
|
|
|
2014-04-02 10:36:16 +00:00
|
|
|
static GstCaps *
|
|
|
|
request_key (GstElement * srtpdec, guint ssrc, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
GST_DEBUG ("request key %08x", ssrc);
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((caps = g_hash_table_lookup (priv->keys, GINT_TO_POINTER (ssrc))))
|
|
|
|
gst_caps_ref (caps);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
static GstElement *
|
2015-01-09 11:40:47 +00:00
|
|
|
request_rtp_rtcp_decoder (GstElement * rtpbin, guint session,
|
2014-03-13 16:35:21 +00:00
|
|
|
GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
|
|
|
|
if (priv->idx != session)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (priv->srtpdec == NULL) {
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = g_strdup_printf ("srtpdec_%u", session);
|
|
|
|
priv->srtpdec = gst_element_factory_make ("srtpdec", name);
|
|
|
|
g_free (name);
|
2014-04-02 10:36:16 +00:00
|
|
|
|
|
|
|
g_signal_connect (priv->srtpdec, "request-key",
|
|
|
|
(GCallback) request_key, stream);
|
2017-02-01 08:44:50 +00:00
|
|
|
|
|
|
|
g_signal_emit (stream, gst_rtsp_stream_signals[SIGNAL_NEW_RTP_RTCP_DECODER],
|
|
|
|
0, priv->srtpdec);
|
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
}
|
|
|
|
return gst_object_ref (priv->srtpdec);
|
|
|
|
}
|
|
|
|
|
2015-06-11 08:38:52 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_request_aux_sender:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @sessid: the session id
|
|
|
|
*
|
|
|
|
* Creating a rtxsend bin
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): a #GstElement.
|
2015-06-11 08:38:52 +00:00
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
2015-04-15 00:45:23 +00:00
|
|
|
GstElement *
|
|
|
|
gst_rtsp_stream_request_aux_sender (GstRTSPStream * stream, guint sessid)
|
2014-11-26 14:12:36 +00:00
|
|
|
{
|
|
|
|
GstElement *bin;
|
|
|
|
GstPad *pad;
|
|
|
|
GstStructure *pt_map;
|
|
|
|
gchar *name;
|
|
|
|
guint pt, rtx_pt;
|
|
|
|
gchar *pt_s;
|
|
|
|
|
2015-04-15 00:45:23 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
2014-11-26 14:12:36 +00:00
|
|
|
pt = gst_rtsp_stream_get_pt (stream);
|
|
|
|
pt_s = g_strdup_printf ("%u", pt);
|
|
|
|
rtx_pt = stream->priv->rtx_pt;
|
|
|
|
|
|
|
|
GST_INFO ("creating rtxsend with pt %u to %u", pt, rtx_pt);
|
|
|
|
|
|
|
|
bin = gst_bin_new (NULL);
|
|
|
|
stream->priv->rtxsend = gst_element_factory_make ("rtprtxsend", NULL);
|
|
|
|
pt_map = gst_structure_new ("application/x-rtp-pt-map",
|
|
|
|
pt_s, G_TYPE_UINT, rtx_pt, NULL);
|
|
|
|
g_object_set (stream->priv->rtxsend, "payload-type-map", pt_map,
|
|
|
|
"max-size-time", GST_TIME_AS_MSECONDS (stream->priv->rtx_time), NULL);
|
2014-12-16 15:46:15 +00:00
|
|
|
g_free (pt_s);
|
2014-11-26 14:12:36 +00:00
|
|
|
gst_structure_free (pt_map);
|
|
|
|
gst_bin_add (GST_BIN (bin), gst_object_ref (stream->priv->rtxsend));
|
|
|
|
|
|
|
|
pad = gst_element_get_static_pad (stream->priv->rtxsend, "src");
|
|
|
|
name = g_strdup_printf ("src_%u", sessid);
|
|
|
|
gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
|
|
|
|
g_free (name);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
|
|
|
pad = gst_element_get_static_pad (stream->priv->rtxsend, "sink");
|
|
|
|
name = g_strdup_printf ("sink_%u", sessid);
|
|
|
|
gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
|
|
|
|
g_free (name);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
|
|
|
return bin;
|
|
|
|
}
|
|
|
|
|
2018-03-29 20:49:26 +00:00
|
|
|
static void
|
2018-04-04 07:06:06 +00:00
|
|
|
add_rtx_pt (gpointer key, GstCaps * caps, GstStructure * pt_map)
|
2018-03-29 20:49:26 +00:00
|
|
|
{
|
|
|
|
guint pt = GPOINTER_TO_INT (key);
|
|
|
|
const GstStructure *s = gst_caps_get_structure (caps, 0);
|
|
|
|
const gchar *apt;
|
|
|
|
|
|
|
|
if (!g_strcmp0 (gst_structure_get_string (s, "encoding-name"), "RTX") &&
|
|
|
|
(apt = gst_structure_get_string (s, "apt"))) {
|
|
|
|
gst_structure_set (pt_map, apt, G_TYPE_UINT, pt, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call with priv->lock taken */
|
|
|
|
static void
|
|
|
|
update_rtx_receive_pt_map (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstStructure *pt_map;
|
|
|
|
|
|
|
|
if (!stream->priv->rtxreceive)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
pt_map = gst_structure_new_empty ("application/x-rtp-pt-map");
|
|
|
|
g_hash_table_foreach (stream->priv->ptmap, (GHFunc) add_rtx_pt, pt_map);
|
|
|
|
g_object_set (stream->priv->rtxreceive, "payload-type-map", pt_map, NULL);
|
|
|
|
gst_structure_free (pt_map);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-02 20:49:35 +00:00
|
|
|
static void
|
2018-06-24 10:45:49 +00:00
|
|
|
retrieve_ulpfec_pt (gpointer key, GstCaps * caps, GstElement * ulpfec_decoder)
|
2018-04-02 20:49:35 +00:00
|
|
|
{
|
|
|
|
guint pt = GPOINTER_TO_INT (key);
|
|
|
|
const GstStructure *s = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
if (!g_strcmp0 (gst_structure_get_string (s, "encoding-name"), "ULPFEC"))
|
|
|
|
g_object_set (ulpfec_decoder, "pt", pt, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_ulpfec_decoder_pt (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
if (!stream->priv->ulpfec_decoder)
|
|
|
|
goto done;
|
|
|
|
|
2018-06-24 10:45:49 +00:00
|
|
|
g_hash_table_foreach (stream->priv->ptmap, (GHFunc) retrieve_ulpfec_pt,
|
|
|
|
stream->priv->ulpfec_decoder);
|
2018-04-02 20:49:35 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-29 20:49:26 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_request_aux_receiver:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @sessid: the session id
|
|
|
|
*
|
|
|
|
* Creating a rtxreceive bin
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): a #GstElement.
|
|
|
|
*
|
|
|
|
* Since: 1.16
|
|
|
|
*/
|
|
|
|
GstElement *
|
|
|
|
gst_rtsp_stream_request_aux_receiver (GstRTSPStream * stream, guint sessid)
|
|
|
|
{
|
|
|
|
GstElement *bin;
|
|
|
|
GstPad *pad;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
bin = gst_bin_new (NULL);
|
|
|
|
stream->priv->rtxreceive = gst_element_factory_make ("rtprtxreceive", NULL);
|
|
|
|
update_rtx_receive_pt_map (stream);
|
2018-04-02 20:49:35 +00:00
|
|
|
update_ulpfec_decoder_pt (stream);
|
2018-03-29 20:49:26 +00:00
|
|
|
gst_bin_add (GST_BIN (bin), gst_object_ref (stream->priv->rtxreceive));
|
|
|
|
|
|
|
|
pad = gst_element_get_static_pad (stream->priv->rtxreceive, "src");
|
|
|
|
name = g_strdup_printf ("src_%u", sessid);
|
|
|
|
gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
|
|
|
|
g_free (name);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
|
|
|
pad = gst_element_get_static_pad (stream->priv->rtxreceive, "sink");
|
|
|
|
name = g_strdup_printf ("sink_%u", sessid);
|
|
|
|
gst_element_add_pad (bin, gst_ghost_pad_new (name, pad));
|
|
|
|
g_free (name);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
|
|
|
|
return bin;
|
|
|
|
}
|
|
|
|
|
2015-01-09 11:40:47 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_pt_map:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @pt: the pt
|
|
|
|
* @caps: a #GstCaps
|
|
|
|
*
|
|
|
|
* Configure a pt map between @pt and @caps.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_pt_map (GstRTSPStream * stream, guint pt, GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
|
2018-02-09 23:07:25 +00:00
|
|
|
if (!GST_IS_CAPS (caps))
|
|
|
|
return;
|
|
|
|
|
2015-01-09 11:40:47 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
g_hash_table_insert (priv->ptmap, GINT_TO_POINTER (pt), gst_caps_ref (caps));
|
2018-03-29 20:49:26 +00:00
|
|
|
update_rtx_receive_pt_map (stream);
|
2015-01-09 11:40:47 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
2015-12-30 16:39:05 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_publish_clock_mode:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @mode: the clock publish mode
|
|
|
|
*
|
|
|
|
* Sets if and how the stream clock should be published according to RFC7273.
|
|
|
|
*
|
|
|
|
* Since: 1.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_publish_clock_mode (GstRTSPStream * stream,
|
|
|
|
GstRTSPPublishClockMode mode)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->publish_clock_mode = mode;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_publish_clock_mode:
|
2017-04-13 17:20:10 +00:00
|
|
|
* @stream: a #GstRTSPStream
|
2015-12-30 16:39:05 +00:00
|
|
|
*
|
|
|
|
* Gets if and how the stream clock should be published according to RFC7273.
|
|
|
|
*
|
|
|
|
* Returns: The GstRTSPPublishClockMode
|
|
|
|
*
|
|
|
|
* Since: 1.8
|
|
|
|
*/
|
|
|
|
GstRTSPPublishClockMode
|
|
|
|
gst_rtsp_stream_get_publish_clock_mode (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstRTSPPublishClockMode ret;
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
ret = priv->publish_clock_mode;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-09 11:40:47 +00:00
|
|
|
static GstCaps *
|
|
|
|
request_pt_map (GstElement * rtpbin, guint session, guint pt,
|
|
|
|
GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
|
|
|
|
if (priv->idx == session) {
|
|
|
|
caps = g_hash_table_lookup (priv->ptmap, GINT_TO_POINTER (pt));
|
|
|
|
if (caps) {
|
|
|
|
GST_DEBUG ("Stream %p, pt %u: caps %" GST_PTR_FORMAT, stream, pt, caps);
|
|
|
|
gst_caps_ref (caps);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("Stream %p, pt %u: no caps", stream, pt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pad_added (GstElement * rtpbin, GstPad * pad, GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
gchar *name;
|
|
|
|
GstPadLinkReturn ret;
|
|
|
|
guint sessid;
|
|
|
|
|
|
|
|
GST_DEBUG ("Stream %p added pad %s:%s for pad %s:%s", stream,
|
|
|
|
GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (priv->sinkpad));
|
|
|
|
|
|
|
|
name = gst_pad_get_name (pad);
|
|
|
|
if (sscanf (name, "recv_rtp_src_%u", &sessid) != 1) {
|
|
|
|
g_free (name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
if (priv->idx != sessid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gst_pad_is_linked (priv->sinkpad)) {
|
|
|
|
GST_WARNING ("Stream %p: Pad %s:%s is linked already", stream,
|
|
|
|
GST_DEBUG_PAD_NAME (priv->sinkpad));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* link the RTP pad to the session manager, it should not really fail unless
|
|
|
|
* this is not really an RTP pad */
|
|
|
|
ret = gst_pad_link (pad, priv->sinkpad);
|
|
|
|
if (ret != GST_PAD_LINK_OK)
|
|
|
|
goto link_failed;
|
|
|
|
priv->recv_rtp_src = gst_object_ref (pad);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
link_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("Stream %p: Failed to link pads %s:%s and %s:%s", stream,
|
|
|
|
GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (priv->sinkpad));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_npt_stop (GstElement * rtpbin, guint session, guint ssrc,
|
|
|
|
GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
/* TODO: What to do here other than this? */
|
|
|
|
GST_DEBUG ("Stream %p: Got EOS", stream);
|
|
|
|
gst_pad_send_event (stream->priv->sinkpad, gst_event_new_eos ());
|
|
|
|
}
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
typedef struct _ProbeData ProbeData;
|
|
|
|
|
|
|
|
struct _ProbeData
|
|
|
|
{
|
|
|
|
GstRTSPStream *stream;
|
|
|
|
/* existing sink, already linked to tee */
|
|
|
|
GstElement *sink1;
|
|
|
|
/* new sink, about to be linked */
|
|
|
|
GstElement *sink2;
|
|
|
|
/* new queue element, that will be linked to tee and sink1 */
|
|
|
|
GstElement **queue1;
|
|
|
|
/* new queue element, that will be linked to tee and sink2 */
|
|
|
|
GstElement **queue2;
|
|
|
|
GstPad *sink_pad;
|
|
|
|
GstPad *tee_pad;
|
|
|
|
guint index;
|
|
|
|
};
|
|
|
|
|
2016-07-22 01:46:16 +00:00
|
|
|
static void
|
2017-10-17 08:44:33 +00:00
|
|
|
free_cb_data (gpointer user_data)
|
2016-07-22 01:46:16 +00:00
|
|
|
{
|
2017-10-17 08:44:33 +00:00
|
|
|
ProbeData *data = user_data;
|
|
|
|
|
|
|
|
gst_object_unref (data->stream);
|
|
|
|
gst_object_unref (data->sink1);
|
|
|
|
gst_object_unref (data->sink2);
|
|
|
|
gst_object_unref (data->sink_pad);
|
|
|
|
gst_object_unref (data->tee_pad);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
2016-07-22 01:46:16 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
static void
|
2017-11-21 08:53:08 +00:00
|
|
|
create_and_plug_queue_to_unlinked_stream (GstRTSPStream * stream,
|
|
|
|
GstElement * tee, GstElement * sink, GstElement ** queue)
|
2017-10-17 08:44:33 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
GstPad *tee_pad;
|
|
|
|
GstPad *queue_pad;
|
|
|
|
GstPad *sink_pad;
|
2016-07-22 01:46:16 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
/* create queue for the new stream */
|
|
|
|
*queue = gst_element_factory_make ("queue", NULL);
|
|
|
|
g_object_set (*queue, "max-size-buffers", 1, "max-size-bytes", 0,
|
2016-07-22 01:46:16 +00:00
|
|
|
"max-size-time", G_GINT64_CONSTANT (0), NULL);
|
2017-10-17 08:44:33 +00:00
|
|
|
gst_bin_add (priv->joined_bin, *queue);
|
2016-07-22 01:46:16 +00:00
|
|
|
|
|
|
|
/* link tee to queue */
|
2021-04-21 08:43:41 +00:00
|
|
|
tee_pad = gst_element_request_pad_simple (tee, "src_%u");
|
2017-10-17 08:44:33 +00:00
|
|
|
queue_pad = gst_element_get_static_pad (*queue, "sink");
|
|
|
|
gst_pad_link (tee_pad, queue_pad);
|
|
|
|
gst_object_unref (queue_pad);
|
|
|
|
gst_object_unref (tee_pad);
|
2016-07-22 01:46:16 +00:00
|
|
|
|
|
|
|
/* link queue to sink */
|
2017-10-17 08:44:33 +00:00
|
|
|
queue_pad = gst_element_get_static_pad (*queue, "src");
|
|
|
|
sink_pad = gst_element_get_static_pad (sink, "sink");
|
|
|
|
gst_pad_link (queue_pad, sink_pad);
|
|
|
|
gst_object_unref (queue_pad);
|
|
|
|
gst_object_unref (sink_pad);
|
|
|
|
|
|
|
|
gst_element_sync_state_with_parent (sink);
|
|
|
|
gst_element_sync_state_with_parent (*queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstPadProbeReturn
|
|
|
|
create_and_plug_queue_to_linked_stream_probe_cb (GstPad * inpad,
|
|
|
|
GstPadProbeInfo * info, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
ProbeData *data = user_data;
|
|
|
|
GstRTSPStream *stream;
|
|
|
|
GstElement **queue1;
|
|
|
|
GstElement **queue2;
|
|
|
|
GstPad *sink_pad;
|
|
|
|
GstPad *tee_pad;
|
|
|
|
GstPad *queue_pad;
|
|
|
|
guint index;
|
|
|
|
|
|
|
|
stream = data->stream;
|
|
|
|
priv = stream->priv;
|
|
|
|
queue1 = data->queue1;
|
|
|
|
queue2 = data->queue2;
|
|
|
|
sink_pad = data->sink_pad;
|
|
|
|
tee_pad = data->tee_pad;
|
|
|
|
index = data->index;
|
|
|
|
|
|
|
|
/* unlink tee and the existing sink:
|
|
|
|
* .-----. .---------.
|
|
|
|
* | tee | | sink1 |
|
|
|
|
* sink src->sink |
|
|
|
|
* '-----' '---------'
|
|
|
|
*/
|
|
|
|
g_assert (gst_pad_unlink (tee_pad, sink_pad));
|
|
|
|
|
|
|
|
/* add queue to the already existing stream */
|
|
|
|
*queue1 = gst_element_factory_make ("queue", NULL);
|
|
|
|
g_object_set (*queue1, "max-size-buffers", 1, "max-size-bytes", 0,
|
|
|
|
"max-size-time", G_GINT64_CONSTANT (0), NULL);
|
|
|
|
gst_bin_add (priv->joined_bin, *queue1);
|
|
|
|
|
|
|
|
/* link tee, queue and sink:
|
|
|
|
* .-----. .---------. .---------.
|
|
|
|
* | tee | | queue1 | | sink1 |
|
|
|
|
* sink src->sink src->sink |
|
|
|
|
* '-----' '---------' '---------'
|
|
|
|
*/
|
|
|
|
queue_pad = gst_element_get_static_pad (*queue1, "sink");
|
|
|
|
gst_pad_link (tee_pad, queue_pad);
|
|
|
|
gst_object_unref (queue_pad);
|
|
|
|
queue_pad = gst_element_get_static_pad (*queue1, "src");
|
|
|
|
gst_pad_link (queue_pad, sink_pad);
|
|
|
|
gst_object_unref (queue_pad);
|
|
|
|
|
|
|
|
gst_element_sync_state_with_parent (*queue1);
|
|
|
|
|
|
|
|
/* create queue and link it to tee and the new sink */
|
|
|
|
create_and_plug_queue_to_unlinked_stream (stream,
|
|
|
|
priv->tee[index], data->sink2, queue2);
|
|
|
|
|
|
|
|
/* the final stream:
|
|
|
|
*
|
|
|
|
* .-----. .---------. .---------.
|
|
|
|
* | tee | | queue1 | | sink1 |
|
|
|
|
* sink src->sink src->sink |
|
|
|
|
* | | '---------' '---------'
|
|
|
|
* | | .---------. .---------.
|
|
|
|
* | | | queue2 | | sink2 |
|
|
|
|
* | src->sink src->sink |
|
|
|
|
* '-----' '---------' '---------'
|
|
|
|
*/
|
|
|
|
|
|
|
|
return GST_PAD_PROBE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-11-21 08:53:08 +00:00
|
|
|
create_and_plug_queue_to_linked_stream (GstRTSPStream * stream,
|
|
|
|
GstElement * sink1, GstElement * sink2, guint index, GstElement ** queue1,
|
2017-10-17 08:44:33 +00:00
|
|
|
GstElement ** queue2)
|
|
|
|
{
|
|
|
|
ProbeData *data;
|
|
|
|
|
|
|
|
data = g_new0 (ProbeData, 1);
|
|
|
|
data->stream = gst_object_ref (stream);
|
|
|
|
data->sink1 = gst_object_ref (sink1);
|
|
|
|
data->sink2 = gst_object_ref (sink2);
|
|
|
|
data->queue1 = queue1;
|
|
|
|
data->queue2 = queue2;
|
|
|
|
data->index = index;
|
|
|
|
|
2017-11-21 08:53:08 +00:00
|
|
|
data->sink_pad = gst_element_get_static_pad (sink1, "sink");
|
2017-10-17 08:44:33 +00:00
|
|
|
g_assert (data->sink_pad);
|
|
|
|
data->tee_pad = gst_pad_get_peer (data->sink_pad);
|
|
|
|
g_assert (data->tee_pad);
|
|
|
|
|
|
|
|
gst_pad_add_probe (data->tee_pad, GST_PAD_PROBE_TYPE_IDLE,
|
|
|
|
create_and_plug_queue_to_linked_stream_probe_cb, data, free_cb_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
plug_udp_sink (GstRTSPStream * stream, GstElement * sink_to_plug,
|
|
|
|
GstElement ** queue_to_plug, guint index, gboolean is_mcast)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
GstElement *existing_sink;
|
|
|
|
|
|
|
|
if (is_mcast)
|
|
|
|
existing_sink = priv->udpsink[index];
|
|
|
|
else
|
|
|
|
existing_sink = priv->mcast_udpsink[index];
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "plug %s sink", is_mcast ? "mcast" : "udp");
|
|
|
|
|
|
|
|
/* add sink to the bin */
|
|
|
|
gst_bin_add (priv->joined_bin, sink_to_plug);
|
|
|
|
|
|
|
|
if (priv->appsink[index] && existing_sink) {
|
|
|
|
|
|
|
|
/* queues are already added for the existing stream, add one for
|
|
|
|
the newly added udp stream */
|
|
|
|
create_and_plug_queue_to_unlinked_stream (stream, priv->tee[index],
|
|
|
|
sink_to_plug, queue_to_plug);
|
|
|
|
|
|
|
|
} else if (priv->appsink[index] || existing_sink) {
|
|
|
|
GstElement **queue;
|
|
|
|
GstElement *element;
|
|
|
|
|
|
|
|
/* add queue to the already existing stream plus the newly created udp
|
|
|
|
stream */
|
|
|
|
if (priv->appsink[index]) {
|
|
|
|
element = priv->appsink[index];
|
|
|
|
queue = &priv->appqueue[index];
|
|
|
|
} else {
|
|
|
|
element = existing_sink;
|
|
|
|
if (is_mcast)
|
|
|
|
queue = &priv->udpqueue[index];
|
|
|
|
else
|
|
|
|
queue = &priv->mcast_udpqueue[index];
|
|
|
|
}
|
|
|
|
|
2017-11-21 08:53:08 +00:00
|
|
|
create_and_plug_queue_to_linked_stream (stream, element, sink_to_plug,
|
|
|
|
index, queue, queue_to_plug);
|
2017-10-17 08:44:33 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
GstPad *tee_pad;
|
|
|
|
GstPad *sink_pad;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "creating first stream");
|
|
|
|
|
|
|
|
/* no need to add queues */
|
2021-04-21 08:43:41 +00:00
|
|
|
tee_pad = gst_element_request_pad_simple (priv->tee[index], "src_%u");
|
2017-10-17 08:44:33 +00:00
|
|
|
sink_pad = gst_element_get_static_pad (sink_to_plug, "sink");
|
|
|
|
gst_pad_link (tee_pad, sink_pad);
|
|
|
|
gst_object_unref (tee_pad);
|
|
|
|
gst_object_unref (sink_pad);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_sync_state_with_parent (sink_to_plug);
|
2016-07-22 01:46:16 +00:00
|
|
|
}
|
|
|
|
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
static void
|
2017-10-17 08:44:33 +00:00
|
|
|
plug_tcp_sink (GstRTSPStream * stream, guint index)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "plug tcp sink");
|
|
|
|
|
|
|
|
/* add sink to the bin */
|
|
|
|
gst_bin_add (priv->joined_bin, priv->appsink[index]);
|
|
|
|
|
|
|
|
if (priv->mcast_udpsink[index] && priv->udpsink[index]) {
|
|
|
|
|
|
|
|
/* queues are already added for the existing stream, add one for
|
|
|
|
the newly added tcp stream */
|
|
|
|
create_and_plug_queue_to_unlinked_stream (stream,
|
2017-11-21 08:53:08 +00:00
|
|
|
priv->tee[index], priv->appsink[index], &priv->appqueue[index]);
|
2017-10-17 08:44:33 +00:00
|
|
|
|
|
|
|
} else if (priv->mcast_udpsink[index] || priv->udpsink[index]) {
|
|
|
|
GstElement **queue;
|
|
|
|
GstElement *element;
|
|
|
|
|
|
|
|
/* add queue to the already existing stream plus the newly created tcp
|
|
|
|
stream */
|
|
|
|
if (priv->mcast_udpsink[index]) {
|
|
|
|
element = priv->mcast_udpsink[index];
|
|
|
|
queue = &priv->mcast_udpqueue[index];
|
|
|
|
} else {
|
|
|
|
element = priv->udpsink[index];
|
|
|
|
queue = &priv->udpqueue[index];
|
|
|
|
}
|
|
|
|
|
2017-11-21 08:53:08 +00:00
|
|
|
create_and_plug_queue_to_linked_stream (stream, element,
|
|
|
|
priv->appsink[index], index, queue, &priv->appqueue[index]);
|
2017-10-17 08:44:33 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
GstPad *tee_pad;
|
|
|
|
GstPad *sink_pad;
|
|
|
|
|
|
|
|
/* no need to add queues */
|
2021-04-21 08:43:41 +00:00
|
|
|
tee_pad = gst_element_request_pad_simple (priv->tee[index], "src_%u");
|
2017-10-17 08:44:33 +00:00
|
|
|
sink_pad = gst_element_get_static_pad (priv->appsink[index], "sink");
|
|
|
|
gst_pad_link (tee_pad, sink_pad);
|
|
|
|
gst_object_unref (tee_pad);
|
|
|
|
gst_object_unref (sink_pad);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_sync_state_with_parent (priv->appsink[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
plug_sink (GstRTSPStream * stream, const GstRTSPTransport * transport,
|
|
|
|
guint index)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gboolean is_tcp, is_udp, is_mcast;
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
is_tcp = transport->lower_transport == GST_RTSP_LOWER_TRANS_TCP;
|
|
|
|
is_udp = transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP;
|
|
|
|
is_mcast = transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST;
|
|
|
|
|
|
|
|
if (is_udp)
|
|
|
|
plug_udp_sink (stream, priv->udpsink[index],
|
|
|
|
&priv->udpqueue[index], index, FALSE);
|
|
|
|
|
|
|
|
else if (is_mcast)
|
|
|
|
plug_udp_sink (stream, priv->mcast_udpsink[index],
|
|
|
|
&priv->mcast_udpqueue[index], index, TRUE);
|
|
|
|
|
|
|
|
else if (is_tcp)
|
|
|
|
plug_tcp_sink (stream, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called with lock */
|
|
|
|
static gboolean
|
|
|
|
create_sender_part (GstRTSPStream * stream, const GstRTSPTransport * transport)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2016-07-22 01:46:16 +00:00
|
|
|
GstPad *pad;
|
2017-10-17 08:44:33 +00:00
|
|
|
GstBin *bin;
|
|
|
|
gboolean is_tcp, is_udp, is_mcast;
|
2017-12-19 09:34:37 +00:00
|
|
|
gint mcast_ttl = 0;
|
2015-11-19 13:09:25 +00:00
|
|
|
gint i;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
GST_DEBUG_OBJECT (stream, "create sender part");
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2017-10-17 08:44:33 +00:00
|
|
|
bin = priv->joined_bin;
|
|
|
|
|
|
|
|
is_tcp = transport->lower_transport == GST_RTSP_LOWER_TRANS_TCP;
|
|
|
|
is_udp = transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP;
|
|
|
|
is_mcast = transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST;
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2017-12-19 09:34:37 +00:00
|
|
|
if (is_mcast)
|
|
|
|
mcast_ttl = transport->ttl;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "tcp: %d, udp: %d, mcast: %d (ttl: %d)", is_tcp,
|
|
|
|
is_udp, is_mcast, mcast_ttl);
|
2017-10-17 08:44:33 +00:00
|
|
|
|
|
|
|
if (is_udp && !priv->server_addr_v4 && !priv->server_addr_v6) {
|
|
|
|
GST_WARNING_OBJECT (stream, "no sockets assigned for UDP");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_mcast && !priv->mcast_addr_v4 && !priv->mcast_addr_v6) {
|
|
|
|
GST_WARNING_OBJECT (stream, "no sockets assigned for UDP multicast");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-12-04 07:01:37 +00:00
|
|
|
|
2019-04-04 22:48:07 +00:00
|
|
|
if (g_object_class_find_property (G_OBJECT_GET_CLASS (priv->payloader),
|
|
|
|
"onvif-no-rate-control"))
|
|
|
|
g_object_set (priv->payloader, "onvif-no-rate-control",
|
|
|
|
!priv->do_rate_control, NULL);
|
|
|
|
|
2020-09-04 19:14:35 +00:00
|
|
|
for (i = 0; i < (priv->enable_rtcp ? 2 : 1); i++) {
|
2017-10-17 08:44:33 +00:00
|
|
|
gboolean link_tee = FALSE;
|
2012-10-26 15:28:10 +00:00
|
|
|
/* For the sender we create this bit of pipeline for both
|
2020-09-04 19:14:35 +00:00
|
|
|
* RTP and RTCP (when enabled).
|
2017-10-17 08:44:33 +00:00
|
|
|
* Initially there will be only one active transport for
|
|
|
|
* the stream, so the pipeline will look like this:
|
|
|
|
*
|
|
|
|
* .--------. .-----. .---------.
|
|
|
|
* | rtpbin | | tee | | sink |
|
|
|
|
* | send->sink src->sink |
|
|
|
|
* '--------' '-----' '---------'
|
|
|
|
*
|
|
|
|
* For each new transport, the already existing branch will
|
|
|
|
* be reconfigured by adding a queue element:
|
2012-10-26 15:28:10 +00:00
|
|
|
*
|
2015-03-23 19:59:52 +00:00
|
|
|
* .--------. .-----. .---------. .---------.
|
|
|
|
* | rtpbin | | tee | | queue | | udpsink |
|
|
|
|
* | send->sink src->sink src->sink |
|
|
|
|
* '--------' | | '---------' '---------'
|
2012-10-26 15:28:10 +00:00
|
|
|
* | | .---------. .---------.
|
2017-10-17 08:44:33 +00:00
|
|
|
* | | | queue | | udpsink |
|
|
|
|
* | src->sink src->sink |
|
|
|
|
* | | '---------' '---------'
|
|
|
|
* | | .---------. .---------.
|
2012-10-26 15:28:10 +00:00
|
|
|
* | | | queue | | appsink |
|
|
|
|
* | src->sink src->sink |
|
|
|
|
* '-----' '---------' '---------'
|
|
|
|
*/
|
2016-07-20 19:11:32 +00:00
|
|
|
|
2015-11-19 13:01:16 +00:00
|
|
|
/* Only link the RTP send src if we're going to send RTP, link
|
|
|
|
* the RTCP send src always */
|
2016-07-20 19:11:32 +00:00
|
|
|
if (!priv->srcpad && i == 0)
|
|
|
|
continue;
|
2015-12-04 07:01:37 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if (!priv->tee[i]) {
|
|
|
|
/* make tee for RTP/RTCP */
|
|
|
|
priv->tee[i] = gst_element_factory_make ("tee", NULL);
|
|
|
|
gst_bin_add (bin, priv->tee[i]);
|
|
|
|
link_tee = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_udp && !priv->udpsink[i]) {
|
|
|
|
/* we create only one pair of udpsinks for IPv4 and IPv6 */
|
2017-11-21 08:53:08 +00:00
|
|
|
create_and_configure_udpsink (stream, &priv->udpsink[i],
|
2017-12-19 09:34:37 +00:00
|
|
|
priv->socket_v4[i], priv->socket_v6[i], FALSE, (i == 0), mcast_ttl);
|
2017-10-17 08:44:33 +00:00
|
|
|
plug_sink (stream, transport, i);
|
|
|
|
} else if (is_mcast && !priv->mcast_udpsink[i]) {
|
|
|
|
/* we create only one pair of mcast-udpsinks for IPv4 and IPv6 */
|
|
|
|
create_and_configure_udpsink (stream, &priv->mcast_udpsink[i],
|
2017-12-19 09:34:37 +00:00
|
|
|
priv->mcast_socket_v4[i], priv->mcast_socket_v6[i], TRUE, (i == 0),
|
|
|
|
mcast_ttl);
|
2017-10-17 08:44:33 +00:00
|
|
|
plug_sink (stream, transport, i);
|
|
|
|
} else if (is_tcp && !priv->appsink[i]) {
|
2016-07-20 19:11:32 +00:00
|
|
|
/* make appsink */
|
|
|
|
priv->appsink[i] = gst_element_factory_make ("appsink", NULL);
|
2018-06-27 10:17:07 +00:00
|
|
|
g_object_set (priv->appsink[i], "emit-signals", FALSE, "buffer-list",
|
|
|
|
TRUE, "max-buffers", 1, NULL);
|
2017-10-17 08:44:33 +00:00
|
|
|
|
2019-04-04 22:48:07 +00:00
|
|
|
if (i == 0)
|
|
|
|
g_object_set (priv->appsink[i], "sync", priv->do_rate_control, NULL);
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
/* we need to set sync and preroll to FALSE for the sink to avoid
|
|
|
|
* deadlock. This is only needed for sink sending RTCP data. */
|
|
|
|
if (i == 1)
|
2017-11-21 08:53:08 +00:00
|
|
|
g_object_set (priv->appsink[i], "async", FALSE, "sync", FALSE, NULL);
|
2017-10-17 08:44:33 +00:00
|
|
|
|
2016-07-20 19:11:32 +00:00
|
|
|
gst_app_sink_set_callbacks (GST_APP_SINK_CAST (priv->appsink[i]),
|
|
|
|
&sink_cb, stream, NULL);
|
2017-10-17 08:44:33 +00:00
|
|
|
plug_sink (stream, transport, i);
|
2016-07-20 19:11:32 +00:00
|
|
|
}
|
2015-11-19 13:01:16 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if (link_tee) {
|
2016-07-20 19:11:32 +00:00
|
|
|
/* and link to rtpbin send pad */
|
2017-10-17 08:44:33 +00:00
|
|
|
gst_element_sync_state_with_parent (priv->tee[i]);
|
2016-07-20 19:11:32 +00:00
|
|
|
pad = gst_element_get_static_pad (priv->tee[i], "sink");
|
|
|
|
gst_pad_link (priv->send_src[i], pad);
|
|
|
|
gst_object_unref (pad);
|
2015-11-19 13:09:25 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2015-11-19 13:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called with lock */
|
|
|
|
static void
|
2016-07-28 19:20:31 +00:00
|
|
|
plug_src (GstRTSPStream * stream, GstBin * bin, GstElement * src,
|
|
|
|
GstElement * funnel)
|
2015-11-19 13:09:25 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstPad *pad, *selpad;
|
2018-06-27 06:30:42 +00:00
|
|
|
gulong id = 0;
|
2016-07-28 19:20:31 +00:00
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
2018-12-05 14:07:25 +00:00
|
|
|
/* add src */
|
|
|
|
gst_bin_add (bin, src);
|
|
|
|
|
2018-06-27 06:30:42 +00:00
|
|
|
pad = gst_element_get_static_pad (src, "src");
|
2016-07-28 19:20:31 +00:00
|
|
|
if (priv->srcpad) {
|
2018-06-27 06:30:42 +00:00
|
|
|
/* block pad so src can't push data while it's not yet linked */
|
|
|
|
id = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BLOCK |
|
|
|
|
GST_PAD_PROBE_TYPE_BUFFER, NULL, NULL, NULL);
|
2016-07-28 19:20:31 +00:00
|
|
|
/* we set and keep these to playing so that they don't cause NO_PREROLL return
|
|
|
|
* values. This is only relevant for PLAY pipelines */
|
|
|
|
gst_element_set_state (src, GST_STATE_PLAYING);
|
|
|
|
gst_element_set_locked_state (src, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and link to the funnel */
|
2021-04-21 08:43:41 +00:00
|
|
|
selpad = gst_element_request_pad_simple (funnel, "sink_%u");
|
2016-07-28 19:20:31 +00:00
|
|
|
gst_pad_link (pad, selpad);
|
2018-06-27 06:30:42 +00:00
|
|
|
if (id != 0)
|
|
|
|
gst_pad_remove_probe (pad, id);
|
2016-07-28 19:20:31 +00:00
|
|
|
gst_object_unref (pad);
|
|
|
|
gst_object_unref (selpad);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called with lock */
|
2017-10-17 08:44:33 +00:00
|
|
|
static gboolean
|
|
|
|
create_receiver_part (GstRTSPStream * stream, const GstRTSPTransport *
|
|
|
|
transport)
|
2016-07-28 19:20:31 +00:00
|
|
|
{
|
2020-07-02 21:52:47 +00:00
|
|
|
gboolean ret = FALSE;
|
2016-07-28 19:20:31 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstPad *pad;
|
2017-10-17 08:44:33 +00:00
|
|
|
GstBin *bin;
|
|
|
|
gboolean tcp;
|
|
|
|
gboolean udp;
|
|
|
|
gboolean mcast;
|
2020-07-02 21:52:47 +00:00
|
|
|
gboolean secure;
|
2015-11-19 13:09:25 +00:00
|
|
|
gint i;
|
2020-07-02 21:52:47 +00:00
|
|
|
GstCaps *rtp_caps;
|
|
|
|
GstCaps *rtcp_caps;
|
2015-11-19 13:09:25 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
GST_DEBUG_OBJECT (stream, "create receiver part");
|
2015-11-19 13:09:25 +00:00
|
|
|
priv = stream->priv;
|
2017-10-17 08:44:33 +00:00
|
|
|
bin = priv->joined_bin;
|
2015-11-19 13:09:25 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
tcp = transport->lower_transport == GST_RTSP_LOWER_TRANS_TCP;
|
|
|
|
udp = transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP;
|
|
|
|
mcast = transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST;
|
2020-07-02 21:52:47 +00:00
|
|
|
secure = (priv->profiles & GST_RTSP_PROFILE_SAVP)
|
|
|
|
|| (priv->profiles & GST_RTSP_PROFILE_SAVPF);
|
|
|
|
|
|
|
|
if (secure) {
|
|
|
|
rtp_caps = gst_caps_new_empty_simple ("application/x-srtp");
|
|
|
|
rtcp_caps = gst_caps_new_empty_simple ("application/x-srtcp");
|
|
|
|
} else {
|
|
|
|
rtp_caps = gst_caps_new_empty_simple ("application/x-rtp");
|
|
|
|
rtcp_caps = gst_caps_new_empty_simple ("application/x-rtcp");
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream,
|
|
|
|
"RTP caps: %" GST_PTR_FORMAT " RTCP caps: %" GST_PTR_FORMAT, rtp_caps,
|
|
|
|
rtcp_caps);
|
2015-11-19 13:09:25 +00:00
|
|
|
|
2020-09-04 19:14:35 +00:00
|
|
|
for (i = 0; i < (priv->enable_rtcp ? 2 : 1); i++) {
|
2016-07-20 19:11:32 +00:00
|
|
|
/* For the receiver we create this bit of pipeline for both
|
2020-09-04 19:14:35 +00:00
|
|
|
* RTP and RTCP (when enabled). We receive RTP/RTCP on appsrc and udpsrc
|
2016-07-20 19:11:32 +00:00
|
|
|
* and it is all funneled into the rtpbin receive pad.
|
|
|
|
*
|
2017-10-17 08:44:33 +00:00
|
|
|
*
|
2016-07-20 19:11:32 +00:00
|
|
|
* .--------. .--------. .--------.
|
|
|
|
* | udpsrc | | funnel | | rtpbin |
|
2017-10-17 08:44:33 +00:00
|
|
|
* | RTP src->sink src->sink |
|
|
|
|
* '--------' | | | |
|
|
|
|
* .--------. | | | |
|
|
|
|
* | appsrc | | | | |
|
|
|
|
* | RTP src->sink | | |
|
|
|
|
* '--------' '--------' | |
|
|
|
|
* | |
|
|
|
|
* .--------. .--------. | |
|
|
|
|
* | udpsrc | | funnel | | |
|
|
|
|
* | RTCP src->sink src->sink |
|
2016-07-20 19:11:32 +00:00
|
|
|
* '--------' | | '--------'
|
|
|
|
* .--------. | |
|
|
|
|
* | appsrc | | |
|
2017-10-17 08:44:33 +00:00
|
|
|
* | RTCP src->sink |
|
2016-07-20 19:11:32 +00:00
|
|
|
* '--------' '--------'
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!priv->sinkpad && i == 0) {
|
|
|
|
/* Only connect recv RTP sink if we expect to receive RTP. Connect recv
|
|
|
|
* RTCP sink always */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make funnel for the RTP/RTCP receivers */
|
2018-06-19 22:10:18 +00:00
|
|
|
if (!priv->funnel[i]) {
|
|
|
|
priv->funnel[i] = gst_element_factory_make ("funnel", NULL);
|
|
|
|
gst_bin_add (bin, priv->funnel[i]);
|
2013-05-30 06:07:48 +00:00
|
|
|
|
2018-06-19 22:10:18 +00:00
|
|
|
pad = gst_element_get_static_pad (priv->funnel[i], "src");
|
|
|
|
gst_pad_link (pad, priv->recv_sink[i]);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
}
|
2016-07-20 19:11:32 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if (udp && !priv->udpsrc_v4[i] && priv->server_addr_v4) {
|
|
|
|
GST_DEBUG_OBJECT (stream, "udp IPv4, create and configure udpsources");
|
|
|
|
if (!create_and_configure_udpsource (&priv->udpsrc_v4[i],
|
2017-11-21 08:53:08 +00:00
|
|
|
priv->socket_v4[i]))
|
2020-07-02 21:52:47 +00:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
g_object_set (priv->udpsrc_v4[i], "caps", rtp_caps, NULL);
|
|
|
|
} else {
|
|
|
|
g_object_set (priv->udpsrc_v4[i], "caps", rtcp_caps, NULL);
|
2021-07-05 09:54:18 +00:00
|
|
|
|
|
|
|
/* block early rtcp packets, pipeline not ready */
|
|
|
|
g_assert (priv->block_early_rtcp_pad == NULL);
|
|
|
|
priv->block_early_rtcp_pad = gst_element_get_static_pad
|
|
|
|
(priv->udpsrc_v4[i], "src");
|
|
|
|
priv->block_early_rtcp_probe = gst_pad_add_probe
|
|
|
|
(priv->block_early_rtcp_pad,
|
|
|
|
GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER, NULL, NULL,
|
|
|
|
NULL);
|
2020-07-02 21:52:47 +00:00
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
|
2016-07-28 19:20:31 +00:00
|
|
|
plug_src (stream, bin, priv->udpsrc_v4[i], priv->funnel[i]);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (udp && !priv->udpsrc_v6[i] && priv->server_addr_v6) {
|
|
|
|
GST_DEBUG_OBJECT (stream, "udp IPv6, create and configure udpsources");
|
|
|
|
if (!create_and_configure_udpsource (&priv->udpsrc_v6[i],
|
2017-11-21 08:53:08 +00:00
|
|
|
priv->socket_v6[i]))
|
2020-07-02 21:52:47 +00:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
g_object_set (priv->udpsrc_v6[i], "caps", rtp_caps, NULL);
|
|
|
|
} else {
|
|
|
|
g_object_set (priv->udpsrc_v6[i], "caps", rtcp_caps, NULL);
|
2021-07-05 09:54:18 +00:00
|
|
|
|
|
|
|
/* block early rtcp packets, pipeline not ready */
|
|
|
|
g_assert (priv->block_early_rtcp_pad_ipv6 == NULL);
|
|
|
|
priv->block_early_rtcp_pad_ipv6 = gst_element_get_static_pad
|
|
|
|
(priv->udpsrc_v6[i], "src");
|
|
|
|
priv->block_early_rtcp_probe_ipv6 = gst_pad_add_probe
|
|
|
|
(priv->block_early_rtcp_pad_ipv6,
|
|
|
|
GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER, NULL, NULL,
|
|
|
|
NULL);
|
2020-07-02 21:52:47 +00:00
|
|
|
}
|
2016-07-21 00:09:57 +00:00
|
|
|
|
2016-07-28 19:20:31 +00:00
|
|
|
plug_src (stream, bin, priv->udpsrc_v6[i], priv->funnel[i]);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
2016-07-20 19:11:32 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if (mcast && !priv->mcast_udpsrc_v4[i] && priv->mcast_addr_v4) {
|
|
|
|
GST_DEBUG_OBJECT (stream, "mcast IPv4, create and configure udpsources");
|
|
|
|
if (!create_and_configure_udpsource (&priv->mcast_udpsrc_v4[i],
|
2017-11-21 08:53:08 +00:00
|
|
|
priv->mcast_socket_v4[i]))
|
2020-07-02 21:52:47 +00:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
g_object_set (priv->mcast_udpsrc_v4[i], "caps", rtp_caps, NULL);
|
|
|
|
} else {
|
|
|
|
g_object_set (priv->mcast_udpsrc_v4[i], "caps", rtcp_caps, NULL);
|
|
|
|
}
|
|
|
|
|
2016-09-05 15:04:50 +00:00
|
|
|
plug_src (stream, bin, priv->mcast_udpsrc_v4[i], priv->funnel[i]);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
2016-09-05 15:04:50 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if (mcast && !priv->mcast_udpsrc_v6[i] && priv->mcast_addr_v6) {
|
|
|
|
GST_DEBUG_OBJECT (stream, "mcast IPv6, create and configure udpsources");
|
|
|
|
if (!create_and_configure_udpsource (&priv->mcast_udpsrc_v6[i],
|
2017-11-21 08:53:08 +00:00
|
|
|
priv->mcast_socket_v6[i]))
|
2020-07-02 21:52:47 +00:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
g_object_set (priv->mcast_udpsrc_v6[i], "caps", rtp_caps, NULL);
|
|
|
|
} else {
|
|
|
|
g_object_set (priv->mcast_udpsrc_v6[i], "caps", rtcp_caps, NULL);
|
|
|
|
}
|
|
|
|
|
2016-09-05 15:04:50 +00:00
|
|
|
plug_src (stream, bin, priv->mcast_udpsrc_v6[i], priv->funnel[i]);
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
2016-09-05 15:04:50 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
if (tcp && !priv->appsrc[i]) {
|
2016-07-20 19:11:32 +00:00
|
|
|
/* make and add appsrc */
|
|
|
|
priv->appsrc[i] = gst_element_factory_make ("appsrc", NULL);
|
|
|
|
priv->appsrc_base_time[i] = -1;
|
|
|
|
g_object_set (priv->appsrc[i], "format", GST_FORMAT_TIME, "is-live",
|
|
|
|
TRUE, NULL);
|
2016-07-28 19:20:31 +00:00
|
|
|
plug_src (stream, bin, priv->appsrc[i], priv->funnel[i]);
|
2013-08-16 15:05:24 +00:00
|
|
|
}
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
gst_element_sync_state_with_parent (priv->funnel[i]);
|
2012-10-26 15:28:10 +00:00
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
|
2020-07-02 21:52:47 +00:00
|
|
|
ret = TRUE;
|
2017-10-17 08:44:33 +00:00
|
|
|
|
2020-07-02 21:52:47 +00:00
|
|
|
done:
|
|
|
|
gst_caps_unref (rtp_caps);
|
|
|
|
gst_caps_unref (rtcp_caps);
|
|
|
|
return ret;
|
2015-11-19 13:09:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 22:30:42 +00:00
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_is_tcp_receiver (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
ret = (priv->sinkpad != NULL && priv->appsrc[0] != NULL);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
static gboolean
|
2018-07-26 10:01:16 +00:00
|
|
|
check_mcast_client_addr (GstRTSPStream * stream, const GstRTSPTransport * tr)
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2018-07-26 10:01:16 +00:00
|
|
|
GList *walk;
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
2018-07-26 10:01:16 +00:00
|
|
|
if (priv->mcast_clients == NULL)
|
|
|
|
goto no_addr;
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
2018-07-26 10:01:16 +00:00
|
|
|
if (tr == NULL)
|
|
|
|
goto no_transport;
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
2018-07-26 10:01:16 +00:00
|
|
|
if (tr->destination == NULL)
|
|
|
|
goto no_destination;
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
2018-07-26 10:01:16 +00:00
|
|
|
for (walk = priv->mcast_clients; walk; walk = g_list_next (walk)) {
|
|
|
|
UdpClientAddrInfo *cli = walk->data;
|
2018-07-25 13:33:18 +00:00
|
|
|
|
2018-07-26 10:01:16 +00:00
|
|
|
if ((g_strcmp0 (cli->address, tr->destination) == 0) &&
|
|
|
|
(cli->rtp_port == tr->port.min))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
|
|
|
no_addr:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (stream, "Adding mcast transport, but no mcast address "
|
|
|
|
"has been reserved");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-07-26 10:01:16 +00:00
|
|
|
no_transport:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (stream, "Adding mcast transport, but no transport "
|
|
|
|
"has been provided");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_destination:
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (stream, "Adding mcast transport, but it doesn't match "
|
|
|
|
"the reserved address");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-19 13:09:25 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_join_bin:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @bin: (transfer none): a #GstBin to join
|
|
|
|
* @rtpbin: (transfer none): a rtpbin element in @bin
|
|
|
|
* @state: the target state of the new elements
|
|
|
|
*
|
|
|
|
* Join the #GstBin @bin that contains the element @rtpbin.
|
|
|
|
*
|
|
|
|
* @stream will link to @rtpbin, which must be inside @bin. The elements
|
|
|
|
* added to @bin will be set to the state given in @state.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_join_bin (GstRTSPStream * stream, GstBin * bin,
|
|
|
|
GstElement * rtpbin, GstState state)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
guint idx;
|
|
|
|
gchar *name;
|
|
|
|
GstPadLinkReturn ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_ELEMENT (rtpbin), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2016-07-14 15:10:31 +00:00
|
|
|
if (priv->joined_bin != NULL)
|
2015-11-19 13:09:25 +00:00
|
|
|
goto was_joined;
|
|
|
|
|
|
|
|
/* create a session with the same index as the stream */
|
|
|
|
idx = priv->idx;
|
|
|
|
|
|
|
|
GST_INFO ("stream %p joining bin as session %u", stream, idx);
|
|
|
|
|
|
|
|
if (priv->profiles & GST_RTSP_PROFILE_SAVP
|
|
|
|
|| priv->profiles & GST_RTSP_PROFILE_SAVPF) {
|
|
|
|
/* For SRTP */
|
|
|
|
g_signal_connect (rtpbin, "request-rtp-encoder",
|
|
|
|
(GCallback) request_rtp_encoder, stream);
|
|
|
|
g_signal_connect (rtpbin, "request-rtcp-encoder",
|
|
|
|
(GCallback) request_rtcp_encoder, stream);
|
|
|
|
g_signal_connect (rtpbin, "request-rtp-decoder",
|
|
|
|
(GCallback) request_rtp_rtcp_decoder, stream);
|
|
|
|
g_signal_connect (rtpbin, "request-rtcp-decoder",
|
|
|
|
(GCallback) request_rtp_rtcp_decoder, stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->sinkpad) {
|
|
|
|
g_signal_connect (rtpbin, "request-pt-map",
|
|
|
|
(GCallback) request_pt_map, stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get pads from the RTP session element for sending and receiving
|
|
|
|
* RTP/RTCP*/
|
|
|
|
if (priv->srcpad) {
|
|
|
|
/* get a pad for sending RTP */
|
|
|
|
name = g_strdup_printf ("send_rtp_sink_%u", idx);
|
2021-04-21 08:43:41 +00:00
|
|
|
priv->send_rtp_sink = gst_element_request_pad_simple (rtpbin, name);
|
2015-11-19 13:09:25 +00:00
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
/* link the RTP pad to the session manager, it should not really fail unless
|
|
|
|
* this is not really an RTP pad */
|
|
|
|
ret = gst_pad_link (priv->srcpad, priv->send_rtp_sink);
|
|
|
|
if (ret != GST_PAD_LINK_OK)
|
|
|
|
goto link_failed;
|
|
|
|
|
|
|
|
name = g_strdup_printf ("send_rtp_src_%u", idx);
|
|
|
|
priv->send_src[0] = gst_element_get_static_pad (rtpbin, name);
|
|
|
|
g_free (name);
|
|
|
|
} else {
|
2017-10-17 08:44:33 +00:00
|
|
|
/* RECORD case: need to connect our sinkpad from here */
|
2015-11-19 13:09:25 +00:00
|
|
|
g_signal_connect (rtpbin, "pad-added", (GCallback) pad_added, stream);
|
|
|
|
/* EOS */
|
|
|
|
g_signal_connect (rtpbin, "on-npt-stop", (GCallback) on_npt_stop, stream);
|
|
|
|
|
|
|
|
name = g_strdup_printf ("recv_rtp_sink_%u", idx);
|
2021-04-21 08:43:41 +00:00
|
|
|
priv->recv_sink[0] = gst_element_request_pad_simple (rtpbin, name);
|
2015-11-19 13:09:25 +00:00
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
2020-09-04 19:14:35 +00:00
|
|
|
if (priv->enable_rtcp) {
|
|
|
|
name = g_strdup_printf ("send_rtcp_src_%u", idx);
|
2021-04-21 08:43:41 +00:00
|
|
|
priv->send_src[1] = gst_element_request_pad_simple (rtpbin, name);
|
2020-09-04 19:14:35 +00:00
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
name = g_strdup_printf ("recv_rtcp_sink_%u", idx);
|
2021-04-21 08:43:41 +00:00
|
|
|
priv->recv_sink[1] = gst_element_request_pad_simple (rtpbin, name);
|
2020-09-04 19:14:35 +00:00
|
|
|
g_free (name);
|
|
|
|
}
|
2015-11-19 13:09:25 +00:00
|
|
|
|
|
|
|
/* get the session */
|
|
|
|
g_signal_emit_by_name (rtpbin, "get-internal-session", idx, &priv->session);
|
|
|
|
|
|
|
|
g_signal_connect (priv->session, "on-new-ssrc", (GCallback) on_new_ssrc,
|
|
|
|
stream);
|
|
|
|
g_signal_connect (priv->session, "on-ssrc-sdes", (GCallback) on_ssrc_sdes,
|
|
|
|
stream);
|
|
|
|
g_signal_connect (priv->session, "on-ssrc-active",
|
|
|
|
(GCallback) on_ssrc_active, stream);
|
|
|
|
g_signal_connect (priv->session, "on-bye-ssrc", (GCallback) on_bye_ssrc,
|
|
|
|
stream);
|
|
|
|
g_signal_connect (priv->session, "on-bye-timeout",
|
|
|
|
(GCallback) on_bye_timeout, stream);
|
|
|
|
g_signal_connect (priv->session, "on-timeout", (GCallback) on_timeout,
|
|
|
|
stream);
|
|
|
|
|
|
|
|
/* signal for sender ssrc */
|
|
|
|
g_signal_connect (priv->session, "on-new-sender-ssrc",
|
|
|
|
(GCallback) on_new_sender_ssrc, stream);
|
|
|
|
g_signal_connect (priv->session, "on-sender-ssrc-active",
|
|
|
|
(GCallback) on_sender_ssrc_active, stream);
|
|
|
|
|
2019-04-04 22:48:07 +00:00
|
|
|
g_object_set (priv->session, "disable-sr-timestamp", !priv->do_rate_control,
|
|
|
|
NULL);
|
|
|
|
|
2015-11-19 13:01:16 +00:00
|
|
|
if (priv->srcpad) {
|
|
|
|
/* be notified of caps changes */
|
|
|
|
priv->caps_sig = g_signal_connect (priv->send_src[0], "notify::caps",
|
|
|
|
(GCallback) caps_notify, stream);
|
2016-10-06 15:47:50 +00:00
|
|
|
priv->caps = gst_pad_get_current_caps (priv->send_src[0]);
|
2015-11-19 13:01:16 +00:00
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2016-09-07 14:12:18 +00:00
|
|
|
priv->joined_bin = bin;
|
2017-10-17 08:44:33 +00:00
|
|
|
GST_DEBUG_OBJECT (stream, "successfully joined bin");
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2012-11-13 10:14:49 +00:00
|
|
|
was_joined:
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
link_failed:
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
GST_WARNING ("failed to link stream %u", idx);
|
2012-11-29 10:11:05 +00:00
|
|
|
gst_object_unref (priv->send_rtp_sink);
|
|
|
|
priv->send_rtp_sink = NULL;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-20 19:11:32 +00:00
|
|
|
static void
|
|
|
|
clear_element (GstBin * bin, GstElement ** elementptr)
|
|
|
|
{
|
|
|
|
if (*elementptr) {
|
|
|
|
gst_element_set_locked_state (*elementptr, FALSE);
|
|
|
|
gst_element_set_state (*elementptr, GST_STATE_NULL);
|
|
|
|
if (GST_ELEMENT_PARENT (*elementptr))
|
|
|
|
gst_bin_remove (bin, *elementptr);
|
|
|
|
else
|
|
|
|
gst_object_unref (*elementptr);
|
|
|
|
*elementptr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_leave_bin:
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-03-23 20:24:48 +00:00
|
|
|
* @bin: (transfer none): a #GstBin
|
|
|
|
* @rtpbin: (transfer none): a rtpbin #GstElement
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2013-04-23 08:16:17 +00:00
|
|
|
* Remove the elements of @stream from @bin.
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
|
|
|
* Return: %TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin,
|
|
|
|
GstElement * rtpbin)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_BIN (bin), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_ELEMENT (rtpbin), FALSE);
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
g_mutex_lock (&priv->send_lock);
|
|
|
|
priv->continue_sending = FALSE;
|
|
|
|
priv->send_cookie++;
|
|
|
|
g_cond_signal (&priv->send_cond);
|
|
|
|
g_mutex_unlock (&priv->send_lock);
|
|
|
|
|
|
|
|
if (priv->send_thread) {
|
|
|
|
g_thread_join (priv->send_thread);
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2016-07-14 15:10:31 +00:00
|
|
|
if (priv->joined_bin == NULL)
|
2012-11-13 10:14:49 +00:00
|
|
|
goto was_not_joined;
|
2016-07-14 15:10:31 +00:00
|
|
|
if (priv->joined_bin != bin)
|
|
|
|
goto wrong_bin;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2015-12-30 16:39:05 +00:00
|
|
|
priv->joined_bin = NULL;
|
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
/* all transports must be removed by now */
|
2014-10-02 19:02:48 +00:00
|
|
|
if (priv->transports != NULL)
|
|
|
|
goto transports_not_removed;
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2019-04-02 06:05:03 +00:00
|
|
|
if (priv->send_pool) {
|
|
|
|
GThreadPool *slask;
|
|
|
|
|
|
|
|
slask = priv->send_pool;
|
|
|
|
priv->send_pool = NULL;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
g_thread_pool_free (slask, TRUE, TRUE);
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
}
|
|
|
|
|
2019-10-07 10:13:47 +00:00
|
|
|
clear_tr_cache (priv);
|
2014-03-13 13:20:17 +00:00
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("stream %p leaving bin", stream);
|
|
|
|
|
2015-01-09 11:40:47 +00:00
|
|
|
if (priv->srcpad) {
|
|
|
|
gst_pad_unlink (priv->srcpad, priv->send_rtp_sink);
|
2015-11-19 13:01:16 +00:00
|
|
|
|
|
|
|
g_signal_handler_disconnect (priv->send_src[0], priv->caps_sig);
|
|
|
|
gst_element_release_request_pad (rtpbin, priv->send_rtp_sink);
|
|
|
|
gst_object_unref (priv->send_rtp_sink);
|
|
|
|
priv->send_rtp_sink = NULL;
|
2015-01-09 11:40:47 +00:00
|
|
|
} else if (priv->recv_rtp_src) {
|
|
|
|
gst_pad_unlink (priv->recv_rtp_src, priv->sinkpad);
|
|
|
|
gst_object_unref (priv->recv_rtp_src);
|
|
|
|
priv->recv_rtp_src = NULL;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2020-09-04 19:14:35 +00:00
|
|
|
for (i = 0; i < (priv->enable_rtcp ? 2 : 1); i++) {
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
clear_element (bin, &priv->udpsrc_v4[i]);
|
|
|
|
clear_element (bin, &priv->udpsrc_v6[i]);
|
|
|
|
clear_element (bin, &priv->udpqueue[i]);
|
2016-07-20 19:11:32 +00:00
|
|
|
clear_element (bin, &priv->udpsink[i]);
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
|
|
|
|
clear_element (bin, &priv->mcast_udpsrc_v4[i]);
|
|
|
|
clear_element (bin, &priv->mcast_udpsrc_v6[i]);
|
|
|
|
clear_element (bin, &priv->mcast_udpqueue[i]);
|
|
|
|
clear_element (bin, &priv->mcast_udpsink[i]);
|
|
|
|
|
|
|
|
clear_element (bin, &priv->appsrc[i]);
|
2016-07-20 19:11:32 +00:00
|
|
|
clear_element (bin, &priv->appqueue[i]);
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
clear_element (bin, &priv->appsink[i]);
|
|
|
|
|
2016-07-20 19:11:32 +00:00
|
|
|
clear_element (bin, &priv->tee[i]);
|
|
|
|
clear_element (bin, &priv->funnel[i]);
|
2012-11-29 10:11:05 +00:00
|
|
|
|
2015-11-19 13:01:16 +00:00
|
|
|
if (priv->sinkpad || i == 1) {
|
|
|
|
gst_element_release_request_pad (rtpbin, priv->recv_sink[i]);
|
|
|
|
gst_object_unref (priv->recv_sink[i]);
|
|
|
|
priv->recv_sink[i] = NULL;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2014-08-13 14:22:16 +00:00
|
|
|
|
2015-11-19 13:01:16 +00:00
|
|
|
if (priv->srcpad) {
|
|
|
|
gst_object_unref (priv->send_src[0]);
|
|
|
|
priv->send_src[0] = NULL;
|
|
|
|
}
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2020-09-04 19:14:35 +00:00
|
|
|
if (priv->enable_rtcp) {
|
|
|
|
gst_element_release_request_pad (rtpbin, priv->send_src[1]);
|
|
|
|
gst_object_unref (priv->send_src[1]);
|
|
|
|
priv->send_src[1] = NULL;
|
|
|
|
}
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_object_unref (priv->session);
|
2013-04-22 14:09:22 +00:00
|
|
|
priv->session = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
if (priv->caps)
|
|
|
|
gst_caps_unref (priv->caps);
|
2013-04-22 14:09:22 +00:00
|
|
|
priv->caps = NULL;
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2014-03-13 16:35:21 +00:00
|
|
|
if (priv->srtpenc)
|
|
|
|
gst_object_unref (priv->srtpenc);
|
2014-11-01 06:01:53 +00:00
|
|
|
if (priv->srtpdec)
|
|
|
|
gst_object_unref (priv->srtpdec);
|
2014-03-13 16:35:21 +00:00
|
|
|
|
2016-09-05 15:04:50 +00:00
|
|
|
if (priv->mcast_addr_v4)
|
|
|
|
gst_rtsp_address_free (priv->mcast_addr_v4);
|
|
|
|
priv->mcast_addr_v4 = NULL;
|
|
|
|
if (priv->mcast_addr_v6)
|
|
|
|
gst_rtsp_address_free (priv->mcast_addr_v6);
|
|
|
|
priv->mcast_addr_v6 = NULL;
|
|
|
|
if (priv->server_addr_v4)
|
|
|
|
gst_rtsp_address_free (priv->server_addr_v4);
|
|
|
|
priv->server_addr_v4 = NULL;
|
|
|
|
if (priv->server_addr_v6)
|
|
|
|
gst_rtsp_address_free (priv->server_addr_v6);
|
|
|
|
priv->server_addr_v6 = NULL;
|
|
|
|
|
2024-02-07 22:36:43 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
g_clear_object (&priv->socket_v4[i]);
|
|
|
|
g_clear_object (&priv->socket_v6[i]);
|
|
|
|
g_clear_object (&priv->mcast_socket_v4[i]);
|
|
|
|
g_clear_object (&priv->mcast_socket_v6[i]);
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2012-11-13 10:14:49 +00:00
|
|
|
|
|
|
|
was_not_joined:
|
|
|
|
{
|
2014-03-03 11:17:48 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-10-02 19:02:48 +00:00
|
|
|
transports_not_removed:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "can't leave bin (transports not removed)");
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-07-14 15:10:31 +00:00
|
|
|
wrong_bin:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (stream, "leaving the wrong bin");
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 16:39:05 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_joined_bin:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the previous joined bin with gst_rtsp_stream_join_bin() or NULL.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Return: (transfer full) (nullable): the joined bin or NULL.
|
2015-12-30 16:39:05 +00:00
|
|
|
*/
|
|
|
|
GstBin *
|
|
|
|
gst_rtsp_stream_get_joined_bin (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstBin *bin = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
bin = priv->joined_bin ? gst_object_ref (priv->joined_bin) : NULL;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return bin;
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_rtpinfo:
|
|
|
|
* @stream: a #GstRTSPStream
|
2018-02-09 23:07:25 +00:00
|
|
|
* @rtptime: (allow-none) (out caller-allocates): result RTP timestamp
|
|
|
|
* @seq: (allow-none) (out caller-allocates): result RTP seqnum
|
|
|
|
* @clock_rate: (allow-none) (out caller-allocates): the clock rate
|
|
|
|
* @running_time: (out caller-allocates): result running-time
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2013-12-26 13:43:35 +00:00
|
|
|
* Retrieve the current rtptime, seq and running-time. This is used to
|
2012-10-25 19:29:58 +00:00
|
|
|
* construct a RTPInfo reply header.
|
|
|
|
*
|
2013-12-26 13:43:35 +00:00
|
|
|
* Returns: %TRUE when rtptime, seq and running-time could be determined.
|
2012-10-25 19:29:58 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_get_rtpinfo (GstRTSPStream * stream,
|
2013-12-26 16:02:50 +00:00
|
|
|
guint * rtptime, guint * seq, guint * clock_rate,
|
|
|
|
GstClockTime * running_time)
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2014-01-22 21:03:14 +00:00
|
|
|
GstStructure *stats;
|
2014-02-04 09:14:45 +00:00
|
|
|
GObjectClass *payobjclass;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
2014-02-04 09:14:45 +00:00
|
|
|
payobjclass = G_OBJECT_GET_CLASS (priv->payloader);
|
|
|
|
|
2013-12-26 16:02:50 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-12-26 13:43:35 +00:00
|
|
|
|
2015-03-09 15:00:07 +00:00
|
|
|
/* First try to extract the information from the last buffer on the sinks.
|
|
|
|
* This will have a more accurate sequence number and timestamp, as between
|
|
|
|
* the payloader and the sink there can be some queues
|
|
|
|
*/
|
2020-03-23 13:51:28 +00:00
|
|
|
if (priv->udpsink[0] || priv->mcast_udpsink[0] || priv->appsink[0]) {
|
2015-03-09 15:00:07 +00:00
|
|
|
GstSample *last_sample;
|
|
|
|
|
|
|
|
if (priv->udpsink[0])
|
|
|
|
g_object_get (priv->udpsink[0], "last-sample", &last_sample, NULL);
|
2020-03-23 13:51:28 +00:00
|
|
|
else if (priv->mcast_udpsink[0])
|
|
|
|
g_object_get (priv->mcast_udpsink[0], "last-sample", &last_sample, NULL);
|
2015-03-09 15:00:07 +00:00
|
|
|
else
|
|
|
|
g_object_get (priv->appsink[0], "last-sample", &last_sample, NULL);
|
|
|
|
|
2023-06-26 06:25:36 +00:00
|
|
|
if (last_sample && !priv->blocking) {
|
2015-03-09 15:00:07 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstSegment *segment;
|
2017-06-22 14:25:07 +00:00
|
|
|
GstStructure *s;
|
2015-03-09 15:00:07 +00:00
|
|
|
GstRTPBuffer rtp_buffer = GST_RTP_BUFFER_INIT;
|
|
|
|
|
|
|
|
caps = gst_sample_get_caps (last_sample);
|
|
|
|
buffer = gst_sample_get_buffer (last_sample);
|
|
|
|
segment = gst_sample_get_segment (last_sample);
|
2017-06-22 14:25:07 +00:00
|
|
|
s = gst_caps_get_structure (caps, 0);
|
2015-03-09 15:00:07 +00:00
|
|
|
|
|
|
|
if (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp_buffer)) {
|
2017-06-22 14:25:07 +00:00
|
|
|
guint ssrc_buf = gst_rtp_buffer_get_ssrc (&rtp_buffer);
|
|
|
|
guint ssrc_stream = 0;
|
|
|
|
if (gst_structure_has_field_typed (s, "ssrc", G_TYPE_UINT) &&
|
|
|
|
gst_structure_get_uint (s, "ssrc", &ssrc_stream) &&
|
|
|
|
ssrc_buf != ssrc_stream) {
|
|
|
|
/* Skip buffers from auxiliary streams. */
|
|
|
|
GST_DEBUG_OBJECT (stream,
|
|
|
|
"not a buffer from the payloader, SSRC: %08x", ssrc_buf);
|
|
|
|
|
|
|
|
gst_rtp_buffer_unmap (&rtp_buffer);
|
|
|
|
gst_sample_unref (last_sample);
|
|
|
|
goto stats;
|
|
|
|
}
|
|
|
|
|
2015-03-09 15:00:07 +00:00
|
|
|
if (seq) {
|
|
|
|
*seq = gst_rtp_buffer_get_seq (&rtp_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rtptime) {
|
2015-03-21 15:04:05 +00:00
|
|
|
*rtptime = gst_rtp_buffer_get_timestamp (&rtp_buffer);
|
2015-03-09 15:00:07 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 15:04:05 +00:00
|
|
|
gst_rtp_buffer_unmap (&rtp_buffer);
|
|
|
|
|
2015-03-09 15:00:07 +00:00
|
|
|
if (running_time) {
|
|
|
|
*running_time =
|
|
|
|
gst_segment_to_running_time (segment, GST_FORMAT_TIME,
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clock_rate) {
|
2015-04-27 10:35:53 +00:00
|
|
|
gst_structure_get_int (s, "clock-rate", (gint *) clock_rate);
|
|
|
|
|
2015-03-09 15:00:07 +00:00
|
|
|
if (*clock_rate == 0 && running_time)
|
|
|
|
*running_time = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
gst_sample_unref (last_sample);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
} else {
|
|
|
|
gst_sample_unref (last_sample);
|
|
|
|
}
|
2020-10-05 22:04:17 +00:00
|
|
|
} else if (priv->blocking) {
|
2023-06-26 06:25:36 +00:00
|
|
|
if (last_sample != NULL)
|
|
|
|
gst_sample_unref (last_sample);
|
2020-10-05 22:04:17 +00:00
|
|
|
if (seq) {
|
|
|
|
if (!priv->blocked_buffer)
|
|
|
|
goto stats;
|
|
|
|
*seq = priv->blocked_seqnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rtptime) {
|
|
|
|
if (!priv->blocked_buffer)
|
|
|
|
goto stats;
|
|
|
|
*rtptime = priv->blocked_rtptime;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (running_time) {
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (priv->blocked_running_time))
|
|
|
|
goto stats;
|
|
|
|
*running_time = priv->blocked_running_time;
|
|
|
|
}
|
2020-11-18 19:36:50 +00:00
|
|
|
|
|
|
|
if (clock_rate) {
|
|
|
|
*clock_rate = priv->blocked_clock_rate;
|
|
|
|
|
|
|
|
if (*clock_rate == 0 && running_time)
|
|
|
|
*running_time = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
2020-10-05 22:04:17 +00:00
|
|
|
goto done;
|
2015-03-09 15:00:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-22 14:25:07 +00:00
|
|
|
stats:
|
2014-02-04 09:14:45 +00:00
|
|
|
if (g_object_class_find_property (payobjclass, "stats")) {
|
|
|
|
g_object_get (priv->payloader, "stats", &stats, NULL);
|
|
|
|
if (stats == NULL)
|
|
|
|
goto no_stats;
|
|
|
|
|
|
|
|
if (seq)
|
2018-11-06 17:21:54 +00:00
|
|
|
gst_structure_get_uint (stats, "seqnum-offset", seq);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2014-02-04 09:14:45 +00:00
|
|
|
if (rtptime)
|
|
|
|
gst_structure_get_uint (stats, "timestamp", rtptime);
|
2014-01-28 13:51:26 +00:00
|
|
|
|
2014-02-04 09:14:45 +00:00
|
|
|
if (running_time)
|
|
|
|
gst_structure_get_clock_time (stats, "running-time", running_time);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2014-02-04 09:14:45 +00:00
|
|
|
if (clock_rate) {
|
|
|
|
gst_structure_get_uint (stats, "clock-rate", clock_rate);
|
|
|
|
if (*clock_rate == 0 && running_time)
|
|
|
|
*running_time = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
gst_structure_free (stats);
|
|
|
|
} else {
|
|
|
|
if (!g_object_class_find_property (payobjclass, "seqnum") ||
|
|
|
|
!g_object_class_find_property (payobjclass, "timestamp"))
|
|
|
|
goto no_stats;
|
2013-12-26 16:02:50 +00:00
|
|
|
|
2014-02-04 15:27:12 +00:00
|
|
|
if (seq)
|
|
|
|
g_object_get (priv->payloader, "seqnum", seq, NULL);
|
|
|
|
|
|
|
|
if (rtptime)
|
|
|
|
g_object_get (priv->payloader, "timestamp", rtptime, NULL);
|
2014-01-22 21:03:14 +00:00
|
|
|
|
2014-02-04 09:14:45 +00:00
|
|
|
if (running_time)
|
2014-01-22 21:03:14 +00:00
|
|
|
*running_time = GST_CLOCK_TIME_NONE;
|
2013-12-26 16:02:50 +00:00
|
|
|
}
|
2015-03-09 15:00:07 +00:00
|
|
|
|
|
|
|
done:
|
2013-12-26 16:02:50 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
return TRUE;
|
2014-01-28 13:51:26 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_stats:
|
|
|
|
{
|
|
|
|
GST_WARNING ("Could not get payloader stats");
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
2018-09-27 17:09:01 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_rates:
|
|
|
|
* @stream: a #GstRTSPStream
|
2020-05-03 13:29:31 +00:00
|
|
|
* @rate: (optional) (out caller-allocates): the configured rate
|
|
|
|
* @applied_rate: (optional) (out caller-allocates): the configured applied_rate
|
2018-09-27 17:09:01 +00:00
|
|
|
*
|
|
|
|
* Retrieve the current rate and/or applied_rate.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if rate and/or applied_rate could be determined.
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_get_rates (GstRTSPStream * stream, gdouble * rate,
|
|
|
|
gdouble * applied_rate)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstEvent *event;
|
|
|
|
const GstSegment *segment;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
if (!rate && !applied_rate) {
|
|
|
|
GST_WARNING_OBJECT (stream, "rate and applied_rate are both NULL");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
|
|
|
|
if (!priv->send_rtp_sink)
|
|
|
|
goto no_rtp_sink_pad;
|
|
|
|
|
|
|
|
event = gst_pad_get_sticky_event (priv->send_rtp_sink, GST_EVENT_SEGMENT, 0);
|
|
|
|
if (!event)
|
|
|
|
goto no_sticky_event;
|
|
|
|
|
|
|
|
gst_event_parse_segment (event, &segment);
|
|
|
|
if (rate)
|
|
|
|
*rate = segment->rate;
|
|
|
|
if (applied_rate)
|
|
|
|
*applied_rate = segment->applied_rate;
|
|
|
|
|
|
|
|
gst_event_unref (event);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_rtp_sink_pad:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (stream, "no send_rtp_sink pad yet");
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_sticky_event:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (stream, "no segment event on send_rtp_sink pad");
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_caps:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Retrieve the current caps of @stream.
|
|
|
|
*
|
2018-02-09 23:07:25 +00:00
|
|
|
* Returns: (transfer full) (nullable): the #GstCaps of @stream.
|
|
|
|
* use gst_caps_unref() after usage.
|
2012-11-29 10:11:05 +00:00
|
|
|
*/
|
|
|
|
GstCaps *
|
|
|
|
gst_rtsp_stream_get_caps (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstCaps *result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((result = priv->caps))
|
|
|
|
gst_caps_ref (result);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_recv_rtp:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @buffer: (transfer full): 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.
|
|
|
|
*
|
|
|
|
* This function takes ownership of @buffer.
|
|
|
|
*
|
|
|
|
* Returns: a GstFlowReturn.
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
|
|
|
gst_rtsp_stream_recv_rtp (GstRTSPStream * stream, GstBuffer * buffer)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstFlowReturn ret;
|
2012-11-13 10:14:49 +00:00
|
|
|
GstElement *element;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_FLOW_ERROR);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2012-10-26 15:28:10 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
|
2016-07-14 15:10:31 +00:00
|
|
|
g_return_val_if_fail (priv->joined_bin != NULL, FALSE);
|
2012-10-26 15:28:10 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-08-16 15:05:24 +00:00
|
|
|
if (priv->appsrc[0])
|
|
|
|
element = gst_object_ref (priv->appsrc[0]);
|
|
|
|
else
|
|
|
|
element = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
|
2013-08-16 15:05:24 +00:00
|
|
|
if (element) {
|
2015-01-16 19:48:42 +00:00
|
|
|
if (priv->appsrc_base_time[0] == -1) {
|
|
|
|
/* Take current running_time. This timestamp will be put on
|
|
|
|
* the first buffer of each stream because we are a live source and so we
|
|
|
|
* timestamp with the running_time. When we are dealing with TCP, we also
|
|
|
|
* only timestamp the first buffer (using the DISCONT flag) because a server
|
|
|
|
* typically bursts data, for which we don't want to compensate by speeding
|
|
|
|
* up the media. The other timestamps will be interpollated from this one
|
|
|
|
* using the RTP timestamps. */
|
|
|
|
GST_OBJECT_LOCK (element);
|
|
|
|
if (GST_ELEMENT_CLOCK (element)) {
|
|
|
|
GstClockTime now;
|
|
|
|
GstClockTime base_time;
|
|
|
|
|
|
|
|
now = gst_clock_get_time (GST_ELEMENT_CLOCK (element));
|
|
|
|
base_time = GST_ELEMENT_CAST (element)->base_time;
|
|
|
|
|
|
|
|
priv->appsrc_base_time[0] = now - base_time;
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = priv->appsrc_base_time[0];
|
|
|
|
GST_DEBUG ("stream %p: first buffer at time %" GST_TIME_FORMAT
|
|
|
|
", base %" GST_TIME_FORMAT, stream, GST_TIME_ARGS (now),
|
|
|
|
GST_TIME_ARGS (base_time));
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (element);
|
|
|
|
}
|
|
|
|
|
2013-08-16 15:05:24 +00:00
|
|
|
ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
|
|
|
|
gst_object_unref (element);
|
|
|
|
} else {
|
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_recv_rtcp:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @buffer: (transfer full): 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.
|
|
|
|
*
|
|
|
|
* This function takes ownership of @buffer.
|
|
|
|
*
|
|
|
|
* Returns: a GstFlowReturn.
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
|
|
|
gst_rtsp_stream_recv_rtcp (GstRTSPStream * stream, GstBuffer * buffer)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
GstFlowReturn ret;
|
2012-11-13 10:14:49 +00:00
|
|
|
GstElement *element;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-10-26 15:28:10 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), GST_FLOW_ERROR);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2012-10-26 15:28:10 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
|
|
|
|
|
2016-07-14 15:10:31 +00:00
|
|
|
if (priv->joined_bin == NULL) {
|
2014-11-28 11:45:14 +00:00
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return GST_FLOW_NOT_LINKED;
|
|
|
|
}
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-08-16 15:05:24 +00:00
|
|
|
if (priv->appsrc[1])
|
|
|
|
element = gst_object_ref (priv->appsrc[1]);
|
|
|
|
else
|
|
|
|
element = NULL;
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
|
2013-08-16 15:05:24 +00:00
|
|
|
if (element) {
|
2015-01-16 19:48:42 +00:00
|
|
|
if (priv->appsrc_base_time[1] == -1) {
|
|
|
|
/* Take current running_time. This timestamp will be put on
|
|
|
|
* the first buffer of each stream because we are a live source and so we
|
|
|
|
* timestamp with the running_time. When we are dealing with TCP, we also
|
|
|
|
* only timestamp the first buffer (using the DISCONT flag) because a server
|
|
|
|
* typically bursts data, for which we don't want to compensate by speeding
|
|
|
|
* up the media. The other timestamps will be interpollated from this one
|
|
|
|
* using the RTP timestamps. */
|
|
|
|
GST_OBJECT_LOCK (element);
|
|
|
|
if (GST_ELEMENT_CLOCK (element)) {
|
|
|
|
GstClockTime now;
|
|
|
|
GstClockTime base_time;
|
|
|
|
|
|
|
|
now = gst_clock_get_time (GST_ELEMENT_CLOCK (element));
|
|
|
|
base_time = GST_ELEMENT_CAST (element)->base_time;
|
|
|
|
|
|
|
|
priv->appsrc_base_time[1] = now - base_time;
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = priv->appsrc_base_time[1];
|
|
|
|
GST_DEBUG ("stream %p: first buffer at time %" GST_TIME_FORMAT
|
|
|
|
", base %" GST_TIME_FORMAT, stream, GST_TIME_ARGS (now),
|
|
|
|
GST_TIME_ARGS (base_time));
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (element);
|
|
|
|
}
|
|
|
|
|
2013-08-16 15:05:24 +00:00
|
|
|
ret = gst_app_src_push_buffer (GST_APP_SRC_CAST (element), buffer);
|
|
|
|
gst_object_unref (element);
|
|
|
|
} else {
|
|
|
|
ret = GST_FLOW_OK;
|
2014-03-23 20:24:48 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2013-08-16 15:05:24 +00:00
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-14 09:41:02 +00:00
|
|
|
/* must be called with lock */
|
|
|
|
static inline void
|
|
|
|
add_client (GstElement * rtp_sink, GstElement * rtcp_sink, const gchar * host,
|
|
|
|
gint rtp_port, gint rtcp_port)
|
|
|
|
{
|
|
|
|
if (rtp_sink != NULL)
|
|
|
|
g_signal_emit_by_name (rtp_sink, "add", host, rtp_port, NULL);
|
|
|
|
if (rtcp_sink != NULL)
|
|
|
|
g_signal_emit_by_name (rtcp_sink, "add", host, rtcp_port, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called with lock */
|
|
|
|
static void
|
|
|
|
remove_client (GstElement * rtp_sink, GstElement * rtcp_sink,
|
|
|
|
const gchar * host, gint rtp_port, gint rtcp_port)
|
|
|
|
{
|
|
|
|
if (rtp_sink != NULL)
|
|
|
|
g_signal_emit_by_name (rtp_sink, "remove", host, rtp_port, NULL);
|
|
|
|
if (rtcp_sink != NULL)
|
|
|
|
g_signal_emit_by_name (rtcp_sink, "remove", host, rtcp_port, NULL);
|
|
|
|
}
|
|
|
|
|
2012-11-13 10:14:49 +00:00
|
|
|
/* must be called with lock */
|
2012-10-25 19:29:58 +00:00
|
|
|
static gboolean
|
|
|
|
update_transport (GstRTSPStream * stream, GstRTSPStreamTransport * trans,
|
|
|
|
gboolean add)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
const GstRTSPTransport *tr;
|
2018-02-14 09:41:02 +00:00
|
|
|
gchar *dest;
|
|
|
|
gint min, max;
|
2019-11-01 11:01:41 +00:00
|
|
|
GList *tr_element;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
tr = gst_rtsp_stream_transport_get_transport (trans);
|
2018-02-14 09:41:02 +00:00
|
|
|
dest = tr->destination;
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2019-11-01 11:01:41 +00:00
|
|
|
tr_element = g_list_find (priv->transports, trans);
|
|
|
|
|
|
|
|
if (add && tr_element)
|
|
|
|
return TRUE;
|
|
|
|
else if (!add && !tr_element)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
switch (tr->lower_transport) {
|
|
|
|
case GST_RTSP_LOWER_TRANS_UDP_MCAST:
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
{
|
2018-02-14 09:41:02 +00:00
|
|
|
min = tr->port.min;
|
|
|
|
max = tr->port.max;
|
|
|
|
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
if (add) {
|
2018-02-14 09:41:02 +00:00
|
|
|
GST_INFO ("adding %s:%d-%d", dest, min, max);
|
2018-07-26 10:01:16 +00:00
|
|
|
if (!check_mcast_client_addr (stream, tr))
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
goto mcast_error;
|
2018-07-26 10:01:16 +00:00
|
|
|
add_client (priv->mcast_udpsink[0], priv->mcast_udpsink[1], dest, min,
|
|
|
|
max);
|
2017-12-19 09:34:37 +00:00
|
|
|
|
|
|
|
if (tr->ttl > 0) {
|
|
|
|
GST_INFO ("setting ttl-mc %d", tr->ttl);
|
2018-02-13 10:04:36 +00:00
|
|
|
if (priv->mcast_udpsink[0])
|
|
|
|
g_object_set (G_OBJECT (priv->mcast_udpsink[0]), "ttl-mc", tr->ttl,
|
|
|
|
NULL);
|
|
|
|
if (priv->mcast_udpsink[1])
|
|
|
|
g_object_set (G_OBJECT (priv->mcast_udpsink[1]), "ttl-mc", tr->ttl,
|
|
|
|
NULL);
|
2017-12-19 09:34:37 +00:00
|
|
|
}
|
2018-02-14 09:41:02 +00:00
|
|
|
priv->transports = g_list_prepend (priv->transports, trans);
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
} else {
|
2018-02-14 09:41:02 +00:00
|
|
|
GST_INFO ("removing %s:%d-%d", dest, min, max);
|
2018-07-26 10:01:16 +00:00
|
|
|
if (!remove_mcast_client_addr (stream, dest, min, max))
|
|
|
|
GST_WARNING_OBJECT (stream,
|
|
|
|
"Failed to remove multicast address: %s:%d-%d", dest, min, max);
|
2019-11-01 11:01:41 +00:00
|
|
|
priv->transports = g_list_delete_link (priv->transports, tr_element);
|
2018-02-14 09:41:02 +00:00
|
|
|
remove_client (priv->mcast_udpsink[0], priv->mcast_udpsink[1], dest,
|
|
|
|
min, max);
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-06-25 16:23:10 +00:00
|
|
|
case GST_RTSP_LOWER_TRANS_UDP:
|
2012-10-25 19:29:58 +00:00
|
|
|
{
|
2018-02-14 09:41:02 +00:00
|
|
|
if (priv->client_side) {
|
2015-11-16 14:12:28 +00:00
|
|
|
/* In client side mode the 'destination' is the RTSP server, so send
|
|
|
|
* to those ports */
|
|
|
|
min = tr->server_port.min;
|
|
|
|
max = tr->server_port.max;
|
2012-10-25 19:29:58 +00:00
|
|
|
} else {
|
|
|
|
min = tr->client_port.min;
|
|
|
|
max = tr->client_port.max;
|
|
|
|
}
|
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
if (add) {
|
2014-02-17 09:43:05 +00:00
|
|
|
GST_INFO ("adding %s:%d-%d", dest, min, max);
|
2018-02-14 09:41:02 +00:00
|
|
|
add_client (priv->udpsink[0], priv->udpsink[1], dest, min, max);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->transports = g_list_prepend (priv->transports, trans);
|
|
|
|
} else {
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("removing %s:%d-%d", dest, min, max);
|
2019-11-01 11:01:41 +00:00
|
|
|
priv->transports = g_list_delete_link (priv->transports, tr_element);
|
2018-02-14 09:41:02 +00:00
|
|
|
remove_client (priv->udpsink[0], priv->udpsink[1], dest, min, max);
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2014-07-10 09:32:20 +00:00
|
|
|
priv->transports_cookie++;
|
2012-10-25 19:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_RTSP_LOWER_TRANS_TCP:
|
2012-11-29 10:11:05 +00:00
|
|
|
if (add) {
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("adding TCP %s", tr->destination);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv->transports = g_list_prepend (priv->transports, trans);
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
priv->n_tcp_transports++;
|
2012-11-29 10:11:05 +00:00
|
|
|
} else {
|
2012-10-25 19:29:58 +00:00
|
|
|
GST_INFO ("removing TCP %s", tr->destination);
|
2019-11-01 11:01:41 +00:00
|
|
|
priv->transports = g_list_delete_link (priv->transports, tr_element);
|
2020-02-14 13:59:25 +00:00
|
|
|
|
|
|
|
gst_rtsp_stream_transport_lock_backlog (trans);
|
|
|
|
gst_rtsp_stream_transport_clear_backlog (trans);
|
|
|
|
gst_rtsp_stream_transport_unlock_backlog (trans);
|
|
|
|
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
priv->n_tcp_transports--;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2014-07-10 09:32:20 +00:00
|
|
|
priv->transports_cookie++;
|
2012-10-25 19:29:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-11-29 10:11:05 +00:00
|
|
|
goto unknown_transport;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
unknown_transport:
|
|
|
|
{
|
|
|
|
GST_INFO ("Unknown transport %d", tr->lower_transport);
|
|
|
|
return FALSE;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
stream: revert back to create udpsrc/udpsink on DESCRIBE for unicast
This is basically reverting changes introduced in commit f62a9a7,
because it was introducing various regressions:
- It introduces a leak of udpsrc elements that got wrongly fixed by adding
an hash table in commit cba045e. We should have at most 4 udpsrc for unicast:
ipv4/ipv6, rtp/rtcp. They can be reused for all unicast clients.
- If a mcast client connects, it creates a new socket in SETUP to try to respect
the destination/port given by the client in the transport, and overrides the
socket already set on the udpsink element. That means that if we already had a
client connected, the source address on the udp packets it receives suddenly
changes.
- If a 2nd mcast client connects, the destination/port in its transport is
ignored but its transport wasn't updated.
What this patch does:
- Revert back to create udpsrc/udpsink for unicast clients on DESCRIBE.
- Always have a tee+queue when udp is enabled. This could be optimized
again in a later patch, but is more complicated. If no unicast clients
connects then those elements are useless, this could be also optimized
in a later patch.
- When mcast transport is added, it creates a new set of udpsrc/udpsink,
seperated from those for unicast clients. Since we already support only
one mcast address, we also create only one set of elements.
https://bugzilla.gnome.org/show_bug.cgi?id=766612
2016-07-28 19:33:05 +00:00
|
|
|
mcast_error:
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
static void
|
2019-10-15 17:08:32 +00:00
|
|
|
on_message_sent (GstRTSPStreamTransport * trans, gpointer user_data)
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
{
|
2020-02-06 21:46:18 +00:00
|
|
|
GstRTSPStream *stream = GST_RTSP_STREAM (user_data);
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "message send complete");
|
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
check_transport_backlog (stream, trans);
|
2019-10-15 17:08:32 +00:00
|
|
|
|
2020-02-06 21:46:18 +00:00
|
|
|
g_mutex_lock (&priv->send_lock);
|
|
|
|
priv->send_cookie++;
|
|
|
|
g_cond_signal (&priv->send_cond);
|
|
|
|
g_mutex_unlock (&priv->send_lock);
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
}
|
2012-10-25 19:29:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_add_transport:
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-03-23 20:24:48 +00:00
|
|
|
* @trans: (transfer none): a #GstRTSPStreamTransport
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
|
|
|
* Add the transport in @trans to @stream. The media of @stream will
|
2019-11-01 11:01:41 +00:00
|
|
|
* then also be send to the values configured in @trans. Adding the
|
|
|
|
* same transport twice will not add it a second time.
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
2012-10-26 15:28:10 +00:00
|
|
|
* @stream must be joined to a bin.
|
|
|
|
*
|
2012-10-25 19:29:58 +00:00
|
|
|
* @trans must contain a valid #GstRTSPTransport.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @trans was added
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_add_transport (GstRTSPStream * stream,
|
|
|
|
GstRTSPStreamTransport * trans)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-11-13 10:14:49 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
|
2016-07-14 15:10:31 +00:00
|
|
|
g_return_val_if_fail (priv->joined_bin != NULL, FALSE);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
res = update_transport (stream, trans, TRUE);
|
Limit queued TCP data messages to one per stream
Before, the watch backlog size in GstRTSPClient was changed
dynamically between unlimited and a fixed size, trying to avoid both
unlimited memory usage and deadlocks while waiting for place in the
queue. (Some of the deadlocks were described in a long comment in
handle_request().)
In the previous commit, we changed to a fixed backlog size of 100.
This is possible, because we now handle RTP/RTCP data messages differently
from RTSP request/response messages.
The data messages are messages tunneled over TCP. We allow at most one
queued data message per stream in GstRTSPClient at a time, and
successfully sent data messages are acked by sending a "message-sent"
callback from the GstStreamTransport. Until that ack comes, the
GstRTSPStream does not call pull_sample() on its appsink, and
therefore the streaming thread in the pipeline will not be blocked
inside GstRTSPClient, waiting for a place in the queue.
pull_sample() is called when we have both an ack and a "new-sample"
signal from the appsink. Then, we know there is a buffer to write.
RTSP request/response messages are not acked in the same way as data
messages. The rest of the 100 places in the queue are used for
them. If the queue becomes full of request/response messages, we
return an error and close the connection to the client.
Change-Id: I275310bc90a219ceb2473c098261acc78be84c97
2018-06-28 09:22:21 +00:00
|
|
|
if (res)
|
2020-05-01 07:42:17 +00:00
|
|
|
gst_rtsp_stream_transport_set_message_sent_full (trans, on_message_sent,
|
|
|
|
stream, NULL);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
|
|
|
|
return res;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_remove_transport:
|
|
|
|
* @stream: a #GstRTSPStream
|
2014-03-23 20:24:48 +00:00
|
|
|
* @trans: (transfer none): a #GstRTSPStreamTransport
|
2012-10-25 19:29:58 +00:00
|
|
|
*
|
|
|
|
* Remove the transport in @trans from @stream. The media of @stream will
|
|
|
|
* not be sent to the values configured in @trans.
|
|
|
|
*
|
2012-10-26 15:28:10 +00:00
|
|
|
* @stream must be joined to a bin.
|
|
|
|
*
|
|
|
|
* @trans must contain a valid #GstRTSPTransport.
|
|
|
|
*
|
2012-10-25 19:29:58 +00:00
|
|
|
* Returns: %TRUE if @trans was removed
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_remove_transport (GstRTSPStream * stream,
|
|
|
|
GstRTSPStreamTransport * trans)
|
|
|
|
{
|
2012-11-29 10:11:05 +00:00
|
|
|
GstRTSPStreamPrivate *priv;
|
2012-11-13 10:14:49 +00:00
|
|
|
gboolean res;
|
|
|
|
|
2012-10-25 19:29:58 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
2012-11-29 10:11:05 +00:00
|
|
|
priv = stream->priv;
|
2012-10-25 19:29:58 +00:00
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
|
2016-07-14 15:10:31 +00:00
|
|
|
g_return_val_if_fail (priv->joined_bin != NULL, FALSE);
|
2012-10-25 19:29:58 +00:00
|
|
|
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
res = update_transport (stream, trans, FALSE);
|
2012-11-29 10:11:05 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
2012-11-13 10:14:49 +00:00
|
|
|
|
|
|
|
return res;
|
2012-10-25 19:29:58 +00:00
|
|
|
}
|
2013-11-12 11:04:55 +00:00
|
|
|
|
2014-04-02 10:36:16 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_update_crypto:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @ssrc: the SSRC
|
2014-06-24 07:48:45 +00:00
|
|
|
* @crypto: (transfer none) (allow-none): a #GstCaps with crypto info
|
2014-04-02 10:36:16 +00:00
|
|
|
*
|
|
|
|
* Update the new crypto information for @ssrc in @stream. If information
|
|
|
|
* for @ssrc did not exist, it will be added. If information
|
|
|
|
* for @ssrc existed, it will be replaced. If @crypto is %NULL, it will
|
|
|
|
* be removed from @stream.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @crypto could be updated
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_update_crypto (GstRTSPStream * stream,
|
|
|
|
guint ssrc, GstCaps * crypto)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
2014-06-27 14:54:22 +00:00
|
|
|
g_return_val_if_fail (crypto == NULL || GST_IS_CAPS (crypto), FALSE);
|
2014-04-02 10:36:16 +00:00
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "update key for %08x", ssrc);
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (crypto)
|
|
|
|
g_hash_table_insert (priv->keys, GINT_TO_POINTER (ssrc),
|
|
|
|
gst_caps_ref (crypto));
|
|
|
|
else
|
|
|
|
g_hash_table_remove (priv->keys, GINT_TO_POINTER (ssrc));
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-11-12 11:04:55 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2014-06-11 23:38:36 +00:00
|
|
|
* Returns: (transfer full) (nullable): the RTP socket or %NULL if no
|
|
|
|
* socket could be allocated for @family. Unref after usage
|
2013-11-12 11:04:55 +00:00
|
|
|
*/
|
|
|
|
GSocket *
|
|
|
|
gst_rtsp_stream_get_rtp_socket (GstRTSPStream * stream, GSocketFamily family)
|
|
|
|
{
|
2018-06-24 10:44:26 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2013-11-12 11:04:55 +00:00
|
|
|
GSocket *socket;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-03-13 10:10:35 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-11-12 11:04:55 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
2018-03-13 10:10:35 +00:00
|
|
|
socket = priv->socket_v6[0];
|
2013-11-12 11:04:55 +00:00
|
|
|
else
|
2018-03-13 10:10:35 +00:00
|
|
|
socket = priv->socket_v4[0];
|
2013-11-12 11:04:55 +00:00
|
|
|
|
2018-03-13 10:10:35 +00:00
|
|
|
if (socket != NULL)
|
|
|
|
socket = g_object_ref (socket);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2013-11-12 11:04:55 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
2014-06-11 23:38:36 +00:00
|
|
|
* Returns: (transfer full) (nullable): the RTCP socket or %NULL if no
|
|
|
|
* socket could be allocated for @family. Unref after usage
|
2013-11-12 11:04:55 +00:00
|
|
|
*/
|
|
|
|
GSocket *
|
|
|
|
gst_rtsp_stream_get_rtcp_socket (GstRTSPStream * stream, GSocketFamily family)
|
|
|
|
{
|
2018-03-13 10:10:35 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2013-11-12 11:04:55 +00:00
|
|
|
GSocket *socket;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-03-13 10:10:35 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2013-11-12 11:04:55 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
2018-03-13 10:10:35 +00:00
|
|
|
socket = priv->socket_v6[1];
|
2013-11-12 11:04:55 +00:00
|
|
|
else
|
2018-03-13 10:10:35 +00:00
|
|
|
socket = priv->socket_v4[1];
|
2013-11-12 11:04:55 +00:00
|
|
|
|
2018-03-13 10:10:35 +00:00
|
|
|
if (socket != NULL)
|
|
|
|
socket = g_object_ref (socket);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2013-11-12 11:04:55 +00:00
|
|
|
|
2017-10-16 09:15:55 +00:00
|
|
|
return socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_rtp_multicast_socket:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @family: the socket family
|
|
|
|
*
|
|
|
|
* Get the multicast RTP socket from @stream for a @family.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): the multicast RTP socket or %NULL if no
|
2019-04-23 12:01:32 +00:00
|
|
|
*
|
2017-10-16 09:15:55 +00:00
|
|
|
* socket could be allocated for @family. Unref after usage
|
|
|
|
*/
|
|
|
|
GSocket *
|
2017-11-21 08:53:08 +00:00
|
|
|
gst_rtsp_stream_get_rtp_multicast_socket (GstRTSPStream * stream,
|
|
|
|
GSocketFamily family)
|
2017-10-16 09:15:55 +00:00
|
|
|
{
|
2018-03-13 10:10:35 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2017-10-16 09:15:55 +00:00
|
|
|
GSocket *socket;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-03-13 10:10:35 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2017-10-16 09:15:55 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
2018-03-13 10:10:35 +00:00
|
|
|
socket = priv->mcast_socket_v6[0];
|
2017-10-16 09:15:55 +00:00
|
|
|
else
|
2018-03-13 10:10:35 +00:00
|
|
|
socket = priv->mcast_socket_v4[0];
|
2017-10-16 09:15:55 +00:00
|
|
|
|
2018-03-13 10:10:35 +00:00
|
|
|
if (socket != NULL)
|
|
|
|
socket = g_object_ref (socket);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2017-10-16 09:15:55 +00:00
|
|
|
|
|
|
|
return socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_rtcp_multicast_socket:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @family: the socket family
|
|
|
|
*
|
|
|
|
* Get the multicast RTCP socket from @stream for a @family.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): the multicast RTCP socket or %NULL if no
|
|
|
|
* socket could be allocated for @family. Unref after usage
|
2019-04-23 12:01:32 +00:00
|
|
|
*
|
|
|
|
* Since: 1.14
|
2017-10-16 09:15:55 +00:00
|
|
|
*/
|
|
|
|
GSocket *
|
2017-11-21 08:53:08 +00:00
|
|
|
gst_rtsp_stream_get_rtcp_multicast_socket (GstRTSPStream * stream,
|
|
|
|
GSocketFamily family)
|
2017-10-16 09:15:55 +00:00
|
|
|
{
|
2018-03-13 10:10:35 +00:00
|
|
|
GstRTSPStreamPrivate *priv = stream->priv;
|
2017-10-16 09:15:55 +00:00
|
|
|
GSocket *socket;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-03-13 10:10:35 +00:00
|
|
|
g_mutex_lock (&priv->lock);
|
2017-10-16 09:15:55 +00:00
|
|
|
if (family == G_SOCKET_FAMILY_IPV6)
|
2018-03-13 10:10:35 +00:00
|
|
|
socket = priv->mcast_socket_v6[1];
|
2017-10-16 09:15:55 +00:00
|
|
|
else
|
2018-03-13 10:10:35 +00:00
|
|
|
socket = priv->mcast_socket_v4[1];
|
2017-10-16 09:15:55 +00:00
|
|
|
|
2018-03-13 10:10:35 +00:00
|
|
|
if (socket != NULL)
|
|
|
|
socket = g_object_ref (socket);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2017-10-16 09:15:55 +00:00
|
|
|
|
2013-11-12 11:04:55 +00:00
|
|
|
return socket;
|
|
|
|
}
|
2013-11-18 10:18:15 +00:00
|
|
|
|
2018-07-26 10:01:16 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_add_multicast_client_address:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @destination: (transfer none): a multicast address to add
|
|
|
|
* @rtp_port: RTP port
|
|
|
|
* @rtcp_port: RTCP port
|
|
|
|
* @family: socket family
|
|
|
|
*
|
|
|
|
* Add multicast client address to stream. At this point, the sockets that
|
|
|
|
* will stream RTP and RTCP data to @destination are supposed to be
|
|
|
|
* allocated.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @destination can be addedd and handled by @stream.
|
2019-04-23 11:38:05 +00:00
|
|
|
*
|
|
|
|
* Since: 1.16
|
2018-07-26 10:01:16 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_add_multicast_client_address (GstRTSPStream * stream,
|
|
|
|
const gchar * destination, guint rtp_port, guint rtcp_port,
|
|
|
|
GSocketFamily family)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
g_return_val_if_fail (destination != NULL, FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if ((family == G_SOCKET_FAMILY_IPV4) && (priv->mcast_socket_v4[0] == NULL))
|
|
|
|
goto socket_error;
|
|
|
|
else if ((family == G_SOCKET_FAMILY_IPV6) &&
|
|
|
|
(priv->mcast_socket_v6[0] == NULL))
|
|
|
|
goto socket_error;
|
|
|
|
|
|
|
|
if (!add_mcast_client_addr (stream, destination, rtp_port, rtcp_port))
|
|
|
|
goto add_addr_error;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
socket_error:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (stream,
|
|
|
|
"Failed to add multicast address: no udp socket");
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
add_addr_error:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (stream,
|
|
|
|
"Failed to add multicast address: invalid address");
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_multicast_client_addresses
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get all multicast client addresses that RTP data will be sent to
|
|
|
|
*
|
|
|
|
* Returns: A comma separated list of host:port pairs with destinations
|
2019-04-23 11:38:05 +00:00
|
|
|
*
|
|
|
|
* Since: 1.16
|
2018-07-26 10:01:16 +00:00
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gst_rtsp_stream_get_multicast_client_addresses (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GString *str;
|
|
|
|
GList *clients;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
str = g_string_new ("");
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
clients = priv->mcast_clients;
|
|
|
|
while (clients != NULL) {
|
|
|
|
UdpClientAddrInfo *client;
|
|
|
|
|
|
|
|
client = (UdpClientAddrInfo *) clients->data;
|
|
|
|
clients = g_list_next (clients);
|
|
|
|
g_string_append_printf (str, "%s:%d%s", client->address, client->rtp_port,
|
|
|
|
(clients != NULL ? "," : ""));
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return g_string_free (str, FALSE);
|
|
|
|
}
|
|
|
|
|
2014-09-08 07:26:23 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_seqnum:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @seqnum: a new sequence number
|
|
|
|
*
|
|
|
|
* Configure the sequence number in the payloader of @stream to @seqnum.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_seqnum_offset (GstRTSPStream * stream, guint16 seqnum)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (priv->payloader), "seqnum-offset", seqnum, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_seqnum:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Get the configured sequence number in the payloader of @stream.
|
|
|
|
*
|
|
|
|
* Returns: the sequence number of the payloader.
|
|
|
|
*/
|
|
|
|
guint16
|
|
|
|
gst_rtsp_stream_get_current_seqnum (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
guint seqnum;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), 0);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (priv->payloader), "seqnum", &seqnum, NULL);
|
|
|
|
|
|
|
|
return seqnum;
|
|
|
|
}
|
|
|
|
|
2013-11-18 10:18:15 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_transport_filter:
|
|
|
|
* @stream: a #GstRTSPStream
|
2013-11-18 10:47:04 +00:00
|
|
|
* @func: (scope call) (allow-none): a callback
|
2014-03-23 20:24:48 +00:00
|
|
|
* @user_data: (closure): user data passed to @func
|
2013-11-18 10:18:15 +00:00
|
|
|
*
|
|
|
|
* Call @func for each transport managed by @stream. The result value of @func
|
|
|
|
* determines what happens to the transport. @func will be called with @stream
|
|
|
|
* locked so no further actions on @stream can be performed from @func.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_REMOVE, the transport will be removed from
|
|
|
|
* @stream.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_KEEP, the transport will remain in @stream.
|
|
|
|
*
|
|
|
|
* If @func returns #GST_RTSP_FILTER_REF, the transport will remain in @stream but
|
|
|
|
* will also be added with an additional ref to the result #GList of this
|
|
|
|
* function..
|
|
|
|
*
|
|
|
|
* When @func is %NULL, #GST_RTSP_FILTER_REF will be assumed for each transport.
|
|
|
|
*
|
|
|
|
* Returns: (element-type GstRTSPStreamTransport) (transfer full): a #GList with all
|
|
|
|
* transports for which @func returned #GST_RTSP_FILTER_REF. After usage, each
|
|
|
|
* element in the #GList should be unreffed before the list is freed.
|
|
|
|
*/
|
|
|
|
GList *
|
|
|
|
gst_rtsp_stream_transport_filter (GstRTSPStream * stream,
|
|
|
|
GstRTSPStreamTransportFilterFunc func, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GList *result, *walk, *next;
|
2015-01-21 14:57:03 +00:00
|
|
|
GHashTable *visited = NULL;
|
2014-07-10 09:32:20 +00:00
|
|
|
guint cookie;
|
2013-11-18 10:18:15 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
result = NULL;
|
2014-07-10 09:32:20 +00:00
|
|
|
if (func)
|
|
|
|
visited = g_hash_table_new_full (NULL, NULL, g_object_unref, NULL);
|
2013-11-18 10:18:15 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2014-07-10 09:32:20 +00:00
|
|
|
restart:
|
|
|
|
cookie = priv->transports_cookie;
|
2013-11-18 10:18:15 +00:00
|
|
|
for (walk = priv->transports; walk; walk = next) {
|
|
|
|
GstRTSPStreamTransport *trans = walk->data;
|
|
|
|
GstRTSPFilterResult res;
|
2014-07-10 09:32:20 +00:00
|
|
|
gboolean changed;
|
2013-11-18 10:18:15 +00:00
|
|
|
|
|
|
|
next = g_list_next (walk);
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
if (func) {
|
|
|
|
/* only visit each transport once */
|
|
|
|
if (g_hash_table_contains (visited, trans))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_hash_table_add (visited, g_object_ref (trans));
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2013-11-18 10:18:15 +00:00
|
|
|
res = func (stream, trans, user_data);
|
2014-07-10 09:32:20 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
} else
|
2013-11-18 10:18:15 +00:00
|
|
|
res = GST_RTSP_FILTER_REF;
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
changed = (cookie != priv->transports_cookie);
|
|
|
|
|
2013-11-18 10:18:15 +00:00
|
|
|
switch (res) {
|
|
|
|
case GST_RTSP_FILTER_REMOVE:
|
|
|
|
update_transport (stream, trans, FALSE);
|
|
|
|
break;
|
|
|
|
case GST_RTSP_FILTER_REF:
|
|
|
|
result = g_list_prepend (result, g_object_ref (trans));
|
|
|
|
break;
|
|
|
|
case GST_RTSP_FILTER_KEEP:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-07-10 09:32:20 +00:00
|
|
|
if (changed)
|
|
|
|
goto restart;
|
2013-11-18 10:18:15 +00:00
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2014-07-10 09:32:20 +00:00
|
|
|
if (func)
|
|
|
|
g_hash_table_unref (visited);
|
|
|
|
|
2013-11-18 10:18:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
2013-11-28 12:42:21 +00:00
|
|
|
|
|
|
|
static GstPadProbeReturn
|
2021-12-16 20:04:53 +00:00
|
|
|
rtp_pad_blocking (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
|
2013-11-28 12:42:21 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstRTSPStream *stream;
|
2017-10-16 10:40:57 +00:00
|
|
|
GstBuffer *buffer = NULL;
|
2020-08-21 01:02:40 +00:00
|
|
|
GstPadProbeReturn ret = GST_PAD_PROBE_OK;
|
2020-10-05 22:04:17 +00:00
|
|
|
GstEvent *event;
|
2013-11-28 12:42:21 +00:00
|
|
|
|
|
|
|
stream = user_data;
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2017-10-16 10:40:57 +00:00
|
|
|
|
|
|
|
if ((info->type & GST_PAD_PROBE_TYPE_BUFFER)) {
|
2020-10-05 22:04:17 +00:00
|
|
|
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
|
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
buffer = gst_pad_probe_info_get_buffer (info);
|
2020-10-05 22:04:17 +00:00
|
|
|
if (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp)) {
|
|
|
|
priv->blocked_buffer = TRUE;
|
|
|
|
priv->blocked_seqnum = gst_rtp_buffer_get_seq (&rtp);
|
|
|
|
priv->blocked_rtptime = gst_rtp_buffer_get_timestamp (&rtp);
|
|
|
|
gst_rtp_buffer_unmap (&rtp);
|
|
|
|
}
|
2020-08-21 01:02:40 +00:00
|
|
|
priv->position = GST_BUFFER_TIMESTAMP (buffer);
|
2023-06-26 06:25:36 +00:00
|
|
|
if (priv->drop_delta_units) {
|
|
|
|
if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
|
|
|
|
g_assert (!priv->blocking);
|
|
|
|
GST_DEBUG_OBJECT (pad, "dropping delta-unit buffer");
|
|
|
|
ret = GST_PAD_PROBE_DROP;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2017-10-16 10:40:57 +00:00
|
|
|
} else if ((info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST)) {
|
2020-10-05 22:04:17 +00:00
|
|
|
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
|
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
GstBufferList *list = gst_pad_probe_info_get_buffer_list (info);
|
|
|
|
buffer = gst_buffer_list_get (list, 0);
|
2020-10-05 22:04:17 +00:00
|
|
|
if (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp)) {
|
|
|
|
priv->blocked_buffer = TRUE;
|
|
|
|
priv->blocked_seqnum = gst_rtp_buffer_get_seq (&rtp);
|
|
|
|
priv->blocked_rtptime = gst_rtp_buffer_get_timestamp (&rtp);
|
|
|
|
gst_rtp_buffer_unmap (&rtp);
|
|
|
|
}
|
2020-08-21 01:02:40 +00:00
|
|
|
priv->position = GST_BUFFER_TIMESTAMP (buffer);
|
2023-06-26 06:25:36 +00:00
|
|
|
if (priv->drop_delta_units) {
|
|
|
|
if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
|
|
|
|
g_assert (!priv->blocking);
|
|
|
|
GST_DEBUG_OBJECT (pad, "dropping delta-unit buffer");
|
|
|
|
ret = GST_PAD_PROBE_DROP;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2020-08-21 01:02:40 +00:00
|
|
|
} else if ((info->type & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)) {
|
|
|
|
if (GST_EVENT_TYPE (info->data) == GST_EVENT_GAP) {
|
|
|
|
gst_event_parse_gap (info->data, &priv->position, NULL);
|
|
|
|
} else {
|
|
|
|
ret = GST_PAD_PROBE_PASS;
|
2023-06-26 06:25:36 +00:00
|
|
|
GST_WARNING ("Passing event.");
|
2020-08-21 01:02:40 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2017-10-16 10:40:57 +00:00
|
|
|
} else {
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
2020-10-05 22:04:17 +00:00
|
|
|
event = gst_pad_get_sticky_event (pad, GST_EVENT_SEGMENT, 0);
|
|
|
|
if (event) {
|
|
|
|
const GstSegment *segment;
|
|
|
|
|
|
|
|
gst_event_parse_segment (event, &segment);
|
|
|
|
priv->blocked_running_time =
|
|
|
|
gst_segment_to_stream_time (segment, GST_FORMAT_TIME, priv->position);
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
|
2020-11-18 19:36:50 +00:00
|
|
|
event = gst_pad_get_sticky_event (pad, GST_EVENT_CAPS, 0);
|
|
|
|
if (event) {
|
|
|
|
GstCaps *caps;
|
|
|
|
GstStructure *s;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
s = gst_caps_get_structure (caps, 0);
|
|
|
|
gst_structure_get_int (s, "clock-rate", &priv->blocked_clock_rate);
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
|
2023-06-26 06:25:36 +00:00
|
|
|
/* make sure to block on the correct frame type */
|
|
|
|
if (priv->drop_delta_units) {
|
|
|
|
g_assert (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT));
|
|
|
|
}
|
|
|
|
|
2020-08-21 01:02:40 +00:00
|
|
|
priv->blocking = TRUE;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "Now blocking");
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "position: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (priv->position));
|
|
|
|
|
2013-11-28 12:42:21 +00:00
|
|
|
gst_element_post_message (priv->payloader,
|
|
|
|
gst_message_new_element (GST_OBJECT_CAST (priv->payloader),
|
2020-11-03 15:56:28 +00:00
|
|
|
gst_structure_new ("GstRTSPStreamBlocking", "is_complete",
|
|
|
|
G_TYPE_BOOLEAN, priv->is_complete, NULL)));
|
2020-08-21 01:02:40 +00:00
|
|
|
done:
|
2023-06-26 06:25:36 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this probe will drop a single buffer. It is used when an old buffer is
|
|
|
|
* blocking the pipeline, such as between a DESCRIBE and a PLAY request. */
|
|
|
|
static GstPadProbeReturn
|
|
|
|
drop_probe (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstRTSPStream *stream;
|
|
|
|
/* drop an old buffer stuck in a blocked pipeline */
|
|
|
|
GstPadProbeReturn ret = GST_PAD_PROBE_DROP;
|
|
|
|
|
|
|
|
stream = user_data;
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
|
|
|
|
if ((info->type & GST_PAD_PROBE_TYPE_BUFFER ||
|
|
|
|
info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST)) {
|
|
|
|
/* if a buffer has been dropped then remove this probe */
|
|
|
|
if (priv->remove_drop_probe) {
|
|
|
|
priv->remove_drop_probe = FALSE;
|
|
|
|
ret = GST_PAD_PROBE_REMOVE;
|
|
|
|
} else {
|
|
|
|
priv->blocking = FALSE;
|
|
|
|
priv->remove_drop_probe = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = GST_PAD_PROBE_PASS;
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2020-08-21 01:02:40 +00:00
|
|
|
return ret;
|
2013-11-28 12:42:21 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 20:04:53 +00:00
|
|
|
static GstPadProbeReturn
|
|
|
|
rtcp_pad_blocking (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstRTSPStream *stream;
|
|
|
|
GstPadProbeReturn ret = GST_PAD_PROBE_OK;
|
|
|
|
|
|
|
|
stream = user_data;
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
|
|
|
|
if ((info->type & GST_PAD_PROBE_TYPE_BUFFER) ||
|
|
|
|
(info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST)) {
|
|
|
|
GST_DEBUG_OBJECT (pad, "Now blocking on buffer");
|
|
|
|
} else if ((info->type & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)) {
|
|
|
|
if (GST_EVENT_TYPE (info->data) == GST_EVENT_GAP) {
|
|
|
|
GST_DEBUG_OBJECT (pad, "Now blocking on gap event");
|
|
|
|
ret = GST_PAD_PROBE_OK;
|
|
|
|
} else {
|
|
|
|
ret = GST_PAD_PROBE_PASS;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-06-26 06:25:36 +00:00
|
|
|
static void
|
|
|
|
install_drop_probe (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
/* if receiver */
|
|
|
|
if (priv->sinkpad)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* install for data channel only */
|
|
|
|
if (priv->send_src[0]) {
|
|
|
|
gst_pad_add_probe (priv->send_src[0],
|
|
|
|
GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER |
|
|
|
|
GST_PAD_PROBE_TYPE_BUFFER_LIST |
|
|
|
|
GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, drop_probe,
|
|
|
|
g_object_ref (stream), g_object_unref);
|
|
|
|
}
|
|
|
|
}
|
2021-12-16 20:04:53 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
static void
|
|
|
|
set_blocked (GstRTSPStream * stream, gboolean blocked)
|
2013-11-28 12:42:21 +00:00
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
2016-11-21 12:29:56 +00:00
|
|
|
int i;
|
2013-11-28 12:42:21 +00:00
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
GST_DEBUG_OBJECT (stream, "blocked: %d", blocked);
|
2013-11-28 12:42:21 +00:00
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
if (blocked) {
|
2019-06-28 10:28:41 +00:00
|
|
|
/* if receiver */
|
|
|
|
if (priv->sinkpad) {
|
|
|
|
priv->blocking = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
2016-11-21 12:29:56 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
2017-10-17 08:44:33 +00:00
|
|
|
if (priv->blocked_id[i] != 0)
|
|
|
|
continue;
|
|
|
|
if (priv->send_src[i]) {
|
2017-11-25 19:32:02 +00:00
|
|
|
priv->blocking = FALSE;
|
2020-10-05 22:04:17 +00:00
|
|
|
priv->blocked_buffer = FALSE;
|
|
|
|
priv->blocked_running_time = GST_CLOCK_TIME_NONE;
|
2020-11-18 19:36:50 +00:00
|
|
|
priv->blocked_clock_rate = 0;
|
2021-12-16 20:04:53 +00:00
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
priv->blocked_id[i] = gst_pad_add_probe (priv->send_src[i],
|
|
|
|
GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER |
|
|
|
|
GST_PAD_PROBE_TYPE_BUFFER_LIST |
|
|
|
|
GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, rtp_pad_blocking,
|
|
|
|
g_object_ref (stream), g_object_unref);
|
|
|
|
} else {
|
|
|
|
priv->blocked_id[i] = gst_pad_add_probe (priv->send_src[i],
|
|
|
|
GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER |
|
|
|
|
GST_PAD_PROBE_TYPE_BUFFER_LIST |
|
|
|
|
GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, rtcp_pad_blocking,
|
|
|
|
g_object_ref (stream), g_object_unref);
|
|
|
|
}
|
2016-11-21 12:29:56 +00:00
|
|
|
}
|
2013-11-28 12:42:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-11-21 12:29:56 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (priv->blocked_id[i] != 0) {
|
|
|
|
gst_pad_remove_probe (priv->send_src[i], priv->blocked_id[i]);
|
|
|
|
priv->blocked_id[i] = 0;
|
|
|
|
}
|
2013-11-28 12:42:21 +00:00
|
|
|
}
|
2016-11-21 12:29:56 +00:00
|
|
|
priv->blocking = FALSE;
|
2013-11-28 12:42:21 +00:00
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_blocked:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @blocked: boolean indicating we should block or unblock
|
|
|
|
*
|
|
|
|
* Blocks or unblocks the dataflow on @stream.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_set_blocked (GstRTSPStream * stream, gboolean blocked)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
set_blocked (stream, blocked);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-06-26 06:25:36 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_install_drop_probe:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* This probe can be installed when the currently blocking buffer should be
|
|
|
|
* dropped. When it has successfully dropped the buffer, it will remove itself.
|
|
|
|
* The goal is to avoid sending old data, typically when there has been a delay
|
|
|
|
* between a DESCRIBE and a PLAY request.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success
|
|
|
|
*
|
|
|
|
* Since: 1.24
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_install_drop_probe (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
install_drop_probe (stream);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_ublock_linked:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Unblocks the dataflow on @stream if it is linked.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success
|
2019-04-23 12:01:32 +00:00
|
|
|
*
|
|
|
|
* Since: 1.14
|
2017-10-17 08:44:33 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_unblock_linked (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (priv->send_src[0] && gst_pad_is_linked (priv->send_src[0]))
|
|
|
|
set_blocked (stream, FALSE);
|
2013-11-28 12:42:21 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_is_blocking:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Check if @stream is blocking on a #GstBuffer.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @stream is blocking
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_is_blocking (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
result = priv->blocking;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2014-08-05 14:12:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_query_position:
|
|
|
|
* @stream: a #GstRTSPStream
|
2018-02-09 23:07:25 +00:00
|
|
|
* @position: (out): current position of a #GstRTSPStream
|
2014-08-05 14:12:19 +00:00
|
|
|
*
|
|
|
|
* Query the position of the stream in %GST_FORMAT_TIME. This only considers
|
|
|
|
* the RTP parts of the pipeline and not the RTCP parts.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the position could be queried
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_query_position (GstRTSPStream * stream, gint64 * position)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstElement *sink;
|
2017-10-16 10:40:57 +00:00
|
|
|
GstPad *pad = NULL;
|
2014-08-05 14:12:19 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
/* query position: if no sinks have been added yet,
|
|
|
|
* we obtain the position from the pad otherwise we query the sinks */
|
|
|
|
|
2014-08-05 14:12:19 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2020-10-08 20:17:16 +00:00
|
|
|
|
|
|
|
if (priv->blocking && GST_CLOCK_TIME_IS_VALID (priv->blocked_running_time)) {
|
|
|
|
*position = priv->blocked_running_time;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-12-04 07:01:37 +00:00
|
|
|
/* depending on the transport type, it should query corresponding sink */
|
2018-03-21 09:56:51 +00:00
|
|
|
if (priv->configured_protocols & GST_RTSP_LOWER_TRANS_UDP)
|
2015-12-04 07:01:37 +00:00
|
|
|
sink = priv->udpsink[0];
|
2018-03-21 09:56:51 +00:00
|
|
|
else if (priv->configured_protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST)
|
2017-10-16 10:40:57 +00:00
|
|
|
sink = priv->mcast_udpsink[0];
|
2015-12-04 07:01:37 +00:00
|
|
|
else
|
|
|
|
sink = priv->appsink[0];
|
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
if (sink) {
|
2014-08-05 14:12:19 +00:00
|
|
|
gst_object_ref (sink);
|
2017-10-16 10:40:57 +00:00
|
|
|
} else if (priv->send_src[0]) {
|
|
|
|
pad = gst_object_ref (priv->send_src[0]);
|
|
|
|
} else {
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2022-04-13 12:34:57 +00:00
|
|
|
GST_WARNING_OBJECT (stream, "Couldn't obtain position: erroneous pipeline");
|
2017-10-16 10:40:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-08-05 14:12:19 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
if (sink) {
|
2017-11-21 08:53:08 +00:00
|
|
|
if (!gst_element_query_position (sink, GST_FORMAT_TIME, position)) {
|
|
|
|
GST_WARNING_OBJECT (stream,
|
2022-04-13 12:34:57 +00:00
|
|
|
"Couldn't obtain position: position query failed");
|
2017-10-16 10:40:57 +00:00
|
|
|
gst_object_unref (sink);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gst_object_unref (sink);
|
|
|
|
} else if (pad) {
|
|
|
|
GstEvent *event;
|
|
|
|
const GstSegment *segment;
|
|
|
|
|
|
|
|
event = gst_pad_get_sticky_event (pad, GST_EVENT_SEGMENT, 0);
|
|
|
|
if (!event) {
|
2022-04-13 12:34:57 +00:00
|
|
|
GST_WARNING_OBJECT (stream, "Couldn't obtain position: no segment event");
|
2017-10-16 10:40:57 +00:00
|
|
|
gst_object_unref (pad);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-08-05 14:12:19 +00:00
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
gst_event_parse_segment (event, &segment);
|
|
|
|
if (segment->format != GST_FORMAT_TIME) {
|
|
|
|
*position = -1;
|
|
|
|
} else {
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
*position = priv->position;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
*position =
|
2017-11-21 08:53:08 +00:00
|
|
|
gst_segment_to_stream_time (segment, GST_FORMAT_TIME, *position);
|
2017-10-16 10:40:57 +00:00
|
|
|
}
|
|
|
|
gst_event_unref (event);
|
|
|
|
gst_object_unref (pad);
|
|
|
|
}
|
2014-08-05 14:12:19 +00:00
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
return TRUE;
|
2014-08-05 14:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_query_stop:
|
|
|
|
* @stream: a #GstRTSPStream
|
2018-02-09 23:07:25 +00:00
|
|
|
* @stop: (out): current stop of a #GstRTSPStream
|
2014-08-05 14:12:19 +00:00
|
|
|
*
|
|
|
|
* Query the stop of the stream in %GST_FORMAT_TIME. This only considers
|
|
|
|
* the RTP parts of the pipeline and not the RTCP parts.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the stop could be queried
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_query_stop (GstRTSPStream * stream, gint64 * stop)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstElement *sink;
|
2017-10-16 10:40:57 +00:00
|
|
|
GstPad *pad = NULL;
|
2014-08-05 14:12:19 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
/* query stop position: if no sinks have been added yet,
|
|
|
|
* we obtain the stop position from the pad otherwise we query the sinks */
|
|
|
|
|
2014-08-05 14:12:19 +00:00
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
2015-12-04 07:01:37 +00:00
|
|
|
/* depending on the transport type, it should query corresponding sink */
|
2018-03-21 09:56:51 +00:00
|
|
|
if (priv->configured_protocols & GST_RTSP_LOWER_TRANS_UDP)
|
2015-12-04 07:01:37 +00:00
|
|
|
sink = priv->udpsink[0];
|
2018-03-21 09:56:51 +00:00
|
|
|
else if (priv->configured_protocols & GST_RTSP_LOWER_TRANS_UDP_MCAST)
|
2017-10-16 10:40:57 +00:00
|
|
|
sink = priv->mcast_udpsink[0];
|
2015-12-04 07:01:37 +00:00
|
|
|
else
|
|
|
|
sink = priv->appsink[0];
|
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
if (sink) {
|
2014-08-05 14:12:19 +00:00
|
|
|
gst_object_ref (sink);
|
2017-10-16 10:40:57 +00:00
|
|
|
} else if (priv->send_src[0]) {
|
|
|
|
pad = gst_object_ref (priv->send_src[0]);
|
|
|
|
} else {
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
GST_WARNING_OBJECT (stream, "Couldn't obtain stop: erroneous pipeline");
|
2014-08-05 14:12:19 +00:00
|
|
|
return FALSE;
|
2017-10-16 10:40:57 +00:00
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
2014-08-05 14:12:19 +00:00
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
if (sink) {
|
|
|
|
GstQuery *query;
|
2014-08-05 14:12:19 +00:00
|
|
|
GstFormat format;
|
2018-11-13 20:28:45 +00:00
|
|
|
gdouble rate;
|
|
|
|
gint64 start_value;
|
|
|
|
gint64 stop_value;
|
2014-08-05 14:12:19 +00:00
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
query = gst_query_new_segment (GST_FORMAT_TIME);
|
|
|
|
if (!gst_element_query (sink, query)) {
|
|
|
|
GST_WARNING_OBJECT (stream, "Couldn't obtain stop: element query failed");
|
|
|
|
gst_query_unref (query);
|
|
|
|
gst_object_unref (sink);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-13 20:28:45 +00:00
|
|
|
gst_query_parse_segment (query, &rate, &format, &start_value, &stop_value);
|
2014-08-05 14:12:19 +00:00
|
|
|
if (format != GST_FORMAT_TIME)
|
|
|
|
*stop = -1;
|
2018-11-13 20:28:45 +00:00
|
|
|
else
|
|
|
|
*stop = rate > 0.0 ? stop_value : start_value;
|
2017-06-02 19:37:54 +00:00
|
|
|
gst_query_unref (query);
|
2017-10-16 10:40:57 +00:00
|
|
|
gst_object_unref (sink);
|
|
|
|
} else if (pad) {
|
|
|
|
GstEvent *event;
|
|
|
|
const GstSegment *segment;
|
|
|
|
|
|
|
|
event = gst_pad_get_sticky_event (pad, GST_EVENT_SEGMENT, 0);
|
|
|
|
if (!event) {
|
|
|
|
GST_WARNING_OBJECT (stream, "Couldn't obtain stop: no segment event");
|
|
|
|
gst_object_unref (pad);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gst_event_parse_segment (event, &segment);
|
|
|
|
if (segment->format != GST_FORMAT_TIME) {
|
|
|
|
*stop = -1;
|
|
|
|
} else {
|
|
|
|
*stop = segment->stop;
|
|
|
|
if (*stop == -1)
|
|
|
|
*stop = segment->duration;
|
|
|
|
else
|
|
|
|
*stop = gst_segment_to_stream_time (segment, GST_FORMAT_TIME, *stop);
|
|
|
|
}
|
|
|
|
gst_event_unref (event);
|
|
|
|
gst_object_unref (pad);
|
2017-06-02 19:37:54 +00:00
|
|
|
}
|
|
|
|
|
2017-10-16 10:40:57 +00:00
|
|
|
return TRUE;
|
2014-08-05 14:12:19 +00:00
|
|
|
}
|
2017-10-17 08:44:33 +00:00
|
|
|
|
2017-11-24 16:34:31 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_seekable:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Checks whether the individual @stream is seekable.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @stream is seekable, else %FALSE.
|
2019-04-23 12:01:32 +00:00
|
|
|
*
|
|
|
|
* Since: 1.14
|
2017-11-24 16:34:31 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_seekable (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
GstPad *pad = NULL;
|
|
|
|
GstQuery *query = NULL;
|
|
|
|
gboolean seekable = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
/* query stop position: if no sinks have been added yet,
|
|
|
|
* we obtain the stop position from the pad otherwise we query the sinks */
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
/* depending on the transport type, it should query corresponding sink */
|
|
|
|
if (priv->srcpad) {
|
|
|
|
pad = gst_object_ref (priv->srcpad);
|
|
|
|
} else {
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
GST_WARNING_OBJECT (stream, "Pad not available, can't query seekability");
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
query = gst_query_new_seeking (GST_FORMAT_TIME);
|
|
|
|
if (!gst_pad_query (pad, query)) {
|
|
|
|
GST_WARNING_OBJECT (stream, "seeking query failed");
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL);
|
|
|
|
|
|
|
|
beach:
|
|
|
|
if (pad)
|
|
|
|
gst_object_unref (pad);
|
|
|
|
if (query)
|
|
|
|
gst_query_unref (query);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream, "Returning %d", seekable);
|
|
|
|
|
|
|
|
return seekable;
|
|
|
|
}
|
|
|
|
|
2017-10-17 08:44:33 +00:00
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_complete_stream:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @transport: a #GstRTSPTransport
|
|
|
|
*
|
|
|
|
* Add a receiver and sender part to the pipeline based on the transport from
|
|
|
|
* SETUP.
|
|
|
|
*
|
2022-04-13 12:34:57 +00:00
|
|
|
* Returns: %TRUE if the stream has been successfully updated.
|
2019-04-23 12:01:32 +00:00
|
|
|
*
|
|
|
|
* Since: 1.14
|
2017-10-17 08:44:33 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_complete_stream (GstRTSPStream * stream,
|
|
|
|
const GstRTSPTransport * transport)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
GST_DEBUG_OBJECT (stream, "complete stream");
|
|
|
|
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
|
2018-03-21 09:56:51 +00:00
|
|
|
if (!(priv->allowed_protocols & transport->lower_transport))
|
2017-10-17 08:44:33 +00:00
|
|
|
goto unallowed_transport;
|
|
|
|
|
|
|
|
if (!create_receiver_part (stream, transport))
|
|
|
|
goto create_receiver_error;
|
|
|
|
|
|
|
|
/* in the RECORD case, we only add RTCP sender part */
|
|
|
|
if (!create_sender_part (stream, transport))
|
|
|
|
goto create_sender_error;
|
|
|
|
|
2018-03-21 09:56:51 +00:00
|
|
|
priv->configured_protocols |= transport->lower_transport;
|
|
|
|
|
2017-10-23 07:49:09 +00:00
|
|
|
priv->is_complete = TRUE;
|
2017-10-17 08:44:33 +00:00
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
2022-04-13 12:34:57 +00:00
|
|
|
GST_DEBUG_OBJECT (stream, "pipeline successfully updated");
|
2017-10-17 08:44:33 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
create_receiver_error:
|
|
|
|
create_sender_error:
|
|
|
|
unallowed_transport:
|
|
|
|
{
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2017-10-23 07:49:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_is_complete:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Checks whether the stream is complete, contains the receiver and the sender
|
|
|
|
* parts. As the stream contains sink(s) element(s), it's possible to perform
|
|
|
|
* seek operations on it.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the stream contains at least one sink element.
|
2019-04-23 12:01:32 +00:00
|
|
|
*
|
|
|
|
* Since: 1.14
|
2017-10-23 07:49:09 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_is_complete (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
ret = priv->is_complete;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2018-02-05 10:49:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_is_sender:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Checks whether the stream is a sender.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the stream is a sender and %FALSE otherwise.
|
2019-04-23 12:01:32 +00:00
|
|
|
*
|
|
|
|
* Since: 1.14
|
2018-02-05 10:49:07 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_is_sender (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
ret = (priv->srcpad != NULL);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_is_receiver:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
*
|
|
|
|
* Checks whether the stream is a receiver.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the stream is a receiver and %FALSE otherwise.
|
2019-04-23 12:01:32 +00:00
|
|
|
*
|
|
|
|
* Since: 1.14
|
2018-02-05 10:49:07 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_is_receiver (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
ret = (priv->sinkpad != NULL);
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2018-03-29 14:06:31 +00:00
|
|
|
|
|
|
|
#define AES_128_KEY_LEN 16
|
|
|
|
#define AES_256_KEY_LEN 32
|
|
|
|
|
|
|
|
#define HMAC_32_KEY_LEN 4
|
|
|
|
#define HMAC_80_KEY_LEN 10
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
mikey_apply_policy (GstCaps * caps, GstMIKEYMessage * msg, guint8 policy)
|
|
|
|
{
|
|
|
|
const gchar *srtp_cipher;
|
|
|
|
const gchar *srtp_auth;
|
|
|
|
const GstMIKEYPayload *sp;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
/* loop over Security policy until we find one containing policy */
|
|
|
|
for (i = 0;; i++) {
|
|
|
|
if ((sp = gst_mikey_message_find_payload (msg, GST_MIKEY_PT_SP, i)) == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (((GstMIKEYPayloadSP *) sp)->policy == policy)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the default ciphers */
|
|
|
|
srtp_cipher = "aes-128-icm";
|
|
|
|
srtp_auth = "hmac-sha1-80";
|
|
|
|
|
|
|
|
/* now override the defaults with what is in the Security Policy */
|
|
|
|
if (sp != NULL) {
|
|
|
|
guint len;
|
2019-04-10 08:32:53 +00:00
|
|
|
guint enc_alg = GST_MIKEY_ENC_AES_CM_128;
|
2018-03-29 14:06:31 +00:00
|
|
|
|
|
|
|
/* collect all the params and go over them */
|
|
|
|
len = gst_mikey_payload_sp_get_n_params (sp);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
const GstMIKEYPayloadSPParam *param =
|
|
|
|
gst_mikey_payload_sp_get_param (sp, i);
|
|
|
|
|
|
|
|
switch (param->type) {
|
|
|
|
case GST_MIKEY_SP_SRTP_ENC_ALG:
|
2019-04-10 08:32:53 +00:00
|
|
|
enc_alg = param->val[0];
|
2018-03-29 14:06:31 +00:00
|
|
|
switch (param->val[0]) {
|
2019-04-10 08:32:53 +00:00
|
|
|
case GST_MIKEY_ENC_NULL:
|
2018-03-29 14:06:31 +00:00
|
|
|
srtp_cipher = "null";
|
|
|
|
break;
|
2019-04-10 08:32:53 +00:00
|
|
|
case GST_MIKEY_ENC_AES_CM_128:
|
|
|
|
case GST_MIKEY_ENC_AES_KW_128:
|
2018-03-29 14:06:31 +00:00
|
|
|
srtp_cipher = "aes-128-icm";
|
|
|
|
break;
|
2019-04-10 08:32:53 +00:00
|
|
|
case GST_MIKEY_ENC_AES_GCM_128:
|
|
|
|
srtp_cipher = "aes-128-gcm";
|
|
|
|
break;
|
2018-03-29 14:06:31 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_MIKEY_SP_SRTP_ENC_KEY_LEN:
|
|
|
|
switch (param->val[0]) {
|
|
|
|
case AES_128_KEY_LEN:
|
2019-04-10 08:32:53 +00:00
|
|
|
if (enc_alg == GST_MIKEY_ENC_AES_CM_128 ||
|
|
|
|
enc_alg == GST_MIKEY_ENC_AES_KW_128) {
|
|
|
|
srtp_cipher = "aes-128-icm";
|
|
|
|
} else if (enc_alg == GST_MIKEY_ENC_AES_GCM_128) {
|
|
|
|
srtp_cipher = "aes-128-gcm";
|
|
|
|
}
|
2018-03-29 14:06:31 +00:00
|
|
|
break;
|
|
|
|
case AES_256_KEY_LEN:
|
2019-04-10 08:32:53 +00:00
|
|
|
if (enc_alg == GST_MIKEY_ENC_AES_CM_128 ||
|
|
|
|
enc_alg == GST_MIKEY_ENC_AES_KW_128) {
|
|
|
|
srtp_cipher = "aes-256-icm";
|
|
|
|
} else if (enc_alg == GST_MIKEY_ENC_AES_GCM_128) {
|
|
|
|
srtp_cipher = "aes-256-gcm";
|
|
|
|
}
|
2018-03-29 14:06:31 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_MIKEY_SP_SRTP_AUTH_ALG:
|
|
|
|
switch (param->val[0]) {
|
2019-04-10 08:32:53 +00:00
|
|
|
case GST_MIKEY_MAC_NULL:
|
2018-03-29 14:06:31 +00:00
|
|
|
srtp_auth = "null";
|
|
|
|
break;
|
2019-04-10 08:32:53 +00:00
|
|
|
case GST_MIKEY_MAC_HMAC_SHA_1_160:
|
2018-03-29 14:06:31 +00:00
|
|
|
srtp_auth = "hmac-sha1-80";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_MIKEY_SP_SRTP_AUTH_KEY_LEN:
|
|
|
|
switch (param->val[0]) {
|
|
|
|
case HMAC_32_KEY_LEN:
|
|
|
|
srtp_auth = "hmac-sha1-32";
|
|
|
|
break;
|
|
|
|
case HMAC_80_KEY_LEN:
|
|
|
|
srtp_auth = "hmac-sha1-80";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_MIKEY_SP_SRTP_SRTP_ENC:
|
|
|
|
break;
|
|
|
|
case GST_MIKEY_SP_SRTP_SRTCP_ENC:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* now configure the SRTP parameters */
|
|
|
|
gst_caps_set_simple (caps,
|
|
|
|
"srtp-cipher", G_TYPE_STRING, srtp_cipher,
|
|
|
|
"srtp-auth", G_TYPE_STRING, srtp_auth,
|
|
|
|
"srtcp-cipher", G_TYPE_STRING, srtp_cipher,
|
|
|
|
"srtcp-auth", G_TYPE_STRING, srtp_auth, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
handle_mikey_data (GstRTSPStream * stream, guint8 * data, gsize size)
|
|
|
|
{
|
|
|
|
GstMIKEYMessage *msg;
|
|
|
|
guint i, n_cs;
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
GstMIKEYPayloadKEMAC *kemac;
|
|
|
|
const GstMIKEYPayloadKeyData *pkd;
|
|
|
|
GstBuffer *key;
|
|
|
|
|
|
|
|
/* the MIKEY message contains a CSB or crypto session bundle. It is a
|
|
|
|
* set of Crypto Sessions protected with the same master key.
|
|
|
|
* In the context of SRTP, an RTP and its RTCP stream is part of a
|
|
|
|
* crypto session */
|
|
|
|
if ((msg = gst_mikey_message_new_from_data (data, size, NULL, NULL)) == NULL)
|
|
|
|
goto parse_failed;
|
|
|
|
|
|
|
|
/* we can only handle SRTP crypto sessions for now */
|
|
|
|
if (msg->map_type != GST_MIKEY_MAP_TYPE_SRTP)
|
|
|
|
goto invalid_map_type;
|
|
|
|
|
|
|
|
/* get the number of crypto sessions. This maps SSRC to its
|
|
|
|
* security parameters */
|
|
|
|
n_cs = gst_mikey_message_get_n_cs (msg);
|
|
|
|
if (n_cs == 0)
|
|
|
|
goto no_crypto_sessions;
|
|
|
|
|
|
|
|
/* we also need keys */
|
|
|
|
if (!(kemac = (GstMIKEYPayloadKEMAC *) gst_mikey_message_find_payload
|
|
|
|
(msg, GST_MIKEY_PT_KEMAC, 0)))
|
|
|
|
goto no_keys;
|
|
|
|
|
|
|
|
/* we don't support encrypted keys */
|
|
|
|
if (kemac->enc_alg != GST_MIKEY_ENC_NULL
|
|
|
|
|| kemac->mac_alg != GST_MIKEY_MAC_NULL)
|
|
|
|
goto unsupported_encryption;
|
|
|
|
|
|
|
|
/* get Key data sub-payload */
|
|
|
|
pkd = (const GstMIKEYPayloadKeyData *)
|
|
|
|
gst_mikey_payload_kemac_get_sub (&kemac->pt, 0);
|
|
|
|
|
2021-05-24 17:58:00 +00:00
|
|
|
key = gst_buffer_new_memdup (pkd->key_data, pkd->key_len);
|
2018-03-29 14:06:31 +00:00
|
|
|
|
|
|
|
/* go over all crypto sessions and create the security policy for each
|
|
|
|
* SSRC */
|
|
|
|
for (i = 0; i < n_cs; i++) {
|
|
|
|
const GstMIKEYMapSRTP *map = gst_mikey_message_get_cs_srtp (msg, i);
|
|
|
|
|
|
|
|
caps = gst_caps_new_simple ("application/x-srtp",
|
|
|
|
"ssrc", G_TYPE_UINT, map->ssrc,
|
|
|
|
"roc", G_TYPE_UINT, map->roc, "srtp-key", GST_TYPE_BUFFER, key, NULL);
|
|
|
|
mikey_apply_policy (caps, msg, map->policy);
|
|
|
|
|
|
|
|
gst_rtsp_stream_update_crypto (stream, map->ssrc, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
gst_mikey_message_unref (msg);
|
|
|
|
gst_buffer_unref (key);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
parse_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (stream, "failed to parse MIKEY message");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
invalid_map_type:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (stream, "invalid map type %d", msg->map_type);
|
|
|
|
goto cleanup_message;
|
|
|
|
}
|
|
|
|
no_crypto_sessions:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (stream, "no crypto sessions");
|
|
|
|
goto cleanup_message;
|
|
|
|
}
|
|
|
|
no_keys:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (stream, "no keys found");
|
|
|
|
goto cleanup_message;
|
|
|
|
}
|
|
|
|
unsupported_encryption:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (stream, "unsupported key encryption");
|
|
|
|
goto cleanup_message;
|
|
|
|
}
|
|
|
|
cleanup_message:
|
|
|
|
{
|
|
|
|
gst_mikey_message_unref (msg);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define IS_STRIP_CHAR(c) (g_ascii_isspace ((guchar)(c)) || ((c) == '\"'))
|
|
|
|
|
|
|
|
static void
|
|
|
|
strip_chars (gchar * str)
|
|
|
|
{
|
|
|
|
gchar *s;
|
|
|
|
gsize len;
|
|
|
|
|
|
|
|
len = strlen (str);
|
|
|
|
while (len--) {
|
|
|
|
if (!IS_STRIP_CHAR (str[len]))
|
|
|
|
break;
|
|
|
|
str[len] = '\0';
|
|
|
|
}
|
|
|
|
for (s = str; *s && IS_STRIP_CHAR (*s); s++);
|
|
|
|
memmove (str, s, len + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_handle_keymgmt:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @keymgmt: a keymgmt header
|
|
|
|
*
|
|
|
|
* Parse and handle a KeyMgmt header.
|
|
|
|
*
|
|
|
|
* Since: 1.16
|
|
|
|
*/
|
|
|
|
/* KeyMgmt = "KeyMgmt" ":" key-mgmt-spec 0*("," key-mgmt-spec)
|
|
|
|
* key-mgmt-spec = "prot" "=" KMPID ";" ["uri" "=" %x22 URI %x22 ";"]
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_handle_keymgmt (GstRTSPStream * stream, const gchar * keymgmt)
|
|
|
|
{
|
|
|
|
gchar **specs;
|
|
|
|
gint i, j;
|
|
|
|
|
|
|
|
specs = g_strsplit (keymgmt, ",", 0);
|
|
|
|
for (i = 0; specs[i]; i++) {
|
|
|
|
gchar **split;
|
|
|
|
|
|
|
|
split = g_strsplit (specs[i], ";", 0);
|
|
|
|
for (j = 0; split[j]; j++) {
|
|
|
|
g_strstrip (split[j]);
|
|
|
|
if (g_str_has_prefix (split[j], "prot=")) {
|
|
|
|
g_strstrip (split[j] + 5);
|
|
|
|
if (!g_str_equal (split[j] + 5, "mikey"))
|
|
|
|
break;
|
|
|
|
GST_DEBUG ("found mikey");
|
|
|
|
} else if (g_str_has_prefix (split[j], "uri=")) {
|
|
|
|
strip_chars (split[j] + 4);
|
|
|
|
GST_DEBUG ("found uri '%s'", split[j] + 4);
|
|
|
|
} else if (g_str_has_prefix (split[j], "data=")) {
|
|
|
|
guchar *data;
|
|
|
|
gsize size;
|
|
|
|
strip_chars (split[j] + 5);
|
|
|
|
GST_DEBUG ("found data '%s'", split[j] + 5);
|
|
|
|
data = g_base64_decode_inplace (split[j] + 5, &size);
|
|
|
|
handle_mikey_data (stream, data, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_strfreev (split);
|
|
|
|
}
|
|
|
|
g_strfreev (specs);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2018-04-02 20:49:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_ulpfec_pt:
|
|
|
|
*
|
|
|
|
* Returns: the payload type used for ULPFEC protection packets
|
|
|
|
*
|
|
|
|
* Since: 1.16
|
|
|
|
*/
|
|
|
|
guint
|
2018-06-24 10:45:49 +00:00
|
|
|
gst_rtsp_stream_get_ulpfec_pt (GstRTSPStream * stream)
|
2018-04-02 20:49:35 +00:00
|
|
|
{
|
|
|
|
guint res;
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
res = stream->priv->ulpfec_pt;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_ulpfec_pt:
|
|
|
|
*
|
|
|
|
* Set the payload type to be used for ULPFEC protection packets
|
|
|
|
*
|
|
|
|
* Since: 1.16
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_ulpfec_pt (GstRTSPStream * stream, guint pt)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
stream->priv->ulpfec_pt = pt;
|
|
|
|
if (stream->priv->ulpfec_encoder) {
|
|
|
|
g_object_set (stream->priv->ulpfec_encoder, "pt", pt, NULL);
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_request_ulpfec_decoder:
|
|
|
|
*
|
|
|
|
* Creating a rtpulpfecdec element
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): a #GstElement.
|
|
|
|
*
|
|
|
|
* Since: 1.16
|
|
|
|
*/
|
|
|
|
GstElement *
|
2018-06-24 10:45:49 +00:00
|
|
|
gst_rtsp_stream_request_ulpfec_decoder (GstRTSPStream * stream,
|
|
|
|
GstElement * rtpbin, guint sessid)
|
2018-04-02 20:49:35 +00:00
|
|
|
{
|
|
|
|
GObject *internal_storage = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
2018-06-24 10:45:49 +00:00
|
|
|
stream->priv->ulpfec_decoder =
|
|
|
|
gst_object_ref (gst_element_factory_make ("rtpulpfecdec", NULL));
|
2018-04-02 20:49:35 +00:00
|
|
|
|
2018-06-24 10:45:49 +00:00
|
|
|
g_signal_emit_by_name (G_OBJECT (rtpbin), "get-internal-storage", sessid,
|
|
|
|
&internal_storage);
|
|
|
|
g_object_set (stream->priv->ulpfec_decoder, "storage", internal_storage,
|
|
|
|
NULL);
|
2018-04-02 20:49:35 +00:00
|
|
|
g_object_unref (internal_storage);
|
|
|
|
update_ulpfec_decoder_pt (stream);
|
|
|
|
|
|
|
|
return stream->priv->ulpfec_decoder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_request_ulpfec_encoder:
|
|
|
|
*
|
|
|
|
* Creating a rtpulpfecenc element
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): a #GstElement.
|
|
|
|
*
|
|
|
|
* Since: 1.16
|
|
|
|
*/
|
|
|
|
GstElement *
|
|
|
|
gst_rtsp_stream_request_ulpfec_encoder (GstRTSPStream * stream, guint sessid)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
|
|
|
|
|
|
|
|
if (!stream->priv->ulpfec_percentage)
|
|
|
|
return NULL;
|
|
|
|
|
2018-06-24 10:45:49 +00:00
|
|
|
stream->priv->ulpfec_encoder =
|
|
|
|
gst_object_ref (gst_element_factory_make ("rtpulpfecenc", NULL));
|
2018-04-02 20:49:35 +00:00
|
|
|
|
2018-06-24 10:45:49 +00:00
|
|
|
g_object_set (stream->priv->ulpfec_encoder, "pt", stream->priv->ulpfec_pt,
|
|
|
|
"percentage", stream->priv->ulpfec_percentage, NULL);
|
2018-04-02 20:49:35 +00:00
|
|
|
|
|
|
|
return stream->priv->ulpfec_encoder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_ulpfec_percentage:
|
|
|
|
*
|
|
|
|
* Sets the amount of redundancy to apply when creating ULPFEC
|
|
|
|
* protection packets.
|
|
|
|
*
|
|
|
|
* Since: 1.16
|
|
|
|
*/
|
|
|
|
void
|
2018-06-24 10:45:49 +00:00
|
|
|
gst_rtsp_stream_set_ulpfec_percentage (GstRTSPStream * stream, guint percentage)
|
2018-04-02 20:49:35 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
stream->priv->ulpfec_percentage = percentage;
|
|
|
|
if (stream->priv->ulpfec_encoder) {
|
|
|
|
g_object_set (stream->priv->ulpfec_encoder, "percentage", percentage, NULL);
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_ulpfec_percentage:
|
|
|
|
*
|
|
|
|
* Returns: the amount of redundancy applied when creating ULPFEC
|
|
|
|
* protection packets.
|
|
|
|
*
|
|
|
|
* Since: 1.16
|
|
|
|
*/
|
|
|
|
guint
|
2018-06-24 10:45:49 +00:00
|
|
|
gst_rtsp_stream_get_ulpfec_percentage (GstRTSPStream * stream)
|
2018-04-02 20:49:35 +00:00
|
|
|
{
|
|
|
|
guint res;
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
res = stream->priv->ulpfec_percentage;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2019-04-04 22:48:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_rate_control:
|
|
|
|
*
|
|
|
|
* Define whether @stream will follow the Rate-Control=no behaviour as specified
|
|
|
|
* in the ONVIF replay spec.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_rate_control (GstRTSPStream * stream, gboolean enabled)
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (stream, "%s rate control",
|
|
|
|
enabled ? "Enabling" : "Disabling");
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
stream->priv->do_rate_control = enabled;
|
|
|
|
if (stream->priv->appsink[0])
|
|
|
|
g_object_set (stream->priv->appsink[0], "sync", enabled, NULL);
|
|
|
|
if (stream->priv->payloader
|
2020-11-18 19:36:50 +00:00
|
|
|
&& g_object_class_find_property (G_OBJECT_GET_CLASS (stream->
|
|
|
|
priv->payloader), "onvif-no-rate-control"))
|
2019-04-04 22:48:07 +00:00
|
|
|
g_object_set (stream->priv->payloader, "onvif-no-rate-control", !enabled,
|
|
|
|
NULL);
|
|
|
|
if (stream->priv->session) {
|
|
|
|
g_object_set (stream->priv->session, "disable-sr-timestamp", !enabled,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_get_rate_control:
|
|
|
|
*
|
|
|
|
* Returns: whether @stream will follow the Rate-Control=no behaviour as specified
|
|
|
|
* in the ONVIF replay spec.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_rtsp_stream_get_rate_control (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_mutex_lock (&stream->priv->lock);
|
|
|
|
ret = stream->priv->do_rate_control;
|
|
|
|
g_mutex_unlock (&stream->priv->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2021-07-05 09:54:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_unblock_rtcp:
|
|
|
|
*
|
|
|
|
* Remove blocking probe from the RTCP source. When creating an UDP source for
|
|
|
|
* RTCP it is initially blocked until this function is called.
|
|
|
|
* This functions should be called once the pipeline is ready for handling RTCP
|
|
|
|
* packets.
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_unblock_rtcp (GstRTSPStream * stream)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
if (priv->block_early_rtcp_probe != 0) {
|
|
|
|
gst_pad_remove_probe
|
|
|
|
(priv->block_early_rtcp_pad, priv->block_early_rtcp_probe);
|
|
|
|
priv->block_early_rtcp_probe = 0;
|
|
|
|
gst_object_unref (priv->block_early_rtcp_pad);
|
|
|
|
priv->block_early_rtcp_pad = NULL;
|
|
|
|
}
|
|
|
|
if (priv->block_early_rtcp_probe_ipv6 != 0) {
|
|
|
|
gst_pad_remove_probe
|
|
|
|
(priv->block_early_rtcp_pad_ipv6, priv->block_early_rtcp_probe_ipv6);
|
|
|
|
priv->block_early_rtcp_probe_ipv6 = 0;
|
|
|
|
gst_object_unref (priv->block_early_rtcp_pad_ipv6);
|
|
|
|
priv->block_early_rtcp_pad_ipv6 = NULL;
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|
2023-06-26 06:25:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtsp_stream_set_drop_delta_units:
|
|
|
|
* @stream: a #GstRTSPStream
|
|
|
|
* @drop: TRUE if delta unit frames are supposed to be dropped.
|
|
|
|
*
|
|
|
|
* Decide whether the blocking probe is supposed to drop delta units at the
|
|
|
|
* beginning of a stream.
|
|
|
|
*
|
|
|
|
* Since: 1.24
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_rtsp_stream_set_drop_delta_units (GstRTSPStream * stream, gboolean drop)
|
|
|
|
{
|
|
|
|
GstRTSPStreamPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_RTSP_STREAM (stream));
|
|
|
|
priv = stream->priv;
|
|
|
|
g_mutex_lock (&priv->lock);
|
|
|
|
priv->drop_delta_units = drop;
|
|
|
|
g_mutex_unlock (&priv->lock);
|
|
|
|
}
|