Browse code

rtsp: Add a buffer_size option

And forward it to rtp and udp.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>

Luca Barbato authored on 2015/03/23 05:16:55
Showing 3 changed files
... ...
@@ -72,8 +72,10 @@
72 72
     { "audio", "Audio", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_AUDIO}, 0, 0, DEC, "allowed_media_types" }, \
73 73
     { "data", "Data", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_DATA}, 0, 0, DEC, "allowed_media_types" }
74 74
 
75
-#define RTSP_REORDERING_OPTS() \
76
-    { "reorder_queue_size", "Number of packets to buffer for handling of reordered packets", OFFSET(reordering_queue_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, DEC }
75
+#define COMMON_OPTS() \
76
+    { "reorder_queue_size", "Number of packets to buffer for handling of reordered packets", OFFSET(reordering_queue_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, DEC }, \
77
+    { "buffer_size",        "Underlying protocol send/receive buffer size",                  OFFSET(buffer_size),           AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, DEC|ENC } \
78
+
77 79
 
78 80
 const AVOption ff_rtsp_options[] = {
79 81
     { "initial_pause",  "Don't start playing the stream immediately", OFFSET(initial_pause), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC },
... ...
@@ -89,7 +91,7 @@ const AVOption ff_rtsp_options[] = {
89 89
     { "min_port", "Minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC },
90 90
     { "max_port", "Maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
91 91
     { "timeout", "Maximum timeout (in seconds) to wait for incoming connections. -1 is infinite. Implies flag listen", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC },
92
-    RTSP_REORDERING_OPTS(),
92
+    COMMON_OPTS(),
93 93
     { NULL },
94 94
 };
95 95
 
... ...
@@ -98,16 +100,28 @@ static const AVOption sdp_options[] = {
98 98
     { "custom_io", "Use custom IO", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_CUSTOM_IO}, 0, 0, DEC, "rtsp_flags" },
99 99
     { "rtcp_to_source", "Send RTCP packets to the source address of received packets", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_RTCP_TO_SOURCE}, 0, 0, DEC, "rtsp_flags" },
100 100
     RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
101
-    RTSP_REORDERING_OPTS(),
101
+    COMMON_OPTS(),
102 102
     { NULL },
103 103
 };
104 104
 
105 105
 static const AVOption rtp_options[] = {
106 106
     RTSP_FLAG_OPTS("rtp_flags", "RTP flags"),
107
-    RTSP_REORDERING_OPTS(),
107
+    COMMON_OPTS(),
108 108
     { NULL },
109 109
 };
110 110
 
111
+
112
+static AVDictionary *map_to_opts(RTSPState *rt)
113
+{
114
+    AVDictionary *opts = NULL;
115
+    char buf[256];
116
+
117
+    snprintf(buf, sizeof(buf), "%d", rt->buffer_size);
118
+    av_dict_set(&opts, "buffer_size", buf, 0);
119
+
120
+    return opts;
121
+}
122
+
111 123
 static void get_word_until_chars(char *buf, int buf_size,
112 124
                                  const char *sep, const char **pp)
113 125
 {
... ...
@@ -1433,12 +1447,18 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
1433 1433
 
1434 1434
             /* first try in specified port range */
1435 1435
             while (j <= rt->rtp_port_max) {
1436
+                AVDictionary *opts = map_to_opts(rt);
1437
+
1436 1438
                 ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1,
1437 1439
                             "?localport=%d", j);
1438 1440
                 /* we will use two ports per rtp stream (rtp and rtcp) */
1439 1441
                 j += 2;
1440
-                if (!ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE,
1441
-                               &s->interrupt_callback, NULL))
1442
+                err = ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE,
1443
+                                 &s->interrupt_callback, &opts);
1444
+
1445
+                av_dict_free(&opts);
1446
+
1447
+                if (!err)
1442 1448
                     goto rtp_opened;
1443 1449
             }
1444 1450
 
... ...
@@ -2236,6 +2256,8 @@ static int sdp_read_header(AVFormatContext *s)
2236 2236
         rtsp_st = rt->rtsp_streams[i];
2237 2237
 
2238 2238
         if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) {
2239
+            AVDictionary *opts = map_to_opts(rt);
2240
+
2239 2241
             getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip),
2240 2242
                         namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
2241 2243
             ff_url_join(url, sizeof(url), "rtp", NULL,
... ...
@@ -2251,8 +2273,12 @@ static int sdp_read_header(AVFormatContext *s)
2251 2251
             append_source_addrs(url, sizeof(url), "block",
2252 2252
                                 rtsp_st->nb_exclude_source_addrs,
2253 2253
                                 rtsp_st->exclude_source_addrs);
2254
-            if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
2255
-                           &s->interrupt_callback, NULL) < 0) {
2254
+            err = ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
2255
+                           &s->interrupt_callback, &opts);
2256
+
2257
+            av_dict_free(&opts);
2258
+
2259
+            if (err < 0) {
2256 2260
                 err = AVERROR_INVALIDDATA;
2257 2261
                 goto fail;
2258 2262
             }
... ...
@@ -397,6 +397,7 @@ typedef struct RTSPState {
397 397
     int reordering_queue_size;
398 398
 
399 399
     char default_lang[4];
400
+    int buffer_size;
400 401
 } RTSPState;
401 402
 
402 403
 #define RTSP_FLAG_FILTER_SRC  0x1    /**< Filter incoming UDP packets -
... ...
@@ -287,10 +287,15 @@ static int rtsp_read_setup(AVFormatContext *s, char* host, char *controlurl)
287 287
                  request.transports[0].interleaved_max);
288 288
     } else {
289 289
         do {
290
+            AVDictionary *opts = NULL;
291
+            char buf[256];
292
+            snprintf(buf, sizeof(buf), "%d", rt->buffer_size);
293
+            av_dict_set(&opts, "buffer_size", buf, 0);
290 294
             ff_url_join(url, sizeof(url), "rtp", NULL, host, localport, NULL);
291 295
             av_dlog(s, "Opening: %s", url);
292 296
             ret = ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
293
-                             &s->interrupt_callback, NULL);
297
+                             &s->interrupt_callback, &opts);
298
+            av_dict_free(&opts);
294 299
             if (ret)
295 300
                 localport += 2;
296 301
         } while (ret || localport > rt->rtp_port_max);