libvideoqueue.cpp 18 KB

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