[FFmpeg-devel] support rtmp_listen with rtmps

Submitted by Chen Fisher on Jan. 24, 2019, 12:36 p.m.

Details

Message ID 20190124123653.54573-1-chen.fisher@gmail.com
State New
Headers show

Commit Message

Chen Fisher Jan. 24, 2019, 12:36 p.m.
Signed-off-by: Chen Fisher <chen.fisher@gmail.com>
---
 libavformat/rtmpproto.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index b741e421af..82b3688658 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -129,6 +129,8 @@  typedef struct RTMPContext {
     char          auth_params[500];
     int           do_reconnect;
     int           auth_tried;
+    char*         cert_file;
+    char*         key_file;
 } RTMPContext;
 
 #define PLAYER_KEY_OPEN_PART_LEN 30   ///< length of partial key used for first client digest signing
@@ -2625,7 +2627,7 @@  static int rtmp_open(URLContext *s, const char *uri, int flags, AVDictionary **o
         }
     }
 
-    if (rt->listen && strcmp(proto, "rtmp")) {
+    if (rt->listen && strcmp(proto, "rtmp") && strcmp(proto, "rtmps")) {
         av_log(s, AV_LOG_ERROR, "rtmp_listen not available for %s\n",
                proto);
         return AVERROR(EINVAL);
@@ -2640,7 +2642,12 @@  static int rtmp_open(URLContext *s, const char *uri, int flags, AVDictionary **o
         /* open the tls connection */
         if (port < 0)
             port = RTMPS_DEFAULT_PORT;
-        ff_url_join(buf, sizeof(buf), "tls", NULL, hostname, port, NULL);
+        if (rt->listen)
+          ff_url_join(buf, sizeof(buf), "tls", NULL, hostname, port,
+              "?listen&listen_timeout=%d&cert=%s&key=%s",
+              rt->listen_timeout * 1000, rt->cert_file, rt->key_file);
+        else
+          ff_url_join(buf, sizeof(buf), "tls", NULL, hostname, port, NULL);
     } else if (!strcmp(proto, "rtmpe") || (!strcmp(proto, "rtmpte"))) {
         if (!strcmp(proto, "rtmpte"))
             av_dict_set(opts, "ffrtmpcrypt_tunneling", "1", 1);
@@ -3112,6 +3119,8 @@  static const AVOption rtmp_options[] = {
     {"rtmp_listen", "Listen for incoming rtmp connections", OFFSET(listen), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC, "rtmp_listen" },
     {"listen",      "Listen for incoming rtmp connections", OFFSET(listen), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC, "rtmp_listen" },
     {"timeout", "Maximum timeout (in seconds) to wait for incoming connections. -1 is infinite. Implies -rtmp_listen 1",  OFFSET(listen_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC, "rtmp_listen" },
+    {"cert_file", "Certificate file", OFFSET(cert_file), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
+    {"key_file", "Key file", OFFSET(key_file), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
     { NULL },
 };