mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
for rtp server can config pt
This commit is contained in:
parent
559b4d3fe7
commit
6a337adc91
@ -265,6 +265,28 @@ timeoutSec=15
|
||||
#该范围同时限制rtsp服务器udp端口范围
|
||||
port_range=30000-35000
|
||||
|
||||
#rtp h264 负载的pt
|
||||
h264_pt=98
|
||||
|
||||
#rtp h265 负载的pt
|
||||
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播放推流、播放超时时间
|
||||
timeoutSec=15
|
||||
|
@ -8,13 +8,13 @@
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "Common/config.h"
|
||||
#include "Util/util.h"
|
||||
#include "Util/NoticeCenter.h"
|
||||
#include "Util/logger.h"
|
||||
#include "Util/onceToken.h"
|
||||
#include "Util/NoticeCenter.h"
|
||||
#include "Util/util.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
@ -159,9 +159,7 @@ namespace Shell {
|
||||
#define SHELL_FIELD "shell."
|
||||
const string kMaxReqSize = SHELL_FIELD "maxReqSize";
|
||||
|
||||
static onceToken token([](){
|
||||
mINI::Instance()[kMaxReqSize] = 1024;
|
||||
});
|
||||
static onceToken token([]() { mINI::Instance()[kMaxReqSize] = 1024; });
|
||||
} // namespace Shell
|
||||
|
||||
////////////RTSP服务器配置///////////
|
||||
@ -193,8 +191,7 @@ static onceToken token([](){
|
||||
mINI::Instance()[kHandshakeSecond] = 15;
|
||||
mINI::Instance()[kKeepAliveSecond] = 15;
|
||||
});
|
||||
} //namespace RTMP
|
||||
|
||||
} // namespace Rtmp
|
||||
|
||||
////////////RTP配置///////////
|
||||
namespace Rtp {
|
||||
@ -210,7 +207,7 @@ static onceToken token([](){
|
||||
mINI::Instance()[kAudioMtuSize] = 600;
|
||||
mINI::Instance()[kRtpMaxSize] = 10;
|
||||
});
|
||||
} //namespace Rtsp
|
||||
} // namespace Rtp
|
||||
|
||||
////////////组播配置///////////
|
||||
namespace MultiCast {
|
||||
@ -275,22 +272,34 @@ static onceToken token([](){
|
||||
});
|
||||
} // namespace Hls
|
||||
|
||||
|
||||
////////////Rtp代理相关配置///////////
|
||||
namespace RtpProxy {
|
||||
#define RTP_PROXY_FIELD "rtp_proxy."
|
||||
const string kDumpDir = RTP_PROXY_FIELD "dumpDir";
|
||||
const string kTimeoutSec = RTP_PROXY_FIELD "timeoutSec";
|
||||
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] = "";
|
||||
mINI::Instance()[kTimeoutSec] = 15;
|
||||
mINI::Instance()[kPortRange] = "30000-35000";
|
||||
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
|
||||
|
||||
|
||||
namespace Client {
|
||||
const string kNetAdapter = "net_adapter";
|
||||
const string kRtpType = "rtp_type";
|
||||
@ -302,7 +311,7 @@ const string kMediaTimeoutMS = "media_timeout_ms";
|
||||
const string kBeatIntervalMS = "beat_interval_ms";
|
||||
const string kBenchmarkMode = "benchmark_mode";
|
||||
const string kWaitTrackReady = "wait_track_ready";
|
||||
}
|
||||
} // namespace Client
|
||||
|
||||
} // namespace mediakit
|
||||
|
||||
@ -370,13 +379,9 @@ public:
|
||||
// printf("%s %d\r\n", __FUNCTION__, (int) _is_thread_local);
|
||||
}
|
||||
|
||||
void *operator new(size_t sz) {
|
||||
return __real_malloc(sz);
|
||||
}
|
||||
void *operator new(size_t sz) { return __real_malloc(sz); }
|
||||
|
||||
void operator delete(void *ptr) {
|
||||
__real_free(ptr);
|
||||
}
|
||||
void operator delete(void *ptr) { __real_free(ptr); }
|
||||
|
||||
void addBlock(size_t c) {
|
||||
if (total_mem) {
|
||||
@ -410,13 +415,9 @@ public:
|
||||
ptr->addBlock(1);
|
||||
}
|
||||
|
||||
~MemThreadInfoLocal() {
|
||||
ptr->delBlock(1);
|
||||
}
|
||||
~MemThreadInfoLocal() { ptr->delBlock(1); }
|
||||
|
||||
MemThreadInfo *get() const {
|
||||
return ptr;
|
||||
}
|
||||
MemThreadInfo *get() const { return ptr; }
|
||||
|
||||
private:
|
||||
MemThreadInfo *ptr;
|
||||
@ -465,10 +466,10 @@ public:
|
||||
#if (defined(__linux__) && !defined(ANDROID)) || defined(__MACH__)
|
||||
#define MAX_STACK_FRAMES 128
|
||||
#define MEM_WARING
|
||||
#include <execinfo.h>
|
||||
#include <limits.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/wait.h>
|
||||
#include <execinfo.h>
|
||||
|
||||
static void print_mem_waring(size_t c) {
|
||||
void *array[MAX_STACK_FRAMES];
|
||||
|
@ -8,15 +8,14 @@
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef COMMON_CONFIG_H
|
||||
#define COMMON_CONFIG_H
|
||||
|
||||
#include <functional>
|
||||
#include "Util/NoticeCenter.h"
|
||||
#include "Util/mini.h"
|
||||
#include "Util/onceToken.h"
|
||||
#include "Util/NoticeCenter.h"
|
||||
#include "macros.h"
|
||||
#include <functional>
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
@ -46,11 +45,14 @@ extern const std::string kBroadcastRecordTs;
|
||||
|
||||
// 收到http api请求广播
|
||||
extern const std::string kBroadcastHttpRequest;
|
||||
#define BroadcastHttpRequestArgs const Parser &parser,const HttpSession::HttpResponseInvoker &invoker,bool &consumed,SockInfo &sender
|
||||
#define BroadcastHttpRequestArgs \
|
||||
const Parser &parser, const HttpSession::HttpResponseInvoker &invoker, bool &consumed, SockInfo &sender
|
||||
|
||||
// 在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限
|
||||
extern const std::string kBroadcastHttpAccess;
|
||||
#define BroadcastHttpAccessArgs const Parser &parser,const std::string &path,const bool &is_dir,const HttpSession::HttpAccessPathInvoker &invoker,SockInfo &sender
|
||||
#define BroadcastHttpAccessArgs \
|
||||
const Parser &parser, const std::string &path, const bool &is_dir, \
|
||||
const HttpSession::HttpAccessPathInvoker &invoker, SockInfo &sender
|
||||
|
||||
// 在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射
|
||||
// 在该事件中通过自行覆盖path参数,可以做到譬如根据虚拟主机或者app选择不同http根目录的目的
|
||||
@ -64,7 +66,9 @@ extern const std::string kBroadcastOnGetRtspRealm;
|
||||
// 请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败
|
||||
// 获取到密码后请调用invoker并输入对应类型的密码和密码类型,invoker执行时会匹配密码
|
||||
extern const std::string kBroadcastOnRtspAuth;
|
||||
#define BroadcastOnRtspAuthArgs const MediaInfo &args,const std::string &realm,const std::string &user_name,const bool &must_no_encrypt,const RtspSession::onAuth &invoker,SockInfo &sender
|
||||
#define BroadcastOnRtspAuthArgs \
|
||||
const MediaInfo &args, const std::string &realm, const std::string &user_name, const bool &must_no_encrypt, \
|
||||
const RtspSession::onAuth &invoker, SockInfo &sender
|
||||
|
||||
// 推流鉴权结果回调对象
|
||||
// 如果err为空则代表鉴权成功
|
||||
@ -72,7 +76,8 @@ using PublishAuthInvoker = std::function<void(const std::string &err, const Prot
|
||||
|
||||
// 收到rtsp/rtmp推流事件广播,通过该事件控制推流鉴权
|
||||
extern const std::string kBroadcastMediaPublish;
|
||||
#define BroadcastMediaPublishArgs const MediaOriginType &type, const MediaInfo &args, const Broadcast::PublishAuthInvoker &invoker,SockInfo &sender
|
||||
#define BroadcastMediaPublishArgs \
|
||||
const MediaOriginType &type, const MediaInfo &args, const Broadcast::PublishAuthInvoker &invoker, SockInfo &sender
|
||||
|
||||
// 播放鉴权结果回调对象
|
||||
// 如果err为空则代表鉴权成功
|
||||
@ -84,11 +89,14 @@ extern const std::string kBroadcastMediaPlayed;
|
||||
|
||||
// shell登录鉴权
|
||||
extern const std::string kBroadcastShellLogin;
|
||||
#define BroadcastShellLoginArgs const std::string &user_name,const std::string &passwd,const Broadcast::AuthInvoker &invoker,SockInfo &sender
|
||||
#define BroadcastShellLoginArgs \
|
||||
const std::string &user_name, const std::string &passwd, const Broadcast::AuthInvoker &invoker, SockInfo &sender
|
||||
|
||||
// 停止rtsp/rtmp/http-flv会话后流量汇报事件广播
|
||||
extern const std::string kBroadcastFlowReport;
|
||||
#define BroadcastFlowReportArgs const MediaInfo &args,const uint64_t &totalBytes,const uint64_t &totalDuration,const bool &isPlayer, SockInfo &sender
|
||||
#define BroadcastFlowReportArgs \
|
||||
const MediaInfo &args, const uint64_t &totalBytes, const uint64_t &totalDuration, const bool &isPlayer, \
|
||||
SockInfo &sender
|
||||
|
||||
// 未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了
|
||||
extern const std::string kBroadcastNotFoundStream;
|
||||
@ -117,18 +125,14 @@ extern const std::string kBroadcastReloadConfig;
|
||||
#define LISTEN_RELOAD_KEY(arg, key, ...) \
|
||||
do { \
|
||||
static ::toolkit::onceToken s_token_listen([]() { \
|
||||
::toolkit::NoticeCenter::Instance().addListener(ReloadConfigTag, \
|
||||
Broadcast::kBroadcastReloadConfig,[](BroadcastReloadConfigArgs) { \
|
||||
__VA_ARGS__; \
|
||||
}); \
|
||||
::toolkit::NoticeCenter::Instance().addListener( \
|
||||
ReloadConfigTag, Broadcast::kBroadcastReloadConfig, [](BroadcastReloadConfigArgs) { __VA_ARGS__; }); \
|
||||
}); \
|
||||
} while (0)
|
||||
|
||||
#define GET_CONFIG(type, arg, key) \
|
||||
static type arg = ::toolkit::mINI::Instance()[key]; \
|
||||
LISTEN_RELOAD_KEY(arg, key, { \
|
||||
RELOAD_KEY(arg, key); \
|
||||
});
|
||||
LISTEN_RELOAD_KEY(arg, key, { RELOAD_KEY(arg, key); });
|
||||
|
||||
#define GET_CONFIG_FUNC(type, arg, key, ...) \
|
||||
static type arg; \
|
||||
@ -199,7 +203,6 @@ extern const std::string kUnreadyFrameCache;
|
||||
extern const std::string kContinuePushMS;
|
||||
} // namespace General
|
||||
|
||||
|
||||
////////////HTTP配置///////////
|
||||
namespace Http {
|
||||
// http 文件发送缓存大小
|
||||
@ -252,8 +255,7 @@ extern const std::string kModifyStamp;
|
||||
extern const std::string kHandshakeSecond;
|
||||
// 维持链接超时时间,默认15秒
|
||||
extern const std::string kKeepAliveSecond;
|
||||
} //namespace RTMP
|
||||
|
||||
} // namespace Rtmp
|
||||
|
||||
////////////RTP配置///////////
|
||||
namespace Rtp {
|
||||
@ -263,7 +265,7 @@ extern const std::string kVideoMtuSize;
|
||||
extern const std::string kAudioMtuSize;
|
||||
// rtp包最大长度限制, 单位KB
|
||||
extern const std::string kRtpMaxSize;
|
||||
} //namespace Rtsp
|
||||
} // namespace Rtp
|
||||
|
||||
////////////组播配置///////////
|
||||
namespace MultiCast {
|
||||
@ -322,6 +324,20 @@ extern const std::string kTimeoutSec;
|
||||
// 随机端口范围,最少确保36个端口
|
||||
// 该范围同时限制rtsp服务器udp端口范围
|
||||
extern const std::string kPortRange;
|
||||
// rtp server h264的pt
|
||||
extern const std::string KH264PT;
|
||||
// rtp server h265的pt
|
||||
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
|
||||
|
||||
/**
|
||||
@ -351,7 +367,7 @@ extern const std::string kBeatIntervalMS;
|
||||
extern const std::string kBenchmarkMode;
|
||||
// 播放器在触发播放成功事件时,是否等待所有track ready时再回调
|
||||
extern const std::string kWaitTrackReady;
|
||||
}
|
||||
} // namespace Client
|
||||
} // namespace mediakit
|
||||
|
||||
#endif /* COMMON_CONFIG_H */
|
||||
|
@ -10,14 +10,14 @@
|
||||
|
||||
#if defined(ENABLE_RTPPROXY)
|
||||
#include "GB28181Process.h"
|
||||
#include "Util/File.h"
|
||||
#include "Http/HttpTSPlayer.h"
|
||||
#include "Extension/CommonRtp.h"
|
||||
#include "Extension/H264Rtp.h"
|
||||
#include "Extension/Factory.h"
|
||||
#include "Extension/Opus.h"
|
||||
#include "Extension/G711.h"
|
||||
#include "Extension/H264Rtp.h"
|
||||
#include "Extension/H265.h"
|
||||
#include "Extension/Opus.h"
|
||||
#include "Http/HttpTSPlayer.h"
|
||||
#include "Util/File.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
@ -66,6 +66,14 @@ void GB28181Process::onRtpSorted(RtpPacket::Ptr rtp) {
|
||||
}
|
||||
|
||||
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;
|
||||
auto &ref = _rtp_receiver[pt];
|
||||
@ -74,64 +82,41 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
|
||||
// 防止pt类型太多导致内存溢出
|
||||
throw std::invalid_argument("rtp pt类型不得超过2种!");
|
||||
}
|
||||
switch (pt) {
|
||||
case 100: {
|
||||
if (pt == opus_pt) {
|
||||
// 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>();
|
||||
_interface->addTrack(track);
|
||||
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
||||
break;
|
||||
}
|
||||
|
||||
case 99: {
|
||||
} else if (pt == h265_pt) {
|
||||
// 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>();
|
||||
_interface->addTrack(track);
|
||||
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
||||
break;
|
||||
}
|
||||
case 98: {
|
||||
} else if (pt == h264_pt) {
|
||||
// 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>();
|
||||
_interface->addTrack(track);
|
||||
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
||||
break;
|
||||
}
|
||||
|
||||
case 0:
|
||||
} else if (pt == g711u_pt || pt == g711a_pt) {
|
||||
// CodecG711U
|
||||
case 8: {
|
||||
// CodecG711A
|
||||
ref = std::make_shared<RtpReceiverImp>(8000,[this](RtpPacket::Ptr rtp) {
|
||||
onRtpSorted(std::move(rtp));
|
||||
});
|
||||
ref = std::make_shared<RtpReceiverImp>(8000, [this](RtpPacket::Ptr rtp) { onRtpSorted(std::move(rtp)); });
|
||||
|
||||
auto track = std::make_shared<G711Track>(pt == 0 ? CodecG711U : CodecG711A, 8000, 1, 16);
|
||||
_interface->addTrack(track);
|
||||
_rtp_decoder[pt] = Factory::getRtpDecoderByTrack(track);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
if (pt != 33 && pt != 96) {
|
||||
} else {
|
||||
if (pt != ts_pt && pt != ps_pt) {
|
||||
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负载
|
||||
_rtp_decoder[pt] = std::make_shared<CommonRtpDecoder>(CodecInvalid, 32 * 1024);
|
||||
@ -145,10 +130,7 @@ bool GB28181Process::inputRtp(bool, const char *data, size_t data_len) {
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置frame回调
|
||||
_rtp_decoder[pt]->addDelegate(std::make_shared<FrameWriterInterfaceHelper>([this](const Frame::Ptr &frame) {
|
||||
onRtpDecode(frame);
|
||||
|
Loading…
Reference in New Issue
Block a user