Beispiel #1
0
static void fa_printopt()
{
    FA_PRINT("NOTE: configuration is below\n");
    FA_PRINT("NOTE: inputfile = %s\n", opt_inputfile);
    FA_PRINT("NOTE: outputfile= %s\n", opt_outputfile);
    FA_PRINT("NOTE: framelen  = %d\n", opt_framelen);
}
Beispiel #2
0
static void fa_printopt()
{
    FA_PRINT("NOTE: configuration is below\n");
    FA_PRINT("NOTE: inputfile = %s\n", opt_inputfile);
    FA_PRINT("NOTE: video outputfile= %s\n", opt_video_outputfile);
    FA_PRINT("NOTE: audio outputfile= %s\n", opt_audio_outputfile);
}
Beispiel #3
0
static void fa_printopt()
{
    FA_PRINT("NOTE: configuration is below\n");
    FA_PRINT("NOTE: inputfile = %s\n", opt_inputfile);
    FA_PRINT("NOTE: outputfile= %s\n", opt_outputfile);
    FA_PRINT("NOTE: bitrate   = %d kbps\n", opt_bitrate);
    FA_PRINT("NOTE: speed lev = %d\n", opt_speedlevel);
}
Beispiel #4
0
/**
 * @brief: check the input value valid, should check the valid scope
 *
 * @return: 0 if success, -1 if error
 */
static int fa_checkopt(int argc)
{
/*
    if(argc < 5) {
        FA_PRINT_ERR("FAIL: input and output file should input\n");
        return -1;
    }
*/
    if(strlen(opt_inputfile) == 0 || strlen(opt_outputfile) == 0) {
        FA_PRINT_ERR("FAIL: input and output file should input\n");
        return -1;

    }

    if(opt_framelen > 8192) {
        FA_PRINT_ERR("FAIL: the frame length is too large, should <= 8192\n");
        return -1;
    }

    if(opt_fftwintype < HAMMING || opt_fftwintype > KAISER) {
        FA_PRINT_ERR("FAIL: fft window type wrong, only 0,1,2,3 active\n");
        return -1;
    }

    if(opt_mdctwintype < MDCT_SINE || opt_mdctwintype > MDCT_KBD) {
        FA_PRINT_ERR("FAIL: mdct window type wrong, only 0,1 active\n");
        return -1;
    }

    FA_PRINT("SUCC: check option ok\n");
    return 0;
}
Beispiel #5
0
/**
 * @brief: check the input value valid, should check the valid scope
 *
 * @return: 0 if success, -1 if error
 */
static int fa_checkopt(int argc)
{
    if(argc < 2) {
        FA_PRINT("%s\n", default_set);
        return 0;
    }

    /*this is just example*/
    if(opt_samplerate > 48000) {
        FA_PRINT_ERR("FAIL: the samplerate is not right\n");
        return -1;
    }

    FA_PRINT("SUCC: check option ok\n");
    return 0;
}
Beispiel #6
0
static void fa_printopt()
{
    FA_PRINT("NOTE: configuration is below\n");
    FA_PRINT("NOTE: inputfile = %s\n", opt_inputfile);
    FA_PRINT("NOTE: outputfile= %s\n", opt_outputfile);
    FA_PRINT("NOTE: overlap   = %d\n", opt_overlap);
    FA_PRINT("NOTE: framelen  = %d\n", opt_framelen);
    FA_PRINT("NOTE: wintype   = %d\n", opt_fftwintype);
    FA_PRINT("      (0:hamming; 1:blackman; 2:kaiser)\n");
}
Beispiel #7
0
static void fa_printopt()
{
    FA_PRINT("NOTE: configuration is below\n");
    FA_PRINT("NOTE: verbose   : %u\n", opt_verbose);
    FA_PRINT("NOTE: fast      : %u\n", opt_fast);
    FA_PRINT("NOTE: bitrate   : %u\n", opt_bitrate);
    FA_PRINT("NOTE: samplerate: %u\n", opt_samplerate);
    FA_PRINT("NOTE: switch1   : %u\n", opt_switch1);
    FA_PRINT("NOTE: switch2   : %u\n", opt_switch2);
}
Beispiel #8
0
/**
 * @brief: check the input value valid, should check the valid scope
 *
 * @return: 0 if success, -1 if error
 */
