]> Creatis software - gdcm.git/blobdiff - src/gdcmmpeg2/src/mpeg2dec/mpeg2dec.c
Allow user to create mutiframes
[gdcm.git] / src / gdcmmpeg2 / src / mpeg2dec / mpeg2dec.c
index ea6d164810c138eab19c098ba5154e2fae238ea4..f07432060e07bfdf73d41605bf596c0078841991 100644 (file)
@@ -42,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[]));
 
@@ -60,20 +61,34 @@ static void Print_Options();
 
 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)
 {
-  return lseek(infile, offset, whence);
+#ifdef FILESTAR
+  return fseek(infile->InFd,offset, whence);
+#else
+  return lseek(infile->InFd,offset, whence);
+#endif
 }
-ssize_t my_read(int infile,void *buf,size_t count)
+ssize_t my_read(istream *infile, void *buf, size_t count)
 {
-  return read(infile,buf,count);
+#ifdef FILESTAR
+  return fread(buf,1,count, infile->InFd);
+#else
+  return read(infile->InFd,buf,count);
+#endif
 }
-int my_close(int infile)
+
+int my_close(istream *infile)
 {
-  return close(infile);
+#ifdef FILESTAR
+  return fclose(infile->InFd);
+#else
+  return close(infile->InFd);
+#endif
 }
 
 int my_fopenr(const char *path, const char *mode, istream *os)
@@ -82,7 +97,7 @@ int my_fopenr(const char *path, const char *mode, istream *os)
   if(fd)
     {
     os->InFd = fd;
-    return 1; //success
+    return 1; /*success*/
     }
   else
     os->InFd = NULL;
@@ -95,7 +110,7 @@ int my_fopen(const char *path, const char *mode, ostream *os)
   if(fd)
     {
     os->OutFd = fd;
-    return 1; //success
+    return 1; /*success*/
     }
   else
     os->OutFd = NULL;
@@ -133,7 +148,6 @@ int my_fclose(ostream *fp)
 
 int my_printf(const char *format, ...)
 {
-  //return printf(format, ...);
   va_list argptr;
   int ret;
 
@@ -146,7 +160,6 @@ int my_printf(const char *format, ...)
 
 int my_sprintf(char *str, const char *format, ...)
 {
-  //return sprintf(str, format, ...);
   va_list argptr;
   int ret;
 
@@ -159,7 +172,6 @@ int my_sprintf(char *str, const char *format, ...)
 
 int my_fprintf(const char *format, ...)
 {
-  //return fprintf(stderr, format, ...);
   va_list argptr;
   int ret;
 
@@ -183,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;
@@ -202,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);
@@ -212,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");
@@ -256,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);
@@ -280,6 +305,8 @@ char *argv[];
     /*close(enhan.Infile);*/
     ld->close_stream(enhan.Infile);
 
+  DeInitialize_Decoder();
+
   return ret;
 }
 #endif /*GDCM_BUILD_MPEG2DEC*/
@@ -306,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;
@@ -395,7 +427,7 @@ static void Initialize_Sequence()
 }
 
 void Error(text)
-char *text;
+const char *text;
 {
   fprintf(stderr,text);
   exit(1);
@@ -430,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"
@@ -738,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);
-  }
+    }
 
 }
 
@@ -761,6 +793,9 @@ static void Deinitialize_Sequence()
 {
   int i;
 
+  /* First cleanup the static buffer in store.c */
+  FreeStaticBuffer();
+
   /* clear flags */
   base.MPEG2_Flag=0;