Commit 2d89322b by lyg1949 Committed by GitHub

Merge pull request #5 from xiongziliang/master

update from origin
parents ade89bdb c507e8a7
Subproject commit ed47015f92cc79dfe3344b3666aafb54f1bbc2f4
Subproject commit 60aab3b9f6230312c882b9d3d360ed27c94ebd9f
Subproject commit 7f7906b05d84c5efeceecb8d6f540a71c8153431
Subproject commit 43facc343afc2b5b70bbbc3c177f20dfa936f2bf
{
"id": "95afe791-f716-426e-99c4-a797e112ab2c",
"name": "127.0.0.1",
"values": [
{
"key": "ZLMediaKit_URL",
"value": "127.0.0.1",
"enabled": true
},
{
"key": "ZLMediaKit_secret",
"value": "035c73f7-bb6b-4889-a715-d9eb2d1925cc",
"enabled": true
},
{
"key": "defaultVhost",
"value": "__defaultVhost__",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2020-07-11T15:16:04.479Z",
"_postman_exported_using": "Postman/7.27.1"
}
\ No newline at end of file
把这两个json文件导入postman就可以愉快的测试ZLMediaKit的restful接口了
\ No newline at end of file
......@@ -257,7 +257,7 @@ static recursive_mutex s_ffmpegMapMtx;
#if defined(ENABLE_RTPPROXY)
//rtp服务器列表
static unordered_map<uint16_t, RtpServer::Ptr> s_rtpServerMap;
static unordered_map<string, RtpServer::Ptr> s_rtpServerMap;
static recursive_mutex s_rtpServerMapMtx;
#endif
......@@ -753,44 +753,53 @@ void installWebApi() {
val["exist"] = true;
val["peer_ip"] = process->get_peer_ip();
val["peer_port"] = process->get_peer_port();
val["local_port"] = process->get_local_port();
val["local_ip"] = process->get_local_ip();
});
api_regist1("/index/api/openRtpServer",[](API_ARGS1){
CHECK_SECRET();
CHECK_ARGS("port", "enable_tcp", "stream_id");
RtpServer::Ptr server = std::make_shared<RtpServer>();
server->start(allArgs["port"], allArgs["stream_id"], allArgs["enable_tcp"].as<bool>());
auto stream_id = allArgs["stream_id"];
auto port = server->getPort();
server->setOnDetach([port]() {
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
if(s_rtpServerMap.find(stream_id) != s_rtpServerMap.end()) {
//为了防止RtpProcess所有权限混乱的问题,不允许重复添加相同的stream_id
throw InvalidArgsException("该stream_id已存在");
}
RtpServer::Ptr server = std::make_shared<RtpServer>();
server->start(allArgs["port"], stream_id, allArgs["enable_tcp"].as<bool>());
server->setOnDetach([stream_id]() {
//设置rtp超时移除事件
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
s_rtpServerMap.erase(port);
s_rtpServerMap.erase(stream_id);
});
//保存对象
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
s_rtpServerMap.emplace(port, server);
s_rtpServerMap.emplace(stream_id, server);
//回复json
val["port"] = port;
val["port"] = server->getPort();
});
api_regist1("/index/api/closeRtpServer",[](API_ARGS1){
CHECK_SECRET();
CHECK_ARGS("port");
CHECK_ARGS("stream_id");
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
val["hit"] = (int)s_rtpServerMap.erase(allArgs["port"].as<uint16_t>());
val["hit"] = (int) s_rtpServerMap.erase(allArgs["stream_id"]);
});
api_regist1("/index/api/listRtpServer",[](API_ARGS1){
CHECK_SECRET();
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
for(auto &pr : s_rtpServerMap){
val["data"].append(pr.first);
for (auto &pr : s_rtpServerMap) {
Value obj;
obj["stream_id"] = pr.first;
obj["port"] = pr.second->getPort();
val["data"].append(obj);
}
});
......
......@@ -118,7 +118,7 @@ RtpCodec::Ptr Factory::getRtpEncoderBySdp(const Sdp::Ptr &sdp) {
case CodecH265 : return std::make_shared<H265RtpEncoder>(ssrc,mtu,sample_rate,pt,interleaved);
case CodecAAC : return std::make_shared<AACRtpEncoder>(ssrc,mtu,sample_rate,pt,interleaved);
case CodecG711A :
case CodecG711U : return std::make_shared<G711RtpEncoder>(ssrc, mtu, sample_rate, pt, interleaved);
case CodecG711U : return std::make_shared<G711RtpEncoder>(codec_id, ssrc, mtu, sample_rate, pt, interleaved);
default : WarnL << "暂不支持该CodecId:" << codec_id; return nullptr;
}
}
......@@ -129,7 +129,7 @@ RtpCodec::Ptr Factory::getRtpDecoderByTrack(const Track::Ptr &track) {
case CodecH265 : return std::make_shared<H265RtpDecoder>();
case CodecAAC : return std::make_shared<AACRtpDecoder>(track->clone());
case CodecG711A :
case CodecG711U : return std::make_shared<G711RtpDecoder>(track->clone());
case CodecG711U : return std::make_shared<G711RtpDecoder>(track->getCodecId());
default : WarnL << "暂不支持该CodecId:" << track->getCodecName(); return nullptr;
}
}
......
......@@ -12,8 +12,8 @@
namespace mediakit{
G711RtpDecoder::G711RtpDecoder(const Track::Ptr &track){
_codecid = track->getCodecId();
G711RtpDecoder::G711RtpDecoder(CodecId codecid){
_codecid = codecid;
_frame = obtainFrame();
}
......@@ -59,16 +59,10 @@ void G711RtpDecoder::onGetG711(const G711Frame::Ptr &frame) {
/////////////////////////////////////////////////////////////////////////////////////
G711RtpEncoder::G711RtpEncoder(uint32_t ui32Ssrc,
uint32_t ui32MtuSize,
uint32_t ui32SampleRate,
uint8_t ui8PayloadType,
uint8_t ui8Interleaved) :
RtpInfo(ui32Ssrc,
ui32MtuSize,
ui32SampleRate,
ui8PayloadType,
ui8Interleaved) {
G711RtpEncoder::G711RtpEncoder(CodecId codecid, uint32_t ui32Ssrc, uint32_t ui32MtuSize,
uint32_t ui32SampleRate, uint8_t ui8PayloadType, uint8_t ui8Interleaved) :
G711RtpDecoder(codecid),
RtpInfo(ui32Ssrc, ui32MtuSize, ui32SampleRate, ui8PayloadType, ui8Interleaved) {
}
void G711RtpEncoder::inputFrame(const Frame::Ptr &frame) {
......
......@@ -21,7 +21,7 @@ class G711RtpDecoder : public RtpCodec , public ResourcePoolHelper<G711Frame> {
public:
typedef std::shared_ptr<G711RtpDecoder> Ptr;
G711RtpDecoder(const Track::Ptr &track);
G711RtpDecoder(CodecId codecid);
~G711RtpDecoder() {}
/**
......@@ -35,9 +35,6 @@ public:
return _codecid;
}
protected:
G711RtpDecoder() {}
private:
void onGetG711(const G711Frame::Ptr &frame);
G711Frame::Ptr obtainFrame();
......@@ -61,7 +58,8 @@ public:
* @param ui8PayloadType pt类型
* @param ui8Interleaved rtsp interleaved 值
*/
G711RtpEncoder(uint32_t ui32Ssrc,
G711RtpEncoder(CodecId codecid,
uint32_t ui32Ssrc,
uint32_t ui32MtuSize,
uint32_t ui32SampleRate,
uint8_t ui8PayloadType = 0,
......
......@@ -80,7 +80,9 @@ void RtpSelector::delProcess(const string &stream_id,const RtpProcess *ptr) {
if (it->second->getProcess().get() != ptr) {
return;
}
auto process = it->second->getProcess();
_map_rtp_process.erase(it);
process->onDetach();
}
void RtpSelector::onManager() {
......
......@@ -59,51 +59,31 @@ public:
//在请求明文密码时如果提供md5密码者则会导致认证失败
typedef std::function<void(bool encrypted,const string &pwd_or_md5)> onAuth;
RtspSession(const Socket::Ptr &pSock);
RtspSession(const Socket::Ptr &sock);
virtual ~RtspSession();
////TcpSession override////
void onRecv(const Buffer::Ptr &pBuf) override;
void onRecv(const Buffer::Ptr &buf) override;
void onError(const SockException &err) override;
void onManager() override;
protected:
//RtspSplitter override
/**
* 收到完整的rtsp包回调,包括sdp等content数据
* @param parser rtsp包
*/
/////RtspSplitter override/////
//收到完整的rtsp包回调,包括sdp等content数据
void onWholeRtspPacket(Parser &parser) override;
/**
* 收到rtp包回调
* @param data
* @param len
*/
void onRtpPacket(const char *data,uint64_t len) override;
/**
* 从rtsp头中获取Content长度
* @param parser
* @return
*/
//收到rtp包回调
void onRtpPacket(const char *data, uint64_t len) override;
//从rtsp头中获取Content长度
int64_t getContentLength(Parser &parser) override;
//RtpReceiver override
void onRtpSorted(const RtpPacket::Ptr &rtppt, int trackidx) override;
//MediaSourceEvent override
bool close(MediaSource &sender,bool force) override ;
////RtpReceiver override////
void onRtpSorted(const RtpPacket::Ptr &rtp, int track_idx) override;
////MediaSourceEvent override////
bool close(MediaSource &sender, bool force) override ;
int totalReaderCount(MediaSource &sender) override;
//TcpSession override
/////TcpSession override////
int send(const Buffer::Ptr &pkt) override;
//收到RTCP包回调
virtual void onRtcpPacket(int track_idx, SdpTrack::Ptr &track, unsigned char *data, unsigned int len);
/**
* 收到RTCP包回调
* @param iTrackidx
* @param track
* @param pucData
* @param uiLen
*/
virtual void onRtcpPacket(int iTrackidx, SdpTrack::Ptr &track, unsigned char *pucData, unsigned int uiLen);
private:
//处理options方法,获取服务器能力
void handleReq_Options(const Parser &parser);
......@@ -127,101 +107,100 @@ private:
void handleReq_Post(const Parser &parser);
//处理SET_PARAMETER、GET_PARAMETER方法,一般用于心跳
void handleReq_SET_PARAMETER(const Parser &parser);
//rtsp资源未找到
void inline send_StreamNotFound();
void send_StreamNotFound();
//不支持的传输模式
void inline send_UnsupportedTransport();
void send_UnsupportedTransport();
//会话id错误
void inline send_SessionNotFound();
void send_SessionNotFound();
//一般rtsp服务器打开端口失败时触发
void inline send_NotAcceptable();
void send_NotAcceptable();
//获取track下标
inline int getTrackIndexByTrackType(TrackType type);
inline int getTrackIndexByControlSuffix(const string &controlSuffix);
inline int getTrackIndexByInterleaved(int interleaved);
int getTrackIndexByTrackType(TrackType type);
int getTrackIndexByControlSuffix(const string &control_suffix);
int getTrackIndexByInterleaved(int interleaved);
//一般用于接收udp打洞包,也用于rtsp推流
inline void onRcvPeerUdpData(int intervaled, const Buffer::Ptr &pBuf, const struct sockaddr &addr);
void onRcvPeerUdpData(int interleaved, const Buffer::Ptr &buf, const struct sockaddr &addr);
//配合onRcvPeerUdpData使用
inline void startListenPeerUdpData(int iTrackIdx);
void startListenPeerUdpData(int track_idx);
////rtsp专有认证相关////
//认证成功
void onAuthSuccess();
//认证失败
void onAuthFailed(const string &realm,const string &why,bool close = true);
void onAuthFailed(const string &realm, const string &why, bool close = true);
//开始走rtsp专有认证流程
void onAuthUser(const string &realm,const string &authorization);
void onAuthUser(const string &realm, const string &authorization);
//校验base64方式的认证加密
void onAuthBasic(const string &realm,const string &strBase64);
void onAuthBasic(const string &realm, const string &auth_base64);
//校验md5方式的认证加密
void onAuthDigest(const string &realm,const string &strMd5);
void onAuthDigest(const string &realm, const string &auth_md5);
//触发url鉴权事件
void emitOnPlay();
//发送rtp给客户端
void sendRtpPacket(const RtspMediaSource::RingDataType &pkt);
//触发rtcp发送
void onSendRtpPacket(const RtpPacket::Ptr &rtp);
//回复客户端
bool sendRtspResponse(const string &res_code,const std::initializer_list<string> &header, const string &sdp = "" , const char *protocol = "RTSP/1.0");
bool sendRtspResponse(const string &res_code,const StrCaseMap &header = StrCaseMap(), const string &sdp = "",const char *protocol = "RTSP/1.0");
bool sendRtspResponse(const string &res_code, const std::initializer_list<string> &header, const string &sdp = "", const char *protocol = "RTSP/1.0");
bool sendRtspResponse(const string &res_code, const StrCaseMap &header = StrCaseMap(), const string &sdp = "", const char *protocol = "RTSP/1.0");
//服务器发送rtcp
void sendSenderReport(bool overTcp,int iTrackIndex);
void sendSenderReport(bool over_tcp, int track_idx);
//设置socket标志
void setSocketFlags();
private:
//用于判断客户端是否超时
Ticker _ticker;
//是否已经触发on_play事件
bool _emit_on_play = false;
//是否开始发送rtp
bool _enable_send_rtp;
//推流或拉流客户端采用的rtp传输方式
Rtsp::eRtpType _rtp_type = Rtsp::RTP_Invalid;
//收到的seq,回复时一致
int _iCseq = 0;
int _cseq = 0;
//消耗的总流量
uint64_t _bytes_usage = 0;
//ContentBase
string _strContentBase;
string _content_base;
//Session号
string _strSession;
string _sessionid;
//记录是否需要rtsp专属鉴权,防止重复触发事件
string _rtsp_realm;
//是否已经触发on_play事件
bool _emit_on_play = false;
//登录认证
string _auth_nonce;
//用于判断客户端是否超时
Ticker _alive_ticker;
//url解析后保存的相关信息
MediaInfo _mediaInfo;
MediaInfo _media_info;
//rtsp推流相关绑定的源
RtspMediaSourceImp::Ptr _push_src;
//rtsp播放器绑定的直播源
std::weak_ptr<RtspMediaSource> _pMediaSrc;
std::weak_ptr<RtspMediaSource> _play_src;
//直播源读取器
RtspMediaSource::RingType::RingReader::Ptr _pRtpReader;
//推流或拉流客户端采用的rtp传输方式
Rtsp::eRtpType _rtpType = Rtsp::RTP_Invalid;
RtspMediaSource::RingType::RingReader::Ptr _play_reader;
//sdp里面有效的track,包含音频或视频
vector<SdpTrack::Ptr> _aTrackInfo;
vector<SdpTrack::Ptr> _sdp_track;
//rtcp统计,trackid idx 为数组下标
RtcpCounter _rtcp_counter[2];
//rtcp发送时间,trackid idx 为数组下标
Ticker _rtcp_send_tickers[2];
////////RTP over udp////////
//RTP端口,trackid idx 为数组下标
Socket::Ptr _apRtpSock[2];
Socket::Ptr _rtp_socks[2];
//RTCP端口,trackid idx 为数组下标
Socket::Ptr _apRtcpSock[2];
Socket::Ptr _rtcp_socks[2];
//标记是否收到播放的udp打洞包,收到播放的udp打洞包后才能知道其外网udp端口号
unordered_set<int> _udpSockConnected;
unordered_set<int> _udp_connected_flags;
////////RTP over udp_multicast////////
//共享的rtp组播对象
RtpMultiCaster::Ptr _multicaster;
//登录认证
string _strNonce;
//消耗的总流量
uint64_t _ui64TotalBytes = 0;
//RTSP over HTTP
////////RTSP over HTTP ////////
//quicktime 请求rtsp会产生两次tcp连接,
//一次发送 get 一次发送post,需要通过x-sessioncookie关联起来
string _http_x_sessioncookie;
function<void(const Buffer::Ptr &pBuf)> _onRecv;
//是否开始发送rtp
bool _enableSendRtp;
//rtsp推流相关
RtspMediaSourceImp::Ptr _pushSrc;
//rtcp统计,trackid idx 为数组下标
RtcpCounter _aRtcpCnt[2];
//rtcp发送时间,trackid idx 为数组下标
Ticker _aRtcpTicker[2];
function<void(const Buffer::Ptr &)> _on_recv;
};
/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论