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 },
 };
 
@@ -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
+
 /**
  * Describes a single stream, as identified by a single m= line block in the
  * SDP content. In the case of RDT, one RTSPStream can represent multiple
diff --git a/libavformat/version.h b/libavformat/version.h
index 82a07db..fb8eeff 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -25,7 +25,7 @@
 
 #define LIBAVFORMAT_VERSION_MAJOR 53
 #define LIBAVFORMAT_VERSION_MINOR  8
-#define LIBAVFORMAT_VERSION_MICRO  0
+#define LIBAVFORMAT_VERSION_MICRO  1
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
@@ -86,5 +86,8 @@
 #ifndef FF_API_TIMESTAMP
 #define FF_API_TIMESTAMP               (LIBAVFORMAT_VERSION_MAJOR < 54)
 #endif
+#ifndef FF_API_RTSP_URL_OPTIONS
+#define FF_API_RTSP_URL_OPTIONS        (LIBAVFORMAT_VERSION_MAJOR < 54)
+#endif
 
 #endif /* AVFORMAT_VERSION_H */
-- 
1.7.3.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to