dslinux/user/pixil/packages/dvdview/dvdview/src Makefile.in Releases config.h config.h.in demo.sh error.cc error.hh main.cc main.cc.org options.cc options.hh types.hh version.hh

amadeus dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:25:58 CEST 2006


Update of /cvsroot/dslinux/dslinux/user/pixil/packages/dvdview/dvdview/src
In directory antilope:/tmp/cvs-serv11916/packages/dvdview/dvdview/src

Added Files:
	Makefile.in Releases config.h config.h.in demo.sh error.cc 
	error.hh main.cc main.cc.org options.cc options.hh types.hh 
	version.hh 
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it

--- NEW FILE: options.cc ---

#include "options.hh"

Options options;

Options::Options()
{
  // Quality
#if 0
  options.UseOnlyOneMVOfBiPred = false;
  options.NoHalfPelInB         = false;

  // Warnings

  options.WarnOnFalseMPEG1Fields = false;


  // Output options

  options.Disable_X11Shm     = false;
#endif
  options.Postproc_ShowMBs   = false;
#if 0
  options.Postproc_ShowQ     = false;
  options.Postproc_ShowMV    = false;
  options.Postproc_ShowMVCol = false;
  options.Postproc_Mark      = false;

  options.Postproc_ShowMV_Hold = false;
  options.Postproc_ShowMV_P    = false;
  options.Postproc_ShowMV_B    = false;
  options.Postproc_ShowMVCol_ShowPhase = false;

  options.FrameWait=0;
#endif
}


--- NEW FILE: error.hh ---
/********************************************************************************
  error.hh

  purpose:
    Error handling stuff: exception handling and error message display.

  notes:

  to do:

  author(s):
   - Dirk Farin, farin at ti.uni-mannheim.de

  modifications:
   29/Sep/1999 - Dirk Farin
    - ShowMessage() can now be given a Excpt_Base argument. This allows
      the MessageDisplay to selectively enable/disable the display of
      some error classes.
   20/Sep/1999 - Dirk Farin
    - complete cleanup, ShowNote() removed
   03/Jan/1999 - Dirk Farin
    - ShowNote()
   28/Dec/1998 - Dirk Farin
    - new implementation based on exceptions
   15/Nov/1998 - Dirk Farin
    - first implementation

 ********************************************************************************
    Copyright (C) 1999  Dirk Farin

    This program is distributed under GNU Public License (GPL) as
    outlined in the COPYING file that comes with the source distribution.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ********************************************************************************/

#ifndef DVDVIEW_ERROR_HH
#define DVDVIEW_ERROR_HH

// We need: __ASSERT_FUNCTION
#  include <assert.h>


/* Severity of a message or an exception. Not all severity levels are allowed
   in exceptions. "ErrSev_Note" must not be used in exceptions as the normal
   program flow should not be interrupted in this case.
   //"ErrSev_Empty" is a dummy value that must not be used anywhere.
*/

enum ErrorSeverity {
  //ErrSev_Empty,   // Initial state of Excpt_Base after creation. Not an error level!
  ErrSev_Note,    // Things that are worth noting but that do not have any implications for execution.
  ErrSev_Warning, // Explains why some things may not be as expected and warn about things that may go wrong.
  ErrSev_Error,   // The usual stuff like "file not found".
  ErrSev_Critical,// Several unexpected errors occurred so something is going seriously wrong.
  ErrSev_Assertion,// This should never never never go wrong. Even if the input is completely damaged.
};



/* A MessageDisplay is the place where warnings and errors go.
 */

class MessageDisplay
{
public:
  virtual ~MessageDisplay() { }

  virtual void ShowMessage(ErrorSeverity,const char* text) const = 0;
  virtual void ShowMessage(const class Excpt_Base&) const = 0;


  // Message output on the standard display.

  static void Show(ErrorSeverity,const char* text);
  static void Show(const class Excpt_Base&);
  static void SetStandardDisplay(MessageDisplay*);

private:
  static const MessageDisplay* std_msgdisplay;
};






class Excpt_Base
{
public:
  Excpt_Base(ErrorSeverity);
  Excpt_Base(ErrorSeverity,const char* text);

  const static unsigned int c_MaxTextLen = 500;

  enum ErrorSeverity m_severity;
  char               m_text[c_MaxTextLen+1];
};


class Excpt_Assertion : public Excpt_Base
{
public:
  Excpt_Assertion(const char* expr,const char* file, const char* function,int line);
};

#ifdef NDEBUG
#define Assert(expr)
#else
#if defined(__ASSERT_FUNCTION) && defined(__STRING)
#define Assert(expr) \
 (void)(expr ? 0 : (throw Excpt_Assertion(__STRING(expr),__FILE__,__ASSERT_FUNCTION,__LINE__),1) );
#else
#define Assert(expr) \
 (void)(expr ? 0 : (throw Excpt_Assertion("no string information",__FILE__,"no function information",__LINE__),1) );
#endif
#endif


class Excpt_NotImplemented : public Excpt_Base
{
public:
  Excpt_NotImplemented(const char* file, int line);
};

#define NotImplemented throw Excpt_NotImplemented(__FILE__,__LINE__);


#endif

--- NEW FILE: config.h.in ---
/* src/config.h.in.  Generated automatically from configure.in by autoheader.  */

/* Define to empty if the keyword does not work.  */
#undef const

/* Define as __inline if that's what the C compiler calls it.  */
#undef inline

/* Define if you have the ANSI C header files.  */
#undef STDC_HEADERS

/* Define if your processor stores words with the most significant
   byte first (like Motorola and SPARC, unlike Intel and VAX).  */
#undef WORDS_BIGENDIAN

/* Define if you have the <strings.h> header file.  */
#undef HAVE_STRINGS_H

/* Define if you have the <unistd.h> header file.  */
#undef HAVE_UNISTD_H

/* Define if you have the X11 library (-lX11).  */
#undef HAVE_LIBX11

/* Define if you have the Xext library (-lXext).  */
#undef HAVE_LIBXEXT

/* Define if MMX assembly code should be compiled. */
#undef ENABLE_MMX

/* Define if your processor allows unaligned memory accesses. */
#undef UNALIGNED_MEMORYACCESS

/* Define if compiling for Linux systems. */
#undef LINUX

/* Define if compiling with PGCC */
#undef PGCC_COMPILER

--- NEW FILE: Releases ---

dvdview / libvideogfx - Release pairs
------------------------------
rel1-0-0 / date20000606
rel1-0-1 / date20000613
rel1-0-2 / date20000620


branches
--------
direct-gfxmem    - store computed data directly into gfxmem


Development releases:
---------------------

devrel0001 - MPEG-1 system decoder is working, all read packets are logged to standard output.
             Needs: libvideogfx/date19990929

devrel0002 - MPEG-1 system decoding is now working up to video access unit creation.
             A test is included that dumps all video access units in hex.
             Needs: libvideogfx/date19990930

devrel0003 - Video decoder is working with MPEG-1 and MPEG-2 streams. Major cleanup in
             the decoder code is still needed. Errors in video layer are not handled yet.
             Needs: libvideogfx/date19991005

