/* get a number before \n */ int get_a_number(int *num) { int count = 0, c, negtive = 0; char line[LINE_LEN + 1]; while(count < LINE_LEN) { c = get_a_char(); if(c == '\n' || c == EOF) break; /* got a number */ if(count && !isdigit(c)) { put_a_char(c); break; } if(isdigit(c)) line[count++] = c; if(c == '-' && !negtive) { line[count++] = c; negtive = 1; } } line[count] = '\0'; if(num) *num = atoi(line); return c; }
int main (const int argc, const char** argv) { GF_Err e; Bool run; /* location of the configuration file: 0 wait for config on a socket, 1 use the given file */ u32 config_flag; char config_file_name[MAX_BUF]; int dest_port; unsigned short tcp_port = 0; /* Should be fine on WIFI network */ unsigned short mtu_size = 1492; int debug = 0; TCP_Input *tcp_conf = NULL; GF_Thread *tcp_thread; GF_Err th_err_tcp; GF_Err th_err_rap; RAP_Input *rap_conf; GF_Thread *rap_thread; CONF_Data *conf; GF_Config *gf_config_file; GF_Err res; GF_Socket *UDP_feedback_socket; u32 socketType_for_updates; PNC_CallbackData * data; GF_RTPChannel * chan; GF_RTPHeader hdr; u32 timer = -1; GF_Mutex *carrousel_mutex; char sdp_fmt[5000]; tcp_thread = NULL; /* init gpac lib */ gf_sys_init(); gf_log_set_level(GF_LOG_ERROR); gf_log_set_tools(GF_LOG_NETWORK|GF_LOG_RTP|GF_LOG_SCENE|GF_LOG_PARSER|GF_LOG_AUTHOR|GF_LOG_CODING|GF_LOG_SCRIPT); GF_SAFEALLOC(conf, CONF_Data); tcp_port = config_flag = 0; socketType_for_updates = GF_SOCK_TYPE_UDP; if (command_line_parsing(argc, argv, &tcp_port, config_file_name, (int *) &config_flag, &mtu_size, &debug, &socketType_for_updates)){ print_usage(); return -1; } setDebugMode( debug ); gf_config_file = NULL; if (config_flag == 1) { char *cfg_path; char *cfg_fname; char *tmp; cfg_fname = config_file_name; cfg_path = config_file_name; tmp = strrchr(cfg_fname, GF_PATH_SEPARATOR); if (tmp) { cfg_fname = tmp+1; tmp[0] = 0; } else { cfg_path = "."; } gf_config_file = gf_cfg_new(cfg_path, cfg_fname); if (!gf_config_file) { fprintf(stderr, "Cannot open config file %s\n", config_file_name); return -1; } else { dprintf(DEBUG_broadcaster, "Using config file %s.\n", config_file_name); } if (parse_config(gf_config_file, conf, debug)) return -1; tcp_port = atoi(conf->config_input_port); } else { GF_SAFEALLOC(tcp_conf, TCP_Input); tcp_conf->config_flag = &config_flag; tcp_conf->RAPtimer = &timer; tcp_conf->port = tcp_port; tcp_conf->config = conf; tcp_thread = gf_th_new("TCPInterface"); /* Starting the thread which will write the received config in a temporary file */ th_err_tcp = gf_th_run(tcp_thread, tcp_server, tcp_conf); fprintf(stdout, "Waiting for configuration on port %d...\n", tcp_conf->port); while(config_flag == 0) { gf_sleep(1000); } fprintf(stdout, "Configuration File received. Starting Streaming ...\n"); } timer = atoi(conf->rap_timer); dest_port = atoi(conf->dest_port); res = PNC_InitRTP(&chan, (char *)conf->dest_ip, dest_port, mtu_size); if (res != 0) { fprintf(stderr, "Cannot initialize RTP output (error: %d)\n", res); exit(1); } carrousel_mutex = gf_mx_new("Carrousel"); data = PNC_Init_SceneGenerator(chan, &hdr, (char *) conf->scene_init_file, socketType_for_updates, (u16) atoi(conf->modif_input_port), debug); if (!data) { fprintf(stderr, "Cannot initialize Scene Generator\n"); exit(1); } data->carrousel_mutex = carrousel_mutex; data->RAPsent = 1; UDP_feedback_socket = gf_sk_new(GF_SOCK_TYPE_UDP); e = gf_sk_bind(UDP_feedback_socket, NULL, (u16)atoi(conf->feedback_port), (char*)conf->feedback_ip, (u16)atoi(conf->feedback_port), 0); if (e) { fprintf(stderr, "Cannot bind socket for bitrate feedback information (%s)\n", gf_error_to_string(e)); } else { e = gf_sk_set_block_mode(UDP_feedback_socket, 1); if (e) { fprintf(stderr, "Cannot set feedback socket block mode (%s)\n", gf_error_to_string(e)); } } data->feedback_socket = UDP_feedback_socket; PNC_InitPacketiser(data, sdp_fmt, mtu_size); PNC_SendInitScene(data); GF_SAFEALLOC(rap_conf, RAP_Input); rap_conf->RAPtimer = &timer; rap_conf->carrousel_mutex = carrousel_mutex; rap_conf->data = data; rap_thread = gf_th_new("RAPGenerator"); th_err_rap = gf_th_run(rap_thread, RAP_send, rap_conf); sdp_generator(data, (char *)conf->dest_ip, sdp_fmt); run = 1; while (run) { GF_Err e = PNC_processBIFSGenerator(data); if (e) { fprintf(stderr, "Cannot Process BIFS data (%s)\n", gf_error_to_string(e)); break; } if (has_input()) { char c = get_a_char(); switch (c) { case 'q': run = 0; break; } } gf_sleep(10); } /* waiting for termination of the RAP thread */ rap_conf->status = 0; while (rap_conf->status != 2) gf_sleep(0); gf_free(rap_conf); gf_th_del(rap_thread); /* waiting for termination of the TCP listening thread */ if (tcp_conf) { tcp_conf->status = 0; while (tcp_conf->status != 2) gf_sleep(0); gf_free(tcp_conf); gf_th_del(tcp_thread); } PNC_Close_SceneGenerator(data); gf_free(conf); if (gf_config_file) gf_cfg_del(gf_config_file); gf_mx_del(carrousel_mutex); gf_sys_close(); return 0; }