/***************************************************************************************
 *
 * output.h is part of SimpleSkyCam.
 *
 *****************************************************************************************/


#ifndef _OUTPUT_H_
#define _OUTPUT_H_

#include "gui.h"
#include "config.h"
#include "video.h"
#include "videoframe.h"
#include "ser.h"


#define OUTPUT_MODE_SER_STARTED		0x0001

class Output {
private:
	int running;
	VideoFrameRaw inFrame;		// input frame
	int inFrameNew;				// new input frame;
	GMutex muteximage;
	GMutex mutexin;
	GMutex mutextmp;			// for access the temp image
	GMutex mutex;				// general mutex for changing settings
	GThread *thread;
	unsigned int mode;			// see OUTPUT_MODE_ flags
	std::string outputfilename;	// current output

	void ComposeOutput();
	void NotifyGTK ();
	SER *outputser;
	int outputserw;			// to detect if the size
	int outputserh;			// changes white recording
	uint32_t outputserfmt;	//

public:
	Output();
	~Output();

	int NewFrame (VideoFrameRaw *rawframe);

	// Thread Releated Functions (maybe soon private?)
	int TryLockInMutex() { return g_mutex_trylock(&mutexin); };
	void LockInMutex() { g_mutex_lock(&mutexin);};
	void UnLockInMutex() { g_mutex_unlock(&mutexin);};

	int TryLockImageMutex() { return g_mutex_trylock(&muteximage); };
	void LockImageMutex() { g_mutex_lock(&muteximage);};
	void UnLockImageMutex() { g_mutex_unlock(&muteximage);};

	void LockMutex() { g_mutex_lock(&mutex);};
	void UnLockMutex() { g_mutex_unlock(&mutex);};

	//
	// Object functions
	void SetObjectSize (int neww, int newh);
	void SetObject (VideoFrame objFrame, int newx, int newy);
	void GetObjectPos (int *x, int *y);

	void SERStart(std::string destpath, std::string sufix);
	void SERStop();

	int GetStatus() { return mode; };

	void Thread();
};

#endif
