rtpdepacketizer.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright (c) 2024 Paul-Louis Ageneau
  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. #if RTC_ENABLE_MEDIA
  9. #include "rtpdepacketizer.hpp"
  10. #include "rtp.hpp"
  11. #include "impl/logcounter.hpp"
  12. #include <cmath>
  13. #include <cstring>
  14. namespace rtc {
  15. RtpDepacketizer::RtpDepacketizer() : mClockRate(0) {}
  16. RtpDepacketizer::RtpDepacketizer(uint32_t clockRate) : mClockRate(clockRate) {}
  17. RtpDepacketizer::~RtpDepacketizer() {}
  18. void RtpDepacketizer::incoming([[maybe_unused]] message_vector &messages,
  19. [[maybe_unused]] const message_callback &send) {
  20. message_vector result;
  21. for (auto &message : messages) {
  22. if (message->type == Message::Control) {
  23. result.push_back(std::move(message));
  24. continue;
  25. }
  26. if (message->size() < sizeof(RtpHeader)) {
  27. PLOG_VERBOSE << "RTP packet is too small, size=" << message->size();
  28. continue;
  29. }
  30. auto pkt = reinterpret_cast<const rtc::RtpHeader *>(message->data());
  31. auto headerSize = sizeof(rtc::RtpHeader) + pkt->csrcCount() + pkt->getExtensionHeaderSize();
  32. auto frameInfo = std::make_shared<FrameInfo>(pkt->timestamp());
  33. if (mClockRate > 0)
  34. frameInfo->timestampSeconds =
  35. std::chrono::duration<double>(double(pkt->timestamp()) / double(mClockRate));
  36. frameInfo->payloadType = pkt->payloadType();
  37. result.push_back(make_message(message->begin() + headerSize, message->end(), frameInfo));
  38. }
  39. messages.swap(result);
  40. }
  41. } // namespace rtc
  42. #endif /* RTC_ENABLE_MEDIA */