[FFmpeg-cvslog] rtsp: Add a buffer_size option
Luca Barbato
git at videolan.org
Wed Apr 1 21:53:50 CEST 2015
ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Sun Mar 22 21:16:55 2015 +0100| [e3ec6fe7bb2a622a863e3912181717a659eb1bad] | committer: Luca Barbato
rtsp: Add a buffer_size option
And forward it to rtp and udp.
Signed-off-by: Luca Barbato <lu_zero at gentoo.org>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e3ec6fe7bb2a622a863e3912181717a659eb1bad
---
libavformat/rtsp.c | 44 +++++++++++++++++++++++++++++++++++---------
libavformat/rtsp.h | 1 +
libavformat/rtspdec.c | 7 ++++++-
3 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 55a7896..1c2c555 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -72,8 +72,10 @@
{ "audio", "Audio", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_AUDIO}, 0, 0, DEC, "allowed_media_types" }, \
{ "data", "Data", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_DATA}, 0, 0, DEC, "allowed_media_types" }
-#define RTSP_REORDERING_OPTS() \
- { "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 }
+#define COMMON_OPTS() \
+ { "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 }, \
+ { "buffer_size", "Underlying protocol send/receive buffer size", OFFSET(buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, DEC|ENC } \
+
const AVOption ff_rtsp_options[] = {
{ "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[] = {
{ "min_port", "Minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC },
{ "max_port", "Maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
{ "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 },
- RTSP_REORDERING_OPTS(),
+ COMMON_OPTS(),
{ NULL },
};
@@ -98,16 +100,28 @@ static const AVOption sdp_options[] = {
{ "custom_io", "Use custom IO", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_CUSTOM_IO}, 0, 0, DEC, "rtsp_flags" },
{ "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" },
RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
- RTSP_REORDERING_OPTS(),
+ COMMON_OPTS(),
{ NULL },
};
static const AVOption rtp_options[] = {
RTSP_FLAG_OPTS("rtp_flags", "RTP flags"),
- RTSP_REORDERING_OPTS(),
+ COMMON_OPTS(),
{ NULL },
};
+
+static AVDictionary *map_to_opts(RTSPState *rt)
+{
+ AVDictionary *opts = NULL;
+ char buf[256];
+
+ snprintf(buf, sizeof(buf), "%d", rt->buffer_size);
+ av_dict_set(&opts, "buffer_size", buf, 0);
+
+ return opts;
+}
+
static void get_word_until_chars(char *buf, int buf_size,
const char *sep, const char **pp)
{
@@ -1433,12 +1447,18 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
/* first try in specified port range */
while (j <= rt->rtp_port_max) {
+ AVDictionary *opts = map_to_opts(rt);
+
ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1,
"?localport=%d", j);
/* we will use two ports per rtp stream (rtp and rtcp) */
j += 2;
- if (!ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE,
- &s->interrupt_callback, NULL))
+ err = ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE,
+ &s->interrupt_callback, &opts);
+
+ av_dict_free(&opts);
+
+ if (!err)
goto rtp_opened;
}
@@ -2236,6 +2256,8 @@ static int sdp_read_header(AVFormatContext *s)
rtsp_st = rt->rtsp_streams[i];
if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) {
+ AVDictionary *opts = map_to_opts(rt);
+
getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip),
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
ff_url_join(url, sizeof(url), "rtp", NULL,
@@ -2251,8 +2273,12 @@ static int sdp_read_header(AVFormatContext *s)
append_source_addrs(url, sizeof(url), "block",
rtsp_st->nb_exclude_source_addrs,
rtsp_st->exclude_source_addrs);
- if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
- &s->interrupt_callback, NULL) < 0) {
+ err = ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
+ &s->interrupt_callback, &opts);
+
+ av_dict_free(&opts);
+
+ if (err < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
}
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 83255a3..7473336 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -397,6 +397,7 @@ typedef struct RTSPState {
int reordering_queue_size;
char default_lang[4];
+ int buffer_size;
} RTSPState;
#define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets -
diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
index 659c768..bb9c674 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -287,10 +287,15 @@ static int rtsp_read_setup(AVFormatContext *s, char* host, char *controlurl)
request.transports[0].interleaved_max);
} else {
do {
+ AVDictionary *opts = NULL;
+ char buf[256];
+ snprintf(buf, sizeof(buf), "%d", rt->buffer_size);
+ av_dict_set(&opts, "buffer_size", buf, 0);
ff_url_join(url, sizeof(url), "rtp", NULL, host, localport, NULL);
av_dlog(s, "Opening: %s", url);
ret = ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
- &s->interrupt_callback, NULL);
+ &s->interrupt_callback, &opts);
+ av_dict_free(&opts);
if (ret)
localport += 2;
} while (ret || localport > rt->rtp_port_max);
More information about the ffmpeg-cvslog
mailing list