ZLMediaKit/src/Rtsp/RtspPusher.h

100 lines
2.8 KiB
C
Raw Normal View History

2019-03-27 18:41:52 +08:00
//
// Created by xzl on 2019/3/27.
//
#ifndef ZLMEDIAKIT_RTSPPUSHER_H
#define ZLMEDIAKIT_RTSPPUSHER_H
#include <string>
#include <memory>
#include "Rtsp.h"
#include "RtspMediaSource.h"
#include "Util/util.h"
#include "Util/logger.h"
#include "Poller/Timer.h"
#include "Network/Socket.h"
#include "Network/TcpClient.h"
#include "RtspSplitter.h"
#include "Pusher/PusherBase.h"
using namespace std;
using namespace toolkit;
namespace mediakit {
class RtspPusher : public TcpClient, public RtspSplitter, public PusherBase {
public:
typedef std::shared_ptr<RtspPusher> Ptr;
RtspPusher(const RtspMediaSource::Ptr &src);
virtual ~RtspPusher();
void publish(const string &strUrl) override;
void teardown() override;
void setOnPublished(const Event &cb) override {
_onPublished = cb;
}
void setOnShutdown(const Event & cb) override{
_onShutdown = cb;
}
protected:
//for Tcpclient override
void onRecv(const Buffer::Ptr &pBuf) override;
void onConnect(const SockException &err) override;
void onErr(const SockException &ex) override;
//RtspSplitter override
void onWholeRtspPacket(Parser &parser) override ;
void onRtpPacket(const char *data,uint64_t len) override {};
private:
void publish(const string &strUrl, const string &strUser, const string &strPwd, Rtsp::eRtpType eType );
2019-03-28 09:34:22 +08:00
void onPublishResult(const SockException &ex);
2019-03-27 18:41:52 +08:00
2019-03-28 09:34:22 +08:00
void sendAnnounce();
void sendSetup(unsigned int uiTrackIndex);
void sendRecord();
void sendOptions();
2019-03-27 18:41:52 +08:00
void handleResAnnounce(const Parser &parser);
void handleResSetup(const Parser &parser, unsigned int uiTrackIndex);
bool handleAuthenticationFailure(const string &paramsStr);
inline int getTrackIndexByTrackType(TrackType type);
void sendRtpPacket(const RtpPacket::Ptr & pkt) ;
2019-03-28 09:34:22 +08:00
void sendRtspRequest(const string &cmd, const string &url ,const StrCaseMap &header = StrCaseMap(),const string &sdp = "" );
void sendRtspRequest(const string &cmd, const string &url ,const std::initializer_list<string> &header,const string &sdp = "");
2019-03-27 18:41:52 +08:00
private:
//rtsp鉴权相关
string _rtspMd5Nonce;
string _rtspRealm;
//超时功能实现
std::shared_ptr<Timer> _pPublishTimer;
//源
std::weak_ptr<RtspMediaSource> _pMediaSrc;
RtspMediaSource::RingType::RingReader::Ptr _pRtspReader;
//事件监听
Event _onShutdown;
Event _onPublished;
string _strUrl;
SdpAttr _sdpAttr;
vector<SdpTrack::Ptr> _aTrackInfo;
string _strSession;
unsigned int _uiCseq = 1;
string _strContentBase;
Rtsp::eRtpType _eType = Rtsp::RTP_TCP;
Socket::Ptr _apUdpSock[2];
function<void(const Parser&)> _onHandshake;
//心跳定时器
std::shared_ptr<Timer> _pBeatTimer;
};
} /* namespace mediakit */
#endif //ZLMEDIAKIT_RTSPPUSHER_H