diff --git a/.vscode/launch.json b/.vscode/launch.json index 085744b..96b9a91 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -35,8 +35,10 @@ // "127.0.0.1","40001","udp src port 20002"], // "args": ["/media/alan/Data/Alan/Documents/WorkSpace/SecMedia/PcapSender/signhw28181.pcap", // "127.0.0.1","30001","udp src port 55763"], - "args": ["/media/alan/Data/Alan/Documents/WorkSpace/SecMedia/PcapRawSender/h265-hikvision-10min.pcap", - "127.0.0.1","40001","udp src port 15060"], //h265 + // "args": ["/media/alan/Data/Alan/Documents/WorkSpace/SecMedia/PcapRawSender/h265-hikvision-10min.pcap", + // "127.0.0.1","40001","udp src port 15060"], //h265 + "args": ["/media/alan/Data/Alan/Documents/WorkSpace/SecMedia/PcapSender/hkh264.pcap", + "127.0.0.1","60006","udp src port 15060"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], diff --git a/PcapSender/main.cpp b/PcapSender/main.cpp index 634e257..2849c54 100644 --- a/PcapSender/main.cpp +++ b/PcapSender/main.cpp @@ -73,6 +73,7 @@ timespec TimeDiff(T && minu,U && sub){ } int ReadPcapAndSend(int socket,sockaddr_in & addr,const string & filename,const string & filter,void * sign_handle){ + // auto sign_h2=EncrypInit(); auto reader=pcpp::IFileReaderDevice::getReader(filename); // verify that a reader interface was indeed created if (reader == NULL) @@ -141,6 +142,8 @@ int ReadPcapAndSend(int socket,sockaddr_in & addr,const string & filename,const sendto(socket,sign_out_buf,offset_len,0,(const sockaddr*)&addr,sizeof(addr)); sendto(socket,sign_out_buf+offset_len,sign_out_len-offset_len,0,(const sockaddr*)&addr,sizeof(addr)); } + // GB28181_stream_in(sign_h2,(char*)payload,payload_len,nullptr); + // GB28181_stream_out(sign_h2,sign_out_buf,&sign_out_len,&offset_len,&append_len, ¶m); @@ -219,6 +222,7 @@ int main(int argc, char *argv[]){ // { cout.flush(); auto sign_h=EncrypInit(); + ReadPcapAndSend(sockfd,addr,filename,filter,sign_h); // } diff --git a/src/GB28181/L2SecurityStream.cpp b/src/GB28181/L2SecurityStream.cpp index a52b462..d453c45 100644 --- a/src/GB28181/L2SecurityStream.cpp +++ b/src/GB28181/L2SecurityStream.cpp @@ -175,10 +175,9 @@ void L2SecurityStream::ThreadSign(){ int L2UdpStream::RtpInput(const uint8_t* data,uint16_t len, void *param){ RTPpackage::rtp_cb_f rtp_cell_cb=[&](const RTPcell::Ptr &rtp_cell){ - static uint16_t prv_seq=0; rtp_cell->precessRTP(); - if( (uint32_t)(prv_seq+1)%(uint32_t)(UINT16_MAX+1) == rtp_cell->seq || prv_seq==0){ + if( (uint32_t)(_prv_seq+1)%(uint32_t)(UINT16_MAX+1) == rtp_cell->seq || _prv_seq==0){ // INFOL("PT: %u Seq: %u PT_len: %u mark: %u\n",rtp_cell->PT,rtp_cell->seq,rtp_cell->_PT_len,(uint8_t)rtp_cell->mark); _rtp_decoder.decodeRtp(rtp_cell->_buffer,rtp_cell->_RTP_len); // on_rtp_out(rtp_cell->_PT_data,rtp_cell->_PT_len,rtp_cell->timestamp,(int)rtp_cell->mark); @@ -187,9 +186,9 @@ void L2SecurityStream::ThreadSign(){ rtp_post_process(rtp_cell); }else { - WRNGL("Disorder rtp Seq: %u+1 != %u \n",prv_seq,rtp_cell->seq); + WRNGL("Disorder rtp Seq: %u+1 != %u \n",_prv_seq,rtp_cell->seq); } - prv_seq=rtp_cell->seq; + _prv_seq=rtp_cell->seq; }; RTPpackage::Ptr RTPpkg=make_shared(rtp_cell_cb,true); diff --git a/src/GB28181/L2SecurityStream.h b/src/GB28181/L2SecurityStream.h index d762173..6b2da7c 100644 --- a/src/GB28181/L2SecurityStream.h +++ b/src/GB28181/L2SecurityStream.h @@ -87,6 +87,8 @@ class L2UdpStream: public L2SecurityStream protected: uint16_t _seq_increment=0; RtpDecoder _rtp_decoder; +private: + uint16_t _prv_seq=0; public: L2UdpStream(sec_set_info* set_info):L2SecurityStream(set_info){ _rtp_decoder.setOnDecode([&](const uint8_t *packet, int bytes, uint32_t timestamp, int flags){ @@ -105,20 +107,37 @@ protected: _seq_increment%=UINT16_MAX; _seq_increment++; uint16_t seq=((uint32_t)_seq_increment+rtp_cell->seq)%((uint32_t)UINT16_MAX+1); + + // if( (uint32_t)(_prv_seq+1)%(uint32_t)(UINT16_MAX+1) == seq || _prv_seq==0){ + // _prv_seq=seq; + // }else{ + // _prv_seq=seq; + // ERROL("OUTPUT Disorder rtp Seq: %u+1 != %u \n",_prv_seq,seq); + // } + if(seqseq){ _seq_increment=0; } + // DEBUGL("increase seq:%u inc:%u\n",seq,_seq_increment); seq=htons(seq); memcpy(buf_ptr+rtp_cell->_tcp_prefix+2,(uint8_t*)&seq,2); // change sequence return buf_ptr+rtp_cell->_prefix; } private: - void incrementRTPseq(const RTPcell::Ptr &rtp_cell) const { + void incrementRTPseq(const RTPcell::Ptr &rtp_cell) { uint16_t seq=((uint32_t)_seq_increment+(uint32_t)rtp_cell->seq)%((uint32_t)UINT16_MAX+1); + // DEBUGL("modify seq:%u old:%u inc:%u\n",seq,rtp_cell->seq,_seq_increment); + // if( (uint32_t)(_prv_seq+1)%(uint32_t)(UINT16_MAX+1) == seq || _prv_seq==0){ + // _prv_seq=seq; + // }else{ + // _prv_seq=seq; + // ERROL("OUTPUT Disorder rtp Seq: %u+1 != %u \n",_prv_seq,seq); + // } if(rtp_cell->_RTPpkg_ptr){ seq=htons(seq); rtp_cell->_RTPpkg_ptr->modifyData(rtp_cell->_RTPpkg_head_pos+rtp_cell->_tcp_prefix+2,(uint8_t*)&seq,2); } + } };