Main Page | Class List | File List | Class Members | File Members

config.c File Reference

#include "standard.h"
#include "al.h"
#include "config.h"
#include "ansi.h"
#include "input.h"
#include "video_codec.h"
#include "channel.h"
#include "mux.h"
#include "demux.h"
#include "audio.h"
#include "vid_wrapper.h"
#include "bch.h"

Go to the source code of this file.

Defines

#define STRLEN   256
#define DEF_CONFIG_FILE   "sim.cfg"
#define DEF_NUM_CHANNELS   3

Functions

void usage (void)
void add_alse (mux *m, al_sending_entity *alse)
void add_alre (demux *d, al_receiving_entity *alre)
controlnew_control (void)
void parse_line (char *s, char *name, char *arg)
void video_config (video_codec *video)
void audio_config (audio_codec *A)
void control_config (control *C)
void mux_table_config (mux *M)
void mux_config (mux *M)
void channel_config (channel *C)
void side_config (_side *side)
void get_config ()
void start_config ()
void finish_config ()
void set_config (int argc, char *argv[])

Variables

_session session
int debug


Define Documentation

#define DEF_CONFIG_FILE   "sim.cfg"
 

Definition at line 34 of file config.c.

Referenced by set_config(), and usage().

#define DEF_NUM_CHANNELS   3
 

Definition at line 36 of file config.c.

#define STRLEN   256
 

Definition at line 33 of file config.c.

Referenced by get_input(), and set_config().


Function Documentation

void add_alre demux d,
al_receiving_entity alre
[static]
 

Definition at line 56 of file config.c.

References demux::al_receivers, and demux::num_al_receivers.

00057 {
00058   d->al_receivers[d->num_al_receivers++] = alre;
00059 }

void add_alse mux m,
al_sending_entity alse
[static]
 

Definition at line 51 of file config.c.

References mux::al_senders, and mux::num_al_senders.

00052 {
00053   m->al_senders[m->num_al_senders++] = alse;
00054 }

void audio_config audio_codec A  ) 
 

Definition at line 148 of file config.c.

References eof_input_file(), equals(), error(), get_str(), audio_codec::input_filename, audio_codec::output_filename, and parse_line().

Referenced by side_config().

00149 {
00150   char str[STRLEN];
00151   char name[STRLEN];
00152   char arg[STRLEN];
00153   int done=0;
00154   FILE *fp;
00155 
00156   while (!done && !eof_input_file()) {
00157 
00158     get_str(str);
00159 
00160     parse_line(str, name, arg);
00161 
00162     if (equals(name, "end")) {
00163       done = 1;
00164     }
00165     else if (equals(name, "inputfile")) {
00166       strcpy(A->input_filename, arg);
00167     }
00168     else if (equals(name, "outputfile")) {
00169       strcpy(A->output_filename, arg);
00170       
00171       /* clear the output file */
00172       fp = fopen(A->output_filename,"w"); 
00173       if (fp==NULL) error("audio_config","Can't open output file");
00174       fclose(fp);
00175     }
00176   }
00177 }

void channel_config channel C  ) 
 

Definition at line 298 of file config.c.

References channel::bit_error_rate, eof_input_file(), equals(), channel::error, channel::error_offset, channel::filename, get_str(), parse_line(), channel::transmission_delay, and channel::transmission_speed.

Referenced by side_config().

00299 {
00300   char str[STRLEN];
00301   char name[STRLEN];
00302   char arg[STRLEN];
00303   int done=0;
00304 
00305   while (!done && !eof_input_file()) {
00306     get_str(str);
00307     parse_line(str, name, arg);
00308     if (equals(name, "end")) {
00309       done = 1;
00310     }
00311     else if (equals(name, "errortype")) {
00312       if (equals(arg, "none"))
00313         C->error=NoErrors;
00314       else if (equals(arg, "random"))
00315         C->error=Random;
00316       else if (equals(arg, "file"))
00317         C->error=File;
00318     }
00319     else if (equals(name, "errorrate")) {
00320       C->bit_error_rate = atof(arg);
00321     }
00322     else if (equals(name, "errorfile")) {
00323       strcpy(C->filename, arg);
00324     }
00325     else if (equals(name, "speed")) {
00326       C->transmission_speed = atoi(arg);
00327     }
00328     else if (equals(name, "delay")) {
00329       C->transmission_delay = atoi(arg);
00330     }
00331     else if (equals(name, "error_offset")) {
00332       C->error_offset = atoi(arg);
00333     }
00334   }
00335 }

void control_config control C  ) 
 

