Browse Source

Z991239-6451 #comment 未安装虚拟摄像头不往虚拟摄像头专用共享内存写视频流

80274480 1 month ago
parent
commit
1cd20f5ebc

+ 6 - 5
Module/mod_localmediaplay/mod_localmediaplay.cpp

@@ -1309,10 +1309,6 @@ DWORD WINAPI MediaPlayThread(LPVOID param)
 				config.bPrimMonitor = true;
 			}
 
-			if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)){
-				break;
-			}
-
 			if (false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)){
 				if (WAIT_TIMEOUT == WaitForSingleObject(entity->m_hStopMediaPlayEvent, 30*DEFAULT_SLEEP_TIME)) {
 					continue;
@@ -1322,6 +1318,10 @@ DWORD WINAPI MediaPlayThread(LPVOID param)
 				}
 			}
 
+			if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
+				break;
+			}
+
 			if (!entity->GetLocalVideoVolume(0, config.nVolume)){
 				config.nVolume = entity->m_defaultVolum;
 			}
@@ -1438,9 +1438,10 @@ DWORD WINAPI MediaPlayThread(LPVOID param)
 		if (uend_time - ustart_time < RVC_MIN_LOCALPLAYER_TIME) {
 			break;
 		}
-		blog = false;
 	}
 
+	blog = false;
+
 	if (entity->m_badplayflag) {
 		entity->m_badplayflag = false;
 	}

+ 36 - 27
Module/mod_mediacontroller/capture.cpp

@@ -1191,14 +1191,17 @@ static void cap_on_original_frame(void* user_data, video_frame* vframe)
 	video_capture_t* video_cap = (video_capture_t*)user_data;
 #ifdef RVC_OS_WIN
 	share_queue* shm_queue = &video_cap->original_shm_queue;
-	if (!shared_queue_push_video(shm_queue, (uint32_t*)vframe->linesize, vframe->width, vframe->height, vframe->data, os_gettime_ns())) {
-		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("caution: insert original frame to shm video failed!");
+	if (shm_queue->hwnd != NULL && shm_queue->header != NULL) {
+		if (!shared_queue_push_video(shm_queue, (uint32_t*)vframe->linesize, vframe->width, vframe->height, vframe->data, os_gettime_ns())) {
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("caution: insert original frame to shm video failed!");
+		}
+		//else {
+		//	share_queue original_queue = video_cap->original_shm_queue;
+		//	DEBUG_QUEUE_INFO(original_queue)
+		//	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("insert original frame to shm video ok, and video frame id is %d.", video_cap->frame_id);
+		//}
 	}
-	//else {
-	//	share_queue original_queue = video_cap->original_shm_queue;
-	//	DEBUG_QUEUE_INFO(original_queue)
-	//	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("insert original frame to shm video ok, and video frame id is %d.", video_cap->frame_id);
-	//}
+
 #else
 	if (-1 != video_cap->virtual_device_fd) {
 		size_t udatalen = vframe->linesize[0] * vframe->height;
@@ -1234,8 +1237,6 @@ static video_capture_t *video_capture_create(capture_t *cap, int camera_type)
 		video_cap->isaveinterval = 0;
 #endif
 #endif
-		uint64_t interval = (uint64_t)1000000000ULL / (uint64_t)cap->config.video_env_fps;
-		int iqueuelen = cap->config.video_env_fps;
 		if (camera_type == CAMERA_TYPE_ENV) {
 			video_cap->snapshot_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE);
 			video_cap->rtp_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE);
@@ -1256,8 +1257,6 @@ static video_capture_t *video_capture_create(capture_t *cap, int camera_type)
 				SWS_FAST_BILINEAR, NULL, NULL, NULL);
 		} 
 		else {
-			interval = (uint64_t)1000000000ULL / (uint64_t)cap->config.video_opt_fps;
-			iqueuelen = cap->config.video_opt_fps;
 			video_cap->snapshot_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE);
 			video_cap->rtp_shm_queue = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE);
 			video_cap->rtp_sws_ctx = sws_getContext(REC_COMMON_VIDEO_SNAPSHOT_HEIGHT, 
@@ -1278,17 +1277,24 @@ static video_capture_t *video_capture_create(capture_t *cap, int camera_type)
 		}
 
 #ifdef RVC_OS_WIN
