Remove files

This commit is contained in:
dijunkun
2023-08-29 00:21:33 +08:00
parent ed8c81540a
commit b9b836119f
12 changed files with 134 additions and 453 deletions

View File

@@ -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;
}

View File

@@ -1,22 +0,0 @@
#pragma once
extern "C" {
#include <libavcodec\adts_parser.h>
#include <libavcodec\avcodec.h>
#include <libavdevice\avdevice.h>
#include <libavfilter\avfilter.h>
#include <libavfilter\buffersink.h>
#include <libavfilter\buffersrc.h>
#include <libavformat\avformat.h>
#include <libavutil\avassert.h>
#include <libavutil\channel_layout.h>
#include <libavutil\error.h>
#include <libavutil\imgutils.h>
#include <libavutil\log.h>
#include <libavutil\mathematics.h>
#include <libavutil\opt.h>
#include <libavutil\samplefmt.h>
#include <libavutil\time.h>
#include <libavutil\timestamp.h>
#include <libswresample\swresample.h>
#include <libswscale\swscale.h>
}

View File

@@ -1,60 +0,0 @@
#include "log_helper.h"
#include <share.h>
#include <stdarg.h>
#include <stdio.h>
#include <mutex>
#define AMLOCK(A) std::lock_guard<std::mutex> 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);
}

View File

@@ -1,63 +0,0 @@
#ifndef AM_LOG
#define AM_LOG
#include <stdio.h>
#include <time.h>
#include <sys\timeb.h>
#include <windows.h>
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

View File

@@ -28,7 +28,8 @@ int main() {
// int resume() override;
// int stop() override;
while(1){}
while (1) {
}
return 0;
}

View File

@@ -1,36 +1,83 @@
#ifndef RECORD_DESKTOP
#define RECORD_DESKTOP
#include "record_desktop_define.h"
#include "headers_ffmpeg.h"
extern "C" {
#include <libavcodec\adts_parser.h>
#include <libavcodec\avcodec.h>
#include <libavdevice\avdevice.h>
#include <libavfilter\avfilter.h>
#include <libavfilter\buffersink.h>
#include <libavfilter\buffersrc.h>
#include <libavformat\avformat.h>
#include <libavutil\avassert.h>
#include <libavutil\channel_layout.h>
#include <libavutil\error.h>
#include <libavutil\imgutils.h>
#include <libavutil\log.h>
#include <libavutil\mathematics.h>
#include <libavutil\opt.h>
#include <libavutil\samplefmt.h>
#include <libavutil\time.h>
#include <libavutil\timestamp.h>
#include <libswresample\swresample.h>
#include <libswscale\swscale.h>
}
#include <atomic>
#include <thread>
#include <functional>
#include <string>
#include <thread>
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<void(AVFrame *frame)> cb_desktop_data;
typedef std::function<void(int)> cb_desktop_error;
typedef std::function<void(AVFrame *frame)> cb_desktop_data;
typedef std::function<void(int)> cb_desktop_error;
class record_desktop
{
class record_desktop {
public:
record_desktop();
virtual ~record_desktop();
virtual int init(
const RECORD_DESKTOP_RECT &rect,
const int fps
) = 0;
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 const AVRational &get_time_base() { return _time_base; }
inline int64_t get_start_time() { return _start_time; }
@@ -38,15 +85,13 @@ namespace am {
public:
inline bool is_recording() { return _running; }
inline const std::string & get_device_name() { return _device_name; }
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) {
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 RECORD_DESKTOP_RECT &get_rect() { return _rect; }
inline const int get_frame_rate() { return _fps; }
@@ -73,8 +118,7 @@ namespace am {
AVRational _time_base;
int64_t _start_time;
AVPixelFormat _pixel_fmt;
};
}
};
} // namespace am
#endif

View File

@@ -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

View File

@@ -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,8 +131,7 @@ 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;
}

View File

@@ -1,39 +0,0 @@
#include "system_error.h"
#include <Windows.h>
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

View File

@@ -1,12 +0,0 @@
#pragma once
#include <string>
namespace am {
class system_error {
public:
static const std::string& error2str(unsigned long error);
};
}

View File

@@ -1,66 +0,0 @@
#include "utils_string.h"
#include <Windows.h>
#ifdef WIN32
#include <Windows.h>
#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

View File

@@ -1,23 +0,0 @@
#pragma once
#include <string>
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);
};
}