您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

124 行
3.2 KiB

  1. #include "XNetSDKTest.h"
  2. #include <string>
  3. int getPos(XSDK_HANDLE hMedia) {
  4. int size = sizeof(hDeviceArr) / sizeof(hDeviceArr[0]);
  5. for (int i = 0; i < size; i++) {
  6. printf("pos:: %d , cached:: %d,hMedia:: %d\r\n",i,hDeviceArr[i],hMedia);
  7. if (hDeviceArr[i] == hMedia) {
  8. return i;
  9. }
  10. }
  11. return -1;
  12. }
  13. int CALLBACK Test_MediaCallBack(XSDK_HANDLE hMedia, const unsigned char *pData, int nDataLen, int nDataType, void *pDataInfo, int nDataInfoSize, void *pUserData)
  14. {
  15. if (EXSDK_DATA_FORMATE_FRAME == nDataType && nDataInfoSize > 0)
  16. {
  17. SXSDK_FRAME_INFO *pFrame = (SXSDK_FRAME_INFO *)pDataInfo;
  18. //if(pFrame->nType==XSDK_FRAME_TYPE_VIDEO)
  19. //{
  20. // FILE *file = fopen("real.dat","ab+") ;
  21. // if(file)
  22. // {
  23. // fwrite(pFrame->pContent,1,pFrame->nFrameLength,file);
  24. // fclose(file);
  25. // }
  26. //}
  27. if (pFrame->nType == XSDK_FRAME_TYPE_VIDEO)
  28. {
  29. int pos = getPos(hMedia);
  30. string fmt("/extdisk/origin/%04d-%02d-%02d-%02d.dat");
  31. char file_name[1024];
  32. snprintf(file_name,sizeof(file_name),fmt.c_str(),pFrame->nYear,pFrame->nMonth,pFrame->nDay,pFrame->nHour) ;
  33. printf("file_path: %d ,%s \r\n", pos,file_name);
  34. // ABFile("video_header.dat", pFrame->pHeader, pFrame->nLength);
  35. ABFile(file_name, pFrame->pContent, pFrame->nFrameLength);
  36. }
  37. //printf("Media[hMedia:%ld][Len:%d][Type:%d/%d][%04d-%02d-%02d %02d:%02d:%02d-%03d]\r\n", hMedia, nDataLen, pFrame->nType, pFrame->nSubType, pFrame->nYear, pFrame->nMonth, pFrame->nDay, pFrame->nHour, pFrame->nMinute, pFrame->nSecond, (int)(pFrame->nTimeStamp % 1000));
  38. }
  39. else if (EXSDK_DATA_MEDIA_ON_PLAY_STATE == nDataType)
  40. {
  41. printf("EXSDK_DATA_MEDIA_ON_PLAY_STATE[%d][%d]\r\n", hMedia, nDataLen);
  42. }
  43. else if (ESXSDK_MEDIA_START_REAL_PLAY == nDataType)
  44. {
  45. printf("OnRealPlayResult[%d][%s]\r\n", hMedia, nDataLen >= 0 ? "Success" : "Failed");
  46. }
  47. else
  48. {
  49. printf("Media[hMedia:%ld][Len:%d][Type:%d]\r\n", hMedia, nDataLen, nDataType);
  50. }
  51. return 0;
  52. }
  53. int TestMediaRealPlay()
  54. {
  55. printf("MediaRealPlay %s\r\n", __FUNCTION__);
  56. XSDK_HANDLE hPlayer[6] ;
  57. bool bPause = false;
  58. int nSpeed = 0;
  59. char c = 0;
  60. int size = sizeof(hDeviceArr) / sizeof(hDeviceArr[0]);
  61. while((c = getchar()) != 'q')
  62. {
  63. switch(c)
  64. {
  65. case 's':
  66. {
  67. for (int i = 0; i < size; i++)
  68. {
  69. if (hPlayer[i])
  70. {
  71. XSDK_MediaStop(hPlayer[i]);
  72. hPlayer[i] = 0;
  73. }
  74. }
  75. for (int i = 0; i < size; i++)
  76. {
  77. SXMediaRealPlayReq param = { 0 };
  78. param.nChannel = 0;
  79. param.nStreamType = 0;
  80. param.nRequestType = EXSDK_DATA_FORMATE_FRAME;
  81. param.pMediaCallback = Test_MediaCallBack;
  82. hPlayer[i] = XSDK_MediaRealPlay(hDeviceArr[i], &param);
  83. bPause = false;
  84. nSpeed = 0;
  85. printf("paly hMedia:: %d\r\n", hDeviceArr[i]);
  86. }
  87. }
  88. break;
  89. case 't':
  90. {
  91. for (int i = 0; i < size; i++)
  92. {
  93. if (hPlayer[i])
  94. {
  95. XSDK_MediaStop(hPlayer[i]);
  96. hPlayer[i] = 0;
  97. }
  98. }
  99. }
  100. break;
  101. }
  102. }
  103. for (int i = 0; i < size; i++)
  104. {
  105. if (hPlayer[i])
  106. {
  107. XSDK_MediaStop(hPlayer[i]);
  108. hPlayer[i] = 0;
  109. }
  110. }
  111. return 0;
  112. }