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 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.
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.
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.
21 #include "consumer_sdl.h"
22 #include <framework/mlt_frame.h>
23 #include <framework/mlt_deque.h>
29 #include <SDL/SDL_syswm.h>
33 # include "consumer_sdl_osx_hack.h"
34 # import <AppKit/NSApplication.h>
35 # import <Foundation/Foundation.h>
39 /** This classes definition.
42 typedef struct consumer_sdl_s
*consumer_sdl
;
46 struct mlt_consumer_s parent
;
47 mlt_properties properties
;
52 uint8_t audio_buffer
[ 4096 * 10 ];
54 pthread_mutex_t audio_mutex
;
55 pthread_cond_t audio_cond
;
56 pthread_mutex_t video_mutex
;
57 pthread_cond_t video_cond
;
66 SDL_Surface
*sdl_screen
;
67 SDL_Overlay
*sdl_overlay
;
73 /** Forward references to static functions.
76 static int consumer_start( mlt_consumer parent
);
77 static int consumer_stop( mlt_consumer parent
);
78 static int consumer_is_stopped( mlt_consumer parent
);
79 static void consumer_close( mlt_consumer parent
);
80 static void *consumer_thread( void * );
81 static int consumer_get_dimensions( int *width
, int *height
);
82 static void consumer_sdl_event( mlt_listener listener
, mlt_properties owner
, mlt_service
this, void **args
);
84 /** This is what will be called by the factory - anything can be passed in
85 via the argument, but keep it simple.
88 mlt_consumer
consumer_sdl_init( char *arg
)
93 [NSApplication sharedApplication
];
95 // Spawn a fake thread so that cocoa knows to be multithreaded
96 DummyThread
*dummy
= [[DummyThread alloc
] init
];
97 [NSThread detachNewThreadSelector
:@
selector(startThread
:) toTarget
:dummy withObject
:nil
];
100 // Create the consumer object
101 consumer_sdl
this = calloc( sizeof( struct consumer_sdl_s
), 1 );
103 // If no malloc'd and consumer init ok
104 if ( this != NULL
&& mlt_consumer_init( &this->parent
, this ) == 0 )
107 this->queue
= mlt_deque_init( );
109 // Get the parent consumer object
110 mlt_consumer parent
= &this->parent
;
112 // We have stuff to clean up, so override the close method
113 parent
->close
= consumer_close
;
115 // get a handle on properties
116 mlt_service service
= MLT_CONSUMER_SERVICE( parent
);
117 this->properties
= MLT_SERVICE_PROPERTIES( service
);
119 // Default display aspect ratio
120 double display_ratio
= mlt_properties_get_double( this->properties
, "display_ratio" );
122 // Set the default volume
123 mlt_properties_set_double( this->properties
, "volume", 1.0 );
125 // This is the initialisation of the consumer
126 pthread_mutex_init( &this->audio_mutex
, NULL
);
127 pthread_cond_init( &this->audio_cond
, NULL
);
128 pthread_mutex_init( &this->video_mutex
, NULL
);
129 pthread_cond_init( &this->video_cond
, NULL
);
131 // Default scaler (for now we'll use nearest)
132 mlt_properties_set( this->properties
, "rescale", "nearest" );
134 // Default buffer for low latency
135 mlt_properties_set_int( this->properties
, "buffer", 1 );
137 // Default progressive true
138 mlt_properties_set_int( this->properties
, "progressive", 0 );
140 // Default audio buffer
141 mlt_properties_set_int( this->properties
, "audio_buffer", 512 );
143 // Ensure we don't join on a non-running object
146 // process actual param
147 if ( arg
== NULL
|| sscanf( arg
, "%dx%d", &this->width
, &this->height
) != 2 )
149 this->width
= mlt_properties_get_int( this->properties
, "width" );
150 this->height
= mlt_properties_get_int( this->properties
, "height" );
153 // Default window size
154 this->window_width
= ( double )this->height
* display_ratio
;
155 this->window_height
= this->height
;
158 this->sdl_flags
= SDL_HWSURFACE
| SDL_ASYNCBLIT
| SDL_HWACCEL
| SDL_RESIZABLE
| SDL_DOUBLEBUF
;
160 // Allow thread to be started/stopped
161 parent
->start
= consumer_start
;
162 parent
->stop
= consumer_stop
;
163 parent
->is_stopped
= consumer_is_stopped
;
165 // Register specific events
166 mlt_events_register( this->properties
, "consumer-sdl-event", ( mlt_transmitter
)consumer_sdl_event
);
168 // Return the consumer produced
172 // malloc or consumer init failed
179 static void consumer_sdl_event( mlt_listener listener
, mlt_properties owner
, mlt_service
this, void **args
)
181 if ( listener
!= NULL
)
182 listener( owner
, this, ( SDL_Event
* )args
[ 0 ] );
185 int consumer_start( mlt_consumer parent
)
187 consumer_sdl
this = parent
->child
;
189 if ( !this->running
)
191 consumer_stop( parent
);
196 // Allow the user to force resizing to window size
197 if ( mlt_properties_get_int( this->properties
, "resize" ) )
199 mlt_properties_set_int( this->properties
, "width", this->width
);
200 mlt_properties_set_int( this->properties
, "height", this->height
);
204 this->width
= mlt_properties_get_int( this->properties
, "width" );
205 this->height
= mlt_properties_get_int( this->properties
, "height" );
208 pthread_create( &this->thread
, NULL
, consumer_thread
, this );
214 int consumer_stop( mlt_consumer parent
)
216 // Get the actual object
217 consumer_sdl
this = parent
->child
;
219 if ( this->joined
== 0 )
221 // Kill the thread and clean up
224 pthread_join( this->thread
, NULL
);
230 int consumer_is_stopped( mlt_consumer parent
)
232 consumer_sdl
this = parent
->child
;
233 return !this->running
;
236 static int sdl_lock_display( )
238 SDL_Surface
*screen
= SDL_GetVideoSurface( );
239 return screen
!= NULL
&& ( !SDL_MUSTLOCK( screen
) || SDL_LockSurface( screen
) >= 0 );
242 static void sdl_unlock_display( )
244 SDL_Surface
*screen
= SDL_GetVideoSurface( );
245 if ( screen
!= NULL
&& SDL_MUSTLOCK( screen
) )
246 SDL_UnlockSurface( screen
);
249 static void sdl_fill_audio( void *udata
, uint8_t *stream
, int len
)
251 consumer_sdl
this = udata
;
254 double volume
= mlt_properties_get_double( this->properties
, "volume" );
256 pthread_mutex_lock( &this->audio_mutex
);
258 // Block until audio received
259 while ( this->running
&& len
> this->audio_avail
)
260 pthread_cond_wait( &this->audio_cond
, &this->audio_mutex
);
262 if ( this->audio_avail
>= len
)
264 // Place in the audio buffer
266 SDL_MixAudio( stream
, this->audio_buffer
, len
, ( int )( ( float )SDL_MIX_MAXVOLUME
* volume
) );
268 memcpy( stream
, this->audio_buffer
, len
);
270 // Remove len from the audio available
271 this->audio_avail
-= len
;
273 // Remove the samples
274 memmove( this->audio_buffer
, this->audio_buffer
+ len
, this->audio_avail
);
278 // Just to be safe, wipe the stream first
279 memset( stream
, 0, len
);
281 // Copy what we have into the stream
282 memcpy( stream
, this->audio_buffer
, this->audio_avail
);
285 SDL_MixAudio( stream
, this->audio_buffer
, len
, ( int )( ( float )SDL_MIX_MAXVOLUME
* volume
) );
288 this->audio_avail
= 0;
291 // We're definitely playing now
294 pthread_cond_broadcast( &this->audio_cond
);
295 pthread_mutex_unlock( &this->audio_mutex
);
298 static int consumer_play_audio( consumer_sdl
this, mlt_frame frame
, int init_audio
, int *duration
)
300 // Get the properties of this consumer
301 mlt_properties properties
= this->properties
;
302 mlt_audio_format afmt
= mlt_audio_pcm
;
304 // Set the preferred params of the test card signal
305 int channels
= mlt_properties_get_int( properties
, "channels" );
306 int frequency
= mlt_properties_get_int( properties
, "frequency" );
307 static int counter
= 0;
309 int samples
= mlt_sample_calculator( mlt_properties_get_double( this->properties
, "fps" ), frequency
, counter
++ );
314 mlt_frame_get_audio( frame
, &pcm
, &afmt
, &frequency
, &channels
, &samples
);
315 *duration
= ( ( samples
* 1000 ) / frequency
);
317 if ( mlt_properties_get_int( properties
, "audio_off" ) )
324 if ( init_audio
== 1 )
326 SDL_AudioSpec request
;
329 int audio_buffer
= mlt_properties_get_int( properties
, "audio_buffer" );
331 // specify audio format
332 memset( &request
, 0, sizeof( SDL_AudioSpec
) );
334 request
.freq
= frequency
;
335 request
.format
= AUDIO_S16
;
336 request
.channels
= channels
;
337 request
.samples
= audio_buffer
;
338 request
.callback
= sdl_fill_audio
;
339 request
.userdata
= (void *)this;
340 if ( SDL_OpenAudio( &request
, &got
) != 0 )
342 fprintf( stderr
, "SDL failed to open audio: %s\n", SDL_GetError() );
345 else if ( got
.size
!= 0 )
352 if ( init_audio
== 0 )
354 mlt_properties properties
= MLT_FRAME_PROPERTIES( frame
);
355 bytes
= ( samples
* channels
* 2 );
356 pthread_mutex_lock( &this->audio_mutex
);
357 while ( this->running
&& bytes
> ( sizeof( this->audio_buffer
) - this->audio_avail
) )
358 pthread_cond_wait( &this->audio_cond
, &this->audio_mutex
);
361 if ( mlt_properties_get_double( properties
, "_speed" ) == 1 )
362 memcpy( &this->audio_buffer
[ this->audio_avail
], pcm
, bytes
);
364 memset( &this->audio_buffer
[ this->audio_avail
], 0, bytes
);
365 this->audio_avail
+= bytes
;
367 pthread_cond_broadcast( &this->audio_cond
);
368 pthread_mutex_unlock( &this->audio_mutex
);
378 static int consumer_play_video( consumer_sdl
this, mlt_frame frame
)
380 // Get the properties of this consumer
381 mlt_properties properties
= this->properties
;
383 mlt_image_format vfmt
= mlt_image_yuv422
;
384 int width
= this->width
, height
= this->height
;
388 if ( this->running
&& mlt_properties_get_int( properties
, "video_off" ) == 0 )
390 // Get the image, width and height
391 mlt_events_fire( properties
, "consumer-frame-show", frame
, NULL
);
392 mlt_frame_get_image( frame
, &image
, &vfmt
, &width
, &height
, 0 );
395 if ( this->sdl_screen
!= NULL
)
399 changed
= consumer_get_dimensions( &this->window_width
, &this->window_height
);
401 while ( SDL_PollEvent( &event
) )
403 mlt_events_fire( this->properties
, "consumer-sdl-event", &event
, NULL
);
407 case SDL_VIDEORESIZE
:
408 this->window_width
= event
.resize
.w
;
409 this->window_height
= event
.resize
.h
;
417 mlt_producer producer
= mlt_properties_get_data( properties
, "transport_producer", NULL
);
418 char keyboard
[ 2 ] = " ";
419 void (*callback
)( mlt_producer
, char * ) = mlt_properties_get_data( properties
, "transport_callback", NULL
);
420 if ( callback
!= NULL
&& producer
!= NULL
&& event
.key
.keysym
.unicode
< 0x80 && event
.key
.keysym
.unicode
> 0 )
422 keyboard
[ 0 ] = ( char )event
.key
.keysym
.unicode
;
423 callback( producer
, keyboard
);
431 if ( width
!= this->width
|| height
!= this->height
)
433 if ( this->sdl_overlay
!= NULL
)
434 SDL_FreeYUVOverlay( this->sdl_overlay
);
435 this->sdl_overlay
= NULL
;
438 if ( this->running
&& ( this->sdl_screen
== NULL
|| changed
) )
440 // Force an overlay recreation
441 if ( this->sdl_overlay
!= NULL
)
442 SDL_FreeYUVOverlay( this->sdl_overlay
);
443 this->sdl_overlay
= NULL
;
445 // open SDL window with video overlay, if possible
447 this->sdl_screen
= SDL_SetVideoMode( this->window_width
, this->window_height
, this->bpp
, this->sdl_flags
);
448 sdl_unlock_display();
449 if ( consumer_get_dimensions( &this->window_width
, &this->window_height
) )
450 this->sdl_screen
= SDL_SetVideoMode( this->window_width
, this->window_height
, this->bpp
, this->sdl_flags
);
451 //SDL_Flip( this->sdl_screen );
452 mlt_properties_set_int( properties
, "changed", 0 );
454 else if ( mlt_properties_get_int( properties
, "changed" ) )
457 this->sdl_screen
= SDL_SetVideoMode( this->window_width
, this->window_height
, this->bpp
, this->sdl_flags
);
458 SDL_SetClipRect( this->sdl_screen
, &this->rect
);
459 sdl_unlock_display();
460 mlt_properties_set_int( properties
, "changed", 0 );
465 // Determine window's new display aspect ratio
466 double this_aspect
= ( double )this->window_width
/ this->window_height
;
468 // Get the display aspect ratio
469 double display_ratio
= mlt_properties_get_double( properties
, "display_ratio" );
471 // Determine frame's display aspect ratio
472 double frame_aspect
= mlt_frame_get_aspect_ratio( frame
) * width
/ height
;
474 // Store the width and height received
476 this->height
= height
;
478 // If using hardware scaler
479 if ( mlt_properties_get( properties
, "rescale" ) != NULL
&&
480 !strcmp( mlt_properties_get( properties
, "rescale" ), "none" ) )
482 // Use hardware scaler to normalise display aspect ratio
483 this->rect
.w
= frame_aspect
/ this_aspect
* this->window_width
;
484 this->rect
.h
= this->window_height
;
485 if ( this->rect
.w
> this->window_width
)
487 this->rect
.w
= this->window_width
;
488 this->rect
.h
= this_aspect
/ frame_aspect
* this->window_height
;
491 // Special case optimisation to negate odd effect of sample aspect ratio
492 // not corresponding exactly with image resolution.
493 else if ( (int)( this_aspect
* 1000 ) == (int)( display_ratio
* 1000 ) )
495 this->rect
.w
= this->window_width
;
496 this->rect
.h
= this->window_height
;
498 // Use hardware scaler to normalise sample aspect ratio
499 else if ( this->window_height
* display_ratio
> this->window_width
)
501 this->rect
.w
= this->window_width
;
502 this->rect
.h
= this->window_width
/ display_ratio
;
506 this->rect
.w
= this->window_height
* display_ratio
;
507 this->rect
.h
= this->window_height
;
510 this->rect
.x
= ( this->window_width
- this->rect
.w
) / 2;
511 this->rect
.y
= ( this->window_height
- this->rect
.h
) / 2;
513 mlt_properties_set_int( this->properties
, "rect_x", this->rect
.x
);
514 mlt_properties_set_int( this->properties
, "rect_y", this->rect
.y
);
515 mlt_properties_set_int( this->properties
, "rect_w", this->rect
.w
);
516 mlt_properties_set_int( this->properties
, "rect_h", this->rect
.h
);
518 SDL_SetClipRect( this->sdl_screen
, &this->rect
);
521 if ( this->running
&& this->sdl_screen
!= NULL
&& this->sdl_overlay
== NULL
)
523 SDL_SetClipRect( this->sdl_screen
, &this->rect
);
524 SDL_Flip( this->sdl_screen
);
526 this->sdl_overlay
= SDL_CreateYUVOverlay( width
, height
, SDL_YUY2_OVERLAY
, this->sdl_screen
);
527 sdl_unlock_display();
530 if ( this->running
&& this->sdl_screen
!= NULL
&& this->sdl_overlay
!= NULL
)
532 this->buffer
= this->sdl_overlay
->pixels
[ 0 ];
534 if ( SDL_LockYUVOverlay( this->sdl_overlay
) >= 0 )
537 memcpy( this->buffer
, image
, width
* height
* 2 );
538 SDL_UnlockYUVOverlay( this->sdl_overlay
);
539 SDL_DisplayYUVOverlay( this->sdl_overlay
, &this->sdl_screen
->clip_rect
);
541 sdl_unlock_display();
548 static void *video_thread( void *arg
)
551 consumer_sdl
this = arg
;
554 NSAutoreleasePool
*pool
= [[NSAutoreleasePool alloc
] init
];
557 // Obtain time of thread start
562 mlt_frame next
= NULL
;
563 mlt_properties properties
= NULL
;
566 // Get real time flag
567 int real_time
= mlt_properties_get_int( this->properties
, "real_time" );
569 // Get the current time
570 gettimeofday( &now
, NULL
);
572 // Determine start time
573 start
= ( int64_t )now
.tv_sec
* 1000000 + now
.tv_usec
;
575 while ( this->running
)
577 // Pop the next frame
578 pthread_mutex_lock( &this->video_mutex
);
579 next
= mlt_deque_pop_front( this->queue
);
580 while ( next
== NULL
&& this->running
)
582 pthread_cond_wait( &this->video_cond
, &this->video_mutex
);
583 next
= mlt_deque_pop_front( this->queue
);
585 pthread_mutex_unlock( &this->video_mutex
);
587 if ( !this->running
|| next
== NULL
) break;
589 // Get the properties
590 properties
= MLT_FRAME_PROPERTIES( next
);
592 // Get the speed of the frame
593 speed
= mlt_properties_get_double( properties
, "_speed" );
595 // Get the current time
596 gettimeofday( &now
, NULL
);
598 // Get the elapsed time
599 elapsed
= ( ( int64_t )now
.tv_sec
* 1000000 + now
.tv_usec
) - start
;
601 // See if we have to delay the display of the current frame
602 if ( mlt_properties_get_int( properties
, "rendered" ) == 1 && this->running
)
604 // Obtain the scheduled playout time
605 mlt_position scheduled
= mlt_properties_get_position( properties
, "playtime" );
607 // Determine the difference between the elapsed time and the scheduled playout time
608 mlt_position difference
= scheduled
- elapsed
;
610 // Smooth playback a bit
611 if ( real_time
&& ( difference
> 20000 && speed
== 1.0 ) )
613 tm
.tv_sec
= difference
/ 1000000;
614 tm
.tv_nsec
= ( difference
% 1000000 ) * 500;
615 nanosleep( &tm
, NULL
);
618 // Show current frame if not too old
619 if ( !real_time
|| ( difference
> -10000 || speed
!= 1.0 || mlt_deque_count( this->queue
) < 2 ) )
620 consumer_play_video( this, next
);
622 // If the queue is empty, recalculate start to allow build up again
623 if ( real_time
&& ( mlt_deque_count( this->queue
) == 0 && speed
== 1.0 ) )
625 gettimeofday( &now
, NULL
);
626 start
= ( ( int64_t )now
.tv_sec
* 1000000 + now
.tv_usec
) - scheduled
+ 20000;
630 // This frame can now be closed
631 mlt_frame_close( next
);
636 mlt_frame_close( next
);
638 mlt_consumer_stopped( &this->parent
);
647 /** Threaded wrapper for pipe.
650 static void *consumer_thread( void *arg
)
653 consumer_sdl
this = arg
;
656 NSAutoreleasePool
*pool
= [[NSAutoreleasePool alloc
] init
];
660 mlt_consumer consumer
= &this->parent
;
665 // internal intialization
668 mlt_frame frame
= NULL
;
669 mlt_properties properties
= NULL
;
671 int64_t playtime
= 0;
672 struct timespec tm
= { 0, 100000 };
674 this->bpp
= mlt_properties_get_int( this->properties
, "bpp" );
676 if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer
), "sdl_started" ) == 0 )
678 if ( SDL_Init( SDL_INIT_VIDEO
| SDL_INIT_NOPARACHUTE
) < 0 )
680 fprintf( stderr
, "Failed to initialize SDL: %s\n", SDL_GetError() );
684 SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY
, SDL_DEFAULT_REPEAT_INTERVAL
);
685 SDL_EnableUNICODE( 1 );
689 if ( SDL_GetVideoSurface( ) != NULL
)
691 this->sdl_screen
= SDL_GetVideoSurface( );
692 consumer_get_dimensions( &this->window_width
, &this->window_height
);
693 mlt_properties_set_int( this->properties
, "changed", 0 );
697 if ( !mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer
), "audio_off" ) )
698 SDL_InitSubSystem( SDL_INIT_AUDIO
);
700 // Loop until told not to
701 while( this->running
)
703 // Get a frame from the attached producer
704 frame
= mlt_consumer_rt_frame( consumer
);
706 // Ensure that we have a frame
709 // Get the frame properties
710 properties
= MLT_FRAME_PROPERTIES( frame
);
713 init_audio
= consumer_play_audio( this, frame
, init_audio
, &duration
);
715 // Determine the start time now
716 if ( this->playing
&& init_video
)
718 // Create the video thread
719 pthread_create( &thread
, NULL
, video_thread
, this );
721 // Video doesn't need to be initialised any more
725 // Set playtime for this frame
726 mlt_properties_set_position( properties
, "playtime", playtime
);
728 while ( this->running
&& mlt_deque_count( this->queue
) > 15 )
729 nanosleep( &tm
, NULL
);
731 // Push this frame to the back of the queue
732 pthread_mutex_lock( &this->video_mutex
);
733 mlt_deque_push_back( this->queue
, frame
);
734 pthread_cond_broadcast( &this->video_cond
);
735 pthread_mutex_unlock( &this->video_mutex
);
737 // Calculate the next playtime
738 playtime
+= ( duration
* 1000 );
742 // Kill the video thread
743 if ( init_video
== 0 )
745 pthread_mutex_lock( &this->video_mutex
);
746 pthread_cond_broadcast( &this->video_cond
);
747 pthread_mutex_unlock( &this->video_mutex
);
748 pthread_join( thread
, NULL
);
752 if ( this->sdl_overlay
!= NULL
)
753 SDL_FreeYUVOverlay( this->sdl_overlay
);
755 if ( !mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer
), "audio_off" ) )
756 SDL_QuitSubSystem( SDL_INIT_AUDIO
);
758 //if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "sdl_started" ) == 0 )
761 while( mlt_deque_count( this->queue
) )
762 mlt_frame_close( mlt_deque_pop_back( this->queue
) );
764 this->sdl_screen
= NULL
;
765 this->sdl_overlay
= NULL
;
766 this->audio_avail
= 0;
775 static int consumer_get_dimensions( int *width
, int *height
)
779 // SDL windows manager structure
782 // Specify the SDL Version
783 SDL_VERSION( &wm
.version
);
789 // Get the wm structure
790 if ( SDL_GetWMInfo( &wm
) == 1 )
792 // Check that we have the X11 wm
793 if ( wm
.subsystem
== SDL_SYSWM_X11
)
795 // Get the SDL window
796 Window window
= wm
.info
.x11
.window
;
798 // Get the display session
799 Display
*display
= wm
.info
.x11
.display
;
801 // Get the window attributes
802 XWindowAttributes attr
;
803 XGetWindowAttributes( display
, window
, &attr
);
805 // Determine whether window has changed
806 changed
= *width
!= attr
.width
|| *height
!= attr
.height
;
808 // Return width and height
810 *height
= attr
.height
;
815 // Unlock the display
821 /** Callback to allow override of the close method.
824 static void consumer_close( mlt_consumer parent
)
826 // Get the actual object
827 consumer_sdl
this = parent
->child
;
830 ///mlt_consumer_stop( parent );
832 // Now clean up the rest
833 mlt_consumer_close( parent
);
836 mlt_deque_close( this->queue
);
839 pthread_mutex_destroy( &this->audio_mutex
);
840 pthread_cond_destroy( &this->audio_cond
);
842 // Finally clean up this