int *init_ais_decoder(char * host, char * port ,int show_levels,int _debug_nmea,int buf_len,int time_print_stats){ debug_nmea=_debug_nmea; if(debug_nmea) fprintf(stderr,"Log NMEA sentences to console ON\n"); else fprintf(stderr,"Log NMEA sentences to console OFF\n"); if (!initSocket(host, port)) { return EXIT_FAILURE; } if (show_levels) on_sound_level_changed=sound_level_changed; on_nmea_sentence_received=nmea_sentence_received; initSoundDecoder(buf_len,time_print_stats); return 0; }
int init_ais_decoder(char * host, char * port ,int show_levels,int _debug_nmea,int buf_len,int time_print_stats, int use_tcp_listener, int tcp_keep_ais_time){ debug_nmea=_debug_nmea; use_tcp = use_tcp_listener; pthread_mutex_init(&message_mutex, NULL); if(debug_nmea) fprintf(stderr,"Log NMEA sentences to console ON\n"); else fprintf(stderr,"Log NMEA sentences to console OFF\n"); if( !use_tcp_listener) { if (host && port && !initSocket(host, port)) { return EXIT_FAILURE; } } else { if (!initTcpSocket(port, debug_nmea, tcp_keep_ais_time)) { return EXIT_FAILURE; } } if (show_levels) on_sound_level_changed=sound_level_changed; on_nmea_sentence_received=nmea_sentence_received; initSoundDecoder(buf_len,time_print_stats); return 0; }
int main(int argc, char *argv[]) { Sound_Channels channels = SOUND_CHANNELS_STEREO; char *host, *port, *file_name=NULL; const char *params=CMD_PARAMS; int alsa=0, pulse=0, file=0, winmm=0; int hfnd=0, pfnd=0, afnd=0; #ifdef WIN32 unsigned int deviceId=WAVE_MAPPER; #endif #ifdef HAVE_ALSA char *alsaDevice=NULL; #endif int opt; while ((opt = getopt(argc, argv, params)) != -1) { switch (opt) { case 'h': host = optarg; hfnd = 1; break; case 'p': port = optarg; pfnd = 1; break; case 'a': #ifdef HAVE_PULSEAUDIO pulse = strcmp(optarg, "pulse") == 0; #endif #ifdef HAVE_ALSA alsa = strcmp(optarg, "alsa") == 0; #endif #ifdef WIN32 winmm = strcmp(optarg, "winmm") == 0; #endif file = strcmp(optarg, "file") == 0; afnd = 1; break; case 'c': if (!strcmp(optarg, "mono")) channels = SOUND_CHANNELS_MONO; else if (!strcmp(optarg, "left")) channels = SOUND_CHANNELS_LEFT; else if (!strcmp(optarg, "right")) channels = SOUND_CHANNELS_RIGHT; break; case 'l': show_levels = 1; break; case 'f': file_name = optarg; break; case 'd': debug_nmea = 1; break; #ifdef WIN32 case 'D': if (!strcmp(optarg, "list")) { printInDevices(); return EXIT_SUCCESS; } else { deviceId = atoi(optarg); } break; #endif #ifdef HAVE_ALSA case 'D': if (!strcmp(optarg, "list")) { printInDevices(); return EXIT_SUCCESS; } else { alsaDevice = optarg; } break; #endif case 'H': default: fprintf(stderr, HELP_MSG); return EXIT_SUCCESS; break; } } if (argc < 2) { fprintf(stderr, HELP_MSG); return EXIT_FAILURE; } if (!hfnd) { fprintf(stderr, "Host is not set\n"); return EXIT_FAILURE; } if (!pfnd) { fprintf(stderr, "Port is not set\n"); return EXIT_FAILURE; } if (!afnd) { fprintf(stderr, "Audio driver is not set\n"); return EXIT_FAILURE; } if (!alsa && !pulse && !winmm && !file) { fprintf(stderr, "Invalid audio driver\n"); return EXIT_FAILURE; } if (!initSocket(host, port)) { return EXIT_FAILURE; } if (show_levels) on_sound_level_changed=sound_level_changed; on_nmea_sentence_received=nmea_sentence_received; Sound_Driver driver = DRIVER_FILE; #ifdef HAVE_ALSA if (alsa) driver = DRIVER_ALSA; #endif #ifdef HAVE_PULSEAUDIO if (pulse) driver = DRIVER_PULSE; #endif int OK=0; #ifdef WIN32 if (!file) driver = DRIVER_WINMM; OK=initSoundDecoder(channels, driver, file_name, deviceId); #else #ifdef HAVE_ALSA OK=initSoundDecoder(channels, driver, file_name, alsaDevice); #else OK=initSoundDecoder(channels, driver, file_name); #endif #endif int stop=0; if (OK) { runSoundDecoder(&stop); } else { fprintf(stderr, "%s\n", errorSoundDecoder); } freeSoundDecoder(); freeaddrinfo(addr); #ifdef WIN32 WSACleanup(); #endif return 0; }