mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 23:25:33 +00:00
Many many bug fixes
This commit is contained in:
@ -76,6 +76,7 @@ public:
|
|||||||
|
|
||||||
virtual void parseSdpLine(string_view line);
|
virtual void parseSdpLine(string_view line);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Entry(const string &mline, string mid, Direction dir = Direction::Unknown);
|
Entry(const string &mline, string mid, Direction dir = Direction::Unknown);
|
||||||
virtual string generateSdpLines(string_view eol) const;
|
virtual string generateSdpLines(string_view eol) const;
|
||||||
@ -142,6 +143,10 @@ public:
|
|||||||
|
|
||||||
void removeFB(const string &string);
|
void removeFB(const string &string);
|
||||||
void addFB(const string &string);
|
void addFB(const string &string);
|
||||||
|
void addAttribute(std::string attr) {
|
||||||
|
fmtps.emplace_back(attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int pt;
|
int pt;
|
||||||
string format;
|
string format;
|
||||||
|
@ -57,11 +57,11 @@ public:
|
|||||||
inline uint32_t ssrc() const { return ntohl(_ssrc);}
|
inline uint32_t ssrc() const { return ntohl(_ssrc);}
|
||||||
|
|
||||||
inline size_t getSize() const {
|
inline size_t getSize() const {
|
||||||
return ((char*)&_ssrc) - ((char*)this) + sizeof(SSRC)*csrcCount();
|
return ((char*)&csrc) - ((char*)this) + sizeof(SSRC)*csrcCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
char * getBody() const {
|
char * getBody() const {
|
||||||
return ((char*) this) + getSize();
|
return ((char*) &csrc) + sizeof(SSRC)*csrcCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setSeqNumber(uint16_t newSeqNo) {
|
inline void setSeqNumber(uint16_t newSeqNo) {
|
||||||
@ -132,7 +132,7 @@ public:
|
|||||||
|
|
||||||
inline void setJitter(uint32_t jitter) { _jitter = htonl(jitter); }
|
inline void setJitter(uint32_t jitter) { _jitter = htonl(jitter); }
|
||||||
|
|
||||||
inline void setNTPOfSR(uint32_t ntp) { _lastReport = htonl(ntp >> 16u); }
|
inline void setNTPOfSR(uint64_t ntp) { _lastReport = htonll(ntp >> 16u); }
|
||||||
inline uint32_t getNTPOfSR() const { return ntohl(_lastReport) << 16u; }
|
inline uint32_t getNTPOfSR() const { return ntohl(_lastReport) << 16u; }
|
||||||
|
|
||||||
inline void setDelaySinceSR(uint32_t sr) {
|
inline void setDelaySinceSR(uint32_t sr) {
|
||||||
@ -168,11 +168,11 @@ public:
|
|||||||
inline uint16_t length() const { return ntohs(_length); }
|
inline uint16_t length() const { return ntohs(_length); }
|
||||||
|
|
||||||
inline void setPayloadType(uint8_t type) { _payloadType = type; }
|
inline void setPayloadType(uint8_t type) { _payloadType = type; }
|
||||||
inline void setReportCount(uint8_t count) { _first = (_first & 0xF0) | (count & 0x0F); }
|
inline void setReportCount(uint8_t count) { _first = (_first & 0b11100000) | (count & 0b00011111); }
|
||||||
inline void setLength(uint16_t length) { _length = htons(length); }
|
inline void setLength(uint16_t length) { _length = htons(length); }
|
||||||
|
|
||||||
inline void prepareHeader(uint8_t payloadType, uint8_t reportCount, uint16_t length) {
|
inline void prepareHeader(uint8_t payloadType, uint8_t reportCount, uint16_t length) {
|
||||||
_first = 0x02 << 6; // version 2, no padding
|
_first = 0b10000000; // version 2, no padding
|
||||||
setReportCount(reportCount);
|
setReportCount(reportCount);
|
||||||
setPayloadType(payloadType);
|
setPayloadType(payloadType);
|
||||||
setLength(length);
|
setLength(length);
|
||||||
@ -241,7 +241,7 @@ public:
|
|||||||
return sizeof(uint32_t) * (1 + size_t(header.length()));
|
return sizeof(uint32_t) * (1 + size_t(header.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32_t ntpTimestamp() const { return ntohll(_ntpTimestamp); }
|
inline uint64_t ntpTimestamp() const { return ntohll(_ntpTimestamp); }
|
||||||
inline uint32_t rtpTimestamp() const { return ntohl(_rtpTimestamp); }
|
inline uint32_t rtpTimestamp() const { return ntohl(_rtpTimestamp); }
|
||||||
inline uint32_t packetCount() const { return ntohl(_packetCount); }
|
inline uint32_t packetCount() const { return ntohl(_packetCount); }
|
||||||
inline uint32_t octetCount() const { return ntohl(_octetCount); }
|
inline uint32_t octetCount() const { return ntohl(_octetCount); }
|
||||||
@ -303,36 +303,42 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct RTCP_REMB {
|
struct RTCP_REMB {
|
||||||
RTCP_HEADER header;
|
RTCP_FB_HEADER header;
|
||||||
SSRC senderSSRC;
|
|
||||||
SSRC mediaSourceSSRC;
|
|
||||||
|
|
||||||
// Unique identifier
|
/*! \brief Unique identifier ('R' 'E' 'M' 'B') */
|
||||||
const char id[4] = {'R', 'E', 'M', 'B'};
|
char id[4];
|
||||||
|
|
||||||
// Num SSRC, Br Exp, Br Mantissa (bit mask)
|
/*! \brief Num SSRC, Br Exp, Br Mantissa (bit mask) */
|
||||||
uint32_t bitrate;
|
uint32_t bitrate;
|
||||||
|
|
||||||
SSRC ssrc[1];
|
SSRC ssrc[1];
|
||||||
|
|
||||||
[[nodiscard]] inline size_t getSize() const {
|
[[nodiscard]] unsigned int getSize() const {
|
||||||
// "length" in packet is one less than the number of 32 bit words in the packet.
|
// "length" in packet is one less than the number of 32 bit words in the packet.
|
||||||
return sizeof(uint32_t) * (1 + size_t(header.length()));
|
return sizeof(uint32_t) * (1 + header.header.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void preparePacket(SSRC senderSSRC, unsigned int numSSRC, unsigned int bitrate) {
|
void preparePacket(SSRC senderSSRC, unsigned int numSSRC, unsigned int bitrate) {
|
||||||
|
|
||||||
// Report Count becomes the format here.
|
// Report Count becomes the format here.
|
||||||
header.prepareHeader(206, 15, 0);
|
header.header.prepareHeader(206, 15, 0);
|
||||||
|
|
||||||
// Always zero.
|
// Always zero.
|
||||||
mediaSourceSSRC = 0;
|
header.setMediaSourceSSRC(0);
|
||||||
|
|
||||||
|
header.setPacketSenderSSRC(senderSSRC);
|
||||||
|
|
||||||
|
id[0] = 'R';
|
||||||
|
id[1] = 'E';
|
||||||
|
id[2] = 'M';
|
||||||
|
id[3] = 'B';
|
||||||
|
|
||||||
this->senderSSRC = htonl(senderSSRC);
|
|
||||||
setBitrate(numSSRC, bitrate);
|
setBitrate(numSSRC, bitrate);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setBitrate(unsigned int numSSRC, unsigned int bitrate) {
|
void setBitrate(unsigned int numSSRC, unsigned int bitrate) {
|
||||||
unsigned int exp = 0;
|
unsigned int exp = 0;
|
||||||
while (bitrate > pow(2, 18) - 1) {
|
while (bitrate > pow(2, 18) - 1) {
|
||||||
exp++;
|
exp++;
|
||||||
@ -340,38 +346,23 @@ struct RTCP_REMB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// "length" in packet is one less than the number of 32 bit words in the packet.
|
// "length" in packet is one less than the number of 32 bit words in the packet.
|
||||||
header.setLength(uint16_t(((sizeof(header) + 4 * 2 + 4 + 4) / 4) - 1 + numSSRC));
|
header.header.setLength((offsetof(RTCP_REMB, ssrc) / sizeof(uint32_t)) - 1 + numSSRC);
|
||||||
|
|
||||||
this->bitrate = htonl((numSSRC << (32u - 8u)) | (exp << (32u - 8u - 6u)) | bitrate);
|
this->bitrate = htonl(
|
||||||
|
(numSSRC << (32u - 8u)) | (exp << (32u - 8u - 6u)) | bitrate
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Make this work
|
void setSsrc(int iterator, SSRC newSssrc){
|
||||||
// uint64_t getBitrate() const{
|
ssrc[iterator] = htonl(newSssrc);
|
||||||
// uint32_t ntohed = ntohl(this->bitrate);
|
|
||||||
// uint64_t bitrate = ntohed & (unsigned int)(pow(2, 18)-1);
|
|
||||||
// unsigned int exp = ntohed & ((unsigned int)( (pow(2, 6)-1)) << (32u-8u-6u));
|
|
||||||
// return bitrate * pow(2,exp);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// uint8_t getNumSSRCS() const {
|
|
||||||
// return ntohl(this->bitrate) & (((unsigned int) pow(2,8)-1) << (32u-8u));
|
|
||||||
// }
|
|
||||||
|
|
||||||
inline void setSSRC(uint8_t iterator, SSRC ssrc) { this->ssrc[iterator] = htonl(ssrc); }
|
|
||||||
|
|
||||||
inline void log() const {
|
|
||||||
header.log();
|
|
||||||
PLOG_DEBUG << "RTCP REMB: "
|
|
||||||
<< " SSRC=" << ntohl(senderSSRC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int sizeWithSSRCs(int numSSRC) {
|
size_t static inline sizeWithSSRCs(int count) {
|
||||||
return (sizeof(header) + 4 * 2 + 4 + 4) + sizeof(SSRC) * numSSRC;
|
return sizeof(RTCP_REMB) + (count-1)*sizeof(SSRC);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct RTCP_PLI {
|
struct RTCP_PLI {
|
||||||
RTCP_FB_HEADER header;
|
RTCP_FB_HEADER header;
|
||||||
|
|
||||||
@ -499,7 +490,7 @@ public:
|
|||||||
header.setSsrc(originalSSRC); // TODO Endianess
|
header.setSsrc(originalSSRC); // TODO Endianess
|
||||||
header.setPayloadType(originalPayloadType);
|
header.setPayloadType(originalPayloadType);
|
||||||
// TODO, the -12 is the size of the header (which is variable!)
|
// TODO, the -12 is the size of the header (which is variable!)
|
||||||
memmove(header.getBody(), header.getBody() + 2, totalSize - 12 - sizeof(uint16_t));
|
memmove(header.getBody(), header.getBody() + sizeof(uint16_t), totalSize - 12 - sizeof(uint16_t));
|
||||||
return totalSize - sizeof(uint16_t);
|
return totalSize - sizeof(uint16_t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -603,9 +603,10 @@ void Description::Video::addVideoCodec(int payloadType, const string &codec) {
|
|||||||
addRTPMap(map);
|
addRTPMap(map);
|
||||||
|
|
||||||
// RTX Packets
|
// RTX Packets
|
||||||
RTPMap rtx(std::to_string(payloadType+1) + " RTP/90000");
|
RTPMap rtx(std::to_string(payloadType+1) + " RTX/90000");
|
||||||
// TODO rtx-time is how long can a request be stashed for before needing to resend it. Needs to be parameterized
|
// TODO rtx-time is how long can a request be stashed for before needing to resend it. Needs to be parameterized
|
||||||
rtx.addFB("apt=" + std::to_string(payloadType) + ";rtx-time=3000");
|
rtx.addAttribute("apt=" + std::to_string(payloadType) + ";rtx-time=3000");
|
||||||
|
addRTPMap(rtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Description::Audio::addAudioCodec(int payloadType, const string &codec) {
|
void Description::Audio::addAudioCodec(int payloadType, const string &codec) {
|
||||||
|
@ -578,7 +578,8 @@ void PeerConnection::forwardMedia(message_ptr message) {
|
|||||||
mMidFromPayloadType.emplace(payloadType, *found);
|
mMidFromPayloadType.emplace(payloadType, *found);
|
||||||
mid = *found;
|
mid = *found;
|
||||||
break;
|
break;
|
||||||
}
|
}else
|
||||||
|
PLOG_WARNING << "Unknown payload type" << payloadType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/rtcp.cpp
10
src/rtcp.cpp
@ -59,12 +59,6 @@ rtc::message_ptr RtcpReceivingSession::incoming(rtc::message_ptr ptr) {
|
|||||||
|
|
||||||
mSsrc = rtp->ssrc();
|
mSsrc = rtp->ssrc();
|
||||||
|
|
||||||
uint32_t seqNo = rtp->seqNumber();
|
|
||||||
// uint32_t rtpTS = rtp->getTS();
|
|
||||||
|
|
||||||
if (mGreatestSeqNo < seqNo)
|
|
||||||
mGreatestSeqNo = seqNo;
|
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,8 +96,8 @@ void RtcpReceivingSession::pushREMB(unsigned int bitrate) {
|
|||||||
rtc::make_message(RTCP_REMB::sizeWithSSRCs(1), rtc::Message::Type::Control);
|
rtc::make_message(RTCP_REMB::sizeWithSSRCs(1), rtc::Message::Type::Control);
|
||||||
auto remb = reinterpret_cast<RTCP_REMB *>(msg->data());
|
auto remb = reinterpret_cast<RTCP_REMB *>(msg->data());
|
||||||
remb->preparePacket(mSsrc, 1, bitrate);
|
remb->preparePacket(mSsrc, 1, bitrate);
|
||||||
remb->setSSRC(0, mSsrc);
|
remb->setSsrc(0, mSsrc);
|
||||||
remb->log();
|
//remb->log();
|
||||||
|
|
||||||
send(msg);
|
send(msg);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user