You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.0 KiB

#ifndef DECODEDATA_H
#define DECODEDATA_H
#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include <mutex>
#include "H264_SEI_typedef.h"
//#include "./stitch_lib/include/StitchStruct.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "./libavformat/avformat.h"
#include "./libswscale/swscale.h"
#include "./libavutil/opt.h"
#include "./libavutil/imgutils.h"
#include "./libavutil/time.h"
#include "./libavutil/avutil.h"
#ifdef __cplusplus
}
#endif
#include "API_FrontStitch.h"
#define UDP_BUFFER_LENGTHIMG 1024
#define UDPIMGWIDTH 1920
#define UDPIMGHEIGHT 1080
typedef struct tagUdpParam
{
uint32_t nFrameNum;
uint32_t nPackNum;
uint32_t nPackIndex;
uint32_t nDataSize;
}UdpParam;
typedef struct tagFRAME_LIST_ELEMENT
{
uint32_t FrameID;
uint8_t *pFrameInfo;
uint32_t len;
} FRAME_LIST_ELEMENT, *PFRAME_LIST_ELEMENT;
class DecodeData
{
public:
DecodeData();
//读取文件
// 二进制分包读取文件函数使用char*作为缓冲区)
// 参数: filename - 文件名, chunkSize - 每个包的大小(字节), startPos - 开始读取的位置, buffer - 接收数据的缓冲区
// 返回值: 实际读取的字节数, 0表示读取失败或已到文件末尾
size_t readFileChunk(const std::string& filename, size_t chunkSize, std::streamoff& startPos, char* buffer);
void processFileInChunks(const std::string& filename, size_t chunkSize);
void DealWithUDPData(char *Buffer, int Length);
void processData(char*cH264Data, int iLength);
void Init();
void UnInit();
int InitDecode();
int DecodeRGBImageAndPara(unsigned char *RGBBuffer,H264SEI_Para_732 SEIdata,int nwidth,int nHeight);
//void getPanoSourceData(unsigned char *dst, unsigned char *src);
void getPanoSourceData(uchar *dst, uchar *src,int w,int h);
public:
int m_CurrentVideo = 1; //0:红外1可见光
int m_LocalHeight = 0;
int m_FrameNo = 0;
int32_t m_nWidth;
int32_t m_nHeight;
uint8_t *m_cUDPBuffer =NULL;
int m_iUDPPoint=0;
int m_iUDPState=0;
int m_nPos=0;
uint32_t m_iImgPacketLen;
uint32_t m_iImgPacketLenTest;
long m_lIndex = 0;
long m_lLostNum = 0;
std::mutex m_UDPdataMutex;
std::list<FRAME_LIST_ELEMENT*> ImageCapQueue;
uint8_t * m_cDecodeBuffer;
long m_lDecodePoint=0;
int m_nRes = 0;
//实时流相关
AVDictionary* m_pFmtOpts;
AVDictionary* m_pCodecOpts;
AVFormatContext* m_pFmtCtx;
AVCodecContext* m_pCodecCtx;
AVPacket* m_pPacket;
AVFrame* m_pFrame;
int m_nVideoStreamIndex;
int m_nAudioStreamIndex;
int m_nSubtitleStreamIndex;
AVCodec* m_pVideoCodec;
int m_nVideoTimeBaseNum;
int m_nVideoTimeBaseDen;
AVPixelFormat m_emPixFmtSrc;
AVPixelFormat m_emPixFmtDst;
SwsContext* m_pSwsCtx;
uint8_t* m_pArrayData[4];
int m_nArrayLinesize[4];
H264SEI_Para_732 SEI_Data = {0};
bool s_bFFMpegInit; //ffmpeg是否初始化
unsigned char* m_pBuffer; //用户格式的数据指针
unsigned char* m_pBufferIR; //用户格式的数据指针
//设备数据处理
bool m_bDataThreadRunning;
std::thread* m_ptrThread_DataDealwith;
typedef void (DecodeData::*ThreadRunFunPtr)();
static void ThreadEntry(ThreadRunFunPtr pRunFun, void* pOwner);
void ThreadFunData(); //数据处理
void DecodeUDPData(uint8_t *cData, long lLength);
void DecodeH264Data(uint8_t *h264Data, long dataLength);
API_FrontStitch* m_frontStitcher;
};
#endif // DECODEDATA_H