2
0

rtppacketizer.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Copyright (c) 2020 Filip Klembara (in2core)
  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_PACKETIZER_H
  9. #define RTC_RTP_PACKETIZER_H
  10. #if RTC_ENABLE_MEDIA
  11. #include "mediahandler.hpp"
  12. #include "message.hpp"
  13. #include "rtppacketizationconfig.hpp"
  14. namespace rtc {
  15. /// RTP packetizer
  16. class RTC_CPP_EXPORT RtpPacketizer : public MediaHandler {
  17. public:
  18. /// Constructs packetizer with given RTP configuration
  19. /// @note RTP configuration is used in packetization process which may change some configuration
  20. /// properties such as sequence number.
  21. /// @param rtpConfig RTP configuration
  22. RtpPacketizer(shared_ptr<RtpPacketizationConfig> rtpConfig);
  23. virtual ~RtpPacketizer();
  24. virtual void media(const Description::Media &desc) override;
  25. virtual void outgoing(message_vector &messages, const message_callback &send) override;
  26. /// RTP packetization config
  27. const shared_ptr<RtpPacketizationConfig> rtpConfig;
  28. protected:
  29. /// Creates RTP packet for given payload
  30. /// @note This function increase sequence number after packetization.
  31. /// @param payload RTP payload
  32. /// @param setMark Set marker flag in RTP packet if true
  33. virtual message_ptr packetize(shared_ptr<binary> payload, bool mark);
  34. private:
  35. static const auto RtpHeaderSize = 12;
  36. static const auto RtpExtHeaderCvoSize = 8;
  37. };
  38. // Generic audio RTP packetizer
  39. template <uint32_t DEFAULT_CLOCK_RATE>
  40. class RTC_CPP_EXPORT AudioRtpPacketizer final : public RtpPacketizer {
  41. public:
  42. inline static const uint32_t DefaultClockRate = DEFAULT_CLOCK_RATE;
  43. inline static const uint32_t defaultClockRate [[deprecated("Use DefaultClockRate")]] =
  44. DEFAULT_CLOCK_RATE; // for backward compatibility
  45. AudioRtpPacketizer(shared_ptr<RtpPacketizationConfig> rtpConfig)
  46. : RtpPacketizer(std::move(rtpConfig)) {}
  47. };
  48. // Audio RTP packetizers
  49. using OpusRtpPacketizer = AudioRtpPacketizer<48000>;
  50. using AACRtpPacketizer = AudioRtpPacketizer<48000>;
  51. // Dummy wrapper for backward compatibility, do not use
  52. class RTC_CPP_EXPORT PacketizationHandler final : public MediaHandler {
  53. public:
  54. PacketizationHandler(shared_ptr<RtpPacketizer> packetizer)
  55. : mPacketizer(std::move(packetizer)) {}
  56. inline void outgoing(message_vector &messages, const message_callback &send) {
  57. return mPacketizer->outgoing(messages, send);
  58. }
  59. private:
  60. shared_ptr<RtpPacketizer> mPacketizer;
  61. };
  62. // Audio packetization handlers for backward compatibility, do not use
  63. using OpusPacketizationHandler [[deprecated("Add OpusRtpPacketizer directly")]] =
  64. PacketizationHandler;
  65. using AACPacketizationHandler [[deprecated("Add AACRtpPacketizer directly")]] =
  66. PacketizationHandler;
  67. } // namespace rtc
  68. #endif /* RTC_ENABLE_MEDIA */
  69. #endif /* RTC_RTP_PACKETIZER_H */