static int fa_checkopt(int argc)
{
    if(argc < 5) {
        FA_PRINT_ERR("FAIL: input and output file should input\n");
        return -1;
    }

    if(strlen(opt_inputfile) == 0 || strlen(opt_outputfile) == 0) {
        FA_PRINT_ERR("FAIL: input and output file should input\n");
        return -1;

    }

    if(opt_framelen > 8192) {
        FA_PRINT_ERR("FAIL: the frame length is too large, should <= 8192\n");
        return -1;
    }

    if(opt_winlen > 2048) {
        FA_PRINT_ERR("FAIL: the window length is too large, should <= 2048\n");
        return -1;
    }

    if(opt_wintype < HAMMING || opt_wintype > KAISER) {
        FA_PRINT_ERR("FAIL: window type wrong, only 0,1,2 active\n");
        return -1;
    }

    if(opt_fc <= 0 || opt_fc >=1) {
        FA_PRINT_ERR("FAIL: cutoff freqency should be in (0,1)\n");
        return -1;
    }

    if(opt_fc1 <= 0 || opt_fc1 >=1) {
        FA_PRINT_ERR("FAIL: cutoff start freqency should be in (0,1)\n");
        return -1;
    }

    if(opt_fc2 <= 0 || opt_fc2 >=1) {
        FA_PRINT_ERR("FAIL: cutoff stop freqency should be in (0,1)\n");
        return -1;
    }

    if(opt_fc1 >= opt_fc2) {
        FA_PRINT_ERR("FAIL: cutoff start freqency should < stop freqency\n");
        return -1;
    }

    FA_PRINT("SUCC: check option ok\n");
    return 0;
}
Beispiel #9
0
/**
 * @brief: check the input value valid, should check the valid scope
 *
 * @return: 0 if success, -1 if error
 */
static int fa_checkopt(int argc)
{

    if(argc < 3) {
        FA_PRINT_ERR("FAIL: input and output file should input\n");
        return -1;
    }

    if (strlen(opt_outputfile) == 0) {
        char tmp[256];
        char *t = strrchr(opt_inputfile, '.');
        int l = t ? strlen(opt_inputfile) - strlen(t) : strlen(opt_inputfile);

        memset(tmp, 0, 256);
        memset(opt_outputfile, 0, 256);

        strncpy(tmp, opt_inputfile, l);
        sprintf(opt_outputfile, "%s.aac", tmp);
    }

    if(strlen(opt_inputfile) == 0 || strlen(opt_outputfile) == 0) {
        FA_PRINT_ERR("FAIL: input and output file should input\n");
        return -1;

    }
/*
    if(opt_bitrate > 256 || opt_bitrate < 32)  {
        FA_PRINT_ERR("FAIL: the bitrate is too large or too short, should be in [32000, 256000]\n");
        return -1;
    }
*/
    if(opt_speedlevel > 6 || opt_speedlevel < 1)  {
        FA_PRINT_ERR("FAIL: out of range, should be in [1,6]\n");
        return -1;
    }
 
    if(opt_bandwidth > 20 || opt_bandwidth < 5)  {
        FA_PRINT_ERR("FAIL: out of range, should be in [5,20] kHz\n");
        return -1;
    }
         

    FA_PRINT("SUCC: check option ok\n");
    return 0;
}
Beispiel #10
0
/**
 * @brief: check the input value valid, should check the valid scope
 *
 * @return: 0 if success, -1 if error
 */
