Browse Source

Z991239-6451 #comment 优化物理摄像头关闭逻辑

80274480 1 month ago
parent
commit
59614bda20
1 changed files with 30 additions and 43 deletions
  1. 30 43
      Module/mod_mediacontroller/mod_mediacontroller.cpp

+ 30 - 43
Module/mod_mediacontroller/mod_mediacontroller.cpp

@@ -211,16 +211,12 @@ void CMediaControllerEntity::OnSysVarEvent(const char *pszKey, const char *pszVa
 {
 	if (_stricmp(pszKey, SYSVAR_CALLSTATE) == 0)
 	{
-		CSimpleStringA strState;
-		GetFunction()->GetSysVar("UIState", strState);
 		if ('C' == pszValue[0]) {
 			StartAllCameras(true);
 		}
 		else if ('O' == pszValue[0]){
-			if (strState.GetLength() > 0 && strState[0] == 'M') {
-				if (eCameraOpened == m_eCameraState) {
-					DelayCloseCameras();
-				}
+			if (eCameraOpened == m_eCameraState) {
+				DelayCloseCameras();
 			}
 		}
 	}
@@ -293,12 +289,8 @@ bool CMediaControllerEntity::HandleVirtucalCamMsg(const char* strMsg)
 	else if (strstr(strMsg, "Stop")) {
 		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Stop virtual Camera %s.", strMsg);
 		m_bVirtualCamOpened = false;
-		CSimpleStringA strState;
-		GetFunction()->GetSysVar("UIState", strState);
-		if (strState.GetLength() > 0 && strState[0] == 'M') {
-			if (eCameraOpened == m_eCameraState) {
-				DelayCloseCameras();
-			}
+		if (eCameraOpened == m_eCameraState) {
+			DelayCloseCameras();
 		}
 		bRet = true;
 	}
@@ -1209,29 +1201,21 @@ void CMediaControllerEntity::OnTimeout(DWORD dwTimerID)
 	}
 	else if (RVC_CAMERA_OFF_TIMER == dwTimerID) {
 		if (eCameraOpened == m_eCameraState) {
-			CSimpleStringA strCallState("");
-			if (Error_Succeed == GetFunction()->GetSysVar(SYSVAR_CALLSTATE, strCallState)) {
-				if ((strCallState.Compare("O") == 0) && (false == m_bVirtualCamOpened)) {
-					if (m_capture) {
-						GetFunction()->KillTimer(RVC_MEDIADEV_STATUS_CHECK_TIMER);
-						capture_stop(m_capture);
-						DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402208V5")("关闭摄像头");
-						capture_destroy(m_capture);
-						m_capture = NULL;
-					}
-					OnCameraStopped();
-					m_eCameraState = eCameraClose;
-					if (m_bCameraOffTimerOn) {
-						if (Error_Succeed != GetFunction()->KillTimer(RVC_CAMERA_OFF_TIMER)) {
-							LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIACONTROLLER_KILLTIMER_ERROR, "stop camera, kill camera off timer failed.");
-						}
-						else {
-							m_bCameraOffTimerOn = false;
-						}
-					}
+			if (m_capture) {
+				GetFunction()->KillTimer(RVC_MEDIADEV_STATUS_CHECK_TIMER);
+				capture_stop(m_capture);
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402208V5")("关闭摄像头");
+				capture_destroy(m_capture);
+				m_capture = NULL;
+			}
+			OnCameraStopped();
+			m_eCameraState = eCameraClose;
+			if (m_bCameraOffTimerOn) {
+				if (Error_Succeed != GetFunction()->KillTimer(RVC_CAMERA_OFF_TIMER)) {
+					LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIACONTROLLER_KILLTIMER_ERROR, "stop camera, kill camera off timer failed.");
 				}
 				else {
-					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CallState is %s, and current virtual camera is %s.", strCallState.GetData(), m_bVirtualCamOpened?"on":"off");
+					m_bCameraOffTimerOn = false;
 				}
 			}
 		}
@@ -1749,20 +1733,23 @@ ErrorCodeEnum CMediaControllerEntity::StartAllCameras(bool bstartaudio)
 void CMediaControllerEntity::DelayCloseCameras() 
 {
 	if (false == m_bCameraOffTimerOn) {
-		if (Error_Succeed != GetFunction()->SetTimer(RVC_CAMERA_OFF_TIMER, this, m_iDelayTime * 1000)) {
-			LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIACONTROLLER_SETTIMER_ERROR, "delay close camera, set camera off timer failed.");
+		CSimpleStringA strCallState("");
+		GetFunction()->GetSysVar(SYSVAR_CALLSTATE, strCallState);
+
+		if ((strCallState.Compare("O") == 0) && (false == m_bOnBusiness) && (false == m_bVirtualCamOpened)) {
+			if (Error_Succeed != GetFunction()->SetTimer(RVC_CAMERA_OFF_TIMER, this, m_iDelayTime * 1000)) {
+				LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIACONTROLLER_SETTIMER_ERROR, "delay close camera, set camera off timer failed.");
+			}
+			else {
+				m_bCameraOffTimerOn = true;
+			}
 		}
 		else {
-			m_bCameraOffTimerOn = true;
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CallState is %s, on business flag is %s, and current virtual camera is %s.", strCallState.GetData(), m_bOnBusiness ? "true" : "false", m_bVirtualCamOpened ? "on" : "off");
 		}
 	}
 	else {
-		if (Error_Succeed == GetFunction()->ResetTimer(RVC_CAMERA_OFF_TIMER, m_iDelayTime * 1000)) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Retset camera off timer success!");
-		}
-		else {
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Retset camera off timer failed!");
-		}
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("camera off timer is already on.");
 	}
 }
 
@@ -2223,10 +2210,10 @@ void CMediaControllerEntity::OnLog( const CAutoArray<CUUID> &SubIDs, const CUUID
 		break;
 
 	case LOG_EVT_END_HANDLE_BUSINESS:
+		m_bOnBusiness = false;
 		if (eCameraOpened == m_eCameraState) {
 			DelayCloseCameras();
 		}
-		m_bOnBusiness = false;
 		break;
 
 	case LOG_EVT_RECORDFAILED: