From 8852b80df865098a7c2895904fac99b6b1e23fbd Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Sun, 27 Feb 2011 09:53:59 +0100 Subject: module-waveout: Add device_name parameter Also use the name in the source/sink description. Based on a patch by srirams, from github. --- src/modules/module-waveout.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-waveout.c b/src/modules/module-waveout.c index 0dbf7ef9..05bc3065 100644 --- a/src/modules/module-waveout.c +++ b/src/modules/module-waveout.c @@ -52,6 +52,7 @@ PA_MODULE_USAGE( "sink_name= " "source_name= " "device= " + "device_name= " "record= " "playback= " "format= " @@ -97,6 +98,7 @@ static const char* const valid_modargs[] = { "sink_name", "source_name", "device", + "device_name", "record", "playback", "fragments", @@ -476,12 +478,14 @@ int pa__init(pa_module *m) { HWAVEOUT hwo = INVALID_HANDLE_VALUE; HWAVEIN hwi = INVALID_HANDLE_VALUE; WAVEFORMATEX wf; + WAVEOUTCAPS pwoc; int nfrags, frag_size; pa_bool_t record = TRUE, playback = TRUE; unsigned int device; pa_sample_spec ss; pa_channel_map map; pa_modargs *ma = NULL; + const char *device_name = NULL; unsigned int i; pa_assert(m); @@ -502,11 +506,31 @@ int pa__init(pa_module *m) { goto fail; } + /* Set the device to be opened. If set device_name is used, + * else device if set and lastly WAVE_MAPPER is the default */ device = WAVE_MAPPER; if (pa_modargs_get_value_u32(ma, "device", &device) < 0) { pa_log("failed to parse device argument"); goto fail; } + if ((device_name = pa_modargs_get_value(ma, "device_name", NULL)) != NULL) { + unsigned int num_devices = waveOutGetNumDevs(); + for (i = 0; i < num_devices; i++) { + if (waveOutGetDevCaps(i, &pwoc, sizeof(pwoc)) == MMSYSERR_NOERROR) + if (_stricmp(device_name, pwoc.szPname) == 0) + break; + } + if (i < num_devices) + device = i; + else { + pa_log("device not found: %s", device_name); + goto fail; + } + } + if (waveOutGetDevCaps(device, &pwoc, sizeof(pwoc)) == MMSYSERR_NOERROR) + device_name = pwoc.szPname; + else + device_name = "unknown"; nfrags = 5; frag_size = 8192; @@ -549,6 +573,7 @@ int pa__init(pa_module *m) { InitializeCriticalSection(&u->crit); if (hwi != INVALID_HANDLE_VALUE) { + char *description = pa_sprintf_malloc("WaveIn on %s", device_name); pa_source_new_data data; pa_source_new_data_init(&data); data.driver = __FILE__; @@ -561,12 +586,14 @@ int pa__init(pa_module *m) { pa_assert(u->source); u->source->userdata = u; - pa_source_set_description(u->source, "Windows waveIn PCM"); + pa_source_set_description(u->source, description); u->source->parent.process_msg = process_msg; + pa_xfree(description); } else u->source = NULL; if (hwo != INVALID_HANDLE_VALUE) { + char *description = pa_sprintf_malloc("WaveOut on %s", device_name); pa_sink_new_data data; pa_sink_new_data_init(&data); data.driver = __FILE__; @@ -581,8 +608,9 @@ int pa__init(pa_module *m) { u->sink->get_volume = sink_get_volume_cb; u->sink->set_volume = sink_set_volume_cb; u->sink->userdata = u; - pa_sink_set_description(u->sink, "Windows waveOut PCM"); + pa_sink_set_description(u->sink, description); u->sink->parent.process_msg = process_msg; + pa_xfree(description); } else u->sink = NULL; -- cgit From c470680e1ba008c05c13231dbbafd69cb9330488 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Tue, 1 Mar 2011 16:06:19 +0100 Subject: Use pulsecore/arpa-inet.h to make arpa/inet.h functionality available Automatically use replacement function on platforms (win32) where not all arpa/inet.h is available natively. --- src/modules/module-protocol-stub.c | 4 +--- src/modules/raop/raop_client.c | 1 - src/modules/rtp/module-rtp-recv.c | 2 +- src/modules/rtp/module-rtp-send.c | 2 +- src/modules/rtp/rtp.c | 2 +- src/modules/rtp/rtsp_client.c | 2 +- src/modules/rtp/sap.c | 2 +- src/modules/rtp/sdp.c | 2 +- 8 files changed, 7 insertions(+), 10 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-protocol-stub.c b/src/modules/module-protocol-stub.c index 7ba54054..52506f95 100644 --- a/src/modules/module-protocol-stub.c +++ b/src/modules/module-protocol-stub.c @@ -30,9 +30,6 @@ #include #include -#ifdef HAVE_ARPA_INET_H -#include -#endif #ifdef HAVE_NETINET_IN_H #include #endif @@ -49,6 +46,7 @@ #include #include #include +#include #ifdef USE_TCP_SOCKETS #define SOCKET_DESCRIPTION "(TCP sockets)" diff --git a/src/modules/raop/raop_client.c b/src/modules/raop/raop_client.c index e3152dd3..7dd96839 100644 --- a/src/modules/raop/raop_client.c +++ b/src/modules/raop/raop_client.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c index a920e66e..1144169b 100644 --- a/src/modules/rtp/module-rtp-recv.c +++ b/src/modules/rtp/module-rtp-recv.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -54,6 +53,7 @@ #include #include #include +#include #include "module-rtp-recv-symdef.h" diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c index ab815223..f53020d1 100644 --- a/src/modules/rtp/module-rtp-send.c +++ b/src/modules/rtp/module-rtp-send.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -49,6 +48,7 @@ #include #include #include +#include #include "module-rtp-send-symdef.h" diff --git a/src/modules/rtp/rtp.c b/src/modules/rtp/rtp.c index 74f0ac38..22e491bf 100644 --- a/src/modules/rtp/rtp.c +++ b/src/modules/rtp/rtp.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -43,6 +42,7 @@ #include #include #include +#include #include "rtp.h" diff --git a/src/modules/rtp/rtsp_client.c b/src/modules/rtp/rtsp_client.c index 6094eb82..fd3b1de3 100644 --- a/src/modules/rtp/rtsp_client.c +++ b/src/modules/rtp/rtsp_client.c @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -46,6 +45,7 @@ #include #include #include +#include #include "rtsp_client.h" diff --git a/src/modules/rtp/sap.c b/src/modules/rtp/sap.c index adde16df..87c8b8f6 100644 --- a/src/modules/rtp/sap.c +++ b/src/modules/rtp/sap.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -48,6 +47,7 @@ #include #include #include +#include #include "sap.h" #include "sdp.h" diff --git a/src/modules/rtp/sdp.c b/src/modules/rtp/sdp.c index 7fc7e38c..3e61d9b8 100644 --- a/src/modules/rtp/sdp.c +++ b/src/modules/rtp/sdp.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -37,6 +36,7 @@ #include #include #include +#include #include "sdp.h" #include "rtp.h" -- cgit From 030f32fe6fe7cca283530e734f23b531d6ebe25b Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Sat, 12 Mar 2011 19:41:07 +0100 Subject: module-waveout: Query device for supported samplerate Instead of using a fixed list list of supported rates, ask the wave subsystem whether the rate can be used. --- src/modules/module-waveout.c | 59 +++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 23 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-waveout.c b/src/modules/module-waveout.c index 05bc3065..44b15dae 100644 --- a/src/modules/module-waveout.c +++ b/src/modules/module-waveout.c @@ -159,12 +159,11 @@ static void do_write(struct userdata *u) { memchunk.memblock = NULL; } - /* Insufficient data in sink buffer? */ + /* Underflow detection */ if (hdr->dwBufferLength == 0) { u->sink_underflow = 1; break; } - u->sink_underflow = 0; res = waveOutPrepareHeader(u->hwo, hdr, sizeof(WAVEHDR)); @@ -292,8 +291,12 @@ finish: } static void CALLBACK chunk_done_cb(HWAVEOUT hwo, UINT msg, DWORD_PTR inst, DWORD param1, DWORD param2) { - struct userdata *u = (struct userdata *)inst; + struct userdata *u = (struct userdata*) inst; + if (msg == WOM_OPEN) + pa_log_debug("WaveOut subsystem opened."); + if (msg == WOM_CLOSE) + pa_log_debug("WaveOut subsystem closed."); if (msg != WOM_DONE) return; @@ -304,8 +307,12 @@ static void CALLBACK chunk_done_cb(HWAVEOUT hwo, UINT msg, DWORD_PTR inst, DWORD } static void CALLBACK chunk_ready_cb(HWAVEIN hwi, UINT msg, DWORD_PTR inst, DWORD param1, DWORD param2) { - struct userdata *u = (struct userdata *)inst; + struct userdata *u = (struct userdata*) inst; + if (msg == WIM_OPEN) + pa_log_debug("WaveIn subsystem opened."); + if (msg == WIM_CLOSE) + pa_log_debug("WaveIn subsystem closed."); if (msg != WIM_DATA) return; @@ -433,17 +440,6 @@ static int ss_to_waveformat(pa_sample_spec *ss, LPWAVEFORMATEX wf) { wf->nChannels = ss->channels; - switch (ss->rate) { - case 8000: - case 11025: - case 22005: - case 44100: - break; - default: - pa_log_error("Unsupported sample rate."); - return -1; - } - wf->nSamplesPerSec = ss->rate; if (ss->format == PA_SAMPLE_U8) @@ -451,7 +447,7 @@ static int ss_to_waveformat(pa_sample_spec *ss, LPWAVEFORMATEX wf) { else if (ss->format == PA_SAMPLE_S16NE) wf->wBitsPerSample = 16; else { - pa_log_error("Unsupported sample format."); + pa_log_error("Unsupported sample format, only u8 and s16 are supported."); return -1; } @@ -467,7 +463,7 @@ int pa__get_n_used(pa_module *m) { struct userdata *u; pa_assert(m); pa_assert(m->userdata); - u = (struct userdata *)m->userdata; + u = (struct userdata*) m->userdata; return (u->sink ? pa_sink_used_by(u->sink) : 0) + (u->source ? pa_source_used_by(u->source) : 0); @@ -479,6 +475,7 @@ int pa__init(pa_module *m) { HWAVEIN hwi = INVALID_HANDLE_VALUE; WAVEFORMATEX wf; WAVEOUTCAPS pwoc; + MMRESULT result; int nfrags, frag_size; pa_bool_t record = TRUE, playback = TRUE; unsigned int device; @@ -551,23 +548,39 @@ int pa__init(pa_module *m) { u = pa_xmalloc(sizeof(struct userdata)); if (record) { - if (waveInOpen(&hwi, device, &wf, (DWORD_PTR)chunk_ready_cb, (DWORD_PTR)u, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) { - pa_log("failed to open waveIn"); + result = waveInOpen(&hwi, device, &wf, 0, 0, WAVE_FORMAT_DIRECT | WAVE_FORMAT_QUERY); + if (result != MMSYSERR_NOERROR) { + pa_log_warn("Sample spec not supported by WaveIn, falling back to default sample rate."); + ss.rate = wf.nSamplesPerSec = m->core->default_sample_spec.rate; + } + result = waveInOpen(&hwi, device, &wf, (DWORD_PTR) chunk_ready_cb, (DWORD_PTR) u, CALLBACK_FUNCTION); + if (result != MMSYSERR_NOERROR) { + char errortext[MAXERRORLENGTH]; + pa_log("Failed to open WaveIn."); + if (waveInGetErrorText(result, errortext, sizeof(errortext)) == MMSYSERR_NOERROR) + pa_log("Error: %s", errortext); goto fail; } if (waveInStart(hwi) != MMSYSERR_NOERROR) { pa_log("failed to start waveIn"); goto fail; } - pa_log_debug("Opened waveIn subsystem."); } if (playback) { - if (waveOutOpen(&hwo, device, &wf, (DWORD_PTR)chunk_done_cb, (DWORD_PTR)u, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) { - pa_log("failed to open waveOut"); + result = waveOutOpen(&hwo, device, &wf, 0, 0, WAVE_FORMAT_DIRECT | WAVE_FORMAT_QUERY); + if (result != MMSYSERR_NOERROR) { + pa_log_warn("Sample spec not supported by WaveOut, falling back to default sample rate."); + ss.rate = wf.nSamplesPerSec = m->core->default_sample_spec.rate; + } + result = waveOutOpen(&hwo, device, &wf, (DWORD_PTR) chunk_done_cb, (DWORD_PTR) u, CALLBACK_FUNCTION); + if (result != MMSYSERR_NOERROR) { + char errortext[MAXERRORLENGTH]; + pa_log("Failed to open WaveOut."); + if (waveOutGetErrorText(result, errortext, sizeof(errortext)) == MMSYSERR_NOERROR) + pa_log("Error: %s", errortext); goto fail; } - pa_log_debug("Opened waveOut subsystem."); } InitializeCriticalSection(&u->crit); -- cgit From 72de043234448ffbb6aa1d3f5a846c20c0aa5928 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Fri, 11 Mar 2011 15:41:29 +0100 Subject: module-waveout: Move thread creation --- src/modules/module-waveout.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-waveout.c b/src/modules/module-waveout.c index 44b15dae..90d05991 100644 --- a/src/modules/module-waveout.c +++ b/src/modules/module-waveout.c @@ -650,7 +650,7 @@ int pa__init(pa_module *m) { pa_assert(u->ihdrs); u->ohdrs = pa_xmalloc0(sizeof(WAVEHDR) * u->fragments); pa_assert(u->ohdrs); - for (i = 0;i < u->fragments;i++) { + for (i = 0; i < u->fragments; i++) { u->ihdrs[i].dwBufferLength = u->fragment_size; u->ohdrs[i].dwBufferLength = u->fragment_size; u->ihdrs[i].lpData = pa_xmalloc(u->fragment_size); @@ -668,22 +668,26 @@ int pa__init(pa_module *m) { u->rtpoll = pa_rtpoll_new(); pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); - if (!(u->thread = pa_thread_new("waveout-source", thread_func, u))) { - pa_log("Failed to create thread."); - goto fail; - } if (u->sink) { pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq); pa_sink_set_rtpoll(u->sink, u->rtpoll); - pa_sink_put(u->sink); } if (u->source) { pa_source_set_asyncmsgq(u->source, u->thread_mq.inq); pa_source_set_rtpoll(u->source, u->rtpoll); - pa_source_put(u->source); } + if (!(u->thread = pa_thread_new("waveout", thread_func, u))) { + pa_log("Failed to create thread."); + goto fail; + } + + if (u->sink) + pa_sink_put(u->sink); + if (u->source) + pa_source_put(u->source); + return 0; fail: @@ -712,7 +716,7 @@ void pa__done(pa_module *m) { pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL); if (u->thread) - pa_thread_free(u->thread); + pa_thread_free(u->thread); pa_thread_mq_done(&u->thread_mq); if (u->sink) @@ -733,7 +737,7 @@ void pa__done(pa_module *m) { waveOutClose(u->hwo); } - for (i = 0;i < u->fragments;i++) { + for (i = 0; i < u->fragments; i++) { pa_xfree(u->ihdrs[i].lpData); pa_xfree(u->ohdrs[i].lpData); } -- cgit From f99b17b825ea7dbf4c2e9ecd490d9b6b54018df3 Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Mon, 14 Mar 2011 10:51:11 +0100 Subject: module-waveout: Fix record/playback args --- src/modules/module-waveout.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-waveout.c b/src/modules/module-waveout.c index 90d05991..6c969212 100644 --- a/src/modules/module-waveout.c +++ b/src/modules/module-waveout.c @@ -256,20 +256,23 @@ static void thread_func(void *userdata) { for (;;) { int ret; + pa_bool_t need_timer = FALSE; - if (PA_SINK_IS_OPENED(u->sink->thread_info.state) || - PA_SOURCE_IS_OPENED(u->source->thread_info.state)) { - + if (u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state)) { if (u->sink->thread_info.rewind_requested) pa_sink_process_rewind(u->sink, 0); - if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) - do_write(u); - if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) - do_read(u); + do_write(u); + need_timer = TRUE; + } + if (u->source && PA_SOURCE_IS_OPENED(u->source->thread_info.state)) { + do_read(u); + need_timer = TRUE; + } + if (need_timer) pa_rtpoll_set_timer_relative(u->rtpoll, u->poll_timeout); - } else + else pa_rtpoll_set_timer_disabled(u->rtpoll); /* Hmm, nothing to do. Let's sleep */ @@ -643,6 +646,7 @@ int pa__init(pa_module *m) { u->sink_underflow = 1; u->poll_timeout = pa_bytes_to_usec(u->fragments * u->fragment_size / 10, &ss); + pa_log_debug("Poll timeout = %.1f ms", (double) u->poll_timeout / PA_USEC_PER_MSEC); u->cur_ihdr = 0; u->cur_ohdr = 0; -- cgit