完善rtsp sdp匹配
This commit is contained in:
parent
ee072191e0
commit
9a2f2cbf2e
|
|
@ -4,7 +4,9 @@
|
||||||
|
|
||||||
#include "Sdp.h"
|
#include "Sdp.h"
|
||||||
#include "Common/Parser.h"
|
#include "Common/Parser.h"
|
||||||
|
#include "Rtsp/Rtsp.h"
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
using namespace mediakit;
|
||||||
|
|
||||||
using onCreateSdpItem = function<SdpItem::Ptr(const string &key, const string &value)>;
|
using onCreateSdpItem = function<SdpItem::Ptr(const string &key, const string &value)>;
|
||||||
static map<string, onCreateSdpItem, StrCaseCompare> sdpItemCreator;
|
static map<string, onCreateSdpItem, StrCaseCompare> sdpItemCreator;
|
||||||
|
|
@ -596,11 +598,11 @@ void SdpAttrFmtp::parse(const string &str) {
|
||||||
auto vec = split(str.substr(pos + 1), ";");
|
auto vec = split(str.substr(pos + 1), ";");
|
||||||
for (auto &item : vec) {
|
for (auto &item : vec) {
|
||||||
trim(item);
|
trim(item);
|
||||||
auto pr_vec = split(item, "=");
|
auto pos = item.find('=');
|
||||||
if (pr_vec.size() != 2) {
|
if(pos == string::npos){
|
||||||
SDP_THROW();
|
SDP_THROW();
|
||||||
}
|
}
|
||||||
arr.emplace_back(std::make_pair(pr_vec[0], pr_vec[1]));
|
arr.emplace_back(std::make_pair(item.substr(0, pos), item.substr(pos + 1)));
|
||||||
}
|
}
|
||||||
if (arr.empty()) {
|
if (arr.empty()) {
|
||||||
SDP_THROW();
|
SDP_THROW();
|
||||||
|
|
@ -746,7 +748,7 @@ string SdpAttrCandidate::toString() const {
|
||||||
return SdpItem::toString();
|
return SdpItem::toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtcSession::loadFrom(const string &str) {
|
void RtcSession::loadFrom(const string &str, bool check) {
|
||||||
RtcSessionSdp sdp;
|
RtcSessionSdp sdp;
|
||||||
sdp.parse(str);
|
sdp.parse(str);
|
||||||
|
|
||||||
|
|
@ -887,12 +889,17 @@ void RtcSession::loadFrom(const string &str) {
|
||||||
auto &plan = rtc_media.plan.back();
|
auto &plan = rtc_media.plan.back();
|
||||||
auto rtpmap_it = rtpmap_map.find(pt);
|
auto rtpmap_it = rtpmap_map.find(pt);
|
||||||
if (rtpmap_it == rtpmap_map.end()) {
|
if (rtpmap_it == rtpmap_map.end()) {
|
||||||
throw std::invalid_argument(StrPrinter << "该pt不存在相对于的a=rtpmap:" << pt);
|
plan.pt = pt;
|
||||||
|
plan.codec = RtpPayload::getCodecId(pt);
|
||||||
|
plan.sample_rate = RtpPayload::getClockRate(pt);
|
||||||
|
plan.channel = RtpPayload::getAudioChannel(pt);
|
||||||
|
} else {
|
||||||
|
plan.pt = rtpmap_it->second.pt;
|
||||||
|
plan.codec = rtpmap_it->second.codec;
|
||||||
|
plan.sample_rate = rtpmap_it->second.sample_rate;
|
||||||
|
plan.channel = rtpmap_it->second.channel;
|
||||||
}
|
}
|
||||||
plan.pt = rtpmap_it->second.pt;
|
|
||||||
plan.codec = rtpmap_it->second.codec;
|
|
||||||
plan.sample_rate = rtpmap_it->second.sample_rate;
|
|
||||||
plan.channel = rtpmap_it->second.channel;
|
|
||||||
auto fmtp_it = fmtp_map.find(pt);
|
auto fmtp_it = fmtp_map.find(pt);
|
||||||
if (fmtp_it != fmtp_map.end()) {
|
if (fmtp_it != fmtp_map.end()) {
|
||||||
plan.fmtp = fmtp_it->second.arr;
|
plan.fmtp = fmtp_it->second.arr;
|
||||||
|
|
@ -905,7 +912,9 @@ void RtcSession::loadFrom(const string &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = sdp.getItemClass<SdpAttrGroup>('a', "group");
|
group = sdp.getItemClass<SdpAttrGroup>('a', "group");
|
||||||
checkValid();
|
if (check) {
|
||||||
|
checkValid();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<SdpItem> wrapSdpAttr(SdpItem::Ptr item){
|
std::shared_ptr<SdpItem> wrapSdpAttr(SdpItem::Ptr item){
|
||||||
|
|
|
||||||
|
|
@ -649,7 +649,7 @@ public:
|
||||||
vector<RtcMedia> media;
|
vector<RtcMedia> media;
|
||||||
SdpAttrGroup group;
|
SdpAttrGroup group;
|
||||||
|
|
||||||
void loadFrom(const string &sdp);
|
void loadFrom(const string &sdp, bool check = true);
|
||||||
void checkValid() const;
|
void checkValid() const;
|
||||||
string toString() const;
|
string toString() const;
|
||||||
RtcMedia *getMedia(TrackType type);
|
RtcMedia *getMedia(TrackType type);
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,6 @@ std::string WebRtcTransport::getAnswerSdp(const string &offer){
|
||||||
fingerprint.hash = getFingerprint(fingerprint.algorithm, _dtls_transport);
|
fingerprint.hash = getFingerprint(fingerprint.algorithm, _dtls_transport);
|
||||||
RtcConfigure configure;
|
RtcConfigure configure;
|
||||||
configure.setDefaultSetting(_ice_server->GetUsernameFragment(), _ice_server->GetPassword(), RtpDirection::recvonly, fingerprint);
|
configure.setDefaultSetting(_ice_server->GetUsernameFragment(), _ice_server->GetPassword(), RtpDirection::recvonly, fingerprint);
|
||||||
configure.addCandidate(*getIceCandidate());
|
|
||||||
onRtcConfigure(configure);
|
onRtcConfigure(configure);
|
||||||
|
|
||||||
//// 生成answer sdp ////
|
//// 生成answer sdp ////
|
||||||
|
|
@ -217,6 +216,7 @@ void WebRtcTransportImp::onStartWebRTC() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush){
|
void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush){
|
||||||
|
//需要修改pt
|
||||||
InfoL << flush;
|
InfoL << flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -237,6 +237,36 @@ void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp) const{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
|
||||||
|
WebRtcTransport::onRtcConfigure(configure);
|
||||||
|
|
||||||
|
RtcSession sdp;
|
||||||
|
sdp.loadFrom(_src->getSdp(), false);
|
||||||
|
|
||||||
|
configure.audio.enable = false;
|
||||||
|
configure.video.enable = false;
|
||||||
|
|
||||||
|
for (auto &m : sdp.media) {
|
||||||
|
switch (m.type) {
|
||||||
|
case TrackVideo: {
|
||||||
|
configure.video.enable = true;
|
||||||
|
configure.video.preferred_codec = {getCodecId(m.plan[0].codec)};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TrackAudio: {
|
||||||
|
configure.audio.enable = true;
|
||||||
|
configure.audio.preferred_codec = {getCodecId(m.plan[0].codec)};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
configure.addCandidate(*getIceCandidate());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void WebRtcTransportImp::onSendSockData(const char *buf, size_t len, struct sockaddr_in *dst, bool flush) {
|
void WebRtcTransportImp::onSendSockData(const char *buf, size_t len, struct sockaddr_in *dst, bool flush) {
|
||||||
auto ptr = BufferRaw::create();
|
auto ptr = BufferRaw::create();
|
||||||
ptr->assign(buf, len);
|
ptr->assign(buf, len);
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,6 @@ protected:
|
||||||
virtual void onStartWebRTC() = 0;
|
virtual void onStartWebRTC() = 0;
|
||||||
virtual void onRtcConfigure(RtcConfigure &configure) const {}
|
virtual void onRtcConfigure(RtcConfigure &configure) const {}
|
||||||
virtual void onCheckSdp(SdpType type, RtcSession &sdp) const;
|
virtual void onCheckSdp(SdpType type, RtcSession &sdp) const;
|
||||||
|
|
||||||
virtual SdpAttrCandidate::Ptr getIceCandidate() const = 0;
|
|
||||||
virtual void onSendSockData(const char *buf, size_t len, struct sockaddr_in *dst, bool flush = true) = 0;
|
virtual void onSendSockData(const char *buf, size_t len, struct sockaddr_in *dst, bool flush = true) = 0;
|
||||||
|
|
||||||
virtual void onRtp(const char *buf, size_t len) = 0;
|
virtual void onRtp(const char *buf, size_t len) = 0;
|
||||||
|
|
@ -116,8 +114,8 @@ protected:
|
||||||
void onStartWebRTC() override;
|
void onStartWebRTC() override;
|
||||||
void onSendSockData(const char *buf, size_t len, struct sockaddr_in *dst, bool flush = true) override;
|
void onSendSockData(const char *buf, size_t len, struct sockaddr_in *dst, bool flush = true) override;
|
||||||
void onCheckSdp(SdpType type, RtcSession &sdp) const override;
|
void onCheckSdp(SdpType type, RtcSession &sdp) const override;
|
||||||
|
void onRtcConfigure(RtcConfigure &configure) const override;
|
||||||
|
|
||||||
SdpAttrCandidate::Ptr getIceCandidate() const override;
|
|
||||||
void onRtp(const char *buf, size_t len) override;
|
void onRtp(const char *buf, size_t len) override;
|
||||||
void onRtcp(const char *buf, size_t len) override;
|
void onRtcp(const char *buf, size_t len) override;
|
||||||
|
|
||||||
|
|
@ -125,6 +123,7 @@ private:
|
||||||
WebRtcTransportImp(const EventPoller::Ptr &poller);
|
WebRtcTransportImp(const EventPoller::Ptr &poller);
|
||||||
void onDestory() override;
|
void onDestory() override;
|
||||||
void onSendRtp(const RtpPacket::Ptr &rtp, bool flush);
|
void onSendRtp(const RtpPacket::Ptr &rtp, bool flush);
|
||||||
|
SdpAttrCandidate::Ptr getIceCandidate() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Socket::Ptr _socket;
|
Socket::Ptr _socket;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue