From: <jpg...@us...> - 2007-10-16 23:34:44
|
Revision: 1201 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1201&view=rev Author: jpgrayson Date: 2007-10-16 16:34:48 -0700 (Tue, 16 Oct 2007) Log Message: ----------- Remove trailing whitespace. Modified Paths: -------------- trunk/simpleclient/stresstest/file.c trunk/simpleclient/stresstest/stresstest.c Modified: trunk/simpleclient/stresstest/file.c =================================================================== --- trunk/simpleclient/stresstest/file.c 2007-10-16 23:32:32 UTC (rev 1200) +++ trunk/simpleclient/stresstest/file.c 2007-10-16 23:34:48 UTC (rev 1201) @@ -17,7 +17,7 @@ memcpy(node->op, op, sizeof(*op)); node->op->packet = malloc(op->bytes); memcpy(node->op->packet, op->packet, op->bytes); - + return node; } @@ -46,13 +46,13 @@ } } -/* +/* * We're forced to use a dirty hack here, due to Theora's idiotic API * Theora needs three separate pieces of data, called headers to initialize * its internal decoder structure. After all three pieces have been received, - * we can call theora_decode_init. - * We use a counter and a flag to make sure we have decoded our three headers and then - * we call theora_decode_init so we can initialize a theora_state structure. + * we can call theora_decode_init. + * We use a counter and a flag to make sure we have decoded our three headers and then + * we call theora_decode_init so we can initialize a theora_state structure. * We use the ts structure to convert a granule position into an actual timestamp. * There are many ways in which this can fail, but we rely on having all three headers * at the beginning of the ogg video bitstream. @@ -64,27 +64,27 @@ struct op_node *node; struct theora_headers *th; long timestamp = 0; - + //fprintf(stderr, "Got theora packet, serialno=%d, size=%d, packetno=%lld, granulepos=%lld\n", serialno, op->bytes, op->packetno, op->granulepos); - + th = (struct theora_headers *)video_stream->data; - + if ( theora_packet_isheader(op) ) { theora_decode_header(&(th->ti), &(th->tc), op); th->header_count++; } - + if ( th->header_count >= 3 && !th->have_headers ) { theora_decode_init(&(th->ts), &(th->ti)); th->have_headers = 1; } - + if ( th->have_headers ) { double d; - + d = theora_granule_time(&(th->ts), op->granulepos); timestamp = (long)(d * 1000); } @@ -98,13 +98,13 @@ video_stream->page_ts = timestamp; video_stream->page_count = 0; } - + if ( !theora_packet_isheader(op) ) { node = create_node(op, serialno, timestamp); append_node(video_stream, node); } - + return 0; } @@ -113,42 +113,42 @@ struct op_node *node; long timestamp; static int cnt = 0; - + timestamp = audio_stream->page_ts + audio_stream->page_count * SPEEX_FRAME_DURATION; audio_stream->page_count++; - + cnt++; //fprintf(stderr, "Got speex packet, serialno=%ld, size=%ld, packetno=%lld, granulepos=%lld, timestamp=%ld\n", serialno, op->bytes, op->packetno, op->granulepos, timestamp); - + // Ignore the first two packets, they are headers if ( cnt > 2 ) { node = create_node(op, serialno, timestamp); append_node(audio_stream, node); } - + return 0; } int read_cb(OGGZ *oggz, ogg_packet *op, long serialno, void *data) { struct theora_headers *th; - + const char theoraId[] = "\x80theora"; const char speexId[] = "Speex "; - + if ( memcmp(op->packet, theoraId, strlen(theoraId)) == 0 ) { //fprintf(stderr, "Detected a Theora stream with serialno=%d\n", serialno); oggz_set_read_callback(oggz, serialno, read_theora_cb, NULL); video_stream->serialno = serialno; - + // Initialize theora specific data fields th = (struct theora_headers *)calloc(1, sizeof(struct theora_headers)); theora_info_init(&(th->ti)); theora_comment_init(&(th->tc)); video_stream->data = th; - + read_theora_cb(oggz, op, serialno, data); } else if ( memcmp(op->packet, speexId, strlen(speexId)) == 0 ) { @@ -179,7 +179,7 @@ void dump_stream(struct ogg_stream *os) { struct op_node *node; - + node = os->first; while ( node != NULL ) { @@ -198,21 +198,21 @@ fprintf(stderr, "Error opening ogg file\n"); } fprintf(stderr, "Successfully opened ogg file %s\n", filename); - + // Initialize internal streams audio_stream = calloc(1, sizeof(struct ogg_stream)); video_stream = calloc(1, sizeof(struct ogg_stream)); - + oggz_set_read_callback(oggz, -1, read_cb, NULL); oggz_set_read_page(oggz, -1, read_page_cb, NULL); - + oggz_run(oggz); - + //fprintf(stderr, "Audio stream, serialno=%d\n", audio_stream->serialno); //dump_stream(audio_stream); //fprintf(stderr, "Video stream, serialno=%d\n", video_stream->serialno); //dump_stream(video_stream); - + oggz_close(oggz); } @@ -221,27 +221,27 @@ ogg_packet *op; struct timeval tv; long time_now; - + if ( os == NULL ) return NULL; - + gettimeofday(&tv, NULL); time_now = tv.tv_sec * 1000 + tv.tv_usec / 1000; - + if ( os->current == NULL ) { // point to the beginning of the stream and reset the time base os->base_ts = time_now; os->current = os->first; } - - op = NULL; + + op = NULL; if ( os->current->timestamp < time_now - os->base_ts ) { op = os->current->op; os->current = os->current->next; } - + return op; } Modified: trunk/simpleclient/stresstest/stresstest.c =================================================================== --- trunk/simpleclient/stresstest/stresstest.c 2007-10-16 23:32:32 UTC (rev 1200) +++ trunk/simpleclient/stresstest/stresstest.c 2007-10-16 23:34:48 UTC (rev 1201) @@ -83,13 +83,13 @@ void signal_handler(int signum) { - if ( signum == SIGTERM || signum == SIGINT ) + if ( signum == SIGTERM || signum == SIGINT ) { running = 0; } } -void fatal_error(char *err) +void fatal_error(char *err) { fprintf(stderr, "FATAL ERROR: %s\n", err); exit(TEST_UNKNOWN_ERROR); @@ -102,10 +102,10 @@ int netstat_callback(struct iaxc_ev_netstats n) { static int i; - + if ( !print_netstats ) return 0; - + if(i++%25 == 0) fprintf(stderr, "RTT\t" "Rjit\tRlos%%\tRlosC\tRpkts\tRdel\tRdrop\tRooo\t" @@ -140,7 +140,7 @@ void process_text_message(char *message) { unsigned int prefs; - + if ( strncmp(message, "CONTROL:", strlen("CONTROL:")) == 0 ) { message += strlen("CONTROL:"); @@ -162,7 +162,7 @@ } void usage() -{ +{ printf( "\n" "Usage is: tescall <options>\n\n" @@ -188,7 +188,7 @@ fprintf(stderr, "Call answered\n"); call_established = 1; } - if (s.state == IAXC_CALL_STATE_FREE) + if (s.state == IAXC_CALL_STATE_FREE) { fprintf(stderr,"Call terminated\n"); running = 0; @@ -199,7 +199,7 @@ int test_mode_callback(iaxc_event e) { - switch ( e.type ) + switch ( e.type ) { case IAXC_EVENT_LEVELS: return levels_callback(e.ev.levels.input, e.ev.levels.output); @@ -230,7 +230,7 @@ int main(int argc, char **argv) { - int i; + int i; char mydest[80], *dest = NULL; char *ogg_file = NULL; int loop = 0; @@ -238,15 +238,15 @@ static struct slice_set_t slice_set; unsigned short source_id; struct timeval now; - + /* install signal handler to catch CRTL-Cs */ signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); - + /* Parse command line */ for(i=1;i<argc;i++) { - if(argv[i][0] == '-') + if(argv[i][0] == '-') { switch(argv[i][1]) { @@ -285,44 +285,44 @@ default: usage(); } - } else + } else dest=argv[i]; } - + if ( dest == NULL ) { // We need a destination to call fprintf(stderr, "No destination, quitting\n"); return -1; } - + if ( ogg_file == NULL ) fprintf(stderr, "No media file, running dry\n"); - + if ( ogg_file ) { // Load ogg file load_ogg_file(ogg_file); } - + // Get start time for timeouts gettimeofday(&start_time, NULL); - + // Initialize iaxclient iaxc_video_format_set(formatp, format, framerate, bitrate, width, height, fragsize); iaxc_set_test_mode(1); - if (iaxc_initialize(MAX_CALLS)) + if (iaxc_initialize(MAX_CALLS)) fatal_error("cannot initialize iaxclient!"); - + iaxc_set_formats(IAXC_FORMAT_SPEEX, IAXC_FORMAT_SPEEX); iaxc_video_bypass_jitter(0); iaxc_set_audio_prefs(IAXC_AUDIO_PREF_RECV_REMOTE_ENCODED); iaxc_set_video_prefs(IAXC_VIDEO_PREF_RECV_REMOTE_ENCODED); - iaxc_set_event_callback(test_mode_callback); - + iaxc_set_event_callback(test_mode_callback); + // Crank the engine iaxc_start_processing_thread(); - + // Dial out int callNo = iaxc_call(dest); if (callNo <= 0) @@ -338,7 +338,7 @@ hangup_and_exit(TEST_NO_CONNECTION); iaxc_millisleep(5); } - + running = 1; while ( running ) { @@ -346,29 +346,29 @@ if ( ogg_file && ( send_audio || send_video ) ) { ogg_packet *op; - + op = get_next_audio_op(); if ( !loop && audio_is_eos() ) break; if ( send_audio && op != NULL && op->bytes > 0 ) iaxc_push_audio(op->packet, op->bytes, SPEEX_SAMPLING_RATE / 1000 * SPEEX_FRAME_DURATION); - + op = get_next_video_op(); if ( !loop && video_is_eos() ) break; if ( send_video && op != NULL && op->bytes > 0 ) iaxc_push_video(op->packet, op->bytes, 1); } - + // Tight spinloops are bad, mmmkay? iaxc_millisleep(5); - + // Exit after a positive timeout gettimeofday(&now, NULL); if ( timeout > 0 && msecdiff(&start_time, &now) > timeout ) running = 0; } - + fprintf(stderr, "Received %d audio frames and %d video frames\n", audio_frames_count, video_frames_count); if ( audio_frames_count == 0 && video_frames_count == 0 ) hangup_and_exit(TEST_NO_MEDIA); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpg...@us...> - 2007-10-17 00:22:06
|
Revision: 1204 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1204&view=rev Author: jpgrayson Date: 2007-10-16 17:22:10 -0700 (Tue, 16 Oct 2007) Log Message: ----------- Add ability to log stresstest output through a log file. Apply timestamp to stresstest log messages. Modified Paths: -------------- trunk/simpleclient/stresstest/file.c trunk/simpleclient/stresstest/stresstest.c Modified: trunk/simpleclient/stresstest/file.c =================================================================== --- trunk/simpleclient/stresstest/file.c 2007-10-16 23:40:00 UTC (rev 1203) +++ trunk/simpleclient/stresstest/file.c 2007-10-17 00:22:10 UTC (rev 1204) @@ -3,6 +3,12 @@ #include <stdio.h> #include "file.h" +#ifdef __GNUC__ +void mylog(const char * fmt, ...) __attribute__ ((format (printf, 1, 2))); +#else +void mylog(const char * fmt, ...); +#endif + static struct ogg_stream *audio_stream; static struct ogg_stream *video_stream; @@ -27,7 +33,7 @@ { if ( os->last != NULL ) { - fprintf(stderr, "Queue inconsistency, bailing...\n"); + mylog("Queue inconsistency, bailing...\n"); return; } os->first = node; @@ -37,7 +43,7 @@ { if ( os->last == NULL ) { - fprintf(stderr, "Queue inconsistency, bailing...\n"); + mylog("Queue inconsistency, bailing...\n"); return; } os->last->next = node; @@ -65,7 +71,8 @@ struct theora_headers *th; long timestamp = 0; - //fprintf(stderr, "Got theora packet, serialno=%d, size=%d, packetno=%lld, granulepos=%lld\n", serialno, op->bytes, op->packetno, op->granulepos); + //mylog("Got theora packet, serialno=%d, size=%d, packetno=%lld, granulepos=%lld\n", + // serialno, op->bytes, op->packetno, op->granulepos); th = (struct theora_headers *)video_stream->data; @@ -118,7 +125,8 @@ audio_stream->page_count++; cnt++; - //fprintf(stderr, "Got speex packet, serialno=%ld, size=%ld, packetno=%lld, granulepos=%lld, timestamp=%ld\n", serialno, op->bytes, op->packetno, op->granulepos, timestamp); + //mylog("Got speex packet, serialno=%ld, size=%ld, packetno=%lld, granulepos=%lld, timestamp=%ld\n", + // serialno, op->bytes, op->packetno, op->granulepos, timestamp); // Ignore the first two packets, they are headers if ( cnt > 2 ) @@ -139,7 +147,7 @@ if ( memcmp(op->packet, theoraId, strlen(theoraId)) == 0 ) { - //fprintf(stderr, "Detected a Theora stream with serialno=%d\n", serialno); + //mylog("Detected a Theora stream with serialno=%d\n", serialno); oggz_set_read_callback(oggz, serialno, read_theora_cb, NULL); video_stream->serialno = serialno; @@ -152,13 +160,14 @@ read_theora_cb(oggz, op, serialno, data); } else if ( memcmp(op->packet, speexId, strlen(speexId)) == 0 ) { - //fprintf(stderr, "Detected a Speex stream with serialno=%d\n", serialno); + //mylog("Detected a Speex stream with serialno=%d\n", serialno); oggz_set_read_callback(oggz, serialno, read_speex_cb, NULL); audio_stream->serialno = serialno; read_speex_cb(oggz, op, serialno, data); } else { - fprintf(stderr, "Got unknown ogg packet, serialno=%d, size=%d, packetno=%d, granulepos=%d\n", serialno, op->bytes, op->packetno, op->granulepos); + mylog("Got unknown ogg packet, serialno=%d, size=%d, packetno=%d, granulepos=%d\n", + serialno, op->bytes, op->packetno, op->granulepos); } return 0; } @@ -171,7 +180,8 @@ audio_stream->page_count = 0; } else if ( serialno == video_stream->serialno ) { - //fprintf(stderr, "Got theora page serialno=%d, header_len=%d, body_len=%d, granulepos=%lld\n", serialno, og->header_len, og->body_len, ogg_page_granulepos(og)); + //mylog("Got theora page serialno=%d, header_len=%d, body_len=%d, granulepos=%lld\n", + // serialno, og->header_len, og->body_len, ogg_page_granulepos(og)); } return 0; } @@ -183,7 +193,9 @@ node = os->first; while ( node != NULL ) { - fprintf(stderr, "Size=%ld, Stream=%ld, packetno=%lld, timestamp=%ld\n", node->op->bytes, node->serialno, node->op->packetno, node->timestamp); + mylog("Size=%ld, Stream=%ld, packetno=%lld, timestamp=%ld\n", + node->op->bytes, node->serialno, + node->op->packetno, node->timestamp); node = node->next; } } @@ -195,9 +207,9 @@ oggz = oggz_open(filename, OGGZ_READ | OGGZ_AUTO); if ( oggz == NULL ) { - fprintf(stderr, "Error opening ogg file\n"); + mylog("Error opening ogg file\n"); } - fprintf(stderr, "Successfully opened ogg file %s\n", filename); + mylog("Successfully opened ogg file %s\n", filename); // Initialize internal streams audio_stream = calloc(1, sizeof(struct ogg_stream)); @@ -208,9 +220,9 @@ oggz_run(oggz); - //fprintf(stderr, "Audio stream, serialno=%d\n", audio_stream->serialno); + //mylog("Audio stream, serialno=%d\n", audio_stream->serialno); //dump_stream(audio_stream); - //fprintf(stderr, "Video stream, serialno=%d\n", video_stream->serialno); + //mylog("Video stream, serialno=%d\n", video_stream->serialno); //dump_stream(video_stream); oggz_close(oggz); Modified: trunk/simpleclient/stresstest/stresstest.c =================================================================== --- trunk/simpleclient/stresstest/stresstest.c 2007-10-16 23:40:00 UTC (rev 1203) +++ trunk/simpleclient/stresstest/stresstest.c 2007-10-17 00:22:10 UTC (rev 1204) @@ -13,6 +13,7 @@ * the GNU Lesser (Library) General Public License */ +#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -62,18 +63,43 @@ static struct timeval start_time; +static FILE * log_file = 0; + +#ifdef __GNUC__ +void mylog(const char * fmt, ...) __attribute__ ((format (printf, 1, 2))); +#endif + +void mylog(const char * fmt, ...) +{ + va_list ap; + time_t t; + struct tm * tmp; + char str[1024]; + char time_str[1024]; + + t = time(0); + tmp = localtime(&t); + + strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", tmp); + snprintf(str, sizeof(str), "stresstest: %s: %s", time_str, fmt); + + va_start(ap, fmt); + vfprintf(log_file ? log_file : stderr, str, ap); + va_end(ap); +} + /* routine used to shutdown and close nicely.*/ void hangup_and_exit(int code) { - fprintf(stderr,"Dump call\n"); + mylog("Dump call\n"); iaxc_dump_call(); - fprintf(stderr,"Sleep for 500 msec\n"); + mylog("Sleep for 500 msec\n"); iaxc_millisleep(500); - fprintf(stderr,"Stop processing thread\n"); + mylog("Stop processing thread\n"); iaxc_stop_processing_thread(); - fprintf(stderr,"Calling iaxc_shutdown..."); + mylog("Calling iaxc_shutdown...\n"); iaxc_shutdown(); - fprintf(stderr,"Exiting with code %d\n", code); + mylog("Exiting with code %d\n", code); exit(code); } @@ -87,12 +113,12 @@ void fatal_error(char *err) { - fprintf(stderr, "FATAL ERROR: %s\n", err); + mylog("FATAL ERROR: %s\n", err); exit(TEST_UNKNOWN_ERROR); } int levels_callback(float input, float output) { - //fprintf(stderr,"Input level: %f\nOutput level: %f\n",input,output); + //mylog("Input level: %f\nOutput level: %f\n", input, output); return 1; } @@ -102,12 +128,12 @@ if ( !print_netstats ) return 0; - if(i++%25 == 0) - fprintf(stderr, "RTT\t" + if ( i++ % 25 == 0 ) + mylog("RTT\t" "Rjit\tRlos%%\tRlosC\tRpkts\tRdel\tRdrop\tRooo\t" "Ljit\tLlos%%\tLlosC\tLpkts\tLdel\tLdrop\tLooo\n"); - fprintf(stderr, "%d\t" + mylog("%d\t" "%d\t%d\t%d\t%d\t%d\t%d\t%d\t" "%d\t%d\t%d\t%d\t%d\t%d\t%d\n", @@ -154,20 +180,21 @@ iaxc_set_video_prefs(prefs); } } else - fprintf(stderr, "Text message received: %s\n", message); + mylog("Text message received: %s\n", message); } void usage() { - printf("Usage is: stresstest <options>\n\n" + printf("Usage: stresstest <options>\n\n" "available options:\n" - " -F <codec,framerate,bitrate,width,height,fragsize> set video parameters\n" + " -F <codec> <framerate> <bitrate> <width> <height> <fragsize> set video parameters\n" " -o <filename> media file to run\n" " -v stop sending video\n" " -a stop sending audio\n" " -l run file in a loop\n" - " -n dump periodic netstats to stderr\n" + " -n dump periodic netstats to log file\n" " -t <timeout> terminate after timeout seconds and report status via return code\n" + " -L <FILE> log to FILE\n" "\n" ); exit(1); @@ -175,16 +202,16 @@ int test_mode_state_callback(struct iaxc_ev_call_state s) { - printf("Call #%d state %d\n", s.callNo, s.state); + mylog("Call #%d state %d\n", s.callNo, s.state); if ( s.state & IAXC_CALL_STATE_COMPLETE ) { - fprintf(stderr, "Call answered\n"); + mylog("Call answered\n"); call_established = 1; } if (s.state == IAXC_CALL_STATE_FREE) { - fprintf(stderr,"Call terminated\n"); + mylog("Call terminated\n"); running = 0; } @@ -273,6 +300,16 @@ usage(); timeout = 1000 * atoi(argv[++i]); break; + case 'L': + if ( i+1 >= argc ) + usage(); + if ( !(log_file = fopen(argv[++i], "w")) ) + { + mylog("failed to open log \"%s\"\n", + argv[i]); + exit(1); + } + break; default: usage(); } @@ -282,15 +319,14 @@ if ( dest == NULL ) { - // We need a destination to call - fprintf(stderr, "No destination, quitting\n"); + mylog("No destination, quitting\n"); return -1; } if ( ogg_file ) load_ogg_file(ogg_file); else - fprintf(stderr, "No media file, running dry\n"); + mylog("No media file, running dry\n"); // Get start time for timeouts gettimeofday(&start_time, NULL); @@ -316,7 +352,7 @@ if (callNo <= 0) iaxc_select_call(callNo); else - fprintf(stderr, "Failed to make call to '%s'", dest); + mylog("Failed to make call to '%s'", dest); // Wait for the call to be established; while ( !call_established ) @@ -362,7 +398,7 @@ running = 0; } - fprintf(stderr, "Received %d audio frames and %d video frames\n", + mylog("Received %d audio frames and %d video frames\n", audio_frames_count, video_frames_count); if ( audio_frames_count == 0 && video_frames_count == 0 ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpg...@us...> - 2008-04-15 22:17:42
|
Revision: 1405 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1405&view=rev Author: jpgrayson Date: 2008-04-15 15:17:47 -0700 (Tue, 15 Apr 2008) Log Message: ----------- Cleanup public versus static interfaces in file module. Other syntactic tidiness. Modified Paths: -------------- trunk/simpleclient/stresstest/file.c trunk/simpleclient/stresstest/file.h Modified: trunk/simpleclient/stresstest/file.c =================================================================== --- trunk/simpleclient/stresstest/file.c 2008-04-15 22:16:27 UTC (rev 1404) +++ trunk/simpleclient/stresstest/file.c 2008-04-15 22:17:47 UTC (rev 1405) @@ -3,16 +3,51 @@ #include <stdio.h> #include "file.h" +#include <oggz/oggz.h> +#include <theora/theora.h> + #ifdef __GNUC__ void mylog(const char * fmt, ...) __attribute__ ((format (printf, 1, 2))); #else void mylog(const char * fmt, ...); #endif +#define THEORA_FRAME_DURATION 1000 / 15 + +struct op_node +{ + ogg_packet *op; + long serialno; + long timestamp; + struct op_node *next; +}; + +struct theora_headers +{ + theora_info ti; + theora_comment tc; + theora_state ts; + int header_count; + int have_headers; +}; + +struct ogg_stream +{ + struct op_node *first; + struct op_node *last; + struct op_node *current; + long serialno; + long page_ts; + long page_count; + long base_ts; + void *data; +}; + static struct ogg_stream *audio_stream; static struct ogg_stream *video_stream; -struct op_node * create_node(ogg_packet *op, long serialno, long timestamp) +static struct op_node * +create_node(ogg_packet *op, long serialno, long timestamp) { struct op_node *node; @@ -27,7 +62,8 @@ return node; } -void append_node(struct ogg_stream *os, struct op_node *node) +static void +append_node(struct ogg_stream *os, struct op_node *node) { if ( os->first == NULL ) { @@ -65,15 +101,13 @@ * * To whoever came up with this convoluted scheme: please consider a change of careers. */ -int read_theora_cb(OGGZ *oggz, ogg_packet *op, long serialno, void *data) +static int +read_theora_cb(OGGZ *oggz, ogg_packet *op, long serialno, void *data) { struct op_node *node; struct theora_headers *th; long timestamp = 0; - //mylog("Got theora packet, serialno=%d, size=%d, packetno=%lld, granulepos=%lld\n", - // serialno, op->bytes, op->packetno, op->granulepos); - th = (struct theora_headers *)video_stream->data; if ( theora_packet_isheader(op) ) @@ -98,7 +132,8 @@ if ( timestamp < 0 ) { - timestamp = video_stream->page_ts + video_stream->page_count * THEORA_FRAME_DURATION; + timestamp = video_stream->page_ts + + video_stream->page_count * THEORA_FRAME_DURATION; video_stream->page_count++; } else { @@ -115,30 +150,29 @@ return 0; } -int read_speex_cb(OGGZ *oggz, ogg_packet *op, long serialno, void *data) +static int +read_speex_cb(OGGZ *oggz, ogg_packet *op, long serialno, void *data) { - struct op_node *node; - long timestamp; - static int cnt = 0; + static int cnt = 0; + const long timestamp = audio_stream->page_ts + + audio_stream->page_count * SPEEX_FRAME_DURATION; - timestamp = audio_stream->page_ts + audio_stream->page_count * SPEEX_FRAME_DURATION; audio_stream->page_count++; cnt++; - //mylog("Got speex packet, serialno=%ld, size=%ld, packetno=%lld, granulepos=%lld, timestamp=%ld\n", - // serialno, op->bytes, op->packetno, op->granulepos, timestamp); // Ignore the first two packets, they are headers if ( cnt > 2 ) { - node = create_node(op, serialno, timestamp); + struct op_node *node = create_node(op, serialno, timestamp); append_node(audio_stream, node); } return 0; } -int read_cb(OGGZ *oggz, ogg_packet *op, long serialno, void *data) +static int +read_cb(OGGZ *oggz, ogg_packet *op, long serialno, void *data) { struct theora_headers *th; @@ -147,12 +181,11 @@ if ( memcmp(op->packet, theoraId, strlen(theoraId)) == 0 ) { - //mylog("Detected a Theora stream with serialno=%d\n", serialno); oggz_set_read_callback(oggz, serialno, read_theora_cb, NULL); video_stream->serialno = serialno; // Initialize theora specific data fields - th = (struct theora_headers *)calloc(1, sizeof(struct theora_headers)); + th = calloc(1, sizeof(struct theora_headers)); theora_info_init(&(th->ti)); theora_comment_init(&(th->tc)); video_stream->data = th; @@ -160,48 +193,37 @@ read_theora_cb(oggz, op, serialno, data); } else if ( memcmp(op->packet, speexId, strlen(speexId)) == 0 ) { - //mylog("Detected a Speex stream with serialno=%d\n", serialno); oggz_set_read_callback(oggz, serialno, read_speex_cb, NULL); audio_stream->serialno = serialno; read_speex_cb(oggz, op, serialno, data); } else { - mylog("Got unknown ogg packet, serialno=%d, size=%d, packetno=%d, granulepos=%d\n", - serialno, op->bytes, op->packetno, op->granulepos); + mylog("Got unknown ogg packet, serialno=%d, size=%d, " + "packetno=%d, granulepos=%d\n", + serialno, op->bytes, + op->packetno, op->granulepos); } return 0; } -int read_page_cb(OGGZ *oggz, const ogg_page *og, long serialno, void *data) +static int +read_page_cb(OGGZ *oggz, const ogg_page *og, long serialno, void *data) { if ( serialno == audio_stream->serialno ) { - audio_stream->page_ts = ogg_page_granulepos(og) * 1000 / SPEEX_SAMPLING_RATE; + audio_stream->page_ts = ogg_page_granulepos(og) * 1000 / + SPEEX_SAMPLING_RATE; audio_stream->page_count = 0; - } else if ( serialno == video_stream->serialno ) + } + else if ( serialno == video_stream->serialno ) { - //mylog("Got theora page serialno=%d, header_len=%d, body_len=%d, granulepos=%lld\n", - // serialno, og->header_len, og->body_len, ogg_page_granulepos(og)); } return 0; } -void dump_stream(struct ogg_stream *os) +void +load_ogg_file(const char *filename) { - struct op_node *node; - - node = os->first; - while ( node != NULL ) - { - mylog("Size=%ld, Stream=%ld, packetno=%lld, timestamp=%ld\n", - node->op->bytes, node->serialno, - node->op->packetno, node->timestamp); - node = node->next; - } -} - -void load_ogg_file(const char *filename) -{ OGGZ *oggz; oggz = oggz_open(filename, OGGZ_READ | OGGZ_AUTO); @@ -220,15 +242,10 @@ oggz_run(oggz); - //mylog("Audio stream, serialno=%d\n", audio_stream->serialno); - //dump_stream(audio_stream); - //mylog("Video stream, serialno=%d\n", video_stream->serialno); - //dump_stream(video_stream); - oggz_close(oggz); } -ogg_packet * get_next_op(struct ogg_stream *os) +static ogg_packet * get_next_op(struct ogg_stream *os) { ogg_packet *op; struct timeval tv; Modified: trunk/simpleclient/stresstest/file.h =================================================================== --- trunk/simpleclient/stresstest/file.h 2008-04-15 22:16:27 UTC (rev 1404) +++ trunk/simpleclient/stresstest/file.h 2008-04-15 22:17:47 UTC (rev 1405) @@ -1,48 +1,11 @@ #ifndef __FILE_H__ #define __FILE_H__ -#include <oggz/oggz.h> -#include <theora/theora.h> +#include <ogg/ogg.h> #define SPEEX_FRAME_DURATION 20 #define SPEEX_SAMPLING_RATE 8000 -#define THEORA_FRAME_DURATION 1000 / 15 - -// Struct used to build chains of packets for delivery -struct op_node -{ - ogg_packet *op; - long serialno; - long timestamp; - struct op_node *next; -}; - -struct ogg_stream -{ - struct op_node *first; - struct op_node *last; - struct op_node *current; - long serialno; - long page_ts; - long page_count; - long base_ts; - void *data; -}; - -struct theora_headers -{ - theora_info ti; - theora_comment tc; - theora_state ts; - int header_count; - int have_headers; -}; - -int read_theora_cb(OGGZ *oggz, ogg_packet *op, long serialno, void *data); -int read_speex_cb(OGGZ *oggz, ogg_packet *op, long serialno, void *data); -int read_cb(OGGZ *oggz, ogg_packet *op, long serialno, void *data); -int read_page_cb(OGGZ *oggz, const ogg_page *og, long serialno, void *data); void load_ogg_file(const char *filename); ogg_packet * get_next_audio_op(); @@ -51,4 +14,4 @@ int audio_is_eos(); int video_is_eos(); -#endif // __FILE_H__ +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpg...@us...> - 2008-07-01 15:52:34
|
Revision: 1438 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1438&view=rev Author: jpgrayson Date: 2008-07-01 08:52:43 -0700 (Tue, 01 Jul 2008) Log Message: ----------- Updates to stresstest to allow for simple commands to be passed to it via stdin. Modified Paths: -------------- trunk/simpleclient/stresstest/file.c trunk/simpleclient/stresstest/file.h trunk/simpleclient/stresstest/stresstest.c Modified: trunk/simpleclient/stresstest/file.c =================================================================== --- trunk/simpleclient/stresstest/file.c 2008-07-01 15:42:30 UTC (rev 1437) +++ trunk/simpleclient/stresstest/file.c 2008-07-01 15:52:43 UTC (rev 1438) @@ -1,11 +1,12 @@ #include <string.h> #include <stdlib.h> #include <stdio.h> -#include "file.h" #include <oggz/oggz.h> #include <theora/theora.h> +#include "file.h" + #ifdef __GNUC__ void mylog(const char * fmt, ...) __attribute__ ((format (printf, 1, 2))); #else @@ -211,7 +212,8 @@ { if ( serialno == audio_stream->serialno ) { - audio_stream->page_ts = ogg_page_granulepos(og) * 1000 / + audio_stream->page_ts = + ogg_page_granulepos((ogg_page *)og) * 1000 / SPEEX_SAMPLING_RATE; audio_stream->page_count = 0; } @@ -221,7 +223,7 @@ return 0; } -void +int load_ogg_file(const char *filename) { OGGZ *oggz; @@ -230,6 +232,7 @@ if ( oggz == NULL ) { mylog("Error opening ogg file\n"); + return -1; } mylog("Successfully opened ogg file %s\n", filename); @@ -243,28 +246,30 @@ oggz_run(oggz); oggz_close(oggz); + + return 0; } -static ogg_packet * get_next_op(struct ogg_stream *os) +static ogg_packet * get_next_op(struct ogg_stream *os, struct timeval tv) { - ogg_packet *op; - struct timeval tv; - long time_now; + ogg_packet *op = 0; + long time_now; - if ( os == NULL ) + if ( !os ) return NULL; - gettimeofday(&tv, NULL); time_now = tv.tv_sec * 1000 + tv.tv_usec / 1000; - if ( os->current == NULL ) + if ( !os->current ) { + if ( !os->first ) + return NULL; + // point to the beginning of the stream and reset the time base os->base_ts = time_now; os->current = os->first; } - op = NULL; if ( os->current->timestamp < time_now - os->base_ts ) { op = os->current->op; @@ -274,14 +279,14 @@ return op; } -ogg_packet * get_next_audio_op() +ogg_packet * get_next_audio_op(struct timeval now) { - return get_next_op(audio_stream); + return get_next_op(audio_stream, now); } -ogg_packet * get_next_video_op() +ogg_packet * get_next_video_op(struct timeval now) { - return get_next_op(video_stream); + return get_next_op(video_stream, now); } int audio_is_eos() Modified: trunk/simpleclient/stresstest/file.h =================================================================== --- trunk/simpleclient/stresstest/file.h 2008-07-01 15:42:30 UTC (rev 1437) +++ trunk/simpleclient/stresstest/file.h 2008-07-01 15:52:43 UTC (rev 1438) @@ -1,15 +1,21 @@ #ifndef __FILE_H__ #define __FILE_H__ +#ifdef WIN32 +#include <windows.h> +#else +#include <time.h> +#endif + #include <ogg/ogg.h> -#define SPEEX_FRAME_DURATION 20 -#define SPEEX_SAMPLING_RATE 8000 +static const int SPEEX_FRAME_DURATION = 20; +static const int SPEEX_SAMPLING_RATE = 8000; -void load_ogg_file(const char *filename); +int load_ogg_file(const char *filename); -ogg_packet * get_next_audio_op(); -ogg_packet * get_next_video_op(); +ogg_packet * get_next_audio_op(struct timeval now); +ogg_packet * get_next_video_op(struct timeval now); int audio_is_eos(); int video_is_eos(); Modified: trunk/simpleclient/stresstest/stresstest.c =================================================================== --- trunk/simpleclient/stresstest/stresstest.c 2008-07-01 15:42:30 UTC (rev 1437) +++ trunk/simpleclient/stresstest/stresstest.c 2008-07-01 15:52:43 UTC (rev 1438) @@ -29,16 +29,31 @@ #include "file.h" #ifdef WIN32 -// Only under windows... +#include <process.h> +typedef uintptr_t a_thread; +#define STDCALL __stdcall +#define snprintf _snprintf #undef main +#else +#include <pthread.h> +typedef pthread_t a_thread; +#define STDCALL #endif -#define MAX_CALLS 1 +static const char STRESS_CMD_UNMUTE_AUDIO[] = "unmute_audio"; +static const char STRESS_CMD_MUTE_AUDIO[] = "mute_audio"; +static const char STRESS_CMD_UNMUTE_VIDEO[] = "unmute_video"; +static const char STRESS_CMD_MUTE_VIDEO[] = "mute_video"; +static const char STRESS_CMD_SHOW_STATE[] = "show_state"; +static const char STRESS_CMD_QUIT[] = "quit"; -#define TEST_OK 0 -#define TEST_NO_CONNECTION -1 -#define TEST_NO_MEDIA -2 -#define TEST_UNKNOWN_ERROR -99 +enum +{ + TEST_OK = 0, + TEST_NO_CONNECTION = -1, + TEST_NO_MEDIA = -2, + TEST_UNKNOWN_ERROR = -99, +}; static const int format = IAXC_FORMAT_H263 | @@ -63,6 +78,7 @@ static int connect_timeout_ms = 5000; static int video_frames_count = 0; static int audio_frames_count = 0; +static int audio_sent_count = 0; static struct timeval start_time; @@ -91,8 +107,54 @@ va_end(ap); } +static int +create_thread(a_thread *thread, + unsigned int (STDCALL * thread_func)(void *), + void *args, unsigned int *thread_id) +{ + int ret = 0; +#ifdef WIN32 + *thread = (uintptr_t)_beginthreadex(NULL, 0, thread_func, + (void *)args, 0, thread_id); + + if ( thread == 0 ) + ret = errno; +#else + void * (*func)(void *) = (void * (*)(void *))thread_func; + + ret = pthread_create(thread, NULL, func, args); +#endif + + return ret; +} + +static struct timeval +get_now(void) +{ + struct timeval tv; +#ifdef WIN32 + FILETIME ft; + LARGE_INTEGER li; + __int64 t; + static int tzflag; + const __int64 EPOCHFILETIME = 116444736000000000i64; + + GetSystemTimeAsFileTime(&ft); + li.LowPart = ft.dwLowDateTime; + li.HighPart = ft.dwHighDateTime; + t = li.QuadPart; /* In 100-nanosecond intervals */ + t -= EPOCHFILETIME; /* Offset to the Epoch time */ + t /= 10; /* In microseconds */ + tv.tv_sec = (long)(t / 1000000); + tv.tv_usec = (long)(t % 1000000); +#else + gettimeofday(&tv, 0); +#endif + return tv; +} + /* routine used to shutdown and close nicely.*/ -void hangup_and_exit(int code) +void hangup_call() { mylog("Dump call\n"); iaxc_dump_call(); @@ -102,8 +164,6 @@ iaxc_stop_processing_thread(); mylog("Calling iaxc_shutdown...\n"); iaxc_shutdown(); - mylog("Exiting with code %d\n", code); - exit(code); } void signal_handler(int signum) @@ -117,7 +177,6 @@ void fatal_error(char *err) { mylog("FATAL ERROR: %s\n", err); - exit(TEST_UNKNOWN_ERROR); } int levels_callback(float input, float output) { @@ -188,12 +247,12 @@ void usage() { - printf("Usage: stresstest <options>\n\n" + printf("Usage: stresstest <options> <dial_string>\n\n" "available options:\n" " -F <codec> <framerate> <bitrate> <width> <height> <fragsize> set video parameters\n" " -o <filename> media file to run\n" - " -v stop sending video\n" - " -a stop sending audio\n" + " -a start with audio muted\n" + " -v start with video 'muted'\n" " -l run file in a loop\n" " -n dump periodic netstats to log file\n" " -t <TIMEOUT> terminate call after TIMEOUT seconds\n" @@ -253,12 +312,88 @@ return (t1->tv_sec - t0->tv_sec) * 1000L + (t1->tv_usec - t0->tv_usec) / 1000L; } +unsigned int STDCALL check_for_command(void *param) +{ + int *cmd_thread_ready = (int *)param; + + *cmd_thread_ready = 1; + + while ( 1 ) + { + char data[512]; + char *str; + + if ( fgets(data, sizeof(data), stdin) ) + { + + data[sizeof(data) - 1] = 0; + + if ( !(str = strtok(data, "\n")) ) + { + mylog("WARNING: invalid input\n"); + } + else if ( !strncmp(str, STRESS_CMD_UNMUTE_AUDIO, + strlen(STRESS_CMD_UNMUTE_AUDIO)) ) + { + // mylog("got command to unmute audio\n"); + send_audio = 1; + } + else if ( !strncmp(str, STRESS_CMD_MUTE_AUDIO, + strlen(STRESS_CMD_MUTE_AUDIO)) ) + { + // mylog("got command to mute audio\n"); + send_audio = 0; + } + else if ( !strncmp(str, STRESS_CMD_UNMUTE_VIDEO, + strlen(STRESS_CMD_UNMUTE_VIDEO)) ) + { + // mylog("got command to unmute video\n"); + send_video = 1; + } + else if ( !strncmp(str, STRESS_CMD_MUTE_VIDEO, + strlen(STRESS_CMD_MUTE_VIDEO)) ) + { + // mylog("got command to mute video\n"); + send_video = 0; + } + else if ( !strncmp(str, STRESS_CMD_SHOW_STATE, + strlen(STRESS_CMD_SHOW_STATE)) ) + { + mylog("got command to show state:\n"); + mylog("running = %d call_established = %d\n", + running, call_established); + mylog("send_video = %d send audio = %d\n", + send_video, send_audio); + mylog("audio frames recvd = %d video frames recvd = %d\n", + audio_frames_count, video_frames_count); + mylog("audio frames sent = %d\n\n", audio_sent_count); + } + else if ( !strncmp(str, STRESS_CMD_QUIT, + strlen(STRESS_CMD_QUIT)) ) + { + mylog("got command to quit\n"); + running = 0; + } + else + { + mylog("invalid input: '%s'\n", str); + } + } + } + + return 0; +} + int main(int argc, char **argv) { int i; char *dest = NULL; char *ogg_file = NULL; int loop = 0; + a_thread command_thread = 0; + unsigned int command_thread_id; + int ret = -1; + int cmd_thread_ready = 0; /* install signal handler to catch CRTL-Cs */ signal(SIGINT, signal_handler); @@ -331,24 +466,34 @@ if ( dest == NULL ) { mylog("No destination, quitting\n"); - return -1; + goto exit; } if ( ogg_file ) - load_ogg_file(ogg_file); + { + if ( load_ogg_file(ogg_file) ) + { + mylog("Failed loading ogg file. Quitting.\n"); + goto exit; + } + } else mylog("No media file, running dry\n"); // Get start time for timeouts - gettimeofday(&start_time, NULL); + start_time = get_now(); // Initialize iaxclient iaxc_video_format_set(formatp, format, framerate, bitrate, width, height, fragsize); iaxc_set_test_mode(1); - if (iaxc_initialize(MAX_CALLS)) + if (iaxc_initialize(1)) + { fatal_error("cannot initialize iaxclient!"); + ret = TEST_UNKNOWN_ERROR; + goto exit; + } iaxc_set_formats(IAXC_FORMAT_SPEEX, IAXC_FORMAT_SPEEX); iaxc_video_bypass_jitter(0); @@ -358,42 +503,71 @@ // Crank the engine if ( iaxc_start_processing_thread() < 0 ) + { fatal_error("failed iaxc_start_processing_thread()\n"); + ret = TEST_UNKNOWN_ERROR; + goto exit; + } + // spin a thread to check for commands from stdin + if ( ret = create_thread(&command_thread, + &check_for_command, + (void *)&cmd_thread_ready, &command_thread_id) ) + { + mylog("failed creating command thread\n"); + goto exit; + } + else + { + while ( !cmd_thread_ready ) + iaxc_millisleep(10); + } + // Dial out if ( iaxc_call(dest) < 0 ) + { fatal_error("failed iaxc_call()"); + ret = TEST_UNKNOWN_ERROR; + goto exit; + } // Wait for the call to be established; while ( !call_established && running ) { struct timeval now; - gettimeofday(&now, NULL); + now = get_now(); if ( connect_timeout_ms > 0 && msecdiff(&start_time, &now) > connect_timeout_ms ) - hangup_and_exit(TEST_NO_CONNECTION); + { + hangup_call(); + ret = TEST_NO_CONNECTION; + goto exit; + } iaxc_millisleep(5); } running = 1; while ( running ) { - struct timeval now; + struct timeval now = get_now(); // We only need this if we actually want to send something - if ( ogg_file && ( send_audio || send_video ) ) + if ( ogg_file ) { ogg_packet *op; - op = get_next_audio_op(); + op = get_next_audio_op(now); if ( !loop && audio_is_eos() ) break; if ( send_audio && op != NULL && op->bytes > 0 ) + { iaxc_push_audio(op->packet, op->bytes, SPEEX_SAMPLING_RATE * SPEEX_FRAME_DURATION / 1000); + audio_sent_count++; + } - op = get_next_video_op(); + op = get_next_video_op(now); if ( !loop && video_is_eos() ) break; if ( send_video && op != NULL && op->bytes > 0 ) @@ -404,7 +578,6 @@ iaxc_millisleep(5); // Exit after a positive timeout - gettimeofday(&now, NULL); if ( call_timeout_ms > 0 && msecdiff(&start_time, &now) > call_timeout_ms ) running = 0; @@ -414,8 +587,14 @@ audio_frames_count, video_frames_count); if ( audio_frames_count == 0 && video_frames_count == 0 ) - hangup_and_exit(TEST_NO_MEDIA); + ret = TEST_NO_MEDIA; else - hangup_and_exit(TEST_OK); - return 0; + ret = TEST_OK; + + hangup_call(); + +exit: + mylog("Exiting with code %d\n", ret); + + return ret; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |