Memory pooling
[melted] / src / modules / gtk2 / filter_rescale.c
index 85bb8cd..049e68a 100644 (file)
@@ -75,8 +75,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                if ( *format == mlt_image_yuv422 && strcmp( interps, "none" ) && ( iwidth != owidth || iheight != oheight ) )
                {
                        // Create the output image
-                       // IRRIGATE ME
-                       uint8_t *output = malloc( owidth * ( oheight + 1 ) * 2 );
+                       void *release = NULL;
+                       uint8_t *output = mlt_pool_allocate( owidth * ( oheight + 1 ) * 2, &release );
 
                        // Calculate strides
                        int istride = iwidth * 2;
@@ -85,7 +85,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                        yuv422_scale_simple( output, owidth, oheight, ostride, input, iwidth, iheight, istride, interp );
                
                        // Now update the frame
-                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, free, NULL );
+                       mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
+                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, NULL, NULL );
                        mlt_properties_set_int( properties, "width", owidth );
                        mlt_properties_set_int( properties, "height", oheight );
 
@@ -97,8 +98,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                        int bpp = (*format == mlt_image_rgb24a ? 4 : 3 );
                        
                        // Create the yuv image
-                       // IRRIGATE ME
-                       uint8_t *output = malloc( owidth * ( oheight + 1 ) * 2 );
+                       void *release = NULL;
+                       uint8_t *output = mlt_pool_allocate( owidth * ( oheight + 1 ) * 2, &release );
 
                        if ( strcmp( interps, "none" ) && ( iwidth != owidth || iheight != oheight ) )
                        {
@@ -113,8 +114,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                if ( bpp == 4 )
                                {
                                        // Allocate the alpha mask
-                                       // IRRIGATE ME
-                                       uint8_t *alpha = malloc( owidth * ( oheight + 1 ) );
+                                       void *alpha_release = NULL;
+                                       uint8_t *alpha = mlt_pool_allocate( owidth * ( oheight + 1 ), &alpha_release );
 
                                        // Convert the image and extract alpha
                                        mlt_convert_rgb24a_to_yuv422( gdk_pixbuf_get_pixels( scaled ),
@@ -122,7 +123,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                                                                  gdk_pixbuf_get_rowstride( scaled ),
                                                                                  output, alpha );
 
-                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), free, NULL );
+                                       mlt_properties_set_data( properties, "alpha_release", alpha_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
+                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), NULL, NULL );
                                }
                                else
                                {
@@ -140,8 +142,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                if ( bpp == 4 )
                                {
                                        // Allocate the alpha mask
-                                       // IRRIGATE ME
-                                       uint8_t *alpha = malloc( owidth * ( oheight + 1 ) );
+                                       void *alpha_release = NULL;
+                                       uint8_t *alpha = mlt_pool_allocate( owidth * ( oheight + 1 ), &alpha_release );
 
                                        // Convert the image and extract alpha
                                        mlt_convert_rgb24a_to_yuv422( input,
@@ -149,7 +151,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                                                                                  owidth * 4,
                                                                                  output, alpha );
 
-                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), free, NULL );
+                                       mlt_properties_set_data( properties, "alpha_release", alpha_release, 0, ( mlt_destructor )mlt_pool_release, NULL );
+                                       mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), NULL, NULL );
                                }
                                else
                                {
@@ -162,7 +165,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                        }
 
                        // Now update the frame
-                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, free, NULL );
+                       mlt_properties_set_data( properties, "image_release", release, 0, ( mlt_destructor )mlt_pool_release, NULL );
+                       mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, NULL, NULL );
                        mlt_properties_set_int( properties, "width", owidth );
                        mlt_properties_set_int( properties, "height", oheight );