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.

119 lines
3.1KB

  1. /*
  2. * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
  5. *
  6. * Use of this source code is governed by MIT license that can be found in the
  7. * LICENSE file in the root of the source tree. All contributing project authors
  8. * may be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef DEVICE_DEVICEHK_H_
  11. #define DEVICE_DEVICEHK_H_
  12. #include <sys/time.h>
  13. #include "HCNetSDK.h"
  14. #include "PlayM4.h"
  15. #include "Device/Device.h"
  16. #include "Util/onceToken.h"
  17. #include "Util/logger.h"
  18. #include "Util/TimeTicker.h"
  19. using namespace toolkit;
  20. namespace mediakit {
  21. class connectInfo {
  22. public:
  23. connectInfo(const char *_strDevIp,
  24. uint16_t _ui16DevPort,
  25. const char *_strUserName,
  26. const char *_strPwd) {
  27. strDevIp = _strDevIp;
  28. ui16DevPort = _ui16DevPort;
  29. strUserName = _strUserName;
  30. strPwd = _strPwd;
  31. }
  32. string strDevIp;
  33. uint16_t ui16DevPort;
  34. string strUserName;
  35. string strPwd;
  36. };
  37. class connectResult {
  38. public:
  39. string strDevName;
  40. uint16_t ui16ChnStart;
  41. uint16_t ui16ChnCount;
  42. };
  43. typedef function<void(bool success, const connectResult &)> connectCB;
  44. typedef function<void(bool success)> relustCB;
  45. class Device: public enable_shared_from_this<Device> {
  46. public:
  47. using Ptr = std::shared_ptr<Device>;
  48. Device() {
  49. }
  50. virtual ~Device(){ disconnect([](bool bSuccess){
  51. });};
  52. virtual void connectDevice(const connectInfo &info, const connectCB &cb, int iTimeOut = 3)=0;
  53. virtual void disconnect(const relustCB &cb) {
  54. }
  55. virtual void addChannel(int iChnIndex, bool bMainStream = true)=0;
  56. virtual void delChannel(int iChnIndex)=0;
  57. virtual void addAllChannel(bool bMainStream = true)=0;
  58. protected:
  59. void onConnected() {
  60. }
  61. void onDisconnected(bool bSelfDisconnect) {
  62. }
  63. };
  64. class DevChannelHK;
  65. class DeviceHK: public Device {
  66. public:
  67. using Ptr = std::shared_ptr<DeviceHK>;
  68. DeviceHK();
  69. virtual ~DeviceHK();
  70. void connectDevice(const connectInfo &info, const connectCB &cb, int iTimeOut = 3) override;
  71. void disconnect(const relustCB &cb) override;
  72. void addChannel(int iChnIndex, bool bMainStream = true) override;
  73. void delChannel(int iChnIndex) override;
  74. void addAllChannel(bool bMainStream = true) override;
  75. private:
  76. map<int, std::shared_ptr<DevChannel> > m_mapChannels;
  77. int64_t m_i64LoginId = -1;
  78. NET_DVR_DEVICEINFO_V30 m_deviceInfo;
  79. void onConnected(LONG lUserID, LPNET_DVR_DEVICEINFO_V30 lpDeviceInfo);
  80. };
  81. class DevChannelHK: public DevChannel {
  82. public:
  83. using Ptr = std::shared_ptr<DevChannel>;
  84. DevChannelHK(int64_t i64LoginId, const char *pcDevName, int iChn, bool bMainStream = true);
  85. virtual ~DevChannelHK();
  86. protected:
  87. int64_t m_i64LoginId = -1;
  88. int64_t m_i64PreviewHandle = -1;
  89. int m_iPlayHandle = -1;
  90. void onPreview(DWORD dwDataType, BYTE *pBuffer, DWORD dwBufSize);
  91. void onGetDecData(char * pBuf, int nSize, FRAME_INFO * pFrameInfo);
  92. bool m_bVideoSeted = false;
  93. bool m_bAudioSeted = false;
  94. };
  95. } /* namespace mediakit */
  96. #endif /* DEVICE_DEVICEHK_H_ */