blob: 7e226b00d25bccc36118fbce82b4d0a90cae02a1 [file] [log] [blame]
Benjamin Wright8efafdf2019-01-11 10:48:42 -08001/*
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 "test/call_config_utils.h"
12
13#include <string>
14#include <vector>
15
16namespace webrtc {
17namespace test {
18
Tommif6f45432022-05-20 15:21:20 +020019// Deserializes a JSON representation of the VideoReceiveStreamInterface::Config
20// back into a valid object. This will not initialize the decoders or the
21// renderer.
22VideoReceiveStreamInterface::Config ParseVideoReceiveStreamJsonConfig(
Benjamin Wright8efafdf2019-01-11 10:48:42 -080023 webrtc::Transport* transport,
24 const Json::Value& json) {
Tommif6f45432022-05-20 15:21:20 +020025 auto receive_config = VideoReceiveStreamInterface::Config(transport);
Mirko Bonadei739baf02019-01-27 17:29:42 +010026 for (const auto& decoder_json : json["decoders"]) {
Tommif6f45432022-05-20 15:21:20 +020027 VideoReceiveStreamInterface::Decoder decoder;
Benjamin Wright8efafdf2019-01-11 10:48:42 -080028 decoder.video_format =
29 SdpVideoFormat(decoder_json["payload_name"].asString());
30 decoder.payload_type = decoder_json["payload_type"].asInt64();
31 for (const auto& params_json : decoder_json["codec_params"]) {
32 std::vector<std::string> members = params_json.getMemberNames();
33 RTC_CHECK_EQ(members.size(), 1);
34 decoder.video_format.parameters[members[0]] =
35 params_json[members[0]].asString();
36 }
37 receive_config.decoders.push_back(decoder);
38 }
39 receive_config.render_delay_ms = json["render_delay_ms"].asInt64();
40 receive_config.target_delay_ms = json["target_delay_ms"].asInt64();
41 receive_config.rtp.remote_ssrc = json["rtp"]["remote_ssrc"].asInt64();
42 receive_config.rtp.local_ssrc = json["rtp"]["local_ssrc"].asInt64();
43 receive_config.rtp.rtcp_mode =
44 json["rtp"]["rtcp_mode"].asString() == "RtcpMode::kCompound"
45 ? RtcpMode::kCompound
46 : RtcpMode::kReducedSize;
Benjamin Wright8efafdf2019-01-11 10:48:42 -080047 receive_config.rtp.transport_cc = json["rtp"]["transport_cc"].asBool();
Elad Alonfadb1812019-05-24 13:40:02 +020048 receive_config.rtp.lntf.enabled = json["rtp"]["lntf"]["enabled"].asInt64();
Benjamin Wright8efafdf2019-01-11 10:48:42 -080049 receive_config.rtp.nack.rtp_history_ms =
50 json["rtp"]["nack"]["rtp_history_ms"].asInt64();
51 receive_config.rtp.ulpfec_payload_type =
52 json["rtp"]["ulpfec_payload_type"].asInt64();
53 receive_config.rtp.red_payload_type =
54 json["rtp"]["red_payload_type"].asInt64();
55 receive_config.rtp.rtx_ssrc = json["rtp"]["rtx_ssrc"].asInt64();
56
57 for (const auto& pl_json : json["rtp"]["rtx_payload_types"]) {
58 std::vector<std::string> members = pl_json.getMemberNames();
59 RTC_CHECK_EQ(members.size(), 1);
60 Json::Value rtx_payload_type = pl_json[members[0]];
61 receive_config.rtp.rtx_associated_payload_types[std::stoi(members[0])] =
62 rtx_payload_type.asInt64();
63 }
64 for (const auto& ext_json : json["rtp"]["extensions"]) {
65 receive_config.rtp.extensions.emplace_back(ext_json["uri"].asString(),
66 ext_json["id"].asInt64(),
67 ext_json["encrypt"].asBool());
68 }
69 return receive_config;
70}
71
Benjamin Wright9db8b882019-01-14 15:30:20 -080072Json::Value GenerateVideoReceiveStreamJsonConfig(
Tommif6f45432022-05-20 15:21:20 +020073 const VideoReceiveStreamInterface::Config& config) {
Benjamin Wright9db8b882019-01-14 15:30:20 -080074 Json::Value root_json;
75
76 root_json["decoders"] = Json::Value(Json::arrayValue);
77 for (const auto& decoder : config.decoders) {
78 Json::Value decoder_json;
79 decoder_json["payload_type"] = decoder.payload_type;
80 decoder_json["payload_name"] = decoder.video_format.name;
81 decoder_json["codec_params"] = Json::Value(Json::arrayValue);
82 for (const auto& codec_param_entry : decoder.video_format.parameters) {
83 Json::Value codec_param_json;
84 codec_param_json[codec_param_entry.first] = codec_param_entry.second;
85 decoder_json["codec_params"].append(codec_param_json);
86 }
87 root_json["decoders"].append(decoder_json);
88 }
89
90 Json::Value rtp_json;
91 rtp_json["remote_ssrc"] = config.rtp.remote_ssrc;
92 rtp_json["local_ssrc"] = config.rtp.local_ssrc;
93 rtp_json["rtcp_mode"] = config.rtp.rtcp_mode == RtcpMode::kCompound
94 ? "RtcpMode::kCompound"
95 : "RtcpMode::kReducedSize";
Benjamin Wright9db8b882019-01-14 15:30:20 -080096 rtp_json["transport_cc"] = config.rtp.transport_cc;
Elad Alonfadb1812019-05-24 13:40:02 +020097 rtp_json["lntf"]["enabled"] = config.rtp.lntf.enabled;
Benjamin Wright9db8b882019-01-14 15:30:20 -080098 rtp_json["nack"]["rtp_history_ms"] = config.rtp.nack.rtp_history_ms;
99 rtp_json["ulpfec_payload_type"] = config.rtp.ulpfec_payload_type;
100 rtp_json["red_payload_type"] = config.rtp.red_payload_type;
101 rtp_json["rtx_ssrc"] = config.rtp.rtx_ssrc;
102 rtp_json["rtx_payload_types"] = Json::Value(Json::arrayValue);
103
104 for (auto& kv : config.rtp.rtx_associated_payload_types) {
105 Json::Value val;
106 val[std::to_string(kv.first)] = kv.second;
107 rtp_json["rtx_payload_types"].append(val);
108 }
109
110 rtp_json["extensions"] = Json::Value(Json::arrayValue);
111 for (auto& ext : config.rtp.extensions) {
112 Json::Value ext_json;
113 ext_json["uri"] = ext.uri;
114 ext_json["id"] = ext.id;
115 ext_json["encrypt"] = ext.encrypt;
116 rtp_json["extensions"].append(ext_json);
117 }
118 root_json["rtp"] = rtp_json;
119
120 root_json["render_delay_ms"] = config.render_delay_ms;
121 root_json["target_delay_ms"] = config.target_delay_ms;
122
123 return root_json;
124}
125
Benjamin Wright8efafdf2019-01-11 10:48:42 -0800126} // namespace test.
127} // namespace webrtc.