rtp_config.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef CALL_RTP_CONFIG_H_
  11. #define CALL_RTP_CONFIG_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <string>
  15. #include <vector>
  16. #include "absl/types/optional.h"
  17. #include "api/rtp_headers.h"
  18. #include "api/rtp_parameters.h"
  19. namespace webrtc {
  20. // Currently only VP8/VP9 specific.
  21. struct RtpPayloadState {
  22. int16_t picture_id = -1;
  23. uint8_t tl0_pic_idx = 0;
  24. int64_t shared_frame_id = 0;
  25. };
  26. // Settings for LNTF (LossNotification). Still highly experimental.
  27. struct LntfConfig {
  28. std::string ToString() const;
  29. bool enabled{false};
  30. };
  31. // Settings for NACK, see RFC 4585 for details.
  32. struct NackConfig {
  33. NackConfig() : rtp_history_ms(0) {}
  34. std::string ToString() const;
  35. // Send side: the time RTP packets are stored for retransmissions.
  36. // Receive side: the time the receiver is prepared to wait for
  37. // retransmissions.
  38. // Set to '0' to disable.
  39. int rtp_history_ms;
  40. };
  41. // Settings for ULPFEC forward error correction.
  42. // Set the payload types to '-1' to disable.
  43. struct UlpfecConfig {
  44. UlpfecConfig()
  45. : ulpfec_payload_type(-1),
  46. red_payload_type(-1),
  47. red_rtx_payload_type(-1) {}
  48. std::string ToString() const;
  49. bool operator==(const UlpfecConfig& other) const;
  50. // Payload type used for ULPFEC packets.
  51. int ulpfec_payload_type;
  52. // Payload type used for RED packets.
  53. int red_payload_type;
  54. // RTX payload type for RED payload.
  55. int red_rtx_payload_type;
  56. };
  57. static const size_t kDefaultMaxPacketSize = 1500 - 40; // TCP over IPv4.
  58. struct RtpConfig {
  59. RtpConfig();
  60. RtpConfig(const RtpConfig&);
  61. ~RtpConfig();
  62. std::string ToString() const;
  63. std::vector<uint32_t> ssrcs;
  64. // The Rtp Stream Ids (aka RIDs) to send in the RID RTP header extension
  65. // if the extension is included in the list of extensions.
  66. // If rids are specified, they should correspond to the |ssrcs| vector.
  67. // This means that:
  68. // 1. rids.size() == 0 || rids.size() == ssrcs.size().
  69. // 2. If rids is not empty, then |rids[i]| should use |ssrcs[i]|.
  70. std::vector<std::string> rids;
  71. // The value to send in the MID RTP header extension if the extension is
  72. // included in the list of extensions.
  73. std::string mid;
  74. // See RtcpMode for description.
  75. RtcpMode rtcp_mode = RtcpMode::kCompound;
  76. // Max RTP packet size delivered to send transport from VideoEngine.
  77. size_t max_packet_size = kDefaultMaxPacketSize;
  78. // Corresponds to the SDP attribute extmap-allow-mixed.
  79. bool extmap_allow_mixed = false;
  80. // RTP header extensions to use for this send stream.
  81. std::vector<RtpExtension> extensions;
  82. // TODO(nisse): For now, these are fixed, but we'd like to support
  83. // changing codec without recreating the VideoSendStream. Then these
  84. // fields must be removed, and association between payload type and codec
  85. // must move above the per-stream level. Ownership could be with
  86. // RtpTransportControllerSend, with a reference from PayloadRouter, where
  87. // the latter would be responsible for mapping the codec type of encoded
  88. // images to the right payload type.
  89. std::string payload_name;
  90. int payload_type = -1;
  91. // Payload should be packetized using raw packetizer (payload header will
  92. // not be added, additional meta data is expected to be present in generic
  93. // frame descriptor RTP header extension).
  94. bool raw_payload = false;
  95. // See LntfConfig for description.
  96. LntfConfig lntf;
  97. // See NackConfig for description.
  98. NackConfig nack;
  99. // See UlpfecConfig for description.
  100. UlpfecConfig ulpfec;
  101. struct Flexfec {
  102. Flexfec();
  103. Flexfec(const Flexfec&);
  104. ~Flexfec();
  105. // Payload type of FlexFEC. Set to -1 to disable sending FlexFEC.
  106. int payload_type = -1;
  107. // SSRC of FlexFEC stream.
  108. uint32_t ssrc = 0;
  109. // Vector containing a single element, corresponding to the SSRC of the
  110. // media stream being protected by this FlexFEC stream.
  111. // The vector MUST have size 1.
  112. //
  113. // TODO(brandtr): Update comment above when we support
  114. // multistream protection.
  115. std::vector<uint32_t> protected_media_ssrcs;
  116. } flexfec;
  117. // Settings for RTP retransmission payload format, see RFC 4588 for
  118. // details.
  119. struct Rtx {
  120. Rtx();
  121. Rtx(const Rtx&);
  122. ~Rtx();
  123. std::string ToString() const;
  124. // SSRCs to use for the RTX streams.
  125. std::vector<uint32_t> ssrcs;
  126. // Payload type to use for the RTX stream.
  127. int payload_type = -1;
  128. } rtx;
  129. // RTCP CNAME, see RFC 3550.
  130. std::string c_name;
  131. bool IsMediaSsrc(uint32_t ssrc) const;
  132. bool IsRtxSsrc(uint32_t ssrc) const;
  133. bool IsFlexfecSsrc(uint32_t ssrc) const;
  134. absl::optional<uint32_t> GetRtxSsrcAssociatedWithMediaSsrc(
  135. uint32_t media_ssrc) const;
  136. uint32_t GetMediaSsrcAssociatedWithRtxSsrc(uint32_t rtx_ssrc) const;
  137. uint32_t GetMediaSsrcAssociatedWithFlexfecSsrc(uint32_t flexfec_ssrc) const;
  138. absl::optional<std::string> GetRidForSsrc(uint32_t ssrc) const;
  139. };
  140. } // namespace webrtc
  141. #endif // CALL_RTP_CONFIG_H_