[XviD-devel] Fw: Fw: libxvidcore decompression

Stephan Assmus superstippi at gmx.de
Fri Apr 25 10:18:27 CEST 2008


reno reballos wrote:
> Hi Master Stephan,
> 
> thank you for the the reply... i had double check and scrutinized 
> everything in my code specially when it comes to initialization of 
> decoder and the main decoder itself, i will share to you my code hope 
> you'll fine a time for this.... and here is exactly what i do... yes, you 
> are free to give any comment with my code:

your main decoding loop is very weird and you do not at all follow what I 
have told you in all my earlier mails. Where do you check the output type?


> //======== main application file routine===============// FILE *fpi = 
> NULL;<-- input file
> FILE *fpo = NULL;<-- output file
> 
>  unsigned char *mp4_buffer = NULL;
> unsigned char *dec_output_buffer = NULL;
> mp4_buffer = (unsigned char*)malloc(1024*1024*2);
> dec_output_buffer = (unsigned char *)malloc(352*240*4);<---this should be 
> enough for the res. of 352*240
> 
> static void *dec_handle = NULL;<--decoder handle
> int useful_bytes = 0;
> int used_bytes = 0;
> 
> 
>     useful_bytes = fread(mp4_buffer, sizeof(unsigned int), 1024, fpi);
> 
>     xvid_dec_stats_t dec_stats;
>     memset(&dec_stats,0, sizeof(xvid_dec_stats_t));
>     dec_stats.version = XVID_VERSION;
> 
>     do{
>     
>         //reading 5008*4 bytes from the file(fpi)
>         useful_bytes = fread(gmp4_buffer, sizeof(unsigned int), 
>         5008,fpi);//65536,5008,2048, 262144reading 1MB 
> 
>         do{
>                 //decode until dec_outBuf got data
>             used_bytes = dec_decode(gmp4_buffer, dec_outBuf, 
>             useful_bytes,&dec_stats);<--in here itself no decoder output 
>             from dec_outBuf...
>         }while(sizeof(dec_outBuf==0));

sizeof(dec_outBuf)==0 ?!?

I would surely hope that your output buffer is not of size 0. Furthermore, 
since this is probably a pointer, sizeof(dec_outBuf) should return 4 on a 
32 bit system *always*. So this loop will only run once, since the 
condition to continue is always false. I told you to check the type 
(dec_stats.type > XVID_TYPE_NOTHING) to see if you have got a frame.

> 
>         sprintf(FileNames, "%sdec%05d.pgm", FilePath, totalframe); fpo = 
>         fopen(FileNames, "w+b");
>         
>         width = dec_stats.data.vol.width;
>         height = dec_stats.data.vol.height;
> 
>         writedata = 
>         fwrite(dec_outBuf,1,width*height*3/2,fpo);//used_bytes 
>         fclose(fpo);
>         totalframe++;
> 
>     }while(useful_bytes>1 || !feof(fpi) || used_bytes==0);
> 
> --------------------------------------------------------------------------

[...]

> -----------------------------------
> 
> //============ decoder main routine ============================= int 
> dec_decode(unsigned char *dec_inputstream, unsigned char 
> *dec_outputstream, int data_length, xvid_dec_stats_t *dec_stats) {
> 
>     int retVal_DEC_decode = NULL;
>      xvid_dec_frame_t dec_frame;
>     memset(&dec_frame,0, sizeof(xvid_dec_frame_t));
>     dec_frame.version = XVID_VERSION;
>     dec_frame.general = 0;
>     dec_frame.bitstream = dec_inputstream;<-- decoder input stream 
>     dec_frame.length = data_length;<-- data length 
>     dec_frame.output.plane[0] = dec_outputstream;<---decoder output 
>     stream dec_stats->type = XVID_TYPE_AUTO;
> 
>     retVal_DEC_decode = xvid_decore(dec_handle, XVID_DEC_DECODE, 
>     &dec_frame,dec_stats); /*note: error checking is removed...*/
>     ...
>     ..
>     .
>     dec_frame.output.stride[0] = (dec_stats->data.vol.width)*3; 
>     dec_frame.output.csp = XVID_CSP_BGR;

Why do you specify stuff after the call to xvid_decore? Any setup needs to 
be done before.

Reno, I don't want to hurt your feelings, but I would strongly suggest you 
start from scratch from the xvid decode example. Take that working example 
and replace the routines that save TGA images to display them on screen 
instead.

To me, it seems like you are not very firm with pointers and memory 
buffers. You should probably read up on that somewhere, just google around 
a bit. Also google for what the sizeof() operator does exactly.

Best regards,
-Stephan




More information about the XviD-devel mailing list