Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WMF update #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 87 additions & 23 deletions mediafoundation/PureThermal/Device.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "pch.h"
#include "Device.h"


template <class T>
void SafeRelease(T** object)
{
Expand All @@ -14,6 +12,9 @@ void SafeRelease(T** object)


Device::Device()
: flir_status(new LEP_STATUS_T)
, _selectedDeviceID("N/A")
, flir_uptime_ms(0)
{
if (!SelectDevice())
{
Expand Down Expand Up @@ -48,14 +49,30 @@ Device::~Device()
}


/*
Check the FLIR LEPTON� Software Interface Description Document (IDD) for more information:
https://cdn.sparkfun.com/assets/0/6/d/2/e/16465-FLIRLepton-SoftwareIDD.pdf
*/
void Device::PrintDeviceInfo()
{
// Version
LepOemSwVersion version{};
char flir_pn[32];
char flir_sn[8];
SetGetExtensionUnit(_xuLepOem, 9, KSPROPERTY_TYPE_GET, &version, sizeof(version));
SetGetExtensionUnit(_xuLepOem, 8, KSPROPERTY_TYPE_GET, flir_pn, sizeof(flir_pn));
SetGetExtensionUnit(_xuLepSys, 3, KSPROPERTY_TYPE_GET, flir_sn, sizeof(flir_sn));

// Part Number
LEP_OEM_PART_NUMBER_T_PTR flir_pn = new LEP_OEM_PART_NUMBER_T;// aka char flir_pn[32];
SetGetExtensionUnit(_xuLepOem, 8, KSPROPERTY_TYPE_GET, flir_pn, sizeof(flir_pn->value));

// Serial Number
LEP_UINT64 flir_sn; // aka char flir_sn[8];
SetGetExtensionUnit(_xuLepSys, 3, KSPROPERTY_TYPE_GET, &flir_sn, sizeof(flir_sn));
//since we have a 64 bit value we need to check every byte for it self
char flir_sn_char[8];
memcpy(flir_sn_char, &flir_sn, 8);

//Uptime
SetGetExtensionUnit(_xuLepSys, 4, KSPROPERTY_TYPE_GET, &flir_uptime_ms, sizeof(flir_uptime_ms));

std::cout
<< "Version gpp: "
<< static_cast<unsigned int>(version.gpp_major) << "."
Expand All @@ -65,17 +82,20 @@ void Device::PrintDeviceInfo()
<< static_cast<unsigned int>(version.dsp_major) << "."
<< static_cast<unsigned int>(version.dsp_minor) << "."
<< static_cast<unsigned int>(version.dsp_build) << "\n"
<< "FLIR part#: " << flir_pn << "\n"
<< "FLIR part#: " << std::string(flir_pn->value) << "\n"
<< "FLIR serial#: ";
for (size_t i = 0; i < sizeof(flir_sn); ++i)
for (size_t i = 0; i < sizeof(flir_sn_char); ++i)
{
if (i != 0)
{
std::cout << "-";
}
std::cout << static_cast<unsigned int>(flir_sn[i]);
std::cout << static_cast<unsigned int>(flir_sn_char[i]);
}
std::cout << "\n";

std::cout << "\nFLIR uptime: " << flir_uptime_ms * 0.001 << " seconds" << std::endl;

std::cout << "\nCam status: " << GetFLIRStatus() << std::endl;
}


Expand Down Expand Up @@ -161,25 +181,39 @@ bool Device::SelectDevice()
hr = MFEnumDeviceSources(pVideoConfig, &_availableVideoDevices, &_numberOfAvailableVideoDevices);
CheckResult(hr, "Device enumeration");

for (UINT32 i = 0; i < _numberOfAvailableVideoDevices; ++i)
{
UINT32 cchName;
WCHAR* szDevicePath;
hr = _availableVideoDevices[i]->GetAllocatedString(
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK,
&szDevicePath, &cchName);
auto sDevicePath = WCharToString(szDevicePath);
CoTaskMemFree(szDevicePath);
CheckResult(hr, "Get video device path");
if (sDevicePath.find("vid_1e4e&pid_0100") != std::string::npos)
if (_numberOfAvailableVideoDevices > 0) {
for (UINT32 i = 0; i < _numberOfAvailableVideoDevices; ++i)
{
_selectedDeviceIndex = i;
break;
UINT32 cchName;
WCHAR* szDevicePath;
hr = _availableVideoDevices[i]->GetAllocatedString(
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK,
&szDevicePath, &cchName);
auto sDevicePath = WCharToString(szDevicePath);
CoTaskMemFree(szDevicePath);
CheckResult(hr, "Get video device path");
std::istringstream f(sDevicePath);
std::vector<std::string> deviceIds;
std::string id;
while (std::getline(f, id, '&')) {
deviceIds.push_back(id);
}

if (sDevicePath.find("vid_1e4e&pid_0100") != std::string::npos)
{
std::cout << "ID for device " << i << ": " + deviceIds[3] << std::endl;

_selectedDeviceIndex = i;
_selectedDeviceID = deviceIds[3];
}
}
}else{
return false;
}

if (_selectedDeviceIndex != (std::numeric_limits<UINT32>::max)())
{
std::cout << std::endl << "Using PureThermal device with index " << _selectedDeviceIndex << " and ID: "<< _selectedDeviceID << std::endl << std::endl;
return true;
}
else
Expand Down Expand Up @@ -515,3 +549,33 @@ HRESULT Device::OnReadSample(HRESULT status, DWORD streamIndex, DWORD streamFlag

return hr;
}

std::string Device::GetFLIRStatus() {

SetGetExtensionUnit(_xuLepSys, 2, KSPROPERTY_TYPE_GET, flir_status, sizeof(flir_status));
std::string status = "N/A";
switch (flir_status->camStatus) {
case LEP_SYSTEM_READY:
status = "Ready";
break;
case LEP_SYSTEM_INITIALIZING:
status = "Initializing";
break;
case LEP_SYSTEM_IN_LOW_POWER_MODE:
status = "In low power mode";
break;
case LEP_SYSTEM_GOING_INTO_STANDBY:
status = "Going into standby";
break;
case LEP_SYSTEM_FLAT_FIELD_IN_PROCESS:
status = "Flat field in process";
break;
case LEP_SYSTEM_END_STATES:
status = "End states";
break;
default:
status = "N/A";
}

return status;
}
47 changes: 46 additions & 1 deletion mediafoundation/PureThermal/Device.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
#pragma once

#include "pch.h"
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <condition_variable>
#include <cstdint>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <mutex>
#include <sstream>
#include <vector>

#include <atlcomcli.h>
#include <mfapi.h>
#include <mferror.h>
#include <mfplay.h>
#include <mfreadwrite.h>
#include <mmsystem.h>
#include <ks.h>
#include <ksproxy.h>
#include <ksmedia.h>
#include <vidcap.h>
#include <shlwapi.h>

#include "LEPTON_Types.h"


class Device : public IMFSourceReaderCallback
Expand Down Expand Up @@ -34,6 +62,19 @@ class Device : public IMFSourceReaderCallback
STDMETHODIMP OnEvent(DWORD, IMFMediaEvent *);
STDMETHODIMP OnFlush(DWORD);

/*
Returns the camera status as a string. Status is based on FLIR LEP_SYSTEM_STATUS_STATES_E_TAG and can be:

LEP_SYSTEM_READY -> Ready
LEP_SYSTEM_INITIALIZING -> Initializing
LEP_SYSTEM_IN_LOW_POWER_MODE -> In low power mode
LEP_SYSTEM_GOING_INTO_STANDBY -> Going into standby
LEP_SYSTEM_FLAT_FIELD_IN_PROCESS -> Flat field in process

Default is "N/A"
*/
std::string GetFLIRStatus();

private:
using XuGuid = std::array<std::uint8_t, 16>;
using FourCC = std::array<std::uint8_t, 4>;
Expand Down Expand Up @@ -68,6 +109,7 @@ class Device : public IMFSourceReaderCallback
IMFActivate** _availableVideoDevices{ nullptr };
UINT32 _numberOfAvailableVideoDevices{ 0 };
UINT32 _selectedDeviceIndex{ (std::numeric_limits<UINT32>::max)() };
std::string _selectedDeviceID;

CComPtr<IMFPresentationDescriptor> _presentationDescriptor{ nullptr };
CComPtr<IMFStreamDescriptor> _streamDescriptor{ nullptr };
Expand All @@ -83,4 +125,7 @@ class Device : public IMFSourceReaderCallback
std::mutex _deviceMutex;
std::condition_variable _deviceCondition;
std::atomic<bool> _frameRequested{ false };

LEP_STATUS_T_PTR flir_status;
LEP_UINT32 flir_uptime_ms; //in Milliseconds
};
Loading