feat/hk #1

Merged
tqcq merged 8 commits from feat/hk into dev 2024-09-04 10:34:35 +08:00
6 changed files with 64 additions and 10 deletions
Showing only changes of commit fe7da4f638 - Show all commits

View File

@ -31,6 +31,8 @@ set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# set(CMAKE_C_FLAGS$ "${CMAKE_C_FLAGS} -fvisibility = hidden")
# set(CMAKE_CXX_FLAGS$ "${CMAKE_CXX_FLAGS} -fvisibility = hidden")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address
# -fno-omit-frame-pointer")
set(SecMedia_Root ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_compile_options(-fPIC)
# add_compile_options(-fvisibility=hidden) add_compile_options(-std=c++11)
@ -105,10 +107,13 @@ file(GLOB SecMedia_api_list ${CMAKE_CURRENT_SOURCE_DIR}/include/common.h)
# # target_compile_options(${PROJECT_NAME} PRIVATE -fvisibility=hidden)
# list(APPEND LINK_LIB_LIST ${LINK_LIB_SVAC_LIST})
#
find_package(Threads REQUIRED)
add_library(${PROJECT_NAME} SHARED ${SecMedia_src_list})
# add_library(${PROJECT_NAME} STATIC ${SecMedia_src_list})
target_link_libraries(${PROJECT_NAME} PUBLIC ${LINK_LIB_SVAC_LIST} rtp)
target_link_libraries(${PROJECT_NAME} PUBLIC ${LINK_LIB_SVAC_LIST} rtp
Threads::Threads)
target_include_directories(
${PROJECT_NAME}
PRIVATE ${SecMedia_Root}

View File

@ -3,20 +3,21 @@
namespace sign {
FrameManager::FrameManager() { Init(); }
FrameManager::FrameManager() {}
FrameManager::~FrameManager() {}
bool
FrameManager::Initialize()
{
Init();
return _rtp_manager.Initialize();
}
bool
FrameManager::Enqueue(Frame::Ptr frame)
{
CheckMagicNumber();
std::lock_guard<std::mutex> _(_frame_queue_lock);
OnFrameEnqueue(frame);
_frame_queue.push(frame);
@ -26,6 +27,7 @@ FrameManager::Enqueue(Frame::Ptr frame)
Frame::Ptr
FrameManager::Dequeue()
{
CheckMagicNumber();
Frame::Ptr frame{nullptr};
auto start = std::chrono::system_clock::now();
{
@ -54,4 +56,13 @@ FrameManager::Init()
OnFrameEnqueue.connect(&_rtp_manager, &RTPManager::OnFrameEnqueue);
}
void
FrameManager::CheckMagicNumber()
{
if (memcmp(magic_number, "MAGI", 4) != 0) {
ERROL("Please Init FrameManager.\n");
exit(-1);
}
}
}// namespace sign

View File

@ -28,8 +28,10 @@ public:
private:
void Init();
void CheckMagicNumber();
private:
char magic_number[4] = {'M', 'A', 'G', 'I'};
RTPManager _rtp_manager;
std::mutex _frame_queue_lock;

View File

@ -1,3 +1,4 @@
#include "HuaWei/HWcommon.h"
#include "HuaWei/HWsign.h"
#include "base/frame_manager.h"
@ -18,6 +19,10 @@ HK_udp_in(void *Handle, const char *buf, const uint32_t len, void *param)
{
sign::FrameManager *fm = (sign::FrameManager *) Handle;
auto frame = sign::Frame::CreateUDPFrame(buf, len);
if (!frame) {
ERROL("Create frame failed\n");
return -1;
}
fm->Enqueue(frame);
return 1;
}

View File

@ -73,8 +73,15 @@ RTPManager::InitVerifySet(void *info)
void
RTPManager::ProcessUDPFrame(Frame::Ptr frame)
{
if (!IsRTPHeader(frame->data(), frame->size())) { return; }
if (!IsRTPHeader(frame->data(), frame->size())) {
INFOL("Not a RTP packet. discard it.\n");
return;
}
auto packet = RTPPacket::CreateCompleteRTPPacket(this, frame);
if (packet->payload_type() == 112) {
INFOL("RTCP packet pt=112. discard it.\n");
return;
}
ProcessPacket(packet);
}
@ -86,7 +93,7 @@ void
RTPManager::ProcessPacket(RTPPacket::Ptr packet)
{
if (!packet->IsComplete()) {
// ERROL("RTP packet is not complete, discard it.\n");
ERROL("RTP packet is not complete, discard it.\n");
return;
}
@ -99,7 +106,7 @@ RTPManager::ProcessPacket(RTPPacket::Ptr packet)
MaybeSetSeq(packet->seq());
if (packet->seq() != _cur_rtp_seq) {
// WRNGL("RTP packet seq is not continuous. cur_seq=%ld, packet->seq=%d\n", _cur_rtp_seq, packet->seq());
WRNGL("RTP packet seq is not continuous. cur_seq=%ld, packet->seq=%d\n", _cur_rtp_seq, packet->seq());
SetCurSeq(packet->seq());
}
IncCurSeq();
@ -110,7 +117,7 @@ RTPManager::ProcessPacket(RTPPacket::Ptr packet)
}
if (_decoder) { _decoder->Input(packet); }
MaybeReplaceSeq(packet);
// MaybeReplaceSeq(packet);
}
void
@ -156,6 +163,25 @@ RTPManager::GetNextSeq()
return (_cur_rtp_seq + 1) & 0xFFFF;
}
static const char *
ToString(H264Nal::H264Nal_t type)
{
switch (type) {
case H264Nal::NAL_IDR:
return "IDR";
case H264Nal::NAL_SEI:
return "SEI";
case H264Nal::NAL_PPS:
return "PPS";
case H264Nal::NAL_SPS:
return "SPS";
case H264Nal::NAL_P_B:
return "P_B";
default:
return "Unknown";
}
}
void
RTPManager::OnRTPDecoded(RTPDecoder::DecodedPacket packet)
{
@ -169,7 +195,8 @@ RTPManager::OnRTPDecoded(RTPDecoder::DecodedPacket packet)
}
auto str = ss.str();
if (!str.empty()) str.pop_back();
INFOL("RTP decoded. type=%2d, size=%5u seq=[%s]\n", h264_type, packet.bytes, str.c_str());
INFOL("RTP decoded. type=%s, size=%5u seq=[%s]\n", ToString((H264Nal::H264Nal_t) h264_type), packet.bytes,
str.c_str());
if (h264_type == H264Nal::NAL_IDR) {
// remove old sign
ResetSignData();

View File

@ -141,8 +141,12 @@ RTPPacket::RTPPacket(RTPManager *owner, Frame::Ptr udp_frame)
rtp_packet_t pkt;
if (rtp_packet_deserialize(&pkt, udp_frame->data(), udp_frame->size()) == 0) {
_state = kComplete;
if (pkt.payloadlen > 0 && pkt.payload) {
uint8_t h264_type = ((uint8_t *) pkt.payload)[0] & 0x1F;
if (h264_type == H264Nal::NAL_SEI) { udp_frame->set_paused(true); }
} else {
// WRNGL("rtp packet payload is empty\n");
}
} else {
_state = kError;
}