onMetadata is forwarded for sure on rtmp, custom scriptdata might not.
---
 libavformat/flvdec.c |   35 +++++++++++++++++++++++------------
 libavformat/flvenc.c |    4 ++--
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 7b348cd..2b07fb3 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -203,6 +203,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream 
*astream, AVStream *vst
     AMFDataType amf_type;
     char str_val[256];
     double num_val;
+    int ret;
 
     num_val = 0;
     ioc = s->pb;
@@ -242,8 +243,10 @@ static int amf_parse_object(AVFormatContext *s, AVStream 
*astream, AVStream *vst
             avio_skip(ioc, 4); //skip 32-bit max array index
             while(avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, 
sizeof(str_val)) > 0) {
                 //this is the only case in which we would want a nested parse 
to not skip over the object
-                if(amf_parse_object(s, astream, vstream, str_val, max_pos, 
depth + 1) < 0)
-                    return -1;
+                ret = amf_parse_object(s, astream, vstream, str_val,
+                                       max_pos, depth + 1);
+                if(ret)
+                    return ret;
             }
             if(avio_r8(ioc) != AMF_END_OF_OBJECT)
                 return -1;
@@ -288,8 +291,11 @@ static int amf_parse_object(AVFormatContext *s, AVStream 
*astream, AVStream *vst
                 st->codec->codec_id = num_val;
                 av_set_pts_info(st, 32, 1, 1000);
             }
-        } else if (amf_type == AMF_DATA_TYPE_STRING)
+        } else if (amf_type == AMF_DATA_TYPE_STRING) {
+            if(!strcmp(key, "data-stream-packet"))
+                return 1;
             av_metadata_set2(&s->metadata, key, str_val, 0);
+        }
     }
 
     return 0;
@@ -299,7 +305,8 @@ static int flv_read_metabody(AVFormatContext *s, int64_t 
next_pos) {
     AMFDataType type;
     AVStream *stream, *astream, *vstream;
     AVIOContext *ioc;
-    int i;
+    int i, ret;
+    int64_t pos;
     char buffer[12]; //only needs to hold the string "data-stream". Anything 
longer is something we don't want.
 
     astream = NULL;
@@ -312,9 +319,6 @@ static int flv_read_metabody(AVFormatContext *s, int64_t 
next_pos) {
         amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
         return -1;
 
-    if(!strcmp(buffer, "data-stream"))
-        return 1;
-
     if(strcmp(buffer, "onMetaData"))
         return -1;
 
@@ -325,11 +329,15 @@ static int flv_read_metabody(AVFormatContext *s, int64_t 
next_pos) {
         else if(stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) vstream = 
stream;
     }
 
-    //parse the second object (we want a mixed array)
-    if(amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
-        return -1;
+    pos = avio_tell(ioc);
 
-    return 0;
+    //parse the second object (we want a mixed array)
+    ret = amf_parse_object(s, astream, vstream, buffer, next_pos, 0);
+    if (ret > 0) {
+        av_log(NULL, AV_LOG_INFO, " ");
+        avio_seek(ioc, pos, SEEK_SET);
+    }
+    return ret;
 }
 
 static AVStream *create_stream(AVFormatContext *s, int is_audio){
@@ -411,7 +419,10 @@ static int flv_data_packet(AVFormatContext *s, AVPacket 
*pkt,
         goto out;
     codec_id = av_int2dbl(avio_rb64(pb));
     amf_get_string(pb, buf, sizeof(buf));
-    if (strcmp(buf,"data") && avio_r8(pb) != AMF_DATA_TYPE_STRING)
+    if (strcmp(buf,"data-stream-packet"))
+        goto out;
+    type = avio_r8(pb);
+    if (type != AMF_DATA_TYPE_STRING)
         goto out;
     length = avio_rb16(pb);
     ret = av_get_packet(s->pb, pkt, length);
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 51180c9..9db2d0f 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -446,12 +446,12 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
         int data_size;
         int metadata_size_pos = avio_tell(pb);
         avio_w8(pb, AMF_DATA_TYPE_STRING);
-        put_amf_string(pb, "data-stream");
+        put_amf_string(pb, "onMetaData");
         avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
         avio_wb32(pb, 2);
         put_amf_string(pb, "codecid");
         put_amf_double(pb, enc->codec_id);
-        put_amf_string(pb, "data");
+        put_amf_string(pb, "data-stream-packet");
         avio_w8(pb, AMF_DATA_TYPE_STRING);
         put_amf_string(pb, pkt->data);
         put_amf_string(pb, "");
-- 
1.7.4.1

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

Reply via email to