Commit 4ead3936 authored by jehan's avatar jehan

add cocoa binding for pcap player

parent 403fda44
...@@ -65,9 +65,14 @@ if(LINK_FLAGS_STR) ...@@ -65,9 +65,14 @@ if(LINK_FLAGS_STR)
endif() endif()
if(PCAP_FOUND) if(PCAP_FOUND)
if(APPLE AND NOT IOS)
set(SOURCE_FILES_OBJC pcap_player_cocoa.m)
endif()
bc_apply_compile_flags(SOURCE_FILES_OBJC STRICT_OPTIONS_CPP STRICT_OPTIONS_OBJC)
set(PCAP_PLAYBACK_SOURCE_FILES pcap_playback.c common.c) set(PCAP_PLAYBACK_SOURCE_FILES pcap_playback.c common.c)
bc_apply_compile_flags(PCAP_PLAYBACK_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_C) bc_apply_compile_flags(PCAP_PLAYBACK_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
add_executable(pcap_playback ${USE_BUNDLE} ${PCAP_PLAYBACK_SOURCE_FILES}) add_executable(pcap_playback ${USE_BUNDLE} ${PCAP_PLAYBACK_SOURCE_FILES} ${SOURCE_FILES_OBJC})
target_link_libraries(pcap_playback ${MS2_LIBS_FOR_TOOLS} ${ORTP_LIBRARIES} ${PCAP_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES}) target_link_libraries(pcap_playback ${MS2_LIBS_FOR_TOOLS} ${ORTP_LIBRARIES} ${PCAP_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES})
target_include_directories(pcap_playback PUBLIC ${PCAP_INCLUDE_DIRS}) target_include_directories(pcap_playback PUBLIC ${PCAP_INCLUDE_DIRS})
if(LINK_FLAGS_STR) if(LINK_FLAGS_STR)
......
...@@ -72,15 +72,15 @@ typedef struct _MediastreamDatas { ...@@ -72,15 +72,15 @@ typedef struct _MediastreamDatas {
// MAIN METHODS // MAIN METHODS
/* init default arguments */ /* init default arguments */
static MediastreamDatas *init_default_args(void); MediastreamDatas *init_default_args(void);
/* parse args */ /* parse args */
static bool_t parse_args(int argc, char **argv, MediastreamDatas *out); bool_t parse_args(int argc, char **argv, MediastreamDatas *out);
/* setup streams */ /* setup streams */
static void setup_media_streams(MediastreamDatas *args); void setup_media_streams(MediastreamDatas *args);
/* run loop */ /* run loop */
static void run_non_interactive_loop(MediastreamDatas *args); void run_non_interactive_loop(MediastreamDatas *args);
/* exit */ /* exit */
static void clear_mediastreams(MediastreamDatas *args); void clear_mediastreams(MediastreamDatas *args);
// HELPER METHODS // HELPER METHODS
static void stop_handler(int signum); static void stop_handler(int signum);
...@@ -94,7 +94,7 @@ const char *usage = "pcap_playback --infile <pcapfile>\n" ...@@ -94,7 +94,7 @@ const char *usage = "pcap_playback --infile <pcapfile>\n"
"This tool directly renders a pcap file to soundcard or screen (for video), using mediastreamer2 filters.\n" "This tool directly renders a pcap file to soundcard or screen (for video), using mediastreamer2 filters.\n"
; ;
#if !TARGET_OS_MAC
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
MediastreamDatas *args; MediastreamDatas *args;
...@@ -115,9 +115,9 @@ int main(int argc, char *argv[]) ...@@ -115,9 +115,9 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
#endif
MediastreamDatas *init_default_args(void)
static MediastreamDatas *init_default_args(void)
{ {
MediastreamDatas *args = (MediastreamDatas *) ms_malloc0(sizeof(MediastreamDatas)); MediastreamDatas *args = (MediastreamDatas *) ms_malloc0(sizeof(MediastreamDatas));
...@@ -136,7 +136,7 @@ static MediastreamDatas *init_default_args(void) ...@@ -136,7 +136,7 @@ static MediastreamDatas *init_default_args(void)
return args; return args;
} }
static bool_t parse_args(int argc, char **argv, MediastreamDatas *out) bool_t parse_args(int argc, char **argv, MediastreamDatas *out)
{ {
int i; int i;
...@@ -239,7 +239,7 @@ static void configure_resampler(MSFilter *resampler,MSFilter *from, MSFilter *to ...@@ -239,7 +239,7 @@ static void configure_resampler(MSFilter *resampler,MSFilter *from, MSFilter *to
from->desc->name, from, to->desc->name, to, from_rate, to_rate, from_channels, to_channels); from->desc->name, from, to->desc->name, to, from_rate, to_rate, from_channels, to_channels);
} }
static void setup_media_streams(MediastreamDatas *args) { void setup_media_streams(MediastreamDatas *args) {
MSConnectionHelper h; MSConnectionHelper h;
MSTickerParams params = {0}; MSTickerParams params = {0};
MSPCAPFilePlayerLayer layer = MSPCAPFilePlayerLayerPayload; MSPCAPFilePlayerLayer layer = MSPCAPFilePlayerLayerPayload;
...@@ -389,7 +389,7 @@ static void setup_media_streams(MediastreamDatas *args) { ...@@ -389,7 +389,7 @@ static void setup_media_streams(MediastreamDatas *args) {
} }
static void run_non_interactive_loop(MediastreamDatas *args) void run_non_interactive_loop(MediastreamDatas *args)
{ {
while (cond) { while (cond) {
int n; int n;
...@@ -411,7 +411,7 @@ static void run_non_interactive_loop(MediastreamDatas *args) ...@@ -411,7 +411,7 @@ static void run_non_interactive_loop(MediastreamDatas *args)
} }
} }
static void clear_mediastreams(MediastreamDatas *args) void clear_mediastreams(MediastreamDatas *args)
{ {
MSConnectionHelper h; MSConnectionHelper h;
......
#import <Carbon/Carbon.h>
#import <AppKit/AppKit.h>
struct _MediastreamDatas;
typedef struct _MediastreamDatas MediastreamDatas;
extern const char * usage;
extern MediastreamDatas* init_default_args();
extern BOOL parse_args(int argc, char** argv, MediastreamDatas* args);
extern void setup_media_streams(MediastreamDatas* args);
extern void run_non_interactive_loop(MediastreamDatas *args);
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);
run_non_interactive_loop(args);
clear_mediastreams(args);
exit(0);
}
-(void)applicationWillFinishLaunching: (NSNotification*) aNotification
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
[self run_mediastreamer_loop];
});
}
-(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);
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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment