...
|
...
|
@@ -3,6 +3,8 @@ |
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
|
#include <pthread.h>
|
|
|
#include <time.h>
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
#include "JZsdkLib.h"
|
...
|
...
|
@@ -13,25 +15,35 @@ |
|
|
|
|
|
|
|
|
#ifdef RTK_MPP_STATUS_ON
|
|
|
|
|
|
#include "MediaProc/MultProc/RTK_mmp/RTK_mmp.h"
|
|
|
#include "MediaProc/Camera/Cam_FrameCatch/Cam_FrameCatch.h"
|
|
|
#include "MediaProc/MediaParm.h"
|
|
|
#include "MediaProc/MultProc/RTK_mmp/Dec/RTK_mmp_dec.h"
|
|
|
#include "MediaProc/MultProc/RTK_mmp/Enc/RTK_mmp_enc.h"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef MEDIA_PROC_CONFIG_STATUS_ON
|
|
|
|
|
|
#include "MediaProc/Camera/Cam_FrameCatch/Cam_FrameCatch.h"
|
|
|
#include "MediaProc/MediaParm.h"
|
|
|
#include "MediaProc/VideoMgmt/VideoStreamPush/VideoStream_Push.h"
|
|
|
#include "MediaProc/VideoMgmt/VideoMgmt.h"
|
|
|
#include "MediaProc/IRC_funtion/IRC_Param.h"
|
|
|
#include "MediaProc/IRC_funtion/IRC_funtion.h"
|
|
|
#include "MediaProc/MediaProc_Param.h"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
static void *g_usb_index = NULL;
|
|
|
|
|
|
// 定义 昆腾的 帧头长度和帧头内容
|
|
|
#define FRAME_HEADER_SIZE 4
|
|
|
static const unsigned char FRAME_HEADER[FRAME_HEADER_SIZE] = {0xaa, 0xbb, 0xcc, 0xdd};
|
|
|
#define NSEC_PER_SEC 1000000000L //1秒的纳秒数
|
|
|
#define TARGET_FPS 30
|
|
|
|
|
|
static unsigned char FrameBuffer[FIRST_HEIGHT * FIRST_WIDTH *2]; //用于存储帧数据的缓冲区
|
|
|
static unsigned int FrameBufferLen = 0; //用于存储帧数据的长度
|
|
|
static FrameBuffer_UseFlag = JZ_FLAGCODE_OFF;
|
|
|
|
|
|
|
|
|
//数据推送函数
|
...
|
...
|
@@ -48,6 +60,7 @@ static T_JZsdkReturnCode JZC1_PushFrame(int CameraIndex, unsigned char* data, un |
|
|
//红外相机
|
|
|
if (currentIndex == 1 && CameraIndex == 1)
|
|
|
{
|
|
|
|
|
|
//推送数据到流转模块
|
|
|
VideoMgmt_Single_FrameIn(data, data_len);
|
|
|
}
|
...
|
...
|
@@ -58,7 +71,6 @@ static T_JZsdkReturnCode JZC1_PushFrame(int CameraIndex, unsigned char* data, un |
|
|
//推送数据到流转模块
|
|
|
VideoMgmt_Single_FrameIn(data, data_len);
|
|
|
}
|
|
|
|
|
|
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -113,7 +125,12 @@ static T_JZsdkReturnCode JZC1_Irc_DataCorrect(unsigned char *data) |
|
|
static T_JZsdkReturnCode JZC1_IrcDeal(unsigned char *data, unsigned int data_len)
|
|
|
{
|
|
|
//JZSDK_LOG_DEBUG("irc数据处理");
|
|
|
|
|
|
if (data_len == 0)
|
|
|
{
|
|
|
JZSDK_LOG_ERROR("无数据错误");
|
|
|
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
|
|
|
}
|
|
|
|
|
|
//红外数据纠正处理
|
|
|
JZC1_Irc_DataCorrect(data);
|
|
|
|
...
|
...
|
@@ -121,6 +138,8 @@ static T_JZsdkReturnCode JZC1_IrcDeal(unsigned char *data, unsigned int data_len |
|
|
U16_t * u16Data = (U16_t *)malloc(sizeof(U16_t) * (data_len / 2));
|
|
|
int u16DataSize = data_len / 2;
|
|
|
|
|
|
//JZSDK_LOG_DEBUG("data_len:%d u16DataSize:%d", data_len / 2, FIRST_HEIGHT * FIRST_WIDTH);
|
|
|
|
|
|
//合成像素,u8转换合并成u16
|
|
|
JZsdk_Merge_U8_to_U16_byReverse(data, data_len, u16Data, &u16DataSize);
|
|
|
|
...
|
...
|
@@ -168,6 +187,83 @@ static T_JZsdkReturnCode JZC1_IrcDeal(unsigned char *data, unsigned int data_len |
|
|
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
|
|
}
|
|
|
|
|
|
static void *JZC1_IrcDataBuffer_Thread(void *args)
|
|
|
{
|
|
|
|
|
|
struct timespec now;
|
|
|
|
|
|
//获取起始时间
|
|
|
struct timespec start_time;
|
|
|
clock_gettime(CLOCK_MONOTONIC, &start_time);
|
|
|
long long prev_time = start_time.tv_sec * NSEC_PER_SEC + start_time.tv_nsec;
|
|
|
|
|
|
//设置间隔时间
|
|
|
long long period = NSEC_PER_SEC / TARGET_FPS;
|
|
|
|
|
|
unsigned char *TempBuffer = (unsigned char *)malloc(163840);
|
|
|
unsigned int TempBufferLen = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
{
|
|
|
//获取当前时间
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
long long current_time = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
|
|
|
|
|
|
//计算时间差
|
|
|
long long elapsed_time = current_time - prev_time;
|
|
|
|
|
|
//超过33ms
|
|
|
if (elapsed_time >= period)
|
|
|
{
|
|
|
while (FrameBuffer_UseFlag == JZ_FLAGCODE_ON)
|
|
|
{
|
|
|
delayUs(100);
|
|
|
}
|
|
|
|
|
|
FrameBuffer_UseFlag = JZ_FLAGCODE_ON;
|
|
|
|
|
|
memset(TempBuffer, 0, sizeof(TempBuffer));
|
|
|
memcpy(TempBuffer, FrameBuffer, FrameBufferLen);
|
|
|
TempBufferLen = FrameBufferLen;
|
|
|
|
|
|
FrameBuffer_UseFlag = JZ_FLAGCODE_OFF;
|
|
|
|
|
|
//红外数据缓冲线程
|
|
|
JZC1_IrcDeal(TempBuffer, TempBufferLen);
|
|
|
|
|
|
prev_time = current_time;
|
|
|
}
|
|
|
|
|
|
// 为了防止过于频繁地调用 clock_gettime,可以添加一个小的睡眠时间
|
|
|
// 例如,休眠1毫秒(100000000纳秒),以减少CPU占用
|
|
|
struct timespec req = { .tv_sec = 0, .tv_nsec = 1000000 };
|
|
|
nanosleep(&req, NULL);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
static T_JZsdkReturnCode JZC1_IrcDataSave(unsigned char *data, unsigned int data_len)
|
|
|
{
|
|
|
//避免缓冲区被同时操作
|
|
|
while (FrameBuffer_UseFlag == JZ_FLAGCODE_ON)
|
|
|
{
|
|
|
delayUs(100);
|
|
|
}
|
|
|
|
|
|
FrameBuffer_UseFlag = JZ_FLAGCODE_ON;
|
|
|
|
|
|
memset(FrameBuffer, 0, sizeof(FrameBuffer));
|
|
|
memcpy(FrameBuffer, data, data_len);
|
|
|
FrameBufferLen = data_len;
|
|
|
|
|
|
FrameBuffer_UseFlag = JZ_FLAGCODE_OFF;
|
|
|
|
|
|
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
|
|
}
|
|
|
|
|
|
//红外数据接收线程
|
|
|
static void *JZC1_IrcDataRecv_Thread(void *args)
|
|
|
{
|
...
|
...
|
@@ -245,7 +341,7 @@ static void *JZC1_IrcDataRecv_Thread(void *args) |
|
|
{
|
|
|
memcpy( &frameData[frameDataLen], buf, frame_len-frameDataLen );
|
|
|
|
|
|
JZC1_IrcDeal(frameData, frame_len);
|
|
|
JZC1_IrcDataSave(frameData, frame_len);
|
|
|
|
|
|
frame = 2;
|
|
|
frameDataLen = 0;
|
...
|
...
|
@@ -265,7 +361,7 @@ static void *JZC1_IrcDataRecv_Thread(void *args) |
|
|
|
|
|
//JZSDK_LOG_INFO("写入1 %d %x", i, frameData[20]);
|
|
|
|
|
|
JZC1_IrcDeal(frameData, frame_len);
|
|
|
JZC1_IrcDataSave(frameData, frame_len);
|
|
|
//JZSDK_LOG_INFO("放入数据到缓冲区");
|
|
|
//memset(frameData,0,sizeof(frameData));
|
|
|
}
|
...
|
...
|
@@ -282,7 +378,7 @@ static void *JZC1_IrcDataRecv_Thread(void *args) |
|
|
memcpy( &frameData[0], buf, frame_len);
|
|
|
|
|
|
//将未处理raw数据放入缓冲区
|
|
|
JZC1_IrcDeal(frameData, frame_len);
|
|
|
JZC1_IrcDataSave(frameData, frame_len);
|
|
|
//JZSDK_LOG_INFO("放入数据到缓冲区");
|
|
|
}
|
|
|
frame++;
|
...
|
...
|
@@ -317,17 +413,30 @@ static T_JZsdkReturnCode JZsdk_JZC1_Irc_Data_Init() |
|
|
pthread_attr_t task_attribute; //线程属性
|
|
|
pthread_attr_init(&task_attribute); //初始化线程属性
|
|
|
pthread_attr_setdetachstate(&task_attribute, PTHREAD_CREATE_DETACHED); //设置线程分离属性
|
|
|
int opus_Protection = pthread_create(&ReadDataTask,&task_attribute,JZC1_IrcDataRecv_Thread,NULL); //线程
|
|
|
if(opus_Protection != 0)
|
|
|
int Urcdata_Protection = pthread_create(&ReadDataTask,&task_attribute,JZC1_IrcDataRecv_Thread,NULL); //线程
|
|
|
if(Urcdata_Protection != 0)
|
|
|
{
|
|
|
JZSDK_LOG_ERROR("创建视频usb线程失败!");
|
|
|
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
|
|
|
}
|
|
|
|
|
|
//初始化送usb数据去处理的线程
|
|
|
pthread_t BufferDataTask;
|
|
|
pthread_attr_t BufferDataTask_attribute; //线程属性
|
|
|
pthread_attr_init(&BufferDataTask_attribute); //初始化线程属性
|
|
|
pthread_attr_setdetachstate(&BufferDataTask_attribute, PTHREAD_CREATE_DETACHED); //设置线程分离属性
|
|
|
int bufferdata_Protection = pthread_create(&BufferDataTask,&BufferDataTask_attribute,JZC1_IrcDataBuffer_Thread,NULL); //线程
|
|
|
if(bufferdata_Protection != 0)
|
|
|
{
|
|
|
JZSDK_LOG_ERROR("创建usb缓冲失败!");
|
|
|
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
|
|
|
}
|
|
|
|
|
|
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
|
|
}
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
//JZ_C1 的媒体初始化
|
|
|
static T_JZsdkReturnCode JZC1_MediaInit()
|
...
|
...
|
@@ -344,7 +453,7 @@ static T_JZsdkReturnCode JZC1_MediaInit() |
|
|
//初始化Mulit模块
|
|
|
#ifdef RTK_MPP_STATUS_ON
|
|
|
//初始化红外的编解码器
|
|
|
RTK_mmp_enc_Init(JZsdk_RtkMmpGetEncHandleAddr(0), MPP_VIDEO_CodingAVC, MPP_FMT_YUV420P, FIRST_WIDTH, FIRST_HEIGHT, 25, 5);
|
|
|
RTK_mmp_enc_Init(JZsdk_RtkMmpGetEncHandleAddr(0), MPP_VIDEO_CodingAVC, MPP_FMT_YUV420P, FIRST_WIDTH, FIRST_HEIGHT, 30, 5);
|
|
|
|
|
|
//初始化光学的编解码器
|
|
|
RTK_mmp_dec_Init(JZsdk_RtkMmpGetDecHandleAddr(1), MPP_VIDEO_CodingMJPEG, MPP_FMT_YUV420SP, SECOND_WIDTH, SECOND_HEIGHT);
|
...
|
...
|
|