

#ifndef LIVE_FRAME_SOURCE_HH_
#define LIVE_FRAME_SOURCE_HH_

/*#ifdef __cplusplus
#define __STDINT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
*/
#ifndef _USAGE_ENVIRONMENT_HH
#include "UsageEnvironment.hh"
#endif
//#include <iostream>
//#include <concurrent_queue.h>
//#include <queue>
#ifndef _FRAMED_SOURCE_HH
#include "FramedSource.hh"
#endif
#include<time.h>

#include <iostream>       // std::cout
#include <thread>         // std::thread
#include <mutex>
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include<semaphore.h>
#include<fcntl.h>
#include<sys/stat.h>

//#define RTP_PACKET_TTL 256
typedef struct ll
{
        unsigned char *Framedata;
        unsigned framesize;
        struct timeval PresentationTime;
        uint64_t frameArrivalTime;
}QUEUE;


#define MAX_BUFFER_VIDEO 			(50)
#define MAX_FRAME_SIZE_VIDEO		(1024*1024)
//#define CLOCK_FREQ_90KHZ    90000
//#define MILLION				1000000


class LiveSourceWithx264: public FramedSource {
public:
	std::string streamName;
    static LiveSourceWithx264* createNew(UsageEnvironment& env,void *livesession);
    EventTriggerId eventTriggerId;
    void LiveStream_cameraFrameData(unsigned char* mFrameByte, unsigned mFrameSize, struct timeval mPresentationTime,uint64_t timeStamp);
	void stopLiveFrameSources();
//    void normalizePresentationTime(struct timeval& toPT, struct timeval const& fromPT);
    static void deliverFrame0(void* clientData);
	uint64_t getSystemDateTimeInMS(void);
	TaskScheduler* m_plive555TaskScheduler = NULL;
protected:
    LiveSourceWithx264(UsageEnvironment& env,void *livesession);
    virtual ~LiveSourceWithx264(void);
private:

    void doGetNextFrame();    
    void deliverFrame();
//    void encodeNewFrame();
 //   void signalNewFrameData();
    static unsigned referenceCount;
    bool isContinue;
    void *videoLiveSession;
	std::mutex mtx;
	QUEUE *head;
	std::queue<QUEUE> camQueue;
	sem_t *waitForFrame;
	uint32_t frameTimeDiffDuration = 0;
	uint64_t prevSystemTime = 0;
	uint64_t currSystemTime = 0;
	int frameCounter = 0;

    // videoCaptureDevice is my BGR data source. You can have according to your need
};
#endif
