add namespace
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
enum AudioDeviceType
|
||||
{
|
||||
Render,
|
||||
Capture
|
||||
};
|
||||
namespace WinDevice {
|
||||
enum AudioDeviceType
|
||||
{
|
||||
Render,
|
||||
Capture
|
||||
};
|
||||
}
|
||||
|
@@ -2,16 +2,16 @@
|
||||
#include <iostream>
|
||||
|
||||
|
||||
AudioManager::AudioManager()
|
||||
WinDevice::AudioManager::AudioManager()
|
||||
{
|
||||
// 创建设备枚举器
|
||||
}
|
||||
|
||||
AudioManager::~AudioManager()
|
||||
WinDevice::AudioManager::~AudioManager()
|
||||
{
|
||||
}
|
||||
|
||||
HRESULT AudioManager::Init()
|
||||
HRESULT WinDevice::AudioManager::Init()
|
||||
{
|
||||
HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), reinterpret_cast<void**>(&pEnumerator));
|
||||
if (FAILED(hr))
|
||||
@@ -31,7 +31,7 @@ HRESULT AudioManager::Init()
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT AudioManager::Uninit()
|
||||
HRESULT WinDevice::AudioManager::Uninit()
|
||||
{
|
||||
pEnumerator = nullptr;
|
||||
pCaptureCollection = nullptr;
|
||||
@@ -41,7 +41,7 @@ HRESULT AudioManager::Uninit()
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IMMDeviceCollection* AudioManager::GetDeviceList(EDataFlow flow)
|
||||
IMMDeviceCollection* WinDevice::AudioManager::GetDeviceList(EDataFlow flow)
|
||||
{
|
||||
if (flow == eCapture)
|
||||
{
|
||||
@@ -66,7 +66,7 @@ IMMDeviceCollection* AudioManager::GetDeviceList(EDataFlow flow)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IMMDevice* AudioManager::GetDefaultDevice(EDataFlow flow)
|
||||
IMMDevice* WinDevice::AudioManager::GetDefaultDevice(EDataFlow flow)
|
||||
{
|
||||
if (flow == eCapture)
|
||||
{
|
||||
@@ -79,7 +79,7 @@ IMMDevice* AudioManager::GetDefaultDevice(EDataFlow flow)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HRESULT AudioManager::_UpdateDeviceList(EDataFlow flow)
|
||||
HRESULT WinDevice::AudioManager::_UpdateDeviceList(EDataFlow flow)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
if (flow == eCapture)
|
||||
@@ -93,7 +93,7 @@ HRESULT AudioManager::_UpdateDeviceList(EDataFlow flow)
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT AudioManager::_UpdateDefaultDevice(EDataFlow flow)
|
||||
HRESULT WinDevice::AudioManager::_UpdateDefaultDevice(EDataFlow flow)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
if (flow == eCapture)
|
||||
|
@@ -2,25 +2,27 @@
|
||||
|
||||
#include <Mmdeviceapi.h>
|
||||
|
||||
class AudioManager
|
||||
{
|
||||
public:
|
||||
AudioManager();
|
||||
~AudioManager();
|
||||
namespace WinDevice {
|
||||
class AudioManager
|
||||
{
|
||||
public:
|
||||
AudioManager();
|
||||
~AudioManager();
|
||||
|
||||
HRESULT Init();
|
||||
HRESULT Uninit();
|
||||
HRESULT Init();
|
||||
HRESULT Uninit();
|
||||
|
||||
IMMDeviceCollection* GetDeviceList(EDataFlow flow);
|
||||
IMMDevice* GetDefaultDevice(EDataFlow flow);
|
||||
IMMDeviceCollection* GetDeviceList(EDataFlow flow);
|
||||
IMMDevice* GetDefaultDevice(EDataFlow flow);
|
||||
|
||||
private:
|
||||
IMMDeviceEnumerator* pEnumerator = NULL;
|
||||
IMMDeviceCollection* pRenderCollection = NULL;
|
||||
IMMDeviceCollection* pCaptureCollection = NULL;
|
||||
IMMDevice* pDefaultRenderEndpoint = NULL;
|
||||
IMMDevice* pDefaultCaptureEndpoint = NULL;
|
||||
private:
|
||||
IMMDeviceEnumerator* pEnumerator = NULL;
|
||||
IMMDeviceCollection* pRenderCollection = NULL;
|
||||
IMMDeviceCollection* pCaptureCollection = NULL;
|
||||
IMMDevice* pDefaultRenderEndpoint = NULL;
|
||||
IMMDevice* pDefaultCaptureEndpoint = NULL;
|
||||
|
||||
HRESULT _UpdateDeviceList(EDataFlow flow);
|
||||
HRESULT _UpdateDefaultDevice(EDataFlow flow);
|
||||
};
|
||||
HRESULT _UpdateDeviceList(EDataFlow flow);
|
||||
HRESULT _UpdateDefaultDevice(EDataFlow flow);
|
||||
};
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
std::string CmdUtil::ExecuteCommand(const std::string& command)
|
||||
std::string WinDevice::CmdUtil::ExecuteCommand(const std::string& command)
|
||||
{
|
||||
spdlog::info("ExecuteCommand command:{0}", command);
|
||||
auto cmd_result = std::string();
|
||||
|
@@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class CmdUtil
|
||||
{
|
||||
public:
|
||||
static std::string ExecuteCommand(const std::string& command);
|
||||
};
|
||||
|
||||
namespace WinDevice {
|
||||
class CmdUtil
|
||||
{
|
||||
public:
|
||||
static std::string ExecuteCommand(const std::string& command);
|
||||
};
|
||||
}
|
@@ -3,18 +3,18 @@
|
||||
#include "spdlog/sinks/stdout_sinks.h"
|
||||
|
||||
|
||||
void Log::Init(LogLevel level, std::string fileName)
|
||||
void WinDevice::Log::Init(LogLevel level, std::string fileName)
|
||||
{
|
||||
spdlog::stdout_logger_mt("console");
|
||||
spdlog::set_level(static_cast<spdlog::level::level_enum>(level)); // 设置日志级别为 debug
|
||||
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
|
||||
}
|
||||
|
||||
void Log::Info(std::string format, std::string args...)
|
||||
void WinDevice::Log::Info(std::string format, std::string args...)
|
||||
{
|
||||
}
|
||||
|
||||
void Log::WInfo(std::wstring format, std::wstring args...)
|
||||
void WinDevice::Log::WInfo(std::wstring format, std::wstring args...)
|
||||
{
|
||||
|
||||
}
|
||||
|
@@ -4,17 +4,20 @@
|
||||
#define LOG_FUNC_START() spdlog::info("=====> {0} start <=====", __FUNCTION__)
|
||||
#define LOG_FUNC_END() spdlog::info("=====> {0} end <=====", __FUNCTION__)
|
||||
|
||||
enum LogLevel : int
|
||||
{
|
||||
Debug = spdlog::level::debug,
|
||||
Info = spdlog::level::info,
|
||||
};
|
||||
namespace WinDevice {
|
||||
enum LogLevel : int
|
||||
{
|
||||
Debug = spdlog::level::debug,
|
||||
Info = spdlog::level::info,
|
||||
};
|
||||
|
||||
class Log
|
||||
{
|
||||
public:
|
||||
static void Init(LogLevel level, std::string fileName);
|
||||
class Log
|
||||
{
|
||||
public:
|
||||
static void Init(LogLevel level, std::string fileName);
|
||||
|
||||
static void Info(std::string format, std::string args...);
|
||||
static void WInfo(std::wstring format, std::wstring args...);
|
||||
};
|
||||
}
|
||||
|
||||
static void Info(std::string format, std::string args...);
|
||||
static void WInfo(std::wstring format, std::wstring args...);
|
||||
};
|
||||
|
@@ -2,24 +2,21 @@
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
|
||||
namespace WinDevcie {
|
||||
namespace WinDevice {
|
||||
|
||||
namespace Utils {
|
||||
template<typename To, typename From>
|
||||
To Convert(const From& input) {
|
||||
std::wstring_convert<std::codecvt_utf8<typename From::value_type>, typename From::value_type> converter;
|
||||
return converter.to_bytes(input);
|
||||
}
|
||||
|
||||
template<typename To, typename From>
|
||||
To Convert(const From& input) {
|
||||
std::wstring_convert<std::codecvt_utf8<typename From::value_type>, typename From::value_type> converter;
|
||||
return converter.to_bytes(input);
|
||||
}
|
||||
std::string Wstring2String(const std::wstring& input) {
|
||||
return Convert<std::string>(input);
|
||||
}
|
||||
|
||||
std::string Wstring2String(const std::wstring& input) {
|
||||
return Convert<std::string>(input);
|
||||
}
|
||||
|
||||
std::string Wchar2String(const WCHAR* input) {
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
return converter.to_bytes(input);
|
||||
}
|
||||
std::string Wchar2String(const WCHAR* input) {
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
return converter.to_bytes(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,9 +1,8 @@
|
||||
#include "TimeUtil.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
|
||||
template <typename Func>
|
||||
void TimeUtil<Func>::CalExecuteTime(Func func)
|
||||
void WinDevice::TimeUtil<Func>::CalExecuteTime(Func func)
|
||||
{
|
||||
// 测量函数调用的耗时
|
||||
const auto start = std::chrono::high_resolution_clock::now();
|
||||
@@ -11,4 +10,4 @@ void TimeUtil<Func>::CalExecuteTime(Func func)
|
||||
const auto end = std::chrono::high_resolution_clock::now();
|
||||
const auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
spdlog::info("Function call duration: {0} ms", duration.count());
|
||||
}
|
||||
}
|
@@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
template <typename Func>
|
||||
|
||||
class TimeUtil
|
||||
{
|
||||
public:
|
||||
static void CalExecuteTime(Func func);
|
||||
};
|
||||
namespace WinDevice {
|
||||
template <typename Func>
|
||||
class TimeUtil
|
||||
{
|
||||
public:
|
||||
static void CalExecuteTime(Func func);
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -4,24 +4,24 @@
|
||||
#include "../Utils/Log.h"
|
||||
#include <dxgi.h>
|
||||
|
||||
ScreenManager::ScreenManager()
|
||||
WinDevice::ScreenManager::ScreenManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ScreenManager::~ScreenManager()
|
||||
WinDevice::ScreenManager::~ScreenManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ScreenManager::UpdateDisplayInfo()
|
||||
void WinDevice::ScreenManager::UpdateDisplayInfo()
|
||||
{
|
||||
_UpdateDisplayDeviceList();
|
||||
_UpdateMonitorInfoMap();
|
||||
_UpdateDisplayAdapterList();
|
||||
}
|
||||
|
||||
void ScreenManager::_UpdateDisplayDeviceList()
|
||||
void WinDevice::ScreenManager::_UpdateDisplayDeviceList()
|
||||
{
|
||||
spdlog::info("=====GetInfoByEnumDisplayDevices start=====");
|
||||
DISPLAY_DEVICE displayDevice;
|
||||
@@ -39,7 +39,7 @@ void ScreenManager::_UpdateDisplayDeviceList()
|
||||
spdlog::info("=====GetInfoByEnumDisplayDevices end=====");
|
||||
}
|
||||
|
||||
void ScreenManager::_UpdateDisplayAdapterList()
|
||||
void WinDevice::ScreenManager::_UpdateDisplayAdapterList()
|
||||
{
|
||||
LOG_FUNC_START();
|
||||
HRESULT hr = S_OK;
|
||||
@@ -56,8 +56,8 @@ void ScreenManager::_UpdateDisplayAdapterList()
|
||||
DXGI_ADAPTER_DESC adapterDesc;
|
||||
pAdapter->GetDesc(&adapterDesc);
|
||||
spdlog::info("Adapter Index:{0}, Description:{1}, DeviceId:{2}, VendorId:{3}, SubSysId:{4}, Revision:{5}, AdapterLuid(H-L):{6}-{7} ",
|
||||
adapterIndex, WinDevcie::Utils::Wchar2String(adapterDesc.Description), adapterDesc.DeviceId, adapterDesc.VendorId, adapterDesc.SubSysId,
|
||||
adapterDesc.Revision, adapterDesc.AdapterLuid.HighPart, adapterDesc.AdapterLuid.LowPart);
|
||||
adapterIndex, WinDevice::Wchar2String(adapterDesc.Description), adapterDesc.DeviceId, adapterDesc.VendorId, adapterDesc.SubSysId,
|
||||
adapterDesc.Revision, adapterDesc.AdapterLuid.HighPart, adapterDesc.AdapterLuid.LowPart);
|
||||
|
||||
// print adapter output info
|
||||
IDXGIOutput* pOutput;
|
||||
@@ -72,7 +72,7 @@ void ScreenManager::_UpdateDisplayAdapterList()
|
||||
{
|
||||
// 输出友好名称
|
||||
spdlog::info("Adapter Output Index:{0}, DeviceName:{1}, szDevice:{2}, right:{3}, bottom:{4}",
|
||||
j, WinDevcie::Utils::Wchar2String(outputDesc.DeviceName), monitorInfo.szDevice, monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom);
|
||||
j, WinDevice::Wchar2String(outputDesc.DeviceName), monitorInfo.szDevice, monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ void ScreenManager::_UpdateDisplayAdapterList()
|
||||
LOG_FUNC_END();
|
||||
}
|
||||
|
||||
BOOL ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
|
||||
BOOL WinDevice::ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
|
||||
{
|
||||
MONITORINFOEX monitorInfo;
|
||||
monitorInfo.cbSize = sizeof(MONITORINFOEX);
|
||||
@@ -110,7 +110,7 @@ BOOL ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
|
||||
if (DisplayConfigGetDeviceInfo(&targetDeviceName.header) == ERROR_SUCCESS)
|
||||
{
|
||||
spdlog::info("_UpdateMonitorInfoMap, monitorDevicePath:{0}, monitorFriendlyDeviceName:{1}",
|
||||
WinDevcie::Utils::Wchar2String(targetDeviceName.monitorDevicePath), WinDevcie::Utils::Wchar2String(targetDeviceName.monitorFriendlyDeviceName));
|
||||
WinDevice::Wchar2String(targetDeviceName.monitorDevicePath), WinDevice::Wchar2String(targetDeviceName.monitorFriendlyDeviceName));
|
||||
|
||||
// 获取指定 HMONITOR 的分辨率信息
|
||||
DEVMODE dm;
|
||||
@@ -133,12 +133,12 @@ BOOL ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CALLBACK ScreenManager::EnumMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
|
||||
BOOL CALLBACK WinDevice::ScreenManager::EnumMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
|
||||
{
|
||||
return ((ScreenManager*)dwData)->_EnumMonitorProc(hMonitor);
|
||||
}
|
||||
|
||||
void ScreenManager::_UpdateMonitorInfoMap()
|
||||
void WinDevice::ScreenManager::_UpdateMonitorInfoMap()
|
||||
{
|
||||
spdlog::info("=====GetInfoByEnumDisplayMonitors start=====");
|
||||
// 枚举显示器
|
||||
|
@@ -3,21 +3,23 @@
|
||||
#include <map>
|
||||
#include <dxgi.h>
|
||||
|
||||
class ScreenManager
|
||||
{
|
||||
public:
|
||||
ScreenManager();
|
||||
~ScreenManager();
|
||||
void UpdateDisplayInfo();
|
||||
namespace WinDevice {
|
||||
class ScreenManager
|
||||
{
|
||||
public:
|
||||
ScreenManager();
|
||||
~ScreenManager();
|
||||
void UpdateDisplayInfo();
|
||||
|
||||
std::vector<DISPLAY_DEVICE> _displayDeviceList;
|
||||
std::map<HMONITOR, MONITORINFOEX> _hMonitorInfoMap;
|
||||
std::vector<IDXGIAdapter*> _displayAdapterList;
|
||||
std::vector<DISPLAY_DEVICE> _displayDeviceList;
|
||||
std::map<HMONITOR, MONITORINFOEX> _hMonitorInfoMap;
|
||||
std::vector<IDXGIAdapter*> _displayAdapterList;
|
||||
|
||||
private:
|
||||
void _UpdateDisplayDeviceList();
|
||||
void _UpdateMonitorInfoMap();
|
||||
void _UpdateDisplayAdapterList();
|
||||
static BOOL CALLBACK EnumMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData);
|
||||
BOOL _EnumMonitorProc(HMONITOR hMonitor);
|
||||
};
|
||||
private:
|
||||
void _UpdateDisplayDeviceList();
|
||||
void _UpdateMonitorInfoMap();
|
||||
void _UpdateDisplayAdapterList();
|
||||
static BOOL CALLBACK EnumMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData);
|
||||
BOOL _EnumMonitorProc(HMONITOR hMonitor);
|
||||
};
|
||||
}
|
||||
|
@@ -4,9 +4,9 @@
|
||||
#include <iostream>
|
||||
#include "Video/ScreenManager.h"
|
||||
int main() {
|
||||
ScreenManager screenManager;
|
||||
WinDevice::ScreenManager screenManager;
|
||||
screenManager.UpdateDisplayInfo();
|
||||
std::cout << "Press Enter to exit..." << std::endl; // 输出提示信息
|
||||
std::cin.get(); // 等待用户输入
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user