Commit graph

1193 commits

Author SHA1 Message Date
David Phung
4f673af4b5 rtsp-media: Ignore GstRTSPStreamBlocking from incomplete streams
To prevent cases with prerolling when the inactive stream prerolls first
and the server proceeds without waiting for the active stream, we will
ignore GstRTSPStreamBlocking messages from incomplete streams. When
there are no complete streams (during DESCRIBE), we will listen to all
streams.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/167>
2020-11-11 13:59:09 +01:00
Xavier Claessens
6f336227cd Meson: Use pkg-config generator
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/1>
2020-10-23 14:03:43 +00:00
Mathieu Duponchelle
1730940abd rtsp-media-factory: expose API to disable RTCP
This is supported by the RFC, and can be useful on systems where
allocating two consecutive ports is problematic, and RTCP is not
necessary.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/159>
2020-10-10 02:06:18 +02:00
Mathieu Duponchelle
6d319f8e49 rtsp-stream: make use of blocked_running_time in query_position
When blocking, the sink element will not have received a buffer
yet and the position query will fail. Instead, we make use of
the running time of the buffer we blocked on.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/160>
2020-10-08 22:28:04 +02:00
Mathieu Duponchelle
a446ba4fb0 rtsp-stream: collect rtp info when blocking
We don't unblock the stream anymore before replying to the
play request (883ddc72bb),
so the sinks don't have a last-sample after potentially flush
seeking. seek_trickmode waits for preroll however, which means
the stream will block and wait for a first buffer. Subsequent
calls to get_rtpinfo() can thus make use of the information.

See https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/issues/115

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/160>
2020-10-08 22:28:04 +02:00
David Phung
1589cb737b rtsp-media: Plug memory leak
The get-storage signal of rtpbin increases the ref count of the storage.
So we have to unref it after usage.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/155>
2020-09-29 10:58:37 +02:00
Guiqin Zou
c747711ac5 rtsp-media: Get rates only on sender streams
When play a media with both sender and receiver stream, like ONVIF
back channel audio in, gst_rtsp_media_get_rates call
gst_rtsp_stream_get_rates for each stream to set the rates. But
gst_rtsp_stream_get_rates return false for the receiver steam, which
lead a g_assert crash.

Instead to get rates on all streams, now just get rates on sender
streams.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/150>
2020-09-18 07:02:12 +00:00
Mathieu Duponchelle
3b9eaa092e rtsp-media: set a 0 storage size for TCP receivers
ulpfec correction is obviously useless when receiving a stream
over TCP, and in TCP modes the rtp storage receives non
timestamped buffers, causing it to queue buffers indefinitely,
until the queue grows so large that sanity checks kick in and
warnings start to get emitted.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/149>
2020-09-09 20:18:44 +00:00
Mathieu Duponchelle
5699ada939 rtsp-stream: preroll on gap events
This allows negotiating a SDP with all streams present, but only
start sending packets at some later point in time

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/146>
2020-09-09 17:46:40 +00:00
Mathieu Duponchelle
883ddc72bb rtsp-media: do not unblock on unsuspend
rtsp_media_unsuspend() is called from handle_play_request()
before sending the play response. Unblocking the streams here
was causing data to be sent out before the client was ready
to handle it, with obvious side effects such as initial packets
getting discarded, causing decoding errors.

Instead we can simply let the media streams be unblocked when
the state of the media is set to PLAYING, which occurs after
sending the play response.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/147>
2020-09-08 21:09:30 +00:00
Jordan Petridis
e3e946c0b0 rtsp-thread-pool.c: fix clang 10 warning
clang 10 is complaining about incompatible types due to the
glib typesystem.

```
../subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-thread-pool.c:534:10: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'GThreadPool **' (aka 'struct _GThreadPool **') [-Werror,-Wincompatible-pointer-types]
```

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/145>
2020-08-03 22:29:49 +03:00
Jordan Petridis
3254b992aa rtsp-thread-pool.c: fix clang 10 warning
clang 10 is complaining about incompatible types due to the
glib typesystem.

