完善rtp服务器对各编码类型es流的支持

This commit is contained in:
xia-chu 2024-11-30 08:50:07 +08:00
parent 892108d6ba
commit d1f3961326

View File

@ -83,29 +83,22 @@ 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<RtpReceiverImp>(8000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
auto track = Factory::getTrackByCodecId(pt == Rtsp::PT_PCMU ? CodecG711U : CodecG711A, 8000, 1, 16);
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<RtpReceiverImp>(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());
break;
}
case Rtsp::PT_JPEG: {
// mjpeg
ref = std::make_shared<RtpReceiverImp>(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
@ -115,7 +108,9 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
track->setIndex(pt);
_interface->addTrack(track);
_rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId());
} else if (pt == h265_pt) {
break;
}
if (pt == h265_pt) {
// H265负载 [AUTO-TRANSLATED:61fbcf7f]
// H265 payload
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
@ -124,7 +119,9 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
track->setIndex(pt);
_interface->addTrack(track);
_rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId());
} else if (pt == h264_pt) {
break;
}
if (pt == h264_pt) {
// H264负载 [AUTO-TRANSLATED:6f3fbb0d]
// H264 payload
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
@ -133,7 +130,9 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
track->setIndex(pt);
_interface->addTrack(track);
_rtp_decoder[pt] = Factory::getRtpDecoderByCodecId(track->getCodecId());
} else {
break;
}
if (pt != Rtsp::PT_MP2T && pt != ps_pt) {
WarnL << "Unknown rtp payload type(" << (int)pt << "), decode it as mpeg-ps or mpeg-ts";
}
@ -152,10 +151,8 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
}
});
}
}
break;
}
}
} while (false);
// 设置frame回调 [AUTO-TRANSLATED:dec7590f]
// Set frame callback
_rtp_decoder[pt]->addDelegate([this, pt](const Frame::Ptr &frame) {
@ -169,7 +166,12 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
}
void GB28181Process::onRtpDecode(const Frame::Ptr &frame) {
if (frame->getCodecId() != CodecInvalid) {
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);