/*
 * pvr350device.h: 
 *
 * See the README file for copyright information and how to reach the author.
 *
 */

#ifndef __PVR350_DEVICE_H
#define __PVR350_DEVICE_H
#include <vdr/device.h>
#include <vdr/thread.h>
#include "pvr350osd.h"
#include "pvr350audio.h"

class cPvr350Device: public cDevice {
private:
	int		fd_out;
	int		fbfd;
	int		fh;
	int		storedglobalalpha;
	ulong		initglobalalpha;
	int		fb_bpp;
	int		fb_pixel_size;
	int		fb_line_len;
	int		fb_size;
	int		osdbufsize;
	uint8_t		*osdbuffer;
	uint8_t		*osdbuf_aligned;
	int		stride;
	int		output_mode;
	bool		Format16_9;

	ePlayMode	m_PlayMode;
	cSpuDecoder	*spuDecoder;

	/* Current sizes of the display */
	int		current_horiz;
	int		current_vertical;
	int		current_afd;
	int		sizechanged;
	int		wss_data;
	int		audiomode;

	int		lx, ly;
	int		width, height;

	bool		useV4L2ioctls;
	uint32_t	KernelVersion;
	uint8_t		m_PCMBuffer[PCM_BUFFER_SIZE];
	uint8_t		m_MP2PESBuffer[MP2_PES_BUFFER_SIZE];
	uint8_t		*m_PESHeader;
	uint8_t		*m_PESPacketData;
	cAC3toMP2	*m_AC3toMP2;
	bool		m_AC3toMP2Init;
	AC3DecodeState_t	m_AC3DecodeState;
	AC3DecodeState_t	*m_AC3DecodeStatePtr;

	void SetVidInfoV4L2(const uchar *mbuf, int count);
	void SetVidInfoIVTV(const uchar *mbuf, int count);
	void OpenV4L2();
	void OpenIVTV();
	void ProcessAC3Audio(uint8_t *PESPacket, int PESHeader_len, int Length);

public:
	cPvr350Device(void);
	~cPvr350Device();
	void MakePrimaryDevice(bool On);
	virtual bool HasDecoder(void) const;

	virtual bool CanReplay(void) const;
	virtual bool SetPlayMode(ePlayMode PlayMode);
	virtual void TrickSpeed(int Speed);
	virtual void Stop_Decode_Black(void);
	virtual void Start_Decode(void);
	virtual void Clear(void);
	virtual void Play(void);
	virtual void Freeze(void);
	virtual void Mute(void);
        virtual int GetAudioChannelDevice(void);
	virtual void SetAudioChannelDevice(int AudioChannel);
	virtual void StillPicture(const uchar *Data, int Length);
	virtual void StillPicture_VideoOnly(uchar *Data, int Length);
	virtual int PlayVideo(const uchar *Data, int Length);
	virtual int PlayAudio(const uchar *Data, int Length, uchar Id);
	virtual void SetVideoFormat(bool VideoFormat16_9);
	virtual void SetVolumeDevice(int Volume);
	virtual bool Poll(cPoller &Poller, int TimeoutMs = 0);
	virtual cSpuDecoder *GetSpuDecoder(void);
	virtual int64_t GetSTC(void);
	void SetVideoSize(int x, int y, int w, int d);
	void Set_wss_mode();
};
#endif
