From c20b0ee03952b83ad2acfb6dd1e5049dda4091e6 Mon Sep 17 00:00:00 2001 From: Niels Elburg Date: Mon, 11 Apr 2005 01:22:52 +0000 Subject: [PATCH] Drop trigger messages on high load git-svn-id: svn://code.dyne.org/veejay/trunk@286 eb8d1916-c9e9-0310-b8de-cf0c9472ead5 --- veejay-current/libvjnet/vj-server.c | 143 +++++++++++++++++++++++++++- veejay-current/veejay/vims.h | 24 ++--- veejay-current/veejay/vj-event.c | 2 +- 3 files changed, 151 insertions(+), 18 deletions(-) diff --git a/veejay-current/libvjnet/vj-server.c b/veejay-current/libvjnet/vj-server.c index 0722281f..88a64917 100644 --- a/veejay-current/libvjnet/vj-server.c +++ b/veejay-current/libvjnet/vj-server.c @@ -441,6 +441,107 @@ int vj_server_poll(vj_server * vje) return 0; } +static int _vj_server_empty_queue(vj_server *vje, int link_id) +{ + // ensure message queue is empty!! + int num_msg = 0; + vj_link **Link = (vj_link**) vje->link; + vj_message **v = Link[link_id]->m_queue; + + int i; + for( i = 0; i < VJ_MAX_PENDING_MSG; i ++ ) + { + if( v[i]->msg ) + free(v[i]->msg); + v[i]->msg = NULL; + v[i]->len = 0; + } + Link[link_id]->n_queued = 0; + Link[link_id]->n_retrieved = 0; + return 1; +} + +static int _vj_parse_highpriority_msg(vj_server *vje,int link_id, char *buf, int buf_len ) +{ + int nmsgs = 0; + int i = 0; + char *s = buf; + int num_msg = 0; + vj_link **Link = (vj_link**) vje->link; + vj_message **v = Link[link_id]->m_queue; + + while( i < buf_len ) + { + while( s[i] != 'V' && s[i+4] != 'D' ) + i ++ ; + + if( s[i] == 'V' && s[i+4] == 'D' ) + { // found message + char tmp_len[4]; + char net_id[4]; + int strlen = 0; + int netid = 0; + bzero(tmp_len,4); + bzero(net_id,4 ); + strncpy( tmp_len, s + (i + 1 ), 3 ); + if(sscanf(tmp_len,"%03d", &strlen)) + { + i += 5; + strncpy( net_id, s + i , 3 ); + if(sscanf(net_id, "%03d", &netid )) + { + if(netid >= 255 ) + { + v[num_msg]->len = strlen; + v[num_msg]->msg = (char*)strndup( s + i , strlen ); + num_msg ++; + if(num_msg == VJ_MAX_PENDING_MSG ) + return num_msg; // cant take more + } + } + i += strlen; + } + else + { + i ++; + } + } + } + return num_msg; +} + + +static int _vj_get_n_msg_waiting(char *buf, int buf_len, int *offset ) +{ + int nmsgs = 0; + int i = 0; + char *s = buf; + while( i < buf_len ) + { + while( s[i] != 'V' && s[i+4] != 'D' ) + i ++ ; + + if( s[i] == 'V' && s[i+4] == 'D' ) + { // found message + char tmp_len[4]; + int strlen = 0; + bzero(tmp_len,4); + strncpy( tmp_len, s + (i + 1 ), 3 ); + if(sscanf(tmp_len,"%03d", &strlen)) + nmsgs++; + i += 5; + i += strlen; + if( nmsgs >= VJ_MAX_PENDING_MSG ) + { + *offset = i; + return VJ_MAX_PENDING_MSG; + } + } + } + return nmsgs; +} + + int _vj_server_parse_msg( vj_server *vje,int link_id, char *buf, int buf_len ) { int i = 0; @@ -460,12 +561,15 @@ int _vj_server_parse_msg( vj_server *vje,int link_id, char *buf, int buf_len ) if( n == 1) { i += 5; // skip header + while( (v[num_msg]->len > 0 ) || v[num_msg]->msg != NULL ) + num_msg ++; + + if(num_msg == VJ_MAX_PENDING_MSG) + return VJ_MAX_PENDING_MSG; + v[num_msg]->len = len; - - if(v[num_msg]->msg != NULL) - free( v[num_msg]->msg ); - v[num_msg]->msg = (char*)strndup( buf + i , len ); + i += len; num_msg ++; } @@ -558,7 +662,36 @@ int vj_server_update( vj_server *vje, int id ) } } - return _vj_server_parse_msg( vje, id, vje->recv_buf,n ); +// return _vj_server_parse_msg( vje, id, vje->recv_buf,n ); + + // ensure all is empty + _vj_server_empty_queue(vje, id); + char *tmp_buf = vje->recv_buf; + int bytes_left = n; + int skip_bytes = 0; + + while( bytes_left > 0 ) + { + int n_msg = _vj_get_n_msg_waiting( tmp_buf, bytes_left, &skip_bytes ); + if( n_msg >= VJ_MAX_PENDING_MSG) + { + // cant skip all! + int hmsg = _vj_parse_highpriority_msg( vje, id,tmp_buf, skip_bytes ); + if(hmsg == VJ_MAX_PENDING_MSG) + { + veejay_msg(VEEJAY_MSG_ERROR, "Link %d is acting very sucispous !", id); + return VJ_MAX_PENDING_MSG; + } + bzero( tmp_buf, skip_bytes ); + tmp_buf += skip_bytes; + bytes_left -= skip_bytes; + } + else + { + return _vj_server_parse_msg( vje, id, tmp_buf, bytes_left ); + } + } + return 0; } void vj_server_shutdown(vj_server *vje) { diff --git a/veejay-current/veejay/vims.h b/veejay-current/veejay/vims.h index 53462524..8d75baae 100644 --- a/veejay-current/veejay/vims.h +++ b/veejay-current/veejay/vims.h @@ -8,8 +8,8 @@ enum { NET_SWITCH_CLIP_TAG = 13, NET_RESIZE_SDL_SCREEN = 12, NET_SET_PLAY_MODE = 2, - NET_EFFECT_LIST = 15, - NET_EDITLIST_LIST = 201, + NET_EFFECT_LIST = 256, + NET_EDITLIST_LIST = 257, NET_SET_MODE_AND_GO = 3, NET_STREAM_COLOR = 6, NET_RGB_PARAMETER_TYPE = 199, @@ -29,7 +29,7 @@ enum { NET_SCREENSHOT = 54, NET_BUNDLE_FILE = 55, NET_BUNDLE_SAVE = 56, - NET_LIST_BUNDLES = 57, + NET_LIST_BUNDLES = 258, NET_BUNDLE_CAPTURE = 58, NET_VIDEO_INFORMATION = 202, NET_AUDIO_ENABLE = 4, @@ -68,10 +68,10 @@ enum { NET_CLIP_CLEAR_FREEZE = 117, NET_CLIP_LOAD_CLIPLIST = 124, NET_CLIP_SAVE_CLIPLIST = 125, - NET_CLIP_HISTORY_LIST = 126, + NET_CLIP_HISTORY_LIST = 259, NET_CLIP_DEL_ALL = 135, NET_CLIP_COPY = 139, - NET_CLIP_LIST = 205, + NET_CLIP_LIST = 260, NET_SET_MARKER_START = 127, NET_SET_MARKER_END = 128, NET_CLIP_REC_START = 130, @@ -81,7 +81,7 @@ enum { NET_CLIP_RENDER_SELECT = 129, NET_CLIP_RENDER_TO = 138, NET_CLIP_RENDER_MOVE = 137, - NET_CLIP_RENDERLIST = 98, + NET_CLIP_RENDERLIST = 261, NET_CLIP_UPDATE = 134, NET_TAG_SELECT = 140, NET_TAG_ACTIVATE = 141, @@ -96,13 +96,13 @@ enum { NET_TAG_OFFLINE_REC_STOP = 151, NET_TAG_REC_START = 152, NET_TAG_REC_STOP = 153, - NET_TAG_LIST = 206, - NET_TAG_DEVICES = 207, + NET_TAG_LIST = 262, + NET_TAG_DEVICES = 263, NET_TAG_CHAIN_ENABLE = 156, NET_TAG_CHAIN_DISABLE = 157, NET_TAG_SET_DESCRIPTION = 158, #ifdef HAVE_V4L - NET_TAG_GET_V4L = 159, + NET_TAG_GET_V4L = 264, NET_TAG_SET_BRIGHTNESS = 160, NET_TAG_SET_CONTRAST = 161, NET_TAG_SET_HUE = 162, @@ -113,14 +113,14 @@ enum { NET_TAG_NEW_MCAST = 166, NET_CHAIN_CHANNEL_INC = 170, NET_CHAIN_CHANNEL_DEC = 171, - NET_CHAIN_GET_ENTRY = 208, + NET_CHAIN_GET_ENTRY = 265, NET_CHAIN_TOGGLE_ALL = 172, NET_CHAIN_ENABLE = 175, NET_CHAIN_DISABLE = 176, NET_CHAIN_CLEAR = 177, NET_CHAIN_FADE_IN = 178, NET_CHAIN_FADE_OUT = 179, - NET_CHAIN_LIST = 209, + NET_CHAIN_LIST = 266, NET_CHAIN_SET_ENTRY = 180, NET_CHAIN_ENTRY_SET_EFFECT = 181, NET_CHAIN_ENTRY_SET_PRESET = 182, @@ -138,7 +138,7 @@ enum { NET_FULLSCREEN = 222, NET_OUTPUT_Y4M_START = 71, NET_OUTPUT_Y4M_STOP = 72, - NET_GET_FRAME = 225, + NET_GET_FRAME = 275, NET_SAMPLE_MODE = 250, NET_BEZERK = 251, NET_DEBUG_LEVEL = 252, diff --git a/veejay-current/veejay/vj-event.c b/veejay-current/veejay/vj-event.c index 421b0567..cdc88317 100644 --- a/veejay-current/veejay/vj-event.c +++ b/veejay-current/veejay/vj-event.c @@ -43,7 +43,7 @@ #include /* Highest possible SDL Key identifier */ #define MAX_SDL_KEY 350 -#define NET_MAX 256 +#define NET_MAX 300 #define MSG_MIN_LEN 5