[FFmpeg-devel] [PATCH] avformat/rtmpproto: Handle NetStream.Play.PublishNotify by re-creating stream.

Ahmed Ammar aammar at genesi-usa.com
Sat Oct 22 12:03:36 EEST 2016


---
 libavformat/rtmpproto.c | 49 +++++++++++++++++++++++++++++++++++++------------
 1 file changed, 37 insertions(+), 12 deletions(-)

diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 95d1c1d..8a32222 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -227,6 +227,11 @@ static int rtmp_send_packet(RTMPContext *rt, RTMPPacket *pkt, int track)
 {
     int ret;
 
+#ifdef DEBUG
+    av_log(rt, AV_LOG_DEBUG, "Sending packet:\n");
+    ff_rtmp_packet_dump(rt, pkt);
+#endif
+
     if (pkt->type == RTMP_PT_INVOKE && track) {
         GetByteContext gbc;
         char name[128];
@@ -2032,6 +2037,29 @@ static int read_number_result(RTMPPacket *pkt, double *number)
     return 0;
 }
 
+static int subscribe_stream(URLContext *s, RTMPContext *rt)
+{
+    int ret = 0;
+
+    if ((ret = gen_create_stream(s, rt)) < 0)
+        goto fail;
+
+    if (rt->is_input) {
+        /* Send the FCSubscribe command when the name of live
+         * stream is defined by the user or if it's a live stream. */
+        if (rt->subscribe) {
+            if ((ret = gen_fcsubscribe_stream(s, rt, rt->subscribe)) < 0)
+                goto fail;
+        } else if (rt->live == -1) {
+            if ((ret = gen_fcsubscribe_stream(s, rt, rt->playpath)) < 0)
+                goto fail;
+        }
+    }
+
+fail:
+    return ret;
+}
+
 static int handle_invoke_result(URLContext *s, RTMPPacket *pkt)
 {
     RTMPContext *rt = s->priv_data;
@@ -2058,20 +2086,9 @@ static int handle_invoke_result(URLContext *s, RTMPPacket *pkt)
                 goto fail;
         }
 
-        if ((ret = gen_create_stream(s, rt)) < 0)
+        if ((ret = subscribe_stream(s, rt)) < 0)
             goto fail;
 
-        if (rt->is_input) {
-            /* Send the FCSubscribe command when the name of live
-             * stream is defined by the user or if it's a live stream. */
-            if (rt->subscribe) {
-                if ((ret = gen_fcsubscribe_stream(s, rt, rt->subscribe)) < 0)
-                    goto fail;
-            } else if (rt->live == -1) {
-                if ((ret = gen_fcsubscribe_stream(s, rt, rt->playpath)) < 0)
-                    goto fail;
-            }
-        }
     } else if (!strcmp(tracked_method, "createStream")) {
         double stream_id;
         if (read_number_result(pkt, &stream_id)) {
@@ -2137,6 +2154,13 @@ static int handle_invoke_status(URLContext *s, RTMPPacket *pkt)
     if (!t && !strcmp(tmpstr, "NetStream.Play.UnpublishNotify")) rt->state = STATE_STOPPED;
     if (!t && !strcmp(tmpstr, "NetStream.Publish.Start")) rt->state = STATE_PUBLISHING;
     if (!t && !strcmp(tmpstr, "NetStream.Seek.Notify")) rt->state = STATE_PLAYING;
+    if (!t && !strcmp(tmpstr, "NetStream.Play.PublishNotify")) {
+        if (gen_delete_stream(s, rt) < 0)
+            return -1;
+
+        if (subscribe_stream(s, rt) < 0)
+            return -1;
+    }
 
     return 0;
 }
@@ -2292,6 +2316,7 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
     int ret;
 
 #ifdef DEBUG
+    av_log(rt, AV_LOG_DEBUG, "Received packet:\n");
     ff_rtmp_packet_dump(s, pkt);
 #endif
 
-- 
2.8.4 (Apple Git-73)



More information about the ffmpeg-devel mailing list