Commit bf39cf3e by xiongziliang

整理优化代码

parent 3e841423
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "MediaSource.h" #include "MediaSource.h"
#include "MediaFile/MediaReader.h" #include "MediaFile/MediaReader.h"
#include "Util/util.h" #include "Util/util.h"
#include "Rtsp/Rtsp.h"
#include "Network/sockutil.h" #include "Network/sockutil.h"
#include "Network/TcpSession.h" #include "Network/TcpSession.h"
......
...@@ -34,10 +34,11 @@ ...@@ -34,10 +34,11 @@
#include <functional> #include <functional>
#include <unordered_map> #include <unordered_map>
#include "Common/config.h" #include "Common/config.h"
#include "Common/Parser.h"
#include "Util/logger.h" #include "Util/logger.h"
#include "Util/TimeTicker.h" #include "Util/TimeTicker.h"
#include "Util/NoticeCenter.h" #include "Util/NoticeCenter.h"
#include "Rtsp/Rtsp.h" #include "Extension/Track.h"
using namespace std; using namespace std;
using namespace toolkit; using namespace toolkit;
......
//
// Created by xzl on 2019/6/28.
//
#include "Parser.h"
namespace mediakit{
string FindField(const char* buf, const char* start, const char *end ,int bufSize) {
if(bufSize <=0 ){
bufSize = strlen(buf);
}
const char *msg_start = buf, *msg_end = buf + bufSize;
int len = 0;
if (start != NULL) {
len = strlen(start);
msg_start = strstr(buf, start);
}
if (msg_start == NULL) {
return "";
}
msg_start += len;
if (end != NULL) {
msg_end = strstr(msg_start, end);
if (msg_end == NULL) {
return "";
}
}
return string(msg_start, msg_end);
}
}//namespace mediakit
\ No newline at end of file
//
// Created by xzl on 2019/6/28.
//
#ifndef ZLMEDIAKIT_PARSER_H
#define ZLMEDIAKIT_PARSER_H
#include <map>
#include <string>
#include "Util/util.h"
using namespace std;
using namespace toolkit;
namespace mediakit{
string FindField(const char *buf, const char *start, const char *end, int bufSize = 0);
struct StrCaseCompare {
bool operator()(const string &__x, const string &__y) const { return strcasecmp(__x.data(), __y.data()) < 0; }
};
class StrCaseMap : public multimap<string, string, StrCaseCompare>{
public:
typedef multimap<string, string, StrCaseCompare> Super ;
StrCaseMap() = default;
~StrCaseMap() = default;
string &operator[](const string &key){
auto it = find(key);
if(it == end()){
it = Super::emplace(key,"");
}
return it->second;
}
template <class K,class V>
void emplace(K &&k , V &&v) {
auto it = find(k);
if(it != end()){
return;
}
Super::emplace(std::forward<K>(k),std::forward<V>(v));
}
template <class K,class V>
void emplace_force(K &&k , V &&v) {
Super::emplace(std::forward<K>(k),std::forward<V>(v));
}
};
class Parser {
public:
Parser() {}
virtual ~Parser() {}
void Parse(const char *buf) {
//解析
const char *start = buf;
Clear();
while (true) {
auto line = FindField(start, NULL, "\r\n");
if (line.size() == 0) {
break;
}
if (start == buf) {
_strMethod = FindField(line.data(), NULL, " ");
_strFullUrl = FindField(line.data(), " ", " ");
auto args_pos = _strFullUrl.find('?');
if (args_pos != string::npos) {
_strUrl = _strFullUrl.substr(0, args_pos);
_params = _strFullUrl.substr(args_pos + 1);
_mapUrlArgs = parseArgs(_params);
} else {
_strUrl = _strFullUrl;
}
_strTail = FindField(line.data(), (_strFullUrl + " ").data(), NULL);
} else {
auto field = FindField(line.data(), NULL, ": ");
auto value = FindField(line.data(), ": ", NULL);
if (field.size() != 0) {
_mapHeaders.emplace_force(field,value);
}
}
start = start + line.size() + 2;
if (strncmp(start, "\r\n", 2) == 0) { //协议解析完毕
_strContent = FindField(start, "\r\n", NULL);
break;
}
}
}
const string &Method() const {
//rtsp方法
return _strMethod;
}
const string &Url() const {
//rtsp url
return _strUrl;
}
const string &FullUrl() const {
//rtsp url with args
return _strFullUrl;
}
const string &Tail() const {
//RTSP/1.0
return _strTail;
}
const string &operator[](const char *name) const {
//rtsp field
auto it = _mapHeaders.find(name);
if (it == _mapHeaders.end()) {
return _strNull;
}
return it->second;
}
const string &Content() const {
return _strContent;
}
void Clear() {
_strMethod.clear();
_strUrl.clear();
_strFullUrl.clear();
_params.clear();
_strTail.clear();
_strContent.clear();
_mapHeaders.clear();
_mapUrlArgs.clear();
}
const string &Params() const {
return _params;
}
void setUrl(const string &url) {
this->_strUrl = url;
}
void setContent(const string &content) {
this->_strContent = content;
}
StrCaseMap &getValues() const {
return _mapHeaders;
}
StrCaseMap &getUrlArgs() const {
return _mapUrlArgs;
}
static StrCaseMap parseArgs(const string &str, const char *pair_delim = "&", const char *key_delim = "=") {
StrCaseMap ret;
auto arg_vec = split(str, pair_delim);
for (string &key_val : arg_vec) {
auto key = FindField(key_val.data(), NULL, key_delim);
auto val = FindField(key_val.data(), key_delim, NULL);
ret.emplace_force(key,val);
}
return ret;
}
private:
string _strMethod;
string _strUrl;
string _strTail;
string _strContent;
string _strNull;
string _strFullUrl;
string _params;
mutable StrCaseMap _mapHeaders;
mutable StrCaseMap _mapUrlArgs;
};
}//namespace mediakit
#endif //ZLMEDIAKIT_PARSER_H
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <cstdlib> #include <cstdlib>
#include "HttpClient.h" #include "HttpClient.h"
#include "Rtsp/Rtsp.h" #include "Common/config.h"
namespace mediakit { namespace mediakit {
......
...@@ -31,9 +31,10 @@ ...@@ -31,9 +31,10 @@
#include <string.h> #include <string.h>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include "Rtsp/Rtsp.h"
#include "Util/util.h" #include "Util/util.h"
#include "Util/mini.h"
#include "Network/TcpClient.h" #include "Network/TcpClient.h"
#include "Common/Parser.h"
#include "HttpRequestSplitter.h" #include "HttpRequestSplitter.h"
#include "HttpCookie.h" #include "HttpCookie.h"
#include "HttpChunkedSplitter.h" #include "HttpChunkedSplitter.h"
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "Util/mini.h" #include "Util/mini.h"
#include "Util/TimeTicker.h" #include "Util/TimeTicker.h"
#include "Network/Socket.h" #include "Network/Socket.h"
#include "Rtsp/Rtsp.h" #include "Common/Parser.h"
using namespace std; using namespace std;
using namespace toolkit; using namespace toolkit;
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <functional> #include <functional>
#include "Common/config.h" #include "Common/config.h"
#include "Rtsp/Rtsp.h" #include "Common/Parser.h"
#include "Network/TcpSession.h" #include "Network/TcpSession.h"
#include "Network/TcpServer.h" #include "Network/TcpServer.h"
#include "Rtmp/RtmpMediaSource.h" #include "Rtmp/RtmpMediaSource.h"
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <algorithm> #include <algorithm>
#include "PlayerBase.h" #include "PlayerBase.h"
#include "Rtsp/Rtsp.h"
#include "Rtsp/RtspPlayerImp.h" #include "Rtsp/RtspPlayerImp.h"
#include "Rtmp/RtmpPlayerImp.h" #include "Rtmp/RtmpPlayerImp.h"
using namespace toolkit; using namespace toolkit;
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <algorithm> #include <algorithm>
#include "PusherBase.h" #include "PusherBase.h"
#include "Rtsp/Rtsp.h"
#include "Rtsp/RtspPusher.h" #include "Rtsp/RtspPusher.h"
#include "Rtmp/RtmpPusher.h" #include "Rtmp/RtmpPusher.h"
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
*/ */
#include "RtmpPlayer.h" #include "RtmpPlayer.h"
#include "Rtsp/Rtsp.h"
#include "Rtmp/utils.h" #include "Rtmp/utils.h"
#include "Util/util.h" #include "Util/util.h"
#include "Util/onceToken.h" #include "Util/onceToken.h"
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include "RtmpProtocol.h" #include "RtmpProtocol.h"
#include "Rtsp/Rtsp.h"
#include "Rtmp/utils.h" #include "Rtmp/utils.h"
#include "Util/util.h" #include "Util/util.h"
#include "Util/onceToken.h" #include "Util/onceToken.h"
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
*/ */
#include "RtmpPusher.h" #include "RtmpPusher.h"
#include "Rtmp/utils.h" #include "Rtmp/utils.h"
#include "Rtsp/Rtsp.h"
#include "Util/util.h" #include "Util/util.h"
#include "Util/onceToken.h" #include "Util/onceToken.h"
#include "Thread/ThreadPool.h" #include "Thread/ThreadPool.h"
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include <unordered_set> #include <unordered_set>
#include <unordered_map> #include <unordered_map>
#include "Common/config.h" #include "Common/config.h"
#include "Rtsp.h"
#include "RtspMediaSource.h" #include "RtspMediaSource.h"
#include "Util/mini.h" #include "Util/mini.h"
#include "Network/Socket.h" #include "Network/Socket.h"
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <map> #include <map>
#include <string> #include <string>
#include <memory> #include <memory>
#include "Rtsp.h"
#include "RtspMuxer/RtpCodec.h" #include "RtspMuxer/RtpCodec.h"
#include "RtspMediaSource.h" #include "RtspMediaSource.h"
......
...@@ -26,34 +26,11 @@ ...@@ -26,34 +26,11 @@
#include <stdlib.h> #include <stdlib.h>
#include "Rtsp.h" #include "Rtsp.h"
#include "Common/Parser.h"
namespace mediakit{ namespace mediakit{
string FindField(const char* buf, const char* start, const char *end ,int bufSize) { void SdpParser::load(const string &sdp) {
if(bufSize <=0 ){
bufSize = strlen(buf);
}
const char *msg_start = buf, *msg_end = buf + bufSize;
int len = 0;
if (start != NULL) {
len = strlen(start);
msg_start = strstr(buf, start);
}
if (msg_start == NULL) {
return "";
}
msg_start += len;
if (end != NULL) {
msg_end = strstr(msg_start, end);
if (msg_end == NULL) {
return "";
}
}
return string(msg_start, msg_end);
}
void SdpAttr::load(const string &sdp) {
_track_map.clear(); _track_map.clear();
string key; string key;
SdpTrack::Ptr track = std::make_shared<SdpTrack>(); SdpTrack::Ptr track = std::make_shared<SdpTrack>();
...@@ -88,7 +65,7 @@ void SdpAttr::load(const string &sdp) { ...@@ -88,7 +65,7 @@ void SdpAttr::load(const string &sdp) {
case 'm':{ case 'm':{
_track_map[key] = track; _track_map[key] = track;
track = std::make_shared<SdpTrack>(); track = std::make_shared<SdpTrack>();
key = FindField(opt_val.data(), nullptr," ");; key = FindField(opt_val.data(), nullptr," ");
track->_m = opt_val; track->_m = opt_val;
} }
break; break;
...@@ -161,11 +138,11 @@ void SdpAttr::load(const string &sdp) { ...@@ -161,11 +138,11 @@ void SdpAttr::load(const string &sdp) {
} }
} }
bool SdpAttr::available() const { bool SdpParser::available() const {
return getTrack(TrackAudio) || getTrack(TrackVideo); return getTrack(TrackAudio) || getTrack(TrackVideo);
} }
SdpTrack::Ptr SdpAttr::getTrack(TrackType type) const { SdpTrack::Ptr SdpParser::getTrack(TrackType type) const {
for (auto &pr : _track_map){ for (auto &pr : _track_map){
if(pr.second->_type == type){ if(pr.second->_type == type){
return pr.second; return pr.second;
...@@ -174,7 +151,7 @@ SdpTrack::Ptr SdpAttr::getTrack(TrackType type) const { ...@@ -174,7 +151,7 @@ SdpTrack::Ptr SdpAttr::getTrack(TrackType type) const {
return nullptr; return nullptr;
} }
vector<SdpTrack::Ptr> SdpAttr::getAvailableTrack() const { vector<SdpTrack::Ptr> SdpParser::getAvailableTrack() const {
vector<SdpTrack::Ptr> ret; vector<SdpTrack::Ptr> ret;
auto video = getTrack(TrackVideo); auto video = getTrack(TrackVideo);
if(video){ if(video){
......
...@@ -63,6 +63,15 @@ public: ...@@ -63,6 +63,15 @@ public:
TrackType type; TrackType type;
}; };
class RtcpCounter {
public:
uint32_t pktCnt = 0;
uint32_t octCount = 0;
//网络字节序
uint32_t timeStamp = 0;
uint32_t lastTimeStamp = 0;
};
class SdpTrack { class SdpTrack {
public: public:
typedef std::shared_ptr<SdpTrack> Ptr; typedef std::shared_ptr<SdpTrack> Ptr;
...@@ -98,13 +107,13 @@ public: ...@@ -98,13 +107,13 @@ public:
uint32_t _time_stamp = 0; uint32_t _time_stamp = 0;
}; };
class SdpAttr { class SdpParser {
public: public:
typedef std::shared_ptr<SdpAttr> Ptr; typedef std::shared_ptr<SdpParser> Ptr;
SdpAttr() {} SdpParser() {}
SdpAttr(const string &sdp) { load(sdp); } SdpParser(const string &sdp) { load(sdp); }
~SdpAttr() {} ~SdpParser() {}
void load(const string &sdp); void load(const string &sdp);
bool available() const; bool available() const;
SdpTrack::Ptr getTrack(TrackType type) const; SdpTrack::Ptr getTrack(TrackType type) const;
...@@ -114,179 +123,6 @@ private: ...@@ -114,179 +123,6 @@ private:
}; };
class RtcpCounter {
public:
uint32_t pktCnt = 0;
uint32_t octCount = 0;
//网络字节序
uint32_t timeStamp = 0;
uint32_t lastTimeStamp = 0;
};
string FindField(const char *buf, const char *start, const char *end, int bufSize = 0);
struct StrCaseCompare {
bool operator()(const string &__x, const string &__y) const { return strcasecmp(__x.data(), __y.data()) < 0; }
};
class StrCaseMap : public multimap<string, string, StrCaseCompare>{
public:
typedef multimap<string, string, StrCaseCompare> Super ;
StrCaseMap() = default;
~StrCaseMap() = default;
string &operator[](const string &key){
auto it = find(key);
if(it == end()){
it = Super::emplace(key,"");
}
return it->second;
}
template <class K,class V>
void emplace(K &&k , V &&v) {
auto it = find(k);
if(it != end()){
return;
}
Super::emplace(std::forward<K>(k),std::forward<V>(v));
}
template <class K,class V>
void emplace_force(K &&k , V &&v) {
Super::emplace(std::forward<K>(k),std::forward<V>(v));
}
};
class Parser {
public:
Parser() {}
virtual ~Parser() {}
void Parse(const char *buf) {
//解析
const char *start = buf;
Clear();
while (true) {
auto line = FindField(start, NULL, "\r\n");
if (line.size() == 0) {
break;
}
if (start == buf) {
_strMethod = FindField(line.data(), NULL, " ");
_strFullUrl = FindField(line.data(), " ", " ");
auto args_pos = _strFullUrl.find('?');
if (args_pos != string::npos) {
_strUrl = _strFullUrl.substr(0, args_pos);
_params = _strFullUrl.substr(args_pos + 1);
_mapUrlArgs = parseArgs(_params);
} else {
_strUrl = _strFullUrl;
}
_strTail = FindField(line.data(), (_strFullUrl + " ").data(), NULL);
} else {
auto field = FindField(line.data(), NULL, ": ");
auto value = FindField(line.data(), ": ", NULL);
if (field.size() != 0) {
_mapHeaders.emplace_force(field,value);
}
}
start = start + line.size() + 2;
if (strncmp(start, "\r\n", 2) == 0) { //协议解析完毕
_strContent = FindField(start, "\r\n", NULL);
break;
}
}
}
const string &Method() const {
//rtsp方法
return _strMethod;
}
const string &Url() const {
//rtsp url
return _strUrl;
}
const string &FullUrl() const {
//rtsp url with args
return _strFullUrl;
}
const string &Tail() const {
//RTSP/1.0
return _strTail;
}
const string &operator[](const char *name) const {
//rtsp field
auto it = _mapHeaders.find(name);
if (it == _mapHeaders.end()) {
return _strNull;
}
return it->second;
}
const string &Content() const {
return _strContent;
}
void Clear() {
_strMethod.clear();
_strUrl.clear();
_strFullUrl.clear();
_params.clear();
_strTail.clear();
_strContent.clear();
_mapHeaders.clear();
_mapUrlArgs.clear();
}
const string &Params() const {
return _params;
}
void setUrl(const string &url) {
this->_strUrl = url;
}
void setContent(const string &content) {
this->_strContent = content;
}
StrCaseMap &getValues() const {
return _mapHeaders;
}
StrCaseMap &getUrlArgs() const {
return _mapUrlArgs;
}
static StrCaseMap parseArgs(const string &str, const char *pair_delim = "&", const char *key_delim = "=") {
StrCaseMap ret;
auto arg_vec = split(str, pair_delim);
for (string &key_val : arg_vec) {
auto key = FindField(key_val.data(), NULL, key_delim);
auto val = FindField(key_val.data(), key_delim, NULL);
ret.emplace_force(key,val);
}
return ret;
}
private:
string _strMethod;
string _strUrl;
string _strTail;
string _strContent;
string _strNull;
string _strFullUrl;
string _params;
mutable StrCaseMap _mapHeaders;
mutable StrCaseMap _mapUrlArgs;
};
/** /**
* rtsp sdp基类 * rtsp sdp基类
*/ */
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <unordered_map> #include <unordered_map>
#include "Rtsp.h"
#include "Common/config.h" #include "Common/config.h"
#include "Common/MediaSource.h" #include "Common/MediaSource.h"
#include "RtspMuxer/RtpCodec.h" #include "RtspMuxer/RtpCodec.h"
...@@ -79,14 +78,14 @@ public: ...@@ -79,14 +78,14 @@ public:
} }
virtual uint32_t getSsrc(TrackType trackType) { virtual uint32_t getSsrc(TrackType trackType) {
auto track = _sdpAttr.getTrack(trackType); auto track = _sdpParser.getTrack(trackType);
if(!track){ if(!track){
return 0; return 0;
} }
return track->_ssrc; return track->_ssrc;
} }
virtual uint16_t getSeqence(TrackType trackType) { virtual uint16_t getSeqence(TrackType trackType) {
auto track = _sdpAttr.getTrack(trackType); auto track = _sdpParser.getTrack(trackType);
if(!track){ if(!track){
return 0; return 0;
} }
...@@ -94,11 +93,11 @@ public: ...@@ -94,11 +93,11 @@ public:
} }
uint32_t getTimeStamp(TrackType trackType) override { uint32_t getTimeStamp(TrackType trackType) override {
auto track = _sdpAttr.getTrack(trackType); auto track = _sdpParser.getTrack(trackType);
if(track) { if(track) {
return track->_time_stamp; return track->_time_stamp;
} }
auto tracks = _sdpAttr.getAvailableTrack(); auto tracks = _sdpParser.getAvailableTrack();
switch (tracks.size()){ switch (tracks.size()){
case 0: return 0; case 0: return 0;
case 1: return tracks[0]->_time_stamp; case 1: return tracks[0]->_time_stamp;
...@@ -107,7 +106,7 @@ public: ...@@ -107,7 +106,7 @@ public:
} }
virtual void setTimeStamp(uint32_t uiStamp) { virtual void setTimeStamp(uint32_t uiStamp) {
auto tracks = _sdpAttr.getAvailableTrack(); auto tracks = _sdpParser.getAvailableTrack();
for (auto &track : tracks) { for (auto &track : tracks) {
track->_time_stamp = uiStamp; track->_time_stamp = uiStamp;
} }
...@@ -116,14 +115,14 @@ public: ...@@ -116,14 +115,14 @@ public:
virtual void onGetSDP(const string& sdp) { virtual void onGetSDP(const string& sdp) {
//派生类设置该媒体源媒体描述信息 //派生类设置该媒体源媒体描述信息
_strSdp = sdp; _strSdp = sdp;
_sdpAttr.load(sdp); _sdpParser.load(sdp);
if(_pRing){ if(_pRing){
regist(); regist();
} }
} }
void onWrite(const RtpPacket::Ptr &rtppt, bool keyPos) override { void onWrite(const RtpPacket::Ptr &rtppt, bool keyPos) override {
auto track = _sdpAttr.getTrack(rtppt->type); auto track = _sdpParser.getTrack(rtppt->type);
if(track){ if(track){
track->_seq = rtppt->sequence; track->_seq = rtppt->sequence;
track->_time_stamp = rtppt->timeStamp; track->_time_stamp = rtppt->timeStamp;
...@@ -166,7 +165,7 @@ private: ...@@ -166,7 +165,7 @@ private:
} }
} }
protected: protected:
SdpAttr _sdpAttr; SdpParser _sdpParser;
string _strSdp; //媒体描述信息 string _strSdp; //媒体描述信息
RingType::Ptr _pRing; //rtp环形缓冲 RingType::Ptr _pRing; //rtp环形缓冲
int _ringSize; int _ringSize;
......
...@@ -220,13 +220,13 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) { ...@@ -220,13 +220,13 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
} }
//解析sdp //解析sdp
_sdpAttr.load(parser.Content()); _sdpParser.load(parser.Content());
_aTrackInfo = _sdpAttr.getAvailableTrack(); _aTrackInfo = _sdpParser.getAvailableTrack();
if (_aTrackInfo.empty()) { if (_aTrackInfo.empty()) {
throw std::runtime_error("无有效的Sdp Track"); throw std::runtime_error("无有效的Sdp Track");
} }
if (!onCheckSDP(parser.Content(), _sdpAttr)) { if (!onCheckSDP(parser.Content(), _sdpParser)) {
throw std::runtime_error("onCheckSDP faied"); throw std::runtime_error("onCheckSDP faied");
} }
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include <string> #include <string>
#include <memory> #include <memory>
#include "Rtsp.h"
#include "RtspSession.h" #include "RtspSession.h"
#include "RtspMediaSource.h" #include "RtspMediaSource.h"
#include "Player/PlayerBase.h" #include "Player/PlayerBase.h"
...@@ -60,7 +59,7 @@ public: ...@@ -60,7 +59,7 @@ public:
float getPacketLossRate(TrackType type) const override; float getPacketLossRate(TrackType type) const override;
protected: protected:
//派生类回调函数 //派生类回调函数
virtual bool onCheckSDP(const string &strSdp, const SdpAttr &sdpAttr) = 0; virtual bool onCheckSDP(const string &strSdp, const SdpParser &parser) = 0;
virtual void onRecvRTP(const RtpPacket::Ptr &pRtppt, const SdpTrack::Ptr &track) = 0; virtual void onRecvRTP(const RtpPacket::Ptr &pRtppt, const SdpTrack::Ptr &track) = 0;
uint32_t getProgressMilliSecond() const; uint32_t getProgressMilliSecond() const;
void seekToMilliSecond(uint32_t ms); void seekToMilliSecond(uint32_t ms);
...@@ -123,7 +122,7 @@ private: ...@@ -123,7 +122,7 @@ private:
void sendReceiverReport(bool overTcp,int iTrackIndex); void sendReceiverReport(bool overTcp,int iTrackIndex);
private: private:
string _strUrl; string _strUrl;
SdpAttr _sdpAttr; SdpParser _sdpParser;
vector<SdpTrack::Ptr> _aTrackInfo; vector<SdpTrack::Ptr> _aTrackInfo;
function<void(const Parser&)> _onHandshake; function<void(const Parser&)> _onHandshake;
Socket::Ptr _apRtpSock[2]; //RTP端口,trackid idx 为数组下标 Socket::Ptr _apRtpSock[2]; //RTP端口,trackid idx 为数组下标
......
...@@ -61,19 +61,19 @@ public: ...@@ -61,19 +61,19 @@ public:
}; };
private: private:
//派生类回调函数 //派生类回调函数
bool onCheckSDP(const string &sdp, const SdpAttr &sdpAttr) override { bool onCheckSDP(const string &sdp, const SdpParser &parser) override {
_pRtspMediaSrc = dynamic_pointer_cast<RtspMediaSource>(_pMediaSrc); _pRtspMediaSrc = dynamic_pointer_cast<RtspMediaSource>(_pMediaSrc);
if(_pRtspMediaSrc){ if(_pRtspMediaSrc){
_pRtspMediaSrc->onGetSDP(sdp); _pRtspMediaSrc->onGetSDP(sdp);
} }
_parser.reset(new RtspDemuxer(sdpAttr)); _parser.reset(new RtspDemuxer(parser));
return true; return true;
} }
void onRecvRTP(const RtpPacket::Ptr &rtppt, const SdpTrack::Ptr &track) override { void onRecvRTP(const RtpPacket::Ptr &rtp, const SdpTrack::Ptr &track) override {
if(_pRtspMediaSrc){ if(_pRtspMediaSrc){
_pRtspMediaSrc->onWrite(rtppt,true); _pRtspMediaSrc->onWrite(rtp,true);
} }
_parser->inputRtp(rtppt); _parser->inputRtp(rtp);
//由于我们重载isInited方法强制认为一旦获取sdp那么就初始化Track成功, //由于我们重载isInited方法强制认为一旦获取sdp那么就初始化Track成功,
//所以我们不需要在后续检验是否初始化成功 //所以我们不需要在后续检验是否初始化成功
......
...@@ -169,8 +169,8 @@ void RtspPusher::sendAnnounce() { ...@@ -169,8 +169,8 @@ void RtspPusher::sendAnnounce() {
throw std::runtime_error("the media source was released"); throw std::runtime_error("the media source was released");
} }
//解析sdp //解析sdp
_sdpAttr.load(src->getSdp()); _sdpParser.load(src->getSdp());
_aTrackInfo = _sdpAttr.getAvailableTrack(); _aTrackInfo = _sdpParser.getAvailableTrack();
if (_aTrackInfo.empty()) { if (_aTrackInfo.empty()) {
throw std::runtime_error("无有效的Sdp Track"); throw std::runtime_error("无有效的Sdp Track");
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <string> #include <string>
#include <memory> #include <memory>
#include "Rtsp.h"
#include "RtspMediaSource.h" #include "RtspMediaSource.h"
#include "Util/util.h" #include "Util/util.h"
#include "Util/logger.h" #include "Util/logger.h"
...@@ -81,7 +80,7 @@ private: ...@@ -81,7 +80,7 @@ private:
Event _onPublished; Event _onPublished;
string _strUrl; string _strUrl;
SdpAttr _sdpAttr; SdpParser _sdpParser;
vector<SdpTrack::Ptr> _aTrackInfo; vector<SdpTrack::Ptr> _aTrackInfo;
string _strSession; string _strSession;
unsigned int _uiCseq = 1; unsigned int _uiCseq = 1;
......
...@@ -244,7 +244,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) { ...@@ -244,7 +244,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
_strSession = makeRandStr(12); _strSession = makeRandStr(12);
_strSdp = parser.Content(); _strSdp = parser.Content();
_aTrackInfo = SdpAttr(_strSdp).getAvailableTrack(); _aTrackInfo = SdpParser(_strSdp).getAvailableTrack();
_pushSrc = std::make_shared<RtspToRtmpMediaSource>(_mediaInfo._vhost,_mediaInfo._app,_mediaInfo._streamid); _pushSrc = std::make_shared<RtspToRtmpMediaSource>(_mediaInfo._vhost,_mediaInfo._app,_mediaInfo._streamid);
_pushSrc->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this())); _pushSrc->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this()));
...@@ -363,8 +363,8 @@ void RtspSession::onAuthSuccess() { ...@@ -363,8 +363,8 @@ void RtspSession::onAuthSuccess() {
} }
//找到了响应的rtsp流 //找到了响应的rtsp流
strongSelf->_strSdp = rtsp_src->getSdp(); strongSelf->_strSdp = rtsp_src->getSdp();
SdpAttr sdpAttr(strongSelf->_strSdp); SdpParser sdpParser(strongSelf->_strSdp);
strongSelf->_aTrackInfo = sdpAttr.getAvailableTrack(); strongSelf->_aTrackInfo = sdpParser.getAvailableTrack();
if (strongSelf->_aTrackInfo.empty()) { if (strongSelf->_aTrackInfo.empty()) {
//该流无效 //该流无效
strongSelf->send_StreamNotFound(); strongSelf->send_StreamNotFound();
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "Common/config.h" #include "Common/config.h"
#include "Network/TcpSession.h" #include "Network/TcpSession.h"
#include "Player/PlayerBase.h" #include "Player/PlayerBase.h"
#include "Rtsp.h"
#include "RtpBroadCaster.h" #include "RtpBroadCaster.h"
#include "RtspMediaSource.h" #include "RtspMediaSource.h"
#include "RtspSplitter.h" #include "RtspSplitter.h"
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#ifndef ZLMEDIAKIT_RTSPSPLITTER_H #ifndef ZLMEDIAKIT_RTSPSPLITTER_H
#define ZLMEDIAKIT_RTSPSPLITTER_H #define ZLMEDIAKIT_RTSPSPLITTER_H
#include "Rtsp.h" #include "Common/Parser.h"
#include "Http/HttpRequestSplitter.h" #include "Http/HttpRequestSplitter.h"
namespace mediakit{ namespace mediakit{
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include <memory> #include <memory>
#include "Util/RingBuffer.h" #include "Util/RingBuffer.h"
#include "Rtsp/Rtsp.h"
#include "Player/PlayerBase.h" #include "Player/PlayerBase.h"
using namespace toolkit; using namespace toolkit;
......
...@@ -35,14 +35,14 @@ using namespace std; ...@@ -35,14 +35,14 @@ using namespace std;
namespace mediakit { namespace mediakit {
RtspDemuxer::RtspDemuxer(const string& sdp) { RtspDemuxer::RtspDemuxer(const string& sdp) {
loadSdp(SdpAttr(sdp)); loadSdp(SdpParser(sdp));
} }
RtspDemuxer::RtspDemuxer(const SdpAttr &attr) { RtspDemuxer::RtspDemuxer(const SdpParser &attr) {
loadSdp(attr); loadSdp(attr);
} }
void RtspDemuxer::loadSdp(const SdpAttr &attr) { void RtspDemuxer::loadSdp(const SdpParser &attr) {
auto tracks = attr.getAvailableTrack(); auto tracks = attr.getAvailableTrack();
for (auto &track : tracks){ for (auto &track : tracks){
switch (track->_type) { switch (track->_type) {
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#define SRC_RTP_RTSPDEMUXER_H_ #define SRC_RTP_RTSPDEMUXER_H_
#include <unordered_map> #include <unordered_map>
#include "Rtsp/Rtsp.h"
#include "Player/PlayerBase.h" #include "Player/PlayerBase.h"
#include "Util/TimeTicker.h" #include "Util/TimeTicker.h"
#include "RtspMuxer/RtpCodec.h" #include "RtspMuxer/RtpCodec.h"
...@@ -42,7 +41,7 @@ class RtspDemuxer : public Demuxer{ ...@@ -42,7 +41,7 @@ class RtspDemuxer : public Demuxer{
public: public:
typedef std::shared_ptr<RtspDemuxer> Ptr; typedef std::shared_ptr<RtspDemuxer> Ptr;
RtspDemuxer(const string &sdp); RtspDemuxer(const string &sdp);
RtspDemuxer(const SdpAttr &attr); RtspDemuxer(const SdpParser &parser);
virtual ~RtspDemuxer(){}; virtual ~RtspDemuxer(){};
/** /**
...@@ -54,7 +53,7 @@ public: ...@@ -54,7 +53,7 @@ public:
private: private:
void makeAudioTrack(const SdpTrack::Ptr &audio); void makeAudioTrack(const SdpTrack::Ptr &audio);
void makeVideoTrack(const SdpTrack::Ptr &video); void makeVideoTrack(const SdpTrack::Ptr &video);
void loadSdp(const SdpAttr &attr); void loadSdp(const SdpParser &parser);
private: private:
RtpCodec::Ptr _audioRtpDecoder; RtpCodec::Ptr _audioRtpDecoder;
RtpCodec::Ptr _videoRtpDecoder; RtpCodec::Ptr _videoRtpDecoder;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论