int dos_rename(const char *oldpath, const char *newpath) { /* This function isn't fully atomic like on Unix, but it's as close as I know how to do under DOS. */ struct trap_state ts; oskit_addr_t dos_buf_phys = (oskit_addr_t)kvtophys(dos_buf); int err; init_ts(&ts); /* Put the oldpath in the first half of dos_buf, and the newpath in the second half. */ if ((strlen(oldpath)+1 > DOS_BUF_SIZE/2) || (strlen(newpath)+1 > DOS_BUF_SIZE/2)) { errno = E2BIG; return -1; } strcpy(dos_buf, oldpath); strcpy(dos_buf+DOS_BUF_SIZE/2, newpath); /* Try once to rename the file. */ ts.trapno = 0x21; ts.eax = 0x5600; ts.v86_ds = dos_buf_phys >> 4; ts.edx = dos_buf_phys & 15; ts.v86_es = dos_buf_phys >> 4; ts.edi = (dos_buf_phys & 15) + DOS_BUF_SIZE/2; base_real_int(&ts); /* If that failed, delete newpath and then retry the rename. We _hope_ the failure was because newpath already existed; the DOS error codes I'm getting back seem to be bogus. */ if ((err = dos_check_err(&ts)) != 0) { ts.trapno = 0x21; ts.eax = 0x4100; ts.v86_ds = dos_buf_phys >> 4; ts.edx = (dos_buf_phys & 15) + DOS_BUF_SIZE/2; base_real_int(&ts); if ((err = dos_check_err(&ts)) != 0) return err; ts.trapno = 0x21; ts.eax = 0x5600; ts.v86_ds = dos_buf_phys >> 4; ts.edx = dos_buf_phys & 15; ts.v86_es = dos_buf_phys >> 4; ts.edi = (dos_buf_phys & 15) + DOS_BUF_SIZE/2; base_real_int(&ts); err = dos_check_err(&ts); }
int dos_read(dos_fd_t fd, void *buf, oskit_size_t size, oskit_size_t *out_actual) { int err; int actual = 0; struct trap_state ts; oskit_addr_t dos_buf_phys = (oskit_addr_t)kvtophys(dos_buf); assert(dos_buf); assert(dos_buf_phys); assert(dos_buf_phys < 0x100000); init_ts(&ts); while (size > 0) { int little_size = size; int little_actual; if (little_size > DOS_BUF_SIZE) little_size = DOS_BUF_SIZE; ts.trapno = 0x21; ts.eax = 0x3f00; ts.ebx = fd; ts.ecx = little_size; ts.v86_ds = dos_buf_phys >> 4; ts.edx = dos_buf_phys & 15; base_real_int(&ts); if ((err = dos_check_err(&ts)) != 0) return err; little_actual = ts.eax & 0xffff; assert(little_actual <= little_size); /* XXX don't copy if buf is <1MB */ memcpy(buf, dos_buf, little_actual); buf += little_actual; size -= little_actual; actual += little_actual; if (little_actual < little_size) break; } *out_actual = actual; return 0; }
struct ccx_demuxer *init_demuxer(void *parent, struct demuxer_cfg *cfg) { int i; struct ccx_demuxer *ctx = malloc(sizeof(struct ccx_demuxer)); if(!ctx) return NULL; ctx->infd = -1;//Set to -1 to indicate no file is open. ctx->m2ts = cfg->m2ts; ctx->auto_stream = cfg->auto_stream; ctx->stream_mode = CCX_SM_ELEMENTARY_OR_NOT_FOUND; ctx->ts_autoprogram = cfg->ts_autoprogram; ctx->ts_allprogram = cfg->ts_allprogram; ctx->ts_datastreamtype = cfg->ts_datastreamtype; ctx->nb_program = 0; ctx->multi_stream_per_prog = 0; if(cfg->ts_forced_program != -1) { ctx->pinfo[ctx->nb_program].pid = CCX_UNKNOWN; ctx->pinfo[ctx->nb_program].program_number = cfg->ts_forced_program; ctx->flag_ts_forced_pn = CCX_TRUE; ctx->nb_program++; } else { ctx->flag_ts_forced_pn = CCX_FALSE; } INIT_LIST_HEAD(&ctx->cinfo_tree.all_stream); INIT_LIST_HEAD(&ctx->cinfo_tree.sib_stream); INIT_LIST_HEAD(&ctx->cinfo_tree.pg_stream); ctx->codec = cfg->codec; ctx->flag_ts_forced_cappid = CCX_FALSE; for(i = 0; i < cfg->nb_ts_cappid; i++) { if(ctx->codec == CCX_CODEC_ANY) update_capinfo(ctx, cfg->ts_cappids[i], cfg->ts_datastreamtype, CCX_CODEC_NONE, 0, NULL); else update_capinfo(ctx, cfg->ts_cappids[i], cfg->ts_datastreamtype, ctx->codec, 0, NULL); } ctx->flag_ts_forced_cappid = cfg->nb_ts_cappid ? CCX_TRUE : CCX_FALSE; ctx->nocodec = cfg->nocodec; ctx->reset = ccx_demuxer_reset; ctx->close = ccx_demuxer_close; ctx->open = ccx_demuxer_open; ctx->is_open = ccx_demuxer_isopen; ctx->get_filesize = ccx_demuxer_getfilesize; ctx->get_stream_mode = ccx_demuxer_get_stream_mode; ctx->print_cfg = ccx_demuxer_print_cfg; ctx->write_es = ccx_demuxer_write_es; ctx->hauppauge_warning_shown = 0; ctx->parent = parent; ctx->last_pat_payload = NULL; ctx->last_pat_length = 0; ctx->fh_out_elementarystream = NULL; ctx->warning_program_not_found_shown = CCX_FALSE; ctx->strangeheader = 0; memset(&ctx->freport, 0, sizeof(ctx->freport)); if (cfg->out_elementarystream_filename != NULL) { if ((ctx->fh_out_elementarystream = fopen (cfg->out_elementarystream_filename,"wb"))==NULL) { print_error(CCX_COMMON_EXIT_FILE_CREATION_FAILED, "Unable to open clean file: %s\n", cfg->out_elementarystream_filename); return NULL; } } for(i = 0; i < MAX_PSI_PID; i++) ctx->PID_buffers[i]=NULL; init_ts(ctx); ctx->filebuffer = NULL; return ctx; }
struct lib_ccx_ctx* init_libraries(struct ccx_s_options *opt) { int ret = 0; struct lib_ccx_ctx *ctx; struct ccx_decoder_608_report *report_608; struct ccx_decoders_common_settings_t *dec_setting; ctx = malloc(sizeof(struct lib_ccx_ctx)); if(!ctx) return NULL; memset(ctx,0,sizeof(struct lib_ccx_ctx)); report_608 = malloc(sizeof(struct ccx_decoder_608_report)); if (!report_608) return NULL; memset(report_608,0,sizeof(struct ccx_decoder_608_report)); ctx->capbufsize = 20000; ctx->capbuf = NULL; ctx->capbuflen = 0; // Bytes read in capbuf // Initialize some constants init_ts(ctx); init_avc(); ctx->stream_mode = CCX_SM_ELEMENTARY_OR_NOT_FOUND; ctx->auto_stream = opt->auto_stream; ctx->m2ts = opt->m2ts; ctx->screens_to_process = -1; ctx->current_file = -1; ctx->infd = -1;//Set to -1 to indicate no file is open. // Set logging functions for libraries ccx_common_logging.debug_ftn = &dbg_print; ccx_common_logging.debug_mask = opt->debug_mask; ccx_common_logging.fatal_ftn = &fatal; ccx_common_logging.log_ftn = &mprint; ccx_common_logging.gui_ftn = &activity_library_process; // Need to set the 608 data for the report to the correct variable. ctx->freport.data_from_608 = report_608; // Same applies for 708 data ctx->freport.data_from_708 = &ccx_decoder_708_report; // Init shared decoder settings dec_setting = init_decoder_setting(opt); ctx->dec_ctx = init_cc_decode(dec_setting); dinit_decoder_setting(&dec_setting); // Init encoder helper variables ccx_encoders_helpers_setup(opt->encoding, opt->nofontcolor, opt->notypesetting, opt->trim_subs); //Initialize input files ctx->inputfile = opt->inputfile; ctx->num_input_files = opt->num_input_files; ret = init_ctx_input(opt, ctx); if (ret < 0) { goto end; } ret = init_ctx_extension(opt, ctx); if (ret < 0) { goto end; } // Init 708 decoder(s) ccx_decoders_708_init_library(ctx->basefilename, ctx->extension, opt->print_file_reports); // Set output structures for the 608 decoder //ctx->dec_ctx->context_cc608_field_1->out = ctx->dec_ctx->wbout1; //ctx->dec_ctx->context_cc608_field_2->out = ctx->dec_ctx->wbout2; // Init XDS buffers ccx_decoders_xds_init_library(&opt->transcript_settings, ctx->subs_delay, opt->millis_separator); //xds_cea608_test(); ctx->subs_delay = opt->subs_delay; ctx->wbout1.filename = opt->wbout2.filename; ctx->wbout2.filename = opt->wbout2.filename; ctx->buffer = (unsigned char *) malloc (BUFSIZE); ctx->pesheaderbuf = (unsigned char *) malloc (188); // Never larger anyway // Init timing ccx_common_timing_init(&ctx->past,opt->nosync); ctx->cc_to_stdout = opt->cc_to_stdout; ctx->hauppauge_mode = opt->hauppauge_mode; ctx->live_stream = opt->live_stream; ctx->binary_concat = opt->binary_concat; build_parity_table(); end: if (ret < 0) { free(ctx); return NULL; } return ctx; }
// tibit void probe_ts(info_t *ipipe) { int i; int found=0, doit=1; uint8_t sync = 0; ts_packet p; ssize_t size=0; #define MAX_PID 20 int pid[MAX_PID]; int npid=0; // look for a syncword while (!found && doit) { i = tc_pread(ipipe->fd_in, (uint8_t *)&sync, 1); if (sync == 0x47) found = 1; if (i == 0) doit = 0; } for (i=0 ; i<MAX_PID; i++) pid[i] = -1; while (size < ipipe->factor*1024*1024) { if((i=tc_pread(ipipe->fd_in, buffer, TS_PACK-1)) != TS_PACK-1) { tc_log_info(__FILE__, "end of stream"); return; } size += i; init_ts (&p); ac_memcpy (&p, buffer, 3); found = 0; for (i=0;i<npid;i++){ if ( get_pid (buffer) == pid[i] ) found = 1; } if (!found) { tc_log_info(__FILE__, "Found pid 0x%x", get_pid (buffer)); pid[npid] = get_pid (buffer); npid++; if (npid >= MAX_PID) { tc_log_warn(__FILE__, "Too many pids"); return; } } found = 0; doit = 1; // read away syncword while (!found && doit) { i = tc_pread(ipipe->fd_in, (uint8_t *)&sync, 1); if (sync == 0x47) found = 1; if (i == 0) doit = 0; size += i; } if(!doit) { tc_log_info(__FILE__, "end of stream"); return; } } if (!npid) tc_log_info(__FILE__, "No pids found"); }