[FFmpeg-soc] [soc]: r1278 - in dirac/libavcodec: dirac.c dirac_wavelet.c dirac_wavelet.h

marco subversion at mplayerhq.hu
Sat Sep 1 11:20:59 CEST 2007


Author: marco
Date: Sat Sep  1 11:20:59 2007
New Revision: 1278

Log:
just allocate the memory once for the IDWT

Modified:
   dirac/libavcodec/dirac.c
   dirac/libavcodec/dirac_wavelet.c
   dirac/libavcodec/dirac_wavelet.h

Modified: dirac/libavcodec/dirac.c
==============================================================================
--- dirac/libavcodec/dirac.c	(original)
+++ dirac/libavcodec/dirac.c	Sat Sep  1 11:20:59 2007
@@ -1654,7 +1654,7 @@ static void decode_component(DiracContex
  * @param coeffs coefficients to transform
  * @return returns 0 on succes, otherwise -1
  */
-int dirac_idwt(DiracContext *s, int16_t *coeffs) {
+int dirac_idwt(DiracContext *s, int16_t *coeffs, int16_t *synth) {
     int level;
     int width, height;
 
@@ -1665,11 +1665,11 @@ int dirac_idwt(DiracContext *s, int16_t 
         switch(s->wavelet_idx) {
         case 0:
             dprintf(s->avctx, "Deslauriers-Debuc (9,5) IDWT\n");
-            dirac_subband_idwt_95(s->avctx, width, height, s->padded_width, coeffs, level);
+            dirac_subband_idwt_95(s->avctx, width, height, s->padded_width, coeffs, synth, level);
             break;
         case 1:
             dprintf(s->avctx, "LeGall (5,3) IDWT\n");
-            dirac_subband_idwt_53(s->avctx, width, height, s->padded_width, coeffs, level);
+            dirac_subband_idwt_53(s->avctx, width, height, s->padded_width, coeffs, synth, level);
             break;
         default:
             av_log(s->avctx, AV_LOG_INFO, "unknown IDWT index: %d\n",
@@ -2502,10 +2502,12 @@ static int dirac_motion_compensation(Dir
  * @return 0 when successful, otherwise -1 is returned
  */
 static int dirac_decode_frame(DiracContext *s) {
+    AVCodecContext *avctx = s->avctx;
     int16_t *coeffs;
     int16_t *line;
     int comp;
     int x,y;
+    int16_t *synth;
 
 START_TIMER
 
@@ -2523,6 +2525,19 @@ START_TIMER
         return -1;
     }
 
+    /* Allocate memory for the IDWT to work in.  */
+    if (avcodec_check_dimensions(avctx, s->padded_luma_width,
+                                 s->padded_luma_height)) {
+        av_log(avctx, AV_LOG_ERROR, "avcodec_check_dimensions() failed\n");
+        return -1;
+    }
+    synth = av_malloc(s->padded_luma_width * s->padded_luma_height
+                      * sizeof(int16_t));
+    if (!synth) {
+        av_log(avctx, AV_LOG_ERROR, "av_malloc() failed\n");
+        return -1;
+    }
+
     for (comp = 0; comp < 3; comp++) {
         uint8_t *frame = s->picture.data[comp];
         int width, height;
@@ -2547,7 +2562,7 @@ START_TIMER
 
         /* Disable to test the current state of the encoder.  */
 #if 1
-        dirac_idwt(s, coeffs);
+        dirac_idwt(s, coeffs, synth);
 #endif
 
         if (s->refs) {
@@ -2575,6 +2590,7 @@ START_TIMER
         av_freep(&s->blmotion);
     }
     av_free(coeffs);
+    av_free(synth);
 
 STOP_TIMER("dirac_frame_decode");
 

Modified: dirac/libavcodec/dirac_wavelet.c
==============================================================================
--- dirac/libavcodec/dirac_wavelet.c	(original)
+++ dirac/libavcodec/dirac_wavelet.c	Sat Sep  1 11:20:59 2007
@@ -101,25 +101,14 @@ static void dirac_subband_dwt_deinterlea
  * @return 0 when successful, otherwise -1 is returned
  */
 int dirac_subband_idwt_53(AVCodecContext *avctx, int width, int height,
-                          int padded_width, int16_t *data, int level) {
-    int16_t *synth, *synthline;
+                          int padded_width, int16_t *data, int16_t *synth, int level) {
+    int16_t *synthline;
     int x, y;
     int synth_width = width  << 1;
     int synth_height = height << 1;
 
 START_TIMER
 
-    if (avcodec_check_dimensions(avctx, synth_width, synth_height)) {
-        av_log(avctx, AV_LOG_ERROR, "avcodec_check_dimensions() failed\n");
-        return -1;
-    }
-
-    synth = av_malloc(synth_width * synth_height * sizeof(int16_t));
-    if (!synth) {
-        av_log(avctx, AV_LOG_ERROR, "av_malloc() failed\n");
-        return -1;
-    }
-
     dirac_subband_idwt_interleave(data, width, height,
                                   padded_width, synth, level);
 
@@ -208,8 +197,6 @@ START_TIMER
 
 STOP_TIMER("idwt53")
 
-    av_free(synth);
-
     return 0;
 }
 
@@ -345,25 +332,14 @@ STOP_TIMER("dwt53")
  * @return 0 when successful, otherwise -1 is returned
  */
 int dirac_subband_idwt_95(AVCodecContext *avctx, int width, int height,
-                          int padded_width, int16_t *data, int level) {
-    int16_t *synth, *synthline;
+                          int padded_width, int16_t *data, int16_t *synth, int level) {
+    int16_t *synthline;
     int x, y;
     int synth_width = width  << 1;
     int synth_height = height << 1;
 
 START_TIMER
 
-    if (avcodec_check_dimensions(avctx, synth_width, synth_height)) {
-        av_log(avctx, AV_LOG_ERROR, "avcodec_check_dimensions() failed\n");
-        return -1;
-    }
-
-    synth = av_malloc(synth_width * synth_height * sizeof(int16_t));
-    if (!synth) {
-        av_log(avctx, AV_LOG_ERROR, "av_malloc() failed\n");
-        return -1;
-    }
-
     dirac_subband_idwt_interleave(data, width, height, padded_width, synth, level);
 
     /* Vertical synthesis: Lifting stage 1.  */
@@ -474,8 +450,6 @@ START_TIMER
 
 STOP_TIMER("idwt95")
 
-    av_free(synth);
-
     return 0;
 }
 

Modified: dirac/libavcodec/dirac_wavelet.h
==============================================================================
--- dirac/libavcodec/dirac_wavelet.h	(original)
+++ dirac/libavcodec/dirac_wavelet.h	Sat Sep  1 11:20:59 2007
@@ -31,10 +31,10 @@
 #include "avcodec.h"
 
 int dirac_subband_idwt_53(AVCodecContext *avctx, int width, int height,
-                          int padded_width, int16_t *data, int level);
+                          int padded_width, int16_t *data, int16_t *synth, int level);
 
 int dirac_subband_idwt_95(AVCodecContext *avctx, int width, int height,
-                          int padded_width, int16_t *data, int level);
+                          int padded_width, int16_t *data, int16_t *synth, int level);
 
 int dirac_subband_dwt_53(AVCodecContext *avctx, int width, int height,
                          int padded_width, int16_t *data, int level);



More information about the FFmpeg-soc mailing list