devrel0004 - enough MPEG-2 system layer decoding is implemented to allow unencrypted DVD playback.
             Some MMX acceleration for motion compensation.
             Needs: libvideogfx/date19991025

--- NEW FILE: main.cc.org ---
/********************************************************************************
    Copyright (C) 1999  Dirk Farin

    This program is distributed under GNU Public License (GPL) as
    outlined in the COPYING file that comes with the source distribution.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ********************************************************************************/


#include "error.hh"
#include "tests/system1.hh"
#include "tests/memalloc.hh"
#include "tests/vidaccess.hh"
#include "tests/videodec.hh"
#include "libvideogfx/init.hh"
#include "config.h"

#include "input/streamsrc_istr.hh"
#include "input/streamsrc_cin.hh"
#include "input/errors.hh"
#include "system/sysdec1.hh"
#include "system/resync.hh"
#include "system/sysdemux.hh"
#include "system/videoauconv.hh"
#include "system/syncer.hh"
#include "system/ptsvideo.hh"
#include "video12/vdecoder.hh"
#include "vpostproc/buffer.hh"
#if 0
#include "vpostproc/pp_imgtype.hh"
#endif
#include "vpostproc/pp_resize.hh"
#include "vpostproc/pp_filteredresize.hh"
#include "vpostproc/pp_mblks.hh"
#include "vpostproc/pp_mv.hh"
#include "vpostproc/pp_mvcol.hh"
#include "vpostproc/pp_qscale.hh"
#include "vpostproc/pp_fps.hh"
#include "output/out_x11.hh"
#include "output/out_ppm.hh"
#include "output/out_yuv.hh"
#include "version.hh"

#if LINUX
#include "output/out_mgavid.hh"
#include "input/streamsrc_linux_vcd.hh"
#endif

#include "libvideogfx/x11/imgwin.hh"
#include "libvideogfx/x11/server.hh"


#include "options.hh"

#include <iostream.h>
#include <fstream.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#if 1
#include "libvideogfx/arch/x86/CPUcapabilities.hh"
#endif


// stream sources

static StreamSource_IStream strsrc_istr;
static StreamSource_cin     strsrc_cin;
#if LINUX
static StreamSource_VCD     strsrc_vcd;
#endif
static StreamSource* streamsrc;


// the system decoder

static SystemDecoder_MPEG1 system_dec;
static SystemResyncer      system_resync;
static SystemDemux         system_demux(system_resync);

// video decoding pipeline

static SystemDemuxExtractor video_extractor;
static VideoAUConverter     vidcon(video_extractor);
static PTSVideoCompleter    video_ptsvideo(vidcon);
static VideoDecoder         video_dec(video_ptsvideo);

// audio decoding pipeline

static SystemDemuxExtractor audio_extractor;
static SystemDemuxExtractor ac3_extractor;
static int ac3stream = 0x80;

// video postprocessors

static DecodedPictureSink* lastoutput;
static Resize_Interface*   resizer;
static VideoPostprocessor_MBBoundaries   pp_mblks;
static VideoPostprocessor_MotionVector   pp_mv;
static VideoPostprocessor_MVCol          pp_mvcol;
static VideoPostprocessor_QScale         pp_qscale;
static VideoPostprocessor_FramesPerSec   pp_fps;
static VideoPostprocessor_Resize         pp_resize;
static VideoPostprocessor_FilteredResize pp_filteredresize;
#if 0
static VideoPostprocessor_ImageType    pp_imgtype;
#endif


// video output

static VideoOutput* outputobject;
static VideoSink_X11 videosink_x11;
static VideoSink_YUVFile videosink_yuv;
static VideoSink_PPMFile videosink_ppm;
#if LINUX
static VideoSink_MGA videosink_mga;
#endif

// synchronization

static Syncer_Realtime syncer_realtime;
static Syncer* syncer = &syncer_realtime;


void InitStreamSource(ifstream& istr)
{
  strsrc_istr.SetIStream(istr);
  streamsrc=&strsrc_istr;
}

void InitStreamSource_cin()
{
  streamsrc=&strsrc_cin;
}


void InitStreamSourceVCD(int track)
{
#if LINUX
  strsrc_vcd.Init();
  if (track<0 || track>strsrc_vcd.AskNTracks())
    throw "VCD track out of range";

  strsrc_vcd.SkipToTrack(track);
  streamsrc=&strsrc_vcd;
#endif
}


void InitVideoDecoder1()
{
  system_dec.SetSource(*streamsrc);
  system_resync.SetSource(&system_dec);

  system_demux.EnableChannel(StreamIDBase_Video|0);

  video_extractor.SetSource(&system_demux);
  video_extractor.SetChannel(StreamIDBase_Video|0);
}


void InitAudioDecoder()
{
  system_demux.EnableChannel(StreamIDBase_Audio|0);
  audio_extractor.SetSource(&system_demux);
  audio_extractor.SetChannel(StreamIDBase_Audio|0);
}


void InitAC3Decoder()
{
  system_demux.EnableChannel(0xBD);
  ac3_extractor.SetSource(&system_demux);
  ac3_extractor.SetChannel(0xBD);
}


void InsertPostprocessor(VideoPostprocessor& pp)
{
  pp.SetNext(lastoutput);
  lastoutput = &pp;
}


void InitVideoDecoder2()
{
  video_dec.SetSink(*lastoutput);
}


int maxframes;

void ViewMPEG(bool audio,bool ac3)
{
  int w,h;

  int nframes=0;
  try
    {
      while (1)
	{
	  while (audio && audio_extractor.PacketPending())
	    {
	      SysPacket_Packet* pck = audio_extractor.GetNextPacket();
	      fwrite(pck->data.AskContents(),pck->data.AskLength(),1,stdout);
	      delete pck;
	    }

	  while (ac3 && ac3_extractor.PacketPending())
	    {
	      SysPacket_Packet* pck = ac3_extractor.GetNextPacket();
	      if (pck->data.AskContents()[0] == ac3stream)
		{
		  fwrite(pck->data.AskContents()+4,
			 pck->data.AskLength()-4,1,stdout);
		}

	      delete pck;
	    }

	  if (outputobject->PictureAvailable())
	    {
	      //cout << "Wait until: " << outputobject->AskPTSOfNextToBeDisplayed() << endl;
	      if (outputobject->AskPTSOfNextToBeDisplayed())
		syncer->WaitUntil(outputobject->AskPTSOfNextToBeDisplayed());
	      outputobject->ShowPicture();
	      nframes++;

	      if (maxframes && nframes>=maxframes)
		break;
	    }
	  else
	    {
	      bool more = video_dec.DecodeAFrame();
	      if (!more)
		break;
	    }
	}
    }
  catch(...)
    {
      cout << "Unexpected end. Decoded up to frame: " << nframes << endl;
      throw;
    }

  cout << "Decoded " << nframes << " frames.\n";
}


