inference.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * @Description: 推理模块
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2021-10-13 09:37:51
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2021-10-13 09:40:21
  8. */
  9. #pragma once
  10. #include <iostream>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <gst/gst.h>
  14. #include <glib.h>
  15. #include <stdio.h>
  16. #include <math.h>
  17. #include <string.h>
  18. #include <sys/time.h>
  19. #include "gstnvdsmeta.h"
  20. #include "gst-nvmessage.h"
  21. #include "DataSource.h"
  22. // ZLMediaKit
  23. #include "Util/logger.h"
  24. #include "Util/NoticeCenter.h"
  25. #include "Poller/EventPoller.h"
  26. #include "Player/PlayerProxy.h"
  27. #include "Rtmp/RtmpPusher.h"
  28. #include "Common/config.h"
  29. #include "Pusher/MediaPusher.h"
  30. #include "Extension/Frame.h"
  31. #include "Util/SqlPool.h"
  32. #include "Network/TcpClient.h"
  33. #include "Poller/Timer.h"
  34. #include "TCPClient.h"
  35. #include <mutex>
  36. #include <list>
  37. using namespace std;
  38. namespace MIVA{
  39. // 基于Deepstream
  40. class Inference
  41. {
  42. private:
  43. // Deepstream
  44. GMainLoop *loop = NULL;
  45. GstElement *pipeline = NULL,*streammux =NULL, *sink = NULL, *pgie = NULL,
  46. *queue1, *queue2, *queue3, *queue4, *queue5, *nvvidconv = NULL,
  47. *nvosd = NULL, *tiler = NULL;
  48. GstElement *transform = NULL;
  49. GstBus *bus = NULL;
  50. guint bus_watch_id;
  51. GstPad *tiler_src_pad = NULL;
  52. guint tiler_rows, tiler_columns;
  53. guint pgie_batch_size;
  54. std::vector<DataSource> m_DataList;
  55. public:
  56. static std::shared_ptr<Inference> CreateNew();
  57. Inference();
  58. ~Inference();
  59. public:
  60. int32_t Init(std::vector<DataSource> DataList);
  61. void Destory();
  62. void ReadyTask();
  63. void StartTask();
  64. void PauseTask();
  65. void StopTask();
  66. void RestartTask();
  67. private:
  68. // static
  69. static GstPadProbeReturn tiler_src_pad_buffer_probe(GstPad * pad, GstPadProbeInfo * info, gpointer u_data);
  70. static gboolean bus_call (GstBus * bus, GstMessage * msg, gpointer data);
  71. static void decodebin_child_added (GstChildProxy * child_proxy, GObject * object,
  72. gchar * name, gpointer user_data);
  73. static GstElement * create_uridecode_bin (guint index, gchar * filename);
  74. static void cb_newpad (GstElement * decodebin, GstPad * pad, gpointer data);
  75. // 动态管理源
  76. gboolean add_sources (int source_Id, std::string uri);
  77. void stop_release_source (gint source_id);
  78. };
  79. }