mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-12 19:24:22 +08:00
release 8.0
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
@@ -22,9 +22,6 @@ namespace mediakit {
|
||||
|
||||
class NackList {
|
||||
public:
|
||||
NackList() = default;
|
||||
~NackList() = default;
|
||||
|
||||
void pushBack(RtpPacket::Ptr rtp);
|
||||
void forEach(const FCI_NACK &nack, const std::function<void(const RtpPacket::Ptr &rtp)> &cb);
|
||||
|
||||
@@ -58,7 +55,6 @@ public:
|
||||
static_assert(kNackRtpSize >=0 && kNackRtpSize <= FCI_NACK::kBitSize, "NackContext::kNackRtpSize must between 0 and 16");
|
||||
|
||||
NackContext();
|
||||
~NackContext() = default;
|
||||
|
||||
void received(uint16_t seq, bool is_rtx = false);
|
||||
void setOnNack(onNack cb);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
@@ -53,7 +53,6 @@ public:
|
||||
template<typename Type>
|
||||
friend void appendExt(std::map<uint8_t, RtpExt> &ret, uint8_t *ptr, const uint8_t *end);
|
||||
friend class RtpExtContext;
|
||||
~RtpExt() = default;
|
||||
|
||||
static std::map<uint8_t/*id*/, RtpExt/*data*/> getExtValue(const RtpHeader *header);
|
||||
static RtpExtType getExtType(const std::string &url);
|
||||
@@ -119,7 +118,6 @@ public:
|
||||
using OnGetRtp = std::function<void(uint8_t pt, uint32_t ssrc, const std::string &rid)>;
|
||||
|
||||
RtpExtContext(const RtcMedia &media);
|
||||
~RtpExtContext() = default;
|
||||
|
||||
void setOnGetRtp(OnGetRtp cb);
|
||||
std::string getRid(uint32_t ssrc) const;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
@@ -26,9 +26,6 @@ public:
|
||||
//每个twcc rtcp包发送的最大时间间隔,单位毫秒
|
||||
static constexpr size_t kMaxTimeDelta = 256;
|
||||
|
||||
TwccContext() = default;
|
||||
~TwccContext() = default;
|
||||
|
||||
void onRtp(uint32_t ssrc, uint16_t twcc_ext_seq, uint64_t stamp_ms);
|
||||
void setOnSendTwccCB(onSendTwccCB cb);
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
@@ -18,7 +18,6 @@ namespace mediakit {
|
||||
class WebRtcEchoTest : public WebRtcTransportImp {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<WebRtcEchoTest>;
|
||||
~WebRtcEchoTest() override = default;
|
||||
static Ptr create(const EventPoller::Ptr &poller);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
@@ -19,7 +19,6 @@ namespace mediakit {
|
||||
class WebRtcPlayer : public WebRtcTransportImp {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<WebRtcPlayer>;
|
||||
~WebRtcPlayer() override = default;
|
||||
static Ptr create(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info, bool preferred_tcp = false);
|
||||
MediaInfo getMediaInfo() { return _media_info; }
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
@@ -19,7 +19,6 @@ namespace mediakit {
|
||||
class WebRtcPusher : public WebRtcTransportImp, public MediaSourceEvent {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<WebRtcPusher>;
|
||||
~WebRtcPusher() override = default;
|
||||
static Ptr create(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src,
|
||||
const std::shared_ptr<void> &ownership, const MediaInfo &info, const ProtocolOption &option, bool preferred_tcp = false);
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
@@ -51,8 +51,6 @@ WebRtcSession::WebRtcSession(const Socket::Ptr &sock) : Session(sock) {
|
||||
_over_tcp = sock->sockType() == SockNum::Sock_TCP;
|
||||
}
|
||||
|
||||
WebRtcSession::~WebRtcSession() = default;
|
||||
|
||||
void WebRtcSession::attachServer(const Server &server) {
|
||||
_server = std::static_pointer_cast<toolkit::TcpServer>(const_cast<Server &>(server).shared_from_this());
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
@@ -27,7 +27,6 @@ using namespace toolkit;
|
||||
class WebRtcSession : public Session, public HttpRequestSplitter {
|
||||
public:
|
||||
WebRtcSession(const Socket::Ptr &sock);
|
||||
~WebRtcSession() override;
|
||||
|
||||
void attachServer(const Server &server) override;
|
||||
void onRecv(const Buffer::Ptr &) override;
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <srtp2/srtp.h>
|
||||
#include "Util/base64.h"
|
||||
#include "Network/sockutil.h"
|
||||
#include "Common/config.h"
|
||||
#include "RtpExt.h"
|
||||
#include "Rtcp/Rtcp.h"
|
||||
@@ -22,7 +24,6 @@
|
||||
#include "WebRtcEchoTest.h"
|
||||
#include "WebRtcPlayer.h"
|
||||
#include "WebRtcPusher.h"
|
||||
|
||||
#include "Rtsp/RtspMediaSourceImp.h"
|
||||
|
||||
#define RTP_SSRC_OFFSET 1
|
||||
@@ -47,15 +48,23 @@ const string kExternIP = RTC_FIELD "externIP";
|
||||
const string kRembBitRate = RTC_FIELD "rembBitRate";
|
||||
// webrtc单端口udp服务器
|
||||
const string kPort = RTC_FIELD "port";
|
||||
|
||||
const string kTcpPort = RTC_FIELD "tcpPort";
|
||||
|
||||
// 比特率设置
|
||||
const string kStartBitrate = RTC_FIELD "start_bitrate";
|
||||
const string kMaxBitrate = RTC_FIELD "max_bitrate";
|
||||
const string kMinBitrate = RTC_FIELD "min_bitrate";
|
||||
|
||||
static onceToken token([]() {
|
||||
mINI::Instance()[kTimeOutSec] = 15;
|
||||
mINI::Instance()[kExternIP] = "";
|
||||
mINI::Instance()[kRembBitRate] = 0;
|
||||
mINI::Instance()[kPort] = 0;
|
||||
mINI::Instance()[kTcpPort] = 0;
|
||||
|
||||
mINI::Instance()[kStartBitrate] = 0;
|
||||
mINI::Instance()[kMaxBitrate] = 0;
|
||||
mINI::Instance()[kMinBitrate] = 0;
|
||||
});
|
||||
|
||||
} // namespace RTC
|
||||
@@ -77,6 +86,28 @@ static void translateIPFromEnv(std::vector<std::string> &v) {
|
||||
}
|
||||
}
|
||||
|
||||
static std::string getServerPrefix() {
|
||||
//stun_user_name格式: base64(ip+udp_port+tcp_port) + _ + number
|
||||
//其中ip为二进制char[4], udp_port/tcp_port为大端 uint16.
|
||||
//number为自增长数,确保短时间内唯一
|
||||
GET_CONFIG(uint16_t, udp_port, Rtc::kPort);
|
||||
GET_CONFIG(uint16_t, tcp_port, Rtc::kTcpPort);
|
||||
char buf[8];
|
||||
auto host = SockUtil::get_local_ip();
|
||||
auto addr = SockUtil::make_sockaddr(host.data(), udp_port);
|
||||
//拷贝ipv4地址
|
||||
memcpy(buf, &(reinterpret_cast<sockaddr_in *>(&addr)->sin_addr), 4);
|
||||
//拷贝udp端口
|
||||
memcpy(buf + 4, &(reinterpret_cast<sockaddr_in *>(&addr)->sin_port), 2);
|
||||
//tcp端口转大端模式
|
||||
addr = SockUtil::make_sockaddr(host.data(), tcp_port);
|
||||
//拷贝tcp端口
|
||||
memcpy(buf + 6, &(reinterpret_cast<sockaddr_in *>(&addr)->sin_port), 2);
|
||||
auto ret = encodeBase64(string(buf, 8)) + '_';
|
||||
InfoL << "MediaServer(" << host << ":" << udp_port << ":" << tcp_port << ") prefix: " << ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char* sockTypeStr(Session* session) {
|
||||
if (session) {
|
||||
switch (session->getSock()->sockType()) {
|
||||
@@ -90,7 +121,8 @@ const char* sockTypeStr(Session* session) {
|
||||
|
||||
WebRtcTransport::WebRtcTransport(const EventPoller::Ptr &poller) {
|
||||
_poller = poller;
|
||||
_identifier = "zlm" + to_string(++s_key);
|
||||
static auto prefix = getServerPrefix();
|
||||
_identifier = prefix + to_string(++s_key);
|
||||
_packet_pool.setSize(64);
|
||||
}
|
||||
|
||||
@@ -295,6 +327,20 @@ void WebRtcTransport::onRtcConfigure(RtcConfigure &configure) const {
|
||||
configure.enableTWCC(!remb_bit_rate);
|
||||
}
|
||||
|
||||
static void setSdpBitrate(RtcSession &sdp) {
|
||||
GET_CONFIG(size_t, max_bitrate, Rtc::kMaxBitrate);
|
||||
GET_CONFIG(size_t, min_bitrate, Rtc::kMinBitrate);
|
||||
GET_CONFIG(size_t, start_bitrate, Rtc::kStartBitrate);
|
||||
|
||||
auto m = (RtcMedia *)(sdp.getMedia(TrackType::TrackVideo));
|
||||
if (m) {
|
||||
auto &plan = m->plan[0];
|
||||
if (max_bitrate) plan.fmtp["x-google-max-bitrate"] = std::to_string(max_bitrate);
|
||||
if (min_bitrate) plan.fmtp["x-google-min-bitrate"] = std::to_string(min_bitrate);
|
||||
if (start_bitrate) plan.fmtp["x-google-start-bitrate"] = std::to_string(start_bitrate);
|
||||
}
|
||||
}
|
||||
|
||||
std::string WebRtcTransport::getAnswerSdp(const string &offer) {
|
||||
try {
|
||||
//// 解析offer sdp ////
|
||||
@@ -316,6 +362,7 @@ std::string WebRtcTransport::getAnswerSdp(const string &offer) {
|
||||
//// 生成answer sdp ////
|
||||
_answer_sdp = configure.createAnswer(*_offer_sdp);
|
||||
onCheckSdp(SdpType::answer, *_answer_sdp);
|
||||
setSdpBitrate(*_answer_sdp);
|
||||
_answer_sdp->checkValid();
|
||||
return _answer_sdp->toString();
|
||||
} catch (exception &ex) {
|
||||
@@ -636,7 +683,7 @@ makeIceCandidate(std::string ip, uint16_t port, uint32_t priority = 100, std::st
|
||||
candidate->foundation = proto + "candidate";
|
||||
// 优先级,单candidate时随便
|
||||
candidate->priority = priority;
|
||||
candidate->address = ip;
|
||||
candidate->address = std::move(ip);
|
||||
candidate->port = port;
|
||||
candidate->type = "host";
|
||||
if (proto == "tcp") {
|
||||
@@ -647,6 +694,12 @@ makeIceCandidate(std::string ip, uint16_t port, uint32_t priority = 100, std::st
|
||||
|
||||
void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
|
||||
WebRtcTransport::onRtcConfigure(configure);
|
||||
if (!_cands.empty()) {
|
||||
for (auto &cand : _cands) {
|
||||
configure.addCandidate(cand);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
GET_CONFIG(uint16_t, local_udp_port, Rtc::kPort);
|
||||
GET_CONFIG(uint16_t, local_tcp_port, Rtc::kTcpPort);
|
||||
@@ -674,6 +727,10 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
|
||||
}
|
||||
}
|
||||
|
||||
void WebRtcTransportImp::setIceCandidate(vector<SdpAttrCandidate> cands) {
|
||||
_cands = std::move(cands);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
class RtpChannel : public RtpTrackImp, public std::enable_shared_from_this<RtpChannel> {
|
||||
@@ -687,8 +744,6 @@ public:
|
||||
_nack_ctx.setOnNack([this](const FCI_NACK &nack) { onNack(nack); });
|
||||
}
|
||||
|
||||
~RtpChannel() override = default;
|
||||
|
||||
RtpPacket::Ptr inputRtp(TrackType type, int sample_rate, uint8_t *ptr, size_t len, bool is_rtx) {
|
||||
auto rtp = RtpTrack::inputRtp(type, sample_rate, ptr, len);
|
||||
if (!rtp) {
|
||||
@@ -786,7 +841,6 @@ void WebRtcTransportImp::onRtcp(const char *buf, size_t len) {
|
||||
if (!rtp_chn) {
|
||||
WarnL << "未识别的sr rtcp包:" << rtcp->dumpString();
|
||||
} else {
|
||||
// InfoL << "接收丢包率,ssrc:" << sr->ssrc << ",loss rate(%):" << rtp_chn->getLossRate();
|
||||
// 设置rtp时间戳与ntp时间戳的对应关系
|
||||
rtp_chn->setNtpStamp(sr->rtpts, sr->getNtpUnixStampMS());
|
||||
auto rr = rtp_chn->createRtcpRR(sr, track->answer_ssrc_rtp);
|
||||
@@ -1168,8 +1222,26 @@ std::string exchangeSdp(const WebRtcInterface &exchanger, const std::string& off
|
||||
return const_cast<WebRtcInterface &>(exchanger).getAnswerSdp(offer);
|
||||
}
|
||||
|
||||
void WebRtcPluginManager::getAnswerSdp(Session &sender, const string &type, const WebRtcArgs &args, const onCreateRtc &cb) {
|
||||
void WebRtcPluginManager::setListener(Listener cb) {
|
||||
lock_guard<mutex> lck(_mtx_creator);
|
||||
_listener = std::move(cb);
|
||||
}
|
||||
|
||||
void WebRtcPluginManager::getAnswerSdp(Session &sender, const string &type, const WebRtcArgs &args, const onCreateRtc &cb_in) {
|
||||
onCreateRtc cb;
|
||||
lock_guard<mutex> lck(_mtx_creator);
|
||||
if (_listener) {
|
||||
auto listener = _listener;
|
||||
auto args_ptr = args.shared_from_this();
|
||||
auto sender_ptr = static_pointer_cast<Session>(sender.shared_from_this());
|
||||
cb = [listener, sender_ptr, type, args_ptr, cb_in](const WebRtcInterface &rtc) {
|
||||
listener(*sender_ptr, type, *args_ptr, rtc);
|
||||
cb_in(rtc);
|
||||
};
|
||||
} else {
|
||||
cb = cb_in;
|
||||
}
|
||||
|
||||
auto it = _map_creator.find(type);
|
||||
if (it == _map_creator.end()) {
|
||||
cb(WebRtcException(SockException(Err_other, "the type can not supported")));
|
||||
@@ -1272,10 +1344,40 @@ void play_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginMana
|
||||
}
|
||||
}
|
||||
|
||||
static void set_webrtc_cands(const WebRtcArgs &args, const WebRtcInterface &rtc) {
|
||||
vector<SdpAttrCandidate> cands;
|
||||
{
|
||||
auto cand_str = trim(args["cand_udp"]);
|
||||
auto ip_port = toolkit::split(cand_str, ":");
|
||||
if (ip_port.size() == 2) {
|
||||
// udp优先
|
||||
auto ice_cand = makeIceCandidate(ip_port[0], atoi(ip_port[1].data()), 120, "udp");
|
||||
cands.emplace_back(std::move(*ice_cand));
|
||||
}
|
||||
}
|
||||
{
|
||||
auto cand_str = trim(args["cand_tcp"]);
|
||||
auto ip_port = toolkit::split(cand_str, ":");
|
||||
if (ip_port.size() == 2) {
|
||||
// tcp模式
|
||||
auto ice_cand = makeIceCandidate(ip_port[0], atoi(ip_port[1].data()), 100, "tcp");
|
||||
cands.emplace_back(std::move(*ice_cand));
|
||||
}
|
||||
}
|
||||
if (!cands.empty()) {
|
||||
// udp优先
|
||||
const_cast<WebRtcInterface &>(rtc).setIceCandidate(std::move(cands));
|
||||
}
|
||||
}
|
||||
|
||||
static onceToken s_rtc_auto_register([]() {
|
||||
WebRtcPluginManager::Instance().registerPlugin("echo", echo_plugin);
|
||||
WebRtcPluginManager::Instance().registerPlugin("push", push_plugin);
|
||||
WebRtcPluginManager::Instance().registerPlugin("play", play_plugin);
|
||||
|
||||
WebRtcPluginManager::Instance().setListener([](Session &sender, const std::string &type, const WebRtcArgs &args, const WebRtcInterface &rtc) {
|
||||
set_webrtc_cands(args, rtc);
|
||||
});
|
||||
});
|
||||
|
||||
}// namespace mediakit
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
||||
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
||||
*
|
||||
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
||||
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
||||
*
|
||||
* Use of this source code is governed by MIT license that can be found in the
|
||||
* Use of this source code is governed by MIT-like license that can be found in the
|
||||
* LICENSE file in the root of the source tree. All contributing project authors
|
||||
* may be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
@@ -37,11 +37,11 @@ extern const std::string kTimeOutSec;
|
||||
|
||||
class WebRtcInterface {
|
||||
public:
|
||||
WebRtcInterface() = default;
|
||||
virtual ~WebRtcInterface() = default;
|
||||
virtual std::string getAnswerSdp(const std::string &offer) = 0;
|
||||
virtual const std::string& getIdentifier() const = 0;
|
||||
virtual const std::string& deleteRandStr() const { static std::string s_null; return s_null; }
|
||||
virtual void setIceCandidate(std::vector<SdpAttrCandidate> cands) {}
|
||||
};
|
||||
|
||||
std::string exchangeSdp(const WebRtcInterface &exchanger, const std::string& offer);
|
||||
@@ -49,7 +49,6 @@ std::string exchangeSdp(const WebRtcInterface &exchanger, const std::string& off
|
||||
class WebRtcException : public WebRtcInterface {
|
||||
public:
|
||||
WebRtcException(const SockException &ex) : _ex(ex) {};
|
||||
~WebRtcException() override = default;
|
||||
std::string getAnswerSdp(const std::string &offer) override {
|
||||
throw _ex;
|
||||
}
|
||||
@@ -70,7 +69,6 @@ class WebRtcTransport : public WebRtcInterface, public RTC::DtlsTransport::Liste
|
||||
public:
|
||||
using Ptr = std::shared_ptr<WebRtcTransport>;
|
||||
WebRtcTransport(const EventPoller::Ptr &poller);
|
||||
~WebRtcTransport() override = default;
|
||||
|
||||
/**
|
||||
* 创建对象
|
||||
@@ -251,6 +249,7 @@ public:
|
||||
void onSendRtp(const RtpPacket::Ptr &rtp, bool flush, bool rtx = false);
|
||||
|
||||
void createRtpChannel(const std::string &rid, uint32_t ssrc, MediaTrack &track);
|
||||
void setIceCandidate(std::vector<SdpAttrCandidate> cands) override;
|
||||
void removeTuple(RTC::TransportTuple* tuple);
|
||||
void safeShutdown(const SockException &ex);
|
||||
|
||||
@@ -306,6 +305,7 @@ private:
|
||||
std::unordered_map<uint32_t/*ssrc*/, MediaTrack::Ptr> _ssrc_to_track;
|
||||
//根据接收rtp的pt获取相关信息
|
||||
std::unordered_map<uint8_t/*pt*/, std::unique_ptr<WrappedMediaTrack>> _pt_to_track;
|
||||
std::vector<SdpAttrCandidate> _cands;
|
||||
};
|
||||
|
||||
class WebRtcTransportManager {
|
||||
@@ -324,9 +324,8 @@ private:
|
||||
std::unordered_map<std::string, std::weak_ptr<WebRtcTransportImp> > _map;
|
||||
};
|
||||
|
||||
class WebRtcArgs {
|
||||
class WebRtcArgs : public std::enable_shared_from_this<WebRtcArgs> {
|
||||
public:
|
||||
WebRtcArgs() = default;
|
||||
virtual ~WebRtcArgs() = default;
|
||||
|
||||
virtual variant operator[](const std::string &key) const = 0;
|
||||
@@ -336,17 +335,20 @@ class WebRtcPluginManager {
|
||||
public:
|
||||
using onCreateRtc = std::function<void(const WebRtcInterface &rtc)>;
|
||||
using Plugin = std::function<void(Session &sender, const WebRtcArgs &args, const onCreateRtc &cb)>;
|
||||
using Listener = std::function<void(Session &sender, const std::string &type, const WebRtcArgs &args, const WebRtcInterface &rtc)>;
|
||||
|
||||
static WebRtcPluginManager &Instance();
|
||||
|
||||
void registerPlugin(const std::string &type, Plugin cb);
|
||||
void getAnswerSdp(Session &sender, const std::string &type, const WebRtcArgs &args, const onCreateRtc &cb);
|
||||
void setListener(Listener cb);
|
||||
|
||||
private:
|
||||
WebRtcPluginManager() = default;
|
||||
|
||||
private:
|
||||
mutable std::mutex _mtx_creator;
|
||||
Listener _listener;
|
||||
std::unordered_map<std::string, Plugin> _map_creator;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user