You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 line
2.9 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 , hMedia:: %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("/media-file/origin/%s/%04d-%02d-%02d-%02d.dat");
  31. char file_name[1024];
  32. snprintf(file_name,sizeof(file_name),fmt.c_str(),DeviceIdArr[pos],pFrame->nYear,pFrame->nMonth,pFrame->nDay,pFrame->nHour) ;
  33. printf("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 = 0;
  57. bool bPause = false;
  58. int nSpeed = 0;
  59. char c = 0;
  60. while((c = getchar()) != 'q')
  61. {
  62. switch(c)
  63. {
  64. case 's':
  65. {
  66. if (hPlayer)
  67. {
  68. XSDK_MediaStop(hPlayer);
  69. hPlayer = 0;
  70. }
  71. int size = sizeof(hDeviceArr) / sizeof(hDeviceArr);
  72. for (int i = 0; i < size; i++)
  73. {
  74. SXMediaRealPlayReq param = { 0 };
  75. param.nChannel = 0;
  76. param.nStreamType = 0;
  77. param.nRequestType = EXSDK_DATA_FORMATE_FRAME;
  78. param.pMediaCallback = Test_MediaCallBack;
  79. hPlayer = XSDK_MediaRealPlay(hDeviceArr[i], &param);
  80. bPause = false;
  81. nSpeed = 0;
  82. }
  83. }
  84. break;
  85. case 't':
  86. {
  87. if (hPlayer)
  88. {
  89. XSDK_MediaStop(hPlayer);
  90. hPlayer = 0;
  91. }
  92. }
  93. break;
  94. }
  95. }
  96. if (hPlayer)
  97. {
  98. XSDK_MediaStop(hPlayer);
  99. hPlayer = 0;
  100. }
  101. return 0;
  102. }