rtppacketizationconfig.hpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * libdatachannel streamer example
  3. * Copyright (c) 2020 Filip Klembara (in2core)
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef RTPPacketizationConfig_hpp
  19. #define RTPPacketizationConfig_hpp
  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. std::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. std::optional<uint16_t> sequenceNumber = std::nullopt,
  60. std::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 /* RTPPacketizationConfig_hpp */