2
0

h264rtppacketizer.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * libdatachannel streamer example
  3. * Copyright (c) 2020 Filip Klembara (in2core)
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef H264_RTP_PACKETIZER_H
  19. #define 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 : public RtpPacketizer, public MediaHandlerRootElement {
  27. std::shared_ptr<NalUnits> splitMessage(binary_ptr message);
  28. const uint16_t maximumFragmentSize;
  29. public:
  30. /// Default clock rate for H264 in RTP
  31. static const auto 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, std::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(std::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 /* H264_RTP_PACKETIZER_H */