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