Filter attachments to services
[melted] / src / modules / sdl / consumer_sdl.c
1 /*
2 * consumer_sdl.c -- A Simple DirectMedia Layer consumer
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Dan Dennedy <dan@dennedy.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program 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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #include "consumer_sdl.h"
22 #include <framework/mlt_frame.h>
23 #include <framework/mlt_deque.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <pthread.h>
28 #include <SDL/SDL.h>
29 #include <SDL/SDL_syswm.h>
30 #include <sys/time.h>
31
32 /** This classes definition.
33 */
34
35 typedef struct consumer_sdl_s *consumer_sdl;
36
37 struct consumer_sdl_s
38 {
39 struct mlt_consumer_s parent;
40 mlt_properties properties;
41 mlt_deque queue;
42 pthread_t thread;
43 int joined;
44 int running;
45 uint8_t audio_buffer[ 4096 * 10 ];
46 int audio_avail;
47 pthread_mutex_t audio_mutex;
48 pthread_cond_t audio_cond;
49 pthread_mutex_t video_mutex;
50 pthread_cond_t video_cond;
51 int window_width;
52 int window_height;
53 float aspect_ratio;
54 float display_aspect;
55 double last_frame_aspect;
56 int width;
57 int height;
58 int playing;
59 int sdl_flags;
60 SDL_Surface *sdl_screen;
61 SDL_Overlay *sdl_overlay;
62 SDL_Rect rect;
63 uint8_t *buffer;
64 };
65
66 /** Forward references to static functions.
67 */
68
69 static int consumer_start( mlt_consumer parent );
70 static int consumer_stop( mlt_consumer parent );
71 static int consumer_is_stopped( mlt_consumer parent );
72 static void consumer_close( mlt_consumer parent );
73 static void *consumer_thread( void * );
74 static int consumer_get_dimensions( int *width, int *height );
75
76 /** This is what will be called by the factory - anything can be passed in
77 via the argument, but keep it simple.
78 */
79
80 mlt_consumer consumer_sdl_init( char *arg )
81 {
82 // Create the consumer object
83 consumer_sdl this = calloc( sizeof( struct consumer_sdl_s ), 1 );
84
85 // If no malloc'd and consumer init ok
86 if ( this != NULL && mlt_consumer_init( &this->parent, this ) == 0 )
87 {
88 // Create the queue
89 this->queue = mlt_deque_init( );
90
91 // Get the parent consumer object
92 mlt_consumer parent = &this->parent;
93
94 // We have stuff to clean up, so override the close method
95 parent->close = consumer_close;
96
97 // get a handle on properties
98 mlt_service service = mlt_consumer_service( parent );
99 this->properties = mlt_service_properties( service );
100
101 // Set the default volume
102 mlt_properties_set_double( this->properties, "volume", 1.0 );
103
104 // This is the initialisation of the consumer
105 pthread_mutex_init( &this->audio_mutex, NULL );
106 pthread_cond_init( &this->audio_cond, NULL);
107 pthread_mutex_init( &this->video_mutex, NULL );
108 pthread_cond_init( &this->video_cond, NULL);
109
110 // Default scaler (for now we'll use nearest)
111 mlt_properties_set( this->properties, "rescale", "nearest" );
112
113 // Default buffer for low latency
114 mlt_properties_set_int( this->properties, "buffer", 1 );
115
116 // Default progressive true
117 mlt_properties_set_int( this->properties, "progressive", 0 );
118
119 // Default audio buffer
120 mlt_properties_set_int( this->properties, "audio_buffer", 1024 );
121
122 // Get sample aspect ratio
123 this->aspect_ratio = mlt_properties_get_double( this->properties, "aspect_ratio" );
124
125 // Ensure we don't join on a non-running object
126 this->joined = 1;
127
128 // Default display aspect ratio
129 this->display_aspect = 4.0 / 3.0;
130
131 // process actual param
132 if ( arg == NULL || sscanf( arg, "%dx%d", &this->width, &this->height ) != 2 )
133 {
134 this->width = mlt_properties_get_int( this->properties, "width" );
135 this->height = mlt_properties_get_int( this->properties, "height" );
136
137 // Default window size
138 this->window_width = ( float )this->height * this->display_aspect;
139 this->window_height = this->height;
140 }
141 else
142 {
143 if ( (int)( ( float )this->width / this->height * 1000 ) !=
144 (int)( this->display_aspect * 1000 ) )
145 {
146 // Override these
147 this->display_aspect = ( float )this->width / this->height;
148 this->aspect_ratio = 1.0;
149 mlt_properties_set_double( this->properties, "aspect_ratio", this->aspect_ratio );
150 }
151
152 // Set window size
153 this->window_width = this->width;
154 this->window_height = this->height;
155 }
156
157 // Set the sdl flags
158 this->sdl_flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL | SDL_RESIZABLE | SDL_DOUBLEBUF;
159
160 // Allow thread to be started/stopped
161 parent->start = consumer_start;
162 parent->stop = consumer_stop;
163 parent->is_stopped = consumer_is_stopped;
164
165 // Return the consumer produced
166 return parent;
167 }
168
169 // malloc or consumer init failed
170 free( this );
171
172 // Indicate failure
173 return NULL;
174 }
175
176 int consumer_start( mlt_consumer parent )
177 {
178 consumer_sdl this = parent->child;
179
180 if ( !this->running )
181 {
182 pthread_attr_t thread_attributes;
183
184 consumer_stop( parent );
185
186 this->running = 1;
187 this->joined = 0;
188
189 // Allow the user to force resizing to window size
190 if ( mlt_properties_get_int( this->properties, "resize" ) )
191 {
192 mlt_properties_set_int( this->properties, "width", this->width );
193 mlt_properties_set_int( this->properties, "height", this->height );
194 }
195
196 // Inherit the scheduling priority
197 pthread_attr_init( &thread_attributes );
198 pthread_attr_setinheritsched( &thread_attributes, PTHREAD_INHERIT_SCHED );
199
200 pthread_create( &this->thread, &thread_attributes, consumer_thread, this );
201 }
202
203 return 0;
204 }
205
206 int consumer_stop( mlt_consumer parent )
207 {
208 // Get the actual object
209 consumer_sdl this = parent->child;
210
211 if ( this->joined == 0 )
212 {
213 // Kill the thread and clean up
214 this->running = 0;
215
216 pthread_mutex_lock( &this->audio_mutex );
217 pthread_cond_broadcast( &this->audio_cond );
218 pthread_mutex_unlock( &this->audio_mutex );
219
220 pthread_join( this->thread, NULL );
221 this->joined = 1;
222 }
223
224 return 0;
225 }
226
227 int consumer_is_stopped( mlt_consumer parent )
228 {
229 consumer_sdl this = parent->child;
230 return !this->running;
231 }
232
233 static int sdl_lock_display( )
234 {
235 SDL_Surface *screen = SDL_GetVideoSurface( );
236 return screen != NULL && ( !SDL_MUSTLOCK( screen ) || SDL_LockSurface( screen ) >= 0 );
237 }
238
239 static void sdl_unlock_display( )
240 {
241 SDL_Surface *screen = SDL_GetVideoSurface( );
242 if ( screen != NULL && SDL_MUSTLOCK( screen ) )
243 SDL_UnlockSurface( screen );
244 }
245
246 static void sdl_fill_audio( void *udata, uint8_t *stream, int len )
247 {
248 consumer_sdl this = udata;
249
250 // Get the volume
251 float volume = mlt_properties_get_double( this->properties, "volume" );
252
253 pthread_mutex_lock( &this->audio_mutex );
254
255 // Block until audio received
256 while ( this->running && len > this->audio_avail )
257 pthread_cond_wait( &this->audio_cond, &this->audio_mutex );
258
259 if ( this->audio_avail >= len )
260 {
261 // Place in the audio buffer
262 memcpy( stream, this->audio_buffer, len );
263
264 // Remove len from the audio available
265 this->audio_avail -= len;
266
267 // Remove the samples
268 memmove( this->audio_buffer, this->audio_buffer + len, this->audio_avail );
269 }
270 else
271 {
272 // Just to be safe, wipe the stream first
273 memset( stream, 0, len );
274
275 // Copy what we have into the stream
276 memcpy( stream, this->audio_buffer, this->audio_avail );
277
278 // Mix the audio
279 SDL_MixAudio( stream, stream, len, ( int )( ( float )SDL_MIX_MAXVOLUME * volume ) );
280
281 // No audio left
282 this->audio_avail = 0;
283 }
284
285 // We're definitely playing now
286 this->playing = 1;
287
288 pthread_cond_broadcast( &this->audio_cond );
289 pthread_mutex_unlock( &this->audio_mutex );
290 }
291
292 static int consumer_play_audio( consumer_sdl this, mlt_frame frame, int init_audio, int *duration )
293 {
294 // Get the properties of this consumer
295 mlt_properties properties = this->properties;
296 mlt_audio_format afmt = mlt_audio_pcm;
297
298 // Set the preferred params of the test card signal
299 int channels = mlt_properties_get_int( properties, "channels" );
300 int frequency = mlt_properties_get_int( properties, "frequency" );
301 static int counter = 0;
302
303 int samples = mlt_sample_calculator( mlt_properties_get_double( this->properties, "fps" ), frequency, counter++ );
304
305 int16_t *pcm;
306 int bytes;
307
308 mlt_frame_get_audio( frame, &pcm, &afmt, &frequency, &channels, &samples );
309 *duration = ( ( samples * 1000 ) / frequency );
310
311 if ( mlt_properties_get_int( properties, "audio_off" ) )
312 {
313 this->playing = 1;
314 init_audio = 1;
315 return init_audio;
316 }
317
318 if ( init_audio == 1 )
319 {
320 SDL_AudioSpec request;
321 SDL_AudioSpec got;
322
323 int audio_buffer = mlt_properties_get_int( properties, "audio_buffer" );
324
325 // specify audio format
326 memset( &request, 0, sizeof( SDL_AudioSpec ) );
327 this->playing = 0;
328 request.freq = frequency;
329 request.format = AUDIO_S16;
330 request.channels = channels;
331 request.samples = audio_buffer;
332 request.callback = sdl_fill_audio;
333 request.userdata = (void *)this;
334 if ( SDL_OpenAudio( &request, &got ) != 0 )
335 {
336 fprintf( stderr, "SDL failed to open audio: %s\n", SDL_GetError() );
337 init_audio = 2;
338 }
339 else if ( got.size != 0 )
340 {
341 SDL_PauseAudio( 0 );
342 init_audio = 0;
343 }
344 }
345
346 if ( init_audio == 0 )
347 {
348 mlt_properties properties = mlt_frame_properties( frame );
349 bytes = ( samples * channels * 2 );
350 pthread_mutex_lock( &this->audio_mutex );
351 while ( this->running && bytes > ( sizeof( this->audio_buffer) - this->audio_avail ) )
352 pthread_cond_wait( &this->audio_cond, &this->audio_mutex );
353 if ( this->running )
354 {
355 if ( mlt_properties_get_double( properties, "_speed" ) == 1 )
356 memcpy( &this->audio_buffer[ this->audio_avail ], pcm, bytes );
357 else
358 memset( &this->audio_buffer[ this->audio_avail ], 0, bytes );
359 this->audio_avail += bytes;
360 }
361 pthread_cond_broadcast( &this->audio_cond );
362 pthread_mutex_unlock( &this->audio_mutex );
363 }
364 else
365 {
366 this->playing = 1;
367 }
368
369 return init_audio;
370 }
371
372 static int consumer_play_video( consumer_sdl this, mlt_frame frame )
373 {
374 // Get the properties of this consumer
375 mlt_properties properties = this->properties;
376
377 mlt_image_format vfmt = mlt_image_yuv422;
378 int width = this->width, height = this->height;
379 uint8_t *image;
380 int changed = 0;
381
382 if ( mlt_properties_get_int( properties, "video_off" ) == 0 )
383 {
384 // Get the image, width and height
385 mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
386
387 // Handle events
388 if ( this->sdl_screen != NULL )
389 {
390 SDL_Event event;
391
392 changed = consumer_get_dimensions( &this->window_width, &this->window_height );
393
394 while ( SDL_PollEvent( &event ) )
395 {
396 switch( event.type )
397 {
398 case SDL_VIDEORESIZE:
399 this->window_width = event.resize.w;
400 this->window_height = event.resize.h;
401 changed = 1;
402 break;
403 case SDL_QUIT:
404 this->running = 0;
405 break;
406 case SDL_KEYDOWN:
407 {
408 mlt_producer producer = mlt_properties_get_data( properties, "transport_producer", NULL );
409 char keyboard[ 2 ] = " ";
410 void (*callback)( mlt_producer, char * ) = mlt_properties_get_data( properties, "transport_callback", NULL );
411 if ( callback != NULL && producer != NULL && event.key.keysym.unicode < 0x80 && event.key.keysym.unicode > 0 )
412 {
413 keyboard[ 0 ] = ( char )event.key.keysym.unicode;
414 callback( producer, keyboard );
415 }
416 }
417 break;
418 }
419 }
420 }
421
422 if ( width != this->width || height != this->height || this->last_frame_aspect != mlt_frame_get_aspect_ratio( frame ) )
423 {
424 this->width = width;
425 this->height = height;
426 this->last_frame_aspect = mlt_frame_get_aspect_ratio( frame );
427 changed = 1;
428 }
429
430 if ( this->sdl_screen == NULL || changed )
431 {
432 // Determine frame's display aspect ratio
433 float frame_aspect = mlt_frame_get_aspect_ratio( frame ) * this->width / this->height;
434
435 // Determine window's new display aspect ratio
436 float this_aspect = ( float )this->window_width / this->window_height;
437
438 // If using hardware scaler
439 if ( mlt_properties_get( properties, "rescale" ) != NULL &&
440 !strcmp( mlt_properties_get( properties, "rescale" ), "none" ) )
441 {
442 // Special case optimisation to negate odd effect of sample aspect ratio
443 // not corresponding exactly with image resolution.
444 if ( ( (int)( this_aspect * 1000 ) == (int)( this->display_aspect * 1000 ) ) &&
445 ( (int)( mlt_frame_get_aspect_ratio( frame ) * 1000 ) == (int)( this->aspect_ratio * 1000 ) ) )
446 {
447 this->rect.w = this->window_width;
448 this->rect.h = this->window_height;
449 }
450 else
451 {
452 // Use hardware scaler to normalise display aspect ratio
453 this->rect.w = frame_aspect / this_aspect * this->window_width;
454 this->rect.h = this->window_height;
455 if ( this->rect.w > this->window_width )
456 {
457 this->rect.w = this->window_width;
458 this->rect.h = this_aspect / frame_aspect * this->window_height;
459 }
460 }
461 }
462 // Special case optimisation to negate odd effect of sample aspect ratio
463 // not corresponding exactly with image resolution.
464 else if ( (int)( this_aspect * 1000 ) == (int)( this->display_aspect * 1000 ) )
465 {
466 this->rect.w = this->window_width;
467 this->rect.h = this->window_height;
468 }
469 // Use hardware scaler to normalise sample aspect ratio
470 else if ( this->window_height * this->display_aspect > this->window_width )
471 {
472 this->rect.w = this->window_width;
473 this->rect.h = this->window_width / this->display_aspect;
474 }
475 else
476 {
477 this->rect.w = this->window_height * this->display_aspect;
478 this->rect.h = this->window_height;
479 }
480
481 this->rect.x = ( this->window_width - this->rect.w ) / 2;
482 this->rect.y = ( this->window_height - this->rect.h ) / 2;
483
484 mlt_properties_set_int( this->properties, "rect_x", this->rect.x );
485 mlt_properties_set_int( this->properties, "rect_y", this->rect.y );
486 mlt_properties_set_int( this->properties, "rect_w", this->rect.w );
487 mlt_properties_set_int( this->properties, "rect_h", this->rect.h );
488
489 // Force an overlay recreation
490 if ( this->sdl_overlay != NULL )
491 SDL_FreeYUVOverlay( this->sdl_overlay );
492
493 // open SDL window with video overlay, if possible
494 sdl_lock_display();
495 this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
496 sdl_unlock_display();
497
498 if ( this->sdl_screen != NULL )
499 {
500 SDL_SetClipRect( this->sdl_screen, &this->rect );
501 sdl_lock_display();
502 this->sdl_overlay = SDL_CreateYUVOverlay( this->width, this->height, SDL_YUY2_OVERLAY, this->sdl_screen );
503 sdl_unlock_display();
504 }
505 }
506
507 if ( mlt_properties_get_int( properties, "changed" ) )
508 {
509 sdl_lock_display();
510 this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
511 SDL_SetClipRect( this->sdl_screen, &this->rect );
512 SDL_Flip( this->sdl_screen );
513 sdl_unlock_display();
514 mlt_properties_set_int( properties, "changed", 0 );
515 }
516
517 if ( this->sdl_screen != NULL && this->sdl_overlay != NULL )
518 {
519 this->buffer = this->sdl_overlay->pixels[ 0 ];
520 sdl_lock_display();
521 if ( SDL_LockYUVOverlay( this->sdl_overlay ) >= 0 )
522 {
523 if ( image != NULL )
524 memcpy( this->buffer, image, width * height * 2 );
525 SDL_UnlockYUVOverlay( this->sdl_overlay );
526 SDL_DisplayYUVOverlay( this->sdl_overlay, &this->sdl_screen->clip_rect );
527 }
528 sdl_unlock_display();
529 }
530 }
531
532 return 0;
533 }
534
535 static void *video_thread( void *arg )
536 {
537 // Identify the arg
538 consumer_sdl this = arg;
539
540 // Obtain time of thread start
541 struct timeval now;
542 int64_t start = 0;
543 int64_t elapsed = 0;
544 struct timespec tm;
545 mlt_frame next = NULL;
546 mlt_properties properties = NULL;
547 double speed = 0;
548
549 // Get real time flag
550 int real_time = mlt_properties_get_int( this->properties, "real_time" );
551
552 // Get the current time
553 gettimeofday( &now, NULL );
554
555 // Determine start time
556 start = ( int64_t )now.tv_sec * 1000000 + now.tv_usec;
557
558 while ( this->running )
559 {
560 // Pop the next frame
561 pthread_mutex_lock( &this->video_mutex );
562 while ( ( next = mlt_deque_pop_front( this->queue ) ) == NULL && this->running )
563 pthread_cond_wait( &this->video_cond, &this->video_mutex );
564 pthread_mutex_unlock( &this->video_mutex );
565
566 // Get the properties
567 properties = mlt_frame_properties( next );
568
569 // Get the speed of the frame
570 speed = mlt_properties_get_double( properties, "_speed" );
571
572 // Get the current time
573 gettimeofday( &now, NULL );
574
575 // Get the elapsed time
576 elapsed = ( ( int64_t )now.tv_sec * 1000000 + now.tv_usec ) - start;
577
578 // See if we have to delay the display of the current frame
579 if ( mlt_properties_get_int( properties, "rendered" ) == 1 && this->running )
580 {
581 // Obtain the scheduled playout time
582 mlt_position scheduled = mlt_properties_get_position( properties, "playtime" );
583
584 // Determine the difference between the elapsed time and the scheduled playout time
585 mlt_position difference = scheduled - elapsed;
586
587 // Smooth playback a bit
588 if ( real_time && ( difference > 20000 && speed == 1.0 ) )
589 {
590 tm.tv_sec = difference / 1000000;
591 tm.tv_nsec = ( difference % 1000000 ) * 500;
592 nanosleep( &tm, NULL );
593 }
594
595 // Show current frame if not too old
596 if ( !real_time || ( difference > -10000 || speed != 1.0 || mlt_deque_count( this->queue ) < 2 ) )
597 consumer_play_video( this, next );
598
599 // If the queue is empty, recalculate start to allow build up again
600 if ( real_time && ( mlt_deque_count( this->queue ) == 0 && speed == 1.0 ) )
601 {
602 gettimeofday( &now, NULL );
603 start = ( ( int64_t )now.tv_sec * 1000000 + now.tv_usec ) - scheduled + 20000;
604 }
605 }
606
607 // This frame can now be closed
608 mlt_frame_close( next );
609 }
610
611 mlt_consumer_stopped( &this->parent );
612
613 return NULL;
614 }
615
616 /** Threaded wrapper for pipe.
617 */
618
619 static void *consumer_thread( void *arg )
620 {
621 // Identify the arg
622 consumer_sdl this = arg;
623
624 // Get the consumer
625 mlt_consumer consumer = &this->parent;
626
627 // Video thread
628 pthread_t thread;
629
630 // internal intialization
631 int init_audio = 1;
632 int init_video = 1;
633 mlt_frame frame = NULL;
634 mlt_properties properties = NULL;
635 int duration = 0;
636 int64_t playtime = 0;
637 struct timespec tm = { 0, 100000 };
638
639 if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE ) < 0 )
640 {
641 fprintf( stderr, "Failed to initialize SDL: %s\n", SDL_GetError() );
642 return NULL;
643 }
644
645 SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
646 SDL_EnableUNICODE( 1 );
647
648 // Loop until told not to
649 while( this->running )
650 {
651 // Get a frame from the attached producer
652 frame = mlt_consumer_rt_frame( consumer );
653
654 // Ensure that we have a frame
655 if ( frame != NULL )
656 {
657 // Get the frame properties
658 properties = mlt_frame_properties( frame );
659
660 // Play audio
661 init_audio = consumer_play_audio( this, frame, init_audio, &duration );
662
663 // Determine the start time now
664 if ( this->playing && init_video )
665 {
666 // Create the video thread
667 pthread_create( &thread, NULL, video_thread, this );
668
669 // Video doesn't need to be initialised any more
670 init_video = 0;
671 }
672
673 // Set playtime for this frame
674 mlt_properties_set_position( properties, "playtime", playtime );
675
676 while ( this->running && mlt_deque_count( this->queue ) > 15 )
677 nanosleep( &tm, NULL );
678
679 // Push this frame to the back of the queue
680 pthread_mutex_lock( &this->video_mutex );
681 mlt_deque_push_back( this->queue, frame );
682 pthread_cond_broadcast( &this->video_cond );
683 pthread_mutex_unlock( &this->video_mutex );
684
685 // Calculate the next playtime
686 playtime += ( duration * 1000 );
687 }
688 }
689
690 // Kill the video thread
691 if ( init_video == 0 )
692 {
693 pthread_mutex_lock( &this->video_mutex );
694 pthread_cond_broadcast( &this->video_cond );
695 pthread_mutex_unlock( &this->video_mutex );
696 pthread_join( thread, NULL );
697 }
698
699 // internal cleanup
700 if ( this->sdl_overlay != NULL )
701 SDL_FreeYUVOverlay( this->sdl_overlay );
702 SDL_Quit( );
703
704 while( mlt_deque_count( this->queue ) )
705 mlt_frame_close( mlt_deque_pop_back( this->queue ) );
706
707 this->sdl_screen = NULL;
708 this->sdl_overlay = NULL;
709 this->audio_avail = 0;
710
711 return NULL;
712 }
713
714 static int consumer_get_dimensions( int *width, int *height )
715 {
716 int changed = 0;
717
718 // SDL windows manager structure
719 SDL_SysWMinfo wm;
720
721 // Specify the SDL Version
722 SDL_VERSION( &wm.version );
723
724 // Lock the display
725 sdl_lock_display();
726
727 // Get the wm structure
728 if ( SDL_GetWMInfo( &wm ) == 1 )
729 {
730 // Check that we have the X11 wm
731 if ( wm.subsystem == SDL_SYSWM_X11 )
732 {
733 // Get the SDL window
734 Window window = wm.info.x11.window;
735
736 // Get the display session
737 Display *display = wm.info.x11.display;
738
739 // Get the window attributes
740 XWindowAttributes attr;
741 XGetWindowAttributes( display, window, &attr );
742
743 // Determine whether window has changed
744 changed = *width != attr.width || *height != attr.height;
745
746 // Return width and height
747 *width = attr.width;
748 *height = attr.height;
749 }
750 }
751
752 // Unlock the display
753 sdl_lock_display();
754
755 return changed;
756 }
757
758 /** Callback to allow override of the close method.
759 */
760
761 static void consumer_close( mlt_consumer parent )
762 {
763 // Get the actual object
764 consumer_sdl this = parent->child;
765
766 // Stop the consumer
767 mlt_consumer_stop( parent );
768
769 // Close the queue
770 mlt_deque_close( this->queue );
771
772 // Destroy mutexes
773 pthread_mutex_destroy( &this->audio_mutex );
774 pthread_cond_destroy( &this->audio_cond );
775
776 // Now clean up the rest
777 mlt_consumer_close( parent );
778
779 // Finally clean up this
780 free( this );
781 }