From 9b22fd38b8259f33928c7b3ff7868e0bc4b60d1e Mon Sep 17 00:00:00 2001 From: Ruslan Migirov Date: Tue, 28 Nov 2023 13:25:36 +0200 Subject: [PATCH] Remove 'friend' from 'read_wavein' callback function (#6971) Resolves build issue in MSYS2 MinGW64 environment Signed-off-by: Ruslan Migirov --- gr-audio/lib/windows/windows_source.cc | 21 +++++++++++++-------- gr-audio/lib/windows/windows_source.h | 20 ++++++++++++++------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/gr-audio/lib/windows/windows_source.cc b/gr-audio/lib/windows/windows_source.cc index ad494417eb5..21999fb1177 100644 --- a/gr-audio/lib/windows/windows_source.cc +++ b/gr-audio/lib/windows/windows_source.cc @@ -321,25 +321,30 @@ int windows_source::open_wavein_device(void) return 0; } -static void CALLBACK read_wavein( +void CALLBACK windows_source::read_wavein( HWAVEIN hwi, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) { - // Ignore WIM_OPEN and WIM_CLOSE messages if (uMsg == WIM_DATA) { - if (!dwInstance) { + windows_source* source = reinterpret_cast(dwInstance); + if (!source) { gr::logger_ptr logger; logger->error("callback function missing buffer queue: {:s}", strerror(errno)); + return; } - LPWAVEHDR lp_wave_hdr = (LPWAVEHDR)dwParam1; // The new audio data - windows_source* source = (windows_source*)dwInstance; + + LPWAVEHDR lp_wave_hdr = + reinterpret_cast(dwParam1); // The new audio data + { - std::lock_guard lock(source->buffer_queue_mutex); - if (source->buffer_queue.size() < MAX_QUEUE_SIZE) { - source->buffer_queue.push(lp_wave_hdr); // Add the buffer to the queue + std::lock_guard lock(source->get_buffer_queue_mutex()); + auto& buffer_queue = source->get_buffer_queue(); + if (buffer_queue.size() < MAX_QUEUE_SIZE) { + buffer_queue.push(lp_wave_hdr); // Add the buffer to the queue } } } } + } /* namespace audio */ } /* namespace gr */ diff --git a/gr-audio/lib/windows/windows_source.h b/gr-audio/lib/windows/windows_source.h index fa206f1b5e4..444c69ea6d1 100644 --- a/gr-audio/lib/windows/windows_source.h +++ b/gr-audio/lib/windows/windows_source.h @@ -11,8 +11,12 @@ #ifndef INCLUDED_AUDIO_WINDOWS_SOURCE_H #define INCLUDED_AUDIO_WINDOWS_SOURCE_H +#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN +#endif +#ifndef NOMINMAX #define NOMINMAX // stops windef.h defining max/min under cygwin +#endif #include #include @@ -51,11 +55,11 @@ class windows_source : public source UINT find_device(std::string szDeviceName); std::queue buffer_queue; std::mutex buffer_queue_mutex; - friend static void CALLBACK read_wavein(HWAVEIN hwi, - UINT uMsg, - DWORD_PTR dwInstance, - DWORD_PTR dwParam1, - DWORD_PTR dwParam2); + static void CALLBACK read_wavein(HWAVEIN hwi, + UINT uMsg, + DWORD_PTR dwInstance, + DWORD_PTR dwParam1, + DWORD_PTR dwParam2); public: windows_source(int sampling_freq, const std::string device_name = ""); @@ -64,9 +68,13 @@ class windows_source : public source int work(int noutput_items, gr_vector_const_void_star& input_items, gr_vector_void_star& output_items); + + std::mutex& get_buffer_queue_mutex() { return buffer_queue_mutex; } + + std::queue& get_buffer_queue() { return buffer_queue; } }; -static void CALLBACK read_wavein( +void CALLBACK read_wavein( HWAVEIN hwi, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2); } /* namespace audio */