From b9b836119f170e4b799e4b805d0c7078c9e3b319 Mon Sep 17 00:00:00 2001 From: dijunkun Date: Tue, 29 Aug 2023 00:21:33 +0800 Subject: [PATCH] Remove files --- application/remote_desk/dll/dllmain.cpp | 19 -- application/remote_desk/dll/headers_ffmpeg.h | 22 -- application/remote_desk/dll/log_helper.cpp | 60 ------ application/remote_desk/dll/log_helper.h | 63 ------ application/remote_desk/dll/main.cpp | 13 +- application/remote_desk/dll/record_desktop.h | 190 +++++++++++------- .../remote_desk/dll/record_desktop_define.h | 45 ----- .../remote_desk/dll/record_desktop_wgc.cpp | 35 +--- application/remote_desk/dll/system_error.cpp | 39 ---- application/remote_desk/dll/system_error.h | 12 -- application/remote_desk/dll/utils_string.cpp | 66 ------ application/remote_desk/dll/utils_string.h | 23 --- 12 files changed, 134 insertions(+), 453 deletions(-) delete mode 100644 application/remote_desk/dll/dllmain.cpp delete mode 100644 application/remote_desk/dll/headers_ffmpeg.h delete mode 100644 application/remote_desk/dll/log_helper.cpp delete mode 100644 application/remote_desk/dll/log_helper.h delete mode 100644 application/remote_desk/dll/record_desktop_define.h delete mode 100644 application/remote_desk/dll/system_error.cpp delete mode 100644 application/remote_desk/dll/system_error.h delete mode 100644 application/remote_desk/dll/utils_string.cpp delete mode 100644 application/remote_desk/dll/utils_string.h diff --git a/application/remote_desk/dll/dllmain.cpp b/application/remote_desk/dll/dllmain.cpp deleted file mode 100644 index f266597..0000000 --- a/application/remote_desk/dll/dllmain.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// dllmain.cpp : Defines the entry point for the DLL application. -#include "pch.h" - -BOOL APIENTRY DllMain( HMODULE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved - ) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - return TRUE; -} - diff --git a/application/remote_desk/dll/headers_ffmpeg.h b/application/remote_desk/dll/headers_ffmpeg.h deleted file mode 100644 index 9d090ef..0000000 --- a/application/remote_desk/dll/headers_ffmpeg.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -extern "C" { -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -} \ No newline at end of file diff --git a/application/remote_desk/dll/log_helper.cpp b/application/remote_desk/dll/log_helper.cpp deleted file mode 100644 index 5d1a424..0000000 --- a/application/remote_desk/dll/log_helper.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "log_helper.h" - -#include -#include -#include - -#include - -#define AMLOCK(A) std::lock_guard lock(A) - -#define LOG_ROLL_SIZE (1024 * 1024) - -AMLog* AMLog::_log = NULL; -std::mutex _lock; - -AMLog::AMLog(FILE* handle) : _handle(handle) { _log = this; } - -AMLog::~AMLog() { - AMLOCK(_lock); - if (_log && _handle) { - fclose(_handle); - _log = NULL; - } -} - -AMLog* AMLog::get(const char* path) { - if (_log || !path) { - return _log; - } - // DWORD size = 0; - // HANDLE file = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, - // FILE_ATTRIBUTE_NORMAL, NULL); if (file != INVALID_HANDLE_VALUE) { - // size = GetFileSize(file, NULL); CloseHandle(file); - // } - // if (size != INVALID_FILE_SIZE && size > LOG_ROLL_SIZE) { - // if (DeleteFileA(path) == FALSE) { - // TCHAR roll_path[MAX_PATH]; - // sprintf_s(roll_path, MAX_PATH, "%s.1", path); - // if (!MoveFileEx(path, roll_path, MOVEFILE_REPLACE_EXISTING)) { - // return NULL; - // } - // } - // } - // FILE* handle = _fsopen(path, "a+", _SH_DENYNO); - // if (!handle) { - // return NULL; - // } - // _log = new AMLog(handle); - return _log; -} - -void AMLog::printf(const char* format, ...) { - AMLOCK(_lock); - va_list args; - - va_start(args, format); - vfprintf(_handle, format, args); - va_end(args); - fflush(_handle); -} diff --git a/application/remote_desk/dll/log_helper.h b/application/remote_desk/dll/log_helper.h deleted file mode 100644 index 39999c2..0000000 --- a/application/remote_desk/dll/log_helper.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef AM_LOG -#define AM_LOG - -#include -#include -#include - -#include - -class AMLog { -public: - ~AMLog(); - static AMLog* get(const char* path = NULL); - void printf(const char* format, ...); - -private: - AMLog(FILE* handle); - -private: - static AMLog* _log; - FILE* _handle; -}; - - -enum AM_LOG_TYPE { - AL_TYPE_DEBUG = 0, - AL_TYPE_INFO, - AL_TYPE_WARN, - AL_TYPE_ERROR, - AL_TYPE_FATAL, -}; - -static const char *AM_LOG_STR[] = { "DEBUG", "INFO", "WARN", "ERROR", "FATAL" }; - -#define al_printf(type,format,datetime,ms,...) \ - printf("%s-%.3d [%s] [%s(%d)] " format "\n", datetime,ms,type, __FUNCTION__,__LINE__, ## __VA_ARGS__) - -#define PRINT_LINE(type, format, datetime, ms, ...) \ - printf("%s-%.3d [%s] [%s(%d)] " format "\n", datetime,ms,type, __FUNCTION__,__LINE__, ## __VA_ARGS__) - -#define al_log(type,format,...) do{ \ - struct _timeb now; \ - struct tm today; \ - char datetime_str[20]; \ - _ftime_s(&now); \ - localtime_s(&today, &now.time); \ - strftime(datetime_str, 20, "%Y-%m-%d %H:%M:%S", &today); \ - AMLog *am_log = AMLog::get(); \ - if(am_log){ \ - am_log->PRINT_LINE(AM_LOG_STR[type], format, datetime_str, now.millitm, ## __VA_ARGS__); \ - } else { \ - al_printf(AM_LOG_STR[type], format, datetime_str, now.millitm, ## __VA_ARGS__); \ - } \ -}while (0) - - -#define al_debug(format, ...) al_log(AL_TYPE_DEBUG, format, ## __VA_ARGS__) -#define al_info(format, ...) al_log(AL_TYPE_INFO, format, ## __VA_ARGS__) -#define al_warn(format, ...) al_log(AL_TYPE_WARN, format, ## __VA_ARGS__) -#define al_error(format, ...) al_log(AL_TYPE_ERROR, format, ## __VA_ARGS__) -#define al_fatal(format, ...) al_log(AL_TYPE_FATAL, format, ## __VA_ARGS__) - -#endif \ No newline at end of file diff --git a/application/remote_desk/dll/main.cpp b/application/remote_desk/dll/main.cpp index 797d927..ab1f1bf 100644 --- a/application/remote_desk/dll/main.cpp +++ b/application/remote_desk/dll/main.cpp @@ -15,11 +15,11 @@ int main() { static am::record_desktop *recorder = new am::record_desktop_wgc(); - RECORD_DESKTOP_RECT rect; - rect.left = 0; - rect.top = 0; - rect.right = GetSystemMetrics(SM_CXSCREEN); - rect.bottom = GetSystemMetrics(SM_CYSCREEN); + RECORD_DESKTOP_RECT rect; + rect.left = 0; + rect.top = 0; + rect.right = GetSystemMetrics(SM_CXSCREEN); + rect.bottom = GetSystemMetrics(SM_CYSCREEN); recorder->init(rect, 10); @@ -28,7 +28,8 @@ int main() { // int resume() override; // int stop() override; - while(1){} + while (1) { + } return 0; } \ No newline at end of file diff --git a/application/remote_desk/dll/record_desktop.h b/application/remote_desk/dll/record_desktop.h index efbadc7..0780538 100644 --- a/application/remote_desk/dll/record_desktop.h +++ b/application/remote_desk/dll/record_desktop.h @@ -1,80 +1,124 @@ #ifndef RECORD_DESKTOP #define RECORD_DESKTOP -#include "record_desktop_define.h" - -#include "headers_ffmpeg.h" - -#include -#include -#include -#include - -namespace am { - typedef std::function cb_desktop_data; - typedef std::function cb_desktop_error; - - class record_desktop - { - public: - record_desktop(); - virtual ~record_desktop(); - - virtual int init( - const RECORD_DESKTOP_RECT &rect, - const int fps - ) = 0; - - virtual int start() = 0; - virtual int pause() = 0; - virtual int resume() = 0; - virtual int stop() = 0; - - inline const AVRational & get_time_base() { return _time_base; } - - inline int64_t get_start_time() { return _start_time; } - - inline AVPixelFormat get_pixel_fmt() { return _pixel_fmt; } - - public: - inline bool is_recording() { return _running; } - inline const std::string & get_device_name() { return _device_name; } - inline const RECORD_DESKTOP_DATA_TYPES get_data_type() { return _data_type; } - inline void registe_cb( - cb_desktop_data on_data, - cb_desktop_error on_error) { - _on_data = on_data; - _on_error = on_error; - } - inline const RECORD_DESKTOP_RECT & get_rect() { return _rect; } - - inline const int get_frame_rate() { return _fps; } - - protected: - virtual void clean_up() = 0; - - protected: - std::atomic_bool _running; - std::atomic_bool _paused; - std::atomic_bool _inited; - - std::thread _thread; - - std::string _device_name; - - RECORD_DESKTOP_RECT _rect; - RECORD_DESKTOP_DATA_TYPES _data_type; - - int _fps; - - cb_desktop_data _on_data; - cb_desktop_error _on_error; - - AVRational _time_base; - int64_t _start_time; - AVPixelFormat _pixel_fmt; - }; +extern "C" { +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include } +#include +#include +#include +#include + +typedef enum { + DT_DESKTOP_NO = 0, + DT_DESKTOP_FFMPEG_GDI, + DT_DESKTOP_FFMPEG_DSHOW, + DT_DESKTOP_WIN_GDI, + DT_DESKTOP_WIN_DUPLICATION, + DT_DESKTOP_WIN_WGC, + DT_DESKTOP_WIN_MAG +} RECORD_DESKTOP_TYPES; + +/* + * Record desktop data type + * + */ + +typedef enum { + AT_DESKTOP_NO = 0, + AT_DESKTOP_RGBA, + AT_DESKTOP_BGRA +} RECORD_DESKTOP_DATA_TYPES; + +/** + * Record desktop rect + * + */ + +typedef struct { + int left; + int top; + int right; + int bottom; +} RECORD_DESKTOP_RECT; + +namespace am { +typedef std::function cb_desktop_data; +typedef std::function cb_desktop_error; + +class record_desktop { + public: + record_desktop(); + virtual ~record_desktop(); + + virtual int init(const RECORD_DESKTOP_RECT &rect, const int fps) = 0; + + virtual int start() = 0; + virtual int pause() = 0; + virtual int resume() = 0; + virtual int stop() = 0; + + inline const AVRational &get_time_base() { return _time_base; } + + inline int64_t get_start_time() { return _start_time; } + + inline AVPixelFormat get_pixel_fmt() { return _pixel_fmt; } + + public: + inline bool is_recording() { return _running; } + inline const std::string &get_device_name() { return _device_name; } + inline const RECORD_DESKTOP_DATA_TYPES get_data_type() { return _data_type; } + inline void registe_cb(cb_desktop_data on_data, cb_desktop_error on_error) { + _on_data = on_data; + _on_error = on_error; + } + inline const RECORD_DESKTOP_RECT &get_rect() { return _rect; } + + inline const int get_frame_rate() { return _fps; } + + protected: + virtual void clean_up() = 0; + + protected: + std::atomic_bool _running; + std::atomic_bool _paused; + std::atomic_bool _inited; + + std::thread _thread; + + std::string _device_name; + + RECORD_DESKTOP_RECT _rect; + RECORD_DESKTOP_DATA_TYPES _data_type; + + int _fps; + + cb_desktop_data _on_data; + cb_desktop_error _on_error; + + AVRational _time_base; + int64_t _start_time; + AVPixelFormat _pixel_fmt; +}; +} // namespace am #endif \ No newline at end of file diff --git a/application/remote_desk/dll/record_desktop_define.h b/application/remote_desk/dll/record_desktop_define.h deleted file mode 100644 index 797ca79..0000000 --- a/application/remote_desk/dll/record_desktop_define.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef RECORD_DESKTOP_DEFINE -#define RECORD_DESKTOP_DEFINE - -/* -* Record typee -* -*/ -typedef enum { - DT_DESKTOP_NO = 0, - DT_DESKTOP_FFMPEG_GDI, - DT_DESKTOP_FFMPEG_DSHOW, - DT_DESKTOP_WIN_GDI, - DT_DESKTOP_WIN_DUPLICATION, - DT_DESKTOP_WIN_WGC, - DT_DESKTOP_WIN_MAG -}RECORD_DESKTOP_TYPES; - -/* -* Record desktop data type -* -*/ - -typedef enum { - AT_DESKTOP_NO = 0, - AT_DESKTOP_RGBA, - AT_DESKTOP_BGRA -}RECORD_DESKTOP_DATA_TYPES; - -/** -* Record desktop rect -* -*/ - -typedef struct { - int left; - int top; - int right; - int bottom; -}RECORD_DESKTOP_RECT; - - - - - -#endif diff --git a/application/remote_desk/dll/record_desktop_wgc.cpp b/application/remote_desk/dll/record_desktop_wgc.cpp index db94912..0058da7 100644 --- a/application/remote_desk/dll/record_desktop_wgc.cpp +++ b/application/remote_desk/dll/record_desktop_wgc.cpp @@ -1,21 +1,15 @@ #include "record_desktop_wgc.h" -#include "utils_string.h" - -#include "system_error.h" #include "error_define.h" -#include "log_helper.h" BOOL WINAPI EnumMonitorProc(HMONITOR hmonitor, HDC hdc, LPRECT lprc, LPARAM data) { - MONITORINFOEX info_ex; info_ex.cbSize = sizeof(MONITORINFOEX); GetMonitorInfo(hmonitor, &info_ex); - if (info_ex.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER) - return true; + if (info_ex.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER) return true; if (info_ex.dwFlags & MONITORINFOF_PRIMARY) { *(HMONITOR *)data = hmonitor; @@ -34,7 +28,6 @@ HMONITOR GetPrimaryMonitor() { namespace am { - record_desktop_wgc::record_desktop_wgc() {} record_desktop_wgc::~record_desktop_wgc() { @@ -44,8 +37,7 @@ record_desktop_wgc::~record_desktop_wgc() { int record_desktop_wgc::init(const RECORD_DESKTOP_RECT &rect, const int fps) { int error = AE_NO; - if (_inited == true) - return error; + if (_inited == true) return error; _fps = fps; _rect = rect; @@ -73,8 +65,6 @@ int record_desktop_wgc::init(const RECORD_DESKTOP_RECT &rect, const int fps) { } while (0); if (error != AE_NO) { - al_debug("%s,last error:%s", err2str(error), - system_error::error2str(GetLastError()).c_str()); } return error; @@ -82,7 +72,7 @@ int record_desktop_wgc::init(const RECORD_DESKTOP_RECT &rect, const int fps) { int record_desktop_wgc::start() { if (_running == true) { - al_warn("record desktop duplication is already running"); + // al_warn("record desktop duplication is already running"); return AE_NO; } @@ -98,29 +88,26 @@ int record_desktop_wgc::start() { int record_desktop_wgc::pause() { _paused = true; - if (session_) - session_->pause(); + if (session_) session_->pause(); return AE_NO; } int record_desktop_wgc::resume() { _paused = false; - if (session_) - session_->resume(); + if (session_) session_->resume(); return AE_NO; } int record_desktop_wgc::stop() { _running = false; - if (session_) - session_->stop(); + if (session_) session_->stop(); return AE_NO; } void record_desktop_wgc::on_frame(const wgc_session::wgc_session_frame &frame) { - al_debug("wgc on frame"); + // al_debug("wgc on frame"); AVFrame *av_frame = av_frame_alloc(); av_frame->pts = av_gettime_relative(); @@ -136,8 +123,7 @@ void record_desktop_wgc::on_frame(const wgc_session::wgc_session_frame &frame) { av_image_fill_arrays(av_frame->data, av_frame->linesize, frame.data, AV_PIX_FMT_BGRA, frame.width, frame.height, 1); - if (_on_data) - _on_data(av_frame); + if (_on_data) _on_data(av_frame); av_frame_free(&av_frame); } @@ -145,10 +131,9 @@ void record_desktop_wgc::on_frame(const wgc_session::wgc_session_frame &frame) { void record_desktop_wgc::clean_up() { _inited = false; - if (session_) - session_->release(); + if (session_) session_->release(); session_ = nullptr; } -} // namespace am \ No newline at end of file +} // namespace am \ No newline at end of file diff --git a/application/remote_desk/dll/system_error.cpp b/application/remote_desk/dll/system_error.cpp deleted file mode 100644 index 001bdca..0000000 --- a/application/remote_desk/dll/system_error.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "system_error.h" - -#include - -namespace am { - -const std::string& system_error::error2str(unsigned long error) { - // DWORD system_locale = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL); - - // HLOCAL local_buf = nullptr; - - // BOOL ret = FormatMessage( - // FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | - // FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, error, system_locale,(PSTR) - // &local_buf, 0, NULL); - - // if (!ret) { - // HMODULE hnetmsg = LoadLibraryEx("netmsg.dll", NULL, - // DONT_RESOLVE_DLL_REFERENCES); if (hnetmsg != nullptr) { - // ret = FormatMessage( FORMAT_MESSAGE_FROM_HMODULE | - // FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER, - // hnetmsg, error, system_locale, (PSTR)&local_buf, 0, NULL); - - // FreeLibrary(hnetmsg); - // } - // } - - // std::string error_str; - - // if (ret) { - // error_str = (LPCTSTR)LocalLock(local_buf); - // LocalFree(local_buf); - // } - - // return error_str; - return ""; -} - -} // namespace am \ No newline at end of file diff --git a/application/remote_desk/dll/system_error.h b/application/remote_desk/dll/system_error.h deleted file mode 100644 index cb8120f..0000000 --- a/application/remote_desk/dll/system_error.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -namespace am { - -class system_error { -public: - static const std::string& error2str(unsigned long error); -}; - -} diff --git a/application/remote_desk/dll/utils_string.cpp b/application/remote_desk/dll/utils_string.cpp deleted file mode 100644 index 90b921a..0000000 --- a/application/remote_desk/dll/utils_string.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "utils_string.h" - -#include -#ifdef WIN32 - -#include - -#endif - -namespace am { - -std::wstring utils_string::ascii_unicode(const std::string &str) { - int unicodeLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, nullptr, 0); - - wchar_t *pUnicode = (wchar_t *)malloc(sizeof(wchar_t) * unicodeLen); - - MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, pUnicode, unicodeLen); - - std::wstring ret_str = pUnicode; - - free(pUnicode); - - return ret_str; -} - -std::string utils_string::unicode_ascii(const std::wstring &wstr) { - int ansiiLen = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, nullptr, 0, - nullptr, nullptr); - char *pAssii = (char *)malloc(sizeof(char) * ansiiLen); - WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, pAssii, ansiiLen, nullptr, - nullptr); - std::string ret_str = pAssii; - free(pAssii); - return ret_str; -} - -std::string utils_string::ascii_utf8(const std::string &str) { - return unicode_utf8(ascii_unicode(str)); -} - -std::string utils_string::utf8_ascii(const std::string &utf8) { - return unicode_ascii(utf8_unicode(utf8)); -} - -std::string utils_string::unicode_utf8(const std::wstring &wstr) { - int ansiiLen = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, - nullptr, nullptr); - char *pAssii = (char *)malloc(sizeof(char) * ansiiLen); - WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, pAssii, ansiiLen, nullptr, - nullptr); - std::string ret_str = pAssii; - free(pAssii); - return ret_str; -} - -std::wstring utils_string::utf8_unicode(const std::string &utf8) { - int unicodeLen = - MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1, nullptr, 0); - wchar_t *pUnicode = (wchar_t *)malloc(sizeof(wchar_t) * unicodeLen); - MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), -1, pUnicode, unicodeLen); - std::wstring ret_str = pUnicode; - free(pUnicode); - return ret_str; -} - -} // namespace am \ No newline at end of file diff --git a/application/remote_desk/dll/utils_string.h b/application/remote_desk/dll/utils_string.h deleted file mode 100644 index 8c5dc42..0000000 --- a/application/remote_desk/dll/utils_string.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include - -namespace am { - - class utils_string - { - public: - static std::wstring ascii_unicode(const std::string & str); - - static std::string unicode_ascii(const std::wstring &wstr); - - static std::string ascii_utf8(const std::string & str); - - static std::string utf8_ascii(const std::string &utf8); - - static std::string unicode_utf8(const std::wstring& wstr); - - static std::wstring utf8_unicode(const std::string &utf8); - }; - -} \ No newline at end of file