scottlamb / retina

High-level RTSP multimedia streaming library, in Rust
https://crates.io/crates/retina
Apache License 2.0
218 stars 46 forks source link

Failed to parse RTSP with: Invalid RTSP message #80

Open tubzby opened 1 year ago

tubzby commented 1 year ago

Thank you for your kind and nice work!

I'm testing the webrtc-proxy example, it failed sometimes with my RTSP camera (sometimes works) with messages on the console:

E20230323 10:39:59.646 main webrtc_proxy] error: RtspFramingError { conn_ctx: ConnectionContext { local_addr: 192.168.8.229:65029, peer_addr: 192.168.123.140:554, established_wall: WallTime(Timespec { sec: 1679539188, nsec: 67880000 }) }, msg_ctx: RtspMessageContext { pos: 668859, received_wall: WallTime(Timespec { sec: 1679539199, nsec: 646905000 }), received: Instant { tv_sec: 228430, tv_nsec: 260722583 } }, description: "Invalid RTSP message; buffered:\nLength: 2184 (0x888) bytes\n0000:   51 f3 1c e1  24 2c 69 f1  00 4a 91 45  e2 1a bc 80   Q...$,i..J.E....\n0010:   ab 28 fe 00  cf 62 eb 48  25 72 9a fd  a9 00 c0 2a   .(...b.H%r.....*\n0020:   7e 0b b6 91  8e 32 c2 12  c2 ee 8f 7d  c6 73 09 c7   ~....2.....}.s..\n0030:   b1 41 9f f3  29 f3 59 83  0d f2 eb ed  7a 4b 82 23   .A..).Y.....zK.#\n0040:   b9 fe 29 f4  90 2d e3 35  ef ac 91 19  5e bd 2e c2   ..)..-.5....^...\n0050:   33 0c a1 35  59 b8 02 a1  67 a7 ae 34  76 cd d1 63   3..5Y...g..4v..c\n0060:   f0 f0 2f 34  73 b9 78 fa  89 dd 28 cd  67 48 b4 71   ../4s.x...(.gH.q\n0070:   43 be cd af  4b 37 76 89  24 b5 83 5e  69 03 00 18   C...K7v.$..^i...\n...2056 (0x808) bytes not shown..." }
E20230323 10:39:59.647 main webrtc_proxy] upstream failure

command:

./target/debug/webrtc-proxy --url RTSP_URL --username USERNAME --password PASSWORD

I tried to use Wireshark to analyze the stream, it might link to an invalid RTSP message, the bytes contain 3 RTSP messages, and the last one is invalid:

image

But it works with ffplay, so I don't know if there is any difference between ffplay and webrtc-proxy.

UPDATE 1: ffplay with Wireshark

It also shows some "RTSP Continuation" messages on Wireshark, which also seems invalid, but it can play anyway:

image
tubzby commented 1 year ago

What's even more strange is that if I run the mp4 example with the same RTSP camera, it never fails!

command:

./target/debug/client mp4 --url RTSP_URL --username USERNAME --password PASSWORD --no-audio --duration 10 out.mp4
tubzby commented 1 year ago

Find out that if I wait some time before inputting the SDP from the web, it has a bigger chance of causing this error.

Maybe we can connect WebRTC before connecting to the RTSP stream?