stream.h
author nathan
Sun, 06 Dec 2009 08:48:57 +0800
branchtrunk
changeset 34 afc13760179b
parent 0 474a1293c3c0
permissions -rw-r--r--
fixed gcc 4.4.1 const errors
nathan@0
     1
/*
nathan@0
     2
 * MP3/MPlayer plugin to VDR (C++)
nathan@0
     3
 *
nathan@34
     4
 * (C) 2001-2009 Stefan Huelswitt <s.huelswitt@gmx.de>
nathan@0
     5
 *
nathan@0
     6
 * This code is free software; you can redistribute it and/or
nathan@0
     7
 * modify it under the terms of the GNU General Public License
nathan@0
     8
 * as published by the Free Software Foundation; either version 2
nathan@0
     9
 * of the License, or (at your option) any later version.
nathan@0
    10
 *
nathan@0
    11
 * This code is distributed in the hope that it will be useful,
nathan@0
    12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nathan@0
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nathan@0
    14
 * GNU General Public License for more details.
nathan@0
    15
 *
nathan@0
    16
 * You should have received a copy of the GNU General Public License
nathan@0
    17
 * along with this program; if not, write to the Free Software
nathan@0
    18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
nathan@0
    19
 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
nathan@0
    20
 */
nathan@0
    21
nathan@0
    22
#ifndef ___STREAM_H
nathan@0
    23
#define ___STREAM_H
nathan@0
    24
nathan@0
    25
#include "decoder.h"
nathan@0
    26
nathan@0
    27
class cNet;
nathan@0
    28
nathan@0
    29
// ----------------------------------------------------------------
nathan@0
    30
nathan@0
    31
#if 0
nathan@0
    32
class cIO : public cFileInfo {
nathan@0
    33
protected:
nathan@0
    34
  bool log;
nathan@0
    35
  unsigned long long readpos;
nathan@0
    36
public:
nathan@0
    37
  cIO(const char *Filename, bool Log);
nathan@0
    38
  virtual ~cIO();
nathan@0
    39
  virtual bool Open(void)=0;
nathan@0
    40
  virtual void Close(void)=0;
nathan@0
    41
  virtual int Read(unsigned char *Data, int Size)=0;
nathan@0
    42
  virtual unsigned char *StreamInit(int Size) { return 0; }
nathan@0
    43
  virtual int Stream(const unsigned char *rest) { return -1; }
nathan@0
    44
  virtual bool Seek(unsigned long long pos, int whence) { return -1; }
nathan@0
    45
  virtual unsigned long long Tell(void) { return readpos; }
nathan@0
    46
  };
nathan@0
    47
nathan@0
    48
// ----------------------------------------------------------------
nathan@0
    49
nathan@0
    50
class cStreamIO {
nathan@0
    51
private:
nathan@0
    52
  int size, fill;
nathan@0
    53
  unsigned char *data;
nathan@0
    54
protected:
nathan@0
    55
  void StreamClear(bool all);
nathan@0
    56
public:
nathan@0
    57
  cStreamIO(void);
nathan@0
    58
  virtual ~cStreamIO();
nathan@0
    59
  virtual unsigned char *StreamInit(int Size);
nathan@0
    60
  virtual int Stream(const unsigned char *rest);
nathan@0
    61
  virtual int Read(unsigned char *Data, int Size)=0;
nathan@0
    62
  };
nathan@0
    63
nathan@0
    64
// ----------------------------------------------------------------
nathan@0
    65
nathan@0
    66
class cFileIO : public cIO, public cStreamIO {
nathan@0
    67
protected:
nathan@0
    68
  int fd;
nathan@0
    69
public:
nathan@0
    70
  cFileIO(const char *Filename, bool Log);
nathan@0
    71
  virtual ~cFileIO();
nathan@0
    72
  virtual bool Open(void);
nathan@0
    73
  virtual void Close(void);
nathan@0
    74
  virtual int Read(unsigned char *Data, int Size);
nathan@0
    75
  virtual bool Seek(unsigned long long pos, int whence);
nathan@0
    76
  };
nathan@0
    77
#endif
nathan@0
    78
nathan@0
    79
// ----------------------------------------------------------------
nathan@0
    80
nathan@0
    81
class cStream : public cFileInfo {
nathan@0
    82
private:
nathan@0
    83
  int fd;
nathan@0
    84
  bool ismmap;
nathan@0
    85
protected:
nathan@0
    86
  unsigned char *buffer;
nathan@0
    87
  unsigned long long readpos, buffpos;
nathan@0
    88
  unsigned long fill;
nathan@0
    89
public:
nathan@0
    90
  cStream(const char *Filename);
nathan@0
    91
  virtual ~cStream();
nathan@0
    92
  virtual bool Open(bool log=true);
nathan@0
    93
  virtual void Close(void);
nathan@0
    94
  virtual bool Stream(unsigned char *&data, unsigned long &len, const unsigned char *rest=NULL);
nathan@0
    95
  virtual bool Seek(unsigned long long pos=0);
nathan@0
    96
  virtual unsigned long long BufferPos(void) { return buffpos; }
nathan@0
    97
  };
nathan@0
    98
nathan@0
    99
// ----------------------------------------------------------------
nathan@0
   100
nathan@0
   101
class cNetStream : public cStream {
nathan@0
   102
private:
nathan@0
   103
  cNet *net;
nathan@0
   104
  char *host, *path, *auth;
nathan@0
   105
  int port, cc;
nathan@0
   106
  //
nathan@0
   107
  char *icyName, *icyUrl, *icyTitle;
nathan@0
   108
  int metaInt, metaCnt;
nathan@0
   109
  bool icyChanged;
nathan@0
   110
  //
nathan@0
   111
  bool ParseURL(const char *line, bool log);
nathan@0
   112
  bool ParseURLFile(const char *name, bool log);
nathan@0
   113
  bool SendRequest(void);
nathan@0
   114
  bool GetHTTPResponse(void);
nathan@0
   115
  bool ParseHeader(const char *buff, const char *name, char **value);
nathan@0
   116
  bool ParseMetaData(void);
nathan@34
   117
  char *ParseMetaString(char *buff, const char *name, char **value);
nathan@0
   118
public:
nathan@0
   119
  cNetStream(const char *Filename);
nathan@0
   120
  virtual ~cNetStream();
nathan@0
   121
  virtual bool Open(bool log=true);
nathan@0
   122
  virtual void Close(void);
nathan@0
   123
  virtual bool Stream(unsigned char *&data, unsigned long &len, const unsigned char *rest=NULL);
nathan@0
   124
  virtual bool Seek(unsigned long long pos=0);
nathan@0
   125
  bool Valid(void) { return ParseURLFile(Filename,false); }
nathan@0
   126
  const char *IcyName(void) const { return icyName; }
nathan@0
   127
  const char *IcyUrl(void) const { return icyUrl; }
nathan@0
   128
  const char *IcyTitle(void) const { return icyTitle; }
nathan@0
   129
  bool IcyChanged(void);
nathan@0
   130
  };
nathan@0
   131
nathan@0
   132
#endif //___STREAM_H