History

rtsp: Allow specifying the UDP port range via AVOptions

Martin Storsjö committed 14 years ago

Commit dbb06b81 parent bc495ba2 files · +16 −2Browse files

Unified · Split

2 files
  1. libavformat/rtsp.c +11 −2
  2. libavformat/rtsp.h +5 −0
libavformat/rtsp.c+11−2
@@ -81,6 +81,8 @@ const AVOption ff_rtsp_options[] = { · 80 unmodified lines
8181 { "http", "HTTP tunneling", 0, AV_OPT_TYPE_CONST, {(1 << RTSP_LOWER_TRANSPORT_HTTP)}, 0, 0, DEC, "rtsp_transport" },
8282 RTSP_FLAG_OPTS("rtsp_flags", "RTSP flags"),
8383 RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
84+ { "min_port", "Minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC },
85+ { "max_port", "Maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
8486 { NULL },
8587 };
8688
@@ -1121,7 +1123,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, · 1034 unmodified lines
11211123 /* XXX: we assume the same server is used for the control of each
11221124 * RTSP stream */
11231125
1124− for (j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) {
1126+ for (j = rt->rtp_port_min, i = 0; i < rt->nb_rtsp_streams; ++i) {
11251127 char transport[2048];
11261128
11271129 /*
@@ -1158,7 +1160,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, · 30 unmodified lines
11581160 }
11591161
11601162 /* first try in specified port range */
1161− while (j <= RTSP_RTP_PORT_MAX) {
1163+ while (j <= rt->rtp_port_max) {
11621164 ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1,
11631165 "?localport=%d", j);
11641166 /* we will use two ports per rtp stream (rtp and rtcp) */
@@ -1356,6 +1358,13 @@ int ff_rtsp_connect(AVFormatContext *s) · 191 unmodified lines
13561358 struct sockaddr_storage peer;
13571359 socklen_t peer_len = sizeof(peer);
13581360
1361+ if (rt->rtp_port_max < rt->rtp_port_min) {
1362+ av_log(s, AV_LOG_ERROR, "Invalid UDP port range, max port %d less "
1363+ "than min port %d\n", rt->rtp_port_max,
1364+ rt->rtp_port_min);
1365+ return AVERROR(EINVAL);
1366+ }
1367+
13591368 if (!ff_network_init())
13601369 return AVERROR(EIO);
13611370
libavformat/rtsp.h+5−0
@@ -359,6 +359,11 @@ typedef struct RTSPState { · 358 unmodified lines
359359 * Mask of all requested media types
360360 */
361361 int media_type_mask;
362+
363+ /**
364+ * Minimum and maximum local UDP ports.
365+ */
366+ int rtp_port_min, rtp_port_max;
362367 } RTSPState;
363368
364369 #define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets -

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t