Definition at line 180 of file config.c.

References eof_input_file(), equals(), get_str(), and parse_line().

Referenced by side_config().

00181 {
00182   char str[STRLEN];
00183   char name[STRLEN];
00184   char arg[STRLEN];
00185   int done=0;
00186 
00187   while (!done && !eof_input_file()) {
00188 
00189     get_str(str);
00190 
00191     parse_line(str, name, arg);
00192 
00193     if (equals(name, "end")) {
00194       done = 1;
00195     }
00196     else if (equals(name, "")) {
00197 
00198     }
00199   }
00200 }

void finish_config  ) 
 

Definition at line 459 of file config.c.

References add_alre(), add_alse(), _side::Audio, al_receiving_entity::back_channel, _side::ciAudio, _side::ciControl, _side::ciVideo, _side::Control, _side::Demux, control::input, audio_codec::input, video_codec::input, _session::local, _side::Mux, new_al_receiving_entity(), new_al_sending_entity(), control::output, audio_codec::output, video_codec::output, _session::remote, session, set_frames(), and _side::Video.

Referenced by set_config().

00464 {
00465   al_sending_entity *alse;
00466   al_receiving_entity *alre;
00467 
00468   /* local side */
00469 
00470   alre = new_al_receiving_entity(&session.local.ciControl);
00471   alse = new_al_sending_entity(&session.local.ciControl);
00472   alre->back_channel = alse;
00473   session.local.Control->output = alse;
00474   session.local.Control->input = alre;
00475   add_alse(session.local.Mux, alse);
00476   add_alre(session.local.Demux, alre);
00477 
00478   alre = new_al_receiving_entity(&session.local.ciAudio);
00479   alse = new_al_sending_entity(&session.local.ciAudio);
00480   alre->back_channel = alse;
00481   session.local.Audio->output = alse;
00482   session.local.Audio->input = alre;
00483   add_alse(session.local.Mux, alse);
00484   add_alre(session.local.Demux, alre);
00485 
00486   alre = new_al_receiving_entity(&session.local.ciVideo);
00487   alse = new_al_sending_entity(&session.local.ciVideo);
00488   alre->back_channel = alse;
00489   session.local.Video->output = alse;
00490   session.local.Video->input = alre;
00491   add_alse(session.local.Mux, alse);
00492   add_alre(session.local.Demux, alre);
00493 
00494   /* remote side */
00495 
00496   alre = new_al_receiving_entity(&session.remote.ciControl);
00497   alse = new_al_sending_entity(&session.remote.ciControl);
00498   alre->back_channel = alse;
00499   session.remote.Control->output = alse;
00500   session.remote.Control->input = alre;
00501   add_alse(session.remote.Mux, alse);
00502   add_alre(session.remote.Demux, alre);
00503 
00504   alre = new_al_receiving_entity(&session.remote.ciAudio);
00505   alse = new_al_sending_entity(&session.remote.ciAudio);
00506   alre->back_channel = alse;
00507   session.remote.Audio->output = alse;
00508   session.remote.Audio->input = alre;
00509   add_alse(session.remote.Mux, alse);
00510   add_alre(session.remote.Demux, alre);
00511 
00512   alre = new_al_receiving_entity(&session.remote.ciVideo);
00513   alse = new_al_sending_entity(&session.remote.ciVideo);
00514   alre->back_channel = alse;
00515   session.remote.Video->output = alse;
00516   session.remote.Video->input = alre;
00517   add_alse(session.remote.Mux, alse);
00518   add_alre(session.remote.Demux, alre);
00519 
00520   /* compute the number of frames in for video codecs */
00521   set_frames(session.local.Video);
00522   set_frames(session.remote.Video);
00523 }

void get_config  ) 
 

Definition at line 383 of file config.c.

References eof_input_file(), equals(), get_str(), _session::local, parse_line(), _session::remote, session, and side_config().

Referenced by set_config().

00384 {
00385   char str[STRLEN];
00386   char name[STRLEN];
00387   char arg[STRLEN];
00388   void *data;
00389 
00390   while (!eof_input_file()) {
00391     
00392     get_str(str);
00393 
00394     parse_line(str, name, arg);
00395 
00396     if (equals(name, "local")) {
00397       if (debug) {
00398         printf("# %s side config \n", name);
00399       }
00400       side_config(&session.local);
00401     }
00402     else if (equals(name, "remote")) {
00403       if (debug) {
00404         printf("# %s side config\n", name);
00405       }
00406       side_config(&session.remote);
00407     }
00408   }
00409 }