static void usage()
{
  cerr <<
    " DVDview " DVDVIEW_VERSION "    " DVDVIEW_DATE " (c) Dirk Farin\n"
    "------------------------------------------------\n"
    "usage: dvdview <options> filename.mpg\n"
    "\n"
    "Options:\n"
    "  -B    Skip B-frames\n"
    "  -P    Skip P-frames (and B-frames)\n"
    "  -T #  Set speed (100 for realtime, >100 for faster)\n"
    "  -S #  Set output size.\n"
    "  -N #  Number of frames to decode\n"
    "  -v #  Enable logging level (0 <= # <= 7)\n"
    "         0 - off\n"
    "         1 - sequence headers\n"
    "         2 - gop headers\n"
    "         3 - picture headers\n"
    "         4 - slice headers\n"
    "         5 - macroblocks\n"
    "         6 - DCT coefficients\n"
    "         7 - binary slice data\n"
    "  -F    Write PPM sequence rather than display stream contents.\n"
    "  -Y    Write single YUV file rather than display stream contents.\n"
    "  -M    Show macroblock boundaries (twice for bigger marks).\n"
    "  -d      Show boundary as dark pixels.\n"
    "  -l      Show boundary as bright pixels.\n"    
    "  -Q    Show QScale of macroblocks.\n"
    "  -V    Show motionvectors of macroblocks (vectors).\n"
    "  -C    Show motionvectors of macroblocks (colors).\n"
    "  -p      Enable vectors in P-frames.\n"
    "  -b      Enable vectors in B-frames.\n"
    "  -c      Show colored motionvectors.\n"
    "  -f      Enable forward vectors.\n"
    "  -r      Enable backward vectors.\n"
    "  -O      hold mode\n"
    "  -s    Show decoder speed in fps.\n"
    "  -A    Extract audio-stream to stdout. Pipe this into mpg123.\n"
    "  -3    Extract AC3-stream to stdout. Pipe this into ac3dec.\n"
    "  -a #    select AC3-stream (0-7) default is 0.\n"
#if 0
    "  -W    Set time to wait after each frame (in 1/100s).\n"
    "  -S    Disable X11 shared memory extension.\n"
    "  -F    DisableSomething=true (development only).\n"
    "  -m    Mark special MBs (development only).\n"
#endif
    "  -h    Show this usage information\n"

#if LINUX
    " - - - - - -  Linux only features  - - - - - -\n"
    "  -D #  Play VideoCD track rather that MPEG file (omit filename)\n"
    "  -X    Use X11 output even when MGA_VID is available.\n"
#endif
    ;
}


extern void GetLinesForDrawing(DecodedImageData* dimg,int first,int last);

#if 0
int main(int argc,char** argv)
{
  InitULib(argc,argv);

  DecodedImageData dimg;
  dimg.m_may_modify=false;
  dimg.m_field_lines=true;
  dimg.m_src_y_start=10;
  dimg.m_src_y_end  =40;
  dimg.m_dst_y_start=1;
  GetLinesForDrawing(&dimg,10,20);
}
#endif

int main(int argc,char** argv)
{
  VideoDecoder_Options vdec_options;

  bool imgtypes=false;
  bool qscales=false;
  bool mvs=false,mvcol=false;
  bool audio=false,ac3=false;
  bool mvf=false,mvb=false,mvcolor=false;
  bool mvpf=false,mvbf=false;
  bool mv_holdmode=false;
  bool fpsdisplay=false;
  bool x11_output=false;   // try MGA first
  int vcd=0;
  bool resize=false;
  int scaled_width,scaled_height;
  bool rescale=false;
  bool filtered_resize=false;

#if 0 && ENABLE_MMX
  cout << "CPU capabilities detected: ";
  if (cpucapabilities.HasMMX()) cout << "MMX ";
  if (cpucapabilities.HasKNI()) cout << "KNI ";
  if (cpucapabilities.Has3dNow()) cout << "3dNow! ";
  if (cpucapabilities.HasMTRR()) cout << "MTRR ";
  if (cpucapabilities.HasCMOV()) cout << "CMOV ";
  if (cpucapabilities.HasFPU()) cout << "FPU ";
  cout << endl;
#endif

#if LINUX
  // Try to use MGA if available.

  bool mga_available = videosink_mga.MGA_Available();
  if (mga_available)
    {
      outputobject = &videosink_mga;
      resizer = &videosink_mga;
    }
  else
    {
      outputobject = &videosink_x11;
      resizer = &pp_resize;

      if (!default_x11server.AskDisplay())
	{ cerr << "Cannot open display.\n"; throw "no display"; }
    }
#else
  // Use X11 output by default

  outputobject = &videosink_x11;
  resizer = &pp_resize;

  if (!default_x11server.AskDisplay())
    { cerr << "Cannot open display.\n"; throw "no display"; }
#endif

  try
    {
#if 1
      int c;

      while ((c=getopt(argc,argv,"f3rlcdv:wpuT:S:BbPHMQVW:FYOCdmAa:hXxD:sN:")) != EOF)
	{
	  switch (c)
	    {
	    case 'v':
	      {
#ifndef NDEBUG
		int level=atoi(optarg);
		if (level>7) level=7;
		if (level<0) level=0;
		switch(level)
		  {
		  case 7: vdec_options.Trace_SliceData = true;
		  case 6: vdec_options.Trace_DCTCoeff  = true;
		  case 5: vdec_options.Trace_MB   = true;
		  case 4: vdec_options.Trace_SlcH = true;
		  case 3: vdec_options.Trace_PicH = true;
		  case 2: vdec_options.Trace_GOPH = true;
		  case 1: vdec_options.Trace_SeqH = true;
		  case 0: break;
		  }
#else
		cerr << "Ignoring option -v#: Verbose output was not compiled in.\n";
#endif
	      }
	      break;
	      
	    case 'M':
	      if (!options.Postproc_ShowMBs)
		options.Postproc_ShowMBs = true;
	      else
		{ pp_mblks.SetBigMarks(); }
	      break;

	    case 'd':
	      pp_mblks.SetStaticMode(0);
	      break;

	    case 'l':
	      pp_mblks.SetStaticMode(255);
	      break;

	    case 'P':
	      vdec_options.DecodeP = vdec_options.DecodeB = false;
	      break;
	      
	    case 'B':
	      vdec_options.DecodeB = false;
	      break;

	    case 'x':
	      imgtypes=true;
	      break;
	      
	    case 'Q':
	      qscales=true;
	      break;
	      
	    case 'V':
	      mvs=true;
	      break;

	    case 'C':
	      mvcol=true;
	      break;

	    case 'O':
	      mv_holdmode=true;
	      break;

	    case 'c': mvcolor=true; break;
	    case 'f': mvf=true; break;
	    case 'r': mvb=true; break;
	    case 'p': mvpf=true; break;
	    case 'b': mvbf=true; break;
	      
	    case 'A':
	      audio=true;
	      break;
	      
	    case '3':
	      ac3=true;
	      break;

	    case 'a':
	      ac3stream = atoi(optarg) + 0x80;
	      break;

	    case 'N':
	      maxframes = atoi(optarg);
	      break;

	    case 'F':
	      outputobject = &videosink_ppm;
	      resizer = &pp_resize;
	      break;

	    case 'Y':
	      outputobject = &videosink_yuv;
	      resizer = &pp_resize;
	      break;

	    case 's':
	      fpsdisplay=true;
	      break;

	    case 'h':
	      usage();
              exit(10);
	      break;

	    case 'T':
	      {
		int speed=atoi(optarg);
		if (speed<=0)
		  {
		    cerr << "Speed must be greater than 0%, using 1%\n";
		    speed=1;
		  }
		syncer_realtime.SetSpeed(speed);
	      }
	      break;

	    case 'S':
	      {
		char* w = strtok(optarg,"xX");
		char* h = strtok(NULL,"xX");
		if (!w || !h)
		  { cerr << "invalid size argument (1)\n"; exit(5); }
		
		scaled_width  = atoi(w);
		scaled_height = atoi(h);

		rescale=true;
	      }
	      break;

	    case 'H':
	      filtered_resize = true;
	      break;

	    case 'X':
	      x11_output=true;
	      break;

#if LINUX
	    case 'D':
	      vcd=atoi(optarg);
	      break;
#endif
	    }
	}

      if (x11_output)
	{
	  outputobject = &videosink_x11;
	  resizer = &pp_resize;

	  if (!default_x11server.AskDisplay())
	    { cerr << "Cannot open display.\n"; throw "no display"; }
	}

      if (filtered_resize && resizer==&pp_resize) { cout << "bla\n"; resizer=&pp_filteredresize; }

      lastoutput = outputobject;


      if (optind==argc && !vcd)
	{ usage(); exit(5); }

      video_dec.SetOptions(vdec_options);

      if (rescale) resizer->SetScaledSize(scaled_width,scaled_height);

      ifstream str;

      if (!vcd)
	{
	  if (strcmp(argv[optind],"-")==0)
	    InitStreamSource_cin();
	  else
	    {
	      str.open(argv[optind]);
	      InitStreamSource(str);
	    }
	}
      else
	{
	  InitStreamSourceVCD(vcd);
	}

      InitVideoDecoder1();
      if (audio) InitAudioDecoder();
      if (ac3)   InitAC3Decoder();

      if (filtered_resize) InsertPostprocessor(pp_filteredresize); else InsertPostprocessor(pp_resize);
      if (qscales)  InsertPostprocessor(pp_qscale);
      if (options.Postproc_ShowMBs) InsertPostprocessor(pp_mblks);
      if (fpsdisplay) InsertPostprocessor(pp_fps);
      if (mvs)
	{
	  if (!mvf && !mvb) { mvf=mvb=true; }
	  pp_mv.SelectMVs(mvf,mvb);
	  pp_mv.ColoredVectors(mvcolor);
	  pp_mv.SelectFrametypes(mvpf,mvbf);
	  InsertPostprocessor(pp_mv);
	}
#if 0
      if (imgtypes) InsertPostprocessor(pp_imgtype);
#endif
      if (mvcol)
	{
	  pp_mvcol.SetHoldMode(mv_holdmode);
	  pp_mvcol.SelectFrametypes(mvpf,mvbf);
	  InsertPostprocessor(pp_mvcol);
	}
      InitVideoDecoder2();

      //str.seekg(200000,ios::beg);

      ViewMPEG(audio,ac3);
#endif

#if 0
      ifstream str(argv[1]);
      ShowSystemPackets(str);
#endif

#if 0
      ifstream str(argv[1]);
      //ShowVideoAccessUnitPackets(str);
      //ShowVideoSyntax(str);
      DecodeVideo(str);
#endif

#if 0
      CheckMemAlloc();
#endif

#if 0
      if (!ProcessOptions(argc,argv, options))
	return 0;
#endif
    }
  catch (Excpt_Base& e)
    {
      MessageDisplay::Show(e.m_severity , e.m_text);
    }
  catch (const char* txt)
    {
      cerr << "error: " << txt << endl;
    }
  catch (...)
    {
      cerr << "error occurred... quitting...\n";
    }
}

