From 732bb17a9a73670b781770b569e16223af357044 Mon Sep 17 00:00:00 2001 From: AlanRen Date: Fri, 14 Jul 2023 08:51:08 -0600 Subject: [PATCH] fix udp --- src/DecEnc/NALUdecode.cpp | 2 +- src/HuaWei/HWcommon.h | 4 +- src/HuaWei/HWsign.cpp | 107 +++++++++++++++++++++----------------- test/main.cpp | 30 ++++++++++- 4 files changed, 89 insertions(+), 54 deletions(-) diff --git a/src/DecEnc/NALUdecode.cpp b/src/DecEnc/NALUdecode.cpp index 256ca80..2b856fd 100644 --- a/src/DecEnc/NALUdecode.cpp +++ b/src/DecEnc/NALUdecode.cpp @@ -5,7 +5,7 @@ namespace SecMedia { int GeneHWSecritySEI(uint8_t* dst, CodecId code_type, uint8_t SecrityLevel,uint32_t vid_len, uint8_t sign_len,uint8_t* sign,char* rtp_head,uint16_t rtp_len) { - char SEIdata[1024] = { 0x00,0x00,0x00,0x01,0x00 }; + char SEIdata[2048] = { 0x00,0x00,0x00,0x01,0x00 }; // const char uuid[] = { "U0VDIFZJRCBQUk9U" }; const uint8_t uuid[] = { 0x86,0xb1 ,0x16 ,0x6e ,0xad ,0xef ,0x67 ,0x3f ,0x70 ,0xbc ,0xe7 ,0xc7 ,0xe6 ,0x95 ,0xc6 ,0x09 }; char* ptr = SEIdata; diff --git a/src/HuaWei/HWcommon.h b/src/HuaWei/HWcommon.h index 0f27725..fc3a31f 100644 --- a/src/HuaWei/HWcommon.h +++ b/src/HuaWei/HWcommon.h @@ -36,8 +36,8 @@ using namespace std; #define TRACEL(x,...) //PRINT(WHITE,x,##__VA_ARGS__) #define DEBUGL(x,...) //PRINT(LIGHT_GRAY,x,##__VA_ARGS__) -#define INFOL(x,...) PRINT(BLUE,x,##__VA_ARGS__) -#define NOTICEL(x,...)PRINT(BROWN,x,##__VA_ARGS__) +#define INFOL(x,...) //PRINT(BLUE,x,##__VA_ARGS__) +#define NOTICEL(x,...)//PRINT(BROWN,x,##__VA_ARGS__) #define WRNGL(x,...) PRINT(YELLOW,x,##__VA_ARGS__) #define ERROL(x,...) PRINT(RED,x,##__VA_ARGS__) diff --git a/src/HuaWei/HWsign.cpp b/src/HuaWei/HWsign.cpp index 42c83e9..cb4b967 100644 --- a/src/HuaWei/HWsign.cpp +++ b/src/HuaWei/HWsign.cpp @@ -259,7 +259,7 @@ void send_rtp(HWsign* Handle,const char * buf, const uint32_t len ,int tcp,void Handle->rtp_cb(send_buff,len,param); free(send_buff); } -void sign_data(HWsign* Handle,const char * buf, const uint32_t len,uint8_t offset,int tcp,void * param,const char * sei_head){ +void sign_data(HWsign* Handle,const char * buf, const uint32_t len,uint8_t offset,int tcp,void * param,const char * sei_head, const uint16_t sei_len){ uint8_t sha[128],sign[128],sei[2048],sei_race[1024]; uint16_t sign_len=64; sm3_update(Handle->sm3_hd,(uint8_t*)buf+offset,len-offset); @@ -274,21 +274,21 @@ void sign_data(HWsign* Handle,const char * buf, const uint32_t len,uint8_t offse print_data2((char*)sign,64,64); Handle->sei_param=nullptr; - auto rtp_len=SecMedia::GeneHWSecritySEI(sei,Handle->track_type,1,len-offset,sign_len,sign,(char *)sei_head,Handle->sei_len); - rtp_len=add_racing_code(sei_race,sei+Handle->sei_len,rtp_len-Handle->sei_len); - memcpy(sei+Handle->sei_len,sei_race,rtp_len); - rtp_len+=Handle->sei_len; - DEBUGL("success!!!!!!!!!! sei package\n"); + auto rtp_len=SecMedia::GeneHWSecritySEI(sei,Handle->track_type,1,len-offset,sign_len,sign,(char *)sei_head,sei_len); + rtp_len=add_racing_code(sei_race,sei+sei_len,rtp_len-sei_len); + memcpy(sei+sei_len,sei_race,rtp_len); + rtp_len+=sei_len; + SUCSL("success sign!!!!!!!!!! sei package\n"); send_rtp(Handle,(char *) sei,rtp_len,tcp,param); // Handle->seq_accu++; } -void none_sign_data(HWsign* Handle,uint8_t offset,int tcp,void * param,const char * sei_head){ - uint8_t sei[1024]; - auto rtp_len=SecMedia::GeneHWSecritySEI(sei,Handle->track_type,0,0,64,nullptr,(char *)sei_head, Handle->sei_len); - Handle->sei_param=nullptr; - WRNGL("Warning!!!!!!!!!! none sei package\n"); - send_rtp(Handle,(char *) sei,rtp_len,tcp,param); -} +// void none_sign_data(HWsign* Handle,uint8_t offset,int tcp,void * param,const char * sei_head){ +// uint8_t sei[1024]; +// auto rtp_len=SecMedia::GeneHWSecritySEI(sei,Handle->track_type,0,0,64,nullptr,(char *)sei_head, Handle->sei_len); +// Handle->sei_param=nullptr; +// WRNGL("Warning!!!!!!!!!! none sei package\n"); +// send_rtp(Handle,(char *) sei,rtp_len,tcp,param); +// } int HWSign_rtp_out(void* Handle, char * buf, uint32_t * len, void ** param){ HWsign* HWSign_hd=(HWsign*) Handle; if(!HWSign_hd) return -1; @@ -344,9 +344,15 @@ int HWSign_rtp_264(HWsign* HWSign_hd, const char * buf, const uint32_t len,int t case 6:{ DEBUGL("SEI!!!!!!!!!! package\n"); if(len<1300){ - memcpy(HWSign_hd->sei_rtp_head,buf,len); - HWSign_hd->sei_len=len; - HWSign_hd->sei_param=param; + + if (!HWSign_hd->buff->empty()) + { + sign_data(HWSign_hd,HWSign_hd->buff->data(),HWSign_hd->buff->size(),0, tcp,param,buf,len); + HWSign_hd->buff->clear(); + }else + { + HWSign_hd->rtp_cb(buf,len,param); + } } return 1; } @@ -367,35 +373,32 @@ int HWSign_rtp_264(HWsign* HWSign_hd, const char * buf, const uint32_t len,int t if (fu.S) { //第一个rtp包 if(!HWSign_hd->buff->empty()){ WRNGL("Warning!!!!!!!!!! missing package\n"); - if (HWSign_hd->sei_param!=nullptr) - { - none_sign_data(HWSign_hd,offset,tcp, HWSign_hd->sei_param,HWSign_hd->sei_rtp_head); - } + // if (HWSign_hd->sei_param!=nullptr) + // { + // none_sign_data(HWSign_hd,offset,tcp, HWSign_hd->sei_param,HWSign_hd->sei_rtp_head); + // } - flush_all(HWSign_hd); + // flush_all(HWSign_hd); } DEBUGL("!!!!!!!!!! I head\n"); HWSign_hd->I_seq=now_seq; - auto rtp_str=make_shared(buf,len); - HWSign_hd->rtp_buff->push_back(make_pair(rtp_str,param)); + // auto rtp_str=make_shared(buf,len); + // HWSign_hd->rtp_buff->push_back(make_pair(rtp_str,param)); HWSign_hd->buff->assign(rtp+2,length-2); + HWSign_hd->rtp_cb(buf,len,param); return 1; } if(HWSign_hd->I_seq>=0){ - auto rtp_str=make_shared(buf,len); - HWSign_hd->rtp_buff->push_back(make_pair(rtp_str,param)); + // auto rtp_str=make_shared(buf,len); + // HWSign_hd->rtp_buff->push_back(make_pair(rtp_str,param)); HWSign_hd->buff->append(rtp+2,length-2); - + HWSign_hd->rtp_cb(buf,len,param); if (!fu.E) { //中间rtp包 return 1; } - if (HWSign_hd->sei_param!=nullptr) - { - sign_data(HWSign_hd,HWSign_hd->buff->data(),HWSign_hd->buff->size(),0, tcp,HWSign_hd->sei_param,HWSign_hd->sei_rtp_head); - } - flush_all(HWSign_hd); + // flush_all(HWSign_hd); HWSign_hd->I_seq=-1; return 1; }else{ @@ -435,9 +438,17 @@ int HWSign_rtp_265(HWsign* HWSign_hd, const char * buf, const uint32_t len,int t case NAL_SEI_PREFIX:{ DEBUGL("SEI!!!!!!!!!! package\n"); if(len<1300){ - memcpy(HWSign_hd->sei_rtp_head,buf,len); - HWSign_hd->sei_len=len; - HWSign_hd->sei_param=param; + if (!HWSign_hd->buff->empty()) + { + sign_data(HWSign_hd,HWSign_hd->buff->data(),HWSign_hd->buff->size(),0, tcp,param,buf,len); + HWSign_hd->buff->clear(); + }else + { + HWSign_hd->rtp_cb(buf,len,param); + } + // memcpy(HWSign_hd->sei_rtp_head,buf,len); + // HWSign_hd->sei_len=len; + // HWSign_hd->sei_param=param; } return 1; } @@ -457,33 +468,31 @@ int HWSign_rtp_265(HWsign* HWSign_hd, const char * buf, const uint32_t len,int t if (fu.S) { //第一个rtp包 if(!HWSign_hd->buff->empty()){ WRNGL("Warning!!!!!!!!!! missing package\n"); - if (HWSign_hd->sei_param!=nullptr) - { - none_sign_data(HWSign_hd,offset,tcp, HWSign_hd->sei_param,HWSign_hd->sei_rtp_head); - } + // if (HWSign_hd->sei_param!=nullptr) + // { + // none_sign_data(HWSign_hd,offset,tcp, HWSign_hd->sei_param,HWSign_hd->sei_rtp_head); + // } - flush_all(HWSign_hd); + // flush_all(HWSign_hd); } DEBUGL("!!!!!!!!!! I head\n"); HWSign_hd->I_seq=now_seq; - auto rtp_str=make_shared(buf,len); - HWSign_hd->rtp_buff->push_back(make_pair(rtp_str,param)); + // auto rtp_str=make_shared(buf,len); + // HWSign_hd->rtp_buff->push_back(make_pair(rtp_str,param)); HWSign_hd->buff->assign(rtp+3,length-3); + HWSign_hd->rtp_cb(buf,len,param); return 1; } if(HWSign_hd->I_seq>=0){ - auto rtp_str=make_shared(buf,len); - HWSign_hd->rtp_buff->push_back(make_pair(rtp_str,param)); + // auto rtp_str=make_shared(buf,len); + // HWSign_hd->rtp_buff->push_back(make_pair(rtp_str,param)); HWSign_hd->buff->append(rtp+3,length-3); + HWSign_hd->rtp_cb(buf,len,param); if (!fu.E) { //中间rtp包 return 1; } - if (HWSign_hd->sei_param!=nullptr) - { - sign_data(HWSign_hd,HWSign_hd->buff->data(),HWSign_hd->buff->size(),0, tcp,HWSign_hd->sei_param,HWSign_hd->sei_rtp_head); - } - flush_all(HWSign_hd); + HWSign_hd->I_seq=-1; return 1; }else{ @@ -556,7 +565,7 @@ int HWSign_rtp_input(void* Handle, const char * buf, const uint32_t len,int tcp, } - return ret; + return 1; } diff --git a/test/main.cpp b/test/main.cpp index a736f39..9373254 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -165,6 +165,32 @@ void UDPtest(){ ARRAY(20,42) ARRAY(21,42) + ARRAY(1,42) + ARRAY(2,42) + ARRAY(3,42) + ARRAY(4,42) + + + + ARRAY(5,42) //I + ARRAY(6,42) + ARRAY(7,42) + ARRAY(8,42) + ARRAY(9,42) + ARRAY(10,42) + ARRAY(11,42) + ARRAY(12,42) + ARRAY(13,42) + ARRAY(14,42) + ARRAY(15,42) + ARRAY(16,42) + ARRAY(17,42) + ARRAY(18,42) + ARRAY(19,42) + ARRAY(20,42) + ARRAY(21,42) + + ///Verify init int vef_ret=-2; @@ -181,8 +207,8 @@ void UDPtest(){ // if(len>1400){ // buf_h[1000]=0x01; // } - vef_ret=HWVerify_rtp_input(Verify_handle,buf_h,len,0,nullptr); - printf("verify status: %d \n",vef_ret); + // vef_ret=HWVerify_rtp_input(Verify_handle,buf_h,len,0,nullptr); + // printf("verify status: %d \n",vef_ret); if (ret==-1) break; udpsocket->Send((char*)buf_h,len,string("192.168.123.1"),30000);