[FFmpeg-devel] [PATCH v2] avformat/icecast: Add option to use TLS connection

Marvin Scholz epirat07 at gmail.com
Sun Jun 14 01:31:58 EEST 2020


---
 doc/protocols.texi    | 3 +++
 libavformat/icecast.c | 8 +++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index 7aa758541c..32c829d2a3 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -520,6 +520,9 @@ audio/mpeg.
 This enables support for Icecast versions < 2.4.0, that do not support the
 HTTP PUT method but the SOURCE method.
 
+ at item tls
+Establish a TLS (HTTPS) connection to Icecast.
+
 @end table
 
 @example
diff --git a/libavformat/icecast.c b/libavformat/icecast.c
index 38af16b99e..cd70d3d337 100644
--- a/libavformat/icecast.c
+++ b/libavformat/icecast.c
@@ -43,6 +43,7 @@ typedef struct IcecastContext {
     int public;
     char *url;
     char *user_agent;
+    int tls;
 } IcecastContext;
 
 #define DEFAULT_ICE_USER "source"
@@ -62,6 +63,7 @@ static const AVOption options[] = {
     { "password", "set password", OFFSET(pass), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
     { "content_type", "set content-type, MUST be set if not audio/mpeg", OFFSET(content_type), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
     { "legacy_icecast", "use legacy SOURCE method, for Icecast < v2.4", OFFSET(legacy_icecast), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
+    { "tls", "use a TLS connection", OFFSET(tls), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
     { NULL }
 };
 
@@ -89,6 +91,7 @@ static int icecast_open(URLContext *h, const char *uri, int flags)
     // URI part variables
     char h_url[1024], host[1024], auth[1024], path[1024];
     char *headers, *user = NULL;
+    const char *real_proto;
     int port, ret;
     AVBPrint bp;
 
@@ -161,8 +164,11 @@ static int icecast_open(URLContext *h, const char *uri, int flags)
         goto cleanup;
     }
 
+    // Check which underlying protocol should be used
+    real_proto = (s->tls) ? "https" : "http";
+
     // Build new URI for passing to http protocol
-    ff_url_join(h_url, sizeof(h_url), "http", auth, host, port, "%s", path);
+    ff_url_join(h_url, sizeof(h_url), real_proto, auth, host, port, "%s", path);
     // Finally open http proto handler
     ret = ffurl_open_whitelist(&s->hd, h_url, AVIO_FLAG_READ_WRITE, NULL,
                                &opt_dict, h->protocol_whitelist, h->protocol_blacklist, h);
-- 
2.24.1 (Apple Git-126)



More information about the ffmpeg-devel mailing list