--- NEW FILE: config.h ---
/* src/config.h.  Generated by configure.  */
/* src/config.h.in.  Generated automatically from configure.in by autoheader.  */

/* Define to empty if the keyword does not work.  */
/* #undef const */

/* Define as __inline if that's what the C compiler calls it.  */
/* #undef inline */

/* Define if you have the ANSI C header files.  */
#define STDC_HEADERS 1

/* Define if your processor stores words with the most significant
   byte first (like Motorola and SPARC, unlike Intel and VAX).  */
/* #undef WORDS_BIGENDIAN */

/* Define if you have the <strings.h> header file.  */
#define HAVE_STRINGS_H 1

/* Define if you have the <unistd.h> header file.  */
#define HAVE_UNISTD_H 1

/* Define if you have the X11 library (-lX11).  */
/* #undef HAVE_LIBX11 */

/* Define if you have the Xext library (-lXext).  */
/* #undef HAVE_LIBXEXT */

/* Define if MMX assembly code should be compiled. */
#define ENABLE_MMX 1

/* Define if your processor allows unaligned memory accesses. */
#define UNALIGNED_MEMORYACCESS 1

/* Define if compiling for Linux systems. */
#define LINUX 1

/* Define if compiling with PGCC */
/* #undef PGCC_COMPILER */

--- NEW FILE: Makefile.in ---

LIBVIDEOGFXROOT = ../libvideogfx

BINDIR  = .

PRGNAME = dvdview

COMMONOBJS = main.o error.o \
	     input/streamsrc_istr.o \
	     input/streamsrc_cin.o \
             system/sysdec1.o system/sysdemux.o system/resync.o \
             system/videoauconv.o system/ptsvideo.o \
             system/syncer.o \
	     utility/bytebuffer.o utility/fastalloc.o \
             video12/vidsyntax.o \
             video12/viddec_mods.o \
             video12/vdecoder.o \
             video12/modules/mcomp_sgl_simple.o \
             video12/modules/idct_arai.o \
             output/out_x11.o \
             output/out_yuv.o \
             output/out_ppm.o \
             output/accumulator.o \
             options.o \
             vpostproc/buffer.o \
             vpostproc/postproc.o \
             vpostproc/pp_mblks.o \
             vpostproc/pp_mv.o \
             vpostproc/pp_mvcol.o \
             vpostproc/pp_qscale.o \
             vpostproc/pp_fps.o \
             vpostproc/pp_resize.o \
             vpostproc/pp_filteredresize.o \

#             tests/system1.o tests/memalloc.o tests/vidaccess.o \
#             tests/videodec.o \
#             vpostproc/pp_imgtype.o \

MMXOBJS =    video12/modules/mcomp_sgl_mmx.o \
             video12/modules/mmxidct.o \

LINUXOBJS =  output/out_mgavid.o input/streamsrc_linux_vcd.o

OBJS = $(COMMONOBJS) @OBJLIST@ # $(ARCHOBJS) $(MOCOBJS)

