直接代理时sdp清洗后再使用

This commit is contained in:
xiongziliang 2019-08-15 19:13:31 +08:00
parent 453994f26b
commit c4f364c487
3 changed files with 82 additions and 1 deletions

View File

@ -30,6 +30,61 @@
namespace mediakit{ namespace mediakit{
static void getAttrSdp(const map<string, string> &attr, _StrPrinter &printer){
const map<string, string>::value_type *ptr = nullptr;
for(auto &pr : attr){
if(pr.first == "control"){
ptr = &pr;
continue;
}
if(pr.second.empty()){
printer << "a=" << pr.first << "\r\n";
}else{
printer << "a=" << pr.first << ":" << pr.second << "\r\n";
}
}
if(ptr){
printer << "a=" << ptr->first << ":" << ptr->second << "\r\n";
}
}
string SdpTrack::toString() const {
_StrPrinter _printer;
switch (_type){
case TrackTitle:{
_printer << "v=" << 0 << "\r\n";
if(!_o.empty()){
_printer << "o="<< _o << "\r\n";
}
if(!_c.empty()){
_printer << "c=" << _c << "\r\n";
}
if(!_t.empty()){
_printer << "t=" << _t << "\r\n";
}
_printer << "s=RTSP Session, streamed by the ZLMediaKit\r\n";
_printer << "i=ZLMediaKit Live Stream\r\n";
getAttrSdp(_attr,_printer);
}
break;
case TrackAudio:
case TrackVideo:{
if(_type == TrackAudio){
_printer << "m=audio 0 RTP/AVP " << _pt << "\r\n";
}else{
_printer << "m=video 0 RTP/AVP " << _pt << "\r\n";
}
if(!_b.empty()){
_printer << "b=" <<_b << "\r\n";
}
getAttrSdp(_attr,_printer);
}
break;
default:
break;
}
return _printer;
}
void SdpParser::load(const string &sdp) { void SdpParser::load(const string &sdp) {
_track_map.clear(); _track_map.clear();
string key; string key;
@ -164,5 +219,28 @@ vector<SdpTrack::Ptr> SdpParser::getAvailableTrack() const {
return ret; return ret;
} }
string SdpParser::toString() const {
string title,audio,video;
for(auto &pr : _track_map){
switch (pr.second->_type){
case TrackTitle:{
title = pr.second->toString();
}
break;
case TrackVideo:{
video = pr.second->toString();
}
break;
case TrackAudio:{
audio = pr.second->toString();
}
break;
default:
break;
}
}
return title + video + audio;
}
}//namespace mediakit }//namespace mediakit

View File

@ -90,6 +90,8 @@ public:
map<char, string> _other; map<char, string> _other;
map<string, string> _attr; map<string, string> _attr;
string toString() const;
public: public:
int _pt; int _pt;
string _codec; string _codec;
@ -118,6 +120,7 @@ public:
bool available() const; bool available() const;
SdpTrack::Ptr getTrack(TrackType type) const; SdpTrack::Ptr getTrack(TrackType type) const;
vector<SdpTrack::Ptr> getAvailableTrack() const; vector<SdpTrack::Ptr> getAvailableTrack() const;
string toString() const ;
private: private:
map<string, SdpTrack::Ptr> _track_map; map<string, SdpTrack::Ptr> _track_map;
}; };

View File

@ -64,7 +64,7 @@ private:
bool onCheckSDP(const string &sdp, const SdpParser &parser) 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(parser.toString());
} }
_parser.reset(new RtspDemuxer(parser)); _parser.reset(new RtspDemuxer(parser));
return true; return true;