Преглед на файлове

Z991240-862 #comment other: 完成screenshot实体改造

胡琛80272472 преди 5 години
родител
ревизия
781edbc286
променени са 4 файла, в които са добавени 188 реда и са изтрити 11 реда
  1. 66 0
      Module/mod_screenshot/CMakeLists.txt
  2. 28 5
      Module/mod_screenshot/mod_screenshot.cpp
  3. 78 6
      Module/mod_screenshot/screencapture.cpp
  4. 16 0
      Module/mod_screenshot/screencapture.h

+ 66 - 0
Module/mod_screenshot/CMakeLists.txt

@@ -0,0 +1,66 @@
+define_module("screenshot")
+
+set(${MODULE_PREFIX}_SRCS
+	mod_screenshot.cpp
+	screencapture.cpp
+	screencapture.h
+	ScreenShot_client_g.h
+	ScreenShot_def_g.h
+	ScreenShot_server_g.h
+	)
+
+set(MOD_VERSION_STRING "0.0.1-dev1")
+add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
+
+conan_cmake_run(REQUIRES zlib/1.2.11@LR04.02_ThirdParty/stable
+BASIC_SETUP CMAKE_TARGETS
+BUILD missing)
+conan_cmake_run(REQUIRES openjpeg/2.0.0@LR04.02_ThirdParty/testing
+    BASIC_SETUP CMAKE_TARGETS
+    BUILD missing)
+conan_cmake_run(REQUIRES opencv/3.1.0@LR04.02_ThirdParty/testing
+BASIC_SETUP CMAKE_TARGETS
+BUILD missing)
+
+if(WIN32)
+target_include_directories(${MODULE_NAME} PRIVATE
+	${RVC_FRAMEWORK_INCLUDES_DIR}
+	${CONAN_RVCFRAMEWORK_ROOT}/include
+    ${MODULE_BASE_DIR}
+	${MODULE_BASE_DIR}/include
+	${OTHER_LIB_BASE_DIR}/libscreencodec
+	${OTHER_LIB_BASE_DIR}/libbizchan
+	${CONAN_INCLUDE_DIRS_OPENCV}
+    ${CONAN_INCLUDE_DIRS_OPENCV}/opencv
+)
+
+# 添加需要依赖的其他共享库(包括系统库)
+target_link_directories(${MODULE_NAME} PRIVATE ${CONAN_LIB_DIRS_OPENJPEG} ${CONAN_LIB_DIRS_OPENCV} ${CONAN_LIB_DIRS_ZLIB} )
+# 添加实体需要依赖的其他共享库(包括系统库)
+target_link_libraries(${MODULE_NAME} ${MODULE_BASE_LIBS} libbizchan libscreencodec ${CONAN_PKG_LIBS_OPENJPEG} ${CONAN_LIBS_OPENCV} ${CONAN_PKG_LIBS_ZLIB})
+
+else(WIN32)
+conan_cmake_run(REQUIRES libX11/1.6@LR04.02_ThirdParty/testing
+BASIC_SETUP CMAKE_TARGETS
+BUILD missing)
+
+target_include_directories(${MODULE_NAME} PRIVATE
+	${RVC_FRAMEWORK_INCLUDES_DIR}
+	${CONAN_RVCFRAMEWORK_ROOT}/include
+    ${MODULE_BASE_DIR}
+	${MODULE_BASE_DIR}/include
+	${OTHER_LIB_BASE_DIR}/libscreencodec
+	${OTHER_LIB_BASE_DIR}/libbizchan
+	${CONAN_INCLUDE_DIRS_OPENCV}
+    ${CONAN_INCLUDE_DIRS_OPENCV}/opencv
+	${CONAN_INCLUDE_DIRS_LIBX11})
+
+# 添加需要依赖的其他共享库(包括系统库)
+target_link_directories(${MODULE_NAME} PRIVATE ${CONAN_LIB_DIRS_OPENJPEG} ${CONAN_LIB_DIRS_OPENCV} ${CONAN_LIB_DIRS_ZLIB} ${CONAN_LIB_DIRS_LIBX11})
+# 添加实体需要依赖的其他共享库(包括系统库)
+target_link_libraries(${MODULE_NAME} ${MODULE_BASE_LIBS} libbizchan libscreencodec ${CONAN_PKG_LIBS_OPENJPEG} ${CONAN_LIBS_OPENCV} ${CONAN_PKG_LIBS_ZLIB} ${CONAN_PKG_LIBS_LIBX11})
+
+endif(WIN32)
+
+
+deploy_module(${MODULE_PREFIX} ${MODULE_NAME})