CC = @CC@
SHELL = /bin/bash
PROFILEFLAGS =
DEBUGFLAGS = -g
CFLAGS = @CFLAGS@ $(PROFILEFLAGS) $(DEBUGFLAGS)
OPTIMIZE = -O3
INCLUDES = -I/usr/include/g++ -I$(LIBVIDEOGFXROOT) -I. # -I$(QTROOT)/include
LNPATH   = -L/usr/X11R6/lib # -L$(QTROOT)/lib
CPPFLAGS = $(INCLUDES)
LNFLAGS  = $(LNPATH) $(PROFILEFLAGS) $(DEBUGFLAGS)
DEFS = # -DNDEBUG

LIBS = @LDFLAGS@ @LIBS@


%.d: %.cc
	@echo "updating dependencies... ($<)"
	@$(SHELL) -ec "$(CC) -MM $(CPPFLAGS) $(DEFS) $< | \
              sed 's@\($(*F)\)\.o@\$*.o $@ @g' > $@; [ -s $@ ] || rm -f $@"

%.d: %.S
	touch $@

moc_%.cc: %.hh
	moc -f $< -o $@

.cc.o:
	$(CC) $(CFLAGS) $(OPTIMIZE) $(DEFS) $(INCLUDES) -o $@ -c $<

$(BINDIR)/$(PRGNAME): $(OBJS) $(LIBVIDEOGFXROOT)/libvideogfx/.libs/libvideogfx.a
	$(CC) $(LNFLAGS) -o $@ $(OBJS) $(LIBVIDEOGFXROOT)/libvideogfx/.libs/libvideogfx.a $(LIBS)

ifneq ($(MAKECMDGOALS),clean)
include $(OBJS:.o=.d)
endif

clean:
	@rm -f $(OBJS:.o=.cc~)
	@rm -f $(OBJS:.o=.hh~)
	@rm -f $(OBJS)
	@rm -f $(MOCOBJS)
	@rm -f $(OBJS:.o=.d)
	@rm -f *~ */*~ core gmon.out
	@rm -f $(PRGNAME)
	@rm -f Makefile


--- NEW FILE: error.cc ---
/********************************************************************************
    Copyright (C) 1999  Dirk Farin

    This program is distributed under GNU Public License (GPL) as
    outlined in the COPYING file that comes with the source distribution.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ********************************************************************************/

#include "error.hh"
#include <iostream.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>


static class MessageDisplay_cerr : public MessageDisplay
{
public:
  void ShowMessage(ErrorSeverity severity,const char* text) const
    {
      cout.flush(); /* Flush program output. Do this for better sync of
                       debug and error display. */

      switch(severity)
        {
          //case ErrSev_Empty:     cerr << "EMPTY-ERROR ! This should not occur !\n"; exit(10); break;
        case ErrSev_Note:      cerr << "Note: ";    break;
        case ErrSev_Warning:   cerr << "Warning: "; break;
        case ErrSev_Error:     cerr << "Error: ";   break;
        case ErrSev_Critical:  cerr << "CRITICAL ERROR: "; break;
        case ErrSev_Assertion: cerr << "ASSERTION FAILED: "; break;
        }

      cerr << text << endl;
    }

  void ShowMessage(const Excpt_Base& e) const
    {
      ShowMessage(e.m_severity , e.m_text);
    }
} msgdisplay_cerr;


void MessageDisplay::Show(ErrorSeverity sev,const char* text)
{
  assert(std_msgdisplay);
  std_msgdisplay->ShowMessage(sev,text);
}

void MessageDisplay::Show(const Excpt_Base& excpt)
{
  assert(std_msgdisplay);
  std_msgdisplay->ShowMessage(excpt);
}

void MessageDisplay::SetStandardDisplay(MessageDisplay* disp)
{
  assert(disp);
  std_msgdisplay = disp;
}

const MessageDisplay* MessageDisplay::std_msgdisplay = &msgdisplay_cerr;





Excpt_Base::Excpt_Base(ErrorSeverity sev)
  : m_severity(sev)
{
  assert(m_severity != ErrSev_Note);

  m_text[0] = 0;
}

Excpt_Base::Excpt_Base(ErrorSeverity sev,const char* txt)
  : m_severity(sev)
{
  assert(m_severity != ErrSev_Note);
  assert(strlen(txt) <= c_MaxTextLen);
  strcpy(m_text,txt);
}

Excpt_Assertion::Excpt_Assertion(const char* expr,const char* file, const char* function,int line)
  : Excpt_Base(ErrSev_Assertion)
{
  sprintf(m_text,
          "file '%s', '%s', line %d (%s).\n",
          file,function,line,expr);
}


Excpt_NotImplemented::Excpt_NotImplemented(const char* file, int line)
  : Excpt_Base(ErrSev_Critical)
{
  sprintf(m_text,"NOT-IMPLEMENTED-YET point reached in file '%s', line %d.\n",file,line);
}

#if 0
void ShowNote(ErrorSeverity sev,const char* txt)
{
  Assert(sev == ErrSev_Note ||
         sev == ErrSev_Warning);

  if (sev==ErrSev_Note) cerr << "Note: ";
  else cerr << "Warning: ";
  cerr << txt << endl;
}

#if 0
void Error(ErrorSeverity errsev,const char* txt)
{
  switch(errsev)
    {
    case ErrSev_Note:     cerr << "Note: ";    break;
    case ErrSev_Warning:  cerr << "Warning: "; break;
    case ErrSev_Error:    cerr << "Error: ";   break;
    case ErrSev_Critical: cerr << "CRITICAL ERROR: "; break;
    }

  cerr << txt << endl;
}
#else
void Error(ErrorSeverity sev,const char* txt)
{
  throw Excpt_Base(sev,txt);
}
#endif
#endif

--- NEW FILE: demo.sh ---
/usr2/microwin/src/bin/nano-X $1 & /usr2/microwin/src/bin/nanowm & ./dvdview -X -L -s /usr2/ccjump.mpeg; sleep 10000

--- NEW FILE: version.hh ---

#ifndef VERSION_HH
#define VERSION_HH

#define DVDVIEW_VERSION "1.2.0pre"        // 8 chars
#define DVDVIEW_DATE    "06.Oct.2000"     // 11 chars

#endif

--- NEW FILE: options.hh ---

#ifndef OPTIONS_HH
#define OPTIONS_HH

#include "types.hh"


struct Options
{
  Options();


  // Quality Flags

#if 0
  bool UseOnlyOneMVOfBiPred;    // This reduces the accuracy of the bidirectional prediction !
  bool NoHalfPelInB;            //  """
#endif

  // Warnings

#if 0
  bool WarnOnFalseMPEG1Fields;
#endif

  // Output options

#if 0
  bool Disable_X11Shm;
#endif
  bool Postproc_ShowMBs;
#if 0
  bool Postproc_ShowQ;
  bool Postproc_ShowMV;
  bool Postproc_ShowMVCol;
  bool Postproc_Mark;

  bool Postproc_ShowMV_Hold;
  bool Postproc_ShowMV_P;
  bool Postproc_ShowMV_B;
  bool Postproc_ShowMVCol_ShowPhase;

  int  FrameWait;  // Time to wait after displaying a frame (in 1/100s)
#endif
};

extern Options options;

#endif

