Move json.h to webrtc namespace

Bug: webrtc:42232595
Change-Id: Ibc4842b123dad332840e3ee2e13eeb3af8b6a0b5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/377820
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43934}
This commit is contained in:
Evan Shrubsole 2025-02-19 15:21:08 +00:00 committed by WebRTC LUCI CQ
parent 3822af6ef1
commit edc5d89a54
6 changed files with 109 additions and 78 deletions

View File

@ -25,7 +25,7 @@ namespace {
void ReadParam(const Json::Value& root, std::string param_name, bool* param) { void ReadParam(const Json::Value& root, std::string param_name, bool* param) {
RTC_DCHECK(param); RTC_DCHECK(param);
bool v; bool v;
if (rtc::GetBoolFromJsonObject(root, param_name, &v)) { if (GetBoolFromJsonObject(root, param_name, &v)) {
*param = v; *param = v;
} }
} }
@ -33,7 +33,7 @@ void ReadParam(const Json::Value& root, std::string param_name, bool* param) {
void ReadParam(const Json::Value& root, std::string param_name, size_t* param) { void ReadParam(const Json::Value& root, std::string param_name, size_t* param) {
RTC_DCHECK(param); RTC_DCHECK(param);
int v; int v;
if (rtc::GetIntFromJsonObject(root, param_name, &v) && v >= 0) { if (GetIntFromJsonObject(root, param_name, &v) && v >= 0) {
*param = v; *param = v;
} }
} }
@ -41,7 +41,7 @@ void ReadParam(const Json::Value& root, std::string param_name, size_t* param) {
void ReadParam(const Json::Value& root, std::string param_name, int* param) { void ReadParam(const Json::Value& root, std::string param_name, int* param) {
RTC_DCHECK(param); RTC_DCHECK(param);
int v; int v;
if (rtc::GetIntFromJsonObject(root, param_name, &v)) { if (GetIntFromJsonObject(root, param_name, &v)) {
*param = v; *param = v;
} }
} }
@ -49,7 +49,7 @@ void ReadParam(const Json::Value& root, std::string param_name, int* param) {
void ReadParam(const Json::Value& root, std::string param_name, float* param) { void ReadParam(const Json::Value& root, std::string param_name, float* param) {
RTC_DCHECK(param); RTC_DCHECK(param);
double v; double v;
if (rtc::GetDoubleFromJsonObject(root, param_name, &v)) { if (GetDoubleFromJsonObject(root, param_name, &v)) {
*param = static_cast<float>(v); *param = static_cast<float>(v);
} }
} }
@ -59,9 +59,9 @@ void ReadParam(const Json::Value& root,
EchoCanceller3Config::Filter::RefinedConfiguration* param) { EchoCanceller3Config::Filter::RefinedConfiguration* param) {
RTC_DCHECK(param); RTC_DCHECK(param);
Json::Value json_array; Json::Value json_array;
if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) { if (GetValueFromJsonObject(root, param_name, &json_array)) {
std::vector<double> v; std::vector<double> v;
rtc::JsonArrayToDoubleVector(json_array, &v); JsonArrayToDoubleVector(json_array, &v);
if (v.size() != 6) { if (v.size() != 6) {
RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name; RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
return; return;
@ -80,9 +80,9 @@ void ReadParam(const Json::Value& root,
EchoCanceller3Config::Filter::CoarseConfiguration* param) { EchoCanceller3Config::Filter::CoarseConfiguration* param) {
RTC_DCHECK(param); RTC_DCHECK(param);
Json::Value json_array; Json::Value json_array;
if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) { if (GetValueFromJsonObject(root, param_name, &json_array)) {
std::vector<double> v; std::vector<double> v;
rtc::JsonArrayToDoubleVector(json_array, &v); JsonArrayToDoubleVector(json_array, &v);
if (v.size() != 3) { if (v.size() != 3) {
RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name; RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
return; return;
@ -99,7 +99,7 @@ void ReadParam(const Json::Value& root,
RTC_DCHECK(param); RTC_DCHECK(param);
Json::Value subsection; Json::Value subsection;
if (rtc::GetValueFromJsonObject(root, param_name, &subsection)) { if (GetValueFromJsonObject(root, param_name, &subsection)) {
ReadParam(subsection, "downmix", &param->downmix); ReadParam(subsection, "downmix", &param->downmix);
ReadParam(subsection, "adaptive_selection", &param->adaptive_selection); ReadParam(subsection, "adaptive_selection", &param->adaptive_selection);
ReadParam(subsection, "activity_power_threshold", ReadParam(subsection, "activity_power_threshold",
@ -116,9 +116,9 @@ void ReadParam(
param) { param) {
RTC_DCHECK(param); RTC_DCHECK(param);
Json::Value json_array; Json::Value json_array;
if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) { if (GetValueFromJsonObject(root, param_name, &json_array)) {
std::vector<int> v; std::vector<int> v;
rtc::JsonArrayToIntVector(json_array, &v); JsonArrayToIntVector(json_array, &v);
if (v.size() != 2) { if (v.size() != 2) {
RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name; RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
return; return;
@ -133,9 +133,9 @@ void ReadParam(const Json::Value& root,
EchoCanceller3Config::Suppressor::MaskingThresholds* param) { EchoCanceller3Config::Suppressor::MaskingThresholds* param) {
RTC_DCHECK(param); RTC_DCHECK(param);
Json::Value json_array; Json::Value json_array;
if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) { if (GetValueFromJsonObject(root, param_name, &json_array)) {
std::vector<double> v; std::vector<double> v;
rtc::JsonArrayToDoubleVector(json_array, &v); JsonArrayToDoubleVector(json_array, &v);
if (v.size() != 3) { if (v.size() != 3) {
RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name; RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
return; return;
@ -170,7 +170,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
} }
Json::Value aec3_root; Json::Value aec3_root;
success = rtc::GetValueFromJsonObject(root, "aec3", &aec3_root); success = GetValueFromJsonObject(root, "aec3", &aec3_root);
if (!success) { if (!success) {
RTC_LOG(LS_ERROR) << "Missing AEC3 config field: " << json_string; RTC_LOG(LS_ERROR) << "Missing AEC3 config field: " << json_string;
*parsing_successful = false; *parsing_successful = false;
@ -178,14 +178,14 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
} }
Json::Value section; Json::Value section;
if (rtc::GetValueFromJsonObject(aec3_root, "buffering", &section)) { if (GetValueFromJsonObject(aec3_root, "buffering", &section)) {
ReadParam(section, "excess_render_detection_interval_blocks", ReadParam(section, "excess_render_detection_interval_blocks",
&cfg.buffering.excess_render_detection_interval_blocks); &cfg.buffering.excess_render_detection_interval_blocks);
ReadParam(section, "max_allowed_excess_render_blocks", ReadParam(section, "max_allowed_excess_render_blocks",
&cfg.buffering.max_allowed_excess_render_blocks); &cfg.buffering.max_allowed_excess_render_blocks);
} }
if (rtc::GetValueFromJsonObject(aec3_root, "delay", &section)) { if (GetValueFromJsonObject(aec3_root, "delay", &section)) {
ReadParam(section, "default_delay", &cfg.delay.default_delay); ReadParam(section, "default_delay", &cfg.delay.default_delay);
ReadParam(section, "down_sampling_factor", &cfg.delay.down_sampling_factor); ReadParam(section, "down_sampling_factor", &cfg.delay.down_sampling_factor);
ReadParam(section, "num_filters", &cfg.delay.num_filters); ReadParam(section, "num_filters", &cfg.delay.num_filters);
@ -203,7 +203,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
&cfg.delay.delay_candidate_detection_threshold); &cfg.delay.delay_candidate_detection_threshold);
Json::Value subsection; Json::Value subsection;
if (rtc::GetValueFromJsonObject(section, "delay_selection_thresholds", if (GetValueFromJsonObject(section, "delay_selection_thresholds",
&subsection)) { &subsection)) {
ReadParam(subsection, "initial", ReadParam(subsection, "initial",
&cfg.delay.delay_selection_thresholds.initial); &cfg.delay.delay_selection_thresholds.initial);
@ -223,7 +223,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
ReadParam(section, "detect_pre_echo", &cfg.delay.detect_pre_echo); ReadParam(section, "detect_pre_echo", &cfg.delay.detect_pre_echo);
} }
if (rtc::GetValueFromJsonObject(aec3_root, "filter", &section)) { if (GetValueFromJsonObject(aec3_root, "filter", &section)) {
ReadParam(section, "refined", &cfg.filter.refined); ReadParam(section, "refined", &cfg.filter.refined);
ReadParam(section, "coarse", &cfg.filter.coarse); ReadParam(section, "coarse", &cfg.filter.coarse);
ReadParam(section, "refined_initial", &cfg.filter.refined_initial); ReadParam(section, "refined_initial", &cfg.filter.refined_initial);
@ -245,7 +245,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
&cfg.filter.export_linear_aec_output); &cfg.filter.export_linear_aec_output);
} }
if (rtc::GetValueFromJsonObject(aec3_root, "erle", &section)) { if (GetValueFromJsonObject(aec3_root, "erle", &section)) {
ReadParam(section, "min", &cfg.erle.min); ReadParam(section, "min", &cfg.erle.min);
ReadParam(section, "max_l", &cfg.erle.max_l); ReadParam(section, "max_l", &cfg.erle.max_l);
ReadParam(section, "max_h", &cfg.erle.max_h); ReadParam(section, "max_h", &cfg.erle.max_h);
@ -257,7 +257,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
&cfg.erle.clamp_quality_estimate_to_one); &cfg.erle.clamp_quality_estimate_to_one);
} }
if (rtc::GetValueFromJsonObject(aec3_root, "ep_strength", &section)) { if (GetValueFromJsonObject(aec3_root, "ep_strength", &section)) {
ReadParam(section, "default_gain", &cfg.ep_strength.default_gain); ReadParam(section, "default_gain", &cfg.ep_strength.default_gain);
ReadParam(section, "default_len", &cfg.ep_strength.default_len); ReadParam(section, "default_len", &cfg.ep_strength.default_len);
ReadParam(section, "nearend_len", &cfg.ep_strength.nearend_len); ReadParam(section, "nearend_len", &cfg.ep_strength.nearend_len);
@ -269,7 +269,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
&cfg.ep_strength.use_conservative_tail_frequency_response); &cfg.ep_strength.use_conservative_tail_frequency_response);
} }
if (rtc::GetValueFromJsonObject(aec3_root, "echo_audibility", &section)) { if (GetValueFromJsonObject(aec3_root, "echo_audibility", &section)) {
ReadParam(section, "low_render_limit", ReadParam(section, "low_render_limit",
&cfg.echo_audibility.low_render_limit); &cfg.echo_audibility.low_render_limit);
ReadParam(section, "normal_render_limit", ReadParam(section, "normal_render_limit",
@ -288,7 +288,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
&cfg.echo_audibility.use_stationarity_properties_at_init); &cfg.echo_audibility.use_stationarity_properties_at_init);
} }
if (rtc::GetValueFromJsonObject(aec3_root, "render_levels", &section)) { if (GetValueFromJsonObject(aec3_root, "render_levels", &section)) {
ReadParam(section, "active_render_limit", ReadParam(section, "active_render_limit",
&cfg.render_levels.active_render_limit); &cfg.render_levels.active_render_limit);
ReadParam(section, "poor_excitation_render_limit", ReadParam(section, "poor_excitation_render_limit",
@ -299,15 +299,14 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
&cfg.render_levels.render_power_gain_db); &cfg.render_levels.render_power_gain_db);
} }
if (rtc::GetValueFromJsonObject(aec3_root, "echo_removal_control", if (GetValueFromJsonObject(aec3_root, "echo_removal_control", &section)) {
&section)) {
ReadParam(section, "has_clock_drift", ReadParam(section, "has_clock_drift",
&cfg.echo_removal_control.has_clock_drift); &cfg.echo_removal_control.has_clock_drift);
ReadParam(section, "linear_and_stable_echo_path", ReadParam(section, "linear_and_stable_echo_path",
&cfg.echo_removal_control.linear_and_stable_echo_path); &cfg.echo_removal_control.linear_and_stable_echo_path);
} }
if (rtc::GetValueFromJsonObject(aec3_root, "echo_model", &section)) { if (GetValueFromJsonObject(aec3_root, "echo_model", &section)) {
Json::Value subsection; Json::Value subsection;
ReadParam(section, "noise_floor_hold", &cfg.echo_model.noise_floor_hold); ReadParam(section, "noise_floor_hold", &cfg.echo_model.noise_floor_hold);
ReadParam(section, "min_noise_floor_power", ReadParam(section, "min_noise_floor_power",
@ -324,16 +323,16 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
&cfg.echo_model.model_reverb_in_nonlinear_mode); &cfg.echo_model.model_reverb_in_nonlinear_mode);
} }
if (rtc::GetValueFromJsonObject(aec3_root, "comfort_noise", &section)) { if (GetValueFromJsonObject(aec3_root, "comfort_noise", &section)) {
ReadParam(section, "noise_floor_dbfs", &cfg.comfort_noise.noise_floor_dbfs); ReadParam(section, "noise_floor_dbfs", &cfg.comfort_noise.noise_floor_dbfs);
} }
Json::Value subsection; Json::Value subsection;
if (rtc::GetValueFromJsonObject(aec3_root, "suppressor", &section)) { if (GetValueFromJsonObject(aec3_root, "suppressor", &section)) {
ReadParam(section, "nearend_average_blocks", ReadParam(section, "nearend_average_blocks",
&cfg.suppressor.nearend_average_blocks); &cfg.suppressor.nearend_average_blocks);
if (rtc::GetValueFromJsonObject(section, "normal_tuning", &subsection)) { if (GetValueFromJsonObject(section, "normal_tuning", &subsection)) {
ReadParam(subsection, "mask_lf", &cfg.suppressor.normal_tuning.mask_lf); ReadParam(subsection, "mask_lf", &cfg.suppressor.normal_tuning.mask_lf);
ReadParam(subsection, "mask_hf", &cfg.suppressor.normal_tuning.mask_hf); ReadParam(subsection, "mask_hf", &cfg.suppressor.normal_tuning.mask_hf);
ReadParam(subsection, "max_inc_factor", ReadParam(subsection, "max_inc_factor",
@ -342,7 +341,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
&cfg.suppressor.normal_tuning.max_dec_factor_lf); &cfg.suppressor.normal_tuning.max_dec_factor_lf);
} }
if (rtc::GetValueFromJsonObject(section, "nearend_tuning", &subsection)) { if (GetValueFromJsonObject(section, "nearend_tuning", &subsection)) {
ReadParam(subsection, "mask_lf", &cfg.suppressor.nearend_tuning.mask_lf); ReadParam(subsection, "mask_lf", &cfg.suppressor.nearend_tuning.mask_lf);
ReadParam(subsection, "mask_hf", &cfg.suppressor.nearend_tuning.mask_hf); ReadParam(subsection, "mask_hf", &cfg.suppressor.nearend_tuning.mask_hf);
ReadParam(subsection, "max_inc_factor", ReadParam(subsection, "max_inc_factor",
@ -360,7 +359,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
ReadParam(section, "last_lf_band", &cfg.suppressor.last_lf_band); ReadParam(section, "last_lf_band", &cfg.suppressor.last_lf_band);
ReadParam(section, "first_hf_band", &cfg.suppressor.first_hf_band); ReadParam(section, "first_hf_band", &cfg.suppressor.first_hf_band);
if (rtc::GetValueFromJsonObject(section, "dominant_nearend_detection", if (GetValueFromJsonObject(section, "dominant_nearend_detection",
&subsection)) { &subsection)) {
ReadParam(subsection, "enr_threshold", ReadParam(subsection, "enr_threshold",
&cfg.suppressor.dominant_nearend_detection.enr_threshold); &cfg.suppressor.dominant_nearend_detection.enr_threshold);
@ -380,7 +379,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
.use_unbounded_echo_spectrum); .use_unbounded_echo_spectrum);
} }
if (rtc::GetValueFromJsonObject(section, "subband_nearend_detection", if (GetValueFromJsonObject(section, "subband_nearend_detection",
&subsection)) { &subsection)) {
ReadParam( ReadParam(
subsection, "nearend_average_blocks", subsection, "nearend_average_blocks",
@ -398,7 +397,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
ReadParam(section, "use_subband_nearend_detection", ReadParam(section, "use_subband_nearend_detection",
&cfg.suppressor.use_subband_nearend_detection); &cfg.suppressor.use_subband_nearend_detection);
if (rtc::GetValueFromJsonObject(section, "high_bands_suppression", if (GetValueFromJsonObject(section, "high_bands_suppression",
&subsection)) { &subsection)) {
ReadParam(subsection, "enr_threshold", ReadParam(subsection, "enr_threshold",
&cfg.suppressor.high_bands_suppression.enr_threshold); &cfg.suppressor.high_bands_suppression.enr_threshold);
@ -417,7 +416,7 @@ void Aec3ConfigFromJsonString(absl::string_view json_string,
&cfg.suppressor.conservative_hf_suppression); &cfg.suppressor.conservative_hf_suppression);
} }
if (rtc::GetValueFromJsonObject(aec3_root, "multi_channel", &section)) { if (GetValueFromJsonObject(aec3_root, "multi_channel", &section)) {
ReadParam(section, "detect_stereo_content", ReadParam(section, "detect_stereo_content",
&cfg.multi_channel.detect_stereo_content); &cfg.multi_channel.detect_stereo_content);
ReadParam(section, "stereo_detection_threshold", ReadParam(section, "stereo_detection_threshold",

View File

@ -17,7 +17,7 @@
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "rtc_base/string_encode.h" #include "rtc_base/string_encode.h"
namespace rtc { namespace webrtc {
bool GetStringFromJson(const Json::Value& in, std::string* out) { bool GetStringFromJson(const Json::Value& in, std::string* out) {
if (!in.isString()) { if (!in.isString()) {
@ -293,4 +293,4 @@ std::string JsonValueToString(const Json::Value& json) {
return output.substr(0, output.size() - 1); // trim trailing newline return output.substr(0, output.size() - 1); // trim trailing newline
} }
} // namespace rtc } // namespace webrtc

View File

@ -17,7 +17,7 @@
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "json/json.h" // IWYU pragma: export #include "json/json.h" // IWYU pragma: export
namespace rtc { namespace webrtc {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// JSON Helpers // JSON Helpers
@ -78,6 +78,41 @@ bool GetDoubleFromJsonObject(const Json::Value& in,
// Writes out a Json value as a string. // Writes out a Json value as a string.
std::string JsonValueToString(const Json::Value& json); std::string JsonValueToString(const Json::Value& json);
} // namespace webrtc
// Re-export symbols from the webrtc namespace for backwards compatibility.
// TODO(bugs.webrtc.org/4222596): Remove once all references are updated.
namespace rtc {
using ::webrtc::BoolVectorToJsonArray;
using ::webrtc::DoubleVectorToJsonArray;
using ::webrtc::GetBoolFromJson;
using ::webrtc::GetBoolFromJsonArray;
using ::webrtc::GetBoolFromJsonObject;
using ::webrtc::GetDoubleFromJson;
using ::webrtc::GetDoubleFromJsonArray;
using ::webrtc::GetDoubleFromJsonObject;
using ::webrtc::GetIntFromJson;
using ::webrtc::GetIntFromJsonArray;
using ::webrtc::GetIntFromJsonObject;
using ::webrtc::GetStringFromJson;
using ::webrtc::GetStringFromJsonArray;
using ::webrtc::GetStringFromJsonObject;
using ::webrtc::GetUIntFromJson;
using ::webrtc::GetUIntFromJsonArray;
using ::webrtc::GetUIntFromJsonObject;
using ::webrtc::GetValueFromJsonArray;
using ::webrtc::GetValueFromJsonObject;
using ::webrtc::IntVectorToJsonArray;
using ::webrtc::JsonArrayToBoolVector;
using ::webrtc::JsonArrayToDoubleVector;
using ::webrtc::JsonArrayToIntVector;
using ::webrtc::JsonArrayToStringVector;
using ::webrtc::JsonArrayToUIntVector;
using ::webrtc::JsonArrayToValueVector;
using ::webrtc::JsonValueToString;
using ::webrtc::StringVectorToJsonArray;
using ::webrtc::UIntVectorToJsonArray;
using ::webrtc::ValueVectorToJsonArray;
} // namespace rtc } // namespace rtc
#endif // RTC_BASE_STRINGS_JSON_H_ #endif // RTC_BASE_STRINGS_JSON_H_

View File

@ -14,7 +14,7 @@
#include "test/gtest.h" #include "test/gtest.h"
namespace rtc { namespace webrtc {
static Json::Value in_s("foo"); static Json::Value in_s("foo");
static Json::Value in_sn("99"); static Json::Value in_sn("99");
@ -280,4 +280,4 @@ TEST(JsonTest, DoubleVectorToFromArray) {
} }
} }
} // namespace rtc } // namespace webrtc

View File

@ -74,23 +74,23 @@ ParseVideoSendStreamConfig(const Json::Value& json) {
RtpGeneratorOptions::VideoSendStreamConfig config; RtpGeneratorOptions::VideoSendStreamConfig config;
// Parse video source settings. // Parse video source settings.
if (!rtc::GetIntFromJsonObject(json, "duration_ms", &config.duration_ms)) { if (!GetIntFromJsonObject(json, "duration_ms", &config.duration_ms)) {
RTC_LOG(LS_WARNING) << "duration_ms not specified using default: " RTC_LOG(LS_WARNING) << "duration_ms not specified using default: "
<< config.duration_ms; << config.duration_ms;
} }
if (!rtc::GetIntFromJsonObject(json, "video_width", &config.video_width)) { if (!GetIntFromJsonObject(json, "video_width", &config.video_width)) {
RTC_LOG(LS_WARNING) << "video_width not specified using default: " RTC_LOG(LS_WARNING) << "video_width not specified using default: "
<< config.video_width; << config.video_width;
} }
if (!rtc::GetIntFromJsonObject(json, "video_height", &config.video_height)) { if (!GetIntFromJsonObject(json, "video_height", &config.video_height)) {
RTC_LOG(LS_WARNING) << "video_height not specified using default: " RTC_LOG(LS_WARNING) << "video_height not specified using default: "
<< config.video_height; << config.video_height;
} }
if (!rtc::GetIntFromJsonObject(json, "video_fps", &config.video_fps)) { if (!GetIntFromJsonObject(json, "video_fps", &config.video_fps)) {
RTC_LOG(LS_WARNING) << "video_fps not specified using default: " RTC_LOG(LS_WARNING) << "video_fps not specified using default: "
<< config.video_fps; << config.video_fps;
} }
if (!rtc::GetIntFromJsonObject(json, "num_squares", &config.num_squares)) { if (!GetIntFromJsonObject(json, "num_squares", &config.num_squares)) {
RTC_LOG(LS_WARNING) << "num_squares not specified using default: " RTC_LOG(LS_WARNING) << "num_squares not specified using default: "
<< config.num_squares; << config.num_squares;
} }
@ -98,11 +98,11 @@ ParseVideoSendStreamConfig(const Json::Value& json) {
// Parse RTP settings for this configuration. // Parse RTP settings for this configuration.
config.rtp.ssrcs.push_back(kDefaultSsrc); config.rtp.ssrcs.push_back(kDefaultSsrc);
Json::Value rtp_json; Json::Value rtp_json;
if (!rtc::GetValueFromJsonObject(json, "rtp", &rtp_json)) { if (!GetValueFromJsonObject(json, "rtp", &rtp_json)) {
RTC_LOG(LS_ERROR) << "video_streams must have an rtp section"; RTC_LOG(LS_ERROR) << "video_streams must have an rtp section";
return std::nullopt; return std::nullopt;
} }
if (!rtc::GetStringFromJsonObject(rtp_json, "payload_name", if (!GetStringFromJsonObject(rtp_json, "payload_name",
&config.rtp.payload_name)) { &config.rtp.payload_name)) {
RTC_LOG(LS_ERROR) << "rtp.payload_name must be specified"; RTC_LOG(LS_ERROR) << "rtp.payload_name must be specified";
return std::nullopt; return std::nullopt;
@ -114,7 +114,7 @@ ParseVideoSendStreamConfig(const Json::Value& json) {
config.rtp.payload_type = config.rtp.payload_type =
GetDefaultTypeForPayloadName(config.rtp.payload_name); GetDefaultTypeForPayloadName(config.rtp.payload_name);
if (!rtc::GetIntFromJsonObject(rtp_json, "payload_type", if (!GetIntFromJsonObject(rtp_json, "payload_type",
&config.rtp.payload_type)) { &config.rtp.payload_type)) {
RTC_LOG(LS_WARNING) RTC_LOG(LS_WARNING)
<< "rtp.payload_type not specified using default for codec type" << "rtp.payload_type not specified using default for codec type"

View File

@ -288,38 +288,37 @@ TEST(RTCStatsTest, RTCStatsPrintsValidJson) {
json_stats.c_str() + json_stats.size(), json_stats.c_str() + json_stats.size(),
&json_output, nullptr)); &json_output, nullptr));
EXPECT_TRUE(rtc::GetStringFromJsonObject(json_output, "id", &id)); EXPECT_TRUE(GetStringFromJsonObject(json_output, "id", &id));
EXPECT_TRUE(rtc::GetIntFromJsonObject(json_output, "timestamp", &timestamp)); EXPECT_TRUE(GetIntFromJsonObject(json_output, "timestamp", &timestamp));
EXPECT_TRUE(rtc::GetBoolFromJsonObject(json_output, "mBool", &m_bool)); EXPECT_TRUE(GetBoolFromJsonObject(json_output, "mBool", &m_bool));
EXPECT_TRUE(rtc::GetIntFromJsonObject(json_output, "mInt32", &m_int32)); EXPECT_TRUE(GetIntFromJsonObject(json_output, "mInt32", &m_int32));
EXPECT_TRUE(rtc::GetDoubleFromJsonObject(json_output, "mDouble", &m_double)); EXPECT_TRUE(GetDoubleFromJsonObject(json_output, "mDouble", &m_double));
EXPECT_TRUE(rtc::GetStringFromJsonObject(json_output, "mString", &m_string)); EXPECT_TRUE(GetStringFromJsonObject(json_output, "mString", &m_string));
Json::Value json_array; Json::Value json_array;
EXPECT_TRUE( EXPECT_TRUE(
rtc::GetValueFromJsonObject(json_output, "mSequenceBool", &json_array)); GetValueFromJsonObject(json_output, "mSequenceBool", &json_array));
EXPECT_TRUE(rtc::JsonArrayToBoolVector(json_array, &sequence_bool)); EXPECT_TRUE(JsonArrayToBoolVector(json_array, &sequence_bool));
EXPECT_TRUE( EXPECT_TRUE(
rtc::GetValueFromJsonObject(json_output, "mSequenceInt32", &json_array)); GetValueFromJsonObject(json_output, "mSequenceInt32", &json_array));
EXPECT_TRUE(rtc::JsonArrayToIntVector(json_array, &sequence_int32)); EXPECT_TRUE(JsonArrayToIntVector(json_array, &sequence_int32));
EXPECT_TRUE( EXPECT_TRUE(
rtc::GetValueFromJsonObject(json_output, "mSequenceDouble", &json_array)); GetValueFromJsonObject(json_output, "mSequenceDouble", &json_array));
EXPECT_TRUE(rtc::JsonArrayToDoubleVector(json_array, &sequence_double)); EXPECT_TRUE(JsonArrayToDoubleVector(json_array, &sequence_double));
EXPECT_TRUE( EXPECT_TRUE(
rtc::GetValueFromJsonObject(json_output, "mSequenceString", &json_array)); GetValueFromJsonObject(json_output, "mSequenceString", &json_array));
EXPECT_TRUE(rtc::JsonArrayToStringVector(json_array, &sequence_string)); EXPECT_TRUE(JsonArrayToStringVector(json_array, &sequence_string));
Json::Value json_map; Json::Value json_map;
EXPECT_TRUE( EXPECT_TRUE(
rtc::GetValueFromJsonObject(json_output, "mMapStringDouble", &json_map)); GetValueFromJsonObject(json_output, "mMapStringDouble", &json_map));
for (const auto& entry : map_string_double) { for (const auto& entry : map_string_double) {
double double_output = 0.0; double double_output = 0.0;
EXPECT_TRUE( EXPECT_TRUE(GetDoubleFromJsonObject(json_map, entry.first, &double_output));
rtc::GetDoubleFromJsonObject(json_map, entry.first, &double_output));
EXPECT_NEAR(double_output, entry.second, GetExpectedError(entry.second)); EXPECT_NEAR(double_output, entry.second, GetExpectedError(entry.second));
} }
@ -354,12 +353,11 @@ TEST(RTCStatsTest, RTCStatsPrintsValidJson) {
std::vector<double> sequence_int64_as_double; std::vector<double> sequence_int64_as_double;
EXPECT_TRUE( EXPECT_TRUE(
rtc::GetDoubleFromJsonObject(json_output, "mInt64", &m_int64_as_double)); GetDoubleFromJsonObject(json_output, "mInt64", &m_int64_as_double));
EXPECT_TRUE( EXPECT_TRUE(
rtc::GetValueFromJsonObject(json_output, "mSequenceInt64", &json_array)); GetValueFromJsonObject(json_output, "mSequenceInt64", &json_array));
EXPECT_TRUE( EXPECT_TRUE(JsonArrayToDoubleVector(json_array, &sequence_int64_as_double));
rtc::JsonArrayToDoubleVector(json_array, &sequence_int64_as_double));
double stats_m_int64_as_double = static_cast<double>(*stats.m_int64); double stats_m_int64_as_double = static_cast<double>(*stats.m_int64);
EXPECT_NEAR(m_int64_as_double, stats_m_int64_as_double, EXPECT_NEAR(m_int64_as_double, stats_m_int64_as_double,
@ -375,13 +373,12 @@ TEST(RTCStatsTest, RTCStatsPrintsValidJson) {
// Similarly, read Uint64 as double // Similarly, read Uint64 as double
EXPECT_TRUE( EXPECT_TRUE(
rtc::GetValueFromJsonObject(json_output, "mMapStringUint64", &json_map)); GetValueFromJsonObject(json_output, "mMapStringUint64", &json_map));
for (const auto& entry : map_string_uint64) { for (const auto& entry : map_string_uint64) {
const double stats_value_as_double = const double stats_value_as_double =
static_cast<double>((*stats.m_map_string_uint64)[entry.first]); static_cast<double>((*stats.m_map_string_uint64)[entry.first]);
double double_output = 0.0; double double_output = 0.0;
EXPECT_TRUE( EXPECT_TRUE(GetDoubleFromJsonObject(json_map, entry.first, &double_output));
rtc::GetDoubleFromJsonObject(json_map, entry.first, &double_output));
EXPECT_NEAR(double_output, stats_value_as_double, EXPECT_NEAR(double_output, stats_value_as_double,
GetExpectedError(stats_value_as_double)); GetExpectedError(stats_value_as_double));
} }
@ -392,8 +389,8 @@ TEST(RTCStatsTest, RTCStatsPrintsValidJson) {
int m_uint64; int m_uint64;
EXPECT_FALSE(stats.m_uint32.has_value()); EXPECT_FALSE(stats.m_uint32.has_value());
EXPECT_FALSE(stats.m_uint64.has_value()); EXPECT_FALSE(stats.m_uint64.has_value());
EXPECT_FALSE(rtc::GetIntFromJsonObject(json_output, "mUint32", &m_uint32)); EXPECT_FALSE(GetIntFromJsonObject(json_output, "mUint32", &m_uint32));
EXPECT_FALSE(rtc::GetIntFromJsonObject(json_output, "mUint64", &m_uint64)); EXPECT_FALSE(GetIntFromJsonObject(json_output, "mUint64", &m_uint64));
std::cout << stats.ToJson() << std::endl; std::cout << stats.ToJson() << std::endl;
} }