```
../subprojects/gst-rtsp-server/gst/rtsp-server/rtsp-thread-pool.c:534:10: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'GThreadPool **' (aka 'struct _GThreadPool **') [-Werror,-Wincompatible-pointer-types]
```

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/145>
2020-08-03 19:34:30 +03:00
Srimanta Panda
e55515188d rtsp-sdp: Fix resource leak in mikey messsage
Fixed a resource leak for mikey message while adding crypto session
failed.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/144>
2020-07-15 11:19:40 +02:00
Mathieu Duponchelle
34590b342e rtsp-stream: explicitly set caps on udpsrc elements
This causes them to send caps events before data flow, which is
usually a pretty correct thing to do!

Not doing so manifested in a bug where ssrcdemux wouldn't forward
the caps it had received with an extra ssrc field, as it hadn't
received any caps event.

Fixes #85

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/141>
2020-07-06 10:20:32 +00:00
Sebastian Dröge
1c74592806 rtspclientsink: Don't call gst_ghost_pad_construct() anymore
It's deprecated, unneeded and doesn't do anything anymore.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/138>
2020-06-22 12:33:32 +03:00
Sebastian Dröge
fb8004a6eb rtsp-media: Add/configure transports when completing the pipeline
Otherwise the transports are not set up yet during the PLAY request
handling when unsuspending (and thus unblocking) the media.

In case of live pipelines this then causes the first few packets to go
to the sinks before they know what to do with them, and they simply
discard them which is rather suboptimal in case of keyframes.

For non-live pipelines this is not a problem because the sink will still
be PAUSED and as such not send out the data yet but wait until it goes
to PLAYING, which is late enough.

Adding the transports multiple times is not a problem: if the transport
is already added it won't be added another time and TRUE will be
returned.

This fixes a regression introduced by a7732a68e8
before 1.14.0.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/issues/107

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/135>
2020-06-15 19:45:38 +03:00
Sebastian Dröge
5562656ec0 rtsp-media: Fix misleading comment
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/135>
2020-06-15 19:45:21 +03:00
Sebastian Dröge
b681200673 rtsp-media: Make sure to also unblock pads when going to PLAYING while buffering
The pad probes are not needed anymore at this point and later when
reaching buffering 100% only the state is changed, no unblocking
happens.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/135>
2020-06-15 18:29:13 +03:00
Sebastian Dröge
e4624197da rtsp-media: Remove duplicated media_unblock() function
It does literally the same as media_streams_set_blocked(FALSE).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/135>
2020-06-15 18:17:40 +03:00
Mathieu Duponchelle
ec5aa720d7 onvif-media-factory: define autoptr cleanup function
And have the factory in the onvif-server example inherit from
GstRTSPOnvifMediaFactory.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/133>
2020-06-10 11:51:31 +00:00
Mathieu Duponchelle
7e598e9184 plugins: uddate gst_type_mark_as_plugin_api() calls 2020-06-06 00:41:51 +02:00
Sebastian Dröge
1a99533be8 plugins: Use gst_type_mark_as_plugin_api() for all non-element plugin types 2020-05-30 23:25:53 +03:00
Tim-Philipp Müller
b61f1081b2 meson: gir: remove bogus sources_top_dir kwarg
Doesn't actually exist. Was fixed differently in Meson
so that the user doesn't have to specify it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/127>
2020-05-27 23:39:37 +01:00
Ludvig Rappe
ae58f7d771 rtsp-media: wait for all GstRTSPStreamBlocking messages
Make sure rtsp-media have received a GstRTSPStreamBlocking message from
each active stream when checking if all streams are blocked.

Without this change there will be a race condition when using two or
more streams and rtsp-media receives a GstRTSPStreamBlocking message
from one of the streams. This is because rtsp-media then checks if all
streams are blocked by calling gst_rtsp_stream_is_blocking() for each
stream. This function call returns TRUE if the stream has sent a
GstRTSPStreamBlocking message, however, rtsp-media may have yet to
receive this message. This would then result in that rtsp-media
erroneously thinks it is blocking all streams which could result in
rtsp-media changing state, from PREPARING to PREPARED. In the case of a
preroll, this could result in that rtsp-media thinks that the pipeline
is prerolled even though that might not be the case.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/124>
2020-05-27 16:35:49 +00:00
Ludvig Rappe
0526a5c9bb rtsp-media: update expected_async_done during suspend
Set expected_async_done to FALSE in default_suspend() if a state change
occurs and the return value from set_target_state() is something other
than GST_STATE_CHANGE_ASYNC.

