Skip to content

Commit

Permalink
send and process payload type and output encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ka9q committed May 4, 2024
1 parent da03f94 commit 49194d3
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 134 deletions.
141 changes: 71 additions & 70 deletions control.c

Large diffs are not rendered by default.

37 changes: 34 additions & 3 deletions dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void dump_metadata(FILE *fp,uint8_t const * const buffer,int length,bool newline

while(cp - buffer < length){
enum status_type const type = *cp++; // increment cp to length field

if(type == EOL)
break; // End of list

Expand Down Expand Up @@ -70,7 +70,7 @@ void dump_metadata(FILE *fp,uint8_t const * const buffer,int length,bool newline
case OUTPUT_DATA_SOURCE_SOCKET:
{
struct sockaddr_storage sock;
fprintf(fp,"data src %s",formatsock(decode_socket(&sock,cp,optlen)));
fprintf(fp,"data src %s",formatsock(decode_socket(&sock,cp,optlen)));
}
break;
case OUTPUT_DATA_DEST_SOCKET:
Expand Down Expand Up @@ -158,7 +158,7 @@ void dump_metadata(FILE *fp,uint8_t const * const buffer,int length,bool newline
fprintf(fp,"fe produces %s samples",decode_int8(cp,optlen) ? "real" : "complex");
break;
case KAISER_BETA:
fprintf(fp,"filter kaiser_beta %g",decode_float(cp,optlen));
fprintf(fp,"filter kaiser_beta %g",decode_float(cp,optlen));
break;
case FILTER_BLOCKSIZE:
fprintf(fp,"filter L %'d",decode_int(cp,optlen));
Expand Down Expand Up @@ -335,6 +335,37 @@ void dump_metadata(FILE *fp,uint8_t const * const buffer,int length,bool newline
case STATUS_INTERVAL:
fprintf(fp,"status interval %d",decode_int(cp,optlen));
break;
case OUTPUT_ENCODING:
{
int e = decode_int(cp,optlen);
fprintf(fp,"encoding %d ",e);
if(e >= NONE && e < UNUSED_ENCODING){
switch(e){
case NO_ENCODING:
fprintf(fp,"none");
break;
case S16LE:
fprintf(fp,"signed 16-bit little endian");
break;
case S16BE:
fprintf(fp,"signed 16-bit big endian");
break;
case OPUS:
fprintf(fp,"Opus");
break;
case F32:
fprintf(fp,"32-bit floating point");
break;
case AX25:
fprintf(fp,"AX.25 packet");
break;
default:
fprintf(fp,"unknown");
}
}
fprintf(fp,"\n");
}
break;
default:
fprintf(fp,"unknown type %d length %d",type,optlen);
break;
Expand Down
42 changes: 21 additions & 21 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ int main(int argc,char *argv[]){
while((c = getopt(argc,argv,"N:hvp:IV")) != -1){
switch(c){
case 'V': // Already shown above
exit(EX_OK);
exit(EX_OK);
case 'p':
FFTW_plan_timelimit = strtod(optarg,NULL);
break;
Expand All @@ -186,17 +186,17 @@ int main(int argc,char *argv[]){
exit(EX_USAGE);
}
}

// Graceful signal catch
signal(SIGPIPE,closedown);
signal(SIGINT,closedown);
signal(SIGKILL,closedown);
signal(SIGQUIT,closedown);
signal(SIGTERM,closedown);
signal(SIGTERM,closedown);
signal(SIGPIPE,SIG_IGN);
signal(SIGUSR1,verbosity);
signal(SIGUSR2,verbosity);

if(argc <= optind){
fprintf(stdout,"Configtable file missing\n");
exit(EX_NOINPUT);
Expand Down Expand Up @@ -287,10 +287,10 @@ static int loadconfig(char const * const file){
char const *p = config_getstring(Configtable,global,"iface",Iface);
if(p != NULL){
Iface = strdup(p);
Default_mcast_iface = Iface;
Default_mcast_iface = Iface;
}
}
// Overrides in [global] of compiled-in defaults
// Overrides in [global] of compiled-in defaults
{
char data_default[256];
snprintf(data_default,sizeof(data_default),"%s-pcm",Name);
Expand Down Expand Up @@ -365,7 +365,7 @@ static int loadconfig(char const * const file){
if(strcasecmp(sname,hardware) == 0){
if(setup_hardware(sname) != 0)
exit(EX_NOINPUT);

break;
}
}
Expand Down Expand Up @@ -445,12 +445,12 @@ static int loadconfig(char const * const file){
int const ip_tos = config_getint(Configtable,sname,"tos",IP_tos);
char const *iface = config_getstring(Configtable,sname,"iface",Iface);
int const update = config_getint(Configtable,sname,"update",Update);

// data stream is shared by all channels in this section
// Now also used for per-channel status/control, with different port number
struct sockaddr_storage data_dest_socket;
struct sockaddr_storage metadata_dest_socket;

// There can be multiple senders to an output stream, so let avahi suppress the duplicate addresses
{
char ttlmsg[100];
Expand Down Expand Up @@ -496,7 +496,7 @@ static int loadconfig(char const * const file){
for(char const *tok = strtok_r(freq_list," \t",&saveptr);
tok != NULL;
tok = strtok_r(NULL," \t",&saveptr)){

double const f = parse_frequency(tok,true);
if(f < 0){
fprintf(stdout,"can't parse frequency %s\n",tok);
Expand Down Expand Up @@ -532,18 +532,18 @@ static int loadconfig(char const * const file){
set_defaults(chan);
if(preset != NULL && loadpreset(chan,Preset_table,preset) != 0)
fprintf(stdout,"warning: in [%s], loadpreset(%s,%s) failed; compiled-in defaults and local settings used\n",sname,Preset_file,preset);

strlcpy(chan->preset,preset,sizeof(chan->preset));
loadpreset(chan,Configtable,sname); // Overwrite with other entries from this section, without overwriting those

// Set up output stream (data + status)
// Data multicast group has already been joined
memcpy(&chan->output.dest_socket,&data_dest_socket,sizeof(chan->output.dest_socket));
strlcpy(chan->output.dest_string,data,sizeof(chan->output.dest_string));
memcpy(&chan->status.dest_socket,&metadata_dest_socket,sizeof(chan->status.dest_socket));

// Set RTP payload type from static table specific to ka9q-radio
// Should assign dynamically, but requires completion of SDP
// Should assign dynamically, but requires completion of SDP
int const type = pt_from_info(chan->output.samprate,chan->output.channels);
if(type < 0){
fprintf(stdout,"can't allocate RTP payload type for samprate %'d, channels %d\n",chan->output.samprate,chan->output.channels);
Expand All @@ -558,7 +558,7 @@ static int loadconfig(char const * const file){
start_demod(chan);
nfreq++;
nchans++;

if(SAP_enable){
// Highly experimental, off by default
char sap_dest[] = "224.2.127.254:9875"; // sap.mcast.net
Expand Down Expand Up @@ -649,7 +649,7 @@ static int setup_hardware(char const *sname){
return -1;
}

int r = (*Frontend.setup)(&Frontend,Configtable,sname);
int r = (*Frontend.setup)(&Frontend,Configtable,sname);
if(r != 0){
fprintf(stdout,"device setup returned %d\n",r);
return r;
Expand All @@ -675,7 +675,7 @@ static int setup_hardware(char const *sname){
pthread_mutex_init(&Frontend.status_mutex,NULL);
pthread_cond_init(&Frontend.status_cond,NULL);
if(Frontend.start){
int r = (*Frontend.start)(&Frontend);
int r = (*Frontend.start)(&Frontend);
if(r != 0)
fprintf(stdout,"Front end start returned %d\n",r);

Expand Down Expand Up @@ -705,7 +705,7 @@ static void *rtcp_send(void *arg){
goto done;
uint8_t buffer[PKTSIZE]; // much larger than necessary
memset(buffer,0,sizeof(buffer));

// Construct sender report
struct rtcp_sr sr;
memset(&sr,0,sizeof(sr));
Expand All @@ -722,12 +722,12 @@ static void *rtcp_send(void *arg){
sr.rtp_timestamp = (0 + gps_time_ns() - Starttime) / BILLION;
sr.packet_count = chan->output.rtp.seq;
sr.byte_count = chan->output.rtp.bytes;

uint8_t *dp = gen_sr(buffer,sizeof(buffer),&sr,NULL,0);

// Construct SDES
struct rtcp_sdes sdes[4];

// CNAME
char hostname[1024];
gethostname(hostname,sizeof(hostname));
Expand All @@ -743,15 +743,15 @@ static void *rtcp_send(void *arg){
sdes[1].type = NAME;
strlcpy(sdes[1].message,"KA9Q Radio Program",sizeof(sdes[1].message));
sdes[1].mlen = strlen(sdes[1].message);

sdes[2].type = EMAIL;
strlcpy(sdes[2].message,"karn@ka9q.net",sizeof(sdes[2].message));
sdes[2].mlen = strlen(sdes[2].message);

sdes[3].type = TOOL;
strlcpy(sdes[3].message,"KA9Q Radio Program",sizeof(sdes[3].message));
sdes[3].mlen = strlen(sdes[3].message);

dp = gen_sdes(dp,sizeof(buffer) - (dp-buffer),chan->output.rtp.ssrc,sdes,4);


Expand Down
18 changes: 14 additions & 4 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,12 +551,15 @@ static void *statproc(void *arg){
fprintf(stderr,"No room!!\n");
continue;
}
sp->chan.inuse = true; // Not sent in status update
sp->ssrc = ssrc;
}
// Always decode directly into local copy, as not every parameter is updated in every status message
memcpy(&sp->sender,&sender,sizeof(sp->sender));
sp->last_active = gps_time_ns(); // Keep active time calc from blowing up before data packet arrives

// Decode directly into local copy, as not every parameter is updated in every status message
// Decoding into a temp copy and then memcpy would write zeroes into unsent parameters
decode_radio_status(&sp->frontend,&sp->chan,buffer+1,length-1);

// Update SNR calculation (not sent explicitly)
float const noise_bandwidth = fabsf(sp->chan.filter.max_IF - sp->chan.filter.min_IF);
float sig_power = sp->chan.sig.bb_power - noise_bandwidth * sp->chan.sig.n0;
Expand All @@ -565,9 +568,16 @@ static void *statproc(void *arg){
float const sn0 = sig_power/sp->chan.sig.n0;
float const snr = power2dB(sn0/noise_bandwidth);
sp->snr = sp->now_active ? snr : -INFINITY;
memcpy(&sp->sender,&sender,sizeof(sp->sender));
sp->last_active = gps_time_ns(); // Keep active time calc from blowing up before data packet arrives
sp->samprate = sp->chan.output.samprate;
int const type = sp->chan.output.rtp.type;

if(type >= 0 && type < 128){
// NO_ENCODING check so we won't break with radiod that doesn't send it yet
if(sp->chan.output.encoding != NO_ENCODING)
add_pt(type,sp->chan.output.samprate,sp->chan.output.channels,sp->chan.output.encoding);
else if(type != Opus_pt)
add_pt(type,sp->chan.output.samprate,sp->chan.output.channels,S16BE); // Heuristic; remove this eventually
}
pthread_mutex_unlock(&Sess_mutex);
}
return NULL;
Expand Down

0 comments on commit 49194d3

Please sign in to comment.