X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2Fgdcmmpeg2%2Fsrc%2Fmpeg2dec%2Fmpeg2dec.c;h=dbfe0f3f25cddabe7b122fa4550de87480d948dd;hb=80a0be0291e7d8760528d89b2fb0a9dcd6d40cb9;hp=09a4ae27cf80fa646f5bba04db445eb56306be73;hpb=dd35c0318900832186867bbe852d56ab58bb3f70;p=gdcm.git diff --git a/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c b/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c index 09a4ae27..dbfe0f3f 100644 --- a/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c +++ b/src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c @@ -28,11 +28,9 @@ * */ -#include #include #include #include -#include // for lseek #define GLOBAL #include "config.h" @@ -40,10 +38,11 @@ /* private prototypes */ static int video_sequence _ANSI_ARGS_((int *framenum)); -static int Decode_Bitstream _ANSI_ARGS_((void)); +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[])); @@ -59,11 +58,136 @@ static void Clear_Options(); static void Print_Options(); #endif + +int my_open(char *filename) +{ + return open(filename,O_RDONLY|O_BINARY); +} + +off_t my_seek(int infile, off_t offset,int whence) +{ + return lseek(infile, offset, whence); +} +ssize_t my_read(int infile,void *buf,size_t count) +{ + return read(infile,buf,count); +} +int my_close(int infile) +{ + return close(infile); +} + +int my_fopenr(const char *path, const char *mode, istream *os) +{ + 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, ...) +{ + //return printf(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, ...) +{ + //return sprintf(str, 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, ...) +{ + //return fprintf(stderr, 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) int argc; char *argv[]; { int ret, code; + base.open_stream = my_open; + base.seek_stream = my_seek; + base.read_stream = my_read; + base.close_stream = my_close; Clear_Options(); @@ -78,7 +202,9 @@ 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) +/* if ((base.Infile=open(Main_Bitstream_Filename,O_RDONLY|O_BINARY))<0) */ + base.Infile = ld->open_stream(Main_Bitstream_Filename); + if( base.Infile < 0 ) { fprintf(stderr,"Base layer input file %s not found\n", Main_Bitstream_Filename); exit(1); @@ -113,13 +239,15 @@ char *argv[]; break; } - lseek(base.Infile, 0l, 0); + /*lseek(base.Infile, 0l, SEEK_SET);*/ + ld->seek_stream(base.Infile,0l,SEEK_SET); Initialize_Buffer(); } if(base.Infile!=0) { - lseek(base.Infile, 0l, 0); + /*lseek(base.Infile, 0l, SEEK_SET);*/ + ld->seek_stream(base.Infile,0l,SEEK_SET); } Initialize_Buffer(); @@ -128,7 +256,9 @@ char *argv[]; { ld = &enhan; /* select enhancement layer context */ - if ((enhan.Infile = open(Enhancement_Layer_Bitstream_Filename,O_RDONLY|O_BINARY))<0) + /*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) { sprintf(Error_Text,"enhancment layer bitstream file %s not found\n", Enhancement_Layer_Bitstream_Filename); @@ -144,15 +274,20 @@ char *argv[]; ret = Decode_Bitstream(); - close(base.Infile); + /*close(base.Infile);*/ + ld->close_stream(base.Infile); if (Two_Streams) - close(enhan.Infile); + /*close(enhan.Infile);*/ + ld->close_stream(enhan.Infile); - return 0; + DeInitialize_Decoder(); + + return ret; } +#endif /*GDCM_BUILD_MPEG2DEC*/ -/* IMPLEMENTAION specific rouintes */ +/* IMPLEMENTATION specific routines */ static void Initialize_Decoder() { int i; @@ -174,6 +309,11 @@ static void Initialize_Decoder() } +static void DeInitialize_Decoder() +{ + free(Clip-384); // WTF !!! +} + /* mostly IMPLEMENTAION specific rouintes */ static void Initialize_Sequence() { @@ -291,27 +431,27 @@ char *argv[]; /* argument vector */ if (argc<2) { printf("\n%s, %s\n",Version,Author); - printf("Usage: mpeg2decode {options}\n\ -Options: -b file main bitstream (base or spatial enhancement layer)\n\ - -cn file conformance report (n: level)\n\ - -e file enhancement layer bitstream (SNR or Data Partitioning)\n\ - -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\ - -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\ - 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\ - \n"); + printf("Usage: mpeg2decode {options}\n" +"Options: -b file main bitstream (base or spatial enhancement layer)\n" +" -cn file conformance report (n: level)\n" +" -e file enhancement layer bitstream (SNR or Data Partitioning)\n" +" -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" +" -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" +" 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" +" \n"); exit(0); } @@ -629,6 +769,9 @@ static void Deinitialize_Sequence() { int i; + /* First clenup the static buffer in store.c */ + FreeStaticBuffer(); + /* clear flags */ base.MPEG2_Flag=0; @@ -764,3 +907,4 @@ static void Print_Options() } #endif +