Added JSON generator for VideoReceiveStream::Config objects.

This change adds a new way for test code to serialize the important information
from a VideoReceiveStream::Config so that it can be stored as configuration data
for WebRTC fuzzers. This code isn't included in the object itself as it is only
going to be used to generate new configurations for the fuzzer each time a new
error_correction or video format is added to WebRTC.

Bug: webrtc:10117
Change-Id: I9b6fb8e0345890ab16f6d319d91e4e316d1f2888
Reviewed-on: https://webrtc-review.googlesource.com/c/116920
Commit-Queue: Benjamin Wright <benwright@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26255}
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 773e25f..a21637f 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -327,6 +327,7 @@
 
   rtc_test("test_support_unittests") {
     deps = [
+      ":call_config_utils",
       ":direct_transport",
       ":fake_video_codecs",
       ":fileutils",
@@ -345,6 +346,7 @@
       "../api/video:builtin_video_bitrate_allocator_factory",
       "../api/video:video_frame",
       "../api/video:video_frame_i420",
+      "../call:video_stream_api",
       "../modules/rtp_rtcp:rtp_rtcp",
       "../modules/video_capture",
       "../modules/video_coding:simulcast_test_fixture_impl",
@@ -358,6 +360,7 @@
       "//third_party/abseil-cpp/absl/strings",
     ]
     sources = [
+      "call_config_utils_unittest.cc",
       "direct_transport_unittest.cc",
       "fake_vp8_encoder_unittest.cc",
       "frame_generator_unittest.cc",
diff --git a/test/call_config_utils.cc b/test/call_config_utils.cc
index 48d4849..671220b 100644
--- a/test/call_config_utils.cc
+++ b/test/call_config_utils.cc
@@ -68,5 +68,59 @@
   return receive_config;
 }
 
+Json::Value GenerateVideoReceiveStreamJsonConfig(
+    const VideoReceiveStream::Config& config) {
+  Json::Value root_json;
+
+  root_json["decoders"] = Json::Value(Json::arrayValue);
+  for (const auto& decoder : config.decoders) {
+    Json::Value decoder_json;
+    decoder_json["payload_type"] = decoder.payload_type;
+    decoder_json["payload_name"] = decoder.video_format.name;
+    decoder_json["codec_params"] = Json::Value(Json::arrayValue);
+    for (const auto& codec_param_entry : decoder.video_format.parameters) {
+      Json::Value codec_param_json;
+      codec_param_json[codec_param_entry.first] = codec_param_entry.second;
+      decoder_json["codec_params"].append(codec_param_json);
+    }
+    root_json["decoders"].append(decoder_json);
+  }
+
+  Json::Value rtp_json;
+  rtp_json["remote_ssrc"] = config.rtp.remote_ssrc;
+  rtp_json["local_ssrc"] = config.rtp.local_ssrc;
+  rtp_json["rtcp_mode"] = config.rtp.rtcp_mode == RtcpMode::kCompound
+                              ? "RtcpMode::kCompound"
+                              : "RtcpMode::kReducedSize";
+  rtp_json["remb"] = config.rtp.remb;
+  rtp_json["transport_cc"] = config.rtp.transport_cc;
+  rtp_json["nack"]["rtp_history_ms"] = config.rtp.nack.rtp_history_ms;
+  rtp_json["ulpfec_payload_type"] = config.rtp.ulpfec_payload_type;
+  rtp_json["red_payload_type"] = config.rtp.red_payload_type;
+  rtp_json["rtx_ssrc"] = config.rtp.rtx_ssrc;
+  rtp_json["rtx_payload_types"] = Json::Value(Json::arrayValue);
+
+  for (auto& kv : config.rtp.rtx_associated_payload_types) {
+    Json::Value val;
+    val[std::to_string(kv.first)] = kv.second;
+    rtp_json["rtx_payload_types"].append(val);
+  }
+
+  rtp_json["extensions"] = Json::Value(Json::arrayValue);
+  for (auto& ext : config.rtp.extensions) {
+    Json::Value ext_json;
+    ext_json["uri"] = ext.uri;
+    ext_json["id"] = ext.id;
+    ext_json["encrypt"] = ext.encrypt;
+    rtp_json["extensions"].append(ext_json);
+  }
+  root_json["rtp"] = rtp_json;
+
+  root_json["render_delay_ms"] = config.render_delay_ms;
+  root_json["target_delay_ms"] = config.target_delay_ms;
+
+  return root_json;
+}
+
 }  // namespace test.
 }  // namespace webrtc.
