blob: ab41a274fbf67382beb247ed83c28ec42859192d [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
19// Deserializes a JSON representation of the VideoReceiveStream::Config back
20// into a valid object. This will not initialize the decoders or the renderer.
21VideoReceiveStream::Config ParseVideoReceiveStreamJsonConfig(
22 webrtc::Transport* transport,
23 const Json::Value& json) {
24 auto receive_config = VideoReceiveStream::Config(transport);
Mirko Bonadei739baf02019-01-27 17:29:42 +010025 for (const auto& decoder_json : json["decoders"]) {
Benjamin Wright8efafdf2019-01-11 10:48:42 -080026 VideoReceiveStream::Decoder decoder;
27 decoder.video_format =
28 SdpVideoFormat(decoder_json["payload_name"].asString());
29 decoder.payload_type = decoder_json["payload_type"].asInt64();
30 for (const auto& params_json : decoder_json["codec_params"]) {
31 std::vector<std::string> members = params_json.getMemberNames();
32 RTC_CHECK_EQ(members.size(), 1);
33 decoder.video_format.parameters[members[0]] =
34 params_json[members[0]].asString();
35 }
36 receive_config.decoders.push_back(decoder);
37 }
38 receive_config.render_delay_ms = json["render_delay_ms"].asInt64();
39 receive_config.target_delay_ms = json["target_delay_ms"].asInt64();
40 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;
Benjamin Wright8efafdf2019-01-11 10:48:42 -080046 receive_config.rtp.transport_cc = json["rtp"]["transport_cc"].asBool();
Elad Alonfadb1812019-05-24 13:40:02 +020047 receive_config.rtp.lntf.enabled = json["rtp"]["lntf"]["enabled"].asInt64();
Benjamin Wright8efafdf2019-01-11 10:48:42 -080048 receive_config.rtp.nack.rtp_history_ms =
49 json["rtp"]["nack"]["rtp_history_ms"].asInt64();
50 receive_config.rtp.ulpfec_payload_type =
51 json["rtp"]["ulpfec_payload_type"].asInt64();
52 receive_config.rtp.red_payload_type =
53 json["rtp"]["red_payload_type"].asInt64();
54 receive_config.rtp.rtx_ssrc = json["rtp"]["rtx_ssrc"].asInt64();
55
56 for (const auto& pl_json : json["rtp"]["rtx_payload_types"]) {
57 std::vector<std::string> members = pl_json.getMemberNames();
58 RTC_CHECK_EQ(members.size(), 1);
59 Json::Value rtx_payload_type = pl_json[members[0]];
60 receive_config.rtp.rtx_associated_payload_types[std::stoi(members[0])] =
61 rtx_payload_type.asInt64();
62 }
63 for (const auto& ext_json : json["rtp"]["extensions"]) {
64 receive_config.rtp.extensions.emplace_back(ext_json["uri"].asString(),
65 ext_json["id"].asInt64(),
66 ext_json["encrypt"].asBool());
67 }
68 return receive_config;
69}
70
Benjamin Wright9db8b882019-01-14 15:30:20 -080071Json::Value GenerateVideoReceiveStreamJsonConfig(
72 const VideoReceiveStream::Config& config) {
73 Json::Value root_json;
74
75 root_json["decoders"] = Json::Value(Json::arrayValue);
76 for (const auto& decoder : config.decoders) {
77 Json::Value decoder_json;
78 decoder_json["payload_type"] = decoder.payload_type;
79 decoder_json["payload_name"] = decoder.video_format.name;
80 decoder_json["codec_params"] = Json::Value(Json::arrayValue);
81 for (const auto& codec_param_entry : decoder.video_format.parameters) {
82 Json::Value codec_param_json;
83 codec_param_json[codec_param_entry.first] = codec_param_entry.second;
84 decoder_json["codec_params"].append(codec_param_json);
85 }
86 root_json["decoders"].append(decoder_json);
87 }
88
89 Json::Value rtp_json;
90 rtp_json["remote_ssrc"] = config.rtp.remote_ssrc;
91 rtp_json["local_ssrc"] = config.rtp.local_ssrc;
92 rtp_json["rtcp_mode"] = config.rtp.rtcp_mode == RtcpMode::kCompound
93 ? "RtcpMode::kCompound"
94 : "RtcpMode::kReducedSize";
Benjamin Wright9db8b882019-01-14 15:30:20 -080095 rtp_json["transport_cc"] = config.rtp.transport_cc;
Elad Alonfadb1812019-05-24 13:40:02 +020096 rtp_json["lntf"]["enabled"] = config.rtp.lntf.enabled;
Benjamin Wright9db8b882019-01-14 15:30:20 -080097 rtp_json["nack"]["rtp_history_ms"] = config.rtp.nack.rtp_history_ms;
98 rtp_json["ulpfec_payload_type"] = config.rtp.ulpfec_payload_type;
99 rtp_json["red_payload_type"] = config.rtp.red_payload_type;
100 rtp_json["rtx_ssrc"] = config.rtp.rtx_ssrc;
101 rtp_json["rtx_payload_types"] = Json::Value(Json::arrayValue);
102
103 for (auto& kv : config.rtp.rtx_associated_payload_types) {
104 Json::Value val;
105 val[std::to_string(kv.first)] = kv.second;
106 rtp_json["rtx_payload_types"].append(val);
107 }
108
109 rtp_json["extensions"] = Json::Value(Json::arrayValue);
110 for (auto& ext : config.rtp.extensions) {
111 Json::Value ext_json;
112 ext_json["uri"] = ext.uri;
113 ext_json["id"] = ext.id;
114 ext_json["encrypt"] = ext.encrypt;
115 rtp_json["extensions"].append(ext_json);
116 }
117 root_json["rtp"] = rtp_json;
118
119 root_json["render_delay_ms"] = config.render_delay_ms;
120 root_json["target_delay_ms"] = config.target_delay_ms;
121
122 return root_json;
123}
124
Benjamin Wright8efafdf2019-01-11 10:48:42 -0800125} // namespace test.
126} // namespace webrtc.