Skip to content

Commit

Permalink
Receive SC can now dump payload to file.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Oct 28, 2024
1 parent 250326d commit 566a04f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions xtransmit/receive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ void run_pipe(shared_sock src, const config& cfg, unique_ptr<metrics::metrics_wr
metrics->add_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)
Expand All @@ -113,6 +127,11 @@ void run_pipe(shared_sock src, const config& cfg, unique_ptr<metrics::metrics_wr
validator->validate_packet(const_buffer(buffer.data(), bytes));
}

if (is_dumping)
{
dumpfile.write(buffer.data(), bytes);
}

if (cfg.send_reply)
{
const string out_message("Message received");
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions xtransmit/receive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 566a04f

Please sign in to comment.