mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-29 14:45:55 +08:00
新增支持mjpeg es rtp流
mpegts/g711 payload改成固定模式
This commit is contained in:
parent
ae950606cb
commit
77e46353ce
@ -293,15 +293,8 @@ h264_pt=98
|
|||||||
h265_pt=99
|
h265_pt=99
|
||||||
#rtp ps 负载的pt
|
#rtp ps 负载的pt
|
||||||
ps_pt=96
|
ps_pt=96
|
||||||
#rtp ts 负载的pt
|
|
||||||
ts_pt=33
|
|
||||||
#rtp opus 负载的pt
|
#rtp opus 负载的pt
|
||||||
opus_pt=100
|
opus_pt=100
|
||||||
#rtp g711u 负载的pt
|
|
||||||
g711u_pt=0
|
|
||||||
#rtp g711a 负载的pt
|
|
||||||
g711a_pt=8
|
|
||||||
|
|
||||||
|
|
||||||
[rtc]
|
[rtc]
|
||||||
#rtc播放推流、播放超时时间
|
#rtc播放推流、播放超时时间
|
||||||
|
@ -317,10 +317,7 @@ const string kPortRange = RTP_PROXY_FIELD "port_range";
|
|||||||
const string kH264PT = RTP_PROXY_FIELD "h264_pt";
|
const string kH264PT = RTP_PROXY_FIELD "h264_pt";
|
||||||
const string kH265PT = RTP_PROXY_FIELD "h265_pt";
|
const string kH265PT = RTP_PROXY_FIELD "h265_pt";
|
||||||
const string kPSPT = RTP_PROXY_FIELD "ps_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 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([]() {
|
static onceToken token([]() {
|
||||||
mINI::Instance()[kDumpDir] = "";
|
mINI::Instance()[kDumpDir] = "";
|
||||||
@ -329,10 +326,7 @@ static onceToken token([]() {
|
|||||||
mINI::Instance()[kH264PT] = 98;
|
mINI::Instance()[kH264PT] = 98;
|
||||||
mINI::Instance()[kH265PT] = 99;
|
mINI::Instance()[kH265PT] = 99;
|
||||||
mINI::Instance()[kPSPT] = 96;
|
mINI::Instance()[kPSPT] = 96;
|
||||||
mINI::Instance()[kTSPT] = 33;
|
|
||||||
mINI::Instance()[kOpusPT] = 100;
|
mINI::Instance()[kOpusPT] = 100;
|
||||||
mINI::Instance()[kG711UPT] = 0;
|
|
||||||
mINI::Instance()[kG711APT] = 8;
|
|
||||||
});
|
});
|
||||||
} // namespace RtpProxy
|
} // namespace RtpProxy
|
||||||
|
|
||||||
|
@ -350,14 +350,8 @@ extern const std::string kH264PT;
|
|||||||
extern const std::string kH265PT;
|
extern const std::string kH265PT;
|
||||||
// rtp server ps 的pt
|
// rtp server ps 的pt
|
||||||
extern const std::string kPSPT;
|
extern const std::string kPSPT;
|
||||||
// rtp server ts 的pt
|
|
||||||
extern const std::string kTSPT;
|
|
||||||
// rtp server opus 的pt
|
// rtp server opus 的pt
|
||||||
extern const std::string kOpusPT;
|
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
|
} // namespace RtpProxy
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,14 +13,15 @@
|
|||||||
#include "Extension/CommonRtp.h"
|
#include "Extension/CommonRtp.h"
|
||||||
#include "Extension/Factory.h"
|
#include "Extension/Factory.h"
|
||||||
#include "Extension/G711.h"
|
#include "Extension/G711.h"
|
||||||
#include "Extension/H264Rtp.h"
|
#include "Extension/H264.h"
|
||||||
#include "Extension/H265.h"
|
#include "Extension/H265.h"
|
||||||
#include "Extension/Opus.h"
|
#include "Extension/Opus.h"
|
||||||
|
#include "Extension/JPEG.h"
|
||||||
#include "Http/HttpTSPlayer.h"
|
#include "Http/HttpTSPlayer.h"
|
||||||
#include "Util/File.h"
|
#include "Util/File.h"
|
||||||
#include "Common/config.h"
|
#include "Common/config.h"
|
||||||
#include "Rtsp/RtpCodec.h"
|
|
||||||
#include "Rtsp/RtpReceiver.h"
|
#include "Rtsp/RtpReceiver.h"
|
||||||
|
#include "Rtsp/Rtsp.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace toolkit;
|
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, h264_pt, RtpProxy::kH264PT);
|
||||||
GET_CONFIG(uint32_t, h265_pt, RtpProxy::kH265PT);
|
GET_CONFIG(uint32_t, h265_pt, RtpProxy::kH265PT);
|
||||||
GET_CONFIG(uint32_t, ps_pt, RtpProxy::kPSPT);
|
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, opus_pt, RtpProxy::kOpusPT);
|
||||||
GET_CONFIG(uint32_t, g711u_pt, RtpProxy::kG711UPT);
|
|
||||||
GET_CONFIG(uint32_t, g711a_pt, RtpProxy::kG711APT);
|
|
||||||
|
|
||||||
RtpHeader *header = (RtpHeader *)data;
|
RtpHeader *header = (RtpHeader *)data;
|
||||||
auto pt = header->pt;
|
auto pt = header->pt;
|
||||||
@ -89,48 +87,54 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
|
|||||||
// 防止pt类型太多导致内存溢出
|
// 防止pt类型太多导致内存溢出
|
||||||
throw std::invalid_argument("rtp pt类型不得超过2种!");
|
throw std::invalid_argument("rtp pt类型不得超过2种!");
|
||||||
}
|
}
|
||||||
|
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 = std::make_shared<G711Track>(pt == Rtsp::PT_PCMU ? CodecG711U : CodecG711A, 8000, 1, 16);
|
||||||
|
_interface->addTrack(track);
|
||||||
|
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Rtsp::PT_JPEG: {
|
||||||
|
// mjpeg
|
||||||
|
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
|
||||||
|
auto track = std::make_shared<JPEGTrack>();
|
||||||
|
_interface->addTrack(track);
|
||||||
|
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
if (pt == opus_pt) {
|
if (pt == opus_pt) {
|
||||||
// opus负载
|
// opus负载
|
||||||
ref = std::make_shared<RtpReceiverImp>(48000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
|
ref = std::make_shared<RtpReceiverImp>(48000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
|
||||||
|
|
||||||
auto track = std::make_shared<OpusTrack>();
|
auto track = std::make_shared<OpusTrack>();
|
||||||
_interface->addTrack(track);
|
_interface->addTrack(track);
|
||||||
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
||||||
} else if (pt == h265_pt) {
|
} else if (pt == h265_pt) {
|
||||||
// H265负载
|
// H265负载
|
||||||
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
|
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
|
||||||
|
|
||||||
auto track = std::make_shared<H265Track>();
|
auto track = std::make_shared<H265Track>();
|
||||||
_interface->addTrack(track);
|
_interface->addTrack(track);
|
||||||
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
||||||
} else if (pt == h264_pt) {
|
} else if (pt == h264_pt) {
|
||||||
// H264负载
|
// H264负载
|
||||||
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
|
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
|
||||||
|
|
||||||
auto track = std::make_shared<H264Track>();
|
auto track = std::make_shared<H264Track>();
|
||||||
_interface->addTrack(track);
|
_interface->addTrack(track);
|
||||||
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
||||||
} else if (pt == g711u_pt || pt == g711a_pt) {
|
|
||||||
// CodecG711U
|
|
||||||
// CodecG711A
|
|
||||||
ref = std::make_shared<RtpReceiverImp>(8000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
|
|
||||||
|
|
||||||
auto track = std::make_shared<G711Track>(pt == g711u_pt ? CodecG711U : CodecG711A, 8000, 1, 16);
|
|
||||||
_interface->addTrack(track);
|
|
||||||
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
|
||||||
} else {
|
} else {
|
||||||
if (pt != ts_pt && pt != ps_pt) {
|
if (pt != Rtsp::PT_MP2T && pt != ps_pt) {
|
||||||
WarnL << "rtp payload type未识别(" << (int)pt << "),已按ts或ps负载处理";
|
WarnL << "rtp payload type未识别(" << (int)pt << "),已按ts或ps负载处理";
|
||||||
}
|
}
|
||||||
|
|
||||||
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
|
ref = std::make_shared<RtpReceiverImp>(90000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
|
||||||
|
|
||||||
// ts或ps负载
|
// ts或ps负载
|
||||||
_rtp_decoder[pt] = std::make_shared<CommonRtpDecoder>(CodecInvalid, 32 * 1024);
|
_rtp_decoder[pt] = std::make_shared<CommonRtpDecoder>(CodecInvalid, 32 * 1024);
|
||||||
// 设置dump目录
|
// 设置dump目录
|
||||||
GET_CONFIG(string, dump_dir, RtpProxy::kDumpDir);
|
GET_CONFIG(string, dump_dir, RtpProxy::kDumpDir);
|
||||||
if (!dump_dir.empty()) {
|
if (!dump_dir.empty()) {
|
||||||
auto save_path = File::absolutePath(_media_info._streamid + ".mp2", dump_dir);
|
auto save_path = File::absolutePath(_media_info._streamid + ".mpeg", dump_dir);
|
||||||
_save_file_ps.reset(File::create_file(save_path.data(), "wb"), [](FILE *fp) {
|
_save_file_ps.reset(File::create_file(save_path.data(), "wb"), [](FILE *fp) {
|
||||||
if (fp) {
|
if (fp) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -138,6 +142,9 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
// 设置frame回调
|
// 设置frame回调
|
||||||
_rtp_decoder[pt]->addDelegate([this](const Frame::Ptr &frame) {
|
_rtp_decoder[pt]->addDelegate([this](const Frame::Ptr &frame) {
|
||||||
onRtpDecode(frame);
|
onRtpDecode(frame);
|
||||||
|
Loading…
Reference in New Issue
Block a user