You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __PROTOCOL_ZL_MEDIASERVER_REST_HEADER__
  2. #define __PROTOCOL_ZL_MEDIASERVER_REST_HEADER__
  3. #ifdef __linux__
  4. #include <features.h>
  5. #endif
  6. #include "../../components/base/basicFunctionality.h"
  7. #include "../../components/base/basicLogCollection.h"
  8. #include "../../components/base/basicSettingsProvider.h"
  9. #include "protocolHTTP.h"
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string>
  13. #include <sys/timeb.h>
  14. #include <sys/types.h>
  15. #include <time.h>
  16. #include <vector>
  17. // https://github.com/xia-chu/ZLMediaKit/wiki
  18. #define ZL_CMD_ADD_FFMPEG 1
  19. #define ZL_CMD_ADD_PROXY 2
  20. #define ZL_ADD_ENCODER_SOURCE ((CSTR) "index/api/addFFmpegSource")
  21. #define ZL_ADD_STREAM_PROXY ((CSTR) "index/api/addStreamProxy")
  22. #define ZL_CLOSE_STREAM ((CSTR) "index/api/close_stream")
  23. #define ZL_DEL_ENCODER_SOURCE ((CSTR) "index/api/delFFmepgSource")
  24. #define ZL_DEL_STREAM_PROXY ((CSTR) "index/api/delStreamProxy")
  25. #define ZL_LIST_SESSIONS ((CSTR) "index/api/getAllSession")
  26. #define ZL_LIST_API ((CSTR) "index/api/getApiList")
  27. #define ZL_LIST_MEDIA ((CSTR) "index/api/getMediaList")
  28. #define ZL_GET_SERVER_CONFIG ((CSTR) "index/api/getServerConfig")
  29. #define ZL_GET_LOAD_STATS ((CSTR) "index/api/getThreadsLoad")
  30. #define ZL_GET_WORK_LOAD_STATS ((CSTR) "index/api/getWorkThreadsLoad")
  31. #define ZL_KICK_SESSION ((CSTR) "index/api/kick_session")
  32. #define ZL_RESTART_SERVER ((CSTR) "index/api/restartServer")
  33. #define ZL_SET_SERVER_CONFIG ((CSTR) "index/api/setServerConfig")
  34. #define ZL_IS_MEDIA_ONLINE ((CSTR) "index/api/isMediaOnline")
  35. typedef struct S_ZL_STREAM_INFO
  36. {
  37. uint32_t streamId;
  38. char key[129];
  39. } ZL_STREAM_INFO;
  40. typedef std::vector<ZL_STREAM_INFO *> V_ZL_STREAM_INFO;
  41. class protocolZLMEDIA : public protocolHTTP
  42. {
  43. private:
  44. basicLogCollection * m_pLog;
  45. config_setting_t * m_pSettings;
  46. char m_pSecret[256];
  47. char m_pAccessPoint[256];
  48. char m_pVHost[256];
  49. char m_pIP[16];
  50. bool m_bSessionOnGo;
  51. bool m_bServerIsPresent;
  52. bool m_bUseSSL;
  53. uint16_t m_nPort;
  54. V_ZL_STREAM_INFO m_vCurrentStreams;
  55. char m_pLastValue[256];
  56. CSTR buildURL(uint8_t CMD, uint32_t streamId, CSTR host, CSTR app, CSTR src);
  57. protected:
  58. virtual bool packetHandler(protocolPackage * Package);
  59. public:
  60. explicit protocolZLMEDIA(config_setting_t * Settings = NULL);
  61. explicit protocolZLMEDIA(CSTR key, CSTR host, CSTR ip, uint32_t port);
  62. ~protocolZLMEDIA();
  63. bool isOnline();
  64. bool restartServer();
  65. bool getConfig();
  66. CSTR addStreamProxy(uint32_t streamId, CSTR app, CSTR mrl);
  67. CSTR addFFmpegSource(uint32_t streamId, CSTR app, CSTR mrl);
  68. bool delStreamProxy(CSTR key);
  69. bool delAllStreamProxys(void);
  70. bool listMedia();
  71. V_ZL_STREAM_INFO * getStreams()
  72. {
  73. return &m_vCurrentStreams;
  74. }
  75. bool requestIsFinished();
  76. };
  77. #endif