Browse code

lavfi: Make default get_video_buffer work with hardware frames

Mark Thompson authored on 2016/11/01 07:14:04
Showing 1 changed files
... ...
@@ -20,6 +20,7 @@
20 20
 #include <stdio.h>
21 21
 
22 22
 #include "libavutil/buffer.h"
23
+#include "libavutil/hwcontext.h"
23 24
 #include "libavutil/imgutils.h"
24 25
 #include "libavutil/mem.h"
25 26
 
... ...
@@ -43,11 +44,16 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
43 43
     if (!frame)
44 44
         return NULL;
45 45
 
46
-    frame->width  = w;
47
-    frame->height = h;
48
-    frame->format = link->format;
46
+    if (link->hw_frames_ctx &&
47
+        ((AVHWFramesContext*)link->hw_frames_ctx->data)->format == link->format) {
48
+        ret = av_hwframe_get_buffer(link->hw_frames_ctx, frame, 0);
49
+    } else {
50
+        frame->width  = w;
51
+        frame->height = h;
52
+        frame->format = link->format;
49 53
 
50
-    ret = av_frame_get_buffer(frame, 32);
54
+        ret = av_frame_get_buffer(frame, 32);
55
+    }
51 56
     if (ret < 0)
52 57
         av_frame_free(&frame);
53 58