From: <jpg...@us...> - 2007-09-21 22:26:11
|
Revision: 1151 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1151&view=rev Author: jpgrayson Date: 2007-09-21 15:26:11 -0700 (Fri, 21 Sep 2007) Log Message: ----------- Put more video-specific code in video.c. Remove some unused code. Modified Paths: -------------- trunk/lib/codec_theora.c trunk/lib/iaxclient_lib.c trunk/lib/video.c trunk/lib/video.h Modified: trunk/lib/codec_theora.c =================================================================== --- trunk/lib/codec_theora.c 2007-09-20 21:30:19 UTC (rev 1150) +++ trunk/lib/codec_theora.c 2007-09-21 22:26:11 UTC (rev 1151) @@ -470,8 +470,6 @@ if ( !c->encstate ) goto bail; - video_reset_codec_stats(c); - c->format = format; c->width = w; c->height = h; Modified: trunk/lib/iaxclient_lib.c =================================================================== --- trunk/lib/iaxclient_lib.c 2007-09-20 21:30:19 UTC (rev 1150) +++ trunk/lib/iaxclient_lib.c 2007-09-21 22:26:11 UTC (rev 1151) @@ -772,42 +772,10 @@ } #ifdef USE_VIDEO -#define VIDEO_STATS_INTERVAL 1000 // In ms -static struct timeval video_stats_start; - -static void send_video_stats() -{ - iaxc_event e; - struct timeval now; - long time; - - // make sure there is a call to do stats on - if (selected_call < 0) - return; - - gettimeofday(&now, NULL); - time = iaxci_msecdiff(&now, &video_stats_start); - if ( time > VIDEO_STATS_INTERVAL ) - { - video_get_stats(&calls[selected_call], &e.ev.videostats.stats, 1); -/* fprintf(stderr, "Video stats: sent_slices=%ld, acc_sent_size=%ld, outbound_frames=%ld, avg_outbound_fps=%f, avg_outbound_bps=%ld, " - "received_slices=%ld, acc_recv_size=%ld, inbound_frames=%ld, dropped_frames=%ld, avg_inbound_fps=%f, avg_inbound_bps=%ld\n", - stats.sent_slices, stats.acc_sent_size, stats.outbound_frames, stats.avg_outbound_fps, stats.avg_outbound_bps, - stats.received_slices, stats.acc_recv_size, stats.inbound_frames, stats.dropped_frames, stats.avg_inbound_fps, stats.avg_inbound_bps);*/ - e.type = IAXC_EVENT_VIDEOSTATS; - e.ev.videostats.callNo = selected_call; - iaxci_post_event(e); - - video_stats_start = now; - } -} - static THREADFUNCDECL(video_proc_thread_func) { struct iaxc_call *call; - gettimeofday(&video_stats_start, NULL); - while ( !video_proc_thread_flag ) { if (selected_call >= 0) @@ -816,9 +784,8 @@ call = NULL; video_send_video(call, selected_call); + video_send_stats(call); - send_video_stats(); - // Tight spinloops are bad, mmmkay? iaxc_millisleep(LOOP_SLEEP); } @@ -827,7 +794,7 @@ return 0; } -#endif /* USE_VIDEO */ +#endif EXPORT int iaxc_start_processing_thread() { Modified: trunk/lib/video.c =================================================================== --- trunk/lib/video.c 2007-09-20 21:30:19 UTC (rev 1150) +++ trunk/lib/video.c 2007-09-21 22:26:11 UTC (rev 1151) @@ -284,6 +284,62 @@ call->vencoder->fragsize = fs; } +static void reset_codec_stats(struct iaxc_video_codec *vcodec) +{ + if ( !vcodec ) + return; + + memset(&vcodec->video_stats, 0, sizeof(struct iaxc_video_stats)); + gettimeofday(&vcodec->video_stats.start_time, 0); +} + +static void reset_video_stats(struct iaxc_call *call) +{ + if ( !call ) + return; + + reset_codec_stats(call->vdecoder); + reset_codec_stats(call->vencoder); +} + +/* Collect and return video statistics. Also reset statistics if required. + * Returns a pointer to the data. + * Right now we use two different codecs for encoding and decoding. We need + * to collate information from both and wrap it into one nice struct. + */ +static int get_stats(struct iaxc_call *call, struct iaxc_video_stats *stats, + int reset) +{ + if ( !call || !stats ) + return -1; + + memset(stats, 0, sizeof(*stats)); + + if ( call->vencoder ) + { + stats->sent_slices = call->vencoder->video_stats.sent_slices; + stats->acc_sent_size = call->vencoder->video_stats.acc_sent_size; + stats->outbound_frames = call->vencoder->video_stats.outbound_frames; + stats->avg_outbound_bps = call->vencoder->video_stats.avg_outbound_bps; + stats->avg_outbound_fps = call->vencoder->video_stats.avg_outbound_fps; + } + + if ( call->vdecoder ) + { + stats->received_slices = call->vdecoder->video_stats.received_slices; + stats->acc_recv_size = call->vdecoder->video_stats.acc_recv_size; + stats->inbound_frames = call->vdecoder->video_stats.inbound_frames; + stats->dropped_frames = call->vdecoder->video_stats.dropped_frames; + stats->avg_inbound_bps = call->vdecoder->video_stats.avg_inbound_bps; + stats->avg_inbound_fps = call->vdecoder->video_stats.avg_inbound_fps; + } + + if ( reset ) + reset_video_stats(call); + + return 0; +} + /* TODO: The encode parameter to this function is unused within this * function. However, clients of this function still use this parameter. * What ends up happening is we instantiate the codec encoder/decoder @@ -303,52 +359,43 @@ */ static struct iaxc_video_codec *create_codec(int format, int encode) { + struct iaxc_video_codec * vcodec = 0; + iaxci_usermsg(IAXC_TEXT_TYPE_NOTICE, "Creating codec format 0x%x", format); + switch ( format ) { case IAXC_FORMAT_H261: case IAXC_FORMAT_H263: case IAXC_FORMAT_H263_PLUS: case IAXC_FORMAT_MPEG4: -#ifdef USE_FFMPEG - return codec_video_ffmpeg_new(format, - iaxc_video_width, - iaxc_video_height, - iaxc_video_framerate, - iaxc_video_bitrate, - iaxc_video_fragsize); -#else - return NULL; -#endif - case IAXC_FORMAT_H264: #ifdef USE_FFMPEG - return codec_video_ffmpeg_new(format, + vcodec = codec_video_ffmpeg_new(format, iaxc_video_width, iaxc_video_height, iaxc_video_framerate, iaxc_video_bitrate, iaxc_video_fragsize); -#else - return NULL; #endif + break; -#ifdef USE_THEORA case IAXC_FORMAT_THEORA: - return codec_video_theora_new(format, +#ifdef USE_THEORA + vcodec = codec_video_theora_new(format, iaxc_video_width, iaxc_video_height, iaxc_video_framerate, iaxc_video_bitrate, iaxc_video_fragsize); -#else - return NULL; #endif + break; } - // Must never happen... - return NULL; + reset_codec_stats(vcodec); + + return vcodec; } /* @@ -422,9 +469,7 @@ /* It is okay if we do not get any video; video capture may be * disabled. */ - if ( !videobuf || - (iaxc_video_prefs & IAXC_VIDEO_PREF_CAPTURE_DISABLE) - ) + if ( !videobuf || (iaxc_video_prefs & IAXC_VIDEO_PREF_CAPTURE_DISABLE) ) return 0; // Send the raw frame to the main app, if necessary @@ -434,7 +479,9 @@ iaxc_video_prefs & IAXC_VIDEO_PREF_RECV_RGB32); } - if ( sel_call < 0 || !call || !(call->state & (IAXC_CALL_STATE_COMPLETE | IAXC_CALL_STATE_OUTGOING) ) ) + if ( sel_call < 0 || !call || + !(call->state & (IAXC_CALL_STATE_COMPLETE | + IAXC_CALL_STATE_OUTGOING)) ) { return -1; } @@ -498,7 +545,7 @@ } // Statistics - gettimeofday(&now, NULL); + gettimeofday(&now, 0); call->vencoder->video_stats.outbound_frames++; time = iaxci_msecdiff(&now, &call->vencoder->video_stats.start_time); if ( time > 0 ) @@ -600,7 +647,7 @@ } /* Statistics */ - gettimeofday(&now, NULL); + gettimeofday(&now, 0); time = iaxci_msecdiff(&now, &call->vdecoder->video_stats.start_time); call->vdecoder->video_stats.received_slices++; call->vdecoder->video_stats.acc_recv_size += encoded_video_len; @@ -727,7 +774,6 @@ yuv2rgb_tables_initialized = 1; } - /* * Faster function to convert YUV420 images to RGB32 * RGB32: 0xFFRRGGBB @@ -784,133 +830,36 @@ } } -/* - * Original function that converts YUV420 images to RGB32 - * RGB32: 0xFFRRGGBB - * Make sure the src and dest buffers have enough room - * dest should be width * height * 4 bytes in size - * Based on the formulas found at http://en.wikipedia.org/wiki/YUV - */ -// void iaxc_YUV420_to_RGB32(int width, int height, char *src, char *dest) -// { -// int i; -// unsigned char * y = (unsigned char *)src; -// unsigned char * u = y + width * height; -// unsigned char * v = u + width * height / 4; -// unsigned int * dst = (unsigned int *)dest; -// -// for ( i = 0; i < height; i++ ) -// { -// int j; -// -// unsigned char * uu = u; -// unsigned char * vv = v; -// -// for ( j = 0; j < width; j++ ) -// { -// int yyy = *y - 16; -// int uuu = *uu - 128; -// int vvv = *vv - 128; -// -// int r = ( 298*yyy + 409*vvv + 128) >> 8; -// int g = ( 298*yyy - 100*uuu - 208*vvv + 128) >> 8; -// int b = ( 298*yyy + 516*uuu + 128) >> 8; -// -// // Clip values to make sure they fit in range -// if ( r < 0 ) -// r = 0; -// else if ( r > 255 ) -// r = 255; -// -// if ( g < 0 ) -// g = 0; -// else if ( g > 255 ) -// g = 255; -// -// if ( b < 0 ) -// b = 0; -// else if ( b > 255 ) -// b = 255; -// -// *(dst++) = 0xff000000 | -// ((unsigned char)r << 16) | -// ((unsigned char)g << 8) | -// ((unsigned char)b << 0); -// -// y++; -// -// if ( j & 1 ) -// { -// uu++; -// vv++; -// } -// } -// -// if ( i & 1 ) -// { -// u += width >> 1; -// v += width >> 1; -// } -// } -// } - int iaxc_is_camera_working() { return video_driver.is_camera_working(&video_driver); } -static void reset_video_stats(struct iaxc_call *call) +int video_send_stats(struct iaxc_call * call) { - if ( !call ) - return; + const long video_stats_interval = 1000; /* milliseconds */ + static struct timeval video_stats_start = {0, 0}; + iaxc_event e; + struct timeval now; - video_reset_codec_stats(call->vdecoder); - video_reset_codec_stats(call->vencoder); -} - -// Collect and return video statistics -// Also reset statistics if required; -// Returns a pointer to the data -// Right now we use two different codecs for encoding and decoding. We need to collate information -// from both and wrap it into one nice struct -int video_get_stats(struct iaxc_call *call, struct iaxc_video_stats *stats, - int reset) -{ - if ( !call || !stats ) + if ( !call ) return -1; - memset(stats, 0, sizeof(*stats)); + if ( video_stats_start.tv_sec == 0 && video_stats_start.tv_usec == 0 ) + gettimeofday(&video_stats_start, 0); - if ( call->vencoder != NULL ) - { - stats->sent_slices = call->vencoder->video_stats.sent_slices; - stats->acc_sent_size = call->vencoder->video_stats.acc_sent_size; - stats->outbound_frames = call->vencoder->video_stats.outbound_frames; - stats->avg_outbound_bps = call->vencoder->video_stats.avg_outbound_bps; - stats->avg_outbound_fps = call->vencoder->video_stats.avg_outbound_fps; - } + gettimeofday(&now, 0); - if ( call->vdecoder != NULL ) + if ( iaxci_msecdiff(&now, &video_stats_start) > video_stats_interval ) { - stats->received_slices = call->vdecoder->video_stats.received_slices; - stats->acc_recv_size = call->vdecoder->video_stats.acc_recv_size; - stats->inbound_frames = call->vdecoder->video_stats.inbound_frames; - stats->dropped_frames = call->vdecoder->video_stats.dropped_frames; - stats->avg_inbound_bps = call->vdecoder->video_stats.avg_inbound_bps; - stats->avg_inbound_fps = call->vdecoder->video_stats.avg_inbound_fps; + get_stats(call, &e.ev.videostats.stats, 1); + e.type = IAXC_EVENT_VIDEOSTATS; + e.ev.videostats.callNo = selected_call; + iaxci_post_event(e); + + video_stats_start = now; } - if ( reset ) - reset_video_stats(call); - return 0; } -void video_reset_codec_stats(struct iaxc_video_codec *vcodec) -{ - if ( vcodec == NULL ) return; - - memset(&vcodec->video_stats, 0, sizeof(struct iaxc_video_stats)); - gettimeofday(&vcodec->video_stats.start_time, NULL); -} - Modified: trunk/lib/video.h =================================================================== --- trunk/lib/video.h 2007-09-20 21:30:19 UTC (rev 1150) +++ trunk/lib/video.h 2007-09-21 22:26:11 UTC (rev 1151) @@ -52,15 +52,12 @@ int video_destroy(void); -int video_get_stats(struct iaxc_call * call, - struct iaxc_video_stats * stats, int reset); - -void video_reset_codec_stats(struct iaxc_video_codec * codec); - int video_send_video(struct iaxc_call *, int); int video_recv_video(struct iaxc_call * call, int sel_call, void * encoded_video, int encoded_video_len, unsigned int ts, int format); +int video_send_stats(struct iaxc_call *); + #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |