On Wed, 12 Oct 2011 20:56:13 +0300, Martin Storsjö <[email protected]> wrote:
> Eventually, the old way of passing options by adding
> stuff to the URL can be dropped.
>
> This avoids having to tamper with the user-specified URL to
> pass options on the transport mode. This also works better
> with redirects, since the options don't need to be parsed out
> from the URL.
> ---
> libavformat/rtsp.c | 27 +++++++++++++++++++++++++--
> libavformat/rtsp.h | 12 +++++++++++-
> libavformat/version.h | 5 ++++-
> 3 files changed, 40 insertions(+), 4 deletions(-)
>
> diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
> index bd94c09..27cf78c 100644
> --- a/libavformat/rtsp.c
> +++ b/libavformat/rtsp.c
> @@ -60,6 +60,13 @@
> const AVOption ff_rtsp_options[] = {
> { "initial_pause", "Don't start playing the stream immediately",
> offsetof(RTSPState, initial_pause), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1,
> AV_OPT_FLAG_DECODING_PARAM },
> FF_RTP_FLAG_OPTS(RTSPState, rtp_muxer_flags),
> + { "rtsp_transport", "RTSP transport protocols", offsetof(RTSPState,
> lower_transport_mask), FF_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX,
> AV_OPT_FLAG_DECODING_PARAM|AV_OPT_FLAG_ENCODING_PARAM, "rtsp_transport" }, \
> + { "udp", "UDP", 0, FF_OPT_TYPE_CONST, {.dbl = 1 <<
> RTSP_LOWER_TRANSPORT_UDP}, INT_MIN, INT_MAX,
> AV_OPT_FLAG_DECODING_PARAM|AV_OPT_FLAG_ENCODING_PARAM, "rtsp_transport" }, \
> + { "tcp", "TCP", 0, FF_OPT_TYPE_CONST, {.dbl = 1 <<
> RTSP_LOWER_TRANSPORT_TCP}, INT_MIN, INT_MAX,
> AV_OPT_FLAG_DECODING_PARAM|AV_OPT_FLAG_ENCODING_PARAM, "rtsp_transport" }, \
> + { "udp_multicast", "UDP multicast", 0, FF_OPT_TYPE_CONST, {.dbl = 1 <<
> RTSP_LOWER_TRANSPORT_UDP_MULTICAST}, INT_MIN, INT_MAX,
> AV_OPT_FLAG_DECODING_PARAM, "rtsp_transport" },
> + { "http", "HTTP tunneling", 0, FF_OPT_TYPE_CONST, {.dbl = (1 <<
> RTSP_LOWER_TRANSPORT_HTTP)}, INT_MIN, INT_MAX, AV_OPT_FLAG_DECODING_PARAM,
> "rtsp_transport" },
> + { "rtsp_flags", "RTSP flags", offsetof(RTSPState, rtsp_flags),
> FF_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_DECODING_PARAM,
> "rtsp_flags" },
> + { "filter_src", "Only receive packets from the negotiated peer IP", 0,
> FF_OPT_TYPE_CONST, {.dbl = RTSP_FLAG_FILTER_SRC}, INT_MIN, INT_MAX,
> AV_OPT_FLAG_DECODING_PARAM, "rtsp_flags" },
> { NULL },
> };
Except for FF->AV issue, some cosmetics suggestions
* we usually #define OFFSET(x) offsetof(priv context, x) and
AV_OPT_FLAG_blah to something shorter, this saves a lot of space
* you can omit .dbl as it's the first element in the union
* min/max make no sense for named constants, so you can set them to 0
and save some more space
* vertical alignment would help readability
feel free to implement as many or as few as you like
>
> @@ -1308,15 +1315,23 @@ int ff_rtsp_connect(AVFormatContext *s)
> char *option_list, *option, *filename;
> int port, err, tcp_fd;
> RTSPMessageHeader reply1 = {0}, *reply = &reply1;
> - int lower_transport_mask = 0;
> + int lower_transport_mask = rt->lower_transport_mask;
> char real_challenge[64] = "";
> struct sockaddr_storage peer;
> socklen_t peer_len = sizeof(peer);
>
> if (!ff_network_init())
> return AVERROR(EIO);
> -redirect:
> +
> rt->control_transport = RTSP_MODE_PLAIN;
> + if (lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_HTTP)) {
> + lower_transport_mask = 1 << RTSP_LOWER_TRANSPORT_TCP;
> + rt->control_transport = RTSP_MODE_TUNNEL;
> + }
> + if (rt->rtsp_flags & RTSP_FLAG_FILTER_SRC)
> + rt->filter_source = 1;
> +
> +redirect:
> /* extract hostname and port */
> av_url_split(NULL, 0, auth, sizeof(auth),
> host, sizeof(host), &port, path, sizeof(path), s->filename);
> @@ -1326,6 +1341,7 @@ redirect:
> if (port < 0)
> port = RTSP_DEFAULT_PORT;
>
> +#if FF_API_RTSP_URL_OPTIONS
> /* search for options */
> option_list = strrchr(path, '?');
> if (option_list) {
> @@ -1333,6 +1349,7 @@ redirect:
> * the options back into the same string. */
> filename = option_list;
> while (option_list) {
> + int handled = 1;
> /* move the option pointer */
> option = ++option_list;
> option_list = strchr(option_list, '&');
> @@ -1358,10 +1375,16 @@ redirect:
> memmove(++filename, option, len);
> filename += len;
> if (option_list) *filename = '&';
> + handled = 0;
> }
> + if (handled)
> + av_log(s, AV_LOG_WARNING, "Options passed via URL are "
> + "deprecated, use -rtsp_transport "
> + "and -rtsp_flags instead.\n");
> }
> *filename = 0;
> }
> +#endif
>
> if (!lower_transport_mask)
> lower_transport_mask = (1 << RTSP_LOWER_TRANSPORT_NB) - 1;
> diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
> index 5327b00..ba87c53 100644
> --- a/libavformat/rtsp.h
> +++ b/libavformat/rtsp.h
> @@ -38,7 +38,10 @@ enum RTSPLowerTransport {
> RTSP_LOWER_TRANSPORT_UDP = 0, /**< UDP/unicast */
> RTSP_LOWER_TRANSPORT_TCP = 1, /**< TCP; interleaved in RTSP */
> RTSP_LOWER_TRANSPORT_UDP_MULTICAST = 2, /**< UDP/multicast */
> - RTSP_LOWER_TRANSPORT_NB
> + RTSP_LOWER_TRANSPORT_NB,
> + RTSP_LOWER_TRANSPORT_HTTP = 8, /**< HTTP tunneled - not a proper
> + transport mode as such,
> + only for use via AVOptions
> */
> };
>
> /**
> @@ -350,8 +353,15 @@ typedef struct RTSPState {
>
> /** Whether the server accepts the x-Dynamic-Rate header */
> int accept_dynamic_rate;
> +
> + /**
> + * Various option flags for the RTSP muxer/demuxer.
> + */
> + int rtsp_flags;
> } RTSPState;
>
> +#define RTSP_FLAG_FILTER_SRC 0x1
I would make this a separate option -- makes for less code, since you
can set rt->filter_source directly.
--
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel