Benjamin Wright | 8efafdf | 2019-01-11 10:48:42 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 16 | namespace webrtc { |
| 17 | namespace test { |
| 18 | |
Tommi | f6f4543 | 2022-05-20 15:21:20 +0200 | [diff] [blame] | 19 | // Deserializes a JSON representation of the VideoReceiveStreamInterface::Config |
| 20 | // back into a valid object. This will not initialize the decoders or the |
| 21 | // renderer. |
| 22 | VideoReceiveStreamInterface::Config ParseVideoReceiveStreamJsonConfig( |
Benjamin Wright | 8efafdf | 2019-01-11 10:48:42 -0800 | [diff] [blame] | 23 | webrtc::Transport* transport, |
| 24 | const Json::Value& json) { |
Tommi | f6f4543 | 2022-05-20 15:21:20 +0200 | [diff] [blame] | 25 | auto receive_config = VideoReceiveStreamInterface::Config(transport); |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 26 | for (const auto& decoder_json : json["decoders"]) { |
Tommi | f6f4543 | 2022-05-20 15:21:20 +0200 | [diff] [blame] | 27 | VideoReceiveStreamInterface::Decoder decoder; |
Benjamin Wright | 8efafdf | 2019-01-11 10:48:42 -0800 | [diff] [blame] | 28 | 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 Wright | 8efafdf | 2019-01-11 10:48:42 -0800 | [diff] [blame] | 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; |
Elad Alon | fadb181 | 2019-05-24 13:40:02 +0200 | [diff] [blame] | 46 | receive_config.rtp.lntf.enabled = json["rtp"]["lntf"]["enabled"].asInt64(); |
Benjamin Wright | 8efafdf | 2019-01-11 10:48:42 -0800 | [diff] [blame] | 47 | 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 Wright | 8efafdf | 2019-01-11 10:48:42 -0800 | [diff] [blame] | 62 | return receive_config; |
| 63 | } |
| 64 | |
Benjamin Wright | 9db8b88 | 2019-01-14 15:30:20 -0800 | [diff] [blame] | 65 | Json::Value GenerateVideoReceiveStreamJsonConfig( |
Tommi | f6f4543 | 2022-05-20 15:21:20 +0200 | [diff] [blame] | 66 | const VideoReceiveStreamInterface::Config& config) { |
Benjamin Wright | 9db8b88 | 2019-01-14 15:30:20 -0800 | [diff] [blame] | 67 | 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 Alon | fadb181 | 2019-05-24 13:40:02 +0200 | [diff] [blame] | 89 | rtp_json["lntf"]["enabled"] = config.rtp.lntf.enabled; |
Benjamin Wright | 9db8b88 | 2019-01-14 15:30:20 -0800 | [diff] [blame] | 90 | 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 Wright | 9db8b88 | 2019-01-14 15:30:20 -0800 | [diff] [blame] | 102 | root_json["rtp"] = rtp_json; |
| 103 | |
| 104 | root_json["render_delay_ms"] = config.render_delay_ms; |
Benjamin Wright | 9db8b88 | 2019-01-14 15:30:20 -0800 | [diff] [blame] | 105 | |
| 106 | return root_json; |
| 107 | } |
| 108 | |
Benjamin Wright | 8efafdf | 2019-01-11 10:48:42 -0800 | [diff] [blame] | 109 | } // namespace test. |
| 110 | } // namespace webrtc. |