xref: /aosp_15_r20/external/webrtc/call/call_factory.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2017 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #include "call/call_factory.h"
12*d9f75844SAndroid Build Coastguard Worker 
13*d9f75844SAndroid Build Coastguard Worker #include <stdio.h>
14*d9f75844SAndroid Build Coastguard Worker 
15*d9f75844SAndroid Build Coastguard Worker #include <memory>
16*d9f75844SAndroid Build Coastguard Worker #include <string>
17*d9f75844SAndroid Build Coastguard Worker #include <utility>
18*d9f75844SAndroid Build Coastguard Worker #include <vector>
19*d9f75844SAndroid Build Coastguard Worker 
20*d9f75844SAndroid Build Coastguard Worker #include "absl/memory/memory.h"
21*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h"
22*d9f75844SAndroid Build Coastguard Worker #include "api/test/simulated_network.h"
23*d9f75844SAndroid Build Coastguard Worker #include "api/units/time_delta.h"
24*d9f75844SAndroid Build Coastguard Worker #include "call/call.h"
25*d9f75844SAndroid Build Coastguard Worker #include "call/degraded_call.h"
26*d9f75844SAndroid Build Coastguard Worker #include "call/rtp_transport_config.h"
27*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/checks.h"
28*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/experiments/field_trial_list.h"
29*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/experiments/field_trial_parser.h"
30*d9f75844SAndroid Build Coastguard Worker 
31*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
32*d9f75844SAndroid Build Coastguard Worker namespace {
33*d9f75844SAndroid Build Coastguard Worker using TimeScopedNetworkConfig = DegradedCall::TimeScopedNetworkConfig;
34*d9f75844SAndroid Build Coastguard Worker 
GetNetworkConfigs(const FieldTrialsView & trials,bool send)35*d9f75844SAndroid Build Coastguard Worker std::vector<TimeScopedNetworkConfig> GetNetworkConfigs(
36*d9f75844SAndroid Build Coastguard Worker     const FieldTrialsView& trials,
37*d9f75844SAndroid Build Coastguard Worker     bool send) {
38*d9f75844SAndroid Build Coastguard Worker   FieldTrialStructList<TimeScopedNetworkConfig> trials_list(
39*d9f75844SAndroid Build Coastguard Worker       {FieldTrialStructMember("queue_length_packets",
40*d9f75844SAndroid Build Coastguard Worker                               [](TimeScopedNetworkConfig* p) {
41*d9f75844SAndroid Build Coastguard Worker                                 // FieldTrialParser does not natively support
42*d9f75844SAndroid Build Coastguard Worker                                 // size_t type, so use this ugly cast as
43*d9f75844SAndroid Build Coastguard Worker                                 // workaround.
44*d9f75844SAndroid Build Coastguard Worker                                 return reinterpret_cast<unsigned*>(
45*d9f75844SAndroid Build Coastguard Worker                                     &p->queue_length_packets);
46*d9f75844SAndroid Build Coastguard Worker                               }),
47*d9f75844SAndroid Build Coastguard Worker        FieldTrialStructMember(
48*d9f75844SAndroid Build Coastguard Worker            "queue_delay_ms",
49*d9f75844SAndroid Build Coastguard Worker            [](TimeScopedNetworkConfig* p) { return &p->queue_delay_ms; }),
50*d9f75844SAndroid Build Coastguard Worker        FieldTrialStructMember("delay_standard_deviation_ms",
51*d9f75844SAndroid Build Coastguard Worker                               [](TimeScopedNetworkConfig* p) {
52*d9f75844SAndroid Build Coastguard Worker                                 return &p->delay_standard_deviation_ms;
53*d9f75844SAndroid Build Coastguard Worker                               }),
54*d9f75844SAndroid Build Coastguard Worker        FieldTrialStructMember(
55*d9f75844SAndroid Build Coastguard Worker            "link_capacity_kbps",
56*d9f75844SAndroid Build Coastguard Worker            [](TimeScopedNetworkConfig* p) { return &p->link_capacity_kbps; }),
57*d9f75844SAndroid Build Coastguard Worker        FieldTrialStructMember(
58*d9f75844SAndroid Build Coastguard Worker            "loss_percent",
59*d9f75844SAndroid Build Coastguard Worker            [](TimeScopedNetworkConfig* p) { return &p->loss_percent; }),
60*d9f75844SAndroid Build Coastguard Worker        FieldTrialStructMember(
61*d9f75844SAndroid Build Coastguard Worker            "allow_reordering",
62*d9f75844SAndroid Build Coastguard Worker            [](TimeScopedNetworkConfig* p) { return &p->allow_reordering; }),
63*d9f75844SAndroid Build Coastguard Worker        FieldTrialStructMember("avg_burst_loss_length",
64*d9f75844SAndroid Build Coastguard Worker                               [](TimeScopedNetworkConfig* p) {
65*d9f75844SAndroid Build Coastguard Worker                                 return &p->avg_burst_loss_length;
66*d9f75844SAndroid Build Coastguard Worker                               }),
67*d9f75844SAndroid Build Coastguard Worker        FieldTrialStructMember(
68*d9f75844SAndroid Build Coastguard Worker            "packet_overhead",
69*d9f75844SAndroid Build Coastguard Worker            [](TimeScopedNetworkConfig* p) { return &p->packet_overhead; }),
70*d9f75844SAndroid Build Coastguard Worker        FieldTrialStructMember(
71*d9f75844SAndroid Build Coastguard Worker            "duration",
72*d9f75844SAndroid Build Coastguard Worker            [](TimeScopedNetworkConfig* p) { return &p->duration; })},
73*d9f75844SAndroid Build Coastguard Worker       {});
74*d9f75844SAndroid Build Coastguard Worker   ParseFieldTrial({&trials_list},
75*d9f75844SAndroid Build Coastguard Worker                   trials.Lookup(send ? "WebRTC-FakeNetworkSendConfig"
76*d9f75844SAndroid Build Coastguard Worker                                      : "WebRTC-FakeNetworkReceiveConfig"));
77*d9f75844SAndroid Build Coastguard Worker   return trials_list.Get();
78*d9f75844SAndroid Build Coastguard Worker }
79*d9f75844SAndroid Build Coastguard Worker 
80*d9f75844SAndroid Build Coastguard Worker }  // namespace
81*d9f75844SAndroid Build Coastguard Worker 
CallFactory()82*d9f75844SAndroid Build Coastguard Worker CallFactory::CallFactory() {
83*d9f75844SAndroid Build Coastguard Worker   call_thread_.Detach();
84*d9f75844SAndroid Build Coastguard Worker }
85*d9f75844SAndroid Build Coastguard Worker 
CreateCall(const Call::Config & config)86*d9f75844SAndroid Build Coastguard Worker Call* CallFactory::CreateCall(const Call::Config& config) {
87*d9f75844SAndroid Build Coastguard Worker   RTC_DCHECK_RUN_ON(&call_thread_);
88*d9f75844SAndroid Build Coastguard Worker   RTC_DCHECK(config.trials);
89*d9f75844SAndroid Build Coastguard Worker 
90*d9f75844SAndroid Build Coastguard Worker   std::vector<DegradedCall::TimeScopedNetworkConfig> send_degradation_configs =
91*d9f75844SAndroid Build Coastguard Worker       GetNetworkConfigs(*config.trials, /*send=*/true);
92*d9f75844SAndroid Build Coastguard Worker   std::vector<DegradedCall::TimeScopedNetworkConfig>
93*d9f75844SAndroid Build Coastguard Worker       receive_degradation_configs =
94*d9f75844SAndroid Build Coastguard Worker           GetNetworkConfigs(*config.trials, /*send=*/false);
95*d9f75844SAndroid Build Coastguard Worker 
96*d9f75844SAndroid Build Coastguard Worker   RtpTransportConfig transportConfig = config.ExtractTransportConfig();
97*d9f75844SAndroid Build Coastguard Worker 
98*d9f75844SAndroid Build Coastguard Worker   Call* call =
99*d9f75844SAndroid Build Coastguard Worker       Call::Create(config, Clock::GetRealTimeClock(),
100*d9f75844SAndroid Build Coastguard Worker                    config.rtp_transport_controller_send_factory->Create(
101*d9f75844SAndroid Build Coastguard Worker                        transportConfig, Clock::GetRealTimeClock()));
102*d9f75844SAndroid Build Coastguard Worker 
103*d9f75844SAndroid Build Coastguard Worker   if (!send_degradation_configs.empty() ||
104*d9f75844SAndroid Build Coastguard Worker       !receive_degradation_configs.empty()) {
105*d9f75844SAndroid Build Coastguard Worker     return new DegradedCall(absl::WrapUnique(call), send_degradation_configs,
106*d9f75844SAndroid Build Coastguard Worker                             receive_degradation_configs);
107*d9f75844SAndroid Build Coastguard Worker   }
108*d9f75844SAndroid Build Coastguard Worker 
109*d9f75844SAndroid Build Coastguard Worker   return call;
110*d9f75844SAndroid Build Coastguard Worker }
111*d9f75844SAndroid Build Coastguard Worker 
CreateCallFactory()112*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<CallFactoryInterface> CreateCallFactory() {
113*d9f75844SAndroid Build Coastguard Worker   return std::unique_ptr<CallFactoryInterface>(new CallFactory());
114*d9f75844SAndroid Build Coastguard Worker }
115*d9f75844SAndroid Build Coastguard Worker 
116*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
117