From b0f7a26f1a6dc061db0a60908842371e7a010db2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 22 Sep 2013 02:40:29 +0200 Subject: network: fix rtsp playback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, libavformat uses UDP for rtsp playback. This doesn't work very well. Apparently the reason is that the buffer sizes libavformat chooses for UDP are way too small, and switching to TCP gets rid of this issue entirely (thanks go to Reimar Döffinger for figuring this out). In theory, you can set buffer sizes as libavformat options, but that doesn't seem to help. Add an option to select the rtsp transport, and make TCP the default. Also remove an outdated comment from stream.c. --- DOCS/man/en/options.rst | 5 +++++ demux/demux_lavf.c | 23 ++++++++++++++++++++++- mpvcore/options.c | 6 ++++++ mpvcore/options.h | 1 + stream/stream.c | 2 +- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index 766118e4c6..8efb1eb70f 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -1772,6 +1772,11 @@ - ``--reset-on-next-file=""`` Do not reset pause mode. +``--rtsp-transport=`` + Select RTSP transport method (default: tcp). This selects the underlying + network transport when playing ``rtsp://...`` URLs. The value ``lavf`` + leaves the decision to libavformat. + ``--saturation=<-100-100>`` Adjust the saturation of the video signal (default: 0). You can get grayscale output with this option. Not supported by all video output diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index dbe16a76b9..1e071f20e2 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -603,12 +603,33 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check) avfc->pb = priv->pb; } - if (avformat_open_input(&avfc, priv->filename, priv->avif, NULL) < 0) { + AVDictionary *dopts = NULL; + + if (matches_avinputformat_name(priv, "rtsp")) { + const char *transport = NULL; + switch (opts->network_rtsp_transport) { + case 1: transport = "udp"; break; + case 2: transport = "tcp"; break; + case 3: transport = "http"; break; + } + if (transport) + av_dict_set(&dopts, "rtsp_transport", transport, 0); + } + + if (avformat_open_input(&avfc, priv->filename, priv->avif, &dopts) < 0) { mp_msg(MSGT_HEADER, MSGL_ERR, "LAVF_header: avformat_open_input() failed\n"); + av_dict_free(&dopts); return -1; } + t = NULL; + while ((t = av_dict_get(dopts, "", t, AV_DICT_IGNORE_SUFFIX))) { + mp_msg(MSGT_OPEN, MSGL_V, "[lavf] Could not set demux option %s=%s\n", + t->key, t->value); + } + av_dict_free(&dopts); + priv->avfc = avfc; if (avformat_find_stream_info(avfc, NULL) < 0) { mp_msg(MSGT_HEADER, MSGL_ERR, diff --git a/mpvcore/options.c b/mpvcore/options.c index e3b3137aed..afeb7e80fa 100644 --- a/mpvcore/options.c +++ b/mpvcore/options.c @@ -382,6 +382,11 @@ const m_option_t mp_opts[] = { {"referrer", &network_referrer, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"cookies", &network_cookies_enabled, CONF_TYPE_FLAG, 0, 0, 1, NULL}, {"cookies-file", &cookies_file, CONF_TYPE_STRING, 0, 0, 0, NULL}, + OPT_CHOICE("rtsp-transport", network_rtsp_transport, 0, + ({"lavf", 0}, + {"udp", 1}, + {"tcp", 2}, + {"http", 3})), // ------------------------- demuxer options -------------------- @@ -794,6 +799,7 @@ const struct MPOpts mp_default_opts = { .stream_cache_min_percent = 20.0, .stream_cache_seek_min_percent = 50.0, .stream_cache_pause = 10.0, + .network_rtsp_transport = 2, .chapterrange = {-1, -1}, .edition_id = -1, .default_max_pts_correction = -1, diff --git a/mpvcore/options.h b/mpvcore/options.h index d425d0789b..b1058fca37 100644 --- a/mpvcore/options.h +++ b/mpvcore/options.h @@ -98,6 +98,7 @@ typedef struct MPOpts { int stream_cache_def_size; float stream_cache_min_percent; float stream_cache_seek_min_percent; + int network_rtsp_transport; int stream_cache_pause; int chapterrange[2]; int edition_id; diff --git a/stream/stream.c b/stream/stream.c index eaf8e4dc51..186fc7c79d 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -86,7 +86,7 @@ static const stream_info_t *const stream_list[] = { #ifdef CONFIG_CDDA &stream_info_cdda, #endif - &stream_info_ffmpeg, // use for rstp:// before http fallback + &stream_info_ffmpeg, &stream_info_avdevice, #ifdef CONFIG_DVBIN &stream_info_dvb, -- cgit v1.2.3