Skip to content

Commit

Permalink
Remove 'friend' from 'read_wavein' callback function (gnuradio#6971)
Browse files Browse the repository at this point in the history
Resolves build issue in MSYS2 MinGW64 environment

Signed-off-by: Ruslan Migirov <[email protected]>
  • Loading branch information
cozycactus authored Nov 28, 2023
1 parent d7f8872 commit 9b22fd3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
21 changes: 13 additions & 8 deletions gr-audio/lib/windows/windows_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<windows_source*>(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<LPWAVEHDR>(dwParam1); // The new audio data

{
std::lock_guard<std::mutex> 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<std::mutex> 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 */
20 changes: 14 additions & 6 deletions gr-audio/lib/windows/windows_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mmsystem.h>
#include <windows.h>
Expand Down Expand Up @@ -51,11 +55,11 @@ class windows_source : public source
UINT find_device(std::string szDeviceName);
std::queue<LPWAVEHDR> 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 = "");
Expand All @@ -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<LPWAVEHDR>& 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 */
Expand Down

0 comments on commit 9b22fd3

Please sign in to comment.