mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
初步支持rtsp推流
This commit is contained in:
parent
84fde961d7
commit
9da5a35524
@ -24,19 +24,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <set>
|
|
||||||
#include <cmath>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "Common/config.h"
|
#include "Common/config.h"
|
||||||
#include "RtspPlayer.h"
|
|
||||||
#include "H264/SPSParser.h"
|
|
||||||
#include "Util/MD5.h"
|
|
||||||
#include "Util/mini.h"
|
|
||||||
#include "Util/util.h"
|
|
||||||
#include "Util/base64.h"
|
|
||||||
#include "Network/sockutil.h"
|
|
||||||
#include "RtpReceiver.h"
|
#include "RtpReceiver.h"
|
||||||
|
|
||||||
#define POP_HEAD(trackidx) \
|
#define POP_HEAD(trackidx) \
|
||||||
|
@ -28,19 +28,12 @@
|
|||||||
#define ZLMEDIAKIT_RTPRECEIVER_H
|
#define ZLMEDIAKIT_RTPRECEIVER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "Rtsp.h"
|
#include "Rtsp.h"
|
||||||
#include "RtspSession.h"
|
#include "RtspMuxer/RtpCodec.h"
|
||||||
#include "RtspMediaSource.h"
|
#include "RtspMediaSource.h"
|
||||||
#include "Player/PlayerBase.h"
|
|
||||||
#include "Util/util.h"
|
|
||||||
#include "Util/logger.h"
|
|
||||||
#include "Util/TimeTicker.h"
|
|
||||||
#include "Poller/Timer.h"
|
|
||||||
#include "Network/Socket.h"
|
|
||||||
#include "Network/TcpClient.h"
|
|
||||||
#include "RtspSplitter.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
@ -222,11 +222,36 @@ void RtspSession::onRecvContent(const char *data, uint64_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int RtspSession::handleReq_ANNOUNCE() {
|
int RtspSession::handleReq_ANNOUNCE() {
|
||||||
sendRtspResponse("200 OK");
|
auto parseCopy = _parser;
|
||||||
_onContent = [this](const char *data, uint64_t len){
|
_onContent = [this,parseCopy](const char *data, uint64_t len){
|
||||||
|
_parser = parseCopy;
|
||||||
_strSdp.assign(data,len);
|
_strSdp.assign(data,len);
|
||||||
SdpAttr attr(_strSdp);
|
//解析url获取媒体名称
|
||||||
_aTrackInfo = attr.getAvailableTrack();
|
_mediaInfo.parse(_parser.FullUrl());
|
||||||
|
|
||||||
|
auto src = dynamic_pointer_cast<RtmpMediaSource>(MediaSource::find(RTSP_SCHEMA,
|
||||||
|
_mediaInfo._vhost,
|
||||||
|
_mediaInfo._app,
|
||||||
|
_mediaInfo._streamid,
|
||||||
|
false));
|
||||||
|
if(src){
|
||||||
|
sendRtspResponse("406 Not Acceptable", {"Content-Type", "text/plain"}, "Already publishing.");
|
||||||
|
WarnL << "ANNOUNCE:"
|
||||||
|
<< "Already publishing:"
|
||||||
|
<< _mediaInfo._vhost << " "
|
||||||
|
<< _mediaInfo._app << " "
|
||||||
|
<< _mediaInfo._streamid << endl;
|
||||||
|
shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_strSession = makeRandStr(12);
|
||||||
|
_aTrackInfo = SdpAttr(_strSdp).getAvailableTrack();
|
||||||
|
_strUrl = _parser.Url();
|
||||||
|
|
||||||
|
_pushSrc = std::make_shared<RtspToRtmpMediaSource>(_mediaInfo._vhost,_mediaInfo._app,_mediaInfo._streamid);
|
||||||
|
_pushSrc->onGetSDP(_strSdp);
|
||||||
|
sendRtspResponse("200 OK");
|
||||||
};
|
};
|
||||||
return atoi(_parser["Content-Length"].data());
|
return atoi(_parser["Content-Length"].data());
|
||||||
}
|
}
|
||||||
@ -994,12 +1019,18 @@ inline void RtspSession::sendRtpPacket(const RtpPacket::Ptr & pkt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RtspSession::onRtpSorted(const RtpPacket::Ptr &rtppt, int trackidx) {
|
||||||
|
if(_pushSrc){
|
||||||
|
_pushSrc->onWrite(rtppt,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
inline void RtspSession::onRcvPeerUdpData(int iTrackIdx, const Buffer::Ptr &pBuf, const struct sockaddr& addr) {
|
inline void RtspSession::onRcvPeerUdpData(int iTrackIdx, const Buffer::Ptr &pBuf, const struct sockaddr& addr) {
|
||||||
//这是rtcp心跳包,说明播放器还存活
|
//这是rtcp心跳包,说明播放器还存活
|
||||||
_ticker.resetTime();
|
_ticker.resetTime();
|
||||||
|
|
||||||
if(iTrackIdx % 2 == 0){
|
if(iTrackIdx % 2 == 0){
|
||||||
// DebugL << "rtp数据包:" << iTrackIdx / 2;
|
handleOneRtp(iTrackIdx / 2,_aTrackInfo[iTrackIdx / 2],( unsigned char *)pBuf->data(),pBuf->size());
|
||||||
|
|
||||||
//这是rtp探测包
|
//这是rtp探测包
|
||||||
if(!_bGotAllPeerUdp){
|
if(!_bGotAllPeerUdp){
|
||||||
//还没有获取完整的rtp探测包
|
//还没有获取完整的rtp探测包
|
||||||
|
@ -39,6 +39,8 @@
|
|||||||
#include "Util/logger.h"
|
#include "Util/logger.h"
|
||||||
#include "Network/TcpSession.h"
|
#include "Network/TcpSession.h"
|
||||||
#include "Http/HttpRequestSplitter.h"
|
#include "Http/HttpRequestSplitter.h"
|
||||||
|
#include "RtpReceiver.h"
|
||||||
|
#include "RtspToRtmpMediaSource.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
@ -64,7 +66,7 @@ private:
|
|||||||
uint32_t _offset;
|
uint32_t _offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RtspSession: public TcpSession, public HttpRequestSplitter {
|
class RtspSession: public TcpSession, public HttpRequestSplitter, public RtpReceiver{
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<RtspSession> Ptr;
|
typedef std::shared_ptr<RtspSession> Ptr;
|
||||||
typedef std::function<void(const string &realm)> onGetRealm;
|
typedef std::function<void(const string &realm)> onGetRealm;
|
||||||
@ -81,6 +83,8 @@ protected:
|
|||||||
//HttpRequestSplitter override
|
//HttpRequestSplitter override
|
||||||
int64_t onRecvHeader(const char *data,uint64_t len) override ;
|
int64_t onRecvHeader(const char *data,uint64_t len) override ;
|
||||||
void onRecvContent(const char *data,uint64_t len) override;
|
void onRecvContent(const char *data,uint64_t len) override;
|
||||||
|
//RtpReceiver override
|
||||||
|
void onRtpSorted(const RtpPacket::Ptr &rtppt, int trackidx) override;
|
||||||
private:
|
private:
|
||||||
void inputRtspOrRtcp(const char *data,uint64_t len);
|
void inputRtspOrRtcp(const char *data,uint64_t len);
|
||||||
void shutdown() override ;
|
void shutdown() override ;
|
||||||
@ -172,6 +176,9 @@ private:
|
|||||||
uint32_t _iTaskTimeLine = 0;
|
uint32_t _iTaskTimeLine = 0;
|
||||||
atomic<bool> _enableSendRtp;
|
atomic<bool> _enableSendRtp;
|
||||||
|
|
||||||
|
//rtsp推流相关
|
||||||
|
RtspToRtmpMediaSource::Ptr _pushSrc;
|
||||||
|
|
||||||
#ifdef RTSP_SEND_RTCP
|
#ifdef RTSP_SEND_RTCP
|
||||||
RtcpCounter _aRtcpCnt[2]; //rtcp统计,trackid idx 为数组下标
|
RtcpCounter _aRtcpCnt[2]; //rtcp统计,trackid idx 为数组下标
|
||||||
Ticker _aRtcpTicker[2]; //rtcp发送时间,trackid idx 为数组下标
|
Ticker _aRtcpTicker[2]; //rtcp发送时间,trackid idx 为数组下标
|
||||||
|
@ -46,7 +46,7 @@ public:
|
|||||||
const string &app,
|
const string &app,
|
||||||
const string &id,
|
const string &id,
|
||||||
bool bEnableHls = true,
|
bool bEnableHls = true,
|
||||||
bool bEnableMp4 = true) : RtspMediaSource(vhost, app, id) {
|
bool bEnableMp4 = false) : RtspMediaSource(vhost, app, id) {
|
||||||
_recorder = std::make_shared<MediaRecorder>(vhost, app, id, bEnableHls, bEnableMp4);
|
_recorder = std::make_shared<MediaRecorder>(vhost, app, id, bEnableHls, bEnableMp4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user