Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTSP/1.0 400 Bad Request when query parameters are supplied in RTSP URL #3295

Closed
1 of 13 tasks
XDGFX opened this issue Apr 25, 2024 · 2 comments · Fixed by bluenviron/gortsplib#619
Closed
1 of 13 tasks
Labels
bug Something isn't working rtsp

Comments

@XDGFX
Copy link

XDGFX commented Apr 25, 2024

Which version are you using?

v1.8.0

Which operating system are you using?

  • Linux amd64 standard
  • Linux amd64 Docker
  • Linux arm64 standard
  • Linux arm64 Docker
  • Linux arm7 standard
  • Linux arm7 Docker
  • Linux arm6 standard
  • Linux arm6 Docker
  • Windows amd64 standard
  • Windows amd64 Docker (WSL backend)
  • macOS amd64 standard
  • macOS amd64 Docker
  • Other (macOS arm64 [M2] Docker)

Describe the issue

When attempting to stream video with RTSP (using Gstreamer), response 400 is given on SETUP request.

Describe how to replicate the issue

  1. Launch MediaMTX with the following config: mediamtx.yml

Docker command I'm using is docker run --restart unless-stopped -v ./src/mediamtx/mediamtx.yml:/mediamtx.yml -v ./src/mediamtx:/app/data -p 8554:8554 -p 1935:1935 -p 8888:8888 -p 8889:8889 -p 8890:8890/udp -p 8189:8189/udp bluenviron/mediamtx

  1. Stream a test video using Gstreamer (v1.22.10), observe the connection has no issues
    gst-launch-1.0 videotestsrc ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! x264enc speed-preset=veryfast tune=zerolatency bitrate=800 ! rtspclientsink protocols=tcp location=rtsp://127.0.0.1:8554/mystream
  2. Stream a test video using Gstreamer, with sample query parameters
    gst-launch-1.0 videotestsrc ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! x264enc speed-preset=veryfast tune=zerolatency bitrate=800 ! rtspclientsink protocols=tcp location=rtsp://127.0.0.1:8554/mystream?key=value
  3. Observe the response: Error (400): Bad Request

Logs

Logs from server:
2024/04/25 12:04:25 INF [RTSP] [conn 192.168.65.1:25173] opened
2024/04/25 12:04:25 DEB [RTSP] [conn 192.168.65.1:25173] [c->s] OPTIONS rtsp://127.0.0.1:8554/mystream?key=value RTSP/1.0
CSeq: 1
Date: Thu, 25 Apr 2024 12:04:25 GMT
User-Agent: GStreamer/1.22.10


2024/04/25 12:04:25 DEB [RTSP] [conn 192.168.65.1:25173] [s->c] RTSP/1.0 200 OK
CSeq: 1
Public: DESCRIBE, ANNOUNCE, SETUP, PLAY, RECORD, PAUSE, GET_PARAMETER, TEARDOWN
Server: gortsplib


2024/04/25 12:04:25 DEB [RTSP] [conn 192.168.65.1:25173] [c->s] ANNOUNCE rtsp://127.0.0.1:8554/mystream?key=value RTSP/1.0
CSeq: 2
Content-Length: 472
Content-Type: application/sdp
Date: Thu, 25 Apr 2024 12:04:25 GMT
User-Agent: GStreamer/1.22.10

v=0
o=- 3559535198 1 IN IP4 127.0.0.1
s=Session streamed with GStreamer
i=rtspclientsink
t=0 0
a=tool:GStreamer
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:819
a=rtpmap:96 H264/90000
a=framerate:30
a=fmtp:96 packetization-mode=1;sprop-parameter-sets=Z/QAHpDZaAoD2wFqDAwMgAAAAwCAAAAeR4sXUA==,aO8xkhk=;profile-level-id=f4001e;level-asymmetry-allowed=1
a=control:stream=0
a=ts-refclk:local
a=mediaclk:sender
a=ssrc:1080323934 cname:user668979404@host-d08b337a

2024/04/25 12:04:25 INF [RTSP] [session 7df37126] created by 192.168.65.1:25173
2024/04/25 12:04:25 DEB [path mystream] created
2024/04/25 12:04:25 DEB [RTSP] [conn 192.168.65.1:25173] [s->c] RTSP/1.0 200 OK
CSeq: 2
Server: gortsplib


2024/04/25 12:04:25 DEB [RTSP] [conn 192.168.65.1:25173] [c->s] SETUP rtsp://127.0.0.1:8554/mystream/stream=0?key=value RTSP/1.0
CSeq: 3
Date: Thu, 25 Apr 2024 12:04:25 GMT
Transport: RTP/AVP/TCP;unicast;interleaved=0-1;mode=RECORD
User-Agent: GStreamer/1.22.10


2024/04/25 12:04:26 DEB [RTSP] [conn 192.168.65.1:25173] [s->c] RTSP/1.0 400 Bad Request
CSeq: 3
Server: gortsplib


2024/04/25 12:04:26 INF [RTSP] [conn 192.168.65.1:25173] closed: media not found
2024/04/25 12:04:26 DEB [path mystream] destroyed: not in use
2024/04/25 12:04:26 INF [RTSP] [session 7df37126] destroyed: not in use

It seems fine until Gstreamer tries to send data to the /mystream/stream=0 endpoint.

Additional info

The reason I need to send a query parameter is for JWT authentication; as specified in the docs I am trying to send jwt=..., however the process fails as described above.

Did you attach the server logs?

yes

Did you attach a network dump?

no

@aler9 aler9 added bug Something isn't working rtsp labels Jun 21, 2024
@aler9
Copy link
Member

aler9 commented Jun 21, 2024

Hello, i can confirm that there's a bug, but it's on the GStreamer side, since in RTSP the control attribute (stream=0) should be appended AFTER query parameters (key=value), not merged with query parameters.

This is the (wrong) request that GStreamer sends when publishing:

SETUP rtsp://127.0.0.1:8554/mystream/stream=0?key=value RTSP/1.0

This is the right one:

SETUP rtsp://127.0.0.1:8554/mystream?key=value/stream=0 RTSP/1.0

The problem is that this split between query parameters and control attribute is not mentioned in the specification, it's an unwritten rule of RTSP that is implemented anywhere nonetheless. Except GStreamer, evidently. Thus i doubt that GStreamer maintainers would accept a patch.

@aler9
Copy link
Member

aler9 commented Sep 15, 2024

This is fixed by bluenviron/gortsplib#619.

With respect to my previous comment, i improved the server in order to support both URL formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rtsp
Projects
None yet
2 participants