]> git.sesse.net Git - mlt/blob - src/modules/sdl/consumer_sdl_still.c
bc82ffa197e649794ab4ef83bc0b2e8aec03245b
[mlt] / src / modules / sdl / consumer_sdl_still.c
1 /*
2  * consumer_sdl_still.c -- A Simple DirectMedia Layer consumer
3  * Copyright (C) 2003-2004, 2010 Ushodaya Enterprises Limited
4  * Author: Charles Yates
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_consumer.h>
22 #include <framework/mlt_frame.h>
23 #include <framework/mlt_deque.h>
24 #include <framework/mlt_factory.h>
25 #include <framework/mlt_filter.h>
26 #include <framework/mlt_log.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <pthread.h>
31 #include <SDL.h>
32 #include <SDL_syswm.h>
33 #include <sys/time.h>
34 #include "consumer_sdl_osx.h"
35
36 extern pthread_mutex_t mlt_sdl_mutex;
37
38 /** This classes definition.
39 */
40
41 typedef struct consumer_sdl_s *consumer_sdl;
42
43 struct consumer_sdl_s
44 {
45         struct mlt_consumer_s parent;
46         mlt_properties properties;
47         pthread_t thread;
48         int joined;
49         int running;
50         int window_width;
51         int window_height;
52         int width;
53         int height;
54         int playing;
55         int sdl_flags;
56         SDL_Surface *sdl_screen;
57         SDL_Rect rect;
58         uint8_t *buffer;
59         int last_position;
60         mlt_producer last_producer;
61 };
62
63 /** Forward references to static functions.
64 */
65
66 static int consumer_start( mlt_consumer parent );
67 static int consumer_stop( mlt_consumer parent );
68 static int consumer_is_stopped( mlt_consumer parent );
69 static void consumer_close( mlt_consumer parent );
70 static void *consumer_thread( void * );
71 static int consumer_get_dimensions( int *width, int *height );
72 static void consumer_sdl_event( mlt_listener listener, mlt_properties owner, mlt_service this, void **args );
73
74 /** This is what will be called by the factory - anything can be passed in
75         via the argument, but keep it simple.
76 */
77
78 mlt_consumer consumer_sdl_still_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
79 {
80         // Create the consumer object
81         consumer_sdl this = calloc( 1, sizeof( struct consumer_sdl_s ) );
82
83         // If no malloc'd and consumer init ok
84         if ( this != NULL && mlt_consumer_init( &this->parent, this, profile ) == 0 )
85         {
86                 // Get the parent consumer object
87                 mlt_consumer parent = &this->parent;
88
89                 // get a handle on properties
90                 mlt_service service = MLT_CONSUMER_SERVICE( parent );
91                 this->properties = MLT_SERVICE_PROPERTIES( service );
92
93                 // We have stuff to clean up, so override the close method
94                 parent->close = consumer_close;
95
96                 // Default scaler (for now we'll use nearest)
97                 mlt_properties_set( this->properties, "rescale", "nearest" );
98
99                 // We're always going to run this in non-realtime mode
100                 mlt_properties_set( this->properties, "real_time", "0" );
101
102                 // Ensure we don't join on a non-running object
103                 this->joined = 1;
104                 
105                 // process actual param
106                 if ( arg == NULL || sscanf( arg, "%dx%d", &this->width, &this->height ) != 2 )
107                 {
108                         this->width = mlt_properties_get_int( this->properties, "width" );
109                         this->height = mlt_properties_get_int( this->properties, "height" );
110                 }
111                 else
112                 {
113                         mlt_properties_set_int( this->properties, "width", this->width );
114                         mlt_properties_set_int( this->properties, "height", this->height );
115                 }
116
117                 // Set the sdl flags
118                 this->sdl_flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL | SDL_RESIZABLE | SDL_DOUBLEBUF;
119
120                 // Allow thread to be started/stopped
121                 parent->start = consumer_start;
122                 parent->stop = consumer_stop;
123                 parent->is_stopped = consumer_is_stopped;
124
125                 // Register specific events
126                 mlt_events_register( this->properties, "consumer-sdl-event", ( mlt_transmitter )consumer_sdl_event );
127
128                 // Return the consumer produced
129                 return parent;
130         }
131
132         // malloc or consumer init failed
133         free( this );
134
135         // Indicate failure
136         return NULL;
137 }
138
139 static void consumer_sdl_event( mlt_listener listener, mlt_properties owner, mlt_service this, void **args )
140 {
141         if ( listener != NULL )
142                 listener( owner, this, ( SDL_Event * )args[ 0 ] );
143 }
144
145 static int consumer_start( mlt_consumer parent )
146 {
147         consumer_sdl this = parent->child;
148
149         if ( !this->running )
150         {
151                 int preview_off = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent ), "preview_off" );
152                 int sdl_started = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent ), "sdl_started" );
153
154                 consumer_stop( parent );
155
156                 this->last_position = -1;
157                 this->running = 1;
158                 this->joined = 0;
159
160                 // Allow the user to force resizing to window size
161                 this->width = mlt_properties_get_int( this->properties, "width" );
162                 this->height = mlt_properties_get_int( this->properties, "height" );
163
164                 // Default window size
165                 double display_ratio = mlt_properties_get_double( this->properties, "display_ratio" );
166                 this->window_width = ( double )this->height * display_ratio + 0.5;
167                 this->window_height = this->height;
168
169                 if ( sdl_started == 0 && preview_off == 0 )
170                 {
171                         pthread_mutex_lock( &mlt_sdl_mutex );
172                         int ret = SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE );
173                         pthread_mutex_unlock( &mlt_sdl_mutex );
174                         if ( ret < 0 )
175                         {
176                                 fprintf( stderr, "Failed to initialize SDL: %s\n", SDL_GetError() );
177                                 return -1;
178                         }
179
180                         SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
181                         SDL_EnableUNICODE( 1 );
182                 }
183                 else if ( preview_off == 0 )
184                 {
185                         pthread_mutex_lock( &mlt_sdl_mutex );
186                         SDL_Surface *screen = SDL_GetVideoSurface( );
187                         pthread_mutex_unlock( &mlt_sdl_mutex );
188                         if ( screen != NULL )
189                         {
190                                 this->sdl_screen = screen;
191                         }
192                 }
193
194                 if ( this->sdl_screen == NULL && preview_off == 0 )
195                 {
196                         pthread_mutex_lock( &mlt_sdl_mutex );
197                         this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
198                         pthread_mutex_unlock( &mlt_sdl_mutex );
199                 }
200
201                 pthread_create( &this->thread, NULL, consumer_thread, this );
202         }
203
204         return 0;
205 }
206
207 static int consumer_stop( mlt_consumer parent )
208 {
209         // Get the actual object
210         consumer_sdl this = parent->child;
211
212         if ( this->joined == 0 )
213         {
214                 int preview_off = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent ), "preview_off" );
215                 int sdl_started = mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent ), "sdl_started" );
216         
217                 // Kill the thread and clean up
218                 this->running = 0;
219
220                 pthread_join( this->thread, NULL );
221                 this->joined = 1;
222
223                 if ( sdl_started == 0 && preview_off == 0 )
224                 {
225                         pthread_mutex_lock( &mlt_sdl_mutex );
226                         SDL_Quit( );
227                         pthread_mutex_unlock( &mlt_sdl_mutex );
228                 }
229
230                 pthread_mutex_lock( &mlt_sdl_mutex );
231                 this->sdl_screen = NULL;
232                 pthread_mutex_unlock( &mlt_sdl_mutex );
233         }
234
235         return 0;
236 }
237
238 static int consumer_is_stopped( mlt_consumer parent )
239 {
240         consumer_sdl this = parent->child;
241         return !this->running;
242 }
243
244 static int sdl_lock_display( )
245 {
246         pthread_mutex_lock( &mlt_sdl_mutex );
247         SDL_Surface *screen = SDL_GetVideoSurface( );
248         int result = screen != NULL && ( !SDL_MUSTLOCK( screen ) || SDL_LockSurface( screen ) >= 0 );
249         pthread_mutex_unlock( &mlt_sdl_mutex );
250         return result;
251 }
252
253 static void sdl_unlock_display( )
254 {
255         pthread_mutex_lock( &mlt_sdl_mutex );
256         SDL_Surface *screen = SDL_GetVideoSurface( );
257         if ( screen != NULL && SDL_MUSTLOCK( screen ) )
258                 SDL_UnlockSurface( screen );
259         pthread_mutex_unlock( &mlt_sdl_mutex );
260 }
261
262 static inline void display_1( SDL_Surface *screen, SDL_Rect rect, uint8_t *image, int width, int height )
263 {
264         // Generate the affine transform scaling values
265         if ( rect.w == 0 || rect.h == 0 ) return;
266         int scale_width = ( width << 16 ) / rect.w;
267         int scale_height = ( height << 16 ) / rect.h;
268         int stride = width * 4;
269         int x, y, row_index;
270         uint8_t *q, *row;
271
272         // Constants defined for clarity and optimisation
273         int scanlength = screen->pitch;
274         uint8_t *start = ( uint8_t * )screen->pixels + rect.y * scanlength + rect.x;
275         uint8_t *p;
276
277         // Iterate through the screen using a very basic scaling algorithm
278         for ( y = 0; y < rect.h; y ++ )
279         {
280                 p = start;
281                 row_index = ( 32768 + scale_height * y ) >> 16;
282                 row = image + stride * row_index;
283                 for ( x = 0; x < rect.w; x ++ )
284                 {
285                         q = row + ( ( ( 32768 + scale_width * x ) >> 16 ) * 4 );
286                         *p ++ = SDL_MapRGB( screen->format, *q, *( q + 1 ), *( q + 2 ) );
287                 }
288                 start += scanlength;
289         }
290 }
291
292 static inline void display_2( SDL_Surface *screen, SDL_Rect rect, uint8_t *image, int width, int height )
293 {
294         // Generate the affine transform scaling values
295         if ( rect.w == 0 || rect.h == 0 ) return;
296         int scale_width = ( width << 16 ) / rect.w;
297         int scale_height = ( height << 16 ) / rect.h;
298         int stride = width * 4;
299         int x, y, row_index;
300         uint8_t *q, *row;
301
302         // Constants defined for clarity and optimisation
303         int scanlength = screen->pitch / 2;
304         uint16_t *start = ( uint16_t * )screen->pixels + rect.y * scanlength + rect.x;
305         uint16_t *p;
306
307         // Iterate through the screen using a very basic scaling algorithm
308         for ( y = 0; y < rect.h; y ++ )
309         {
310                 p = start;
311                 row_index = ( 32768 + scale_height * y ) >> 16;
312                 row = image + stride * row_index;
313                 for ( x = 0; x < rect.w; x ++ )
314                 {
315                         q = row + ( ( ( 32768 + scale_width * x ) >> 16 ) * 4 );
316                         *p ++ = SDL_MapRGB( screen->format, *q, *( q + 1 ), *( q + 2 ) );
317                 }
318                 start += scanlength;
319         }
320 }
321
322 static inline void display_3( SDL_Surface *screen, SDL_Rect rect, uint8_t *image, int width, int height )
323 {
324         // Generate the affine transform scaling values
325         if ( rect.w == 0 || rect.h == 0 ) return;
326         int scale_width = ( width << 16 ) / rect.w;
327         int scale_height = ( height << 16 ) / rect.h;
328         int stride = width * 4;
329         int x, y, row_index;
330         uint8_t *q, *row;
331
332         // Constants defined for clarity and optimisation
333         int scanlength = screen->pitch;
334         uint8_t *start = ( uint8_t * )screen->pixels + rect.y * scanlength + rect.x;
335         uint8_t *p;
336         uint32_t pixel;
337
338         // Iterate through the screen using a very basic scaling algorithm
339         for ( y = 0; y < rect.h; y ++ )
340         {
341                 p = start;
342                 row_index = ( 32768 + scale_height * y ) >> 16;
343                 row = image + stride * row_index;
344                 for ( x = 0; x < rect.w; x ++ )
345                 {
346                         q = row + ( ( ( 32768 + scale_width * x ) >> 16 ) * 4 );
347                         pixel = SDL_MapRGB( screen->format, *q, *( q + 1 ), *( q + 2 ) );
348                         *p ++ = (pixel & 0xFF0000) >> 16;
349                         *p ++ = (pixel & 0x00FF00) >> 8;
350                         *p ++ = (pixel & 0x0000FF);
351                 }
352                 start += scanlength;
353         }
354 }
355
356 static inline void display_4( SDL_Surface *screen, SDL_Rect rect, uint8_t *image, int width, int height )
357 {
358         // Generate the affine transform scaling values
359         if ( rect.w == 0 || rect.h == 0 ) return;
360         int scale_width = ( width << 16 ) / rect.w;
361         int scale_height = ( height << 16 ) / rect.h;
362         int stride = width * 4;
363         int x, y, row_index;
364         uint8_t *q, *row;
365
366         // Constants defined for clarity and optimisation
367         int scanlength = screen->pitch / 4;
368         uint32_t *start = ( uint32_t * )screen->pixels + rect.y * scanlength + rect.x;
369         uint32_t *p;
370
371         // Iterate through the screen using a very basic scaling algorithm
372         for ( y = 0; y < rect.h; y ++ )
373         {
374                 p = start;
375                 row_index = ( 32768 + scale_height * y ) >> 16;
376                 row = image + stride * row_index;
377                 for ( x = 0; x < rect.w; x ++ )
378                 {
379                         q = row + ( ( ( 32768 + scale_width * x ) >> 16 ) * 4 );
380                         *p ++ = SDL_MapRGB( screen->format, *q, *( q + 1 ), *( q + 2 ) );
381                 }
382                 start += scanlength;
383         }
384 }
385
386 static int consumer_play_video( consumer_sdl this, mlt_frame frame )
387 {
388         // Get the properties of this consumer
389         mlt_properties properties = this->properties;
390
391         mlt_image_format vfmt = mlt_image_rgb24a;
392         int height = this->height;
393         int width = this->width;
394         uint8_t *image = NULL;
395         int changed = 0;
396         double display_ratio = mlt_properties_get_double( this->properties, "display_ratio" );
397
398         void ( *lock )( void ) = mlt_properties_get_data( properties, "app_lock", NULL );
399         void ( *unlock )( void ) = mlt_properties_get_data( properties, "app_unlock", NULL );
400
401         if ( lock != NULL ) lock( );
402         void *pool = mlt_cocoa_autorelease_init();
403         sdl_lock_display();
404         
405         // Handle events
406         if ( this->sdl_screen != NULL )
407         {
408                 SDL_Event event;
409
410                 pthread_mutex_lock( &mlt_sdl_mutex );
411                 changed = consumer_get_dimensions( &this->window_width, &this->window_height );
412                 pthread_mutex_unlock( &mlt_sdl_mutex );
413
414                 while ( SDL_PollEvent( &event ) )
415                 {
416                         mlt_events_fire( this->properties, "consumer-sdl-event", &event, NULL );
417
418                         switch( event.type )
419                         {
420                                 case SDL_VIDEORESIZE:
421                                         this->window_width = event.resize.w;
422                                         this->window_height = event.resize.h;
423                                         changed = 1;
424                                         break;
425                                 case SDL_QUIT:
426                                         this->running = 0;
427                                         break;
428                                 case SDL_KEYDOWN:
429                                         {
430                                                 mlt_producer producer = mlt_properties_get_data( properties, "transport_producer", NULL );
431                                                 char keyboard[ 2 ] = " ";
432                                                 void (*callback)( mlt_producer, char * ) = mlt_properties_get_data( properties, "transport_callback", NULL );
433                                                 if ( callback != NULL && producer != NULL && event.key.keysym.unicode < 0x80 && event.key.keysym.unicode > 0 )
434                                                 {
435                                                         keyboard[ 0 ] = ( char )event.key.keysym.unicode;
436                                                         callback( producer, keyboard );
437                                                 }
438                                         }
439                                         break;
440                         }
441                 }
442         }
443
444         if ( this->sdl_screen == NULL || changed )
445         {
446                 // open SDL window
447                 pthread_mutex_lock( &mlt_sdl_mutex );
448                 this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
449                 if ( consumer_get_dimensions( &this->window_width, &this->window_height ) )
450                         this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
451
452                 uint32_t color = mlt_properties_get_int( this->properties, "window_background" );
453                 if ( this->sdl_screen )
454                 {
455                         SDL_FillRect( this->sdl_screen, NULL, color >> 8 );
456                         changed = 1;
457                 }
458                 pthread_mutex_unlock( &mlt_sdl_mutex );
459         }
460         mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "test_audio", 1 );
461         if ( changed == 0 &&
462                  this->last_position == mlt_frame_get_position( frame ) &&
463                  this->last_producer == mlt_frame_get_original_producer( frame ) &&
464                  !mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "refresh" ) )
465         {
466                 sdl_unlock_display( );
467                 mlt_cocoa_autorelease_close( pool );
468                 if ( unlock != NULL ) unlock( );
469                 struct timespec tm = { 0, 100000 };
470                 nanosleep( &tm, NULL );
471                 return 0;
472         }
473
474         // Update last frame shown info
475         this->last_position = mlt_frame_get_position( frame );
476         this->last_producer = mlt_frame_get_original_producer( frame );
477
478         // Get the image, width and height
479         mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
480
481         if ( image != NULL )
482         {
483                 char *rescale = mlt_properties_get( properties, "rescale" );
484                 if ( rescale != NULL && strcmp( rescale, "none" ) )
485                 {
486                         double this_aspect = display_ratio / ( ( double )this->window_width / ( double )this->window_height );
487                         this->rect.w = this_aspect * this->window_width;
488                         this->rect.h = this->window_height;
489                         if ( this->rect.w > this->window_width )
490                         {
491                                 this->rect.w = this->window_width;
492                                 this->rect.h = ( 1.0 / this_aspect ) * this->window_height;
493                         }
494                 }
495                 else
496                 {
497                         double frame_aspect = mlt_frame_get_aspect_ratio( frame ) * width / height;
498                         this->rect.w = frame_aspect * this->window_height;
499                         this->rect.h = this->window_height;
500                         if ( this->rect.w > this->window_width )
501                         {
502                                 this->rect.w = this->window_width;
503                                 this->rect.h = ( 1.0 / frame_aspect ) * this->window_width;
504                         }
505                 }
506
507                 this->rect.x = ( this->window_width - this->rect.w ) / 2;
508                 this->rect.y = ( this->window_height - this->rect.h ) / 2;
509
510                 mlt_properties_set_int( this->properties, "rect_x", this->rect.x );
511                 mlt_properties_set_int( this->properties, "rect_y", this->rect.y );
512                 mlt_properties_set_int( this->properties, "rect_w", this->rect.w );
513                 mlt_properties_set_int( this->properties, "rect_h", this->rect.h );
514         }
515         
516         pthread_mutex_lock( &mlt_sdl_mutex );
517         SDL_Surface *screen = SDL_GetVideoSurface( );
518         if ( !mlt_consumer_is_stopped( &this->parent ) && screen != NULL && this->sdl_screen != NULL && this->sdl_screen->pixels != NULL )
519         {
520                 switch( this->sdl_screen->format->BytesPerPixel )
521                 {
522                         case 1:
523                                 display_1( this->sdl_screen, this->rect, image, width, height );
524                                 break;
525                         case 2:
526                                 display_2( this->sdl_screen, this->rect, image, width, height );
527                                 break;
528                         case 3:
529                                 display_3( this->sdl_screen, this->rect, image, width, height );
530                                 break;
531                         case 4:
532                                 display_4( this->sdl_screen, this->rect, image, width, height );
533                                 break;
534                         default:
535                                 fprintf( stderr, "Unsupported video depth %d\n", this->sdl_screen->format->BytesPerPixel );
536                                 break;
537                 }
538
539                 // Flip it into sight
540                 SDL_Flip( this->sdl_screen );
541         }
542         pthread_mutex_unlock( &mlt_sdl_mutex );
543
544         sdl_unlock_display();
545         mlt_cocoa_autorelease_close( pool );
546         if ( unlock != NULL ) unlock( );
547         mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
548
549         return 1;
550 }
551
552 /** Threaded wrapper for pipe.
553 */
554
555 static void *consumer_thread( void *arg )
556 {
557         // Identify the arg
558         consumer_sdl this = arg;
559
560         // Get the consumer
561         mlt_consumer consumer = &this->parent;
562         mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
563         mlt_frame frame = NULL;
564
565         // Allow the hosting app to provide the preview
566         int preview_off = mlt_properties_get_int( properties, "preview_off" );
567
568         // Loop until told not to
569         while( this->running )
570         {
571                 // Get a frame from the attached producer
572                 frame = mlt_consumer_rt_frame( consumer );
573
574                 // Ensure that we have a frame
575                 if ( this->running && frame != NULL )
576                 {
577                         if ( preview_off == 0 )
578                         {
579                                 consumer_play_video( this, frame );
580                         }
581                         else
582                         {
583                                 mlt_image_format vfmt = mlt_image_rgb24a;
584                                 int height = this->height;
585                                 int width = this->width;
586                                 uint8_t *image = NULL;
587                                 mlt_image_format preview_format = mlt_properties_get_int( properties, "preview_format" );
588
589                                 // Check if a specific colour space has been requested
590                                 if ( preview_off && preview_format != mlt_image_none )
591                                         vfmt = preview_format;
592                         
593                                 mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
594                                 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame ), "format", vfmt );
595                                 mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
596                         }
597                         mlt_frame_close( frame );
598                 }
599                 else
600                 {
601                         if ( frame ) mlt_frame_close( frame );
602                         this->running = 0;
603                 }
604         }
605
606         return NULL;
607 }
608
609 static int consumer_get_dimensions( int *width, int *height )
610 {
611         int changed = 0;
612
613         // SDL windows manager structure
614         SDL_SysWMinfo wm;
615
616         // Specify the SDL Version
617         SDL_VERSION( &wm.version );
618
619 #ifndef __DARWIN__
620         // Get the wm structure
621         if ( SDL_GetWMInfo( &wm ) == 1 )
622         {
623 #ifndef WIN32
624                 // Check that we have the X11 wm
625                 if ( wm.subsystem == SDL_SYSWM_X11 ) 
626                 {
627                         // Get the SDL window
628                         Window window = wm.info.x11.window;
629
630                         // Get the display session
631                         Display *display = wm.info.x11.display;
632
633                         // Get the window attributes
634                         XWindowAttributes attr;
635                         XGetWindowAttributes( display, window, &attr );
636
637                         // Determine whether window has changed
638                         changed = *width != attr.width || *height != attr.height;
639
640                         // Return width and height
641                         *width = attr.width;
642                         *height = attr.height;
643                 }
644 #endif
645         }
646 #endif
647
648         return changed;
649 }
650
651 /** Callback to allow override of the close method.
652 */
653
654 static void consumer_close( mlt_consumer parent )
655 {
656         // Get the actual object
657         consumer_sdl this = parent->child;
658
659         // Stop the consumer
660         mlt_consumer_stop( parent );
661
662         // Now clean up the rest
663         mlt_consumer_close( parent );
664
665         // Finally clean up this
666         free( this );
667 }