Skip to content

Commit 7b7657d

Browse files
committed
Prefer TCP again
This changes the behaviour of "Protocol" option of device configuration, which affects how the source RTSP stream is being consumed. Historically, TCP was preferred. Then, since 01bac09 ("Refactored input device and added option to select AUTO rtp protocol") UDP with fallback to TCP became the default ("AUTO" mode). This makes picture in recordings prone to smearing, so it was decided to switch back to TCP by default. Previously, fallback to TCP was done in our code; this commit makes use of FFmpeg's "rtsp_flags=+prefer_tcp" which accomplishes suitable behaviour: try TCP, fallback to UDP.
1 parent 2079c3d commit 7b7657d

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

lib/lavf_device.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ void lavf_device::stop()
7575
int lavf_device::start()
7676
{
7777
if (ctx) return 0;
78-
bool using_tcp = false;
7978

8079
AVDictionary *avopt_open_input = NULL;
8180
AVInputFormat *input_fmt = NULL;
@@ -88,11 +87,10 @@ int lavf_device::start()
8887

8988
if (!strncmp(url, "rtsp://", 7))
9089
{
91-
if (rtp_protocol == RTP_PROTOCOL_TCP || tcp_fallback)
92-
{
93-
av_dict_set(&avopt_open_input, "rtsp_flags", "+prefer_tcp", 0);
94-
tcp_fallback = false;
95-
using_tcp = true;
90+
switch (rtp_protocol) {
91+
case RTP_PROTOCOL_TCP: av_dict_set(&avopt_open_input, "rtsp_transport", "tcp", 0); break;
92+
case RTP_PROTOCOL_UDP: av_dict_set(&avopt_open_input, "rtsp_transport", "+udp+udp_multicast", 0); break;
93+
case RTP_PROTOCOL_AUTO: av_dict_set(&avopt_open_input, "rtsp_flags", "+prefer_tcp", 0); break;
9694
}
9795
}
9896

@@ -118,14 +116,6 @@ int lavf_device::start()
118116
av_strerror(re, error_message, sizeof(error_message));
119117
bc_log(Error, "Failed to open stream. Error: %d (%s)", re, error_message);
120118
ctx = NULL;
121-
122-
if (rtp_protocol == RTP_PROTOCOL_AUTO && !using_tcp)
123-
{
124-
bc_log(Info, "Falling back to TCP connection");
125-
tcp_fallback = true;
126-
return start();
127-
}
128-
129119
return -1;
130120
}
131121

lib/lavf_device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class lavf_device : public input_device
5252
private:
5353
char url[1024];
5454
int rtp_protocol = RTP_PROTOCOL_AUTO;
55-
bool tcp_fallback = false;
5655
char error_message[512];
5756

5857
AVFormatContext *ctx;

0 commit comments

Comments
 (0)