ZLMediaKit/tests/DeviceHK/DeviceHK.h

119 lines
3.2 KiB
C++
Raw Normal View History

2017-10-09 22:11:01 +08:00
/*
2020-04-04 20:30:09 +08:00
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
2017-09-27 16:20:30 +08:00
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
2020-04-04 20:30:09 +08:00
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
2017-05-11 11:26:45 +08:00
*/
#ifndef DEVICE_DEVICEHK_H_
#define DEVICE_DEVICEHK_H_
#include <sys/time.h>
#include "HCNetSDK.h"
#include "PlayM4.h"
#include "Device/Device.h"
#include "Util/onceToken.h"
#include "Util/logger.h"
#include "Util/TimeTicker.h"
2018-10-24 17:17:55 +08:00
using namespace toolkit;
2017-05-11 11:26:45 +08:00
2018-10-24 17:17:55 +08:00
namespace mediakit {
2017-05-11 11:26:45 +08:00
class connectInfo {
public:
2020-03-20 11:51:24 +08:00
connectInfo(const char *_strDevIp,
uint16_t _ui16DevPort,
const char *_strUserName,
const char *_strPwd) {
strDevIp = _strDevIp;
ui16DevPort = _ui16DevPort;
strUserName = _strUserName;
strPwd = _strPwd;
}
string strDevIp;
uint16_t ui16DevPort;
string strUserName;
string strPwd;
2017-05-11 11:26:45 +08:00
};
class connectResult {
public:
2020-03-20 11:51:24 +08:00
string strDevName;
uint16_t ui16ChnStart;
uint16_t ui16ChnCount;
2017-05-11 11:26:45 +08:00
};
typedef function<void(bool success, const connectResult &)> connectCB;
typedef function<void(bool success)> relustCB;
class Device: public enable_shared_from_this<Device> {
public:
2020-03-20 11:51:24 +08:00
typedef std::shared_ptr<Device> Ptr;
Device() {
}
virtual ~Device(){ disconnect([](bool bSuccess){
});};
2017-05-11 11:26:45 +08:00
2020-03-20 11:51:24 +08:00
virtual void connectDevice(const connectInfo &info, const connectCB &cb, int iTimeOut = 3)=0;
2017-05-11 11:26:45 +08:00
2020-03-20 11:51:24 +08:00
virtual void disconnect(const relustCB &cb) {
}
2017-05-11 11:26:45 +08:00
2020-03-20 11:51:24 +08:00
virtual void addChannel(int iChnIndex, bool bMainStream = true)=0;
2017-05-11 11:26:45 +08:00
2020-03-20 11:51:24 +08:00
virtual void delChannel(int iChnIndex)=0;
2017-05-11 11:26:45 +08:00
2020-03-20 11:51:24 +08:00
virtual void addAllChannel(bool bMainStream = true)=0;
2017-05-11 11:26:45 +08:00
protected:
2020-03-20 11:51:24 +08:00
void onConnected() {
}
void onDisconnected(bool bSelfDisconnect) {
}
2017-05-11 11:26:45 +08:00
};
class DevChannelHK;
class DeviceHK: public Device {
public:
2020-03-20 11:51:24 +08:00
typedef std::shared_ptr<DeviceHK> Ptr;
DeviceHK();
virtual ~DeviceHK();
2017-05-11 11:26:45 +08:00
2020-03-20 11:51:24 +08:00
void connectDevice(const connectInfo &info, const connectCB &cb, int iTimeOut = 3) override;
void disconnect(const relustCB &cb) override;
2017-05-11 11:26:45 +08:00
2020-03-20 11:51:24 +08:00
void addChannel(int iChnIndex, bool bMainStream = true) override;
void delChannel(int iChnIndex) override;
void addAllChannel(bool bMainStream = true) override;
2017-05-11 11:26:45 +08:00
private:
2020-03-20 11:51:24 +08:00
map<int, std::shared_ptr<DevChannel> > m_mapChannels;
int64_t m_i64LoginId = -1;
NET_DVR_DEVICEINFO_V30 m_deviceInfo;
void onConnected(LONG lUserID, LPNET_DVR_DEVICEINFO_V30 lpDeviceInfo);
2017-05-11 11:26:45 +08:00
};
class DevChannelHK: public DevChannel {
public:
2020-03-20 11:51:24 +08:00
typedef std::shared_ptr<DevChannel> Ptr;
DevChannelHK(int64_t i64LoginId, const char *pcDevName, int iChn, bool bMainStream = true);
virtual ~DevChannelHK();
2017-05-11 11:26:45 +08:00
protected:
2020-03-20 11:51:24 +08:00
int64_t m_i64LoginId = -1;
int64_t m_i64PreviewHandle = -1;
int m_iPlayHandle = -1;
void onPreview(DWORD dwDataType, BYTE *pBuffer, DWORD dwBufSize);
void onGetDecData(char * pBuf, int nSize, FRAME_INFO * pFrameInfo);
bool m_bVideoSeted = false;
bool m_bAudioSeted = false;
2017-05-11 11:26:45 +08:00
};
2018-10-24 17:17:55 +08:00
} /* namespace mediakit */
2017-05-11 11:26:45 +08:00
#endif /* DEVICE_DEVICEHK_H_ */