dvbpsi.h 6.47 KB
Newer Older
1 2 3 4
/*******************************************************************************
* dvbpsi.h: common tools to use the libdvbpsi
*-------------------------------------------------------------------------------
* (c)1999-2002 VideoLAN
5
* $Id: dvbpsi.h,v 1.4 2003/08/14 17:20:36 adq Exp $
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
*
* 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 _DVBPSI_H_
#define _DVBPSI_H_


//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------
#define DVBPSI_EVENT_NEXT       (1 << 0)
#define DVBPSI_EVENT_CURRENT    (1 << 1)


39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
//------------------------------------------------------------------------------
// C_DvbPsiTable
//------------------------------------------------------------------------------
class C_DvbPsiTable
{
public:
  C_DvbPsiTable();
  virtual ~C_DvbPsiTable();

  // TS Generation
  virtual void Generate() = 0;
  void TsReset();
  bool TsHasNext();
  void TsWrite(C_TsPacket *pPacket);

protected:
  u16 m_iPid;
  dvbpsi_psi_section_t *m_pSections;

private:
  dvbpsi_psi_section_t *m_pCurrentSection;
  byte *m_pPosInSection;
  u8 m_iContinuityCounter;
};


65 66 67
//------------------------------------------------------------------------------
// C_DvbPsiPat
//------------------------------------------------------------------------------
68
class C_DvbPsiPat : public C_DvbPsiTable
69 70 71 72 73 74 75 76
{
public:
  // Base constructor
  C_DvbPsiPat(u16 iTsId, u8 iVersion, bool bCurrentNext);
  // Low level constructor
  C_DvbPsiPat(dvbpsi_pat_t* pPat);

  C_DvbPsiPat(const C_DvbPsiPat& cPat);
77
  virtual ~C_DvbPsiPat();
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

  void BuildFromNext(C_DvbPsiPat *pNextPat);

  bool CurrentNext() const
  {
    return m_sPat.b_current_next;
  };

  // Low level access
  dvbpsi_pat_t* GetLowLevelPat()
  {
    return &m_sPat;
  };

  dvbpsi_pat_program_t* GetProgram(u16 iNumber) const;

  // (A - B) == (A - intersection(A, B))
  C_DvbPsiPat operator - (const C_DvbPsiPat& cPat) const;
  C_DvbPsiPat& operator = (const C_DvbPsiPat& cPat);

  // PAT generation
99
  virtual void Generate();
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

protected:
private:
  dvbpsi_pat_t m_sPat;
};


//------------------------------------------------------------------------------
// I_DvbPsiPatHandler
//------------------------------------------------------------------------------
class I_DvbPsiPatHandler
{
public:
  I_DvbPsiPatHandler();
  virtual ~I_DvbPsiPatHandler();

  void HandlePat(C_DvbPsiPat* pPat);

protected:
  virtual void OnDvbPsiPatEvent(int iEvent) = 0;

  C_DvbPsiPat *m_pPreviousPat;
  C_DvbPsiPat *m_pCurrentPat;
  C_DvbPsiPat *m_pNextPat;

private:
};


//------------------------------------------------------------------------------
// C_DvbPsiPatDecoder
//------------------------------------------------------------------------------
class C_DvbPsiPatDecoder : public I_TsPacketHandler
{
public:
  C_DvbPsiPatDecoder(C_NetList *pTsProvider, I_DvbPsiPatHandler *pHandler);

  void Attach();
  void Detach();

140
  virtual bool HandlePacket(C_TsPacket* pPacket);
141 142 143 144
  virtual bool HandlePrefillPacket(C_TsPacket* pPacket) { return false; }
  virtual void Shutdown() {}
  virtual void PrefillStart() {}
  virtual void PrefillComplete() {}
145 146 147 148 149 150 151 152 153 154 155 156 157
private:
  static void Callback(C_DvbPsiPatDecoder *pThis, dvbpsi_pat_t* p_new_pat);

  C_NetList *m_pTsProvider;
  I_DvbPsiPatHandler *m_pHandler;

  dvbpsi_handle m_hDvbPsi;
};


//------------------------------------------------------------------------------
// C_DvbPsiPmt
//------------------------------------------------------------------------------
158
class C_DvbPsiPmt : public C_DvbPsiTable
159 160 161
{
public:
  // Base constructor
162 163
  C_DvbPsiPmt(u16 iProgramNumber, u8 iVersion, bool bCurrentNext, u16 iPcrPid,
              u16 iPid = 0);
164 165 166 167
  // Low level constructor
  C_DvbPsiPmt(dvbpsi_pmt_t* pPmt);

  C_DvbPsiPmt(const C_DvbPsiPmt& cPmt);
168
  virtual ~C_DvbPsiPmt();
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188

  void BuildFromNext(C_DvbPsiPmt *pNextPmt);

  bool CurrentNext() const
  {
    return m_sPmt.b_current_next;
  };

  // Low level access
  dvbpsi_pmt_t* GetLowLevelPmt()
  {
    return &m_sPmt;
  };

  dvbpsi_pmt_es_t* GetEs(u16 iPid) const;

  // (A - B) == (A - intersection(A, B))
  C_DvbPsiPmt operator - (const C_DvbPsiPmt& cPmt) const;
  C_DvbPsiPmt& operator = (const C_DvbPsiPmt& cPmt);

189 190 191
  // PMT generation
  virtual void Generate();

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
protected:
private:
  dvbpsi_pmt_t m_sPmt;
};


//------------------------------------------------------------------------------
// I_DvbPsiPmtHandler
//------------------------------------------------------------------------------
class I_DvbPsiPmtHandler
{
public:
  I_DvbPsiPmtHandler();
  virtual ~I_DvbPsiPmtHandler();

  void HandlePmt(C_DvbPsiPmt* pPmt);

protected:
  virtual void OnDvbPsiPmtEvent(int iEvent) = 0;

  C_DvbPsiPmt *m_pPreviousPmt;
  C_DvbPsiPmt *m_pCurrentPmt;
  C_DvbPsiPmt *m_pNextPmt;

private:
};


//------------------------------------------------------------------------------
// C_DvbPsiPmtDecoder
//------------------------------------------------------------------------------
class C_DvbPsiPmtDecoder : public I_TsPacketHandler
{
public:
  C_DvbPsiPmtDecoder(u16 iProgramNumber,
                     C_NetList *pTsProvider,
                     I_DvbPsiPmtHandler *pHandler);

  void Attach();
  void Detach();

233
  virtual bool HandlePacket(C_TsPacket* pPacket);
234
  virtual bool HandlePrefillPacket(C_TsPacket* pPacket) { return false; }
235
  virtual void Shutdown() {}
236 237
  virtual void PrefillStart() {}
  virtual void PrefillComplete() {}
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

private:
  static void Callback(C_DvbPsiPmtDecoder *pThis, dvbpsi_pmt_t* p_new_pmt);

  u16 m_iProgramNumber;
  C_NetList *m_pTsProvider;
  I_DvbPsiPmtHandler *m_pHandler;

  dvbpsi_handle m_hDvbPsi;
};


#else
#error "Multiple inclusions of dvbpsi.h"
#endif