Without this change there is a risk that expected_async_done will be
TRUE even though no asynchronous state change is taking place. This
could happen if the pipeline is set to PAUSED using
media_set_pipeline_state_locked(), an asynchronous state change starts
and then the media is suspended (which could result in a state change,
aborting the asynchronous state change). If the media is suspended
before the asynchronous state change ends then expected_async_done will
be TRUE but no asynchronous state change is taking place.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/123>
2020-05-27 15:23:04 +00:00
Kristofer Björkström
ba7d568bb3 rtsp-client: Fix race condition in rtsp ctrl timeout by WeakRef client
There was a race condition where client was being finalized and
concurrently in some other thread the rtsp ctrl timout was relying on
client data that was being freed.
When rtsp ctrl timeout is setup, a WeakRef on Client is set.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/121>
2020-05-27 15:31:34 +02:00
Gregor Boirie
6459a61e8f media-factory: complete DSCP QoS setting support
add dscp_qos setting support at factory and media level to setup IP DSCP
field of bounded UDP sinks.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/issues/6

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/120>
2020-05-18 11:12:00 +03:00
Sebastian Dröge
5d8abd9bfd rtsp-client: Fix some race conditions around timeout source removal
We always need to take the lock while accessing it as otherwise another
thread might've removed it in the meantime. Also when destroying and
creating a new one, ensure that the mutex is not shortly unlocked in
between as during that time another one might potentially be created
already.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/119>
2020-05-14 11:07:46 +03:00
Sebastian Dröge
8052957c24 rtsp-media: Mark out parameters accordingly in gst_rtsp_media_get_rates()
And the same for gst_rtsp_stream_get_rates().

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/118>
2020-05-03 13:31:37 +00:00
Sebastian Dröge
65bfa84d7a rtsp-stream-transport: Fix accidental API/ABI breakage with message_sent callbacks
The old API is preserved now and new API was added that provides the
additional parameter to the callback.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/issues/104

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/116>
2020-05-01 10:45:45 +03:00
Sebastian Dröge
e7802c1be7 rtsp-client: Store the timeout source by pointer instead of id
That way we don't have to retrieve it again from the main context when
destroying it but can directly do so.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/115>
2020-04-28 23:33:49 +03:00
Sebastian Dröge
4188dbb99b rtsp-client: Clean up watch/watch context and related state consistently
And assert that it was cleaned up properly before the client is
finalized. If something is still around when the client is shut down
then something went very wrong before.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/115>
2020-04-28 23:16:18 +03:00
Sebastian Dröge
680ddb9fd3 rtsp-client: Combine the pre-session and post-session timeout
They previously used the same state but different mechanisms and
functions, which was difficult to follow, error prone and simply
confusing.

Also adjust the test for the post-session timeout a bit to be less racy
now that the timing has slightly changed.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/115>
2020-04-28 11:12:30 +03:00
Sebastian Dröge
d33057a031 rtsp-client: Don't ever close the client connection directly when a session is torn down
There might be other sessions that are running over the same RTSP
connection and we should not simply close the client directly if one of
them is torn down.

By default the connection will be closed once the client closes it or
the OS does. This behaviour can be adjusted with the
post-session-timeout property, which allows to close it automatically
from the server side after all sessions are gone and the given timeout
is reached.

This reverts the previous commit.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/115>
2020-04-28 11:12:30 +03:00
Sebastian Dröge
f2b82c28a3 rtsp-client: If the TEARDOWN response can be sent directly, directly close the client
Instead of closing it never at all. Previously there was only code that
closed the client asynchronously if sending the response happened
asynchrously at a later time.

Thanks to Christian M for debugging this issue.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/issues/102

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/114>
2020-04-27 13:53:22 +03:00
Michael Olbrich
a696d980b5 rtsp-stream: use mcast_udpsink[0] last-sample if available for rtpinfo
Otherwise no sink is found for multicast sreams and the less accurate
fallback is used to determine the current sequence number and timestamp.
2020-03-30 16:57:05 +02:00
Sebastian Dröge
44ccca3086 rtsp-auth: Fix NULL pointer dereference when handling an invalid basic Authorization header
When using the basic authentication scheme, we wouldn't validate that
the authorization field of the credentials is not NULL and pass it on
to g_hash_table_lookup(). g_str_hash() however is not NULL-safe and will
dereference the NULL pointer and crash.
A specially crafted (read: invalid) RTSP header can cause this to
happen.

As a solution, check for the authorization to be not NULL before
continuing processing it and if it is simply fail authentication.

