From 77e46353ce845eae807cbbf8c5d788538dde9d91 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Fri, 30 Dec 2022 18:04:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81mjpeg=20es?= =?UTF-8?q?=20rtp=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mpegts/g711 payload改成固定模式 --- conf/config.ini | 7 --- src/Common/config.cpp | 6 --- src/Common/config.h | 6 --- src/Rtp/GB28181Process.cpp | 107 ++++++++++++++++++++----------------- 4 files changed, 57 insertions(+), 69 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index ae0ce077..86b403ea 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -293,15 +293,8 @@ h264_pt=98 h265_pt=99 #rtp ps 负载的pt ps_pt=96 -#rtp ts 负载的pt -ts_pt=33 #rtp opus 负载的pt opus_pt=100 -#rtp g711u 负载的pt -g711u_pt=0 -#rtp g711a 负载的pt -g711a_pt=8 - [rtc] #rtc播放推流、播放超时时间 diff --git a/src/Common/config.cpp b/src/Common/config.cpp index cb24064b..bf8213f1 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -317,10 +317,7 @@ const string kPortRange = RTP_PROXY_FIELD "port_range"; const string kH264PT = RTP_PROXY_FIELD "h264_pt"; const string kH265PT = RTP_PROXY_FIELD "h265_pt"; const string kPSPT = RTP_PROXY_FIELD "ps_pt"; -const string kTSPT = RTP_PROXY_FIELD "ts_pt"; const string kOpusPT = RTP_PROXY_FIELD "opus_pt"; -const string kG711UPT = RTP_PROXY_FIELD "g711u_pt"; -const string kG711APT = RTP_PROXY_FIELD "g711a_pt"; static onceToken token([]() { mINI::Instance()[kDumpDir] = ""; @@ -329,10 +326,7 @@ static onceToken token([]() { mINI::Instance()[kH264PT] = 98; mINI::Instance()[kH265PT] = 99; mINI::Instance()[kPSPT] = 96; - mINI::Instance()[kTSPT] = 33; mINI::Instance()[kOpusPT] = 100; - mINI::Instance()[kG711UPT] = 0; - mINI::Instance()[kG711APT] = 8; }); } // namespace RtpProxy diff --git a/src/Common/config.h b/src/Common/config.h index 36177ec4..cc281f6e 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -350,14 +350,8 @@ extern const std::string kH264PT; extern const std::string kH265PT; // rtp server ps 的pt extern const std::string kPSPT; -// rtp server ts 的pt -extern const std::string kTSPT; // rtp server opus 的pt extern const std::string kOpusPT; -// rtp server g711u 的pt -extern const std::string kG711UPT; -// rtp server g711a 的pt -extern const std::string kG711APT; } // namespace RtpProxy /** diff --git a/src/Rtp/GB28181Process.cpp b/src/Rtp/GB28181Process.cpp index d7bc0142..b4f93f75 100644 --- a/src/Rtp/GB28181Process.cpp +++ b/src/Rtp/GB28181Process.cpp @@ -13,14 +13,15 @@ #include "Extension/CommonRtp.h" #include "Extension/Factory.h" #include "Extension/G711.h" -#include "Extension/H264Rtp.h" +#include "Extension/H264.h" #include "Extension/H265.h" #include "Extension/Opus.h" +#include "Extension/JPEG.h" #include "Http/HttpTSPlayer.h" #include "Util/File.h" #include "Common/config.h" -#include "Rtsp/RtpCodec.h" #include "Rtsp/RtpReceiver.h" +#include "Rtsp/Rtsp.h" using namespace std; using namespace toolkit; @@ -76,10 +77,7 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) { GET_CONFIG(uint32_t, h264_pt, RtpProxy::kH264PT); GET_CONFIG(uint32_t, h265_pt, RtpProxy::kH265PT); GET_CONFIG(uint32_t, ps_pt, RtpProxy::kPSPT); - GET_CONFIG(uint32_t, ts_pt, RtpProxy::kTSPT); GET_CONFIG(uint32_t, opus_pt, RtpProxy::kOpusPT); - GET_CONFIG(uint32_t, g711u_pt, RtpProxy::kG711UPT); - GET_CONFIG(uint32_t, g711a_pt, RtpProxy::kG711APT); RtpHeader *header = (RtpHeader *)data; auto pt = header->pt; @@ -89,53 +87,62 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) { // 防止pt类型太多导致内存溢出 throw std::invalid_argument("rtp pt类型不得超过2种!"); } - if (pt == opus_pt) { - // opus负载 - ref = std::make_shared(48000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); - - auto track = std::make_shared(); - _interface->addTrack(track); - _rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track); - } else if (pt == h265_pt) { - // H265负载 - ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); - - auto track = std::make_shared(); - _interface->addTrack(track); - _rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track); - } else if (pt == h264_pt) { - // H264负载 - ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); - - auto track = std::make_shared(); - _interface->addTrack(track); - _rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track); - } else if (pt == g711u_pt || pt == g711a_pt) { - // CodecG711U - // CodecG711A - ref = std::make_shared(8000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); - - auto track = std::make_shared(pt == g711u_pt ? CodecG711U : CodecG711A, 8000, 1, 16); - _interface->addTrack(track); - _rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track); - } else { - if (pt != ts_pt && pt != ps_pt) { - WarnL << "rtp payload type未识别(" << (int)pt << "),已按ts或ps负载处理"; + 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 = std::make_shared(pt == Rtsp::PT_PCMU ? CodecG711U : CodecG711A, 8000, 1, 16); + _interface->addTrack(track); + _rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track); + break; } - - ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); - - // ts或ps负载 - _rtp_decoder[pt] = std::make_shared(CodecInvalid, 32 * 1024); - // 设置dump目录 - GET_CONFIG(string, dump_dir, RtpProxy::kDumpDir); - if (!dump_dir.empty()) { - auto save_path = File::absolutePath(_media_info._streamid + ".mp2", dump_dir); - _save_file_ps.reset(File::create_file(save_path.data(), "wb"), [](FILE *fp) { - if (fp) { - fclose(fp); + case Rtsp::PT_JPEG: { + // mjpeg + ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); + auto track = std::make_shared(); + _interface->addTrack(track); + _rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track); + break; + } + default: { + if (pt == opus_pt) { + // opus负载 + ref = std::make_shared(48000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); + auto track = std::make_shared(); + _interface->addTrack(track); + _rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track); + } else if (pt == h265_pt) { + // H265负载 + ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); + auto track = std::make_shared(); + _interface->addTrack(track); + _rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track); + } else if (pt == h264_pt) { + // H264负载 + ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); + auto track = std::make_shared(); + _interface->addTrack(track); + _rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track); + } else { + if (pt != Rtsp::PT_MP2T && pt != ps_pt) { + WarnL << "rtp payload type未识别(" << (int)pt << "),已按ts或ps负载处理"; } - }); + ref = std::make_shared(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); }); + // ts或ps负载 + _rtp_decoder[pt] = std::make_shared(CodecInvalid, 32 * 1024); + // 设置dump目录 + GET_CONFIG(string, dump_dir, RtpProxy::kDumpDir); + if (!dump_dir.empty()) { + auto save_path = File::absolutePath(_media_info._streamid + ".mpeg", dump_dir); + _save_file_ps.reset(File::create_file(save_path.data(), "wb"), [](FILE *fp) { + if (fp) { + fclose(fp); + } + }); + } + } + break; } } // 设置frame回调