void mux_config mux M  ) 
 

Definition at line 225 of file config.c.

References eof_input_file(), equals(), get_str(), mux_parameters::head_t, mux_parameters::header_code, mux_parameters::level, mux_parameters::mpl_code, mux_parameters::mpl_sync_threshold, mux_parameters::mpl_t, mux_table_config(), mux::params, parse_line(), mux_parameters::payload_max, mux_parameters::payload_min, mux_parameters::stat_file, strtobch_type(), mux_parameters::sync_flag_length, mux_parameters::sync_threshold, and mux_parameters::use_mpl.

Referenced by side_config().

00226 {
00227   char str[STRLEN];
00228   char name[STRLEN];
00229   char arg[STRLEN];
00230   int done=0;
00231 
00232   FILE *fp;
00233   while (!done && !eof_input_file()) {
00234     get_str(str);
00235     parse_line(str, name, arg);
00236 
00237     if (equals(name, "end")) {
00238       done = 1;
00239     }
00240     else if (equals(name, "table")) {
00241       mux_table_config(M);
00242     }
00243     else if (equals(name, "sync_flag_length")) {
00244       if (equals(arg,"16d"))
00245         M->params->sync_flag_length = 32;
00246       else
00247         M->params->sync_flag_length = atoi(arg);
00248     }
00249     else if (equals(name, "sync_threshold")) {
00250       M->params->sync_threshold = atoi(arg);
00251     }
00252     else if (equals(name, "header_code")) {
00253       M->params->header_code = strtobch_type(arg);
00254     }
00255     else if (equals(name, "level2")) {
00256       M->params->use_mpl = 1;
00257       M->params->level = 2;
00258       /* hard code some level 2 things.  could remove */
00259       M->params->header_code = GOLAY23_12;
00260       M->params->use_mpl = 0;
00261     }
00262     else if (equals(name, "level1")) {
00263       M->params->use_mpl = 0;
00264       M->params->level = 1;
00265     }
00266     else if (equals(name, "level0")) {
00267       M->params->use_mpl = 0;
00268       M->params->level = 1;  /* uses same logic as level 1 */
00269     }
00270     else if (equals(name, "mpl_code")) {
00271       M->params->mpl_code = strtobch_type(arg);
00272     }
00273     else if (equals(name, "payload_min")) {
00274       M->params->payload_min = atoi(arg);
00275     }
00276     else if (equals(name, "payload_max")) {
00277       M->params->payload_max = atoi(arg);
00278     }
00279     else if (equals(name, "stat_file")) {
00280       strcpy(M->params->stat_file,arg);
00281       fp = fopen(M->params->stat_file,"w"); /* delete this file if exists */
00282       assert(fp!=NULL);
00283       fclose(fp);
00284     }
00285     else if (equals(name, "mpl_t")) {
00286       M->params->mpl_t = atoi(arg);
00287     }
00288     else if (equals(name, "head_t")) {
00289       M->params->head_t = atoi(arg);
00290     }
00291     else if (equals(name, "mpl_sync_threshold")) {
00292       M->params->mpl_sync_threshold = atoi(arg);
00293     }
00294   }
00295 }

void mux_table_config mux M  ) 
 

Definition at line 203 of file config.c.

References add_to_mux_table(), eof_input_file(), equals(), get_str(), mux_parameters::mux_table, mux_parameters::mux_table_size, mux::params, and parse_line().

Referenced by mux_config().

00204 {
00205   char str[STRLEN];
00206   char name[STRLEN];
00207   char arg[STRLEN];
00208   int done=0;
00209 
00210   while (!done && !eof_input_file()) {
00211     get_str(str);
00212     parse_line(str, name, arg);
00213     if (equals(name, "end")) {
00214       done = 1;
00215     }
00216     else if (equals(name, "entry")) {
00217       if (M->params->mux_table_size < MAX_MUX_TABLE_SIZE) 
00218         add_to_mux_table(M->params->mux_table,
00219                          &(M->params->mux_table_size), arg);
00220     }
00221   }
00222 }

control* new_control void   ) 
 

Definition at line 62 of file config.c.

Referenced by start_config().

00063 {
00064   control *bob = malloc(sizeof(control));
00065   if (bob != NULL) {
00066 
00067   }
00068   return(bob);
00069 }

void parse_line char *  s,
char *  name,
char *  arg
[static]
 

Definition at line 72 of file config.c.

References a.

