plihandler.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * Copyright (c) 2023 Arda Cinar
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  7. */
  8. #include "plihandler.hpp"
  9. #include "rtp.hpp"
  10. #if RTC_ENABLE_MEDIA
  11. namespace rtc {
  12. PliHandler::PliHandler(std::function<void(void)> onPli) : mOnPli(onPli) {}
  13. void PliHandler::incoming(message_vector &messages, [[maybe_unused]] const message_callback &send) {
  14. for (const auto &message : messages) {
  15. size_t offset = 0;
  16. while ((sizeof(RtcpHeader) + offset) <= message->size()) {
  17. auto header = reinterpret_cast<RtcpHeader *>(message->data() + offset);
  18. uint8_t payload_type = header->payloadType();
  19. if (payload_type == 196) {
  20. // FIR message, call pli handler anyway
  21. mOnPli();
  22. break;
  23. } else if (payload_type == 206) {
  24. // On a payload specific fb message, there is a "feedback message type" (FMT) in the
  25. // header instead of a report count. PT = 206, FMT = 1 means a PLI message
  26. uint8_t feedback_message_type = header->reportCount();
  27. if (feedback_message_type == 1) {
  28. mOnPli();
  29. break;
  30. }
  31. }
  32. offset += header->lengthInBytes();
  33. }
  34. }
  35. }
  36. } // namespace rtc
  37. #endif // RTC_ENABLE_MEDIA