rtppacketizationconfig.hpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /// 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
  47. /// be used if value is nullopt)
  48. void setStartTime(double startTime_s, EpochStart epochStart,
  49. optional<uint32_t> startTimestamp = std::nullopt);
  50. /// Construct RTP configuration used in packetization process
  51. /// @param ssrc SSRC of source
  52. /// @param cname CNAME of source
  53. /// @param payloadType Payload type of source
  54. /// @param clockRate Clock rate of source used in timestamps
  55. /// @param sequenceNumber Initial sequence number of RTP packets (random number is choosed if
  56. /// nullopt)
  57. /// @param timestamp Initial timastamp of RTP packets (random number is choosed if nullopt)
  58. RtpPacketizationConfig(SSRC ssrc, std::string cname, uint8_t payloadType, uint32_t clockRate,
  59. optional<uint16_t> sequenceNumber = std::nullopt,
  60. optional<uint32_t> timestamp = std::nullopt);
  61. /// Convert timestamp to seconds
  62. /// @param timestamp Timestamp
  63. /// @param clockRate Clock rate for timestamp calculation
  64. static double getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate);
  65. /// Convert timestamp to seconds
  66. /// @param timestamp Timestamp
  67. double timestampToSeconds(uint32_t timestamp);
  68. /// Convert seconds to timestamp
  69. /// @param seconds Number of seconds
  70. /// @param clockRate Clock rate for timestamp calculation
  71. static uint32_t getTimestampFromSeconds(double seconds, uint32_t clockRate);
  72. /// Convert seconds to timestamp
  73. /// @param seconds Number of seconds
  74. uint32_t secondsToTimestamp(double seconds);
  75. };
  76. } // namespace rtc
  77. #endif /* RTC_ENABLE_MEDIA */
  78. #endif /* RTC_RTP_PACKETIZATION_CONFIG_H */