Commit 53bf6b15 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'e3ec6fe7'

* commit 'e3ec6fe7':
  rtsp: Add a buffer_size option

Conflicts:
	libavformat/rtsp.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents b99a8e4e e3ec6fe7
...@@ -74,8 +74,10 @@ ...@@ -74,8 +74,10 @@
{ "data", "Data", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_DATA}, 0, 0, DEC, "allowed_media_types" }, \ { "data", "Data", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_DATA}, 0, 0, DEC, "allowed_media_types" }, \
{ "subtitle", "Subtitle", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_SUBTITLE}, 0, 0, DEC, "allowed_media_types" } { "subtitle", "Subtitle", 0, AV_OPT_TYPE_CONST, {.i64 = 1 << AVMEDIA_TYPE_SUBTITLE}, 0, 0, DEC, "allowed_media_types" }
#define RTSP_REORDERING_OPTS() \ #define COMMON_OPTS() \
{ "reorder_queue_size", "set number of packets to buffer for handling of reordered packets", OFFSET(reordering_queue_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, DEC } { "reorder_queue_size", "set 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[] = { const AVOption ff_rtsp_options[] = {
{ "initial_pause", "do not start playing the stream immediately", OFFSET(initial_pause), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC }, { "initial_pause", "do not start playing the stream immediately", OFFSET(initial_pause), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC },
...@@ -93,7 +95,7 @@ const AVOption ff_rtsp_options[] = { ...@@ -93,7 +95,7 @@ const AVOption ff_rtsp_options[] = {
{ "max_port", "set maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC }, { "max_port", "set maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
{ "timeout", "set maximum timeout (in seconds) to wait for incoming connections (-1 is infinite, imply flag listen)", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC }, { "timeout", "set maximum timeout (in seconds) to wait for incoming connections (-1 is infinite, imply flag listen)", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC },
{ "stimeout", "set timeout (in microseconds) of socket TCP I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC }, { "stimeout", "set timeout (in microseconds) of socket TCP I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC },
RTSP_REORDERING_OPTS(), COMMON_OPTS(),
{ "user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT}, 0, 0, DEC }, { "user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT}, 0, 0, DEC },
{ NULL }, { NULL },
}; };
...@@ -103,16 +105,28 @@ static const AVOption sdp_options[] = { ...@@ -103,16 +105,28 @@ static const AVOption sdp_options[] = {
{ "custom_io", "use custom I/O", 0, AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_CUSTOM_IO}, 0, 0, DEC, "rtsp_flags" }, { "custom_io", "use custom I/O", 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" }, { "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", "set media types to accept from the server"), RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from the server"),
RTSP_REORDERING_OPTS(), COMMON_OPTS(),
{ NULL }, { NULL },
}; };
static const AVOption rtp_options[] = { static const AVOption rtp_options[] = {
RTSP_FLAG_OPTS("rtp_flags", "set RTP flags"), RTSP_FLAG_OPTS("rtp_flags", "set RTP flags"),
RTSP_REORDERING_OPTS(), COMMON_OPTS(),
{ NULL }, { 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, static void get_word_until_chars(char *buf, int buf_size,
const char *sep, const char **pp) const char *sep, const char **pp)
{ {
...@@ -1436,12 +1450,18 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, ...@@ -1436,12 +1450,18 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
/* first try in specified port range */ /* first try in specified port range */
while (j <= rt->rtp_port_max) { while (j <= rt->rtp_port_max) {
AVDictionary *opts = map_to_opts(rt);
ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1, ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1,
"?localport=%d", j); "?localport=%d", j);
/* we will use two ports per rtp stream (rtp and rtcp) */ /* we will use two ports per rtp stream (rtp and rtcp) */
j += 2; j += 2;
if (!ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE, err = ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE,
&s->interrupt_callback, NULL)) &s->interrupt_callback, &opts);
av_dict_free(&opts);
if (!err)
goto rtp_opened; goto rtp_opened;
} }
av_log(s, AV_LOG_ERROR, "Unable to open an input RTP port\n"); av_log(s, AV_LOG_ERROR, "Unable to open an input RTP port\n");
...@@ -2256,6 +2276,8 @@ static int sdp_read_header(AVFormatContext *s) ...@@ -2256,6 +2276,8 @@ static int sdp_read_header(AVFormatContext *s)
rtsp_st = rt->rtsp_streams[i]; rtsp_st = rt->rtsp_streams[i];
if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) { 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), getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip),
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST); namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
ff_url_join(url, sizeof(url), "rtp", NULL, ff_url_join(url, sizeof(url), "rtp", NULL,
...@@ -2271,8 +2293,12 @@ static int sdp_read_header(AVFormatContext *s) ...@@ -2271,8 +2293,12 @@ static int sdp_read_header(AVFormatContext *s)
append_source_addrs(url, sizeof(url), "block", append_source_addrs(url, sizeof(url), "block",
rtsp_st->nb_exclude_source_addrs, rtsp_st->nb_exclude_source_addrs,
rtsp_st->exclude_source_addrs); rtsp_st->exclude_source_addrs);
if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, err = ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
&s->interrupt_callback, NULL) < 0) { &s->interrupt_callback, &opts);
av_dict_free(&opts);
if (err < 0) {
err = AVERROR_INVALIDDATA; err = AVERROR_INVALIDDATA;
goto fail; goto fail;
} }
......
...@@ -407,6 +407,7 @@ typedef struct RTSPState { ...@@ -407,6 +407,7 @@ typedef struct RTSPState {
char *user_agent; char *user_agent;
char default_lang[4]; char default_lang[4];
int buffer_size;
} RTSPState; } RTSPState;
#define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets - #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,10 +287,15 @@ static int rtsp_read_setup(AVFormatContext *s, char* host, char *controlurl)
request.transports[0].interleaved_max); request.transports[0].interleaved_max);
} else { } else {
do { 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); ff_url_join(url, sizeof(url), "rtp", NULL, host, localport, NULL);
av_dlog(s, "Opening: %s", url); av_dlog(s, "Opening: %s", url);
ret = ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, 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) if (ret)
localport += 2; localport += 2;
} while (ret || localport > rt->rtp_port_max); } while (ret || localport > rt->rtp_port_max);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment