libvideoqueue.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. // libvideoqueue.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "libvideoqueue.h"
  4. #include "../libsharememory/libsharememory.h"
  5. #include "../../Other/libvideoframework/videoutil.h"
  6. #ifdef RVC_OS_WIN
  7. #include "stdafx.h"
  8. #include "ipp.h"
  9. #else
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <assert.h>
  13. #endif // RVC_OS_WIN
  14. typedef struct Qnode
  15. {
  16. unsigned int videoframeindex;
  17. unsigned int nextqnodeindex;
  18. }Qnode, *queueptr;
  19. typedef struct linkqueue
  20. {
  21. unsigned int frontindex;
  22. unsigned int rearindex;
  23. unsigned int queuelens;
  24. }linkqueue;
  25. //// the same as libvideoframe/videoutil.h
  26. //typedef struct video_frame {
  27. // unsigned char *data[4];
  28. // int linesize[4];
  29. // int width;
  30. // int height;
  31. // int format; /* VIDEO_FORMAT_xxx */
  32. //}video_frame;
  33. #if 0
  34. // for rgb24
  35. static void vertical_flip(unsigned char *src_data, int linesize, int width, int height, unsigned char *dst_data)
  36. {
  37. int i;
  38. int actual_line = width * 3;
  39. unsigned char *p = dst_data;
  40. unsigned char *q = src_data + (height-1)*linesize;
  41. for (i = 0; i < height; ++i) {
  42. memcpy(p, q, actual_line);
  43. p += linesize;
  44. q -= linesize;
  45. }
  46. }
  47. // for rgb24
  48. static void horizontal_flip(unsigned char *data, int linesize, int width, int height)
  49. {
  50. int i, j;
  51. LPBYTE lpData = data;
  52. for (i = 0; i < height; ++i) {
  53. LPBYTE x = lpData;
  54. LPBYTE y = x + (width-1) * 3;
  55. for (j = 0; j < width >> 1; ++j) {
  56. swap(*x, *y);
  57. x++;
  58. y++;
  59. swap(*x, *y);
  60. x++;
  61. y++;
  62. swap(*x, *y);
  63. x++;
  64. y-=5;
  65. }
  66. lpData += linesize;
  67. }
  68. }
  69. #endif
  70. class libvideoqueue_impl
  71. {
  72. private:
  73. Clibsharememory m_ShareMem;
  74. void* m_lpMem;
  75. linkqueue*m_pQueue;
  76. int m_nTimeSignLens;
  77. int m_nQueueAddrLens;
  78. int m_nQnodeAddrLens;
  79. int m_nFrameAddrLens;
  80. int m_nDataAddrlens;
  81. char* szShareMemName;
  82. unsigned long aQnodeAddr[MAX_VIDEOQUEUE_LENS];
  83. unsigned long aVideoFrameAddr[MAX_VIDEOQUEUE_LENS];
  84. unsigned long aImgDataAddr[MAX_VIDEOQUEUE_LENS];
  85. unsigned long nTimeSignAddr;
  86. public:
  87. libvideoqueue_impl(const char* videoqueuename,int framesize=MAX_VIDEOQNODE_SIZE)
  88. {
  89. m_lpMem = NULL;
  90. m_pQueue = NULL;
  91. szShareMemName = NULL;
  92. m_nQueueAddrLens = 0;
  93. m_nQnodeAddrLens = 0;
  94. m_nTimeSignLens = 0;
  95. m_nFrameAddrLens = 0;
  96. m_nDataAddrlens = 0;
  97. for(int i=0;i<MAX_VIDEOQUEUE_LENS;i++)
  98. {
  99. aQnodeAddr[i] = 0;
  100. aVideoFrameAddr[i] = 0;
  101. aImgDataAddr[i] = 0;
  102. }
  103. nTimeSignAddr = 0;
  104. InitQueue(videoqueuename,framesize);
  105. }
  106. ~libvideoqueue_impl()
  107. {
  108. ClearVideoQueue();
  109. }
  110. //初始化队列
  111. bool InitQueue(const char* szName,int framesize=MAX_VIDEOQNODE_SIZE)
  112. {
  113. bool bret = false;
  114. m_nQueueAddrLens = sizeof(linkqueue);
  115. m_nQnodeAddrLens = MAX_VIDEOQUEUE_LENS*sizeof(Qnode);
  116. m_nFrameAddrLens = MAX_VIDEOQUEUE_LENS*sizeof(videoq_frame);
  117. m_nDataAddrlens = MAX_VIDEOQUEUE_LENS*framesize;
  118. m_nTimeSignLens = sizeof(unsigned int);
  119. unsigned long nMemTotalNum = m_nTimeSignLens+m_nQueueAddrLens+m_nQnodeAddrLens+m_nFrameAddrLens+m_nDataAddrlens;
  120. if (m_ShareMem.Create(szName,nMemTotalNum)&&(m_nDataAddrlens!=0))
  121. {
  122. m_lpMem = m_ShareMem.Lock(1000);
  123. if(m_lpMem != NULL)
  124. {
  125. memset(m_lpMem,0,nMemTotalNum);
  126. m_pQueue = (linkqueue *)m_lpMem;
  127. for(int i =0;i<MAX_VIDEOQUEUE_LENS;i++)
  128. {
  129. aQnodeAddr[i] = (unsigned long)m_pQueue+m_nQueueAddrLens+sizeof(Qnode)*i;
  130. aVideoFrameAddr[i] = (unsigned long)m_pQueue+m_nQueueAddrLens+m_nQnodeAddrLens+sizeof(videoq_frame)*i;
  131. aImgDataAddr[i] = (unsigned long)m_pQueue+m_nQueueAddrLens+m_nQnodeAddrLens+m_nFrameAddrLens+framesize*i;
  132. }
  133. nTimeSignAddr = (unsigned long)m_pQueue+m_nQueueAddrLens+m_nQnodeAddrLens+m_nFrameAddrLens+m_nDataAddrlens;
  134. m_pQueue->frontindex = m_pQueue->rearindex = 0;
  135. m_pQueue->queuelens = 0;
  136. m_ShareMem.Unlock();
  137. bret = true;
  138. }
  139. }
  140. else if(m_ShareMem.Open(szName))
  141. {
  142. m_ShareMem.GetBytes();
  143. m_lpMem = m_ShareMem.Lock(1000);
  144. if(m_lpMem != NULL)
  145. {
  146. m_pQueue = (linkqueue*)m_lpMem;
  147. for(int i =0;i<MAX_VIDEOQUEUE_LENS;i++)
  148. {
  149. aQnodeAddr[i] = (unsigned long)m_pQueue+m_nQueueAddrLens+sizeof(Qnode)*i;
  150. aVideoFrameAddr[i] = (unsigned long)m_pQueue+m_nQueueAddrLens+m_nQnodeAddrLens+sizeof(videoq_frame)*i;
  151. aImgDataAddr[i] = (unsigned long)m_pQueue+m_nQueueAddrLens+m_nQnodeAddrLens+m_nFrameAddrLens+framesize*i;
  152. }
  153. nTimeSignAddr = (unsigned long)m_pQueue+m_nQueueAddrLens+m_nQnodeAddrLens+m_nFrameAddrLens+m_nDataAddrlens;
  154. m_ShareMem.Unlock();
  155. bret = true;
  156. }
  157. }
  158. return bret;
  159. }
  160. //返回队列的元素个数,视频队列长度
  161. int GetVideoLens()
  162. {
  163. if(m_ShareMem.IsValid())
  164. {
  165. m_lpMem = m_ShareMem.Lock(1000);
  166. if(m_lpMem != NULL)
  167. {
  168. int num = m_pQueue->queuelens;
  169. m_ShareMem.Unlock();
  170. return num;
  171. }
  172. else
  173. {
  174. return 0;
  175. }
  176. }
  177. else
  178. {
  179. return 0;
  180. }
  181. }
  182. //往视频循环队列尾部插节点
  183. bool InsertVideo(videoq_frame* Video, int flags,unsigned int nowtime)
  184. {
  185. if(m_ShareMem.IsValid())
  186. {
  187. m_lpMem = m_ShareMem.Lock(1000);
  188. if(m_lpMem != NULL)
  189. {
  190. unsigned int nRearNextIndex = 0;
  191. //保存当前对位指针的序列号
  192. queueptr rearptrfront = (queueptr)aQnodeAddr[m_pQueue->rearindex];
  193. //如果队列已满
  194. if(m_pQueue->queuelens == MAX_VIDEOQUEUE_LENS)
  195. {
  196. m_pQueue->rearindex = (m_pQueue->rearindex+1)%MAX_VIDEOQUEUE_LENS;
  197. m_pQueue->frontindex = (m_pQueue->frontindex+1)%MAX_VIDEOQUEUE_LENS;
  198. m_pQueue->queuelens = MAX_VIDEOQUEUE_LENS;
  199. }
  200. else if (m_pQueue->queuelens == 0)
  201. {
  202. m_pQueue->rearindex = 0;
  203. m_pQueue->frontindex = 0;
  204. m_pQueue->queuelens++;
  205. }
  206. else
  207. {
  208. m_pQueue->rearindex = (m_pQueue->rearindex+1)%MAX_VIDEOQUEUE_LENS;
  209. m_pQueue->frontindex = m_pQueue->frontindex;
  210. m_pQueue->queuelens++;
  211. }
  212. if (Video != NULL)
  213. {
  214. queueptr rearqnodetmp = (queueptr)aQnodeAddr[m_pQueue->rearindex];
  215. rearqnodetmp->videoframeindex = m_pQueue->rearindex;
  216. rearqnodetmp->nextqnodeindex = 0;
  217. videoq_frame*videotmp = (videoq_frame*)aVideoFrameAddr[m_pQueue->rearindex];
  218. videotmp->data = (unsigned char*)aImgDataAddr[m_pQueue->rearindex ];
  219. videotmp->format = Video->format;
  220. if (VIDEOQ_FORMAT_I420 == Video->format){
  221. videotmp->framesize = Video->height * Video->width * 3/2;
  222. }
  223. else {
  224. videotmp->framesize = Video->height * Video->width * 3;
  225. }
  226. videotmp->height = Video->height;
  227. videotmp->width = Video->width;
  228. videotmp->iframeid = Video->iframeid;
  229. unsigned int*Ptr = (unsigned int*)nTimeSignAddr;
  230. *Ptr = nowtime;
  231. #ifdef RVC_OS_WIN
  232. if (flags) {
  233. IppiAxis flip;
  234. if (flags == VIDEOQUEUE_FLAG_VERTICAL_FLIP) { // 上下翻转
  235. flip = ippAxsHorizontal; // x轴
  236. } else if (flags == VIDEOQUEUE_FLAG_HORIZONTAL_FLIP) { // 左右翻转
  237. flip = ippAxsVertical; // y轴
  238. } else {
  239. flip = ippAxsBoth;
  240. }
  241. IppiSize roiSize;
  242. roiSize.width = videotmp->width;
  243. roiSize.height = videotmp->height;
  244. ippiMirror_8u_C3R(Video->data, Video->framesize/Video->height, videotmp->data, videotmp->width*3, roiSize, flip);
  245. } else {
  246. IppiSize roiSize;
  247. roiSize.width = videotmp->width;
  248. roiSize.height = videotmp->height;
  249. ippiCopy_8u_C3R(Video->data, Video->framesize/Video->height, videotmp->data, videotmp->width*3, roiSize);
  250. }
  251. #else
  252. memcpy(videotmp->data, Video->data, Video->framesize);
  253. #endif // RVC_OS_WIN
  254. rearptrfront->nextqnodeindex = m_pQueue->rearindex;
  255. }
  256. m_ShareMem.Unlock();
  257. return true;
  258. }
  259. else
  260. {
  261. return false;
  262. }
  263. }
  264. else
  265. {
  266. return false;
  267. }
  268. }
  269. //读视频队列头部节点
  270. bool GetVideo(videoq_frame* Video, int flags)
  271. {
  272. if(m_ShareMem.IsValid())
  273. {
  274. m_lpMem = m_ShareMem.Lock(1000);
  275. if(m_lpMem != NULL)
  276. {
  277. if (m_pQueue->queuelens == 0)
  278. {
  279. m_ShareMem.Unlock();
  280. return false;
  281. }
  282. else
  283. {
  284. videoq_frame*videotemp = (videoq_frame*)aVideoFrameAddr[m_pQueue->frontindex];
  285. Video->format = videotemp->format;
  286. Video->framesize = videotemp->framesize;
  287. Video->height = videotemp->height;
  288. Video->width = videotemp->width;
  289. Video->iframeid = videotemp->iframeid;
  290. #ifdef RVC_OS_WIN
  291. if (flags) {
  292. IppiAxis flip;
  293. if (flags == VIDEOQUEUE_FLAG_VERTICAL_FLIP) { // 上下翻转
  294. flip = ippAxsHorizontal; // x轴
  295. }
  296. else if (flags == VIDEOQUEUE_FLAG_HORIZONTAL_FLIP) { // 左右翻转
  297. flip = ippAxsVertical; // y轴
  298. }
  299. else {
  300. flip = ippAxsBoth;
  301. }
  302. IppiSize roiSize;
  303. roiSize.width = videotemp->width;
  304. roiSize.height = videotemp->height;
  305. try
  306. {
  307. ippiMirror_8u_C3R((unsigned char*)aImgDataAddr[m_pQueue->frontindex], videotemp->width * 3, Video->data, videotemp->width * 3, roiSize, flip);
  308. }
  309. catch (...)
  310. {
  311. m_ShareMem.Unlock();
  312. return false;
  313. }
  314. }
  315. else
  316. {
  317. IppiSize roiSize;
  318. roiSize.width = videotemp->width;
  319. roiSize.height = videotemp->height;
  320. try
  321. {
  322. ippiCopy_8u_C3R((unsigned char*)aImgDataAddr[m_pQueue->frontindex], videotemp->width * 3, Video->data, videotemp->width * 3, roiSize);
  323. //memcpy(Video->data,(unsigned char*)aImgDataAddr[m_pQueue->frontindex],videotemp->framesize);
  324. }
  325. catch (...)
  326. {
  327. m_ShareMem.Unlock();
  328. return false;
  329. }
  330. }
  331. #else
  332. try
  333. {
  334. memcpy(Video->data,(unsigned char*)aImgDataAddr[m_pQueue->frontindex],videotemp->framesize);
  335. }
  336. catch (...)
  337. {
  338. m_ShareMem.Unlock();
  339. return false;
  340. }
  341. #endif // RVC_OS_WIN
  342. m_ShareMem.Unlock();
  343. return true;
  344. }
  345. }
  346. else
  347. {
  348. return false;
  349. }
  350. }
  351. else
  352. {
  353. return false;
  354. }
  355. }
  356. bool GetVideo2(video_frame* Video, int flags)
  357. {
  358. if(m_ShareMem.IsValid())
  359. {
  360. m_lpMem = m_ShareMem.Lock(1000);
  361. if(m_lpMem != NULL)
  362. {
  363. if (m_pQueue->queuelens == 0)
  364. {
  365. m_ShareMem.Unlock();
  366. return false;
  367. }
  368. else
  369. {
  370. videoq_frame*videotemp = (videoq_frame*)aVideoFrameAddr[m_pQueue->frontindex];
  371. assert(Video->height == videotemp->height);
  372. assert(Video->width == videotemp->width);
  373. #ifdef RVC_OS_WIN
  374. //Video->format = videotemp->format;
  375. //Video->framesize = videotemp->framesize;
  376. //Video->height = videotemp->height;
  377. //Video->width = videotemp->width;
  378. if (flags) {
  379. IppiAxis flip;
  380. if (flags == VIDEOQUEUE_FLAG_VERTICAL_FLIP) { // 上下翻转
  381. flip = ippAxsHorizontal; // x轴
  382. } else if (flags == VIDEOQUEUE_FLAG_HORIZONTAL_FLIP) { // 左右翻转
  383. flip = ippAxsVertical; // y轴
  384. } else {
  385. flip = ippAxsBoth;
  386. }
  387. IppiSize roiSize;
  388. roiSize.width = videotemp->width;
  389. roiSize.height = videotemp->height;
  390. ippiMirror_8u_C3R((unsigned char*)aImgDataAddr[m_pQueue->frontindex], videotemp->width*3, Video->data[0], Video->linesize[0], roiSize, flip);
  391. } else {
  392. IppiSize roiSize;
  393. roiSize.width = videotemp->width;
  394. roiSize.height = videotemp->height;
  395. ippiCopy_8u_C3R((unsigned char*)aImgDataAddr[m_pQueue->frontindex], videotemp->width*3, Video->data[0], Video->linesize[0], roiSize);
  396. }
  397. #else
  398. Video->iframeid = videotemp->iframeid;
  399. for (int i = 0; i < videotemp->height; i++)
  400. {
  401. memcpy(Video->data[0] + i*Video->linesize[0], (unsigned char*)aImgDataAddr[m_pQueue->frontindex] + i * Video->width*3, Video->width*3);
  402. }
  403. #endif // RVC_OS_WIN
  404. m_ShareMem.Unlock();
  405. return true;
  406. }
  407. }
  408. else
  409. {
  410. return false;
  411. }
  412. }
  413. else
  414. {
  415. return false;
  416. }
  417. }
  418. bool GetVideo3(videoq_frame* Video, int flags)
  419. {
  420. if(m_ShareMem.IsValid())
  421. {
  422. m_lpMem = m_ShareMem.Lock(1000);
  423. if(m_lpMem != NULL)
  424. {
  425. if (m_pQueue->queuelens == 0)
  426. {
  427. m_ShareMem.Unlock();
  428. return false;
  429. }
  430. else
  431. {
  432. videoq_frame*videotemp = (videoq_frame*)aVideoFrameAddr[m_pQueue->frontindex];
  433. Video->format = videotemp->format;
  434. Video->framesize = videotemp->framesize;
  435. Video->height = videotemp->height;
  436. Video->width = videotemp->width;
  437. Video->iframeid = videotemp->iframeid;
  438. #ifdef RVC_OS_WIN
  439. if (flags)
  440. {
  441. IppiAxis flip;
  442. if (flags == VIDEOQUEUE_FLAG_VERTICAL_FLIP)
  443. { // 上下翻转
  444. flip = ippAxsHorizontal; // x轴
  445. }
  446. else if (flags == VIDEOQUEUE_FLAG_HORIZONTAL_FLIP)
  447. { // 左右翻转
  448. flip = ippAxsVertical; // y轴
  449. }
  450. else
  451. {
  452. flip = ippAxsBoth;
  453. }
  454. IppiSize roiSize;
  455. roiSize.width = videotemp->width;
  456. roiSize.height = videotemp->height;
  457. try
  458. {
  459. ippiMirror_8u_C3R((unsigned char*)aImgDataAddr[m_pQueue->frontindex], videotemp->width*3, Video->data, videotemp->height*3, roiSize, flip);
  460. }
  461. catch (...)
  462. {
  463. m_ShareMem.Unlock();
  464. return false;
  465. }
  466. }
  467. else
  468. {
  469. IppiSize roiSize;
  470. roiSize.width = videotemp->width;
  471. roiSize.height = videotemp->height;
  472. try
  473. {
  474. ippiCopy_8u_C3R((unsigned char*)aImgDataAddr[m_pQueue->frontindex], videotemp->width*3, Video->data, videotemp->height*3, roiSize);
  475. }
  476. catch (...)
  477. {
  478. m_ShareMem.Unlock();
  479. return false;
  480. }
  481. }
  482. #else
  483. //memcpy(Video->data, (unsigned char*)aImgDataAddr[m_pQueue->frontindex], videotemp->framesize);
  484. for (int i = 0; i < videotemp->height; i++)
  485. {
  486. memcpy((unsigned char*)Video->data + i * videotemp->height * 3, (unsigned char*)aImgDataAddr[m_pQueue->frontindex] + i * videotemp->width * 3, videotemp->width * 3);
  487. }
  488. #endif // RVC_OS_WIN
  489. m_ShareMem.Unlock();
  490. return true;
  491. }
  492. }
  493. else
  494. {
  495. return false;
  496. }
  497. }
  498. else
  499. {
  500. return false;
  501. }
  502. }
  503. //读视频队列头部节点,并删除头部节点
  504. bool GetVideoAndDel(videoq_frame* Video, int flags)
  505. {
  506. if(m_ShareMem.IsValid())
  507. {
  508. m_lpMem = m_ShareMem.Lock(1000);
  509. if(m_lpMem != NULL)
  510. {
  511. if (m_pQueue->queuelens == 0)
  512. {
  513. m_ShareMem.Unlock();
  514. return false;
  515. }
  516. else
  517. {
  518. videoq_frame*videotemp = (videoq_frame*)aVideoFrameAddr[m_pQueue->frontindex];
  519. Video->format = videotemp->format;
  520. Video->framesize = videotemp->framesize;
  521. Video->height = videotemp->height;
  522. Video->width = videotemp->width;
  523. Video->iframeid = videotemp->iframeid;
  524. #ifdef RVC_OS_WIN
  525. if (flags) {
  526. IppiAxis flip;
  527. if (flags == VIDEOQUEUE_FLAG_VERTICAL_FLIP) { // 上下翻转
  528. flip = ippAxsHorizontal; // x轴
  529. } else if (flags == VIDEOQUEUE_FLAG_HORIZONTAL_FLIP) { // 左右翻转
  530. flip = ippAxsVertical; // y轴
  531. } else {
  532. flip = ippAxsBoth;
  533. }
  534. IppiSize roiSize;
  535. roiSize.width = videotemp->width;
  536. roiSize.height = videotemp->height;
  537. ippiMirror_8u_C3R((unsigned char*)aImgDataAddr[m_pQueue->frontindex], videotemp->width*3, Video->data, videotemp->width*3, roiSize, flip);
  538. } else {
  539. memcpy(Video->data,(unsigned char*)aImgDataAddr[m_pQueue->frontindex],videotemp->framesize);
  540. }
  541. #else
  542. memcpy(Video->data, (unsigned char*)aImgDataAddr[m_pQueue->frontindex], videotemp->framesize);
  543. #endif // RVC_OS_WIN
  544. unsigned char*data = (unsigned char*)aImgDataAddr[m_pQueue->frontindex];
  545. memset(data,0,videotemp->framesize);
  546. memset(videotemp,0,sizeof(videoq_frame));
  547. queueptr qnodetmp = (queueptr)aQnodeAddr[m_pQueue->frontindex];
  548. m_pQueue->frontindex = qnodetmp->nextqnodeindex;
  549. qnodetmp = (queueptr)aQnodeAddr[m_pQueue->rearindex];
  550. qnodetmp->nextqnodeindex = 0;
  551. m_pQueue->queuelens--;
  552. m_ShareMem.Unlock();
  553. return true;
  554. }
  555. }
  556. else
  557. {
  558. return false;
  559. }
  560. }
  561. else
  562. {
  563. return false;
  564. }
  565. }
  566. //清除队列
  567. bool ClearVideoQueue()
  568. {
  569. if(m_ShareMem.IsValid())
  570. {
  571. m_lpMem = m_ShareMem.Lock(1000);
  572. if(m_lpMem != NULL)
  573. {
  574. if (m_pQueue->queuelens != 0)
  575. {
  576. while(m_pQueue->queuelens != 0)
  577. {
  578. videoq_frame*videotemp = (videoq_frame*)aVideoFrameAddr[m_pQueue->frontindex];
  579. unsigned char*data = (unsigned char*)aImgDataAddr[m_pQueue->frontindex];
  580. memset(data,0,videotemp->framesize);
  581. memset(videotemp,0,sizeof(videoq_frame));
  582. queueptr qnodetmp = (queueptr)aQnodeAddr[m_pQueue->frontindex];
  583. m_pQueue->frontindex = qnodetmp->nextqnodeindex;
  584. qnodetmp = (queueptr)aQnodeAddr[m_pQueue->rearindex];
  585. qnodetmp->nextqnodeindex = 0;
  586. m_pQueue->queuelens--;
  587. }
  588. }
  589. m_ShareMem.Unlock();
  590. return true;
  591. }
  592. else
  593. {
  594. return false;
  595. }
  596. }
  597. else
  598. {
  599. return false;
  600. }
  601. }
  602. //删除队头的数据
  603. bool DeleteHeadVideo()
  604. {
  605. if(m_ShareMem.IsValid())
  606. {
  607. m_lpMem = m_ShareMem.Lock(1000);
  608. if(m_lpMem != NULL)
  609. {
  610. if (m_pQueue->queuelens != 0)
  611. {
  612. videoq_frame*videotemp = (videoq_frame*)aVideoFrameAddr[m_pQueue->frontindex];
  613. unsigned char*data = (unsigned char*)aImgDataAddr[m_pQueue->frontindex];
  614. memset(data,0,videotemp->framesize);
  615. memset(videotemp,0,sizeof(videoq_frame));
  616. queueptr qnodetmp = (queueptr)aQnodeAddr[m_pQueue->frontindex];
  617. m_pQueue->frontindex = qnodetmp->nextqnodeindex;
  618. qnodetmp = (queueptr)aQnodeAddr[m_pQueue->rearindex];
  619. qnodetmp->nextqnodeindex = 0;
  620. m_pQueue->queuelens--;
  621. }
  622. m_ShareMem.Unlock();
  623. return true;
  624. }
  625. else
  626. {
  627. return false;
  628. }
  629. }
  630. else
  631. {
  632. return false;
  633. }
  634. }
  635. //获取图像的大小
  636. int GetFrameSize(int&width,int&height)
  637. {
  638. if(m_ShareMem.IsValid())
  639. {
  640. m_lpMem = m_ShareMem.Lock(1000);
  641. if(m_lpMem != NULL)
  642. {
  643. int nFrameSize = 0;
  644. if (m_pQueue->queuelens != 0)
  645. {
  646. videoq_frame*videotmp = (videoq_frame*)aVideoFrameAddr[m_pQueue->frontindex];
  647. nFrameSize = videotmp->framesize;
  648. width = videotmp->width;
  649. height = videotmp->height;
  650. }
  651. m_ShareMem.Unlock();
  652. return nFrameSize;
  653. }
  654. else
  655. {
  656. return 0;
  657. }
  658. }
  659. else
  660. {
  661. return 0;
  662. }
  663. }
  664. unsigned int GetLastFrameTime()
  665. {
  666. if(m_ShareMem.IsValid())
  667. {
  668. m_lpMem = m_ShareMem.Lock(1000);
  669. if(m_lpMem != NULL)
  670. {
  671. unsigned int nLastFrameTime = 0;
  672. nLastFrameTime = *(unsigned int *)nTimeSignAddr;
  673. m_ShareMem.Unlock();
  674. return nLastFrameTime;
  675. }
  676. else
  677. {
  678. return 0;
  679. }
  680. }
  681. else
  682. {
  683. return 0;
  684. }
  685. }
  686. };
  687. // 这是已导出类的构造函数。
  688. // 有关类定义的信息,请参阅 libvideoqueue.h
  689. Clibvideoqueue::Clibvideoqueue(const char* videoqueuename,int framesize)
  690. {
  691. m_pImpl = new libvideoqueue_impl(videoqueuename,framesize);
  692. return;
  693. }
  694. Clibvideoqueue::~Clibvideoqueue()
  695. {
  696. ClearVideoQueue();
  697. delete m_pImpl;
  698. return;
  699. }
  700. bool Clibvideoqueue::InsertVideo(videoq_frame* Video, int flags,unsigned int nowtime)
  701. {
  702. bool bRst = m_pImpl->InsertVideo(Video, flags,nowtime);
  703. return bRst;
  704. }
  705. bool Clibvideoqueue::GetVideo(videoq_frame* Video, int flags)
  706. {
  707. bool bRst = m_pImpl->GetVideo(Video, flags);
  708. return bRst;
  709. }
  710. bool Clibvideoqueue::GetVideo2(video_frame* Video, int flags)
  711. {
  712. bool bRst = m_pImpl->GetVideo2(Video, flags);
  713. return bRst;
  714. }
  715. bool Clibvideoqueue::GetVideo3(videoq_frame* Video, int flags)
  716. {
  717. bool bRst = m_pImpl->GetVideo3(Video, flags);
  718. return bRst;
  719. }
  720. bool Clibvideoqueue::GetVideoAndDel(videoq_frame* Video, int flags)
  721. {
  722. bool bRst = m_pImpl->GetVideoAndDel(Video, flags);
  723. return bRst;
  724. }
  725. int Clibvideoqueue::GetVideoLens(void)
  726. {
  727. int i = m_pImpl->GetVideoLens();
  728. return i;
  729. }
  730. void Clibvideoqueue::ClearVideoQueue()
  731. {
  732. m_pImpl->ClearVideoQueue();
  733. return;
  734. }
  735. int Clibvideoqueue::GetFrameSize(int&width,int&height)
  736. {
  737. int i = m_pImpl->GetFrameSize(width,height);
  738. return i;
  739. }
  740. void Clibvideoqueue::DeleteHeadVideo()
  741. {
  742. m_pImpl->DeleteHeadVideo();
  743. return;
  744. }
  745. unsigned int Clibvideoqueue::GetLastFrameTime()
  746. {
  747. return m_pImpl->GetLastFrameTime();
  748. }