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