*
*/
-#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <fcntl.h>
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[]));
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 <stdarg.h>
+
+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)
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;
/* 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);
if(base.Infile != 0)
{
- Initialize_Buffer();
-
+ Initialize_Buffer();
+
if(Show_Bits(8)==0x47)
{
sprintf(Error_Text,"Decoder currently does not parse transport streams\n");
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);
/*close(enhan.Infile);*/
ld->close_stream(enhan.Infile);
+ DeInitialize_Decoder();
+
return ret;
}
+#endif /*GDCM_BUILD_MPEG2DEC*/
/* IMPLEMENTATION specific routines */
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;
}
void Error(text)
-char *text;
+const char *text;
{
fprintf(stderr,text);
exit(1);
" -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"
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);
- }
+ }
}
{
int i;
+ /* First cleanup the static buffer in store.c */
+ FreeStaticBuffer();
+
/* clear flags */
base.MPEG2_Flag=0;