| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #ifndef TINYPLAYER3_RECEIVER_BASE_H
- #define TINYPLAYER3_RECEIVER_BASE_H
- #include "codec/codec_base.hpp"
- #include "core/utility.hpp"
- #include <fmt/chrono.h>
- #include <fmt/format.h>
- #include <functional>
- enum receiver_type {
- RECEIVER_TCP,
- RECEIVER_UDP,
- RECEIVER_UDP_FEC
- };
- class receiver_base {
- public:
- using cb_func_type = std::function<void(frame_info)>;
- struct create_config {
- cb_func_type cb_func = nullptr;
- bool enable_log = false;
- };
- explicit receiver_base(const create_config &conf) {
- cb_func = conf.cb_func;
- // create log file if requested
- if (conf.enable_log) {
- auto file_name = fmt::format("log_{:%Y_%m_%d_%H_%M_%S}.csv",
- std::chrono::system_clock::now());
- log_file.open(file_name);
- }
- }
- protected:
- void commit_frame(const frame_info &frame) {
- log_frame_received(frame.frame_id);
- cb_func(frame);
- }
- private:
- cb_func_type cb_func;
- std::ofstream log_file;
- void log_frame_received(uint64_t frame_id) {
- if (!log_file.is_open()) return;
- log_file << fmt::format("{},{}\n", frame_id, current_timestamp());
- }
- };
- #endif //TINYPLAYER3_RECEIVER_BASE_H
|