[libav-commits] rtmp: Support 'rtmp_playpath', an option which overrides the stream identifier

Samuel Pitoiset git at libav.org
Mon Apr 16 22:17:48 CEST 2012


Module: libav
Branch: master
Commit: b3b175120151b9d39f05a7e24e322a70ab835138

Author:    Samuel Pitoiset <samuel.pitoiset at gmail.com>
Committer: Martin Storsjö <martin at martin.st>
Date:      Sun Apr 15 21:50:50 2012 +0200

rtmp: Support 'rtmp_playpath', an option which overrides the stream identifier

This option is the stream identifier to play or to publish.
Sometimes the URL parser cannot determine the correct
playpath automatically, so it must be given explicitly
using this option (ie. -rtmp_playpath).

Signed-off-by: Martin Storsjö <martin at martin.st>

---

 libavformat/rtmpproto.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 1d27c6f..9cdb639 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -43,6 +43,7 @@
 //#define DEBUG
 
 #define APP_MAX_LENGTH 128
+#define PLAYPATH_MAX_LENGTH 256
 
 /** RTMP protocol handler state */
 typedef enum {
@@ -64,7 +65,7 @@ typedef struct RTMPContext {
     RTMPPacket    prev_pkt[2][RTMP_CHANNELS]; ///< packet history used when reading and sending packets
     int           chunk_size;                 ///< size of the chunks RTMP packets are divided into
     int           is_input;                   ///< input/output flag
-    char          playpath[256];              ///< path to filename to play (with possible "mp4:" prefix)
+    char          *playpath;                  ///< stream identifier to play (with possible "mp4:" prefix)
     char          *app;                       ///< name of application
     ClientState   state;                      ///< current state
     int           main_channel_id;            ///< an additional channel ID which is used for some invocations
@@ -890,14 +891,22 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
         rt->app = old_app;
     }
 
-    if (!strchr(fname, ':') &&
-        (!strcmp(fname + strlen(fname) - 4, ".f4v") ||
-         !strcmp(fname + strlen(fname) - 4, ".mp4"))) {
-        memcpy(rt->playpath, "mp4:", 5);
-    } else {
-        rt->playpath[0] = 0;
+    if (!rt->playpath) {
+        rt->playpath = av_malloc(PLAYPATH_MAX_LENGTH);
+        if (!rt->playpath) {
+            rtmp_close(s);
+            return AVERROR(ENOMEM);
+        }
+
+        if (!strchr(fname, ':') &&
+            (!strcmp(fname + strlen(fname) - 4, ".f4v") ||
+             !strcmp(fname + strlen(fname) - 4, ".mp4"))) {
+            memcpy(rt->playpath, "mp4:", 5);
+        } else {
+            rt->playpath[0] = 0;
+        }
+        strncat(rt->playpath, fname, PLAYPATH_MAX_LENGTH - 5);
     }
-    strncat(rt->playpath, fname, sizeof(rt->playpath) - 5);
 
     rt->client_report_size = 1048576;
     rt->bytes_read = 0;
@@ -1041,6 +1050,7 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
 
 static const AVOption rtmp_options[] = {
     {"rtmp_app", "Name of application to connect to on the RTMP server", OFFSET(app), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
+    {"rtmp_playpath", "Stream identifier to play or to publish", OFFSET(playpath), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
     { NULL },
 };
 



More information about the libav-commits mailing list