From d1f3961326dacf54f4d2fd56f7f15fd1b377a30d Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 30 Nov 2024 08:50:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84rtp=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E5=AF=B9=E5=90=84=E7=BC=96=E7=A0=81=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?es=E6=B5=81=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/GB28181Process.cpp | 144 +++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 71 deletions(-) diff --git a/src/Rtp/GB28181Process.cpp b/src/Rtp/GB28181Process.cpp index 26210d05..b5688b0e 100644 --- a/src/Rtp/GB28181Process.cpp +++ b/src/Rtp/GB28181Process.cpp @@ -83,79 +83,76 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) { // Prevent too many pt types from causing memory overflow WarnL << "Rtp payload type more than 2 types: " << _rtp_receiver.size(); } - switch (pt) { - case Rtsp::PT_PCMA: - case Rtsp::PT_PCMU: { - // CodecG711U or CodecG711A - ref = std::make_shared(8000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); - auto track = Factory::getTrackByCodecId(pt == Rtsp::PT_PCMU ? CodecG711U : CodecG711A, 8000, 1, 16); - CHECK(track); - track->setIndex(pt); - _interface->addTrack(track); - _rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId()); - break; - } - case Rtsp::PT_JPEG: { - // mjpeg - ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); - auto track = Factory::getTrackByCodecId(CodecJPEG); - CHECK(track); - track->setIndex(pt); - _interface->addTrack(track); - _rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId()); - break; - } - default: { - if (pt == opus_pt) { - // opus负载 [AUTO-TRANSLATED:defa6a8d] - // opus payload - ref = std::make_shared(48000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); - auto track = Factory::getTrackByCodecId(CodecOpus); + + do { + if (pt < 96) { + auto codec = RtpPayload::getCodecId(pt); + if (codec != CodecInvalid && codec != CodecTS) { + auto sample_rate = RtpPayload::getClockRate(pt); + auto channels = RtpPayload::getAudioChannel(pt); + ref = std::make_shared(sample_rate, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); + auto track = Factory::getTrackByCodecId(codec, sample_rate, channels); CHECK(track); track->setIndex(pt); _interface->addTrack(track); _rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId()); - } else if (pt == h265_pt) { - // H265负载 [AUTO-TRANSLATED:61fbcf7f] - // H265 payload - ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); - auto track = Factory::getTrackByCodecId(CodecH265); - CHECK(track); - track->setIndex(pt); - _interface->addTrack(track); - _rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId()); - } else if (pt == h264_pt) { - // H264负载 [AUTO-TRANSLATED:6f3fbb0d] - // H264 payload - ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); - auto track = Factory::getTrackByCodecId(CodecH264); - CHECK(track); - track->setIndex(pt); - _interface->addTrack(track); - _rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId()); - } else { - if (pt != Rtsp::PT_MP2T && pt != ps_pt) { - WarnL << "Unknown rtp payload type(" << (int)pt << "), decode it as mpeg-ps or mpeg-ts"; - } - ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); - // ts或ps负载 [AUTO-TRANSLATED:3ca31480] - // ts or ps payload - _rtp_decoder[pt] = std::make_shared(CodecInvalid, 32 * 1024); - // 设置dump目录 [AUTO-TRANSLATED:23c88ace] - // Set dump directory - GET_CONFIG(string, dump_dir, RtpProxy::kDumpDir); - if (!dump_dir.empty()) { - auto save_path = File::absolutePath(_media_info.stream + ".mpeg", dump_dir); - _save_file_ps.reset(File::create_file(save_path.data(), "wb"), [](FILE *fp) { - if (fp) { - fclose(fp); - } - }); - } + break; } + } + if (pt == opus_pt) { + // opus负载 [AUTO-TRANSLATED:defa6a8d] + // opus payload + ref = std::make_shared(48000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); + auto track = Factory::getTrackByCodecId(CodecOpus); + CHECK(track); + track->setIndex(pt); + _interface->addTrack(track); + _rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId()); break; } - } + if (pt == h265_pt) { + // H265负载 [AUTO-TRANSLATED:61fbcf7f] + // H265 payload + ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); + auto track = Factory::getTrackByCodecId(CodecH265); + CHECK(track); + track->setIndex(pt); + _interface->addTrack(track); + _rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId()); + break; + } + if (pt == h264_pt) { + // H264负载 [AUTO-TRANSLATED:6f3fbb0d] + // H264 payload + ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); + auto track = Factory::getTrackByCodecId(CodecH264); + CHECK(track); + track->setIndex(pt); + _interface->addTrack(track); + _rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId()); + break; + } + + if (pt != Rtsp::PT_MP2T && pt != ps_pt) { + WarnL << "Unknown rtp payload type(" << (int)pt << "), decode it as mpeg-ps or mpeg-ts"; + } + ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); + // ts或ps负载 [AUTO-TRANSLATED:3ca31480] + // ts or ps payload + _rtp_decoder[pt] = std::make_shared(CodecInvalid, 32 * 1024); + // 设置dump目录 [AUTO-TRANSLATED:23c88ace] + // Set dump directory + GET_CONFIG(string, dump_dir, RtpProxy::kDumpDir); + if (!dump_dir.empty()) { + auto save_path = File::absolutePath(_media_info.stream + ".mpeg", dump_dir); + _save_file_ps.reset(File::create_file(save_path.data(), "wb"), [](FILE *fp) { + if (fp) { + fclose(fp); + } + }); + } + } while (false); + // 设置frame回调 [AUTO-TRANSLATED:dec7590f] // Set frame callback _rtp_decoder[pt]->addDelegate([this, pt](const Frame::Ptr &frame) { @@ -169,11 +166,16 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) { } void GB28181Process::onRtpDecode(const Frame::Ptr &frame) { - if (frame->getCodecId() != CodecInvalid) { - // 这里不是ps或ts [AUTO-TRANSLATED:6f79ac69] - // This is not ps or ts - _interface->inputFrame(frame); - return; + switch (frame->getCodecId()) { + case CodecInvalid: + case CodecTS: + case CodecPS: break; + + default: + // 这里不是ps或ts [AUTO-TRANSLATED:6f79ac69] + // This is not ps or ts + _interface->inputFrame(frame); + return; } // 这是TS或PS [AUTO-TRANSLATED:55782860]