static int fa_checkopt(int argc)
{
    if(argc < 5) {
        FA_PRINT_ERR("FAIL: input and output file should input\n");
        return -1;
    }

    if(strlen(opt_inputfile) == 0 || strlen(opt_outputfile) == 0) {
        FA_PRINT_ERR("FAIL: input and output file should input\n");
        return -1;

    }
    if(opt_framelen > 8192) {
        FA_PRINT_ERR("FAIL: the frame length is too large\n");
        return -1;
    }

    FA_PRINT("SUCC: check option ok\n");
    return 0;
}
Beispiel #11
0
int main(int argc, char *argv[])  
{  
    int ret;

    FA_PRINT_INIT(FA_PRINT_ENABLE,
                  FA_PRINT_FILE_ENABLE,FA_PRINT_STDOUT_ENABLE,FA_PRINT_STDERR_ENABLE,
                  /*FA_PRINT_FILE_DISABLE,FA_PRINT_STDOUT_ENABLE,FA_PRINT_STDERR_ENABLE,*/
                  FA_PRINT_PID_ENABLE,
                  "/tmp", "testlog", "TS");

    ret = fa_parseopt(argc, argv);
    if(ret)
        FA_PRINT_ERR("FAIL: now doing the abnormal things\n");
    else
        FA_PRINT("SUCC: now doing the normal thing\n");

    FA_PRINT_DBG("TEST: now test debug info\n");

    FA_PRINT_UNINIT();
    return 0;  
}  
Beispiel #12
0
/**
 * @brief: check the input value valid, should check the valid scope
 *
 * @return: 0 if success, -1 if error
 */
static int fa_checkopt(int argc)
{

    if(argc < 5) {
        FA_PRINT_ERR("FAIL: input and output file should input\n");
        return -1;
    }

    if(strlen(opt_inputfile) == 0) {
        FA_PRINT_ERR("FAIL: input and output file should input\n");
        return -1;
    }

    if(strlen(opt_video_outputfile) == 0 && strlen(opt_audio_outputfile) == 0) {
        FA_PRINT_ERR("FAIL: input and output file should input\n");
        return -1;
    }

    FA_PRINT("SUCC: check option ok\n");
    return 0;
}
Beispiel #13
0
static int udpsrv_open(fa_trans_t *trans, char *hostname, int port)
{
	
    struct addrinfo hints, *cur_ai;
	udpsrv_context_t *s = NULL;
	int ret;
    char portstr[10];
	int fd = -1;
    int tmp;

	if (port <= 0 || port >= 65536) {
        FA_PRINT("FAIL: %s , [err at: %s-%d]\n", FA_ERR_NETWORK_PORTNO, __FILE__, __LINE__);
		return -1;	//port is not correct
	}

    s = fa_malloc(sizeof(udpsrv_context_t));
    if (!s) {
        FA_PRINT("FAIL: %s , [err at: %s-%d]\n", FA_ERR_SYS_NOMEM, __FILE__, __LINE__);
        return -1;
    }

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_DGRAM;
    snprintf(portstr, sizeof(portstr), "%d", port);
    ret = getaddrinfo(hostname, portstr, &hints, &(s->ai));	//cvt the hostname to the address(support ipv6)
    if (ret) {
        FA_PRINT("FAIL: %s , [err at: %s-%d]\n", FA_ERR_SYS_IO, __FILE__, __LINE__);
        goto fail;
    }
    cur_ai = s->ai;

    fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
    if (fd < 0)
        goto fail;

    tmp = 1;
    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(tmp));

    if (bind (fd, cur_ai->ai_addr, cur_ai->ai_addrlen) < 0) {
        char bindmsg[32];
        /*snprintf(bindmsg, sizeof(bindmsg), "bind(port %d)", ntohs(cur_ai->ai_addr->sin_port));*/
        snprintf(bindmsg, sizeof(bindmsg), "bind fail");
//        perror (bindmsg);
        FA_PRINT("FAIL: %s , [err at: %s-%d]\n", bindmsg, __FILE__, __LINE__);
        closesocket(fd);
        return -1;
    }

#ifdef UDP_USE_BLOCK
    fa_socket_nonblock(fd, 0);
#else 
    fa_socket_nonblock(fd, 1);
#endif

    s->fd = fd;

    trans->priv_data = s;

    return 0;

fail:
    FA_PRINT("FAIL: %s , [err at: %s-%d]\n", FA_ERR_SYS_IO, __FILE__, __LINE__);
    if (fd >= 0)
        closesocket(fd);
    if (s) {
        if (s->ai)
            freeaddrinfo(s->ai);
        fa_free(s);
    }

    return -1;
}
Beispiel #14
0
/**
 * @brief: parse the command line
 *         this is the simple template which will be used by falab projects
 *
 * @param:argc
 * @param:argv[]
 *
 * @return: 0 if success, -1 if error(input value maybe not right)
 */
