Browse Source

added check size & identifier rtp remb & changed parameters for callback

Vladimir Voronin 1 year ago
parent
commit
6b4390990f
4 changed files with 13 additions and 10 deletions
  1. 2 2
      include/rtc/rembhandler.hpp
  2. 1 1
      include/rtc/rtc.h
  3. 2 2
      src/capi.cpp
  4. 8 5
      src/rembhandler.cpp

+ 2 - 2
include/rtc/rembhandler.hpp

@@ -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;
 };

+ 1 - 1
include/rtc/rtc.h

@@ -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
 

+ 2 - 2
src/capi.cpp

@@ -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;

+ 8 - 5
src/rembhandler.cpp

@@ -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) {
@@ -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();