00073 {
00074   int i,n,a;
00075   
00076   i=n=a=0;
00077   
00078   /* skip whitespace */
00079   while (s[i] && (s[i]==' ' || s[i]=='\t'))
00080     i++;
00081   /* copy name */
00082   while (s[i] && !(s[i]==' ' || s[i]=='\t'))
00083     name[n++]=s[i++];
00084   name[n]=0;
00085   /* skip more whitespace */
00086   while (s[i] && (s[i]==' ' || s[i]=='\t'))
00087     i++;
00088   /* copy argument */
00089   while (s[i])
00090     arg[a++]=s[i++];
00091   arg[a]=0;
00092 }

void set_config int  argc,
char *  argv[]
 

Definition at line 526 of file config.c.

References close_input_file(), debug, DEF_CONFIG_FILE, equals(), finish_config(), get_config(), open_input_file(), prefix(), start_config(), STRLEN, and usage().

Referenced by main().

00531 {
00532   int i;
00533   char config_file[STRLEN];
00534 
00535   strcpy(config_file, DEF_CONFIG_FILE);
00536 
00537   /*
00538    * Check if we should print out usage thing.
00539    */
00540 
00541   if (argc > 1 && prefix("-h", argv[1])) {
00542     usage();
00543     exit(0);
00544   }
00545 
00546   if (argc > 1 && strcmp(argv[1], "-advice")==0) {
00547     printf("\aDon't Panic!\n");
00548     exit(42);
00549   }
00550 
00551   /* 
00552    * Process command line arguments.
00553    */
00554 
00555   for (i = 1; i < argc; i++) {
00556     if (argv[i][0]=='-') {
00557       if (strcmp(argv[i], "-c")==0) {
00558         i++;
00559         if (i < argc) {
00560           config_file[STRLEN-1]='\0';
00561           strncpy(config_file, argv[i], STRLEN-1);
00562         }
00563       } 
00564       else if (equals(argv[i], "-d")) {
00565         if (i < (argc - 1)) {
00566           if (argv[i+1][0]!='-') {
00567             i++;
00568             debug = atoi(argv[i]);
00569           }
00570         }
00571         else {
00572           debug = 0;
00573         }
00574       }
00575     } 
00576     else {
00577       fprintf(stderr, "Invalid command line option: %s\n", argv[i]); 
00578       exit(1);
00579     }
00580   }
00581 
00582   /*
00583    * Open the config file.
00584    */
00585 
00586   open_input_file(config_file);
00587 
00588   start_config();
00589   get_config();
00590   finish_config();
00591 
00592   close_input_file();
00593 }

void side_config _side side  ) 
 

Definition at line 338 of file config.c.

References _side::Audio, audio_config(), _side::Channel, channel_config(), _side::Control, control_config(), eof_input_file(), equals(), get_str(), _side::Mux, mux_config(), parse_line(), _side::Video, and video_config().

Referenced by get_config().

00339 {
00340   char str[STRLEN];
00341   char name[STRLEN];
00342   char arg[STRLEN];
00343   
00344   int done=0;
00345 
00346   while (!done && !eof_input_file()) {
00347   
00348     get_str(str);
00349     parse_line(str, name, arg);
00350 
00351     if (equals(name, "end")) {
00352       done = 1;
00353     }
00354     else if (equals(name, "video")) {
00355       if (debug)
00356         printf("\t# entering %s section\n", name);
00357       video_config(side->Video);
00358     }
00359     else if (equals(name, "audio")) {
00360       if (debug)
00361         printf("\t# entering %s section\n", name);
00362       audio_config(side->Audio);
00363     }
00364     else if (equals(name, "control")) {
00365       if (debug)
00366         printf("\t# entering %s section\n", name);
00367       control_config(side->Control);
00368     }
00369     else if (equals(name, "mux")) {
00370       if (debug)
00371         printf("\t# entering %s section\n", name);
00372       mux_config(side->Mux);
00373     }
00374     else if (equals(name, "channel")) {
00375       if (debug)
00376         printf("\t# entering %s section\n", name);
00377       channel_config(side->Channel);
00378     }
00379   }
00380 }

void start_config  ) 
 

Definition at line 412 of file config.c.

References _side::Audio, _side::Channel, _side::ciAudio, _side::ciControl, _side::ciVideo, _side::Control, _side::Demux, demux::input, _session::local, _side::Mux, new_audio_codec(), new_channel(), new_control(), new_demux(), new_mux(), new_mux_parameters(), new_video_codec(), mux::output, mux::params, demux::params, _session::remote, session, channel_info::type, and _side::Video.

Referenced by set_config().

