int main(int argc, char *argv[]) { char temp[10]; pj_caching_pool cp; pj_pool_t *pool; pjmedia_endpt *ep; pjmedia_stream *stream; pjmedia_codec_info *ci; int rport = 5321; char *rhost = "239.1.0.2"; //char *rhost = "192.168.2.50"; if (argc < 3) { usage(argv[0]); } #if 1 int lport; lport = atoi(argv[1]); char *file = argv[2]; #endif #if 0 int lport = 2345; #endif pj_init(); pj_log_set_level(5); pj_caching_pool_init(&cp, NULL, 1024); streamer.pool = pj_pool_create(&cp.factory, "pool1", 1024, 1024, NULL); pjmedia_endpt_create(&cp.factory, NULL, 1, &streamer.ep); pjmedia_codec_g711_init(streamer.ep); streamer_init(&streamer, streamer.ep, streamer.pool); streamer_config_stream(&streamer, lport, rhost, rport); streamer_config_file_source(&streamer, file); //streamer_config_dev_source(&streamer, 2); streamer_start(&streamer); fprintf(stdout, "Local port: %d, File: %s\n", lport, file); while(1) { fprintf(stdout, "s=Stop - r=Resume: "); fflush(stdout); if (fgets(temp, sizeof(temp), stdin) == NULL) exit(-1); fprintf(stdout, "%s\n",temp); switch(temp[0]) { case 's': case 'S': streamer_stop(&streamer); break; case 'r': case 'R': streamer_start(&streamer); break; case '+': rport++; streamer_stop(&streamer); streamer_config_stream(&streamer, lport, rhost, rport); streamer_start(&streamer); break; case '-': rport--; streamer_stop(&streamer); streamer_config_stream(&streamer, lport, rhost, rport); streamer_start(&streamer); break; case 'v': streamer_update_stats(&streamer); fprintf(stdout, "rtt:%d - delay:%d - pkt:%d - lost: %d - discard:%d\n", streamer.streams[0].delay.mean_rtt_us, streamer.streams[0].delay.mean_delay_ms, streamer.streams[0].drop.pkt, streamer.streams[0].drop.lost, streamer.streams[0].drop.discard); break; } pj_thread_sleep(5*100); } return 0; }
int main(int argc, char **argv) { size_t c; int status; // Default values. arguments.verbose = DEBUG_LEVEL_INFO; arguments.port = 0; arguments.channel = 0; arguments.channel2 = arguments.channel + 1; arguments.packetsize = 1024; arguments.period_size = 512; arguments.nb_periods = 2; // number of extra frames to buffer on top of the // nb_periods x period_size. adds to the latency arguments.frame_slack = 0; // number of extra ISO packet descriptors to queue, // doesn't add to the latency. arguments.iso_slack = 0; arguments.startoncycle = -1; arguments.countdown = 4; arguments.printinterval = 100; arguments.rtprio = 0; // Parse our arguments; every option seen by `parse_opt' will // be reflected in `arguments'. if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { debugError("Could not parse command line\n" ); return -1; } // utility file descriptor char *device = NULL; if(asprintf(&device, "/dev/fw%zd", arguments.port) < 0) { debugError("Failed create device string\n"); exit(-1); } // open the specified port debugOutput(DEBUG_LEVEL_INFO, "Open device %s...\n", device); int util_fd = open( device, O_RDWR ); if(util_fd < 0) { debugError("Failed to open %s\n", device); free(device); exit(-1); } free(device); setDebugLevel(arguments.verbose); // AM824 settings struct am824_settings stream_settings; stream_settings.syt_interval = 8; // connection settings struct stream_settings settings; settings.type = STREAM_TYPE_RECEIVE; settings.channel = 0; settings.port = arguments.port; settings.max_packet_size = arguments.packetsize; settings.client_data = &stream_settings; settings.process_header = NULL; settings.process_payload = receive_am824_packet_data; settings.packet_size_for_sync = FRAMES_PER_PACKET; // setup the streamer streamer_t strm = streamer_new(); if(strm == NULL) { debugError("Could not allocate streamer\n"); exit(-1); } __u32 conn_ids[16]; if(streamer_init(strm, arguments.port, arguments.period_size, arguments.nb_periods, arguments.frame_slack, arguments.iso_slack, FRAMES_PER_SECOND) < 0) { debugError("Failed to init streamer\n"); close(util_fd); exit(-1); } #if 0 settings.channel = arguments.channel; settings.type = STREAM_TYPE_TRANSMIT; settings.process_header = NULL; settings.process_payload = transmit_am824_packet_data; #else settings.channel = 0; settings.type = STREAM_TYPE_RECEIVE; settings.process_header = NULL; settings.process_payload = receive_am824_packet_data; #endif status = streamer_add_stream(strm, &settings); if(status < 0) { debugError("Failed to add connection\n"); streamer_free(strm); close(util_fd); exit(-1); } conn_ids[0] = status; #if 1 settings.channel = arguments.channel2; settings.type = STREAM_TYPE_TRANSMIT; settings.process_header = NULL; settings.process_payload = transmit_am824_packet_data; #else settings.channel = 1; settings.type = STREAM_TYPE_RECEIVE; settings.process_header = NULL; settings.process_payload = receive_am824_packet_data; #endif status = streamer_add_stream(strm, &settings); if(status < 0) { debugError("Failed to add connection\n"); streamer_free(strm); close(util_fd); exit(-1); } conn_ids[1] = status; #if 0 settings.channel = 12; settings.type = STREAM_TYPE_TRANSMIT; settings.process_header = NULL; settings.process_payload = transmit_am824_packet_data; #else settings.channel = arguments.channel; settings.type = STREAM_TYPE_RECEIVE; settings.process_header = NULL; settings.process_payload = receive_am824_packet_data; #endif status = streamer_add_stream(strm, &settings); if(status < 0) { debugError("Failed to add connection\n"); streamer_free(strm); close(util_fd); exit(-1); } conn_ids[2] = status; streamer_start_connection(strm, conn_ids[0], -1); streamer_set_sync_connection(strm, conn_ids[0]); int nruns = arguments.countdown; // start the streamer if(streamer_start(strm) < 0) { debugError("Could not start streamer\n"); return -1; } do { // debugOutput(DEBUG_LEVEL_INFO, debugWarning( ">>>>>>>>>> Run %d <<<<<<<<<<\n", (int)(arguments.countdown - nruns)); if(arguments.countdown - nruns == 10) { streamer_start_connection(strm, conn_ids[1], -1); } if(arguments.countdown - nruns == 20) { streamer_start_connection(strm, conn_ids[2], -1); } if(arguments.countdown - nruns == 30) { settings.channel = 3; settings.type = STREAM_TYPE_RECEIVE; settings.process_header = NULL; settings.process_payload = receive_am824_packet_data; status = streamer_add_stream(strm, &settings); if(status < 0) { debugError("Failed to add connection\n"); streamer_free(strm); close(util_fd); exit(-1); } conn_ids[3] = status; } if(arguments.countdown - nruns == 40) { streamer_start_connection(strm, conn_ids[3], -1); } if(arguments.countdown - nruns == 50) { streamer_set_sync_connection(strm, conn_ids[3]); } /* ============================== * * WAIT * * ============================== */ if(streamer_wait_for_period(strm) < 0) { debugError("Failed to wait for period\n"); goto out; } /* ============================== * * READ * * ============================== */ streamer_read_frames(strm); /* ============================== * * PROCESS * * ============================== */ /* ============================== * * WRITE * * ============================== */ streamer_write_frames(strm); /* ============================== * * REQUEUE * * ============================== */ if(streamer_queue_next_period(strm) < 0) { debugError("queue failed\n"); goto out; } } while(--nruns); out: if(streamer_stop(strm) < 0) { debugError("Could not stop streamer\n"); return -1; } streamer_free(strm); close(util_fd); return 0; }