Markus Handell | 0357b3e | 2020-03-16 13:40:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | |
| 11 | #include <memory> |
| 12 | #include <tuple> |
| 13 | |
| 14 | #include "api/rtc_event_log/rtc_event_log_factory.h" |
| 15 | #include "api/task_queue/default_task_queue_factory.h" |
| 16 | #include "media/base/fake_media_engine.h" |
| 17 | #include "p2p/base/fake_port_allocator.h" |
| 18 | #include "pc/media_session.h" |
| 19 | #include "pc/peer_connection_wrapper.h" |
| 20 | #include "rtc_base/gunit.h" |
| 21 | #include "rtc_base/strings/string_builder.h" |
| 22 | #include "test/gmock.h" |
| 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | using ::testing::Combine; |
| 27 | using ::testing::ElementsAre; |
| 28 | using ::testing::Field; |
| 29 | using ::testing::Return; |
| 30 | using ::testing::Values; |
| 31 | |
| 32 | class PeerConnectionHeaderExtensionTest |
| 33 | : public ::testing::TestWithParam< |
| 34 | std::tuple<cricket::MediaType, SdpSemantics>> { |
| 35 | protected: |
| 36 | std::unique_ptr<PeerConnectionWrapper> CreatePeerConnection( |
| 37 | cricket::MediaType media_type, |
| 38 | absl::optional<SdpSemantics> semantics, |
| 39 | std::vector<RtpHeaderExtensionCapability> extensions) { |
| 40 | auto voice = std::make_unique<cricket::FakeVoiceEngine>(); |
| 41 | auto video = std::make_unique<cricket::FakeVideoEngine>(); |
| 42 | if (media_type == cricket::MediaType::MEDIA_TYPE_AUDIO) |
| 43 | voice->SetRtpHeaderExtensions(extensions); |
| 44 | else |
| 45 | video->SetRtpHeaderExtensions(extensions); |
| 46 | auto media_engine = std::make_unique<cricket::CompositeMediaEngine>( |
| 47 | std::move(voice), std::move(video)); |
| 48 | PeerConnectionFactoryDependencies factory_dependencies; |
| 49 | factory_dependencies.network_thread = rtc::Thread::Current(); |
| 50 | factory_dependencies.worker_thread = rtc::Thread::Current(); |
| 51 | factory_dependencies.signaling_thread = rtc::Thread::Current(); |
| 52 | factory_dependencies.task_queue_factory = CreateDefaultTaskQueueFactory(); |
| 53 | factory_dependencies.media_engine = std::move(media_engine); |
| 54 | factory_dependencies.call_factory = CreateCallFactory(); |
| 55 | factory_dependencies.event_log_factory = |
| 56 | std::make_unique<RtcEventLogFactory>( |
| 57 | factory_dependencies.task_queue_factory.get()); |
| 58 | |
| 59 | auto pc_factory = |
| 60 | CreateModularPeerConnectionFactory(std::move(factory_dependencies)); |
| 61 | |
| 62 | auto fake_port_allocator = std::make_unique<cricket::FakePortAllocator>( |
| 63 | rtc::Thread::Current(), nullptr); |
| 64 | auto observer = std::make_unique<MockPeerConnectionObserver>(); |
| 65 | PeerConnectionInterface::RTCConfiguration config; |
| 66 | if (semantics) |
| 67 | config.sdp_semantics = *semantics; |
| 68 | auto pc = pc_factory->CreatePeerConnection( |
| 69 | config, std::move(fake_port_allocator), nullptr, observer.get()); |
| 70 | observer->SetPeerConnectionInterface(pc.get()); |
| 71 | return std::make_unique<PeerConnectionWrapper>(pc_factory, pc, |
| 72 | std::move(observer)); |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | TEST_P(PeerConnectionHeaderExtensionTest, TransceiverOffersHeaderExtensions) { |
| 77 | cricket::MediaType media_type; |
| 78 | SdpSemantics semantics; |
| 79 | std::tie(media_type, semantics) = GetParam(); |
| 80 | if (semantics != SdpSemantics::kUnifiedPlan) |
| 81 | return; |
| 82 | std::vector<RtpHeaderExtensionCapability> extensions( |
| 83 | {RtpHeaderExtensionCapability("uri1", 1, |
| 84 | RtpTransceiverDirection::kStopped), |
| 85 | RtpHeaderExtensionCapability("uri2", 2, |
| 86 | RtpTransceiverDirection::kSendOnly), |
| 87 | RtpHeaderExtensionCapability("uri3", 3, |
| 88 | RtpTransceiverDirection::kRecvOnly), |
| 89 | RtpHeaderExtensionCapability("uri4", 4, |
| 90 | RtpTransceiverDirection::kSendRecv)}); |
| 91 | std::unique_ptr<PeerConnectionWrapper> wrapper = |
| 92 | CreatePeerConnection(media_type, semantics, extensions); |
| 93 | auto transceiver = wrapper->AddTransceiver(media_type); |
| 94 | EXPECT_EQ(transceiver->HeaderExtensionsToOffer(), extensions); |
| 95 | } |
| 96 | |
| 97 | TEST_P(PeerConnectionHeaderExtensionTest, |
| 98 | SenderReceiverCapabilitiesReturnNotStoppedExtensions) { |
| 99 | cricket::MediaType media_type; |
| 100 | SdpSemantics semantics; |
| 101 | std::tie(media_type, semantics) = GetParam(); |
| 102 | std::unique_ptr<PeerConnectionWrapper> wrapper = CreatePeerConnection( |
| 103 | media_type, semantics, |
| 104 | std::vector<RtpHeaderExtensionCapability>( |
| 105 | {RtpHeaderExtensionCapability("uri1", 1, |
| 106 | RtpTransceiverDirection::kSendRecv), |
| 107 | RtpHeaderExtensionCapability("uri2", 2, |
| 108 | RtpTransceiverDirection::kStopped), |
| 109 | RtpHeaderExtensionCapability("uri3", 3, |
| 110 | RtpTransceiverDirection::kRecvOnly)})); |
| 111 | EXPECT_THAT(wrapper->pc_factory() |
| 112 | ->GetRtpSenderCapabilities(media_type) |
| 113 | .header_extensions, |
| 114 | ElementsAre(Field(&RtpHeaderExtensionCapability::uri, "uri1"), |
| 115 | Field(&RtpHeaderExtensionCapability::uri, "uri3"))); |
| 116 | EXPECT_EQ(wrapper->pc_factory() |
| 117 | ->GetRtpReceiverCapabilities(media_type) |
| 118 | .header_extensions, |
| 119 | wrapper->pc_factory() |
| 120 | ->GetRtpSenderCapabilities(media_type) |
| 121 | .header_extensions); |
| 122 | } |
| 123 | |
| 124 | INSTANTIATE_TEST_SUITE_P( |
| 125 | , |
| 126 | PeerConnectionHeaderExtensionTest, |
| 127 | Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 128 | Values(cricket::MediaType::MEDIA_TYPE_AUDIO, |
| 129 | cricket::MediaType::MEDIA_TYPE_VIDEO)), |
| 130 | [](const testing::TestParamInfo< |
| 131 | PeerConnectionHeaderExtensionTest::ParamType>& info) { |
| 132 | cricket::MediaType media_type; |
| 133 | SdpSemantics semantics; |
| 134 | std::tie(media_type, semantics) = info.param; |
| 135 | return (rtc::StringBuilder("With") |
| 136 | << (semantics == SdpSemantics::kPlanB ? "PlanB" : "UnifiedPlan") |
| 137 | << "And" |
| 138 | << (media_type == cricket::MediaType::MEDIA_TYPE_AUDIO ? "Voice" |
| 139 | : "Video") |
| 140 | << "Engine") |
| 141 | .str(); |
| 142 | }); |
| 143 | |
| 144 | } // namespace webrtc |