rtppacketizationconfig.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. public:
  26. const SSRC ssrc;
  27. const std::string cname;
  28. const uint8_t payloadType;
  29. const uint32_t clockRate;
  30. const uint8_t videoOrientationId;
  31. // current sequence number
  32. uint16_t sequenceNumber;
  33. // current timestamp
  34. uint32_t timestamp;
  35. // start timestamp
  36. uint32_t startTimestamp;
  37. /// Current video orientation
  38. ///
  39. /// Bit# 7 6 5 4 3 2 1 0
  40. /// Definition 0 0 0 0 C F R1 R0
  41. ///
  42. /// C
  43. /// 0 - Front-facing camera (use this if unsure)
  44. /// 1 - Back-facing camera
  45. ///
  46. /// F
  47. /// 0 - No Flip
  48. /// 1 - Horizontal flip
  49. ///
  50. /// R1 R0 - CW rotation that receiver must apply
  51. /// 0 - 0 degrees
  52. /// 1 - 90 degrees
  53. /// 2 - 180 degrees
  54. /// 3 - 270 degrees
  55. uint8_t videoOrientation = 0;
  56. /// Construct RTP configuration used in packetization process
  57. /// @param ssrc SSRC of source
  58. /// @param cname CNAME of source
  59. /// @param payloadType Payload type of source
  60. /// @param clockRate Clock rate of source used in timestamps
  61. /// nullopt)
  62. /// @param videoOrientationId Video orientation (see above)
  63. RtpPacketizationConfig(SSRC ssrc, std::string cname, uint8_t payloadType, uint32_t clockRate,
  64. uint8_t videoOrientationId = 0);
  65. RtpPacketizationConfig(const RtpPacketizationConfig &) = delete;
  66. /// Convert timestamp to seconds
  67. /// @param timestamp Timestamp
  68. /// @param clockRate Clock rate for timestamp calculation
  69. static double getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate);
  70. /// Convert timestamp to seconds
  71. /// @param timestamp Timestamp
  72. double timestampToSeconds(uint32_t timestamp);
  73. /// Convert seconds to timestamp
  74. /// @param seconds Number of seconds
  75. /// @param clockRate Clock rate for timestamp calculation
  76. static uint32_t getTimestampFromSeconds(double seconds, uint32_t clockRate);
  77. /// Convert seconds to timestamp
  78. /// @param seconds Number of seconds
  79. uint32_t secondsToTimestamp(double seconds);
  80. // deprecated, do not use
  81. double startTime = 0.;
  82. enum class EpochStart : uint64_t {
  83. T1970 = 2208988800, // number of seconds between 1970 and 1900
  84. T1900 = 0
  85. };
  86. [[deprecated]] void setStartTime(double startTime, EpochStart epochStart,
  87. optional<uint32_t> startTimestamp = std::nullopt);
  88. };
  89. } // namespace rtc
  90. #endif /* RTC_ENABLE_MEDIA */
  91. #endif /* RTC_RTP_PACKETIZATION_CONFIG_H */