image_streamer_impl.h 2.3 KB

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