changeset 30327:028ec0735169

swscale-example: use av_malloc() Image buffers require 16-byte alignment, so av_malloc() should be used. Fixes crash on PPC.
author mru
date Tue, 19 Jan 2010 03:47:11 +0000
parents 63f2871ba1b3
children 0e52b96c6199
files libswscale/swscale-example.c
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libswscale/swscale-example.c	Mon Jan 18 23:34:07 2010 +0000
+++ b/libswscale/swscale-example.c	Tue Jan 19 03:47:11 2010 +0000
@@ -25,6 +25,7 @@
 #include <stdarg.h>
 
 #undef HAVE_AV_CONFIG_H
+#include "libavutil/mem.h"
 #include "libavutil/avutil.h"
 #include "libavutil/lfg.h"
 #include "swscale.h"
@@ -101,9 +102,9 @@
         else
             dstStride[i]= dstW*4;
 
-        src[i]= malloc(srcStride[i]*srcH);
-        dst[i]= malloc(dstStride[i]*dstH);
-        out[i]= malloc(refStride[i]*h);
+        src[i]= av_malloc(srcStride[i]*srcH);
+        dst[i]= av_malloc(dstStride[i]*dstH);
+        out[i]= av_malloc(refStride[i]*h);
         if (!src[i] || !dst[i] || !out[i]) {
             perror("Malloc");
             res = -1;
@@ -173,9 +174,9 @@
     sws_freeContext(outContext);
 
     for (i=0; i<4; i++) {
-        free(src[i]);
-        free(dst[i]);
-        free(out[i]);
+        av_free(src[i]);
+        av_free(dst[i]);
+        av_free(out[i]);
     }
 
     return res;
@@ -216,10 +217,10 @@
 
 int main(int argc, char **argv)
 {
-    uint8_t *rgb_data = malloc (W*H*4);
+    uint8_t *rgb_data = av_malloc (W*H*4);
     uint8_t *rgb_src[3]= {rgb_data, NULL, NULL};
     int rgb_stride[3]={4*W, 0, 0};
-    uint8_t *data = malloc (4*W*H);
+    uint8_t *data = av_malloc (4*W*H);
     uint8_t *src[4]= {data, data+W*H, data+W*H*2, data+W*H*3};
     int stride[4]={W, W, W, W};
     int x, y;
@@ -240,10 +241,10 @@
     }
     sws_scale(sws, rgb_src, rgb_stride, 0, H, src, stride);
     sws_freeContext(sws);
-    free(rgb_data);
+    av_free(rgb_data);
 
     selfTest(src, stride, W, H);
-    free(data);
+    av_free(data);
 
     return 0;
 }