rtppacketizationconfig.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 RTPPacketizationConfig_hpp
  19. #define RTPPacketizationConfig_hpp
  20. #if RTC_ENABLE_MEDIA
  21. #include "rtp.hpp"
  22. namespace rtc {
  23. /// RTP configuration used in packetization process
  24. class RTC_CPP_EXPORT RTPPacketizationConfig {
  25. uint32_t _startTimestamp = 0;
  26. double _startTime_s = 0;
  27. RTPPacketizationConfig(const RTPPacketizationConfig&) = delete;
  28. public:
  29. const SSRC ssrc;
  30. const std::string cname;
  31. const uint8_t payloadType;
  32. const uint32_t clockRate;
  33. const double & startTime_s = _startTime_s;
  34. const uint32_t & startTimestamp = _startTimestamp;
  35. /// current sequence number
  36. uint16_t sequenceNumber;
  37. /// current timestamp
  38. uint32_t timestamp;
  39. enum class EpochStart: unsigned long long {
  40. T1970 = 2208988800, // number of seconds between 1970 and 1900
  41. T1900 = 0
  42. };
  43. /// Creates relation between time and timestamp mapping given start time and start timestamp
  44. /// @param startTime_s Start time of the stream
  45. /// @param epochStart Type of used epoch
  46. /// @param startTimestamp Corresponding timestamp for given start time (current timestamp will be used if value is nullopt)
  47. void setStartTime(double startTime_s, EpochStart epochStart, std::optional<uint32_t> startTimestamp = std::nullopt);
  48. /// Construct RTP configuration used in packetization process
  49. /// @param ssrc SSRC of source
  50. /// @param cname CNAME of source
  51. /// @param payloadType Payload type of source
  52. /// @param clockRate Clock rate of source used in timestamps
  53. /// @param sequenceNumber Initial sequence number of RTP packets (random number is choosed if nullopt)
  54. /// @param timestamp Initial timastamp of RTP packets (random number is choosed if nullopt)
  55. RTPPacketizationConfig(SSRC ssrc, std::string cname, uint8_t payloadType, uint32_t clockRate, std::optional<uint16_t> sequenceNumber = std::nullopt, std::optional<uint32_t> timestamp = std::nullopt);
  56. /// Convert timestamp to seconds
  57. /// @param timestamp Timestamp
  58. /// @param clockRate Clock rate for timestamp calculation
  59. static double getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate);
  60. /// Convert timestamp to seconds
  61. /// @param timestamp Timestamp
  62. double timestampToSeconds(uint32_t timestamp);
  63. /// Convert seconds to timestamp
  64. /// @param seconds Number of seconds
  65. /// @param clockRate Clock rate for timestamp calculation
  66. static uint32_t getTimestampFromSeconds(double seconds, uint32_t clockRate);
  67. /// Convert seconds to timestamp
  68. /// @param seconds Number of seconds
  69. uint32_t secondsToTimestamp(double seconds);
  70. };
  71. } // namespace
  72. #endif /* RTC_ENABLE_MEDIA */
  73. #endif /* RTPPacketizationConfig_hpp */