292 lines
7.2 KiB
C++
292 lines
7.2 KiB
C++
#include<iostream>
|
|
#include<stdlib.h>
|
|
#include<stdio.h>
|
|
#include <unistd.h>
|
|
#include<string>
|
|
#include<functional>
|
|
#include "common.h"
|
|
#include "HuaWei/HWsign.h"
|
|
#include "HuaWei/HWsec.h"
|
|
// #include "data264.h"
|
|
#include "data265.h"
|
|
// #include "H265TCP.h"
|
|
#include "putdata.h"
|
|
#include<netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include<sys/socket.h>
|
|
#include <thread>
|
|
|
|
extern void pushdata(RTPpackage::Ptr ptr);
|
|
using namespace std;
|
|
|
|
|
|
void print_data(const char * buf, uint32_t len){
|
|
printf("\n --%d-- \n",len);
|
|
for (int num = 0; num < 12; num++)
|
|
{
|
|
printf("%02X ", (uint8_t)buf[num]);
|
|
}
|
|
printf(", ");
|
|
for (int num = 12; num < 20; num++)
|
|
{
|
|
printf("%02X ", (uint8_t)buf[num]);
|
|
}
|
|
|
|
printf("\n ---- \n");
|
|
}
|
|
|
|
void print_rtp(const char * buf, uint32_t len){
|
|
uint8_t mask=0;
|
|
uint16_t seq=0;
|
|
uint32_t stamp=0;
|
|
mask=(uint8_t)*(buf+1)>>7;
|
|
memcpy(&seq, buf + 2, 2);
|
|
seq= ntohs(seq);
|
|
memcpy(&stamp, buf + 4, 4);
|
|
stamp= ntohl(stamp);
|
|
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ modify @@@@@@@@@ seq %d stamp %d mask %d",seq,stamp,mask);
|
|
print_data(buf,len);
|
|
}
|
|
|
|
// mask=*(pkt##x+offset+1)>>7; \
|
|
// memcpy(&seq, pkt##x+offset + 2, 2); \
|
|
// seq= ntohs(seq); \
|
|
// memcpy(&stamp, pkt##x+offset + 4, 4); \
|
|
// stamp= ntohl(stamp); \
|
|
// printf("raw seq %d stamp %d mask %d",seq,stamp,mask); \
|
|
// print_data((const char*)pkt##x+offset,sizeof(pkt##x)-offset); \
|
|
|
|
#define ARRAY(x,offset) { \
|
|
id=(int *)malloc(sizeof(int)); \
|
|
*id=x; \
|
|
auto ret =HWSign_rtp_input(sign_handle,(const char*)pkt##x+offset,sizeof(pkt##x)-offset,(void*)id); \
|
|
}
|
|
|
|
void tcp_test(){
|
|
sec_set_info sign_info={
|
|
2,
|
|
"HwaWei_Sec_Camera",
|
|
"2021-07-06T17:27:19.000",
|
|
32,
|
|
64,
|
|
{
|
|
0x24,0x88,0xc8,0xdc,0x7f,0xd7,0xe0,0x91,0x30,0x1b,0x5c,0x58,0x2f,0xe7,0x44,0x7d,
|
|
0x2f,0x43,0xe4,0xee,0xc8,0x7d,0xc0,0xfb,0xa4,0xb8,0x7d,0x4b,0x8a,0x69,0x7c,0x4e
|
|
},
|
|
{
|
|
0xaa,0xb1,0x3f,0xd7,0x66,0xe2,0x75,0x97,0xc0,0x03,0xe6,0xe4,0x1d,0x77,0x54,0x78,
|
|
0xc8,0x29,0xb2,0x0b,0x9e,0xd1,0xff,0xa3,0x6a,0x6f,0xd2,0x7f,0xd6,0x2d,0xaa,0x3f,
|
|
0xc9,0x24,0xec,0x6c,0x96,0x0a,0x7b,0x73,0xf6,0xe6,0xfc,0xda,0x3a,0x08,0xfd,0x92,
|
|
0xfc,0x00,0x08,0x97,0x78,0x2c,0x71,0x6b,0xe1,0x26,0xf5,0x1e,0xba,0x31,0xf5,0xb2,
|
|
}
|
|
};
|
|
|
|
void * hw_sec_ptr= HWSign_tcp_init(&sign_info);
|
|
|
|
char buf_out[2048];
|
|
int ret=1;
|
|
uint32_t * param;
|
|
uint32_t len=0;
|
|
|
|
#if 1
|
|
for (uint32_t rd=1;rd>0;rd--){
|
|
pushfile(hw_sec_ptr,0);
|
|
// printout(hw_sec_ptr);
|
|
}
|
|
|
|
#else
|
|
for (uint32_t rd=5;rd>0;rd--){
|
|
pushdata(hw_sec_ptr);
|
|
printout(hw_sec_ptr);
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
|
|
HWSign_tcp_release(hw_sec_ptr);
|
|
}
|
|
|
|
|
|
void UDPtest(){
|
|
// EXPAND(DEFER(A)());
|
|
void * sign_handle=nullptr;
|
|
|
|
auto udpsocket=new UdpSocket();
|
|
udpsocket->Socket();
|
|
// udpsocket.Send()
|
|
// [udpsocket](const char * rtp_ptr, const uint32_t rtp_len){
|
|
// udpsocket->Send(rtp_ptr,rtp_len,string("192.168.123.1"),30000);
|
|
// // print_rtp(rtp_ptr,rtp_len);
|
|
// }
|
|
uint8_t mask;
|
|
uint16_t seq=0;
|
|
uint32_t stamp=0;
|
|
int* id;
|
|
int ret,count;
|
|
void * Verify_handle=nullptr;
|
|
// SDF_Device_open();
|
|
|
|
Verify_handle=HWVerify_init();
|
|
sec_set_info sign_info={
|
|
2,
|
|
"HwaWei_Sec_Camera",
|
|
"2021-07-06T17:27:19.000",
|
|
32,
|
|
64,
|
|
{
|
|
0x24,0x88,0xc8,0xdc,0x7f,0xd7,0xe0,0x91,0x30,0x1b,0x5c,0x58,0x2f,0xe7,0x44,0x7d,
|
|
0x2f,0x43,0xe4,0xee,0xc8,0x7d,0xc0,0xfb,0xa4,0xb8,0x7d,0x4b,0x8a,0x69,0x7c,0x4e
|
|
},
|
|
{
|
|
0xaa,0xb1,0x3f,0xd7,0x66,0xe2,0x75,0x97,0xc0,0x03,0xe6,0xe4,0x1d,0x77,0x54,0x78,
|
|
0xc8,0x29,0xb2,0x0b,0x9e,0xd1,0xff,0xa3,0x6a,0x6f,0xd2,0x7f,0xd6,0x2d,0xaa,0x3f,
|
|
0xc9,0x24,0xec,0x6c,0x96,0x0a,0x7b,0x73,0xf6,0xe6,0xfc,0xda,0x3a,0x08,0xfd,0x92,
|
|
0xfc,0x00,0x08,0x97,0x78,0x2c,0x71,0x6b,0xe1,0x26,0xf5,0x1e,0xba,0x31,0xf5,0xb2,
|
|
}
|
|
};
|
|
sign_handle=HWSign_init(&sign_info);
|
|
|
|
// char buf_test[2048];
|
|
// uint32_t len_test;
|
|
// int* id_test;
|
|
// HWSign_rtp_out(sign_handle,buf_test,&len_test,(void **)&id_test);
|
|
|
|
// 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)
|
|
|
|
|
|
for (int loop=0;loop<=4;loop++){
|
|
|
|
|
|
// 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)
|
|
|
|
usleep(100);
|
|
// ARRAY(20,42)
|
|
// ARRAY(21,42)
|
|
|
|
// sleep(1);
|
|
// usleep(50);
|
|
// 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;
|
|
|
|
|
|
//////////////////////
|
|
ret=1;count=0;
|
|
while (ret==1)
|
|
{
|
|
char buf_h[2048];
|
|
uint32_t len;
|
|
int* id;
|
|
count++;
|
|
ret=HWSign_rtp_out(sign_handle,buf_h,&len,(void **)&id);
|
|
// 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);
|
|
if (ret==-1) break;
|
|
|
|
udpsocket->Send((char*)buf_h,len,string("192.168.123.1"),30000);
|
|
|
|
// printf("%d %d %d\n",count,*id,len);
|
|
free(id);
|
|
// printf(" modify @@@@@@@@@ id %d seq %d stamp %d mask %d",id,seq,stamp,mask);
|
|
// print_data(buf_h,len);
|
|
// sleep(0.1);
|
|
/* code */
|
|
}
|
|
// }
|
|
|
|
// printf("raw");
|
|
// print_data((const char*)pkt2+42,sizeof(pkt2)-42);
|
|
// HWSign_rtp_input(sign_handle,(const char*)pkt2+42,sizeof(pkt2)-42,0);
|
|
|
|
// printf("raw");
|
|
// print_data((const char*)pkt3+42,sizeof(pkt3)-42);
|
|
// HWSign_rtp_input(sign_handle,(const char*)pkt3+42,sizeof(pkt3)-42,0);
|
|
|
|
|
|
HWSign_release(sign_handle);
|
|
HWVerify_release(Verify_handle);
|
|
// SDF_Device_close();
|
|
}
|
|
|
|
|
|
|
|
int main(){
|
|
// std:thread threads[2];
|
|
|
|
// for (size_t i = 0; i < 2; i++)
|
|
// {
|
|
// threads[i]=std::thread(tcp_test);
|
|
// }
|
|
|
|
// for (auto & th:threads)
|
|
// th.join();
|
|
// UDPtest();
|
|
tcp_test();
|
|
|
|
} |