#ifndef _PVR_DEVICE_H_
#define _PVR_DEVICE_H_

#include <vdr/device.h>

class cPvrReadThread;

class cPvrDevice : public cDevice
{
private:
	static bool Probe(int DeviceNumber);
public:
	static bool Initialize(void);
	static void ReInitAll(void);
	static int Count();
	static cPvrDevice * Get(int index);
private:
	int number;
	int video_fd;
	int radio_fd;
	int vbi_fd;
	int tunerInput;
	int frequency;
	int vpid;
	int apid;
	int tpid;
	int lastNorm;
	int lastInput;
	bool dvrOpen;
	uint64_t dvrOpenTime;
	
	cRingBufferLinear * tsBuffer;
	cPvrReadThread * readThread;
	bool delivered;
	cMutex mutex;

protected:
	virtual bool SetChannelDevice(const cChannel *Channel, bool LiveView);
	virtual bool SetPid(cPidHandle *Handle, int Type, bool On);
	virtual bool OpenDvr(void);
	virtual void CloseDvr(void);
	virtual bool GetTSPacket(uchar *&Data);
public:
	cPvrDevice(int DeviceNumber);
	virtual ~cPvrDevice(void);
	virtual int ProvidesCa(const cChannel *Channel) const;
	virtual bool ProvidesSource(int Source) const;
	virtual bool ProvidesTransponder(const cChannel *Channel) const;
	virtual bool ProvidesChannel(const cChannel *Channel, int Priority = -1, bool *NeedsDetachReceivers = NULL) const;
	void ReInit(void);

	bool Tune(int frequency);
	bool SetInput(int input);
	bool SetVideoNorm(int norm);
	bool SetVideoSize(int width, int height);
	bool SetCodec(void);
	bool SetPicture(int brightness, int contrast, int saturation, int hue);
	bool SetVolume(int volume);
};

#endif
