rtppacketizationconfig.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Copyright (c) 2020 Filip Klembara (in2core)
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  7. */
  8. #ifndef RTC_RTP_PACKETIZATION_CONFIG_H
  9. #define RTC_RTP_PACKETIZATION_CONFIG_H
  10. #if RTC_ENABLE_MEDIA
  11. #include "dependencydescriptor.hpp"
  12. #include "rtp.hpp"
  13. namespace rtc {
  14. // RTP configuration used in packetization process
  15. class RTC_CPP_EXPORT RtpPacketizationConfig {
  16. public:
  17. SSRC ssrc;
  18. std::string cname;
  19. uint8_t payloadType;
  20. uint32_t clockRate;
  21. uint8_t videoOrientationId;
  22. // current sequence number
  23. uint16_t sequenceNumber;
  24. // current timestamp
  25. uint32_t timestamp;
  26. // start timestamp
  27. uint32_t startTimestamp;
  28. /// Current video orientation
  29. ///
  30. /// Bit# 7 6 5 4 3 2 1 0
  31. /// Definition 0 0 0 0 C F R1 R0
  32. ///
  33. /// C
  34. /// 0 - Front-facing camera (use this if unsure)
  35. /// 1 - Back-facing camera
  36. ///
  37. /// F
  38. /// 0 - No Flip
  39. /// 1 - Horizontal flip
  40. ///
  41. /// R1 R0 - CW rotation that receiver must apply
  42. /// 0 - 0 degrees
  43. /// 1 - 90 degrees
  44. /// 2 - 180 degrees
  45. /// 3 - 270 degrees
  46. uint8_t videoOrientation = 0;
  47. // MID Extension Header
  48. uint8_t midId = 0;
  49. optional<std::string> mid;
  50. // RID Extension Header
  51. uint8_t ridId = 0;
  52. optional<std::string> rid;
  53. // Dependency Descriptor Extension Header
  54. uint8_t dependencyDescriptorId = 0;
  55. struct DependencyDescriptorContext {
  56. DependencyDescriptor descriptor;
  57. std::bitset<32> activeChains;
  58. FrameDependencyStructure structure;
  59. };
  60. optional<DependencyDescriptorContext> dependencyDescriptorContext;
  61. /// Construct RTP configuration used in packetization process
  62. /// @param ssrc SSRC of source
  63. /// @param cname CNAME of source
  64. /// @param payloadType Payload type of source
  65. /// @param clockRate Clock rate of source used in timestamps
  66. /// nullopt)
  67. /// @param videoOrientationId Video orientation (see above)
  68. RtpPacketizationConfig(SSRC ssrc, std::string cname, uint8_t payloadType, uint32_t clockRate,
  69. uint8_t videoOrientationId = 0);
  70. RtpPacketizationConfig(const RtpPacketizationConfig &) = delete;
  71. /// Convert timestamp to seconds
  72. /// @param timestamp Timestamp
  73. /// @param clockRate Clock rate for timestamp calculation
  74. static double getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate);
  75. /// Convert timestamp to seconds
  76. /// @param timestamp Timestamp
  77. double timestampToSeconds(uint32_t timestamp);
  78. /// Convert seconds to timestamp
  79. /// @param seconds Number of seconds
  80. /// @param clockRate Clock rate for timestamp calculation
  81. static uint32_t getTimestampFromSeconds(double seconds, uint32_t clockRate);
  82. /// Convert seconds to timestamp
  83. /// @param seconds Number of seconds
  84. uint32_t secondsToTimestamp(double seconds);
  85. };
  86. } // namespace rtc
  87. #endif /* RTC_ENABLE_MEDIA */
  88. #endif /* RTC_RTP_PACKETIZATION_CONFIG_H */