-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplaym4interface.cpp
More file actions
582 lines (460 loc) · 17.4 KB
/
playm4interface.cpp
File metadata and controls
582 lines (460 loc) · 17.4 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
#include "playm4interface.h"
#include "errormanager.h"
#include "qtvsplayer.h"
#include "ui_qtvsplayer.h"
#include "infos.h"
//#include <include/PlayM4.h>
#include "filesliste.h"
#include "videoctrls.h"
#include <string>
#include <QtDebug>
#include <Qt>
using namespace std;
bool isIndexed = false;
bool isound = false;
PLAYM4_HWND playm4interface::hwnd;
int playm4interface::m_pblocalportnum = -1;
QString playm4interface::m_pblocalfilepath;
bool playm4interface::FsOpened = false;
void* playm4interface::nUser;
FRAME_INFO *playm4interface::pFRAME_INFO;
int playm4interface::nModule = 0;
int playm4interface::FsTime = 0;
unsigned int playm4interface::VideoFs(QString fileName)
{
QtVsPlayer::LoadCursor(true);
VideoCtrls::EndRead = false;
isound = false;
isIndexed = false;
//initval();
m_pblocalfilepath = fileName;
printf("---File name:%s\r\n",m_pblocalfilepath.toUtf8().data());
if (FsOpened == true) {
Stop();
FreePort();
FsOpened = false;
m_pblocalportnum = -1;
}
if (m_pblocalportnum == -1) {
SetPort();
}
//PlayM4_SetDecCallBackExMend(m_pblocalportnum, &SetDecCallBack, NULL, 0, 0);
// int DecryptStatus = PlayM4_SetSecretKey(m_pblocalportnum, 0, "paassww", 11);
FsOpened= PlayM4_OpenFile(m_pblocalportnum, m_pblocalfilepath.toUtf8().data());
InitCallback(1,360);
if (!FsOpened)
{
DisplayError("PlayM4_OpenFile",PlayM4_GetLastError(m_pblocalportnum));
}
QTime dieTime= QTime::currentTime().addSecs(5);
while(!isIndexed) { // STEP-5
//delay();
if (QTime::currentTime() > dieTime) {
break;
}
}
#if (defined(_WIN32))
// if (!PlayM4_SetDecodeEngineEx(m_pblocalportnum,HARD_DECODE_ENGINE))
// {
// DisplayError("PlayM4_SetDecodeEngineEx",PlayM4_GetLastError(m_pblocalportnum));
// }
#elif defined(__linux__)// | defined(__APPLE__)
int DecodeEngine = PlayM4_GetDecodeEngine(m_pblocalportnum);
if (!DecodeEngine)
{
qDebug() << "Using SOFT_DECODE_ENGINE";
}else{
qDebug() << "Using HARD_DECODE_ENGINE";
}
qDebug() << "Try to set HARD_DECODE_ENGINE";
if (!PlayM4_SetDecodeEngine(m_pblocalportnum,HARD_DECODE_ENGINE))
{
DisplayError("PlayM4_SetDecodeEngine",PlayM4_GetLastError(m_pblocalportnum));
}
DecodeEngine = PlayM4_GetDecodeEngine(m_pblocalportnum);
if (!DecodeEngine)
{
qDebug() << "Using SOFT_DECODE_ENGINE";
}else{
qDebug() << "Using HARD_DECODE_ENGINE";
}/**/
//PlayM4_SetRunTimeInfoCallBack(int nPort, void (CALLBACK* RunTimeInfoCBFun)(int nPort, RunTimeInfo* pstRunTimeInfo, void* pUser), void* pUser);
playm4interface::nModule = 1;
if (! PlayM4_SetRunTimeInfoCallBackEx(m_pblocalportnum, nModule, (void (CALLBACK *)(int , RunTimeInfo* , void* ))SetRunTimeInfoCBFun, nUser))
{
DisplayError("PlayM4_SetRunTimeInfoCallBackEx",PlayM4_GetLastError(m_pblocalportnum));
}
#endif
if (!PlayM4_GetCaps())
{
DisplayError("PlayM4_GetCaps",PlayM4_GetLastError(m_pblocalportnum));
//PlayM4_SetCurrentFrameNum(m_pblocalportnum, 0);
}
if (!PlayM4_PlaySound(m_pblocalportnum))
{
DisplayError("PlayM4_PlaySound",PlayM4_GetLastError(m_pblocalportnum));
}
if (!PlayM4_Play(m_pblocalportnum, hwnd))
{
DisplayError("PlayM4_Play",PlayM4_GetLastError(m_pblocalportnum));
//PlayM4_SetCurrentFrameNum(m_pblocalportnum, 0);
}
int frames = PlayM4_GetFileTotalFrames(m_pblocalportnum); // STEP-6
qDebug() << frames << " <- PlayM4_GetFileTotalFrames()";
FsTime =PlayM4_GetFileTime(m_pblocalportnum);
qDebug() << "File Time" << FsTime;
PlayM4_GetSourceBufferRemain(m_pblocalportnum);
PlayM4_ResetSourceBuffer(m_pblocalportnum);
PlayM4_ResetSourceBufFlag(m_pblocalportnum);
int width = 0, height = 0;
PlayM4_GetPictureSize(m_pblocalportnum,&width,&height);
qDebug() << width << "x" << height << " <- PlayM4_GetPictureSize()" ;
//delay();
QtVsPlayer::WVideoCtrls->RestoreSeek();
QtVsPlayer::WVideoCtrls->InitTimeSlide();
RefreshPlay();
if (!PlayM4_SyncToAudio(m_pblocalportnum, true))
{
DisplayError("PlayM4_SyncToAudio",PlayM4_GetLastError(m_pblocalportnum));
}
QtVsPlayer::LoadCursor(false);
//emit DisplayError(PlayM4_GetLastError(m_pblocalportnum));
return 0;//PlayM4_GetLastError(m_pblocalportnum);
}
void playm4interface::delay()
{
QTime dieTime= QTime::currentTime().addSecs(1);
while (QTime::currentTime() < dieTime)
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
void playm4interface::DisplayError(QString Source, unsigned int ErrMess)
{
QString QerrMess=ErrorManager::error_codes(Source, ErrMess);
//printf("---Hik Sdk error response :from %s : %s\r\n", Source.toUtf8().data(), QerrMess.toUtf8().data());
return;
}
void playm4interface::SetPort()
{
if (m_pblocalportnum == -1) {
//FreePort();
//bool bSuccess;
//from qtdemo//////
unsigned int dwVersion = PlayM4_GetSdkVersion();
QString strPlaySDKVersion;
printf("PlayCtrl V%d.%d.%d.%d\r\n", (0xff000000 & dwVersion)>>24, (0x00ff0000 & dwVersion)>>16,\
(0x0000ff00 & dwVersion)>>8, (0x000000ff & dwVersion));
//ui.m_labelPlayerSDKVersion->setText(strPlaySDKVersion);
//printf("\r\n%.8x <- PlayM4_GetSdkVersion()\r\n",PlayM4_GetSdkVersion());
GetCap(PlayM4_GetCaps());
//bSuccess = PlayM4_GetPort((int *)&m_pblocalportnum);
if (!PlayM4_GetPort(&m_pblocalportnum))
{
DisplayError("PlayM4_GetPort", PlayM4_GetLastError(m_pblocalportnum));
}
printf("Debug---Port:%d\r\n",m_pblocalportnum);
bool CallBResp = false;
#if (defined(_WIN32))
//CallBResp = PlayM4_SetFileRefCallBack(m_pblocalportnum, (void (__stdcall *)(long,char *,long,long,long,long,long,long))PlayM4DisplayCallBack);
#elif defined(__linux__)
//int PlayM4_SetFileRefCallBack(int nPort, void (CALLBACK *pFileRefDone)(unsigned int nPort,void* nUser),void* nUser);
CallBResp = PlayM4_SetFileRefCallBack(m_pblocalportnum, (void (CALLBACK *)(unsigned int,void*))SetFileRefCallBack,nUser);
#endif
if (!CallBResp){
DisplayError("PlayM4_SetFileRefCallBack",PlayM4_GetLastError(m_pblocalportnum));
}
//PlayM4_SetFileEndMsg(m_pblocalportnum, hwnd,0);
VideoCtrls::HikNumPort = m_pblocalportnum;
}
return;
}
void playm4interface::FreePort()
{
if (m_pblocalportnum > -1) {
if (!PlayM4_CloseFile(m_pblocalportnum))
{
DisplayError("PlayM4_CloseFile", PlayM4_GetLastError(m_pblocalportnum));
}
if (!PlayM4_FreePort(m_pblocalportnum))
{
DisplayError("PlayM4_FreePort", PlayM4_GetLastError(m_pblocalportnum));
}
}
m_pblocalportnum = -1;
return;
}
int playm4interface::RefreshPlay()
{
if(isIndexed) {
SetVideoWin(0);
#if (defined(__linux__))
if (!PlayM4_WndResolutionChange(m_pblocalportnum))
{
DisplayError("PlayM4_WndResolutionChange",PlayM4_GetLastError(m_pblocalportnum));
}
#endif
/*if (!PlayM4_RefreshPlay(m_pblocalportnum))
{
DisplayError("PlayM4_RefreshPlay",PlayM4_GetLastError(m_pblocalportnum));
}*/
}
return 0;
}
int playm4interface::SetVideoWin(unsigned int nRegionNum)
{
#if (defined(__linux__))
return PlayM4_SetVideoWindow(m_pblocalportnum,nRegionNum,hwnd);
#endif
return nRegionNum;
}
int playm4interface::Pause(unsigned int nPause)//nPause=1 pause, =0 resume
{
return PlayM4_Pause(m_pblocalportnum,nPause);
}
int playm4interface::Play()
{
bool Ret = false;
Ret = PlayM4_Play(m_pblocalportnum,hwnd);
if (!Ret)
{
DisplayError("PlayM4_Play",PlayM4_GetLastError(m_pblocalportnum));
}else{
RefreshPlay();
FsOpened = true;
}
return Ret;
}
int playm4interface::Stop()
{
if (FsOpened) {
if (isound) {
if (!PlayM4_StopSound())
{
DisplayError("PlayM4_StopSound", PlayM4_GetLastError(m_pblocalportnum));
}
}
if (!PlayM4_Stop(m_pblocalportnum))
{
DisplayError("PlayM4_Stop", PlayM4_GetLastError(m_pblocalportnum));
}
FsOpened = false;
isound = false;
}
return 1;
}
int playm4interface::Fast()
{
//printf("Debug---Fastest Port:%s",(std::to_string(playm4interface::m_pblocalportnum)).data());
return PlayM4_Fast(playm4interface::m_pblocalportnum);
}
int playm4interface::Slow()
{
return PlayM4_Slow(m_pblocalportnum);
}
int playm4interface::OneByOne()
{
return PlayM4_OneByOne(m_pblocalportnum);
}
int playm4interface::OneByOneBack()
{
#if (defined(__linux__))
PlayM4_WndResolutionChange(m_pblocalportnum);
#endif
return PlayM4_ReversePlay(m_pblocalportnum);
//return PlayM4_OneByOneBack(m_pblocalportnum);
}
int playm4interface::SetVolume(unsigned short Volume)
{
/*unsigned short GetVolume = PlayM4_GetVolume(m_pblocalportnum);
qDebug() << GetVolume;*/
return PlayM4_SetVolume(m_pblocalportnum, Volume);
}
/*
void playm4interface::initval()
{
//parameters Assignment
m_pbUserID = usrid;
m_pbCurrChannel = channelnum;
//m_pblocalfilepath.clear();
m_pbdstarttime.clear();
m_pbdstoptime.clear();
m_pbfiletype = 0;
m_pbfileattr = 0;
m_pbdownloadhandle = -1;
//play handle
m_pbhandle = -1;
}
*/
void playm4interface::GetCap(int nFlag)
{
QString csCap="";
if(!(nFlag&SUPPORT_SSE))
{
csCap+="Don't support SSE instruction set;\r\n";
}
if(!(nFlag&SUPPORT_DDRAW))
{
csCap+="Create DirectDraw faild;\r\n";
}
if(!(nFlag&SUPPORT_BLT))
{
csCap+="Error when blitting overlay or offscreen;Error when blitting overlay or offscreen;\r\n";
}
if(!(nFlag&SUPPORT_BLTFOURCC))
{
csCap+="Don't support color-space conversions;\r\n";
}
if(!(nFlag&SUPPORT_BLTSHRINKX))
{
csCap+="Don't support arbitrary shrinking of a surface along the x-axis\r\n";
}
if(!(nFlag&SUPPORT_BLTSHRINKY))
{
csCap+="Don't supports arbitrary shrinking of a surface along the y-axis (vertically);\r\n";
}
if(!(nFlag&SUPPORT_BLTSTRETCHX))
{
csCap+="Don't supports arbitrary stretching of a surface along the x-axis;\r\n";
}
if(!(nFlag&SUPPORT_BLTSTRETCHY))
{
csCap+="Don't supports arbitrary stretching of a surface along the y-axis;\r\n";
}
if(csCap.length()>0)
{
csCap+="If your video adapter chip is made by nVidia,please update the new driver!\r\n";
}
printf("\r\n%s\r\n",csCap.toUtf8().data());
}
void playm4interface::GetMetadatas()
{
bool CallBResp = false;
#if (defined(_WIN32))
PlayM4_SetDecCallBack(m_pblocalportnum,(void (CALLBACK* )(int ,char * ,long ,FRAME_INFO * , void* ,void*))SetDecCallBack);
#elif defined(__linux__)
CallBResp = PlayM4_SetDecCallBack(m_pblocalportnum, (void (CALLBACK *)(int,char *,int,FRAME_INFO *, void*,int))SetDecCallBack);
#endif
if (!CallBResp){
DisplayError("PlayM4_SetDecCallBack",PlayM4_GetLastError(m_pblocalportnum));
}
}
void playm4interface::InitCallback( unsigned int nBeginTime, unsigned int nEndTime)
{
bool CallBResp = false;
#if (defined(_WIN32))
//PlayM4_SetAudioCallBack
BOOL _stdcall PlayM4_SetAudioCallBack (LONG nPort, void (_stdcall * funAudio) (long
nPort, char * pAudioBuf, long nSize, long nStamp, long nType, long nUser), long nUser);
//CallBResp = PlayM4_SetAudioCallBack(m_pblocalportnum, (void (__stdcall *)(long,char *,long,long,long,long))SetAudioCallBack,0);
#elif defined(__linux__)
//int PlayM4_SetAudioCallBack(int nPort, void (__stdcall* funAudio)(int nPort, char* pAudioBuf, int nSize, int nStamp, int nType, int nUser), int nUser);
CallBResp = PlayM4_SetAudioCallBack(m_pblocalportnum, (void (CALLBACK *)(int, char*, int, int, int, int))SetAudioCallBack,0);
#endif
if (!CallBResp){
DisplayError("PlayM4_SetAudioCallBack",PlayM4_GetLastError(m_pblocalportnum));
}
#if (defined(_WIN32))
//CallBResp = PlayM4_SetDecCallBack(m_pblocalportnum, (void (CALLBACK *)(long,char *,long,long,long,long,long,long))PlayM4DisplayCallBack);
#elif defined(__linux__)
//callback work, but no sound anymore !!!
//int PlayM4_SetDecCallBackMend(int nPort,void (CALLBACK* DecCBFun)(int nPort,char * pBuf,int nSize,FRAME_INFO * pFrameInfo, void* nUser,int nReserved2), void* nUser);
//or
//int PlayM4_SetDecCallBack(int nPort,void (CALLBACK* DecCBFun)(int nPort,char* pBuf,int nSize,FRAME_INFO * pFrameInfo, void* nReserved1,int nReserved2));
//CallBResp = PlayM4_SetDecCallBack(m_pblocalportnum, (void (CALLBACK *)(int,char *,int,FRAME_INFO *, void*,int))SetDecCallBack);
#endif
/*if (!CallBResp){
DisplayError("PlayM4_SetDecCallBack",PlayM4_GetLastError(m_pblocalportnum));
}*/
}
void CALLBACK playm4interface::SetFileRefCallBack(int nPort,void* nUser)
{
isIndexed = true;
qDebug() << "Callback called, file is indexed (" << nPort << "," << nUser<< ")";
bool CallBResp = false;
#if (defined(_WIN32))
//CallBResp = PlayM4_SetVerifyCallBack(m_pblocalportnum, (void (__stdcall *)(long,char *,long,long,long,long,long,long))PlayM4DisplayCallBack);
#elif defined(__linux__)
//int PlayM4_SetVerifyCallBack(int nPort, unsigned int nBeginTime, unsigned int nEndTime, void (__stdcall* funVerify)(int nPort, FRAME_POS* pFilePos, unsigned int bIsVideo, unsigned int nUser), unsigned int nUser);
CallBResp = PlayM4_SetVerifyCallBack(m_pblocalportnum, 0, 360,(void (CALLBACK *)(int, FRAME_POS*, unsigned int, unsigned int ))SetVerifyCallBack,0);
#endif
if (!CallBResp){
DisplayError("PlayM4_SetVerifyCallBack",PlayM4_GetLastError(m_pblocalportnum));
}
}
void CALLBACK playm4interface::SetAudioCallBack(int nPort, char* pAudioBuf, int nSize, int nStamp, int nType, int nUser)
{
printf("SetAudioCallBack---%d:%d\r\n",nPort, nUser);
}
void CALLBACK playm4interface::SetVerifyCallBack(int nPort, FRAME_POS* pFilePos, unsigned int bIsVideo, unsigned int nUser)
{
printf("SetVerifyCallBack---%d:%d:%d:%u\r\n", nPort,pFilePos->nErrorFrameSize, bIsVideo, nUser);
}
void CALLBACK playm4interface::SetDecCallBack(int nPort,char * pBuf,int nSize,FRAME_INFO * pFrameInfo, void* nUser,int nReserved2)
{
/* ENGINESUPPORT pstEngineSupport;
if (!PlayM4_GetEngineSupport(m_pblocalportnum, &pstEngineSupport))
{
DisplayError("PlayM4_GetEngineSupport",PlayM4_GetLastError(m_pblocalportnum));
}else{
qDebug() << pstEngineSupport.chReserved;
qDebug() << &pstEngineSupport.stHDecodeSupport;
qDebug() << &pstEngineSupport.stRenderSupport;
} */
Infos *InfDialog = new Infos();
InfDialog->InfoData = "";
//printf("SetDecCallBack---%l:%l\r\n",nPort, nSize);
//qDebug() << pFrameInfo;
pFRAME_INFO = pFrameInfo;
if ((pFRAME_INFO->nType == T_AUDIO16 | pFRAME_INFO->nType == T_AUDIO8) && !isound) {
PlaySound();
}
if (pFRAME_INFO) {
qDebug() << "FrameNum : " <<playm4interface::pFRAME_INFO->dwFrameNum;
InfDialog->InfoData.append("\nFrameNum : " + QString::number(pFRAME_INFO->dwFrameNum));
qDebug() << "FrameRate : " <<playm4interface::pFRAME_INFO->nFrameRate;
InfDialog->InfoData.append("\nFrameRate : " + QString::number(pFRAME_INFO->nFrameRate));
qDebug() << "\nWidth : " <<playm4interface::pFRAME_INFO->nWidth;
InfDialog->InfoData.append("\nWidth : " + QString::number(pFRAME_INFO->nWidth));
qDebug() << "Height : " <<playm4interface::pFRAME_INFO->nHeight;
InfDialog->InfoData.append("\nHeight : " + QString::number(pFRAME_INFO->nHeight));
qDebug() << "Stamp : " <<playm4interface::pFRAME_INFO->nStamp;
InfDialog->InfoData.append("\nStamp : " + QString::number(pFRAME_INFO->nStamp));
qDebug() << "Type : " <<playm4interface::pFRAME_INFO->nType;
InfDialog->InfoData.append("\nType : " + QString::number(pFRAME_INFO->nType));
}
else
{
int width = 0, height = 0;
PlayM4_GetPictureSize(playm4interface::m_pblocalportnum,&width,&height);
qDebug() << width << "x" << height << " <- PlayM4_GetPictureSize()" ;
InfDialog->InfoData.append("\nVideo resolution : " + QString::number(width) + "x" + QString::number(height));
}
#if (defined(_WIN32))
//PlayM4_SetDecCallBack(m_pblocalportnum, (void (CALLBACK *)(int,char *,long,int,FRAME_INFO*, void*, void*))NULL);
#elif defined(__linux__)
PlayM4_SetDecCallBack(m_pblocalportnum, (void (CALLBACK *)(int,char *,int,FRAME_INFO *, void*,int))NULL);
#endif
InfDialog->exec();
}
void CALLBACK playm4interface::SetRunTimeInfoCBFun(int nPort, RunTimeInfo* pstRunTimeInfo, void* pUser)
{
qDebug() << pstRunTimeInfo << " <- pstRunTimeInfo()" ;
qDebug() << pUser << " <- pUser()" ;
}
bool AudioSwitch = true;
void playm4interface::PlaySound()
{
if (!AudioSwitch) {
if (!PlayM4_PlaySound(m_pblocalportnum))
{
DisplayError("PlayM4_PlaySound",PlayM4_GetLastError(m_pblocalportnum));
}
AudioSwitch = true;
} else {
if (!PlayM4_StopSound())
{
DisplayError("PlayM4_StopSound",PlayM4_GetLastError(m_pblocalportnum));
}
AudioSwitch = false;
}
isound = true;
}