I want to create a mosaic for cameras on the TV, but my DVR is old and doesn't have RTSP support.
I figured out that I can use the SDK from Dahua. I followed this question to help me with the login process.
It worked, and now I really want to get the buffer and try to stream using WebRTC. Here is my code:
const ffi = require('ffi-napi');
const ref = require('ref-napi');
const libm = ffi.Library('./dhnetsdk', {
CLIENT_Init: [ref.types.bool, []],
CLIENT_LoginEx2: [ref.types.int64, [
'string', // pchDVRIP
ref.types.ushort, // wDVRPort
'string', // pchUserName
'string', // pchPassword
ref.types.int, // emSpecCap
'pointer', // pCapParam
'pointer', // lpDeviceInfo
'int*', // error
]],
CLIENT_Cleanup: [ref.types.void, []],
CLIENT_GetLastError: [ref.types.long, []],
CLIENT_SetNetworkParam: [ref.types.void, [
ref.types.Object
]],
CLIENT_GetSDKVersion: [ref.types.long, []],
CLIENT_RealPlay: [ref.types.int64, [
ref.types.int64, // lLoginID
ref.types.int, // nChannelID
]],
CLIENT_SetRealDataCallBackEx2: [ref.types.bool, [
ref.types.int64, // lRealHandle
'pointer', // fRealDataCallBackEx
ref.types.uchar, // dwUser
ref.types.uchar, // dwFlag
]],
CLIENT_Logout: [ref.types.bool, [
ref.types.int64
]]
});
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
(async () => {
if (libm.CLIENT_Init()) {
try {
const pchDVRIP = 'myDVRIP';
const wDVRPort = 37777;
const pchUserName = 'user';
const pchPassword = '******';
const emSpecCap = 0;
const pCapParam = null;
const lpDeviceInfo = null;
const error = ref.alloc('int');
const loginID = libm.CLIENT_LoginEx2(pchDVRIP, wDVRPort, pchUserName, pchPassword, emSpecCap, pCapParam, lpDeviceInfo, error);
if (loginID == 0) {
throw new Error('Failed login: ' + error.deref().toString());
}
await sleep(1000);
const realID = libm.CLIENT_RealPlay(loginID, 0);
if (0 == realID) {
throw new Error("CLIENT_RealPlayEx: failed! Error code: " + libm.CLIENT_GetLastError().toString());
}
const fRealDataCallBackEx = ffi.Callback('void', ['int64', 'uchar', 'pointer', 'uchar', 'int64', 'uchar'],
function (lRealHandle, dwDataType, pBuffer, dwBufSize, param, dwUser) {
console.log('onca');
console.log({
lRealHandle, dwDataType, pBuffer, dwBufSize, param, dwUser
});
});
await sleep(1000);
const result = libm.CLIENT_SetRealDataCallBackEx2(realID, fRealDataCallBackEx, null, 2);
console.log(result);
libm.CLIENT_Logout(loginID);
} catch (error) {
console.log(error);
}
libm.CLIENT_Cleanup();
} else {
console.log('Init failed');
}
})();
The result of libm.CLIENT_SetRealDataCallBackEx2
is true
, indicating that it worked. However, the callback function is not being called.
I attempted to create the callback as per the documentation, but I didn't receive the buffer information in the callback function. It seems like the callback function is being ignored.