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

struct _MediastreamDatas;
typedef struct _MediastreamDatas MediastreamDatas;

extern MediastreamDatas* init_default_args();
extern BOOL parse_args(int argc, char** argv, MediastreamDatas* plop);
extern void setup_media_streams(MediastreamDatas* args);
10
extern void mediastream_run_loop(MediastreamDatas* args);
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
extern void clear_mediastreams(MediastreamDatas* args);

@interface MyApplicationDelegate: NSObject
{
    NSWindow *window;
    MediastreamDatas* args;
}
-(void)registerArgs:(MediastreamDatas*) args;
-(void)applicationWillFinishLaunching: (NSNotification*) aNotification;
-(void)applicationDidFinishLaunching: (NSNotification*) aNotification;
-(BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSApplication *)theApplication;
@end

@implementation MyApplicationDelegate

-(void)registerArgs:(MediastreamDatas*) a {
    args = a;
}

-(void) run_mediastreamer_loop {
    setup_media_streams(args);
32
    mediastream_run_loop(args);
jehan's avatar
jehan committed
33 34
	clear_mediastreams(args);
	exit(0);
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
}

-(void)applicationWillFinishLaunching: (NSNotification*) aNotification
{
    [self performSelectorInBackground:@selector(run_mediastreamer_loop) withObject:nil];
}

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

-(BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSApplication *)theApplication
{
    return YES;
}

-(void)dealloc
{
    [window release];
    [super dealloc];
}
@end

int main(int argc, char **argv)
{
    MediastreamDatas* args = init_default_args();
    if (!parse_args(argc, argv, args)) {
        NSLog(@"Arguments parsing fail (argc=%d)", argc);
        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;
}