diff --git a/test/call_config_utils.h b/test/call_config_utils.h
index 246c7f8..186c67f 100644
--- a/test/call_config_utils.h
+++ b/test/call_config_utils.h
@@ -23,6 +23,10 @@
     webrtc::Transport* transport,
     const Json::Value& json);
 
+// Serialize a VideoReceiveStream::Config into a Json object.
+Json::Value GenerateVideoReceiveStreamJsonConfig(
+    const VideoReceiveStream::Config& config);
+
 }  // namespace test
 }  // namespace webrtc
 
diff --git a/test/call_config_utils_unittest.cc b/test/call_config_utils_unittest.cc
new file mode 100644
index 0000000..afc48c4
--- /dev/null
+++ b/test/call_config_utils_unittest.cc
@@ -0,0 +1,68 @@
+/*
+ *  Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "test/call_config_utils.h"
+
+#include "call/video_receive_stream.h"
+#include "test/gtest.h"
+
+namespace webrtc {
+namespace test {
+
+TEST(CallConfigUtils, MarshalUnmarshalProcessSameObject) {
+  VideoReceiveStream::Config recv_config(nullptr);
+
+  VideoReceiveStream::Decoder decoder;
+  decoder.payload_type = 10;
+  decoder.video_format.name = "test";
+  decoder.video_format.parameters["99"] = 98;
+  recv_config.decoders.push_back(decoder);
+  recv_config.render_delay_ms = 10;
+  recv_config.target_delay_ms = 15;
+  recv_config.rtp.remote_ssrc = 100;
+  recv_config.rtp.local_ssrc = 101;
+  recv_config.rtp.rtcp_mode = RtcpMode::kCompound;
+  recv_config.rtp.remb = false;
+  recv_config.rtp.transport_cc = false;
+  recv_config.rtp.nack.rtp_history_ms = 150;
+  recv_config.rtp.red_payload_type = 50;
+  recv_config.rtp.rtx_ssrc = 1000;
+  recv_config.rtp.rtx_associated_payload_types[10] = 10;
+  recv_config.rtp.extensions.emplace_back("uri", 128, true);
+
+  VideoReceiveStream::Config unmarshaled_config =
+      ParseVideoReceiveStreamJsonConfig(
+          nullptr, GenerateVideoReceiveStreamJsonConfig(recv_config));
+
+  EXPECT_EQ(recv_config.decoders[0].payload_type,
+            unmarshaled_config.decoders[0].payload_type);
+  EXPECT_EQ(recv_config.decoders[0].video_format.name,
+            unmarshaled_config.decoders[0].video_format.name);
+  EXPECT_EQ(recv_config.decoders[0].video_format.parameters,
+            unmarshaled_config.decoders[0].video_format.parameters);
+  EXPECT_EQ(recv_config.render_delay_ms, unmarshaled_config.render_delay_ms);
+  EXPECT_EQ(recv_config.target_delay_ms, unmarshaled_config.target_delay_ms);
+  EXPECT_EQ(recv_config.rtp.remote_ssrc, unmarshaled_config.rtp.remote_ssrc);
+  EXPECT_EQ(recv_config.rtp.local_ssrc, unmarshaled_config.rtp.local_ssrc);
+  EXPECT_EQ(recv_config.rtp.rtcp_mode, unmarshaled_config.rtp.rtcp_mode);
+  EXPECT_EQ(recv_config.rtp.remb, unmarshaled_config.rtp.remb);
+  EXPECT_EQ(recv_config.rtp.transport_cc, unmarshaled_config.rtp.transport_cc);
+  EXPECT_EQ(recv_config.rtp.nack.rtp_history_ms,
+            unmarshaled_config.rtp.nack.rtp_history_ms);
+  EXPECT_EQ(recv_config.rtp.red_payload_type,
+            unmarshaled_config.rtp.red_payload_type);
+  EXPECT_EQ(recv_config.rtp.rtx_ssrc, unmarshaled_config.rtp.rtx_ssrc);
+  EXPECT_EQ(recv_config.rtp.rtx_associated_payload_types,
+            unmarshaled_config.rtp.rtx_associated_payload_types);
+  EXPECT_EQ(recv_config.rtp.extensions, recv_config.rtp.extensions);
+}
+
+}  // namespace test
+}  // namespace webrtc