mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
直接代理时sdp清洗后再使用
This commit is contained in:
parent
453994f26b
commit
c4f364c487
@ -30,6 +30,61 @@
|
||||
|
||||
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 = ≺
|
||||
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) {
|
||||
_track_map.clear();
|
||||
string key;
|
||||
@ -164,5 +219,28 @@ vector<SdpTrack::Ptr> SdpParser::getAvailableTrack() const {
|
||||
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
|
||||
|
||||
|
@ -90,6 +90,8 @@ public:
|
||||
|
||||
map<char, string> _other;
|
||||
map<string, string> _attr;
|
||||
|
||||
string toString() const;
|
||||
public:
|
||||
int _pt;
|
||||
string _codec;
|
||||
@ -118,6 +120,7 @@ public:
|
||||
bool available() const;
|
||||
SdpTrack::Ptr getTrack(TrackType type) const;
|
||||
vector<SdpTrack::Ptr> getAvailableTrack() const;
|
||||
string toString() const ;
|
||||
private:
|
||||
map<string, SdpTrack::Ptr> _track_map;
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ private:
|
||||
bool onCheckSDP(const string &sdp, const SdpParser &parser) override {
|
||||
_pRtspMediaSrc = dynamic_pointer_cast<RtspMediaSource>(_pMediaSrc);
|
||||
if(_pRtspMediaSrc){
|
||||
_pRtspMediaSrc->onGetSDP(sdp);
|
||||
_pRtspMediaSrc->onGetSDP(parser.toString());
|
||||
}
|
||||
_parser.reset(new RtspDemuxer(parser));
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user