On Sat, 21 Sep 2013, Luca Barbato wrote:

---
libavformat/rtmpproto.c | 119 +++++++++++++++++++++++-------------------------
1 file changed, 57 insertions(+), 62 deletions(-)

The patch itself looks ok to me, one comment further below as note to either of us who wants to get to it first.

diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index a2dffd0..2b2baa3 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -2061,65 +2061,81 @@ static int handle_invoke(URLContext *s, RTMPPacket *pkt)
    return ret;
}

-static int handle_notify(URLContext *s, RTMPPacket *pkt) {
-    RTMPContext *rt  = s->priv_data;
-    const uint8_t *p = NULL;
-    uint8_t commandbuffer[64];
-    char statusmsg[128];
-    int stringlen;
-    GetByteContext gbc;
-    PutByteContext pbc;
-    uint32_t ts;
-    int old_flv_size, err;
-    const uint8_t *datatowrite;
-    unsigned datatowritelength;
-
-    p = pkt->data;
-    bytestream2_init(&gbc, p, pkt->size);
-    if (ff_amf_read_string(&gbc, commandbuffer, sizeof(commandbuffer),
-                           &stringlen))
-        return AVERROR_INVALIDDATA;
-    if (!strcmp(commandbuffer, "@setDataFrame")) {
-        datatowrite       = gbc.buffer;
-        datatowritelength = bytestream2_get_bytes_left(&gbc);
-        if (ff_amf_read_string(&gbc, statusmsg,
-                               sizeof(statusmsg), &stringlen))
-            return AVERROR_INVALIDDATA;
-    } else {
-        datatowrite       = pkt->data;
-        datatowritelength = pkt->size;
-    }
-
-    /* Provide ECMAArray to flv */
-    ts = pkt->timestamp;
+static int update_offset(RTMPContext *rt, int size)
+{
+    int old_flv_size;

    // generate packet header and put data into buffer for FLV demuxer
    if (rt->flv_off < rt->flv_size) {
        // There is old unread data in the buffer, thus append at the end
        old_flv_size  = rt->flv_size;
-        rt->flv_size += datatowritelength + 15;
+        rt->flv_size += size + 15;
    } else {
        // All data has been read, write the new data at the start of the buffer
        old_flv_size = 0;
-        rt->flv_size = datatowritelength + 15;
+        rt->flv_size = size + 15;
        rt->flv_off  = 0;
    }

-    if ((err = av_reallocp(&rt->flv_data, rt->flv_size)) < 0)
-        return err;
+    return old_flv_size;
+}
+
+static int append_flv_data(RTMPContext *rt, RTMPPacket *pkt, int skip)
+{
+    int old_flv_size, ret;
+    PutByteContext pbc;
+    const uint8_t *data = pkt->data + skip;
+    const int size      = pkt->size - skip;
+    uint32_t ts         = pkt->timestamp;
+
+    av_log(NULL, AV_LOG_ERROR, "Timestamp %d\n",
+           ts);
+
+    old_flv_size = update_offset(rt, size);
+
+    if ((ret = av_reallocp(&rt->flv_data, rt->flv_size)) < 0)
+        return ret;

Not relevant for this patch, but potential future improvement: Don't realloc every time, but keep track of the allocation size and check if we need to enlarge it at all, so we in practice won't need to do the realloc in most calls later.

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

Reply via email to