--- NEW FILE: main.cc ---
/********************************************************************************
    Copyright (C) 1999  Dirk Farin

    This program is distributed under GNU Public License (GPL) as
    outlined in the COPYING file that comes with the source distribution.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ********************************************************************************/


#include "error.hh"
#include "tests/system1.hh"
#include "tests/memalloc.hh"
#include "tests/vidaccess.hh"
#include "tests/videodec.hh"
#include "libvideogfx/init.hh"
#include "config.h"

#include "input/streamsrc_istr.hh"
#include "input/streamsrc_cin.hh"
#include "input/errors.hh"
#include "system/sysdec1.hh"
#include "system/resync.hh"
#include "system/sysdemux.hh"
#include "system/videoauconv.hh"
#include "system/syncer.hh"
#include "system/ptsvideo.hh"
#include "video12/vdecoder.hh"
#include "vpostproc/buffer.hh"
#if 0
#include "vpostproc/pp_imgtype.hh"
#endif
#include "vpostproc/pp_resize.hh"
#include "vpostproc/pp_filteredresize.hh"
#include "vpostproc/pp_mblks.hh"
#include "vpostproc/pp_mv.hh"
#include "vpostproc/pp_mvcol.hh"
#include "vpostproc/pp_qscale.hh"
#include "vpostproc/pp_fps.hh"
#include "output/out_x11.hh"
#include "output/out_ppm.hh"
#include "output/out_yuv.hh"
#include "version.hh"

#if LINUX
#include "output/out_mgavid.hh"
#include "input/streamsrc_linux_vcd.hh"
#endif

#include "libvideogfx/nanox/imgwin.hh"
#include "libvideogfx/nanox/server.hh"


#include "options.hh"

#include <iostream.h>
#include <fstream.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#include "libvideogfx/arch/x86/CPUcapabilities.hh"
#endif

class DvdApp 
{
protected:
  // stream sources

   StreamSource_IStream strsrc_istr;
   StreamSource_cin     strsrc_cin;
#if LINUX
   StreamSource_VCD     strsrc_vcd;
#endif
   StreamSource* streamsrc;


  // the system decoder
  
   SystemDecoder_MPEG1 system_dec;
   SystemResyncer      system_resync;
   SystemDemux         system_demux;
  
  // video decoding pipeline
  
   SystemDemuxExtractor video_extractor;
   VideoAUConverter     vidcon;
   PTSVideoCompleter    video_ptsvideo;
   VideoDecoder         video_dec;
  
  // audio decoding pipeline
  
   SystemDemuxExtractor audio_extractor;
   SystemDemuxExtractor ac3_extractor;
   int ac3stream;
  
  // video postprocessors
  
   DecodedPictureSink* lastoutput;
   Resize_Interface*   resizer;
   VideoPostprocessor_MBBoundaries   pp_mblks;
   VideoPostprocessor_MotionVector   pp_mv;
   VideoPostprocessor_MVCol          pp_mvcol;
   VideoPostprocessor_QScale         pp_qscale;
   VideoPostprocessor_FramesPerSec   pp_fps;
   VideoPostprocessor_Resize         pp_resize;
   VideoPostprocessor_FilteredResize pp_filteredresize;
#if 0
   VideoPostprocessor_ImageType    pp_imgtype;
#endif

  VideoOutput* outputobject;  
  VideoSink_YUVFile videosink_yuv;
  VideoSink_PPMFile videosink_ppm;
#if LINUX
  VideoSink_MGA videosink_mga;
#endif
  
  // synchronization
  
   Syncer_Realtime syncer_realtime;
   Syncer* syncer;

  // command line args 
  static   bool imgtypes;
  static   bool qscales;
  static   bool mvs;
  static   bool mvcol;
  static   bool audio;
  static   bool ac3;
  static   bool mvf;
  static   bool mvb;
  static   bool mvcolor;
  static   bool mvpf;
  static   bool mvbf;
  static   bool mv_holdmode;
  static   bool fpsdisplay;
  static   bool x11_output;   // try MGA first
  static   int  vcd;
  static   int  maxframes;
  static   bool resize;

  static   bool rescale;
  static   bool filtered_resize;

  static   bool _initialized;

public:

  void InitStreamSource(ifstream& istr);
  void InitVideoDecoder1();
  void InitStreamSource_cin();
  void InitStreamSourceVCD(int track);
  void InitAudioDecoder();
  void InitAC3Decoder();
  void InsertPostprocessor(VideoPostprocessor& pp);
  void InitVideoDecoder2();
  void ViewMPEG(bool audio,bool ac3);
  DvdApp(int argc,char** argv);

  void InitOptions();
};

bool DvdApp::imgtypes;
bool DvdApp::qscales;
bool DvdApp::mvs;
bool DvdApp::mvcol;
bool DvdApp::audio;
bool DvdApp::ac3;
bool DvdApp::mvf;
bool DvdApp::mvb;
bool DvdApp::mvcolor;
bool DvdApp::mvpf;
bool DvdApp::mvbf;
bool DvdApp::mv_holdmode;
bool DvdApp::fpsdisplay;
bool DvdApp::x11_output;
int  DvdApp::vcd;
int  DvdApp::maxframes;
bool DvdApp::resize;
bool DvdApp::rescale;
bool DvdApp::filtered_resize;
bool DvdApp::_initialized;
static   bool loop;
extern bool fullscreen;

// video output
static   VideoSink_X11 videosink_x11;

void DvdApp::InitStreamSource(ifstream& istr)
{
  strsrc_istr.SetIStream(istr);
  streamsrc=&strsrc_istr;
}

void DvdApp::InitStreamSource_cin()
{
  streamsrc=&strsrc_cin;
}


void DvdApp::InitStreamSourceVCD(int track)
{
#if LINUX
  strsrc_vcd.Init();
  if (track<0 || track>strsrc_vcd.AskNTracks())
    throw "VCD track out of range";

  strsrc_vcd.SkipToTrack(track);
  streamsrc=&strsrc_vcd;
#endif
}


void DvdApp::InitVideoDecoder1()
{
  system_dec.SetSource(*streamsrc);
  system_resync.SetSource(&system_dec);

  system_demux.EnableChannel(StreamIDBase_Video|0);

  video_extractor.SetSource(&system_demux);
  video_extractor.SetChannel(StreamIDBase_Video|0);
}


void DvdApp::InitAudioDecoder()
{
  system_demux.EnableChannel(StreamIDBase_Audio|0);
  audio_extractor.SetSource(&system_demux);
  audio_extractor.SetChannel(StreamIDBase_Audio|0);
}


void DvdApp::InitAC3Decoder()
{
  system_demux.EnableChannel(0xBD);
  ac3_extractor.SetSource(&system_demux);
  ac3_extractor.SetChannel(0xBD);
}


void DvdApp::InsertPostprocessor(VideoPostprocessor& pp)
{
  pp.SetNext(lastoutput);
  lastoutput = &pp;
}


void DvdApp::InitVideoDecoder2()
{
  video_dec.SetSink(*lastoutput);
}

