sdp_changer.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2019 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 TEST_PC_E2E_SDP_SDP_CHANGER_H_
  11. #define TEST_PC_E2E_SDP_SDP_CHANGER_H_
  12. #include <map>
  13. #include <string>
  14. #include <vector>
  15. #include "absl/strings/string_view.h"
  16. #include "absl/types/optional.h"
  17. #include "api/array_view.h"
  18. #include "api/jsep.h"
  19. #include "api/rtp_parameters.h"
  20. #include "api/test/peerconnection_quality_test_fixture.h"
  21. #include "media/base/rid_description.h"
  22. #include "pc/session_description.h"
  23. #include "pc/simulcast_description.h"
  24. namespace webrtc {
  25. namespace webrtc_pc_e2e {
  26. // Creates list of capabilities, which can be set on RtpTransceiverInterface via
  27. // RtpTransceiverInterface::SetCodecPreferences(...) to negotiate use of codecs
  28. // from list of |supported_codecs| which will match |video_codecs|. If flags
  29. // |ulpfec| or |flexfec| set to true corresponding FEC codec will be added.
  30. // FEC and RTX codecs will be added after required codecs.
  31. //
  32. // All codecs will be added only if they exists in the list of
  33. // |supported_codecs|. If multiple codecs from this list will match
  34. // |video_codecs|, then all of them will be added to the output
  35. // vector and they will be added in the same order, as they were in
  36. // |supported_codecs|.
  37. std::vector<RtpCodecCapability> FilterVideoCodecCapabilities(
  38. rtc::ArrayView<const PeerConnectionE2EQualityTestFixture::VideoCodecConfig>
  39. video_codecs,
  40. bool use_rtx,
  41. bool use_ulpfec,
  42. bool use_flexfec,
  43. rtc::ArrayView<const RtpCodecCapability> supported_codecs);
  44. struct LocalAndRemoteSdp {
  45. LocalAndRemoteSdp(std::unique_ptr<SessionDescriptionInterface> local_sdp,
  46. std::unique_ptr<SessionDescriptionInterface> remote_sdp)
  47. : local_sdp(std::move(local_sdp)), remote_sdp(std::move(remote_sdp)) {}
  48. // Sdp, that should be as local description on the peer, that created it.
  49. std::unique_ptr<SessionDescriptionInterface> local_sdp;
  50. // Sdp, that should be set as remote description on the peer opposite to the
  51. // one, who created it.
  52. std::unique_ptr<SessionDescriptionInterface> remote_sdp;
  53. };
  54. struct PatchingParams {
  55. PatchingParams(
  56. std::vector<PeerConnectionE2EQualityTestFixture::VideoCodecConfig>
  57. video_codecs,
  58. bool use_conference_mode,
  59. std::map<std::string, int> stream_label_to_simulcast_streams_count)
  60. : video_codecs(std::move(video_codecs)),
  61. use_conference_mode(use_conference_mode),
  62. stream_label_to_simulcast_streams_count(
  63. stream_label_to_simulcast_streams_count) {}
  64. std::vector<PeerConnectionE2EQualityTestFixture::VideoCodecConfig>
  65. video_codecs;
  66. bool use_conference_mode;
  67. std::map<std::string, int> stream_label_to_simulcast_streams_count;
  68. };
  69. class SignalingInterceptor {
  70. public:
  71. explicit SignalingInterceptor(PatchingParams params) : params_(params) {}
  72. LocalAndRemoteSdp PatchOffer(
  73. std::unique_ptr<SessionDescriptionInterface> offer);
  74. LocalAndRemoteSdp PatchAnswer(
  75. std::unique_ptr<SessionDescriptionInterface> offer);
  76. std::vector<std::unique_ptr<IceCandidateInterface>> PatchOffererIceCandidates(
  77. rtc::ArrayView<const IceCandidateInterface* const> candidates);
  78. std::vector<std::unique_ptr<IceCandidateInterface>>
  79. PatchAnswererIceCandidates(
  80. rtc::ArrayView<const IceCandidateInterface* const> candidates);
  81. private:
  82. // Contains information about simulcast section, that is required to perform
  83. // modified offer/answer and ice candidates exchange.
  84. struct SimulcastSectionInfo {
  85. SimulcastSectionInfo(const std::string& mid,
  86. cricket::MediaProtocolType media_protocol_type,
  87. const std::vector<cricket::RidDescription>& rids_desc);
  88. const std::string mid;
  89. const cricket::MediaProtocolType media_protocol_type;
  90. std::vector<std::string> rids;
  91. cricket::SimulcastDescription simulcast_description;
  92. webrtc::RtpExtension mid_extension;
  93. webrtc::RtpExtension rid_extension;
  94. webrtc::RtpExtension rrid_extension;
  95. cricket::TransportDescription transport_description;
  96. };
  97. struct SignalingContext {
  98. SignalingContext() = default;
  99. // SignalingContext is not copyable and movable.
  100. SignalingContext(SignalingContext&) = delete;
  101. SignalingContext& operator=(SignalingContext&) = delete;
  102. SignalingContext(SignalingContext&&) = delete;
  103. SignalingContext& operator=(SignalingContext&&) = delete;
  104. void AddSimulcastInfo(const SimulcastSectionInfo& info);
  105. bool HasSimulcast() const { return !simulcast_infos.empty(); }
  106. std::vector<SimulcastSectionInfo> simulcast_infos;
  107. std::map<std::string, SimulcastSectionInfo*> simulcast_infos_by_mid;
  108. std::map<std::string, SimulcastSectionInfo*> simulcast_infos_by_rid;
  109. std::vector<std::string> mids_order;
  110. };
  111. LocalAndRemoteSdp PatchVp8Offer(
  112. std::unique_ptr<SessionDescriptionInterface> offer);
  113. LocalAndRemoteSdp PatchVp9Offer(
  114. std::unique_ptr<SessionDescriptionInterface> offer);
  115. LocalAndRemoteSdp PatchVp8Answer(
  116. std::unique_ptr<SessionDescriptionInterface> offer);
  117. LocalAndRemoteSdp PatchVp9Answer(
  118. std::unique_ptr<SessionDescriptionInterface> offer);
  119. void FillSimulcastContext(SessionDescriptionInterface* offer);
  120. std::unique_ptr<cricket::SessionDescription> RestoreMediaSectionsOrder(
  121. std::unique_ptr<cricket::SessionDescription> source);
  122. PatchingParams params_;
  123. SignalingContext context_;
  124. };
  125. } // namespace webrtc_pc_e2e
  126. } // namespace webrtc
  127. #endif // TEST_PC_E2E_SDP_SDP_CHANGER_H_