int fa_parseopt(int argc, char *argv[])
{
    int ret;
    const char *die_msg = NULL;

    while (1) {
        static char * const     short_options = "hHLi:o:l:t:";  
        static struct option    long_options[] = 
                                {
                                    { "help"       , 0, 0, 'h'}, 
                                    { "long-help"  , 0, 0, 'H'},
                                    { "license"    , 0, 0, 'L'},
                                    { "input"      , 1, 0, 'i'},                 
                                    { "output"     , 1, 0, 'o'},                 
                                    { "framelen"   , 1, 0, 'l'},        
                                    { "wintype"    , 1, 0, 't'},        
                                    { "winlen"     , 1, 0, OPT_WINLEN},
                                    { "firtype"    , 1, 0, OPT_FIRTYPE},
                                    { "cutoff"     , 1, 0, OPT_CUTOFF},
                                    { "cutoff1"    , 1, 0, OPT_CUTOFF1},
                                    { "cutoff2"    , 1, 0, OPT_CUTOFF2},
                                    {0             , 0, 0,  0},
                                };
        int c = -1;
        int option_index = 0;

        c = getopt_long(argc, argv, 
                        short_options, long_options, &option_index);

        if (c == -1) {
            break;
        }

        if (!c) {
            die_msg = usage;
            break;
        }

        switch (c) {
            case 'h': {
                          die_msg = short_help;
                          break;
                      }

            case 'H': {
                          die_msg = long_help;
                          break;
                      }
                      
            case 'L': {
                          die_msg = license;
                          break;
                      }

            case 'i': {
                          if (sscanf(optarg, "%s", opt_inputfile) > 0) {
                              FA_PRINT("SUCC: inputfile is %s\n", opt_inputfile);
                          }else {
                              FA_PRINT_ERR("FAIL: no inputfile\n");
                          }
                          break;
                      }

            case 'o': {
                          if (sscanf(optarg, "%s", opt_outputfile) > 0) {
                              FA_PRINT("SUCC: outputfile is %s\n", opt_outputfile);
                          }else {
                              FA_PRINT_ERR("FAIL: no outputfile\n");
                          }
                          break;
                      }

            case 'l': {
                          unsigned int i;
                          if (sscanf(optarg, "%u", &i) > 0) {
                              opt_framelen = i;
                              FA_PRINT("SUCC: set frame length = %u\n", opt_framelen);
                          }
                          break;
                      }

            case 't': {
                          unsigned int i;
                          if (sscanf(optarg, "%u", &i) > 0) {
                              opt_wintype = i;
                              FA_PRINT("SUCC: set win type = %u\n", opt_wintype);
                          }
                          break;
                      }
                      
            case OPT_WINLEN: {
                                  unsigned int i;
                                  if (sscanf(optarg, "%u", &i) > 0) {
                                      opt_winlen = i;
                                      FA_PRINT("SUCC: set window length = %u\n", opt_winlen);
                                  }
                                  break;
                             }
                             
            case OPT_FIRTYPE: {
                                  unsigned int i;
                                  if (sscanf(optarg, "%u", &i) > 0) {
                                      opt_firtype = i;
                                      FA_PRINT("SUCC: set fir type = %u\n", opt_firtype);
                                  }
                                  break;
                              }
                             
            case OPT_CUTOFF: {
                                  float i;
                                  if (sscanf(optarg, "%f", &i) > 0) {
                                      opt_fc = i;
                                      FA_PRINT("SUCC: set fir cutoff freqency = %f\n", opt_fc);
                                  }
                                  break;
                              }
                             
            case OPT_CUTOFF1:{
                                  float i;
                                  if (sscanf(optarg, "%f", &i) > 0) {
                                      opt_fc1 = i;
                                      FA_PRINT("SUCC: set fir cutoff start freqency = %f\n", opt_fc1);
                                  }
                                  break;
                              }
                             
            case OPT_CUTOFF2:{
                                  float i;
                                  if (sscanf(optarg, "%f", &i) > 0) {
                                      opt_fc2 = i;
                                      FA_PRINT("SUCC: set fir cutoff stop freqency = %f\n", opt_fc2);
                                  }
                                  break;
                              }

            case '?':
            default:
                      die_msg = usage;
                      break;
        }
    }

    if(die_msg) {
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*check the input validity*/
    ret = fa_checkopt(argc);
    if(ret) {
        die_msg = usage;
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*print the settings*/
    fa_printopt();

    return 0;
fail:
    return -1;
}
Beispiel #15
0
static void fa_printopt()
{
    FA_PRINT("NOTE: configuration is below\n");
    FA_PRINT("NOTE: inputfile = %s\n", opt_inputfile);
    FA_PRINT("NOTE: outputfile= %s\n", opt_outputfile);
    FA_PRINT("NOTE: framelen  = %d\n", opt_framelen);
    FA_PRINT("NOTE: window len= %d\n", opt_winlen);
    FA_PRINT("NOTE: wintype   = %d\n", opt_wintype);
    FA_PRINT("      (0:hamming; 1:blackman; 2:kaiser)\n");
    FA_PRINT("NOTE: firtype   = %d\n", opt_firtype);
    FA_PRINT("      (0:lpf; 1:hpf; 2:bandpass; 3:bandstop)\n");
    FA_PRINT("NOTE: cutoff    = %f\n", opt_fc);
    FA_PRINT("NOTE: cutoff1   = %f\n", opt_fc1);
    FA_PRINT("NOTE: cutoff2   = %f\n", opt_fc2);
}
Beispiel #16
0
/**
 * @brief: parse the command line
 *         this is the simple template which will be used by falab projects
 *
 * @param:argc
 * @param:argv[]
 *
 * @return: 0 if success, -1 if error(input value maybe not right)
 */
int fa_parseopt(int argc, char *argv[])
{
    int ret;
    const char *die_msg = NULL;

    while (1) {
        static char * const     short_options = "hHLi:o:l:";  
        static struct option    long_options[] = 
                                {
                                    { "help"       , 0, 0, 'h'}, 
                                    { "long-help"  , 0, 0, 'H'},
                                    { "license"    , 0, 0, 'L'},
                                    { "input"      , 1, 0, 'i'},                 
                                    { "output"     , 1, 0, 'o'},                 
                                    { "framelen"   , 1, 0, 'l'},        
                                    {0             , 0, 0,  0},
                                };
        int c = -1;
        int option_index = 0;

        c = getopt_long(argc, argv, 
                        short_options, long_options, &option_index);

        if (c == -1) {
            break;
        }

        if (!c) {
            die_msg = usage;
            break;
        }

        switch (c) {
            case 'h': {
                          die_msg = short_help;
                          break;
                      }

            case 'H': {
                          die_msg = long_help;
                          break;
                      }
                      
            case 'L': {
                          die_msg = license;
                          break;
                      }

            case 'i': {
                          if (sscanf(optarg, "%s", opt_inputfile) > 0) {
                              FA_PRINT("SUCC: inputfile is %s\n", opt_inputfile);
                          }else {
                              FA_PRINT_ERR("FAIL: no inputfile\n");
                          }
                          break;
                      }

            case 'o': {
                          if (sscanf(optarg, "%s", opt_outputfile) > 0) {
                              FA_PRINT("SUCC: outputfile is %s\n", opt_outputfile);
                          }else {
                              FA_PRINT_ERR("FAIL: no outputfile\n");
                          }
                          break;
                      }

            case 'l': {
                          unsigned int i;
                          if (sscanf(optarg, "%u", &i) > 0) {
                              opt_framelen = i;
                              FA_PRINT("SUCC: set frame length = %u\n", opt_framelen);
                          }
                          break;
                      }

            case '?':
            default:
                      die_msg = usage;
                      break;
        }
    }

    if(die_msg) {
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*check the input validity*/
    ret = fa_checkopt(argc);
    if(ret) {
        die_msg = usage;
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*print the settings*/
    fa_printopt();

    return 0;
fail:
    return -1;
}
Beispiel #17
0
/**
 * @brief: parse the command line
 *         this is the simple template which will be used by falab projects
 *
 * @param:argc
 * @param:argv[]
 *
 * @return: 0 if success, -1 if error(input value maybe not right)
 */
int fa_parseopt(int argc, char *argv[])
{
    int ret;
    const char *die_msg = NULL;

    while (1) {
        static char * const     short_options = "hHLli:v:a:";
        static struct option    long_options[] =
        {
            { "help"           , 0, 0, 'h'},
            { "help"           , 0, 0, 'H'},
            { "license"        , 0, 0, 'L'},
            { "license"        , 0, 0, 'l'},
            { "input"          , 1, 0, 'i'},
            { "video output"   , 1, 0, 'v'},
            { "audio output"   , 1, 0, 'a'},
            {0                 , 0, 0,  0},
        };
        int c = -1;
        int option_index = 0;

        c = getopt_long(argc, argv, short_options, long_options, &option_index);

        if (c == -1) {
            break;
        }

        if (!c) {
            die_msg = usage;
            break;
        }

        switch (c) {
        case 'h': {
            die_msg = help;
            break;
        }

        case 'H': {
            die_msg = help;
            break;
        }

        case 'L': {
            die_msg = license;
            break;
        }

        case 'l': {
            die_msg = license;
            break;
        }

        case 'i': {
            if (sscanf(optarg, "%s", opt_inputfile) > 0) {
                FA_PRINT("SUCC: inputfile is %s\n", opt_inputfile);
            } else {
                FA_PRINT_ERR("FAIL: no inputfile\n");
            }
            break;
        }

        case 'v': {
            if (sscanf(optarg, "%s", opt_video_outputfile) > 0) {
                FA_PRINT("SUCC: video outputfile is %s\n", opt_video_outputfile);
            } else {
                FA_PRINT_ERR("FAIL: no video outputfile\n");
            }
            break;
        }

        case 'a': {
            if (sscanf(optarg, "%s", opt_audio_outputfile) > 0) {
                FA_PRINT("SUCC: audio outputfile is %s\n", opt_audio_outputfile);
            } else {
                FA_PRINT_ERR("FAIL: no audio outputfile\n");
            }
            break;
        }

        case '?':
        default:
            die_msg = usage;
            break;
        }
    }

    if(die_msg) {
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*check the input validity*/
    ret = fa_checkopt(argc);
    if(ret) {
        die_msg = usage;
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*print the settings*/
    fa_printopt();

    return 0;
fail:
    return -1;
}
Beispiel #18
0
/**
 * @brief: parse the command line
 *         this is the simple template which will be used by falab projects
 *
 * @param:argc
 * @param:argv[]
 *
 * @return: 0 if success, -1 if error(input value maybe not right)
 */
int fa_parseopt(int argc, char *argv[])
{
    int ret;
    const char *die_msg = NULL;

    while (1) {
        static char * const     short_options = "hHLvfb:R:";  
        static struct option    long_options[] = 
                                {
                                    { "help"       , 0, 0, 'h'}, 
                                    { "long-help"  , 0, 0, 'H'},
                                    { "license"    , 0, 0, 'L'},
                                    { "verbose"    , 0, 0, 'v'},  
                                    { "fast"       , 0, 0, 'f'},  
                                    { "bitrate"    , 1, 0, 'b'},                // need 1 argument 
                                    { "samplerate" , 1, 0, 'R'},                // need 1 argument 
                                    { "switch1"    , 0, 0, SWITCH1_FLAG},       // --switch1 will return SWIATCH1_FLAG 
                                    { "switch2"    , 1, 0, SWITCH2_FLAG},       // --switch2 will return SWIATCH2_FLAG 
                                    {0             , 0, 0, 0},
                                };
        int c = -1;
        int option_index = 0;

        c = getopt_long(argc, argv, 
                        short_options, long_options, &option_index);

        if (c == -1) {
            break;
        }

        if (!c) {
            die_msg = usage;
            break;
        }

        switch (c) {
            case 'h': {
                          die_msg = short_help;
                          break;
                      }

            case 'H': {
                          die_msg = long_help;
                          break;
                      }
                      
            case 'L': {
                          die_msg = license;
                          break;
                      }

            case 'v': {
                          opt_verbose = 1;
                          FA_PRINT("SUCC: verbose mode active\n");
                          break;
                      }

            case 'f': {
                          opt_fast = 1;
                          FA_PRINT("SUCC: fast mode active\n");
                          break;
                      }

            case 'b': {
                          unsigned int i;
                          if (sscanf(optarg, "%u", &i) > 0) {
                              opt_bitrate = 1000 * i;
                              FA_PRINT("SUCC: set bitrate=%u\n", opt_bitrate);
                          }else {
                              opt_bitrate = 0;
                              FA_PRINT("WARN: bitrate not set\n");
                          }
                          break;
                      }

            case 'R': {
                          unsigned int i;
                          if (sscanf(optarg, "%u", &i) > 0) {
                              opt_samplerate = i;
                              FA_PRINT("SUCC: set samplerate=%u\n", opt_samplerate);
                          }else {
                              opt_samplerate = 0;
                              FA_PRINT("WARN: samplerate not set\n");
                          }
                          break;
                      }

            case SWITCH1_FLAG:{
                                  opt_switch1 = 1;
                                  FA_PRINT("SUCC: switch1 set, default = 1 \n");
                                  break;
                              }

            case SWITCH2_FLAG:{
                                  unsigned int i;
                                  if (sscanf(optarg, "%d", &i) > 0) {
                                      opt_switch2 = i;
                                      FA_PRINT("SUCC: set switch2=%d\n", opt_switch2);
                                  }else {
                                      opt_switch2 = 0;
                                      FA_PRINT("WARN: switch2 not set\n");
                                  }
                                  break;
                              }

            case '?':
            default:
                      die_msg = usage;
                      break;
        }
    }

    if(die_msg) {
        FA_PRINT("%s\n", die_msg);
        goto fail;
    }

    /*check the input validity*/
    ret = fa_checkopt(argc);
    if(ret) {
        die_msg = usage;
        goto fail;
    }

    /*print the settings*/
    fa_printopt();

    return 0;
fail:
    return -1;
}
Beispiel #19
0
int main()
{
    fa_trans_t *trans;

    int  port;
    char hostname[1024];
    int  recv_len;
    int  real_recv_len;
    char buf[TRANS_BUF_SIZE];


#ifdef USE_LOGFILE
#ifdef WIN32
    FA_PRINT_INIT(FA_PRINT_ENABLE,
                  FA_PRINT_FILE_ENABLE,FA_PRINT_STDOUT_ENABLE,FA_PRINT_STDERR_ENABLE,
                  FA_PRINT_PID_ENABLE,
                  ".\\log_udpsrv\\", "udpsrvlog", "UDPSRV", 10);
#else
    FA_PRINT_INIT(FA_PRINT_ENABLE,
                  FA_PRINT_FILE_ENABLE,FA_PRINT_STDOUT_ENABLE,FA_PRINT_STDERR_ENABLE,
                  FA_PRINT_PID_ENABLE,
                  "./log_udpsrv/", "udpsrvlog", "UDPSRV", 10);
#endif
#endif


    if (fa_network_init()) {
        FA_PRINT("FAIL: %s , [err at: %s-%d]\n", FA_ERR_SYS_IO, __FILE__, __LINE__);
        return -1;
    }

#ifdef __GNUC__
    fa_sigpipe_init(NULL);
#endif


    strcpy(hostname, "192.168.20.82");
    /*strcpy(hostname, "192.168.20.38");*/
    port = 1984;

    /*create trans unit*/
    trans = fa_create_trans(fa_create_trans_udpsrv, fa_destroy_trans_udpsrv);

    /*try to open trans*/
    if(trans->open(trans,hostname,port)<0) {
        printf("open  fail\n");
        return -1;
    }

    recv_len = TRANS_BUF_SIZE;

    while(1) {
        char buf1[128];

        real_recv_len = trans->recv(trans, buf, recv_len);
        if (real_recv_len == -2)
            printf("recv time out, continue try \n");
        else {
            printf("-->want %d, recv %d bytes\n", recv_len, real_recv_len);
#if 1
            sprintf(buf1, "recv %d bytes\n", real_recv_len);
            trans->send(trans, buf1, strlen(buf1));
#endif
        }

        if(real_recv_len< 0) {
            printf("recv fail\n");
            continue;
        }
    }

    fa_network_close();


    return 0;


}