rtppacketizer.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #if RTC_ENABLE_MEDIA
  19. #include "rtppacketizer.hpp"
  20. namespace rtc {
  21. RTPPacketizer::RTPPacketizer(std::shared_ptr<RTPPacketizationConfig> rtpConfig): rtpConfig(rtpConfig) { }
  22. message_ptr RTPPacketizer::packetize(binary payload, bool setMark) {
  23. auto msg = make_message(rtpHeaderSize + payload.size());
  24. auto * rtp = (RTP *)msg->data();
  25. rtp->setPayloadType(rtpConfig->payloadType);
  26. // increase sequence number
  27. rtp->setSeqNumber(rtpConfig->sequenceNumber++);
  28. rtp->setTimestamp(rtpConfig->timestamp);
  29. rtp->setSsrc(rtpConfig->ssrc);
  30. if (setMark) {
  31. rtp->setMarker(true);
  32. }
  33. rtp->preparePacket();
  34. copy(payload.begin(), payload.end(), msg->begin() + rtpHeaderSize);
  35. return msg;
  36. }
  37. } // namespace
  38. #endif /* RTC_ENABLE_MEDIA */