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