srs-control 0.2.2
Loading...
Searching...
No Matches
DataSocket.cpp
Go to the documentation of this file.
1#include "DataSocket.hpp"
3#include "srs/Application.hpp"
8#include <asio/awaitable.hpp>
9#include <asio/detached.hpp>
10#include <asio/impl/co_spawn.hpp>
11#include <cstddef>
12#include <fmt/format.h>
13#include <memory>
14
15namespace srs::connection
16{
17 DataSocket::DataSocket(int port_number,
18 io_context_type& io_context,
19 std::size_t buffer_size,
21 : SpecialSocket(port_number, io_context)
22 , buffer_size_{ buffer_size }
24 , io_context_{ &io_context }
26 , token_{ workflow.get_queue_producer_token() }
27 {
28 }
29
30 // WARN: is it really needed?
31 void DataSocket::register_send_action_imp(asio::awaitable<void> /* action */,
32 const std::shared_ptr<ConnectionType>& /*connection*/)
33 {
34 // asio::co_spawn(*io_context_, std::move(action), asio::detached);
35 }
36
37 void DataSocket::response_handler(const UDPEndpoint& /*endpoint*/, std::size_t read_size)
38 {
39 read_msg_buffer_.resize(read_size);
42 }
43
45 {
46 const auto _ = ExitLogger{};
47 auto& timer = get_cancel_timer();
48 timer.cancel();
49 }
50
52 {
53 if (auto* report = get_report(); report != nullptr)
54 {
55 auto stat = AppReport::FrameReadingStat{};
56 stat.n_frames = get_n_records();
57 stat.total_bytes_read = get_n_bytes();
58 stat.total_time_ns = get_total_time_ns();
59 report->register_frame_reading_result(fmt::format("{}", get_socket().local_endpoint()), stat);
60 }
61 }
62} // namespace srs::connection
BufferQueue::Token token_
DataSocket(int port_number, io_context_type &io_context, std::size_t buffer_size, workflow::AnalysisHandle &workflow)
gsl::not_null< io_context_type * > io_context_
void register_send_action_imp(asio::awaitable< void > action, const std::shared_ptr< ConnectionType > &connection)
void response_handler(const UDPEndpoint &endpoint, std::size_t read_size)
gsl::not_null< workflow::AnalysisHandle * > workflow_handler_
void cancel()
Cancel reading the data from the UDP socket.
auto get_total_time_ns() const -> std::uint64_t
Getter for the total listening time in nano seconds.
auto get_n_records() const -> std::size_t
Getter for the number of frames read.
auto get_n_bytes() const -> std::size_t
Getter for the number of bytes read.
auto get_socket() const -> udp::socket &
Getter for the asio udp socket object.
asio::ip::basic_endpoint< asio::ip::udp > UDPEndpoint
asio::thread_pool io_context_type