int main(int argc, char * argv[]) { #ifdef _WIN32 extern char* optarg; #endif int ch; ProgName = argv[0]; PrintUsage(); while ((ch = getopt(argc,argv, "hc:C:v:t:d:n:u:U:")) != EOF) { switch(ch) { case 'h': PrintUsage(); return 0; break; case 'c': ConfigPlayListCapacity =atoi(optarg); break; case 'C': ConfigAllowCache =atoi(optarg); break; case 'v': ConfigM3U8Version =atoi(optarg); break; case 't': ConfigTargetDuration =atoi(optarg); break; case 'd': ConfigHLSRootDir =optarg; break; case 'n': ConfigHLSessionName =optarg; break; case 'U': ConfigHttpRootUrl =optarg; break; case '?': return 0; break; default: break; } } int buf_size = 1024*512; char *pbuf = (char *) malloc(buf_size); FILE *fES = NULL; int position = 0; int iFrameNo = 0; int timestamp = 0; fES = fopen("./EasyPusher.264", "rb"); if (NULL == fES) return 0; //EasyHLS SDK需要首先经过激活才能继续调用 if(0 != EasyHLS_Activate(KEY)) return -1; //创建EasyHLS Session fHLSHandle = EasyHLS_Session_Create(ConfigPlayListCapacity, ConfigAllowCache, ConfigM3U8Version); char subDir[64] = { 0 }; sprintf(subDir,"%s/",ConfigHLSessionName); EasyHLS_ResetStreamCache(fHLSHandle, ConfigHLSRootDir, subDir, ConfigHLSessionName, ConfigTargetDuration); printf("HLS URL:%s%s/%s.m3u8\n", ConfigHLSRootDir, ConfigHLSessionName, ConfigHLSessionName); while (1) { int nReadBytes = fread(pbuf+position, 1, 1, fES); if (nReadBytes < 1) { if (feof(fES)) { position = 0; fseek(fES, 0, SEEK_SET); continue; } break; } position ++; if (position > 5) { unsigned char naltype = ( (unsigned char)pbuf[position-1] & 0x1F); if ( (unsigned char)pbuf[position-5]== 0x00 && (unsigned char)pbuf[position-4]== 0x00 && (unsigned char)pbuf[position-3] == 0x00 && (unsigned char)pbuf[position-2] == 0x01 && (naltype == 0x07 || naltype == 0x01 ) ) { int framesize = position - 5; naltype = (unsigned char)pbuf[4] & 0x1F; timestamp += 1000/25; unsigned int uiFrameType = 0; if (naltype == 0x07) { uiFrameType = TS_TYPE_PES_VIDEO_I_FRAME; } else { uiFrameType = TS_TYPE_PES_VIDEO_P_FRAME; } EasyHLS_VideoMux(fHLSHandle, uiFrameType, (unsigned char*)pbuf, framesize, timestamp*90, timestamp*90, timestamp*90); #ifndef _WIN32 usleep(30*1000); #else Sleep(30); #endif memmove(pbuf, pbuf+position-5, 5); position = 5; iFrameNo ++; } } } printf("Press Enter exit...\n"); getchar(); EasyHLS_Session_Release(fHLSHandle); fHLSHandle = 0; free(pbuf); return 0; }
int main(int argc, char * argv[]) { #ifdef _WIN32 extern char* optarg; #endif int ch; ProgName = argv[0]; PrintUsage(); while ((ch = getopt(argc,argv, "hc:C:v:t:i:d:n:u:U:")) != EOF) { switch(ch) { case 'h': PrintUsage(); return 0; break; case 'c': ConfigPlayListCapacity =atoi(optarg); break; case 'C': ConfigAllowCache =atoi(optarg); break; case 'v': ConfigM3U8Version =atoi(optarg); break; case 't': ConfigTargetDuration =atoi(optarg); break; case 'i': ConfigFirtTSIFrameCount = atoi(optarg); break; case 'd': ConfigHLSRootDir =optarg; break; case 'n': ConfigHLSessionName =optarg; break; case 'u': ConfigRTSPURL =optarg; break; case 'U': ConfigHttpRootUrl =optarg; break; case '?': return 0; break; default: break; } } int isEasyHLSActivated = EasyHLS_Activate(KEY); switch(isEasyHLSActivated) { case EASY_ACTIVATE_INVALID_KEY: printf("EasyHLS_KEY is EASY_ACTIVATE_INVALID_KEY!\n"); break; case EASY_ACTIVATE_TIME_ERR: printf("EasyHLS_KEY is EASY_ACTIVATE_TIME_ERR!\n"); break; case EASY_ACTIVATE_PROCESS_NAME_LEN_ERR: printf("EasyHLS_KEY is EASY_ACTIVATE_PROCESS_NAME_LEN_ERR!\n"); break; case EASY_ACTIVATE_PROCESS_NAME_ERR: printf("EasyHLS_KEY is EASY_ACTIVATE_PROCESS_NAME_ERR!\n"); break; case EASY_ACTIVATE_VALIDITY_PERIOD_ERR: printf("EasyHLS_KEY is EASY_ACTIVATE_VALIDITY_PERIOD_ERR!\n"); break; case EASY_ACTIVATE_SUCCESS: printf("EasyHLS_KEY is EASY_ACTIVATE_SUCCESS!\n"); break; } if(EASY_ACTIVATE_SUCCESS != isEasyHLSActivated) return -1; if( EASY_ACTIVATE_SUCCESS != EasyRTSP_Activate(EasyRTSPClient_KEY)) return -1; //创建EasyRTSPClient EasyRTSP_Init(&fRTSPHandle); if (NULL == fRTSPHandle) return 0; unsigned int mediaType = EASY_SDK_VIDEO_FRAME_FLAG | EASY_SDK_AUDIO_FRAME_FLAG; //设置数据回调处理 EasyRTSP_SetCallback(fRTSPHandle, __RTSPClientCallBack); //打开RTSP流 EasyRTSP_OpenStream(fRTSPHandle, 0, ConfigRTSPURL, EASY_RTP_OVER_TCP, mediaType, 0, 0, NULL, 1000, 0, 0x01, 1); //创建EasyHLS Session fHLSHandle = EasyHLS_Session_Create(ConfigPlayListCapacity, ConfigAllowCache, ConfigM3U8Version); char subDir[64] = { 0 }; sprintf(subDir,"%s/",ConfigHLSessionName); EasyHLS_ResetStreamCache(fHLSHandle, ConfigHLSRootDir, subDir, ConfigHLSessionName, ConfigTargetDuration, ConfigFirtTSIFrameCount); printf("HLS URL:%s%s/%s.m3u8\n", ConfigHLSRootDir, ConfigHLSessionName, ConfigHLSessionName); printf("Press Enter exit...\n"); getchar(); EasyHLS_Session_Release(fHLSHandle); fHLSHandle = 0; EasyRTSP_CloseStream(fRTSPHandle); EasyRTSP_Deinit(&fRTSPHandle); fRTSPHandle = NULL; return 0; }