PRIVATE void put_byte P1 (UVAL, val) { if (val >= (UVAL) 32 && val <= (UVAL) 126 && val != (UVAL) '\\' && val != (UVAL) '"') { put_header (stringgen, alignment_of_type (tp_char)); oprintf ("%c", (int) val); outcol++; } else { put_header (bytegen, alignment_of_type (tp_char)); oprintf ("0x%lx", val & OxffUL); outcol += 4; } }
static inline void ct_build_group(const struct nf_conntrack *ct, int a, struct nethdr *n, int b, int size) { void *ptr = put_header(n, b, size); nfct_get_attr_grp(ct, a, ptr); }
WERROR multilist_set_window(struct multilist *list, WINDOW *window) { int maxy, maxx; bool rerender = false; getmaxyx(window, maxy, maxx); /* rerender pad if window width is different. */ if (list->data && maxx != list->window_width) { rerender = true; } list->window = window; list->window_width = maxx; list->window_height = maxy; list->start_row = 0; if (rerender) { const void *row = multilist_get_current_row(list); WERROR rv = multilist_set_data(list, list->data); if (W_ERROR_IS_OK(rv) && row) { multilist_set_current_row(list, row); } return rv; } else { put_header(list); fix_start_row(list); } return WERR_OK; }
PRIVATE void put_pointer P1 (const EXPR *, ep) { put_header (longgen, alignment_of_type (tp_pointer)); putconst (ep); outcol += 10; }
/*Func: opt_x() * lseek 8 bytes from the beginning of arc * read the file name from argv and ready to search * find the file name from CLA * read each header file and store it in info strct * create a file by using open(info->name,RDWR_0|CREATE_O,0666) * set header of a new file * copy and paste the rest of the content from arch (use info->size) */ void opt_x(int argc, char **argv,int arch, int *filecount, int *fcalled, file *info){ char cur_name[16]; char *null_cur_name; char *null_info_name; int newfile=0; int fbyte_max=120; int fbyte=0; struct stat archinfo; fstat(arch,&archinfo); fbyte_max = archinfo.st_size; for((*fcalled) = 0; (*fcalled)<filecount[3];++(*fcalled)){ fbyte = 0; lseek(arch,8,SEEK_SET); read_filename(argv,filecount,2,fcalled,info);//get name from CLA for(fbyte_max ; fbyte < fbyte_max; fbyte++ ){ //for the end of file read(arch, cur_name,16); //get name of the file from arch null_cur_name = null_str(cur_name,16);//turn both of the name into null_cur_name = shrt_str(null_cur_name); null_info_name = null_str(info->name,16);//null terminated strings null_info_name = shrt_str(null_info_name); if(!strcmp(null_cur_name, null_info_name)){ put_header(arch, info); remove(null_info_name); newfile = open(null_info_name, O_RDWR|O_CREAT,0666); info->desc = arch; lseek(arch,2,SEEK_CUR); write_file_content(newfile, info); if(atoi(info->size)%2!=0) lseek(arch,1,SEEK_CUR); utime(null_info_name, atoi(info->time)); chmod(null_info_name, strtol(info->mode,NULL,8)); break; }else{ iter_arch(arch,&fbyte,info); } }//where the for EOF ends if(fbyte>=fbyte_max) printf(CY"Warning: File(\"%s\") doesn't documented in archeive.\nThe other file has successfully extract\n"NC,null_info_name); } /* printf("info->name: %.16s\n",info->name); printf("info->time: %.12s\n",info->time); printf("info->uid: %.6s\n",info->uid); printf("info->gid: %.6s\n",info->gid); printf("info->mode: %.8s\n",info->mode); printf("info->size: %.10s\n",info->size); */ return; }
static int test_init_simple() { yla_cop_type prg[HEADER_SIZE + 1]; yla_cop_type *ptr = prg; put_header(&ptr, 0, 0, 1); put_commd(&ptr, CHALT); yla_vm vm; YLATEST_ASSERT_TRUE(yla_vm_init(&vm, prg, HEADER_SIZE + 1), "normal"); YLATEST_ASSERT_TRUE(yla_vm_do_command(&vm) == -1, "halt expected") YLATEST_ASSERT_TRUE(yla_vm_done(&vm), "normal"); return 0; }
static int test_code_limit() { yla_cop_type prg[HEADER_SIZE + 1]; yla_cop_type *ptr = prg; put_header(&ptr, 0, 0, 1); put_commd(&ptr, CNOP); yla_vm vm; YLATEST_ASSERT_TRUE(yla_vm_init(&vm, prg, HEADER_SIZE + 1), "normal"); YLATEST_ASSERT_FALSE(yla_vm_run(&vm), "normal") YLATEST_ASSERT_TRUE(yla_vm_last_error(&vm) == YLA_VM_ERROR_CODE_SEG_EXCEED, "incorrect error code"); YLATEST_ASSERT_TRUE(yla_vm_done(&vm), "normal"); return 0; }
static int test_init_simple_run() { yla_cop_type prg[HEADER_SIZE + 2]; yla_cop_type *ptr = prg; put_header(&ptr, 0, 0, 2); put_commd(&ptr, CNOP); put_commd(&ptr, CHALT); yla_vm vm; YLATEST_ASSERT_TRUE(yla_vm_init(&vm, prg, HEADER_SIZE + 2), "normal"); YLATEST_ASSERT_TRUE(yla_vm_run(&vm), "normal") YLATEST_ASSERT_TRUE(yla_vm_done(&vm), "normal"); return 0; }
static int test_push() { yla_cop_type prg[HEADER_SIZE + 4]; yla_cop_type *ptr = prg; put_header(&ptr, 1, 0, 4); put_commd(&ptr, CPUSH); put_value(&ptr, 0x1234); put_commd(&ptr, CHALT); yla_vm vm; YLATEST_ASSERT_TRUE(yla_vm_init(&vm, prg, HEADER_SIZE + 4), "normal"); YLATEST_ASSERT_TRUE(yla_vm_run(&vm), "normal") YLATEST_ASSERT_TRUE(yla_vm_done(&vm), "normal"); return 0; }
static int test_get_stack_full() { yla_cop_type prg[HEADER_SIZE + 4]; yla_cop_type *ptr = prg; put_header(&ptr, 0, 0, 4); put_commd(&ptr, CPUSH); put_value(&ptr, 0x1234); put_commd(&ptr, CHALT); yla_vm vm; YLATEST_ASSERT_TRUE(yla_vm_init(&vm, prg, HEADER_SIZE + 4), "normal"); YLATEST_ASSERT_FALSE(yla_vm_run(&vm), "normal") YLATEST_ASSERT_TRUE(yla_vm_last_error(&vm) == YLA_VM_ERROR_STACK_FULL, "incorrect error code"); YLATEST_ASSERT_TRUE(yla_vm_done(&vm), "normal"); return 0; }
static int asf_write_markers(AVFormatContext *s) { ASFContext *asf = s->priv_data; AVIOContext *pb = s->pb; int i; AVRational scale = {1, 10000000}; int64_t hpos = put_header(pb, &ff_asf_marker_header); ff_put_guid(pb, &ff_asf_reserved_4);// ASF spec mandates this reserved value avio_wl32(pb, s->nb_chapters); // markers count avio_wl16(pb, 0); // ASF spec mandates 0 for this avio_wl16(pb, 0); // name length 0, no name given for (i = 0; i < s->nb_chapters; i++) { AVChapter *c = s->chapters[i]; AVDictionaryEntry *t = av_dict_get(c->metadata, "title", NULL, 0); int64_t pres_time = av_rescale_q(c->start, c->time_base, scale); uint64_t offset; int32_t send_time = get_send_time(asf, pres_time, &offset); int len = 0; uint8_t *buf; AVIOContext *dyn_buf; if (t) { if (avio_open_dyn_buf(&dyn_buf) < 0) return AVERROR(ENOMEM); avio_put_str16le(dyn_buf, t->value); len = avio_close_dyn_buf(dyn_buf, &buf); } avio_wl64(pb, offset); // offset of the packet with send_time avio_wl64(pb, pres_time + PREROLL_TIME * 10000); // presentation time avio_wl16(pb, 12 + len); // entry length avio_wl32(pb, send_time); // send time avio_wl32(pb, 0); // flags, should be 0 avio_wl32(pb, len / 2); // marker desc length in WCHARS! if (t) { avio_write(pb, buf, len); // marker desc av_freep(&buf); } } end_header(pb, hpos); return 0; }
void opt_v(int argc, char **argv,int arch, int *filecount, int *fcalled, file *info){ int fbyte_max=1; int fbyte=0; char cur_name[16]; char *null_cur_name; char null_time[13]; struct stat archinfo; fstat(arch,&archinfo); fbyte_max = archinfo.st_size; fbyte = 0; lseek(arch,8,SEEK_SET); for(fbyte=0; fbyte < fbyte_max; fbyte++){ read(arch,cur_name,16); null_cur_name = null_str(cur_name,16); null_cur_name = shrt_str(null_cur_name); (fbyte) += 60+atoi(info->size); if(fbyte < fbyte_max){ put_header(arch,info); lseek(arch,atoi(info->size)+2,SEEK_CUR); print_mode(info); printf("%.6s",info->uid); printf("/%.6s",info->gid); printf("%.10s",info->size); //null_time= null_str(info->time,12); //null_time= shrt_str(null_time); //strftime(null_time,12,"%c",info->time); printf("%.12s",info->time); printf("%.16s",null_cur_name); printf("\n"); if(atoi(info->size)%2!=0){ lseek(arch,1,SEEK_CUR); (fbyte)++; } } } }
/* * Create a new library */ int create_library(char *libname) { FILE *libfp; struct rdlm_hdr hdr; hdr.magic = RDLAMAG; hdr.hdrsize = 0; hdr.date = time(NULL); hdr.owner = getuid(); hdr.group = getgid(); hdr.mode = umask(022); hdr.size = 0; libfp = fopen(libname, "wb"); if (!libfp) error_exit(1, true, "could not open '%s'\n", libname); /* Write library header */ put_header(&hdr, libfp, NULL); fclose(libfp); return true; }
WERROR multilist_set_data(struct multilist *list, const void *data) { WERROR rv; SMB_ASSERT(list->window != NULL); list->data = data; calc_column_widths(list); if (list->pad) { delwin(list->pad); } /* construct a pad that is exactly the width of the window, and as tall as required to fit all data rows. */ list->nrows = data_get_row_count(list); list->pad = newpad(MAX(list->nrows, 1), list->window_width); if (list->pad == NULL) { return WERR_NOT_ENOUGH_MEMORY; } /* add the column headers to the window and render all rows to the pad. */ werase(list->window); put_header(list); rv = put_data(list); if (!W_ERROR_IS_OK(rv)) { return rv; } /* initialize the cursor */ list->start_row = 0; list->cursor_row = 0; list->current_row = data_get_first_row(list); highlight_current_row(list); return WERR_OK; }
/* * Add a module to the library */ int add_module(FILE * libfp, const char *fname, char *modname) { FILE *modfp; struct rdlm_hdr hdr = { RDLMMAG, 0, 0, 0, 0, 0, 0 }; struct stat finfo; int i; if (options.verbose) fprintf(stderr, "adding module %s\n", modname); /* Initialize some fields in the module header */ if (stat(fname, &finfo) < 0) error_exit(1, true, "could not stat '%s'", fname); hdr.date = finfo.st_mtime; hdr.owner = finfo.st_uid; hdr.group = finfo.st_gid; hdr.size = finfo.st_size; modfp = fopen(fname, "rb"); if (!modfp) error_exit(1, true, "could not open '%s'", fname); /* Write module header */ put_header(&hdr, libfp, modname); /* Put the module itself */ while (!feof(modfp)) { i = fgetc(modfp); if (i == EOF) break; if (fputc(i, libfp) == EOF) error_exit(1, false, "write error"); } fclose(modfp); return true; }
/* put sequence header if needed */ static void mpeg1_encode_sequence_header(MpegEncContext *s) { unsigned int vbv_buffer_size; unsigned int fps, v; int i; uint64_t time_code; float best_aspect_error= 1E10; float aspect_ratio= av_q2d(s->avctx->sample_aspect_ratio); int constraint_parameter_flag; if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA) if (s->current_picture.key_frame) { AVRational framerate= ff_frame_rate_tab[s->frame_rate_index]; /* mpeg1 header repeated every gop */ put_header(s, SEQ_START_CODE); put_bits(&s->pb, 12, s->width); put_bits(&s->pb, 12, s->height); #if 0 //MEANX for(i=1; i<15; i++){ float error= aspect_ratio; if(s->codec_id == CODEC_ID_MPEG1VIDEO || i <=1) error-= 1.0/ff_mpeg1_aspect[i]; else error-= av_q2d(ff_mpeg2_aspect[i])*s->height/s->width; error= FFABS(error); if(error < best_aspect_error){ best_aspect_error= error; s->aspect_ratio_info= i; } } #endif // MEANX //MEANX put_bits(&s->pb, 4, s->aspect_ratio_info); //MEANX put_bits(&s->pb, 4, s->frame_rate_index); // MEANX 4:3 if(s->avctx->sample_aspect_ratio.num==16 && s->avctx->sample_aspect_ratio.den==9) { //printf("FFmpeg : Wide\n"); put_bits(&s->pb,4,3); //16:9 } else //4:3 { if(s->codec_id == CODEC_ID_MPEG2VIDEO) put_bits(&s->pb, 4, 2); else put_bits(&s->pb, 4, 12); // MPEG1 } // /MEANX // //MEANX PULLDOWN put_bits(&s->pb, 4, s->frame_rate_index); if((s->flags2 & CODEC_FLAG2_32_PULLDOWN) && (s->codec_id == CODEC_ID_MPEG2VIDEO)) { put_bits(&s->pb, 4,4); } else { put_bits(&s->pb, 4, s->frame_rate_index); } //MEANX pulldown if(s->avctx->rc_max_rate_header){ //MEANX we use header v = (s->avctx->rc_max_rate_header + 399) / 400; if (v > 0x3ffff && s->codec_id == CODEC_ID_MPEG1VIDEO) v = 0x3ffff; }else{ v= 0x3FFFF; } // MEANX we use rc_buffer_size_header here to force // a correct rc_buffer_size if(s->avctx->rc_buffer_size_header) vbv_buffer_size = s->avctx->rc_buffer_size_header; else /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */ vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024; vbv_buffer_size= (vbv_buffer_size + 16383) / 16384; put_bits(&s->pb, 18, v & 0x3FFFF); put_bits(&s->pb, 1, 1); /* marker */ put_bits(&s->pb, 10, vbv_buffer_size & 0x3FF); constraint_parameter_flag= s->width <= 768 && s->height <= 576 && s->mb_width * s->mb_height <= 396 && s->mb_width * s->mb_height * framerate.num <= framerate.den*396*25 && framerate.num <= framerate.den*30 && s->avctx->me_range && s->avctx->me_range < 128 && vbv_buffer_size <= 20 && v <= 1856000/400 && s->codec_id == CODEC_ID_MPEG1VIDEO; put_bits(&s->pb, 1, constraint_parameter_flag); ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix); ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); if(s->codec_id == CODEC_ID_MPEG2VIDEO){ put_header(s, EXT_START_CODE); put_bits(&s->pb, 4, 1); //seq ext put_bits(&s->pb, 1, s->avctx->profile == 0); //escx 1 for 4:2:2 profile */ put_bits(&s->pb, 3, s->avctx->profile); //profile put_bits(&s->pb, 4, s->avctx->level); //level // MEANX pulldown put_bits(&s->pb, 1, s->progressive_sequence); // MEANX Pulldown if(s->flags2 & CODEC_FLAG2_32_PULLDOWN) //MEANX put_bits(&s->pb, 1, 0); else put_bits(&s->pb, 1, s->progressive_sequence); // /MEANX put_bits(&s->pb, 2, s->chroma_format); put_bits(&s->pb, 2, 0); //horizontal size ext put_bits(&s->pb, 2, 0); //vertical size ext put_bits(&s->pb, 12, v>>18); //bitrate ext put_bits(&s->pb, 1, 1); //marker put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext put_bits(&s->pb, 1, s->low_delay); put_bits(&s->pb, 2, 0); // frame_rate_ext_n put_bits(&s->pb, 5, 0); // frame_rate_ext_d }
PRIVATE void put_word P1 (UVAL, val) { put_header (wordgen, alignment_of_type (tp_short)); oprintf ("0x%lx", val & OxffffUL); outcol += 6; }
/* put sequence header if needed */ static void mpeg1_encode_sequence_header(MpegEncContext *s) { unsigned int vbv_buffer_size; unsigned int fps, v; uint64_t time_code; int constraint_parameter_flag; if (s->current_picture.f.key_frame) { AVRational framerate= ff_frame_rate_tab[s->frame_rate_index]; /* mpeg1 header repeated every gop */ put_header(s, SEQ_START_CODE); put_sbits(&s->pb, 12, s->width ); put_sbits(&s->pb, 12, s->height); put_bits(&s->pb, 4, s->aspect_ratio_info); put_bits(&s->pb, 4, s->frame_rate_index); if(s->avctx->rc_max_rate){ v = (s->avctx->rc_max_rate + 399) / 400; if (v > 0x3ffff && s->codec_id == CODEC_ID_MPEG1VIDEO) v = 0x3ffff; }else{ v= 0x3FFFF; } if(s->avctx->rc_buffer_size) vbv_buffer_size = s->avctx->rc_buffer_size; else /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */ vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024; vbv_buffer_size= (vbv_buffer_size + 16383) / 16384; put_sbits(&s->pb, 18, v); put_bits(&s->pb, 1, 1); /* marker */ put_sbits(&s->pb, 10, vbv_buffer_size); constraint_parameter_flag= s->width <= 768 && s->height <= 576 && s->mb_width * s->mb_height <= 396 && s->mb_width * s->mb_height * framerate.num <= framerate.den*396*25 && framerate.num <= framerate.den*30 && s->avctx->me_range && s->avctx->me_range < 128 && vbv_buffer_size <= 20 && v <= 1856000/400 && s->codec_id == CODEC_ID_MPEG1VIDEO; put_bits(&s->pb, 1, constraint_parameter_flag); ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix); ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); if(s->codec_id == CODEC_ID_MPEG2VIDEO){ put_header(s, EXT_START_CODE); put_bits(&s->pb, 4, 1); //seq ext put_bits(&s->pb, 1, s->avctx->profile == 0); //escx 1 for 4:2:2 profile */ put_bits(&s->pb, 3, s->avctx->profile); //profile put_bits(&s->pb, 4, s->avctx->level); //level put_bits(&s->pb, 1, s->progressive_sequence); put_bits(&s->pb, 2, s->chroma_format); put_bits(&s->pb, 2, s->width >>12); put_bits(&s->pb, 2, s->height>>12); put_bits(&s->pb, 12, v>>18); //bitrate ext put_bits(&s->pb, 1, 1); //marker put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext put_bits(&s->pb, 1, s->low_delay); put_bits(&s->pb, 2, 0); // frame_rate_ext_n put_bits(&s->pb, 5, 0); // frame_rate_ext_d if (s->avctx->color_primaries != AVCOL_PRI_UNSPECIFIED) { put_header(s, EXT_START_CODE); put_bits(&s->pb, 4, 2); //seq display ext put_bits(&s->pb, 3, 0); //video_format, set to component put_bits(&s->pb, 1, 1); //colour_description put_bits(&s->pb, 8, s->avctx->color_primaries); //colour_primaries put_bits(&s->pb, 8, s->avctx->color_transfer); //transfer_characteristics put_bits(&s->pb, 8, s->avctx->color_matrix); //matrix_coefficients put_bits(&s->pb, 14, s->width); put_bits(&s->pb, 1, 1); put_bits(&s->pb, 14, s->height); put_bits(&s->pb, 1, 0); } }
void opt_d(int argc, char **argv,int *arch, int *filecount, int *fcalled, file *info){ int fbyte_max=1; int fbyte=0; int size = 0; int tsize = 0; int tempfile=0; int temparch =0; char cur_name[16]; char *null_cur_name; char *null_info_name; char *str_buf; struct stat archinfo; struct stat temparch_info; fstat((*arch),&archinfo); temparch = open_file("temp_arch",1); fbyte_max = archinfo.st_size; //for fcalled goes here fbyte = 0; lseek((*arch),8,SEEK_SET); read_filename(argv,filecount,4,fcalled,info); for(fbyte=0; fbyte < fbyte_max; ){ read((*arch),cur_name,16); null_cur_name = null_str(cur_name,16); null_cur_name = shrt_str(null_cur_name); null_info_name= null_str(info->name,16); null_info_name = shrt_str(null_info_name); (fbyte) += 60+atoi(info->size); if(fbyte < fbyte_max){ if(!strcmp(null_cur_name,null_info_name)){//equal iter_arch((*arch), &fbyte, info); (fbyte) -= 60+atoi(info->size); }else{ tempfile = 0; put_header((*arch), info); lseek((*arch),2,SEEK_CUR); /*printf("\ninfo->name: %.16s\n",info->name); printf("cur name: %.16s\n",cur_name); printf("info->time: %.12s\n",info->time); printf("info->uid: %.6s\n",info->uid); printf("info->gid: %.6s\n",info->gid); printf("info->mode: %.8s\n",info->mode); printf("info->size: %.10s\n",info->size); */ //so now the header are read correctly //Time to put info in files tempfile = create_tempfile(); write_file_header2(tempfile,cur_name,info); info->desc = (*arch); write_file_content(tempfile,info); all_in_arch(tempfile,temparch,fcalled,info); if(tsize%2!=0){ write(temparch,"\n",1); } (*fcalled)++; close(tempfile); if(atoi(info->size)%2!=0) lseek((*arch),1,SEEK_CUR); } } } //FIXME: the temp_arch has the correct info but when copy to arch itself has wrong info. fstat(temparch,&temparch_info); size = temparch_info.st_size; printf("temparch.size: %d\n",size); str_buf = malloc(sizeof(char)*size); read(temparch,str_buf,size); //ftruncate((*arch),(sizeof(char))*size); lseek((*arch),0,SEEK_SET); write((*arch),str_buf,size); free(str_buf); close(temparch); //remove("temp_arch"); }
/* * concatenate two (or more) files into one single file */ void concatenate(int argc, char **argv) { int zerr; gzFile fd; struct log_global_header hdr, tmp; memset(&hdr, 0, sizeof(struct log_global_header)); /* open the output file for writing */ fd = gzopen(GBL_LOGFILE, "wb"); ON_ERROR(fd, NULL, "%s", gzerror(fd, &zerr)); /* * use GBL_LOG_FD here so the get_header function * will use this file */ GBL_LOG_FD = gzopen(argv[argc], "rb"); ON_ERROR(GBL_LOG_FD, NULL, "%s", gzerror(GBL_LOG_FD, &zerr)); /* get the file header */ if (get_header(&hdr) != E_SUCCESS) FATAL_ERROR("Invalid log file (%s)", argv[argc]); /* write the header */ put_header(fd, &hdr); printf("Concatenating file [%s]", argv[argc]); /* copy the first file into the output */ dump_file(fd, &hdr); /* move the pointer to the next file */ argc++; /* cicle thru the file list */ while(argv[argc] != NULL) { GBL_LOG_FD = gzopen(argv[argc], "rb"); ON_ERROR(GBL_LOG_FD, NULL, "%s", gzerror(GBL_LOG_FD, &zerr)); /* get the file header */ if (get_header(&tmp) != E_SUCCESS) FATAL_ERROR("Invalid log file (%s)", argv[argc]); /* check if the files are compatible */ if (hdr.type != tmp.type) FATAL_ERROR("Cannot concatenate different type of file"); printf("Concatenating file [%s]", argv[argc]); /* concatenate this file */ dump_file(fd, &tmp); gzclose(GBL_LOG_FD); argc++; } gzclose(fd); printf("\nAll files concatenated into: %s\n\n", GBL_LOGFILE); exit(0); }
/* write the header (used two times if non streamed) */ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size) { ASFContext *asf = s->priv_data; AVIOContext *pb = s->pb; AVDictionaryEntry *tags[5]; int header_size, n, extra_size, extra_size2, wav_extra_size, file_time; int has_title, has_aspect_ratio = 0; int metadata_count; AVCodecContext *enc; int64_t header_offset, cur_pos, hpos; int bit_rate; int64_t duration; ff_metadata_conv(&s->metadata, ff_asf_metadata_conv, NULL); tags[0] = av_dict_get(s->metadata, "title", NULL, 0); tags[1] = av_dict_get(s->metadata, "author", NULL, 0); tags[2] = av_dict_get(s->metadata, "copyright", NULL, 0); tags[3] = av_dict_get(s->metadata, "comment", NULL, 0); tags[4] = av_dict_get(s->metadata, "rating", NULL, 0); duration = asf->duration + PREROLL_TIME * 10000; has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4]; metadata_count = av_dict_count(s->metadata); bit_rate = 0; for (n = 0; n < s->nb_streams; n++) { enc = s->streams[n]->codec; avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */ bit_rate += enc->bit_rate; if ( enc->codec_type == AVMEDIA_TYPE_VIDEO && enc->sample_aspect_ratio.num > 0 && enc->sample_aspect_ratio.den > 0) has_aspect_ratio++; } if (asf->is_streamed) { put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */ } ff_put_guid(pb, &ff_asf_header); avio_wl64(pb, -1); /* header length, will be patched after */ avio_wl32(pb, 3 + has_title + !!metadata_count + s->nb_streams); /* number of chunks in header */ avio_w8(pb, 1); /* ??? */ avio_w8(pb, 2); /* ??? */ /* file header */ header_offset = avio_tell(pb); hpos = put_header(pb, &ff_asf_file_header); ff_put_guid(pb, &ff_asf_my_guid); avio_wl64(pb, file_size); file_time = 0; avio_wl64(pb, unix_to_file_time(file_time)); avio_wl64(pb, asf->nb_packets); /* number of packets */ avio_wl64(pb, duration); /* end time stamp (in 100ns units) */ avio_wl64(pb, asf->duration); /* duration (in 100ns units) */ avio_wl64(pb, PREROLL_TIME); /* start time stamp */ avio_wl32(pb, (asf->is_streamed || !pb->seekable) ? 3 : 2); /* ??? */ avio_wl32(pb, s->packet_size); /* packet size */ avio_wl32(pb, s->packet_size); /* packet size */ avio_wl32(pb, bit_rate ? bit_rate : -1); /* Maximum data rate in bps */ end_header(pb, hpos); /* unknown headers */ hpos = put_header(pb, &ff_asf_head1_guid); ff_put_guid(pb, &ff_asf_head2_guid); avio_wl16(pb, 6); if (has_aspect_ratio) { int64_t hpos2; avio_wl32(pb, 26 + has_aspect_ratio * 84); hpos2 = put_header(pb, &ff_asf_metadata_header); avio_wl16(pb, 2 * has_aspect_ratio); for (n = 0; n < s->nb_streams; n++) { enc = s->streams[n]->codec; if ( enc->codec_type == AVMEDIA_TYPE_VIDEO && enc->sample_aspect_ratio.num > 0 && enc->sample_aspect_ratio.den > 0) { AVRational sar = enc->sample_aspect_ratio; avio_wl16(pb, 0); // the stream number is set like this below avio_wl16(pb, n + 1); avio_wl16(pb, 26); // name_len avio_wl16(pb, 3); // value_type avio_wl32(pb, 4); // value_len avio_put_str16le(pb, "AspectRatioX"); avio_wl32(pb, sar.num); avio_wl16(pb, 0); // the stream number is set like this below avio_wl16(pb, n + 1); avio_wl16(pb, 26); // name_len avio_wl16(pb, 3); // value_type avio_wl32(pb, 4); // value_len avio_put_str16le(pb, "AspectRatioY"); avio_wl32(pb, sar.den); } } end_header(pb, hpos2); } else { avio_wl32(pb, 0); } end_header(pb, hpos); /* title and other infos */ if (has_title) { int len; uint8_t *buf; AVIOContext *dyn_buf; if (avio_open_dyn_buf(&dyn_buf) < 0) return AVERROR(ENOMEM); hpos = put_header(pb, &ff_asf_comment_header); for (n = 0; n < FF_ARRAY_ELEMS(tags); n++) { len = tags[n] ? avio_put_str16le(dyn_buf, tags[n]->value) : 0; avio_wl16(pb, len); } len = avio_close_dyn_buf(dyn_buf, &buf); avio_write(pb, buf, len); av_freep(&buf); end_header(pb, hpos); } if (metadata_count) { AVDictionaryEntry *tag = NULL; hpos = put_header(pb, &ff_asf_extended_content_header); avio_wl16(pb, metadata_count); while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { put_str16(pb, tag->key); avio_wl16(pb, 0); put_str16(pb, tag->value); } end_header(pb, hpos); } /* chapters using ASF markers */ if (!asf->is_streamed && s->nb_chapters) { int ret; if (ret = asf_write_markers(s)) return ret; } /* stream headers */ for (n = 0; n < s->nb_streams; n++) { int64_t es_pos; // ASFStream *stream = &asf->streams[n]; enc = s->streams[n]->codec; asf->streams[n].num = n + 1; asf->streams[n].seq = 1; switch (enc->codec_type) { case AVMEDIA_TYPE_AUDIO: wav_extra_size = 0; extra_size = 18 + wav_extra_size; extra_size2 = 8; break; default: case AVMEDIA_TYPE_VIDEO: wav_extra_size = enc->extradata_size; extra_size = 0x33 + wav_extra_size; extra_size2 = 0; break; } hpos = put_header(pb, &ff_asf_stream_header); if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { ff_put_guid(pb, &ff_asf_audio_stream); ff_put_guid(pb, &ff_asf_audio_conceal_spread); } else { ff_put_guid(pb, &ff_asf_video_stream); ff_put_guid(pb, &ff_asf_video_conceal_none); } avio_wl64(pb, 0); /* ??? */ es_pos = avio_tell(pb); avio_wl32(pb, extra_size); /* wav header len */ avio_wl32(pb, extra_size2); /* additional data len */ avio_wl16(pb, n + 1); /* stream number */ avio_wl32(pb, 0); /* ??? */ if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { /* WAVEFORMATEX header */ int wavsize = ff_put_wav_header(pb, enc, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX); if (wavsize < 0) return -1; if (wavsize != extra_size) { cur_pos = avio_tell(pb); avio_seek(pb, es_pos, SEEK_SET); avio_wl32(pb, wavsize); /* wav header len */ avio_seek(pb, cur_pos, SEEK_SET); } /* ERROR Correction */ avio_w8(pb, 0x01); if (enc->codec_id == AV_CODEC_ID_ADPCM_G726 || !enc->block_align) { avio_wl16(pb, 0x0190); avio_wl16(pb, 0x0190); } else { avio_wl16(pb, enc->block_align); avio_wl16(pb, enc->block_align); } avio_wl16(pb, 0x01); avio_w8(pb, 0x00); } else { avio_wl32(pb, enc->width); avio_wl32(pb, enc->height); avio_w8(pb, 2); /* ??? */ avio_wl16(pb, 40 + enc->extradata_size); /* size */ /* BITMAPINFOHEADER header */ ff_put_bmp_header(pb, enc, ff_codec_bmp_tags, 1, 0); } end_header(pb, hpos); } /* media comments */ hpos = put_header(pb, &ff_asf_codec_comment_header); ff_put_guid(pb, &ff_asf_codec_comment1_header); avio_wl32(pb, s->nb_streams); for (n = 0; n < s->nb_streams; n++) { const AVCodecDescriptor *codec_desc; const char *desc; enc = s->streams[n]->codec; codec_desc = avcodec_descriptor_get(enc->codec_id); if (enc->codec_type == AVMEDIA_TYPE_AUDIO) avio_wl16(pb, 2); else if (enc->codec_type == AVMEDIA_TYPE_VIDEO) avio_wl16(pb, 1); else avio_wl16(pb, -1); if (enc->codec_id == AV_CODEC_ID_WMAV2) desc = "Windows Media Audio V8"; else desc = codec_desc ? codec_desc->name : NULL; if (desc) { AVIOContext *dyn_buf; uint8_t *buf; int len; if (avio_open_dyn_buf(&dyn_buf) < 0) return AVERROR(ENOMEM); avio_put_str16le(dyn_buf, desc); len = avio_close_dyn_buf(dyn_buf, &buf); avio_wl16(pb, len / 2); // "number of characters" = length in bytes / 2 avio_write(pb, buf, len); av_freep(&buf); } else avio_wl16(pb, 0); avio_wl16(pb, 0); /* no parameters */ /* id */ if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { avio_wl16(pb, 2); avio_wl16(pb, enc->codec_tag); } else { avio_wl16(pb, 4); avio_wl32(pb, enc->codec_tag); } if (!enc->codec_tag) return -1; } end_header(pb, hpos); /* patch the header size fields */ cur_pos = avio_tell(pb); header_size = cur_pos - header_offset; if (asf->is_streamed) { header_size += 8 + 30 + DATA_HEADER_SIZE; avio_seek(pb, header_offset - 10 - 30, SEEK_SET); avio_wl16(pb, header_size); avio_seek(pb, header_offset - 2 - 30, SEEK_SET); avio_wl16(pb, header_size); header_size -= 8 + 30 + DATA_HEADER_SIZE; } header_size += 24 + 6; avio_seek(pb, header_offset - 14, SEEK_SET); avio_wl64(pb, header_size); avio_seek(pb, cur_pos, SEEK_SET); /* movie chunk, followed by packets of packet_size */ asf->data_offset = cur_pos; ff_put_guid(pb, &ff_asf_data_header); avio_wl64(pb, data_chunk_size); ff_put_guid(pb, &ff_asf_my_guid); avio_wl64(pb, asf->nb_packets); /* nb packets */ avio_w8(pb, 1); /* ??? */ avio_w8(pb, 1); /* ??? */ return 0; }
static inline void ct_build_u8(const struct nf_conntrack *ct, int a, struct nethdr *n, int b) { void *ptr = put_header(n, b, sizeof(uint8_t)); memcpy(ptr, nfct_get_attr(ct, a), sizeof(uint8_t)); }
/* put sequence header if needed */ static void mpeg1_encode_sequence_header(MpegEncContext *s) { unsigned int vbv_buffer_size, fps, v; int i, constraint_parameter_flag; uint64_t time_code; int64_t best_aspect_error = INT64_MAX; AVRational aspect_ratio = s->avctx->sample_aspect_ratio; if (aspect_ratio.num == 0 || aspect_ratio.den == 0) aspect_ratio = (AVRational){1,1}; // pixel aspect 1.1 (VGA) if (s->current_picture.f->key_frame) { AVRational framerate = ff_mpeg12_frame_rate_tab[s->frame_rate_index]; /* mpeg1 header repeated every gop */ put_header(s, SEQ_START_CODE); put_sbits(&s->pb, 12, s->width & 0xFFF); put_sbits(&s->pb, 12, s->height & 0xFFF); for (i = 1; i < 15; i++) { int64_t error = aspect_ratio.num * (1LL<<32) / aspect_ratio.den; if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO || i <= 1) error -= (1LL<<32) / ff_mpeg1_aspect[i]; else error -= (1LL<<32)*ff_mpeg2_aspect[i].num * s->height / s->width / ff_mpeg2_aspect[i].den; error = FFABS(error); if (error - 2 <= best_aspect_error) { best_aspect_error = error; s->aspect_ratio_info = i; } } put_bits(&s->pb, 4, s->aspect_ratio_info); put_bits(&s->pb, 4, s->frame_rate_index); if (s->avctx->rc_max_rate) { v = (s->avctx->rc_max_rate + 399) / 400; if (v > 0x3ffff && s->codec_id == AV_CODEC_ID_MPEG1VIDEO) v = 0x3ffff; } else { v = 0x3FFFF; } if (s->avctx->rc_buffer_size) vbv_buffer_size = s->avctx->rc_buffer_size; else /* VBV calculation: Scaled so that a VCD has the proper * VBV size of 40 kilobytes */ vbv_buffer_size = ((20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024; vbv_buffer_size = (vbv_buffer_size + 16383) / 16384; put_sbits(&s->pb, 18, v); put_bits(&s->pb, 1, 1); // marker put_sbits(&s->pb, 10, vbv_buffer_size); constraint_parameter_flag = s->width <= 768 && s->height <= 576 && s->mb_width * s->mb_height <= 396 && s->mb_width * s->mb_height * framerate.num <= 396 * 25 * framerate.den && framerate.num <= framerate.den * 30 && s->avctx->me_range && s->avctx->me_range < 128 && vbv_buffer_size <= 20 && v <= 1856000 / 400 && s->codec_id == AV_CODEC_ID_MPEG1VIDEO; put_bits(&s->pb, 1, constraint_parameter_flag); ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix); ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) { AVFrameSideData *side_data; int width = s->width; int height = s->height; int use_seq_disp_ext; put_header(s, EXT_START_CODE); put_bits(&s->pb, 4, 1); // seq ext put_bits(&s->pb, 1, s->avctx->profile == 0); // escx 1 for 4:2:2 profile put_bits(&s->pb, 3, s->avctx->profile); // profile put_bits(&s->pb, 4, s->avctx->level); // level put_bits(&s->pb, 1, s->progressive_sequence); put_bits(&s->pb, 2, s->chroma_format); put_bits(&s->pb, 2, s->width >> 12); put_bits(&s->pb, 2, s->height >> 12); put_bits(&s->pb, 12, v >> 18); // bitrate ext put_bits(&s->pb, 1, 1); // marker put_bits(&s->pb, 8, vbv_buffer_size >> 10); // vbv buffer ext put_bits(&s->pb, 1, s->low_delay); put_bits(&s->pb, 2, s->mpeg2_frame_rate_ext.num-1); // frame_rate_ext_n put_bits(&s->pb, 5, s->mpeg2_frame_rate_ext.den-1); // frame_rate_ext_d side_data = av_frame_get_side_data(s->current_picture_ptr->f, AV_FRAME_DATA_PANSCAN); if (side_data) { AVPanScan *pan_scan = (AVPanScan *)side_data->data; if (pan_scan->width && pan_scan->height) { width = pan_scan->width >> 4; height = pan_scan->height >> 4; } }
static inline void addattr(struct nethdr *n, int attr, const void *data, size_t len) { void *ptr = put_header(n, attr, len); memcpy(ptr, data, len); }
/* write the header (used two times if non streamed) */ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size) { ASFContext *asf = s->priv_data; ByteIOContext *pb = s->pb; AVMetadataTag *title, *author, *copyright, *comment; int header_size, n, extra_size, extra_size2, wav_extra_size, file_time; int has_title; int metadata_count; AVCodecContext *enc; int64_t header_offset, cur_pos, hpos; int bit_rate; int64_t duration; title = av_metadata_get(s->metadata, "title" , NULL, 0); author = av_metadata_get(s->metadata, "author" , NULL, 0); copyright = av_metadata_get(s->metadata, "copyright", NULL, 0); comment = av_metadata_get(s->metadata, "comment" , NULL, 0); duration = asf->duration + PREROLL_TIME * 10000; has_title = title || author || copyright || comment; metadata_count = s->metadata ? s->metadata->count : 0; bit_rate = 0; for(n=0;n<s->nb_streams;n++) { enc = s->streams[n]->codec; av_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */ bit_rate += enc->bit_rate; } if (asf->is_streamed) { put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */ } put_guid(pb, &ff_asf_header); put_le64(pb, -1); /* header length, will be patched after */ put_le32(pb, 3 + has_title + !!metadata_count + s->nb_streams); /* number of chunks in header */ put_byte(pb, 1); /* ??? */ put_byte(pb, 2); /* ??? */ /* file header */ header_offset = url_ftell(pb); hpos = put_header(pb, &ff_asf_file_header); put_guid(pb, &ff_asf_my_guid); put_le64(pb, file_size); file_time = 0; put_le64(pb, unix_to_file_time(file_time)); put_le64(pb, asf->nb_packets); /* number of packets */ put_le64(pb, duration); /* end time stamp (in 100ns units) */ put_le64(pb, asf->duration); /* duration (in 100ns units) */ put_le64(pb, PREROLL_TIME); /* start time stamp */ put_le32(pb, (asf->is_streamed || url_is_streamed(pb)) ? 3 : 2); /* ??? */ put_le32(pb, asf->packet_size); /* packet size */ put_le32(pb, asf->packet_size); /* packet size */ put_le32(pb, bit_rate); /* Nominal data rate in bps */ end_header(pb, hpos); /* unknown headers */ hpos = put_header(pb, &ff_asf_head1_guid); put_guid(pb, &ff_asf_head2_guid); put_le32(pb, 6); put_le16(pb, 0); end_header(pb, hpos); /* title and other infos */ if (has_title) { hpos = put_header(pb, &ff_asf_comment_header); put_le16(pb, title ? 2 * (strlen(title->value ) + 1) : 0); put_le16(pb, author ? 2 * (strlen(author->value ) + 1) : 0); put_le16(pb, copyright ? 2 * (strlen(copyright->value) + 1) : 0); put_le16(pb, comment ? 2 * (strlen(comment->value ) + 1) : 0); put_le16(pb, 0); if (title ) put_str16_nolen(pb, title->value ); if (author ) put_str16_nolen(pb, author->value ); if (copyright) put_str16_nolen(pb, copyright->value); if (comment ) put_str16_nolen(pb, comment->value ); end_header(pb, hpos); } if (metadata_count) { AVMetadataTag *tag = NULL; hpos = put_header(pb, &ff_asf_extended_content_header); put_le16(pb, metadata_count); while ((tag = av_metadata_get(s->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) { put_le16(pb, 2*(strlen(tag->key) + 3) + 1); put_le16(pb, 'W'); put_le16(pb, 'M'); put_le16(pb, '/'); put_str16_nolen(pb, tag->key); put_le16(pb, 0); put_le16(pb, 2*strlen(tag->value) + 1); put_str16_nolen(pb, tag->value); } end_header(pb, hpos); } /* stream headers */ for(n=0;n<s->nb_streams;n++) { int64_t es_pos; // ASFStream *stream = &asf->streams[n]; enc = s->streams[n]->codec; asf->streams[n].num = n + 1; asf->streams[n].seq = 0; switch(enc->codec_type) { case CODEC_TYPE_AUDIO: wav_extra_size = 0; extra_size = 18 + wav_extra_size; extra_size2 = 8; break; default: case CODEC_TYPE_VIDEO: wav_extra_size = enc->extradata_size; extra_size = 0x33 + wav_extra_size; extra_size2 = 0; break; } hpos = put_header(pb, &ff_asf_stream_header); if (enc->codec_type == CODEC_TYPE_AUDIO) { put_guid(pb, &ff_asf_audio_stream); put_guid(pb, &ff_asf_audio_conceal_spread); } else { put_guid(pb, &ff_asf_video_stream); put_guid(pb, &ff_asf_video_conceal_none); } put_le64(pb, 0); /* ??? */ es_pos = url_ftell(pb); put_le32(pb, extra_size); /* wav header len */ put_le32(pb, extra_size2); /* additional data len */ put_le16(pb, n + 1); /* stream number */ put_le32(pb, 0); /* ??? */ if (enc->codec_type == CODEC_TYPE_AUDIO) { /* WAVEFORMATEX header */ int wavsize = put_wav_header(pb, enc); if ((enc->codec_id != CODEC_ID_MP3) && (enc->codec_id != CODEC_ID_MP2) && (enc->codec_id != CODEC_ID_ADPCM_IMA_WAV) && (enc->extradata_size==0)) { wavsize += 2; put_le16(pb, 0); } if (wavsize < 0) return -1; if (wavsize != extra_size) { cur_pos = url_ftell(pb); url_fseek(pb, es_pos, SEEK_SET); put_le32(pb, wavsize); /* wav header len */ url_fseek(pb, cur_pos, SEEK_SET); } /* ERROR Correction */ put_byte(pb, 0x01); if(enc->codec_id == CODEC_ID_ADPCM_G726 || !enc->block_align){ put_le16(pb, 0x0190); put_le16(pb, 0x0190); }else{ put_le16(pb, enc->block_align); put_le16(pb, enc->block_align); } put_le16(pb, 0x01); put_byte(pb, 0x00); } else { put_le32(pb, enc->width); put_le32(pb, enc->height); put_byte(pb, 2); /* ??? */ put_le16(pb, 40 + enc->extradata_size); /* size */ /* BITMAPINFOHEADER header */ put_bmp_header(pb, enc, codec_bmp_tags, 1); } end_header(pb, hpos); } /* media comments */ hpos = put_header(pb, &ff_asf_codec_comment_header); put_guid(pb, &ff_asf_codec_comment1_header); put_le32(pb, s->nb_streams); for(n=0;n<s->nb_streams;n++) { AVCodec *p; enc = s->streams[n]->codec; p = avcodec_find_encoder(enc->codec_id); if(enc->codec_type == CODEC_TYPE_AUDIO) put_le16(pb, 2); else if(enc->codec_type == CODEC_TYPE_VIDEO) put_le16(pb, 1); else put_le16(pb, -1); if(enc->codec_id == CODEC_ID_WMAV2) put_str16(pb, "Windows Media Audio V8"); else put_str16(pb, p ? p->name : enc->codec_name); put_le16(pb, 0); /* no parameters */ /* id */ if (enc->codec_type == CODEC_TYPE_AUDIO) { put_le16(pb, 2); put_le16(pb, enc->codec_tag); } else { put_le16(pb, 4); put_le32(pb, enc->codec_tag); } if(!enc->codec_tag) return -1; } end_header(pb, hpos); /* patch the header size fields */ cur_pos = url_ftell(pb); header_size = cur_pos - header_offset; if (asf->is_streamed) { header_size += 8 + 30 + 50; url_fseek(pb, header_offset - 10 - 30, SEEK_SET); put_le16(pb, header_size); url_fseek(pb, header_offset - 2 - 30, SEEK_SET); put_le16(pb, header_size); header_size -= 8 + 30 + 50; } header_size += 24 + 6; url_fseek(pb, header_offset - 14, SEEK_SET); put_le64(pb, header_size); url_fseek(pb, cur_pos, SEEK_SET); /* movie chunk, followed by packets of packet_size */ asf->data_offset = cur_pos; put_guid(pb, &ff_asf_data_header); put_le64(pb, data_chunk_size); put_guid(pb, &ff_asf_my_guid); put_le64(pb, asf->nb_packets); /* nb packets */ put_byte(pb, 1); /* ??? */ put_byte(pb, 1); /* ??? */ return 0; }
PRIVATE void put_short P1 (const EXPR *, ep) { put_header (wordgen, alignment_of_type (tp_short)); putconst (ep); outcol += 10; }
PRIVATE void put_char P1 (const EXPR *, ep) { put_header (bytegen, alignment_of_type (tp_char)); putconst (ep); outcol += 10; }
/* * Main */ int main(int argc, char **argv) { FILE *libfp, *tmpfp, *modfp = NULL; struct stat finfo; struct rdlm_hdr hdr; char buf[MAXMODNAMELEN], *p = NULL; char c; int i; progname = argv[0]; _argv = argv; if (argc < 2) { usage(); exit(1); } /* Check whether some modifiers were specified */ for (i = 1; i < strlen(argv[1]); i++) { switch (c = argv[1][i]) { case 'c': options.createok = true; break; case 'f': options.usefname = true; break; case 'l': options.align = true; break; case 'o': options.odate = true; break; case 'u': options.fresh = true; break; case 'v': options.verbose++; break; case 'V': show_version(); exit(0); default: if (strchr(commands, c) == NULL) error_exit(2, false, "invalid command or modifier '%c'", c); } } if (argc < 3) error_exit(2, false, "missing library name"); /* Process the command */ if (argv[1][0] == '-') argv[1]++; switch (c = argv[1][0]) { case 'a': /* add a module */ if (argc < 4 || (!options.usefname && argc != 5)) error_exit(2, false, "invalid number of arguments"); /* Check if a library already exists. If not - create it */ if (access(argv[2], F_OK) < 0) { if (!options.createok) fprintf(stderr, "creating library %s\n", argv[2]); create_library(argv[2]); } libfp = fopen(argv[2], "ab"); if (!libfp) error_exit(1, true, "could not open '%s'", argv[2]); if (!options.usefname) add_module(libfp, argv[4], argv[3]); else for (i = 3; i < argc; i++) add_module(libfp, argv[i], argv[i]); fclose(libfp); break; case 'n': /* create library */ create_library(argv[2]); break; case 'x': /* extract module(s) */ if (!options.usefname) argc--; if (argc < 4) error_exit(2, false, "required parameter missing"); p = options.usefname ? argv[3] : argv[4]; case 't': /* list library contents */ libfp = fopen(argv[2], "rb"); if (!libfp) error_exit(1, true, "could not open '%s'\n", argv[2]); /* Read library header */ if (fread(&hdr, 1, sizeof(hdr), libfp) != sizeof(hdr) || hdr.magic != RDLAMAG) error_exit(1, false, "invalid library format"); /* Walk through the library looking for requested module */ while (!feof(libfp)) { /* Read module header */ i = fread(&hdr, 1, sizeof(hdr), libfp); if (feof(libfp)) break; if (i != sizeof(hdr) || hdr.magic != RDLMMAG) error_exit(1, false, "invalid module header"); /* Read module name */ i = hdr.hdrsize - sizeof(hdr); if (i > sizeof(buf) || fread(buf, 1, i, libfp) != i) error_exit(1, false, "invalid module name"); if (c == 'x') { /* Check against desired name */ if (!strcmp(buf, argv[3])) { if (options.verbose) fprintf(stderr, "extracting module %s to file %s\n", buf, p); modfp = fopen(p, "wb"); if (!modfp) error_exit(1, true, "could not open '%s'", p); } } else { printf("%-40s ", buf); if (options.verbose) { printf("%ld bytes", hdr.size); } putchar('\n'); } copybytes(libfp, modfp, hdr.size); if (modfp) break; } fclose(libfp); if (modfp) fclose(modfp); else if (c == 'x') error_exit(1, false, "module '%s' not found in '%s'", argv[3], argv[2]); break; case 'r': /* replace module(s) */ argc--; if (stat(argv[4], &finfo) < 0) error_exit(1, true, "could not stat '%s'", argv[4]); case 'd': /* delete module(s) */ if (argc < 4) error_exit(2, false, "required parameter missing"); libfp = fopen(argv[2], "rb"); if (!libfp) error_exit(1, true, "could not open '%s'", argv[2]); /* Copy the library into a temporary file */ tmpfp = tmpfile(); if (!tmpfp) error_exit(1, true, "could not open temporary file"); stat(argv[2], &finfo); copybytes(libfp, tmpfp, finfo.st_size); rewind(tmpfp); freopen(argv[2], "wb", libfp); /* Read library header and write it to a new file */ if (fread(&hdr, 1, sizeof(hdr), tmpfp) != sizeof(hdr) || hdr.magic != RDLAMAG) error_exit(1, false, "invalid library format"); put_header(&hdr, libfp, NULL); /* Walk through the library looking for requested module */ while (!feof(tmpfp)) { /* Read module header */ if (fread(&hdr, 1, sizeof(hdr), tmpfp) != sizeof(hdr) || hdr.magic != RDLMMAG) error_exit(1, false, "invalid module header"); /* Read module name */ i = hdr.hdrsize - sizeof(hdr); if (i > sizeof(buf) || fread(buf, 1, i, tmpfp) != i) error_exit(1, false, "invalid module name"); /* Check against desired name */ if (!strcmp(buf, argv[3]) && (c == 'd' || !options.odate || finfo.st_mtime <= hdr.date)) { if (options.verbose) fprintf(stderr, "deleting module %s\n", buf); fseek(tmpfp, hdr.size, SEEK_CUR); break; } else { put_header(&hdr, libfp, buf); copybytes(tmpfp, libfp, hdr.size); } } if (c == 'r') { /* Copy new module into library */ p = options.usefname ? argv[4] : argv[3]; add_module(libfp, argv[4], p); } /* Copy rest of library if any */ while (!feof(tmpfp)) { if ((i = fgetc(tmpfp)) == EOF) break; if (fputc(i, libfp) == EOF) error_exit(1, false, "write error"); } fclose(libfp); fclose(tmpfp); break; default: error_exit(2, false, "invalid command '%c'\n", c); } return 0; }
/* put sequence header if needed */ static void mpeg1_encode_sequence_header(MpegEncContext *s) { unsigned int vbv_buffer_size; unsigned int fps, v; int i; uint64_t time_code; float best_aspect_error= 1E10; float aspect_ratio= av_q2d(s->avctx->sample_aspect_ratio); int constraint_parameter_flag; if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA) if (s->current_picture.f.key_frame) { AVRational framerate= avpriv_frame_rate_tab[s->frame_rate_index]; /* mpeg1 header repeated every gop */ put_header(s, SEQ_START_CODE); put_sbits(&s->pb, 12, s->width ); put_sbits(&s->pb, 12, s->height); for(i=1; i<15; i++){ float error= aspect_ratio; if(s->codec_id == CODEC_ID_MPEG1VIDEO || i <=1) error-= 1.0/ff_mpeg1_aspect[i]; else error-= av_q2d(ff_mpeg2_aspect[i])*s->height/s->width; error= FFABS(error); if(error < best_aspect_error){ best_aspect_error= error; s->aspect_ratio_info= i; } } put_bits(&s->pb, 4, s->aspect_ratio_info); put_bits(&s->pb, 4, s->frame_rate_index); if(s->avctx->rc_max_rate){ v = (s->avctx->rc_max_rate + 399) / 400; if (v > 0x3ffff && s->codec_id == CODEC_ID_MPEG1VIDEO) v = 0x3ffff; }else{ v= 0x3FFFF; } if(s->avctx->rc_buffer_size) vbv_buffer_size = s->avctx->rc_buffer_size; else /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */ vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024; vbv_buffer_size= (vbv_buffer_size + 16383) / 16384; put_sbits(&s->pb, 18, v); put_bits(&s->pb, 1, 1); /* marker */ put_sbits(&s->pb, 10, vbv_buffer_size); constraint_parameter_flag= s->width <= 768 && s->height <= 576 && s->mb_width * s->mb_height <= 396 && s->mb_width * s->mb_height * framerate.num <= framerate.den*396*25 && framerate.num <= framerate.den*30 && s->avctx->me_range && s->avctx->me_range < 128 && vbv_buffer_size <= 20 && v <= 1856000/400 && s->codec_id == CODEC_ID_MPEG1VIDEO; put_bits(&s->pb, 1, constraint_parameter_flag); ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix); ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); if(s->codec_id == CODEC_ID_MPEG2VIDEO){ put_header(s, EXT_START_CODE); put_bits(&s->pb, 4, 1); //seq ext put_bits(&s->pb, 1, s->avctx->profile == 0); //escx 1 for 4:2:2 profile */ put_bits(&s->pb, 3, s->avctx->profile); //profile put_bits(&s->pb, 4, s->avctx->level); //level put_bits(&s->pb, 1, s->progressive_sequence); put_bits(&s->pb, 2, s->chroma_format); put_bits(&s->pb, 2, s->width >>12); put_bits(&s->pb, 2, s->height>>12); put_bits(&s->pb, 12, v>>18); //bitrate ext put_bits(&s->pb, 1, 1); //marker put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext put_bits(&s->pb, 1, s->low_delay); put_bits(&s->pb, 2, 0); // frame_rate_ext_n put_bits(&s->pb, 5, 0); // frame_rate_ext_d }
PRIVATE void put_dword P1 (UVAL, val) { put_header (longgen, alignment_of_type (tp_long)); oprintf ("0x%lx", val); outcol += 10; }