rtppacketizationconfig.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_RTP_PACKETIZATION_CONFIG_H
  19. #define RTC_RTP_PACKETIZATION_CONFIG_H
  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. const uint8_t videoOrientationId;
  36. /// current sequence number
  37. uint16_t sequenceNumber;
  38. /// current timestamp
  39. uint32_t timestamp;
  40. /// Current video orientation
  41. ///
  42. /// Bit# 7 6 5 4 3 2 1 0
  43. /// Definition 0 0 0 0 C F R1 R0
  44. ///
  45. /// C
  46. /// 0 - Front-facing camera (use this if unsure)
  47. /// 1 - Back-facing camera
  48. ///
  49. /// F
  50. /// 0 - No Flip
  51. /// 1 - Horizontal flip
  52. ///
  53. /// R1 R0 - CW rotation that receiver must apply
  54. /// 0 - 0 degrees
  55. /// 1 - 90 degrees
  56. /// 2 - 180 degrees
  57. /// 3 - 270 degrees
  58. uint8_t videoOrientation = 0;
  59. enum class EpochStart : unsigned long long {
  60. T1970 = 2208988800, // number of seconds between 1970 and 1900
  61. T1900 = 0
  62. };
  63. /// Creates relation between time and timestamp mapping given start time and start timestamp
  64. /// @param startTime_s Start time of the stream
  65. /// @param epochStart Type of used epoch
  66. /// @param startTimestamp Corresponding timestamp for given start time (current timestamp will
  67. /// be used if value is nullopt)
  68. void setStartTime(double startTime_s, EpochStart epochStart,
  69. optional<uint32_t> startTimestamp = std::nullopt);
  70. /// Construct RTP configuration used in packetization process
  71. /// @param ssrc SSRC of source
  72. /// @param cname CNAME of source
  73. /// @param payloadType Payload type of source
  74. /// @param clockRate Clock rate of source used in timestamps
  75. /// @param sequenceNumber Initial sequence number of RTP packets (random number is choosed if
  76. /// nullopt)
  77. /// @param timestamp Initial timastamp of RTP packets (random number is choosed if nullopt)
  78. RtpPacketizationConfig(SSRC ssrc, std::string cname, uint8_t payloadType, uint32_t clockRate,
  79. optional<uint16_t> sequenceNumber = std::nullopt,
  80. optional<uint32_t> timestamp = std::nullopt,
  81. uint8_t videoOrientationId = 0);
  82. /// Convert timestamp to seconds
  83. /// @param timestamp Timestamp
  84. /// @param clockRate Clock rate for timestamp calculation
  85. static double getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate);
  86. /// Convert timestamp to seconds
  87. /// @param timestamp Timestamp
  88. double timestampToSeconds(uint32_t timestamp);
  89. /// Convert seconds to timestamp
  90. /// @param seconds Number of seconds
  91. /// @param clockRate Clock rate for timestamp calculation
  92. static uint32_t getTimestampFromSeconds(double seconds, uint32_t clockRate);
  93. /// Convert seconds to timestamp
  94. /// @param seconds Number of seconds
  95. uint32_t secondsToTimestamp(double seconds);
  96. };
  97. } // namespace rtc
  98. #endif /* RTC_ENABLE_MEDIA */
  99. #endif /* RTC_RTP_PACKETIZATION_CONFIG_H */