+ 28 - 5
Module/mod_screenshot/mod_screenshot.cpp

@@ -4,17 +4,20 @@
 #include "screencapture.h"
 #include <screencodec.h>
 
-#include "..\mod_assistantchannel\AssistantChannel_client_g.h"
+#include "mod_assistantchannel/AssistantChannel_client_g.h"
 using namespace AssistantChannel;
-#include "..\mod_Assistantchannel\chan_protocol.h"
+#include "mod_assistantchannel/chan_protocol.h"
 
-#include "..\\mod_assistantchannel\\VideoDesc.h"
+#include "mod_assistantchannel/VideoDesc.h"
 // add by ly 20150514
 #include "jpeg2k.h"
 #include "ScreenShot_server_g.h"
 #include "cv.h"
 #include "highgui.h"
 #include "cxcore.h"
+
+#include "CommEntityUtil.hpp"
+
 using namespace ScreenShot;
 
 #define LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE		0x50500001  //ЭÖúͨµÀÖØÆô
@@ -243,8 +246,13 @@ public:
 			screen_encoder_session_destroy(m_enc_session);
 			m_enc_session = NULL;
 		}
+#ifdef RVC_OS_WIN
 		int cx = GetSystemMetrics(SM_CXSCREEN);
 		int cy = GetSystemMetrics(SM_CYSCREEN);
+#else
+		int cx, cy;
+		getScreenSize(&cx, &cy);
+#endif
 		if (m_bIsWallMachine)
 		{
 			cy = cy-640;
@@ -264,8 +272,13 @@ public:
 	void Capture(int id)
 	{
 		CSystemStaticInfo SysInfo;
+#ifdef RVC_OS_WIN
 		int cx = GetSystemMetrics(SM_CXSCREEN);
 		int cy = GetSystemMetrics(SM_CYSCREEN);
+#else
+		int cx, cy;
+		getScreenSize(&cx, &cy);
+#endif
 		RECT rc = {0, 0, cx, cy};
 		int size = 0;
 		int err = screencapture_capture(&rc, NULL, &size);
@@ -331,14 +344,19 @@ public:
 		}	
 
 		free(buf);
-		LOG_TRACE("encode size = %d Bytes, time = %d", Info.data.m_iLength, GetTickCount());
+		LOG_TRACE("encode size = %d Bytes, time = %d", Info.data.m_iLength, SP::Module::Comm::RVCGetTickCount());
 	}
 
 	void Capture1(int id)
 	{
 		CSystemStaticInfo SysInfo;
+#ifdef RVC_OS_WIN
 		int cx = GetSystemMetrics(SM_CXSCREEN);
 		int cy = GetSystemMetrics(SM_CYSCREEN);
+#else
+		int cx, cy;
+		getScreenSize(&cx, &cy);
+#endif
 		RECT rc = {0, 0, cx, cy};
 		int size = 0;
 		int err = screencapture_capture(&rc, NULL, &size);
@@ -385,7 +403,7 @@ public:
 		//DumpCaptureDat((const char*)Info.data.m_pData, Info.data.m_iLength);
 		m_pChannelClient->Send(Info);
 		free(buf);
-		LOG_TRACE("encode size = %d Bytes, time = %d", Info.data.m_iLength, GetTickCount());
+		LOG_TRACE("encode size = %d Bytes, time = %d", Info.data.m_iLength, SP::Module::Comm::RVCGetTickCount());
 	}
 
 	void Capture2(RECT *lprc, CBlob &image)
