X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2Fgdcmmpeg2%2Fsrc%2Fmpeg2dec%2Fmpeg2dec.c;h=f07432060e07bfdf73d41605bf596c0078841991;hb=98cf38e32be18dc2b7d3d1a13e45f60717b008bc;hp=f5f7dc43f1740c6cc6b6a171865bf0ad561ea960;hpb=a2dc7f14b6bab4d1c55bc7621efa74bf8d3f7681;p=gdcm.git diff --git a/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c b/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c index f5f7dc43..f0743206 100644 --- a/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c +++ b/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c @@ -28,7 +28,6 @@ * */ -#include #include #include #include @@ -43,6 +42,7 @@ static int Decode_Bitstream _ANSI_ARGS_((void)); static int Headers _ANSI_ARGS_((void)); static void Initialize_Sequence _ANSI_ARGS_((void)); static void Initialize_Decoder _ANSI_ARGS_((void)); +static void DeInitialize_Decoder _ANSI_ARGS_((void)); static void Deinitialize_Sequence _ANSI_ARGS_((void)); static void Process_Options _ANSI_ARGS_((int argc, char *argv[])); @@ -58,24 +58,136 @@ static void Clear_Options(); static void Print_Options(); #endif + int my_open(char *filename) { + abort(); return open(filename,O_RDONLY|O_BINARY); } -off_t my_seek(int infile, off_t offset,int whence) + +off_t my_seek(istream *infile, off_t offset, int whence) +{ +#ifdef FILESTAR + return fseek(infile->InFd,offset, whence); +#else + return lseek(infile->InFd,offset, whence); +#endif +} +ssize_t my_read(istream *infile, void *buf, size_t count) { - return lseek(infile, offset, whence); +#ifdef FILESTAR + return fread(buf,1,count, infile->InFd); +#else + return read(infile->InFd,buf,count); +#endif } -ssize_t my_read(int infile,void *buf,size_t count) + +int my_close(istream *infile) { - return read(infile,buf,count); +#ifdef FILESTAR + return fclose(infile->InFd); +#else + return close(infile->InFd); +#endif } -int my_close(int infile) + +int my_fopenr(const char *path, const char *mode, istream *os) { - return close(infile); + FILE *fd = fopen(path, mode); + if(fd) + { + os->InFd = fd; + return 1; /*success*/ + } + else + os->InFd = NULL; + return 0; } +int my_fopen(const char *path, const char *mode, ostream *os) +{ + FILE *fd = fopen(path, mode); + if(fd) + { + os->OutFd = fd; + return 1; /*success*/ + } + else + os->OutFd = NULL; + return 0; +} +int my_fseek(ostream *stream, long offset, int whence) +{ + return fseek(stream->OutFd, offset, whence); +} +int my_fseekr(istream *stream, long offset, int whence) +{ + return fseek(stream->InFd, offset, whence); +} + +size_t my_fread(void *ptr, size_t size, size_t nmemb, istream *stream) +{ + return fread(ptr, size, nmemb, stream->InFd); +} + +size_t my_fwrite(const void *ptr, size_t size, size_t nmemb, ostream *stream) +{ + return fwrite(ptr, size, nmemb, stream->OutFd); +} + +int my_fcloser(istream *fp) +{ + return fclose(fp->InFd); +} +int my_fclose(ostream *fp) +{ + return fclose(fp->OutFd); +} +#include + +int my_printf(const char *format, ...) +{ + va_list argptr; + int ret; + + va_start(argptr, format); + ret = vprintf(format, argptr); + va_end(argptr); + + return ret; +} + +int my_sprintf(char *str, const char *format, ...) +{ + va_list argptr; + int ret; + + va_start(argptr, format); + ret = vsprintf(str,format, argptr); + va_end(argptr); + + return ret; +} + +int my_fprintf(const char *format, ...) +{ + va_list argptr; + int ret; + + va_start(argptr, format); + ret = vfprintf(stderr,format, argptr); + va_end(argptr); + + return ret; +} +void my_exit(int status) +{ + exit(status); +} + + +#define GDCM_BUILD_MPEG2DEC #ifdef GDCM_BUILD_MPEG2DEC int main(argc,argv) @@ -83,7 +195,8 @@ int argc; char *argv[]; { int ret, code; - base.open_stream = my_open; + istream bos,eos; + /*base.open_stream = my_open;*/ base.seek_stream = my_seek; base.read_stream = my_read; base.close_stream = my_close; @@ -102,8 +215,14 @@ char *argv[]; /* open MPEG base layer bitstream file(s) */ /* NOTE: this is either a base layer stream or a spatial enhancement stream */ /* if ((base.Infile=open(Main_Bitstream_Filename,O_RDONLY|O_BINARY))<0) */ - base.Infile = ld->open_stream(Main_Bitstream_Filename); - if( base.Infile < 0 ) + /*base.Infile = ld->open_stream(Main_Bitstream_Filename);*/ + base.Infile = &bos; +#ifdef FILESTAR + base.Infile->InFd = fopen(Main_Bitstream_Filename, "rb"); +#else + base.Infile->InFd = open(Main_Bitstream_Filename,O_RDONLY|O_BINARY ); +#endif + if( !base.Infile->InFd) { fprintf(stderr,"Base layer input file %s not found\n", Main_Bitstream_Filename); exit(1); @@ -112,8 +231,8 @@ char *argv[]; if(base.Infile != 0) { - Initialize_Buffer(); - + Initialize_Buffer(); + if(Show_Bits(8)==0x47) { sprintf(Error_Text,"Decoder currently does not parse transport streams\n"); @@ -156,8 +275,14 @@ char *argv[]; ld = &enhan; /* select enhancement layer context */ /*if ((enhan.Infile = open(Enhancement_Layer_Bitstream_Filename,O_RDONLY|O_BINARY))<0)*/ - enhan.Infile = ld->open_stream(Enhancement_Layer_Bitstream_Filename); - if (enhan.Infile<0) + /*enhan.Infile = ld->open_stream(Enhancement_Layer_Bitstream_Filename);*/ + enhan.Infile = &eos; +#ifdef FILESTAR + enhan.Infile->InFd = fopen(Main_Bitstream_Filename, "rb"); +#else + enhan.Infile->InFd = open(Enhancement_Layer_Bitstream_Filename,O_RDONLY|O_BINARY); +#endif + if (enhan.Infile->InFd) { sprintf(Error_Text,"enhancment layer bitstream file %s not found\n", Enhancement_Layer_Bitstream_Filename); @@ -180,6 +305,8 @@ char *argv[]; /*close(enhan.Infile);*/ ld->close_stream(enhan.Infile); + DeInitialize_Decoder(); + return ret; } #endif /*GDCM_BUILD_MPEG2DEC*/ @@ -206,7 +333,12 @@ static void Initialize_Decoder() } -/* mostly IMPLEMENTAION specific rouintes */ +static void DeInitialize_Decoder() +{ + free(Clip-384); /* I love magic number */ +} + +/* mostly IMPLEMENTAION specific routines */ static void Initialize_Sequence() { int cc, size; @@ -295,7 +427,7 @@ static void Initialize_Sequence() } void Error(text) -char *text; +const char *text; { fprintf(stderr,text); exit(1); @@ -330,16 +462,16 @@ char *argv[]; /* argument vector */ " -f store/display interlaced video in frame format\n" " -g concatenated file format for substitution method (-x)\n" " -in file information & statistics report (n: level)\n" -" -l file file name pattern for lower layer sequence\n" -" (for spatial scalability)\n" +" -l file file name pattern for lower layer sequence\n"); +printf(" (for spatial scalability)\n" " -on file output format (0:YUV 1:SIF 2:TGA 3:PPM 4:X11 5:X11HiQ)\n" " -q disable warnings to stderr\n" " -r use double precision reference IDCT\n" " -t enable low level tracing to stdout\n" " -u file print user_data to stdio or file\n" " -vn verbose output (n: level)\n" -" -x file filename pattern of picture substitution sequence\n\n" -"File patterns: for sequential filenames, \"printf\" style, e.g. rec%%d\n" +" -x file filename pattern of picture substitution sequence\n\n"); +printf("File patterns: for sequential filenames, \"printf\" style, e.g. rec%%d\n" " or rec%%d%%c for fieldwise storage\n" "Levels: 0:none 1:sequence 2:picture 3:slice 4:macroblock 5:block\n\n" "Example: mpeg2decode -b bitstream.mpg -f -r -o0 rec%%d\n" @@ -638,21 +770,21 @@ static int Decode_Bitstream() Bitstream_Framenum = 0; for(;;) - { + { #ifdef VERIFY Clear_Verify_Headers(); #endif /* VERIFY */ ret = Headers(); - + if(ret==1) - { - ret = video_sequence(&Bitstream_Framenum); - } + { + /*ret =*/ video_sequence(&Bitstream_Framenum); + } else return(ret); - } + } } @@ -661,6 +793,9 @@ static void Deinitialize_Sequence() { int i; + /* First cleanup the static buffer in store.c */ + FreeStaticBuffer(); + /* clear flags */ base.MPEG2_Flag=0;