]> git.sesse.net Git - mlt/blob - src/modules/gtk2/producer_pixbuf.c
Fix calloc() parameter ordering
[mlt] / src / modules / gtk2 / producer_pixbuf.c
1 /*
2  * producer_pixbuf.c -- raster image loader based upon gdk-pixbuf
3  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4  * Author: Dan Dennedy <dan@dennedy.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <framework/mlt_producer.h>
22 #include <framework/mlt_frame.h>
23 #include <framework/mlt_cache.h>
24 #include <framework/mlt_log.h>
25 #include <gdk-pixbuf/gdk-pixbuf.h>
26
27 #include "config.h"
28
29 #ifdef USE_EXIF
30 #include <libexif/exif-data.h>
31 #endif
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <pthread.h>
37 #include <math.h>
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <unistd.h>
41 #include <dirent.h>
42 #include <ctype.h>
43
44 // this protects concurrent access to gdk_pixbuf
45 static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
46
47 typedef struct producer_pixbuf_s *producer_pixbuf;
48
49 struct producer_pixbuf_s
50 {
51         struct mlt_producer_s parent;
52
53         // File name list
54         mlt_properties filenames;
55         int count;
56         int image_idx;
57         int pixbuf_idx;
58         int width;
59         int height;
60         uint8_t *alpha;
61         uint8_t *image;
62         mlt_cache_item image_cache;
63         mlt_cache_item alpha_cache;
64         mlt_cache_item pixbuf_cache;
65         GdkPixbuf *pixbuf;
66         mlt_image_format format;
67 };
68
69 static void load_filenames( producer_pixbuf self, mlt_properties producer_properties );
70 static int refresh_pixbuf( producer_pixbuf self, mlt_frame frame );
71 static int producer_get_frame( mlt_producer parent, mlt_frame_ptr frame, int index );
72 static void producer_close( mlt_producer parent );
73
74 mlt_producer producer_pixbuf_init( char *filename )
75 {
76         producer_pixbuf self = calloc( 1, sizeof( struct producer_pixbuf_s ) );
77         if ( self != NULL && mlt_producer_init( &self->parent, self ) == 0 )
78         {
79                 mlt_producer producer = &self->parent;
80
81                 // Get the properties interface
82                 mlt_properties properties = MLT_PRODUCER_PROPERTIES( &self->parent );
83         
84                 // Callback registration
85                 producer->get_frame = producer_get_frame;
86                 producer->close = ( mlt_destructor )producer_close;
87
88                 // Set the default properties
89                 mlt_properties_set( properties, "resource", filename );
90                 mlt_properties_set_int( properties, "ttl", 25 );
91                 mlt_properties_set_int( properties, "aspect_ratio", 1 );
92                 mlt_properties_set_int( properties, "progressive", 1 );
93                 mlt_properties_set_int( properties, "seekable", 1 );
94
95                 // Validate the resource
96                 if ( filename )
97                         load_filenames( self, properties );
98                 if ( self->count )
99                 {
100                         mlt_frame frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
101                         if ( frame )
102                         {
103                                 mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame );
104                                 mlt_properties_set_data( frame_properties, "producer_pixbuf", self, 0, NULL, NULL );
105                                 mlt_frame_set_position( frame, mlt_producer_position( producer ) );
106                                 mlt_properties_set_position( frame_properties, "pixbuf_position", mlt_producer_position( producer ) );
107                                 refresh_pixbuf( self, frame );
108                                 mlt_cache_item_close( self->pixbuf_cache );
109                                 mlt_frame_close( frame );
110                         }
111                 }
112                 if ( self->width == 0 )
113                 {
114                         producer_close( producer );
115                         producer = NULL;
116                 }
117                 return producer;
118         }
119         free( self );
120         return NULL;
121 }
122
123 static int load_svg( producer_pixbuf self, mlt_properties properties, const char *filename )
124 {
125         int result = 0;
126
127         // Read xml string
128         if ( strstr( filename, "<svg" ) )
129         {
130                 // Generate a temporary file for the svg
131                 char fullname[ 1024 ] = "/tmp/mlt.XXXXXX";
132                 int fd = g_mkstemp( fullname );
133
134                 if ( fd > -1 )
135                 {
136                         // Write the svg into the temp file
137                         ssize_t remaining_bytes;
138                         const char *xml = filename;
139
140                         // Strip leading crap
141                         while ( xml[0] != '<' )
142                                 xml++;
143
144                         remaining_bytes = strlen( xml );
145                         while ( remaining_bytes > 0 )
146                                 remaining_bytes -= write( fd, xml + strlen( xml ) - remaining_bytes, remaining_bytes );
147                         close( fd );
148
149                         mlt_properties_set( self->filenames, "0", fullname );
150
151                         // Teehe - when the producer closes, delete the temp file and the space allo
152                         mlt_properties_set_data( properties, "__temporary_file__", fullname, 0, ( mlt_destructor )unlink, NULL );
153                         result = 1;
154                 }
155         }
156         return result;
157 }
158
159 static int load_sequence( producer_pixbuf self, mlt_properties properties, const char *filename )
160 {
161         int result = 0;
162
163         // Obtain filenames with pattern
164         if ( strchr( filename, '%' ) != NULL )
165         {
166                 // handle picture sequences
167                 int i = mlt_properties_get_int( properties, "begin" );
168                 int gap = 0;
169                 char full[1024];
170                 int keyvalue = 0;
171                 char key[ 50 ];
172
173                 while ( gap < 100 )
174                 {
175                         struct stat buf;
176                         snprintf( full, 1023, filename, i ++ );
177                         if ( stat( full, &buf ) == 0 )
178                         {
179                                 sprintf( key, "%d", keyvalue ++ );
180                                 mlt_properties_set( self->filenames, key, full );
181                                 gap = 0;
182                         }
183                         else
184                         {
185                                 gap ++;
186                         }
187                 }
188                 if ( mlt_properties_count( self->filenames ) > 0 )
189                 {
190                         mlt_properties_set_int( properties, "ttl", 1 );
191                         result = 1;
192                 }
193         }
194         return result;
195 }
196
197 static int load_sequence2( producer_pixbuf self, mlt_properties properties, const char *filename )
198 {
199         int result = 0;
200         const char *start;
201
202         // Obtain filenames with pattern containing a begin value, e.g. foo%1234d.png
203         if ( ( start = strchr( filename, '%' ) ) )
204         {
205                 const char *end = ++start;
206                 while ( isdigit( *end ) ) end++;
207                 if ( end > start && ( end[0] == 'd' || end[0] == 'i' || end[0] == 'u' ) )
208                 {
209                         int n = end - start;
210                         char *s = calloc( 1, n + 1 );
211                         strncpy( s, start, n );
212                         mlt_properties_set( properties, "begin", s );
213                         free( s );
214                         s = calloc( 1, strlen( filename ) );
215                         strncpy( s, filename, start - filename );
216                         sprintf( s + ( start - filename ), ".%d%s", n, end );
217                         result = load_sequence( self, properties, s );
218                         free( s );
219                 }
220         }
221         return result;
222 }
223
224 static int load_folder( producer_pixbuf self, mlt_properties properties, const char *filename )
225 {
226         int result = 0;
227
228         // Obtain filenames with folder
229         if ( strstr( filename, "/.all." ) != NULL )
230         {
231                 char wildcard[ 1024 ];
232                 char *dir_name = strdup( filename );
233                 char *extension = strrchr( dir_name, '.' );
234
235                 *( strstr( dir_name, "/.all." ) + 1 ) = '\0';
236                 sprintf( wildcard, "*%s", extension );
237
238                 mlt_properties_dir_list( self->filenames, dir_name, wildcard, 1 );
239
240                 free( dir_name );
241                 result = 1;
242         }
243         return result;
244 }
245
246 static void load_filenames( producer_pixbuf self, mlt_properties properties )
247 {
248         char *filename = mlt_properties_get( properties, "resource" );
249         self->filenames = mlt_properties_new( );
250
251         if (!load_svg( self, properties, filename ) &&
252                 !load_sequence( self, properties, filename ) &&
253                 !load_sequence2( self, properties, filename ) &&
254                 !load_folder( self, properties, filename ) )
255         {
256                 mlt_properties_set( self->filenames, "0", filename );
257         }
258         self->count = mlt_properties_count( self->filenames );
259 }
260
261 static GdkPixbuf* reorient_with_exif( producer_pixbuf self, int image_idx, GdkPixbuf *pixbuf )
262 {
263 #ifdef USE_EXIF
264         mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( &self->parent );
265         ExifData *d = exif_data_new_from_file( mlt_properties_get_value( self->filenames, image_idx ) );
266         ExifEntry *entry;
267         int exif_orientation = 0;
268
269         /* get orientation and rotate image accordingly if necessary */
270         if (d)
271         {
272                 if ( ( entry = exif_content_get_entry ( d->ifd[EXIF_IFD_0], EXIF_TAG_ORIENTATION ) ) )
273                         exif_orientation = exif_get_short (entry->data, exif_data_get_byte_order (d));
274
275                 /* Free the EXIF data */
276                 exif_data_unref(d);
277         }
278
279         // Remember EXIF value, might be useful for someone
280         mlt_properties_set_int( producer_props, "_exif_orientation" , exif_orientation );
281
282         if ( exif_orientation > 1 )
283         {
284                 GdkPixbuf *processed = NULL;
285                 GdkPixbufRotation matrix = GDK_PIXBUF_ROTATE_NONE;
286
287                 // Rotate image according to exif data
288                 switch ( exif_orientation ) {
289                   case 2:
290                           processed = gdk_pixbuf_flip ( pixbuf, TRUE );
291                           break;
292                   case 3:
293                           matrix = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
294                           processed = pixbuf;
295                           break;
296                   case 4:
297                           processed = gdk_pixbuf_flip ( pixbuf, FALSE );
298                           break;
299                   case 5:
300                           matrix = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
301                           processed = gdk_pixbuf_flip ( pixbuf, TRUE );
302                           break;
303                   case 6:
304                           matrix = GDK_PIXBUF_ROTATE_CLOCKWISE;
305                           processed = pixbuf;
306                           break;
307                   case 7:
308                           matrix = GDK_PIXBUF_ROTATE_CLOCKWISE;
309                           processed = gdk_pixbuf_flip ( pixbuf, TRUE );
310                           break;
311                   case 8:
312                           matrix = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
313                           processed = pixbuf;
314                           break;
315                 }
316                 if ( processed )
317                 {
318                         pixbuf = gdk_pixbuf_rotate_simple( processed, matrix );
319                         g_object_unref( processed );
320                 }
321         }
322 #endif
323         return pixbuf;
324 }
325
326 static int refresh_pixbuf( producer_pixbuf self, mlt_frame frame )
327 {
328         // Obtain properties of frame and producer
329         mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
330         mlt_producer producer = &self->parent;
331         mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
332
333         // Check if user wants us to reload the image
334         if ( mlt_properties_get_int( producer_props, "force_reload" ) )
335         {
336                 self->pixbuf = NULL;
337                 self->image = NULL;
338                 mlt_properties_set_int( producer_props, "force_reload", 0 );
339         }
340
341         // Get the time to live for each frame
342         double ttl = mlt_properties_get_int( producer_props, "ttl" );
343
344         // Get the original position of this frame
345         mlt_position position = mlt_properties_get_position( properties, "pixbuf_position" );
346         position += mlt_producer_get_in( producer );
347
348         // Image index
349         int current_idx = ( int )floor( ( double )position / ttl ) % self->count;
350
351         // Key for the cache
352         char image_key[ 10 ];
353         sprintf( image_key, "%d", current_idx );
354
355         int disable_exif = mlt_properties_get_int( producer_props, "disable_exif" );
356
357         if ( current_idx != self->pixbuf_idx )
358                 self->pixbuf = NULL;
359         if ( !self->pixbuf || mlt_properties_get_int( producer_props, "_disable_exif" ) != disable_exif )
360         {
361                 GError *error = NULL;
362
363                 self->image = NULL;
364                 pthread_mutex_lock( &g_mutex );
365                 self->pixbuf = gdk_pixbuf_new_from_file( mlt_properties_get_value( self->filenames, current_idx ), &error );
366                 if ( self->pixbuf )
367                 {
368                         // Read the exif value for this file
369                         if ( !disable_exif )
370                                 self->pixbuf = reorient_with_exif( self, current_idx, self->pixbuf );
371
372                         // Register this pixbuf for destruction and reuse
373                         mlt_cache_item_close( self->pixbuf_cache );
374                         mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "pixbuf.pixbuf", self->pixbuf, 0, ( mlt_destructor )g_object_unref );
375                         self->pixbuf_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "pixbuf.pixbuf" );
376                         self->pixbuf_idx = current_idx;
377
378                         // Store the width/height of the pixbuf temporarily
379                         self->width = gdk_pixbuf_get_width( self->pixbuf );
380                         self->height = gdk_pixbuf_get_height( self->pixbuf );
381
382                         mlt_events_block( producer_props, NULL );
383                         mlt_properties_set_int( producer_props, "meta.media.width", self->width );
384                         mlt_properties_set_int( producer_props, "meta.media.height", self->height );
385                         mlt_properties_set_int( producer_props, "_disable_exif", disable_exif );
386                         mlt_events_unblock( producer_props, NULL );
387
388                 }
389                 pthread_mutex_unlock( &g_mutex );
390         }
391
392         // Set width/height of frame
393         mlt_properties_set_int( properties, "width", self->width );
394         mlt_properties_set_int( properties, "height", self->height );
395
396         return current_idx;
397 }
398
399 static void refresh_image( producer_pixbuf self, mlt_frame frame, mlt_image_format format, int width, int height )
400 {
401         // Obtain properties of frame and producer
402         mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
403         mlt_producer producer = &self->parent;
404
405         // Get index and pixbuf
406         int current_idx = refresh_pixbuf( self, frame );
407
408         // optimization for subsequent iterations on single picture
409         if ( current_idx != self->image_idx || width != self->width || height != self->height )
410                 self->image = NULL;
411         mlt_log_debug( MLT_PRODUCER_SERVICE( producer ), "image %p pixbuf %p idx %d current_idx %d pixbuf_idx %d width %d\n",
412                 self->image, self->pixbuf, current_idx, self->image_idx, self->pixbuf_idx, width );
413
414         // If we have a pixbuf and we need an image
415         if ( self->pixbuf && ( !self->image || ( format != mlt_image_none && format != self->format ) ) )
416         {
417                 char *interps = mlt_properties_get( properties, "rescale.interp" );
418                 int interp = GDK_INTERP_BILINEAR;
419
420                 if ( strcmp( interps, "nearest" ) == 0 )
421                         interp = GDK_INTERP_NEAREST;
422                 else if ( strcmp( interps, "tiles" ) == 0 )
423                         interp = GDK_INTERP_TILES;
424                 else if ( strcmp( interps, "hyper" ) == 0 || strcmp( interps, "bicubic" ) == 0 )
425                         interp = GDK_INTERP_HYPER;
426
427                 // Note - the original pixbuf is already safe and ready for destruction
428                 pthread_mutex_lock( &g_mutex );
429                 GdkPixbuf* pixbuf = gdk_pixbuf_scale_simple( self->pixbuf, width, height, interp );
430
431                 // Store width and height
432                 self->width = width;
433                 self->height = height;
434
435                 // Allocate/define image
436                 int has_alpha = gdk_pixbuf_get_has_alpha( pixbuf );
437                 int src_stride = gdk_pixbuf_get_rowstride( pixbuf );
438                 int dst_stride = self->width * ( has_alpha ? 4 : 3 );
439                 int image_size = dst_stride * ( height + 1 );
440                 self->image = mlt_pool_alloc( image_size );
441                 self->alpha = NULL;
442                 self->format = has_alpha ? mlt_image_rgb24a : mlt_image_rgb24;
443
444                 if ( src_stride != dst_stride )
445                 {
446                         int y = self->height;
447                         uint8_t *src = gdk_pixbuf_get_pixels( pixbuf );
448                         uint8_t *dst = self->image;
449                         while ( y-- )
450                         {
451                                 memcpy( dst, src, dst_stride );
452                                 dst += dst_stride;
453                                 src += src_stride;
454                         }
455                 }
456                 else
457                 {
458                         memcpy( self->image, gdk_pixbuf_get_pixels( pixbuf ), src_stride * height );
459                 }
460                 pthread_mutex_unlock( &g_mutex );
461
462                 // Convert image to requested format
463                 if ( format != mlt_image_none && format != self->format )
464                 {
465                         uint8_t *buffer = NULL;
466
467                         // First, set the image so it can be converted when we get it
468                         mlt_frame_replace_image( frame, self->image, self->format, width, height );
469                         mlt_frame_set_image( frame, self->image, image_size, mlt_pool_release );
470                         self->format = format;
471
472                         // get_image will do the format conversion
473                         mlt_frame_get_image( frame, &buffer, &format, &width, &height, 0 );
474
475                         // cache copies of the image and alpha buffers
476                         if ( buffer )
477                         {
478                                 image_size = mlt_image_format_size( format, width, height, NULL );
479                                 self->image = mlt_pool_alloc( image_size );
480                                 memcpy( self->image, buffer, image_size );
481                         }
482                         if ( ( buffer = mlt_frame_get_alpha_mask( frame ) ) )
483                         {
484                                 self->alpha = mlt_pool_alloc( width * height );
485                                 memcpy( self->alpha, buffer, width * height );
486                         }
487                 }
488
489                 // Update the cache
490                 mlt_cache_item_close( self->image_cache );
491                 mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "pixbuf.image", self->image, image_size, mlt_pool_release );
492                 self->image_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "pixbuf.image" );
493                 self->image_idx = current_idx;
494                 mlt_cache_item_close( self->alpha_cache );
495                 self->alpha_cache = NULL;
496                 if ( self->alpha )
497                 {
498                         mlt_service_cache_put( MLT_PRODUCER_SERVICE( producer ), "pixbuf.alpha", self->alpha, width * height, mlt_pool_release );
499                         self->alpha_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "pixbuf.alpha" );
500                 }
501
502                 // Finished with pixbuf now
503                 g_object_unref( pixbuf );
504         }
505
506         // Set width/height of frame
507         mlt_properties_set_int( properties, "width", self->width );
508         mlt_properties_set_int( properties, "height", self->height );
509 }
510
511 static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
512 {
513         int error = 0;
514         
515         // Obtain properties of frame and producer
516         mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
517         producer_pixbuf self = mlt_properties_get_data( properties, "producer_pixbuf", NULL );
518         mlt_producer producer = &self->parent;
519
520         // Use the width and height suggested by the rescale filter because we can do our own scaling.
521         *width = mlt_properties_get_int( properties, "rescale_width" );
522         *height = mlt_properties_get_int( properties, "rescale_height" );
523
524         // Restore pixbuf and image
525         mlt_service_lock( MLT_PRODUCER_SERVICE( producer ) );
526         self->pixbuf_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "pixbuf.pixbuf" );
527         self->pixbuf = mlt_cache_item_data( self->pixbuf_cache, NULL );
528         self->image_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "pixbuf.image" );
529         self->image = mlt_cache_item_data( self->image_cache, NULL );
530         self->alpha_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "pixbuf.alpha" );
531         self->alpha = mlt_cache_item_data( self->alpha_cache, NULL );
532
533         // Refresh the image
534         refresh_image( self, frame, *format, *width, *height );
535
536         // Get width and height (may have changed during the refresh)
537         *width = self->width;
538         *height = self->height;
539         *format = self->format;
540
541         // NB: Cloning is necessary with this producer (due to processing of images ahead of use)
542         // The fault is not in the design of mlt, but in the implementation of the pixbuf producer...
543         if ( self->image )
544         {
545                 // Clone the image
546                 int image_size = mlt_image_format_size( self->format, self->width, self->height, NULL );
547                 uint8_t *image_copy = mlt_pool_alloc( image_size );
548                 memcpy( image_copy, self->image, image_size );
549                 // Now update properties so we free the copy after
550                 mlt_frame_set_image( frame, image_copy, image_size, mlt_pool_release );
551                 // We're going to pass the copy on
552                 *buffer = image_copy;
553                 mlt_log_debug( MLT_PRODUCER_SERVICE( &self->parent ), "%dx%d (%s)\n",
554                         self->width, self->height, mlt_image_format_name( *format ) );
555                 // Clone the alpha channel
556                 if ( self->alpha )
557                 {
558                         image_copy = mlt_pool_alloc( self->width * self->height );
559                         memcpy( image_copy, self->alpha, self->width * self->height );
560                         mlt_frame_set_alpha( frame, image_copy, self->width * self->height, mlt_pool_release );
561                 }
562         }
563         else
564         {
565                 error = 1;
566         }
567
568         // Release references and locks
569         mlt_cache_item_close( self->pixbuf_cache );
570         mlt_cache_item_close( self->image_cache );
571         mlt_cache_item_close( self->alpha_cache );
572         mlt_service_unlock( MLT_PRODUCER_SERVICE( &self->parent ) );
573
574         return error;
575 }
576
577 static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
578 {
579         // Get the real structure for this producer
580         producer_pixbuf self = producer->child;
581
582         // Fetch the producers properties
583         mlt_properties producer_properties = MLT_PRODUCER_PROPERTIES( producer );
584
585         if ( self->filenames == NULL && mlt_properties_get( producer_properties, "resource" ) != NULL )
586                 load_filenames( self, producer_properties );
587
588         // Generate a frame
589         *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( producer ) );
590
591         if ( *frame != NULL && self->count > 0 )
592         {
593                 // Obtain properties of frame and producer
594                 mlt_properties properties = MLT_FRAME_PROPERTIES( *frame );
595
596                 // Set the producer on the frame properties
597                 mlt_properties_set_data( properties, "producer_pixbuf", self, 0, NULL, NULL );
598
599                 // Update timecode on the frame we're creating
600                 mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
601
602                 // Ensure that we have a way to obtain the position in the get_image
603                 mlt_properties_set_position( properties, "pixbuf_position", mlt_producer_position( producer ) );
604
605                 // Refresh the pixbuf
606                 self->pixbuf_cache = mlt_service_cache_get( MLT_PRODUCER_SERVICE( producer ), "pixbuf.pixbuf" );
607                 self->pixbuf = mlt_cache_item_data( self->pixbuf_cache, NULL );
608                 refresh_pixbuf( self, *frame );
609                 mlt_cache_item_close( self->pixbuf_cache );
610
611                 // Set producer-specific frame properties
612                 mlt_properties_set_int( properties, "progressive", mlt_properties_get_int( producer_properties, "progressive" ) );
613                 
614                 double force_ratio = mlt_properties_get_double( producer_properties, "force_aspect_ratio" );
615                 if ( force_ratio > 0.0 )
616                         mlt_properties_set_double( properties, "aspect_ratio", force_ratio );
617                 else
618                         mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( producer_properties, "aspect_ratio" ) );
619
620                 // Push the get_image method
621                 mlt_frame_push_get_image( *frame, producer_get_image );
622         }
623
624         // Calculate the next timecode
625         mlt_producer_prepare_next( producer );
626
627         return 0;
628 }
629
630 static void producer_close( mlt_producer parent )
631 {
632         producer_pixbuf self = parent->child;
633         parent->close = NULL;
634         mlt_service_cache_purge( MLT_PRODUCER_SERVICE(parent) );
635         mlt_producer_close( parent );
636         mlt_properties_close( self->filenames );
637         free( self );
638 }