dslinux/user/pixil/packages/dvdview/dvdview/src/input errors.hh streamsrc.hh streamsrc_cin.cc streamsrc_cin.hh streamsrc_istr.cc streamsrc_istr.hh streamsrc_linux_vcd.cc streamsrc_linux_vcd.hh

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


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

Added Files:
	errors.hh streamsrc.hh streamsrc_cin.cc streamsrc_cin.hh 
	streamsrc_istr.cc streamsrc_istr.hh streamsrc_linux_vcd.cc 
	streamsrc_linux_vcd.hh 
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it

--- NEW FILE: streamsrc_istr.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 "input/streamsrc_istr.hh"
#include "error.hh"

#include <iostream.h>


StreamSource_IStream::StreamSource_IStream()
 : d_istr(NULL)
{
}


StreamSource_IStream::~StreamSource_IStream()
{
}


uint32 StreamSource_IStream::FillBuffer(uint8* mem,uint32 maxlen)
{
  Assert(d_istr);

  d_istr->read(mem,maxlen);
  return d_istr->gcount();
}


bool StreamSource_IStream::MoreDataPending() const
{
  Assert(d_istr);

  return !d_istr->eof();
}


uint64 StreamSource_IStream::AskStreamLength() const
{
  Assert(d_istr);

  int64 currentpos; currentpos = d_istr->tellg();
  d_istr->seekg(0,ios::end);
  int64 length; length = d_istr->tellg();
  d_istr->seekg(currentpos);

  return length;
}


uint64 StreamSource_IStream::AskCurrentPosition() const
{
  return d_istr->tellg();
}


uint64 StreamSource_IStream::SetCurrentPosition(uint64 pos)
{
  d_istr->seekg(pos);
  return pos;
}

--- NEW FILE: streamsrc_cin.hh ---
/********************************************************************************
  input/streamsrc_istr.hh

  purpose:
    A stream source that reads data out of a C++ "istream".

  notes:

  to do:

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

  modifications:
   ??/???/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 INPUT_STREAMSRC_CIN_HH
#define INPUT_STREAMSRC_CIN_HH

#include "input/streamsrc.hh"


class StreamSource_cin : public StreamSource
{
public:
   StreamSource_cin();
  ~StreamSource_cin();

  uint32 FillBuffer(uint8* mem,uint32 maxlen);
  bool   MoreDataPending() const;
  
  bool   IsFiniteStream() const { return true; }
  uint64 AskStreamLength() const;
  
  bool   MaySeek() const { return true; }
  uint64 AskCurrentPosition() const;
  uint64 SetCurrentPosition(uint64);

private:
};

#endif

--- NEW FILE: streamsrc.hh ---
/********************************************************************************
  input/streamsrc.hh

  purpose:
    Abstract base class: objects of this class are the source of
    the data. This may be an ordinary file, a VCD/DVD reader or
    a network connection.

  notes:
   - All methods do not throw any exceptions.

  to do:

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

  modifications:
   ??/???/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 INPUT_STREAMSRC_HH
#define INPUT_STREAMSRC_HH

#include "types.hh"


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

  virtual uint32 FillBuffer(uint8* mem,uint32 maxlen) = 0;
  virtual bool   MoreDataPending() const = 0;

  /* If the stream is of finite length, you may call AskStreamLength().
     It is however not guaranteed that the size of the stream will not
     grow any more.

     These methods are provided to show a progress bar that displays
     where you are when playing from a file. Displaying a progress
     bar not always makes sense. If you are displaying a live video
     signal, it is quite useless.
  */
  virtual bool   IsFiniteStream() const = 0;
  virtual uint64 AskStreamLength() const = 0;


  /* These methods allow seeking in the input stream if this is possible.
     When the stream is located on a random access medium, seeking
     will normally be possible. On the other hand, when playing a
     stream that is received online via a network connection, seeking
     is not possible.

     Even when seeking is possible, it is not guaranteed that you can
     seek to any arbitrary position. This may be the case when you buffer
     for example the last 5 minutes of a live stream. So you may seek
     back up to 5 minutes but not more. Although this application is
     quite exotic you should check the result of "SetCurrentPosition()",
     which is the position that the class decides to set the current
     position really to.
  */
  virtual bool   MaySeek() const = 0;
  virtual uint64 AskCurrentPosition() const = 0;
  virtual uint64 SetCurrentPosition(uint64) = 0;
};