This fixes CVE-2020-6095 and TALOS-2020-1018.

Discovered by Peter Wang of Cisco ASIG.
2020-03-23 16:06:43 +02:00
Göran Jönsson
daa18dc867 rtsp-client: Use watch_context before unref
Move the usage of priv->watch_context to beginning of function
gst_rtsp_client_finalize. Instead of use it after
g_main_context_unref (priv->watch_context).
2020-03-09 14:17:34 +01:00
Mathieu Duponchelle
8410c69da9 rtsp-stream: fix deadlock on transport removal
We cannot take the RTSPStream lock while holding a transport backlog
lock, as remove_transport may be called externally, which will
take first the RTSPStream lock then the transport backlog lock.
2020-02-24 20:24:29 +00:00
Mathieu Duponchelle
fa41cbe9a4 rtsp-stream: clear backlog when removing transport
This ensures we don't end up calling any of transports' callbacks
with a potentially unreffed user_data (in practice, a client that
may have been removed)
2020-02-24 20:24:29 +00:00
Mathieu Duponchelle
54b6b3bcab rtsp-stream: marshal calls to send_tcp_message to a single thread
In order to address the race condition pointed out at
https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/merge_requests/108#note_403579
we get rid of the send thread pool, and instead spawn and manage
a single thread to pull samples from app sinks and add them to
the transport's backlogs.

Additionally, we now also always go through the backlogs in order
to simplify the logic.
2020-02-24 20:24:29 +00:00
Mathieu Duponchelle
50ecbb1596 rtsp-stream: properly protect TCP backlog access
Fixes #97

We cannot hold stream->lock while pushing data, but need
to consistently check the state of the backlog both from
the send_tcp_message function and the on_message_sent function,
which may or may not be called from the same thread.

This commit introduces internal API to allow for potentially
recursive locking of transport streams, addressing a race
condition where the RTSP stream could push items out of order
when popping them from the backlog.
2020-02-24 20:24:29 +00:00
Sebastian Dröge
a2ba3639a5 rtsp-media: Sink pipeline in gst_rtsp_media_take_pipeline()
It's taken ownership of by the media, and returned with `transfer none`
from the GstRTSPMedia::create_pipeline() vfunc. If we don't sink it
first then any bindings will wrongly take ownership of the pipeline once
it arrives in bindings code.
2020-02-22 00:43:31 +02:00
Marc Leeman
7b5dbb0561 rtsp-media: fix default latency 2020-02-03 12:30:14 +00:00
Mathieu Duponchelle
90f7e851f4 rtsp-client: make closing more thread safe
+ Take the watch lock prior to using priv->watch
+ Flush both the watch and connection before closing / unreffing

gst_rtsp_connection_close() is not threadsafe on its own, this is
a workaround at the client level, where we control both the watch
and the connection
2020-01-23 18:08:21 +00:00
Jordan Petridis
b4948f69a0
rtsp-latency-bin: replace G_TYPE_INSTANCE_GET_PRIVATE as it's been deprecated
from glib
```
Deprecated: 2.58: Use %G_ADD_PRIVATE and the generated
  `your_type_get_instance_private()` function instead
```
2020-01-23 17:00:59 +02:00
Zoltán Imets
aa8126b239 rtsp-client: add property post-session-timeout
This is a TCP connection timeout for client connections, in seconds.
If a positive value is set for this property, the client connection
will be kept alive for this amount of seconds after the last session
timeout. For negative values of this property the connection timeout
handling is delegated to the system (just as it was before).

Fixes #83
2020-01-15 11:47:27 +00:00
Mark Nauwelaerts
0ed32e0d53 rtsp-stream: check for NULL transports prior to ref'ing 2020-01-11 22:58:48 +01:00
Mathieu Duponchelle
e0a4355d6b rtsp-stream: fix checking of TCP backpressure
The internal index of our appsinks, while it can be used to
determine whether a message is RTP or RTCP, is not necessarily
the same as the interleaved channel. Let the stream-transport
determine the channel to check backpressure for, the same way
it determines the channel according to whether it is sending
RTP or RTCP.
2020-01-09 14:10:44 +01:00
Olivier Crête
73b4929803 rtsp-session: Butcher the file to please gst-indent in the CI
This should be reverted once the CI has an updated gst-indent.
2019-12-18 19:48:31 +00:00