mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-10-30 16:27:36 +08:00
rtsp推流拉流转发时修整sdp
rtsp推流修整时间戳
This commit is contained in:
parent
bf7363714d
commit
fb1d7dd5a6
3
.gitignore
vendored
3
.gitignore
vendored
@ -33,4 +33,5 @@
|
||||
|
||||
/cmake-build-debug/
|
||||
/.idea/
|
||||
/c_wrapper/.idea/
|
||||
/c_wrapper/.idea/
|
||||
/release/mac/Debug/
|
@ -161,13 +161,16 @@ namespace Rtsp {
|
||||
const string kAuthBasic = RTSP_FIELD"authBasic";
|
||||
const string kHandshakeSecond = RTSP_FIELD"handshakeSecond";
|
||||
const string kKeepAliveSecond = RTSP_FIELD"keepAliveSecond";
|
||||
const string kDirectProxy = RTSP_FIELD"directProxy";;
|
||||
const string kDirectProxy = RTSP_FIELD"directProxy";
|
||||
const string kModifyStamp = RTSP_FIELD"modifyStamp";
|
||||
|
||||
onceToken token([](){
|
||||
//默认Md5方式认证
|
||||
mINI::Instance()[kAuthBasic] = 0;
|
||||
mINI::Instance()[kHandshakeSecond] = 15;
|
||||
mINI::Instance()[kKeepAliveSecond] = 15;
|
||||
mINI::Instance()[kDirectProxy] = 1;
|
||||
mINI::Instance()[kModifyStamp] = true;
|
||||
},nullptr);
|
||||
|
||||
} //namespace Rtsp
|
||||
|
@ -209,6 +209,8 @@ extern const string kKeepAliveSecond;
|
||||
//假定您的拉流源地址不是264或265或AAC,那么你可以使用直接代理的方式来支持rtsp代理
|
||||
//默认开启rtsp直接代理,rtmp由于没有这些问题,是强制开启直接代理的
|
||||
extern const string kDirectProxy;
|
||||
//rtsp推流是否修改时间戳
|
||||
extern const string kModifyStamp;
|
||||
} //namespace Rtsp
|
||||
|
||||
////////////RTMP服务器配置///////////
|
||||
|
@ -38,10 +38,6 @@ RtspDemuxer::RtspDemuxer(const string& sdp) {
|
||||
loadSdp(SdpParser(sdp));
|
||||
}
|
||||
|
||||
RtspDemuxer::RtspDemuxer(const SdpParser &attr) {
|
||||
loadSdp(attr);
|
||||
}
|
||||
|
||||
void RtspDemuxer::loadSdp(const SdpParser &attr) {
|
||||
auto tracks = attr.getAvailableTrack();
|
||||
for (auto &track : tracks){
|
||||
|
@ -41,7 +41,6 @@ class RtspDemuxer : public Demuxer{
|
||||
public:
|
||||
typedef std::shared_ptr<RtspDemuxer> Ptr;
|
||||
RtspDemuxer(const string &sdp);
|
||||
RtspDemuxer(const SdpParser &parser);
|
||||
virtual ~RtspDemuxer(){};
|
||||
|
||||
/**
|
||||
|
@ -219,14 +219,14 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
|
||||
_strContentBase.pop_back();
|
||||
}
|
||||
|
||||
SdpParser sdpParser(parser.Content());
|
||||
//解析sdp
|
||||
_sdpParser.load(parser.Content());
|
||||
_aTrackInfo = _sdpParser.getAvailableTrack();
|
||||
_aTrackInfo = sdpParser.getAvailableTrack();
|
||||
|
||||
if (_aTrackInfo.empty()) {
|
||||
throw std::runtime_error("无有效的Sdp Track");
|
||||
}
|
||||
if (!onCheckSDP(parser.Content(), _sdpParser)) {
|
||||
if (!onCheckSDP(sdpParser.toString())) {
|
||||
throw std::runtime_error("onCheckSDP faied");
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
float getPacketLossRate(TrackType type) const override;
|
||||
protected:
|
||||
//派生类回调函数
|
||||
virtual bool onCheckSDP(const string &strSdp, const SdpParser &parser) = 0;
|
||||
virtual bool onCheckSDP(const string &strSdp) = 0;
|
||||
virtual void onRecvRTP(const RtpPacket::Ptr &pRtppt, const SdpTrack::Ptr &track) = 0;
|
||||
uint32_t getProgressMilliSecond() const;
|
||||
void seekToMilliSecond(uint32_t ms);
|
||||
@ -124,7 +124,6 @@ private:
|
||||
void createUdpSockIfNecessary(int track_idx);
|
||||
private:
|
||||
string _strUrl;
|
||||
SdpParser _sdpParser;
|
||||
vector<SdpTrack::Ptr> _aTrackInfo;
|
||||
function<void(const Parser&)> _onHandshake;
|
||||
Socket::Ptr _apRtpSock[2]; //RTP端口,trackid idx 为数组下标
|
||||
|
@ -61,12 +61,12 @@ public:
|
||||
};
|
||||
private:
|
||||
//派生类回调函数
|
||||
bool onCheckSDP(const string &sdp, const SdpParser &parser) override {
|
||||
bool onCheckSDP(const string &sdp) override {
|
||||
_pRtspMediaSrc = dynamic_pointer_cast<RtspMediaSource>(_pMediaSrc);
|
||||
if(_pRtspMediaSrc){
|
||||
_pRtspMediaSrc->onGetSDP(parser.toString());
|
||||
_pRtspMediaSrc->onGetSDP(sdp);
|
||||
}
|
||||
_parser.reset(new RtspDemuxer(parser));
|
||||
_parser.reset(new RtspDemuxer(sdp));
|
||||
return true;
|
||||
}
|
||||
void onRecvRTP(const RtpPacket::Ptr &rtp, const SdpTrack::Ptr &track) override {
|
||||
|
@ -242,13 +242,13 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
|
||||
throw SockException(Err_shutdown,err);
|
||||
}
|
||||
|
||||
_strSession = makeRandStr(12);
|
||||
_strSdp = parser.Content();
|
||||
_aTrackInfo = SdpParser(_strSdp).getAvailableTrack();
|
||||
SdpParser sdpParser(parser.Content());
|
||||
_strSession = makeRandStr(12);
|
||||
_aTrackInfo = sdpParser.getAvailableTrack();
|
||||
|
||||
_pushSrc = std::make_shared<RtspToRtmpMediaSource>(_mediaInfo._vhost,_mediaInfo._app,_mediaInfo._streamid);
|
||||
_pushSrc->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this()));
|
||||
_pushSrc->onGetSDP(_strSdp);
|
||||
_pushSrc->onGetSDP(sdpParser.toString());
|
||||
sendRtspResponse("200 OK");
|
||||
}
|
||||
|
||||
@ -362,9 +362,7 @@ void RtspSession::onAuthSuccess() {
|
||||
return;
|
||||
}
|
||||
//找到了响应的rtsp流
|
||||
strongSelf->_strSdp = rtsp_src->getSdp();
|
||||
SdpParser sdpParser(strongSelf->_strSdp);
|
||||
strongSelf->_aTrackInfo = sdpParser.getAvailableTrack();
|
||||
strongSelf->_aTrackInfo = SdpParser(rtsp_src->getSdp()).getAvailableTrack();
|
||||
if (strongSelf->_aTrackInfo.empty()) {
|
||||
//该流无效
|
||||
strongSelf->send_StreamNotFound();
|
||||
@ -383,7 +381,7 @@ void RtspSession::onAuthSuccess() {
|
||||
{"Content-Base",strongSelf->_strContentBase + "/",
|
||||
"x-Accept-Retransmit","our-retransmit",
|
||||
"x-Accept-Dynamic-Rate","1"
|
||||
},strongSelf->_strSdp);
|
||||
},rtsp_src->getSdp());
|
||||
});
|
||||
}
|
||||
void RtspSession::onAuthFailed(const string &realm,const string &why,bool close) {
|
||||
@ -918,7 +916,12 @@ inline void RtspSession::send_NotAcceptable() {
|
||||
|
||||
|
||||
void RtspSession::onRtpSorted(const RtpPacket::Ptr &rtppt, int trackidx) {
|
||||
|
||||
GET_CONFIG(bool,modify_stamp,Rtsp::kModifyStamp);
|
||||
if(modify_stamp){
|
||||
int64_t dts_out;
|
||||
_stamp[trackidx].revise(0, 0, dts_out, dts_out);
|
||||
rtppt->timeStamp = dts_out;
|
||||
}
|
||||
_pushSrc->onWrite(rtppt, false);
|
||||
}
|
||||
inline void RtspSession::onRcvPeerUdpData(int intervaled, const Buffer::Ptr &pBuf, const struct sockaddr& addr) {
|
||||
|
@ -190,8 +190,6 @@ private:
|
||||
int _iCseq = 0;
|
||||
//ContentBase
|
||||
string _strContentBase;
|
||||
//推流端发送的sdp或播放端请求的sdp
|
||||
string _strSdp;
|
||||
//Session号
|
||||
string _strSession;
|
||||
//是否第一次播放,第一次播放需要鉴权,第二次播放属于暂停恢复
|
||||
@ -235,6 +233,8 @@ private:
|
||||
RtcpCounter _aRtcpCnt[2];
|
||||
//rtcp发送时间,trackid idx 为数组下标
|
||||
Ticker _aRtcpTicker[2];
|
||||
//时间戳修整器
|
||||
Stamp _stamp[2];
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user