#endif

--- NEW FILE: errors.hh ---
/********************************************************************************
  input/errors.hh

  purpose:
    Stream input errors.

  notes:

  to do:

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

  modifications:
   27/Sep/1999 - 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_INPUT_ERRORS_HH
#define DVDVIEW_INPUT_ERRORS_HH

#include "error.hh"

struct Excpt_Error_InvalidData : public Excpt_Base
{ Excpt_Error_InvalidData(const char* txt="Invalid data read.") : Excpt_Base(ErrSev_Error,txt) { } };

struct Excpt_Error_UnexpectedEndOfStream : public Excpt_Base
{ Excpt_Error_UnexpectedEndOfStream()     : Excpt_Base(ErrSev_Error,"Unexpected end of stream reached.") { } };

#endif

--- NEW FILE: streamsrc_linux_vcd.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 "input/streamsrc_linux_vcd.hh"
#include "error.hh"

#include <math.h>
#include <iostream.h>
#include <string.h>


StreamSource_VCD::StreamSource_VCD()
  : d_fd(0),
    d_buflen(0)
{
}


StreamSource_VCD::~StreamSource_VCD()
{
  close(d_fd);
}


void StreamSource_VCD::Init(const char* device)
{
  d_fd = open(device,O_RDONLY|O_NONBLOCK);
  if (d_fd==-1)
    { perror("CDROM open: "); throw "error opening cdrom"; }

  struct cdrom_tochdr tochdr;
  if (ioctl(d_fd,CDROMREADTOCHDR,&tochdr)==-1)
    { perror("read CDROM toc header: "); throw "error reading CDROM toc header"; }

  d_nTracks = tochdr.cdth_trk1-1;

#if 0
  cout << "First track: " << ((int)tochdr.cdth_trk0) << endl;
  cout << "Last  track: " << ((int)tochdr.cdth_trk1) << endl;


  for (int i=tochdr.cdth_trk0 ; i<=tochdr.cdth_trk1 ; i++)
    {
      struct cdrom_tocentry tocentry;

      tocentry.cdte_track  = i;
      tocentry.cdte_format = CDROM_MSF;

      if (ioctl(d_fd,CDROMREADTOCENTRY,&tocentry)==-1)
	{ perror("read CDROM toc entry: "); throw "error reading CDROM toc entry"; }

      cout << "track:  " << ((int)tocentry.cdte_track) << endl
	   << "adr:    " << ((int)tocentry.cdte_adr) << endl
	   << "ctrl:   " << ((int)tocentry.cdte_ctrl) << endl
	   << "format: " << ((int)tocentry.cdte_format) << endl
	   << " min:   " << ((int)tocentry.cdte_addr.msf.minute) << endl
	   << " sec:   " << ((int)tocentry.cdte_addr.msf.second) << endl
	   << " frame: " << ((int)tocentry.cdte_addr.msf.frame) << endl
	   << "datamode: " << ((int)tocentry.cdte_datamode) << endl;

      cout << endl;
    }
#endif

  SkipToTrack(2);
}

int  StreamSource_VCD::AskNTracks() const
{
  return d_nTracks;
}


int  StreamSource_VCD::AskCurrentTrack() const
{
  NotImplemented;
}


void StreamSource_VCD::SkipToTrack(int track)
{
  d_entry.cdte_format = CDROM_MSF;
  d_entry.cdte_track  = track+1;
  if (ioctl(d_fd, CDROMREADTOCENTRY, &d_entry)) {
    perror("ioctl dif1");
    return;
  }       
}


uint32 StreamSource_VCD::FillBuffer(uint8* mem,uint32 maxlen)
{
  if (d_buflen!=0)
    {
      int size = min(maxlen,d_buflen);
      memcpy(mem,&d_buf[d_bufidx],size);
      d_buflen -= size;
      d_bufidx += size;
      return size;
    }
  else
    {
      memcpy(d_buf,&d_entry.cdte_addr.msf,sizeof(struct cdrom_msf));
      ioctl(d_fd,CDROMREADRAW,d_buf);

      d_entry.cdte_addr.msf.frame++;
      if (d_entry.cdte_addr.msf.frame==75)
        {                     
          d_entry.cdte_addr.msf.frame=0;
          d_entry.cdte_addr.msf.second++;
        }                     
      if (d_entry.cdte_addr.msf.second==60)
        {                     
          d_entry.cdte_addr.msf.second=0;
          d_entry.cdte_addr.msf.minute++;
        }

      if (maxlen>=2324)
        {
          memcpy(mem,&d_buf[24],2324);
          return 2324;
        }
      else
        {
          memcpy(mem,&d_buf[24],maxlen);
          d_bufidx = 24+maxlen;
          d_buflen = 2324-maxlen;
          return maxlen;
        }
    }
}


bool   StreamSource_VCD::MoreDataPending() const
{
  // TODO
  return true;
}


uint64 StreamSource_VCD::AskStreamLength() const
{
  // TODO
  return 0;
}


uint64 StreamSource_VCD::AskCurrentPosition() const
{
  // TODO
  return 0;
}


uint64 StreamSource_VCD::SetCurrentPosition(uint64 pos)
{
  // TODO
  return pos;
}

--- NEW FILE: streamsrc_linux_vcd.hh ---
/********************************************************************************
  input/streamsrc_linux_vcd.hh

  purpose:
    A stream source that reads data directly from a VideoCD.

  notes:
    This code is Linux specific!

  to do:
   - This is alpha stage code!

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

  modifications:
   ??/???/1999 - 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 INPUT_STREAMSRC_LINUX_VCD_HH
#define INPUT_STREAMSRC_LINUX_VCD_HH

extern "C" {
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
#include <linux/cdrom.h>
}

#include "input/streamsrc.hh"
#include <iostream.h>



class StreamSource_VCD : public StreamSource
{
public:
  StreamSource_VCD();
  ~StreamSource_VCD();


  // VCD specific methods

  void Init(const char* device="/dev/cdrom");
  int  AskNTracks() const;
  int  AskCurrentTrack() const;
  void SkipToTrack(int track);


  // overloaded methods

  uint32 FillBuffer(uint8* mem,uint32 maxlen);
  bool   MoreDataPending() const;
  
  bool   IsFiniteStream() const { return true; }
  uint64 AskStreamLength() const;
  
  bool   MaySeek() const { return false; } // TODO: of course seeking should be possible.
  uint64 AskCurrentPosition() const;
  uint64 SetCurrentPosition(uint64);

private:
  int d_fd;
  int d_nTracks;
  struct cdrom_tocentry d_entry;

  uint8  d_buf[2352];
  uint32 d_bufidx;
  uint32 d_buflen;
};

#endif

--- NEW FILE: streamsrc_cin.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 "input/streamsrc_cin.hh"
#include "error.hh"

#include <iostream.h>


StreamSource_cin::StreamSource_cin()
{
}


StreamSource_cin::~StreamSource_cin()
{
}


uint32 StreamSource_cin::FillBuffer(uint8* mem,uint32 maxlen)
{
  cin.read(mem,maxlen);
  return cin.gcount();
}


bool StreamSource_cin::MoreDataPending() const
{
  return !cin.eof();
}


uint64 StreamSource_cin::AskStreamLength() const
{
  return (uint64)(-1);
}


uint64 StreamSource_cin::AskCurrentPosition() const
{
  return cin.tellg();
}


uint64 StreamSource_cin::SetCurrentPosition(uint64 pos)
{
  cin.seekg(pos);
  return pos;
}

--- NEW FILE: streamsrc_istr.hh ---
/********************************************************************************
  input/streamsrc_istr.hh

  purpose:
    A stream source that reads data out of a C++ "istream".

  notes:

  to do:

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

  modifications:
   ??/???/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 INPUT_STREAMSRC_ISTR_HH
#define INPUT_STREAMSRC_ISTR_HH

#include "input/streamsrc.hh"


class StreamSource_IStream : public StreamSource
{
public:
   StreamSource_IStream();
  ~StreamSource_IStream();

  void SetIStream(class istream& istr) { d_istr = &istr; }

  uint32 FillBuffer(uint8* mem,uint32 maxlen);
  bool   MoreDataPending() const;
  
  bool   IsFiniteStream() const { return true; }
  uint64 AskStreamLength() const;
  
  bool   MaySeek() const { return true; }
  uint64 AskCurrentPosition() const;
  uint64 SetCurrentPosition(uint64);

private:
  class istream* d_istr;
};

#endif




More information about the dslinux-commit mailing list