#ifndef _PVR_READER_H_
#define _PVR_READER_H_

#include "common.h"

class cPvrReadThread : public cThread {
private:
  cPvrDevice* parent;
  bool active;
  bool stop;
  int video_fd;
  cRingBufferLinear * tsBuffer;
  cMutex * mutex;

  uint8_t  ts_buffer[188];
  uint8_t  video_counter;
  uint8_t  audio_counter;
  uint8_t  text_counter;
  uint8_t  pes_buffer[64 * 1024];
  uint8_t  pes_stream_id;
  uint32_t pes_offset;
  uint32_t pes_length;
  uint32_t pes_tmp;

  void ParseProgramStream(uint8_t * Data, uint32_t Length);
  void PesToTs(uint8_t * Data, uint32_t Length);
  int  PutData(const unsigned char * Data, int Count);
protected:
  virtual void Action(void);
public:
  cPvrReadThread(int VideoDevice, cRingBufferLinear * TsBuffer,\
                 cMutex * Mutex, cPvrDevice* _parent);
  virtual ~cPvrReadThread(void);
};


#endif
