You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
5.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include "test/call_config_utils.h"
  11. #include <string>
  12. #include <vector>
  13. namespace webrtc {
  14. namespace test {
  15. // Deserializes a JSON representation of the VideoReceiveStream::Config back
  16. // into a valid object. This will not initialize the decoders or the renderer.
  17. VideoReceiveStream::Config ParseVideoReceiveStreamJsonConfig(
  18. webrtc::Transport* transport,
  19. const Json::Value& json) {
  20. auto receive_config = VideoReceiveStream::Config(transport);
  21. for (const auto& decoder_json : json["decoders"]) {
  22. VideoReceiveStream::Decoder decoder;
  23. decoder.video_format =
  24. SdpVideoFormat(decoder_json["payload_name"].asString());
  25. decoder.payload_type = decoder_json["payload_type"].asInt64();
  26. for (const auto& params_json : decoder_json["codec_params"]) {
  27. std::vector<std::string> members = params_json.getMemberNames();
  28. RTC_CHECK_EQ(members.size(), 1);
  29. decoder.video_format.parameters[members[0]] =
  30. params_json[members[0]].asString();
  31. }
  32. receive_config.decoders.push_back(decoder);
  33. }
  34. receive_config.render_delay_ms = json["render_delay_ms"].asInt64();
  35. receive_config.target_delay_ms = json["target_delay_ms"].asInt64();
  36. receive_config.rtp.remote_ssrc = json["rtp"]["remote_ssrc"].asInt64();
  37. receive_config.rtp.local_ssrc = json["rtp"]["local_ssrc"].asInt64();
  38. receive_config.rtp.rtcp_mode =
  39. json["rtp"]["rtcp_mode"].asString() == "RtcpMode::kCompound"
  40. ? RtcpMode::kCompound
  41. : RtcpMode::kReducedSize;
  42. receive_config.rtp.transport_cc = json["rtp"]["transport_cc"].asBool();
  43. receive_config.rtp.lntf.enabled = json["rtp"]["lntf"]["enabled"].asInt64();
  44. receive_config.rtp.nack.rtp_history_ms =
  45. json["rtp"]["nack"]["rtp_history_ms"].asInt64();
  46. receive_config.rtp.ulpfec_payload_type =
  47. json["rtp"]["ulpfec_payload_type"].asInt64();
  48. receive_config.rtp.red_payload_type =
  49. json["rtp"]["red_payload_type"].asInt64();
  50. receive_config.rtp.rtx_ssrc = json["rtp"]["rtx_ssrc"].asInt64();
  51. for (const auto& pl_json : json["rtp"]["rtx_payload_types"]) {
  52. std::vector<std::string> members = pl_json.getMemberNames();
  53. RTC_CHECK_EQ(members.size(), 1);
  54. Json::Value rtx_payload_type = pl_json[members[0]];
  55. receive_config.rtp.rtx_associated_payload_types[std::stoi(members[0])] =
  56. rtx_payload_type.asInt64();
  57. }
  58. for (const auto& ext_json : json["rtp"]["extensions"]) {
  59. receive_config.rtp.extensions.emplace_back(ext_json["uri"].asString(),
  60. ext_json["id"].asInt64(),
  61. ext_json["encrypt"].asBool());
  62. }
  63. return receive_config;
  64. }
  65. Json::Value GenerateVideoReceiveStreamJsonConfig(
  66. const VideoReceiveStream::Config& config) {
  67. Json::Value root_json;
  68. root_json["decoders"] = Json::Value(Json::arrayValue);
  69. for (const auto& decoder : config.decoders) {
  70. Json::Value decoder_json;
  71. decoder_json["payload_type"] = decoder.payload_type;
  72. decoder_json["payload_name"] = decoder.video_format.name;
  73. decoder_json["codec_params"] = Json::Value(Json::arrayValue);
  74. for (const auto& codec_param_entry : decoder.video_format.parameters) {
  75. Json::Value codec_param_json;
  76. codec_param_json[codec_param_entry.first] = codec_param_entry.second;
  77. decoder_json["codec_params"].append(codec_param_json);
  78. }
  79. root_json["decoders"].append(decoder_json);
  80. }
  81. Json::Value rtp_json;
  82. rtp_json["remote_ssrc"] = config.rtp.remote_ssrc;
  83. rtp_json["local_ssrc"] = config.rtp.local_ssrc;
  84. rtp_json["rtcp_mode"] = config.rtp.rtcp_mode == RtcpMode::kCompound
  85. ? "RtcpMode::kCompound"
  86. : "RtcpMode::kReducedSize";
  87. rtp_json["transport_cc"] = config.rtp.transport_cc;
  88. rtp_json["lntf"]["enabled"] = config.rtp.lntf.enabled;
  89. rtp_json["nack"]["rtp_history_ms"] = config.rtp.nack.rtp_history_ms;
  90. rtp_json["ulpfec_payload_type"] = config.rtp.ulpfec_payload_type;
  91. rtp_json["red_payload_type"] = config.rtp.red_payload_type;
  92. rtp_json["rtx_ssrc"] = config.rtp.rtx_ssrc;
  93. rtp_json["rtx_payload_types"] = Json::Value(Json::arrayValue);
  94. for (auto& kv : config.rtp.rtx_associated_payload_types) {
  95. Json::Value val;
  96. val[std::to_string(kv.first)] = kv.second;
  97. rtp_json["rtx_payload_types"].append(val);
  98. }
  99. rtp_json["extensions"] = Json::Value(Json::arrayValue);
  100. for (auto& ext : config.rtp.extensions) {
  101. Json::Value ext_json;
  102. ext_json["uri"] = ext.uri;
  103. ext_json["id"] = ext.id;
  104. ext_json["encrypt"] = ext.encrypt;
  105. rtp_json["extensions"].append(ext_json);
  106. }
  107. root_json["rtp"] = rtp_json;
  108. root_json["render_delay_ms"] = config.render_delay_ms;
  109. root_json["target_delay_ms"] = config.target_delay_ms;
  110. return root_json;
  111. }
  112. } // namespace test.
  113. } // namespace webrtc.