OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/api/trackmediainfomap.h" | |
12 | |
13 #include <initializer_list> | |
14 #include <memory> | |
15 #include <utility> | |
16 #include <vector> | |
17 | |
18 #include "webrtc/api/audiotrack.h" | |
19 #include "webrtc/api/rtpreceiverinterface.h" | |
20 #include "webrtc/api/rtpsenderinterface.h" | |
21 #include "webrtc/api/test/fakertpsenderreceiver.h" | |
22 #include "webrtc/api/test/fakevideotracksource.h" | |
23 #include "webrtc/api/videotrack.h" | |
24 #include "webrtc/base/refcount.h" | |
25 #include "webrtc/media/base/mediachannel.h" | |
26 #include "webrtc/test/gtest.h" | |
27 | |
28 namespace webrtc { | |
29 | |
30 namespace { | |
31 | |
32 RtpParameters CreateRtpParametersWithSsrcs( | |
33 std::initializer_list<uint32_t> ssrcs) { | |
34 RtpParameters params; | |
35 for (uint32_t ssrc : ssrcs) { | |
36 RtpEncodingParameters encoding_params; | |
37 encoding_params.ssrc = rtc::Optional<uint32_t>(ssrc); | |
38 params.encodings.push_back(encoding_params); | |
39 } | |
40 return params; | |
41 } | |
42 | |
43 TrackMediaInfoMap CreateAndInitializeMap( | |
44 std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info, | |
45 std::unique_ptr<cricket::VideoMediaInfo> video_media_info, | |
46 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& rtp_senders, | |
47 const std::vector<rtc::scoped_refptr<RtpReceiverInterface>>& | |
48 rtp_receivers) { | |
49 TrackMediaInfoMap map(std::move(voice_media_info), | |
50 std::move(video_media_info)); | |
51 map.Initialize(rtp_senders, rtp_receivers); | |
52 return map; | |
53 } | |
54 | |
55 } // namespace | |
56 | |
57 TEST(TrackMediaInfoMapTest, SingleSenderAndReceiverWithOneSsrc) { | |
58 cricket::VoiceMediaInfo* voice_media_info = new cricket::VoiceMediaInfo(); | |
59 cricket::VideoMediaInfo* video_media_info = new cricket::VideoMediaInfo(); | |
60 std::vector<rtc::scoped_refptr<RtpSenderInterface>> rtp_senders; | |
61 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> rtp_receivers; | |
62 | |
63 // Local audio track and sender info using an RTP sender with SSRC 1. | |
64 rtc::scoped_refptr<AudioTrack> local_audio_track = | |
65 AudioTrack::Create("LocalAudioTrack", nullptr); | |
66 | |
67 rtc::scoped_refptr<FakeRtpSender> audio_sender = | |
68 new FakeRtpSender(cricket::MEDIA_TYPE_AUDIO, | |
69 CreateRtpParametersWithSsrcs({1})); | |
70 audio_sender->SetTrack(local_audio_track); | |
71 rtp_senders.push_back(audio_sender); | |
72 | |
73 voice_media_info->senders.push_back(cricket::VoiceSenderInfo()); | |
74 voice_media_info->senders[0].local_stats.push_back(cricket::SsrcSenderInfo()); | |
75 voice_media_info->senders[0].local_stats[0].ssrc = 1; | |
76 | |
77 // Remote audio track and receiver info using an RTP sender with SSRC 2. | |
78 rtc::scoped_refptr<AudioTrack> remote_audio_track = | |
79 AudioTrack::Create("RemoteAudioTrack", nullptr); | |
80 | |
81 rtc::scoped_refptr<FakeRtpReceiver> audio_receiver = | |
82 new FakeRtpReceiver(cricket::MEDIA_TYPE_AUDIO, | |
83 CreateRtpParametersWithSsrcs({2})); | |
84 audio_receiver->SetTrack(remote_audio_track); | |
85 rtp_receivers.push_back(audio_receiver); | |
86 | |
87 voice_media_info->receivers.push_back(cricket::VoiceReceiverInfo()); | |
88 voice_media_info->receivers[0].local_stats.push_back( | |
89 cricket::SsrcReceiverInfo()); | |
90 voice_media_info->receivers[0].local_stats[0].ssrc = 2; | |
91 | |
92 // Local video track and sender info using an RTP sender with SSRC 3. | |
93 rtc::scoped_refptr<VideoTrack> local_video_track = | |
94 VideoTrack::Create("LocalVideoTrack", | |
95 FakeVideoTrackSource::Create(false)); | |
96 | |
97 rtc::scoped_refptr<FakeRtpSender> video_sender = | |
98 new FakeRtpSender(cricket::MEDIA_TYPE_VIDEO, | |
99 CreateRtpParametersWithSsrcs({3})); | |
100 video_sender->SetTrack(local_video_track); | |
101 rtp_senders.push_back(video_sender); | |
102 | |
103 video_media_info->senders.push_back(cricket::VideoSenderInfo()); | |
104 video_media_info->senders[0].local_stats.push_back(cricket::SsrcSenderInfo()); | |
105 video_media_info->senders[0].local_stats[0].ssrc = 3; | |
106 | |
107 // Remote video track and receiver info using an RTP sender with SSRC 4. | |
108 rtc::scoped_refptr<VideoTrack> remote_video_track = | |
109 VideoTrack::Create("RemoteVideoTrack", | |
110 FakeVideoTrackSource::Create(false)); | |
111 | |
112 rtc::scoped_refptr<FakeRtpReceiver> video_receiver = | |
113 new FakeRtpReceiver(cricket::MEDIA_TYPE_VIDEO, | |
114 CreateRtpParametersWithSsrcs({4})); | |
115 video_receiver->SetTrack(remote_video_track); | |
116 rtp_receivers.push_back(video_receiver); | |
117 | |
118 video_media_info->receivers.push_back(cricket::VideoReceiverInfo()); | |
119 video_media_info->receivers[0].local_stats.push_back( | |
120 cricket::SsrcReceiverInfo()); | |
121 video_media_info->receivers[0].local_stats[0].ssrc = 4; | |
122 | |
123 TrackMediaInfoMap map = CreateAndInitializeMap( | |
124 std::unique_ptr<cricket::VoiceMediaInfo>(voice_media_info), | |
125 std::unique_ptr<cricket::VideoMediaInfo>(video_media_info), | |
126 rtp_senders, | |
127 rtp_receivers); | |
128 | |
129 // Local audio track <-> RTP audio sender | |
130 ASSERT_TRUE(map.GetVoiceSenderInfos(*local_audio_track)); | |
131 EXPECT_EQ(*map.GetVoiceSenderInfos(*local_audio_track), | |
132 std::vector<cricket::VoiceSenderInfo*>({ | |
133 &voice_media_info->senders[0] })); | |
134 EXPECT_EQ(map.GetAudioTrack(voice_media_info->senders[0]), | |
135 local_audio_track.get()); | |
136 | |
137 // Remote audio track <-> RTP audio receiver | |
138 EXPECT_EQ(map.GetVoiceReceiverInfo(*remote_audio_track), | |
139 &voice_media_info->receivers[0]); | |
140 EXPECT_EQ(map.GetAudioTrack(voice_media_info->receivers[0]), | |
141 remote_audio_track.get()); | |
142 | |
143 // Local video track <-> RTP video sender | |
144 ASSERT_TRUE(map.GetVideoSenderInfos(*local_video_track)); | |
145 EXPECT_EQ(*map.GetVideoSenderInfos(*local_video_track), | |
146 std::vector<cricket::VideoSenderInfo*>({ | |
147 &video_media_info->senders[0] })); | |
148 EXPECT_EQ(map.GetVideoTrack(video_media_info->senders[0]), | |
149 local_video_track.get()); | |
150 | |
151 // Remote video track <-> RTP video receiver | |
152 EXPECT_EQ(map.GetVideoReceiverInfo(*remote_video_track), | |
153 &video_media_info->receivers[0]); | |
154 EXPECT_EQ(map.GetVideoTrack(video_media_info->receivers[0]), | |
155 remote_video_track.get()); | |
156 } | |
157 | |
158 TEST(TrackMediaInfoMapTest, SingleSenderWithMissingSsrc) { | |
159 cricket::VoiceMediaInfo* voice_media_info = new cricket::VoiceMediaInfo(); | |
160 cricket::VideoMediaInfo* video_media_info = new cricket::VideoMediaInfo(); | |
161 std::vector<rtc::scoped_refptr<RtpSenderInterface>> rtp_senders; | |
162 | |
163 // Local audio track and sender info using an RTP sender without an SSRC. | |
164 rtc::scoped_refptr<AudioTrack> local_audio_track = | |
165 AudioTrack::Create("LocalAudioTrack", nullptr); | |
166 | |
167 rtc::scoped_refptr<FakeRtpSender> audio_sender = | |
168 new FakeRtpSender(cricket::MEDIA_TYPE_AUDIO, | |
169 CreateRtpParametersWithSsrcs({})); | |
170 audio_sender->SetTrack(local_audio_track); | |
171 rtp_senders.push_back(audio_sender); | |
172 | |
173 // Local video track and sender info using an RTP sender without an SSRC. | |
174 rtc::scoped_refptr<VideoTrack> local_video_track = | |
175 VideoTrack::Create("LocalVideoTrack", | |
176 FakeVideoTrackSource::Create(false)); | |
177 | |
178 rtc::scoped_refptr<FakeRtpSender> video_sender = | |
179 new FakeRtpSender(cricket::MEDIA_TYPE_VIDEO, | |
180 CreateRtpParametersWithSsrcs({})); | |
181 video_sender->SetTrack(local_video_track); | |
182 rtp_senders.push_back(video_sender); | |
183 | |
184 TrackMediaInfoMap map = CreateAndInitializeMap( | |
185 std::unique_ptr<cricket::VoiceMediaInfo>(voice_media_info), | |
186 std::unique_ptr<cricket::VideoMediaInfo>(video_media_info), | |
187 rtp_senders, | |
188 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>()); | |
189 | |
190 EXPECT_FALSE(map.GetVoiceSenderInfos(*local_audio_track)); | |
191 EXPECT_FALSE(map.GetVideoSenderInfos(*local_video_track)); | |
192 } | |
193 | |
194 TEST(TrackMediaInfoMapTest, SingleSenderWithMultipleSsrcs) { | |
195 cricket::VoiceMediaInfo* voice_media_info = new cricket::VoiceMediaInfo(); | |
196 cricket::VideoMediaInfo* video_media_info = new cricket::VideoMediaInfo(); | |
197 std::vector<rtc::scoped_refptr<RtpSenderInterface>> rtp_senders; | |
198 | |
199 // Local audio track and sender infos using RTP sender with SSRCs 1 and 2. | |
200 rtc::scoped_refptr<AudioTrack> local_audio_track = | |
201 AudioTrack::Create("LocalAudioTrack", nullptr); | |
202 | |
203 rtc::scoped_refptr<FakeRtpSender> audio_sender = | |
204 new FakeRtpSender(cricket::MEDIA_TYPE_AUDIO, | |
205 CreateRtpParametersWithSsrcs({1, 2})); | |
206 audio_sender->SetTrack(local_audio_track); | |
207 rtp_senders.push_back(audio_sender); | |
208 | |
209 voice_media_info->senders.push_back(cricket::VoiceSenderInfo()); | |
210 voice_media_info->senders[0].local_stats.push_back(cricket::SsrcSenderInfo()); | |
211 voice_media_info->senders[0].local_stats[0].ssrc = 1; | |
212 voice_media_info->senders.push_back(cricket::VoiceSenderInfo()); | |
213 voice_media_info->senders[1].local_stats.push_back(cricket::SsrcSenderInfo()); | |
214 voice_media_info->senders[1].local_stats[0].ssrc = 2; | |
215 | |
216 // Local video track and sender infos using RTP sender with SSRCs 3 and 4. | |
217 rtc::scoped_refptr<VideoTrack> local_video_track = | |
218 VideoTrack::Create("LocalVideoTrack", | |
219 FakeVideoTrackSource::Create(false)); | |
220 | |
221 rtc::scoped_refptr<FakeRtpSender> video_sender = | |
222 new FakeRtpSender(cricket::MEDIA_TYPE_VIDEO, | |
223 CreateRtpParametersWithSsrcs({3, 4})); | |
224 video_sender->SetTrack(local_video_track); | |
225 rtp_senders.push_back(video_sender); | |
226 | |
227 video_media_info->senders.push_back(cricket::VideoSenderInfo()); | |
hta-webrtc
2017/01/05 09:46:56
There's a ton of repeated code here.
Can you make
hbos
2017/01/05 15:27:56
Done.
| |
228 video_media_info->senders[0].local_stats.push_back(cricket::SsrcSenderInfo()); | |
229 video_media_info->senders[0].local_stats[0].ssrc = 3; | |
230 video_media_info->senders.push_back(cricket::VideoSenderInfo()); | |
231 video_media_info->senders[1].local_stats.push_back(cricket::SsrcSenderInfo()); | |
232 video_media_info->senders[1].local_stats[0].ssrc = 4; | |
233 | |
234 TrackMediaInfoMap map = CreateAndInitializeMap( | |
235 std::unique_ptr<cricket::VoiceMediaInfo>(voice_media_info), | |
236 std::unique_ptr<cricket::VideoMediaInfo>(video_media_info), | |
237 rtp_senders, | |
238 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>()); | |
239 | |
240 // Local audio track <-> RTP audio senders | |
241 ASSERT_TRUE(map.GetVoiceSenderInfos(*local_audio_track)); | |
242 EXPECT_EQ(*map.GetVoiceSenderInfos(*local_audio_track), | |
243 std::vector<cricket::VoiceSenderInfo*>({ | |
244 &voice_media_info->senders[0], | |
245 &voice_media_info->senders[1] })); | |
246 EXPECT_EQ(map.GetAudioTrack(voice_media_info->senders[0]), | |
247 local_audio_track.get()); | |
248 EXPECT_EQ(map.GetAudioTrack(voice_media_info->senders[1]), | |
249 local_audio_track.get()); | |
250 | |
251 // Local video track <-> RTP video senders | |
252 ASSERT_TRUE(map.GetVideoSenderInfos(*local_video_track)); | |
253 EXPECT_EQ(*map.GetVideoSenderInfos(*local_video_track), | |
254 std::vector<cricket::VideoSenderInfo*>({ | |
255 &video_media_info->senders[0], | |
256 &video_media_info->senders[1] })); | |
257 EXPECT_EQ(map.GetVideoTrack(video_media_info->senders[0]), | |
258 local_video_track.get()); | |
259 EXPECT_EQ(map.GetVideoTrack(video_media_info->senders[1]), | |
260 local_video_track.get()); | |
261 } | |
262 | |
263 TEST(TrackMediaInfoMapTest, MultipleSendersWithOneSsrc) { | |
264 cricket::VoiceMediaInfo* voice_media_info = new cricket::VoiceMediaInfo(); | |
265 cricket::VideoMediaInfo* video_media_info = new cricket::VideoMediaInfo(); | |
266 std::vector<rtc::scoped_refptr<RtpSenderInterface>> rtp_senders; | |
267 | |
268 // Local audio track and sender infos using RTP senders with SSRC 1 and 2. | |
269 rtc::scoped_refptr<AudioTrack> local_audio_track = | |
270 AudioTrack::Create("LocalAudioTrack", nullptr); | |
271 | |
272 rtc::scoped_refptr<FakeRtpSender> audio_sender_ssrc1 = | |
273 new FakeRtpSender(cricket::MEDIA_TYPE_AUDIO, | |
274 CreateRtpParametersWithSsrcs({1})); | |
275 audio_sender_ssrc1->SetTrack(local_audio_track); | |
276 rtp_senders.push_back(audio_sender_ssrc1); | |
277 | |
278 rtc::scoped_refptr<FakeRtpSender> audio_sender_ssrc2 = | |
279 new FakeRtpSender(cricket::MEDIA_TYPE_AUDIO, | |
280 CreateRtpParametersWithSsrcs({2})); | |
281 audio_sender_ssrc2->SetTrack(local_audio_track); | |
282 rtp_senders.push_back(audio_sender_ssrc2); | |
283 | |
284 voice_media_info->senders.push_back(cricket::VoiceSenderInfo()); | |
285 voice_media_info->senders[0].local_stats.push_back(cricket::SsrcSenderInfo()); | |
286 voice_media_info->senders[0].local_stats[0].ssrc = 1; | |
287 voice_media_info->senders.push_back(cricket::VoiceSenderInfo()); | |
288 voice_media_info->senders[1].local_stats.push_back(cricket::SsrcSenderInfo()); | |
289 voice_media_info->senders[1].local_stats[0].ssrc = 2; | |
290 | |
291 // Local video track and sender infos using RTP senders with SSRC 3 and 4. | |
292 rtc::scoped_refptr<VideoTrack> local_video_track = | |
293 VideoTrack::Create("LocalVideoTrack", | |
294 FakeVideoTrackSource::Create(false)); | |
295 | |
296 rtc::scoped_refptr<FakeRtpSender> video_sender_ssrc3 = | |
297 new FakeRtpSender(cricket::MEDIA_TYPE_VIDEO, | |
298 CreateRtpParametersWithSsrcs({3})); | |
299 video_sender_ssrc3->SetTrack(local_video_track); | |
300 rtp_senders.push_back(video_sender_ssrc3); | |
301 | |
302 rtc::scoped_refptr<FakeRtpSender> video_sender_ssrc4 = | |
303 new FakeRtpSender(cricket::MEDIA_TYPE_VIDEO, | |
304 CreateRtpParametersWithSsrcs({4})); | |
305 video_sender_ssrc4->SetTrack(local_video_track); | |
306 rtp_senders.push_back(video_sender_ssrc4); | |
307 | |
308 video_media_info->senders.push_back(cricket::VideoSenderInfo()); | |
309 video_media_info->senders[0].local_stats.push_back(cricket::SsrcSenderInfo()); | |
310 video_media_info->senders[0].local_stats[0].ssrc = 3; | |
311 video_media_info->senders.push_back(cricket::VideoSenderInfo()); | |
312 video_media_info->senders[1].local_stats.push_back(cricket::SsrcSenderInfo()); | |
313 video_media_info->senders[1].local_stats[0].ssrc = 4; | |
314 | |
315 TrackMediaInfoMap map = CreateAndInitializeMap( | |
316 std::unique_ptr<cricket::VoiceMediaInfo>(voice_media_info), | |
317 std::unique_ptr<cricket::VideoMediaInfo>(video_media_info), | |
318 rtp_senders, | |
319 std::vector<rtc::scoped_refptr<RtpReceiverInterface>>()); | |
320 | |
321 // Local audio track <-> RTP audio senders | |
322 ASSERT_TRUE(map.GetVoiceSenderInfos(*local_audio_track)); | |
323 EXPECT_EQ(*map.GetVoiceSenderInfos(*local_audio_track), | |
324 std::vector<cricket::VoiceSenderInfo*>({ | |
325 &voice_media_info->senders[0], | |
326 &voice_media_info->senders[1] })); | |
327 EXPECT_EQ(map.GetAudioTrack(voice_media_info->senders[0]), | |
328 local_audio_track.get()); | |
329 EXPECT_EQ(map.GetAudioTrack(voice_media_info->senders[1]), | |
330 local_audio_track.get()); | |
331 | |
332 // Local video track <-> RTP video senders | |
333 ASSERT_TRUE(map.GetVideoSenderInfos(*local_video_track)); | |
334 EXPECT_EQ(*map.GetVideoSenderInfos(*local_video_track), | |
335 std::vector<cricket::VideoSenderInfo*>({ | |
336 &video_media_info->senders[0], | |
337 &video_media_info->senders[1] })); | |
338 EXPECT_EQ(map.GetVideoTrack(video_media_info->senders[0]), | |
339 local_video_track.get()); | |
340 EXPECT_EQ(map.GetVideoTrack(video_media_info->senders[1]), | |
341 local_video_track.get()); | |
342 } | |
343 | |
344 // Death tests. | |
345 // Disabled on Android because death tests misbehave on Android, see | |
346 // base/test/gtest_util.h. | |
347 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | |
348 | |
349 TEST(TrackMediaInfoMapDeathTest, SingleReceiverWithMultipleSsrcs) { | |
350 cricket::VoiceMediaInfo* voice_media_info = new cricket::VoiceMediaInfo(); | |
351 cricket::VideoMediaInfo* video_media_info = new cricket::VideoMediaInfo(); | |
352 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> rtp_receivers; | |
353 | |
354 // Remote audio track and receiver infos using RTP receiver /w SSRCs 1 and 2. | |
355 rtc::scoped_refptr<AudioTrack> remote_audio_track = | |
356 AudioTrack::Create("RemoteAudioTrack", nullptr); | |
357 | |
358 rtc::scoped_refptr<FakeRtpReceiver> audio_receiver = | |
359 new FakeRtpReceiver(cricket::MEDIA_TYPE_AUDIO, | |
360 CreateRtpParametersWithSsrcs({1, 2})); | |
361 audio_receiver->SetTrack(remote_audio_track); | |
362 rtp_receivers.push_back(audio_receiver); | |
363 | |
364 voice_media_info->receivers.push_back(cricket::VoiceReceiverInfo()); | |
365 voice_media_info->receivers[0].local_stats.push_back( | |
366 cricket::SsrcReceiverInfo()); | |
367 voice_media_info->receivers[0].local_stats[0].ssrc = 1; | |
368 voice_media_info->receivers.push_back(cricket::VoiceReceiverInfo()); | |
369 voice_media_info->receivers[1].local_stats.push_back( | |
370 cricket::SsrcReceiverInfo()); | |
371 voice_media_info->receivers[1].local_stats[0].ssrc = 2; | |
372 | |
373 // Remote video track and receiver infos using RTP receiver /w SSRCs 3 and 4. | |
374 rtc::scoped_refptr<VideoTrack> remote_video_track = | |
375 VideoTrack::Create("RemoteVideoTrack", | |
376 FakeVideoTrackSource::Create(false)); | |
377 | |
378 rtc::scoped_refptr<FakeRtpReceiver> video_receiver = | |
379 new FakeRtpReceiver(cricket::MEDIA_TYPE_VIDEO, | |
380 CreateRtpParametersWithSsrcs({3, 4})); | |
381 video_receiver->SetTrack(remote_video_track); | |
382 rtp_receivers.push_back(video_receiver); | |
383 | |
384 video_media_info->receivers.push_back(cricket::VideoReceiverInfo()); | |
385 video_media_info->receivers[0].local_stats.push_back( | |
386 cricket::SsrcReceiverInfo()); | |
387 video_media_info->receivers[0].local_stats[0].ssrc = 3; | |
388 video_media_info->receivers.push_back(cricket::VideoReceiverInfo()); | |
389 video_media_info->receivers[1].local_stats.push_back( | |
390 cricket::SsrcReceiverInfo()); | |
391 video_media_info->receivers[1].local_stats[0].ssrc = 4; | |
392 | |
393 EXPECT_DEATH(CreateAndInitializeMap( | |
394 std::unique_ptr<cricket::VoiceMediaInfo>(voice_media_info), | |
395 std::unique_ptr<cricket::VideoMediaInfo>(video_media_info), | |
396 std::vector<rtc::scoped_refptr<RtpSenderInterface>>(), | |
397 rtp_receivers), ""); | |
398 } | |
399 | |
400 TEST(TrackMediaInfoMapDeathTest, MultipleReceiversWithOneSsrc) { | |
401 cricket::VoiceMediaInfo* voice_media_info = new cricket::VoiceMediaInfo(); | |
402 cricket::VideoMediaInfo* video_media_info = new cricket::VideoMediaInfo(); | |
403 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> rtp_receivers; | |
404 | |
405 // Remote audio track and receiver infos using RTP receivers /w SSRC 1 and 2. | |
406 rtc::scoped_refptr<AudioTrack> remote_audio_track = | |
407 AudioTrack::Create("RemoteAudioTrack", nullptr); | |
408 | |
409 rtc::scoped_refptr<FakeRtpReceiver> audio_receiver_ssrc1 = | |
410 new FakeRtpReceiver(cricket::MEDIA_TYPE_AUDIO, | |
411 CreateRtpParametersWithSsrcs({1})); | |
412 audio_receiver_ssrc1->SetTrack(remote_audio_track); | |
413 rtp_receivers.push_back(audio_receiver_ssrc1); | |
414 | |
415 rtc::scoped_refptr<FakeRtpReceiver> audio_receiver_ssrc2 = | |
416 new FakeRtpReceiver(cricket::MEDIA_TYPE_AUDIO, | |
417 CreateRtpParametersWithSsrcs({2})); | |
418 audio_receiver_ssrc2->SetTrack(remote_audio_track); | |
419 rtp_receivers.push_back(audio_receiver_ssrc2); | |
420 | |
421 voice_media_info->receivers.push_back(cricket::VoiceReceiverInfo()); | |
422 voice_media_info->receivers[0].local_stats.push_back( | |
423 cricket::SsrcReceiverInfo()); | |
424 voice_media_info->receivers[0].local_stats[0].ssrc = 1; | |
425 voice_media_info->receivers.push_back(cricket::VoiceReceiverInfo()); | |
426 voice_media_info->receivers[1].local_stats.push_back( | |
427 cricket::SsrcReceiverInfo()); | |
428 voice_media_info->receivers[1].local_stats[0].ssrc = 2; | |
429 | |
430 // Remote video track and receiver infos using RTP receivers /w SSRC 3 and 4. | |
431 rtc::scoped_refptr<VideoTrack> remote_video_track = | |
432 VideoTrack::Create("RemoteVideoTrack", | |
433 FakeVideoTrackSource::Create(false)); | |
434 | |
435 rtc::scoped_refptr<FakeRtpReceiver> video_receiver_ssrc3 = | |
436 new FakeRtpReceiver(cricket::MEDIA_TYPE_VIDEO, | |
437 CreateRtpParametersWithSsrcs({3})); | |
438 video_receiver_ssrc3->SetTrack(remote_video_track); | |
439 rtp_receivers.push_back(video_receiver_ssrc3); | |
440 | |
441 rtc::scoped_refptr<FakeRtpReceiver> video_receiver_ssrc4 = | |
442 new FakeRtpReceiver(cricket::MEDIA_TYPE_VIDEO, | |
443 CreateRtpParametersWithSsrcs({4})); | |
444 video_receiver_ssrc4->SetTrack(remote_video_track); | |
445 rtp_receivers.push_back(video_receiver_ssrc4); | |
446 | |
447 video_media_info->receivers.push_back(cricket::VideoReceiverInfo()); | |
448 video_media_info->receivers[0].local_stats.push_back( | |
449 cricket::SsrcReceiverInfo()); | |
450 video_media_info->receivers[0].local_stats[0].ssrc = 3; | |
451 video_media_info->receivers.push_back(cricket::VideoReceiverInfo()); | |
452 video_media_info->receivers[1].local_stats.push_back( | |
453 cricket::SsrcReceiverInfo()); | |
454 video_media_info->receivers[1].local_stats[0].ssrc = 4; | |
455 | |
456 EXPECT_DEATH(CreateAndInitializeMap( | |
457 std::unique_ptr<cricket::VoiceMediaInfo>(voice_media_info), | |
458 std::unique_ptr<cricket::VideoMediaInfo>(video_media_info), | |
459 std::vector<rtc::scoped_refptr<RtpSenderInterface>>(), | |
460 rtp_receivers), ""); | |
461 } | |
462 | |
463 TEST(TrackMediaInfoMapDeathTest, SingleSenderAndReceiverWithSsrcNotUnique) { | |
464 cricket::VoiceMediaInfo* voice_media_info = new cricket::VoiceMediaInfo(); | |
465 cricket::VideoMediaInfo* video_media_info = new cricket::VideoMediaInfo(); | |
466 std::vector<rtc::scoped_refptr<RtpSenderInterface>> rtp_senders; | |
467 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> rtp_receivers; | |
468 | |
469 // Local audio track and sender info using an RTP sender with SSRC 1. | |
470 rtc::scoped_refptr<AudioTrack> local_audio_track = | |
471 AudioTrack::Create("LocalAudioTrack", nullptr); | |
472 | |
473 rtc::scoped_refptr<FakeRtpSender> audio_sender = | |
474 new FakeRtpSender(cricket::MEDIA_TYPE_AUDIO, | |
475 CreateRtpParametersWithSsrcs({1})); | |
476 audio_sender->SetTrack(local_audio_track); | |
477 rtp_senders.push_back(audio_sender); | |
478 | |
479 voice_media_info->senders.push_back(cricket::VoiceSenderInfo()); | |
480 voice_media_info->senders[0].local_stats.push_back(cricket::SsrcSenderInfo()); | |
481 voice_media_info->senders[0].local_stats[0].ssrc = 1; | |
482 | |
483 // Remote audio track and receiver info using an RTP sender with SSRC 1. | |
484 rtc::scoped_refptr<AudioTrack> remote_audio_track = | |
485 AudioTrack::Create("RemoteAudioTrack", nullptr); | |
486 | |
487 rtc::scoped_refptr<FakeRtpReceiver> audio_receiver = | |
488 new FakeRtpReceiver(cricket::MEDIA_TYPE_AUDIO, | |
489 CreateRtpParametersWithSsrcs({1})); | |
490 audio_receiver->SetTrack(remote_audio_track); | |
491 rtp_receivers.push_back(audio_receiver); | |
492 | |
493 voice_media_info->receivers.push_back(cricket::VoiceReceiverInfo()); | |
494 voice_media_info->receivers[0].local_stats.push_back( | |
495 cricket::SsrcReceiverInfo()); | |
496 voice_media_info->receivers[0].local_stats[0].ssrc = 1; | |
497 | |
498 // Local video track and sender info using an RTP sender with SSRC 1. | |
499 rtc::scoped_refptr<VideoTrack> local_video_track = | |
500 VideoTrack::Create("LocalVideoTrack", | |
501 FakeVideoTrackSource::Create(false)); | |
502 | |
503 rtc::scoped_refptr<FakeRtpSender> video_sender = | |
504 new FakeRtpSender(cricket::MEDIA_TYPE_VIDEO, | |
505 CreateRtpParametersWithSsrcs({1})); | |
506 video_sender->SetTrack(local_video_track); | |
507 rtp_senders.push_back(video_sender); | |
508 | |
509 video_media_info->senders.push_back(cricket::VideoSenderInfo()); | |
510 video_media_info->senders[0].local_stats.push_back(cricket::SsrcSenderInfo()); | |
511 video_media_info->senders[0].local_stats[0].ssrc = 1; | |
512 | |
513 // Remote video track and receiver info using an RTP sender with SSRC 1. | |
514 rtc::scoped_refptr<VideoTrack> remote_video_track = | |
515 VideoTrack::Create("RemoteVideoTrack", | |
516 FakeVideoTrackSource::Create(false)); | |
517 | |
518 rtc::scoped_refptr<FakeRtpReceiver> video_receiver = | |
519 new FakeRtpReceiver(cricket::MEDIA_TYPE_VIDEO, | |
520 CreateRtpParametersWithSsrcs({1})); | |
521 video_receiver->SetTrack(remote_video_track); | |
522 rtp_receivers.push_back(video_receiver); | |
523 | |
524 video_media_info->receivers.push_back(cricket::VideoReceiverInfo()); | |
525 video_media_info->receivers[0].local_stats.push_back( | |
526 cricket::SsrcReceiverInfo()); | |
527 video_media_info->receivers[0].local_stats[0].ssrc = 1; | |
528 | |
529 EXPECT_DEATH(CreateAndInitializeMap( | |
530 std::unique_ptr<cricket::VoiceMediaInfo>(voice_media_info), | |
531 std::unique_ptr<cricket::VideoMediaInfo>(video_media_info), | |
532 std::vector<rtc::scoped_refptr<RtpSenderInterface>>(), | |
533 rtp_receivers), ""); | |
534 } | |
535 | |
536 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | |
537 | |
538 } // namespace webrtc | |
OLD | NEW |