-		bool bret = shared_queue_create(&video_cap->original_shm_queue, camera_type,
-			VIDEO_FORMAT_YUY2, REC_COMMON_VIDEO_SNAPSHOT_WIDTH, REC_COMMON_VIDEO_SNAPSHOT_HEIGHT, interval,
-			iqueuelen);
+		int idevid = capture_get_video_device_id((camera_type == CAMERA_TYPE_ENV) ? RVC_ENV_VIRTUALCAMERA : RVC_OPT_VIRTUALCAMERA);
+		if (idevid >= 0) {
+			int ivideo_cap_fps = ((camera_type == CAMERA_TYPE_ENV) ? cap->config.video_env_fps : cap->config.video_opt_fps);
+			uint64_t interval = (uint64_t)1000000000ULL / (uint64_t)ivideo_cap_fps;
+			int iqueuelen = ivideo_cap_fps;
 
-		if (bret) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("create %s original share video queue success.", (camera_type == CAMERA_TYPE_ENV) ? "env":"opt");
-			share_queue original_queue = video_cap->original_shm_queue;
-			DEBUG_QUEUE_INFO(original_queue)
-		}
-		else {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("create %s original share video queue failed.", (camera_type == CAMERA_TYPE_ENV) ? "env" : "opt");
+			bool bret = shared_queue_create(&video_cap->original_shm_queue, camera_type,
+				VIDEO_FORMAT_YUY2, REC_COMMON_VIDEO_SNAPSHOT_WIDTH, REC_COMMON_VIDEO_SNAPSHOT_HEIGHT, interval,
+				iqueuelen);
+
+			if (bret) {
+				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("create %s original share video queue success.", (camera_type == CAMERA_TYPE_ENV) ? "env" : "opt");
+				share_queue original_queue = video_cap->original_shm_queue;
+				DEBUG_QUEUE_INFO(original_queue)
+			}
+			else {
+				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("create %s original share video queue failed.", (camera_type == CAMERA_TYPE_ENV) ? "env" : "opt");
+			}
 		}
 #else
 		video_cap->virtual_device_fd = -1;
@@ -1343,9 +1349,14 @@ static void video_capture_destroy(video_capture_t *video_cap)
 		}
 
 #ifdef RVC_OS_WIN
-		shared_queue_write_close(&video_cap->original_shm_queue);
+		share_queue* q = &video_cap->original_shm_queue;
+		if ((NULL != q->hwnd) && (NULL != q->header)) {
+			shared_queue_write_close(&video_cap->original_shm_queue);
+		}
 #else
-		rvc_videocap_close_video_device(video_cap->virtual_device_fd);
+		if (-1 != video_cap->virtual_device_fd) {
+			rvc_videocap_close_video_device(video_cap->virtual_device_fd);
+		}
 #endif
 
 		FREE(video_cap);
