mediastream_cocoa.m 2.14 KB
Newer Older
1 2 3 4 5 6
#import <Carbon/Carbon.h>
#import <AppKit/AppKit.h>

struct _MediastreamDatas;
typedef struct _MediastreamDatas MediastreamDatas;

7
extern const char * usage;
8
extern MediastreamDatas* init_default_args();
9
extern BOOL parse_args(int argc, char** argv, MediastreamDatas* args);
10
extern void setup_media_streams(MediastreamDatas* args);
11
extern void mediastream_run_loop(MediastreamDatas* args);
12 13 14 15
extern void clear_mediastreams(MediastreamDatas* args);

@interface MyApplicationDelegate: NSObject
{
16 17
	NSWindow *window;
	MediastreamDatas* args;
18 19 20 21 22 23 24 25 26 27
}
-(void)registerArgs:(MediastreamDatas*) args;
-(void)applicationWillFinishLaunching: (NSNotification*) aNotification;
-(void)applicationDidFinishLaunching: (NSNotification*) aNotification;
-(BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSApplication *)theApplication;
@end

@implementation MyApplicationDelegate

-(void)registerArgs:(MediastreamDatas*) a {
28
	args = a;
29 30 31
}

-(void) run_mediastreamer_loop {
32 33
	setup_media_streams(args);
	mediastream_run_loop(args);
jehan's avatar
jehan committed
34 35
	clear_mediastreams(args);
	exit(0);
36 37 38 39
}

-(void)applicationWillFinishLaunching: (NSNotification*) aNotification
{
40
	dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
41 42
		[self run_mediastreamer_loop];
	});
43 44 45 46 47 48 49 50
}

-(void)applicationDidFinishLaunching: (NSNotification*) aNotification
{
}

-(BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSApplication *)theApplication
{
51
	return YES;
52 53 54 55
}

-(void)dealloc
{
56 57
	[window release];
	[super dealloc];
58 59 60 61 62
}
@end

int main(int argc, char **argv)
{
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
	MediastreamDatas* args = init_default_args();
	if (!parse_args(argc, argv, args)) {
		NSLog(@"Arguments parsing fail (argc=%d)", argc);
		NSLog(@"%s\n", usage);
		exit(-1);
	}


	static const ProcessSerialNumber thePSN = { 0, kCurrentProcess };
	TransformProcessType(&thePSN, kProcessTransformToForegroundApplication);
	SetFrontProcess(&thePSN);
	NSAutoreleasePool *aPool = [[NSAutoreleasePool alloc] init];
	[NSApplication sharedApplication];
	MyApplicationDelegate *aMyApplicationDelegate = [[MyApplicationDelegate alloc] init];
	[aMyApplicationDelegate registerArgs:args];
	[NSApp setDelegate: aMyApplicationDelegate];
	[aPool release];
	[NSApp run];
	return 0;
82
}