diff options
author | gnieboer <gnieboer@corpcomm.net> | 2016-10-12 19:27:56 -0400 |
---|---|---|
committer | gnieboer <gnieboer@corpcomm.net> | 2016-10-12 19:38:24 -0400 |
commit | 4edbf58d2462f1102216a3a027cdfacb46c7108b (patch) | |
tree | 45c26acdfbe2c8846cc8047e3717a989a30f5889 /gr-audio/lib | |
parent | ce354379fee28872ea103eafa9164e6fc1ea54a1 (diff) |
gr-audio: implemented blocking in windows audio sink
Diffstat (limited to 'gr-audio/lib')
-rw-r--r-- | gr-audio/lib/windows/windows_sink.cc | 22 | ||||
-rw-r--r-- | gr-audio/lib/windows/windows_sink.h | 14 |
2 files changed, 24 insertions, 12 deletions
diff --git a/gr-audio/lib/windows/windows_sink.cc b/gr-audio/lib/windows/windows_sink.cc index 4ec798b0ba..52456dbdc4 100644 --- a/gr-audio/lib/windows/windows_sink.cc +++ b/gr-audio/lib/windows/windows_sink.cc @@ -46,10 +46,10 @@ namespace gr { sink::sptr windows_sink_fcn(int sampling_rate, const std::string &device_name, - bool) + bool ok_to_block) { return sink::sptr - (new windows_sink(sampling_rate, device_name)); + (new windows_sink(sampling_rate, device_name, ok_to_block)); } static const double CHUNK_TIME = prefs::singleton()->get_double("audio_windows", "period_time", 0.1); // 100 ms (below 3ms distortion will likely occur regardless of number of buffers, will likely be a higher limit on slower machines) @@ -63,13 +63,13 @@ namespace gr { return (default_device == "default" ? "WAVE_MAPPER" : default_device); } - windows_sink::windows_sink(int sampling_freq, const std::string device_name) + windows_sink::windows_sink(int sampling_freq, const std::string device_name, bool ok_to_block) : sync_block("audio_windows_sink", io_signature::make(1, 2, sizeof(float)), io_signature::make(0, 0, 0)), d_sampling_freq(sampling_freq), d_device_name(device_name.empty() ? default_device_name() : device_name), - d_fd(-1), d_buffers(0), d_chunk_size(0) + d_fd(-1), d_buffers(0), d_chunk_size(0), d_ok_to_block(ok_to_block) { /* Initialize the WAVEFORMATEX for 16-bit, 44KHz, stereo */ wave_format.wFormatTag = WAVE_FORMAT_PCM; @@ -154,10 +154,20 @@ namespace gr { } } if (!chosen_header) { - WaitForSingleObject(d_wave_write_event, 100); - printf("aO"); + if (!d_ok_to_block) + { + // drop the input data, print warning, and return control. + printf("aO"); + return noutput_items; + } + else { + WaitForSingleObject(d_wave_write_event, 100); + } } if (c++ > 10) { + // After waiting for 1 second, then something else is seriously wrong so let's + // just fail and give some debugging information about the status + // of the buffers. for (int i = 0; i < nPeriods; i++) { printf("%d: %d\n", i, d_buffers[i]->dwFlags); } diff --git a/gr-audio/lib/windows/windows_sink.h b/gr-audio/lib/windows/windows_sink.h index 2bfdbd318d..de905c68fd 100644 --- a/gr-audio/lib/windows/windows_sink.h +++ b/gr-audio/lib/windows/windows_sink.h @@ -49,22 +49,24 @@ namespace gr { int d_fd; LPWAVEHDR *d_buffers; DWORD d_chunk_size; - DWORD d_buffer_size; + DWORD d_buffer_size; + bool d_ok_to_block; HWAVEOUT d_h_waveout; HANDLE d_wave_write_event; - WAVEFORMATEX wave_format; + WAVEFORMATEX wave_format; protected: int string_to_int(const std::string & s); int open_waveout_device(void); int write_waveout(LPWAVEHDR lp_wave_hdr); - MMRESULT is_format_supported(LPWAVEFORMATEX pwfx, UINT uDeviceID); - bool is_number(const std::string& s); - UINT find_device(std::string szDeviceName); + MMRESULT is_format_supported(LPWAVEFORMATEX pwfx, UINT uDeviceID); + bool is_number(const std::string& s); + UINT find_device(std::string szDeviceName); public: windows_sink(int sampling_freq, - const std::string device_name = ""); + const std::string device_name, + bool ok_to_block); ~windows_sink(); int work(int noutput_items, |