2 * consumer_sdl.c -- A Simple DirectMedia Layer consumer
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Dan Dennedy <dan@dennedy.org>
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.
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.
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
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>
31 #include <SDL/SDL_syswm.h>
34 /** This classes definition.
37 typedef struct consumer_sdl_s
*consumer_sdl
;
41 struct mlt_consumer_s parent
;
42 mlt_properties properties
;
47 uint8_t audio_buffer
[ 4096 * 10 ];
49 pthread_mutex_t audio_mutex
;
50 pthread_cond_t audio_cond
;
51 pthread_mutex_t video_mutex
;
52 pthread_cond_t video_cond
;
61 SDL_Surface
*sdl_screen
;
62 SDL_Overlay
*sdl_overlay
;
69 /** Forward references to static functions.
72 static int consumer_start( mlt_consumer parent
);
73 static int consumer_stop( mlt_consumer parent
);
74 static int consumer_is_stopped( mlt_consumer parent
);
75 static void consumer_close( mlt_consumer parent
);
76 static void *consumer_thread( void * );
77 static int consumer_get_dimensions( int *width
, int *height
);
78 static void consumer_sdl_event( mlt_listener listener
, mlt_properties owner
, mlt_service
this, void **args
);
80 /** This is what will be called by the factory - anything can be passed in
81 via the argument, but keep it simple.
84 mlt_consumer
consumer_sdl_init( mlt_profile profile
, mlt_service_type type
, const char *id
, char *arg
)
86 // Create the consumer object
87 consumer_sdl
this = calloc( sizeof( struct consumer_sdl_s
), 1 );
89 // If no malloc'd and consumer init ok
90 if ( this != NULL
&& mlt_consumer_init( &this->parent
, this, profile
) == 0 )
93 this->queue
= mlt_deque_init( );
95 // Get the parent consumer object
96 mlt_consumer parent
= &this->parent
;
98 // We have stuff to clean up, so override the close method
99 parent
->close
= consumer_close
;
101 // get a handle on properties
102 mlt_service service
= MLT_CONSUMER_SERVICE( parent
);
103 this->properties
= MLT_SERVICE_PROPERTIES( service
);
105 // Set the default volume
106 mlt_properties_set_double( this->properties
, "volume", 1.0 );
108 // This is the initialisation of the consumer
109 pthread_mutex_init( &this->audio_mutex
, NULL
);
110 pthread_cond_init( &this->audio_cond
, NULL
);
111 pthread_mutex_init( &this->video_mutex
, NULL
);
112 pthread_cond_init( &this->video_cond
, NULL
);
114 // Default scaler (for now we'll use nearest)
115 mlt_properties_set( this->properties
, "rescale", "nearest" );
117 // Default buffer for low latency
118 mlt_properties_set_int( this->properties
, "buffer", 1 );
120 // Default progressive true
121 mlt_properties_set_int( this->properties
, "progressive", 0 );
123 // Default audio buffer
124 mlt_properties_set_int( this->properties
, "audio_buffer", 512 );
126 // Ensure we don't join on a non-running object
129 // process actual param
130 if ( arg
== NULL
|| sscanf( arg
, "%dx%d", &this->width
, &this->height
) != 2 )
132 this->width
= mlt_properties_get_int( this->properties
, "width" );
133 this->height
= mlt_properties_get_int( this->properties
, "height" );
137 this->sdl_flags
= SDL_HWSURFACE
| SDL_ASYNCBLIT
| SDL_HWACCEL
| SDL_RESIZABLE
| SDL_DOUBLEBUF
;
139 // Allow thread to be started/stopped
140 parent
->start
= consumer_start
;
141 parent
->stop
= consumer_stop
;
142 parent
->is_stopped
= consumer_is_stopped
;
144 // Register specific events
145 mlt_events_register( this->properties
, "consumer-sdl-event", ( mlt_transmitter
)consumer_sdl_event
);
147 // Return the consumer produced
151 // malloc or consumer init failed
158 static void consumer_sdl_event( mlt_listener listener
, mlt_properties owner
, mlt_service
this, void **args
)
160 if ( listener
!= NULL
)
161 listener( owner
, this, ( SDL_Event
* )args
[ 0 ] );
164 int consumer_start( mlt_consumer parent
)
166 consumer_sdl
this = parent
->child
;
168 if ( !this->running
)
170 int video_off
= mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent
), "video_off" );
171 int preview_off
= mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent
), "preview_off" );
172 int display_off
= video_off
| preview_off
;
173 int audio_off
= mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent
), "audio_off" );
174 int sdl_started
= mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent
), "sdl_started" );
176 consumer_stop( parent
);
181 if ( mlt_properties_get_int( this->properties
, "width" ) > 0 )
182 this->width
= mlt_properties_get_int( this->properties
, "width" );
183 if ( mlt_properties_get_int( this->properties
, "height" ) > 0 )
184 this->height
= mlt_properties_get_int( this->properties
, "height" );
186 this->bpp
= mlt_properties_get_int( this->properties
, "bpp" );
188 // Attach a colour space converter
189 if ( preview_off
&& !this->filtered
)
191 mlt_profile profile
= mlt_service_profile( MLT_CONSUMER_SERVICE( parent
) );
192 mlt_filter filter
= mlt_factory_filter( profile
, "avcolour_space", NULL
);
195 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter
), "forced", mlt_image_yuv422
);
196 mlt_service_attach( MLT_CONSUMER_SERVICE( parent
), filter
);
197 mlt_filter_close( filter
);
202 if ( sdl_started
== 0 && display_off
== 0 )
204 if ( SDL_Init( SDL_INIT_VIDEO
| SDL_INIT_NOPARACHUTE
) < 0 )
206 fprintf( stderr
, "Failed to initialize SDL: %s\n", SDL_GetError() );
210 SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY
, SDL_DEFAULT_REPEAT_INTERVAL
);
211 SDL_EnableUNICODE( 1 );
213 else if ( display_off
== 0 )
215 this->sdl_screen
= SDL_GetVideoSurface( );
218 if ( audio_off
== 0 )
219 SDL_InitSubSystem( SDL_INIT_AUDIO
);
221 // Default window size
222 double display_ratio
= mlt_properties_get_double( this->properties
, "display_ratio" );
223 this->window_width
= ( double )this->height
* display_ratio
;
224 this->window_height
= this->height
;
226 if ( this->sdl_screen
== NULL
&& display_off
== 0 )
228 if ( mlt_properties_get_int( this->properties
, "fullscreen" ) )
230 const SDL_VideoInfo
*vi
= SDL_GetVideoInfo();
231 this->window_width
= vi
->current_w
;
232 this->window_height
= vi
->current_h
;
233 this->sdl_flags
|= SDL_FULLSCREEN
;
234 SDL_ShowCursor( SDL_DISABLE
);
236 this->sdl_screen
= SDL_SetVideoMode( this->window_width
, this->window_height
, 0, this->sdl_flags
);
239 pthread_create( &this->thread
, NULL
, consumer_thread
, this );
245 int consumer_stop( mlt_consumer parent
)
247 // Get the actual object
248 consumer_sdl
this = parent
->child
;
250 if ( this->joined
== 0 )
252 // Kill the thread and clean up
256 pthread_join( this->thread
, NULL
);
259 if ( this->sdl_overlay
!= NULL
)
260 SDL_FreeYUVOverlay( this->sdl_overlay
);
261 this->sdl_overlay
= NULL
;
263 if ( !mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent
), "audio_off" ) )
265 pthread_mutex_lock( &this->audio_mutex
);
266 pthread_cond_broadcast( &this->audio_cond
);
267 pthread_mutex_unlock( &this->audio_mutex
);
268 SDL_QuitSubSystem( SDL_INIT_AUDIO
);
271 if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( parent
), "sdl_started" ) == 0 )
274 this->sdl_screen
= NULL
;
280 int consumer_is_stopped( mlt_consumer parent
)
282 consumer_sdl
this = parent
->child
;
283 return !this->running
;
286 static int sdl_lock_display( )
288 SDL_Surface
*screen
= SDL_GetVideoSurface( );
289 return screen
!= NULL
&& ( !SDL_MUSTLOCK( screen
) || SDL_LockSurface( screen
) >= 0 );
292 static void sdl_unlock_display( )
294 SDL_Surface
*screen
= SDL_GetVideoSurface( );
295 if ( screen
!= NULL
&& SDL_MUSTLOCK( screen
) )
296 SDL_UnlockSurface( screen
);
299 static void sdl_fill_audio( void *udata
, uint8_t *stream
, int len
)
301 consumer_sdl
this = udata
;
304 double volume
= mlt_properties_get_double( this->properties
, "volume" );
306 pthread_mutex_lock( &this->audio_mutex
);
308 // Block until audio received
309 while ( this->running
&& len
> this->audio_avail
)
310 pthread_cond_wait( &this->audio_cond
, &this->audio_mutex
);
312 if ( this->audio_avail
>= len
)
314 // Place in the audio buffer
316 SDL_MixAudio( stream
, this->audio_buffer
, len
, ( int )( ( float )SDL_MIX_MAXVOLUME
* volume
) );
318 memcpy( stream
, this->audio_buffer
, len
);
320 // Remove len from the audio available
321 this->audio_avail
-= len
;
323 // Remove the samples
324 memmove( this->audio_buffer
, this->audio_buffer
+ len
, this->audio_avail
);
328 // Just to be safe, wipe the stream first
329 memset( stream
, 0, len
);
332 SDL_MixAudio( stream
, this->audio_buffer
, len
, ( int )( ( float )SDL_MIX_MAXVOLUME
* volume
) );
335 this->audio_avail
= 0;
338 // We're definitely playing now
341 pthread_cond_broadcast( &this->audio_cond
);
342 pthread_mutex_unlock( &this->audio_mutex
);
345 static int consumer_play_audio( consumer_sdl
this, mlt_frame frame
, int init_audio
, int *duration
)
347 // Get the properties of this consumer
348 mlt_properties properties
= this->properties
;
349 mlt_audio_format afmt
= mlt_audio_pcm
;
351 // Set the preferred params of the test card signal
352 int channels
= mlt_properties_get_int( properties
, "channels" );
353 int frequency
= mlt_properties_get_int( properties
, "frequency" );
354 static int counter
= 0;
356 int samples
= mlt_sample_calculator( mlt_properties_get_double( this->properties
, "fps" ), frequency
, counter
++ );
361 mlt_frame_get_audio( frame
, &pcm
, &afmt
, &frequency
, &channels
, &samples
);
362 *duration
= ( ( samples
* 1000 ) / frequency
);
364 if ( mlt_properties_get_int( properties
, "audio_off" ) )
371 if ( init_audio
== 1 )
373 SDL_AudioSpec request
;
376 int audio_buffer
= mlt_properties_get_int( properties
, "audio_buffer" );
378 // specify audio format
379 memset( &request
, 0, sizeof( SDL_AudioSpec
) );
381 request
.freq
= frequency
;
382 request
.format
= AUDIO_S16SYS
;
383 request
.channels
= channels
;
384 request
.samples
= audio_buffer
;
385 request
.callback
= sdl_fill_audio
;
386 request
.userdata
= (void *)this;
387 if ( SDL_OpenAudio( &request
, &got
) != 0 )
389 fprintf( stderr
, "SDL failed to open audio: %s\n", SDL_GetError() );
392 else if ( got
.size
!= 0 )
399 if ( init_audio
== 0 )
401 mlt_properties properties
= MLT_FRAME_PROPERTIES( frame
);
402 bytes
= ( samples
* channels
* 2 );
403 pthread_mutex_lock( &this->audio_mutex
);
404 while ( this->running
&& bytes
> ( sizeof( this->audio_buffer
) - this->audio_avail
) )
405 pthread_cond_wait( &this->audio_cond
, &this->audio_mutex
);
408 if ( mlt_properties_get_double( properties
, "_speed" ) == 1 )
409 memcpy( &this->audio_buffer
[ this->audio_avail
], pcm
, bytes
);
411 memset( &this->audio_buffer
[ this->audio_avail
], 0, bytes
);
412 this->audio_avail
+= bytes
;
414 pthread_cond_broadcast( &this->audio_cond
);
415 pthread_mutex_unlock( &this->audio_mutex
);
425 static int consumer_play_video( consumer_sdl
this, mlt_frame frame
)
427 // Get the properties of this consumer
428 mlt_properties properties
= this->properties
;
430 mlt_image_format vfmt
= mlt_image_yuv422
;
431 int width
= this->width
, height
= this->height
;
435 int video_off
= mlt_properties_get_int( properties
, "video_off" );
436 int preview_off
= mlt_properties_get_int( properties
, "preview_off" );
437 mlt_image_format preview_format
= mlt_properties_get_int( properties
, "preview_format" );
438 int display_off
= video_off
| preview_off
;
440 if ( this->running
&& display_off
== 0 )
442 // Get the image, width and height
443 mlt_frame_get_image( frame
, &image
, &vfmt
, &width
, &height
, 0 );
444 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame
), "format", vfmt
);
445 mlt_events_fire( properties
, "consumer-frame-show", frame
, NULL
);
448 if ( this->sdl_screen
!= NULL
)
453 changed
= consumer_get_dimensions( &this->window_width
, &this->window_height
);
454 sdl_unlock_display( );
456 while ( SDL_PollEvent( &event
) )
458 mlt_events_fire( this->properties
, "consumer-sdl-event", &event
, NULL
);
462 case SDL_VIDEORESIZE
:
463 this->window_width
= event
.resize
.w
;
464 this->window_height
= event
.resize
.h
;
472 mlt_producer producer
= mlt_properties_get_data( properties
, "transport_producer", NULL
);
473 char keyboard
[ 2 ] = " ";
474 void (*callback
)( mlt_producer
, char * ) = mlt_properties_get_data( properties
, "transport_callback", NULL
);
475 if ( callback
!= NULL
&& producer
!= NULL
&& event
.key
.keysym
.unicode
< 0x80 && event
.key
.keysym
.unicode
> 0 )
477 keyboard
[ 0 ] = ( char )event
.key
.keysym
.unicode
;
478 callback( producer
, keyboard
);
488 if ( width
!= this->width
|| height
!= this->height
)
490 if ( this->sdl_overlay
!= NULL
)
491 SDL_FreeYUVOverlay( this->sdl_overlay
);
492 this->sdl_overlay
= NULL
;
495 if ( this->running
&& ( this->sdl_screen
== NULL
|| changed
) )
497 // Force an overlay recreation
498 if ( this->sdl_overlay
!= NULL
)
499 SDL_FreeYUVOverlay( this->sdl_overlay
);
500 this->sdl_overlay
= NULL
;
502 // open SDL window with video overlay, if possible
503 this->sdl_screen
= SDL_SetVideoMode( this->window_width
, this->window_height
, this->bpp
, this->sdl_flags
);
504 if ( consumer_get_dimensions( &this->window_width
, &this->window_height
) )
505 this->sdl_screen
= SDL_SetVideoMode( this->window_width
, this->window_height
, this->bpp
, this->sdl_flags
);
510 // Determine window's new display aspect ratio
511 double this_aspect
= ( double )this->window_width
/ this->window_height
;
513 // Get the display aspect ratio
514 double display_ratio
= mlt_properties_get_double( properties
, "display_ratio" );
516 // Determine frame's display aspect ratio
517 double frame_aspect
= mlt_frame_get_aspect_ratio( frame
) * width
/ height
;
519 // Store the width and height received
521 this->height
= height
;
523 // If using hardware scaler
524 if ( mlt_properties_get( properties
, "rescale" ) != NULL
&&
525 !strcmp( mlt_properties_get( properties
, "rescale" ), "none" ) )
527 // Use hardware scaler to normalise display aspect ratio
528 this->rect
.w
= frame_aspect
/ this_aspect
* this->window_width
;
529 this->rect
.h
= this->window_height
;
530 if ( this->rect
.w
> this->window_width
)
532 this->rect
.w
= this->window_width
;
533 this->rect
.h
= this_aspect
/ frame_aspect
* this->window_height
;
536 // Special case optimisation to negate odd effect of sample aspect ratio
537 // not corresponding exactly with image resolution.
538 else if ( (int)( this_aspect
* 1000 ) == (int)( display_ratio
* 1000 ) )
540 this->rect
.w
= this->window_width
;
541 this->rect
.h
= this->window_height
;
543 // Use hardware scaler to normalise sample aspect ratio
544 else if ( this->window_height
* display_ratio
> this->window_width
)
546 this->rect
.w
= this->window_width
;
547 this->rect
.h
= this->window_width
/ display_ratio
;
551 this->rect
.w
= this->window_height
* display_ratio
;
552 this->rect
.h
= this->window_height
;
555 this->rect
.x
= ( this->window_width
- this->rect
.w
) / 2;
556 this->rect
.y
= ( this->window_height
- this->rect
.h
) / 2;
557 this->rect
.x
-= this->rect
.x
% 2;
559 mlt_properties_set_int( this->properties
, "rect_x", this->rect
.x
);
560 mlt_properties_set_int( this->properties
, "rect_y", this->rect
.y
);
561 mlt_properties_set_int( this->properties
, "rect_w", this->rect
.w
);
562 mlt_properties_set_int( this->properties
, "rect_h", this->rect
.h
);
564 SDL_SetClipRect( this->sdl_screen
, &this->rect
);
567 if ( this->running
&& this->sdl_screen
!= NULL
&& this->sdl_overlay
== NULL
)
569 SDL_SetClipRect( this->sdl_screen
, &this->rect
);
570 this->sdl_overlay
= SDL_CreateYUVOverlay( width
, height
, SDL_YUY2_OVERLAY
, this->sdl_screen
);
573 if ( this->running
&& this->sdl_screen
!= NULL
&& this->sdl_overlay
!= NULL
)
575 this->buffer
= this->sdl_overlay
->pixels
[ 0 ];
576 if ( SDL_LockYUVOverlay( this->sdl_overlay
) >= 0 )
579 memcpy( this->buffer
, image
, width
* height
* 2 );
580 SDL_UnlockYUVOverlay( this->sdl_overlay
);
581 SDL_DisplayYUVOverlay( this->sdl_overlay
, &this->sdl_screen
->clip_rect
);
585 sdl_unlock_display();
587 else if ( this->running
)
589 vfmt
= preview_format
== mlt_image_none ? mlt_image_rgb24a
: preview_format
;
591 mlt_frame_get_image( frame
, &image
, &vfmt
, &width
, &height
, 0 );
592 mlt_properties_set_int( MLT_FRAME_PROPERTIES( frame
), "format", vfmt
);
593 mlt_events_fire( properties
, "consumer-frame-show", frame
, NULL
);
599 static void *video_thread( void *arg
)
602 consumer_sdl
this = arg
;
604 // Obtain time of thread start
609 mlt_frame next
= NULL
;
610 mlt_properties properties
= NULL
;
613 // Get real time flag
614 int real_time
= mlt_properties_get_int( this->properties
, "real_time" );
616 // Get the current time
617 gettimeofday( &now
, NULL
);
619 // Determine start time
620 start
= ( int64_t )now
.tv_sec
* 1000000 + now
.tv_usec
;
622 while ( this->running
)
624 // Pop the next frame
625 pthread_mutex_lock( &this->video_mutex
);
626 next
= mlt_deque_pop_front( this->queue
);
627 while ( next
== NULL
&& this->running
)
629 pthread_cond_wait( &this->video_cond
, &this->video_mutex
);
630 next
= mlt_deque_pop_front( this->queue
);
632 pthread_mutex_unlock( &this->video_mutex
);
634 if ( !this->running
|| next
== NULL
) break;
636 // Get the properties
637 properties
= MLT_FRAME_PROPERTIES( next
);
639 // Get the speed of the frame
640 speed
= mlt_properties_get_double( properties
, "_speed" );
642 // Get the current time
643 gettimeofday( &now
, NULL
);
645 // Get the elapsed time
646 elapsed
= ( ( int64_t )now
.tv_sec
* 1000000 + now
.tv_usec
) - start
;
648 // See if we have to delay the display of the current frame
649 if ( mlt_properties_get_int( properties
, "rendered" ) == 1 && this->running
)
651 // Obtain the scheduled playout time
652 int64_t scheduled
= mlt_properties_get_int( properties
, "playtime" );
654 // Determine the difference between the elapsed time and the scheduled playout time
655 int64_t difference
= scheduled
- elapsed
;
657 // Smooth playback a bit
658 if ( real_time
&& ( difference
> 20000 && speed
== 1.0 ) )
660 tm
.tv_sec
= difference
/ 1000000;
661 tm
.tv_nsec
= ( difference
% 1000000 ) * 500;
662 nanosleep( &tm
, NULL
);
665 // Show current frame if not too old
666 if ( !real_time
|| ( difference
> -10000 || speed
!= 1.0 || mlt_deque_count( this->queue
) < 2 ) )
667 consumer_play_video( this, next
);
669 // If the queue is empty, recalculate start to allow build up again
670 if ( real_time
&& ( mlt_deque_count( this->queue
) == 0 && speed
== 1.0 ) )
672 gettimeofday( &now
, NULL
);
673 start
= ( ( int64_t )now
.tv_sec
* 1000000 + now
.tv_usec
) - scheduled
+ 20000;
677 // This frame can now be closed
678 mlt_frame_close( next
);
683 mlt_frame_close( next
);
685 mlt_consumer_stopped( &this->parent
);
690 /** Threaded wrapper for pipe.
693 static void *consumer_thread( void *arg
)
696 consumer_sdl
this = arg
;
699 mlt_consumer consumer
= &this->parent
;
701 // Convenience functionality
702 int terminate_on_pause
= mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer
), "terminate_on_pause" );
708 // internal intialization
711 mlt_frame frame
= NULL
;
712 mlt_properties properties
= NULL
;
714 int64_t playtime
= 0;
715 struct timespec tm
= { 0, 100000 };
717 // Loop until told not to
718 while( !terminated
&& this->running
)
720 // Get a frame from the attached producer
721 frame
= mlt_consumer_rt_frame( consumer
);
723 // Check for termination
724 if ( terminate_on_pause
&& frame
!= NULL
)
725 terminated
= mlt_properties_get_double( MLT_FRAME_PROPERTIES( frame
), "_speed" ) == 0.0;
727 // Ensure that we have a frame
730 // Get the frame properties
731 properties
= MLT_FRAME_PROPERTIES( frame
);
734 init_audio
= consumer_play_audio( this, frame
, init_audio
, &duration
);
736 // Determine the start time now
737 if ( this->playing
&& init_video
)
739 // Create the video thread
740 pthread_create( &thread
, NULL
, video_thread
, this );
742 // Video doesn't need to be initialised any more
746 // Set playtime for this frame
747 mlt_properties_set_int( properties
, "playtime", playtime
);
749 while ( this->running
&& mlt_deque_count( this->queue
) > 15 )
750 nanosleep( &tm
, NULL
);
752 // Push this frame to the back of the queue
753 pthread_mutex_lock( &this->video_mutex
);
754 mlt_deque_push_back( this->queue
, frame
);
755 pthread_cond_broadcast( &this->video_cond
);
756 pthread_mutex_unlock( &this->video_mutex
);
758 // Calculate the next playtime
759 playtime
+= ( duration
* 1000 );
765 // Kill the video thread
766 if ( init_video
== 0 )
768 pthread_mutex_lock( &this->video_mutex
);
769 pthread_cond_broadcast( &this->video_cond
);
770 pthread_mutex_unlock( &this->video_mutex
);
771 pthread_join( thread
, NULL
);
774 while( mlt_deque_count( this->queue
) )
775 mlt_frame_close( mlt_deque_pop_back( this->queue
) );
777 this->sdl_screen
= NULL
;
778 this->audio_avail
= 0;
783 static int consumer_get_dimensions( int *width
, int *height
)
787 // SDL windows manager structure
790 // Specify the SDL Version
791 SDL_VERSION( &wm
.version
);
794 //sdl_lock_display();
797 // Get the wm structure
798 if ( SDL_GetWMInfo( &wm
) == 1 )
800 // Check that we have the X11 wm
801 if ( wm
.subsystem
== SDL_SYSWM_X11
)
803 // Get the SDL window
804 Window window
= wm
.info
.x11
.window
;
806 // Get the display session
807 Display
*display
= wm
.info
.x11
.display
;
809 // Get the window attributes
810 XWindowAttributes attr
;
811 XGetWindowAttributes( display
, window
, &attr
);
813 // Determine whether window has changed
814 changed
= *width
!= attr
.width
|| *height
!= attr
.height
;
816 // Return width and height
818 *height
= attr
.height
;
823 // Unlock the display
824 //sdl_unlock_display();
829 /** Callback to allow override of the close method.
832 static void consumer_close( mlt_consumer parent
)
834 // Get the actual object
835 consumer_sdl
this = parent
->child
;
838 ///mlt_consumer_stop( parent );
840 // Now clean up the rest
841 mlt_consumer_close( parent
);
844 mlt_deque_close( this->queue
);
847 pthread_mutex_destroy( &this->audio_mutex
);
848 pthread_cond_destroy( &this->audio_cond
);
850 // Finally clean up this