mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-10-30 16:27:36 +08:00
尝试添加rtp类型自动判断逻辑
This commit is contained in:
parent
f384f5e025
commit
c77f82f02c
@ -168,8 +168,6 @@ checkSource=1
|
|||||||
dumpDir=
|
dumpDir=
|
||||||
#udp和tcp代理服务器,支持rtp(必须是ts或ps类型)代理
|
#udp和tcp代理服务器,支持rtp(必须是ts或ps类型)代理
|
||||||
port=10000
|
port=10000
|
||||||
#rtp如果是ts/ps类型则选择MP2P,还可以设置为MP4V-ES
|
|
||||||
rtp_type=MP2P
|
|
||||||
#rtp超时时间,单位秒
|
#rtp超时时间,单位秒
|
||||||
timeoutSec=15
|
timeoutSec=15
|
||||||
|
|
||||||
|
@ -282,15 +282,12 @@ namespace RtpProxy {
|
|||||||
const string kDumpDir = RTP_PROXY_FIELD"dumpDir";
|
const string kDumpDir = RTP_PROXY_FIELD"dumpDir";
|
||||||
//是否限制udp数据来源ip和端口
|
//是否限制udp数据来源ip和端口
|
||||||
const string kCheckSource = RTP_PROXY_FIELD"checkSource";
|
const string kCheckSource = RTP_PROXY_FIELD"checkSource";
|
||||||
//rtp类型,支持MP2P/MP4V-ES
|
|
||||||
const string kRtpType = RTP_PROXY_FIELD"rtp_type";
|
|
||||||
//rtp接收超时时间
|
//rtp接收超时时间
|
||||||
const string kTimeoutSec = RTP_PROXY_FIELD"timeoutSec";
|
const string kTimeoutSec = RTP_PROXY_FIELD"timeoutSec";
|
||||||
|
|
||||||
onceToken token([](){
|
onceToken token([](){
|
||||||
mINI::Instance()[kDumpDir] = "";
|
mINI::Instance()[kDumpDir] = "";
|
||||||
mINI::Instance()[kCheckSource] = 1;
|
mINI::Instance()[kCheckSource] = 1;
|
||||||
mINI::Instance()[kRtpType] = "MP2P";
|
|
||||||
mINI::Instance()[kTimeoutSec] = 15;
|
mINI::Instance()[kTimeoutSec] = 15;
|
||||||
},nullptr);
|
},nullptr);
|
||||||
} //namespace RtpProxy
|
} //namespace RtpProxy
|
||||||
|
@ -306,8 +306,6 @@ namespace RtpProxy {
|
|||||||
extern const string kDumpDir;
|
extern const string kDumpDir;
|
||||||
//是否限制udp数据来源ip和端口
|
//是否限制udp数据来源ip和端口
|
||||||
extern const string kCheckSource;
|
extern const string kCheckSource;
|
||||||
//rtp类型,支持MP2P/MP4V-ES
|
|
||||||
extern const string kRtpType;
|
|
||||||
//rtp接收超时时间
|
//rtp接收超时时间
|
||||||
extern const string kTimeoutSec;
|
extern const string kTimeoutSec;
|
||||||
} //namespace RtpProxy
|
} //namespace RtpProxy
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
#include "Util/logger.h"
|
#include "Util/logger.h"
|
||||||
#include "RtpDecoder.h"
|
#include "RtpDecoder.h"
|
||||||
#include "rtp-payload.h"
|
#include "rtp-payload.h"
|
||||||
|
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
@ -45,7 +44,13 @@ RtpDecoder::~RtpDecoder() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtpDecoder::decodeRtp(const void *data, int bytes,const char *type_name) {
|
void RtpDecoder::decodeRtp(const void *data, int bytes,const string &type_name) {
|
||||||
|
if(_rtp_type != type_name && _rtp_decoder){
|
||||||
|
//rtp类型发生变化,切换之
|
||||||
|
rtp_payload_decode_destroy(_rtp_decoder);
|
||||||
|
_rtp_decoder = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if(!_rtp_decoder){
|
if(!_rtp_decoder){
|
||||||
static rtp_payload_t s_func= {
|
static rtp_payload_t s_func= {
|
||||||
[](void* param, int bytes){
|
[](void* param, int bytes){
|
||||||
@ -64,11 +69,14 @@ void RtpDecoder::decodeRtp(const void *data, int bytes,const char *type_name) {
|
|||||||
|
|
||||||
uint8_t rtp_type = 0x7F & ((uint8_t *) data)[1];
|
uint8_t rtp_type = 0x7F & ((uint8_t *) data)[1];
|
||||||
InfoL << "rtp type:" << (int) rtp_type;
|
InfoL << "rtp type:" << (int) rtp_type;
|
||||||
_rtp_decoder = rtp_payload_decode_create(rtp_type, type_name, &s_func, this);
|
_rtp_decoder = rtp_payload_decode_create(rtp_type, type_name.data(), &s_func, this);
|
||||||
if (!_rtp_decoder) {
|
if (!_rtp_decoder) {
|
||||||
WarnL << "unsupported rtp type:" << (int) rtp_type << ",size:" << bytes << ",hexdump" << hexdump(data, bytes > 16 ? 16 : bytes);
|
WarnL << "unsupported rtp type:" << (int) rtp_type << ",size:" << bytes << ",hexdump" << hexdump(data, bytes > 16 ? 16 : bytes);
|
||||||
|
}else{
|
||||||
|
_rtp_type = type_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_rtp_decoder){
|
if(_rtp_decoder){
|
||||||
rtp_payload_decode_input(_rtp_decoder,data,bytes);
|
rtp_payload_decode_input(_rtp_decoder,data,bytes);
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,12 @@ public:
|
|||||||
RtpDecoder();
|
RtpDecoder();
|
||||||
virtual ~RtpDecoder();
|
virtual ~RtpDecoder();
|
||||||
protected:
|
protected:
|
||||||
void decodeRtp(const void *data, int bytes,const char *type_name);
|
void decodeRtp(const void *data, int bytes,const string &type_name);
|
||||||
virtual void onRtpDecode(const void *packet, int bytes, uint32_t timestamp, int flags) = 0;
|
virtual void onRtpDecode(const void *packet, int bytes, uint32_t timestamp, int flags) = 0;
|
||||||
private:
|
private:
|
||||||
void *_rtp_decoder = nullptr;
|
void *_rtp_decoder = nullptr;
|
||||||
BufferRaw::Ptr _buffer;
|
BufferRaw::Ptr _buffer;
|
||||||
|
string _rtp_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
namespace mediakit{
|
namespace mediakit{
|
||||||
|
|
||||||
|
static const vector<string> kRtpTypes = {"MP2P","MP4V-ES"};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合并一些时间戳相同的frame
|
* 合并一些时间戳相同的frame
|
||||||
@ -84,6 +85,7 @@ RtpProcess::RtpProcess(uint32_t ssrc) {
|
|||||||
_track->_samplerate = 90000;
|
_track->_samplerate = 90000;
|
||||||
_track->_type = TrackVideo;
|
_track->_type = TrackVideo;
|
||||||
_track->_ssrc = _ssrc;
|
_track->_ssrc = _ssrc;
|
||||||
|
getNextRtpType();
|
||||||
DebugL << printSSRC(_ssrc);
|
DebugL << printSSRC(_ssrc);
|
||||||
|
|
||||||
GET_CONFIG(bool,toRtxp,General::kPublishToRtxp);
|
GET_CONFIG(bool,toRtxp,General::kPublishToRtxp);
|
||||||
@ -153,6 +155,14 @@ bool RtpProcess::inputRtp(const char *data, int data_len,const struct sockaddr *
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RtpProcess::getNextRtpType(){
|
||||||
|
_rtp_type = kRtpTypes[_rtp_type_idx++];
|
||||||
|
_rtp_dec_failed_cnt = 0;
|
||||||
|
if(_rtp_type_idx == kRtpTypes.size()){
|
||||||
|
_rtp_type_idx = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RtpProcess::onRtpSorted(const RtpPacket::Ptr &rtp, int) {
|
void RtpProcess::onRtpSorted(const RtpPacket::Ptr &rtp, int) {
|
||||||
if(rtp->sequence != _sequence + 1){
|
if(rtp->sequence != _sequence + 1){
|
||||||
WarnL << rtp->sequence << " != " << _sequence << "+1";
|
WarnL << rtp->sequence << " != " << _sequence << "+1";
|
||||||
@ -166,8 +176,7 @@ void RtpProcess::onRtpSorted(const RtpPacket::Ptr &rtp, int) {
|
|||||||
fwrite((uint8_t *) rtp->data() + 4, rtp->size() - 4, 1, _save_file_rtp.get());
|
fwrite((uint8_t *) rtp->data() + 4, rtp->size() - 4, 1, _save_file_rtp.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
GET_CONFIG(string,rtp_type,::RtpProxy::kRtpType);
|
decodeRtp(rtp->data() + 4 ,rtp->size() - 4,_rtp_type);
|
||||||
decodeRtp(rtp->data() + 4 ,rtp->size() - 4,rtp_type.data());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtpProcess::onRtpDecode(const void *packet, int bytes, uint32_t, int flags) {
|
void RtpProcess::onRtpDecode(const void *packet, int bytes, uint32_t, int flags) {
|
||||||
@ -178,6 +187,12 @@ void RtpProcess::onRtpDecode(const void *packet, int bytes, uint32_t, int flags)
|
|||||||
auto ret = decodePS((uint8_t *)packet,bytes);
|
auto ret = decodePS((uint8_t *)packet,bytes);
|
||||||
if(ret != bytes){
|
if(ret != bytes){
|
||||||
WarnL << ret << " != " << bytes << " " << flags;
|
WarnL << ret << " != " << bytes << " " << flags;
|
||||||
|
if(++_rtp_dec_failed_cnt == 10){
|
||||||
|
getNextRtpType();
|
||||||
|
InfoL << "rtp of ssrc " << printSSRC(_ssrc) << " change to type: " << _rtp_type ;
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
_rtp_dec_failed_cnt = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,5 +322,6 @@ void RtpProcess::setListener(const std::weak_ptr<MediaSourceEvent> &listener){
|
|||||||
_muxer->setListener(listener);
|
_muxer->setListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
#endif//defined(ENABLE_RTPPROXY)
|
#endif//defined(ENABLE_RTPPROXY)
|
@ -62,6 +62,8 @@ protected:
|
|||||||
int64_t dts,
|
int64_t dts,
|
||||||
const void *data,
|
const void *data,
|
||||||
int bytes) override ;
|
int bytes) override ;
|
||||||
|
private:
|
||||||
|
void getNextRtpType();
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<FILE> _save_file_rtp;
|
std::shared_ptr<FILE> _save_file_rtp;
|
||||||
std::shared_ptr<FILE> _save_file_ps;
|
std::shared_ptr<FILE> _save_file_ps;
|
||||||
@ -77,6 +79,9 @@ private:
|
|||||||
Ticker _last_rtp_time;
|
Ticker _last_rtp_time;
|
||||||
map<int,Stamp> _stamps;
|
map<int,Stamp> _stamps;
|
||||||
uint32_t _dts = 0;
|
uint32_t _dts = 0;
|
||||||
|
int _rtp_type_idx = 0;
|
||||||
|
string _rtp_type;
|
||||||
|
int _rtp_dec_failed_cnt = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//namespace mediakit
|
}//namespace mediakit
|
||||||
|
@ -98,8 +98,6 @@ int main(int argc,char *argv[]) {
|
|||||||
rtspSrv->start<RtspSession>(554);//默认554
|
rtspSrv->start<RtspSession>(554);//默认554
|
||||||
rtmpSrv->start<RtmpSession>(1935);//默认1935
|
rtmpSrv->start<RtmpSession>(1935);//默认1935
|
||||||
httpSrv->start<HttpSession>(80);//默认80
|
httpSrv->start<HttpSession>(80);//默认80
|
||||||
//此处可以选择MP4V-ES或MP2P
|
|
||||||
mINI::Instance()[RtpProxy::kRtpType] = "MP4V-ES";
|
|
||||||
//此处选择是否导出调试文件
|
//此处选择是否导出调试文件
|
||||||
// mINI::Instance()[RtpProxy::kDumpDir] = "/Users/xzl/Desktop/";
|
// mINI::Instance()[RtpProxy::kDumpDir] = "/Users/xzl/Desktop/";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user