From 566a04fad4fff86c3d79877acd8b7347ddc9ef43 Mon Sep 17 00:00:00 2001 From: Maxim Sharabayko Date: Mon, 28 Oct 2024 09:12:56 +0100 Subject: [PATCH] Receive SC can now dump payload to file. --- xtransmit/receive.cpp | 21 +++++++++++++++++++++ xtransmit/receive.hpp | 2 ++ 2 files changed, 23 insertions(+) diff --git a/xtransmit/receive.cpp b/xtransmit/receive.cpp index a9b148f..7d06c22 100644 --- a/xtransmit/receive.cpp +++ b/xtransmit/receive.cpp @@ -94,6 +94,20 @@ void run_pipe(shared_sock src, const config& cfg, unique_ptradd_validator(validator, conn_id); } + std::ofstream dumpfile; + if (!cfg.dump_to_file.empty()) + { + spdlog::info(LOG_SC_RECEIVE "Dumping received payload to file {}.", cfg.dump_to_file); + + dumpfile.open(cfg.dump_to_file, std::ios::out | std::ios::binary); + if (!dumpfile) + { + spdlog::error(LOG_SC_RECEIVE "Failed to open file for output. Path: {0}.", cfg.dump_to_file); + return; + } + } + + const bool is_dumping = dumpfile.is_open(); try { while (!force_break) @@ -113,6 +127,11 @@ void run_pipe(shared_sock src, const config& cfg, unique_ptrvalidate_packet(const_buffer(buffer.data(), bytes)); } + if (is_dumping) + { + dumpfile.write(buffer.data(), bytes); + } + if (cfg.send_reply) { const string out_message("Message received"); @@ -181,6 +200,8 @@ CLI::App* xtransmit::receive::add_subcommand(CLI::App& app, config& cfg, std::ve sc_receive->add_option("--metricsfile", cfg.metrics_file, "Metrics output filename (default stdout)"); sc_receive->add_option("--metricsfreq", cfg.metrics_freq_ms, fmt::format("Metrics report frequency, ms (default {})", cfg.metrics_freq_ms)) ->transform(CLI::AsNumberWithUnit(to_ms, CLI::AsNumberWithUnit::CASE_SENSITIVE)); + sc_receive->add_option("--dump-to-file", cfg.dump_to_file, "Dump received payload to a file (default: none)"); + sc_receive->add_option("--dump-timestamps-to-file", cfg.dump_timestamps_to_file, "Dump timestamps of SRT packets to a file (default: none)"); sc_receive->add_flag("--twoway", cfg.send_reply, "Both send and receive data"); apply_cli_opts(*sc_receive, cfg); diff --git a/xtransmit/receive.hpp b/xtransmit/receive.hpp index 741e82b..b86ae0a 100644 --- a/xtransmit/receive.hpp +++ b/xtransmit/receive.hpp @@ -20,6 +20,8 @@ struct config : stats_config, conn_config bool enable_metrics = false; unsigned metrics_freq_ms = 1000; std::string metrics_file; + std::string dump_to_file; + std::string dump_timestamps_to_file; int max_connections = 1; // Maximum number of connections on a socket int message_size = 1316; };