blob: 155fad1c24d7fa810ff2b17e98839fdd9d051f5c [file] [log] [blame]
Benjamin Wright8efafdf2019-01-11 18:48:421/*
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 16:29:4225 for (const auto& decoder_json : json["decoders"]) {
Benjamin Wright8efafdf2019-01-11 18:48:4226 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;
46 receive_config.rtp.remb = json["rtp"]["remb"].asBool();
47 receive_config.rtp.transport_cc = json["rtp"]["transport_cc"].asBool();
Elad Alonfadb1812019-05-24 11:40:0248 receive_config.rtp.lntf.enabled = json["rtp"]["lntf"]["enabled"].asInt64();
Benjamin Wright8efafdf2019-01-11 18:48:4249 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 23:30:2072Json::Value GenerateVideoReceiveStreamJsonConfig(
73 const VideoReceiveStream::Config& config) {
74 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";
96 rtp_json["remb"] = config.rtp.remb;
97 rtp_json["transport_cc"] = config.rtp.transport_cc;
Elad Alonfadb1812019-05-24 11:40:0298 rtp_json["lntf"]["enabled"] = config.rtp.lntf.enabled;
Benjamin Wright9db8b882019-01-14 23:30:2099 rtp_json["nack"]["rtp_history_ms"] = config.rtp.nack.rtp_history_ms;
100 rtp_json["ulpfec_payload_type"] = config.rtp.ulpfec_payload_type;
101 rtp_json["red_payload_type"] = config.rtp.red_payload_type;
102 rtp_json["rtx_ssrc"] = config.rtp.rtx_ssrc;
103 rtp_json["rtx_payload_types"] = Json::Value(Json::arrayValue);
104
105 for (auto& kv : config.rtp.rtx_associated_payload_types) {
106 Json::Value val;
107 val[std::to_string(kv.first)] = kv.second;
108 rtp_json["rtx_payload_types"].append(val);
109 }
110
111 rtp_json["extensions"] = Json::Value(Json::arrayValue);
112 for (auto& ext : config.rtp.extensions) {
113 Json::Value ext_json;
114 ext_json["uri"] = ext.uri;
115 ext_json["id"] = ext.id;
116 ext_json["encrypt"] = ext.encrypt;
117 rtp_json["extensions"].append(ext_json);
118 }
119 root_json["rtp"] = rtp_json;
120
121 root_json["render_delay_ms"] = config.render_delay_ms;
122 root_json["target_delay_ms"] = config.target_delay_ms;
123
124 return root_json;
125}
126
Benjamin Wright8efafdf2019-01-11 18:48:42127} // namespace test.
128} // namespace webrtc.