mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
[AFV] Ref T730, use CoInitializeEx on windows for threaded CAfvClient
This commit is contained in:
@@ -674,9 +674,37 @@ namespace BlackCore
|
|||||||
|
|
||||||
void CAfvClient::initialize()
|
void CAfvClient::initialize()
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (!m_winCoInitialized)
|
||||||
|
{
|
||||||
|
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||||
|
|
||||||
|
// RPC_E_CHANGED_MODE: CoInitializeEx was already called by someone else in this thread with a different mode.
|
||||||
|
if (hr == RPC_E_CHANGED_MODE)
|
||||||
|
{
|
||||||
|
CLogMessage(this).debug(u"CoInitializeEx was already called with a different mode. Trying again.");
|
||||||
|
hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// S_OK: The COM library was initialized successfully on this thread.
|
||||||
|
// S_FALSE: The COM library is already initialized on this thread. Reference count was incremented. This is not an error.
|
||||||
|
if (hr == S_OK || hr == S_FALSE) { m_winCoInitialized = true; }
|
||||||
|
}
|
||||||
|
#endif
|
||||||
CLogMessage(this).info(u"Initialize AFV client in thread: %1") << CThreadUtils::threadInfo(this->thread());
|
CLogMessage(this).info(u"Initialize AFV client in thread: %1") << CThreadUtils::threadInfo(this->thread());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAfvClient::cleanup()
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (m_winCoInitialized)
|
||||||
|
{
|
||||||
|
CoUninitialize();
|
||||||
|
m_winCoInitialized = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void CAfvClient::onPositionUpdateTimer()
|
void CAfvClient::onPositionUpdateTimer()
|
||||||
{
|
{
|
||||||
if (hasContext())
|
if (hasContext())
|
||||||
|
|||||||
@@ -244,6 +244,9 @@ namespace BlackCore
|
|||||||
//! \copydoc BlackMisc::CContinuousWorker::initialize
|
//! \copydoc BlackMisc::CContinuousWorker::initialize
|
||||||
virtual void initialize() override;
|
virtual void initialize() override;
|
||||||
|
|
||||||
|
//! \copydoc BlackMisc::CContinuousWorker::cleanup
|
||||||
|
virtual void cleanup() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void opusDataAvailable(const Audio::OpusDataAvailableArgs &args);
|
void opusDataAvailable(const Audio::OpusDataAvailableArgs &args);
|
||||||
void audioOutDataAvailable(const AudioRxOnTransceiversDto &dto);
|
void audioOutDataAvailable(const AudioRxOnTransceiversDto &dto);
|
||||||
@@ -292,6 +295,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
std::atomic_bool m_isStarted { false };
|
std::atomic_bool m_isStarted { false };
|
||||||
std::atomic_bool m_loopbackOn { false };
|
std::atomic_bool m_loopbackOn { false };
|
||||||
|
std::atomic_bool m_winCoInitialized { false }; //!< Windows only CoInitializeEx
|
||||||
QDateTime m_startDateTimeUtc;
|
QDateTime m_startDateTimeUtc;
|
||||||
|
|
||||||
double m_inputVolumeDb;
|
double m_inputVolumeDb;
|
||||||
|
|||||||
Reference in New Issue
Block a user