Skip to content

Commit

Permalink
Refactor towards changing the vomp monitor interface
Browse files Browse the repository at this point in the history
  • Loading branch information
lakeman committed Aug 9, 2012
1 parent 7705676 commit 736a8f4
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 152 deletions.
84 changes: 12 additions & 72 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,6 @@ int monitor_process_command(struct monitor_context *c)
c->flags|=MONITOR_PEERS;
else if (!strcasecmp(cmd,"ignore peers"))
c->flags&=~MONITOR_PEERS;
else if (sscanf(cmd,"FASTAUDIO:%x:%d",&callSessionToken,&flag)==2)
{
// TODO half implemented
int i;
for(i=0;i<vomp_call_count;i++)
if (vomp_call_states[i].local.session==callSessionToken
||callSessionToken==0) {
vomp_call_states[i].fast_audio=flag;
break;
}
}
else if (sscanf(cmd,"call %s %s %s",sid,localDid,remoteDid)==3) {
DEBUG("here");
int gotSid = 0;
Expand Down Expand Up @@ -411,26 +400,18 @@ int monitor_process_command(struct monitor_context *c)
vomp_dial(keyring->contexts[cn]->identities[in]->keypairs[kp]->public_key, (unsigned char *)sid, localDid, remoteDid);
}
}
}
else if (sscanf(cmd,"status %x",&callSessionToken)==1) {
int i;
for(i=0;i<vomp_call_count;i++)
if (vomp_call_states[i].local.session==callSessionToken
||callSessionToken==0) {
monitor_call_status(&vomp_call_states[i]);
}
} else if (sscanf(cmd,"ringing %x",&callSessionToken)==1) {
vomp_call_state *call=vomp_find_call_by_session(callSessionToken);
struct vomp_call_state *call=vomp_find_call_by_session(callSessionToken);
vomp_ringing(call);
} else if (sscanf(cmd,"pickup %x",&callSessionToken)==1) {
vomp_call_state *call=vomp_find_call_by_session(callSessionToken);
struct vomp_call_state *call=vomp_find_call_by_session(callSessionToken);
vomp_pickup(call);
}
else if (sscanf(cmd,"hangup %x",&callSessionToken)==1) {
vomp_call_state *call=vomp_find_call_by_session(callSessionToken);
struct vomp_call_state *call=vomp_find_call_by_session(callSessionToken);
vomp_hangup(call);
} else if (sscanf(cmd,"dtmf %x %s",&callSessionToken,digits)==2) {
vomp_call_state *call=vomp_find_call_by_session(callSessionToken);
struct vomp_call_state *call=vomp_find_call_by_session(callSessionToken);
if (call){
int i;
for(i=0;i<strlen(digits);i++) {
Expand Down Expand Up @@ -466,7 +447,7 @@ int monitor_process_data(struct monitor_context *c)
RETURN(-1);
}

vomp_call_state *call=vomp_find_call_by_session(c->sample_call_session_token);
struct vomp_call_state *call=vomp_find_call_by_session(c->sample_call_session_token);
if (!call) {
write_str(c->alarm.poll.fd,"\nERROR:No such call\n");
RETURN(-1);
Expand Down Expand Up @@ -507,33 +488,6 @@ int monitor_announce_bundle(rhizome_manifest *m)
return 0;
}

int monitor_call_status(vomp_call_state *call)
{
int i;
char msg[1024];
IN();
snprintf(msg,1024,"\nCALLSTATUS:%06x:%06x:%d:%d:%d:%s:%s:%s:%s\n",
call->local.session,call->remote.session,
call->local.state,call->remote.state,
call->fast_audio,
alloca_tohex_sid(call->local.sid),
alloca_tohex_sid(call->remote.sid),
call->local.did,call->remote.did);
msg[1023]=0;
for(i=monitor_socket_count -1;i>=0;i--) {
if (!(monitor_sockets[i].flags&MONITOR_VOMP))
continue;
if ( set_nonblock(monitor_sockets[i].alarm.poll.fd) == -1
|| write_str_nonblock(monitor_sockets[i].alarm.poll.fd, msg) == -1
|| set_block(monitor_sockets[i].alarm.poll.fd) == -1
) {
INFOF("Tearing down monitor client #%d", i);
monitor_client_close(&monitor_sockets[i]);
}
}
RETURN(0);
}

int monitor_announce_peer(const unsigned char *sid)
{
char msg[1024];
Expand All @@ -550,27 +504,13 @@ int monitor_announce_unreachable_peer(const unsigned char *sid)
return 0;
}

int monitor_send_audio(vomp_call_state *call, int audio_codec, unsigned int start_time, unsigned int end_time, const unsigned char *audio, int audio_length)
{
if (0) DEBUGF("Tell call monitor about audio for call %06x:%06x",
call->local.session,call->remote.session);
int sample_bytes=vomp_sample_size(audio_codec);
char msg[1024 + MAX_AUDIO_BYTES];
/* All commands followed by binary data start with *len:, so that
they can be easily parsed at the far end, even if not supported.
Put newline at start of these so that receiving data in command
mode doesn't confuse the parser. */
int msglen = snprintf(msg, 1024,
"\n*%d:AUDIOPACKET:%06x:%06x:%d:%d:%d:%d:%d\n",
sample_bytes,
call->local.session,call->remote.session,
call->local.state,call->remote.state,
audio_codec, start_time, end_time);

bcopy(audio, &msg[msglen], sample_bytes);
msglen+=sample_bytes;
msg[msglen++]='\n';
monitor_tell_clients(msg, msglen, MONITOR_VOMP);
// test if any monitor clients are interested in a particular type of event
int monitor_client_interested(int mask){
int i;
for(i=monitor_socket_count -1;i>=0;i--) {
if (monitor_sockets[i].flags & mask)
return 1;
}
return 0;
}

Expand Down
39 changes: 7 additions & 32 deletions serval.h
Original file line number Diff line number Diff line change
Expand Up @@ -1028,32 +1028,8 @@ typedef struct vomp_sample_block {
unsigned char bytes[1024];
} vomp_sample_block;

typedef struct vomp_call_state {
struct sched_ent alarm;
vomp_call_half local;
vomp_call_half remote;
int initiated_call;
int fast_audio;
time_ms_t create_time;
time_ms_t last_activity;
time_ms_t audio_clock;
int audio_started;
// last local & remote status we sent to all interested parties
int last_sent_status;
unsigned char remote_codec_list[256];
int recent_sample_rotor;
vomp_sample_block recent_samples[VOMP_MAX_RECENT_SAMPLES];

int sample_pos;
unsigned int seen_samples[VOMP_MAX_RECENT_SAMPLES *4];
} vomp_call_state;

extern int vomp_call_count;
extern int vomp_active_call;
extern vomp_call_state vomp_call_states[VOMP_MAX_CALLS];


vomp_call_state *vomp_find_call_by_session(int session_token);
struct vomp_call_state;
struct vomp_call_state *vomp_find_call_by_session(int session_token);
int vomp_mdp_event(overlay_mdp_frame *mdp,
struct sockaddr_un *recvaddr,int recvaddrlen);
int vomp_mdp_received(overlay_mdp_frame *mdp);
Expand All @@ -1062,10 +1038,10 @@ int vomp_sample_size(int c);
int vomp_codec_timespan(int c);
int vomp_parse_dtmf_digit(char c);
int vomp_dial(unsigned char *local_sid, unsigned char *remote_sid, char *local_did, char *remote_did);
int vomp_pickup(vomp_call_state *call);
int vomp_hangup(vomp_call_state *call);
int vomp_ringing(vomp_call_state *call);
int vomp_send_status_remote_audio(vomp_call_state *call, int audio_codec, const unsigned char *audio, int audio_length);
int vomp_pickup(struct vomp_call_state *call);
int vomp_hangup(struct vomp_call_state *call);
int vomp_ringing(struct vomp_call_state *call);
int vomp_send_status_remote_audio(struct vomp_call_state *call, int audio_codec, const unsigned char *audio, int audio_length);


typedef struct command_line_option {
Expand Down Expand Up @@ -1113,11 +1089,10 @@ int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);

int monitor_setup_sockets();
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
int monitor_call_status(vomp_call_state *call);
int monitor_send_audio(vomp_call_state *call, int audio_codec, unsigned int start_time, unsigned int end_time, const unsigned char *audio, int audio_length);
int monitor_announce_peer(const unsigned char *sid);
int monitor_announce_unreachable_peer(const unsigned char *sid);
int monitor_tell_clients(char *msg, int msglen, int mask);
int monitor_client_interested(int mask);
extern int monitor_socket_count;


Expand Down
Loading

0 comments on commit 736a8f4

Please sign in to comment.