#ifndef __CCRECEIVER_H
#define __CCRECEIVER_H

#define TS_SIZE       188
#define PAY_START     0x40
#define ADAPT_FIELD   0x20
#define PAYLOAD       0x10
#define PTS_DTS_FLAGS 0xC0

#define READ_BUFFER 5000

#include <vdr/thread.h>
#include <vdr/receiver.h>

#include "ccextractor.h"
#include "commons.h"

class cCcReceiver : public cReceiver, public cThread {
public:
  //cCcReceiver(int Ca, int Vpid);
  cCcReceiver(int Ca, int Vpid, int Apid[], int Dpid[]);
  virtual ~cCcReceiver();
  CC_Data *GetCC();
  
protected:
	bool StoreStream(byte *data, int len);
	int GetUserData(byte *store);
	
  virtual void Activate(bool On);
  virtual void Receive(uchar *Data, int Length);
  virtual void Action(void);  
  
private:
  int   m_VideoPid;
  bool  m_Active;
  cCCExtractor *m_parser;
  int	m_lastPacketSize;
  
  cMutex m_Mutex;
  cMutex m_Mutex_Data;
  
  byte m_queue[READ_BUFFER];
  int m_queue_size;
};

#endif //__CCRECEIVER_H
