unixcw : init at 3.5.1

+716
+37
pkgs/applications/misc/unixcw/default.nix
··· 1 + {stdenv, fetchurl, libpulseaudio, alsaLib , pkgconfig, qt5}: 2 + stdenv.mkDerivation rec { 3 + name = "unixcw-${version}"; 4 + version = "3.5.1"; 5 + src = fetchurl { 6 + url = "mirror://sourceforge/unixcw/unixcw_${version}.orig.tar.gz"; 7 + sha256 ="5f3aacd8a26e16e6eff437c7ae1e9b389956fb137eeb3de24670ce05de479e7a"; 8 + }; 9 + patches = [ 10 + ./remove-use-of-dlopen.patch 11 + ]; 12 + buildInputs = [libpulseaudio alsaLib pkgconfig qt5.qtbase]; 13 + CFLAGS ="-lasound -lpulse-simple"; 14 + 15 + meta = with stdenv.lib; { 16 + description = "sound characters as Morse code on the soundcard or console speaker"; 17 + longDescription = '' 18 + unixcw is a project providing libcw library and a set of programs 19 + using the library: cw, cwgen, cwcp and xcwcp. 20 + The programs are intended for people who want to learn receiving 21 + and sending Morse code. 22 + unixcw is developed and tested primarily on GNU/Linux system. 23 + 24 + cw reads characters from an input file, or from standard input, 25 + and sounds each valid character as Morse code on either the system sound card, 26 + or the system console speaker. 27 + After it sounds a character, cw echoes it to standard output. 28 + The input stream can contain embedded command strings. 29 + These change the parameters used when sounding the Morse code. 30 + cw reports any errors in embedded commands 31 + ''; 32 + homepage = "http://unixcw.sourceforge.net"; 33 + maintainers = [ maintainers.mafo ]; 34 + license = licenses.gpl2; 35 + platforms=platforms.linux; 36 + }; 37 + }
+677
pkgs/applications/misc/unixcw/remove-use-of-dlopen.patch
··· 1 + From e4b91b5a7943a3b54f555ff2e0029b83bd96b131 Mon Sep 17 00:00:00 2001 2 + From: MarcFontaine <MarcFontaine@users.noreply.github.com> 3 + Date: Sat, 9 Jun 2018 11:02:11 +0200 4 + Subject: [PATCH] remove use of dlopen 5 + 6 + --- 7 + src/libcw/libcw_alsa.c | 215 ++++++++++--------------------------------------- 8 + src/libcw/libcw_pa.c | 118 ++++----------------------- 9 + 2 files changed, 56 insertions(+), 277 deletions(-) 10 + 11 + diff --git a/src/libcw/libcw_alsa.c b/src/libcw/libcw_alsa.c 12 + index a669c6e..17c306d 100644 13 + --- a/src/libcw/libcw_alsa.c 14 + +++ b/src/libcw/libcw_alsa.c 15 + @@ -35,7 +35,6 @@ 16 + 17 + 18 + 19 + -#include <dlfcn.h> /* dlopen() and related symbols */ 20 + #include <alsa/asoundlib.h> 21 + 22 + 23 + @@ -65,7 +64,6 @@ static const snd_pcm_format_t CW_ALSA_SAMPLE_FORMAT = SND_PCM_FORMAT_S16; /* "Si 24 + 25 + 26 + static int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *params); 27 + -static int cw_alsa_dlsym_internal(void *handle); 28 + static int cw_alsa_write_internal(cw_gen_t *gen); 29 + static int cw_alsa_debug_evaluate_write_internal(cw_gen_t *gen, int rv); 30 + static int cw_alsa_open_device_internal(cw_gen_t *gen); 31 + @@ -80,56 +78,6 @@ static int cw_alsa_print_params_internal(snd_pcm_hw_params_t *hw_params); 32 + 33 + 34 + 35 + -static struct { 36 + - void *handle; 37 + - 38 + - int (* snd_pcm_open)(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode); 39 + - int (* snd_pcm_close)(snd_pcm_t *pcm); 40 + - int (* snd_pcm_prepare)(snd_pcm_t *pcm); 41 + - int (* snd_pcm_drop)(snd_pcm_t *pcm); 42 + - snd_pcm_sframes_t (* snd_pcm_writei)(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size); 43 + - 44 + - const char *(* snd_strerror)(int errnum); 45 + - 46 + - int (* snd_pcm_hw_params_malloc)(snd_pcm_hw_params_t **ptr); 47 + - int (* snd_pcm_hw_params_any)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params); 48 + - int (* snd_pcm_hw_params_set_format)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val); 49 + - int (* snd_pcm_hw_params_set_rate_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir); 50 + - int (* snd_pcm_hw_params_set_access)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t _access); 51 + - int (* snd_pcm_hw_params_set_channels)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val); 52 + - int (* snd_pcm_hw_params)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params); 53 + - int (* snd_pcm_hw_params_get_periods)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir); 54 + - int (* snd_pcm_hw_params_get_period_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir); 55 + - int (* snd_pcm_hw_params_get_period_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir); 56 + - int (* snd_pcm_hw_params_get_buffer_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val); 57 + -} cw_alsa = { 58 + - .handle = NULL, 59 + - 60 + - .snd_pcm_open = NULL, 61 + - .snd_pcm_close = NULL, 62 + - .snd_pcm_prepare = NULL, 63 + - .snd_pcm_drop = NULL, 64 + - .snd_pcm_writei = NULL, 65 + - 66 + - .snd_strerror = NULL, 67 + - 68 + - .snd_pcm_hw_params_malloc = NULL, 69 + - .snd_pcm_hw_params_any = NULL, 70 + - .snd_pcm_hw_params_set_format = NULL, 71 + - .snd_pcm_hw_params_set_rate_near = NULL, 72 + - .snd_pcm_hw_params_set_access = NULL, 73 + - .snd_pcm_hw_params_set_channels = NULL, 74 + - .snd_pcm_hw_params = NULL, 75 + - .snd_pcm_hw_params_get_periods = NULL, 76 + - .snd_pcm_hw_params_get_period_size = NULL, 77 + - .snd_pcm_hw_params_get_period_size_min = NULL, 78 + - .snd_pcm_hw_params_get_buffer_size = NULL 79 + -}; 80 + - 81 + - 82 + - 83 + - 84 + - 85 + 86 + /** 87 + \brief Check if it is possible to open ALSA output 88 + @@ -144,34 +92,19 @@ static struct { 89 + */ 90 + bool cw_is_alsa_possible(const char *device) 91 + { 92 + - const char *library_name = "libasound.so.2"; 93 + - if (!cw_dlopen_internal(library_name, &(cw_alsa.handle))) { 94 + - cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 95 + - "cw_alsa: can't access ALSA library \"%s\"", library_name); 96 + - return false; 97 + - } 98 + - 99 + - int rv = cw_alsa_dlsym_internal(cw_alsa.handle); 100 + - if (rv < 0) { 101 + - cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 102 + - "cw_alsa: failed to resolve ALSA symbol #%d, can't correctly load ALSA library", rv); 103 + - dlclose(cw_alsa.handle); 104 + - return false; 105 + - } 106 + - 107 + - const char *dev = device ? device : CW_DEFAULT_ALSA_DEVICE; 108 + + int rv; 109 + + const char *dev = device ? device : CW_DEFAULT_ALSA_DEVICE; 110 + snd_pcm_t *alsa_handle; 111 + - rv = cw_alsa.snd_pcm_open(&alsa_handle, 112 + + rv = snd_pcm_open(&alsa_handle, 113 + dev, /* name */ 114 + SND_PCM_STREAM_PLAYBACK, /* stream (playback/capture) */ 115 + 0); /* mode, 0 | SND_PCM_NONBLOCK | SND_PCM_ASYNC */ 116 + if (rv < 0) { 117 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 118 + "cw_alsa: can't open ALSA device \"%s\"", dev); 119 + - dlclose(cw_alsa.handle); 120 + return false; 121 + } else { 122 + - cw_alsa.snd_pcm_close(alsa_handle); 123 + + snd_pcm_close(alsa_handle); 124 + return true; 125 + } 126 + } 127 + @@ -204,7 +137,7 @@ int cw_alsa_write_internal(cw_gen_t *gen) 128 + /* Send audio buffer to ALSA. 129 + Size of correct and current data in the buffer is the same as 130 + ALSA's period, so there should be no underruns */ 131 + - int rv = cw_alsa.snd_pcm_writei(gen->alsa_data.handle, gen->buffer, gen->buffer_n_samples); 132 + + int rv = snd_pcm_writei(gen->alsa_data.handle, gen->buffer, gen->buffer_n_samples); 133 + cw_alsa_debug_evaluate_write_internal(gen, rv); 134 + /* 135 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_INFO, 136 + @@ -231,7 +164,7 @@ int cw_alsa_write_internal(cw_gen_t *gen) 137 + */ 138 + int cw_alsa_open_device_internal(cw_gen_t *gen) 139 + { 140 + - int rv = cw_alsa.snd_pcm_open(&gen->alsa_data.handle, 141 + + int rv = snd_pcm_open(&gen->alsa_data.handle, 142 + gen->audio_device, /* name */ 143 + SND_PCM_STREAM_PLAYBACK, /* stream (playback/capture) */ 144 + 0); /* mode, 0 | SND_PCM_NONBLOCK | SND_PCM_ASYNC */ 145 + @@ -251,7 +184,7 @@ int cw_alsa_open_device_internal(cw_gen_t *gen) 146 + /* TODO: move this to cw_alsa_set_hw_params_internal(), 147 + deallocate hw_params */ 148 + snd_pcm_hw_params_t *hw_params = NULL; 149 + - rv = cw_alsa.snd_pcm_hw_params_malloc(&hw_params); 150 + + rv = snd_pcm_hw_params_malloc(&hw_params); 151 + if (rv < 0) { 152 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 153 + "cw_alsa: can't allocate memory for ALSA hw params"); 154 + @@ -265,7 +198,7 @@ int cw_alsa_open_device_internal(cw_gen_t *gen) 155 + return CW_FAILURE; 156 + } 157 + 158 + - rv = cw_alsa.snd_pcm_prepare(gen->alsa_data.handle); 159 + + rv = snd_pcm_prepare(gen->alsa_data.handle); 160 + if (rv < 0) { 161 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 162 + "cw_alsa: can't prepare ALSA handler"); 163 + @@ -275,7 +208,7 @@ int cw_alsa_open_device_internal(cw_gen_t *gen) 164 + /* Get size for data buffer */ 165 + snd_pcm_uframes_t frames; /* period size in frames */ 166 + int dir = 1; 167 + - rv = cw_alsa.snd_pcm_hw_params_get_period_size_min(hw_params, &frames, &dir); 168 + + rv = snd_pcm_hw_params_get_period_size_min(hw_params, &frames, &dir); 169 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_INFO, 170 + "cw_alsa: rv = %d, ALSA buffer size would be %u frames", rv, (unsigned int) frames); 171 + 172 + @@ -305,14 +238,11 @@ int cw_alsa_open_device_internal(cw_gen_t *gen) 173 + void cw_alsa_close_device_internal(cw_gen_t *gen) 174 + { 175 + /* "Stop a PCM dropping pending frames. " */ 176 + - cw_alsa.snd_pcm_drop(gen->alsa_data.handle); 177 + - cw_alsa.snd_pcm_close(gen->alsa_data.handle); 178 + + snd_pcm_drop(gen->alsa_data.handle); 179 + + snd_pcm_close(gen->alsa_data.handle); 180 + 181 + gen->audio_device_is_open = false; 182 + 183 + - if (cw_alsa.handle) { 184 + - dlclose(cw_alsa.handle); 185 + - } 186 + 187 + #if CW_DEV_RAW_SINK 188 + if (gen->dev_raw_sink != -1) { 189 + @@ -332,11 +262,11 @@ int cw_alsa_debug_evaluate_write_internal(cw_gen_t *gen, int rv) 190 + if (rv == -EPIPE) { 191 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_WARNING, 192 + "cw_alsa: underrun"); 193 + - cw_alsa.snd_pcm_prepare(gen->alsa_data.handle); 194 + + snd_pcm_prepare(gen->alsa_data.handle); 195 + } else if (rv < 0) { 196 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_WARNING, 197 + - "cw_alsa: writei: %s", cw_alsa.snd_strerror(rv)); 198 + - cw_alsa.snd_pcm_prepare(gen->alsa_data.handle); 199 + + "cw_alsa: writei: %s", snd_strerror(rv)); 200 + + snd_pcm_prepare(gen->alsa_data.handle); 201 + } else if (rv != gen->buffer_n_samples) { 202 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_WARNING, 203 + "cw_alsa: short write, %d != %d", rv, gen->buffer_n_samples); 204 + @@ -363,19 +293,19 @@ int cw_alsa_debug_evaluate_write_internal(cw_gen_t *gen, int rv) 205 + int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *hw_params) 206 + { 207 + /* Get current hw configuration. */ 208 + - int rv = cw_alsa.snd_pcm_hw_params_any(gen->alsa_data.handle, hw_params); 209 + + int rv = snd_pcm_hw_params_any(gen->alsa_data.handle, hw_params); 210 + if (rv < 0) { 211 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 212 + - "cw_alsa: get current hw params: %s", cw_alsa.snd_strerror(rv)); 213 + + "cw_alsa: get current hw params: %s", snd_strerror(rv)); 214 + return CW_FAILURE; 215 + } 216 + 217 + 218 + /* Set the sample format */ 219 + - rv = cw_alsa.snd_pcm_hw_params_set_format(gen->alsa_data.handle, hw_params, CW_ALSA_SAMPLE_FORMAT); 220 + + rv = snd_pcm_hw_params_set_format(gen->alsa_data.handle, hw_params, CW_ALSA_SAMPLE_FORMAT); 221 + if (rv < 0) { 222 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 223 + - "cw_alsa: can't set sample format: %s", cw_alsa.snd_strerror(rv)); 224 + + "cw_alsa: can't set sample format: %s", snd_strerror(rv)); 225 + return CW_FAILURE; 226 + } 227 + 228 + @@ -387,7 +317,7 @@ int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *hw_params 229 + bool success = false; 230 + for (int i = 0; cw_supported_sample_rates[i]; i++) { 231 + rate = cw_supported_sample_rates[i]; 232 + - int rv = cw_alsa.snd_pcm_hw_params_set_rate_near(gen->alsa_data.handle, hw_params, &rate, &dir); 233 + + int rv = snd_pcm_hw_params_set_rate_near(gen->alsa_data.handle, hw_params, &rate, &dir); 234 + if (!rv) { 235 + if (rate != cw_supported_sample_rates[i]) { 236 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_WARNING, "cw_alsa: imprecise sample rate:"); 237 + @@ -402,7 +332,7 @@ int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *hw_params 238 + 239 + if (!success) { 240 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 241 + - "cw_alsa: can't get sample rate: %s", cw_alsa.snd_strerror(rv)); 242 + + "cw_alsa: can't get sample rate: %s", snd_strerror(rv)); 243 + return CW_FAILURE; 244 + } else { 245 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_INFO, 246 + @@ -410,18 +340,18 @@ int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *hw_params 247 + } 248 + 249 + /* Set PCM access type */ 250 + - rv = cw_alsa.snd_pcm_hw_params_set_access(gen->alsa_data.handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); 251 + + rv = snd_pcm_hw_params_set_access(gen->alsa_data.handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); 252 + if (rv < 0) { 253 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 254 + - "cw_alsa: can't set access type: %s", cw_alsa.snd_strerror(rv)); 255 + + "cw_alsa: can't set access type: %s", snd_strerror(rv)); 256 + return CW_FAILURE; 257 + } 258 + 259 + /* Set number of channels */ 260 + - rv = cw_alsa.snd_pcm_hw_params_set_channels(gen->alsa_data.handle, hw_params, CW_AUDIO_CHANNELS); 261 + + rv = snd_pcm_hw_params_set_channels(gen->alsa_data.handle, hw_params, CW_AUDIO_CHANNELS); 262 + if (rv < 0) { 263 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 264 + - "cw_alsa: can't set number of channels: %s", cw_alsa.snd_strerror(rv)); 265 + + "cw_alsa: can't set number of channels: %s", snd_strerror(rv)); 266 + return CW_FAILURE; 267 + } 268 + 269 + @@ -496,7 +426,7 @@ int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *hw_params 270 + snd_pcm_uframes_t accepted = 0; /* buffer size in frames */ 271 + dir = 0; 272 + for (snd_pcm_uframes_t val = 0; val < 10000; val++) { 273 + - rv = cw_alsa.snd_pcm_hw_params_test_buffer_size(gen->alsa_data.handle, hw_params, val); 274 + + rv = snd_pcm_hw_params_test_buffer_size(gen->alsa_data.handle, hw_params, val); 275 + if (rv == 0) { 276 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_INFO, 277 + "cw_alsa: accepted buffer size: %u", (unsigned int) accepted); 278 + @@ -507,10 +437,10 @@ int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *hw_params 279 + } 280 + 281 + if (accepted > 0) { 282 + - rv = cw_alsa.snd_pcm_hw_params_set_buffer_size(gen->alsa_data.handle, hw_params, accepted); 283 + + rv = snd_pcm_hw_params_set_buffer_size(gen->alsa_data.handle, hw_params, accepted); 284 + if (rv < 0) { 285 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 286 + - "cw_alsa: can't set accepted buffer size %u: %s", (unsigned int) accepted, cw_alsa.snd_strerror(rv)); 287 + + "cw_alsa: can't set accepted buffer size %u: %s", (unsigned int) accepted, snd_strerror(rv)); 288 + } 289 + } else { 290 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 291 + @@ -526,7 +456,7 @@ int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *hw_params 292 + /* this limit should be enough, "accepted" on my machine is 8 */ 293 + const unsigned int n_periods_max = 30; 294 + for (unsigned int val = 1; val < n_periods_max; val++) { 295 + - rv = cw_alsa.snd_pcm_hw_params_test_periods(gen->alsa_data.handle, hw_params, val, dir); 296 + + rv = snd_pcm_hw_params_test_periods(gen->alsa_data.handle, hw_params, val, dir); 297 + if (rv == 0) { 298 + accepted = val; 299 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_INFO, 300 + @@ -534,10 +464,10 @@ int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *hw_params 301 + } 302 + } 303 + if (accepted > 0) { 304 + - rv = cw_alsa.snd_pcm_hw_params_set_periods(gen->alsa_data.handle, hw_params, accepted, dir); 305 + + rv = snd_pcm_hw_params_set_periods(gen->alsa_data.handle, hw_params, accepted, dir); 306 + if (rv < 0) { 307 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 308 + - "cw_alsa: can't set accepted number of periods %d: %s", accepted, cw_alsa.snd_strerror(rv)); 309 + + "cw_alsa: can't set accepted number of periods %d: %s", accepted, snd_strerror(rv)); 310 + } 311 + } else { 312 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 313 + @@ -549,7 +479,7 @@ int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *hw_params 314 + /* Test period size */ 315 + dir = 0; 316 + for (snd_pcm_uframes_t val = 0; val < 100000; val++) { 317 + - rv = cw_alsa.snd_pcm_hw_params_test_period_size(gen->alsa_data.handle, hw_params, val, dir); 318 + + rv = snd_pcm_hw_params_test_period_size(gen->alsa_data.handle, hw_params, val, dir); 319 + if (rv == 0) { 320 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_INFO, 321 + "cw_alsa: accepted period size: %lu", val); 322 + @@ -562,7 +492,7 @@ int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *hw_params 323 + /* Test buffer time */ 324 + dir = 0; 325 + for (unsigned int val = 0; val < 100000; val++) { 326 + - rv = cw_alsa.snd_pcm_hw_params_test_buffer_time(gen->alsa_data.handle, hw_params, val, dir); 327 + + rv = snd_pcm_hw_params_test_buffer_time(gen->alsa_data.handle, hw_params, val, dir); 328 + if (rv == 0) { 329 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_INFO, 330 + "cw_alsa: accepted buffer time: %d", val); 331 + @@ -573,10 +503,10 @@ int cw_alsa_set_hw_params_internal(cw_gen_t *gen, snd_pcm_hw_params_t *hw_params 332 + #endif /* #if CW_ALSA_HW_BUFFER_CONFIG */ 333 + 334 + /* Save hw parameters to device */ 335 + - rv = cw_alsa.snd_pcm_hw_params(gen->alsa_data.handle, hw_params); 336 + + rv = snd_pcm_hw_params(gen->alsa_data.handle, hw_params); 337 + if (rv < 0) { 338 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 339 + - "cw_alsa: can't save hw parameters: %s", cw_alsa.snd_strerror(rv)); 340 + + "cw_alsa: can't save hw parameters: %s", snd_strerror(rv)); 341 + return CW_FAILURE; 342 + } else { 343 + return CW_SUCCESS; 344 + @@ -600,30 +530,30 @@ int cw_alsa_print_params_internal(snd_pcm_hw_params_t *hw_params) 345 + unsigned int val = 0; 346 + int dir = 0; 347 + 348 + - int rv = cw_alsa.snd_pcm_hw_params_get_periods(hw_params, &val, &dir); 349 + + int rv = snd_pcm_hw_params_get_periods(hw_params, &val, &dir); 350 + if (rv < 0) { 351 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 352 + - "cw_alsa: can't get 'periods': %s", cw_alsa.snd_strerror(rv)); 353 + + "cw_alsa: can't get 'periods': %s", snd_strerror(rv)); 354 + } else { 355 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_INFO, 356 + "cw_alsa: 'periods' = %u", val); 357 + } 358 + 359 + snd_pcm_uframes_t period_size = 0; 360 + - rv = cw_alsa.snd_pcm_hw_params_get_period_size(hw_params, &period_size, &dir); 361 + + rv = snd_pcm_hw_params_get_period_size(hw_params, &period_size, &dir); 362 + if (rv < 0) { 363 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 364 + - "cw_alsa: can't get 'period size': %s", cw_alsa.snd_strerror(rv)); 365 + + "cw_alsa: can't get 'period size': %s", snd_strerror(rv)); 366 + } else { 367 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_INFO, 368 + "cw_alsa: 'period size' = %u", (unsigned int) period_size); 369 + } 370 + 371 + snd_pcm_uframes_t buffer_size; 372 + - rv = cw_alsa.snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size); 373 + + rv = snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size); 374 + if (rv < 0) { 375 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 376 + - "cw_alsa: can't get buffer size: %s", cw_alsa.snd_strerror(rv)); 377 + + "cw_alsa: can't get buffer size: %s", snd_strerror(rv)); 378 + } else { 379 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_INFO, 380 + "cw_alsa: 'buffer size' = %u", (unsigned int) buffer_size); 381 + @@ -642,70 +572,9 @@ int cw_alsa_print_params_internal(snd_pcm_hw_params_t *hw_params) 382 + 383 + 384 + 385 + -/** 386 + - \brief Resolve/get symbols from ALSA library 387 + - 388 + - Function resolves/gets addresses of few ALSA functions used by 389 + - libcw and stores them in cw_alsa global variable. 390 + - 391 + - On failure the function returns negative value, different for every 392 + - symbol that the funciton failed to resolve. Function stops and returns 393 + - on first failure. 394 + - 395 + - \param handle - handle to open ALSA library 396 + - 397 + - \return 0 on success 398 + - \return negative value on failure 399 + -*/ 400 + -static int cw_alsa_dlsym_internal(void *handle) 401 + -{ 402 + - *(void **) &(cw_alsa.snd_pcm_open) = dlsym(handle, "snd_pcm_open"); 403 + - if (!cw_alsa.snd_pcm_open) return -1; 404 + - *(void **) &(cw_alsa.snd_pcm_close) = dlsym(handle, "snd_pcm_close"); 405 + - if (!cw_alsa.snd_pcm_close) return -2; 406 + - *(void **) &(cw_alsa.snd_pcm_prepare) = dlsym(handle, "snd_pcm_prepare"); 407 + - if (!cw_alsa.snd_pcm_prepare) return -3; 408 + - *(void **) &(cw_alsa.snd_pcm_drop) = dlsym(handle, "snd_pcm_drop"); 409 + - if (!cw_alsa.snd_pcm_drop) return -4; 410 + - *(void **) &(cw_alsa.snd_pcm_writei) = dlsym(handle, "snd_pcm_writei"); 411 + - if (!cw_alsa.snd_pcm_writei) return -5; 412 + - 413 + - *(void **) &(cw_alsa.snd_strerror) = dlsym(handle, "snd_strerror"); 414 + - if (!cw_alsa.snd_strerror) return -10; 415 + - 416 + - *(void **) &(cw_alsa.snd_pcm_hw_params_malloc) = dlsym(handle, "snd_pcm_hw_params_malloc"); 417 + - if (!cw_alsa.snd_pcm_hw_params_malloc) return -20; 418 + - *(void **) &(cw_alsa.snd_pcm_hw_params_any) = dlsym(handle, "snd_pcm_hw_params_any"); 419 + - if (!cw_alsa.snd_pcm_hw_params_any) return -21; 420 + - *(void **) &(cw_alsa.snd_pcm_hw_params_set_format) = dlsym(handle, "snd_pcm_hw_params_set_format"); 421 + - if (!cw_alsa.snd_pcm_hw_params_set_format) return -22; 422 + - *(void **) &(cw_alsa.snd_pcm_hw_params_set_rate_near) = dlsym(handle, "snd_pcm_hw_params_set_rate_near"); 423 + - if (!cw_alsa.snd_pcm_hw_params_set_rate_near) return -23; 424 + - *(void **) &(cw_alsa.snd_pcm_hw_params_set_access) = dlsym(handle, "snd_pcm_hw_params_set_access"); 425 + - if (!cw_alsa.snd_pcm_hw_params_set_access) return -24; 426 + - *(void **) &(cw_alsa.snd_pcm_hw_params_set_channels) = dlsym(handle, "snd_pcm_hw_params_set_channels"); 427 + - if (!cw_alsa.snd_pcm_hw_params_set_channels) return -25; 428 + - *(void **) &(cw_alsa.snd_pcm_hw_params) = dlsym(handle, "snd_pcm_hw_params"); 429 + - if (!cw_alsa.snd_pcm_hw_params) return -26; 430 + - *(void **) &(cw_alsa.snd_pcm_hw_params_get_periods) = dlsym(handle, "snd_pcm_hw_params_get_periods"); 431 + - if (!cw_alsa.snd_pcm_hw_params_get_periods) return -27; 432 + - *(void **) &(cw_alsa.snd_pcm_hw_params_get_period_size) = dlsym(handle, "snd_pcm_hw_params_get_period_size"); 433 + - if (!cw_alsa.snd_pcm_hw_params_get_period_size) return -28; 434 + - *(void **) &(cw_alsa.snd_pcm_hw_params_get_period_size_min) = dlsym(handle, "snd_pcm_hw_params_get_period_size_min"); 435 + - if (!cw_alsa.snd_pcm_hw_params_get_period_size_min) return -29; 436 + - *(void **) &(cw_alsa.snd_pcm_hw_params_get_buffer_size) = dlsym(handle, "snd_pcm_hw_params_get_buffer_size"); 437 + - if (!cw_alsa.snd_pcm_hw_params_get_buffer_size) return -30; 438 + - 439 + - return 0; 440 + -} 441 + - 442 + - 443 + - 444 + - 445 + - 446 + void cw_alsa_drop(cw_gen_t *gen) 447 + { 448 + - cw_alsa.snd_pcm_drop(gen->alsa_data.handle); 449 + + snd_pcm_drop(gen->alsa_data.handle); 450 + 451 + return; 452 + } 453 + @@ -721,7 +590,7 @@ void cw_alsa_drop(cw_gen_t *gen) 454 + 455 + 456 + #include <stdbool.h> 457 + -#include "libcw_alsa.h" 458 + +#include "libh" 459 + 460 + 461 + 462 + diff --git a/src/libcw/libcw_pa.c b/src/libcw/libcw_pa.c 463 + index 8269e9d..e190200 100644 464 + --- a/src/libcw/libcw_pa.c 465 + +++ b/src/libcw/libcw_pa.c 466 + @@ -39,7 +39,6 @@ 467 + #include <unistd.h> 468 + #include <stdlib.h> 469 + #include <stdbool.h> 470 + -#include <dlfcn.h> /* dlopen() and related symbols */ 471 + #include <string.h> 472 + #include <assert.h> 473 + #include <sys/types.h> 474 + @@ -63,39 +62,12 @@ extern cw_debug_t cw_debug_object_dev; 475 + 476 + 477 + static pa_simple *cw_pa_simple_new_internal(pa_sample_spec *ss, pa_buffer_attr *ba, const char *device, const char *stream_name, int *error); 478 + -static int cw_pa_dlsym_internal(void *handle); 479 + static int cw_pa_open_device_internal(cw_gen_t *gen); 480 + static void cw_pa_close_device_internal(cw_gen_t *gen); 481 + static int cw_pa_write_internal(cw_gen_t *gen); 482 + 483 + 484 + 485 + -static struct { 486 + - void *handle; 487 + - 488 + - pa_simple *(* pa_simple_new)(const char *server, const char *name, pa_stream_direction_t dir, const char *dev, const char *stream_name, const pa_sample_spec *ss, const pa_channel_map *map, const pa_buffer_attr *attr, int *error); 489 + - void (* pa_simple_free)(pa_simple *s); 490 + - int (* pa_simple_write)(pa_simple *s, const void *data, size_t bytes, int *error); 491 + - pa_usec_t (* pa_simple_get_latency)(pa_simple *s, int *error); 492 + - int (* pa_simple_drain)(pa_simple *s, int *error); 493 + - 494 + - size_t (* pa_usec_to_bytes)(pa_usec_t t, const pa_sample_spec *spec); 495 + - char *(* pa_strerror)(int error); 496 + -} cw_pa = { 497 + - .handle = NULL, 498 + - 499 + - .pa_simple_new = NULL, 500 + - .pa_simple_free = NULL, 501 + - .pa_simple_write = NULL, 502 + - .pa_simple_get_latency = NULL, 503 + - .pa_simple_drain = NULL, 504 + - 505 + - .pa_usec_to_bytes = NULL, 506 + - .pa_strerror = NULL 507 + -}; 508 + - 509 + - 510 + - 511 + 512 + static const pa_sample_format_t CW_PA_SAMPLE_FORMAT = PA_SAMPLE_S16LE; /* Signed 16 bit, Little Endian */ 513 + static const int CW_PA_BUFFER_N_SAMPLES = 1024; 514 + @@ -117,21 +89,6 @@ static const int CW_PA_BUFFER_N_SAMPLES = 1024; 515 + */ 516 + bool cw_is_pa_possible(const char *device) 517 + { 518 + - const char *library_name = "libpulse-simple.so"; 519 + - if (!cw_dlopen_internal(library_name, &(cw_pa.handle))) { 520 + - cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 521 + - "libcw_pa: can't access PulseAudio library \"%s\"", library_name); 522 + - return false; 523 + - } 524 + - 525 + - int rv = cw_pa_dlsym_internal(cw_pa.handle); 526 + - if (rv < 0) { 527 + - cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 528 + - "libcw_pa: failed to resolve PulseAudio symbol #%d, can't correctly load PulseAudio library", rv); 529 + - dlclose(cw_pa.handle); 530 + - return false; 531 + - } 532 + - 533 + const char *dev = (char *) NULL; 534 + if (device && strcmp(device, CW_DEFAULT_PA_DEVICE)) { 535 + dev = device; 536 + @@ -145,13 +102,10 @@ bool cw_is_pa_possible(const char *device) 537 + 538 + if (!s) { 539 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 540 + - "libcw_pa: can't connect to PulseAudio server: %s", cw_pa.pa_strerror(error)); 541 + - if (cw_pa.handle) { 542 + - dlclose(cw_pa.handle); 543 + - } 544 + + "libcw_pa: can't connect to PulseAudio server: %s", pa_strerror(error)); 545 + return false; 546 + } else { 547 + - cw_pa.pa_simple_free(s); 548 + + pa_simple_free(s); 549 + s = NULL; 550 + return true; 551 + } 552 + @@ -186,10 +140,10 @@ int cw_pa_write_internal(cw_gen_t *gen) 553 + 554 + int error = 0; 555 + size_t n_bytes = sizeof (gen->buffer[0]) * gen->buffer_n_samples; 556 + - int rv = cw_pa.pa_simple_write(gen->pa_data.s, gen->buffer, n_bytes, &error); 557 + + int rv = pa_simple_write(gen->pa_data.s, gen->buffer, n_bytes, &error); 558 + if (rv < 0) { 559 + cw_debug_msg ((&cw_debug_object), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 560 + - "libcw_pa: pa_simple_write() failed: %s", cw_pa.pa_strerror(error)); 561 + + "libcw_pa: pa_simple_write() failed: %s", pa_strerror(error)); 562 + } else { 563 + //cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_INFO, "libcw_pa: written %d samples with PulseAudio", gen->buffer_n_samples); 564 + } 565 + @@ -237,13 +191,13 @@ pa_simple *cw_pa_simple_new_internal(pa_sample_spec *ss, pa_buffer_attr *ba, con 566 + } 567 + 568 + // http://www.mail-archive.com/pulseaudio-tickets@mail.0pointer.de/msg03295.html 569 + - ba->tlength = cw_pa.pa_usec_to_bytes(50*1000, ss); 570 + - ba->minreq = cw_pa.pa_usec_to_bytes(0, ss); 571 + - ba->maxlength = cw_pa.pa_usec_to_bytes(50*1000, ss); 572 + + ba->tlength = pa_usec_to_bytes(50*1000, ss); 573 + + ba->minreq = pa_usec_to_bytes(0, ss); 574 + + ba->maxlength = pa_usec_to_bytes(50*1000, ss); 575 + /* ba->prebuf = ; */ /* ? */ 576 + /* ba->fragsize = sizeof(uint32_t) -1; */ /* not relevant to playback */ 577 + 578 + - pa_simple *s = cw_pa.pa_simple_new(NULL, /* server name (NULL for default) */ 579 + + pa_simple *s = pa_simple_new(NULL, /* server name (NULL for default) */ 580 + "libcw", /* descriptive name of client (application name etc.) */ 581 + PA_STREAM_PLAYBACK, /* stream direction */ 582 + dev, /* device/sink name (NULL for default) */ 583 + @@ -258,47 +212,6 @@ pa_simple *cw_pa_simple_new_internal(pa_sample_spec *ss, pa_buffer_attr *ba, con 584 + 585 + 586 + 587 + - 588 + - 589 + -/** 590 + - \brief Resolve/get symbols from PulseAudio library 591 + - 592 + - Function resolves/gets addresses of few PulseAudio functions used by 593 + - libcw and stores them in cw_pa global variable. 594 + - 595 + - On failure the function returns negative value, different for every 596 + - symbol that the funciton failed to resolve. Function stops and returns 597 + - on first failure. 598 + - 599 + - \param handle - handle to open PulseAudio library 600 + - 601 + - \return 0 on success 602 + - \return negative value on failure 603 + -*/ 604 + -int cw_pa_dlsym_internal(void *handle) 605 + -{ 606 + - *(void **) &(cw_pa.pa_simple_new) = dlsym(handle, "pa_simple_new"); 607 + - if (!cw_pa.pa_simple_new) return -1; 608 + - *(void **) &(cw_pa.pa_simple_free) = dlsym(handle, "pa_simple_free"); 609 + - if (!cw_pa.pa_simple_free) return -2; 610 + - *(void **) &(cw_pa.pa_simple_write) = dlsym(handle, "pa_simple_write"); 611 + - if (!cw_pa.pa_simple_write) return -3; 612 + - *(void **) &(cw_pa.pa_strerror) = dlsym(handle, "pa_strerror"); 613 + - if (!cw_pa.pa_strerror) return -4; 614 + - *(void **) &(cw_pa.pa_simple_get_latency) = dlsym(handle, "pa_simple_get_latency"); 615 + - if (!cw_pa.pa_simple_get_latency) return -5; 616 + - *(void **) &(cw_pa.pa_simple_drain) = dlsym(handle, "pa_simple_drain"); 617 + - if (!cw_pa.pa_simple_drain) return -6; 618 + - *(void **) &(cw_pa.pa_usec_to_bytes) = dlsym(handle, "pa_usec_to_bytes"); 619 + - if (!cw_pa.pa_usec_to_bytes) return -7; 620 + - 621 + - return 0; 622 + -} 623 + - 624 + - 625 + - 626 + - 627 + - 628 + /** 629 + \brief Open PulseAudio output, associate it with given generator 630 + 631 + @@ -325,16 +238,16 @@ int cw_pa_open_device_internal(cw_gen_t *gen) 632 + 633 + if (!gen->pa_data.s) { 634 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 635 + - "libcw_pa: can't connect to PulseAudio server: %s", cw_pa.pa_strerror(error)); 636 + + "libcw_pa: can't connect to PulseAudio server: %s", pa_strerror(error)); 637 + return false; 638 + } 639 + 640 + gen->buffer_n_samples = CW_PA_BUFFER_N_SAMPLES; 641 + gen->sample_rate = gen->pa_data.ss.rate; 642 + 643 + - if ((gen->pa_data.latency_usecs = cw_pa.pa_simple_get_latency(gen->pa_data.s, &error)) == (pa_usec_t) -1) { 644 + + if ((gen->pa_data.latency_usecs = pa_simple_get_latency(gen->pa_data.s, &error)) == (pa_usec_t) -1) { 645 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 646 + - "libcw_pa: pa_simple_get_latency() failed: %s", cw_pa.pa_strerror(error)); 647 + + "libcw_pa: pa_simple_get_latency() failed: %s", pa_strerror(error)); 648 + } 649 + 650 + #if CW_DEV_RAW_SINK 651 + @@ -357,20 +270,17 @@ void cw_pa_close_device_internal(cw_gen_t *gen) 652 + if (gen->pa_data.s) { 653 + /* Make sure that every single sample was played */ 654 + int error; 655 + - if (cw_pa.pa_simple_drain(gen->pa_data.s, &error) < 0) { 656 + + if (pa_simple_drain(gen->pa_data.s, &error) < 0) { 657 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_ERROR, 658 + - "libcw_pa: pa_simple_drain() failed: %s", cw_pa.pa_strerror(error)); 659 + + "libcw_pa: pa_simple_drain() failed: %s", pa_strerror(error)); 660 + } 661 + - cw_pa.pa_simple_free(gen->pa_data.s); 662 + + pa_simple_free(gen->pa_data.s); 663 + gen->pa_data.s = NULL; 664 + } else { 665 + cw_debug_msg ((&cw_debug_object_dev), CW_DEBUG_SOUND_SYSTEM, CW_DEBUG_WARNING, 666 + "libcw_pa: called the function for NULL PA sink"); 667 + } 668 + 669 + - if (cw_pa.handle) { 670 + - dlclose(cw_pa.handle); 671 + - } 672 + 673 + #if CW_DEV_RAW_SINK 674 + if (gen->dev_raw_sink != -1) { 675 + -- 676 + 2.16.2 677 +
+2
pkgs/top-level/all-packages.nix
··· 21243 21243 21244 21244 unicode-paracode = callPackage ../tools/misc/unicode { }; 21245 21245 21246 + unixcw = callPackage ../applications/misc/unixcw { }; 21247 + 21246 21248 valauncher = callPackage ../applications/misc/valauncher { }; 21247 21249 21248 21250 vault = callPackage ../tools/security/vault { };