ac_result_t ac_add_frame(jb_frame_t *frame){ euclidean3_t tmp; float result; if(ac.frame_count){ // This isn't the first frame... euclidean3_copy(&frame->acc, &tmp); euclidean3_sub(&tmp, &ac.last, &tmp); ac.activity_per_frame[ac.frame_count - 1] = euclidean3_measure(&tmp); } ac.frame_count += 1; if(ac.frame_count == NFRAMES - 1){ arm_power_f32(ac.activity_per_frame, NFRAMES - 1, &result); // Convert to average power result /= (NFRAMES - 1); ac_init(); if(result < activity_threshold){ return AC_RES_INACTIVE; } return AC_RES_ACTIVE; } euclidean3_copy(&frame->acc, &ac.last); return AC_RES_INCOMPLETE; }
void ac_startup(ac_uptr ptr, ac_uint uword) { ac_init(ptr, uword); main(); ac_poweroff(); /* * If poweroff didn't work, reset the cpu */ reset_x86(); }
/** * \internal * \brief Setup Function: AC callback mode test. * * This function initializes the AC to generate interrupt when the AC * output toggles. * * \param test Current test case. */ static void setup_ac_callback_mode_test(const struct test_case *test) { enum status_code status = STATUS_ERR_IO; /* Structure for AC configuration */ struct ac_config config; struct ac_chan_config channel_config; /* Set the flag to false */ ac_init_success = false; ac_reset(&ac_inst); ac_get_config_defaults(&config); /* Initialize the AC */ status = ac_init(&ac_inst, AC, &config); /* Check for successful initialization */ test_assert_true(test, status == STATUS_OK, "AC initialization failed"); /* Configure the AC input pin */ struct system_pinmux_config ac0_pin_conf; system_pinmux_get_config_defaults(&ac0_pin_conf); ac0_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT; ac0_pin_conf.mux_position = MUX_PA04B_AC_AIN0; system_pinmux_pin_set_config(PIN_PA04B_AC_AIN0, &ac0_pin_conf); /* Channel configuration */ status = STATUS_ERR_IO; ac_chan_get_config_defaults(&channel_config); channel_config.sample_mode = AC_CHAN_MODE_CONTINUOUS; channel_config.positive_input = AC_CHAN_POS_MUX_PIN0; channel_config.negative_input = AC_CHAN_NEG_MUX_SCALED_VCC; channel_config.vcc_scale_factor = AC_SCALER_0_50_VOLT; status = ac_chan_set_config(&ac_inst, AC_CHAN_CHANNEL_0, &channel_config); /* Check for successful initialization */ test_assert_true(test, status == STATUS_OK, "AC channel initialization failed"); /* Callback configuration */ status = ac_register_callback(&ac_inst, ac_user_callback, AC_CALLBACK_COMPARATOR_0); test_assert_true(test, status == STATUS_OK, "AC callback registration failed"); /* Enable the AC channel & the module */ ac_chan_enable(&ac_inst, AC_CHAN_CHANNEL_0); ac_enable(&ac_inst); ac_enable_callback(&ac_inst, AC_CALLBACK_COMPARATOR_0); if (status == STATUS_OK) { ac_init_success = true; } }
MpAmipInterface::MpAmipInterface() : MpInterface() { if(!amip_dll) { bool res = loadAmipDll(); if(!res) { amip_dll = NULL; return; } ac_init(AC_START_CLIENT); } }
static void configure_ac(void) { static struct ac_module ac_instance; struct ac_config config_ac; ac_get_config_defaults(&config_ac); config_ac.ana_source_generator = GCLK_GENERATOR_1; config_ac.dig_source_generator = GCLK_GENERATOR_1; /* Initialize and enable the Analog Comparator with the user settings */ ac_init(&ac_instance, AC1, &config_ac); /* Create a new configuration structure for the Analog Comparator channel * settings and fill with the default module channel settings. */ struct ac_chan_config ac_chan_conf; ac_chan_get_config_defaults(&ac_chan_conf); /* Set the Analog Comparator channel configuration settings */ ac_chan_conf.sample_mode = AC_CHAN_MODE_CONTINUOUS; ac_chan_conf.filter = AC_CHAN_FILTER_NONE; ac_chan_conf.positive_input = AC_CHAN_POS_MUX_PIN3; ac_chan_conf.negative_input = AC_CHAN_NEG_MUX_SCALED_VCC; ac_chan_conf.vcc_scale_factor = AC_SCALING_FACTOR; ac_chan_conf.output_mode = AC_CHAN_OUTPUT_INTERNAL; /* Initialize and enable the Analog Comparator channel with the user * settings */ ac_chan_set_config(&ac_instance, 0, &ac_chan_conf); /* Set up a pin as an AC channel input */ struct system_pinmux_config ac0_pin_conf; system_pinmux_get_config_defaults(&ac0_pin_conf); ac0_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT; ac0_pin_conf.mux_position = MUX_PB03B_AC1_AIN3; system_pinmux_pin_set_config(PIN_PB03B_AC1_AIN3, &ac0_pin_conf); /* Setup event output from AC */ struct ac_events ac_event_conf; memset(&ac_event_conf, 0, sizeof(struct ac_events)); ac_event_conf.generate_event_on_state[0] = true; ac_enable_events(&ac_instance, &ac_event_conf); /* enable AC channel */ ac_chan_enable(&ac_instance, 0); ac_enable(&ac_instance); }
Datum adaptive_add_item_agg2(PG_FUNCTION_ARGS) { AdaptiveCounter acounter; /* info for anyelement */ Oid element_type = get_fn_expr_argtype(fcinfo->flinfo, 1); Datum element = PG_GETARG_DATUM(1); int16 typlen; bool typbyval; char typalign; /* is the counter created (if not, create it with default parameters) */ if (PG_ARGISNULL(0)) { acounter = ac_init(DEFAULT_ERROR, DEFAULT_NDISTINCT); } else { acounter = (AdaptiveCounter)PG_GETARG_BYTEA_P(0); } /* add the item to the estimator */ if (! PG_ARGISNULL(1)) { /* TODO The requests for type info shouldn't be a problem (thanks to lsyscache), * but if it turns out to have a noticeable impact it's possible to cache that * between the calls (in the estimator). */ /* get type information for the second parameter (anyelement item) */ get_typlenbyvalalign(element_type, &typlen, &typbyval, &typalign); /* it this a varlena type, passed by reference or by value ? */ if (typlen == -1) { /* varlena */ ac_add_item(acounter, VARDATA(element), VARSIZE(element) - VARHDRSZ); } else if (typbyval) { /* fixed-length, passed by value */ ac_add_item(acounter, (char*)&element, typlen); } else { /* fixed-length, passed by reference */ ac_add_item(acounter, (char*)element, typlen); } } /* return the updated bytea */ PG_RETURN_BYTEA_P(acounter); }
/** * \internal * \brief Test for AC initialization. * * This test initializes the AC module and checks whether the * initialization is successful or not. * * If this test fails no other tests will run. * * \param test Current test case. */ static void run_ac_init_test(const struct test_case *test) { enum status_code status = STATUS_ERR_IO; /* Structure for AC configuration */ struct ac_config config; struct ac_chan_config channel_config; ac_get_config_defaults(&config); /* Initialize the AC */ status = ac_init(&ac_inst, AC, &config); /* Check for successful initialization */ test_assert_true(test, status == STATUS_OK, "AC initialization failed"); status = STATUS_ERR_IO; ac_chan_get_config_defaults(&channel_config); channel_config.sample_mode = AC_CHAN_MODE_SINGLE_SHOT; channel_config.positive_input = AC_CHAN_POS_MUX_PIN0; channel_config.negative_input = AC_CHAN_NEG_MUX_SCALED_VCC; channel_config.vcc_scale_factor = AC_SCALER_0_50_VOLT; struct system_pinmux_config ac0_pin_conf; system_pinmux_get_config_defaults(&ac0_pin_conf); ac0_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT; ac0_pin_conf.mux_position = MUX_PA04B_AC_AIN0; system_pinmux_pin_set_config(PIN_PA04B_AC_AIN0, &ac0_pin_conf); /* Set the channel configuration */ status = ac_chan_set_config(&ac_inst, AC_CHAN_CHANNEL_0, &channel_config); /* Check for successful configuration */ test_assert_true(test, status == STATUS_OK, "AC channel configuration failed"); /* Enable the AC channel & AC module */ ac_chan_enable(&ac_inst, AC_CHAN_CHANNEL_0); ac_enable(&ac_inst); if (status == STATUS_OK) { ac_init_success = true; } }
//! [setup_3] void configure_ac(void) { //! [setup_3] /* Create a new configuration structure for the Analog Comparator settings * and fill with the default module settings. */ //! [setup_4] struct ac_config config_ac; //! [setup_4] //! [setup_5] ac_get_config_defaults(&config_ac); //! [setup_5] /* Alter any Analog Comparator configuration settings here if required */ /* Initialize and enable the Analog Comparator with the user settings */ //! [setup_6] ac_init(&ac_instance, AC, &config_ac); //! [setup_6] }
u32 dcdm_dp_init_ac_engine(void *buf) { u32 size; dcdmd_sig_ac_spec_s *ac_spec; if(NULL == buf) { return 1; } ac_spec = (dcdmd_sig_ac_spec_s *)buf; if(regex_init()) { return ERROR_NO_MEMORY; } memset(&g_dcdm_ac_engine, 0, sizeof(dcdm_ac_engine_s)); g_dcdm_ac_engine.ac.method = ac_spec->ac_method; g_dcdm_ac_engine.ac.threshold_state = ac_spec->ac_threshold_state; size = g_dp_ac_full_num_states * AC_BITMAP_STATE_NUM_RATIO * (sizeof(ac_bitmap_s) + sizeof(u32)); g_dcdm_ac_engine.ac.bitmap_state_table = conplat_malloc (size, MODULEID_DCDM); if(NULL == g_dcdm_ac_engine.ac.bitmap_state_table) { printk("<0>Fail to alloc memory for ac bitmap state table!\r\n"); return ERROR_NO_MEMORY; } g_dcdm_ac_engine.bitmap_state_table_size = size; size = g_dp_ac_full_num_states * (AC_BITMAP_STATE_NUM_RATIO + 1) * sizeof(ac_search_match_s); g_dcdm_ac_engine.ac.match_table = conplat_malloc (size, MODULEID_DCDM); if(NULL == g_dcdm_ac_engine.ac.match_table) { printk("<0>Fail to alloc memory for ac match state table!\r\n"); return ERROR_NO_MEMORY; } g_dcdm_ac_engine.match_state_table_size = size; ac_init(); return ERROR_SUCCESS; }
Datum adaptive_init(PG_FUNCTION_ARGS) { AdaptiveCounter ac; float errorRate; int ndistinct; errorRate = PG_GETARG_FLOAT4(0); ndistinct = PG_GETARG_INT32(1); /* ndistinct has to be positive, error rate between 0 and 1 (not 0) */ if (ndistinct < 1) { elog(ERROR, "ndistinct (expected number of distinct values) has to at least 1"); } else if ((errorRate <= 0) || (errorRate > 1)) { elog(ERROR, "error rate has to be between 0 and 1"); } ac = ac_init(errorRate, ndistinct); PG_RETURN_BYTEA_P(ac); }
void test_rp_ctx_create(rp_ctx_t **rp_ctx_p) { int rc = SR_ERR_OK; rp_ctx_t *ctx = NULL; ctx = calloc(1, sizeof(*ctx)); assert_non_null(ctx); rc = ac_init(TEST_DATA_SEARCH_DIR, &ctx->ac_ctx); assert_int_equal(SR_ERR_OK, rc); rc = np_init(ctx, &ctx->np_ctx); assert_int_equal(SR_ERR_OK, rc); rc = pm_init(ctx, TEST_INTERNAL_SCHEMA_SEARCH_DIR, TEST_DATA_SEARCH_DIR, &ctx->pm_ctx); assert_int_equal(SR_ERR_OK, rc); rc = dm_init(ctx->ac_ctx, ctx->np_ctx, ctx->pm_ctx, TEST_SCHEMA_SEARCH_DIR, TEST_DATA_SEARCH_DIR, &ctx->dm_ctx); assert_int_equal(SR_ERR_OK, rc); *rp_ctx_p = ctx; }
int main(int argc, char *argv[]) { /* needed by filter modules */ TCVHandle tcv_handle = tcv_init(); CmdLet cmdlet = cmdlet_usage; int ch, ret, status, i = 0; CmdLetData cdata = { .modpath = MOD_PATH, .factory = NULL, .modsnum = 0, }; ac_init(AC_ALL); tc_set_config_dir(NULL); libtc_init(&argc, &argv); filter[0].id = 0; /* to make gcc happy */ for (i = 0; i < MAX_MODS; i++) { modrequest_init(&cdata.mods[i]); } while (1) { ch = getopt(argc, argv, "LCd:?vhm:"); if (ch == -1) { break; } switch (ch) { case 'L': cmdlet = cmdlet_list; break; case 'C': cmdlet = cmdlet_check; break; case 'd': if (optarg[0] == '-') { cmdlet_usage(&cdata, argc, argv); return STATUS_BAD_PARAM; } verbose = atoi(optarg); break; case 'm': cdata.modpath = optarg; break; case 'v': version(); return STATUS_OK; case '?': /* fallthrough */ case 'h': /* fallthrough */ default: cmdlet_usage(&cdata, argc, argv); return STATUS_OK; } } /* XXX: watch out here */ argc -= optind; argv += optind; /* * we can't distinguish from OMS and NMS modules at glance, so try * first using new module system */ cdata.factory = tc_new_module_factory(cdata.modpath, verbose); status = cmdlet(&cdata, argc, argv); ret = tc_del_module_factory(cdata.factory); /* XXX: unchecked */ tcv_free(tcv_handle); return status; }
int main(int argc, char *argv[]) { struct common_struct rtf; struct AVIStreamHeader ash, vsh; avi_t *avifile; int err, fd, id = 0, track_num = 0, n, ch, debug = TC_FALSE; int brate = 0, val1 = 0, val2 = 1, a_rate, a_chan, a_bits; long ah_off = 0, af_off = 0, vh_off = 0, vf_off = 0; char codec[5], *str = NULL, *filename = NULL; uint32_t change = CHANGE_NOTHING; ac_init(AC_ALL); if (argc==1) usage(EXIT_FAILURE); while ((ch = getopt(argc, argv, "df:i:N:F:vb:e:a:?h")) != -1) { switch (ch) { case 'N': VALIDATE_OPTION; id = strtol(optarg, NULL, 16); if (id < 0) { tc_log_error(EXE, "invalid parameter set for option -N"); } else { change |= CHANGE_AUDIO_FMT; } break; case 'a': VALIDATE_OPTION; track_num = atoi(optarg); if (track_num < 0) usage(EXIT_FAILURE); break; case 'f': VALIDATE_OPTION; n = sscanf(optarg,"%d,%d", &val1, &val2); if (n != 2 || val1 < 0 || val2 < 0) { tc_log_error(EXE, "invalid parameter set for option -f"); } else { change |= CHANGE_VIDEO_FPS; } break; case 'F': VALIDATE_OPTION; str = optarg; if(strlen(str) > 4 || strlen(str) == 0) { tc_log_error(EXE, "invalid parameter set for option -F"); } else { change |= CHANGE_VIDEO_FOURCC; } break; case 'i': VALIDATE_OPTION; filename = optarg; break; case 'b': VALIDATE_OPTION; brate = atoi(optarg); change |= CHANGE_AUDIO_BR; break; case 'v': version(); exit(0); case 'e': VALIDATE_OPTION; n = sscanf(optarg,"%d,%d,%d", &a_rate, &a_bits, &a_chan); switch (n) { case 3: change |= CHANGE_AUDIO_RATE; case 2: change |= CHANGE_AUDIO_BITS; case 1: change |= CHANGE_AUDIO_CHANS; break; default: tc_log_error(EXE, "invalid parameter set for option -e"); } break; case 'd': debug = TC_TRUE; break; case 'h': usage(EXIT_SUCCESS); default: usage(EXIT_FAILURE); } } if (!filename) usage(EXIT_FAILURE); tc_log_info(EXE, "scanning AVI-file %s for header information", filename); avifile = AVI_open_input_file(filename, 1); if (!avifile) { AVI_print_error("AVI open"); exit(1); } AVI_info(avifile); if (AVI_set_audio_track(avifile, track_num) < 0) { tc_log_error(EXE, "invalid audio track"); } ah_off = AVI_audio_codech_offset(avifile); af_off = AVI_audio_codecf_offset(avifile); vh_off = AVI_video_codech_offset(avifile); vf_off = AVI_video_codecf_offset(avifile); if (debug) { tc_log_info(EXE, "offsets: ah=%li af=%li vh=%li vf=%li", ah_off, af_off, vh_off, vf_off); } AVI_close(avifile); fd = open(filename, O_RDWR); if (fd < 0) { perror("open"); exit(1); } lseek(fd, vh_off, SEEK_SET); hdr_read("video codec [h]", fd, codec, 4); codec[4] = 0; lseek(fd, vf_off, SEEK_SET); hdr_read("video codec [f]", fd, codec, 4); codec[4] = 0; if (change & CHANGE_VIDEO_FPS) { lseek(fd, vh_off-4, SEEK_SET); hdr_read("video fps", fd, &vsh, sizeof(vsh)); vsh.dwRate = (long)val1; vsh.dwScale = (long)val2; lseek(fd, vh_off-4, SEEK_SET); hdr_write("video fps", fd, &vsh, sizeof(vsh)); } if (change & CHANGE_VIDEO_FOURCC) { lseek(fd,vh_off,SEEK_SET); if (strncmp(str,"RGB",3) == 0) { hdr_write("video 4cc", fd, codec, 4); } else { hdr_write("video 4cc", fd, str, 4); } lseek(fd,vf_off,SEEK_SET); if(strncmp(str,"RGB",3)==0) { memset(codec, 0, 4); hdr_write("video 4cc", fd, codec, 4); } else { hdr_write("video 4cc", fd, str, 4); } } if (NEED_AUDIO_CHANGE(change)) { lseek(fd, ah_off, SEEK_SET); hdr_read("audio header [h]", fd, &ash, sizeof(ash)); lseek(fd, af_off, SEEK_SET); hdr_read("audio header [f]", fd, &rtf, sizeof(rtf)); if (change & CHANGE_AUDIO_FMT) { rtf.wFormatTag = (unsigned short) id; } if (change & CHANGE_AUDIO_BR) { rtf.dwAvgBytesPerSec = (long) 1000*brate/8; ash.dwRate = (long) 1000*brate/8; ash.dwScale = 1; } if (change & CHANGE_AUDIO_CHANS) { rtf.wChannels = (short) a_chan; } if (change & CHANGE_AUDIO_BITS) { rtf.wBitsPerSample = (short) a_bits; } if (change & CHANGE_AUDIO_RATE) { rtf.dwSamplesPerSec = (long) a_rate; } lseek(fd, ah_off ,SEEK_SET); hdr_write("audio header [h]", fd, &ash, sizeof(ash)); lseek(fd, af_off ,SEEK_SET); hdr_write("audio header [f]", fd, &rtf, sizeof(rtf)); } err = close(fd); if (err) { perror("close"); exit(1); } avifile = AVI_open_input_file(filename, 1); if (!avifile) { AVI_print_error("AVI open"); exit(1); } tc_log_info(EXE, "updated AVI file %s", filename); AVI_info(avifile); AVI_close(avifile); return 0; }
main() { char i,j,k,l,m,n; disp_off(); /* <- I don't think this works.... */ spr_set(); spr_hide(); load_default_font(); set_screen_size(SCR_SIZE_32x32); disp_on(); if(!sgx_detect()) { put_string("Halt: SGX not hardware found", 2, 13); for(;;){} } /* These NEED to be set, else you won't see the SGX 2nd layer BG or sprites. */ vpc_win_size( VPC_WIN_A, 0x01ff); vpc_win_size( VPC_WIN_B, 0x01ff); vpc_win_reg( VPC_WIN_A, VDC_ON+VPC_NORM); vpc_win_reg( VPC_WIN_B, VDC_ON+VPC_NORM); vpc_win_reg( VPC_WIN_AB, VDC_ON+VPC_NORM); vpc_win_reg( VPC_WIN_NONE, VDC_ON+VPC_NORM); set_font_pal(4); set_font_color(14,0); load_default_font(); put_string("SGX hardware found", 2, 3); sgx_set_screen_size(SCR_SIZE_32x32); sgx_load_vram(0x0000,map, 0x400); sgx_load_vram(0x1000,tile, 0x4000); load_palette(0, pal,16); sgx_spr_hide(); sgx_spr_set(1); sgx_disp_on(); put_string("Arcade Card: ", 2, 4); if ( ac_init() ) { put_string("detected.", 15, 4); /* initialize AC register 0 to address 0x000000 and +1 auto-increment */ ac_full_reg0(0x00,0x0000,0x0000,0x0001,0x11); put_string("CD->AC xfer... ", 2, 5); /* transfer 8k at a time from CD to AC memory via AC reg #0 */ ac_cd_xfer(AC_REG0,0,0x1c2,4); ac_cd_xfer(AC_REG0,0,0x1c6,4); ac_cd_xfer(AC_REG0,0,0x1ca,4); ac_cd_xfer(AC_REG0,0,0x1ce,4); ac_cd_xfer(AC_REG0,0,0x1d2,4); ac_cd_xfer(AC_REG0,0,0x1d6,4); ac_cd_xfer(AC_REG0,0,0x1da,4); ac_cd_xfer(AC_REG0,0,0x1de,4); put_string("finished.", 17, 5); sgx_bg_on(); /* reset AC reg #0 address to 0x000000 */ ac_addr_reg0(0x00,0x0000); ac_vram_dma(AC_REG0 ,0x1000,0x3c00, SGX); ac_addr_reg0(0x00,0x8000); ac_vram_dma(AC_REG0 ,0x0000,0x800, SGX); ac_addr_reg0(0x00,0x8800); ac_vce_copy( AC_REG0, 0x00, 0x100 ); vsync(60); vsync(60); } else { put_string("not detected.", 15, 4); for(;;){} } put_string("Scrolling SGX layer ", 2, 6); for(;;) { for( j=0; j<0xff; j++) { vsync(); sgx_scroll( j , j); } } }
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; }
int32_t main(int32_t argc, char *argv[]) { fix_stacksize(); run_tests(); int32_t i, j; prog_name = argv[0]; struct timespec start_ts; cs_gettime(&start_ts); // Initialize clock_type if(pthread_key_create(&getclient, NULL)) { fprintf(stderr, "Could not create getclient, exiting..."); exit(1); } void (*mod_def[])(struct s_module *) = { #ifdef MODULE_MONITOR module_monitor, #endif #ifdef MODULE_CAMD33 module_camd33, #endif #ifdef MODULE_CAMD35 module_camd35, #endif #ifdef MODULE_CAMD35_TCP module_camd35_tcp, #endif #ifdef MODULE_NEWCAMD module_newcamd, #endif #ifdef MODULE_CCCAM module_cccam, #endif #ifdef MODULE_PANDORA module_pandora, #endif #ifdef MODULE_GHTTP module_ghttp, #endif #ifdef CS_CACHEEX module_csp, #endif #ifdef MODULE_GBOX module_gbox, #endif #ifdef MODULE_CONSTCW module_constcw, #endif #ifdef MODULE_RADEGAST module_radegast, #endif #ifdef MODULE_SCAM module_scam, #endif #ifdef MODULE_SERIAL module_serial, #endif #ifdef HAVE_DVBAPI module_dvbapi, #endif 0 }; find_conf_dir(); parse_cmdline_params(argc, argv); if(bg && do_daemon(1, 0)) { printf("Error starting in background (errno=%d: %s)", errno, strerror(errno)); cs_exit(1); } get_random_bytes_init(); #ifdef WEBIF if(cs_restart_mode) { restart_daemon(); } #endif memset(&cfg, 0, sizeof(struct s_config)); cfg.max_pending = max_pending; if(cs_confdir[strlen(cs_confdir) - 1] != '/') { strcat(cs_confdir, "/"); } init_signal_pre(); // because log could cause SIGPIPE errors, init a signal handler first init_first_client(); cs_lock_create(__func__, &system_lock, "system_lock", 5000); cs_lock_create(__func__, &config_lock, "config_lock", 10000); cs_lock_create(__func__, &gethostbyname_lock, "gethostbyname_lock", 10000); cs_lock_create(__func__, &clientlist_lock, "clientlist_lock", 5000); cs_lock_create(__func__, &readerlist_lock, "readerlist_lock", 5000); cs_lock_create(__func__, &fakeuser_lock, "fakeuser_lock", 5000); cs_lock_create(__func__, &ecmcache_lock, "ecmcache_lock", 5000); cs_lock_create(__func__, &ecm_pushed_deleted_lock, "ecm_pushed_deleted_lock", 5000); cs_lock_create(__func__, &readdir_lock, "readdir_lock", 5000); cs_lock_create(__func__, &cwcycle_lock, "cwcycle_lock", 5000); init_cache(); cacheex_init_hitcache(); init_config(); cs_init_log(); init_machine_info(); init_check(); if(!oscam_pidfile && cfg.pidfile) { oscam_pidfile = cfg.pidfile; } if(!oscam_pidfile) { oscam_pidfile = get_tmp_dir_filename(default_pidfile, sizeof(default_pidfile), "oscam.pid"); } if(oscam_pidfile) { pidfile_create(oscam_pidfile); } cs_init_statistics(); coolapi_open_all(); init_stat(); ssl_init(); // These initializations *MUST* be called after init_config() // because modules depend on config values. for(i = 0; mod_def[i]; i++) { struct s_module *module = &modules[i]; mod_def[i](module); } init_sidtab(); init_readerdb(); cfg.account = init_userdb(); init_signal(); init_provid(); init_srvid(); init_tierid(); init_fakecws(); start_garbage_collector(gbdb); cacheex_init(); init_len4caid(); init_irdeto_guess_tab(); write_versionfile(false); led_init(); led_status_default(); azbox_init(); mca_init(); global_whitelist_read(); ratelimit_read(); for(i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; if((module->type & MOD_CONN_NET)) { for(j = 0; j < module->ptab.nports; j++) { start_listener(module, &module->ptab.ports[j]); } } } //set time for server to now to avoid 0 in monitor/webif first_client->last = time((time_t *)0); webif_init(); start_thread("reader check", (void *) &reader_check, NULL, NULL, 1, 1); cw_process_thread_start(); checkcache_process_thread_start(); lcd_thread_start(); do_report_emm_support(); init_cardreader(); cs_waitforcardinit(); emm_load_cache(); load_emmstat_from_file(); led_status_starting(); ac_init(); start_thread("card poll", (void *) &card_poll, NULL, NULL, 1, 1); for(i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; if((module->type & MOD_CONN_SERIAL) && module->s_handler) { module->s_handler(NULL, NULL, i); } } // main loop function process_clients(); SAFE_COND_SIGNAL(&card_poll_sleep_cond); // Stop card_poll thread cw_process_thread_wakeup(); // Stop cw_process thread SAFE_COND_SIGNAL(&reader_check_sleep_cond); // Stop reader_check thread // Cleanup #ifdef MODULE_GBOX stop_sms_sender(); #endif webif_close(); azbox_close(); coolapi_close_all(); mca_close(); led_status_stopping(); led_stop(); lcd_thread_stop(); remove_versionfile(); stat_finish(); dvbapi_stop_all_descrambling(); dvbapi_save_channel_cache(); emm_save_cache(); save_emmstat_to_file(); cccam_done_share(); gbox_send_good_night(); kill_all_clients(); kill_all_readers(); for(i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; if((module->type & MOD_CONN_NET)) { for(j = 0; j < module->ptab.nports; j++) { struct s_port *port = &module->ptab.ports[j]; if(port->fd) { shutdown(port->fd, SHUT_RDWR); close(port->fd); port->fd = 0; } } } } if(oscam_pidfile) { unlink(oscam_pidfile); } // sleep a bit, so hopefully all threads are stopped when we continue cs_sleepms(200); free_cache(); cacheex_free_hitcache(); webif_tpls_free(); init_free_userdb(cfg.account); cfg.account = NULL; init_free_sidtab(); free_readerdb(); free_irdeto_guess_tab(); config_free(); ssl_done(); detect_valgrind(); if (!running_under_valgrind) cs_log("cardserver down"); else cs_log("running under valgrind, waiting 5 seconds before stopping cardserver"); log_free(); if (running_under_valgrind) sleep(5); // HACK: Wait a bit for things to settle stop_garbage_collector(); NULLFREE(first_client->account); NULLFREE(first_client); free(stb_boxtype); free(stb_boxname); // This prevents the compiler from removing config_mak from the final binary syslog_ident = config_mak; return exit_oscam; }
/** Initialize the FreeWPC program. */ __noreturn__ void freewpc_init (void) { extern __common__ void system_reset (void); /* Initialize the platform specifics first */ VOIDCALL (platform_init); /* Reset the blanking and watchdog circuitry. * Eventually, the watchdog will be tickled every 1ms * by the IRQ; until interrupts are enabled, we will * have to do this periodically ourselves. */ pinio_watchdog_reset (); /* Set init complete flag to false. When everything is * ready, we'll change this to a 1. */ sys_init_complete = 0; periodic_ok = 0; sys_init_pending_tasks = 0; /* Initialize all of the other kernel subsystems, * starting with the hardware-centric ones and moving on * to software features. */ /* Initialize the real-time scheduler. The periodic functions are scheduled at compile-time using the 'gensched' utility. */ VOIDCALL (tick_init); /* Initialize the hardware. * After each init call, tickle the watchdog (IRQ isn't enabled yet) * to prevent it from expiring and resetting the CPU. * We don't use a callset here because there are some ordering * dependencies -- some modules must be initialized before others -- * and gencallset doesn't allow us to express those conditions. */ #ifdef DEBUGGER db_init (); bpt_init (); pinio_watchdog_reset (); #endif ac_init (); pinio_watchdog_reset (); sol_init (); pinio_watchdog_reset (); #ifdef CONFIG_GI gi_init (); pinio_watchdog_reset (); #endif display_init (); pinio_watchdog_reset (); switch_init (); pinio_watchdog_reset (); flipper_init (); pinio_watchdog_reset (); lamp_init (); pinio_watchdog_reset (); device_init (); pinio_watchdog_reset (); free_timer_init (); pinio_watchdog_reset (); sound_init (); pinio_watchdog_reset (); #if (MACHINE_PIC == 1) pic_init (); pinio_watchdog_reset (); #endif /* task_init is somewhat special in that it transforms the system * from a single task into a multitasking one. After this, tasks * can be spawned if need be. A task is created for the current * thread of execution, too. */ task_init (); pinio_watchdog_reset (); #ifdef CONFIG_NATIVE /* Notify the simulator when the core OS is up and running. */ sim_init (); #endif /* Initialize the sound board early in a background * thread, since it involves polling for data back from it, * which may take unknown (or even infinite) time. */ sys_init_pending_tasks++; task_create_gid (GID_SOUND_INIT, sound_board_init); /* Enable interrupts (IRQs and FIRQs). Do this as soon as possible, * but not before all of the hardware modules are done. */ enable_interrupts (); /* Initialize everything else. Some of these are given explicitly to force a particular order, since callsets do not guarantee the order of invocation. For most things the order doesn't matter. */ deff_init (); leff_init (); test_init (); adj_init (); log_init (); callset_invoke (init); /* Check all adjustments and make sure that their checksums are valid. If problems are found, those adjustments will be made sane again. */ csum_area_check_all (); /* Enable periodic processing. */ periodic_ok = 1; task_sleep (TIME_16MS); /* The system is initialized from a hardware perspective. * Now, perform additional final initializations. */ system_reset (); /* The system can run itself now, this task is done! */ task_exit (); }
int main(int argc, char *argv[]) { int ch; const char *filename = NULL; const char *modpath = tc_module_default_path(); const char *regpath = tc_module_registry_default_path(); const char *modtype = "filter"; const char *modarg = ""; /* nothing */ const char *modcfg = ""; /* nothing */ const char *socketfile = NULL; const char *fmtname = NULL; int print_mod = 0; int connect_socket = 0; int ret = 0; int status = STATUS_NO_MODULE; /* needed by filter modules */ TCVHandle tcv_handle = tcv_init(); TCRegistry registry = NULL; TCFactory factory = NULL; TCModule module = NULL; ac_init(AC_ALL); tc_ext_init(); if (argc == 1) { usage(); return STATUS_BAD_PARAM; } libtc_init(&argc, &argv); while (1) { ch = getopt(argc, argv, "C:F:d:i:?vhpm:M:r:s:t:"); if (ch == -1) { break; } switch (ch) { case 'd': if (optarg[0] == '-') { usage(); return STATUS_BAD_PARAM; } verbose = atoi(optarg); break; case 'i': if (optarg[0] == '-') { usage(); return STATUS_BAD_PARAM; } filename = optarg; break; case 'C': modcfg = optarg; break; case 'F': fmtname = optarg; break; case 'm': modpath = optarg; break; case 'M': modarg = optarg; break; case 'r': regpath = optarg; break; case 't': if (!optarg) { usage(); return STATUS_BAD_PARAM; } if (!strcmp(optarg, "filter") || !strcmp(optarg, "encode") || !strcmp(optarg, "multiplex")) { modtype = optarg; } else { modtype = NULL; } break; case 's': if (optarg[0] == '-') { usage(); return STATUS_BAD_PARAM; } connect_socket = 1; socketfile = optarg; break; case 'p': print_mod = 1; break; case 'v': version(); return STATUS_OK; case '?': /* fallthrough */ case 'h': /* fallthrough */ default: usage(); return STATUS_OK; } } if (print_mod) { printf("%s\n", modpath); return STATUS_OK; } if (connect_socket) { do_connect_socket(socketfile); return STATUS_OK; } if (!filename && !fmtname) { usage(); return STATUS_BAD_PARAM; } if (!modtype || !strcmp(modtype, "import")) { tc_log_error(EXE, "Unknown module type (not in filter, encode, multiplex)"); return STATUS_BAD_PARAM; } if (strlen(modcfg) > 0 && strlen(modarg) > 0) { tc_log_error(EXE, "Cannot configure and inspect module on the same time"); return STATUS_BAD_PARAM; } /* * we can't distinguish from OMS and NMS modules at glance, so try * first using new module system */ factory = tc_new_module_factory(modpath, TC_MAX(verbose - 4, 0)); /* FIXME */ registry = tc_new_module_registry(factory, regpath, TC_MAX(verbose - 4, 0)); /* FIXME */ if (fmtname) { TCCodecID codec = tc_codec_from_string(fmtname); TCFormatID format = tc_format_from_string(fmtname); if (codec == TC_CODEC_ERROR && format == TC_FORMAT_ERROR) { tc_log_error(EXE, "unrecognized format `%s'", fmtname); } else { const char *modnames = tc_get_module_name_for_format(registry, modtype, fmtname); if (modnames) { puts(modnames); } } } else { module = tc_new_module(factory, modtype, filename, TC_NONE); if (module != NULL) { status = query_new_module(module, modcfg, modarg); tc_del_module(factory, module); } else if (!strcmp(modtype, "filter")) { status = query_old_module(filename, modpath); } } ret = tc_del_module_registry(registry); ret = tc_del_module_factory(factory); tcv_free(tcv_handle); return status; }
int main(int argc, char *argv[]) { avi_t *avifile, *avifile1, *avifile2; char *outfile=NULL, *infile=NULL, *audfile=NULL; long rate, mp3rate; int j, ch, cc=0, track_num=0, out_track_num=-1; int width, height, format=0, format_add, chan, bits, aud_error=0; double fps; char *codec; long offset, frames, n, bytes, aud_offset=0; int key; int aud_tracks; // for mp3 audio FILE *f=NULL; int len, headlen, chan_i, rate_i, mp3rate_i; unsigned long vid_chunks=0; char head[8]; off_t pos; double aud_ms = 0.0, vid_ms = 0.0; double aud_ms_w[AVI_MAX_TRACKS]; ac_init(AC_ALL); if(argc==1) usage(EXIT_FAILURE); while ((ch = getopt(argc, argv, "A:a:b:ci:o:p:f:x:?hv")) != -1) { switch (ch) { case 'i': if(optarg[0]=='-') usage(EXIT_FAILURE); infile = optarg; break; case 'A': if(optarg[0]=='-') usage(EXIT_FAILURE); out_track_num = atoi(optarg); if(out_track_num<-1) usage(EXIT_FAILURE); break; case 'a': if(optarg[0]=='-') usage(EXIT_FAILURE); track_num = atoi(optarg); if(track_num<0) usage(EXIT_FAILURE); break; case 'b': if(optarg[0]=='-') usage(EXIT_FAILURE); is_vbr = atoi(optarg); if(is_vbr<0) usage(EXIT_FAILURE); break; case 'c': drop_video = 1; break; case 'o': if(optarg[0]=='-') usage(EXIT_FAILURE); outfile = optarg; break; case 'p': if(optarg[0]=='-') usage(EXIT_FAILURE); audfile = optarg; break; case 'f': if(optarg[0]=='-') usage(EXIT_FAILURE); comfile = optarg; break; case 'x': if(optarg[0]=='-') usage(EXIT_FAILURE); indexfile = optarg; break; case 'v': version(); exit(EXIT_SUCCESS); case 'h': usage(EXIT_SUCCESS); default: usage(EXIT_FAILURE); } } if(outfile == NULL || infile == NULL) usage(EXIT_FAILURE); printf("scanning file %s for video/audio parameter\n", infile); // open first file for video/audio info read only if(indexfile) { if (NULL == (avifile1 = AVI_open_input_indexfile(infile,0,indexfile))) { AVI_print_error("AVI open with index file"); } } else if(NULL == (avifile1 = AVI_open_input_file(infile,1))) { AVI_print_error("AVI open"); exit(1); } AVI_info(avifile1); // safety checks if(strcmp(infile, outfile)==0) { printf("error: output filename conflicts with input filename\n"); exit(1); } ch = optind; while (ch < argc) { if(tc_file_check(argv[ch]) != 0) { printf("error: file not found\n"); exit(1); } if(strcmp(argv[ch++], outfile)==0) { printf("error: output filename conflicts with input filename\n"); exit(1); } } // open output file if(NULL == (avifile = AVI_open_output_file(outfile))) { AVI_print_error("AVI open"); exit(1); } // read video info; width = AVI_video_width(avifile1); height = AVI_video_height(avifile1); fps = AVI_frame_rate(avifile1); codec = AVI_video_compressor(avifile1); //set video in outputfile AVI_set_video(avifile, width, height, fps, codec); if (comfile!=NULL) AVI_set_comment_fd(avifile, open(comfile, O_RDONLY)); //multi audio tracks? aud_tracks = AVI_audio_tracks(avifile1); if (out_track_num < 0) out_track_num = aud_tracks; for(j=0; j<aud_tracks; ++j) { if (out_track_num == j) continue; AVI_set_audio_track(avifile1, j); rate = AVI_audio_rate(avifile1); chan = AVI_audio_channels(avifile1); bits = AVI_audio_bits(avifile1); format = AVI_audio_format(avifile1); mp3rate= AVI_audio_mp3rate(avifile1); //printf("TRACK %d MP3RATE %ld VBR %ld\n", j, mp3rate, AVI_get_audio_vbr(avifile1)); //set next track of output file AVI_set_audio_track(avifile, j); AVI_set_audio(avifile, chan, rate, bits, format, mp3rate); AVI_set_audio_vbr(avifile, AVI_get_audio_vbr(avifile1)); } if(audfile!=NULL) goto audio_merge; // close reopen in merger function AVI_close(avifile1); //------------------------------------------------------------- printf("merging multiple AVI-files (concatenating) ...\n"); // extract and write to new files printf ("file %02d %s\n", ++cc, infile); merger(avifile, infile); while (optind < argc) { printf ("file %02d %s\n", ++cc, argv[optind]); merger(avifile, argv[optind++]); } // close new AVI file AVI_close(avifile); printf("... done merging %d file(s) in %s\n", cc, outfile); // reopen file for video/audio info if(NULL == (avifile = AVI_open_input_file(outfile,1))) { AVI_print_error("AVI open"); exit(1); } AVI_info(avifile); return(0); //------------------------------------------------------------- // ************************************************* // Merge the audio track of an additional AVI file // ************************************************* audio_merge: printf("merging audio %s track %d (multiplexing) into %d ...\n", audfile, track_num, out_track_num); // open audio file read only if(NULL == (avifile2 = AVI_open_input_file(audfile,1))) { int f=open(audfile, O_RDONLY), ret=0; char head[1024], *c; c = head; if (f>0 && (1024 == read(f, head, 1024)) ) { while ((c-head<1024-8) && (ret = tc_probe_audio_header(c, 8))<=0 ) { c++; } close(f); if (ret > 0) { aud_offset = c-head; //printf("found atrack 0x%x off=%ld\n", ret, aud_offset); goto merge_mp3; } } AVI_print_error("AVI open"); exit(1); } AVI_info(avifile2); //switch to requested track if(AVI_set_audio_track(avifile2, track_num)<0) { fprintf(stderr, "invalid audio track\n"); } rate = AVI_audio_rate(avifile2); chan = AVI_audio_channels(avifile2); bits = AVI_audio_bits(avifile2); format = AVI_audio_format(avifile2); mp3rate= AVI_audio_mp3rate(avifile2); //set next track AVI_set_audio_track(avifile, out_track_num); AVI_set_audio(avifile, chan, rate, bits, format, mp3rate); AVI_set_audio_vbr(avifile, AVI_get_audio_vbr(avifile2)); AVI_seek_start(avifile1); frames = AVI_video_frames(avifile1); offset = 0; printf ("file %02d %s\n", ++cc, infile); for (n=0; n<AVI_MAX_TRACKS; n++) aud_ms_w[n] = 0.0; vid_chunks=0; for (n=0; n<frames; ++n) { // video bytes = AVI_read_frame(avifile1, data, &key); if(bytes < 0) { AVI_print_error("AVI read video frame"); return(-1); } if(AVI_write_frame(avifile, data, bytes, key)<0) { AVI_print_error("AVI write video frame"); return(-1); } ++vid_chunks; vid_ms = vid_chunks*1000.0/fps; for(j=0; j<aud_tracks; ++j) { if (j == out_track_num) continue; AVI_set_audio_track(avifile1, j); AVI_set_audio_track(avifile, j); chan = AVI_audio_channels(avifile1); // audio chan = AVI_audio_channels(avifile1); if(chan) { sync_audio_video_avi2avi(vid_ms, &aud_ms_w[j], avifile1, avifile); } } // merge additional track // audio chan = AVI_audio_channels(avifile2); AVI_set_audio_track(avifile, out_track_num); if(chan) { sync_audio_video_avi2avi(vid_ms, &aud_ms, avifile2, avifile); } // progress fprintf(stderr, "[%s] (%06ld-%06ld)\r", outfile, offset, offset + n); } fprintf(stderr,"\n"); offset = frames; //more files to merge? AVI_close(avifile1); while (optind < argc) { printf ("file %02d %s\n", ++cc, argv[optind]); if(NULL == ( avifile1 = AVI_open_input_file(argv[optind++],1))) { AVI_print_error("AVI open"); goto finish; } AVI_seek_start(avifile1); frames = AVI_video_frames(avifile1); for (n=0; n<frames; ++n) { // video bytes = AVI_read_frame(avifile1, data, &key); if(bytes < 0) { AVI_print_error("AVI read video frame"); return(-1); } if(AVI_write_frame(avifile, data, bytes, key)<0) { AVI_print_error("AVI write video frame"); return(-1); } ++vid_chunks; vid_ms = vid_chunks*1000.0/fps; // audio for(j=0; j<aud_tracks; ++j) { if (j == out_track_num) continue; AVI_set_audio_track(avifile1, j); AVI_set_audio_track(avifile, j); chan = AVI_audio_channels(avifile1); if(chan) { sync_audio_video_avi2avi(vid_ms, &aud_ms_w[j], avifile1, avifile); } } // merge additional track chan = AVI_audio_channels(avifile2); AVI_set_audio_track(avifile, out_track_num); if(chan) { sync_audio_video_avi2avi(vid_ms, &aud_ms, avifile2, avifile); } // chan // progress fprintf(stderr, "[%s] (%06ld-%06ld)\r", outfile, offset, offset + n); } fprintf(stderr, "\n"); offset += frames; AVI_close(avifile1); } finish: // close new AVI file printf("... done multiplexing in %s\n", outfile); AVI_info(avifile); AVI_close(avifile); return(0); // ************************************************* // Merge a raw audio file which is either MP3 or AC3 // ************************************************* merge_mp3: f = fopen(audfile,"rb"); if (!f) { perror ("fopen"); exit(1); } fseek(f, aud_offset, SEEK_SET); len = fread(head, 1, 8, f); format_add = tc_probe_audio_header(head, len); headlen = tc_get_audio_header(head, len, format_add, &chan_i, &rate_i, &mp3rate_i); fprintf(stderr, "... this looks like a %s track ...\n", (format_add==0x55)?"MP3":"AC3"); fseek(f, aud_offset, SEEK_SET); //set next track AVI_set_audio_track(avifile, out_track_num); AVI_set_audio(avifile, chan_i, rate_i, 16, format_add, mp3rate_i); AVI_set_audio_vbr(avifile, is_vbr); AVI_seek_start(avifile1); frames = AVI_video_frames(avifile1); offset = 0; for (n=0; n<AVI_MAX_TRACKS; ++n) aud_ms_w[n] = 0.0; for (n=0; n<frames; ++n) { // video bytes = AVI_read_frame(avifile1, data, &key); if(bytes < 0) { AVI_print_error("AVI read video frame"); return(-1); } if(AVI_write_frame(avifile, data, bytes, key)<0) { AVI_print_error("AVI write video frame"); return(-1); } vid_chunks++; vid_ms = vid_chunks*1000.0/fps; for(j=0; j<aud_tracks; ++j) { if (j == out_track_num) continue; AVI_set_audio_track(avifile1, j); AVI_set_audio_track(avifile, j); chan = AVI_audio_channels(avifile1); if(chan) { sync_audio_video_avi2avi(vid_ms, &aud_ms_w[j], avifile1, avifile); } } // merge additional track if(headlen>4 && !aud_error) { while (aud_ms < vid_ms) { //printf("reading Audio Chunk ch(%ld) vms(%lf) ams(%lf)\n", vid_chunks, vid_ms, aud_ms); pos = ftell(f); len = fread (head, 1, 8, f); if (len<=0) { //eof fprintf(stderr, "EOF in %s; continuing ..\n", audfile); aud_error=1; break; } if ( (headlen = tc_get_audio_header(head, len, format_add, NULL, NULL, &mp3rate_i))<0) { fprintf(stderr, "Broken %s track #(%d)? skipping\n", (format_add==0x55?"MP3":"AC3"), aud_tracks); aud_ms = vid_ms; aud_error=1; } else { // look in import/tcscan.c for explanation aud_ms += (headlen*8.0)/(mp3rate_i); } fseek (f, pos, SEEK_SET); len = fread (data, headlen, 1, f); if (len<=0) { //eof fprintf(stderr, "EOF in %s; continuing ..\n", audfile); aud_error=1; break; } AVI_set_audio_track(avifile, out_track_num); if(AVI_write_audio(avifile, data, headlen)<0) { AVI_print_error("AVI write audio frame"); return(-1); } } } // progress fprintf(stderr, "[%s] (%06ld-%06ld)\r", outfile, offset, offset + n); } fprintf(stderr,"\n"); offset = frames; // more files? while (optind < argc) { printf ("file %02d %s\n", ++cc, argv[optind]); if(NULL == ( avifile1 = AVI_open_input_file(argv[optind++],1))) { AVI_print_error("AVI open"); goto finish; } AVI_seek_start(avifile1); frames = AVI_video_frames(avifile1); for (n=0; n<frames; ++n) { // video bytes = AVI_read_frame(avifile1, data, &key); if(bytes < 0) { AVI_print_error("AVI read video frame"); return(-1); } if(AVI_write_frame(avifile, data, bytes, key)<0) { AVI_print_error("AVI write video frame"); return(-1); } vid_chunks++; vid_ms = vid_chunks*1000.0/fps; for(j=0; j<aud_tracks; ++j) { if (j == out_track_num) continue; AVI_set_audio_track(avifile1, j); AVI_set_audio_track(avifile, j); chan = AVI_audio_channels(avifile1); if(chan) { sync_audio_video_avi2avi(vid_ms, &aud_ms_w[j], avifile1, avifile); } } // merge additional track // audio if(headlen>4 && !aud_error) { while (aud_ms < vid_ms) { //printf("reading Audio Chunk ch(%ld) vms(%lf) ams(%lf)\n", vid_chunks, vid_ms, aud_ms); pos = ftell(f); len = fread (head, 8, 1, f); if (len<=0) { //eof fprintf(stderr, "EOF in %s; continuing ..\n", audfile); aud_error=1; break; } if ( (headlen = tc_get_audio_header(head, len, format_add, NULL, NULL, &mp3rate_i))<0) { fprintf(stderr, "Broken %s track #(%d)?\n", (format_add==0x55?"MP3":"AC3"), aud_tracks); aud_ms = vid_ms; aud_error=1; } else { // look in import/tcscan.c for explanation aud_ms += (headlen*8.0)/(mp3rate_i); } fseek (f, pos, SEEK_SET); len = fread (data, headlen, 1, f); if (len<=0) { //eof fprintf(stderr, "EOF in %s; continuing ..\n", audfile); aud_error=1; break; } AVI_set_audio_track(avifile, out_track_num); if(AVI_write_audio(avifile, data, headlen)<0) { AVI_print_error("AVI write audio frame"); return(-1); } } } // progress fprintf(stderr, "[%s] (%06ld-%06ld)\r", outfile, offset, offset + n); } fprintf(stderr, "\n"); offset += frames; AVI_close(avifile1); } if (f) fclose(f); printf("... done multiplexing in %s\n", outfile); AVI_close(avifile); return(0); }
/** * \brief Main Application Routine * - Initialize the system clocks * - Initialize the sleep manager * - Initialize the power save measures * - Initialize the ACIFB module * - Initialize the AST to trigger ACIFB at regular intervals * - Go to STATIC sleep mode and wake up on a touch status change */ int main(void) { /* Switch on the STATUS LED */ gpio_clr_gpio_pin(STATUS_LED); /* Switch off the error LED. */ gpio_set_gpio_pin(ERROR_LED); /* * Initialize the system clock. * Note: Clock settings are specified in conf_clock.h */ sysclk_init(); /* * Initialize the sleep manager. * Note: CONFIG_SLEEPMGR_ENABLE should have been defined in conf_sleepmgr.h */ sleepmgr_init(); /* Lock required sleep mode. */ sleepmgr_lock_mode(SLEEPMGR_STATIC); /* Initialize the delay routines */ delay_init(sysclk_get_cpu_hz()); /* Initialize the power saving features */ power_save_measures_init(); /* Switch off the error LED. */ gpio_set_gpio_pin(ERROR_LED); #if DEBUG_MESSAGES /* Enable the clock to USART interface */ sysclk_enable_peripheral_clock(DBG_USART); /* Initialize the USART interface to print trace messages */ init_dbg_rs232(sysclk_get_pba_hz()); print_dbg("\r Sleepwalking with ACIFB Module in UC3L \n"); print_dbg("\r Initializing ACIFB Module..... \n"); #endif /* Initialize the Analog Comparator peripheral */ if (ac_init() != STATUS_OK) { #if DEBUG_MESSAGES /* Error initializing the ACIFB peripheral */ print_dbg("\r Error initializing Analog Comparator module \n"); #endif while (1) { delay_ms(LED_DELAY); gpio_tgl_gpio_pin(ERROR_LED); } } #if DEBUG_MESSAGES print_dbg("\r ACIFB Module initialized. \n"); print_dbg("\r Initializing AST Module..... \n"); #endif /* Initialize the AST peripheral */ if (ast_init() != STATUS_OK) { #if DEBUG_MESSAGES print_dbg("\r Error initializing AST module \n"); #endif /* Error initializing the AST peripheral */ while (1) { delay_ms(LED_DELAY); gpio_tgl_gpio_pin(ERROR_LED); } } #if DEBUG_MESSAGES print_dbg("\r AST Module initialized. \n"); #endif /* Application routine */ while (1) { /* Enable Asynchronous wake-up for ACIFB */ pm_asyn_wake_up_enable(AVR32_PM_AWEN_ACIFBWEN_MASK); #if DEBUG_MESSAGES print_dbg("\r Going to STATIC sleep mode \n"); print_dbg( "\r Wake up only when input is higher than threshold \n"); #endif /* Switch off the status LED */ gpio_set_gpio_pin(STATUS_LED); /* Disable GPIO clock before entering sleep mode */ sysclk_disable_pba_module(SYSCLK_GPIO); AVR32_INTC.ipr[0]; /* Enter STATIC sleep mode */ sleepmgr_enter_sleep(); /* Enable GPIO clock after waking from sleep mode */ sysclk_enable_pba_module(SYSCLK_GPIO); /* Switch on the status LED */ gpio_clr_gpio_pin(STATUS_LED); #if DEBUG_MESSAGES print_dbg("\r Output higher than threshold \n"); print_dbg("\n"); #else /* LED on for few ms */ delay_ms(LED_DELAY); #endif /* Clear the wake up & enable it to enter sleep mode again */ pm_asyn_wake_up_disable(AVR32_PM_AWEN_ACIFBWEN_MASK); /* Clear All AST Interrupt request and clear SR */ ast_clear_all_status_flags(&AVR32_AST); } return 0; } /* End of main() */
int main(int argc, char *argv[]) { avi_t *avifile1=NULL; avi_t *avifile2=NULL; avi_t *avifile3=NULL; char *in_file=NULL, *out_file=NULL; long frames, bytes; double fps; char *codec; int track_num=0, aud_tracks; int encode_null=0; int i, j, n, key, shift=0; int ch, preload=0; long rate, mp3rate; int width, height, format, chan, bits; int be_quiet = 0; FILE *status_fd = stderr; /* for null frame encoding */ char nulls[32000]; long nullbytes=0; char tmp0[] = "/tmp/nullfile.00.avi"; /* XXX: use mktemp*() */ buffer_list_t *ptr; double vid_ms = 0.0, shift_ms = 0.0, one_vid_ms = 0.0; double aud_ms [ AVI_MAX_TRACKS ]; int aud_bitrate = 0; int aud_chunks = 0; ac_init(AC_ALL); if(argc==1) usage(EXIT_FAILURE); while ((ch = getopt(argc, argv, "a:b:vi:o:n:Nq?h")) != -1) { switch (ch) { case 'i': if(optarg[0]=='-') usage(EXIT_FAILURE); in_file=optarg; break; case 'a': if(optarg[0]=='-') usage(EXIT_FAILURE); track_num = atoi(optarg); if(track_num<0) usage(EXIT_FAILURE); break; case 'b': if(optarg[0]=='-') usage(EXIT_FAILURE); is_vbr = atoi(optarg); if(is_vbr<0) usage(EXIT_FAILURE); break; case 'o': if(optarg[0]=='-') usage(EXIT_FAILURE); out_file=optarg; break; case 'f': if(optarg[0]=='-') usage(EXIT_FAILURE); comfile = optarg; break; case 'n': if(sscanf(optarg,"%d", &shift)!=1) { fprintf(stderr, "invalid parameter for option -n\n"); usage(EXIT_FAILURE); } break; case 'N': encode_null=1; break; case 'q': be_quiet = 1; break; case 'v': version(); exit(0); break; case 'h': usage(EXIT_SUCCESS); default: usage(EXIT_FAILURE); } } // check if(in_file==NULL || out_file == NULL) usage(EXIT_FAILURE); if(shift == 0) fprintf(stderr, "no sync requested - exit"); memset (nulls, 0, sizeof(nulls)); // open file if(NULL == (avifile1 = AVI_open_input_file(in_file,1))) { AVI_print_error("AVI open"); exit(1); } if(strcmp(in_file, out_file)==0) { printf("error: output filename conflicts with input filename\n"); exit(1); } if(NULL == (avifile2 = AVI_open_output_file(out_file))) { AVI_print_error("AVI open"); exit(1); } if (be_quiet) { if (!(status_fd = fopen("/dev/null", "w"))) { fprintf(stderr, "Can't open /dev/null\n"); exit(1); } } // read video info; AVI_info(avifile1); // read video info; frames = AVI_video_frames(avifile1); width = AVI_video_width(avifile1); height = AVI_video_height(avifile1); fps = AVI_frame_rate(avifile1); codec = AVI_video_compressor(avifile1); //set video in outputfile AVI_set_video(avifile2, width, height, fps, codec); if (comfile!=NULL) AVI_set_comment_fd(avifile2, open(comfile, O_RDONLY)); aud_tracks = AVI_audio_tracks(avifile1); for(j=0; j<aud_tracks; ++j) { AVI_set_audio_track(avifile1, j); rate = AVI_audio_rate(avifile1); chan = AVI_audio_channels(avifile1); bits = AVI_audio_bits(avifile1); format = AVI_audio_format(avifile1); mp3rate= AVI_audio_mp3rate(avifile1); //set next track of output file AVI_set_audio_track(avifile2, j); AVI_set_audio(avifile2, chan, rate, bits, format, mp3rate); AVI_set_audio_vbr(avifile2, is_vbr); } //switch to requested audio_channel if(AVI_set_audio_track(avifile1, track_num)<0) { fprintf(stderr, "invalid auto track\n"); } AVI_set_audio_track(avifile2, track_num); if (encode_null) { char cmd[1024]; rate = AVI_audio_rate(avifile2); chan = AVI_audio_channels(avifile2); bits = AVI_audio_bits(avifile2); format = AVI_audio_format(avifile2); mp3rate= AVI_audio_mp3rate(avifile2); if (bits==0) bits=16; if (mp3rate%2) mp3rate++; fprintf(status_fd, "Creating silent mp3 frame with current parameter\n"); memset (cmd, 0, sizeof(cmd)); tc_snprintf(cmd, sizeof(cmd), "transcode -i /dev/zero -o %s -x raw,raw" " -n 0x1 -g 16x16 -y raw,raw -c 0-5 -e %ld,%d,%d -b %ld -q0", tmp0, rate,bits,chan, mp3rate); printf(cmd); system(cmd); if(NULL == (avifile3 = AVI_open_input_file(tmp0,1))) { AVI_print_error("AVI open"); exit(1); } nullbytes = AVI_audio_size(avifile3, 3); /* just read a few frames */ if(AVI_read_audio(avifile3, nulls, nullbytes) < 0) { AVI_print_error("AVI audio read frame"); return(-1); } memset (nulls, 0, sizeof(nulls)); if(AVI_read_audio(avifile3, nulls, nullbytes) < 0) { AVI_print_error("AVI audio read frame"); return(-1); } memset (nulls, 0, sizeof(nulls)); if(AVI_read_audio(avifile3, nulls, nullbytes) < 0) { AVI_print_error("AVI audio read frame"); return(-1); } /* printf("\nBytes (%ld): \n", nullbytes); { int asd=0; for (asd=0; asd<nullbytes; asd++){ printf("%x ",(unsigned char)nulls[asd]); } printf("\n"); } */ } vid_ms = 0.0; shift_ms = 0.0; for (n=0; n<AVI_MAX_TRACKS; ++n) aud_ms[n] = 0.0; // --------------------------------------------------------------------- for (n=0; n<frames; ++n) { // video unchanged bytes = AVI_read_frame(avifile1, data, &key); if(bytes < 0) { AVI_print_error("AVI read video frame"); return(-1); } if(AVI_write_frame(avifile2, data, bytes, key)<0) { AVI_print_error("AVI write video frame"); return(-1); } vid_ms = (n+1)*1000.0/fps; // Pass-through all other audio tracks. for(j=0; j<aud_tracks; ++j) { // skip track we want to modify if (j == track_num) continue; // switch to track AVI_set_audio_track(avifile1, j); AVI_set_audio_track(avifile2, j); sync_audio_video_avi2avi(vid_ms, &aud_ms[j], avifile1, avifile2); } //switch to requested audio_channel if(AVI_set_audio_track(avifile1, track_num)<0) { fprintf(stderr, "invalid auto track\n"); } AVI_set_audio_track(avifile2, track_num); shift_ms = (double)shift*1000.0/fps; one_vid_ms = 1000.0/fps; format = AVI_audio_format(avifile1); rate = AVI_audio_rate(avifile1); chan = AVI_audio_channels(avifile1); bits = AVI_audio_bits(avifile1); bits = bits==0?16:bits; mp3rate= AVI_audio_mp3rate(avifile1); if(shift>0) { // for n < shift, shift audio frames are discarded if(!preload) { if (tc_format_ms_supported(format)) { for(i=0;i<shift;++i) { //fprintf (stderr, "shift (%d) i (%d) n (%d) a (%d)\n", shift, i, n, aud_chunks); while (aud_ms[track_num] < vid_ms + one_vid_ms*(double)i) { aud_bitrate = (format==0x1||format==0x2000)?1:0; aud_chunks++; if( (bytes = AVI_read_audio_chunk(avifile1, data)) <= 0) { aud_ms[track_num] = vid_ms + one_vid_ms*i; if (bytes == 0) continue; AVI_print_error("AVI 2 audio read frame"); break; } if ( !aud_bitrate && tc_get_audio_header(data, bytes, format, NULL, NULL, &aud_bitrate)<0) { // if this is the last frame of the file, slurp in audio chunks if (n == frames-1) continue; aud_ms[track_num] = vid_ms + one_vid_ms*i; } else aud_ms[track_num] += (bytes*8.0)/(format==0x1?((double)(rate*chan*bits)/1000.0): (format==0x2000?(double)(mp3rate):aud_bitrate)); } } } else { // fallback bytes=0; for(i=0;i<shift;++i) { do { if( (bytes = AVI_read_audio_chunk(avifile1, data)) < 0) { AVI_print_error("AVI audio read frame"); return(-1); } } while (AVI_can_read_audio(avifile1)); } } preload=1; } // copy rest of the track if(n<frames-shift) { if (tc_format_ms_supported(format)) { while (aud_ms[track_num] < vid_ms + shift_ms) { aud_chunks++; aud_bitrate = (format==0x1||format==0x2000)?1:0; if( (bytes = AVI_read_audio_chunk(avifile1, data)) < 0) { aud_ms[track_num] = vid_ms + shift_ms; AVI_print_error("AVI 3 audio read frame"); break; } if(AVI_write_audio(avifile2, data, bytes) < 0) { AVI_print_error("AVI 3 write audio frame"); return(-1); } fprintf(status_fd, "V [%05d][%08.2f] | A [%05d][%08.2f] [%05ld]\r", n, vid_ms, aud_chunks, aud_ms[track_num], bytes); if (bytes == 0) { aud_ms[track_num] = vid_ms + shift_ms; continue; } if(n>=frames-2*shift) { // save audio frame for later ptr = buffer_register(n); if(ptr==NULL) { fprintf(stderr,"buffer allocation failed\n"); break; } ac_memcpy(ptr->data, data, bytes); ptr->size = bytes; ptr->status = BUFFER_READY; } if ( !aud_bitrate && tc_get_audio_header(data, bytes, format, NULL, NULL, &aud_bitrate)<0) { if (n == frames-1) continue; aud_ms[track_num] = vid_ms + shift_ms; } else aud_ms[track_num] += (bytes*8.0)/(format==0x1?((double)(rate*chan*bits)/1000.0): (format==0x2000?(double)(mp3rate):aud_bitrate)); } } else { // fallback bytes = AVI_audio_size(avifile1, n+shift-1); do { if( (bytes = AVI_read_audio_chunk(avifile1, data)) < 0) { AVI_print_error("AVI audio read frame"); return(-1); } if(AVI_write_audio(avifile2, data, bytes) < 0) { AVI_print_error("AVI write audio frame"); return(-1); } fprintf(status_fd, "V [%05d] | A [%05d] [%05ld]\r", n, n+shift, bytes); if(n>=frames-2*shift) { // save audio frame for later ptr = buffer_register(n); if(ptr==NULL) { fprintf(stderr,"buffer allocation failed\n"); break; } ac_memcpy(ptr->data, data, bytes); ptr->size = bytes; ptr->status = BUFFER_READY; } } while (AVI_can_read_audio(avifile1)); } } // padding at the end if(n>=frames-shift) { if (!ptrlen) { ptr = buffer_retrieve(); ac_memcpy (ptrdata, ptr->data, ptr->size); ptrlen = ptr->size; } if (tc_format_ms_supported(format)) { while (aud_ms[track_num] < vid_ms + shift_ms) { aud_bitrate = (format==0x1||format==0x2000)?1:0; // mute this -- check if can mute (valid A header)! if (tc_probe_audio_header(ptrdata, ptrlen) > 0) tc_format_mute(ptrdata, ptrlen, format); if(AVI_write_audio(avifile2, ptrdata, ptrlen) < 0) { AVI_print_error("AVI write audio frame"); return(-1); } fprintf(status_fd, " V [%05d][%08.2f] | A [%05d][%08.2f] [%05ld]\r", n, vid_ms, n+shift, aud_ms[track_num], bytes); if ( !aud_bitrate && tc_get_audio_header(ptrdata, ptrlen, format, NULL, NULL, &aud_bitrate)<0) { //if (n == frames-1) continue; aud_ms[track_num] = vid_ms + shift_ms; } else aud_ms[track_num] += (ptrlen*8.0)/(format==0x1?((double)(rate*chan*bits)/1000.0): (format==0x2000?(double)(mp3rate):aud_bitrate)); } } else { // fallback // get next audio frame ptr = buffer_retrieve(); while (1) { printf("ptr->id (%d) ptr->size (%d)\n", ptr->id, ptr->size); if(ptr==NULL) { fprintf(stderr,"no buffer found\n"); break; } if (encode_null) { if(AVI_write_audio(avifile2, nulls, nullbytes)<0) { AVI_print_error("AVI write audio frame"); return(-1); } } else { // simple keep old frames to force exact time delay if(AVI_write_audio(avifile2, ptr->data, ptr->size)<0) { AVI_print_error("AVI write audio frame"); return(-1); } } fprintf(status_fd, "V [%05d] | padding\r", n); if (ptr->next && ptr->next->id == ptr->id) { buffer_remove(ptr); ptr = buffer_retrieve(); continue; } buffer_remove(ptr); break; } // 1 } } // ************************************* // negative shift (pad audio at start) // ************************************* } else { if (tc_format_ms_supported(format)) { /* fprintf(status_fd, "n(%d) -shift(%d) shift_ms (%.2lf) vid_ms(%.2lf) aud_ms[%d](%.2lf) v-s(%.2lf)\n", n, -shift, shift_ms, vid_ms, track_num, aud_ms[track_num], vid_ms + shift_ms); */ // shift<0 -> shift_ms<0 ! while (aud_ms[track_num] < vid_ms) { /* fprintf(stderr, " 1 (%02d) %s frame_read len=%4ld (A/V) (%8.2f/%8.2f)\n", n, format==0x55?"MP3":"AC3", bytes, aud_ms[track_num], vid_ms); */ aud_bitrate = (format==0x1||format==0x2000)?1:0; if( (bytes = AVI_read_audio_chunk(avifile1, data)) < 0) { AVI_print_error("AVI 2 audio read frame"); aud_ms[track_num] = vid_ms; break; //return(-1); } // save audio frame for later ptr = buffer_register(n); if(ptr==NULL) { fprintf(stderr,"buffer allocation failed\n"); break; } ac_memcpy(ptr->data, data, bytes); ptr->size = bytes; ptr->status = BUFFER_READY; if(n<-shift) { // mute this -- check if can mute! if (tc_probe_audio_header(data, bytes) > 0) tc_format_mute(data, bytes, format); // simple keep old frames to force exact time delay if(AVI_write_audio(avifile2, data, bytes)<0) { AVI_print_error("AVI write audio frame"); return(-1); } fprintf(status_fd, "V [%05d] | padding\r", n); } else { if (n==-shift) fprintf(status_fd, "\n"); // get next audio frame ptr = buffer_retrieve(); if(ptr==NULL) { fprintf(stderr,"no buffer found\n"); break; } if(AVI_write_audio(avifile2, ptr->data, ptr->size)<0) { AVI_print_error("AVI write audio frame"); return(-1); } bytes = ptr->size; ac_memcpy (data, ptr->data, bytes); fprintf(status_fd, "V [%05d] | A [%05d]\r", n, ptr->id); buffer_remove(ptr); } if ( !aud_bitrate && tc_get_audio_header(data, bytes, format, NULL, NULL, &aud_bitrate)<0) { if (n == frames-1) continue; aud_ms[track_num] = vid_ms; } else aud_ms[track_num] += (bytes*8.0)/(format==0x1?((double)(rate*chan*bits)/1000.0): (format==0x2000?(double)(mp3rate):aud_bitrate)); /* fprintf(stderr, " 1 (%02d) %s frame_read len=%4ld (A/V) (%8.2f/%8.2f)\n", n, format==0x55?"MP3":"AC3", bytes, aud_ms[track_num], vid_ms); */ } } else { // no supported format bytes = AVI_audio_size(avifile1, n); if(bytes > SIZE_RGB_FRAME) { fprintf(stderr, "invalid frame size\n"); return(-1); } if(AVI_read_audio(avifile1, data, bytes) < 0) { AVI_print_error("AVI audio read frame"); return(-1); } // save audio frame for later ptr = buffer_register(n); if(ptr==NULL) { fprintf(stderr,"buffer allocation failed\n"); break; } ac_memcpy(ptr->data, data, bytes); ptr->size = bytes; ptr->status = BUFFER_READY; if(n<-shift) { if (encode_null) { if(AVI_write_audio(avifile2, nulls, nullbytes)<0) { AVI_print_error("AVI write audio frame"); return(-1); } } else { // simple keep old frames to force exact time delay if(AVI_write_audio(avifile2, data, bytes)<0) { AVI_print_error("AVI write audio frame"); return(-1); } } fprintf(status_fd, "V [%05d] | padding\r", n); } else { // get next audio frame ptr = buffer_retrieve(); if(ptr==NULL) { fprintf(stderr,"no buffer found\n"); break; } if(AVI_write_audio(avifile2, ptr->data, ptr->size)<0) { AVI_print_error("AVI write audio frame"); return(-1); } fprintf(status_fd, "V [%05d] | A [%05d]\r", n, ptr->id); buffer_remove(ptr); } } } } fprintf(status_fd, "\n"); if (be_quiet) { fclose(status_fd); } AVI_close(avifile1); AVI_close(avifile2); if (avifile3) { memset(nulls, 0, sizeof(nulls)); tc_snprintf(nulls, sizeof(nulls), "rm -f %s", tmp0); system(nulls); AVI_close(avifile3); } return(0); }
/** * \internal * \brief Setup Function: AC window mode test. * * This function initializes the AC in window mode detection. * 0.25V and 0.75V from internal voltage scaler are used as lower * and upper limits of the window respectively. * * \param test Current test case. */ static void setup_ac_window_mode_test(const struct test_case *test) { enum status_code status = STATUS_ERR_IO; /* Structure for AC configuration */ struct ac_config config; struct ac_chan_config channel_config; struct ac_win_config window_config; /* Set the flag to false */ ac_init_success = false; ac_reset(&ac_inst); ac_get_config_defaults(&config); /* Initialize the AC */ status = ac_init(&ac_inst, AC, &config); /* Check for successful initialization */ test_assert_true(test, status == STATUS_OK, "AC initialization failed"); /* Configure the AC input pin */ struct system_pinmux_config ac0_pin_conf; system_pinmux_get_config_defaults(&ac0_pin_conf); ac0_pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT; ac0_pin_conf.mux_position = MUX_PA04B_AC_AIN0; system_pinmux_pin_set_config(PIN_PA04B_AC_AIN0, &ac0_pin_conf); /* Channel configuration */ status = STATUS_ERR_IO; ac_chan_get_config_defaults(&channel_config); channel_config.sample_mode = AC_CHAN_MODE_SINGLE_SHOT; channel_config.positive_input = AC_CHAN_POS_MUX_PIN0; channel_config.negative_input = AC_CHAN_NEG_MUX_SCALED_VCC; channel_config.vcc_scale_factor = AC_SCALER_0_25_VOLT; /* Set the channel configuration for CHAN1 - Lower limit*/ status = ac_chan_set_config(&ac_inst, AC_CHAN_CHANNEL_1, &channel_config); /* Check for successful initialization */ test_assert_true(test, status == STATUS_OK, "AC channel 1 initialization failed"); /* Set the channel configuration for CHAN0 - Upper limit*/ channel_config.vcc_scale_factor = AC_SCALER_0_75_VOLT; status = ac_chan_set_config(&ac_inst, AC_CHAN_CHANNEL_0, &channel_config); /* Check for successful initialization */ test_assert_true(test, status == STATUS_OK, "AC channel 0 initialization failed"); /* Window mode configuration */ status = STATUS_ERR_IO; ac_win_get_config_defaults(&window_config); status = ac_win_set_config(&ac_inst, AC_WIN_CHANNEL_0, &window_config); /* Check for successful initialization */ test_assert_true(test, status == STATUS_OK, "AC window mode initialization failed"); /* Enable the AC channels */ ac_chan_enable(&ac_inst, AC_CHAN_CHANNEL_0); ac_chan_enable(&ac_inst, AC_CHAN_CHANNEL_1); /* Enable window mode */ status = ac_win_enable(&ac_inst, AC_WIN_CHANNEL_0); /* Check for successful initialization */ test_assert_true(test, status == STATUS_OK, "AC window mode enable failed"); /* Enable AC module */ ac_enable(&ac_inst); if (status == STATUS_OK) { ac_init_success = true; } }
Datum adaptive_add_item_agg(PG_FUNCTION_ARGS) { AdaptiveCounter acounter; float4 errorRate; /* 0 - 1, e.g. 0.01 means 1% */ int ndistinct; /* expected number of distinct values */ /* info for anyelement */ Oid element_type = get_fn_expr_argtype(fcinfo->flinfo, 1); Datum element = PG_GETARG_DATUM(1); int16 typlen; bool typbyval; char typalign; /* is the counter created (if not, create it with default parameters) */ if (PG_ARGISNULL(0)) { errorRate = PG_GETARG_FLOAT4(2); ndistinct = PG_GETARG_INT32(3); /* ndistinct has to be positive, error rate between 0 and 1 (not 0) */ if (ndistinct < 1) { elog(ERROR, "ndistinct (expected number of distinct values) has to at least 1"); } else if ((errorRate <= 0) || (errorRate > 1)) { elog(ERROR, "error rate has to be between 0 and 1"); } acounter = ac_init(errorRate, ndistinct); } else { /* existing estimator */ acounter = (AdaptiveCounter)PG_GETARG_BYTEA_P(0); } /* add the item to the estimator */ if (! PG_ARGISNULL(1)) { /* TODO The requests for type info shouldn't be a problem (thanks to lsyscache), * but if it turns out to have a noticeable impact it's possible to cache that * between the calls (in the estimator). */ /* get type information for the second parameter (anyelement item) */ get_typlenbyvalalign(element_type, &typlen, &typbyval, &typalign); /* it this a varlena type, passed by reference or by value ? */ if (typlen == -1) { /* varlena */ ac_add_item(acounter, VARDATA(element), VARSIZE(element) - VARHDRSZ); } else if (typbyval) { /* fixed-length, passed by value */ ac_add_item(acounter, (char*)&element, typlen); } else { /* fixed-length, passed by reference */ ac_add_item(acounter, (char*)element, typlen); } } /* return the updated bytea */ PG_RETURN_BYTEA_P(acounter); }
int main(int argc, char *argv[]) { int ch; const char *filename = NULL; const char *modpath = MOD_PATH; #ifdef ENABLE_EXPERIMENTAL const char *modtype = "filter"; const char *modarg = ""; /* nothing */ const char *modcfg = ""; /* nothing */ #endif const char *socketfile = NULL; char options[OPTS_SIZE] = { '\0', }; int print_mod = 0; int connect_socket = 0; int ret = 0; int status = STATUS_NO_MODULE; /* needed by filter modules */ TCVHandle tcv_handle = tcv_init(); #ifdef ENABLE_EXPERIMENTAL TCFactory factory = NULL; TCModule module = NULL; #endif vframe_list_t ptr; memset(&ptr, 0, sizeof(ptr)); ac_init(AC_ALL); tc_config_set_dir(NULL); if (argc == 1) { usage(); return STATUS_BAD_PARAM; } libtc_init(&argc, &argv); while (1) { #ifdef ENABLE_EXPERIMENTAL ch = getopt(argc, argv, "C:d:i:?vhpm:M:s:t:"); #else /* !ENABLE_EXPERIMENTAL */ ch = getopt(argc, argv, "d:i:?vhps:"); #endif if (ch == -1) { break; } switch (ch) { case 'd': if (optarg[0] == '-') { usage(); return STATUS_BAD_PARAM; } verbose = atoi(optarg); break; case 'i': if (optarg[0] == '-') { usage(); return STATUS_BAD_PARAM; } filename = optarg; break; #ifdef ENABLE_EXPERIMENTAL case 'C': modcfg = optarg; break; case 'm': modpath = optarg; break; case 'M': modarg = optarg; break; case 't': if (!optarg) { usage(); return STATUS_BAD_PARAM; } if (!strcmp(optarg, "filter") || !strcmp(optarg, "encode") || !strcmp(optarg, "multiplex")) { modtype = optarg; } else { modtype = NULL; } break; #endif case 's': if (optarg[0] == '-') { usage(); return STATUS_BAD_PARAM; } connect_socket = 1; socketfile = optarg; break; case 'p': print_mod = 1; break; case 'v': version(); return STATUS_OK; case '?': /* fallthrough */ case 'h': /* fallthrough */ default: usage(); return STATUS_OK; } } if (print_mod) { printf("%s\n", modpath); return STATUS_OK; } if (connect_socket) { do_connect_socket(socketfile); return STATUS_OK; } if (!filename) { usage(); return STATUS_BAD_PARAM; } #ifdef ENABLE_EXPERIMENTAL if (!modtype || !strcmp(modtype, "import")) { tc_log_error(EXE, "Unknown module type (not in filter, encode, multiplex)"); return STATUS_BAD_PARAM; } if (strlen(modcfg) > 0 && strlen(modarg) > 0) { tc_log_error(EXE, "Cannot configure and inspect module on the same time"); return STATUS_BAD_PARAM; } /* * we can't distinguish from OMS and NMS modules at glance, so try * first using new module system */ factory = tc_new_module_factory(modpath, TC_MAX(verbose - 4, 0)); module = tc_new_module(factory, modtype, filename, TC_NONE); if (module != NULL) { const char *answer = NULL; if (verbose >= TC_DEBUG) { tc_log_info(EXE, "using new module system"); } if (strlen(modcfg) > 0) { int ret = tc_module_configure(module, modcfg, tc_get_vob()); if (ret == TC_OK) { status = STATUS_OK; } else { status = STATUS_MODULE_FAILED; tc_log_error(EXE, "configure returned error"); } tc_module_stop(module); } else { if (verbose >= TC_INFO) { /* overview and options */ tc_module_inspect(module, "help", &answer); puts(answer); /* module capabilities */ tc_module_show_info(module, verbose); } if (strlen(modarg) > 0) { tc_log_info(EXE, "informations about '%s' for " "module:", modarg); tc_module_inspect(module, modarg, &answer); puts(answer); } status = STATUS_OK; } tc_del_module(factory, module); } else if (!strcmp(modtype, "filter")) #endif /* ENABLE_EXPERIMENTAL */ { char namebuf[NAME_LEN]; #ifdef ENABLE_EXPERIMENTAL /* compatibility support only for filters */ if (verbose >= TC_DEBUG) { tc_log_info(EXE, "using old module system"); } #endif /* ok, fallback to old module system */ strlcpy(namebuf, filename, NAME_LEN); filter[0].name = namebuf; ret = load_plugin(modpath, 0, verbose); if (ret != 0) { tc_log_error(__FILE__, "unable to load filter `%s' (path=%s)", filter[0].name, modpath); status = STATUS_NO_MODULE; } else { strlcpy(options, "help", OPTS_SIZE); ptr.tag = TC_FILTER_INIT; if ((ret = filter[0].entry(&ptr, options)) != 0) { status = STATUS_MODULE_ERROR; } else { memset(options, 0, OPTS_SIZE); ptr.tag = TC_FILTER_GET_CONFIG; ret = filter[0].entry(&ptr, options); if (ret == 0) { if (verbose >= TC_INFO) { fputs("START\n", stdout); fputs(options, stdout); fputs("END\n", stdout); } status = STATUS_OK; } } } } #ifdef ENABLE_EXPERIMENTAL ret = tc_del_module_factory(factory); #endif tcv_free(tcv_handle); return status; }
int32_t main (int32_t argc, char *argv[]) { int32_t i, j; prog_name = argv[0]; if (pthread_key_create(&getclient, NULL)) { fprintf(stderr, "Could not create getclient, exiting..."); exit(1); } void (*mod_def[])(struct s_module *)= { #ifdef MODULE_MONITOR module_monitor, #endif #ifdef MODULE_CAMD33 module_camd33, #endif #ifdef MODULE_CAMD35 module_camd35, #endif #ifdef MODULE_CAMD35_TCP module_camd35_tcp, #endif #ifdef MODULE_NEWCAMD module_newcamd, #endif #ifdef MODULE_CCCAM module_cccam, #endif #ifdef MODULE_PANDORA module_pandora, #endif #ifdef MODULE_GHTTP module_ghttp, #endif #ifdef CS_CACHEEX module_csp, #endif #ifdef MODULE_GBOX module_gbox, #endif #ifdef MODULE_CONSTCW module_constcw, #endif #ifdef MODULE_RADEGAST module_radegast, #endif #ifdef MODULE_SERIAL module_serial, #endif #ifdef HAVE_DVBAPI module_dvbapi, #endif 0 }; void (*cardsystem_def[])(struct s_cardsystem *)= { #ifdef READER_NAGRA reader_nagra, #endif #ifdef READER_IRDETO reader_irdeto, #endif #ifdef READER_CONAX reader_conax, #endif #ifdef READER_CRYPTOWORKS reader_cryptoworks, #endif #ifdef READER_SECA reader_seca, #endif #ifdef READER_VIACCESS reader_viaccess, #endif #ifdef READER_VIDEOGUARD reader_videoguard1, reader_videoguard2, reader_videoguard12, #endif #ifdef READER_DRE reader_dre, #endif #ifdef READER_TONGFANG reader_tongfang, #endif #ifdef READER_BULCRYPT reader_bulcrypt, #endif #ifdef READER_GRIFFIN reader_griffin, #endif #ifdef READER_DGCRYPT reader_dgcrypt, #endif 0 }; void (*cardreader_def[])(struct s_cardreader *)= { #ifdef CARDREADER_DB2COM cardreader_db2com, #endif #if defined(CARDREADER_INTERNAL_AZBOX) cardreader_internal_azbox, #elif defined(CARDREADER_INTERNAL_COOLAPI) cardreader_internal_cool, #elif defined(CARDREADER_INTERNAL_SCI) cardreader_internal_sci, #endif #ifdef CARDREADER_PHOENIX cardreader_mouse, #endif #ifdef CARDREADER_MP35 cardreader_mp35, #endif #ifdef CARDREADER_PCSC cardreader_pcsc, #endif #ifdef CARDREADER_SC8IN1 cardreader_sc8in1, #endif #ifdef CARDREADER_SMARGO cardreader_smargo, #endif #ifdef CARDREADER_SMART cardreader_smartreader, #endif #ifdef CARDREADER_STAPI cardreader_stapi, #endif 0 }; parse_cmdline_params(argc, argv); if (bg && do_daemon(1,0)) { printf("Error starting in background (errno=%d: %s)", errno, strerror(errno)); cs_exit(1); } get_random_bytes_init(); #ifdef WEBIF if (cs_restart_mode) restart_daemon(); #endif memset(&cfg, 0, sizeof(struct s_config)); cfg.max_pending = max_pending; if (cs_confdir[strlen(cs_confdir) - 1] != '/') strcat(cs_confdir, "/"); init_signal_pre(); // because log could cause SIGPIPE errors, init a signal handler first init_first_client(); cs_lock_create(&system_lock, 5, "system_lock"); cs_lock_create(&config_lock, 10, "config_lock"); cs_lock_create(&gethostbyname_lock, 10, "gethostbyname_lock"); cs_lock_create(&clientlist_lock, 5, "clientlist_lock"); cs_lock_create(&readerlist_lock, 5, "readerlist_lock"); cs_lock_create(&fakeuser_lock, 5, "fakeuser_lock"); cs_lock_create(&ecmcache_lock, 5, "ecmcache_lock"); cs_lock_create(&readdir_lock, 5, "readdir_lock"); cs_lock_create(&cwcycle_lock, 5, "cwcycle_lock"); cs_lock_create(&hitcache_lock, 5, "hitcache_lock"); coolapi_open_all(); init_config(); cs_init_log(); if (!oscam_pidfile && cfg.pidfile) oscam_pidfile = cfg.pidfile; if (!oscam_pidfile) { oscam_pidfile = get_tmp_dir_filename(default_pidfile, sizeof(default_pidfile), "oscam.pid"); } if (oscam_pidfile) pidfile_create(oscam_pidfile); cs_init_statistics(); init_check(); init_stat(); // These initializations *MUST* be called after init_config() // because modules depend on config values. for (i=0; mod_def[i]; i++) { struct s_module *module = &modules[i]; mod_def[i](module); } for (i=0; cardsystem_def[i]; i++) { memset(&cardsystems[i], 0, sizeof(struct s_cardsystem)); cardsystem_def[i](&cardsystems[i]); } for (i=0; cardreader_def[i]; i++) { memset(&cardreaders[i], 0, sizeof(struct s_cardreader)); cardreader_def[i](&cardreaders[i]); } init_sidtab(); init_readerdb(); cfg.account = init_userdb(); init_signal(); init_srvid(); init_tierid(); init_provid(); start_garbage_collector(gbdb); cacheex_init(); init_len4caid(); init_irdeto_guess_tab(); write_versionfile(false); led_init(); led_status_default(); azbox_init(); mca_init(); global_whitelist_read(); cacheex_load_config_file(); for (i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; if ((module->type & MOD_CONN_NET)) { for (j = 0; j < module->ptab.nports; j++) { start_listener(module, &module->ptab.ports[j]); } } } //set time for server to now to avoid 0 in monitor/webif first_client->last=time((time_t *)0); webif_init(); start_thread((void *) &reader_check, "reader check"); cw_process_thread_start(); lcd_thread_start(); do_report_emm_support(); init_cardreader(); cs_waitforcardinit(); led_status_starting(); ac_init(); for (i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; if ((module->type & MOD_CONN_SERIAL) && module->s_handler) module->s_handler(NULL, NULL, i); } // main loop function process_clients(); cw_process_thread_wakeup(); // Stop cw_process thread pthread_cond_signal(&reader_check_sleep_cond); // Stop reader_check thread // Cleanup webif_close(); azbox_close(); coolapi_close_all(); mca_close(); led_status_stopping(); led_stop(); lcd_thread_stop(); remove_versionfile(); stat_finish(); cccam_done_share(); kill_all_clients(); kill_all_readers(); if (oscam_pidfile) unlink(oscam_pidfile); webif_tpls_free(); init_free_userdb(cfg.account); cfg.account = NULL; init_free_sidtab(); free_readerdb(); free_irdeto_guess_tab(); config_free(); cs_log("cardserver down"); log_free(); stop_garbage_collector(); free(first_client->account); free(first_client); // This prevents the compiler from removing config_mak from the final binary syslog_ident = config_mak; return exit_oscam; }
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); }