mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 15:15:28 +00:00
Renamed createTrack() to addTrack() and added addDataChannel()
This commit is contained in:
@ -65,7 +65,7 @@ int main() {
|
||||
media.setBitrate(
|
||||
3000); // Request 3Mbps (Browsers do not encode more than 2.5MBps from a webcam)
|
||||
|
||||
auto track = pc->createTrack(media);
|
||||
auto track = pc->addTrack(media);
|
||||
|
||||
auto session = std::make_shared<rtc::RtcpSession>();
|
||||
track->setRtcpHandler(session);
|
||||
|
@ -86,6 +86,10 @@ public:
|
||||
void setRemoteDescription(Description description);
|
||||
void addRemoteCandidate(Candidate candidate);
|
||||
|
||||
std::shared_ptr<DataChannel> addDataChannel(string label, string protocol = "",
|
||||
Reliability reliability = {});
|
||||
|
||||
// Equivalent to calling addDataChannel() and setLocalDescription()
|
||||
std::shared_ptr<DataChannel> createDataChannel(string label, string protocol = "",
|
||||
Reliability reliability = {});
|
||||
|
||||
@ -102,7 +106,7 @@ public:
|
||||
std::optional<std::chrono::milliseconds> rtt();
|
||||
|
||||
// Track media support requires compiling with libSRTP
|
||||
std::shared_ptr<Track> createTrack(Description::Media description);
|
||||
std::shared_ptr<Track> addTrack(Description::Media description);
|
||||
void onTrack(std::function<void(std::shared_ptr<Track> track)> callback);
|
||||
|
||||
// libnice only
|
||||
|
@ -119,6 +119,10 @@ RTC_EXPORT int rtcGetRemoteAddress(int pc, char *buffer, int size);
|
||||
|
||||
// DataChannel
|
||||
RTC_EXPORT int rtcSetDataChannelCallback(int pc, rtcDataChannelCallbackFunc cb);
|
||||
RTC_EXPORT int rtcAddDataChannel(int pc, const char *label); // returns dc id
|
||||
RTC_EXPORT int rtcAddDataChannelExt(int pc, const char *label, const char *protocol,
|
||||
const rtcReliability *reliability); // returns dc id
|
||||
// Equivalent to calling rtcAddDataChannel() and rtcSetLocalDescription()
|
||||
RTC_EXPORT int rtcCreateDataChannel(int pc, const char *label); // returns dc id
|
||||
RTC_EXPORT int rtcCreateDataChannelExt(int pc, const char *label, const char *protocol,
|
||||
const rtcReliability *reliability); // returns dc id
|
||||
@ -130,7 +134,7 @@ RTC_EXPORT int rtcGetDataChannelReliability(int dc, rtcReliability *reliability)
|
||||
|
||||
// Track
|
||||
RTC_EXPORT int rtcSetTrackCallback(int pc, rtcTrackCallbackFunc cb);
|
||||
RTC_EXPORT int rtcCreateTrack(int pc, const char *mediaDescriptionSdp); // returns tr id
|
||||
RTC_EXPORT int rtcAddTrack(int pc, const char *mediaDescriptionSdp); // returns tr id
|
||||
RTC_EXPORT int rtcDeleteTrack(int tr);
|
||||
|
||||
RTC_EXPORT int rtcGetTrackDescription(int tr, char *buffer, int size);
|
||||
|
@ -85,8 +85,9 @@ std::optional<Description> PeerConnection::remoteDescription() const {
|
||||
void PeerConnection::setLocalDescription() {
|
||||
PLOG_VERBOSE << "Setting local description";
|
||||
|
||||
if (std::atomic_load(&mIceTransport))
|
||||
throw std::logic_error("Local description is already set");
|
||||
if (std::atomic_load(&mIceTransport)) {
|
||||
PLOG_DEBUG << "Local description is already set";
|
||||
}
|
||||
|
||||
// RFC 5763: The endpoint that is the offerer MUST use the setup attribute value of
|
||||
// setup:actpass.
|
||||
@ -197,7 +198,7 @@ std::optional<string> PeerConnection::remoteAddress() const {
|
||||
return iceTransport ? iceTransport->getRemoteAddress() : nullopt;
|
||||
}
|
||||
|
||||
shared_ptr<DataChannel> PeerConnection::createDataChannel(string label, string protocol,
|
||||
shared_ptr<DataChannel> PeerConnection::addDataChannel(string label, string protocol,
|
||||
Reliability reliability) {
|
||||
if (auto local = localDescription(); local && !local->hasApplication()) {
|
||||
PLOG_ERROR << "The PeerConnection was negociated without DataChannel support.";
|
||||
@ -214,18 +215,17 @@ shared_ptr<DataChannel> PeerConnection::createDataChannel(string label, string p
|
||||
auto channel =
|
||||
emplaceDataChannel(role, std::move(label), std::move(protocol), std::move(reliability));
|
||||
|
||||
if (!iceTransport) {
|
||||
// RFC 5763: The endpoint that is the offerer MUST use the setup attribute value of
|
||||
// setup:actpass.
|
||||
// See https://tools.ietf.org/html/rfc5763#section-5
|
||||
iceTransport = initIceTransport(Description::Role::ActPass);
|
||||
processLocalDescription(iceTransport->getLocalDescription(Description::Type::Offer));
|
||||
iceTransport->gatherLocalCandidates();
|
||||
} else {
|
||||
if (auto transport = std::atomic_load(&mSctpTransport))
|
||||
if (transport->state() == SctpTransport::State::Connected)
|
||||
channel->open(transport);
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
shared_ptr<DataChannel> PeerConnection::createDataChannel(string label, string protocol,
|
||||
Reliability reliability) {
|
||||
auto channel = addDataChannel(label, protocol, reliability);
|
||||
setLocalDescription();
|
||||
return channel;
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ bool PeerConnection::hasMedia() const {
|
||||
return local && local->hasAudioOrVideo();
|
||||
}
|
||||
|
||||
std::shared_ptr<Track> PeerConnection::createTrack(Description::Media description) {
|
||||
std::shared_ptr<Track> PeerConnection::addTrack(Description::Media description) {
|
||||
if (localDescription())
|
||||
throw std::logic_error("Tracks must be created before local description");
|
||||
|
||||
|
23
src/rtc.cpp
23
src/rtc.cpp
@ -268,11 +268,11 @@ int rtcDeletePeerConnection(int pc) {
|
||||
});
|
||||
}
|
||||
|
||||
int rtcCreateDataChannel(int pc, const char *label) {
|
||||
return rtcCreateDataChannelExt(pc, label, nullptr, nullptr);
|
||||
int rtcAddDataChannel(int pc, const char *label) {
|
||||
return rtcAddDataChannelExt(pc, label, nullptr, nullptr);
|
||||
}
|
||||
|
||||
int rtcCreateDataChannelExt(int pc, const char *label, const char *protocol,
|
||||
int rtcAddDataChannelExt(int pc, const char *label, const char *protocol,
|
||||
const rtcReliability *reliability) {
|
||||
return WRAP({
|
||||
Reliability r = {};
|
||||
@ -291,7 +291,7 @@ int rtcCreateDataChannelExt(int pc, const char *label, const char *protocol,
|
||||
}
|
||||
}
|
||||
auto peerConnection = getPeerConnection(pc);
|
||||
int dc = emplaceDataChannel(peerConnection->createDataChannel(
|
||||
int dc = emplaceDataChannel(peerConnection->addDataChannel(
|
||||
string(label ? label : ""), string(protocol ? protocol : ""), r));
|
||||
if (auto ptr = getUserPointer(pc))
|
||||
rtcSetUserPointer(dc, *ptr);
|
||||
@ -299,6 +299,17 @@ int rtcCreateDataChannelExt(int pc, const char *label, const char *protocol,
|
||||
});
|
||||
}
|
||||
|
||||
int rtcCreateDataChannel(int pc, const char *label) {
|
||||
return rtcCreateDataChannelExt(pc, label, nullptr, nullptr);
|
||||
}
|
||||
|
||||
int rtcCreateDataChannelExt(int pc, const char *label, const char *protocol,
|
||||
const rtcReliability *reliability) {
|
||||
int dc = rtcAddDataChannelExt(pc, label, protocol, reliability);
|
||||
rtcSetLocalDescription(pc);
|
||||
return dc;
|
||||
}
|
||||
|
||||
int rtcDeleteDataChannel(int dc) {
|
||||
return WRAP({
|
||||
auto dataChannel = getDataChannel(dc);
|
||||
@ -313,13 +324,13 @@ int rtcDeleteDataChannel(int dc) {
|
||||
});
|
||||
}
|
||||
|
||||
int rtcCreateTrack(int pc, const char *mediaDescriptionSdp) {
|
||||
int rtcAddTrack(int pc, const char *mediaDescriptionSdp) {
|
||||
if (!mediaDescriptionSdp)
|
||||
throw std::invalid_argument("Unexpected null pointer for track media description");
|
||||
|
||||
auto peerConnection = getPeerConnection(pc);
|
||||
Description::Media media{string(mediaDescriptionSdp)};
|
||||
int tr = emplaceTrack(peerConnection->createTrack(std::move(media)));
|
||||
int tr = emplaceTrack(peerConnection->addTrack(std::move(media)));
|
||||
if (auto ptr = getUserPointer(pc))
|
||||
rtcSetUserPointer(tr, *ptr);
|
||||
return tr;
|
||||
|
@ -151,7 +151,7 @@ int test_capi_track_main() {
|
||||
goto error;
|
||||
|
||||
// Peer 1: Create track
|
||||
peer1->tr = rtcCreateTrack(peer1->pc, mediaDescription);
|
||||
peer1->tr = rtcAddTrack(peer1->pc, mediaDescription);
|
||||
rtcSetOpenCallback(peer1->tr, openCallback);
|
||||
rtcSetClosedCallback(peer1->tr, closedCallback);
|
||||
|
||||
|
@ -102,7 +102,7 @@ void test_track() {
|
||||
std::atomic_store(&t2, t);
|
||||
});
|
||||
|
||||
auto t1 = pc1->createTrack(Description::Video("test"));
|
||||
auto t1 = pc1->addTrack(Description::Video("test"));
|
||||
|
||||
pc1->setLocalDescription();
|
||||
|
||||
|
Reference in New Issue
Block a user