update for linux.

This commit is contained in:
amass 2024-10-01 23:01:52 +08:00
parent 1ce4afdc25
commit 2d78ddbd04
3 changed files with 26 additions and 25 deletions

View File

@ -32,7 +32,7 @@ set(OPENSSL_INCLUDE_DIR ${OpenSSL_ROOT}/include)
set(OpenSSL_LIBRARY_DIRS ${OpenSSL_ROOT}/lib)
set(OpenSSL_LIBRARIES libssl libcrypto)
set(FFmpeg_ROOT ${Libraries_ROOT}/ffmpeg-7.0.1-full_build-shared)
set(FFmpeg_ROOT ${Libraries_ROOT}/ffmpeg-7.0.2-full_build-shared)
set(FFmpeg_INCLUDE_DIR ${FFmpeg_ROOT}/include)
set(FFmpeg_LIB_DIR ${FFmpeg_ROOT}/lib)

View File

@ -6,6 +6,13 @@
#include <mfapi.h>
#include <mfcaptureengine.h>
struct DeviceDiscovery::Device {
Device(IMFMediaSource *source);
~Device();
IMFMediaSource *source = nullptr;
IMFSourceReader *reader = nullptr;
};
template <class T>
void SafeRelease(T **ppT) {
if (*ppT) {
@ -17,6 +24,21 @@ void SafeRelease(T **ppT) {
DeviceDiscovery::DeviceDiscovery() {
}
static std::string deviceName(IMFActivate *device) {
std::string ret;
WCHAR *friendlyName = nullptr;
uint32_t nameLength = 0;
auto result = device->GetAllocatedString(MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, &friendlyName, &nameLength);
if (SUCCEEDED(result)) {
ret = Amass::StringUtility::wstringToString(std::wstring(friendlyName, nameLength));
}
if (friendlyName != nullptr) {
CoTaskMemFree(friendlyName);
}
return ret;
}
std::shared_ptr<DeviceDiscovery::Device> DeviceDiscovery::find(const std::string &deviceName, std::error_code &error) {
std::shared_ptr<Device> ret;
@ -45,7 +67,7 @@ std::shared_ptr<DeviceDiscovery::Device> DeviceDiscovery::find(const std::string
int index = -1;
for (int i = 0; i < count; i++) {
auto name = this->deviceName(devices[i]);
auto name = ::deviceName(devices[i]);
LOG(info) << "device[" << i << "]: " << name;
if (name == deviceName) {
index = i;
@ -63,21 +85,6 @@ std::shared_ptr<DeviceDiscovery::Device> DeviceDiscovery::find(const std::string
return ret;
}
std::string DeviceDiscovery::deviceName(IMFActivate *device) {
std::string ret;
WCHAR *friendlyName = nullptr;
uint32_t nameLength = 0;
auto result = device->GetAllocatedString(MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, &friendlyName, &nameLength);
if (SUCCEEDED(result)) {
ret = Amass::StringUtility::wstringToString(std::wstring(friendlyName, nameLength));
}
if (friendlyName != nullptr) {
CoTaskMemFree(friendlyName);
}
return ret;
}
void DeviceDiscovery::enterOtaMode(const std::shared_ptr<Device> &device, std::error_code &error) {
auto resolutions = deviceResolutions(device);
LOG(info) << "device resolutions:";
@ -144,7 +151,7 @@ std::vector<std::string> DeviceDiscovery::devices() {
}
for (int i = 0; i < count; i++) {
auto name = this->deviceName(devices[i]);
auto name = ::deviceName(devices[i]);
ret.push_back(name);
}
return ret;

View File

@ -12,12 +12,7 @@ class DeviceDiscovery {
constexpr static int32_t OtaSpecificWidth = 96;
public:
struct Device {
Device(IMFMediaSource *source);
~Device();
IMFMediaSource *source = nullptr;
IMFSourceReader *reader = nullptr;
};
struct Device;
using Resolution = std::pair<int32_t, int32_t>;
using Resolutions = std::vector<Resolution>;
@ -27,7 +22,6 @@ public:
std::vector<std::string> devices();
protected:
std::string deviceName(IMFActivate *device);
Resolutions deviceResolutions(const std::shared_ptr<Device> &source);
};
#endif // __DEVICEDISCOVERY_H__