Skip to content

Commit

Permalink
One shot REMB magic check
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemirtingas committed Jul 6, 2024
1 parent fb7444d commit 6f88df5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/rembhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@

#if RTC_ENABLE_MEDIA

static inline uint32_t makeEndianAgnosticValue(uint32_t value) {
return ((uint8_t *)&value)[0] | (((uint8_t *)&value)[1] << 8) | (((uint8_t *)&value)[2] << 16) |
(((uint8_t *)&value)[3] << 24);
}

namespace rtc {

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

void RembHandler::incoming(message_vector &messages, [[maybe_unused]] const message_callback &send) {
static uint32_t rembValue = makeEndianAgnosticValue('BMER');

for (const auto &message : messages) {
size_t offset = 0;
while ((sizeof(RtcpHeader) + offset) <= message->size()) {
Expand All @@ -31,7 +38,7 @@ void RembHandler::incoming(message_vector &messages, [[maybe_unused]] const mess
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') {
if (*(reinterpret_cast<const uint32_t *>(&remb->_id)) == rembValue) {
mOnRemb(remb->getBitrate());
break;
}
Expand Down

0 comments on commit 6f88df5

Please sign in to comment.