Skip to content

Commit

Permalink
added check size & identifier rtp remb & changed parameters for callback
Browse files Browse the repository at this point in the history
  • Loading branch information
evaldemar committed Jun 7, 2024
1 parent f6c8073 commit 6b43909
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/rtc/rembhandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ namespace rtc {

/// Responds to REMB messages sent by the receiver.
class RTC_CPP_EXPORT RembHandler final : public MediaHandler {
rtc::synchronized_callback<unsigned int, unsigned int> mOnRemb;
rtc::synchronized_callback<unsigned int> mOnRemb;

public:
/// Constructs the RembResponder object to notify whenever a bitrate
/// @param onRemb The callback that gets called whenever a bitrate by the receiver
RembHandler(std::function<void(unsigned int, unsigned int)> onRemb);
RembHandler(std::function<void(unsigned int)> onRemb);

void incoming(message_vector &messages, const message_callback &send) override;
};
Expand Down
2 changes: 1 addition & 1 deletion include/rtc/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ typedef void *(RTC_API *rtcInterceptorCallbackFunc)(int pc, const char *message,
typedef void(RTC_API *rtcBufferedAmountLowCallbackFunc)(int id, void *ptr);
typedef void(RTC_API *rtcAvailableCallbackFunc)(int id, void *ptr);
typedef void(RTC_API *rtcPliHandlerCallbackFunc)(int tr, void *ptr);
typedef void(RTC_API *rtcRembHandlerCallbackFunc)(int tr, unsigned int numSSRC, unsigned int bitrate, void *ptr);
typedef void(RTC_API *rtcRembHandlerCallbackFunc)(int tr, unsigned int bitrate, void *ptr);

// Log

Expand Down
4 changes: 2 additions & 2 deletions src/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,9 +1334,9 @@ int rtcChainPliHandler(int tr, rtcPliHandlerCallbackFunc cb) {
int rtcChainRembHandler(int tr, rtcRembHandlerCallbackFunc cb) {
return wrap([&] {
auto track = getTrack(tr);
auto handler = std::make_shared<RembHandler>([tr, cb](unsigned int numSSRC, unsigned int bitrate) {
auto handler = std::make_shared<RembHandler>([tr, cb](unsigned int bitrate) {
if (auto ptr = getUserPointer(tr))
cb(tr, numSSRC, bitrate, *ptr);
cb(tr, bitrate, *ptr);
});
track->chainMediaHandler(handler);
return RTC_ERR_SUCCESS;
Expand Down
13 changes: 8 additions & 5 deletions src/rembhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace rtc {

RembHandler::RembHandler(std::function<void(unsigned int, unsigned int)> onRemb) : mOnRemb(onRemb) {}
RembHandler::RembHandler(std::function<void(unsigned int)> onRemb) : mOnRemb(onRemb) {}

void RembHandler::incoming(message_vector &messages, [[maybe_unused]] const message_callback &send) {
for (const auto &message : messages) {
Expand All @@ -28,10 +28,13 @@ void RembHandler::incoming(message_vector &messages, [[maybe_unused]] const mess
auto header = reinterpret_cast<RtcpHeader *>(message->data() + offset);
uint8_t payload_type = header->payloadType();

if (payload_type == 206 && header->reportCount() == 15) {
auto remb = reinterpret_cast<RtcpRemb *>(message->data() + offset);
mOnRemb(remb->getNumSSRC(), remb->getBitrate());
break;
if (payload_type == 206 && header->reportCount() == 15 && header->lengthInBytes() == sizeof(RtcpRemb)) {
auto remb = reinterpret_cast<RtcpRemb *>(message->data() + offset);

if (remb->_id[0] == 'R' && remb->_id[1] == 'E' && remb->_id[2] == 'M' && remb->_id[3] == 'B') {
mOnRemb(remb->getBitrate());
break;
}
}

offset += header->lengthInBytes();
Expand Down

0 comments on commit 6b43909

Please sign in to comment.