2
0

rtpdepacketizer.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef RTC_RTP_DEPACKETIZER_H
  9. #define RTC_RTP_DEPACKETIZER_H
  10. #if RTC_ENABLE_MEDIA
  11. #include "mediahandler.hpp"
  12. #include "message.hpp"
  13. #include <set>
  14. namespace rtc {
  15. // Base RTP depacketizer class
  16. class RTC_CPP_EXPORT RtpDepacketizer : public MediaHandler {
  17. public:
  18. RtpDepacketizer();
  19. RtpDepacketizer(uint32_t clockRate);
  20. virtual ~RtpDepacketizer();
  21. virtual void incoming(message_vector &messages, const message_callback &send) override;
  22. protected:
  23. shared_ptr<FrameInfo> createFrameInfo(uint32_t timestamp, uint8_t payloadType) const;
  24. private:
  25. const uint32_t mClockRate;
  26. };
  27. // Base class for video RTP depacketizer
  28. class RTC_CPP_EXPORT VideoRtpDepacketizer : public RtpDepacketizer {
  29. public:
  30. inline static const uint32_t ClockRate = 90000;
  31. VideoRtpDepacketizer();
  32. virtual ~VideoRtpDepacketizer();
  33. protected:
  34. struct sequence_cmp {
  35. bool operator()(message_ptr a, message_ptr b) const;
  36. };
  37. using message_buffer = std::set<message_ptr, sequence_cmp>;
  38. virtual message_ptr reassemble(message_buffer &messages) = 0;
  39. private:
  40. void incoming(message_vector &messages, const message_callback &send) override;
  41. message_buffer mBuffer;
  42. };
  43. // Generic audio RTP depacketizer
  44. template <uint32_t DEFAULT_CLOCK_RATE>
  45. class RTC_CPP_EXPORT AudioRtpDepacketizer final : public RtpDepacketizer {
  46. public:
  47. inline static const uint32_t DefaultClockRate = DEFAULT_CLOCK_RATE;
  48. AudioRtpDepacketizer(uint32_t clockRate = DefaultClockRate) : RtpDepacketizer(clockRate) {}
  49. };
  50. // Audio RTP depacketizers
  51. using OpusRtpDepacketizer = AudioRtpDepacketizer<48000>;
  52. using AACRtpDepacketizer = AudioRtpDepacketizer<48000>;
  53. using PCMARtpDepacketizer = AudioRtpDepacketizer<8000>;
  54. using PCMURtpDepacketizer = AudioRtpDepacketizer<8000>;
  55. using G722RtpDepacketizer = AudioRtpDepacketizer<8000>;
  56. } // namespace rtc
  57. #endif /* RTC_ENABLE_MEDIA */
  58. #endif /* RTC_RTP_DEPACKETIZER_H */