00413 {
00414   /*
00415    * local side stuff. 
00416    */
00417   session.local.Video = new_video_codec("Local Video");
00418   session.local.Audio = new_audio_codec("Local Audio");
00419   session.local.Control = new_control();
00420   session.local.Mux = new_mux("Local Mux");
00421   session.local.Mux->params = new_mux_parameters("local -> remote");
00422   session.local.Demux = new_demux("Local Demux");
00423   session.local.Channel = new_channel("Local -> Remote channel");
00424 
00425   session.local.ciControl.type = AL1;
00426   session.local.ciAudio.type = AL2;
00427   session.local.ciVideo.type = AL3;
00428 
00429   /*
00430    * same stuff basically over here.
00431    */
00432   session.remote.Video = new_video_codec("Remote Video");
00433   session.remote.Audio = new_audio_codec("Remote Audio");
00434   session.remote.Control = new_control();
00435   session.remote.Mux = new_mux("Remote Mux");
00436   session.remote.Mux->params = new_mux_parameters("remote -> local");
00437   session.remote.Demux = new_demux("Remote Demux");
00438   session.remote.Channel = new_channel("Remote -> Local channel");
00439 
00440   session.remote.ciControl.type = AL1;
00441   session.remote.ciAudio.type = AL2;
00442   session.remote.ciVideo.type = AL3;
00443   
00444   /*
00445    * share parameters between local mux & remote demux 
00446    * and remote mux and local demux.
00447    */
00448   session.local.Demux->params = session.remote.Mux->params;
00449   session.remote.Demux->params = session.local.Mux->params;
00450 
00451 
00452   session.local.Mux->output = session.local.Channel;
00453   session.local.Demux->input = session.remote.Channel;
00454   session.remote.Mux->output = session.remote.Channel;
00455   session.remote.Demux->input = session.local.Channel;
00456 
00457 }

void usage void   )  [static]
 

Definition at line 38 of file config.c.

References DEF_CONFIG_FILE.

Referenced by set_config().

00039 {
00040   printf("\n");
00041   printf("Usage: sim [-d debug_level] [-c config_file]\n");
00042   printf("       sim -h\n");
00043   printf("\n");
00044   printf("-c config_file  = set config file [%s]\n", DEF_CONFIG_FILE); 
00045   printf("-d debug_level  = set debug_level\n");
00046   printf("-h              = print this message\n");
00047   printf("\n");
00048 }

void video_config video_codec video  ) 
 

Definition at line 95 of file config.c.

References eof_input_file(), equals(), error(), get_str(), video_codec::input_file, video_codec::no_coding, video_codec::output_file, parse_line(), video_codec::retransmit, video_codec::sequenced, video_codec::streamname, video_codec::targetrate, and video_codec::tmndecode.

Referenced by side_config().

00096 {
00097   char str[STRLEN];
00098   char name[STRLEN];
00099   char arg[STRLEN];
00100   int done=0;
00101   FILE *fp;
00102 
00103   while (!done && !eof_input_file()) {
00104 
00105     get_str(str);
00106 
00107     parse_line(str, name, arg);
00108 
00109     if (equals(name, "end")) {
00110       done = 1;
00111     }
00112     else if (equals(name, "inputfile")) {
00113       strcpy(video->input_file, arg);
00114     }
00115     else if (equals(name, "no_coding")) {
00116       video->no_coding = 1;
00117     }
00118     else if (equals(name, "outputfile")) {
00119       strcpy(video->output_file, arg);
00120       
00121       /* clear the output file */
00122       fp = fopen(video->output_file,"w"); 
00123       if (fp==NULL) error("video_config","Can't open output file");
00124       fclose(fp);
00125     }
00126     else if (equals(name, "streamfile")) {
00127       strcpy(video->streamname, arg);
00128     }
00129     else if (equals(name, "bitrate")) {
00130       video->targetrate = atoi(arg);
00131     }
00132 
00133     /* the rest of these are logical channel params */
00134 
00135     else if (equals(name, "sequenced")) {
00136       video->sequenced=1;
00137     }
00138     else if (equals(name, "retransmit")) {
00139       video->retransmit=1;
00140     }
00141     else if (equals(name, "tmndecode")) {
00142       video->tmndecode=1;
00143     }
00144   }
00145 }


Variable Documentation

int debug
 

Definition at line 23 of file main.c.

_session session
 

Definition at line 22 of file main.c.

Referenced by cleanup(), finish_config(), get_config(), main_loop(), and start_config().


Generated on Sun Jul 16 16:27:45 2006 by  doxygen 1.3.9.1