blob: d93c902bbe266bfe7fe36ef9bd316b54e5c49845 [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();
Benjamin Wright8efafdf2019-01-11 10:48:42 -080040 receive_config.rtp.remote_ssrc = json["rtp"]["remote_ssrc"].asInt64();
41 receive_config.rtp.local_ssrc = json["rtp"]["local_ssrc"].asInt64();
42 receive_config.rtp.rtcp_mode =
43 json["rtp"]["rtcp_mode"].asString() == "RtcpMode::kCompound"
44 ? RtcpMode::kCompound
45 : RtcpMode::kReducedSize;
Elad Alonfadb1812019-05-24 13:40:02 +020046 receive_config.rtp.lntf.enabled = json["rtp"]["lntf"]["enabled"].asInt64();
Benjamin Wright8efafdf2019-01-11 10:48:42 -080047 receive_config.rtp.nack.rtp_history_ms =
48 json["rtp"]["nack"]["rtp_history_ms"].asInt64();
49 receive_config.rtp.ulpfec_payload_type =
50 json["rtp"]["ulpfec_payload_type"].asInt64();
51 receive_config.rtp.red_payload_type =
52 json["rtp"]["red_payload_type"].asInt64();
53 receive_config.rtp.rtx_ssrc = json["rtp"]["rtx_ssrc"].asInt64();
54
55 for (const auto& pl_json : json["rtp"]["rtx_payload_types"]) {
56 std::vector<std::string> members = pl_json.getMemberNames();
57 RTC_CHECK_EQ(members.size(), 1);
58 Json::Value rtx_payload_type = pl_json[members[0]];
59 receive_config.rtp.rtx_associated_payload_types[std::stoi(members[0])] =
60 rtx_payload_type.asInt64();
61 }
Benjamin Wright8efafdf2019-01-11 10:48:42 -080062 return receive_config;
63}
64
Benjamin Wright9db8b882019-01-14 15:30:20 -080065Json::Value GenerateVideoReceiveStreamJsonConfig(
Tommif6f45432022-05-20 15:21:20 +020066 const VideoReceiveStreamInterface::Config& config) {
Benjamin Wright9db8b882019-01-14 15:30:20 -080067 Json::Value root_json;
68
69 root_json["decoders"] = Json::Value(Json::arrayValue);
70 for (const auto& decoder : config.decoders) {
71 Json::Value decoder_json;
72 decoder_json["payload_type"] = decoder.payload_type;
73 decoder_json["payload_name"] = decoder.video_format.name;
74 decoder_json["codec_params"] = Json::Value(Json::arrayValue);
75 for (const auto& codec_param_entry : decoder.video_format.parameters) {
76 Json::Value codec_param_json;
77 codec_param_json[codec_param_entry.first] = codec_param_entry.second;
78 decoder_json["codec_params"].append(codec_param_json);
79 }
80 root_json["decoders"].append(decoder_json);
81 }
82
83 Json::Value rtp_json;
84 rtp_json["remote_ssrc"] = config.rtp.remote_ssrc;
85 rtp_json["local_ssrc"] = config.rtp.local_ssrc;
86 rtp_json["rtcp_mode"] = config.rtp.rtcp_mode == RtcpMode::kCompound
87 ? "RtcpMode::kCompound"
88 : "RtcpMode::kReducedSize";
Elad Alonfadb1812019-05-24 13:40:02 +020089 rtp_json["lntf"]["enabled"] = config.rtp.lntf.enabled;
Benjamin Wright9db8b882019-01-14 15:30:20 -080090 rtp_json["nack"]["rtp_history_ms"] = config.rtp.nack.rtp_history_ms;
91 rtp_json["ulpfec_payload_type"] = config.rtp.ulpfec_payload_type;
92 rtp_json["red_payload_type"] = config.rtp.red_payload_type;
93 rtp_json["rtx_ssrc"] = config.rtp.rtx_ssrc;
94 rtp_json["rtx_payload_types"] = Json::Value(Json::arrayValue);
95
96 for (auto& kv : config.rtp.rtx_associated_payload_types) {
97 Json::Value val;
98 val[std::to_string(kv.first)] = kv.second;
99 rtp_json["rtx_payload_types"].append(val);
100 }
101
Benjamin Wright9db8b882019-01-14 15:30:20 -0800102 root_json["rtp"] = rtp_json;
103
104 root_json["render_delay_ms"] = config.render_delay_ms;
Benjamin Wright9db8b882019-01-14 15:30:20 -0800105
106 return root_json;
107}
108
Benjamin Wright8efafdf2019-01-11 10:48:42 -0800109} // namespace test.
110} // namespace webrtc.