| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #ifndef DEPTHGUIDE_IMAGE_STREAMER_IMPL_H
- #define DEPTHGUIDE_IMAGE_STREAMER_IMPL_H
- #include "module/image_streamer.h"
- #include "codec/encoder_nvenc.h"
- #include "codec/scene_encoder.h"
- #include "core/async_queue.hpp"
- #include "network_v3/sender_tcp.h"
- #include "network_v3/sender_udp_fec.h"
- #include <boost/asio/post.hpp>
- using boost::asio::post;
- struct image_streamer::impl {
- create_config conf;
- image_streamer *q_this = nullptr;
- io_context *ctx = nullptr;
- bool is_running = false;
- encoder_type chose_encoder_type = ENCODER_NVENC;
- std::unique_ptr<encoder_nvenc> enc_nvenc;
- // for all encoder
- bool enc_save_file = false;
- bool enc_save_length = false;
- bool enc_idr_requested = false;
- // for NvEnc
- cv::Size img_size;
- float enc_bitrate_mbps = 5.0f; // 5Mbps
- // for NvJpeg
- // TODO
- sender_type chose_sender_type = SENDER_UDP_FEC;
- std::shared_ptr<sender_base> sender;
- // for all sender
- uint16_t sender_listen_port = 5279; // make ImGui happy
- io_context *sender_ctx = nullptr;
- bool sender_enable_log = false;
- bool enable_aux_thread = true; // run sender in another thread
- std::unique_ptr<io_context> aux_ctx;
- // for UDP and UDP (FEC)
- uint16_t sender_mtu = 1500;
- // for UDP (FEC)
- float sender_parity_rate = 0.2f;
- // for auxiliary thread
- using frame_queue_type = async_queue<frame_info>;
- std::shared_ptr<frame_queue_type> frame_queue;
- std::unique_ptr<std::thread> aux_thread;
- obj_conn_type img_cb_conn;
- // for scene encoder
- uint64_t last_scene_id = 0;
- std::unique_ptr<image_encoder> i_enc;
- std::unique_ptr<pc_encoder> p_enc;
- std::unique_ptr<scene_encoder> s_enc;
- explicit impl(create_config _conf) {
- conf = _conf;
- ctx = conf.asio_ctx;
- }
- ~impl() {
- if (is_running) {
- stop();
- }
- }
- void show_config();
- void show();
- void start();
- void change_frame_rate(int fps);
- void stop();
- void create_scene_encoder();
- void create_encoder();
- void create_sender();
- void image_callback(obj_name_type name);
- frame_info encode_scene();
- frame_info encode_image();
- /* sender may run in the auxiliary thread,
- * because it may do complex processing in CPU */
- void aux_thread_work();
- };
- #endif //DEPTHGUIDE_IMAGE_STREAMER_IMPL_H
|