mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
完成rtc发送
This commit is contained in:
parent
4a62314be9
commit
c42b678cab
@ -1129,7 +1129,8 @@ void RtcMedia::checkValid() const{
|
|||||||
auto rtx_plan = getPlan("rtx");
|
auto rtx_plan = getPlan("rtx");
|
||||||
if (rtx_plan) {
|
if (rtx_plan) {
|
||||||
//开启rtx后必须指定rtx_ssrc
|
//开启rtx后必须指定rtx_ssrc
|
||||||
CHECK(!rtx_ssrc.empty() || !send_rtp);
|
//todo 此处不确定
|
||||||
|
// CHECK(!rtx_ssrc.empty() || !send_rtp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,14 @@ void WebRtcTransport::onSendSockData(const char *buf, size_t len, bool flush){
|
|||||||
onSendSockData(buf, len, (struct sockaddr_in *) tuple, flush);
|
onSendSockData(buf, len, (struct sockaddr_in *) tuple, flush);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const RtcSession& WebRtcTransport::getSdp(SdpType type) const{
|
||||||
|
switch (type) {
|
||||||
|
case SdpType::offer: return *_offer_sdp;
|
||||||
|
case SdpType::answer: return *_answer_sdp;
|
||||||
|
default: throw std::invalid_argument("不识别的sdp类型");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string getFingerprint(const string &algorithm_str, const std::shared_ptr<RTC::DtlsTransport> &transport){
|
string getFingerprint(const string &algorithm_str, const std::shared_ptr<RTC::DtlsTransport> &transport){
|
||||||
auto algorithm = RTC::DtlsTransport::GetFingerprintAlgorithm(algorithm_str);
|
auto algorithm = RTC::DtlsTransport::GetFingerprintAlgorithm(algorithm_str);
|
||||||
for (auto &finger_prints : transport->GetLocalFingerprints()) {
|
for (auto &finger_prints : transport->GetLocalFingerprints()) {
|
||||||
@ -108,7 +116,7 @@ std::string WebRtcTransport::getAnswerSdp(const string &offer){
|
|||||||
fingerprint.algorithm = _offer_sdp->media[0].fingerprint.algorithm;
|
fingerprint.algorithm = _offer_sdp->media[0].fingerprint.algorithm;
|
||||||
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::sendrecv, fingerprint);
|
||||||
onRtcConfigure(configure);
|
onRtcConfigure(configure);
|
||||||
|
|
||||||
//// 生成answer sdp ////
|
//// 生成answer sdp ////
|
||||||
@ -201,6 +209,9 @@ void WebRtcTransportImp::attach(const RtspMediaSource::Ptr &src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcTransportImp::onStartWebRTC() {
|
void WebRtcTransportImp::onStartWebRTC() {
|
||||||
|
if (!canSendRtp()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_reader = _src->getRing()->attach(_socket->getPoller(), true);
|
_reader = _src->getRing()->attach(_socket->getPoller(), true);
|
||||||
weak_ptr<WebRtcTransportImp> weak_self = shared_from_this();
|
weak_ptr<WebRtcTransportImp> weak_self = shared_from_this();
|
||||||
_reader->setReadCB([weak_self](const RtspMediaSource::RingDataType &pkt){
|
_reader->setReadCB([weak_self](const RtspMediaSource::RingDataType &pkt){
|
||||||
@ -215,25 +226,43 @@ void WebRtcTransportImp::onStartWebRTC() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t WebRtcTransportImp::getSendPayloadType(TrackType type) {
|
||||||
|
for (auto &m : getSdp(SdpType::answer).media) {
|
||||||
|
if (m.type == type) {
|
||||||
|
return m.plan[0].pt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush){
|
void WebRtcTransportImp::onSendRtp(const RtpPacket::Ptr &rtp, bool flush){
|
||||||
//需要修改pt
|
//需要修改pt
|
||||||
InfoL << flush;
|
if (rtp->type == TrackVideo) {
|
||||||
|
rtp->getHeader()->pt = getSendPayloadType(rtp->type);
|
||||||
|
sendRtpPacket(rtp->data() + RtpPacket::kRtpTcpHeaderSize, rtp->size() - RtpPacket::kRtpTcpHeaderSize, flush);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WebRtcTransportImp::canSendRtp() const{
|
||||||
|
auto &sdp = getSdp(SdpType::answer);
|
||||||
|
return sdp.media[0].direction == RtpDirection::sendrecv || sdp.media[0].direction == RtpDirection::sendonly;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp) const{
|
void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp) const{
|
||||||
WebRtcTransport::onCheckSdp(type, sdp);
|
WebRtcTransport::onCheckSdp(type, sdp);
|
||||||
if (type != SdpType::answer) {
|
if (type != SdpType::answer || !canSendRtp()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &m : sdp.media) {
|
for (auto &m : sdp.media) {
|
||||||
if (m.type == TrackApplication) {
|
if (m.type == TrackApplication) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
m.rtp_ssrc.ssrc = _src->getSsrc(m.type);
|
m.rtp_ssrc.ssrc = _src->getSsrc(m.type);
|
||||||
m.rtx_ssrc.ssrc = 2 + m.rtp_ssrc.ssrc;
|
|
||||||
|
|
||||||
m.rtp_ssrc.cname = "zlmediakit-rtc";
|
m.rtp_ssrc.cname = "zlmediakit-rtc";
|
||||||
m.rtx_ssrc.cname = "zlmediakit-rtc";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,12 +316,10 @@ SdpAttrCandidate::Ptr WebRtcTransportImp::getIceCandidate() const{
|
|||||||
|
|
||||||
void WebRtcTransportImp::onRtp(const char *buf, size_t len) {
|
void WebRtcTransportImp::onRtp(const char *buf, size_t len) {
|
||||||
RtpHeader *rtp = (RtpHeader *) buf;
|
RtpHeader *rtp = (RtpHeader *) buf;
|
||||||
// TraceL << (int)rtp->ssrc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcTransportImp::onRtcp(const char *buf, size_t len) {
|
void WebRtcTransportImp::onRtcp(const char *buf, size_t len) {
|
||||||
RtcpHeader *rtcp = (RtcpHeader *) buf;
|
RtcpHeader *rtcp = (RtcpHeader *) buf;
|
||||||
// TraceL << rtcpTypeToStr((RtcpType)rtcp->pt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////
|
||||||
|
@ -79,6 +79,9 @@ protected:
|
|||||||
virtual void onRtp(const char *buf, size_t len) = 0;
|
virtual void onRtp(const char *buf, size_t len) = 0;
|
||||||
virtual void onRtcp(const char *buf, size_t len) = 0;
|
virtual void onRtcp(const char *buf, size_t len) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const RtcSession& getSdp(SdpType type) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onSendSockData(const char *buf, size_t len, bool flush = true);
|
void onSendSockData(const char *buf, size_t len, bool flush = true);
|
||||||
void setRemoteDtlsFingerprint(const RtcSession &remote);
|
void setRemoteDtlsFingerprint(const RtcSession &remote);
|
||||||
@ -124,11 +127,14 @@ private:
|
|||||||
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;
|
SdpAttrCandidate::Ptr getIceCandidate() const;
|
||||||
|
uint8_t getSendPayloadType(TrackType type);
|
||||||
|
bool canSendRtp() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Socket::Ptr _socket;
|
Socket::Ptr _socket;
|
||||||
RtspMediaSource::Ptr _src;
|
RtspMediaSource::Ptr _src;
|
||||||
RtspMediaSource::RingType::RingReader::Ptr _reader;
|
RtspMediaSource::RingType::RingReader::Ptr _reader;
|
||||||
|
RtcSession _answer_sdp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user