|
@@ -42,6 +42,129 @@
|
|
|
#define BUFFER_SIZE 256
|
|
|
#endif
|
|
|
|
|
|
+enum eMsgType {
|
|
|
+ eStartCamera,
|
|
|
+ eCapProcess,
|
|
|
+ eStopCamera,
|
|
|
+ eMsgDefault
|
|
|
+};
|
|
|
+
|
|
|
+static char* GetCameraInfo(int mode)
|
|
|
+{
|
|
|
+ switch (mode) {
|
|
|
+ case ModeVideoEnv:
|
|
|
+ {
|
|
|
+ return "RVC_ENV_Virtual_Camera";
|
|
|
+ }
|
|
|
+ case ModeVideoOpt:
|
|
|
+ {
|
|
|
+ return "RVC_OPT_Virtual_Camera";
|
|
|
+ }
|
|
|
+ default: {
|
|
|
+ return "Error_Camera_Info";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static bool GetStartCameraMsg(char* szbuffer, int ibufferlen, int imode, char* pstrmsg)
|
|
|
+{
|
|
|
+ char* strCameraInfo = GetCameraInfo(imode);
|
|
|
+
|
|
|
+ snprintf(szbuffer, ibufferlen, "%s %s+%s", pstrmsg, strCameraInfo, "Start");
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+static bool GetStopCameraMsg(char* szbuffer, int ibufferlen, int imode, char* pstrmsg, int icaptime, int iframenums)
|
|
|
+{
|
|
|
+ char* strCameraInfo = GetCameraInfo(imode);
|
|
|
+
|
|
|
+ snprintf(szbuffer, ibufferlen, "%s %s+%s", pstrmsg, strCameraInfo, "Stop");
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+static bool GetDefaultCameraMsg(char* szbuffer, int ibufferlen, int imode, char* pstrmsg)
|
|
|
+{
|
|
|
+ char* strCameraInfo = GetCameraInfo(imode);
|
|
|
+
|
|
|
+ snprintf(szbuffer, ibufferlen, "%s+%s", strCameraInfo, pstrmsg);
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+static bool ConstructMsg(char* szbuffer, int ibufferlen, int imode, eMsgType eType, char* pstrmsg, int icaptime, int iframenums)
|
|
|
+{
|
|
|
+ switch (eType) {
|
|
|
+ case eStartCamera:
|
|
|
+ {
|
|
|
+ return GetStartCameraMsg(szbuffer, ibufferlen, imode, pstrmsg);
|
|
|
+ }
|
|
|
+ case eCapProcess:
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ case eStopCamera:
|
|
|
+ {
|
|
|
+ return GetStopCameraMsg(szbuffer, ibufferlen, imode, pstrmsg, icaptime, iframenums);
|
|
|
+ }
|
|
|
+ case eMsgDefault:
|
|
|
+ {
|
|
|
+ return GetDefaultCameraMsg(szbuffer, ibufferlen, imode, pstrmsg);
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static bool PostCameraStateMsg(int imode, eMsgType eType, char* pstrmsg, int icaptime = 0, int iframenums = 0)
|
|
|
+{
|
|
|
+ bool bRet = false;
|
|
|
+ //Connect to the server mailslot using CreateFile()
|
|
|
+ HANDLE hMailslot = CreateFileA(
|
|
|
+ szMailslot, // mailslot name
|
|
|
+ GENERIC_WRITE, // mailslot write only
|
|
|
+ FILE_SHARE_READ, // required for mailslots
|
|
|
+ NULL, // default security attributes
|
|
|
+ OPEN_EXISTING, // opens existing mailslot
|
|
|
+ FILE_ATTRIBUTE_NORMAL, // normal attributes
|
|
|
+ NULL); // no template file
|
|
|
+
|
|
|
+ if (INVALID_HANDLE_VALUE == hMailslot) {
|
|
|
+ return bRet; //Error
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //We are done connecting to the mailslot,
|
|
|
+ //Mailslot communication is one-way,
|
|
|
+ //client will just write to mailslot
|
|
|
+ //Using WriteFile()
|
|
|
+
|
|
|
+ char szBuffer[BUFFER_SIZE] = { 0 };
|
|
|
+ ConstructMsg(szBuffer, BUFFER_SIZE, imode, eType, pstrmsg, icaptime, iframenums);
|
|
|
+
|
|
|
+ DWORD cbBytes;
|
|
|
+
|
|
|
+ //Send the message to server
|
|
|
+ BOOL bResult = WriteFile(
|
|
|
+ hMailslot, // handle to mailslot
|
|
|
+ szBuffer, // buffer to write from
|
|
|
+ strlen(szBuffer) + 1, // number of bytes to write, include the NULL
|
|
|
+ &cbBytes, // number of bytes written
|
|
|
+ NULL); // not overlapped I/O
|
|
|
+
|
|
|
+ if ((!bResult) || (strlen(szBuffer) + 1 != cbBytes)) {
|
|
|
+ CloseHandle(hMailslot);
|
|
|
+ return false; //Error
|
|
|
+ }
|
|
|
+
|
|
|
+ CloseHandle(hMailslot);
|
|
|
+
|
|
|
+ bRet = true;
|
|
|
+
|
|
|
+ return bRet; //Success
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
CUnknown * WINAPI CreateEnvInstance(LPUNKNOWN lpunk, HRESULT *phr)
|
|
|
{
|
|
@@ -166,6 +289,12 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
|
|
|
REFERENCE_TIME end_time = 0;
|
|
|
REFERENCE_TIME duration = 0;
|
|
|
|
|
|
+ static bool bloged = false;
|
|
|
+ if (!bloged) {
|
|
|
+ PostCameraStateMsg(m_queue_mode, eMsgDefault, __FUNCTION__);
|
|
|
+ bloged = true;
|
|
|
+ }
|
|
|
+
|
|
|
hr = pms->GetPointer((BYTE**)&m_dst);
|
|
|
long lsize = pms->GetSize();
|
|
|
|
|
@@ -183,6 +312,18 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
|
|
|
shared_queue_get_video_format(m_queue_mode, &m_format, &m_frame_width, &m_frame_height, &m_time_perframe);
|
|
|
SetGetTimeout();
|
|
|
m_sync_timeout = 0;
|
|
|
+ static bool bsucloged = false;
|
|
|
+ if (!bsucloged) {
|
|
|
+ PostCameraStateMsg(m_queue_mode, eMsgDefault, "shared_queue_open success");
|
|
|
+ bsucloged = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ static bool bfailloged = false;
|
|
|
+ if (!bfailloged) {
|
|
|
+ PostCameraStateMsg(m_queue_mode, eMsgDefault, "shared_queue_open failed");
|
|
|
+ bfailloged = true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -385,113 +526,6 @@ HRESULT CVCamStream::DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIE
|
|
|
return NOERROR;
|
|
|
}
|
|
|
|
|
|
-static char* GetCameraInfo(int mode)
|
|
|
-{
|
|
|
- switch (mode) {
|
|
|
- case ModeVideoEnv:
|
|
|
- {
|
|
|
- return "RVC_ENV_Virtual_Camera";
|
|
|
- }
|
|
|
- case ModeVideoOpt:
|
|
|
- {
|
|
|
- return "RVC_OPT_Virtual_Camera";
|
|
|
- }
|
|
|
- default: {
|
|
|
- return "Error_Camera_Info";
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static bool GetStartCameraMsg(char* szbuffer, int ibufferlen, int imode)
|
|
|
-{
|
|
|
- char* strCameraInfo = GetCameraInfo(imode);
|
|
|
-
|
|
|
- _snprintf(szbuffer, ibufferlen, "%s+%s", strCameraInfo, "Start");
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-static bool GetStopCameraMsg(char* szbuffer, int ibufferlen, int imode, int icaptime, int iframenums)
|
|
|
-{
|
|
|
- char* strCameraInfo = GetCameraInfo(imode);
|
|
|
-
|
|
|
- _snprintf(szbuffer, ibufferlen, "%s+%s", strCameraInfo, "Stop");
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-static bool ConstructMsg(char* szbuffer, int ibufferlen, int imode, bool bstart, int icaptime, int iframenums)
|
|
|
-{
|
|
|
- bool bRet = false;
|
|
|
- if (bstart) {
|
|
|
- bRet = GetStartCameraMsg(szbuffer, ibufferlen, imode);
|
|
|
- }
|
|
|
- else {
|
|
|
- bRet = GetStopCameraMsg(szbuffer, ibufferlen, imode, icaptime, iframenums);
|
|
|
- }
|
|
|
-
|
|
|
- return bRet;
|
|
|
-}
|
|
|
-
|
|
|
-static bool PostCameraStateMsg(int imode, bool bstart, int icaptime = 0, int iframenums = 0)
|
|
|
-{
|
|
|
- bool bRet = false;
|
|
|
- //Connect to the server mailslot using CreateFile()
|
|
|
- HANDLE hMailslot = CreateFileA(
|
|
|
- szMailslot, // mailslot name
|
|
|
- GENERIC_WRITE, // mailslot write only
|
|
|
- FILE_SHARE_READ, // required for mailslots
|
|
|
- NULL, // default security attributes
|
|
|
- OPEN_EXISTING, // opens existing mailslot
|
|
|
- FILE_ATTRIBUTE_NORMAL, // normal attributes
|
|
|
- NULL); // no template file
|
|
|
-
|
|
|
- if (INVALID_HANDLE_VALUE == hMailslot)
|
|
|
- {
|
|
|
- printf("\nError occurred while connecting"
|
|
|
- " to the server: %d", GetLastError());
|
|
|
- return bRet; //Error
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- printf("\nCreateFile() was successful.");
|
|
|
- }
|
|
|
-
|
|
|
- //We are done connecting to the mailslot,
|
|
|
- //Mailslot communication is one-way,
|
|
|
- //client will just write to mailslot
|
|
|
- //Using WriteFile()
|
|
|
-
|
|
|
- char szBuffer[BUFFER_SIZE] = {0};
|
|
|
- ConstructMsg(szBuffer, BUFFER_SIZE, imode, bstart, icaptime, iframenums);
|
|
|
-
|
|
|
- DWORD cbBytes;
|
|
|
-
|
|
|
- //Send the message to server
|
|
|
- BOOL bResult = WriteFile(
|
|
|
- hMailslot, // handle to mailslot
|
|
|
- szBuffer, // buffer to write from
|
|
|
- strlen(szBuffer) + 1, // number of bytes to write, include the NULL
|
|
|
- &cbBytes, // number of bytes written
|
|
|
- NULL); // not overlapped I/O
|
|
|
-
|
|
|
- if ((!bResult) || (strlen(szBuffer) + 1 != cbBytes))
|
|
|
- {
|
|
|
- printf("\nError occurred while writing"
|
|
|
- " to the server: %d", GetLastError());
|
|
|
- CloseHandle(hMailslot);
|
|
|
- return false; //Error
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- printf("\nWriteFile() was successful.");
|
|
|
- }
|
|
|
-
|
|
|
- CloseHandle(hMailslot);
|
|
|
- bRet = true;
|
|
|
-
|
|
|
- return bRet; //Success
|
|
|
-}
|
|
|
|
|
|
HRESULT CVCamStream::OnThreadCreate()
|
|
|
{
|
|
@@ -500,7 +534,7 @@ HRESULT CVCamStream::OnThreadCreate()
|
|
|
m_dshow_start_ts = 0;
|
|
|
m_system_start_time = 0;
|
|
|
m_camera_started = true;
|
|
|
- PostCameraStateMsg(m_queue_mode, m_camera_started);
|
|
|
+ PostCameraStateMsg(m_queue_mode, eStartCamera, __FUNCTION__);
|
|
|
|
|
|
return NOERROR;
|
|
|
}
|
|
@@ -513,7 +547,7 @@ HRESULT CVCamStream::OnThreadDestroy()
|
|
|
if (m_queue.header) {
|
|
|
shared_queue_read_close(&m_queue);
|
|
|
}
|
|
|
- PostCameraStateMsg(m_queue_mode, m_camera_started);
|
|
|
+ PostCameraStateMsg(m_queue_mode, eStopCamera, __FUNCTION__);
|
|
|
|
|
|
return NOERROR;
|
|
|
}
|