srs-control 0.2.2
Loading...
Searching...
No Matches
UDPWriter.cpp
Go to the documentation of this file.
1#include "UDPWriter.hpp"
4#include "srs/utils/UDPFormatters.hpp" // IWYU pragma: keep
6#include <asio/ip/udp.hpp>
7#include <cstddef>
8#include <fmt/format.h>
9#include <memory>
10#include <ranges>
11#include <spdlog/spdlog.h>
12
13namespace srs::sink
14{
16 asio::ip::udp::endpoint remote_endpoint,
17 std::size_t n_lines,
19 : SinkTask{ fmt::format("{}", remote_endpoint), deser_mode, n_lines }
20 {
21 connections_.reserve(n_lines);
22 output_data_.resize(n_lines);
23 for ([[maybe_unused]] const auto idx : std::views::iota(0, static_cast<int>(n_lines)))
24 {
25 connections_.emplace_back(std::make_unique<connection::UDPWriterConnection>(io_context, remote_endpoint));
26 }
27 }
28
29 UDP::~UDP() noexcept
30 {
31 for (auto& connection : connections_)
32 {
33 connection->close();
34 }
35 spdlog::info("Writer: UDP socket writer to the remote socket {:?} is closed successfully.", get_name());
36 }
37} // namespace srs::sink
SinkTask(std::string_view name, DataConvertOptions prev_convert, std::size_t n_lines=1)
Definition BaseTask.hpp:109
UDP(io_context_type &io_context, asio::ip::udp::endpoint remote_endpoint, std::size_t n_lines, process::DataConvertOptions deser_mode=process::DataConvertOptions::none)
Definition UDPWriter.cpp:15
std::vector< OutputType > output_data_
~UDP() noexcept
Definition UDPWriter.cpp:29
std::vector< std::unique_ptr< connection::UDPWriterConnection > > connections_
fmt formatter related specialization.
asio::thread_pool io_context_type