#pragma once

#include "frameinfo.h"
#include "filereader.h"
#include "global_data.h"
#include "worker_thread.h"
#include "../thirdparty/mqtt/cmd_transport_mqtt.h"

#include <string>

class RebuildManager : public ZCWorkThread, public TransportObserver
{
public:
	RebuildManager();
	~RebuildManager();

	bool Init();

	bool ConnectMqttServer();
	void DisConnectMqttServer();
	int Connected() { return m_nMqttSuccess; }

	bool OpenMediaFile();
	void CloseMediaFile();

	bool StartPull();
	void StopPull();

	bool EndOfFile();

private:

	virtual void DoRunning();

	//
	// TransportObserver
	//
	virtual void OnConnectServerSuccess(bool success);
	virtual void OnSubscribeTopicSuccess(bool success);
	virtual void OnReceiveMessage(std::string message);

private:
	void ParseNaluBySize(AVPacket &pkt);
	void ParseNaluByAvcc(AVPacket &pkt);
	void ParseNaluByAnnexB(AVPacket &pkt);
	void AddOnePacket(AVPacket &pkt, uint8_t *buffer, size_t size);
	int Delete0x03FromNalu(uint8_t* src, uint8_t*dst, int src_length);
	bool GetWhiteBoardData(AVPacket &pkt, CFrameInfo &frameInfo);

private:
	void CallBackWhiteBoardData(AVPacket &pkt);

private:
	GlobalData m_configData;

private:
	CmdTransportMqtt *m_pMqtt;
	int	m_nMqttSuccess;

private:
	CFileReader	m_fileReader;
};