2
0

h264rtppacketizer.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 "nalunit.hpp"
  22. #include "rtppacketizer.hpp"
  23. #include "mediahandlerrootelement.hpp"
  24. namespace rtc {
  25. /// RTP packetization of h264 payload
  26. class RTC_CPP_EXPORT H264RtpPacketizer final : public RtpPacketizer, public MediaHandlerRootElement {
  27. shared_ptr<NalUnits> splitMessage(binary_ptr message);
  28. const uint16_t maximumFragmentSize;
  29. public:
  30. /// Default clock rate for H264 in RTP
  31. inline static const uint32_t defaultClockRate = 90 * 1000;
  32. /// Nalunit separator
  33. enum class Separator {
  34. LongStartSequence, // 0x00, 0x00, 0x00, 0x01
  35. ShortStartSequence, // 0x00, 0x00, 0x01
  36. StartSequence, // LongStartSequence or ShortStartSequence
  37. Length // first 4 bytes is nal unit length
  38. };
  39. H264RtpPacketizer(H264RtpPacketizer::Separator separator, shared_ptr<RtpPacketizationConfig> rtpConfig,
  40. uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
  41. /// Constructs h264 payload packetizer with given RTP configuration.
  42. /// @note RTP configuration is used in packetization process which may change some configuration
  43. /// properties such as sequence number.
  44. /// @param rtpConfig RTP configuration
  45. /// @param maximumFragmentSize maximum size of one NALU fragment
  46. H264RtpPacketizer(shared_ptr<RtpPacketizationConfig> rtpConfig,
  47. uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
  48. ChainedOutgoingProduct processOutgoingBinaryMessage(ChainedMessagesProduct messages, message_ptr control) override;
  49. private:
  50. const Separator separator;
  51. };
  52. } // namespace rtc
  53. #endif /* RTC_ENABLE_MEDIA */
  54. #endif /* RTC_H264_RTP_PACKETIZER_H */