int tlsio_schannel_close(CONCRETE_IO_HANDLE tls_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context) { int result = 0; 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) || (tls_io_instance->tlsio_state == TLSIO_STATE_CLOSING)) { result = __LINE__; } else { tls_io_instance->tlsio_state = TLSIO_STATE_CLOSING; tls_io_instance->on_io_close_complete = on_io_close_complete; tls_io_instance->on_io_close_complete_context = callback_context; if (xio_close(tls_io_instance->socket_io, on_underlying_io_close_complete, tls_io_instance) != 0) { result = __LINE__; } else { result = 0; } } } return result; }
static void on_underlying_io_open_complete(void* context, IO_OPEN_RESULT open_result) { HEADER_DETECT_IO_INSTANCE* header_detect_io_instance = (HEADER_DETECT_IO_INSTANCE*)context; switch (header_detect_io_instance->io_state) { default: break; case IO_STATE_OPENING_UNDERLYING_IO: if (open_result == IO_OPEN_OK) { header_detect_io_instance->io_state = IO_STATE_WAIT_FOR_HEADER; } else { if (xio_close(header_detect_io_instance->underlying_io, on_underlying_io_close_complete, header_detect_io_instance) != 0) { header_detect_io_instance->io_state = IO_STATE_NOT_OPEN; indicate_open_complete(header_detect_io_instance, IO_OPEN_ERROR); } } break; } }
void mqtt_client_sample_run() { if (platform_init() != 0) { PrintLogFunction(LOG_LINE, "platform_init failed"); } else { MQTT_CLIENT_HANDLE mqttHandle = mqtt_client_init(OnRecvCallback, OnOperationComplete, NULL, PrintLogFunction); if (mqttHandle == NULL) { PrintLogFunction(LOG_LINE, "mqtt_client_init failed"); } else { MQTT_CLIENT_OPTIONS options = { 0 }; options.clientId = "azureiotclient"; options.willMessage = NULL; options.username = NULL; options.password = NULL; options.keepAliveInterval = 10; options.useCleanSession = true; options.qualityOfServiceValue = DELIVER_AT_MOST_ONCE; SOCKETIO_CONFIG config = {"test.mosquitto.org", PORT_NUM_UNENCRYPTED, NULL}; XIO_HANDLE xio = xio_create(socketio_get_interface_description(), &config, PrintLogFunction); if (xio == NULL) { PrintLogFunction(LOG_LINE, "xio_create failed"); } else { if (mqtt_client_connect(mqttHandle, xio, &options) != 0) { PrintLogFunction(LOG_LINE, "mqtt_client_connect failed"); } else { do { mqtt_client_dowork(mqttHandle); } while (g_continue); } xio_close(xio, OnCloseComplete, NULL); } mqtt_client_deinit(mqttHandle); } platform_deinit(); } #ifdef _CRT_DBG_MAP_ALLOC _CrtDumpMemoryLeaks(); #endif }
/** * Shows a configuration menu for the machine. * * @param pContext Context object * @return Main menu state */ ut_state ut_state_config_maquina(ut_context* pContext) { ut_menu config_menu; uint8_t i; /* Initialize variables */ init(); /* Initialize menu */ ut_menu_init(&config_menu); /* Options */ config_menu.title = gszConfigMenuTitle; // config_menu.offset = 1; /* Items */ for(i = 0; i < CFG_MAQUINA_MAX; i++) { config_menu.items[config_menu.numItems++].text = configsMaq[i].name; } /* Show menu */ config_menu.selectedItem = 0; if(ut_menu_browse(&config_menu, DEFAULT_CONFIG_TIMEOUT) < 0) { return STATE_MAIN_MENU; } /* Set selected item */ pContext->value[0] = STATE_CONFIG_MAQUINA; configsVar = &configsMaq[config_menu.selectedItem]; switch(config_menu.selectedItem) { case CFG_MAQUINA_PARAMETROS: ut_lcd_output_warning("CUIDADO!!!\nA MÁQUINA IRÁ\nRESETAR\n"); if(delay_esc(2000) == KEY_ESC) { xio_close(cs.primary_src); ut_lcd_output_warning("COMANDO\nCANCELADO\n"); /* Delay */ vTaskDelay(1000 / portTICK_PERIOD_MS); return STATE_CONFIG_MAQUINA; } configsVar->name = "DESEJA CONTINUAR?"; pContext->value[0] = STATE_CONFIG_MAQUINA; pContext->value[1] = STATE_CONFIG_PARAMETROS_MAQ; break; default: break; } return geNextStateMaq[config_menu.selectedItem]; }
/** * 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 {
void uih_save_disable(struct uih_context *uih) { if (uih->save) { last = 1; if (uih->savec->mode >= UIH_SAVEANIMATION) uih_saveframe(uih); if (xio_close(uih->savec->file)) outputerror(uih); uih->save = 0; free(uih->savec->fcontext); tl_free_timer(uih->savec->timer); tl_free_timer(uih->savec->synctimer); free(uih->savec); uih_updatemenus(uih, "save"); } }
int saslclientio_close(CONCRETE_IO_HANDLE sasl_client_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context) { int result = 0; /* Codes_SRS_SASLCLIENTIO_01_017: [If sasl_client_io is NULL, saslclientio_close shall fail and return a non-zero value.] */ if (sasl_client_io == NULL) { result = __LINE__; } else { SASL_CLIENT_IO_INSTANCE* sasl_client_io_instance = (SASL_CLIENT_IO_INSTANCE*)sasl_client_io; /* Codes_SRS_SASLCLIENTIO_01_098: [saslclientio_close shall only perform the close if the state is OPEN, OPENING or ERROR.] */ if ((sasl_client_io_instance->io_state == IO_STATE_NOT_OPEN) || (sasl_client_io_instance->io_state == IO_STATE_CLOSING)) { result = __LINE__; } else { sasl_client_io_instance->io_state = IO_STATE_CLOSING; /* Codes_SRS_SASLCLIENTIO_01_015: [saslclientio_close shall close the underlying io handle passed in saslclientio_create by calling xio_close.] */ if (xio_close(sasl_client_io_instance->underlying_io, on_underlying_io_close_complete, sasl_client_io_instance) != 0) { /* Codes_SRS_SASLCLIENTIO_01_018: [If xio_close fails, then saslclientio_close shall return a non-zero value.] */ result = __LINE__; } else { /* Codes_SRS_SASLCLIENTIO_01_016: [On success, saslclientio_close shall return 0.] */ result = 0; } } } return result; }
int tls_server_io_schannel_close(CONCRETE_IO_HANDLE tls_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context) { int result = 0; if (tls_io == NULL) { LogError("invalid argument detected: 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) || (tls_io_instance->tlsio_state == TLS_SERVER_IO_STATE_CLOSING)) { 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->tlsio_state = TLS_SERVER_IO_STATE_CLOSING; tls_io_instance->on_io_close_complete = on_io_close_complete; tls_io_instance->on_io_close_complete_context = callback_context; if (xio_close(tls_io_instance->socket_io, on_underlying_io_close_complete, tls_io_instance) != 0) { LogError("xio_close failed"); result = __FAILURE__; } else { result = 0; } } } return result; }
static void handle_error(SASL_CLIENT_IO_INSTANCE* sasl_client_io_instance) { switch (sasl_client_io_instance->io_state) { default: case IO_STATE_NOT_OPEN: break; case IO_STATE_OPENING_UNDERLYING_IO: case IO_STATE_SASL_HANDSHAKE: if (xio_close(sasl_client_io_instance->underlying_io, on_underlying_io_close_complete, sasl_client_io_instance) != 0) { sasl_client_io_instance->io_state = IO_STATE_NOT_OPEN; indicate_open_complete(sasl_client_io_instance, IO_OPEN_ERROR); } break; case IO_STATE_OPEN: sasl_client_io_instance->io_state = IO_STATE_ERROR; indicate_error(sasl_client_io_instance); break; } }
int headerdetectio_close(CONCRETE_IO_HANDLE header_detect_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_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_CLOSING)) { result = __LINE__; } else { header_detect_io_instance->io_state = IO_STATE_CLOSING; header_detect_io_instance->on_io_close_complete = on_io_close_complete; header_detect_io_instance->on_io_close_complete_context = callback_context; if (xio_close(header_detect_io_instance->underlying_io, on_underlying_io_close_complete, header_detect_io_instance) != 0) { result = __LINE__; } else { result = 0; } } } return result; }
static void warning_semzeromaquina_callback(warn_btn_t btn_type) { switch (btn_type) { case BTN_PRESSED_SIM: if (warning_case == 0) { xio_close(cs.primary_src); warn_args.buttonUseInit = BTN_ASK; warn_args.img_txt[0] = IMG_CONTINUAR; warn_args.msg_count = 1; warn_args.func_callback = warning_desloca_callback; warning_page.p_args = &warn_args; mn_screen_change(&warning_page,EVENT_SHOW); } else if (warning_case == 1) { warning_page.p_args = &warn_zerarpeca_args; mn_screen_change(&warning_page,EVENT_SHOW); } break; case BTN_PRESSED_NAO: mn_screen_change(&manual_page,EVENT_SHOW); break; } }
catalog_t * load_catalog (xio_file f, CONST char **error) { int i; int line = 1; int size; int c; catalog_t *catalog = alloc_catalog (); static char errort[40]; char name[1024]; char value[1024]; if (catalog == NULL) { *error = "Out of memory"; } if (f == NULL) { *error = "File could not be opended"; free_catalog (catalog); return NULL; } /* Just very simple parsing loop of format * [blanks]name[blanks]"value"[blanks] * Blanks should be comments using # or space, newline, \r and tabulator * Value shoud contain and \ seqences where \\ means \ and * \[something] means something. Should be used for character " */ while (!xio_feof (f)) { do { c = xio_getc (f); if (c == '\n') line++; if (c == '#') { while ((c = xio_getc (f)) != '\n' && c != XIO_EOF); line++; } } while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); /*Skip blanks */ if (c == XIO_EOF) { if (xio_feof (f)) break; free_catalog (catalog); seterror ("read error"); xio_close (f); return NULL; } i = 0; /*read name */ do { name[i] = c; i++; c = xio_getc (f); if (c == '\n') line++; if (i == 1024) { seterror ("Name is too long(1024 or more characters)"); free_catalog (catalog); xio_close (f); return NULL; } } while (c != '\n' && c != ' ' && c != '\t' && c != XIO_EOF); /*Skip blanks */ while (c == ' ' || c == '\n' || c == '\r' || c == '\t') { c = xio_getc (f); if (c == '\n') line++; if (c == '#') { while ((c = xio_getc (f)) != '\n' && c != XIO_EOF); line++; } } /*Skip blanks */ if (c == XIO_EOF) { if (xio_feof (f)) seterror ("Inexpected end of file after name field"); else seterror ("read error"); free_catalog (catalog); xio_close (f); return NULL; } name[i] = 0; if (c != '"') { seterror ("Begin of value field expected (\")"); free_catalog (catalog); xio_close (f); return NULL; } c = xio_getc (f); if (c == '\n') line++; i = 0; size = 0; do { if (c == '\\') value[i] = xio_getc (f); else value[i] = c; i++; c = xio_getc (f); if (c == '\n') line++, size = 0; if (size == 40 && c != '"') { fprintf (stderr, "Warning - too long text at line %i\n", line); } size++; if (i == 1024) { seterror ("Value is too long(1024 or more characters)"); free_catalog (catalog); xio_close (f); return NULL; } } while (c != '"' && c != XIO_EOF); if (c == XIO_EOF) { seterror ("Inexpeced end of file in value filed"); free_catalog (catalog); xio_close (f); return NULL; } value[i] = 0; find_variable (catalog, name, value); } /*while */ xio_close (f); return (catalog); } /*load_catalog */
stat_t _command_dispatch() { #ifdef __AVR stat_t status; // read input line or return if not a completed line // xio_gets() is a non-blocking workalike of fgets() while (true) { if ((status = xio_gets(cs.primary_src, cs.in_buf, sizeof(cs.in_buf))) == STAT_OK) { cs.bufp = cs.in_buf; break; } // handle end-of-file from file devices if (status == STAT_EOF) { // EOF can come from file devices only if (cfg.comm_mode == TEXT_MODE) { fprintf_P(stderr, PSTR("End of command file\n")); } else { rpt_exception(STAT_EOF); // not really an exception } tg_reset_source(); // reset to default source } return (status); // Note: STAT_EAGAIN, errors, etc. will drop through } #endif // __AVR #ifdef __ARM // detect USB connection and transition to disconnected state if it disconnected if (SerialUSB.isConnected() == false) cs.state = CONTROLLER_NOT_CONNECTED; // read input line and return if not a completed line if (cs.state == CONTROLLER_READY) { if (read_line(cs.in_buf, &cs.read_index, sizeof(cs.in_buf)) != STAT_OK) { cs.bufp = cs.in_buf; return (STAT_OK); // This is an exception: returns OK for anything NOT OK, so the idler always runs } } else if (cs.state == CONTROLLER_NOT_CONNECTED) { if (SerialUSB.isConnected() == false) return (STAT_OK); cm_request_queue_flush(); rpt_print_system_ready_message(); cs.state = CONTROLLER_STARTUP; } else if (cs.state == CONTROLLER_STARTUP) { // run startup code cs.state = CONTROLLER_READY; } else { return (STAT_OK); } cs.read_index = 0; #endif // __ARM #ifdef __RX stat_t status; parse_gcode_func_selection(CODE_PARSER); // read input line or return if not a completed line // xio_gets() is a non-blocking workalike of fgets() while (true) { if ((status = xio_gets(cs.primary_src, cs.in_buf, sizeof(cs.in_buf))) == STAT_OK) { cs.bufp = cs.in_buf; break; } // handle end-of-file from file devices if (status == STAT_EOF) { // EOF can come from file devices only //gfilerunning = false; xio_close(cs.primary_src); // macro_func_ptr = command_idle; if (cfg.comm_mode == TEXT_MODE) { fprintf_P(stderr, PSTR("End of command file\n")); } else { rpt_exception(STAT_EOF); // not really an exception } tg_reset_source(); // reset to default source } return (status); // Note: STAT_EAGAIN, errors, etc. will drop through } #endif // __AVR // set up the buffers cs.linelen = strlen(cs.in_buf)+1; // linelen only tracks primary input strncpy(cs.saved_buf, cs.bufp, SAVED_BUFFER_LEN-1); // save input buffer for reporting // dispatch the new text line switch (toupper(*cs.bufp)) { // first char case '!': { cm_request_feedhold(); break; } // include for AVR diagnostics and ARM serial case '%': { cm_request_queue_flush(); break; } case '~': { cm_request_cycle_start(); break; } case NUL: { // blank line (just a CR) if (cfg.comm_mode != JSON_MODE) { text_response(STAT_OK, cs.saved_buf); } break; } case '$': case '?': case 'H': { // text mode input cfg.comm_mode = TEXT_MODE; text_response(text_parser(cs.bufp), cs.saved_buf); break; } case '{': { // JSON input cfg.comm_mode = JSON_MODE; json_parser(cs.bufp); break; } default: { // anything else must be Gcode if (cfg.comm_mode == JSON_MODE) { // run it as JSON... strncpy(cs.out_buf, cs.bufp, INPUT_BUFFER_LEN -8); // use out_buf as temp sprintf((char *)cs.bufp,"{\"gc\":\"%s\"}\n", (char *)cs.out_buf); // '-8' is used for JSON chars json_parser(cs.bufp); } else { //...or run it as text text_response(gc_gcode_parser(cs.bufp), cs.saved_buf); } } } return (STAT_OK); }
static void MqttOpCompleteCallback(MQTT_CLIENT_HANDLE handle, MQTT_CLIENT_EVENT_RESULT actionResult, const void* msgInfo, void* callbackCtx) { (void)handle; if (callbackCtx != NULL) { PMQTTTRANSPORT_HANDLE_DATA transportData = (PMQTTTRANSPORT_HANDLE_DATA)callbackCtx; switch (actionResult) { case MQTT_CLIENT_ON_PUBLISH_ACK: case MQTT_CLIENT_ON_PUBLISH_COMP: { const PUBLISH_ACK* puback = (const PUBLISH_ACK*)msgInfo; if (puback != NULL) { PDLIST_ENTRY currentListEntry = transportData->waitingForAck.Flink; while (currentListEntry != &transportData->waitingForAck) { MQTT_MESSAGE_DETAILS_LIST* mqttMsgEntry = containingRecord(currentListEntry, MQTT_MESSAGE_DETAILS_LIST, entry); DLIST_ENTRY saveListEntry; saveListEntry.Flink = currentListEntry->Flink; if (puback->packetId == mqttMsgEntry->msgPacketId) { (void)DList_RemoveEntryList(currentListEntry); //First remove the item from Waiting for Ack List. sendMsgComplete(mqttMsgEntry->iotHubMessageEntry, transportData, IOTHUB_BATCHSTATE_SUCCESS); free(mqttMsgEntry); } currentListEntry = saveListEntry.Flink; } } break; } case MQTT_CLIENT_ON_CONNACK: { const CONNECT_ACK* connack = (const CONNECT_ACK*)msgInfo; if (connack != NULL) { if (connack->returnCode == CONNECTION_ACCEPTED) { // The connect packet has been acked transportData->currPacketState = CONNACK_TYPE; } else { LogError("Connection not accepted, return code: %d.\r\n", connack->returnCode); (void)mqtt_client_disconnect(transportData->mqttClient); transportData->connected = false; transportData->currPacketState = PACKET_TYPE_ERROR; } } else { LogError("MQTT_CLIENT_ON_CONNACK CONNACK parameter is NULL.\r\n"); } break; } case MQTT_CLIENT_ON_SUBSCRIBE_ACK: { const SUBSCRIBE_ACK* suback = (const SUBSCRIBE_ACK*)msgInfo; if (suback != NULL) { if (suback->qosCount == 1) { // The connect packet has been acked transportData->currPacketState = SUBACK_TYPE; } else { LogError("QOS count was not expected: %d.\r\n", (int)suback->qosCount); } } break; } case MQTT_CLIENT_ON_PUBLISH_RECV: case MQTT_CLIENT_ON_PUBLISH_REL: { // Currently not used break; } case MQTT_CLIENT_ON_DISCONNECT: { // Close the client so we can reconnect again transportData->connected = false; transportData->currPacketState = DISCONNECT_TYPE; break; } case MQTT_CLIENT_ON_ERROR: { xio_close(transportData->xioTransport, NULL, NULL); transportData->connected = false; transportData->currPacketState = PACKET_TYPE_ERROR; } } } }
void page_handler (void *p_arg) { mn_screen_event_t *p_page_hdl = p_arg; if (p_page_hdl->event == EVENT_SHOW) { page->wt_selected = mn_screen_select_widget(page,&btn_manual); } else if (p_page_hdl->event == EVENT_SIGNAL(btn_manual.id,EVENT_CLICK)) { mn_screen_change(&jog_page,EVENT_SHOW); } else if (p_page_hdl->event == EVENT_SIGNAL(btn_vel_manual.id,EVENT_CLICK)) { vel_keypad_args.p_var = &configVarJog[JOG_RAPIDO]; vel_keypad_args.step = 1; vel_keypad_args.min = 10; vel_keypad_args.max = 10000; vel_keypad_args.p_ret_page = page; vel_keypad_args.p_next_page = page; keypad_page.p_args = &vel_keypad_args; mn_screen_change(&keypad_page,EVENT_SHOW); } else if (p_page_hdl->event == EVENT_SIGNAL(btn_deslocar.id,EVENT_CLICK)) { if (zeromaq_flag == true) { xio_close(cs.primary_src); warn_args.buttonUseInit = BTN_ASK; warn_args.img_txt[0] = IMG_CONTINUAR; warn_args.msg_count = 1; warn_args.func_callback = warning_desloca_callback; warning_page.p_args = &warn_args; mn_screen_change(&warning_page,EVENT_SHOW); } else { warning_case = 0; warning_page.p_args = &warn_semzeromaquina_args; mn_screen_change(&warning_page,EVENT_SHOW); } } else if (p_page_hdl->event == EVENT_SIGNAL(btn_zerar_maq.id,EVENT_CLICK)) { warning_page.p_args = &warn_zerarmaquina_args; mn_screen_change(&warning_page,EVENT_SHOW); } else if (p_page_hdl->event == EVENT_SIGNAL(btn_zerar_peca.id,EVENT_CLICK)) { if (zeromaq_flag == true) { warning_page.p_args = &warn_zerarpeca_args; mn_screen_change(&warning_page,EVENT_SHOW); } else { warning_case = 1; warning_page.p_args = &warn_semzeromaquina_args; mn_screen_change(&warning_page,EVENT_SHOW); } } else if (p_page_hdl->event == EVENT_SIGNAL(btn_voltar.id,EVENT_CLICK)) { mn_screen_change(&main_page,EVENT_SHOW); } else if (p_page_hdl->event == EMERGENCIA_SIGNAL_EVENT) { emergencia_args.p_ret_page = page; emergencia_page.p_args = &emergencia_args; mn_screen_change(&emergencia_page,EVENT_SHOW); } }
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); }