QTSS_Error EasyCameraSource::netDevStartStream() { //如果未登录,返回失败 if (!cameraLogin()) return QTSS_RequestFailed; //已经在流传输中,返回QTSS_NoErr if (m_bStreamFlag) return QTSS_NoErr; OSMutexLocker locker(this->GetMutex()); QTSS_Error theErr = QTSS_NoErr; HI_S32 s32Ret = HI_SUCCESS; HI_S_STREAM_INFO struStreamInfo; HI_NET_DEV_SetEventCallBack(m_u32Handle, (HI_ON_EVENT_CALLBACK)OnEventCallback, this); HI_NET_DEV_SetStreamCallBack(m_u32Handle, (HI_ON_STREAM_CALLBACK)OnStreamCallback, this); HI_NET_DEV_SetDataCallBack(m_u32Handle, (HI_ON_DATA_CALLBACK)OnDataCallback, this); struStreamInfo.u32Channel = HI_NET_DEV_CHANNEL_1; struStreamInfo.blFlag = sStreamType ? HI_TRUE : HI_FALSE; struStreamInfo.u32Mode = HI_NET_DEV_STREAM_MODE_TCP; struStreamInfo.u8Type = HI_NET_DEV_STREAM_ALL; s32Ret = HI_NET_DEV_StartStream(m_u32Handle, &struStreamInfo); if (s32Ret != HI_SUCCESS) { qtss_printf("HI_NET_DEV_StartStream Fail\n"); return QTSS_RequestFailed; } m_bStreamFlag = true; m_bForceIFrame = true; qtss_printf("HI_NET_DEV_StartStream SUCCESS\n"); return QTSS_NoErr; }
int main() { HI_S32 s32Ret = HI_SUCCESS; HI_S_STREAM_INFO struStreamInfo; HI_NET_DEV_Init(); s32Ret = HI_NET_DEV_Login(&u32Handle, UNAME, PWORD, DHOST, DPORT); 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, NULL); //HI_NET_DEV_SetDataCallBack(u32Handle, OnDataCallback, &a); struStreamInfo.u32Channel = HI_NET_DEV_CHANNEL_1; struStreamInfo.blFlag = HI_TRUE;; 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; } EASY_MEDIA_INFO_T mediainfo; memset(&mediainfo, 0x00, sizeof(EASY_MEDIA_INFO_T)); mediainfo.u32VideoCodec = EASY_SDK_VIDEO_CODEC_H264; mediainfo.u32AudioCodec = EASY_SDK_AUDIO_CODEC_G711A;//默认摄像机输出PCMA mediainfo.u32AudioSamplerate = 8000; fPusherHandle = EasyPusher_Create(); EasyPusher_SetEventCallback(fPusherHandle, __EasyPusher_Callback, 0, NULL); EasyPusher_StartStream(fPusherHandle, SHOST, SPORT, SNAME, "admin", "admin", &mediainfo, 1024); while(1) { #ifdef _WIN32 Sleep(10); #else usleep(10*1000); #endif }; EasyPusher_StopStream(fPusherHandle); EasyPusher_Release(fPusherHandle); fPusherHandle = 0; HI_NET_DEV_StopStream(u32Handle); HI_NET_DEV_Logout(u32Handle); HI_NET_DEV_DeInit(); return 0; }
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[]) { int isActivated = 0; #ifndef _WIN32 signal(SIGPIPE, SIG_IGN); #endif #ifdef _WIN32 extern char* optarg; #endif int ch; ProgName = argv[0]; PrintUsage(); while ((ch = getopt(argc,argv, "hd:p:n:N:P:H:T:")) != EOF) { switch(ch) { case 'h': PrintUsage(); return 0; break; case 'd': ConfigIP =optarg; break; case 'p': ConfigPort =optarg; break; case 'n': ConfigName =optarg; break; case 'N': ConfigUName =optarg; break; case 'P': ConfigPWD =optarg; break; case 'H': ConfigDHost =optarg; break; case 'T': ConfigDPort =optarg; break; case '?': return 0; break; default: break; } } isActivated = EasyPusher_Activate(KEY); switch(isActivated) { case EASY_ACTIVATE_INVALID_KEY: printf("KEY is EASY_ACTIVATE_INVALID_KEY!\n"); break; case EASY_ACTIVATE_TIME_ERR: printf("KEY is EASY_ACTIVATE_TIME_ERR!\n"); break; case EASY_ACTIVATE_PROCESS_NAME_LEN_ERR: printf("KEY is EASY_ACTIVATE_PROCESS_NAME_LEN_ERR!\n"); break; case EASY_ACTIVATE_PROCESS_NAME_ERR: printf("KEY is EASY_ACTIVATE_PROCESS_NAME_ERR!\n"); break; case EASY_ACTIVATE_VALIDITY_PERIOD_ERR: printf("KEY is EASY_ACTIVATE_VALIDITY_PERIOD_ERR!\n"); break; case EASY_ACTIVATE_SUCCESS: printf("KEY is EASY_ACTIVATE_SUCCESS!\n"); break; } if(EASY_ACTIVATE_SUCCESS != isActivated) return -1; HI_S32 s32Ret = HI_SUCCESS; HI_S_STREAM_INFO struStreamInfo; HI_NET_DEV_Init(); s32Ret = HI_NET_DEV_Login(&u32Handle, ConfigUName, ConfigPWD, ConfigDHost, atoi(ConfigDPort)); 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, NULL); //HI_NET_DEV_SetDataCallBack(u32Handle, OnDataCallback, &a); struStreamInfo.u32Channel = HI_NET_DEV_CHANNEL_1; struStreamInfo.blFlag = HI_TRUE;; 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; } EASY_MEDIA_INFO_T mediainfo; memset(&mediainfo, 0x00, sizeof(EASY_MEDIA_INFO_T)); mediainfo.u32VideoCodec = EASY_SDK_VIDEO_CODEC_H264; mediainfo.u32VideoFps = 25; mediainfo.u32AudioCodec = EASY_SDK_AUDIO_CODEC_G711A;//SDK output Audio PCMA mediainfo.u32AudioSamplerate = 8000; mediainfo.u32AudioChannel = 1; fPusherHandle = EasyPusher_Create(); EasyPusher_SetEventCallback(fPusherHandle, __EasyPusher_Callback, 0, NULL); EasyPusher_StartStream(fPusherHandle, ConfigIP, atoi(ConfigPort), ConfigName, "admin", "admin", &mediainfo, 1024, false);//1M缓冲区 printf("Press Enter exit...\n"); getchar(); EasyPusher_StopStream(fPusherHandle); EasyPusher_Release(fPusherHandle); fPusherHandle = 0; HI_NET_DEV_StopStream(u32Handle); HI_NET_DEV_Logout(u32Handle); HI_NET_DEV_DeInit(); return 0; }
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, UNAME, PWORD, DHOST, DPORT); 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; } WSADATA wsaData; WSAStartup(MAKEWORD(2,2), &wsaData); EASY_MEDIA_INFO_T mediainfo; memset(&mediainfo, 0x00, sizeof(EASY_MEDIA_INFO_T)); mediainfo.u32VideoCodec = 0x1C; pusherHandle = EasyPusher_Create(); EasyPusher_SetEventCallback(pusherHandle, __EasyPusher_Callback, 0, NULL); EasyPusher_StartStream(pusherHandle, SHOST, SPORT, "live.sdp", "admin", "admin", &mediainfo); printf("*** live streaming url:rtsp://%s:%d/live.sdp ***\n", SHOST, SPORT); while(1) { Sleep(10); }; EasyPusher_StopStream(pusherHandle); EasyPusher_Release(pusherHandle); pusherHandle = 0; HI_NET_DEV_StopStream(u32Handle); HI_NET_DEV_Logout(u32Handle); HI_NET_DEV_DeInit(); return 0; }