1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
| #include "mainwindow.h"
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/types_c.h>
void CALLBACK DecCBFun(long nPort, char* pBuf, long nSize, FRAME_INFO* pFrameInfo, long nReserved1, long nReserved2)
{
long lFrameType = pFrameInfo->nType;
if (lFrameType == T_YV12)
{
MainWindow* win = port2MainWindow[nPort];
if (nullptr == win)
{
qDebug() << "lookup main window from " << nPort << " failed.";
return;
}
win->realYuvCallback(pBuf, nSize, pFrameInfo->nStamp, pFrameInfo->nWidth, pFrameInfo->nHeight);
}
}
void MainWindow::realYuvCallback(const char* pBuf, int len, int64_t nStamp, int width, int height)
{
cv::Mat dst(height, width, CV_8UC3);
cv::Mat src(height + height / 2, width, CV_8UC1, (uchar*)pBuf);
cv::cvtColor(src, dst, CV_YUV2RGBA_YV12); // CV_YUV2BGR_YV12);
cv::line(dst, cv::Point(0, 0), cv::Point(100, 100), cv::Scalar(255, 0, 0), 10);
vren_.Render_d3d(dst);
}
void CALLBACK fRealDataCallBack(LONG lRealHandle, DWORD dwDataType, BYTE* pBuffer, DWORD dwBufSize, void* pUser)
{
MainWindow* pThis = (MainWindow*)pUser;
pThis->realDataCallback(lRealHandle, dwDataType, pBuffer, dwBufSize);
}
void MainWindow::realDataCallback(LONG lRealHandle, DWORD dwDataType, BYTE* pBuffer, DWORD dwBufSize)
{
DWORD dRet = 0;
BOOL inData = FALSE;
switch (dwDataType)
{
case NET_DVR_SYSHEAD:
if (!PlayM4_GetPort(&port_))
{
break;
}
port2MainWindow[port_] = this;
playWnd_ = (HWND)ui->widgetVideo->winId();
vren_.SetParam(playWnd_);
if (!PlayM4_OpenStream(port_, pBuffer, dwBufSize, 1024 * 1024))
{
dRet = PlayM4_GetLastError(port_);
break;
}
if (!PlayM4_SetDecCallBackEx(port_, DecCBFun, NULL, NULL))
{
dRet = PlayM4_GetLastError(port_);
break;
}
if (!PlayM4_Play(port_, NULL)) // playWnd_))
{
dRet = PlayM4_GetLastError(port_);
break;
}
}
} |