@@ -459,8 +477,13 @@ void CScreenShotSession::Handle_StartScreenShot(SpReqAnsContext<ScreenShotServic
 {
 	Dbg("accepted params: %d, %d, %d, %d", ctx->Req.Left, ctx->Req.Top, ctx->Req.Width, ctx->Req.Height);
 	
+#ifdef RVC_OS_WIN
 	int cx = GetSystemMetrics(SM_CXSCREEN);
 	int cy = GetSystemMetrics(SM_CYSCREEN);
+#else
+	int cx, cy;
+	getScreenSize(&cx, &cy);
+#endif
 	if (ctx->Req.Left < 0 || ctx->Req.Left > cx || ctx->Req.Width <= 0 || ctx->Req.Width > cx ||
 		ctx->Req.Top < 0 || ctx->Req.Top > cy || ctx->Req.Height <= 0 || ctx->Req.Height > cy)
 	{

+ 78 - 6
Module/mod_screenshot/screencapture.cpp

@@ -1,6 +1,7 @@
 #include "stdafx.h"
 #include "screencapture.h"
 
+#ifdef RVC_OS_WIN
 static HMONITOR GetPrimaryMonitorHandle()
 {
 	const POINT ptZero = {0, 0};
@@ -505,20 +506,91 @@ on_error:
 	return rc;
 }
 
+#else
 
-int screencapture_clipoff(int width, int height, void *buf, int n_rc, RECT *rcs)
+#include <X11/Xutil.h>
+#include <X11/Xlib.h>
+
+int screencapture_capture(RECT* lprc, void* buf, int* size) {
+	int width = lprc->right - lprc->left;
+	int height = lprc->bottom - lprc->top;
+	int linesize = (width * 3 + 3) & 0xfffffffc;
+
+	if (buf == NULL) {
+		*size = linesize * height;
+		return 0;
+	}
+
+	Display* display = XOpenDisplay(NULL);
+	Window root = DefaultRootWindow(display);
+
+	XImage* image = XGetImage(display, root, lprc ? lprc->left : 0, lprc ? lprc->top : 0, width, height, AllPlanes, ZPixmap);
+
+	unsigned long red_mask = image->red_mask;
+	unsigned long green_mask = image->green_mask;
+	unsigned long blue_mask = image->blue_mask;
+
+	for (int x = 0; x < width; x++){
+		for (int y = 0; y < height; y++)
+		{
+			unsigned long pixel = XGetPixel(image, x, y);
+
+			unsigned char blue = pixel & blue_mask;
+			unsigned char green = (pixel & green_mask) >> 8;
+			unsigned char red = (pixel & red_mask) >> 16;
+
+			((unsigned char *)buf)[(x + width * y) * 3] = red;
+			((unsigned char*)buf)[(x + width * y) * 3 + 1] = green;
+			((unsigned char*)buf)[(x + width * y) * 3 + 2] = blue;
+		}
+	}
+
+	*size = linesize * height;
+
+	if (image != NULL) {
+		XDestroyImage(image);
+		image = NULL;
+	}
+	if (display != NULL) {
+		XCloseDisplay(display);
+		display = NULL;
+	}
+
+	return 0;
+}
+
+
+int getScreenSize(int* width, int* height) {
+	Display* display = XOpenDisplay(NULL);
+	int default_id = DefaultScreen(display);
+	Screen* screen = ScreenOfDisplay(display, default_id);
+
+	*width = screen->width;
+	*height = screen->height;
+
+	if (display != NULL) {
+		XCloseDisplay(display);
+		display = NULL;
+	}
+
+	return 0;
+}
+
+#endif
+
+
+int screencapture_clipoff(int width, int height, void* buf, int n_rc, RECT* rcs)
 {
 	int i, k;
-	char *p;
+	char* p;
 
 	for (i = 0; i < n_rc; ++i) {
-		RECT *lprc = &rcs[i];
+		RECT* lprc = &rcs[i];
 		for (k = lprc->top, p = (char*)buf + lprc->top * width * 3 + lprc->left * 3; k < lprc->bottom; ++k) {
-			memset(p, 0, (lprc->right - lprc->left)*3);
+			memset(p, 0, (lprc->right - lprc->left) * 3);
 			p += width * 3;
 		}
 	}
 
 	return 0;
-}
-
+}

+ 16 - 0
Module/mod_screenshot/screencapture.h

@@ -5,6 +5,22 @@
 
 #include <iobuffer.h>
 
+#ifdef RVC_OS_LINUX
+typedef struct tagRECT
+{
+    LONG    left;
+    LONG    top;
+    LONG    right;
+    LONG    bottom;
+} RECT, * PRECT, NEAR* NPRECT, FAR* LPRECT;
+
+
+int getScreenSize(int* width, int* height);
+
+#endif // RVC_OS_LINUX
+
+
+
 // if lprc == null, then full screen
 // zero on success, -1 on failed
 int screencapture_capture(RECT *lprc, void *buf, int *size);