h264rtppacketizer.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Copyright (c) 2020 Filip Klembara (in2core)
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef RTC_H264_RTP_PACKETIZER_H
  19. #define RTC_H264_RTP_PACKETIZER_H
  20. #if RTC_ENABLE_MEDIA
  21. #include "mediahandlerrootelement.hpp"
  22. #include "nalunit.hpp"
  23. #include "rtppacketizer.hpp"
  24. namespace rtc {
  25. /// RTP packetization of h264 payload
  26. class RTC_CPP_EXPORT H264RtpPacketizer final : public RtpPacketizer,
  27. public MediaHandlerRootElement {
  28. shared_ptr<NalUnits> splitMessage(binary_ptr message);
  29. const uint16_t maximumFragmentSize;
  30. public:
  31. /// Default clock rate for H264 in RTP
  32. inline static const uint32_t defaultClockRate = 90 * 1000;
  33. /// Nalunit separator
  34. enum class Separator {
  35. LongStartSequence, // 0x00, 0x00, 0x00, 0x01
  36. ShortStartSequence, // 0x00, 0x00, 0x01
  37. StartSequence, // LongStartSequence or ShortStartSequence
  38. Length // first 4 bytes is nal unit length
  39. };
  40. H264RtpPacketizer(H264RtpPacketizer::Separator separator,
  41. shared_ptr<RtpPacketizationConfig> rtpConfig,
  42. uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
  43. /// Constructs h264 payload packetizer with given RTP configuration.
  44. /// @note RTP configuration is used in packetization process which may change some configuration
  45. /// properties such as sequence number.
  46. /// @param rtpConfig RTP configuration
  47. /// @param maximumFragmentSize maximum size of one NALU fragment
  48. H264RtpPacketizer(shared_ptr<RtpPacketizationConfig> rtpConfig,
  49. uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
  50. ChainedOutgoingProduct processOutgoingBinaryMessage(ChainedMessagesProduct messages,
  51. message_ptr control) override;
  52. private:
  53. const Separator separator;
  54. };
  55. } // namespace rtc
  56. #endif /* RTC_ENABLE_MEDIA */
  57. #endif /* RTC_H264_RTP_PACKETIZER_H */