#include "rtspservice.h"
#include "rtputils.h"
#include "ringfifo.h"
#include "sample_comm.h"
#include "loadbmp.h"
#include "GPS-INS/nacelle_uart_ctl.h"
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include
#include
#include
#include
#define SD_SAVE 1
extern int g_s32Quit ;
int g_udp_socket;
VIDEO_NORM_E gs_enNorm = VIDEO_ENCODING_MODE_PAL;
static pthread_t gs_VencPid;
pthread_t g_stRgnThread = 0;
pthread_t g_stOSDThread = 0;
static pthread_t gs_VdaPid[2];
#define SAMPLE_VDA_MD_CHN 0
static SAMPLE_VENC_GETSTREAM_PARA_S gs_stPara;
extern float g_xG,g_yG,g_zG,g_x_angspeed,g_y_angspeed,g_z_angspeed,g_xclj,g_yclj,g_zclj,g_pitch,g_roll,g_heading_ang;
extern double g_lng,g_lat;//
extern char g_lng_flag,g_lat_flag;
extern int g_nace_fd,g_msg_fd,g_sins_gps_fd;
typedef struct hiRGN_SIZE_S
{
HI_U32 u32RgnNum;
SIZE_S stSIZE;
} RGN_SIZE_S;
typedef struct hiRGN_ATTR_INFO_S
{
RGN_HANDLE Handle;
HI_U32 u32RgnNum;
} RGN_ATTR_INFO_S;
#define SAMPLE_RGN_NOT_PASS(err)\
do {\
printf("\033[0;31mtest case not pass at line:%d err:%x\033[0;39m\n",\
__FUNCTION__,__LINE__,err);\
exit(-1);\
}while(0)
typedef struct hiVDA_OD_PARAM_S
{
HI_BOOL bThreadStart;
VDA_CHN VdaChn;
} VDA_OD_PARAM_S;
typedef struct hiVDA_MD_PARAM_S
{
HI_BOOL bThreadStart;
VDA_CHN VdaChn;
} VDA_MD_PARAM_S;
typedef struct G_VDA_OBJ_S
{
HI_U16 u16Left;
HI_U16 u16Top;
HI_U16 u16Right;
HI_U16 u16Bottom;
}G_VDA_OBJ_S;
typedef struct MD_DATA_TEST
{
HI_U32 u32ObjNum; /*OBJ number*/
G_VDA_OBJ_S data;
HI_U32 u32IndexOfMaxObj; /*index of max OBJ*/
HI_U32 u32SizeOfMaxObj; /*size of max OBJ*/
HI_U32 u32SizeOfTotalObj; /*total size of all OBJ*/
}md_data_test;
HI_U32 g_md_flag = 0;
md_data_test g_md_data;
static VDA_MD_PARAM_S gs_stMdParam;
#if 0
int sdl_test()
{
TTF_Font *font;
SDL_Surface *text, *temp;
/* Initialize the TTF library */
if ( TTF_Init() OVERLAYEX_MAX_NUM_VPSS)
{
printf("cover num(%d) is bigger than OVERLAY_MAX_NUM_VPSS(%d)..\n", u32RgnNum, OVERLAY_MAX_NUM_VPSS);
return NULL;
}
TTF_Font *font;
SDL_Surface *text, *temp;
SDL_Surface *text2, *temp2;
SDL_Surface *text3, *temp3;
SDL_Surface *text4, *temp4;
SDL_Surface *text5, *temp5;
/* Initialize the TTF library */
if ( TTF_Init() ",g_pitch,g_roll,g_heading_ang);
if (g_lng_flag == 'E' g_lat_flag == 'N') {
sprintf(string2 g_lng,g_lat);
} else if (g_lng_flag == 'E' g_lat_flag == 'W') {
sprintf(string2,">",g_lng,g_lat);
}else if (g_lng_flag == 'S' g_lat_flag == 'N') {
sprintf(string2g_lng,g_lat);
}else {
sprintf(string2g_lng,g_lat);
}
//printf("string size is %d\n",strlen(string));
text = TTF_RenderUTF8_Solid(font, string, forecol);
text2 = TTF_RenderUTF8_Solid(font, string2, forecol);
text3 = TTF_RenderUTF8_Solid(font, string3, forecol);
text4 = TTF_RenderUTF8_Solid(font, string4, forecol);
text5 = TTF_RenderUTF8_Solid(font, string5, forecol);
/* Convert to 16 bits per pixel */
temp = SDL_CreateRGBSurface(SDL_SWSURFACE,
text->w, text->h, 16,
0x00FF0000, 0x0000FF00, 0x000000FF,/*0x00FF0000, 0x0000FF00, 0x000000FF*/
0);
SDL_Rect bounds;
if (temp != NULL) {
bounds.x = 0;
bounds.y = 0;
bounds.w = text->w;
bounds.h = text->h;
if (SDL_LowerBlit(text, bounds, temp, bounds) w, text2->h, 16,
0x00FF0000, 0x0000FF00, 0x000000FF,/*0x00FF0000, 0x0000FF00, 0x000000FF*/
0);
SDL_Rect bounds2;
if (temp2 != NULL) {
bounds2.x = 0;
bounds2.y = 0;
bounds2.w = text2->w;
bounds2.h = text2->h;
if (SDL_LowerBlit(text2, bounds2, temp2, bounds2) w, text3->h, 16,
0x00FF0000, 0x0000FF00, 0x000000FF,/*0x00FF0000, 0x0000FF00, 0x000000FF*/
0);
SDL_Rect bounds3;
if (temp3 != NULL) {
bounds3.x = 0;
bounds3.y = 0;
bounds3.w = text3->w;
bounds3.h = text3->h;
if (SDL_LowerBlit(text3, bounds3, temp3, bounds3) w, text4->h, 16,
0x00FF0000, 0x0000FF00, 0x000000FF,/*0x00FF0000, 0x0000FF00, 0x000000FF*/
0);
SDL_Rect bounds4;
if (temp4 != NULL) {
bounds4.x = 0;
bounds4.y = 0;
bounds4.w = text4->w;
bounds4.h = text->h;
if (SDL_LowerBlit(text4, bounds4, temp4, bounds4) w, text5->h, 16,
0x00FF0000, 0x0000FF00, 0x000000FF,/*0x00FF0000, 0x0000FF00, 0x000000FF*/
0);
SDL_Rect bounds5;
if (temp5 != NULL) {
bounds5.x = 0;
bounds5.y = 0;
bounds5.w = text5->w;
bounds5.h = text5->h;
if (SDL_LowerBlit(text5, bounds5, temp5, bounds5) w;
stBitmap.u32Height = temp->h;
stBitmap.pData= temp->pixels;
stBitmap.enPixelFormat= PIXEL_FORMAT_RGB_1555 ;
// printf("temp->pitch = %d\n",temp->pitch);
s32Ret = HI_MPI_RGN_SetBitMap(Handle,stBitmap);
if(s32Ret != HI_SUCCESS) {
SAMPLE_PRT("HI_MPI_RGN_SetBitMap failed with %#x!\n", s32Ret);
}
SDL_FreeSurface(text);
SDL_FreeSurface(temp);
stBitmap2.u32Width = temp2->w;
stBitmap2.u32Height = temp2->h;
stBitmap2.pData= temp2->pixels;
stBitmap2.enPixelFormat= PIXEL_FORMAT_RGB_1555 ;
// printf("temp->pitch = %d\n",temp->pitch);
s32Ret = HI_MPI_RGN_SetBitMap(Handle+1,stBitmap2);
if(s32Ret != HI_SUCCESS) {
SAMPLE_PRT("HI_MPI_RGN_SetBitMap failed with %#x!\n", s32Ret);
}
SDL_FreeSurface(text2);
SDL_FreeSurface(temp2);
stBitmap3.u32Width = temp3->w;
stBitmap3.u32Height = temp3->h;
stBitmap3.pData= temp3->pixels;
stBitmap3.enPixelFormat= PIXEL_FORMAT_RGB_1555 ;
// printf("temp->pitch = %d\n",temp->pitch);
s32Ret = HI_MPI_RGN_SetBitMap(Handle+2,stBitmap3);
if(s32Ret != HI_SUCCESS) {
SAMPLE_PRT("HI_MPI_RGN_SetBitMap failed with %#x!\n", s32Ret);
}
SDL_FreeSurface(text3);
SDL_FreeSurface(temp3);
stBitmap4.u32Width = temp4->w;
stBitmap4.u32Height = temp4->h;
stBitmap4.pData= temp4->pixels;
stBitmap4.enPixelFormat= PIXEL_FORMAT_RGB_1555 ;
// printf("temp->pitch = %d\n",temp->pitch);
s32Ret = HI_MPI_RGN_SetBitMap(Handle+3,stBitmap4);
if(s32Ret != HI_SUCCESS) {
SAMPLE_PRT("HI_MPI_RGN_SetBitMap failed with %#x!\n", s32Ret);
}
SDL_FreeSurface(text4);
SDL_FreeSurface(temp4);
stBitmap5.u32Width = temp5->w;
stBitmap5.u32Height = temp5->h;
stBitmap5.pData= temp5->pixels;
stBitmap5.enPixelFormat= PIXEL_FORMAT_RGB_1555 ;
// printf("temp->pitch = %d\n",temp->pitch);
s32Ret = HI_MPI_RGN_SetBitMap(Handle+4,stBitmap5);
if(s32Ret != HI_SUCCESS) {
SAMPLE_PRT("HI_MPI_RGN_SetBitMap failed with %#x!\n", s32Ret);
}
SDL_FreeSurface(text5);
SDL_FreeSurface(temp5);
sleep(1);
}
TTF_CloseFont(font);
TTF_Quit();
return NULL;
}
HI_S32 SAMPLE_RGN_CreateOverlayExForVpss(RGN_HANDLE Handle, HI_U32 u32Num)
{
HI_S32 i;
HI_S32 s32Ret;
MPP_CHN_S stChn;
HI_U32 u32layer = 0;
RGN_ATTR_S stRgnAttrSet;
RGN_CHN_ATTR_S stChnAttr;
//╁vpss
/*attach the OSD to the vpss*/
stChn.enModId = HI_ID_VPSS;
stChn.s32DevId = 0;
stChn.s32ChnId = VPSS_CHN0;
for (i = Handle; i 0) {//right
// printf("right %d\n",mov_x_necle);
#if 1
nacelle_ctl_dt.start = 0xA0;
nacelle_ctl_dt.devnum = 0x0F;
nacelle_ctl_dt.data[0] = 0x0;
nacelle_ctl_dt.data[1] = 0x04;
nacelle_ctl_dt.data[2] = 0x64;
nacelle_ctl_dt.data[3] = 0x64;
nacelle_ctl_dt.end = 0xAF;
nacelle_ctl_dt.crc =nacelle_ctl_dt.data[0]^nacelle_ctl_dt.data[1]^nacelle_ctl_dt.data[2]^nacelle_ctl_dt.data[3] ;
write(g_nace_fd,nacelle_ctl_dt,sizeof(NACELLE_CTL));
usleep(mov_x_necle*1000);
#endif
}
nacelle_ctl_dt.start = 0xA0;
nacelle_ctl_dt.devnum = 0x0F;
nacelle_ctl_dt.data[0] = 0x0;
nacelle_ctl_dt.data[1] = 0x0;
nacelle_ctl_dt.data[2] = 0x64;
nacelle_ctl_dt.data[3] = 0x64;
nacelle_ctl_dt.end =0xAF;
nacelle_ctl_dt.crc =nacelle_ctl_dt.data[0]^nacelle_ctl_dt.data[1]^nacelle_ctl_dt.data[2]^nacelle_ctl_dt.data[3] ;
write(g_nace_fd,nacelle_ctl_dt,sizeof(NACELLE_CTL));
#if 1
if (mov_y_necle 0) {//?
// printf("down %d\n",mov_y_necle);
#if 1
nacelle_ctl_dt.start = 0xA0;
nacelle_ctl_dt.devnum = 0x0F;
nacelle_ctl_dt.data[0] = 0x0;
nacelle_ctl_dt.data[1] = 0x08;
nacelle_ctl_dt.data[2] = 0x64;
nacelle_ctl_dt.data[3] = 0x64;
nacelle_ctl_dt.end = 0xAF;
nacelle_ctl_dt.crc =nacelle_ctl_dt.data[0]^nacelle_ctl_dt.data[1]^nacelle_ctl_dt.data[2]^nacelle_ctl_dt.data[3] ;
write(g_nace_fd,nacelle_ctl_dt,sizeof(NACELLE_CTL));
usleep(5*mov_y_necle*1000);
#endif
}
nacelle_ctl_dt.start = 0xA0;
nacelle_ctl_dt.devnum = 0x0F;
nacelle_ctl_dt.data[0] = 0x0;
nacelle_ctl_dt.data[1] = 0x0;
nacelle_ctl_dt.data[2] = 0x64;
nacelle_ctl_dt.data[3] = 0x64;
nacelle_ctl_dt.end =0xAF;
nacelle_ctl_dt.crc =nacelle_ctl_dt.data[0]^nacelle_ctl_dt.data[1]^nacelle_ctl_dt.data[2]^nacelle_ctl_dt.data[3] ;
write(g_nace_fd,nacelle_ctl_dt,sizeof(NACELLE_CTL));
#endif
nacelle_ctl_dt.start = 0xA0;
nacelle_ctl_dt.devnum = 0x0F;
nacelle_ctl_dt.data[0] = 0x0;
nacelle_ctl_dt.data[1] = 0x0b;
nacelle_ctl_dt.data[2] = 0x0;
nacelle_ctl_dt.data[3] = 0x01;
nacelle_ctl_dt.end = 0xAF;
nacelle_ctl_dt.crc =nacelle_ctl_dt.data[0]^nacelle_ctl_dt.data[1]^nacelle_ctl_dt.data[2]^nacelle_ctl_dt.data[3] ;
write(g_nace_fd,nacelle_ctl_dt,sizeof(NACELLE_CTL));
}
/*Motion Region Data*/
/******************************************************************************
* function : change coverex
******************************************************************************/
void* SAMPLE_RGN_VpssCoverExDynamicDisplay(void* p)
{
HI_S32 s32Ret;
HI_U32 u32RgnNum;
RGN_HANDLE Handle;
RGN_HANDLE startHandle;
MPP_CHN_S stChn;
RGN_CHN_ATTR_S stChnAttr;
RGN_ATTR_INFO_S* pstRgnAttrInfo = NULL;
stChn.enModId = HI_ID_VPSS;
stChn.s32DevId = 0;
stChn.s32ChnId = 0;
pstRgnAttrInfo = (RGN_ATTR_INFO_S*)p;
startHandle = pstRgnAttrInfo->Handle;
u32RgnNum = pstRgnAttrInfo->u32RgnNum;
if (u32RgnNum > COVEREX_MAX_NUM_VPSS)
{
printf("coverex num(%d) is bigger than COVEREX_MAX_NUM_VPSS(%d)..\n", u32RgnNum, COVEREX_MAX_NUM_VPSS);
return NULL;
}
while (HI_FALSE == 0)
{
if (g_md_flag > 0) {
s32Ret = HI_MPI_VDA_StopRecvPic(0);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("err(0x%x)!!!!\n", s32Ret);
}
stChnAttr.bShow = HI_TRUE;
stChnAttr.enType = COVEREX_RGN;
stChnAttr.unChnAttr.stCoverExChn.enCoverType = AREA_QUAD_RANGLE;
stChnAttr.unChnAttr.stCoverExChn.stQuadRangle.bSolid = HI_FALSE;
stChnAttr.unChnAttr.stCoverExChn.stQuadRangle.u32Thick = 2;
stChnAttr.unChnAttr.stCoverExChn.stQuadRangle.stPoint[0].s32X =g_md_data.data.u16Left;
stChnAttr.unChnAttr.stCoverExChn.stQuadRangle.stPoint[0].s32Y = g_md_data.data.u16Top;
stChnAttr.unChnAttr.stCoverExChn.stQuadRangle.stPoint[1].s32X = g_md_data.data.u16Right;
stChnAttr.unChnAttr.stCoverExChn.stQuadRangle.stPoint[1].s32Y = g_md_data.data.u16Top;
stChnAttr.unChnAttr.stCoverExChn.stQuadRangle.stPoint[2].s32X = g_md_data.data.u16Right;
stChnAttr.unChnAttr.stCoverExChn.stQuadRangle.stPoint[2].s32Y = g_md_data.data.u16Bottom;
stChnAttr.unChnAttr.stCoverExChn.stQuadRangle.stPoint[3].s32X = g_md_data.data.u16Left;
stChnAttr.unChnAttr.stCoverExChn.stQuadRangle.stPoint[3].s32Y = g_md_data.data.u16Bottom;
stChnAttr.unChnAttr.stCoverExChn.u32Color = 0x00ff00;
printf("%d %d %d %d\n",g_md_data.data.u16Left,g_md_data.data.u16Top,g_md_data.data.u16Right,g_md_data.data.u16Bottom);
stChnAttr.unChnAttr.stCoverExChn.u32Layer = Handle - startHandle;
s32Ret = HI_MPI_RGN_SetDisplayAttr(Handle, stChn, stChnAttr);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_RGN_NOT_PASS(s32Ret);
}
//sleep(5);
#if 0
move_nacle();
#endif
//sleep(2);
s32Ret = HI_MPI_VDA_StartRecvPic(0);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("err!\n");
return NULL;
}
g_md_flag = 0;
}
usleep(10000);
#if 0
else {
printf("222222222222222\n");
stChnAttr.bShow = HI_FALSE;
stChnAttr.unChnAttr.stCoverExChn.u32Layer = 0;
s32Ret = HI_MPI_RGN_SetDisplayAttr(Handle, stChn, stChnAttr);
}
#endif
}
return (HI_VOID*)HI_SUCCESS;
}
HI_S32 SAMPLE_RGN_CreateCoverEx(RGN_HANDLE Handle, HI_U32 u32Num)
{
HI_S32 i;
HI_S32 s32Ret;
MPP_CHN_S stChn;
RGN_ATTR_S stRgnAttr;
RGN_CHN_ATTR_S stChnAttr;
/* Add cover to vpss group */
stChn.enModId = HI_ID_VPSS;
stChn.s32DevId = 0;
stChn.s32ChnId = 0;
/* Create cover and attach to vpss group */
for (i = Handle; i VdaChn;
/* decide the stream file name, and open file to save stream */
/* Set Venc Fd. */
VdaFd = HI_MPI_VDA_GetFd(VdaChn);
if (VdaFd bThreadStart)
{
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("err!\n");
return NULL;
}
FD_ZERO(read_fds);
FD_SET(VdaFd, read_fds);
TimeoutVal.tv_sec = 2;
TimeoutVal.tv_usec = 0;
s32Ret = select(maxfd + 1, read_fds, NULL, NULL, TimeoutVal);
if (s32Ret 0) {
g_md_flag = 1;
// printf("ssssssssssssssssssssssssssssssss\n");
testnum = stVdaData.unData.stMdData.stObjData.u32IndexOfMaxObj;
g_md_data.data.u16Bottom = stVdaData.unData.stMdData.stObjData.pstAddr[testnum].u16Bottom;
g_md_data.data.u16Left= stVdaData.unData.stMdData.stObjData.pstAddr[testnum].u16Left;
g_md_data.data.u16Right= stVdaData.unData.stMdData.stObjData.pstAddr[testnum].u16Right;
g_md_data.data.u16Top= stVdaData.unData.stMdData.stObjData.pstAddr[testnum].u16Top;
} else {
g_md_flag = 0;
}