天地伟业解码器sdk二次开发
https://www.likecs.com/show-206201.html
我需要用C++实现,但我自己照着C#改也改不好,
应该回调函数这儿出问题了
这我自己一边现学一遍写的,大部分找着sdk的开发手册来的,肯定有问题,不知道怎么搞了
我看了几个老哥的回复,但是都不太沾边啊,我现在的问题是登录不上去,程序调用不了摄像头
我自己判断是回调函数那边有问题,但是我技术不够,解决不了
试了之后是-3一直是未登录
登录返回值是0,但是回调函数那边没反应
而且它这返回值是0,还返回一个ID,该怎么接收呢
#include<stdio.h>
#include"DecCtrlClient.h"
#include"ActionControl.h"
#include"DecCtrlClientTypes.h"
#include"GlobalTypes.h"
#include"net_sdk_types.h"
#include"RetValue.h"
#include"x_type.h"
#include <iostream>
using namespace std;
int g_iLogonID = -1;
//主回调
int tMainNotify(unsigned long _lID, unsigned int _uiMsg, unsigned int _iChannel, int _iPos, void* _pvParam, int _iParamSize, void* _pvUserData)
{
switch (_uiMsg)
{
case DEC_WCM_DEC_LOGON:
{
if (DEC_LOGON_SUCCESS == (int)_pvParam)
{
DEC_ClientGetLogonState((int)_lID);
cout << "登录成功" << endl;
}
cout << "登录失败" << endl;
break;
}
case DEC_WCM_ERR_ORDER:
break;
case DEC_WCM_DEC_PICSNAP:
cout << "抓拍" << endl;
break;
case DEC_WCM_DEC_GETPICFILENAME:
break;
//......
//......
//......
default:
cout << "未有正确消息值传递进来" << endl;
break;
}
return 0;
}
//参数改变回调函数
int tParaChangeNotify(unsigned long _lID, unsigned int _uiMsg, unsigned int _iChannel, int _iPos, void* _pvParam, int _iParamSize, void* _pvUserData)
{
switch (_uiMsg)
{
case DEC_PARACHANGE_ENCODERPAPA:
break;
//......
//......
//......
default:
cout << "未有消息值传递进来" << endl;
break;
}
return 0;
}
/*
int PrintScreen() {
int iRet = -1;
ServerItem tServerItem = { 0 };
tServerItem.iSize = sizeof(ServerItem);
PicSnap Sp = {0};
Sp.uServerItem = tServerItem;
//iRet = DEC_ClientSendCommand(g_iLogonID,0,0, DEC_COMMAND_PICSNAP, Sp,1024);
}
*/
int main() {
//初始化
DEC_ClientStartup(0,NULL);
//设置回调函数
DecNotifyFun tDecNotifyFun = { 0 };
tDecNotifyFun.iSize = sizeof(DecNotifyFun);
tDecNotifyFun.pMainNotify = tMainNotify;
tDecNotifyFun.pParamChangeNotify = tParaChangeNotify;
DEC_ClientSetNotify(&tDecNotifyFun);
//登录设备
g_iLogonID = DEC_ClientLogon("192.168.1.2", "Admin", "1111", 3000);
if (g_iLogonID < 0)
{
cout << g_iLogonID << endl;
OutputDebugString("Logon failed!\n");
}
//抓拍
cout << "****************" << endl;
//注销登录
DEC_ClientLogout(g_iLogonID);
//释放SDK资源
DEC_ClientCleanup();
return 0;
}
以下是一个简单的示例代码,用于使用天地伟业解码器sdk进行解码:
#include <iostream>
#include "TDWDecoder.h"
int main() {
// 创建解码器
TDWDecoder decoder;
// 打开视频文件
if (!decoder.open("test.mp4")) {
std::cerr << "Failed to open video file!" << std::endl;
return -1;
}
// 获取视频信息
int width = decoder.getWidth();
int height = decoder.getHeight();
int fps = decoder.getFPS();
int frameCount = decoder.getFrameCount();
std::cout << "Video Info: " << width << "x" << height << ", " << fps << "fps, " << frameCount << " frames" << std::endl;
// 解码视频帧
for (int i = 0; i < frameCount; i++) {
// 获取下一帧
cv::Mat frame;
if (!decoder.read(frame)) {
std::cerr << "Failed to read frame " << i << "!" << std::endl;
break;
}
// 显示帧
cv::imshow("Frame", frame);
cv::waitKey(1);
}
// 关闭解码器
decoder.release();
return 0;
}
在这个示例中,我们首先创建了一个TDWDecoder对象,然后使用open()函数打开了一个名为"test.mp4"的视频文件。然后我们通过getWidth()、getHeight()、getFPS()和getFrameCount()函数获取了视频的一些基本信息,并将其打印到控制台上。接着我们使用read()函数逐帧读取视频,然后使用imshow()函数显示每一帧。最后我们使用release()函数释放解码器对象。
请注意,这只是一个简单的示例代码,你需要根据你的具体需求进行修改和扩展。
你可以在C++中使用解码器SDK的回调函数,需要先定义一个函数作为回调函数,在函数中实现你的逻辑,然后将该函数的指针传递给解码器SDK。当解码器SDK需要调用回调函数时,就会调用你定义的函数。下面是一个简单的示例:
// 定义回调函数
void MyCallbackFunction(int data) {
// 在这里实现你的逻辑
std::cout << "Data received: " << data << std::endl;
}
// 将回调函数传递给SDK
DecoderSDK.SetCallbackFunction(MyCallbackFunction);
在上面的示例中,MyCallbackFunction
是一个接受一个整数参数的函数,你可以根据需要定义你自己的回调函数。然后,将函数指针传递给解码器SDK的设置回调函数的接口中。当解码器SDK需要调用回调函数时,就会自动调用你定义的函数。
需要注意的是,回调函数的参数和返回值需要根据SDK的要求进行定义,否则会导致编译错误或运行时错误。另外,你需要在适当的时候取消回调函数,以避免内存泄漏等问题。
天地伟业64位SDK二次开发为网站
可以借鉴下
https://blog.csdn.net/weixin_30256901/article/details/98270328
以下答案由GPT-3.5大模型与博主波罗歌共同编写:
在使用天地伟业解码器SDK进行二次开发时,常常需要用到回调函数进行异步通信,其中回调函数需要遵循特定的函数原型进行编写,以下是一个简单的示例:
int notifyFun(unsigned long lID, unsigned int uiMsg, unsigned int iChannel, int iPos, void* pvParam, int iParamSize, void* pvUserData)
{
// 根据uiMsg的不同值,处理不同的异步通知消息
switch (uiMsg)
{
case DEC_WCM_DEC_LOGON:
if((int)pvParam) // 登录成功
{
printf("DecLogon: %d success.\n", lID);
}
else // 登录失败
{
printf("DecLogon: %d failed.\n", lID);
}
break;
case DEC_WCM_DEC_GOTSTREAM:
printf("Got Stream.Successfully play.\n");
break;
case DEC_WCM_DEC_ERR:
printf("Play Error.\n");
break;
default:
printf("Unknown message %d.\n", uiMsg);
break;
}
return 0;
}
其中我一个常见的问题是,回调函数返回值始终是-3,这可能是由于回调函数名与SDK所要求的回调函数名不一致导致的,具体的回调函数名需在设置回调函数时传入。
以下是一个完整的C++示例代码,可以参考一下:
#include "DecCtrlClient.h"
#include "DecCtrlClientTypes.h"
#include "GlobalTypes.h"
#include "RetValue.h"
#include "x_type.h"
#include <iostream>
using namespace std;
//主回调函数
int tMainNotify(unsigned long _lID, unsigned int _uiMsg, unsigned int _iChannel, int _iPos, void* _pvParam, int _iParamSize, void* _pvUserData)
{
switch (_uiMsg)
{
case DEC_WCM_DEC_LOGON:
{
if ((int)_pvParam)
{
//登录成功
cout << "登录成功" << endl;
}
else
{
//登录失败
cout << "登录失败" << endl;
}
break;
}
default:
{
//其他消息
break;
}
}
return 0;
}
int main()
{
//初始化
DEC_ClientStartup(0, NULL);
//设置回调函数
DecNotifyFun tDecNotifyFun = { 0 };
tDecNotifyFun.iSize = sizeof(DecNotifyFun);
tDecNotifyFun.pMainNotify = tMainNotify;
DEC_ClientSetNotify(&tDecNotifyFun);
//登录设备
int iLogonId = DEC_ClientLogon("192.168.1.2", "admin", "123456", 3000);
if (iLogonId < 0)
{
cout << "登录失败" << endl;
}
//等待用户输入,直到用户输入q
char ch;
do
{
ch = getchar();
} while (ch != 'q');
//注销登录
DEC_ClientLogout(iLogonId);
//释放SDK资源
DEC_ClientCleanup();
return 0;
}
在使用时,不同的功能需要调用不同的命令,可以参考SDK的开发手册进行调用。
同时可以使用日志输出等方法进行调试,确定具体错误原因。
如果我的回答解决了您的问题,请采纳!