rtppacketizationconfig.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 mStartTimestamp = 0;
  26. double mStartTime = 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 = mStartTime;
  34. const uint32_t &startTimestamp = mStartTimestamp;
  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. // For backward compatibility, do not use
  60. const double &startTime_s = mStartTime;
  61. enum class EpochStart : uint64_t {
  62. T1970 = 2208988800, // number of seconds between 1970 and 1900
  63. T1900 = 0
  64. };
  65. /// Creates relation between time and timestamp mapping given start time and start timestamp
  66. /// @param startTime Start time of the stream
  67. /// @param epochStart Type of used epoch
  68. /// @param startTimestamp Corresponding timestamp for given start time (current timestamp will
  69. /// be used if value is nullopt)
  70. void setStartTime(double startTime, EpochStart epochStart,
  71. optional<uint32_t> startTimestamp = std::nullopt);
  72. /// Construct RTP configuration used in packetization process
  73. /// @param ssrc SSRC of source
  74. /// @param cname CNAME of source
  75. /// @param payloadType Payload type of source
  76. /// @param clockRate Clock rate of source used in timestamps
  77. /// @param sequenceNumber Initial sequence number of RTP packets (random number is choosed if
  78. /// nullopt)
  79. /// @param timestamp Initial timastamp of RTP packets (random number is choosed if nullopt)
  80. RtpPacketizationConfig(SSRC ssrc, std::string cname, uint8_t payloadType, uint32_t clockRate,
  81. optional<uint16_t> sequenceNumber = std::nullopt,
  82. optional<uint32_t> timestamp = std::nullopt,
  83. uint8_t videoOrientationId = 0);
  84. /// Convert timestamp to seconds
  85. /// @param timestamp Timestamp
  86. /// @param clockRate Clock rate for timestamp calculation
  87. static double getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate);
  88. /// Convert timestamp to seconds
  89. /// @param timestamp Timestamp
  90. double timestampToSeconds(uint32_t timestamp);
  91. /// Convert seconds to timestamp
  92. /// @param seconds Number of seconds
  93. /// @param clockRate Clock rate for timestamp calculation
  94. static uint32_t getTimestampFromSeconds(double seconds, uint32_t clockRate);
  95. /// Convert seconds to timestamp
  96. /// @param seconds Number of seconds
  97. uint32_t secondsToTimestamp(double seconds);
  98. };
  99. } // namespace rtc
  100. #endif /* RTC_ENABLE_MEDIA */
  101. #endif /* RTC_RTP_PACKETIZATION_CONFIG_H */