void DvdApp::ViewMPEG(bool audio,bool ac3)
{
  int w,h;

  int nframes=0;
  try
    {
      while (1)
	{
	  while (audio && audio_extractor.PacketPending())
	    {
	      SysPacket_Packet* pck = audio_extractor.GetNextPacket();
	      fwrite(pck->data.AskContents(),pck->data.AskLength(),1,stdout);
	      delete pck;
	    }

	  while (ac3 && ac3_extractor.PacketPending())
	    {
	      SysPacket_Packet* pck = ac3_extractor.GetNextPacket();
	      if (pck->data.AskContents()[0] == ac3stream)
		{
		  fwrite(pck->data.AskContents()+4,
			 pck->data.AskLength()-4,1,stdout);
		}

	      delete pck;
	    }

	  if (outputobject->PictureAvailable())
	    {
	      //cout << "Wait until: " << outputobject->AskPTSOfNextToBeDisplayed() << endl;
	      if (outputobject->AskPTSOfNextToBeDisplayed())
		syncer->WaitUntil(outputobject->AskPTSOfNextToBeDisplayed());
	      outputobject->ShowPicture();
	      nframes++;

	      if (maxframes && nframes>=maxframes)
		break;
	    }
	  else
	    {
	      bool more = video_dec.DecodeAFrame();
	      if (!more)
		break;
	    }
	}
    }
  catch(...)
    {
      cout << "Unexpected end. Decoded up to frame: " << nframes << endl;
      throw;
    }

  cout << "Decoded " << nframes << " frames.\n";
}


static void usage()
{
  cerr <<
    " DVDview " DVDVIEW_VERSION "    " DVDVIEW_DATE " (c) Dirk Farin\n"
    "------------------------------------------------\n"
    "usage: dvdview <options> filename.mpg\n"
    "\n"
    "Options:\n"
    "  -B    Skip B-frames\n"
    "  -P    Skip P-frames (and B-frames)\n"
    "  -T #  Set speed (100 for realtime, >100 for faster)\n"
    "  -S #  Set output size.\n"
    "  -N #  Number of frames to decode\n"
    "  -L    Loop continuously\n"
    "  -U    Use fullscreen\n"
    "  -v #  Enable logging level (0 <= # <= 7)\n"
    "         0 - off\n"
    "         1 - sequence headers\n"
    "         2 - gop headers\n"
    "         3 - picture headers\n"
    "         4 - slice headers\n"
    "         5 - macroblocks\n"
    "         6 - DCT coefficients\n"
    "         7 - binary slice data\n"
    "  -F    Write PPM sequence rather than display stream contents.\n"
    "  -Y    Write single YUV file rather than display stream contents.\n"
    "  -M    Show macroblock boundaries (twice for bigger marks).\n"
    "  -d      Show boundary as dark pixels.\n"
    "  -l      Show boundary as bright pixels.\n"    
    "  -Q    Show QScale of macroblocks.\n"
    "  -V    Show motionvectors of macroblocks (vectors).\n"
    "  -C    Show motionvectors of macroblocks (colors).\n"
    "  -p      Enable vectors in P-frames.\n"
    "  -b      Enable vectors in B-frames.\n"
    "  -c      Show colored motionvectors.\n"
    "  -f      Enable forward vectors.\n"
    "  -r      Enable backward vectors.\n"
    "  -O      hold mode\n"
    "  -s    Show decoder speed in fps.\n"
    "  -A    Extract audio-stream to stdout. Pipe this into mpg123.\n"
    "  -3    Extract AC3-stream to stdout. Pipe this into ac3dec.\n"
    "  -a #    select AC3-stream (0-7) default is 0.\n"
#if 0
    "  -W    Set time to wait after each frame (in 1/100s).\n"
    "  -S    Disable X11 shared memory extension.\n"
    "  -F    DisableSomething=true (development only).\n"
    "  -m    Mark special MBs (development only).\n"
#endif
    "  -h    Show this usage information\n"

#if LINUX
    " - - - - - -  Linux only features  - - - - - -\n"
    "  -D #  Play VideoCD track rather that MPEG file (omit filename)\n"
    "  -X    Use X11 output even when MGA_VID is available.\n"
#endif
    ;
}


extern void GetLinesForDrawing(DecodedImageData* dimg,int first,int last);

#if 0
int main(int argc,char** argv)
{
  InitULib(argc,argv);

  DecodedImageData dimg;
  dimg.m_may_modify=false;
  dimg.m_field_lines=true;
  dimg.m_src_y_start=10;
  dimg.m_src_y_end  =40;
  dimg.m_dst_y_start=1;
  GetLinesForDrawing(&dimg,10,20);
}
#endif

int main(int argc, char ** argv)
{
  do {
    DvdApp * m  = new DvdApp(argc,argv);
    delete m;
    videosink_x11.reset();
  } while (loop);
}

void DvdApp::InitOptions()
{
  if(!_initialized) {
    imgtypes=false;
    qscales=false;
    mvs=false;
    mvcol=false;
    audio=false;
    ac3=false;
    mvf=false;
    mvb=false;
    mvcolor=false;
    mvpf=false;
    mvbf=false;
    mv_holdmode=false;
    fpsdisplay=false;
    x11_output=false;   // try MGA first
    vcd=0;
    resize=false;
    rescale=false;
    filtered_resize=false;
  }
}

DvdApp::DvdApp(int argc,char** argv) :
  system_demux(system_resync),
  vidcon(video_extractor),
  video_ptsvideo(vidcon),
  video_dec(video_ptsvideo),
  ac3stream(0x08),
  syncer(&syncer_realtime)

