#ifndef VDR_EM84XX_THREAD_H
#define VDR_EM84XX_THREAD_H

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

#include <stdint.h>
#include <fmp.h>

class cDeviceEm84xx;

class cThreadEm84xx: public cThread {
private:
	enum em84MsgType {
		em84VideoPacket,
		em84AudioPacket,
		em84StillPicture,
		em84TrickMode,
		em84Pause,
		em84Play
	};
	
	enum em84ThreadState
	{
		em84Playing,
		em84Paused,
		em84Trickmode
	};
		
	struct em84MsgHeader {
		uint16_t msgtype;
		uint16_t msglen;
	};

	bool       mActive;
	int        mPipe[2];

	cDeviceEm84xx* mEm84Device;

protected:
	virtual void Action(void);
	
public:
	cThreadEm84xx(cDeviceEm84xx* Em84Device);
	virtual ~cThreadEm84xx();

	int PlayPacket(const uchar *Data, int Length, bool isAudio);
	int StillPicture(const uchar *Data, int Length);
	void TrickSpeed(int Speed);
	void Play(void);
	void Freeze(void);

	int mLastMsgType;
	void AddPoller(cPoller &Poller);

	void Start(void);
	void Stop(void);
};

#endif // VDR_EM84XX_THREAD_H
