henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 11 | #include "api/peer_connection_interface.h" |
| 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <limits.h> |
| 14 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 16 | #include <string> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 17 | #include <utility> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 18 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 19 | |
Steve Anton | 1c9c9fc | 2019-02-14 15:13:09 -0800 | [diff] [blame] | 20 | #include "absl/strings/str_replace.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 21 | #include "absl/types/optional.h" |
| 22 | #include "api/audio/audio_mixer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
| 24 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "api/call/call_factory_interface.h" |
Mirko Bonadei | 2ff3f49 | 2018-11-22 09:00:13 +0100 | [diff] [blame] | 26 | #include "api/create_peerconnection_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 27 | #include "api/data_channel_interface.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 28 | #include "api/jsep.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 29 | #include "api/media_stream_interface.h" |
| 30 | #include "api/media_types.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 31 | #include "api/rtc_error.h" |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 32 | #include "api/rtc_event_log/rtc_event_log.h" |
| 33 | #include "api/rtc_event_log/rtc_event_log_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 34 | #include "api/rtc_event_log_output.h" |
| 35 | #include "api/rtp_receiver_interface.h" |
| 36 | #include "api/rtp_sender_interface.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 37 | #include "api/rtp_transceiver_direction.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 38 | #include "api/scoped_refptr.h" |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 39 | #include "api/task_queue/default_task_queue_factory.h" |
Erik Språng | ceb4495 | 2020-09-22 11:36:35 +0200 | [diff] [blame] | 40 | #include "api/transport/field_trial_based_config.h" |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 41 | #include "api/video_codecs/builtin_video_decoder_factory.h" |
| 42 | #include "api/video_codecs/builtin_video_encoder_factory.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 43 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 44 | #include "media/base/media_config.h" |
| 45 | #include "media/base/media_engine.h" |
| 46 | #include "media/base/stream_params.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 47 | #include "media/engine/webrtc_media_engine.h" |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 48 | #include "media/engine/webrtc_media_engine_defaults.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 49 | #include "media/sctp/sctp_transport_internal.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 50 | #include "modules/audio_device/include/audio_device.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 51 | #include "modules/audio_processing/include/audio_processing.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 52 | #include "p2p/base/fake_port_allocator.h" |
| 53 | #include "p2p/base/p2p_constants.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 54 | #include "p2p/base/port.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 55 | #include "p2p/base/port_allocator.h" |
| 56 | #include "p2p/base/transport_description.h" |
| 57 | #include "p2p/base/transport_info.h" |
| 58 | #include "pc/audio_track.h" |
| 59 | #include "pc/media_session.h" |
| 60 | #include "pc/media_stream.h" |
| 61 | #include "pc/peer_connection.h" |
| 62 | #include "pc/peer_connection_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 63 | #include "pc/rtp_sender.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 64 | #include "pc/rtp_sender_proxy.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 65 | #include "pc/session_description.h" |
| 66 | #include "pc/stream_collection.h" |
| 67 | #include "pc/test/fake_audio_capture_module.h" |
| 68 | #include "pc/test/fake_rtc_certificate_generator.h" |
| 69 | #include "pc/test/fake_video_track_source.h" |
| 70 | #include "pc/test/mock_peer_connection_observers.h" |
| 71 | #include "pc/test/test_sdp_strings.h" |
| 72 | #include "pc/video_track.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 73 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 74 | #include "rtc_base/gunit.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 75 | #include "rtc_base/ref_counted_object.h" |
| 76 | #include "rtc_base/rtc_certificate_generator.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 77 | #include "rtc_base/socket_address.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 78 | #include "rtc_base/thread.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 79 | #include "rtc_base/virtual_socket_server.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 80 | #include "test/gmock.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 81 | #include "test/gtest.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 82 | |
| 83 | #ifdef WEBRTC_ANDROID |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 84 | #include "pc/test/android_test_initializer.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 85 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 87 | namespace webrtc { |
| 88 | namespace { |
| 89 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 90 | static const char kStreamId1[] = "local_stream_1"; |
| 91 | static const char kStreamId2[] = "local_stream_2"; |
| 92 | static const char kStreamId3[] = "local_stream_3"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 93 | static const int kDefaultStunPort = 3478; |
| 94 | static const char kStunAddressOnly[] = "stun:address"; |
| 95 | static const char kStunInvalidPort[] = "stun:address:-1"; |
| 96 | static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; |
| 97 | static const char kStunAddressPortAndMore2[] = "stun:address:port more"; |
Niels Möller | db4def9 | 2019-03-18 16:53:59 +0100 | [diff] [blame] | 98 | static const char kTurnIceServerUri[] = "turn:turn.example.org"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | static const char kTurnUsername[] = "user"; |
| 100 | static const char kTurnPassword[] = "password"; |
| 101 | static const char kTurnHostname[] = "turn.example.org"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 102 | static const uint32_t kTimeout = 10000U; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 104 | static const char kStreams[][8] = {"stream1", "stream2"}; |
| 105 | static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"}; |
| 106 | static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"}; |
| 107 | |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 108 | static const char kRecvonly[] = "recvonly"; |
| 109 | static const char kSendrecv[] = "sendrecv"; |
| 110 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 111 | // Reference SDP with a MediaStream with label "stream1" and audio track with |
| 112 | // id "audio_1" and a video track with id "video_1; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 113 | static const char kSdpStringWithStream1PlanB[] = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 114 | "v=0\r\n" |
| 115 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 116 | "s=-\r\n" |
| 117 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 118 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 119 | "a=ice-ufrag:e5785931\r\n" |
| 120 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 121 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 122 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 123 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 124 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 125 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 126 | "a=rtpmap:103 ISAC/16000\r\n" |
| 127 | "a=ssrc:1 cname:stream1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 128 | "a=ssrc:1 mslabel:stream1\r\n" |
| 129 | "a=ssrc:1 label:audiotrack0\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 130 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 131 | "a=ice-ufrag:e5785931\r\n" |
| 132 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 133 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 134 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 135 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 136 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 137 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 138 | "a=rtpmap:120 VP8/90000\r\n" |
| 139 | "a=ssrc:2 cname:stream1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 140 | "a=ssrc:2 mslabel:stream1\r\n" |
| 141 | "a=ssrc:2 label:videotrack0\r\n"; |
| 142 | // Same string as above but with the MID changed to the Unified Plan default. |
| 143 | // This is needed so that this SDP can be used as an answer for a Unified Plan |
| 144 | // offer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 145 | static const char kSdpStringWithStream1UnifiedPlan[] = |
| 146 | "v=0\r\n" |
| 147 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 148 | "s=-\r\n" |
| 149 | "t=0 0\r\n" |
| 150 | "m=audio 1 RTP/AVPF 103\r\n" |
| 151 | "a=ice-ufrag:e5785931\r\n" |
| 152 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 153 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 154 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 155 | "a=mid:0\r\n" |
| 156 | "a=sendrecv\r\n" |
| 157 | "a=rtcp-mux\r\n" |
| 158 | "a=rtpmap:103 ISAC/16000\r\n" |
| 159 | "a=ssrc:1 cname:stream1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 160 | "a=ssrc:1 mslabel:stream1\r\n" |
| 161 | "a=ssrc:1 label:audiotrack0\r\n" |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 162 | "m=video 1 RTP/AVPF 120\r\n" |
| 163 | "a=ice-ufrag:e5785931\r\n" |
| 164 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 165 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 166 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 167 | "a=mid:1\r\n" |
| 168 | "a=sendrecv\r\n" |
| 169 | "a=rtcp-mux\r\n" |
| 170 | "a=rtpmap:120 VP8/90000\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 171 | "a=ssrc:2 cname:stream1\r\n" |
| 172 | "a=ssrc:2 mslabel:stream1\r\n" |
| 173 | "a=ssrc:2 label:videotrack0\r\n"; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 174 | |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 175 | // Reference SDP with a MediaStream with label "stream1" and audio track with |
| 176 | // id "audio_1"; |
| 177 | static const char kSdpStringWithStream1AudioTrackOnly[] = |
| 178 | "v=0\r\n" |
| 179 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 180 | "s=-\r\n" |
| 181 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 182 | "m=audio 1 RTP/AVPF 103\r\n" |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 183 | "a=ice-ufrag:e5785931\r\n" |
| 184 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 185 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 186 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 187 | "a=mid:audio\r\n" |
| 188 | "a=sendrecv\r\n" |
| 189 | "a=rtpmap:103 ISAC/16000\r\n" |
| 190 | "a=ssrc:1 cname:stream1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 191 | "a=ssrc:1 mslabel:stream1\r\n" |
| 192 | "a=ssrc:1 label:audiotrack0\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 193 | "a=rtcp-mux\r\n"; |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 194 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 195 | // Reference SDP with two MediaStreams with label "stream1" and "stream2. Each |
| 196 | // MediaStreams have one audio track and one video track. |
| 197 | // This uses MSID. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 198 | static const char kSdpStringWithStream1And2PlanB[] = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 199 | "v=0\r\n" |
| 200 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 201 | "s=-\r\n" |
| 202 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 203 | "a=msid-semantic: WMS stream1 stream2\r\n" |
| 204 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 205 | "a=ice-ufrag:e5785931\r\n" |
| 206 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 207 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 208 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 209 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 210 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 211 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 212 | "a=rtpmap:103 ISAC/16000\r\n" |
| 213 | "a=ssrc:1 cname:stream1\r\n" |
| 214 | "a=ssrc:1 msid:stream1 audiotrack0\r\n" |
| 215 | "a=ssrc:3 cname:stream2\r\n" |
| 216 | "a=ssrc:3 msid:stream2 audiotrack1\r\n" |
| 217 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 218 | "a=ice-ufrag:e5785931\r\n" |
| 219 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 220 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 221 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 222 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 223 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 224 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 225 | "a=rtpmap:120 VP8/0\r\n" |
| 226 | "a=ssrc:2 cname:stream1\r\n" |
| 227 | "a=ssrc:2 msid:stream1 videotrack0\r\n" |
| 228 | "a=ssrc:4 cname:stream2\r\n" |
| 229 | "a=ssrc:4 msid:stream2 videotrack1\r\n"; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 230 | static const char kSdpStringWithStream1And2UnifiedPlan[] = |
| 231 | "v=0\r\n" |
| 232 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 233 | "s=-\r\n" |
| 234 | "t=0 0\r\n" |
| 235 | "a=msid-semantic: WMS stream1 stream2\r\n" |
| 236 | "m=audio 1 RTP/AVPF 103\r\n" |
| 237 | "a=ice-ufrag:e5785931\r\n" |
| 238 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 239 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 240 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 241 | "a=mid:0\r\n" |
| 242 | "a=sendrecv\r\n" |
| 243 | "a=rtcp-mux\r\n" |
| 244 | "a=rtpmap:103 ISAC/16000\r\n" |
| 245 | "a=ssrc:1 cname:stream1\r\n" |
| 246 | "a=ssrc:1 msid:stream1 audiotrack0\r\n" |
| 247 | "m=video 1 RTP/AVPF 120\r\n" |
| 248 | "a=ice-ufrag:e5785931\r\n" |
| 249 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 250 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 251 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 252 | "a=mid:1\r\n" |
| 253 | "a=sendrecv\r\n" |
| 254 | "a=rtcp-mux\r\n" |
| 255 | "a=rtpmap:120 VP8/0\r\n" |
| 256 | "a=ssrc:2 cname:stream1\r\n" |
| 257 | "a=ssrc:2 msid:stream1 videotrack0\r\n" |
| 258 | "m=audio 1 RTP/AVPF 103\r\n" |
| 259 | "a=ice-ufrag:e5785931\r\n" |
| 260 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 261 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 262 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 263 | "a=mid:2\r\n" |
| 264 | "a=sendrecv\r\n" |
| 265 | "a=rtcp-mux\r\n" |
| 266 | "a=rtpmap:103 ISAC/16000\r\n" |
| 267 | "a=ssrc:3 cname:stream2\r\n" |
| 268 | "a=ssrc:3 msid:stream2 audiotrack1\r\n" |
| 269 | "m=video 1 RTP/AVPF 120\r\n" |
| 270 | "a=ice-ufrag:e5785931\r\n" |
| 271 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 272 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 273 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 274 | "a=mid:3\r\n" |
| 275 | "a=sendrecv\r\n" |
| 276 | "a=rtcp-mux\r\n" |
| 277 | "a=rtpmap:120 VP8/0\r\n" |
| 278 | "a=ssrc:4 cname:stream2\r\n" |
| 279 | "a=ssrc:4 msid:stream2 videotrack1\r\n"; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 280 | |
| 281 | // Reference SDP without MediaStreams. Msid is not supported. |
| 282 | static const char kSdpStringWithoutStreams[] = |
| 283 | "v=0\r\n" |
| 284 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 285 | "s=-\r\n" |
| 286 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 287 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 288 | "a=ice-ufrag:e5785931\r\n" |
| 289 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 290 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 291 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 292 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 293 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 294 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 295 | "a=rtpmap:103 ISAC/16000\r\n" |
| 296 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 297 | "a=ice-ufrag:e5785931\r\n" |
| 298 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 299 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 300 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 301 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 302 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 303 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 304 | "a=rtpmap:120 VP8/90000\r\n"; |
| 305 | |
| 306 | // Reference SDP without MediaStreams. Msid is supported. |
| 307 | static const char kSdpStringWithMsidWithoutStreams[] = |
| 308 | "v=0\r\n" |
| 309 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 310 | "s=-\r\n" |
| 311 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 312 | "a=msid-semantic: WMS\r\n" |
| 313 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 314 | "a=ice-ufrag:e5785931\r\n" |
| 315 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 316 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 317 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 318 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 319 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 320 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 321 | "a=rtpmap:103 ISAC/16000\r\n" |
| 322 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 323 | "a=ice-ufrag:e5785931\r\n" |
| 324 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 325 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 326 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 327 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 328 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 329 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 330 | "a=rtpmap:120 VP8/90000\r\n"; |
| 331 | |
| 332 | // Reference SDP without MediaStreams and audio only. |
| 333 | static const char kSdpStringWithoutStreamsAudioOnly[] = |
| 334 | "v=0\r\n" |
| 335 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 336 | "s=-\r\n" |
| 337 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 338 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 339 | "a=ice-ufrag:e5785931\r\n" |
| 340 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 341 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 342 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 343 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 344 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 345 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 346 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 347 | |
| 348 | // Reference SENDONLY SDP without MediaStreams. Msid is not supported. |
| 349 | static const char kSdpStringSendOnlyWithoutStreams[] = |
| 350 | "v=0\r\n" |
| 351 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 352 | "s=-\r\n" |
| 353 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 354 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 355 | "a=ice-ufrag:e5785931\r\n" |
| 356 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 357 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 358 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 359 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 360 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 361 | "a=sendonly\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 362 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 363 | "a=rtpmap:103 ISAC/16000\r\n" |
| 364 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 365 | "a=ice-ufrag:e5785931\r\n" |
| 366 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 367 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 368 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 369 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 370 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 371 | "a=sendonly\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 372 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 373 | "a=rtpmap:120 VP8/90000\r\n"; |
| 374 | |
| 375 | static const char kSdpStringInit[] = |
| 376 | "v=0\r\n" |
| 377 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 378 | "s=-\r\n" |
| 379 | "t=0 0\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 380 | "a=msid-semantic: WMS\r\n"; |
| 381 | |
| 382 | static const char kSdpStringAudio[] = |
| 383 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 384 | "a=ice-ufrag:e5785931\r\n" |
| 385 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 386 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 387 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 388 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 389 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 390 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 391 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 392 | |
| 393 | static const char kSdpStringVideo[] = |
| 394 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 395 | "a=ice-ufrag:e5785931\r\n" |
| 396 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 397 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 398 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 399 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 400 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 401 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 402 | "a=rtpmap:120 VP8/90000\r\n"; |
| 403 | |
| 404 | static const char kSdpStringMs1Audio0[] = |
| 405 | "a=ssrc:1 cname:stream1\r\n" |
| 406 | "a=ssrc:1 msid:stream1 audiotrack0\r\n"; |
| 407 | |
| 408 | static const char kSdpStringMs1Video0[] = |
| 409 | "a=ssrc:2 cname:stream1\r\n" |
| 410 | "a=ssrc:2 msid:stream1 videotrack0\r\n"; |
| 411 | |
| 412 | static const char kSdpStringMs1Audio1[] = |
| 413 | "a=ssrc:3 cname:stream1\r\n" |
| 414 | "a=ssrc:3 msid:stream1 audiotrack1\r\n"; |
| 415 | |
| 416 | static const char kSdpStringMs1Video1[] = |
| 417 | "a=ssrc:4 cname:stream1\r\n" |
| 418 | "a=ssrc:4 msid:stream1 videotrack1\r\n"; |
| 419 | |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 420 | static const char kDtlsSdesFallbackSdp[] = |
| 421 | "v=0\r\n" |
| 422 | "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n" |
| 423 | "s=-\r\n" |
| 424 | "c=IN IP4 0.0.0.0\r\n" |
| 425 | "t=0 0\r\n" |
| 426 | "a=group:BUNDLE audio\r\n" |
| 427 | "a=msid-semantic: WMS\r\n" |
| 428 | "m=audio 1 RTP/SAVPF 0\r\n" |
| 429 | "a=sendrecv\r\n" |
| 430 | "a=rtcp-mux\r\n" |
| 431 | "a=mid:audio\r\n" |
| 432 | "a=ssrc:1 cname:stream1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 433 | "a=ssrc:1 mslabel:stream1\r\n" |
| 434 | "a=ssrc:1 label:audiotrack0\r\n" |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 435 | "a=ice-ufrag:e5785931\r\n" |
| 436 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 437 | "a=rtpmap:0 pcmu/8000\r\n" |
| 438 | "a=fingerprint:sha-1 " |
| 439 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n" |
| 440 | "a=setup:actpass\r\n" |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 441 | "a=crypto:0 AES_CM_128_HMAC_SHA1_80 " |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 442 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 443 | "dummy_session_params\r\n"; |
| 444 | |
Niels Möller | dec9f74 | 2019-06-03 15:25:20 +0200 | [diff] [blame] | 445 | class RtcEventLogOutputNull final : public RtcEventLogOutput { |
| 446 | public: |
| 447 | bool IsActive() const override { return true; } |
| 448 | bool Write(const std::string& output) override { return true; } |
| 449 | }; |
| 450 | |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 451 | using ::cricket::StreamParams; |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 452 | using ::testing::Exactly; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 453 | using ::testing::Values; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 454 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 455 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
| 456 | using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 457 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 458 | // Gets the first ssrc of given content type from the ContentInfo. |
| 459 | bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) { |
| 460 | if (!content_info || !ssrc) { |
| 461 | return false; |
| 462 | } |
| 463 | const cricket::MediaContentDescription* media_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 464 | content_info->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 465 | if (!media_desc || media_desc->streams().empty()) { |
| 466 | return false; |
| 467 | } |
| 468 | *ssrc = media_desc->streams().begin()->first_ssrc(); |
| 469 | return true; |
| 470 | } |
| 471 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 472 | // Get the ufrags out of an SDP blob. Useful for testing ICE restart |
| 473 | // behavior. |
| 474 | std::vector<std::string> GetUfrags( |
| 475 | const webrtc::SessionDescriptionInterface* desc) { |
| 476 | std::vector<std::string> ufrags; |
| 477 | for (const cricket::TransportInfo& info : |
| 478 | desc->description()->transport_infos()) { |
| 479 | ufrags.push_back(info.description.ice_ufrag); |
| 480 | } |
| 481 | return ufrags; |
| 482 | } |
| 483 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 484 | void SetSsrcToZero(std::string* sdp) { |
| 485 | const char kSdpSsrcAtribute[] = "a=ssrc:"; |
| 486 | const char kSdpSsrcAtributeZero[] = "a=ssrc:0"; |
| 487 | size_t ssrc_pos = 0; |
| 488 | while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) != |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 489 | std::string::npos) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 490 | size_t end_ssrc = sdp->find(" ", ssrc_pos); |
| 491 | sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero); |
| 492 | ssrc_pos = end_ssrc; |
| 493 | } |
| 494 | } |
| 495 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 496 | // Check if `streams` contains the specified track. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 497 | bool ContainsTrack(const std::vector<cricket::StreamParams>& streams, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 498 | const std::string& stream_id, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 499 | const std::string& track_id) { |
| 500 | for (const cricket::StreamParams& params : streams) { |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 501 | if (params.first_stream_id() == stream_id && params.id == track_id) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 502 | return true; |
| 503 | } |
| 504 | } |
| 505 | return false; |
| 506 | } |
| 507 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 508 | // Check if `senders` contains the specified sender, by id. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 509 | bool ContainsSender( |
| 510 | const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, |
| 511 | const std::string& id) { |
| 512 | for (const auto& sender : senders) { |
| 513 | if (sender->id() == id) { |
| 514 | return true; |
| 515 | } |
| 516 | } |
| 517 | return false; |
| 518 | } |
| 519 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 520 | // Check if `senders` contains the specified sender, by id and stream id. |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 521 | bool ContainsSender( |
| 522 | const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, |
| 523 | const std::string& id, |
| 524 | const std::string& stream_id) { |
| 525 | for (const auto& sender : senders) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 526 | if (sender->id() == id && sender->stream_ids()[0] == stream_id) { |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 527 | return true; |
| 528 | } |
| 529 | } |
| 530 | return false; |
| 531 | } |
| 532 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 533 | // Create a collection of streams. |
| 534 | // CreateStreamCollection(1) creates a collection that |
| 535 | // correspond to kSdpStringWithStream1. |
| 536 | // CreateStreamCollection(2) correspond to kSdpStringWithStream1And2. |
| 537 | rtc::scoped_refptr<StreamCollection> CreateStreamCollection( |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 538 | int number_of_streams, |
| 539 | int tracks_per_stream) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 540 | rtc::scoped_refptr<StreamCollection> local_collection( |
| 541 | StreamCollection::Create()); |
| 542 | |
| 543 | for (int i = 0; i < number_of_streams; ++i) { |
| 544 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( |
| 545 | webrtc::MediaStream::Create(kStreams[i])); |
| 546 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 547 | for (int j = 0; j < tracks_per_stream; ++j) { |
| 548 | // Add a local audio track. |
| 549 | rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 550 | webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j], |
| 551 | nullptr)); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 552 | stream->AddTrack(audio_track.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 553 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 554 | // Add a local video track. |
| 555 | rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
| 556 | webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j], |
perkj | 773be36 | 2017-07-31 23:22:01 -0700 | [diff] [blame] | 557 | webrtc::FakeVideoTrackSource::Create(), |
| 558 | rtc::Thread::Current())); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 559 | stream->AddTrack(video_track.get()); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 560 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 561 | |
| 562 | local_collection->AddStream(stream); |
| 563 | } |
| 564 | return local_collection; |
| 565 | } |
| 566 | |
| 567 | // Check equality of StreamCollections. |
| 568 | bool CompareStreamCollections(StreamCollectionInterface* s1, |
| 569 | StreamCollectionInterface* s2) { |
| 570 | if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) { |
| 571 | return false; |
| 572 | } |
| 573 | |
| 574 | for (size_t i = 0; i != s1->count(); ++i) { |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 575 | if (s1->at(i)->id() != s2->at(i)->id()) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 576 | return false; |
| 577 | } |
| 578 | webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks(); |
| 579 | webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks(); |
| 580 | webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks(); |
| 581 | webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks(); |
| 582 | |
| 583 | if (audio_tracks1.size() != audio_tracks2.size()) { |
| 584 | return false; |
| 585 | } |
| 586 | for (size_t j = 0; j != audio_tracks1.size(); ++j) { |
| 587 | if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) { |
| 588 | return false; |
| 589 | } |
| 590 | } |
| 591 | if (video_tracks1.size() != video_tracks2.size()) { |
| 592 | return false; |
| 593 | } |
| 594 | for (size_t j = 0; j != video_tracks1.size(); ++j) { |
| 595 | if (video_tracks1[j]->id() != video_tracks2[j]->id()) { |
| 596 | return false; |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | return true; |
| 601 | } |
| 602 | |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 603 | // Helper class to test Observer. |
| 604 | class MockTrackObserver : public ObserverInterface { |
| 605 | public: |
| 606 | explicit MockTrackObserver(NotifierInterface* notifier) |
| 607 | : notifier_(notifier) { |
| 608 | notifier_->RegisterObserver(this); |
| 609 | } |
| 610 | |
| 611 | ~MockTrackObserver() { Unregister(); } |
| 612 | |
| 613 | void Unregister() { |
| 614 | if (notifier_) { |
| 615 | notifier_->UnregisterObserver(this); |
| 616 | notifier_ = nullptr; |
| 617 | } |
| 618 | } |
| 619 | |
Danil Chapovalov | 3a35312 | 2020-05-15 11:16:53 +0200 | [diff] [blame] | 620 | MOCK_METHOD(void, OnChanged, (), (override)); |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 621 | |
| 622 | private: |
| 623 | NotifierInterface* notifier_; |
| 624 | }; |
| 625 | |
nisse | 528b793 | 2017-05-08 03:21:43 -0700 | [diff] [blame] | 626 | // The PeerConnectionMediaConfig tests below verify that configuration and |
| 627 | // constraints are propagated into the PeerConnection's MediaConfig. These |
| 628 | // settings are intended for MediaChannel constructors, but that is not |
| 629 | // exercised by these unittest. |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 630 | class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { |
| 631 | public: |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 632 | static rtc::scoped_refptr<PeerConnectionFactoryForTest> |
| 633 | CreatePeerConnectionFactoryForTest() { |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 634 | PeerConnectionFactoryDependencies dependencies; |
| 635 | dependencies.worker_thread = rtc::Thread::Current(); |
| 636 | dependencies.network_thread = rtc::Thread::Current(); |
| 637 | dependencies.signaling_thread = rtc::Thread::Current(); |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 638 | dependencies.task_queue_factory = CreateDefaultTaskQueueFactory(); |
Erik Språng | ceb4495 | 2020-09-22 11:36:35 +0200 | [diff] [blame] | 639 | dependencies.trials = std::make_unique<FieldTrialBasedConfig>(); |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 640 | cricket::MediaEngineDependencies media_deps; |
| 641 | media_deps.task_queue_factory = dependencies.task_queue_factory.get(); |
henrika | 919dc2e | 2017-10-12 14:24:55 +0200 | [diff] [blame] | 642 | // Use fake audio device module since we're only testing the interface |
| 643 | // level, and using a real one could make tests flaky when run in parallel. |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 644 | media_deps.adm = FakeAudioCaptureModule::Create(); |
| 645 | SetMediaEngineDefaults(&media_deps); |
Erik Språng | ceb4495 | 2020-09-22 11:36:35 +0200 | [diff] [blame] | 646 | media_deps.trials = dependencies.trials.get(); |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 647 | dependencies.media_engine = |
| 648 | cricket::CreateMediaEngine(std::move(media_deps)); |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 649 | dependencies.call_factory = webrtc::CreateCallFactory(); |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 650 | dependencies.event_log_factory = std::make_unique<RtcEventLogFactory>( |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 651 | dependencies.task_queue_factory.get()); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 652 | |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 653 | return rtc::make_ref_counted<PeerConnectionFactoryForTest>( |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 654 | std::move(dependencies)); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 657 | using PeerConnectionFactory::PeerConnectionFactory; |
kwiberg | 1e4e8cb | 2017-01-31 01:48:08 -0800 | [diff] [blame] | 658 | |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 659 | private: |
deadbeef | d7850b2 | 2017-08-23 10:59:19 -0700 | [diff] [blame] | 660 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 661 | }; |
| 662 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 663 | // TODO(steveanton): Convert to use the new PeerConnectionWrapper. |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 664 | class PeerConnectionInterfaceBaseTest : public ::testing::Test { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 665 | protected: |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 666 | explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics) |
| 667 | : vss_(new rtc::VirtualSocketServer()), |
| 668 | main_(vss_.get()), |
| 669 | sdp_semantics_(sdp_semantics) { |
phoglund | 37ebcf0 | 2016-01-08 05:04:57 -0800 | [diff] [blame] | 670 | #ifdef WEBRTC_ANDROID |
| 671 | webrtc::InitializeAndroidObjects(); |
| 672 | #endif |
| 673 | } |
| 674 | |
Tomas Gunnarsson | 2efb8a5 | 2021-04-01 16:26:57 +0200 | [diff] [blame] | 675 | void SetUp() override { |
deadbeef | d7850b2 | 2017-08-23 10:59:19 -0700 | [diff] [blame] | 676 | // Use fake audio capture module since we're only testing the interface |
| 677 | // level, and using a real one could make tests flaky when run in parallel. |
| 678 | fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 679 | pc_factory_ = webrtc::CreatePeerConnectionFactory( |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 680 | rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 681 | rtc::scoped_refptr<webrtc::AudioDeviceModule>( |
| 682 | fake_audio_capture_module_), |
| 683 | webrtc::CreateBuiltinAudioEncoderFactory(), |
| 684 | webrtc::CreateBuiltinAudioDecoderFactory(), |
| 685 | webrtc::CreateBuiltinVideoEncoderFactory(), |
| 686 | webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */, |
| 687 | nullptr /* audio_processing */); |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 688 | ASSERT_TRUE(pc_factory_); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 689 | pc_factory_for_test_ = |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 690 | PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 691 | } |
| 692 | |
Tomas Gunnarsson | 2efb8a5 | 2021-04-01 16:26:57 +0200 | [diff] [blame] | 693 | void TearDown() override { |
| 694 | if (pc_) |
| 695 | pc_->Close(); |
| 696 | } |
| 697 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 698 | void CreatePeerConnection() { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 699 | CreatePeerConnection(PeerConnectionInterface::RTCConfiguration()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Harald Alvestrand | f9e502d | 2021-10-13 15:26:26 +0000 | [diff] [blame] | 702 | // DTLS does not work in a loopback call, so is disabled for many |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 703 | // tests in this file. |
| 704 | void CreatePeerConnectionWithoutDtls() { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 705 | RTCConfiguration config; |
Harald Alvestrand | f9e502d | 2021-10-13 15:26:26 +0000 | [diff] [blame] | 706 | PeerConnectionFactoryInterface::Options options; |
| 707 | options.disable_encryption = true; |
| 708 | pc_factory_->SetOptions(options); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 709 | CreatePeerConnection(config); |
Harald Alvestrand | f9e502d | 2021-10-13 15:26:26 +0000 | [diff] [blame] | 710 | options.disable_encryption = false; |
| 711 | pc_factory_->SetOptions(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 714 | void CreatePeerConnectionWithIceTransportsType( |
| 715 | PeerConnectionInterface::IceTransportsType type) { |
| 716 | PeerConnectionInterface::RTCConfiguration config; |
| 717 | config.type = type; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 718 | return CreatePeerConnection(config); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | void CreatePeerConnectionWithIceServer(const std::string& uri, |
Niels Möller | db4def9 | 2019-03-18 16:53:59 +0100 | [diff] [blame] | 722 | const std::string& username, |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 723 | const std::string& password) { |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 724 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 725 | PeerConnectionInterface::IceServer server; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 726 | server.uri = uri; |
Niels Möller | db4def9 | 2019-03-18 16:53:59 +0100 | [diff] [blame] | 727 | server.username = username; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 728 | server.password = password; |
| 729 | config.servers.push_back(server); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 730 | CreatePeerConnection(config); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 731 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 732 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 733 | void CreatePeerConnection(const RTCConfiguration& config) { |
Tomas Gunnarsson | 2efb8a5 | 2021-04-01 16:26:57 +0200 | [diff] [blame] | 734 | if (pc_) { |
| 735 | pc_->Close(); |
| 736 | pc_ = nullptr; |
| 737 | } |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 738 | std::unique_ptr<cricket::FakePortAllocator> port_allocator( |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 739 | new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
| 740 | port_allocator_ = port_allocator.get(); |
jiayl@webrtc.org | a576faf | 2014-01-29 17:45:53 +0000 | [diff] [blame] | 741 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 742 | // Create certificate generator unless DTLS constraint is explicitly set to |
| 743 | // false. |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 744 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 745 | |
Harald Alvestrand | f9e502d | 2021-10-13 15:26:26 +0000 | [diff] [blame] | 746 | // These won't be used if encryption is turned off, but that's harmless. |
| 747 | fake_certificate_generator_ = new FakeRTCCertificateGenerator(); |
| 748 | cert_generator.reset(fake_certificate_generator_); |
| 749 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 750 | RTCConfiguration modified_config = config; |
| 751 | modified_config.sdp_semantics = sdp_semantics_; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 752 | PeerConnectionDependencies pc_dependencies(&observer_); |
| 753 | pc_dependencies.cert_generator = std::move(cert_generator); |
| 754 | pc_dependencies.allocator = std::move(port_allocator); |
| 755 | auto result = pc_factory_->CreatePeerConnectionOrError( |
| 756 | modified_config, std::move(pc_dependencies)); |
| 757 | ASSERT_TRUE(result.ok()); |
| 758 | pc_ = result.MoveValue(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 759 | observer_.SetPeerConnectionInterface(pc_.get()); |
| 760 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 761 | } |
| 762 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 763 | void CreatePeerConnectionExpectFail(const std::string& uri) { |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 764 | PeerConnectionInterface::RTCConfiguration config; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 765 | PeerConnectionInterface::IceServer server; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 766 | server.uri = uri; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 767 | config.servers.push_back(server); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 768 | config.sdp_semantics = sdp_semantics_; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 769 | PeerConnectionDependencies pc_dependencies(&observer_); |
| 770 | auto result = pc_factory_->CreatePeerConnectionOrError( |
| 771 | config, std::move(pc_dependencies)); |
| 772 | EXPECT_FALSE(result.ok()); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Steve Anton | 038834f | 2017-07-14 15:59:59 -0700 | [diff] [blame] | 775 | void CreatePeerConnectionExpectFail( |
| 776 | PeerConnectionInterface::RTCConfiguration config) { |
| 777 | PeerConnectionInterface::IceServer server; |
| 778 | server.uri = kTurnIceServerUri; |
| 779 | server.password = kTurnPassword; |
| 780 | config.servers.push_back(server); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 781 | config.sdp_semantics = sdp_semantics_; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 782 | PeerConnectionDependencies pc_dependencies(&observer_); |
| 783 | auto result = pc_factory_->CreatePeerConnectionOrError( |
| 784 | config, std::move(pc_dependencies)); |
| 785 | EXPECT_FALSE(result.ok()); |
Steve Anton | 038834f | 2017-07-14 15:59:59 -0700 | [diff] [blame] | 786 | } |
| 787 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 788 | void CreatePeerConnectionWithDifferentConfigurations() { |
Niels Möller | db4def9 | 2019-03-18 16:53:59 +0100 | [diff] [blame] | 789 | CreatePeerConnectionWithIceServer(kStunAddressOnly, "", ""); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 790 | EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
| 791 | EXPECT_EQ(0u, port_allocator_->turn_servers().size()); |
| 792 | EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 793 | EXPECT_EQ(kDefaultStunPort, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 794 | port_allocator_->stun_servers().begin()->port()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 795 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 796 | CreatePeerConnectionExpectFail(kStunInvalidPort); |
| 797 | CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); |
| 798 | CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 799 | |
Niels Möller | db4def9 | 2019-03-18 16:53:59 +0100 | [diff] [blame] | 800 | CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername, |
| 801 | kTurnPassword); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 802 | EXPECT_EQ(0u, port_allocator_->stun_servers().size()); |
| 803 | EXPECT_EQ(1u, port_allocator_->turn_servers().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 804 | EXPECT_EQ(kTurnUsername, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 805 | port_allocator_->turn_servers()[0].credentials.username); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 806 | EXPECT_EQ(kTurnPassword, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 807 | port_allocator_->turn_servers()[0].credentials.password); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 808 | EXPECT_EQ(kTurnHostname, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 809 | port_allocator_->turn_servers()[0].ports[0].address.hostname()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | void ReleasePeerConnection() { |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 813 | pc_ = nullptr; |
| 814 | observer_.SetPeerConnectionInterface(nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 817 | rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( |
| 818 | const std::string& label) { |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 819 | return pc_factory_->CreateVideoTrack(label, |
| 820 | FakeVideoTrackSource::Create().get()); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | void AddVideoTrack(const std::string& track_label, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 824 | const std::vector<std::string>& stream_ids = {}) { |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 825 | auto sender_or_error = |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 826 | pc_->AddTrack(CreateVideoTrack(track_label), stream_ids); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 827 | ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 830 | void AddVideoStream(const std::string& label) { |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 831 | rtc::scoped_refptr<MediaStreamInterface> stream( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 832 | pc_factory_->CreateLocalMediaStream(label)); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 833 | stream->AddTrack(CreateVideoTrack(label + "v0").get()); |
| 834 | ASSERT_TRUE(pc_->AddStream(stream.get())); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack( |
| 838 | const std::string& label) { |
| 839 | return pc_factory_->CreateAudioTrack(label, nullptr); |
| 840 | } |
| 841 | |
| 842 | void AddAudioTrack(const std::string& track_label, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 843 | const std::vector<std::string>& stream_ids = {}) { |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 844 | auto sender_or_error = |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 845 | pc_->AddTrack(CreateAudioTrack(track_label), stream_ids); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 846 | ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type()); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | void AddAudioStream(const std::string& label) { |
| 850 | rtc::scoped_refptr<MediaStreamInterface> stream( |
| 851 | pc_factory_->CreateLocalMediaStream(label)); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 852 | stream->AddTrack(CreateAudioTrack(label + "a0").get()); |
| 853 | ASSERT_TRUE(pc_->AddStream(stream.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 856 | void AddAudioVideoStream(const std::string& stream_id, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 857 | const std::string& audio_track_label, |
| 858 | const std::string& video_track_label) { |
| 859 | // Create a local stream. |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 860 | rtc::scoped_refptr<MediaStreamInterface> stream( |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 861 | pc_factory_->CreateLocalMediaStream(stream_id)); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 862 | stream->AddTrack(CreateAudioTrack(audio_track_label).get()); |
| 863 | stream->AddTrack(CreateVideoTrack(video_track_label).get()); |
| 864 | ASSERT_TRUE(pc_->AddStream(stream.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 865 | } |
| 866 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 867 | rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType( |
| 868 | cricket::MediaType media_type) { |
| 869 | for (auto receiver : pc_->GetReceivers()) { |
| 870 | if (receiver->media_type() == media_type) { |
| 871 | return receiver; |
| 872 | } |
| 873 | } |
| 874 | return nullptr; |
| 875 | } |
| 876 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 877 | bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 878 | const RTCOfferAnswerOptions* options, |
| 879 | bool offer) { |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 880 | auto observer = |
| 881 | rtc::make_ref_counted<MockCreateSessionDescriptionObserver>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 882 | if (offer) { |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 883 | pc_->CreateOffer(observer.get(), |
| 884 | options ? *options : RTCOfferAnswerOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 885 | } else { |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 886 | pc_->CreateAnswer(observer.get(), |
| 887 | options ? *options : RTCOfferAnswerOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 888 | } |
| 889 | EXPECT_EQ_WAIT(true, observer->called(), kTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 890 | *desc = observer->MoveDescription(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 891 | return observer->result(); |
| 892 | } |
| 893 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 894 | bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc, |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 895 | const RTCOfferAnswerOptions* options) { |
| 896 | return DoCreateOfferAnswer(desc, options, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 897 | } |
| 898 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 899 | bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 900 | const RTCOfferAnswerOptions* options) { |
| 901 | return DoCreateOfferAnswer(desc, options, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 904 | bool DoSetSessionDescription( |
| 905 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 906 | bool local) { |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 907 | auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 908 | if (local) { |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 909 | pc_->SetLocalDescription(observer.get(), desc.release()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 910 | } else { |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 911 | pc_->SetRemoteDescription(observer.get(), desc.release()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 912 | } |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 913 | if (pc_->signaling_state() != PeerConnectionInterface::kClosed) { |
| 914 | EXPECT_EQ_WAIT(true, observer->called(), kTimeout); |
| 915 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 916 | return observer->result(); |
| 917 | } |
| 918 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 919 | bool DoSetLocalDescription( |
| 920 | std::unique_ptr<SessionDescriptionInterface> desc) { |
| 921 | return DoSetSessionDescription(std::move(desc), true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 924 | bool DoSetRemoteDescription( |
| 925 | std::unique_ptr<SessionDescriptionInterface> desc) { |
| 926 | return DoSetSessionDescription(std::move(desc), false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | // Calls PeerConnection::GetStats and check the return value. |
| 930 | // It does not verify the values in the StatReports since a RTCP packet might |
| 931 | // be required. |
| 932 | bool DoGetStats(MediaStreamTrackInterface* track) { |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 933 | auto observer = rtc::make_ref_counted<MockStatsObserver>(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 934 | if (!pc_->GetStats(observer.get(), track, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 935 | PeerConnectionInterface::kStatsOutputLevelStandard)) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 936 | return false; |
| 937 | EXPECT_TRUE_WAIT(observer->called(), kTimeout); |
| 938 | return observer->called(); |
| 939 | } |
| 940 | |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 941 | // Call the standards-compliant GetStats function. |
| 942 | bool DoGetRTCStats() { |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 943 | auto callback = |
| 944 | rtc::make_ref_counted<webrtc::MockRTCStatsCollectorCallback>(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 945 | pc_->GetStats(callback.get()); |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 946 | EXPECT_TRUE_WAIT(callback->called(), kTimeout); |
| 947 | return callback->called(); |
| 948 | } |
| 949 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 950 | void InitiateCall() { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 951 | CreatePeerConnectionWithoutDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 952 | // Create a local stream with audio&video tracks. |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 953 | if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) { |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 954 | AddAudioVideoStream(kStreamId1, "audio_track", "video_track"); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 955 | } else { |
| 956 | // Unified Plan does not support AddStream, so just add an audio and video |
| 957 | // track. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 958 | AddAudioTrack(kAudioTracks[0], {kStreamId1}); |
| 959 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 960 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 961 | CreateOfferReceiveAnswer(); |
| 962 | } |
| 963 | |
| 964 | // Verify that RTP Header extensions has been negotiated for audio and video. |
| 965 | void VerifyRemoteRtpHeaderExtensions() { |
| 966 | const cricket::MediaContentDescription* desc = |
| 967 | cricket::GetFirstAudioContentDescription( |
| 968 | pc_->remote_description()->description()); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 969 | ASSERT_TRUE(desc != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 970 | EXPECT_GT(desc->rtp_header_extensions().size(), 0u); |
| 971 | |
| 972 | desc = cricket::GetFirstVideoContentDescription( |
| 973 | pc_->remote_description()->description()); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 974 | ASSERT_TRUE(desc != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 975 | EXPECT_GT(desc->rtp_header_extensions().size(), 0u); |
| 976 | } |
| 977 | |
| 978 | void CreateOfferAsRemoteDescription() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 979 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 980 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 981 | std::string sdp; |
| 982 | EXPECT_TRUE(offer->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 983 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 984 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 985 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 986 | EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); |
| 987 | } |
| 988 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 989 | void CreateAndSetRemoteOffer(const std::string& sdp) { |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 990 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 991 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 992 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 993 | EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); |
| 994 | } |
| 995 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 996 | void CreateAnswerAsLocalDescription() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 997 | std::unique_ptr<SessionDescriptionInterface> answer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 998 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 999 | |
| 1000 | // TODO(perkj): Currently SetLocalDescription fails if any parameters in an |
| 1001 | // audio codec change, even if the parameter has nothing to do with |
| 1002 | // receiving. Not all parameters are serialized to SDP. |
| 1003 | // Since CreatePrAnswerAsLocalDescription serialize/deserialize |
| 1004 | // the SessionDescription, it is necessary to do that here to in order to |
| 1005 | // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. |
| 1006 | // https://code.google.com/p/webrtc/issues/detail?id=1356 |
| 1007 | std::string sdp; |
| 1008 | EXPECT_TRUE(answer->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1009 | std::unique_ptr<SessionDescriptionInterface> new_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1010 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1011 | EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1012 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 1013 | } |
| 1014 | |
| 1015 | void CreatePrAnswerAsLocalDescription() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1016 | std::unique_ptr<SessionDescriptionInterface> answer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1017 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1018 | |
| 1019 | std::string sdp; |
| 1020 | EXPECT_TRUE(answer->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1021 | std::unique_ptr<SessionDescriptionInterface> pr_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1022 | webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1023 | EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1024 | EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_); |
| 1025 | } |
| 1026 | |
| 1027 | void CreateOfferReceiveAnswer() { |
| 1028 | CreateOfferAsLocalDescription(); |
| 1029 | std::string sdp; |
| 1030 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
| 1031 | CreateAnswerAsRemoteDescription(sdp); |
| 1032 | } |
| 1033 | |
| 1034 | void CreateOfferAsLocalDescription() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1035 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1036 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1037 | // TODO(perkj): Currently SetLocalDescription fails if any parameters in an |
| 1038 | // audio codec change, even if the parameter has nothing to do with |
| 1039 | // receiving. Not all parameters are serialized to SDP. |
| 1040 | // Since CreatePrAnswerAsLocalDescription serialize/deserialize |
| 1041 | // the SessionDescription, it is necessary to do that here to in order to |
| 1042 | // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. |
| 1043 | // https://code.google.com/p/webrtc/issues/detail?id=1356 |
| 1044 | std::string sdp; |
| 1045 | EXPECT_TRUE(offer->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1046 | std::unique_ptr<SessionDescriptionInterface> new_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1047 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1048 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1049 | EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1050 | EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_); |
mallinath@webrtc.org | 68cbd01 | 2014-01-22 00:16:46 +0000 | [diff] [blame] | 1051 | // Wait for the ice_complete message, so that SDP will have candidates. |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 1052 | EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1055 | void CreateAnswerAsRemoteDescription(const std::string& sdp) { |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1056 | std::unique_ptr<SessionDescriptionInterface> answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1057 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1058 | ASSERT_TRUE(answer); |
| 1059 | EXPECT_TRUE(DoSetRemoteDescription(std::move(answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1060 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 1061 | } |
| 1062 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1063 | void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) { |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1064 | std::unique_ptr<SessionDescriptionInterface> pr_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1065 | webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1066 | ASSERT_TRUE(pr_answer); |
| 1067 | EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1068 | EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1069 | std::unique_ptr<SessionDescriptionInterface> answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1070 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1071 | ASSERT_TRUE(answer); |
| 1072 | EXPECT_TRUE(DoSetRemoteDescription(std::move(answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1073 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 1074 | } |
| 1075 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1076 | // Waits until a remote stream with the given id is signaled. This helper |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1077 | // function will verify both OnAddTrack and OnAddStream (Plan B only) are |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1078 | // called with the given stream id and expected number of tracks. |
| 1079 | void WaitAndVerifyOnAddStream(const std::string& stream_id, |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1080 | int expected_num_tracks) { |
| 1081 | // Verify that both OnAddStream and OnAddTrack are called. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1082 | EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1083 | EXPECT_EQ_WAIT(expected_num_tracks, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1084 | observer_.CountAddTrackEventsForStream(stream_id), kTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | // Creates an offer and applies it as a local session description. |
| 1088 | // Creates an answer with the same SDP an the offer but removes all lines |
| 1089 | // that start with a:ssrc" |
| 1090 | void CreateOfferReceiveAnswerWithoutSsrc() { |
| 1091 | CreateOfferAsLocalDescription(); |
| 1092 | std::string sdp; |
| 1093 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
| 1094 | SetSsrcToZero(&sdp); |
| 1095 | CreateAnswerAsRemoteDescription(sdp); |
| 1096 | } |
| 1097 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1098 | // This function creates a MediaStream with label kStreams[0] and |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 1099 | // `number_of_audio_tracks` and `number_of_video_tracks` tracks and the |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1100 | // corresponding SessionDescriptionInterface. The SessionDescriptionInterface |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1101 | // is returned and the MediaStream is stored in |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 1102 | // `reference_collection_` |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1103 | std::unique_ptr<SessionDescriptionInterface> |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1104 | CreateSessionDescriptionAndReference(size_t number_of_audio_tracks, |
| 1105 | size_t number_of_video_tracks) { |
| 1106 | EXPECT_LE(number_of_audio_tracks, 2u); |
| 1107 | EXPECT_LE(number_of_video_tracks, 2u); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1108 | |
| 1109 | reference_collection_ = StreamCollection::Create(); |
| 1110 | std::string sdp_ms1 = std::string(kSdpStringInit); |
| 1111 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1112 | std::string mediastream_id = kStreams[0]; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1113 | |
| 1114 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1115 | webrtc::MediaStream::Create(mediastream_id)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1116 | reference_collection_->AddStream(stream); |
| 1117 | |
| 1118 | if (number_of_audio_tracks > 0) { |
| 1119 | sdp_ms1 += std::string(kSdpStringAudio); |
| 1120 | sdp_ms1 += std::string(kSdpStringMs1Audio0); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1121 | AddAudioTrack(kAudioTracks[0], stream.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1122 | } |
| 1123 | if (number_of_audio_tracks > 1) { |
| 1124 | sdp_ms1 += kSdpStringMs1Audio1; |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1125 | AddAudioTrack(kAudioTracks[1], stream.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | if (number_of_video_tracks > 0) { |
| 1129 | sdp_ms1 += std::string(kSdpStringVideo); |
| 1130 | sdp_ms1 += std::string(kSdpStringMs1Video0); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1131 | AddVideoTrack(kVideoTracks[0], stream.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1132 | } |
| 1133 | if (number_of_video_tracks > 1) { |
| 1134 | sdp_ms1 += kSdpStringMs1Video1; |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1135 | AddVideoTrack(kVideoTracks[1], stream.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1138 | return std::unique_ptr<SessionDescriptionInterface>( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1139 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | void AddAudioTrack(const std::string& track_id, |
| 1143 | MediaStreamInterface* stream) { |
| 1144 | rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 1145 | webrtc::AudioTrack::Create(track_id, nullptr)); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1146 | ASSERT_TRUE(stream->AddTrack(audio_track.get())); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | void AddVideoTrack(const std::string& track_id, |
| 1150 | MediaStreamInterface* stream) { |
| 1151 | rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
nisse | af510af | 2016-03-21 08:20:42 -0700 | [diff] [blame] | 1152 | webrtc::VideoTrack::Create(track_id, |
perkj | 773be36 | 2017-07-31 23:22:01 -0700 | [diff] [blame] | 1153 | webrtc::FakeVideoTrackSource::Create(), |
| 1154 | rtc::Thread::Current())); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1155 | ASSERT_TRUE(stream->AddTrack(video_track.get())); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1158 | std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1159 | CreatePeerConnectionWithoutDtls(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1160 | AddAudioTrack(kAudioTracks[0]); |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1161 | std::unique_ptr<SessionDescriptionInterface> offer; |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1162 | EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 1163 | return offer; |
| 1164 | } |
| 1165 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1166 | std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() { |
| 1167 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1168 | AddAudioStream(kStreamId1); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1169 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 1170 | EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 1171 | return offer; |
| 1172 | } |
| 1173 | |
| 1174 | std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() { |
| 1175 | EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack())); |
| 1176 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 1177 | EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); |
| 1178 | return answer; |
| 1179 | } |
| 1180 | |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1181 | std::unique_ptr<SessionDescriptionInterface> |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1182 | CreateAnswerWithOneAudioStream() { |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1183 | EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream())); |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1184 | std::unique_ptr<SessionDescriptionInterface> answer; |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1185 | EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); |
| 1186 | return answer; |
| 1187 | } |
| 1188 | |
| 1189 | const std::string& GetFirstAudioStreamCname( |
| 1190 | const SessionDescriptionInterface* desc) { |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1191 | const cricket::AudioContentDescription* audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1192 | cricket::GetFirstAudioContentDescription(desc->description()); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1193 | return audio_desc->streams()[0].cname; |
| 1194 | } |
| 1195 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1196 | std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions( |
| 1197 | const RTCOfferAnswerOptions& offer_answer_options) { |
| 1198 | RTC_DCHECK(pc_); |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 1199 | auto observer = |
| 1200 | rtc::make_ref_counted<MockCreateSessionDescriptionObserver>(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1201 | pc_->CreateOffer(observer.get(), offer_answer_options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1202 | EXPECT_EQ_WAIT(true, observer->called(), kTimeout); |
| 1203 | return observer->MoveDescription(); |
| 1204 | } |
| 1205 | |
| 1206 | void CreateOfferWithOptionsAsRemoteDescription( |
| 1207 | std::unique_ptr<SessionDescriptionInterface>* desc, |
| 1208 | const RTCOfferAnswerOptions& offer_answer_options) { |
| 1209 | *desc = CreateOfferWithOptions(offer_answer_options); |
| 1210 | ASSERT_TRUE(desc != nullptr); |
| 1211 | std::string sdp; |
| 1212 | EXPECT_TRUE((*desc)->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1213 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1214 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1215 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1216 | EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); |
| 1217 | } |
| 1218 | |
| 1219 | void CreateOfferWithOptionsAsLocalDescription( |
| 1220 | std::unique_ptr<SessionDescriptionInterface>* desc, |
| 1221 | const RTCOfferAnswerOptions& offer_answer_options) { |
| 1222 | *desc = CreateOfferWithOptions(offer_answer_options); |
| 1223 | ASSERT_TRUE(desc != nullptr); |
| 1224 | std::string sdp; |
| 1225 | EXPECT_TRUE((*desc)->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1226 | std::unique_ptr<SessionDescriptionInterface> new_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1227 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1228 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1229 | EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer))); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1230 | EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_); |
| 1231 | } |
| 1232 | |
| 1233 | bool HasCNCodecs(const cricket::ContentInfo* content) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1234 | RTC_DCHECK(content); |
| 1235 | RTC_DCHECK(content->media_description()); |
| 1236 | for (const cricket::AudioCodec& codec : |
| 1237 | content->media_description()->as_audio()->codecs()) { |
| 1238 | if (codec.name == "CN") { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1239 | return true; |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1240 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1241 | } |
| 1242 | return false; |
| 1243 | } |
| 1244 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1245 | const char* GetSdpStringWithStream1() const { |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 1246 | if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) { |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1247 | return kSdpStringWithStream1PlanB; |
| 1248 | } else { |
| 1249 | return kSdpStringWithStream1UnifiedPlan; |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | const char* GetSdpStringWithStream1And2() const { |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 1254 | if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) { |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1255 | return kSdpStringWithStream1And2PlanB; |
| 1256 | } else { |
| 1257 | return kSdpStringWithStream1And2UnifiedPlan; |
| 1258 | } |
| 1259 | } |
| 1260 | |
deadbeef | 9a6f4d4 | 2017-05-15 19:43:33 -0700 | [diff] [blame] | 1261 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 1262 | rtc::AutoSocketServerThread main_; |
deadbeef | d7850b2 | 2017-08-23 10:59:19 -0700 | [diff] [blame] | 1263 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 1264 | cricket::FakePortAllocator* port_allocator_ = nullptr; |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 1265 | FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1266 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; |
| 1267 | rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_; |
| 1268 | rtc::scoped_refptr<PeerConnectionInterface> pc_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1269 | MockPeerConnectionObserver observer_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1270 | rtc::scoped_refptr<StreamCollection> reference_collection_; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1271 | const SdpSemantics sdp_semantics_; |
| 1272 | }; |
| 1273 | |
| 1274 | class PeerConnectionInterfaceTest |
| 1275 | : public PeerConnectionInterfaceBaseTest, |
| 1276 | public ::testing::WithParamInterface<SdpSemantics> { |
| 1277 | protected: |
| 1278 | PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {} |
| 1279 | }; |
| 1280 | |
| 1281 | class PeerConnectionInterfaceTestPlanB |
| 1282 | : public PeerConnectionInterfaceBaseTest { |
| 1283 | protected: |
| 1284 | PeerConnectionInterfaceTestPlanB() |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 1285 | : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB_DEPRECATED) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1286 | }; |
| 1287 | |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1288 | // Generate different CNAMEs when PeerConnections are created. |
| 1289 | // The CNAMEs are expected to be generated randomly. It is possible |
| 1290 | // that the test fails, though the possibility is very low. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1291 | TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) { |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1292 | std::unique_ptr<SessionDescriptionInterface> offer1 = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1293 | CreateOfferWithOneAudioTrack(); |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1294 | std::unique_ptr<SessionDescriptionInterface> offer2 = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1295 | CreateOfferWithOneAudioTrack(); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1296 | EXPECT_NE(GetFirstAudioStreamCname(offer1.get()), |
| 1297 | GetFirstAudioStreamCname(offer2.get())); |
| 1298 | } |
| 1299 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1300 | TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) { |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1301 | std::unique_ptr<SessionDescriptionInterface> answer1 = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1302 | CreateAnswerWithOneAudioTrack(); |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1303 | std::unique_ptr<SessionDescriptionInterface> answer2 = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1304 | CreateAnswerWithOneAudioTrack(); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1305 | EXPECT_NE(GetFirstAudioStreamCname(answer1.get()), |
| 1306 | GetFirstAudioStreamCname(answer2.get())); |
| 1307 | } |
| 1308 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1309 | TEST_P(PeerConnectionInterfaceTest, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1310 | CreatePeerConnectionWithDifferentConfigurations) { |
| 1311 | CreatePeerConnectionWithDifferentConfigurations(); |
| 1312 | } |
| 1313 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1314 | TEST_P(PeerConnectionInterfaceTest, |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1315 | CreatePeerConnectionWithDifferentIceTransportsTypes) { |
| 1316 | CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone); |
| 1317 | EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter()); |
| 1318 | CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay); |
| 1319 | EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); |
| 1320 | CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost); |
| 1321 | EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST, |
| 1322 | port_allocator_->candidate_filter()); |
| 1323 | CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll); |
| 1324 | EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter()); |
| 1325 | } |
| 1326 | |
| 1327 | // Test that when a PeerConnection is created with a nonzero candidate pool |
| 1328 | // size, the pooled PortAllocatorSession is created with all the attributes |
| 1329 | // in the RTCConfiguration. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1330 | TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) { |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1331 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 1332 | config.sdp_semantics = sdp_semantics_; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1333 | PeerConnectionInterface::IceServer server; |
| 1334 | server.uri = kStunAddressOnly; |
| 1335 | config.servers.push_back(server); |
| 1336 | config.type = PeerConnectionInterface::kRelay; |
| 1337 | config.disable_ipv6 = true; |
| 1338 | config.tcp_candidate_policy = |
| 1339 | PeerConnectionInterface::kTcpCandidatePolicyDisabled; |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 1340 | config.candidate_network_policy = |
| 1341 | PeerConnectionInterface::kCandidateNetworkPolicyLowCost; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1342 | config.ice_candidate_pool_size = 1; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1343 | CreatePeerConnection(config); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1344 | |
| 1345 | const cricket::FakePortAllocatorSession* session = |
| 1346 | static_cast<const cricket::FakePortAllocatorSession*>( |
| 1347 | port_allocator_->GetPooledSession()); |
| 1348 | ASSERT_NE(nullptr, session); |
| 1349 | EXPECT_EQ(1UL, session->stun_servers().size()); |
| 1350 | EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 1351 | EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP); |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 1352 | EXPECT_LT(0U, |
| 1353 | session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
deadbeef | d21eab3 | 2017-07-26 16:50:11 -0700 | [diff] [blame] | 1356 | // Test that network-related RTCConfiguration members are applied to the |
| 1357 | // PortAllocator when CreatePeerConnection is called. Specifically: |
| 1358 | // - disable_ipv6_on_wifi |
| 1359 | // - max_ipv6_networks |
| 1360 | // - tcp_candidate_policy |
| 1361 | // - candidate_network_policy |
| 1362 | // - prune_turn_ports |
| 1363 | // |
| 1364 | // Note that the candidate filter (RTCConfiguration::type) is already tested |
| 1365 | // above. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1366 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | d21eab3 | 2017-07-26 16:50:11 -0700 | [diff] [blame] | 1367 | CreatePeerConnectionAppliesNetworkConfigToPortAllocator) { |
| 1368 | // Create fake port allocator. |
| 1369 | std::unique_ptr<cricket::FakePortAllocator> port_allocator( |
| 1370 | new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
| 1371 | cricket::FakePortAllocator* raw_port_allocator = port_allocator.get(); |
| 1372 | |
| 1373 | // Create RTCConfiguration with some network-related fields relevant to |
| 1374 | // PortAllocator populated. |
| 1375 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 1376 | config.sdp_semantics = sdp_semantics_; |
deadbeef | d21eab3 | 2017-07-26 16:50:11 -0700 | [diff] [blame] | 1377 | config.disable_ipv6_on_wifi = true; |
| 1378 | config.max_ipv6_networks = 10; |
| 1379 | config.tcp_candidate_policy = |
| 1380 | PeerConnectionInterface::kTcpCandidatePolicyDisabled; |
| 1381 | config.candidate_network_policy = |
| 1382 | PeerConnectionInterface::kCandidateNetworkPolicyLowCost; |
| 1383 | config.prune_turn_ports = true; |
| 1384 | |
| 1385 | // Create the PC factory and PC with the above config. |
| 1386 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory( |
| 1387 | webrtc::CreatePeerConnectionFactory( |
| 1388 | rtc::Thread::Current(), rtc::Thread::Current(), |
Karl Wiberg | 1b0eae3 | 2017-10-17 14:48:54 +0200 | [diff] [blame] | 1389 | rtc::Thread::Current(), fake_audio_capture_module_, |
| 1390 | webrtc::CreateBuiltinAudioEncoderFactory(), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 1391 | webrtc::CreateBuiltinAudioDecoderFactory(), |
| 1392 | webrtc::CreateBuiltinVideoEncoderFactory(), |
| 1393 | webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */, |
| 1394 | nullptr /* audio_processing */)); |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1395 | PeerConnectionDependencies pc_dependencies(&observer_); |
| 1396 | pc_dependencies.allocator = std::move(port_allocator); |
| 1397 | auto result = pc_factory_->CreatePeerConnectionOrError( |
| 1398 | config, std::move(pc_dependencies)); |
| 1399 | EXPECT_TRUE(result.ok()); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1400 | observer_.SetPeerConnectionInterface(result.value().get()); |
deadbeef | d21eab3 | 2017-07-26 16:50:11 -0700 | [diff] [blame] | 1401 | |
| 1402 | // Now validate that the config fields set above were applied to the |
| 1403 | // PortAllocator, as flags or otherwise. |
| 1404 | EXPECT_FALSE(raw_port_allocator->flags() & |
| 1405 | cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI); |
| 1406 | EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks()); |
| 1407 | EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP); |
| 1408 | EXPECT_TRUE(raw_port_allocator->flags() & |
| 1409 | cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 1410 | EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY, |
| 1411 | raw_port_allocator->turn_port_prune_policy()); |
deadbeef | d21eab3 | 2017-07-26 16:50:11 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1414 | // Check that GetConfiguration returns the configuration the PeerConnection was |
| 1415 | // constructed with, before SetConfiguration is called. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1416 | TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) { |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1417 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 1418 | config.sdp_semantics = sdp_semantics_; |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1419 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1420 | CreatePeerConnection(config); |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1421 | |
| 1422 | PeerConnectionInterface::RTCConfiguration returned_config = |
| 1423 | pc_->GetConfiguration(); |
| 1424 | EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type); |
| 1425 | } |
| 1426 | |
| 1427 | // Check that GetConfiguration returns the last configuration passed into |
| 1428 | // SetConfiguration. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1429 | TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) { |
Piotr (Peter) Slatala | 37227be | 2018-11-21 07:42:22 -0800 | [diff] [blame] | 1430 | PeerConnectionInterface::RTCConfiguration starting_config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 1431 | starting_config.sdp_semantics = sdp_semantics_; |
Piotr (Peter) Slatala | 37227be | 2018-11-21 07:42:22 -0800 | [diff] [blame] | 1432 | starting_config.bundle_policy = |
| 1433 | webrtc::PeerConnection::kBundlePolicyMaxBundle; |
| 1434 | CreatePeerConnection(starting_config); |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1435 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1436 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1437 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 1438 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1439 | |
| 1440 | PeerConnectionInterface::RTCConfiguration returned_config = |
| 1441 | pc_->GetConfiguration(); |
| 1442 | EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type); |
| 1443 | } |
| 1444 | |
Steve Anton | c79268f | 2018-04-24 09:54:10 -0700 | [diff] [blame] | 1445 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) { |
| 1446 | CreatePeerConnection(); |
| 1447 | |
| 1448 | pc_->Close(); |
| 1449 | |
| 1450 | EXPECT_FALSE( |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 1451 | pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()).ok()); |
Steve Anton | c79268f | 2018-04-24 09:54:10 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1454 | TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1455 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1456 | AddVideoStream(kStreamId1); |
| 1457 | AddAudioStream(kStreamId2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1458 | ASSERT_EQ(2u, pc_->local_streams()->count()); |
| 1459 | |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 1460 | // Test we can add multiple local streams to one peerconnection. |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1461 | rtc::scoped_refptr<MediaStreamInterface> stream( |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1462 | pc_factory_->CreateLocalMediaStream(kStreamId3)); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1463 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1464 | pc_factory_->CreateAudioTrack( |
| 1465 | kStreamId3, static_cast<AudioSourceInterface*>(nullptr))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1466 | stream->AddTrack(audio_track.get()); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1467 | EXPECT_TRUE(pc_->AddStream(stream.get())); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 1468 | EXPECT_EQ(3u, pc_->local_streams()->count()); |
| 1469 | |
| 1470 | // Remove the third stream. |
| 1471 | pc_->RemoveStream(pc_->local_streams()->at(2)); |
| 1472 | EXPECT_EQ(2u, pc_->local_streams()->count()); |
| 1473 | |
| 1474 | // Remove the second stream. |
| 1475 | pc_->RemoveStream(pc_->local_streams()->at(1)); |
| 1476 | EXPECT_EQ(1u, pc_->local_streams()->count()); |
| 1477 | |
| 1478 | // Remove the first stream. |
| 1479 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 1480 | EXPECT_EQ(0u, pc_->local_streams()->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1483 | // Test that the created offer includes streams we added. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1484 | // Don't run under Unified Plan since the stream API is not available. |
| 1485 | TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1486 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1487 | AddAudioVideoStream(kStreamId1, "audio_track", "video_track"); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1488 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1489 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1490 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1491 | const cricket::AudioContentDescription* audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1492 | cricket::GetFirstAudioContentDescription(offer->description()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1493 | EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track")); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1494 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1495 | const cricket::VideoContentDescription* video_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1496 | cricket::GetFirstVideoContentDescription(offer->description()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1497 | EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track")); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1498 | |
| 1499 | // Add another stream and ensure the offer includes both the old and new |
| 1500 | // streams. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1501 | AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2"); |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1502 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1503 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1504 | audio_desc = cricket::GetFirstAudioContentDescription(offer->description()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1505 | EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track")); |
| 1506 | EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2")); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1507 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1508 | video_desc = cricket::GetFirstVideoContentDescription(offer->description()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1509 | EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track")); |
| 1510 | EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2")); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1513 | // Don't run under Unified Plan since the stream API is not available. |
| 1514 | TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1515 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1516 | AddVideoStream(kStreamId1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1517 | ASSERT_EQ(1u, pc_->local_streams()->count()); |
| 1518 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 1519 | EXPECT_EQ(0u, pc_->local_streams()->count()); |
| 1520 | } |
| 1521 | |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1522 | // Test for AddTrack and RemoveTrack methods. |
| 1523 | // Tests that the created offer includes tracks we added, |
| 1524 | // and that the RtpSenders are created correctly. |
| 1525 | // Also tests that RemoveTrack removes the tracks from subsequent offers. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1526 | // Only tested with Plan B since Unified Plan is covered in more detail by tests |
| 1527 | // in peerconnection_jsep_unittests.cc |
| 1528 | TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1529 | CreatePeerConnectionWithoutDtls(); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1530 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1531 | CreateAudioTrack("audio_track")); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1532 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1533 | CreateVideoTrack("video_track")); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1534 | auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue(); |
| 1535 | auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue(); |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1536 | EXPECT_EQ(1UL, audio_sender->stream_ids().size()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1537 | EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1538 | EXPECT_EQ("audio_track", audio_sender->id()); |
| 1539 | EXPECT_EQ(audio_track, audio_sender->track()); |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1540 | EXPECT_EQ(1UL, video_sender->stream_ids().size()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1541 | EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1542 | EXPECT_EQ("video_track", video_sender->id()); |
| 1543 | EXPECT_EQ(video_track, video_sender->track()); |
| 1544 | |
| 1545 | // Now create an offer and check for the senders. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1546 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1547 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1548 | |
| 1549 | const cricket::ContentInfo* audio_content = |
| 1550 | cricket::GetFirstAudioContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1551 | EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(), |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1552 | kStreamId1, "audio_track")); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1553 | |
| 1554 | const cricket::ContentInfo* video_content = |
| 1555 | cricket::GetFirstVideoContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1556 | EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(), |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1557 | kStreamId1, "video_track")); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1558 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1559 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1560 | |
| 1561 | // Now try removing the tracks. |
Harald Alvestrand | 93dd763 | 2022-01-19 12:28:45 +0000 | [diff] [blame] | 1562 | EXPECT_TRUE(pc_->RemoveTrackOrError(audio_sender).ok()); |
| 1563 | EXPECT_TRUE(pc_->RemoveTrackOrError(video_sender).ok()); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1564 | |
| 1565 | // Create a new offer and ensure it doesn't contain the removed senders. |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1566 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1567 | |
| 1568 | audio_content = cricket::GetFirstAudioContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1569 | EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(), |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1570 | kStreamId1, "audio_track")); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1571 | |
| 1572 | video_content = cricket::GetFirstVideoContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1573 | EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(), |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1574 | kStreamId1, "video_track")); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1575 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1576 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1577 | |
| 1578 | // Calling RemoveTrack on a sender no longer attached to a PeerConnection |
| 1579 | // should return false. |
Harald Alvestrand | 93dd763 | 2022-01-19 12:28:45 +0000 | [diff] [blame] | 1580 | EXPECT_FALSE(pc_->RemoveTrackOrError(audio_sender).ok()); |
| 1581 | EXPECT_FALSE(pc_->RemoveTrackOrError(video_sender).ok()); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | // Test creating senders without a stream specified, |
| 1585 | // expecting a random stream ID to be generated. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1586 | TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1587 | CreatePeerConnectionWithoutDtls(); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1588 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1589 | CreateAudioTrack("audio_track")); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1590 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1591 | CreateVideoTrack("video_track")); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1592 | auto audio_sender = |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 1593 | pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue(); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1594 | auto video_sender = |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 1595 | pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue(); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1596 | EXPECT_EQ("audio_track", audio_sender->id()); |
| 1597 | EXPECT_EQ(audio_track, audio_sender->track()); |
| 1598 | EXPECT_EQ("video_track", video_sender->id()); |
| 1599 | EXPECT_EQ(video_track, video_sender->track()); |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 1600 | if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) { |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 1601 | // If the ID is truly a random GUID, it should be infinitely unlikely they |
| 1602 | // will be the same. |
| 1603 | EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids()); |
| 1604 | } else { |
| 1605 | // We allows creating tracks without stream ids under Unified Plan |
| 1606 | // semantics. |
| 1607 | EXPECT_EQ(0u, video_sender->stream_ids().size()); |
| 1608 | EXPECT_EQ(0u, audio_sender->stream_ids().size()); |
| 1609 | } |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1610 | } |
| 1611 | |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1612 | // Test that we can call GetStats() after AddTrack but before connecting |
| 1613 | // the PeerConnection to a peer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1614 | TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) { |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1615 | CreatePeerConnectionWithoutDtls(); |
| 1616 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1617 | CreateAudioTrack("audio_track")); |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1618 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1619 | CreateVideoTrack("video_track")); |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 1620 | auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>()); |
| 1621 | auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>()); |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1622 | EXPECT_TRUE(DoGetStats(nullptr)); |
| 1623 | } |
| 1624 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1625 | TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) { |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1626 | CreatePeerConnectionWithoutDtls(); |
| 1627 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1628 | CreateAudioTrack("audio_track")); |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1629 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1630 | CreateVideoTrack("video_track")); |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1631 | auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>()); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 1632 | ASSERT_TRUE(audio_sender.ok()); |
| 1633 | auto* audio_sender_proxy = |
| 1634 | static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>( |
| 1635 | audio_sender.value().get()); |
| 1636 | EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId()); |
| 1637 | |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1638 | auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>()); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 1639 | ASSERT_TRUE(video_sender.ok()); |
| 1640 | auto* video_sender_proxy = |
| 1641 | static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>( |
| 1642 | video_sender.value().get()); |
| 1643 | EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId()); |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1644 | } |
| 1645 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1646 | // Don't run under Unified Plan since the stream API is not available. |
| 1647 | TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) { |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1648 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1649 | AddVideoStream(kStreamId1); |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1650 | auto senders = pc_->GetSenders(); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 1651 | ASSERT_EQ(1u, senders.size()); |
| 1652 | auto* sender_proxy = |
| 1653 | static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>( |
| 1654 | senders[0].get()); |
| 1655 | EXPECT_NE(0, sender_proxy->internal()->AttachmentId()); |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1656 | } |
| 1657 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1658 | TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1659 | InitiateCall(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1660 | WaitAndVerifyOnAddStream(kStreamId1, 2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1661 | VerifyRemoteRtpHeaderExtensions(); |
| 1662 | } |
| 1663 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1664 | TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1665 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1666 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1667 | CreateOfferAsLocalDescription(); |
| 1668 | std::string offer; |
| 1669 | EXPECT_TRUE(pc_->local_description()->ToString(&offer)); |
| 1670 | CreatePrAnswerAndAnswerAsRemoteDescription(offer); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1671 | WaitAndVerifyOnAddStream(kStreamId1, 1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1674 | TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1675 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1676 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1677 | |
| 1678 | CreateOfferAsRemoteDescription(); |
| 1679 | CreateAnswerAsLocalDescription(); |
| 1680 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1681 | WaitAndVerifyOnAddStream(kStreamId1, 1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1684 | TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1685 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1686 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1687 | |
| 1688 | CreateOfferAsRemoteDescription(); |
| 1689 | CreatePrAnswerAsLocalDescription(); |
| 1690 | CreateAnswerAsLocalDescription(); |
| 1691 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1692 | WaitAndVerifyOnAddStream(kStreamId1, 1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1695 | // Don't run under Unified Plan since the stream API is not available. |
| 1696 | TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1697 | InitiateCall(); |
| 1698 | ASSERT_EQ(1u, pc_->remote_streams()->count()); |
| 1699 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 1700 | CreateOfferReceiveAnswer(); |
| 1701 | EXPECT_EQ(0u, pc_->remote_streams()->count()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1702 | AddVideoStream(kStreamId1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1703 | CreateOfferReceiveAnswer(); |
| 1704 | } |
| 1705 | |
| 1706 | // Tests that after negotiating an audio only call, the respondent can perform a |
| 1707 | // renegotiation that removes the audio stream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1708 | TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1709 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1710 | AddAudioStream(kStreamId1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1711 | CreateOfferAsRemoteDescription(); |
| 1712 | CreateAnswerAsLocalDescription(); |
| 1713 | |
| 1714 | ASSERT_EQ(1u, pc_->remote_streams()->count()); |
| 1715 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 1716 | CreateOfferReceiveAnswer(); |
| 1717 | EXPECT_EQ(0u, pc_->remote_streams()->count()); |
| 1718 | } |
| 1719 | |
| 1720 | // Test that candidates are generated and that we can parse our own candidates. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1721 | TEST_P(PeerConnectionInterfaceTest, IceCandidates) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1722 | CreatePeerConnectionWithoutDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1723 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1724 | EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1725 | // SetRemoteDescription takes ownership of offer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1726 | std::unique_ptr<SessionDescriptionInterface> offer; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1727 | AddVideoTrack(kVideoTracks[0]); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1728 | EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1729 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1730 | |
| 1731 | // SetLocalDescription takes ownership of answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1732 | std::unique_ptr<SessionDescriptionInterface> answer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1733 | EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1734 | EXPECT_TRUE(DoSetLocalDescription(std::move(answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1735 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1736 | EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 1737 | EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1738 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1739 | EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1742 | // Test that CreateOffer and CreateAnswer will fail if the track labels are |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1743 | // not unique. |
Steve Anton | 0756373 | 2018-06-26 11:13:50 -0700 | [diff] [blame] | 1744 | TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1745 | CreatePeerConnectionWithoutDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1746 | // Create a regular offer for the CreateAnswer test later. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1747 | std::unique_ptr<SessionDescriptionInterface> offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1748 | EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1749 | EXPECT_TRUE(offer); |
| 1750 | offer.reset(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1751 | |
| 1752 | // Create a local stream with audio&video tracks having same label. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1753 | AddAudioTrack("track_label", {kStreamId1}); |
| 1754 | AddVideoTrack("track_label", {kStreamId1}); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1755 | |
| 1756 | // Test CreateOffer |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1757 | EXPECT_FALSE(DoCreateOffer(&offer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1758 | |
| 1759 | // Test CreateAnswer |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1760 | std::unique_ptr<SessionDescriptionInterface> answer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1761 | EXPECT_FALSE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | // Test that we will get different SSRCs for each tracks in the offer and answer |
| 1765 | // we created. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1766 | TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1767 | CreatePeerConnectionWithoutDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1768 | // Create a local stream with audio&video tracks having different labels. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1769 | AddAudioTrack(kAudioTracks[0], {kStreamId1}); |
| 1770 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1771 | |
| 1772 | // Test CreateOffer |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1773 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1774 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1775 | int audio_ssrc = 0; |
| 1776 | int video_ssrc = 0; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1777 | EXPECT_TRUE( |
| 1778 | GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc)); |
| 1779 | EXPECT_TRUE( |
| 1780 | GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1781 | EXPECT_NE(audio_ssrc, video_ssrc); |
| 1782 | |
| 1783 | // Test CreateAnswer |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1784 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1785 | std::unique_ptr<SessionDescriptionInterface> answer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1786 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1787 | audio_ssrc = 0; |
| 1788 | video_ssrc = 0; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1789 | EXPECT_TRUE( |
| 1790 | GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc)); |
| 1791 | EXPECT_TRUE( |
| 1792 | GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1793 | EXPECT_NE(audio_ssrc, video_ssrc); |
| 1794 | } |
| 1795 | |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1796 | // Test that it's possible to call AddTrack on a MediaStream after adding |
| 1797 | // the stream to a PeerConnection. |
| 1798 | // TODO(deadbeef): Remove this test once this behavior is no longer supported. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1799 | // Don't run under Unified Plan since the stream API is not available. |
| 1800 | TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1801 | CreatePeerConnectionWithoutDtls(); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1802 | // Create audio stream and add to PeerConnection. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1803 | AddAudioStream(kStreamId1); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1804 | MediaStreamInterface* stream = pc_->local_streams()->at(0); |
| 1805 | |
| 1806 | // Add video track to the audio-only stream. |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1807 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1808 | CreateVideoTrack("video_label")); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1809 | stream->AddTrack(video_track.get()); |
| 1810 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1811 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1812 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1813 | |
| 1814 | const cricket::MediaContentDescription* video_desc = |
| 1815 | cricket::GetFirstVideoContentDescription(offer->description()); |
| 1816 | EXPECT_TRUE(video_desc != nullptr); |
| 1817 | } |
| 1818 | |
| 1819 | // Test that it's possible to call RemoveTrack on a MediaStream after adding |
| 1820 | // the stream to a PeerConnection. |
| 1821 | // TODO(deadbeef): Remove this test once this behavior is no longer supported. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1822 | // Don't run under Unified Plan since the stream API is not available. |
| 1823 | TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1824 | CreatePeerConnectionWithoutDtls(); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1825 | // Create audio/video stream and add to PeerConnection. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1826 | AddAudioVideoStream(kStreamId1, "audio_label", "video_label"); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1827 | MediaStreamInterface* stream = pc_->local_streams()->at(0); |
| 1828 | |
| 1829 | // Remove the video track. |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1830 | stream->RemoveTrack(stream->GetVideoTracks()[0].get()); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1831 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1832 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1833 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1834 | |
| 1835 | const cricket::MediaContentDescription* video_desc = |
| 1836 | cricket::GetFirstVideoContentDescription(offer->description()); |
| 1837 | EXPECT_TRUE(video_desc == nullptr); |
| 1838 | } |
| 1839 | |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 1840 | // Test creating a sender with a stream ID, and ensure the ID is populated |
| 1841 | // in the offer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1842 | // Don't run under Unified Plan since the stream API is not available. |
| 1843 | TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1844 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1845 | pc_->CreateSender("video", kStreamId1); |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 1846 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1847 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1848 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 1849 | |
| 1850 | const cricket::MediaContentDescription* video_desc = |
| 1851 | cricket::GetFirstVideoContentDescription(offer->description()); |
| 1852 | ASSERT_TRUE(video_desc != nullptr); |
| 1853 | ASSERT_EQ(1u, video_desc->streams().size()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1854 | EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id()); |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 1855 | } |
| 1856 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1857 | // Test that we can specify a certain track that we want statistics about. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1858 | TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1859 | InitiateCall(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1860 | ASSERT_LT(0u, pc_->GetSenders().size()); |
| 1861 | ASSERT_LT(0u, pc_->GetReceivers().size()); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1862 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1863 | pc_->GetReceivers()[0]->track(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1864 | EXPECT_TRUE(DoGetStats(remote_audio.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1865 | |
| 1866 | // Remove the stream. Since we are sending to our selves the local |
| 1867 | // and the remote stream is the same. |
Harald Alvestrand | 93dd763 | 2022-01-19 12:28:45 +0000 | [diff] [blame] | 1868 | pc_->RemoveTrackOrError(pc_->GetSenders()[0]); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1869 | // Do a re-negotiation. |
| 1870 | CreateOfferReceiveAnswer(); |
| 1871 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1872 | // Test that we still can get statistics for the old track. Even if it is not |
| 1873 | // sent any longer. |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1874 | EXPECT_TRUE(DoGetStats(remote_audio.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | // Test that we can get stats on a video track. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1878 | TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1879 | InitiateCall(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1880 | auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 1881 | ASSERT_TRUE(video_receiver); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1882 | EXPECT_TRUE(DoGetStats(video_receiver->track().get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | // Test that we don't get statistics for an invalid track. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1886 | TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1887 | InitiateCall(); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1888 | rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track( |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 1889 | pc_factory_->CreateAudioTrack("unknown track", nullptr)); |
| 1890 | EXPECT_FALSE(DoGetStats(unknown_audio_track.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1893 | TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) { |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1894 | CreatePeerConnectionWithoutDtls(); |
| 1895 | EXPECT_TRUE(DoGetRTCStats()); |
| 1896 | // Clearing stats cache is needed now, but should be temporary. |
| 1897 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693 |
| 1898 | pc_->ClearStatsCache(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1899 | AddAudioTrack(kAudioTracks[0], {kStreamId1}); |
| 1900 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1901 | EXPECT_TRUE(DoGetRTCStats()); |
| 1902 | pc_->ClearStatsCache(); |
| 1903 | CreateOfferReceiveAnswer(); |
| 1904 | EXPECT_TRUE(DoGetRTCStats()); |
| 1905 | } |
| 1906 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1907 | // This tests that a SCTP data channel is returned using different |
| 1908 | // DataChannelInit configurations. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1909 | TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1910 | RTCConfiguration rtc_config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1911 | CreatePeerConnection(rtc_config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1912 | |
| 1913 | webrtc::DataChannelInit config; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1914 | auto channel = pc_->CreateDataChannelOrError("1", &config); |
| 1915 | EXPECT_TRUE(channel.ok()); |
| 1916 | EXPECT_TRUE(channel.value()->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 1917 | EXPECT_TRUE(observer_.renegotiation_needed_); |
| 1918 | observer_.renegotiation_needed_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1919 | |
| 1920 | config.ordered = false; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1921 | channel = pc_->CreateDataChannelOrError("2", &config); |
| 1922 | EXPECT_TRUE(channel.ok()); |
| 1923 | EXPECT_TRUE(channel.value()->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 1924 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1925 | |
| 1926 | config.ordered = true; |
| 1927 | config.maxRetransmits = 0; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1928 | channel = pc_->CreateDataChannelOrError("3", &config); |
| 1929 | EXPECT_TRUE(channel.ok()); |
| 1930 | EXPECT_FALSE(channel.value()->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 1931 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1932 | |
Harald Alvestrand | f3736ed | 2019-04-08 13:09:30 +0200 | [diff] [blame] | 1933 | config.maxRetransmits = absl::nullopt; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1934 | config.maxRetransmitTime = 0; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1935 | channel = pc_->CreateDataChannelOrError("4", &config); |
| 1936 | EXPECT_TRUE(channel.ok()); |
| 1937 | EXPECT_FALSE(channel.value()->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 1938 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
Harald Alvestrand | f3736ed | 2019-04-08 13:09:30 +0200 | [diff] [blame] | 1941 | // For backwards compatibility, we want people who "unset" maxRetransmits |
| 1942 | // and maxRetransmitTime by setting them to -1 to get what they want. |
| 1943 | TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) { |
| 1944 | RTCConfiguration rtc_config; |
Harald Alvestrand | f3736ed | 2019-04-08 13:09:30 +0200 | [diff] [blame] | 1945 | CreatePeerConnection(rtc_config); |
| 1946 | |
| 1947 | webrtc::DataChannelInit config; |
| 1948 | config.maxRetransmitTime = -1; |
| 1949 | config.maxRetransmits = -1; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1950 | auto channel = pc_->CreateDataChannelOrError("1", &config); |
| 1951 | EXPECT_TRUE(channel.ok()); |
Harald Alvestrand | f3736ed | 2019-04-08 13:09:30 +0200 | [diff] [blame] | 1952 | } |
| 1953 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1954 | // This tests that no data channel is returned if both maxRetransmits and |
| 1955 | // maxRetransmitTime are set for SCTP data channels. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1956 | TEST_P(PeerConnectionInterfaceTest, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1957 | CreateSctpDataChannelShouldFailForInvalidConfig) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1958 | RTCConfiguration rtc_config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1959 | CreatePeerConnection(rtc_config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1960 | |
| 1961 | std::string label = "test"; |
| 1962 | webrtc::DataChannelInit config; |
| 1963 | config.maxRetransmits = 0; |
| 1964 | config.maxRetransmitTime = 0; |
| 1965 | |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1966 | auto channel = pc_->CreateDataChannelOrError(label, &config); |
| 1967 | EXPECT_FALSE(channel.ok()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1970 | // The test verifies that creating a SCTP data channel with an id already in use |
| 1971 | // or out of range should fail. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1972 | TEST_P(PeerConnectionInterfaceTest, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1973 | CreateSctpDataChannelWithInvalidIdShouldFail) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1974 | RTCConfiguration rtc_config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1975 | CreatePeerConnection(rtc_config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1976 | |
| 1977 | webrtc::DataChannelInit config; |
| 1978 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1979 | config.id = 1; |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 1980 | config.negotiated = true; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1981 | auto channel = pc_->CreateDataChannelOrError("1", &config); |
| 1982 | EXPECT_TRUE(channel.ok()); |
| 1983 | EXPECT_EQ(1, channel.value()->id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1984 | |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1985 | channel = pc_->CreateDataChannelOrError("x", &config); |
| 1986 | EXPECT_FALSE(channel.ok()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1987 | |
| 1988 | config.id = cricket::kMaxSctpSid; |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 1989 | config.negotiated = true; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1990 | channel = pc_->CreateDataChannelOrError("max", &config); |
| 1991 | EXPECT_TRUE(channel.ok()); |
| 1992 | EXPECT_EQ(config.id, channel.value()->id()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1993 | |
| 1994 | config.id = cricket::kMaxSctpSid + 1; |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 1995 | config.negotiated = true; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 1996 | channel = pc_->CreateDataChannelOrError("x", &config); |
| 1997 | EXPECT_FALSE(channel.ok()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2000 | // Verifies that duplicated label is allowed for SCTP data channel. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2001 | TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2002 | RTCConfiguration rtc_config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2003 | CreatePeerConnection(rtc_config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2004 | |
| 2005 | std::string label = "test"; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 2006 | auto channel = pc_->CreateDataChannelOrError(label, nullptr); |
| 2007 | EXPECT_TRUE(channel.ok()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2008 | |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 2009 | auto dup_channel = pc_->CreateDataChannelOrError(label, nullptr); |
| 2010 | EXPECT_TRUE(dup_channel.ok()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
Mirko Bonadei | 5eb43b4 | 2021-01-18 13:24:40 +0100 | [diff] [blame] | 2013 | #ifdef WEBRTC_HAVE_SCTP |
Zhi Huang | 644fde4 | 2018-04-02 19:16:26 -0700 | [diff] [blame] | 2014 | // This tests that SCTP data channels can be rejected in an answer. |
| 2015 | TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer) |
| 2016 | #else |
| 2017 | TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer) |
| 2018 | #endif |
| 2019 | { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2020 | RTCConfiguration rtc_config; |
| 2021 | CreatePeerConnection(rtc_config); |
Zhi Huang | 644fde4 | 2018-04-02 19:16:26 -0700 | [diff] [blame] | 2022 | |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 2023 | auto offer_channel = pc_->CreateDataChannelOrError("offer_channel", NULL); |
Zhi Huang | 644fde4 | 2018-04-02 19:16:26 -0700 | [diff] [blame] | 2024 | |
| 2025 | CreateOfferAsLocalDescription(); |
| 2026 | |
| 2027 | // Create an answer where the m-line for data channels are rejected. |
| 2028 | std::string sdp; |
| 2029 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
| 2030 | std::unique_ptr<SessionDescriptionInterface> answer( |
| 2031 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
| 2032 | ASSERT_TRUE(answer); |
| 2033 | cricket::ContentInfo* data_info = |
| 2034 | cricket::GetFirstDataContent(answer->description()); |
| 2035 | data_info->rejected = true; |
| 2036 | |
| 2037 | DoSetRemoteDescription(std::move(answer)); |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 2038 | EXPECT_EQ(DataChannelInterface::kClosed, offer_channel.value()->state()); |
Zhi Huang | 644fde4 | 2018-04-02 19:16:26 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2041 | // Test that we can create a session description from an SDP string from |
| 2042 | // FireFox, use it as a remote session description, generate an answer and use |
| 2043 | // the answer as a local description. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2044 | TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2045 | RTCConfiguration rtc_config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2046 | CreatePeerConnection(rtc_config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2047 | AddAudioTrack("audio_label"); |
| 2048 | AddVideoTrack("video_label"); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2049 | std::unique_ptr<SessionDescriptionInterface> desc( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2050 | webrtc::CreateSessionDescription(SdpType::kOffer, |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2051 | webrtc::kFireFoxSdpOffer, nullptr)); |
| 2052 | EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2053 | CreateAnswerAsLocalDescription(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2054 | ASSERT_TRUE(pc_->local_description() != nullptr); |
| 2055 | ASSERT_TRUE(pc_->remote_description() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2056 | |
| 2057 | const cricket::ContentInfo* content = |
| 2058 | cricket::GetFirstAudioContent(pc_->local_description()->description()); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2059 | ASSERT_TRUE(content != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2060 | EXPECT_FALSE(content->rejected); |
| 2061 | |
| 2062 | content = |
| 2063 | cricket::GetFirstVideoContent(pc_->local_description()->description()); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2064 | ASSERT_TRUE(content != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2065 | EXPECT_FALSE(content->rejected); |
Mirko Bonadei | 5eb43b4 | 2021-01-18 13:24:40 +0100 | [diff] [blame] | 2066 | #ifdef WEBRTC_HAVE_SCTP |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2067 | content = |
| 2068 | cricket::GetFirstDataContent(pc_->local_description()->description()); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2069 | ASSERT_TRUE(content != nullptr); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 2070 | EXPECT_FALSE(content->rejected); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 2071 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 2074 | // Test that fallback from DTLS to SDES is not supported. |
| 2075 | // The fallback was previously supported but was removed to simplify the code |
| 2076 | // and because it's non-standard. |
| 2077 | TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2078 | RTCConfiguration rtc_config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2079 | CreatePeerConnection(rtc_config); |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 2080 | // Wait for fake certificate to be generated. Previously, this is what caused |
| 2081 | // the "a=crypto" lines to be rejected. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2082 | AddAudioTrack("audio_label"); |
| 2083 | AddVideoTrack("video_label"); |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 2084 | ASSERT_NE(nullptr, fake_certificate_generator_); |
| 2085 | EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(), |
| 2086 | kTimeout); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2087 | std::unique_ptr<SessionDescriptionInterface> desc( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2088 | webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp, |
| 2089 | nullptr)); |
Harald Alvestrand | 0d01841 | 2021-11-04 13:52:31 +0000 | [diff] [blame] | 2090 | EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false)); |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 2091 | } |
| 2092 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2093 | // Test that we can create an audio only offer and receive an answer with a |
| 2094 | // limited set of audio codecs and receive an updated offer with more audio |
| 2095 | // codecs, where the added codecs are not supported. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2096 | TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2097 | CreatePeerConnectionWithoutDtls(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2098 | AddAudioTrack("audio_label"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2099 | CreateOfferAsLocalDescription(); |
| 2100 | |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 2101 | const char* answer_sdp = (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED |
| 2102 | ? webrtc::kAudioSdpPlanB |
| 2103 | : webrtc::kAudioSdpUnifiedPlan); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2104 | std::unique_ptr<SessionDescriptionInterface> answer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2105 | webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2106 | EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2107 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2108 | const char* reoffer_sdp = |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 2109 | (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2110 | ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB |
| 2111 | : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2112 | std::unique_ptr<SessionDescriptionInterface> updated_offer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2113 | webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2114 | EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2115 | CreateAnswerAsLocalDescription(); |
| 2116 | } |
| 2117 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2118 | // Test that if we're receiving (but not sending) a track, subsequent offers |
| 2119 | // will have m-lines with a=recvonly. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2120 | TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2121 | RTCConfiguration rtc_config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2122 | CreatePeerConnection(rtc_config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2123 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2124 | CreateAnswerAsLocalDescription(); |
| 2125 | |
| 2126 | // At this point we should be receiving stream 1, but not sending anything. |
| 2127 | // A new offer should be recvonly. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2128 | std::unique_ptr<SessionDescriptionInterface> offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2129 | DoCreateOffer(&offer, nullptr); |
| 2130 | |
| 2131 | const cricket::ContentInfo* video_content = |
| 2132 | cricket::GetFirstVideoContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2133 | ASSERT_EQ(RtpTransceiverDirection::kRecvOnly, |
| 2134 | video_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2135 | |
| 2136 | const cricket::ContentInfo* audio_content = |
| 2137 | cricket::GetFirstAudioContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2138 | ASSERT_EQ(RtpTransceiverDirection::kRecvOnly, |
| 2139 | audio_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | // Test that if we're receiving (but not sending) a track, and the |
| 2143 | // offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to |
| 2144 | // false, the generated m-lines will be a=inactive. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2145 | TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2146 | RTCConfiguration rtc_config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2147 | CreatePeerConnection(rtc_config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2148 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2149 | CreateAnswerAsLocalDescription(); |
| 2150 | |
| 2151 | // At this point we should be receiving stream 1, but not sending anything. |
| 2152 | // A new offer would be recvonly, but we'll set the "no receive" constraints |
| 2153 | // to make it inactive. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2154 | std::unique_ptr<SessionDescriptionInterface> offer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2155 | RTCOfferAnswerOptions options; |
| 2156 | options.offer_to_receive_audio = 0; |
| 2157 | options.offer_to_receive_video = 0; |
| 2158 | DoCreateOffer(&offer, &options); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2159 | |
| 2160 | const cricket::ContentInfo* video_content = |
| 2161 | cricket::GetFirstVideoContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2162 | ASSERT_EQ(RtpTransceiverDirection::kInactive, |
| 2163 | video_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2164 | |
| 2165 | const cricket::ContentInfo* audio_content = |
| 2166 | cricket::GetFirstAudioContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2167 | ASSERT_EQ(RtpTransceiverDirection::kInactive, |
| 2168 | audio_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2171 | // Test that we can use SetConfiguration to change the ICE servers of the |
| 2172 | // PortAllocator. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2173 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) { |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2174 | CreatePeerConnection(); |
| 2175 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2176 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2177 | PeerConnectionInterface::IceServer server; |
| 2178 | server.uri = "stun:test_hostname"; |
| 2179 | config.servers.push_back(server); |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2180 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2181 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2182 | EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
| 2183 | EXPECT_EQ("test_hostname", |
| 2184 | port_allocator_->stun_servers().begin()->hostname()); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2185 | } |
| 2186 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2187 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) { |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2188 | CreatePeerConnection(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2189 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2190 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2191 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2192 | EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); |
| 2193 | } |
| 2194 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2195 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2196 | PeerConnectionInterface::RTCConfiguration config; |
| 2197 | config.prune_turn_ports = false; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2198 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2199 | config = pc_->GetConfiguration(); |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 2200 | EXPECT_EQ(webrtc::NO_PRUNE, port_allocator_->turn_port_prune_policy()); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2201 | |
| 2202 | config.prune_turn_ports = true; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2203 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 2204 | EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY, |
| 2205 | port_allocator_->turn_port_prune_policy()); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2206 | } |
| 2207 | |
skvlad | d1f5fda | 2017-02-03 16:54:05 -0800 | [diff] [blame] | 2208 | // Test that the ice check interval can be changed. This does not verify that |
| 2209 | // the setting makes it all the way to P2PTransportChannel, as that would |
| 2210 | // require a very complex set of mocks. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2211 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) { |
skvlad | d1f5fda | 2017-02-03 16:54:05 -0800 | [diff] [blame] | 2212 | PeerConnectionInterface::RTCConfiguration config; |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 2213 | config.ice_check_min_interval = absl::nullopt; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2214 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2215 | config = pc_->GetConfiguration(); |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 2216 | config.ice_check_min_interval = 100; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2217 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
Qingsi Wang | bca1485 | 2019-06-26 14:56:02 -0700 | [diff] [blame] | 2218 | config = pc_->GetConfiguration(); |
| 2219 | EXPECT_EQ(config.ice_check_min_interval, 100); |
| 2220 | } |
| 2221 | |
| 2222 | TEST_P(PeerConnectionInterfaceTest, |
| 2223 | SetConfigurationChangesSurfaceIceCandidatesOnIceTransportTypeChanged) { |
| 2224 | PeerConnectionInterface::RTCConfiguration config; |
| 2225 | config.surface_ice_candidates_on_ice_transport_type_changed = false; |
| 2226 | CreatePeerConnection(config); |
| 2227 | config = pc_->GetConfiguration(); |
| 2228 | EXPECT_FALSE(config.surface_ice_candidates_on_ice_transport_type_changed); |
| 2229 | |
| 2230 | config.surface_ice_candidates_on_ice_transport_type_changed = true; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2231 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
Qingsi Wang | bca1485 | 2019-06-26 14:56:02 -0700 | [diff] [blame] | 2232 | config = pc_->GetConfiguration(); |
| 2233 | EXPECT_TRUE(config.surface_ice_candidates_on_ice_transport_type_changed); |
skvlad | d1f5fda | 2017-02-03 16:54:05 -0800 | [diff] [blame] | 2234 | } |
| 2235 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2236 | // Test that when SetConfiguration changes both the pool size and other |
| 2237 | // attributes, the pooled session is created with the updated attributes. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2238 | TEST_P(PeerConnectionInterfaceTest, |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2239 | SetConfigurationCreatesPooledSessionCorrectly) { |
| 2240 | CreatePeerConnection(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2241 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2242 | config.ice_candidate_pool_size = 1; |
| 2243 | PeerConnectionInterface::IceServer server; |
| 2244 | server.uri = kStunAddressOnly; |
| 2245 | config.servers.push_back(server); |
| 2246 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2247 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2248 | |
| 2249 | const cricket::FakePortAllocatorSession* session = |
| 2250 | static_cast<const cricket::FakePortAllocatorSession*>( |
| 2251 | port_allocator_->GetPooledSession()); |
| 2252 | ASSERT_NE(nullptr, session); |
| 2253 | EXPECT_EQ(1UL, session->stun_servers().size()); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2254 | } |
| 2255 | |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2256 | // Test that after SetLocalDescription, changing the pool size is not allowed, |
| 2257 | // and an invalid modification error is returned. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2258 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2259 | CantChangePoolSizeAfterSetLocalDescription) { |
| 2260 | CreatePeerConnection(); |
| 2261 | // Start by setting a size of 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2262 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2263 | config.ice_candidate_pool_size = 1; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2264 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2265 | |
| 2266 | // Set remote offer; can still change pool size at this point. |
| 2267 | CreateOfferAsRemoteDescription(); |
| 2268 | config.ice_candidate_pool_size = 2; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2269 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2270 | |
| 2271 | // Set local answer; now it's too late. |
| 2272 | CreateAnswerAsLocalDescription(); |
| 2273 | config.ice_candidate_pool_size = 3; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2274 | RTCError error = pc_->SetConfiguration(config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2275 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2276 | } |
| 2277 | |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2278 | // Test that after setting an answer, extra pooled sessions are discarded. The |
| 2279 | // ICE candidate pool is only intended to be used for the first offer/answer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2280 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2281 | ExtraPooledSessionsDiscardedAfterApplyingAnswer) { |
| 2282 | CreatePeerConnection(); |
| 2283 | |
| 2284 | // Set a larger-than-necessary size. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2285 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2286 | config.ice_candidate_pool_size = 4; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2287 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2288 | |
| 2289 | // Do offer/answer. |
| 2290 | CreateOfferAsRemoteDescription(); |
| 2291 | CreateAnswerAsLocalDescription(); |
| 2292 | |
| 2293 | // Expect no pooled sessions to be left. |
| 2294 | const cricket::PortAllocatorSession* session = |
| 2295 | port_allocator_->GetPooledSession(); |
| 2296 | EXPECT_EQ(nullptr, session); |
| 2297 | } |
| 2298 | |
| 2299 | // After Close is called, pooled candidates should be discarded so as to not |
| 2300 | // waste network resources. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2301 | TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) { |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2302 | CreatePeerConnection(); |
| 2303 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2304 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2305 | config.ice_candidate_pool_size = 3; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2306 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2307 | pc_->Close(); |
| 2308 | |
| 2309 | // Expect no pooled sessions to be left. |
| 2310 | const cricket::PortAllocatorSession* session = |
| 2311 | port_allocator_->GetPooledSession(); |
| 2312 | EXPECT_EQ(nullptr, session); |
| 2313 | } |
| 2314 | |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2315 | // Test that SetConfiguration returns an invalid modification error if |
| 2316 | // modifying a field in the configuration that isn't allowed to be modified. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2317 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2318 | SetConfigurationReturnsInvalidModificationError) { |
| 2319 | PeerConnectionInterface::RTCConfiguration config; |
| 2320 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced; |
| 2321 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate; |
| 2322 | config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2323 | CreatePeerConnection(config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2324 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2325 | PeerConnectionInterface::RTCConfiguration modified_config = |
| 2326 | pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2327 | modified_config.bundle_policy = |
| 2328 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2329 | RTCError error = pc_->SetConfiguration(modified_config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2330 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2331 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2332 | modified_config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2333 | modified_config.rtcp_mux_policy = |
| 2334 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2335 | error = pc_->SetConfiguration(modified_config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2336 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2337 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2338 | modified_config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2339 | modified_config.continual_gathering_policy = |
| 2340 | PeerConnectionInterface::GATHER_CONTINUALLY; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2341 | error = pc_->SetConfiguration(modified_config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2342 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2343 | } |
| 2344 | |
| 2345 | // Test that SetConfiguration returns a range error if the candidate pool size |
| 2346 | // is negative or larger than allowed by the spec. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2347 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2348 | SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) { |
| 2349 | PeerConnectionInterface::RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2350 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2351 | config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2352 | |
| 2353 | config.ice_candidate_pool_size = -1; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2354 | RTCError error = pc_->SetConfiguration(config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2355 | EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type()); |
| 2356 | |
| 2357 | config.ice_candidate_pool_size = INT_MAX; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2358 | error = pc_->SetConfiguration(config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2359 | EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type()); |
| 2360 | } |
| 2361 | |
| 2362 | // Test that SetConfiguration returns a syntax error if parsing an ICE server |
| 2363 | // URL failed. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2364 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2365 | SetConfigurationReturnsSyntaxErrorFromBadIceUrls) { |
| 2366 | PeerConnectionInterface::RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2367 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2368 | config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2369 | |
| 2370 | PeerConnectionInterface::IceServer bad_server; |
| 2371 | bad_server.uri = "stunn:www.example.com"; |
| 2372 | config.servers.push_back(bad_server); |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2373 | RTCError error = pc_->SetConfiguration(config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2374 | EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type()); |
| 2375 | } |
| 2376 | |
| 2377 | // Test that SetConfiguration returns an invalid parameter error if a TURN |
| 2378 | // IceServer is missing a username or password. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2379 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2380 | SetConfigurationReturnsInvalidParameterIfCredentialsMissing) { |
| 2381 | PeerConnectionInterface::RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2382 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2383 | config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2384 | |
| 2385 | PeerConnectionInterface::IceServer bad_server; |
| 2386 | bad_server.uri = "turn:www.example.com"; |
| 2387 | // Missing password. |
| 2388 | bad_server.username = "foo"; |
| 2389 | config.servers.push_back(bad_server); |
| 2390 | RTCError error; |
Niels Möller | 340e0c5 | 2019-08-26 11:03:47 +0200 | [diff] [blame] | 2391 | EXPECT_EQ(pc_->SetConfiguration(config).type(), |
| 2392 | RTCErrorType::INVALID_PARAMETER); |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2393 | } |
| 2394 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2395 | // Test that PeerConnection::Close changes the states to closed and all remote |
| 2396 | // tracks change state to ended. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2397 | TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2398 | // Initialize a PeerConnection and negotiate local and remote session |
| 2399 | // description. |
| 2400 | InitiateCall(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2401 | |
| 2402 | // With Plan B, verify the stream count. The analog with Unified Plan is the |
| 2403 | // RtpTransceiver count. |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 2404 | if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) { |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2405 | ASSERT_EQ(1u, pc_->local_streams()->count()); |
| 2406 | ASSERT_EQ(1u, pc_->remote_streams()->count()); |
| 2407 | } else { |
| 2408 | ASSERT_EQ(2u, pc_->GetTransceivers().size()); |
| 2409 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2410 | |
| 2411 | pc_->Close(); |
| 2412 | |
| 2413 | EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state()); |
| 2414 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed, |
| 2415 | pc_->ice_connection_state()); |
| 2416 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete, |
| 2417 | pc_->ice_gathering_state()); |
| 2418 | |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 2419 | if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) { |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2420 | EXPECT_EQ(1u, pc_->local_streams()->count()); |
| 2421 | EXPECT_EQ(1u, pc_->remote_streams()->count()); |
| 2422 | } else { |
Harald Alvestrand | 936f1af | 2020-09-22 07:41:50 +0000 | [diff] [blame] | 2423 | // Verify that the RtpTransceivers are still returned. |
| 2424 | EXPECT_EQ(2u, pc_->GetTransceivers().size()); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2425 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2426 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2427 | auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2428 | auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 2429 | if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) { |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 2430 | ASSERT_TRUE(audio_receiver); |
| 2431 | ASSERT_TRUE(video_receiver); |
| 2432 | // Track state may be updated asynchronously. |
| 2433 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, |
| 2434 | audio_receiver->track()->state(), kTimeout); |
| 2435 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, |
| 2436 | video_receiver->track()->state(), kTimeout); |
| 2437 | } else { |
| 2438 | ASSERT_FALSE(audio_receiver); |
| 2439 | ASSERT_FALSE(video_receiver); |
| 2440 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | // Test that PeerConnection methods fails gracefully after |
| 2444 | // PeerConnection::Close has been called. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2445 | // Don't run under Unified Plan since the stream API is not available. |
| 2446 | TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2447 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 2448 | AddAudioVideoStream(kStreamId1, "audio_label", "video_label"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2449 | CreateOfferAsRemoteDescription(); |
| 2450 | CreateAnswerAsLocalDescription(); |
| 2451 | |
| 2452 | ASSERT_EQ(1u, pc_->local_streams()->count()); |
Niels Möller | e7cc883 | 2022-01-04 15:20:03 +0100 | [diff] [blame] | 2453 | rtc::scoped_refptr<MediaStreamInterface> local_stream( |
| 2454 | pc_->local_streams()->at(0)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2455 | |
| 2456 | pc_->Close(); |
| 2457 | |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2458 | pc_->RemoveStream(local_stream.get()); |
| 2459 | EXPECT_FALSE(pc_->AddStream(local_stream.get())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2460 | |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 2461 | EXPECT_FALSE(pc_->CreateDataChannelOrError("test", NULL).ok()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2462 | |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2463 | EXPECT_TRUE(pc_->local_description() != nullptr); |
| 2464 | EXPECT_TRUE(pc_->remote_description() != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2465 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2466 | std::unique_ptr<SessionDescriptionInterface> offer; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2467 | EXPECT_FALSE(DoCreateOffer(&offer, nullptr)); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2468 | std::unique_ptr<SessionDescriptionInterface> answer; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2469 | EXPECT_FALSE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2470 | |
| 2471 | std::string sdp; |
| 2472 | ASSERT_TRUE(pc_->remote_description()->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2473 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2474 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2475 | EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2476 | |
| 2477 | ASSERT_TRUE(pc_->local_description()->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2478 | std::unique_ptr<SessionDescriptionInterface> local_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2479 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2480 | EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | // Test that GetStats can still be called after PeerConnection::Close. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2484 | TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2485 | InitiateCall(); |
| 2486 | pc_->Close(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2487 | DoGetStats(nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2488 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2489 | |
| 2490 | // NOTE: The series of tests below come from what used to be |
| 2491 | // mediastreamsignaling_unittest.cc, and are mostly aimed at testing that |
| 2492 | // setting a remote or local description has the expected effects. |
| 2493 | |
| 2494 | // This test verifies that the remote MediaStreams corresponding to a received |
| 2495 | // SDP string is created. In this test the two separate MediaStreams are |
| 2496 | // signaled. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2497 | TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2498 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2499 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2500 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2501 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2502 | rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2503 | EXPECT_TRUE( |
| 2504 | CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 2505 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2506 | EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr); |
| 2507 | |
| 2508 | // Create a session description based on another SDP with another |
| 2509 | // MediaStream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2510 | CreateAndSetRemoteOffer(GetSdpStringWithStream1And2()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2511 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2512 | rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2513 | EXPECT_TRUE( |
| 2514 | CompareStreamCollections(observer_.remote_streams(), reference2.get())); |
| 2515 | } |
| 2516 | |
| 2517 | // This test verifies that when remote tracks are added/removed from SDP, the |
| 2518 | // created remote streams are updated appropriately. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2519 | // Don't run under Unified Plan since this test uses Plan B SDP to test Plan B |
| 2520 | // specific behavior. |
| 2521 | TEST_F(PeerConnectionInterfaceTestPlanB, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2522 | AddRemoveTrackFromExistingRemoteMediaStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2523 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2524 | CreatePeerConnection(config); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2525 | std::unique_ptr<SessionDescriptionInterface> desc_ms1 = |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2526 | CreateSessionDescriptionAndReference(1, 1); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2527 | EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2528 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2529 | reference_collection_.get())); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2530 | |
| 2531 | // Add extra audio and video tracks to the same MediaStream. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2532 | std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks = |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2533 | CreateSessionDescriptionAndReference(2, 2); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2534 | EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2535 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2536 | reference_collection_.get())); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2537 | rtc::scoped_refptr<AudioTrackInterface> audio_track2 = |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2538 | observer_.remote_streams()->at(0)->GetAudioTracks()[1]; |
| 2539 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state()); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2540 | rtc::scoped_refptr<VideoTrackInterface> video_track2 = |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2541 | observer_.remote_streams()->at(0)->GetVideoTracks()[1]; |
| 2542 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2543 | |
| 2544 | // Remove the extra audio and video tracks. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2545 | std::unique_ptr<SessionDescriptionInterface> desc_ms2 = |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2546 | CreateSessionDescriptionAndReference(1, 1); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2547 | MockTrackObserver audio_track_observer(audio_track2.get()); |
| 2548 | MockTrackObserver video_track_observer(video_track2.get()); |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2549 | |
| 2550 | EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1)); |
| 2551 | EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2552 | EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2553 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2554 | reference_collection_.get())); |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2555 | // Track state may be updated asynchronously. |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2556 | EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2557 | audio_track2->state(), kTimeout); |
| 2558 | EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, |
| 2559 | video_track2->state(), kTimeout); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | // This tests that remote tracks are ended if a local session description is set |
| 2563 | // that rejects the media content type. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2564 | TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2565 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2566 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2567 | // First create and set a remote offer, then reject its video content in our |
| 2568 | // answer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2569 | CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB); |
| 2570 | auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO); |
| 2571 | ASSERT_TRUE(audio_receiver); |
| 2572 | auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 2573 | ASSERT_TRUE(video_receiver); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2574 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2575 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio = |
| 2576 | audio_receiver->track(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2577 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state()); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2578 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_video = |
| 2579 | video_receiver->track(); |
| 2580 | EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2581 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2582 | std::unique_ptr<SessionDescriptionInterface> local_answer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2583 | EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2584 | cricket::ContentInfo* video_info = |
| 2585 | local_answer->description()->GetContentByName("video"); |
| 2586 | video_info->rejected = true; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2587 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer))); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2588 | EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state()); |
| 2589 | EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2590 | |
| 2591 | // Now create an offer where we reject both video and audio. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2592 | std::unique_ptr<SessionDescriptionInterface> local_offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2593 | EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2594 | video_info = local_offer->description()->GetContentByName("video"); |
| 2595 | ASSERT_TRUE(video_info != nullptr); |
| 2596 | video_info->rejected = true; |
| 2597 | cricket::ContentInfo* audio_info = |
| 2598 | local_offer->description()->GetContentByName("audio"); |
| 2599 | ASSERT_TRUE(audio_info != nullptr); |
| 2600 | audio_info->rejected = true; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2601 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer))); |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2602 | // Track state may be updated asynchronously. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2603 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(), |
| 2604 | kTimeout); |
| 2605 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(), |
| 2606 | kTimeout); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | // This tests that we won't crash if the remote track has been removed outside |
| 2610 | // of PeerConnection and then PeerConnection tries to reject the track. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2611 | // Don't run under Unified Plan since the stream API is not available. |
| 2612 | TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2613 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2614 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2615 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2616 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2617 | remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0].get()); |
| 2618 | remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0].get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2619 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2620 | std::unique_ptr<SessionDescriptionInterface> local_answer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2621 | webrtc::CreateSessionDescription(SdpType::kAnswer, |
| 2622 | GetSdpStringWithStream1(), nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2623 | cricket::ContentInfo* video_info = |
| 2624 | local_answer->description()->GetContentByName("video"); |
| 2625 | video_info->rejected = true; |
| 2626 | cricket::ContentInfo* audio_info = |
| 2627 | local_answer->description()->GetContentByName("audio"); |
| 2628 | audio_info->rejected = true; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2629 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2630 | |
| 2631 | // No crash is a pass. |
| 2632 | } |
| 2633 | |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 2634 | // This tests that if a recvonly remote description is set, no remote streams |
| 2635 | // will be created, even if the description contains SSRCs/MSIDs. |
| 2636 | // See: https://code.google.com/p/webrtc/issues/detail?id=5054 |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2637 | TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2638 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2639 | CreatePeerConnection(config); |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 2640 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2641 | std::string recvonly_offer = GetSdpStringWithStream1(); |
Steve Anton | 1c9c9fc | 2019-02-14 15:13:09 -0800 | [diff] [blame] | 2642 | absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer); |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 2643 | CreateAndSetRemoteOffer(recvonly_offer); |
| 2644 | |
| 2645 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 2646 | } |
| 2647 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2648 | // This tests that a default MediaStream is created if a remote session |
| 2649 | // description doesn't contain any streams and no MSID support. |
| 2650 | // It also tests that the default stream is updated if a video m-line is added |
| 2651 | // in a subsequent session description. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2652 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2653 | TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2654 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2655 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2656 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 2657 | |
| 2658 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2659 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2660 | |
| 2661 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2662 | EXPECT_EQ(0u, remote_stream->GetVideoTracks().size()); |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 2663 | EXPECT_EQ("default", remote_stream->id()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2664 | |
| 2665 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2666 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2667 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2668 | EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id()); |
deadbeef | 884f585 | 2016-01-15 09:20:04 -0800 | [diff] [blame] | 2669 | EXPECT_EQ(MediaStreamTrackInterface::kLive, |
| 2670 | remote_stream->GetAudioTracks()[0]->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2671 | ASSERT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 2672 | EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id()); |
deadbeef | 884f585 | 2016-01-15 09:20:04 -0800 | [diff] [blame] | 2673 | EXPECT_EQ(MediaStreamTrackInterface::kLive, |
| 2674 | remote_stream->GetVideoTracks()[0]->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | // This tests that a default MediaStream is created if a remote session |
| 2678 | // description doesn't contain any streams and media direction is send only. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2679 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2680 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 2681 | SendOnlySdpWithoutMsidCreatesDefaultStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2682 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2683 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2684 | CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams); |
| 2685 | |
| 2686 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2687 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2688 | |
| 2689 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2690 | EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 2691 | EXPECT_EQ("default", remote_stream->id()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | // This tests that it won't crash when PeerConnection tries to remove |
| 2695 | // a remote track that as already been removed from the MediaStream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2696 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2697 | TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2698 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2699 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2700 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2701 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2702 | remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0].get()); |
| 2703 | remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0].get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2704 | |
| 2705 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2706 | |
| 2707 | // No crash is a pass. |
| 2708 | } |
| 2709 | |
| 2710 | // This tests that a default MediaStream is created if the remote session |
| 2711 | // description doesn't contain any streams and don't contain an indication if |
| 2712 | // MSID is supported. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2713 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2714 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 2715 | SdpWithoutMsidAndStreamsCreatesDefaultStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2716 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2717 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2718 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2719 | |
| 2720 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2721 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2722 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2723 | EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 2724 | } |
| 2725 | |
| 2726 | // This tests that a default MediaStream is not created if the remote session |
| 2727 | // description doesn't contain any streams but does support MSID. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2728 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2729 | TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2730 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2731 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2732 | CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams); |
| 2733 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 2734 | } |
| 2735 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 2736 | // This tests that when setting a new description, the old default tracks are |
| 2737 | // not destroyed and recreated. |
| 2738 | // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250 |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2739 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2740 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 2741 | DefaultTracksNotDestroyedAndRecreated) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2742 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2743 | CreatePeerConnection(config); |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 2744 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 2745 | |
| 2746 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2747 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2748 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2749 | |
| 2750 | // Set the track to "disabled", then set a new description and ensure the |
| 2751 | // track is still disabled, which ensures it hasn't been recreated. |
| 2752 | remote_stream->GetAudioTracks()[0]->set_enabled(false); |
| 2753 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 2754 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2755 | EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled()); |
| 2756 | } |
| 2757 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2758 | // This tests that a default MediaStream is not created if a remote session |
| 2759 | // description is updated to not have any MediaStreams. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2760 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2761 | TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2762 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2763 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2764 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2765 | rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2766 | EXPECT_TRUE( |
| 2767 | CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 2768 | |
| 2769 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2770 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 2771 | } |
| 2772 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 2773 | // This tests that a default MediaStream is created if a remote SDP comes from |
| 2774 | // an endpoint that doesn't signal SSRCs, but signals media stream IDs. |
| 2775 | TEST_F(PeerConnectionInterfaceTestPlanB, |
| 2776 | SdpWithMsidWithoutSsrcCreatesDefaultStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2777 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2778 | CreatePeerConnection(config); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 2779 | std::string sdp_string = kSdpStringWithoutStreamsAudioOnly; |
| 2780 | // Add a=msid lines to simulate a Unified Plan endpoint that only |
| 2781 | // signals stream IDs with a=msid lines. |
| 2782 | sdp_string.append("a=msid:audio_stream_id audio_track_id\n"); |
| 2783 | |
| 2784 | CreateAndSetRemoteOffer(sdp_string); |
| 2785 | |
| 2786 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2787 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2788 | EXPECT_EQ("default", remote_stream->id()); |
| 2789 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2790 | } |
| 2791 | |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 2792 | // This tests that when a Plan B endpoint receives an SDP that signals no media |
| 2793 | // stream IDs indicated by the special character "-" in the a=msid line, that |
| 2794 | // a default stream ID will be used for the MediaStream ID. This can occur |
| 2795 | // when a Unified Plan endpoint signals no media stream IDs, but signals both |
| 2796 | // a=ssrc msid and a=msid lines for interop signaling with Plan B. |
| 2797 | TEST_F(PeerConnectionInterfaceTestPlanB, |
| 2798 | SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2799 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2800 | CreatePeerConnection(config); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 2801 | // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so |
| 2802 | // the sender's stream ID will be interpreted as no stream IDs. |
| 2803 | std::string sdp_string = kSdpStringWithStream1AudioTrackOnly; |
| 2804 | sdp_string.append("a=msid:- audiotrack0\n"); |
| 2805 | |
| 2806 | CreateAndSetRemoteOffer(sdp_string); |
| 2807 | |
| 2808 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2809 | // Because SSRCs are signaled the track ID will be what was signaled in the |
| 2810 | // a=msid line. |
| 2811 | EXPECT_EQ("audiotrack0", observer_.last_added_track_label_); |
| 2812 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2813 | EXPECT_EQ("default", remote_stream->id()); |
| 2814 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
Seth Hampson | 83d676b | 2018-04-05 18:12:09 -0700 | [diff] [blame] | 2815 | |
| 2816 | // Previously a bug ocurred when setting the remote description a second time. |
| 2817 | // This is because we checked equality of the remote StreamParams stream ID |
| 2818 | // (empty), and the previously set stream ID for the remote sender |
| 2819 | // ("default"). This cause a track to be removed, then added, when really |
| 2820 | // nothing should occur because it is the same track. |
| 2821 | CreateAndSetRemoteOffer(sdp_string); |
| 2822 | EXPECT_EQ(0u, observer_.remove_track_events_.size()); |
| 2823 | EXPECT_EQ(1u, observer_.add_track_events_.size()); |
| 2824 | EXPECT_EQ("audiotrack0", observer_.last_added_track_label_); |
| 2825 | remote_stream = observer_.remote_streams()->at(0); |
| 2826 | EXPECT_EQ("default", remote_stream->id()); |
| 2827 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 2828 | } |
| 2829 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2830 | // This tests that an RtpSender is created when the local description is set |
| 2831 | // after adding a local stream. |
| 2832 | // TODO(deadbeef): This test and the one below it need to be updated when |
| 2833 | // an RtpSender's lifetime isn't determined by when a local description is set. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2834 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2835 | TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2836 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2837 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2838 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2839 | // Create an offer with 1 stream with 2 tracks of each type. |
| 2840 | rtc::scoped_refptr<StreamCollection> stream_collection = |
| 2841 | CreateStreamCollection(1, 2); |
| 2842 | pc_->AddStream(stream_collection->at(0)); |
| 2843 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 2844 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2845 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2846 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2847 | auto senders = pc_->GetSenders(); |
| 2848 | EXPECT_EQ(4u, senders.size()); |
| 2849 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2850 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2851 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 2852 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 2853 | |
| 2854 | // Remove an audio and video track. |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2855 | pc_->RemoveStream(stream_collection->at(0)); |
| 2856 | stream_collection = CreateStreamCollection(1, 1); |
| 2857 | pc_->AddStream(stream_collection->at(0)); |
| 2858 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2859 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2860 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2861 | senders = pc_->GetSenders(); |
| 2862 | EXPECT_EQ(2u, senders.size()); |
| 2863 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2864 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2865 | EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1])); |
| 2866 | EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1])); |
| 2867 | } |
| 2868 | |
| 2869 | // This tests that an RtpSender is created when the local description is set |
| 2870 | // before adding a local stream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2871 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2872 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 2873 | AddLocalStreamAfterLocalDescriptionChanged) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2874 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2875 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2876 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2877 | rtc::scoped_refptr<StreamCollection> stream_collection = |
| 2878 | CreateStreamCollection(1, 2); |
| 2879 | // Add a stream to create the offer, but remove it afterwards. |
| 2880 | pc_->AddStream(stream_collection->at(0)); |
| 2881 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 2882 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 2883 | pc_->RemoveStream(stream_collection->at(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2884 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2885 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2886 | auto senders = pc_->GetSenders(); |
| 2887 | EXPECT_EQ(0u, senders.size()); |
| 2888 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2889 | pc_->AddStream(stream_collection->at(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2890 | senders = pc_->GetSenders(); |
| 2891 | EXPECT_EQ(4u, senders.size()); |
| 2892 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2893 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2894 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 2895 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 2896 | } |
| 2897 | |
| 2898 | // This tests that the expected behavior occurs if the SSRC on a local track is |
| 2899 | // changed when SetLocalDescription is called. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2900 | TEST_P(PeerConnectionInterfaceTest, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 2901 | ChangeSsrcOnTrackInLocalSessionDescription) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2902 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2903 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2904 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2905 | AddAudioTrack(kAudioTracks[0]); |
| 2906 | AddVideoTrack(kVideoTracks[0]); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2907 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 2908 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 2909 | // Grab a copy of the offer before it gets passed into the PC. |
Steve Anton | d9e4a06 | 2018-07-24 18:23:33 -0700 | [diff] [blame] | 2910 | std::unique_ptr<SessionDescriptionInterface> modified_offer = |
| 2911 | webrtc::CreateSessionDescription( |
| 2912 | webrtc::SdpType::kOffer, offer->session_id(), |
Harald Alvestrand | 4d7160e | 2019-04-12 07:01:29 +0200 | [diff] [blame] | 2913 | offer->session_version(), offer->description()->Clone()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2914 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2915 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2916 | auto senders = pc_->GetSenders(); |
| 2917 | EXPECT_EQ(2u, senders.size()); |
| 2918 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2919 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2920 | |
| 2921 | // Change the ssrc of the audio and video track. |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2922 | cricket::MediaContentDescription* desc = |
| 2923 | cricket::GetFirstAudioContentDescription(modified_offer->description()); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2924 | ASSERT_TRUE(desc != nullptr); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2925 | for (StreamParams& stream : desc->mutable_streams()) { |
| 2926 | for (unsigned int& ssrc : stream.ssrcs) { |
| 2927 | ++ssrc; |
| 2928 | } |
| 2929 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2930 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2931 | desc = |
| 2932 | cricket::GetFirstVideoContentDescription(modified_offer->description()); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2933 | ASSERT_TRUE(desc != nullptr); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2934 | for (StreamParams& stream : desc->mutable_streams()) { |
| 2935 | for (unsigned int& ssrc : stream.ssrcs) { |
| 2936 | ++ssrc; |
| 2937 | } |
| 2938 | } |
| 2939 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2940 | EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2941 | senders = pc_->GetSenders(); |
| 2942 | EXPECT_EQ(2u, senders.size()); |
| 2943 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2944 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2945 | // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC |
| 2946 | // changed. |
| 2947 | } |
| 2948 | |
| 2949 | // This tests that the expected behavior occurs if a new session description is |
| 2950 | // set with the same tracks, but on a different MediaStream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2951 | // Don't run under Unified Plan since the stream API is not available. |
| 2952 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 2953 | SignalSameTracksInSeparateMediaStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2954 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2955 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2956 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2957 | rtc::scoped_refptr<StreamCollection> stream_collection = |
| 2958 | CreateStreamCollection(2, 1); |
| 2959 | pc_->AddStream(stream_collection->at(0)); |
| 2960 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 2961 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2962 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2963 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2964 | auto senders = pc_->GetSenders(); |
| 2965 | EXPECT_EQ(2u, senders.size()); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2966 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0])); |
| 2967 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0])); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2968 | |
| 2969 | // Add a new MediaStream but with the same tracks as in the first stream. |
| 2970 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1( |
| 2971 | webrtc::MediaStream::Create(kStreams[1])); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 2972 | stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0].get()); |
| 2973 | stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0].get()); |
| 2974 | pc_->AddStream(stream_1.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2975 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2976 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2977 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2978 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2979 | auto new_senders = pc_->GetSenders(); |
| 2980 | // Should be the same senders as before, but with updated stream id. |
| 2981 | // Note that this behavior is subject to change in the future. |
| 2982 | // We may decide the PC should ignore existing tracks in AddStream. |
| 2983 | EXPECT_EQ(senders, new_senders); |
| 2984 | EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); |
| 2985 | EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 2988 | // This tests that PeerConnectionObserver::OnAddTrack is correctly called. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2989 | TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2990 | RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2991 | CreatePeerConnection(config); |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 2992 | CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly); |
| 2993 | EXPECT_EQ(observer_.num_added_tracks_, 1); |
| 2994 | EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]); |
| 2995 | |
| 2996 | // Create and set the updated remote SDP. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2997 | CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB); |
Steve Anton | 0f5400a | 2018-07-17 14:25:36 -0700 | [diff] [blame] | 2998 | EXPECT_EQ(observer_.num_added_tracks_, 2); |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 2999 | EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]); |
| 3000 | } |
| 3001 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3002 | // Test that when SetConfiguration is called and the configuration is |
| 3003 | // changing, the next offer causes an ICE restart. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3004 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) { |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3005 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 3006 | config.sdp_semantics = sdp_semantics_; |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3007 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3008 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3009 | config = pc_->GetConfiguration(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 3010 | AddAudioTrack(kAudioTracks[0], {kStreamId1}); |
| 3011 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3012 | |
| 3013 | // Do initial offer/answer so there's something to restart. |
| 3014 | CreateOfferAsLocalDescription(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3015 | CreateAnswerAsRemoteDescription(GetSdpStringWithStream1()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3016 | |
| 3017 | // Grab the ufrags. |
| 3018 | std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); |
| 3019 | |
| 3020 | // Change ICE policy, which should trigger an ICE restart on the next offer. |
| 3021 | config.type = PeerConnectionInterface::kAll; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 3022 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3023 | CreateOfferAsLocalDescription(); |
| 3024 | |
| 3025 | // Grab the new ufrags. |
| 3026 | std::vector<std::string> subsequent_ufrags = |
| 3027 | GetUfrags(pc_->local_description()); |
| 3028 | |
| 3029 | // Sanity check. |
| 3030 | EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size()); |
| 3031 | // Check that each ufrag is different. |
| 3032 | for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) { |
| 3033 | EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]); |
| 3034 | } |
| 3035 | } |
| 3036 | |
| 3037 | // Test that when SetConfiguration is called and the configuration *isn't* |
| 3038 | // changing, the next offer does *not* cause an ICE restart. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3039 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) { |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3040 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 3041 | config.sdp_semantics = sdp_semantics_; |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3042 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3043 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3044 | config = pc_->GetConfiguration(); |
| 3045 | AddAudioTrack(kAudioTracks[0]); |
| 3046 | AddVideoTrack(kVideoTracks[0]); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3047 | |
| 3048 | // Do initial offer/answer so there's something to restart. |
| 3049 | CreateOfferAsLocalDescription(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3050 | CreateAnswerAsRemoteDescription(GetSdpStringWithStream1()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3051 | |
| 3052 | // Grab the ufrags. |
| 3053 | std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); |
| 3054 | |
| 3055 | // Call SetConfiguration with a config identical to what the PC was |
| 3056 | // constructed with. |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 3057 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3058 | CreateOfferAsLocalDescription(); |
| 3059 | |
| 3060 | // Grab the new ufrags. |
| 3061 | std::vector<std::string> subsequent_ufrags = |
| 3062 | GetUfrags(pc_->local_description()); |
| 3063 | |
| 3064 | EXPECT_EQ(initial_ufrags, subsequent_ufrags); |
| 3065 | } |
| 3066 | |
| 3067 | // Test for a weird corner case scenario: |
| 3068 | // 1. Audio/video session established. |
| 3069 | // 2. SetConfiguration changes ICE config; ICE restart needed. |
| 3070 | // 3. ICE restart initiated by remote peer, but only for one m= section. |
| 3071 | // 4. Next createOffer should initiate an ICE restart, but only for the other |
| 3072 | // m= section; it would be pointless to do an ICE restart for the m= section |
| 3073 | // that was already restarted. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3074 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) { |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3075 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 3076 | config.sdp_semantics = sdp_semantics_; |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3077 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3078 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3079 | config = pc_->GetConfiguration(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 3080 | AddAudioTrack(kAudioTracks[0], {kStreamId1}); |
| 3081 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3082 | |
| 3083 | // Do initial offer/answer so there's something to restart. |
| 3084 | CreateOfferAsLocalDescription(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3085 | CreateAnswerAsRemoteDescription(GetSdpStringWithStream1()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3086 | |
| 3087 | // Change ICE policy, which should set the "needs-ice-restart" flag. |
| 3088 | config.type = PeerConnectionInterface::kAll; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 3089 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3090 | |
| 3091 | // Do ICE restart for the first m= section, initiated by remote peer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3092 | std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3093 | webrtc::CreateSessionDescription(SdpType::kOffer, |
| 3094 | GetSdpStringWithStream1(), nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3095 | ASSERT_TRUE(remote_offer); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3096 | remote_offer->description()->transport_infos()[0].description.ice_ufrag = |
| 3097 | "modified"; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3098 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3099 | CreateAnswerAsLocalDescription(); |
| 3100 | |
| 3101 | // Grab the ufrags. |
| 3102 | std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3103 | ASSERT_EQ(2U, initial_ufrags.size()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3104 | |
| 3105 | // Create offer and grab the new ufrags. |
| 3106 | CreateOfferAsLocalDescription(); |
| 3107 | std::vector<std::string> subsequent_ufrags = |
| 3108 | GetUfrags(pc_->local_description()); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3109 | ASSERT_EQ(2U, subsequent_ufrags.size()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3110 | |
| 3111 | // Ensure that only the ufrag for the second m= section changed. |
| 3112 | EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]); |
| 3113 | EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]); |
| 3114 | } |
| 3115 | |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3116 | // Tests that the methods to return current/pending descriptions work as |
| 3117 | // expected at different points in the offer/answer exchange. This test does |
| 3118 | // one offer/answer exchange as the offerer, then another as the answerer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3119 | TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3120 | // This disables DTLS so we can apply an answer to ourselves. |
| 3121 | CreatePeerConnection(); |
| 3122 | |
| 3123 | // Create initial local offer and get SDP (which will also be used as |
| 3124 | // answer/pranswer); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3125 | std::unique_ptr<SessionDescriptionInterface> local_offer; |
| 3126 | ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr)); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3127 | std::string sdp; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3128 | EXPECT_TRUE(local_offer->ToString(&sdp)); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3129 | |
| 3130 | // Set local offer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3131 | SessionDescriptionInterface* local_offer_ptr = local_offer.get(); |
| 3132 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer))); |
| 3133 | EXPECT_EQ(local_offer_ptr, pc_->pending_local_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3134 | EXPECT_EQ(nullptr, pc_->pending_remote_description()); |
| 3135 | EXPECT_EQ(nullptr, pc_->current_local_description()); |
| 3136 | EXPECT_EQ(nullptr, pc_->current_remote_description()); |
| 3137 | |
| 3138 | // Set remote pranswer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3139 | std::unique_ptr<SessionDescriptionInterface> remote_pranswer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3140 | webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3141 | SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get(); |
| 3142 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer))); |
| 3143 | EXPECT_EQ(local_offer_ptr, pc_->pending_local_description()); |
| 3144 | EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3145 | EXPECT_EQ(nullptr, pc_->current_local_description()); |
| 3146 | EXPECT_EQ(nullptr, pc_->current_remote_description()); |
| 3147 | |
| 3148 | // Set remote answer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3149 | std::unique_ptr<SessionDescriptionInterface> remote_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3150 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3151 | SessionDescriptionInterface* remote_answer_ptr = remote_answer.get(); |
| 3152 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer))); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3153 | EXPECT_EQ(nullptr, pc_->pending_local_description()); |
| 3154 | EXPECT_EQ(nullptr, pc_->pending_remote_description()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3155 | EXPECT_EQ(local_offer_ptr, pc_->current_local_description()); |
| 3156 | EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3157 | |
| 3158 | // Set remote offer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3159 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3160 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3161 | SessionDescriptionInterface* remote_offer_ptr = remote_offer.get(); |
| 3162 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
| 3163 | EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3164 | EXPECT_EQ(nullptr, pc_->pending_local_description()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3165 | EXPECT_EQ(local_offer_ptr, pc_->current_local_description()); |
| 3166 | EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3167 | |
| 3168 | // Set local pranswer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3169 | std::unique_ptr<SessionDescriptionInterface> local_pranswer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3170 | webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3171 | SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get(); |
| 3172 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer))); |
| 3173 | EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description()); |
| 3174 | EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description()); |
| 3175 | EXPECT_EQ(local_offer_ptr, pc_->current_local_description()); |
| 3176 | EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3177 | |
| 3178 | // Set local answer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3179 | std::unique_ptr<SessionDescriptionInterface> local_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3180 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3181 | SessionDescriptionInterface* local_answer_ptr = local_answer.get(); |
| 3182 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer))); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3183 | EXPECT_EQ(nullptr, pc_->pending_remote_description()); |
| 3184 | EXPECT_EQ(nullptr, pc_->pending_local_description()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3185 | EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description()); |
| 3186 | EXPECT_EQ(local_answer_ptr, pc_->current_local_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3187 | } |
| 3188 | |
zhihuang | 7798501 | 2017-02-07 15:45:16 -0800 | [diff] [blame] | 3189 | // Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog |
| 3190 | // after the PeerConnection is closed. |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 3191 | // This version tests the StartRtcEventLog version that receives an object |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 3192 | // of type `RtcEventLogOutput`. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3193 | TEST_P(PeerConnectionInterfaceTest, |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 3194 | StartAndStopLoggingToOutputAfterPeerConnectionClosed) { |
| 3195 | CreatePeerConnection(); |
| 3196 | // The RtcEventLog will be reset when the PeerConnection is closed. |
| 3197 | pc_->Close(); |
| 3198 | |
Niels Möller | dec9f74 | 2019-06-03 15:25:20 +0200 | [diff] [blame] | 3199 | EXPECT_FALSE( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 3200 | pc_->StartRtcEventLog(std::make_unique<webrtc::RtcEventLogOutputNull>(), |
Niels Möller | dec9f74 | 2019-06-03 15:25:20 +0200 | [diff] [blame] | 3201 | webrtc::RtcEventLog::kImmediateOutput)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 3202 | pc_->StopRtcEventLog(); |
| 3203 | } |
| 3204 | |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3205 | // Test that generated offers/answers include "ice-option:trickle". |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3206 | TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) { |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3207 | CreatePeerConnection(); |
| 3208 | |
| 3209 | // First, create an offer with audio/video. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3210 | RTCOfferAnswerOptions options; |
| 3211 | options.offer_to_receive_audio = 1; |
| 3212 | options.offer_to_receive_video = 1; |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3213 | std::unique_ptr<SessionDescriptionInterface> offer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3214 | ASSERT_TRUE(DoCreateOffer(&offer, &options)); |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3215 | cricket::SessionDescription* desc = offer->description(); |
| 3216 | ASSERT_EQ(2u, desc->transport_infos().size()); |
| 3217 | EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle")); |
| 3218 | EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle")); |
| 3219 | |
| 3220 | // Apply the offer as a remote description, then create an answer. |
Harald Alvestrand | 61f74d9 | 2020-03-02 11:20:00 +0100 | [diff] [blame] | 3221 | EXPECT_FALSE(pc_->can_trickle_ice_candidates()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3222 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
Harald Alvestrand | 61f74d9 | 2020-03-02 11:20:00 +0100 | [diff] [blame] | 3223 | ASSERT_TRUE(pc_->can_trickle_ice_candidates()); |
| 3224 | EXPECT_TRUE(*(pc_->can_trickle_ice_candidates())); |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3225 | std::unique_ptr<SessionDescriptionInterface> answer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3226 | ASSERT_TRUE(DoCreateAnswer(&answer, &options)); |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3227 | desc = answer->description(); |
| 3228 | ASSERT_EQ(2u, desc->transport_infos().size()); |
| 3229 | EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle")); |
| 3230 | EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle")); |
| 3231 | } |
| 3232 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3233 | // Test that ICE renomination isn't offered if it's not enabled in the PC's |
| 3234 | // RTCConfiguration. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3235 | TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3236 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 3237 | config.sdp_semantics = sdp_semantics_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3238 | config.enable_ice_renomination = false; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3239 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3240 | AddAudioTrack("foo"); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3241 | |
| 3242 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3243 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3244 | cricket::SessionDescription* desc = offer->description(); |
| 3245 | EXPECT_EQ(1u, desc->transport_infos().size()); |
| 3246 | EXPECT_FALSE( |
| 3247 | desc->transport_infos()[0].description.GetIceParameters().renomination); |
| 3248 | } |
| 3249 | |
| 3250 | // Test that the ICE renomination option is present in generated offers/answers |
| 3251 | // if it's enabled in the PC's RTCConfiguration. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3252 | TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3253 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 3254 | config.sdp_semantics = sdp_semantics_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3255 | config.enable_ice_renomination = true; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3256 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3257 | AddAudioTrack("foo"); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3258 | |
| 3259 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3260 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3261 | cricket::SessionDescription* desc = offer->description(); |
| 3262 | EXPECT_EQ(1u, desc->transport_infos().size()); |
| 3263 | EXPECT_TRUE( |
| 3264 | desc->transport_infos()[0].description.GetIceParameters().renomination); |
| 3265 | |
| 3266 | // Set the offer as a remote description, then create an answer and ensure it |
| 3267 | // has the renomination flag too. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3268 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3269 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 3270 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
| 3271 | desc = answer->description(); |
| 3272 | EXPECT_EQ(1u, desc->transport_infos().size()); |
| 3273 | EXPECT_TRUE( |
| 3274 | desc->transport_infos()[0].description.GetIceParameters().renomination); |
| 3275 | } |
| 3276 | |
| 3277 | // Test that if CreateOffer is called with the deprecated "offer to receive |
| 3278 | // audio/video" constraints, they're processed and result in an offer with |
| 3279 | // audio/video sections just as if RTCOfferAnswerOptions had been used. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3280 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3281 | CreatePeerConnection(); |
| 3282 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3283 | RTCOfferAnswerOptions options; |
| 3284 | options.offer_to_receive_audio = 1; |
| 3285 | options.offer_to_receive_video = 1; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3286 | std::unique_ptr<SessionDescriptionInterface> offer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3287 | ASSERT_TRUE(DoCreateOffer(&offer, &options)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3288 | |
| 3289 | cricket::SessionDescription* desc = offer->description(); |
| 3290 | const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc); |
| 3291 | const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc); |
| 3292 | ASSERT_NE(nullptr, audio); |
| 3293 | ASSERT_NE(nullptr, video); |
| 3294 | EXPECT_FALSE(audio->rejected); |
| 3295 | EXPECT_FALSE(video->rejected); |
| 3296 | } |
| 3297 | |
| 3298 | // Test that if CreateAnswer is called with the deprecated "offer to receive |
| 3299 | // audio/video" constraints, they're processed and can be used to reject an |
| 3300 | // offered m= section just as can be done with RTCOfferAnswerOptions; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3301 | // Don't run under Unified Plan since this behavior is not supported. |
| 3302 | TEST_F(PeerConnectionInterfaceTestPlanB, |
| 3303 | CreateAnswerWithOfferToReceiveConstraints) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3304 | CreatePeerConnection(); |
| 3305 | |
| 3306 | // First, create an offer with audio/video and apply it as a remote |
| 3307 | // description. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3308 | RTCOfferAnswerOptions options; |
| 3309 | options.offer_to_receive_audio = 1; |
| 3310 | options.offer_to_receive_video = 1; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3311 | std::unique_ptr<SessionDescriptionInterface> offer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3312 | ASSERT_TRUE(DoCreateOffer(&offer, &options)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3313 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3314 | |
| 3315 | // Now create answer that rejects audio/video. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3316 | options.offer_to_receive_audio = 0; |
| 3317 | options.offer_to_receive_video = 0; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3318 | std::unique_ptr<SessionDescriptionInterface> answer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3319 | ASSERT_TRUE(DoCreateAnswer(&answer, &options)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3320 | |
| 3321 | cricket::SessionDescription* desc = answer->description(); |
| 3322 | const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc); |
| 3323 | const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc); |
| 3324 | ASSERT_NE(nullptr, audio); |
| 3325 | ASSERT_NE(nullptr, video); |
| 3326 | EXPECT_TRUE(audio->rejected); |
| 3327 | EXPECT_TRUE(video->rejected); |
| 3328 | } |
| 3329 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3330 | // Test that negotiation can succeed with a data channel only, and with the max |
| 3331 | // bundle policy. Previously there was a bug that prevented this. |
Mirko Bonadei | 5eb43b4 | 2021-01-18 13:24:40 +0100 | [diff] [blame] | 3332 | #ifdef WEBRTC_HAVE_SCTP |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3333 | TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) { |
| 3334 | #else |
| 3335 | TEST_P(PeerConnectionInterfaceTest, |
| 3336 | DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) { |
Mirko Bonadei | 5eb43b4 | 2021-01-18 13:24:40 +0100 | [diff] [blame] | 3337 | #endif // WEBRTC_HAVE_SCTP |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3338 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 3339 | config.sdp_semantics = sdp_semantics_; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3340 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3341 | CreatePeerConnection(config); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3342 | |
| 3343 | // First, create an offer with only a data channel and apply it as a remote |
| 3344 | // description. |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 3345 | pc_->CreateDataChannelOrError("test", nullptr); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3346 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3347 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3348 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3349 | |
| 3350 | // Create and set answer as well. |
| 3351 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 3352 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3353 | EXPECT_TRUE(DoSetLocalDescription(std::move(answer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3356 | TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3357 | CreatePeerConnection(); |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 3358 | BitrateSettings bitrate; |
| 3359 | bitrate.start_bitrate_bps = 100000; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3360 | EXPECT_TRUE(pc_->SetBitrate(bitrate).ok()); |
| 3361 | } |
| 3362 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3363 | TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3364 | CreatePeerConnection(); |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 3365 | BitrateSettings bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3366 | bitrate.min_bitrate_bps = -1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3367 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3368 | } |
| 3369 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3370 | TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3371 | CreatePeerConnection(); |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 3372 | BitrateSettings bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3373 | bitrate.min_bitrate_bps = 5; |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 3374 | bitrate.start_bitrate_bps = 3; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3375 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3376 | } |
| 3377 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3378 | TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3379 | CreatePeerConnection(); |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 3380 | BitrateSettings bitrate; |
| 3381 | bitrate.start_bitrate_bps = -1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3382 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3383 | } |
| 3384 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3385 | TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3386 | CreatePeerConnection(); |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 3387 | BitrateSettings bitrate; |
| 3388 | bitrate.start_bitrate_bps = 10; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3389 | bitrate.max_bitrate_bps = 8; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3390 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3391 | } |
| 3392 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3393 | TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3394 | CreatePeerConnection(); |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 3395 | BitrateSettings bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3396 | bitrate.min_bitrate_bps = 10; |
| 3397 | bitrate.max_bitrate_bps = 8; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3398 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3399 | } |
| 3400 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3401 | TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3402 | CreatePeerConnection(); |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 3403 | BitrateSettings bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3404 | bitrate.max_bitrate_bps = -1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3405 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3406 | } |
| 3407 | |
Niels Möller | 0c4f7be | 2018-05-07 14:01:37 +0200 | [diff] [blame] | 3408 | // The current bitrate from BitrateSettings is currently clamped |
Sebastian Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame] | 3409 | // by Call's BitrateConstraints, which comes from the SDP or a default value. |
| 3410 | // This test checks that a call to SetBitrate with a current bitrate that will |
| 3411 | // be clamped succeeds. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3412 | TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3413 | CreatePeerConnection(); |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 3414 | BitrateSettings bitrate; |
| 3415 | bitrate.start_bitrate_bps = 1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3416 | EXPECT_TRUE(pc_->SetBitrate(bitrate).ok()); |
| 3417 | } |
| 3418 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3419 | // The following tests verify that the offer can be created correctly. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3420 | TEST_P(PeerConnectionInterfaceTest, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3421 | CreateOfferFailsWithInvalidOfferToReceiveAudio) { |
| 3422 | RTCOfferAnswerOptions rtc_options; |
| 3423 | |
| 3424 | // Setting offer_to_receive_audio to a value lower than kUndefined or greater |
| 3425 | // than kMaxOfferToReceiveMedia should be treated as invalid. |
| 3426 | rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1; |
| 3427 | CreatePeerConnection(); |
| 3428 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3429 | |
| 3430 | rtc_options.offer_to_receive_audio = |
| 3431 | RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; |
| 3432 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3433 | } |
| 3434 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3435 | TEST_P(PeerConnectionInterfaceTest, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3436 | CreateOfferFailsWithInvalidOfferToReceiveVideo) { |
| 3437 | RTCOfferAnswerOptions rtc_options; |
| 3438 | |
| 3439 | // Setting offer_to_receive_video to a value lower than kUndefined or greater |
| 3440 | // than kMaxOfferToReceiveMedia should be treated as invalid. |
| 3441 | rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1; |
| 3442 | CreatePeerConnection(); |
| 3443 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3444 | |
| 3445 | rtc_options.offer_to_receive_video = |
| 3446 | RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; |
| 3447 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3448 | } |
| 3449 | |
| 3450 | // Test that the audio and video content will be added to an offer if both |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 3451 | // `offer_to_receive_audio` and `offer_to_receive_video` options are 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3452 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3453 | RTCOfferAnswerOptions rtc_options; |
| 3454 | rtc_options.offer_to_receive_audio = 1; |
| 3455 | rtc_options.offer_to_receive_video = 1; |
| 3456 | |
| 3457 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3458 | CreatePeerConnection(); |
| 3459 | offer = CreateOfferWithOptions(rtc_options); |
| 3460 | ASSERT_TRUE(offer); |
| 3461 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3462 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3463 | } |
| 3464 | |
| 3465 | // Test that only audio content will be added to the offer if only |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 3466 | // `offer_to_receive_audio` options is 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3467 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3468 | RTCOfferAnswerOptions rtc_options; |
| 3469 | rtc_options.offer_to_receive_audio = 1; |
| 3470 | rtc_options.offer_to_receive_video = 0; |
| 3471 | |
| 3472 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3473 | CreatePeerConnection(); |
| 3474 | offer = CreateOfferWithOptions(rtc_options); |
| 3475 | ASSERT_TRUE(offer); |
| 3476 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3477 | EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description())); |
| 3478 | } |
| 3479 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 3480 | // Test that only video content will be added if only `offer_to_receive_video` |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3481 | // options is 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3482 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3483 | RTCOfferAnswerOptions rtc_options; |
| 3484 | rtc_options.offer_to_receive_audio = 0; |
| 3485 | rtc_options.offer_to_receive_video = 1; |
| 3486 | |
| 3487 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3488 | CreatePeerConnection(); |
| 3489 | offer = CreateOfferWithOptions(rtc_options); |
| 3490 | ASSERT_TRUE(offer); |
| 3491 | EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description())); |
| 3492 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3493 | } |
| 3494 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3495 | // Test that no media content will be added to the offer if using default |
| 3496 | // RTCOfferAnswerOptions. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3497 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3498 | RTCOfferAnswerOptions rtc_options; |
| 3499 | |
| 3500 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3501 | CreatePeerConnection(); |
| 3502 | offer = CreateOfferWithOptions(rtc_options); |
| 3503 | ASSERT_TRUE(offer); |
| 3504 | EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description())); |
| 3505 | EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description())); |
| 3506 | } |
| 3507 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 3508 | // Test that if `ice_restart` is true, the ufrag/pwd will change, otherwise |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3509 | // ufrag/pwd will be the same in the new offer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3510 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) { |
| 3511 | CreatePeerConnection(); |
| 3512 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3513 | RTCOfferAnswerOptions rtc_options; |
| 3514 | rtc_options.ice_restart = false; |
| 3515 | rtc_options.offer_to_receive_audio = 1; |
| 3516 | |
| 3517 | std::unique_ptr<SessionDescriptionInterface> offer; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3518 | CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3519 | std::string mid = cricket::GetFirstAudioContent(offer->description())->name; |
| 3520 | auto ufrag1 = |
| 3521 | offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag; |
| 3522 | auto pwd1 = |
| 3523 | offer->description()->GetTransportInfoByName(mid)->description.ice_pwd; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3524 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 3525 | // `ice_restart` is false, the ufrag/pwd shouldn't change. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3526 | CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3527 | auto ufrag2 = |
| 3528 | offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag; |
| 3529 | auto pwd2 = |
| 3530 | offer->description()->GetTransportInfoByName(mid)->description.ice_pwd; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3531 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 3532 | // `ice_restart` is true, the ufrag/pwd should change. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3533 | rtc_options.ice_restart = true; |
| 3534 | CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3535 | auto ufrag3 = |
| 3536 | offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag; |
| 3537 | auto pwd3 = |
| 3538 | offer->description()->GetTransportInfoByName(mid)->description.ice_pwd; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3539 | |
| 3540 | EXPECT_EQ(ufrag1, ufrag2); |
| 3541 | EXPECT_EQ(pwd1, pwd2); |
| 3542 | EXPECT_NE(ufrag2, ufrag3); |
| 3543 | EXPECT_NE(pwd2, pwd3); |
| 3544 | } |
| 3545 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 3546 | // Test that if `use_rtp_mux` is true, the bundling will be enabled in the |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3547 | // offer; if it is false, there won't be any bundle group in the offer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3548 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3549 | RTCOfferAnswerOptions rtc_options; |
| 3550 | rtc_options.offer_to_receive_audio = 1; |
| 3551 | rtc_options.offer_to_receive_video = 1; |
| 3552 | |
| 3553 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3554 | CreatePeerConnection(); |
| 3555 | |
| 3556 | rtc_options.use_rtp_mux = true; |
| 3557 | offer = CreateOfferWithOptions(rtc_options); |
| 3558 | ASSERT_TRUE(offer); |
| 3559 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3560 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3561 | EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE)); |
| 3562 | |
| 3563 | rtc_options.use_rtp_mux = false; |
| 3564 | offer = CreateOfferWithOptions(rtc_options); |
| 3565 | ASSERT_TRUE(offer); |
| 3566 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3567 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3568 | EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE)); |
| 3569 | } |
| 3570 | |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3571 | // This test ensures OnRenegotiationNeeded is called when we add track with |
| 3572 | // MediaStream -> AddTrack in the same way it is called when we add track with |
| 3573 | // PeerConnection -> AddTrack. |
| 3574 | // The test can be removed once addStream is rewritten in terms of addTrack |
| 3575 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=7815 |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3576 | // Don't run under Unified Plan since the stream API is not available. |
| 3577 | TEST_F(PeerConnectionInterfaceTestPlanB, |
| 3578 | MediaStreamAddTrackRemoveTrackRenegotiate) { |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3579 | CreatePeerConnectionWithoutDtls(); |
| 3580 | rtc::scoped_refptr<MediaStreamInterface> stream( |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 3581 | pc_factory_->CreateLocalMediaStream(kStreamId1)); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 3582 | pc_->AddStream(stream.get()); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3583 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 3584 | CreateAudioTrack("audio_track")); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3585 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 3586 | CreateVideoTrack("video_track")); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 3587 | stream->AddTrack(audio_track.get()); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3588 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3589 | observer_.renegotiation_needed_ = false; |
| 3590 | |
Guido Urdaneta | 70c2db1 | 2019-04-16 12:24:14 +0200 | [diff] [blame] | 3591 | CreateOfferReceiveAnswer(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 3592 | stream->AddTrack(video_track.get()); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3593 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3594 | observer_.renegotiation_needed_ = false; |
| 3595 | |
Guido Urdaneta | 70c2db1 | 2019-04-16 12:24:14 +0200 | [diff] [blame] | 3596 | CreateOfferReceiveAnswer(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 3597 | stream->RemoveTrack(audio_track.get()); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3598 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3599 | observer_.renegotiation_needed_ = false; |
| 3600 | |
Guido Urdaneta | 70c2db1 | 2019-04-16 12:24:14 +0200 | [diff] [blame] | 3601 | CreateOfferReceiveAnswer(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 3602 | stream->RemoveTrack(video_track.get()); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3603 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3604 | observer_.renegotiation_needed_ = false; |
| 3605 | } |
| 3606 | |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3607 | // Tests that an error is returned if a description is applied that has fewer |
| 3608 | // media sections than the existing description. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3609 | TEST_P(PeerConnectionInterfaceTest, |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3610 | MediaSectionCountEnforcedForSubsequentOffer) { |
| 3611 | CreatePeerConnection(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3612 | AddAudioTrack("audio_label"); |
| 3613 | AddVideoTrack("video_label"); |
| 3614 | |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3615 | std::unique_ptr<SessionDescriptionInterface> offer; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3616 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3617 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
| 3618 | |
| 3619 | // A remote offer with fewer media sections should be rejected. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3620 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3621 | offer->description()->contents().pop_back(); |
| 3622 | offer->description()->contents().pop_back(); |
| 3623 | ASSERT_TRUE(offer->description()->contents().empty()); |
| 3624 | EXPECT_FALSE(DoSetRemoteDescription(std::move(offer))); |
| 3625 | |
| 3626 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 3627 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
| 3628 | EXPECT_TRUE(DoSetLocalDescription(std::move(answer))); |
| 3629 | |
| 3630 | // A subsequent local offer with fewer media sections should be rejected. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3631 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3632 | offer->description()->contents().pop_back(); |
| 3633 | offer->description()->contents().pop_back(); |
| 3634 | ASSERT_TRUE(offer->description()->contents().empty()); |
| 3635 | EXPECT_FALSE(DoSetLocalDescription(std::move(offer))); |
| 3636 | } |
| 3637 | |
Johannes Kron | 89f874e | 2018-11-12 10:25:48 +0100 | [diff] [blame] | 3638 | TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) { |
| 3639 | RTCConfiguration config; |
Emil Lundmark | 801c999 | 2021-01-19 13:06:32 +0100 | [diff] [blame] | 3640 | // Default behavior is true. |
Johannes Kron | 89f874e | 2018-11-12 10:25:48 +0100 | [diff] [blame] | 3641 | CreatePeerConnection(config); |
| 3642 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3643 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Emil Lundmark | 801c999 | 2021-01-19 13:06:32 +0100 | [diff] [blame] | 3644 | EXPECT_TRUE(offer->description()->extmap_allow_mixed()); |
| 3645 | // Possible to set to false. |
| 3646 | config.offer_extmap_allow_mixed = false; |
Johannes Kron | 89f874e | 2018-11-12 10:25:48 +0100 | [diff] [blame] | 3647 | CreatePeerConnection(config); |
Artem Titov | 4f3a2eb | 2021-01-26 09:58:21 +0100 | [diff] [blame] | 3648 | offer = nullptr; |
Johannes Kron | 89f874e | 2018-11-12 10:25:48 +0100 | [diff] [blame] | 3649 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Emil Lundmark | 801c999 | 2021-01-19 13:06:32 +0100 | [diff] [blame] | 3650 | EXPECT_FALSE(offer->description()->extmap_allow_mixed()); |
Johannes Kron | 89f874e | 2018-11-12 10:25:48 +0100 | [diff] [blame] | 3651 | } |
| 3652 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 3653 | INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest, |
| 3654 | PeerConnectionInterfaceTest, |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 3655 | Values(SdpSemantics::kPlanB_DEPRECATED, |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 3656 | SdpSemantics::kUnifiedPlan)); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3657 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 3658 | class PeerConnectionMediaConfigTest : public ::testing::Test { |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3659 | protected: |
| 3660 | void SetUp() override { |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 3661 | pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest(); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3662 | } |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 3663 | const cricket::MediaConfig TestCreatePeerConnection( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3664 | const RTCConfiguration& config) { |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 3665 | PeerConnectionDependencies pc_dependencies(&observer_); |
| 3666 | auto result = |
| 3667 | pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies)); |
| 3668 | EXPECT_TRUE(result.ok()); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 3669 | observer_.SetPeerConnectionInterface(result.value().get()); |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 3670 | return result.value()->GetConfiguration().media_config; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3671 | } |
| 3672 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 3673 | rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3674 | MockPeerConnectionObserver observer_; |
| 3675 | }; |
| 3676 | |
Yves Gerey | f3ff14c | 2018-10-25 10:28:12 +0200 | [diff] [blame] | 3677 | // This sanity check validates the test infrastructure itself. |
| 3678 | TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) { |
| 3679 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 3680 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 3681 | PeerConnectionDependencies pc_dependencies(&observer_); |
| 3682 | auto result = |
| 3683 | pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies)); |
| 3684 | EXPECT_TRUE(result.ok()); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 3685 | observer_.SetPeerConnectionInterface(result.value().get()); |
Florent Castelli | 7242440 | 2022-04-06 03:45:10 +0200 | [diff] [blame] | 3686 | result.value()->Close(); // No abort -> ok. |
Yves Gerey | f3ff14c | 2018-10-25 10:28:12 +0200 | [diff] [blame] | 3687 | SUCCEED(); |
| 3688 | } |
| 3689 | |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3690 | // This test verifies the default behaviour with no constraints and a |
| 3691 | // default RTCConfiguration. |
| 3692 | TEST_F(PeerConnectionMediaConfigTest, TestDefaults) { |
| 3693 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 3694 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3695 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3696 | const cricket::MediaConfig& media_config = TestCreatePeerConnection(config); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3697 | |
Henrik Boström | 35c5cc8 | 2022-04-14 09:23:20 +0200 | [diff] [blame] | 3698 | EXPECT_TRUE(media_config.enable_dscp); |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3699 | EXPECT_TRUE(media_config.video.enable_cpu_adaptation); |
| 3700 | EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 3701 | EXPECT_FALSE(media_config.video.suspend_below_min_bitrate); |
Niels Möller | 6539f69 | 2018-01-18 08:58:50 +0100 | [diff] [blame] | 3702 | EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3703 | } |
| 3704 | |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3705 | // This test verifies that the enable_prerenderer_smoothing flag is |
nisse | 528b793 | 2017-05-08 03:21:43 -0700 | [diff] [blame] | 3706 | // propagated from RTCConfiguration to the PeerConnection. |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3707 | TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) { |
| 3708 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 3709 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3710 | |
Niels Möller | 71bdda0 | 2016-03-31 12:59:59 +0200 | [diff] [blame] | 3711 | config.set_prerenderer_smoothing(false); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3712 | const cricket::MediaConfig& media_config = TestCreatePeerConnection(config); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3713 | |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3714 | EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 3715 | } |
| 3716 | |
Niels Möller | 6539f69 | 2018-01-18 08:58:50 +0100 | [diff] [blame] | 3717 | // This test verifies that the experiment_cpu_load_estimator flag is |
| 3718 | // propagated from RTCConfiguration to the PeerConnection. |
| 3719 | TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) { |
| 3720 | PeerConnectionInterface::RTCConfiguration config; |
Henrik Boström | 62995db | 2022-01-03 09:58:10 +0100 | [diff] [blame] | 3721 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Niels Möller | 6539f69 | 2018-01-18 08:58:50 +0100 | [diff] [blame] | 3722 | |
| 3723 | config.set_experiment_cpu_load_estimator(true); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3724 | const cricket::MediaConfig& media_config = TestCreatePeerConnection(config); |
Niels Möller | 6539f69 | 2018-01-18 08:58:50 +0100 | [diff] [blame] | 3725 | |
| 3726 | EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator); |
| 3727 | } |
| 3728 | |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 3729 | // Tests a few random fields being different. |
| 3730 | TEST(RTCConfigurationTest, ComparisonOperators) { |
| 3731 | PeerConnectionInterface::RTCConfiguration a; |
| 3732 | PeerConnectionInterface::RTCConfiguration b; |
| 3733 | EXPECT_EQ(a, b); |
| 3734 | |
| 3735 | PeerConnectionInterface::RTCConfiguration c; |
| 3736 | c.servers.push_back(PeerConnectionInterface::IceServer()); |
| 3737 | EXPECT_NE(a, c); |
| 3738 | |
| 3739 | PeerConnectionInterface::RTCConfiguration d; |
| 3740 | d.type = PeerConnectionInterface::kRelay; |
| 3741 | EXPECT_NE(a, d); |
| 3742 | |
| 3743 | PeerConnectionInterface::RTCConfiguration e; |
| 3744 | e.audio_jitter_buffer_max_packets = 5; |
| 3745 | EXPECT_NE(a, e); |
| 3746 | |
| 3747 | PeerConnectionInterface::RTCConfiguration f; |
| 3748 | f.ice_connection_receiving_timeout = 1337; |
| 3749 | EXPECT_NE(a, f); |
| 3750 | |
| 3751 | PeerConnectionInterface::RTCConfiguration g; |
| 3752 | g.disable_ipv6 = true; |
| 3753 | EXPECT_NE(a, g); |
| 3754 | |
| 3755 | PeerConnectionInterface::RTCConfiguration h( |
| 3756 | PeerConnectionInterface::RTCConfigurationType::kAggressive); |
| 3757 | EXPECT_NE(a, h); |
| 3758 | } |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 3759 | |
| 3760 | } // namespace |
| 3761 | } // namespace webrtc |