{
  int scaled_width,scaled_height;

  VideoDecoder_Options vdec_options;

  // possibly initialize user options to default values
  InitOptions();

#if 0 && ENABLE_MMX
  cout << "CPU capabilities detected: ";
  if (cpucapabilities.HasMMX()) cout << "MMX ";
  if (cpucapabilities.HasKNI()) cout << "KNI ";
  if (cpucapabilities.Has3dNow()) cout << "3dNow! ";
  if (cpucapabilities.HasMTRR()) cout << "MTRR ";
  if (cpucapabilities.HasCMOV()) cout << "CMOV ";
  if (cpucapabilities.HasFPU()) cout << "FPU ";
  cout << endl;
#endif

#if LINUX
  // Try to use MGA if available.

  bool mga_available = videosink_mga.MGA_Available();
  if (mga_available)
    {
      outputobject = &videosink_mga;
      resizer = &videosink_mga;
    }
  else
    {
      outputobject = &videosink_x11;
      resizer = &pp_resize;

      if (!default_x11server.AskDisplay())
	{ cerr << "Cannot open display.\n"; throw "no display"; }
    }
#else
  // Use X11 output by default

  outputobject = &videosink_x11;
  resizer = &pp_resize;

  if (!default_x11server.AskDisplay())
    { cerr << "Cannot open display.\n"; throw "no display"; }
#endif

  try
    {
#if 1
      int c;

      // only parse the command line args if we haven't before (from _initialized)

      while (!_initialized && (c=getopt(argc,argv,"f3rlcdv:wpuT:S:BbPHMQVW:FYOCdmAa:hXxD:sN:L")) != EOF)
	{
	  switch (c)
	    {
	    case 'v':
	      {
#ifndef NDEBUG
		int level=atoi(optarg);
		if (level>7) level=7;
		if (level<0) level=0;
		switch(level)
		  {
		  case 7: vdec_options.Trace_SliceData = true;
		  case 6: vdec_options.Trace_DCTCoeff  = true;
		  case 5: vdec_options.Trace_MB   = true;
		  case 4: vdec_options.Trace_SlcH = true;
		  case 3: vdec_options.Trace_PicH = true;
		  case 2: vdec_options.Trace_GOPH = true;
		  case 1: vdec_options.Trace_SeqH = true;
		  case 0: break;
		  }
#else
		cerr << "Ignoring option -v#: Verbose output was not compiled in.\n";
#endif
	      }
	      break;
	      
	    case 'M':
	      if (!options.Postproc_ShowMBs)
		options.Postproc_ShowMBs = true;
	      else
		{ pp_mblks.SetBigMarks(); }
	      break;

	    case 'd':
	      pp_mblks.SetStaticMode(0);
	      break;

	    case 'l':
	      pp_mblks.SetStaticMode(255);
	      break;

	    case 'P':
	      vdec_options.DecodeP = vdec_options.DecodeB = false;
	      break;
	      
	    case 'B':
	      vdec_options.DecodeB = false;
	      break;

	    case 'x':
	      imgtypes=true;
	      break;
	      
	    case 'Q':
	      qscales=true;
	      break;
	      
	    case 'V':
	      mvs=true;
	      break;

	    case 'C':
	      mvcol=true;
	      break;

	    case 'O':
	      mv_holdmode=true;
	      break;

	    case 'c': mvcolor=true; break;
	    case 'f': mvf=true; break;
	    case 'r': mvb=true; break;
	    case 'p': mvpf=true; break;
	    case 'b': mvbf=true; break;
	      
	    case 'A':
	      audio=true;
	      break;
	      
	    case '3':
	      ac3=true;
	      break;

	    case 'a':
	      ac3stream = atoi(optarg) + 0x80;
	      break;

	    case 'N':
	      maxframes = atoi(optarg);
	      break;

	    case 'F':
	      outputobject = &videosink_ppm;
	      resizer = &pp_resize;
	      break;

	    case 'Y':
	      outputobject = &videosink_yuv;
	      resizer = &pp_resize;
	      break;

	    case 's':
	      fpsdisplay=true;
	      break;

	    case 'h':
	      usage();
              exit(10);
	      break;

	    case 'T':
	      {
		int speed=atoi(optarg);
		if (speed<=0)
		  {
		    cerr << "Speed must be greater than 0%, using 1%\n";
		    speed=1;
		  }
		syncer_realtime.SetSpeed(speed);
	      }
	      break;

	    case 'S':
	      {
		char* w = strtok(optarg,"xX");
		char* h = strtok(NULL,"xX");
		if (!w || !h)
		  { cerr << "invalid size argument (1)\n"; exit(5); }
		
		scaled_width  = atoi(w);
		scaled_height = atoi(h);

		rescale=true;
	      }
	      break;

	    case 'H':
	      filtered_resize = true;
	      break;

	    case 'X':
	      x11_output=true;
	      break;

	    case 'L':
	      loop=true;
	      break;

	    case 'U':
	      fullscreen=true;
	      break;

#if LINUX
	    case 'D':
	      vcd=atoi(optarg);
	      break;
#endif
	    }
	}

      // make sure we don't re-initialize from the command line args 
      _initialized = true;

      if (x11_output)
	{
	  outputobject = &videosink_x11;
	  resizer = &pp_resize;

  	  if (!default_x11server.AskDisplay())
	    { cerr << "Cannot open display.\n"; throw "no display"; }
	}

      if (filtered_resize && resizer==&pp_resize) { cout << "bla\n"; resizer=&pp_filteredresize; }

      lastoutput = outputobject;


      if (optind==argc && !vcd)
	{ usage(); exit(5); }

      video_dec.SetOptions(vdec_options);

      if (rescale) resizer->SetScaledSize(scaled_width,scaled_height);



      ifstream str;

      if (!vcd)
	{
	  if (strcmp(argv[optind],"-")==0)
	    InitStreamSource_cin();
	  else
	    {
	      str.open(argv[optind]);
	      InitStreamSource(str);
	    }
	}
      else
	{
	  InitStreamSourceVCD(vcd);
	}

      InitVideoDecoder1();
      if (audio) InitAudioDecoder();
      if (ac3)   InitAC3Decoder();

      if (filtered_resize) InsertPostprocessor(pp_filteredresize); else InsertPostprocessor(pp_resize);
      if (qscales)  InsertPostprocessor(pp_qscale);
      if (options.Postproc_ShowMBs) InsertPostprocessor(pp_mblks);
      if (fpsdisplay) InsertPostprocessor(pp_fps);
      if (mvs)
	{
	  if (!mvf && !mvb) { mvf=mvb=true; }
	  pp_mv.SelectMVs(mvf,mvb);
	  pp_mv.ColoredVectors(mvcolor);
	  pp_mv.SelectFrametypes(mvpf,mvbf);
	  InsertPostprocessor(pp_mv);
	}
#if 0
      if (imgtypes) InsertPostprocessor(pp_imgtype);
#endif
      if (mvcol)
	{
	  pp_mvcol.SetHoldMode(mv_holdmode);
	  pp_mvcol.SelectFrametypes(mvpf,mvbf);
	  InsertPostprocessor(pp_mvcol);
	}
      InitVideoDecoder2();

      //str.seekg(200000,ios::beg);


      ViewMPEG(audio,ac3);

#endif

#if 0
      ifstream str(argv[1]);
      ShowSystemPackets(str);
#endif

#if 0
      ifstream str(argv[1]);
      //ShowVideoAccessUnitPackets(str);
      //ShowVideoSyntax(str);
      DecodeVideo(str);
#endif

#if 0
      CheckMemAlloc();
#endif

#if 0
      if (!ProcessOptions(argc,argv, options))
	return 0;
#endif
    }
  catch (Excpt_Base& e)
    {
      MessageDisplay::Show(e.m_severity , e.m_text);
    }
  catch (const char* txt)
    {
      cerr << "error: " << txt << endl;
    }
  catch (...)
    {
      cerr << "error occurred... quitting...\n";
    }
}

--- NEW FILE: types.hh ---
/********************************************************************************
  types.hh

  purpose:
    Quite useless since source code reorganization.

  notes:

  to do:

  author(s):
   - Dirk Farin, farin at ti.uni-mannheim.de

  modifications:

 ********************************************************************************
    Copyright (C) 1999  Dirk Farin

    This program is distributed under GNU Public License (GPL) as
    outlined in the COPYING file that comes with the source distribution.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ********************************************************************************/

#ifndef DVDVIEW_TYPES_HH
#define DVDVIEW_TYPES_HH

#include "libvideogfx/types.hh"

#endif




More information about the dslinux-commit mailing list