Example #1
0
/**
 * Shows a configuration menu for the machine.
 *
 * @param pContext Context object
 * @return Main menu state
 */
ut_state ut_state_config_auto_menu(ut_context* pContext)
{
	char Str[30];
	void *temp = NULL;
	char *pstr;
	ut_menu config_menu;
	uint8_t i;
	spiffs_stat fileStat;
	uint8_t uiMsgRow = 0;

	/* Initialize variables */
	init();

	/* Initialize menu */
	ut_menu_init(&config_menu);

	/* Options */
	config_menu.title = gszConfigMenuTitle;
	config_menu.currentState = STATE_CONFIG_AUTO_MODE;
	/* Items */
	for(i = 0; i < CONFIG_AUTO_MAX; i++)
	{
		config_menu.items[config_menu.numItems++].text = configs_auto[i].name;
	}

	/* Show menu */
	config_menu.selectedItem = 0;
	if(ut_menu_browse(&config_menu, DEFAULT_CONFIG_TIMEOUT) < 0)
	{
		return STATE_MAIN_MENU;
	}
	configsVar = &configs_auto[config_menu.selectedItem];
	switch(config_menu.selectedItem)
	{
		case CONFIG_AUTO_RODAR_PROG:
		case CONFIG_AUTO_MODO_SIM:
			xio_open(cs.primary_src,0,0);
			if(uspiffs[0].f < 0)
			{
				xio_close(cs.primary_src);
				ut_lcd_output_warning("NENHUM ARQUIVO\n\
									   CARREGADO\n");

				vTaskDelay(2000 / portTICK_PERIOD_MS);
				pContext->value[0] = STATE_CONFIG_AUTO_MODE;
				pContext->value[1] = STATE_CONFIG_AUTO_MODE;
				return STATE_CHOOSE_FILE;
			}
			else
			{
Example #2
0
int headerdetectio_open(CONCRETE_IO_HANDLE header_detect_io, ON_IO_OPEN_COMPLETE on_io_open_complete, void* on_io_open_complete_context, ON_BYTES_RECEIVED on_bytes_received, void* on_bytes_received_context, ON_IO_ERROR on_io_error, void* on_io_error_context)
{
	int result;

	if (header_detect_io == NULL)
	{
		result = __LINE__;
	}
	else
	{
		HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)header_detect_io;

        if (header_detect_io_instance->io_state != IO_STATE_NOT_OPEN &&
            header_detect_io_instance->io_state != IO_STATE_OPEN)
        {
            result = __LINE__;
        }
		else
		{
			header_detect_io_instance->on_bytes_received = on_bytes_received;
			header_detect_io_instance->on_io_open_complete = on_io_open_complete;
			header_detect_io_instance->on_io_error = on_io_error;
            header_detect_io_instance->on_bytes_received_context = on_bytes_received_context;
            header_detect_io_instance->on_io_open_complete_context = on_io_open_complete_context;
            header_detect_io_instance->on_io_error_context = on_io_error_context;

            if (header_detect_io_instance->io_state == IO_STATE_OPEN)
            {
                indicate_open_complete(header_detect_io_instance, IO_OPEN_OK);
            }
            else
            {
                header_detect_io_instance->header_pos = 0;
                header_detect_io_instance->io_state = IO_STATE_OPENING_UNDERLYING_IO;

                if (xio_open(header_detect_io_instance->underlying_io, on_underlying_io_open_complete, header_detect_io_instance, on_underlying_io_bytes_received, header_detect_io_instance, on_underlying_io_error, header_detect_io_instance) != 0)
                {
                    result = __LINE__;
                }
                else
                {
                    result = 0;
                }
            }
		}
	}

	return result;
}
Example #3
0
int saslclientio_open(CONCRETE_IO_HANDLE sasl_client_io, ON_IO_OPEN_COMPLETE on_io_open_complete, ON_BYTES_RECEIVED on_bytes_received, ON_IO_ERROR on_io_error, void* callback_context)
{
	int result = 0;

	/* Codes_SRS_SASLCLIENTIO_01_011: [If any of the sasl_client_io or on_bytes_received arguments is NULL, saslclientio_open shall fail and return a non-zero value.] */
	if ((sasl_client_io == NULL) ||
		(on_bytes_received == NULL))
	{
		result = __LINE__;
	}
	else
	{
		SASL_CLIENT_IO_INSTANCE* sasl_client_io_instance = (SASL_CLIENT_IO_INSTANCE*)sasl_client_io;

		if (sasl_client_io_instance->io_state != IO_STATE_NOT_OPEN)
		{
			result = __LINE__;
		}
		else
		{
			sasl_client_io_instance->on_bytes_received = on_bytes_received;
			sasl_client_io_instance->on_io_open_complete = on_io_open_complete;
			sasl_client_io_instance->on_io_error = on_io_error;
			sasl_client_io_instance->open_callback_context = callback_context;
			sasl_client_io_instance->sasl_header_exchange_state = SASL_HEADER_EXCHANGE_IDLE;
			sasl_client_io_instance->sasl_client_negotiation_state = SASL_CLIENT_NEGOTIATION_NOT_STARTED;
			sasl_client_io_instance->header_bytes_received = 0;
			sasl_client_io_instance->io_state = IO_STATE_OPENING_UNDERLYING_IO;

			/* Codes_SRS_SASLCLIENTIO_01_009: [saslclientio_open shall call xio_open on the underlying_io passed to saslclientio_create.] */
			/* Codes_SRS_SASLCLIENTIO_01_013: [saslclientio_open shall pass to xio_open a callback for receiving bytes and a state changed callback for the underlying_io state changes.] */
			if (xio_open(sasl_client_io_instance->underlying_io, on_underlying_io_open_complete, on_underlying_io_bytes_received, on_underlying_io_error, sasl_client_io_instance) != 0)
			{
				/* Codes_SRS_SASLCLIENTIO_01_012: [If the open of the underlying_io fails, saslclientio_open shall fail and return non-zero value.] */
				result = __LINE__;
			}
			else
			{
				/* Codes_SRS_SASLCLIENTIO_01_010: [On success, saslclientio_open shall return 0.] */
				result = 0;
			}
		}
	}
	
	return result;
}
int tls_server_io_schannel_open(CONCRETE_IO_HANDLE tls_io, ON_IO_OPEN_COMPLETE on_io_open_complete, void* on_io_open_complete_context, ON_BYTES_RECEIVED on_bytes_received, void* on_bytes_received_context, ON_IO_ERROR on_io_error, void* on_io_error_context)
{
    int result;

    if (tls_io == NULL)
    {
        LogError("invalid argument detected: CONCRETE_IO_HANDLE tls_io = %p", tls_io);
        result = __FAILURE__;
    }
    else
    {
        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;

        if (tls_io_instance->tlsio_state != TLS_SERVER_IO_STATE_NOT_OPEN)
        {
            LogError("invalid tls_io_instance->tlsio_state = %s", ENUM_TO_STRING(TLS_SERVER_IO_STATE, tls_io_instance->tlsio_state));
            result = __FAILURE__;
        }
        else
        {
            tls_io_instance->on_io_open_complete = on_io_open_complete;
            tls_io_instance->on_io_open_complete_context = on_io_open_complete_context;

            tls_io_instance->on_bytes_received = on_bytes_received;
            tls_io_instance->on_bytes_received_context = on_bytes_received_context;

            tls_io_instance->on_io_error = on_io_error;
            tls_io_instance->on_io_error_context = on_io_error_context;

            tls_io_instance->tlsio_state = TLS_SERVER_IO_STATE_OPENING_UNDERLYING_IO;

            if (xio_open(tls_io_instance->socket_io, on_underlying_io_open_complete, tls_io_instance, on_underlying_io_bytes_received, tls_io_instance, on_underlying_io_error, tls_io_instance) != 0)
            {
                LogError("xio_open failed");
                tls_io_instance->tlsio_state = TLS_SERVER_IO_STATE_NOT_OPEN;
                result = __FAILURE__;
            }
            else
            {
                result = 0;
            }
        }
    }

    return result;
}
int tlsio_schannel_open(CONCRETE_IO_HANDLE tls_io, ON_IO_OPEN_COMPLETE on_io_open_complete, void* on_io_open_complete_context, ON_BYTES_RECEIVED on_bytes_received, void* on_bytes_received_context, ON_IO_ERROR on_io_error, void* on_io_error_context)
{
    int result;

    if (tls_io == NULL)
    {
        result = __LINE__;
    }
    else
    {
        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;

        if (tls_io_instance->tlsio_state != TLSIO_STATE_NOT_OPEN)
        {
            result = __LINE__;
        }
        else
        {
            tls_io_instance->on_io_open_complete = on_io_open_complete;
            tls_io_instance->on_io_open_complete_context = on_io_open_complete_context;

            tls_io_instance->on_bytes_received = on_bytes_received;
            tls_io_instance->on_bytes_received_context = on_bytes_received_context;

            tls_io_instance->on_io_error = on_io_error;
            tls_io_instance->on_io_error_context = on_io_error_context;

            tls_io_instance->tlsio_state = TLSIO_STATE_OPENING_UNDERLYING_IO;

            if (xio_open(tls_io_instance->socket_io, on_underlying_io_open_complete, tls_io_instance, on_underlying_io_bytes_received, tls_io_instance, on_underlying_io_error, tls_io_instance) != 0)
            {
                result = __LINE__;
                tls_io_instance->tlsio_state = TLSIO_STATE_NOT_OPEN;
            }
            else
            {
                result = 0;
            }
        }
    }

    return result;
}
int tlsio_wolfssl_open(CONCRETE_IO_HANDLE tls_io, ON_IO_OPEN_COMPLETE on_io_open_complete, void* on_io_open_complete_context, ON_BYTES_RECEIVED on_bytes_received, void* on_bytes_received_context, ON_IO_ERROR on_io_error, void* on_io_error_context)
{
    int result;

    if (tls_io == NULL)
    {
        result = __LINE__;
    }
    else
    {
        TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)tls_io;

        if (tls_io_instance->tlsio_state != TLSIO_STATE_NOT_OPEN)
        {
            LogError("Invalid state encountered.");
            result = __LINE__;
        }
        else
        {
            tls_io_instance->on_bytes_received = on_bytes_received;
            tls_io_instance->on_bytes_received_context = on_bytes_received_context;

            tls_io_instance->on_io_open_complete = on_io_open_complete;
            tls_io_instance->on_io_open_complete_context = on_io_open_complete_context;

            tls_io_instance->on_io_error = on_io_error;
            tls_io_instance->on_io_error_context = on_io_error_context;

            tls_io_instance->tlsio_state = TLSIO_STATE_OPENING_UNDERLYING_IO;

            if (create_wolfssl_instance(tls_io_instance) != 0)
            {
                tls_io_instance->tlsio_state = TLSIO_STATE_NOT_OPEN;
                result = __LINE__;
            }
            else if (xio_open(tls_io_instance->socket_io, on_underlying_io_open_complete, tls_io_instance, on_underlying_io_bytes_received, tls_io_instance, on_underlying_io_error, tls_io_instance) != 0)
            {
                tls_io_instance->tlsio_state = TLSIO_STATE_NOT_OPEN;
                result = __LINE__;
            }
            else
            {
                // The state can get changed in the on_underlying_io_open_complete
                if (tls_io_instance->tlsio_state == TLSIO_STATE_ERROR)
                {
                    LogError("Failed to connect to server.  The certificates may not be correct.");
                    result = __LINE__;
                }
                else
                {
                    int res;
                    tls_io_instance->tlsio_state = TLSIO_STATE_IN_HANDSHAKE;
                    res = wolfSSL_connect(tls_io_instance->ssl);
                    if (res != SSL_SUCCESS)
                    {
                        LogError("Failed to connect to server.");
                        tls_io_instance->tlsio_state = TLSIO_STATE_NOT_OPEN;
                        result = __LINE__;
                    }
                    else
                    {
                        result = 0;
                    }
                }
            }
        }
    }

    return result;
}
Example #7
0
int main(int argc, char *argv[])
{
    info_t ipipe;
    int ch, n, user = 0, demux_mode = TC_DEMUX_SEQ_ADJUST;
    int npass = 0, *pass = NULL, *new_pass = NULL;
    int keep_initial_seq = 0, hard_fps_flag = 0, pack_sl = PACKAGE_ALL;
    int unit_seek = 0, resync_seq1 = 0, resync_seq2 = INT_MAX;
    int a_track = 0, v_track = 0, subid = 0x80;
    double fps = PAL_FPS;
    long stream_stype = TC_STYPE_UNKNOWN;
    long stream_codec = TC_CODEC_UNKNOWN;
    long stream_magic = TC_MAGIC_UNKNOWN;
    long x;
    char *magic = "", *codec = NULL, *name = NULL;
    char *logfile = SYNC_LOGFILE, *str = NULL, *end = NULL;
    //defaults:
    //proper initialization
    memset(&ipipe, 0, sizeof(info_t));

    libtc_init(&argc, &argv);

    while ((ch = getopt(argc, argv, "A:a:d:x:i:vt:S:M:f:P:WHs:O?h")) != -1) {
        switch (ch) {
          case 'i':
            if (optarg[0] == '-') usage(EXIT_FAILURE);
            name = optarg;
            break;

          case 'O':
            keep_initial_seq = 1;
            break;

          case 'P':
            if (optarg[0] == '-') usage(EXIT_FAILURE);
            logfile = optarg;
            break;

          case 'S':
            if (optarg[0] == '-') usage(EXIT_FAILURE);
            n = sscanf(optarg,"%d,%d-%d",
                       &unit_seek, &resync_seq1, &resync_seq2);
            if (n < 0) {
                tc_log_error(EXE, "invalid parameter for option -S");
                usage(EXIT_FAILURE);
            }

            if (unit_seek < 0) {
                tc_log_error(EXE, "invalid unit parameter for option -S");
                usage(EXIT_FAILURE);
            }

            if (resync_seq1 < 0 || resync_seq2 < 0
             || resync_seq1 >= resync_seq2) {
                tc_log_error(EXE, "invalid sequence parameter for option -S");
                usage(EXIT_FAILURE);
            }
            break;

          case 'd':
            if (optarg[0] == '-') usage(EXIT_FAILURE);
            verbose = atoi(optarg);
            break;

          case 'f':
            if (optarg[0] == '-') usage(EXIT_FAILURE);
            fps = atof(optarg);
            break;

          case 'W':
            demux_mode = TC_DEMUX_SEQ_LIST;
            logfile = NULL;
            break;

          case 'H':
            hard_fps_flag = 1;
            break;

          case 'x':
            if (optarg[0] == '-') usage(EXIT_FAILURE);
            codec = optarg;

            if (strcmp(codec,"ac3") == 0) {
                pack_sl = PACKAGE_AUDIO_AC3;
                stream_codec = TC_CODEC_AC3;
            }

            if (strcmp(codec,"mpeg2") == 0) {
                pack_sl = PACKAGE_VIDEO;
                stream_codec = TC_CODEC_MPEG2;
            }

            if (strcmp(codec,"mp3") == 0) {
                pack_sl = PACKAGE_AUDIO_MP3;
                stream_codec = TC_CODEC_MP3;
            }

            if (strcmp(codec,"pcm") == 0) {
                pack_sl = PACKAGE_AUDIO_PCM;
                stream_codec = TC_CODEC_PCM;
            }

            if (strcmp(codec,"ps1") == 0) {
                pack_sl = PACKAGE_SUBTITLE;
                stream_codec = TC_CODEC_SUB;
            }
            break;

          case 't':
            if (optarg[0] == '-') usage(EXIT_FAILURE);
            magic = optarg;
            user = 1;
            break;

          case 's':
            if (optarg[0] == '-') usage(EXIT_FAILURE);
            subid = strtol(optarg, NULL, 16);
            break;

          case 'A':
            if (optarg[0] == '-') usage(EXIT_FAILURE);
            while (1) {
                x = strtol(str, &end, 0);
                if ((end == str) || (x < 1) || (x > 0xff)) {
                    tc_log_error(EXE, "invalid parameter for option -A");
                    exit(1);
                }

                if (*end == '\0') {
                    break;
                }
                if (*end != ',') {
                    tc_log_error(EXE, "invalid parameter for option -A");
                    exit(1);
                }
                str = end + 1;
                new_pass = realloc(pass, (npass + 1) * sizeof (int));
                if (new_pass == NULL) {
                    tc_log_error(EXE, "out of memory");
                    exit(1);
                }
                pass = new_pass;
                pass[npass++] = (int)x;
            }
            break;

          case 'M':
            if (optarg[0] == '-') usage(EXIT_FAILURE);
            demux_mode = atoi(optarg);

            if (demux_mode == TC_DEMUX_OFF)
                verbose = TC_QUIET;
            if (demux_mode < 0 || demux_mode > TC_DEMUX_MAX_OPTS) {
                tc_log_error(EXE, "invalid parameter for option -M");
                exit(1);
            }
            break;

          case 'a':
            if (optarg[0] == '-') usage(EXIT_FAILURE);

            if ((n = sscanf(optarg,"%d,%d", &a_track, &v_track)) <= 0) {
                tc_log_error(EXE, "invalid parameter for option -a");
                exit(1);
            }
            break;

          case 'v':
            version();
            exit(0);
            break;

          case 'h':
            usage(EXIT_SUCCESS);
          default:
            usage(EXIT_FAILURE);
        }
    }

    ac_init(AC_ALL);

    /* ------------------------------------------------------------
     * fill out defaults for info structure
     * ------------------------------------------------------------*/

    // assume defaults
    if (name == NULL)
        stream_stype=TC_STYPE_STDIN;

    // no autodetection yet
    if (argc == 1) {
        usage(EXIT_FAILURE);
    }

    // do not try to mess with the stream
    if (stream_stype == TC_STYPE_STDIN) {
        ipipe.fd_in = STDIN_FILENO;
    } else {
        if (tc_file_check(name))
            exit(1);

        ipipe.fd_in = xio_open(name, O_RDONLY);
        if (ipipe.fd_in < 0) {
            tc_log_perror(EXE, "open file");
            exit(1);
        }

        // try to find out the filetype
        stream_magic = fileinfo(ipipe.fd_in, 0);

        if (verbose)
            tc_log_msg(EXE, "(pid=%d) %s", getpid(), filetype(stream_magic));
    }

    // fill out defaults for info structure
    ipipe.fd_out = STDOUT_FILENO;

    ipipe.magic = stream_magic;
    ipipe.stype = stream_stype;
    ipipe.codec = stream_codec;

    ipipe.verbose = verbose;

    ipipe.ps_unit = unit_seek;
    ipipe.ps_seq1 = resync_seq1;
    ipipe.ps_seq2 = resync_seq2;

    ipipe.demux  = demux_mode;
    ipipe.select = pack_sl;
    ipipe.keep_seq = keep_initial_seq;
    ipipe.subid = subid;
    ipipe.fps = fps;

    ipipe.hard_fps_flag = hard_fps_flag;
    ipipe.track = a_track;
    ipipe.name  = logfile;

    //FIXME: video defaults to 0

    /* ------------------------------------------------------------
     * main processing mode
     * ------------------------------------------------------------*/

    if (npass > 0)
        tcdemux_pass_through(&ipipe, pass, npass);
    else
        tcdemux_thread(&ipipe);

    return 0;
}
Example #8
0
int main(int argc, char *argv[])
{

    info_t ipipe;

    int user=0;

    long
	stream_stype = TC_STYPE_UNKNOWN,
	stream_magic = TC_MAGIC_UNKNOWN,
	stream_codec = TC_CODEC_UNKNOWN;

    int ch, done=0, track=0;
    char *magic=NULL, *codec=NULL, *name=NULL;

    //proper initialization
    memset(&ipipe, 0, sizeof(info_t));
    ipipe.frame_limit[0]=0;
    ipipe.frame_limit[1]=LONG_MAX;

    libtc_init(&argc, &argv);

    while ((ch = getopt(argc, argv, "d:x:i:f:a:vt:C:?h")) != -1) {

	switch (ch) {

	case 'i':

	  if(optarg[0]=='-') usage(EXIT_FAILURE);
	  name = optarg;

	  break;

	case 'd':

	  if(optarg[0]=='-') usage(EXIT_FAILURE);
	  verbose = atoi(optarg);

	  break;

	case 'x':

	  if(optarg[0]=='-') usage(EXIT_FAILURE);
	  codec = optarg;
	  break;

	case 'f':

	  if(optarg[0]=='-') usage(EXIT_FAILURE);
	  ipipe.nav_seek_file = optarg;

	  break;

	case 't':

	  if(optarg[0]=='-') usage(EXIT_FAILURE);
	  magic = optarg;
	  user=1;

	  break;

	case 'a':

	  if(optarg[0]=='-') usage(EXIT_FAILURE);
	  track = strtol(optarg, NULL, 0);
	  break;

        case 'C':

          if(optarg[0]=='-') usage(EXIT_FAILURE);
          if (2 != sscanf(optarg,"%ld-%ld", &ipipe.frame_limit[0], &ipipe.frame_limit[1])) usage(EXIT_FAILURE);
          if (ipipe.frame_limit[0] > ipipe.frame_limit[1])
          {
                tc_log_error(EXE, "Invalid -C options");
                usage(EXIT_FAILURE);
          }
          break;

	case 'v':
	  version();
	  exit(0);
	  break;

	case 'h':
	  usage(EXIT_SUCCESS);
	default:
	  usage(EXIT_FAILURE);
	}
    }

    ac_init(AC_ALL);

    /* ------------------------------------------------------------
     *
     * fill out defaults for info structure
     *
     * ------------------------------------------------------------*/

    // assume defaults
    if(name==NULL) stream_stype=TC_STYPE_STDIN;

    // no autodetection yet
    if(codec==NULL && magic==NULL) {
      tc_log_error(EXE, "invalid codec %s", codec);
      usage(EXIT_FAILURE);
    }

    if(codec==NULL) codec="";

    // do not try to mess with the stream
    if(stream_stype!=TC_STYPE_STDIN) {

      if(tc_file_check(name)) exit(1);

      if((ipipe.fd_in = xio_open(name, O_RDONLY))<0) {
	tc_log_perror(EXE, "file open");
	return(-1);
      }

      stream_magic = fileinfo(ipipe.fd_in, 0);

      if(verbose & TC_DEBUG)
	tc_log_msg(EXE, "(pid=%d) %s", getpid(), filetype(stream_magic));

    } else ipipe.fd_in = STDIN_FILENO;

    if(verbose & TC_DEBUG)
	tc_log_msg(EXE, "(pid=%d) starting, doing %s", getpid(), codec);

    // fill out defaults for info structure
    ipipe.fd_out = STDOUT_FILENO;

    ipipe.magic   = stream_magic;
    ipipe.stype   = stream_stype;
    ipipe.codec   = stream_codec;
    ipipe.track   = track;
    ipipe.select  = TC_VIDEO;

    ipipe.verbose = verbose;

    ipipe.name = name;

    /* ------------------------------------------------------------
     *
     * codec specific section
     *
     * note: user provided magic values overwrite autodetection!
     *
     * ------------------------------------------------------------*/

    if(magic==NULL) magic="";

    // OGM

    if (ipipe.magic == TC_MAGIC_OGG) {

	// dummy for video
	if(strcmp(codec, "raw")==0) ipipe.codec = TC_CODEC_RGB24;
	if((strcmp(codec, "vorbis")==0) || (strcmp(codec, "ogg")==0)) {
	    ipipe.codec = TC_CODEC_VORBIS;
	    ipipe.select = TC_AUDIO;
	}
	if(strcmp(codec, "mp3")==0) {
	    ipipe.codec = TC_CODEC_MP3;
	    ipipe.select = TC_AUDIO;
	}
	if(strcmp(codec, "pcm")==0) {
	    ipipe.codec = TC_CODEC_PCM;
	    ipipe.select = TC_AUDIO;
	}

	extract_ogm(&ipipe);
	done = 1;
    }

    // MPEG2
    if(strcmp(codec,"mpeg2")==0) {

      ipipe.codec = TC_CODEC_MPEG2;

      if(strcmp(magic, "vob")==0) ipipe.magic = TC_MAGIC_VOB;
      if(strcmp(magic, "m2v")==0) ipipe.magic = TC_MAGIC_M2V;
      if(strcmp(magic, "raw")==0) ipipe.magic = TC_MAGIC_RAW;

      extract_mpeg2(&ipipe);
      done = 1;
    }

    // PCM
    if(strcmp(codec,"pcm")==0) {

	ipipe.codec = TC_CODEC_PCM;
	ipipe.select = TC_AUDIO;

	if(strcmp(magic, "vob")==0) ipipe.magic = TC_MAGIC_VOB;
	if(strcmp(magic, "avi")==0) ipipe.magic = TC_MAGIC_AVI;
	if(strcmp(magic, "raw")==0) ipipe.magic = TC_MAGIC_RAW;
	if(strcmp(magic, "wav")==0) ipipe.magic = TC_MAGIC_WAV;

	extract_pcm(&ipipe);
	done = 1;
    }

    // SUBTITLE (private_stream_1)
    if(strcmp(codec,"ps1")==0) {

	ipipe.codec = TC_CODEC_PS1;
	ipipe.select = TC_AUDIO;

	if(strcmp(magic, "vob")==0) ipipe.magic = TC_MAGIC_VOB;
	if(strcmp(magic, "vdr")==0) ipipe.magic = TC_MAGIC_VDR;

	extract_ac3(&ipipe);
	done = 1;
    }


    // DV
    if(strcmp(codec,"dv")==0) {

	ipipe.codec = TC_CODEC_DV;

	if(strcmp(magic, "avi")==0) ipipe.magic = TC_MAGIC_AVI;
	if(strcmp(magic, "raw")==0) ipipe.magic = TC_MAGIC_RAW;

	extract_dv(&ipipe);
	done = 1;
    }


    // RGB
    if(strcmp(codec,"rgb")==0) {

	ipipe.codec = TC_CODEC_RGB24;

	if(strcmp(magic, "avi")==0) ipipe.magic = TC_MAGIC_AVI;
	if(strcmp(magic, "raw")==0) ipipe.magic = TC_MAGIC_RAW;
	if(strcmp(magic, "wav")==0) ipipe.magic = TC_MAGIC_WAV;

	extract_rgb(&ipipe);
	done = 1;
    }


    // DTS
    if(strcmp(codec,"dts")==0) {

	ipipe.codec = TC_CODEC_DTS;
	ipipe.select = TC_AUDIO;

	if(strcmp(magic, "raw")==0) ipipe.magic = TC_MAGIC_RAW;
	if(strcmp(magic, "vob")==0) ipipe.magic = TC_MAGIC_VOB;

	extract_ac3(&ipipe);
	done = 1;
    }

    // AC3
    if(strcmp(codec,"ac3")==0) {

	ipipe.codec = TC_CODEC_AC3;
	ipipe.select = TC_AUDIO;

	if(strcmp(magic, "raw")==0) ipipe.magic = TC_MAGIC_RAW;
	if(strcmp(magic, "vob")==0) ipipe.magic = TC_MAGIC_VOB;

	extract_ac3(&ipipe);
	done = 1;
    }

    // MP3
    if(strcmp(codec,"mp3")==0 || strcmp(codec,"mp2")==0) {

	ipipe.codec = TC_CODEC_MP3;
	ipipe.select = TC_AUDIO;

	if(strcmp(magic, "avi")==0) ipipe.magic = TC_MAGIC_AVI;
	if(strcmp(magic, "raw")==0) ipipe.magic = TC_MAGIC_RAW;
	if(strcmp(magic, "vob")==0) ipipe.magic = TC_MAGIC_VOB;

	extract_mp3(&ipipe);
	done = 1;
    }

    // YUV420P
    if(strcmp(codec,"yuv420p")==0) {

	ipipe.codec = TC_CODEC_YUV420P;

	if(strcmp(magic, "avi")==0) ipipe.magic = TC_MAGIC_AVI;
	if(strcmp(magic, "raw")==0) ipipe.magic = TC_MAGIC_RAW;
	if(strcmp(magic, "yuv4mpeg")==0) ipipe.magic = TC_MAGIC_YUV4MPEG;

	extract_yuv(&ipipe);
	done = 1;
    }

    // YUV422P
    if(strcmp(codec,"yuv422p")==0) {

	ipipe.codec = TC_CODEC_YUV422P;

	if(strcmp(magic, "avi")==0) ipipe.magic = TC_MAGIC_AVI;
	if(strcmp(magic, "raw")==0) ipipe.magic = TC_MAGIC_RAW;
	if(strcmp(magic, "yuv4mpeg")==0) ipipe.magic = TC_MAGIC_YUV4MPEG;

	extract_yuv(&ipipe);
	done = 1;
    }

    // UYVY
    if(strcmp(codec,"uyvy")==0) {

	ipipe.codec = TC_CODEC_UYVY;

	if(strcmp(magic, "avi")==0) ipipe.magic = TC_MAGIC_AVI;
	if(strcmp(magic, "raw")==0) ipipe.magic = TC_MAGIC_RAW;

	extract_yuv(&ipipe);
	done = 1;
    }


    // LZO
    if(strcmp(codec,"lzo")==0) {

	ipipe.codec = TC_CODEC_YUV420P;

	if(strcmp(magic, "avi")==0) ipipe.magic = TC_MAGIC_AVI;
	if(strcmp(magic, "raw")==0) ipipe.magic = TC_MAGIC_RAW;

	extract_lzo(&ipipe);
	done = 1;
    }


    // AVI extraction

    //need to check if there isn't a codec from the input option (if we have a file with TC_MAGIC_AVI and we specify -x pcm we have pcm and rgb output)
    if ((strcmp(magic, "avi")==0 || ipipe.magic==TC_MAGIC_AVI)&& (codec == NULL)) {

	ipipe.magic=TC_MAGIC_AVI;
	extract_avi(&ipipe);
	done = 1;
    }

    if (strcmp(codec, "raw")==0 || strcmp(codec, "video")==0) {
	ipipe.select=TC_VIDEO-1;
	ipipe.magic=TC_MAGIC_AVI;
	extract_avi(&ipipe);
	done = 1;
    }


    if(!done) {
	tc_log_error(EXE, "(pid=%d) unable to handle codec %s", getpid(), codec);
	exit(1);
    }

    if(ipipe.fd_in != STDIN_FILENO) xio_close(ipipe.fd_in);

    return(0);
}