--- trunk/xvidcore/examples/odivx_enc_dec.c 2002/03/08 02:46:11 3 +++ trunk/xvidcore/examples/odivx_enc_dec.c 2002/11/27 21:09:10 684 @@ -41,25 +41,24 @@ #include #include -#include "encore2.h" -#include "decore.h" /* these come with XviD */ +#include "divx4.h" #define ARG_FRAMERATE 25 #define ARG_BITRATE 900 int QUALITY =5; -int QUANTI = 0; // used for fixed-quantizer encoding +int QUANTI = 0; /* used for fixed-quantizer encoding */ int XDIM=0; -int YDIM=0; // will be set when reading first image +int YDIM=0; /* will be set when reading first image */ int filenr = 0; -int save_m4v_flag = 0; // save MPEG4-bytestream? -int save_dec_flag = 0; // save decompressed bytestream? -char filepath[256] = "."; // path where to save +int save_m4v_flag = 0; /* save MPEG4-bytestream? */ +int save_dec_flag = 0; /* save decompressed bytestream? */ +char filepath[256] = "."; /* path where to save */ -void *enchandle = NULL; // enchandle is a void*, written by encore -const long dechandle = 0x0815; // dechandle is a unique constant!!! +void *enchandle = NULL; /* enchandle is a void*, written by encore */ +const long dechandle = 0x0815; /* dechandle is a unique constant!!! */ /*********************************************************************/ /* Routines for file input/output, nothing specific to XviD */ @@ -103,7 +102,7 @@ fread(buff1_ptr3,XDIM/2,1,stdin); buff1_ptr3 += XDIM/2; } - fread(&dummy,1,1,handle); // should be EOF + fread(&dummy,1,1,handle); /* should be EOF */ return 0; } @@ -120,7 +119,7 @@ enc_param.x_dim = XDIM; enc_param.y_dim = YDIM; - enc_param.framerate = ARG_FRAMERATE; // a float + enc_param.framerate = ARG_FRAMERATE; /* a float */ enc_param.bitrate = ARG_BITRATE*1000; enc_param.rc_period = 2000; @@ -132,17 +131,17 @@ enc_param.quality = QUALITY; - enc_param.use_bidirect = 0; // use bidirectional coding - enc_param.deinterlace = 0; // fast deinterlace - enc_param.obmc = 0; // flag to enable overlapped block motion compensation mode + enc_param.use_bidirect = 0; /* use bidirectional coding */ + enc_param.deinterlace = 0; /* fast deinterlace */ + enc_param.obmc = 0; /* flag to enable overlapped block motion compensation mode */ enc_param.max_key_interval = (int)ARG_FRAMERATE*10; - enc_param.handle = NULL; //will be filled by encore + enc_param.handle = NULL; /*will be filled by encore */ status = encore(enchandle, ENC_OPT_INIT, &enc_param, NULL); enchandle = enc_param.handle; -// if (status) +/* if (status) */ printf("Encore INIT return %d, handle=%lx\n", status, enchandle); return status; @@ -152,7 +151,7 @@ { int status; status = encore(enchandle, ENC_OPT_RELEASE, NULL, NULL); -// if (status) +/* if (status) */ printf("Encore RELEASE return %d\n", status); return status; @@ -166,9 +165,9 @@ enc_frame.image = (void *) image; enc_frame.bitstream = (void *) bitstream; - enc_frame.length = 0; // filled by encore - enc_frame.colorspace = ENC_CSP_YV12; // input is YUV - enc_frame.mvs = NULL; // unsupported + enc_frame.length = 0; /* filled by encore */ + enc_frame.colorspace = ENC_CSP_YV12; /* input is YUV */ + enc_frame.mvs = NULL; /* unsupported */ if (QUANTI==0) { @@ -176,7 +175,7 @@ } else { enc_frame.quant = QUANTI; - enc_frame.intra = -1; // let encoder decide if frame is INTER/INTRA + enc_frame.intra = -1; /* let encoder decide if frame is INTER/INTRA */ status = encore(enchandle, ENC_OPT_ENCODE_VBR, &enc_frame, &enc_result); } @@ -199,19 +198,18 @@ int status; DEC_PARAM dec_param; - DEC_SET dec_set; dec_param.x_dim = XDIM; dec_param.y_dim = YDIM; - dec_param.output_format = DEC_RGB24; // output color format, , see + dec_param.output_format = DEC_RGB24; /* output color format, , see */ dec_param.time_incr = 20; status = decore(dechandle, DEC_OPT_INIT, &dec_param, NULL); -// if (status) +/* if (status) */ printf("Decore INIT return %d\n", status); -// We don't do any postprocessing here... +/* We don't do any postprocessing here... */ /* dec_set.postproc_level = 0; status = decore(dechandle, DEC_OPT_SETPP, &dec_set, NULL); @@ -232,7 +230,7 @@ dec_frame.length = m4v_size; dec_frame.bitstream = m4v_buffer; dec_frame.bmp = rgb_buffer; - dec_frame.render_flag = 1; // 0 means: skip this frame + dec_frame.render_flag = 1; /* 0 means: skip this frame */ dec_frame.stride = XDIM; status = decore(dechandle, DEC_OPT_FRAME, &dec_frame, &dec_frame_info); @@ -246,7 +244,7 @@ { int status; status = decore(dechandle, DEC_OPT_RELEASE, NULL, NULL); -// if (status) +/* if (status) */ printf("Decore RELEASE return %d\n", status); return status; } @@ -263,7 +261,6 @@ unsigned char *rgb_buffer = NULL; int status; - int frame_size; int m4v_size; char filename[256]; @@ -280,27 +277,27 @@ /* now we know the sizes, so allocate memory */ yuv_buffer = (unsigned char *) malloc(XDIM*YDIM); if (!yuv_buffer) - goto free_all_memory; // goto is one of the most underestimated instructions in C !!! - divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2); // this should really be enough! + goto free_all_memory; /* goto is one of the most underestimated instructions in C !!! */ + divx_buffer = (unsigned char *) malloc(XDIM*YDIM*2); /* this should really be enough! */ if (!divx_buffer) - goto free_all_memory; // actually, every program should contain a goto + goto free_all_memory; /* actually, every program should contain a goto */ - YDIM = YDIM*2/3; // PGM is YUV 4:2:0 format, so height is *3/2 too much + YDIM = YDIM*2/3; /* PGM is YUV 4:2:0 format, so height is *3/2 too much */ rgb_buffer = (unsigned char *) malloc(XDIM*YDIM*4); if (!rgb_buffer) - goto free_all_memory; // the more, the better! + goto free_all_memory; /* the more, the better! */ /*********************************************************************/ /* DIVX PART Start */ /*********************************************************************/ status = enc_init(); -// if (status) +/* if (status) */ printf("Encore INIT return %d, handle=%lx\n", status, enchandle); status = dec_init(); -// if (status) +/* if (status) */ printf("Decore INIT return %d\n", status); @@ -310,7 +307,7 @@ do { - status = read_pgmdata(stdin, yuv_buffer); // read PGM data (YUV-format) + status = read_pgmdata(stdin, yuv_buffer); /* read PGM data (YUV-format) */ if (status) { fprintf(stderr, "PGM-Data-Error: %d\n", status); /* this should not happen */ @@ -344,7 +341,7 @@ filehandle=fopen(filename,"wb"); if (filehandle) { - fprintf(filehandle,"P6\n"); // rgb24 in PPM format + fprintf(filehandle,"P6\n"); /* rgb24 in PPM format */ fprintf(filehandle,"%d %d 255\n",XDIM,YDIM); fwrite(rgb_buffer,XDIM,YDIM*3,filehandle); fclose(filehandle); @@ -352,7 +349,7 @@ } filenr++; - status = read_pgmheader(stdin); // if it was the last PGM, stop after it + status = read_pgmheader(stdin); /* if it was the last PGM, stop after it */ if (status) { fprintf(stderr, "PGM-Header-Error: %d\n", status); /* normally, just end of file */ @@ -369,11 +366,11 @@ /* Stop XviD */ dec_stop(); -// if (status) +/* if (status) */ printf("Encore RELEASE return %d\n", status); enc_stop(); -// if (status) +/* if (status) */ printf("Decore RELEASE return %d\n", status); free_all_memory: