int main() { HI_S32 s32Ret = HI_SUCCESS; HI_S_STREAM_INFO struStreamInfo; HI_U32 a; HI_NET_DEV_Init(); s32Ret = HI_NET_DEV_Login(&u32Handle, CNAME, CPWORD, CHOST, CPORT); if (s32Ret != HI_SUCCESS) { HI_NET_DEV_DeInit(); return -1; } //HI_NET_DEV_SetEventCallBack(u32Handle, OnEventCallback, &a); HI_NET_DEV_SetStreamCallBack(u32Handle, (HI_ON_STREAM_CALLBACK)OnStreamCallback, &a); //HI_NET_DEV_SetDataCallBack(u32Handle, OnDataCallback, &a); struStreamInfo.u32Channel = HI_NET_DEV_CHANNEL_1; struStreamInfo.blFlag = HI_FALSE;//HI_FALSE; struStreamInfo.u32Mode = HI_NET_DEV_STREAM_MODE_TCP; struStreamInfo.u8Type = HI_NET_DEV_STREAM_ALL; s32Ret = HI_NET_DEV_StartStream(u32Handle, &struStreamInfo); if (s32Ret != HI_SUCCESS) { HI_NET_DEV_Logout(u32Handle); u32Handle = 0; return -1; } //创建EasyHLS Session fHlsHandle = EasyHLS_Session_Create(PLAYLIST_CAPACITY, ALLOW_CACHE, M3U8_VERSION); char subDir[64] = { 0 }; sprintf(subDir,"%s/",HLS_SESSION_NAME); EasyHLS_ResetStreamCache(fHlsHandle, HLS_ROOT_DIR, subDir, HLS_SESSION_NAME, TARGET_DURATION); printf("HLS URL:%s%s/%s.m3u8", HTTP_ROOT_URL, HLS_SESSION_NAME, HLS_SESSION_NAME); while(1) { #ifndef _WIN32 usleep(10*1000); #else Sleep(10); #endif }; EasyHLS_Session_Release(fHlsHandle); fHlsHandle = 0; HI_NET_DEV_StopStream(u32Handle); HI_NET_DEV_Logout(u32Handle); HI_NET_DEV_DeInit(); 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: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 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: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': ConfigRTSPURL =optarg; break; case 'U': ConfigHttpRootUrl =optarg; break; case '?': return 0; break; default: break; } } //创建NVSource 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, RTP_OVER_TCP, mediaType, 0, 0, NULL, 1000, 0); //创建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); printf("Press Enter exit...\n"); getchar(); EasyHLS_Session_Release(fHLSHandle); fHLSHandle = 0; EasyRTSP_CloseStream(fRTSPHandle); EasyRTSP_Deinit(&fRTSPHandle); fRTSPHandle = NULL; 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; }