//****************************************************************** //** //** M A I N //** //****************************************************************** int main(int argc, char* argv[]) { gnsdk_error_t error = 0; gnsdk_cstr_t client_id = GNSDK_NULL; gnsdk_cstr_t client_id_tag = GNSDK_NULL; gnsdk_cstr_t license_path = GNSDK_NULL; gnsdk_manager_handle_t sdkmgr_handle = GNSDK_NULL; //** Display SDK Versions printf("\ngnsdk_manager: v%s \t(built %s)\n", gnsdk_manager_get_version(), gnsdk_manager_get_build_date()); printf( "gnsdk_musicid: v%s \t(built %s)\n\n", gnsdk_musicid_get_version(), gnsdk_musicid_get_build_date()); //** Client ID and License file must be passed in if (argc < 4) { printf("usage:\n\n\t\tsample.exe clientid clientidtag license\n"); return -1; } client_id = argv[1]; client_id_tag = argv[2]; license_path = argv[3]; //** Initialize SDK Manager - get handle error = gnsdk_manager_initialize(&sdkmgr_handle, license_path, GNSDK_MANAGER_LICENSEDATA_FILENAME); error = init_musicid(); error = init_musicid_file(); shutdown_all(); return 0; } //** main()
void shutdown_application(int32_t exit_code) { shutdown_all(wiimote); #if HAVE_GTK shutdown_gui(); #endif exit(exit_code); }
int main(int argc, char *argv[]) { int ret; char* dev = NULL; char errbuf[PCAP_ERRBUF_SIZE]; struct bpf_program comp_filter_exp; /** The compiled filter expression */ char filter_exp[] = "ether dst 91:E0:F0:00:0e:80"; /** The filter expression */ struct pcap_pkthdr header; /** header pcap gives us */ const u_char* packet; /** actual packet */ signal(SIGINT, shutdown_all); int c; while((c = getopt(argc, argv, "hi:")) > 0) { switch (c) { case 'h': help(); break; case 'i': dev = strdup(optarg); break; default: fprintf(stderr, "Unrecognized option!\n"); } } if (NULL == dev) { help(); } if (create_socket()) { fprintf(stderr, "Socket creation failed.\n"); return (errno); } send_process('D'); /** report domain status */ init_jack(); fprintf(stdout,"Waiting for talker...\n"); await_talker(); send_process('R'); /** send_ready */ #ifdef LIBSND char* filename = "listener.wav"; SF_INFO* sf_info = (SF_INFO*)malloc(sizeof(SF_INFO)); memset(sf_info, 0, sizeof(SF_INFO)); sf_info->samplerate = SAMPLES_PER_SECOND; sf_info->channels = CHANNELS; sf_info->format = SF_FORMAT_WAV | SF_FORMAT_PCM_24; if (0 == sf_format_check(sf_info)) { fprintf(stderr, "Wrong format.\n"); shutdown_all(0); return -1; } if (NULL == (snd_file = sf_open(filename, SFM_WRITE, sf_info))) { fprintf(stderr, "Could not create file %s.\n", filename); shutdown_all(0); return -1; } #endif /** session, get session handler */ handle = pcap_open_live(dev, BUFSIZ, 1, -1, errbuf); if (NULL == handle) { fprintf(stderr, "Could not open device %s: %s.\n", dev, errbuf); shutdown_all(0); return -1; } /** compile and apply filter */ if (-1 == pcap_compile(handle, &comp_filter_exp, filter_exp, 0, PCAP_NETMASK_UNKNOWN)) { fprintf(stderr, "Could not parse filter %s: %s.\n", filter_exp, pcap_geterr(handle)); shutdown_all(0); return -1; } if (-1 == pcap_setfilter(handle, &comp_filter_exp)) { fprintf(stderr, "Could not install filter %s: %s.\n", filter_exp, pcap_geterr(handle)); shutdown_all(0); return -1; } /** loop forever and call callback-function for every received packet */ pcap_loop(handle, -1, pcap_callback, NULL); usleep(-1); return 0; }
jack_client_t* init_jack(void) { const char* client_name = "simple_listener"; const char* server_name = NULL; jack_options_t options = JackNullOption; jack_status_t status; client = jack_client_open (client_name, options, &status, server_name); if (NULL == client) { fprintf (stderr, "jack_client_open() failed\n "); shutdown_all(0); exit (1); } if (status & JackServerStarted) { fprintf (stderr, "JACK server started\n"); } if (status & JackNameNotUnique) { client_name = jack_get_client_name(client); fprintf (stderr, "unique name `%s' assigned\n", client_name); } jack_set_process_callback(client, process_jack, 0); jack_on_shutdown(client, jack_shutdown, 0); outputports = (jack_port_t**) malloc (CHANNELS * sizeof (jack_port_t*)); out = (jack_default_audio_sample_t**) malloc (CHANNELS * sizeof (jack_default_audio_sample_t*)); ringbuffer = jack_ringbuffer_create (SAMPLE_SIZE * DEFAULT_RINGBUFFER_SIZE * CHANNELS); jack_ringbuffer_mlock(ringbuffer); memset(out, 0, sizeof (jack_default_audio_sample_t*)*CHANNELS); memset(ringbuffer->buf, 0, ringbuffer->size); for(int i = 0; i < CHANNELS; i++) { char* portName; if (asprintf(&portName, "output%d", i) < 0) { fprintf(stderr, "could not create portname for port %d\n", i); shutdown_all(0); exit(1); } outputports[i] = jack_port_register (client, portName, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if (NULL == outputports[i]) { fprintf (stderr, "cannot register output port \"%d\"!\n", i); shutdown_all(0); exit (1); } } const char** ports; if (jack_activate (client)) { fprintf (stderr, "cannot activate client\n"); shutdown_all(0); exit(1); } ports = jack_get_ports(client, NULL, NULL, JackPortIsPhysical|JackPortIsInput); if(NULL == ports) { fprintf (stderr, "no physical playback ports\n"); shutdown_all(0); exit(1); } int i = 0; while(i < CHANNELS && NULL != ports[i]) { if (jack_connect(client, jack_port_name(outputports[i]), ports[i])) fprintf (stderr, "cannot connect output ports\n"); i++; } free(ports); }
void jack_shutdown(void* arg) { printf("JACK shutdown\n"); shutdown_all(0); }