#include <SDL/SDL_syswm.h>
#include <sys/time.h>
+#ifdef __DARWIN__
+# include "consumer_sdl_osx_hack.h"
+# import <AppKit/NSApplication.h>
+# import <Foundation/Foundation.h>
+#endif
+
+
/** This classes definition.
*/
mlt_consumer consumer_sdl_init( char *arg )
{
+#ifdef __DARWIN__
+ // Initialize Cocoa
+ NSApplicationLoad();
+ [NSApplication sharedApplication];
+
+ // Spawn a fake thread so that cocoa knows to be multithreaded
+ DummyThread *dummy = [[DummyThread alloc] init];
+ [NSThread detachNewThreadSelector:@selector(startThread:) toTarget:dummy withObject:nil];
+#endif
+
// Create the consumer object
consumer_sdl this = calloc( sizeof( struct consumer_sdl_s ), 1 );
if ( !this->running )
{
- pthread_attr_t thread_attributes;
-
consumer_stop( parent );
this->running = 1;
mlt_properties_set_int( this->properties, "height", this->height );
}
- // Inherit the scheduling priority
- pthread_attr_init( &thread_attributes );
- pthread_attr_setinheritsched( &thread_attributes, PTHREAD_INHERIT_SCHED );
-
- pthread_create( &this->thread, &thread_attributes, consumer_thread, this );
+ pthread_create( &this->thread, NULL, consumer_thread, this );
}
return 0;
if ( this->joined == 0 )
{
// Kill the thread and clean up
+ this->joined = 1;
this->running = 0;
-
- pthread_mutex_lock( &this->audio_mutex );
- pthread_cond_broadcast( &this->audio_cond );
- pthread_mutex_unlock( &this->audio_mutex );
-
pthread_join( this->thread, NULL );
- this->joined = 1;
}
return 0;
uint8_t *image;
int changed = 0;
- if ( mlt_properties_get_int( properties, "video_off" ) == 0 )
+ if ( this->running && mlt_properties_get_int( properties, "video_off" ) == 0 )
{
// Get the image, width and height
mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
mlt_properties_set_int( properties, "changed", 0 );
}
- if ( 1 )
+ if ( this->running )
{
// Determine window's new display aspect ratio
float this_aspect = ( float )this->window_width / this->window_height;
SDL_SetClipRect( this->sdl_screen, &this->rect );
}
- if ( this->sdl_screen != NULL && this->sdl_overlay == NULL )
+ if ( this->running && this->sdl_screen != NULL && this->sdl_overlay == NULL )
{
SDL_SetClipRect( this->sdl_screen, &this->rect );
SDL_Flip( this->sdl_screen );
sdl_unlock_display();
}
- if ( this->sdl_screen != NULL && this->sdl_overlay != NULL )
+ if ( this->running && this->sdl_screen != NULL && this->sdl_overlay != NULL )
{
this->buffer = this->sdl_overlay->pixels[ 0 ];
sdl_lock_display();
// Identify the arg
consumer_sdl this = arg;
+#ifdef __DARWIN__
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
+
// Obtain time of thread start
struct timeval now;
int64_t start = 0;
{
// Pop the next frame
pthread_mutex_lock( &this->video_mutex );
- while ( ( next = mlt_deque_pop_front( this->queue ) ) == NULL && this->running )
+ next = mlt_deque_pop_front( this->queue );
+ while ( next == NULL && this->running )
+ {
pthread_cond_wait( &this->video_cond, &this->video_mutex );
+ next = mlt_deque_pop_front( this->queue );
+ }
pthread_mutex_unlock( &this->video_mutex );
+ if ( !this->running || next == NULL ) break;
+
// Get the properties
properties = MLT_FRAME_PROPERTIES( next );
// This frame can now be closed
mlt_frame_close( next );
+ next = NULL;
}
+ if ( next != NULL )
+ mlt_frame_close( next );
+
mlt_consumer_stopped( &this->parent );
+#ifdef __DARWIN__
+ [pool release];
+#endif
+
return NULL;
}
// Identify the arg
consumer_sdl this = arg;
+#ifdef __DARWIN__
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#endif
+
// Get the consumer
mlt_consumer consumer = &this->parent;
if ( !mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "audio_off" ) )
SDL_QuitSubSystem( SDL_INIT_AUDIO );
- if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "sdl_started" ) == 0 )
- SDL_Quit( );
+ //if ( mlt_properties_get_int( MLT_CONSUMER_PROPERTIES( consumer ), "sdl_started" ) == 0 )
+ //SDL_Quit( );
while( mlt_deque_count( this->queue ) )
mlt_frame_close( mlt_deque_pop_back( this->queue ) );
this->sdl_overlay = NULL;
this->audio_avail = 0;
+#ifdef __DARWIN__
+ [pool release];
+#endif
+
return NULL;
}
// Lock the display
sdl_lock_display();
+#ifndef __DARWIN__
// Get the wm structure
if ( SDL_GetWMInfo( &wm ) == 1 )
{
*height = attr.height;
}
}
+#endif
// Unlock the display
sdl_lock_display();
consumer_sdl this = parent->child;
// Stop the consumer
- mlt_consumer_stop( parent );
+ ///mlt_consumer_stop( parent );
+
+ // Now clean up the rest
+ mlt_consumer_close( parent );
// Close the queue
mlt_deque_close( this->queue );
pthread_mutex_destroy( &this->audio_mutex );
pthread_cond_destroy( &this->audio_cond );
- // Now clean up the rest
- mlt_consumer_close( parent );
-
// Finally clean up this
free( this );
}