|
| 1 | +#ifdef _MSC_BUILD |
| 2 | +#include <windows.h> |
| 3 | +#include <tchar.h> |
| 4 | +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") |
| 5 | +#pragma comment(lib,"XEngine_Core/XEngine_OPenSsl") |
| 6 | +#pragma comment(lib,"XEngine_Client/XClient_Socket") |
| 7 | +#pragma comment(lib,"XEngine_AVCodec/XEngine_AVHelp") |
| 8 | +#pragma comment(lib,"Ws2_32") |
| 9 | +#endif |
| 10 | +#include <thread> |
| 11 | +#include <XEngine_Include/XEngine_CommHdr.h> |
| 12 | +#include <XEngine_Include/XEngine_Types.h> |
| 13 | +#include <XEngine_Include/XEngine_ProtocolHdr.h> |
| 14 | +#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h> |
| 15 | +#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h> |
| 16 | +#include <XEngine_Include/XEngine_Core/OPenSsl_Define.h> |
| 17 | +#include <XEngine_Include/XEngine_Core/OPenSsl_Error.h> |
| 18 | +#include <XEngine_Include/XEngine_Client/XClient_Define.h> |
| 19 | +#include <XEngine_Include/XEngine_Client/XClient_Error.h> |
| 20 | +#include <XEngine_Include/XEngine_AVCodec/AVCollect_Define.h> |
| 21 | +#include <XEngine_Include/XEngine_AVCodec/VideoCodec_Define.h> |
| 22 | +#include <XEngine_Include/XEngine_AVCodec/AVHelp_Define.h> |
| 23 | +#include <XEngine_Include/XEngine_AVCodec/AVHelp_Error.h> |
| 24 | +#include "../../XEngine_Source/XEngine_UserProtocol.h" |
| 25 | +using namespace std; |
| 26 | + |
| 27 | +//需要优先配置XEngine |
| 28 | +//WINDOWS使用VS2022 x86 或者 x64 debug 编译 |
| 29 | +//linux::g++ -std=c++17 -Wall -g APPClient_JT1078.cpp -o APPClient_JT1078.exe -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -L /usr/local/lib/XEngine_Release/XEngine_SystemSdk -L ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -lXEngine_BaseLib -lNetHelp_APIClient -lXEngine_SystemApi -ljsoncpp |
| 30 | +//macos::g++ -std=c++17 -Wall -g APPClient_JT1078.cpp -o APPClient_JT1078.exe -lXEngine_BaseLib -lNetHelp_APIClient -lXEngine_SystemApi -ljsoncpp |
| 31 | + |
| 32 | +void XEngine_Device_StrtoBCD(LPCXSTR lpszPhoneCode, XBYTE* ptszBCD) |
| 33 | +{ |
| 34 | + for (int i = 0, nPos = 0; i < 6; i++) |
| 35 | + { |
| 36 | + OPenSsl_Codec_2BytesToBCD(&lpszPhoneCode[nPos], ptszBCD[i]); |
| 37 | + nPos += 2; |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +int main() |
| 42 | +{ |
| 43 | + WSADATA st_WSAData; |
| 44 | + WSAStartup(MAKEWORD(2, 2), &st_WSAData); |
| 45 | + |
| 46 | + LPCXSTR lpszFile = _X("D:\\h264 file\\1080P.264"); |
| 47 | + LPCXSTR lpszPhone = _X("013699435573"); |
| 48 | + LPCXSTR lpszAddr = _X("127.0.0.1"); |
| 49 | + int nPort = 5602; |
| 50 | + XSOCKET hSocket; |
| 51 | + |
| 52 | + if (!XClient_TCPSelect_Create(&hSocket, lpszAddr, nPort)) |
| 53 | + { |
| 54 | + _xtprintf(_X("连接失败")); |
| 55 | + return -1; |
| 56 | + } |
| 57 | + |
| 58 | + FILE *pSt_File = _xtfopen(lpszFile, _X("rb")); |
| 59 | + if (NULL == pSt_File) |
| 60 | + { |
| 61 | + _xtprintf(_X("文件打开失败!")); |
| 62 | + return -1; |
| 63 | + } |
| 64 | + |
| 65 | + int nSeq = 0; |
| 66 | + XNETHANDLE xhToken = 0; |
| 67 | + AVHelp_Parse_FrameInit(&xhToken, ENUM_XENGINE_AVCODEC_VIDEO_TYPE_H264); |
| 68 | + |
| 69 | + while (true) |
| 70 | + { |
| 71 | + XCHAR tszRVBuffer[8192]; |
| 72 | + memset(tszRVBuffer, '\0', sizeof(tszRVBuffer)); |
| 73 | + |
| 74 | + int nRet = fread(tszRVBuffer, 1, sizeof(tszRVBuffer), pSt_File); |
| 75 | + if (nRet <= 0) |
| 76 | + { |
| 77 | + fclose(pSt_File); |
| 78 | + pSt_File = _xtfopen(lpszFile, _X("rb")); |
| 79 | + if (NULL == pSt_File) |
| 80 | + { |
| 81 | + break; |
| 82 | + } |
| 83 | + } |
| 84 | + int nListCount = 0; |
| 85 | + AVHELP_FRAMEDATA** ppSt_Frame; |
| 86 | + AVHelp_Parse_FrameGet(xhToken, tszRVBuffer, nRet, &ppSt_Frame, &nListCount); |
| 87 | + for (int i = 0; i < nListCount; i++) |
| 88 | + { |
| 89 | + bool bFirst = true; |
| 90 | + int nCpyCount = 0; |
| 91 | + int nUseCount = 0; |
| 92 | + int nMsgCount = ppSt_Frame[i]->nMsgLen; |
| 93 | + XENGINE_AVCODEC_VIDEOFRAMETYPE enFrameType; |
| 94 | + |
| 95 | + printf("%d\n", nMsgCount); |
| 96 | + AVHelp_Parse_NaluType((LPCXSTR)ppSt_Frame[i]->ptszMsgBuffer, ENUM_XENGINE_AVCODEC_VIDEO_TYPE_H264, &enFrameType); |
| 97 | + while (nMsgCount > 0) |
| 98 | + { |
| 99 | + XENGINE_RTPPACKETHDR st_RTPPacket; |
| 100 | + XENGINE_RTPPACKETTAIL st_PacketTail; |
| 101 | + |
| 102 | + memset(&st_RTPPacket, '\0', sizeof(XENGINE_RTPPACKETHDR)); |
| 103 | + memset(&st_PacketTail, '\0', sizeof(XENGINE_RTPPACKETTAIL)); |
| 104 | + |
| 105 | + st_RTPPacket.byFlags[0] = 0x30; |
| 106 | + st_RTPPacket.byFlags[1] = 0x31; |
| 107 | + st_RTPPacket.byFlags[2] = 0x63; |
| 108 | + st_RTPPacket.byFlags[3] = 0x64; |
| 109 | + |
| 110 | + st_RTPPacket.byV = 2; |
| 111 | + st_RTPPacket.byX = 0; |
| 112 | + st_RTPPacket.byCC = 1; |
| 113 | + st_RTPPacket.byM = 0; |
| 114 | + st_RTPPacket.byPT = 98; |
| 115 | + |
| 116 | + st_RTPPacket.byChannel = 1; |
| 117 | + st_RTPPacket.byType = 0; |
| 118 | + st_RTPPacket.byPacket = 0; |
| 119 | + |
| 120 | + if (nMsgCount > 950) |
| 121 | + { |
| 122 | + if (bFirst) |
| 123 | + { |
| 124 | + st_RTPPacket.byPacket = 1; |
| 125 | + bFirst = false; |
| 126 | + } |
| 127 | + else |
| 128 | + { |
| 129 | + st_RTPPacket.byPacket = 3; |
| 130 | + } |
| 131 | + nCpyCount = 950; |
| 132 | + } |
| 133 | + else |
| 134 | + { |
| 135 | + st_RTPPacket.byM = 1; |
| 136 | + st_RTPPacket.byPacket = 2; |
| 137 | + nCpyCount = nMsgCount; |
| 138 | + } |
| 139 | + |
| 140 | + if (ENUM_XENGINE_AVCODEC_VIDEO_FRAMETYPE_P == enFrameType) |
| 141 | + { |
| 142 | + st_RTPPacket.byType = 1; |
| 143 | + } |
| 144 | + else |
| 145 | + { |
| 146 | + st_RTPPacket.byType = 0; |
| 147 | + } |
| 148 | + |
| 149 | + st_RTPPacket.wSerial = htons(nSeq++); |
| 150 | + XEngine_Device_StrtoBCD(lpszPhone, st_RTPPacket.bySIMNumber); |
| 151 | + BaseLib_OperatorTime_SetXTPTime(&st_RTPPacket.ullTimestamp); |
| 152 | + |
| 153 | + int nPos = 0; |
| 154 | + XCHAR tszMsgBuffer[2048]; |
| 155 | + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); |
| 156 | + |
| 157 | + memcpy(tszMsgBuffer, &st_RTPPacket, sizeof(XENGINE_RTPPACKETHDR)); |
| 158 | + nPos += sizeof(XENGINE_RTPPACKETHDR); |
| 159 | + |
| 160 | + memcpy(tszMsgBuffer + nPos, &st_PacketTail, sizeof(XENGINE_RTPPACKETTAIL)); |
| 161 | + nPos += sizeof(XENGINE_RTPPACKETTAIL); |
| 162 | + |
| 163 | + XSHOT wLen = htons(nCpyCount); |
| 164 | + memcpy(tszMsgBuffer + nPos, &wLen, sizeof(XSHOT)); |
| 165 | + nPos += sizeof(XSHOT); |
| 166 | + |
| 167 | + XClient_TCPSelect_SendMsg(hSocket, tszMsgBuffer, nPos); |
| 168 | + XClient_TCPSelect_SendMsg(hSocket, (LPCXSTR)ppSt_Frame[i]->ptszMsgBuffer + nUseCount, nCpyCount); |
| 169 | + nUseCount += nCpyCount; |
| 170 | + nMsgCount -= nCpyCount; |
| 171 | + } |
| 172 | + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ppSt_Frame[i]->ptszMsgBuffer); |
| 173 | + } |
| 174 | + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_Frame, nListCount); |
| 175 | + std::this_thread::sleep_for(std::chrono::milliseconds(40)); |
| 176 | + } |
| 177 | + AVHelp_Parse_FrameClose(xhToken); |
| 178 | + |
| 179 | + WSACleanup(); |
| 180 | + return 0; |
| 181 | +} |
0 commit comments