h264packetizationhandler.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * libdatachannel client 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 H264PacketizationHandler_hpp
  19. #define H264PacketizationHandler_hpp
  20. #if RTC_ENABLE_MEDIA
  21. #include "rtcp.hpp"
  22. #include "h264rtppacketizer.hpp"
  23. #include "rtcpsenderreportable.hpp"
  24. #include "nalunit.hpp"
  25. namespace rtc {
  26. /// Handler for H264 packetization
  27. class H264PacketizationHandler: public RtcpHandler, public RTCPSenderReportable {
  28. /// RTP packetizer for H264
  29. const std::shared_ptr<H264RTPPacketizer> packetizer;
  30. const uint16_t maximumFragmentSize;
  31. std::shared_ptr<NalUnits> splitMessage(message_ptr message);
  32. public:
  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. /// Construct handler for H264 packetization.
  41. /// @param separator Nal units separator
  42. /// @param packetizer RTP packetizer for h264
  43. H264PacketizationHandler(Separator separator, std::shared_ptr<H264RTPPacketizer> packetizer, uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
  44. /// Returns message unchanged
  45. /// @param ptr message
  46. message_ptr incoming(message_ptr ptr) override;
  47. /// Returns packetized message if message type is binary
  48. /// @note NAL units in `ptr` message must be separated by `separator` given in constructor
  49. /// @note If message generates multiple rtp packets, all but last are send using `outgoingCallback`. It is your responsibility to send last packet.
  50. /// @param ptr message containing all NAL units for current timestamp (one sample)
  51. /// @return last packet
  52. message_ptr outgoing(message_ptr ptr) override;
  53. private:
  54. /// Separator
  55. const Separator separator;
  56. };
  57. } // namespace
  58. #endif /* RTC_ENABLE_MEDIA */
  59. #endif /* H264PacketizationHandler_hpp */