image_streamer_impl.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef DEPTHGUIDE_IMAGE_STREAMER_IMPL_H
  2. #define DEPTHGUIDE_IMAGE_STREAMER_IMPL_H
  3. #include "module/image_streamer.h"
  4. #include "codec/encoder_nvenc.h"
  5. #include "core/async_queue.hpp"
  6. #include "network_v3/sender_tcp.h"
  7. #include "network_v3/sender_udp_fec.h"
  8. #include <boost/asio/post.hpp>
  9. using boost::asio::post;
  10. struct image_streamer::impl {
  11. create_config conf;
  12. image_streamer *q_this = nullptr;
  13. io_context *ctx = nullptr;
  14. bool is_running = false;
  15. encoder_type chose_encoder_type = ENCODER_NVENC;
  16. std::unique_ptr<encoder_nvenc> enc_nvenc;
  17. // for all encoder
  18. bool enc_save_file = false;
  19. bool enc_save_length = false;
  20. bool enc_idr_requested = false;
  21. // for NvEnc
  22. cv::Size img_size;
  23. float enc_bitrate_mbps = 5.0f; // 5Mbps
  24. // for NvJpeg
  25. // TODO
  26. sender_type chose_sender_type = SENDER_UDP_FEC;
  27. std::shared_ptr<sender_base> sender;
  28. // for all sender
  29. uint16_t sender_listen_port = 5279; // make ImGui happy
  30. io_context *sender_ctx = nullptr;
  31. bool sender_enable_log = false;
  32. bool enable_aux_thread = true; // run sender in another thread
  33. std::unique_ptr<io_context> aux_ctx;
  34. // for UDP and UDP (FEC)
  35. uint16_t sender_mtu = 1500;
  36. // for UDP (FEC)
  37. float sender_parity_rate = 0.2f;
  38. // for auxiliary thread
  39. using frame_queue_type = async_queue<frame_info>;
  40. std::shared_ptr<frame_queue_type> frame_queue;
  41. std::unique_ptr<std::thread> aux_thread;
  42. obj_conn_type img_cb_conn;
  43. explicit impl(create_config _conf) {
  44. conf = _conf;
  45. ctx = conf.asio_ctx;
  46. }
  47. ~impl() {
  48. if (is_running) {
  49. stop();
  50. }
  51. }
  52. void show_config();
  53. void show();
  54. void start();
  55. void change_frame_rate(int fps);
  56. void stop();
  57. void create_encoder();
  58. void create_sender();
  59. void image_callback(obj_name_type name);
  60. frame_info encode_image();
  61. /* sender may run in the auxiliary thread,
  62. * because it may do complex processing in CPU */
  63. void aux_thread_work();
  64. };
  65. #endif //DEPTHGUIDE_IMAGE_STREAMER_IMPL_H