mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-02-28 11:10:53 +08:00
整理优化代码
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
#include "MediaSource.h"
|
||||
#include "MediaFile/MediaReader.h"
|
||||
#include "Util/util.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Network/sockutil.h"
|
||||
#include "Network/TcpSession.h"
|
||||
|
||||
|
||||
@@ -34,10 +34,11 @@
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include "Common/config.h"
|
||||
#include "Common/Parser.h"
|
||||
#include "Util/logger.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
#include "Util/NoticeCenter.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Extension/Track.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
32
src/Common/Parser.cpp
Normal file
32
src/Common/Parser.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// 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
|
||||
182
src/Common/Parser.h
Normal file
182
src/Common/Parser.h
Normal file
@@ -0,0 +1,182 @@
|
||||
//
|
||||
// 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 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include "HttpClient.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Common/config.h"
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
|
||||
@@ -31,9 +31,10 @@
|
||||
#include <string.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Util/util.h"
|
||||
#include "Util/mini.h"
|
||||
#include "Network/TcpClient.h"
|
||||
#include "Common/Parser.h"
|
||||
#include "HttpRequestSplitter.h"
|
||||
#include "HttpCookie.h"
|
||||
#include "HttpChunkedSplitter.h"
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "Util/mini.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
#include "Network/Socket.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Common/Parser.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace toolkit;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include "Common/config.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Common/Parser.h"
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Network/TcpServer.h"
|
||||
#include "Rtmp/RtmpMediaSource.h"
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include "PlayerBase.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Rtsp/RtspPlayerImp.h"
|
||||
#include "Rtmp/RtmpPlayerImp.h"
|
||||
using namespace toolkit;
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include "PusherBase.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Rtsp/RtspPusher.h"
|
||||
#include "Rtmp/RtmpPusher.h"
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
|
||||
#include "RtmpPlayer.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Rtmp/utils.h"
|
||||
#include "Util/util.h"
|
||||
#include "Util/onceToken.h"
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include "RtmpProtocol.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Rtmp/utils.h"
|
||||
#include "Util/util.h"
|
||||
#include "Util/onceToken.h"
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
#include "RtmpPusher.h"
|
||||
#include "Rtmp/utils.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Util/util.h"
|
||||
#include "Util/onceToken.h"
|
||||
#include "Thread/ThreadPool.h"
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include "Common/config.h"
|
||||
#include "Rtsp.h"
|
||||
#include "RtspMediaSource.h"
|
||||
#include "Util/mini.h"
|
||||
#include "Network/Socket.h"
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "Rtsp.h"
|
||||
#include "RtspMuxer/RtpCodec.h"
|
||||
#include "RtspMediaSource.h"
|
||||
|
||||
|
||||
@@ -26,34 +26,11 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "Rtsp.h"
|
||||
#include "Common/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);
|
||||
}
|
||||
|
||||
|
||||
void SdpAttr::load(const string &sdp) {
|
||||
void SdpParser::load(const string &sdp) {
|
||||
_track_map.clear();
|
||||
string key;
|
||||
SdpTrack::Ptr track = std::make_shared<SdpTrack>();
|
||||
@@ -88,7 +65,7 @@ void SdpAttr::load(const string &sdp) {
|
||||
case 'm':{
|
||||
_track_map[key] = track;
|
||||
track = std::make_shared<SdpTrack>();
|
||||
key = FindField(opt_val.data(), nullptr," ");;
|
||||
key = FindField(opt_val.data(), nullptr," ");
|
||||
track->_m = opt_val;
|
||||
}
|
||||
break;
|
||||
@@ -161,11 +138,11 @@ void SdpAttr::load(const string &sdp) {
|
||||
}
|
||||
}
|
||||
|
||||
bool SdpAttr::available() const {
|
||||
bool SdpParser::available() const {
|
||||
return getTrack(TrackAudio) || getTrack(TrackVideo);
|
||||
}
|
||||
|
||||
SdpTrack::Ptr SdpAttr::getTrack(TrackType type) const {
|
||||
SdpTrack::Ptr SdpParser::getTrack(TrackType type) const {
|
||||
for (auto &pr : _track_map){
|
||||
if(pr.second->_type == type){
|
||||
return pr.second;
|
||||
@@ -174,7 +151,7 @@ SdpTrack::Ptr SdpAttr::getTrack(TrackType type) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
vector<SdpTrack::Ptr> SdpAttr::getAvailableTrack() const {
|
||||
vector<SdpTrack::Ptr> SdpParser::getAvailableTrack() const {
|
||||
vector<SdpTrack::Ptr> ret;
|
||||
auto video = getTrack(TrackVideo);
|
||||
if(video){
|
||||
|
||||
192
src/Rtsp/Rtsp.h
192
src/Rtsp/Rtsp.h
@@ -63,6 +63,15 @@ public:
|
||||
TrackType type;
|
||||
};
|
||||
|
||||
class RtcpCounter {
|
||||
public:
|
||||
uint32_t pktCnt = 0;
|
||||
uint32_t octCount = 0;
|
||||
//网络字节序
|
||||
uint32_t timeStamp = 0;
|
||||
uint32_t lastTimeStamp = 0;
|
||||
};
|
||||
|
||||
class SdpTrack {
|
||||
public:
|
||||
typedef std::shared_ptr<SdpTrack> Ptr;
|
||||
@@ -98,13 +107,13 @@ public:
|
||||
uint32_t _time_stamp = 0;
|
||||
};
|
||||
|
||||
class SdpAttr {
|
||||
class SdpParser {
|
||||
public:
|
||||
typedef std::shared_ptr<SdpAttr> Ptr;
|
||||
typedef std::shared_ptr<SdpParser> Ptr;
|
||||
|
||||
SdpAttr() {}
|
||||
SdpAttr(const string &sdp) { load(sdp); }
|
||||
~SdpAttr() {}
|
||||
SdpParser() {}
|
||||
SdpParser(const string &sdp) { load(sdp); }
|
||||
~SdpParser() {}
|
||||
void load(const string &sdp);
|
||||
bool available() const;
|
||||
SdpTrack::Ptr getTrack(TrackType type) const;
|
||||
@@ -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基类
|
||||
*/
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include "Rtsp.h"
|
||||
#include "Common/config.h"
|
||||
#include "Common/MediaSource.h"
|
||||
#include "RtspMuxer/RtpCodec.h"
|
||||
@@ -79,14 +78,14 @@ public:
|
||||
}
|
||||
|
||||
virtual uint32_t getSsrc(TrackType trackType) {
|
||||
auto track = _sdpAttr.getTrack(trackType);
|
||||
auto track = _sdpParser.getTrack(trackType);
|
||||
if(!track){
|
||||
return 0;
|
||||
}
|
||||
return track->_ssrc;
|
||||
}
|
||||
virtual uint16_t getSeqence(TrackType trackType) {
|
||||
auto track = _sdpAttr.getTrack(trackType);
|
||||
auto track = _sdpParser.getTrack(trackType);
|
||||
if(!track){
|
||||
return 0;
|
||||
}
|
||||
@@ -94,11 +93,11 @@ public:
|
||||
}
|
||||
|
||||
uint32_t getTimeStamp(TrackType trackType) override {
|
||||
auto track = _sdpAttr.getTrack(trackType);
|
||||
auto track = _sdpParser.getTrack(trackType);
|
||||
if(track) {
|
||||
return track->_time_stamp;
|
||||
}
|
||||
auto tracks = _sdpAttr.getAvailableTrack();
|
||||
auto tracks = _sdpParser.getAvailableTrack();
|
||||
switch (tracks.size()){
|
||||
case 0: return 0;
|
||||
case 1: return tracks[0]->_time_stamp;
|
||||
@@ -107,7 +106,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void setTimeStamp(uint32_t uiStamp) {
|
||||
auto tracks = _sdpAttr.getAvailableTrack();
|
||||
auto tracks = _sdpParser.getAvailableTrack();
|
||||
for (auto &track : tracks) {
|
||||
track->_time_stamp = uiStamp;
|
||||
}
|
||||
@@ -116,14 +115,14 @@ public:
|
||||
virtual void onGetSDP(const string& sdp) {
|
||||
//派生类设置该媒体源媒体描述信息
|
||||
_strSdp = sdp;
|
||||
_sdpAttr.load(sdp);
|
||||
_sdpParser.load(sdp);
|
||||
if(_pRing){
|
||||
regist();
|
||||
}
|
||||
}
|
||||
|
||||
void onWrite(const RtpPacket::Ptr &rtppt, bool keyPos) override {
|
||||
auto track = _sdpAttr.getTrack(rtppt->type);
|
||||
auto track = _sdpParser.getTrack(rtppt->type);
|
||||
if(track){
|
||||
track->_seq = rtppt->sequence;
|
||||
track->_time_stamp = rtppt->timeStamp;
|
||||
@@ -166,7 +165,7 @@ private:
|
||||
}
|
||||
}
|
||||
protected:
|
||||
SdpAttr _sdpAttr;
|
||||
SdpParser _sdpParser;
|
||||
string _strSdp; //媒体描述信息
|
||||
RingType::Ptr _pRing; //rtp环形缓冲
|
||||
int _ringSize;
|
||||
|
||||
@@ -220,13 +220,13 @@ void RtspPlayer::handleResDESCRIBE(const Parser& parser) {
|
||||
}
|
||||
|
||||
//解析sdp
|
||||
_sdpAttr.load(parser.Content());
|
||||
_aTrackInfo = _sdpAttr.getAvailableTrack();
|
||||
_sdpParser.load(parser.Content());
|
||||
_aTrackInfo = _sdpParser.getAvailableTrack();
|
||||
|
||||
if (_aTrackInfo.empty()) {
|
||||
throw std::runtime_error("无有效的Sdp Track");
|
||||
}
|
||||
if (!onCheckSDP(parser.Content(), _sdpAttr)) {
|
||||
if (!onCheckSDP(parser.Content(), _sdpParser)) {
|
||||
throw std::runtime_error("onCheckSDP faied");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "Rtsp.h"
|
||||
#include "RtspSession.h"
|
||||
#include "RtspMediaSource.h"
|
||||
#include "Player/PlayerBase.h"
|
||||
@@ -60,7 +59,7 @@ public:
|
||||
float getPacketLossRate(TrackType type) const override;
|
||||
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;
|
||||
uint32_t getProgressMilliSecond() const;
|
||||
void seekToMilliSecond(uint32_t ms);
|
||||
@@ -123,7 +122,7 @@ private:
|
||||
void sendReceiverReport(bool overTcp,int iTrackIndex);
|
||||
private:
|
||||
string _strUrl;
|
||||
SdpAttr _sdpAttr;
|
||||
SdpParser _sdpParser;
|
||||
vector<SdpTrack::Ptr> _aTrackInfo;
|
||||
function<void(const Parser&)> _onHandshake;
|
||||
Socket::Ptr _apRtpSock[2]; //RTP端口,trackid idx 为数组下标
|
||||
|
||||
@@ -61,19 +61,19 @@ public:
|
||||
};
|
||||
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);
|
||||
if(_pRtspMediaSrc){
|
||||
_pRtspMediaSrc->onGetSDP(sdp);
|
||||
}
|
||||
_parser.reset(new RtspDemuxer(sdpAttr));
|
||||
_parser.reset(new RtspDemuxer(parser));
|
||||
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){
|
||||
_pRtspMediaSrc->onWrite(rtppt,true);
|
||||
_pRtspMediaSrc->onWrite(rtp,true);
|
||||
}
|
||||
_parser->inputRtp(rtppt);
|
||||
_parser->inputRtp(rtp);
|
||||
|
||||
//由于我们重载isInited方法强制认为一旦获取sdp那么就初始化Track成功,
|
||||
//所以我们不需要在后续检验是否初始化成功
|
||||
|
||||
@@ -169,8 +169,8 @@ void RtspPusher::sendAnnounce() {
|
||||
throw std::runtime_error("the media source was released");
|
||||
}
|
||||
//解析sdp
|
||||
_sdpAttr.load(src->getSdp());
|
||||
_aTrackInfo = _sdpAttr.getAvailableTrack();
|
||||
_sdpParser.load(src->getSdp());
|
||||
_aTrackInfo = _sdpParser.getAvailableTrack();
|
||||
|
||||
if (_aTrackInfo.empty()) {
|
||||
throw std::runtime_error("无有效的Sdp Track");
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "Rtsp.h"
|
||||
#include "RtspMediaSource.h"
|
||||
#include "Util/util.h"
|
||||
#include "Util/logger.h"
|
||||
@@ -81,7 +80,7 @@ private:
|
||||
Event _onPublished;
|
||||
|
||||
string _strUrl;
|
||||
SdpAttr _sdpAttr;
|
||||
SdpParser _sdpParser;
|
||||
vector<SdpTrack::Ptr> _aTrackInfo;
|
||||
string _strSession;
|
||||
unsigned int _uiCseq = 1;
|
||||
|
||||
@@ -244,7 +244,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
|
||||
|
||||
_strSession = makeRandStr(12);
|
||||
_strSdp = parser.Content();
|
||||
_aTrackInfo = SdpAttr(_strSdp).getAvailableTrack();
|
||||
_aTrackInfo = SdpParser(_strSdp).getAvailableTrack();
|
||||
|
||||
_pushSrc = std::make_shared<RtspToRtmpMediaSource>(_mediaInfo._vhost,_mediaInfo._app,_mediaInfo._streamid);
|
||||
_pushSrc->setListener(dynamic_pointer_cast<MediaSourceEvent>(shared_from_this()));
|
||||
@@ -363,8 +363,8 @@ void RtspSession::onAuthSuccess() {
|
||||
}
|
||||
//找到了响应的rtsp流
|
||||
strongSelf->_strSdp = rtsp_src->getSdp();
|
||||
SdpAttr sdpAttr(strongSelf->_strSdp);
|
||||
strongSelf->_aTrackInfo = sdpAttr.getAvailableTrack();
|
||||
SdpParser sdpParser(strongSelf->_strSdp);
|
||||
strongSelf->_aTrackInfo = sdpParser.getAvailableTrack();
|
||||
if (strongSelf->_aTrackInfo.empty()) {
|
||||
//该流无效
|
||||
strongSelf->send_StreamNotFound();
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include "Common/config.h"
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Player/PlayerBase.h"
|
||||
#include "Rtsp.h"
|
||||
#include "RtpBroadCaster.h"
|
||||
#include "RtspMediaSource.h"
|
||||
#include "RtspSplitter.h"
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#ifndef ZLMEDIAKIT_RTSPSPLITTER_H
|
||||
#define ZLMEDIAKIT_RTSPSPLITTER_H
|
||||
|
||||
#include "Rtsp.h"
|
||||
#include "Common/Parser.h"
|
||||
#include "Http/HttpRequestSplitter.h"
|
||||
|
||||
namespace mediakit{
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#include <memory>
|
||||
#include "Util/RingBuffer.h"
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Player/PlayerBase.h"
|
||||
using namespace toolkit;
|
||||
|
||||
|
||||
@@ -35,14 +35,14 @@ using namespace std;
|
||||
namespace mediakit {
|
||||
|
||||
RtspDemuxer::RtspDemuxer(const string& sdp) {
|
||||
loadSdp(SdpAttr(sdp));
|
||||
loadSdp(SdpParser(sdp));
|
||||
}
|
||||
|
||||
RtspDemuxer::RtspDemuxer(const SdpAttr &attr) {
|
||||
RtspDemuxer::RtspDemuxer(const SdpParser &attr) {
|
||||
loadSdp(attr);
|
||||
}
|
||||
|
||||
void RtspDemuxer::loadSdp(const SdpAttr &attr) {
|
||||
void RtspDemuxer::loadSdp(const SdpParser &attr) {
|
||||
auto tracks = attr.getAvailableTrack();
|
||||
for (auto &track : tracks){
|
||||
switch (track->_type) {
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#define SRC_RTP_RTSPDEMUXER_H_
|
||||
|
||||
#include <unordered_map>
|
||||
#include "Rtsp/Rtsp.h"
|
||||
#include "Player/PlayerBase.h"
|
||||
#include "Util/TimeTicker.h"
|
||||
#include "RtspMuxer/RtpCodec.h"
|
||||
@@ -42,7 +41,7 @@ class RtspDemuxer : public Demuxer{
|
||||
public:
|
||||
typedef std::shared_ptr<RtspDemuxer> Ptr;
|
||||
RtspDemuxer(const string &sdp);
|
||||
RtspDemuxer(const SdpAttr &attr);
|
||||
RtspDemuxer(const SdpParser &parser);
|
||||
virtual ~RtspDemuxer(){};
|
||||
|
||||
/**
|
||||
@@ -54,7 +53,7 @@ public:
|
||||
private:
|
||||
void makeAudioTrack(const SdpTrack::Ptr &audio);
|
||||
void makeVideoTrack(const SdpTrack::Ptr &video);
|
||||
void loadSdp(const SdpAttr &attr);
|
||||
void loadSdp(const SdpParser &parser);
|
||||
private:
|
||||
RtpCodec::Ptr _audioRtpDecoder;
|
||||
RtpCodec::Ptr _videoRtpDecoder;
|
||||
|
||||
Reference in New Issue
Block a user