Stream info: any rtmp&h264 stream.

p.s. sometimes it'll take a time. sometimes no. but leak will be oblivious
~3MB in second and then oom killer will kill app.


2014-05-30 14:25 GMT+03:00 Luca Barbato <[email protected]>:

> On 30/05/14 11:19, Roman Savchenko wrote:
> > Hi,
> >
> > I don't know should I report this to bugzilla, because it's more "dev
> > notice" . But if you add AVFrameSideData with av_frame_new_side_data -
> the
> > memory will start leaking. I cant catch where, because I don't know all
> > "frame steps".
>
> Do you have a code snippet that shows the problem handy?
>
> lu
>
> _______________________________________________
> libav-devel mailing list
> [email protected]
> https://lists.libav.org/mailman/listinfo/libav-devel
>
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index c4ce278..cad55aa 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1675,13 +1675,36 @@ static int get_consumed_bytes(int pos, int buf_size)
     return pos;
 }
 
-static int output_frame(H264Context *h, AVFrame *dst, AVFrame *src)
+static int output_frame(H264Context *h, AVFrame *dst, H264Picture *src)
 {
     int i;
-    int ret = av_frame_ref(dst, src);
+    int ret = av_frame_ref(dst, &src->f);
     if (ret < 0)
         return ret;
 
+    if (src->mb_type_buf && src->mb_type_buf->data) {
+        AVFrameSideData *mb_type_sd = av_frame_new_side_data(dst, AV_FRAME_DATA_MB_TYPE, src->mb_type_buf->size);
+        if (mb_type_sd) {
+            memcpy(mb_type_sd->data, src->mb_type_buf->data, src->mb_type_buf->size);
+        }
+    }
+
+    if (src->motion_val_buf[0] && src->motion_val_buf[0]->data &&
+        src->motion_val_buf[1] && src->motion_val_buf[1]->data) {
+        int size;
+        AVFrameSideData *motion_val_sd;
+        
+        size = src->motion_val_buf[0]->size;
+        motion_val_sd = av_frame_new_side_data(dst, AV_FRAME_DATA_MOTION_VAL, size * 2);
+        if (motion_val_sd) {
+            for (i = 0; i < 2; ++i) {
+                uint8_t *s = src->motion_val_buf[i]->data;
+                uint8_t *d = &(motion_val_sd->data[i * size]);
+                memcpy(d, s, size);
+            }
+        }
+    }
+
     if (!h->sps.crop)
         return 0;
 
@@ -1735,7 +1758,7 @@ out:
             h->delayed_pic[i] = h->delayed_pic[i + 1];
 
         if (out) {
-            ret = output_frame(h, pict, &out->f);
+            ret = output_frame(h, pict, out);
             if (ret < 0)
                 return ret;
             *got_frame = 1;
@@ -1773,7 +1796,7 @@ out:
             if (!h->next_output_pic->recovered)
                 h->next_output_pic->f.flags |= AV_FRAME_FLAG_CORRUPT;
 
-            ret = output_frame(h, pict, &h->next_output_pic->f);
+            ret = output_frame(h, pict, h->next_output_pic);
             if (ret < 0)
                 return ret;
             *got_frame = 1;
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 958cd26..ff904b3 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -81,6 +81,14 @@ enum AVFrameSideDataType {
      * See libavutil/display.h for a detailed description of the data.
      */
     AV_FRAME_DATA_DISPLAYMATRIX,
+    /**
+    * H264 macroblock type as copy of H264Picture.mb_type_buf
+    */
+    AV_FRAME_DATA_MB_TYPE,
+    /**
+    *	H264 motion value as serialized copy of H264Picture.motion_val_buf
+    */
+    AV_FRAME_DATA_MOTION_VAL,
 };
 
 typedef struct AVFrameSideData {
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to