1 /*
2 * Copyright (c) 2019 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 "modules/rtp_rtcp/include/rtp_header_extension_map.h"
12 #include "modules/rtp_rtcp/source/rtp_header_extensions.h"
13 #include "modules/rtp_rtcp/source/rtp_packet.h"
14 #include "modules/rtp_rtcp/source/rtp_util.h"
15 #include "pc/media_session.h"
16 #include "pc/session_description.h"
17 #include "test/field_trial.h"
18 #include "test/gtest.h"
19 #include "test/peer_scenario/peer_scenario.h"
20
21 namespace webrtc {
22 namespace test {
23 namespace {
AudioExtensions(const SessionDescriptionInterface & session)24 RtpHeaderExtensionMap AudioExtensions(
25 const SessionDescriptionInterface& session) {
26 auto* audio_desc =
27 cricket::GetFirstAudioContentDescription(session.description());
28 return RtpHeaderExtensionMap(audio_desc->rtp_header_extensions());
29 }
30
31 } // namespace
32
TEST(RemoteEstimateEndToEnd,OfferedCapabilityIsInAnswer)33 TEST(RemoteEstimateEndToEnd, OfferedCapabilityIsInAnswer) {
34 PeerScenario s(*test_info_);
35
36 auto* caller = s.CreateClient(PeerScenarioClient::Config());
37 auto* callee = s.CreateClient(PeerScenarioClient::Config());
38
39 auto send_link = {s.net()->NodeBuilder().Build().node};
40 auto ret_link = {s.net()->NodeBuilder().Build().node};
41
42 s.net()->CreateRoute(caller->endpoint(), send_link, callee->endpoint());
43 s.net()->CreateRoute(callee->endpoint(), ret_link, caller->endpoint());
44
45 auto signaling = s.ConnectSignaling(caller, callee, send_link, ret_link);
46 caller->CreateVideo("VIDEO", PeerScenarioClient::VideoSendTrackConfig());
47 std::atomic<bool> offer_exchange_done(false);
48 signaling.NegotiateSdp(
49 [](SessionDescriptionInterface* offer) {
50 for (auto& cont : offer->description()->contents()) {
51 cont.media_description()->set_remote_estimate(true);
52 }
53 },
54 [&](const SessionDescriptionInterface& answer) {
55 for (auto& cont : answer.description()->contents()) {
56 EXPECT_TRUE(cont.media_description()->remote_estimate());
57 }
58 offer_exchange_done = true;
59 });
60 RTC_CHECK(s.WaitAndProcess(&offer_exchange_done));
61 }
62
TEST(RemoteEstimateEndToEnd,AudioUsesAbsSendTimeExtension)63 TEST(RemoteEstimateEndToEnd, AudioUsesAbsSendTimeExtension) {
64 // Defined before PeerScenario so it gets destructed after, to avoid use after free.
65 std::atomic<bool> received_abs_send_time(false);
66 PeerScenario s(*test_info_);
67
68 auto* caller = s.CreateClient(PeerScenarioClient::Config());
69 auto* callee = s.CreateClient(PeerScenarioClient::Config());
70
71 auto send_node = s.net()->NodeBuilder().Build().node;
72 auto ret_node = s.net()->NodeBuilder().Build().node;
73
74 s.net()->CreateRoute(caller->endpoint(), {send_node}, callee->endpoint());
75 s.net()->CreateRoute(callee->endpoint(), {ret_node}, caller->endpoint());
76
77 auto signaling = s.ConnectSignaling(caller, callee, {send_node}, {ret_node});
78 caller->CreateAudio("AUDIO", cricket::AudioOptions());
79 signaling.StartIceSignaling();
80 RtpHeaderExtensionMap extension_map;
81 std::atomic<bool> offer_exchange_done(false);
82 signaling.NegotiateSdp(
83 [&extension_map](SessionDescriptionInterface* offer) {
84 extension_map = AudioExtensions(*offer);
85 EXPECT_TRUE(extension_map.IsRegistered(kRtpExtensionAbsoluteSendTime));
86 },
87 [&](const SessionDescriptionInterface& answer) {
88 EXPECT_TRUE(AudioExtensions(answer).IsRegistered(
89 kRtpExtensionAbsoluteSendTime));
90 offer_exchange_done = true;
91 });
92 RTC_CHECK(s.WaitAndProcess(&offer_exchange_done));
93 send_node->router()->SetWatcher(
94 [extension_map, &received_abs_send_time](const EmulatedIpPacket& packet) {
95 // The dummy packets used by the fake signaling are filled with 0. We
96 // want to ignore those and we can do that on the basis that the first
97 // byte of RTP packets are guaranteed to not be 0.
98 RtpPacket rtp_packet(&extension_map);
99 // TODO(bugs.webrtc.org/14525): Look why there are RTP packets with
100 // payload 72 or 73 (these don't have the RTP AbsoluteSendTime
101 // Extension).
102 if (rtp_packet.Parse(packet.data) && rtp_packet.PayloadType() == 111) {
103 EXPECT_TRUE(rtp_packet.HasExtension<AbsoluteSendTime>());
104 received_abs_send_time = true;
105 }
106 });
107 RTC_CHECK(s.WaitAndProcess(&received_abs_send_time));
108 caller->pc()->Close();
109 callee->pc()->Close();
110 }
111 } // namespace test
112 } // namespace webrtc
113