mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 23:25:33 +00:00
Add API to set track id in msid
This commit is contained in:
@ -141,9 +141,9 @@ public:
|
||||
void removeFormat(const string &fmt);
|
||||
|
||||
void addSSRC(uint32_t ssrc, std::optional<string> name,
|
||||
std::optional<string> msid = nullopt);
|
||||
std::optional<string> msid = nullopt, std::optional<string> trackID = nullopt);
|
||||
void replaceSSRC(uint32_t oldSSRC, uint32_t ssrc, std::optional<string> name,
|
||||
std::optional<string> msid = nullopt);
|
||||
std::optional<string> msid = nullopt, std::optional<string> trackID = nullopt);
|
||||
bool hasSSRC(uint32_t ssrc);
|
||||
std::vector<uint32_t> getSSRCs();
|
||||
|
||||
|
@ -215,8 +215,9 @@ RTC_EXPORT int rtcGetTrackDescription(int tr, char *buffer, int size);
|
||||
/// @param _direction Direction
|
||||
/// @param _name Name (optional)
|
||||
/// @param _msid MSID (optional)
|
||||
/// @param _trackID Track ID used in MSID (optional)
|
||||
/// @returns Track id
|
||||
RTC_EXPORT int rtcAddTrackEx(int pc, rtcCodec codec, int payloadType, uint32_t ssrc, const char *_mid, rtcDirection direction, const char *_name, const char *_msid);
|
||||
RTC_EXPORT int rtcAddTrackEx(int pc, rtcCodec codec, int payloadType, uint32_t ssrc, const char *_mid, rtcDirection direction, const char *_name, const char *_msid, const char *_trackID);
|
||||
|
||||
/// Set H264PacketizationHandler for track
|
||||
/// @param tr Track id
|
||||
|
13
src/capi.cpp
13
src/capi.cpp
@ -435,7 +435,7 @@ int rtcDeleteDataChannel(int dc) {
|
||||
|
||||
#if RTC_ENABLE_MEDIA
|
||||
|
||||
void setSSRC(Description::Media *description, uint32_t ssrc, const char *_name, const char *_msid) {
|
||||
void setSSRC(Description::Media *description, uint32_t ssrc, const char *_name, const char *_msid, const char *_trackID) {
|
||||
|
||||
optional<string> name = nullopt;
|
||||
if (_name) {
|
||||
@ -447,11 +447,16 @@ void setSSRC(Description::Media *description, uint32_t ssrc, const char *_name,
|
||||
msid = string(_msid);
|
||||
}
|
||||
|
||||
description->addSSRC(ssrc, name, msid);
|
||||
optional<string> trackID = nullopt;
|
||||
if (_trackID) {
|
||||
trackID = string(_trackID);
|
||||
}
|
||||
|
||||
description->addSSRC(ssrc, name, msid, trackID);
|
||||
}
|
||||
|
||||
int rtcAddTrackEx(int pc, rtcCodec codec, int payloadType, uint32_t ssrc, const char *_mid,
|
||||
rtcDirection _direction, const char *_name, const char *_msid) {
|
||||
rtcDirection _direction, const char *_name, const char *_msid, const char *_trackID) {
|
||||
return WRAP({
|
||||
auto peerConnection = getPeerConnection(pc);
|
||||
|
||||
@ -516,7 +521,7 @@ int rtcAddTrackEx(int pc, rtcCodec codec, int payloadType, uint32_t ssrc, const
|
||||
throw std::invalid_argument("Unexpected codec");
|
||||
} else {
|
||||
auto description = optDescription.value();
|
||||
setSSRC(&description, ssrc, _name, _msid);
|
||||
setSSRC(&description, ssrc, _name, _msid, _trackID);
|
||||
|
||||
int tr = emplaceTrack(peerConnection->addTrack(std::move(description)));
|
||||
if (auto ptr = getUserPointer(pc)) {
|
||||
|
@ -525,20 +525,20 @@ Description::Entry::removeAttribute(std::vector<string>::iterator it) {
|
||||
}
|
||||
|
||||
void Description::Media::addSSRC(uint32_t ssrc, std::optional<string> name,
|
||||
std::optional<string> msid) {
|
||||
std::optional<string> msid, std::optional<string> trackID) {
|
||||
if (name)
|
||||
mAttributes.emplace_back("ssrc:" + std::to_string(ssrc) + " cname:" + *name);
|
||||
else
|
||||
mAttributes.emplace_back("ssrc:" + std::to_string(ssrc));
|
||||
|
||||
if (msid)
|
||||
mAttributes.emplace_back("ssrc:" + std::to_string(ssrc) + " msid:" + *msid + " " + *msid);
|
||||
mAttributes.emplace_back("ssrc:" + std::to_string(ssrc) + " msid:" + *msid + " " + trackID.value_or(*msid));
|
||||
|
||||
mSsrcs.emplace_back(ssrc);
|
||||
}
|
||||
|
||||
void Description::Media::replaceSSRC(uint32_t oldSSRC, uint32_t ssrc, std::optional<string> name,
|
||||
std::optional<string> msid) {
|
||||
std::optional<string> msid, std::optional<string> trackID) {
|
||||
auto it = mAttributes.begin();
|
||||
while (it != mAttributes.end()) {
|
||||
if (it->find("ssrc:" + std::to_string(oldSSRC)) == 0) {
|
||||
@ -546,7 +546,7 @@ void Description::Media::replaceSSRC(uint32_t oldSSRC, uint32_t ssrc, std::optio
|
||||
} else
|
||||
it++;
|
||||
}
|
||||
addSSRC(ssrc, std::move(name), std::move(msid));
|
||||
addSSRC(ssrc, std::move(name), std::move(msid), std::move(trackID));
|
||||
}
|
||||
|
||||
void Description::Media::removeSSRC(uint32_t oldSSRC) {
|
||||
|
Reference in New Issue
Block a user