@@ -1849,8 +1860,6 @@ namespace MediaController {
 
 	ErrorCodeEnum capture_start(capture_t *cap, bool bstartaudio)
 	{
-		int rc = 0;
-
 		if (bstartaudio) {
 			if ('N' == cap->config.strAudioState[0] || 'P' == cap->config.strAudioState[0]) {
 				ErrorCodeEnum rslt = start_audio_capture(cap->handfree_audio);
@@ -2085,7 +2094,7 @@ namespace MediaController {
 
 			char t2[MAX_PATH] = {0};
 			strcpy(t2, t1);
-			for (int j = 0; j < strlen(t2); ++j)
+			for (int j = 0; j < (int)strlen(t2); ++j)
 			{
 				t2[j] = toupper(t2[j]);
 				if (t2[j] == '#') t2[j] = '\\';
@@ -2200,7 +2209,7 @@ namespace MediaController {
 				char t[MAX_PATH] = { 0 };
 				WCHAR tmp1[MAX_PATH] = { 0 };
 				char t1[MAX_PATH] = { 0 };
-				WCHAR tmp2[MAX_PATH] = { 0 };
+				//WCHAR tmp2[MAX_PATH] = { 0 };
 				char t2[MAX_PATH] = { 0 };
 				videocap_get_device_name(i, tmp, ARRAYSIZE(tmp));
 				WideCharToMultiByte(CP_ACP, 0, tmp, -1, t, sizeof(t), 0, NULL);

+ 0 - 7
Module/mod_mediacontroller/mod_mediacontroller.cpp

@@ -85,18 +85,11 @@
 #define NETLINK_RVC 17
 #endif
 
-
 #ifdef RVC_OS_WIN
 typedef HRESULT(__stdcall* PFNREGISTERSERVER)(void);
 typedef HRESULT(__stdcall* PFNUNREGISTERSERVER)(void);
 #endif
 
-
-#ifndef RVC_DEFAULT_KERNEL_VERSION
-#define RVC_DEFAULT_KERNEL_VERSION "4.19.0-arm64-desktop"
-#endif
-
-
 #ifdef RVC_OS_WIN
 static void __audio_render_log(audiorender_loglevel elevel, void* user_data, const char* fmt, va_list arg)
 {

+ 4 - 4
Other/win/virtualcam/virtualcam.cpp

@@ -259,7 +259,7 @@ void CVCamStream::SetSyncTimeout()
 
 void CVCamStream::SetGetTimeout()
 {
-	m_get_timeout = ((VIDEOINFOHEADER*)m_mt.pbFormat)->AvgTimePerFrame * 3 / (RVC_SLEEP_DURATION * 10000);
+	m_get_timeout = (int)((VIDEOINFOHEADER*)m_mt.pbFormat)->AvgTimePerFrame * 3 / (RVC_SLEEP_DURATION * 10000);
 }
 
 HRESULT CVCamStream::QueryInterface(REFIID riid, void **ppv)
@@ -404,7 +404,7 @@ HRESULT CVCamStream::GetMediaType(int iPosition, CMediaType *pmt)
 		ListSupportFormat();
 	}
 		
-	if (iPosition < 0 || iPosition > m_format_list.size() - 1) {
+	if (iPosition < 0 || iPosition > (int)(m_format_list.size() - 1)) {
 		return E_INVALIDARG;
 	}
 
@@ -468,7 +468,7 @@ HRESULT CVCamStream::CheckMediaType(const CMediaType *pMediaType)
 	return E_INVALIDARG;
 } 
 
-bool CVCamStream::ValidateResolution(long width, long height)
+bool CVCamStream::ValidateResolution(uint32_t width, uint32_t height)
 {
 	if (width < RVC_MIN_WIDTH || height < RVC_MIN_HEIGHT) {
 		return false;
@@ -597,7 +597,7 @@ HRESULT STDMETHODCALLTYPE CVCamStream::GetStreamCaps(int iIndex, AM_MEDIA_TYPE *
 		ListSupportFormat();
 	}
 
-	if (iIndex < 0 || iIndex > m_format_list.size() - 1) {
+	if (iIndex < 0 || iIndex > (int)(m_format_list.size() - 1)) {
 		return E_INVALIDARG;
 	}
 

+ 1 - 1
Other/win/virtualcam/virtualcam.h

@@ -119,7 +119,7 @@ private:
 
 	bool ListSupportFormat(void);
 	bool CheckRvcSetting(void);
-	bool ValidateResolution(long width, long height);
+	bool ValidateResolution(uint32_t width, uint32_t height);
 	void SetSyncTimeout();
 	void SetGetTimeout();