From 8ca254c49065cb49fcc6225f1270752f61ba8b17 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 11 Aug 2008 19:46:11 +0200 Subject: fix two uninitialized memory accesses --- src/modules/module-alsa-source.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules/module-alsa-source.c') diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index 1cc467d9..f1b6622a 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -234,7 +234,7 @@ static size_t check_left_to_record(struct userdata *u, snd_pcm_sframes_t n) { static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { int work_done = 0; - pa_usec_t max_sleep_usec, process_usec; + pa_usec_t max_sleep_usec = 0, process_usec = 0; size_t left_to_record; pa_assert(u); @@ -331,7 +331,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { static int unix_read(struct userdata *u, pa_usec_t *sleep_usec) { int work_done = 0; - pa_usec_t max_sleep_usec, process_usec; + pa_usec_t max_sleep_usec = 0, process_usec = 0; size_t left_to_record; pa_assert(u); @@ -837,7 +837,7 @@ static void thread_func(void *userdata) { /* Read some data and pass it to the sources */ if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) { int work_done = 0; - pa_usec_t sleep_usec; + pa_usec_t sleep_usec = 0; if (u->use_mmap) work_done = mmap_read(u, &sleep_usec); -- cgit From 8a10eba744c42cb5db4e6446c2f77b6cbc5eb028 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Aug 2008 13:59:06 +0200 Subject: extend hardware dB scale in software to full range if necessary, instead of reverting back to software-only volume control --- src/modules/module-alsa-source.c | 239 ++++++++++++++++++++++++--------------- 1 file changed, 148 insertions(+), 91 deletions(-) (limited to 'src/modules/module-alsa-source.c') diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index f1b6622a..0e4efad5 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -69,8 +69,7 @@ PA_MODULE_USAGE( "mmap= " "tsched= " "tsched_buffer_size= " - "tsched_buffer_watermark= " - "mixer_reset="); + "tsched_buffer_watermark="); static const char* const valid_modargs[] = { "source_name", @@ -86,7 +85,6 @@ static const char* const valid_modargs[] = { "tsched", "tsched_buffer_size", "tsched_buffer_watermark", - "mixer_reset", NULL }; @@ -113,6 +111,9 @@ struct userdata { long hw_volume_max, hw_volume_min; long hw_dB_max, hw_dB_min; pa_bool_t hw_dB_supported; + pa_bool_t mixer_seperate_channels; + + pa_cvolume hardware_volume; size_t frame_size, fragment_size, hwbuf_size, tsched_watermark; unsigned nfragments; @@ -680,8 +681,8 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) { return 0; if (mask & SND_CTL_EVENT_MASK_VALUE) { - pa_source_get_volume(u->source); - pa_source_get_mute(u->source); + pa_source_get_volume(u->source, TRUE); + pa_source_get_mute(u->source, TRUE); } return 0; @@ -690,30 +691,60 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) { static int source_get_volume_cb(pa_source *s) { struct userdata *u = s->userdata; int err; - int i; + unsigned i; + pa_cvolume r; + char t[PA_CVOLUME_SNPRINT_MAX]; pa_assert(u); pa_assert(u->mixer_elem); - for (i = 0; i < s->sample_spec.channels; i++) { - long alsa_vol; + if (u->mixer_seperate_channels) { - pa_assert(snd_mixer_selem_has_capture_channel(u->mixer_elem, u->mixer_map[i])); + r.channels = s->sample_spec.channels; - if (u->hw_dB_supported) { + for (i = 0; i < s->sample_spec.channels; i++) { + long alsa_vol; - if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) >= 0) { - s->volume.values[i] = pa_sw_volume_from_dB(alsa_vol / 100.0); - continue; - } + if (u->hw_dB_supported) { + + if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; + + r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); + } else { + + if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; - u->hw_dB_supported = FALSE; + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + } } - if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + } else { + long alsa_vol; + + pa_assert(u->hw_dB_supported); + + if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0) goto fail; - s->volume.values[i] = (pa_volume_t) roundf(((float) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0)); + } + + pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r)); + + if (!pa_cvolume_equal(&u->hardware_volume, &r)) { + + u->hardware_volume = s->volume = r; + + if (u->hw_dB_supported) { + pa_cvolume reset; + + /* Hmm, so the hardware volume changed, let's reset our software volume */ + + pa_cvolume_reset(&reset, s->sample_spec.channels); + pa_source_set_soft_volume(s, &reset); + } } return 0; @@ -727,45 +758,90 @@ fail: static int source_set_volume_cb(pa_source *s) { struct userdata *u = s->userdata; int err; - int i; + unsigned i; + pa_cvolume r; pa_assert(u); pa_assert(u->mixer_elem); - for (i = 0; i < s->sample_spec.channels; i++) { - long alsa_vol; - pa_volume_t vol; + if (u->mixer_seperate_channels) { - pa_assert(snd_mixer_selem_has_capture_channel(u->mixer_elem, u->mixer_map[i])); + r.channels = s->sample_spec.channels; - vol = PA_MIN(s->volume.values[i], PA_VOLUME_NORM); + for (i = 0; i < s->sample_spec.channels; i++) { + long alsa_vol; + pa_volume_t vol; - if (u->hw_dB_supported) { - alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100); - alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max); + vol = s->volume.values[i]; + if (u->hw_dB_supported) { - if ((err = snd_mixer_selem_set_capture_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, -1)) >= 0) { + alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100); + alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max); - if (snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol) >= 0) - s->volume.values[i] = pa_sw_volume_from_dB(alsa_vol / 100.0); + if ((err = snd_mixer_selem_set_capture_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, 1)) < 0) + goto fail; - continue; - } + if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; + + r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); + } else { - u->hw_dB_supported = FALSE; + alsa_vol = (long) round(((double) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; + alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max); + + if ((err = snd_mixer_selem_set_capture_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0) + goto fail; + + if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; + + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + } } - alsa_vol = (long) roundf(((float) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; - alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max); + } else { + pa_volume_t vol; + long alsa_vol; + + pa_assert(u->hw_dB_supported); + + vol = pa_cvolume_max(&s->volume); - if ((err = snd_mixer_selem_set_capture_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0) + alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100); + alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max); + + if ((err = snd_mixer_selem_set_capture_dB_all(u->mixer_elem, alsa_vol, 1)) < 0) + goto fail; + + if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0) goto fail; - if (snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol) >= 0) - s->volume.values[i] = (pa_volume_t) roundf(((float) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + pa_cvolume_set(&r, s->volume.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0)); } + u->hardware_volume = r; + + if (u->hw_dB_supported) { + char t[PA_CVOLUME_SNPRINT_MAX]; + + /* Match exactly what the user requested by software */ + + pa_alsa_volume_divide(&r, &s->volume); + pa_source_set_soft_volume(s, &r); + + pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->volume)); + pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume)); + pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &r)); + + } else + + /* We can't match exactly what the user requested, hence let's + * at least tell the user about it */ + + s->volume = r; + return 0; fail: @@ -932,7 +1008,7 @@ int pa__init(pa_module*m) { const char *name; char *name_buf = NULL; pa_bool_t namereg_fail; - pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d, mixer_reset = TRUE; + pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d; pa_source_new_data data; snd_pcm_info_alloca(&pcm_info); @@ -988,11 +1064,6 @@ int pa__init(pa_module*m) { use_tsched = FALSE; } - if (pa_modargs_get_value_boolean(ma, "mixer_reset", &mixer_reset) < 0) { - pa_log("Failed to parse mixer_reset argument."); - goto fail; - } - u = pa_xnew0(struct userdata, 1); u->core = m->core; u->module = m; @@ -1146,6 +1217,8 @@ int pa__init(pa_module*m) { u->hw_dB_supported = FALSE; u->hw_dB_min = u->hw_dB_max = 0; u->hw_volume_min = u->hw_volume_max = 0; + u->mixer_seperate_channels = FALSE; + pa_cvolume_mute(&u->hardware_volume, u->source->sample_spec.channels); if (use_tsched) fix_tsched_watermark(u); @@ -1168,67 +1241,51 @@ int pa__init(pa_module*m) { if (u->mixer_handle) { pa_assert(u->mixer_elem); - if (snd_mixer_selem_has_capture_volume(u->mixer_elem)) - if (pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, FALSE) >= 0 && - snd_mixer_selem_get_capture_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) >= 0) { - - pa_bool_t suitable = TRUE; + if (snd_mixer_selem_has_capture_volume(u->mixer_elem)) { + pa_bool_t suitable = TRUE; + if (snd_mixer_selem_get_capture_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) < 0) { + pa_log_info("Failed to get volume range. Falling back to software volume control."); + suitable = FALSE; + } else { pa_log_info("Volume ranges from %li to %li.", u->hw_volume_min, u->hw_volume_max); + pa_assert(u->hw_volume_min < u->hw_volume_max); + } - if (u->hw_volume_min > u->hw_volume_max) { - - pa_log_info("Minimal volume %li larger than maximum volume %li. Strange stuff Falling back to software volume control.", u->hw_volume_min, u->hw_volume_max); - suitable = FALSE; - - } else if (u->hw_volume_max - u->hw_volume_min < 3) { - - pa_log_info("Device has less than 4 volume levels. Falling back to software volume control."); - suitable = FALSE; - - } else if (snd_mixer_selem_get_capture_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) >= 0) { - - pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); - - /* Let's see if this thing actually is useful for muting */ - if (u->hw_dB_min > -6000) { - pa_log_info("Device cannot attenuate for more than -60 dB (only %0.2f dB supported), falling back to software volume control.", ((double) u->hw_dB_min) / 100); - - suitable = FALSE; - } else if (u->hw_dB_max < 0) { - - pa_log_info("Device is still attenuated at maximum volume setting (%0.2f dB is maximum). Strange stuff. Falling back to software volume control.", ((double) u->hw_dB_max) / 100); - suitable = FALSE; - - } else if (u->hw_dB_min >= u->hw_dB_max) { - - pa_log_info("Minimal dB (%0.2f) larger or equal to maximum dB (%0.2f). Strange stuff. Falling back to software volume control.", ((double) u->hw_dB_min) / 100, ((double) u->hw_dB_max) / 100); - suitable = FALSE; + if (snd_mixer_selem_get_capture_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0) + pa_log_info("Mixer doesn't support dB information."); + else { + pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); + pa_assert(u->hw_dB_min < u->hw_dB_max); + u->hw_dB_supported = TRUE; + } - } else - u->hw_dB_supported = TRUE; - } + if (suitable && + !u->hw_dB_supported && + u->hw_volume_max - u->hw_volume_min < 3) { - if (suitable) { - u->source->get_volume = source_get_volume_cb; - u->source->set_volume = source_set_volume_cb; - u->source->flags |= PA_SOURCE_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SOURCE_DECIBEL_VOLUME : 0); - pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported"); + pa_log_info("Device has less than 4 volume levels. Falling back to software volume control."); + suitable = FALSE; + } - } else if (mixer_reset) { - pa_log_info("Using software volume control. Trying to reset sound card to 0 dB."); - pa_alsa_0dB_capture(u->mixer_elem); - } else - pa_log_info("Using software volume control. Leaving hw mixer controls untouched."); - } + if (suitable) { + u->mixer_seperate_channels = pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, FALSE) >= 0; + u->source->get_volume = source_get_volume_cb; + u->source->set_volume = source_set_volume_cb; + u->source->flags |= PA_SOURCE_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SOURCE_DECIBEL_VOLUME : 0); + pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported"); + } else + pa_log_info("Using software volume control."); + } if (snd_mixer_selem_has_capture_switch(u->mixer_elem)) { u->source->get_mute = source_get_mute_cb; u->source->set_mute = source_set_mute_cb; u->source->flags |= PA_SOURCE_HW_MUTE_CTRL; - } + } else + pa_log_info("Using software mute control."); u->mixer_fdl = pa_alsa_fdlist_new(); -- cgit From 5cc2187bec5923e13fb3958d57a5243aaa57b982 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 18 Aug 2008 19:55:55 +0200 Subject: add some code to make invalid valgrind warnings go away --- src/modules/module-alsa-source.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/modules/module-alsa-source.c') diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index 0e4efad5..9cf5aaf6 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -28,6 +28,10 @@ #include +#ifdef HAVE_VALGRIND_MEMCHECK_H +#include +#endif + #include #include #include @@ -710,6 +714,10 @@ static int source_get_volume_cb(pa_source *s) { if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) goto fail; +#ifdef HAVE_VALGRIND_MEMCHECK_H + VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol)); +#endif + r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); } else { @@ -728,6 +736,10 @@ static int source_get_volume_cb(pa_source *s) { if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0) goto fail; +#ifdef HAVE_VALGRIND_MEMCHECK_H + VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol)); +#endif + pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0)); } @@ -1255,6 +1267,11 @@ int pa__init(pa_module*m) { if (snd_mixer_selem_get_capture_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0) pa_log_info("Mixer doesn't support dB information."); else { +#ifdef HAVE_VALGRIND_MEMCHECK_H + VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_min, sizeof(u->hw_dB_min)); + VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max)); +#endif + pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); pa_assert(u->hw_dB_min < u->hw_dB_max); u->hw_dB_supported = TRUE; -- cgit From b7026bf248948a6a30386ddbcc137f48f369a51e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 19 Aug 2008 22:39:54 +0200 Subject: add a few more gcc warning flags and fix quite a few problems found by doing so --- src/modules/module-alsa-source.c | 55 ++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'src/modules/module-alsa-source.c') diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index 9cf5aaf6..54ffde57 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -141,7 +141,7 @@ static void fix_tsched_watermark(struct userdata *u) { size_t min_sleep, min_wakeup; pa_assert(u); - max_use = u->hwbuf_size - u->hwbuf_unused_frames * u->frame_size; + max_use = u->hwbuf_size - (size_t) u->hwbuf_unused_frames * u->frame_size; min_sleep = pa_usec_to_bytes(TSCHED_MIN_SLEEP_USEC, &u->source->sample_spec); min_wakeup = pa_usec_to_bytes(TSCHED_MIN_WAKEUP_USEC, &u->source->sample_spec); @@ -212,8 +212,8 @@ static int try_recover(struct userdata *u, const char *call, int err) { static size_t check_left_to_record(struct userdata *u, snd_pcm_sframes_t n) { size_t left_to_record; - if (n*u->frame_size < u->hwbuf_size) - left_to_record = u->hwbuf_size - (n*u->frame_size); + if ((size_t) n*u->frame_size < u->hwbuf_size) + left_to_record = u->hwbuf_size - ((size_t) n*u->frame_size); else left_to_record = 0; @@ -256,7 +256,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { if (PA_UNLIKELY((n = snd_pcm_avail_update(u->pcm_handle)) < 0)) { - if ((r = try_recover(u, "snd_pcm_avail_update", n)) == 0) + if ((r = try_recover(u, "snd_pcm_avail_update", (int) n)) == 0) continue; return r; @@ -277,6 +277,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { snd_pcm_uframes_t offset, frames = (snd_pcm_uframes_t) n; pa_memchunk chunk; void *p; + snd_pcm_sframes_t sframes; /* pa_log_debug("%lu frames to read", (unsigned long) frames); */ @@ -309,9 +310,9 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { pa_source_post(u->source, &chunk); pa_memblock_unref_fixed(chunk.memblock); - if (PA_UNLIKELY((err = snd_pcm_mmap_commit(u->pcm_handle, offset, frames)) < 0)) { + if (PA_UNLIKELY((sframes = snd_pcm_mmap_commit(u->pcm_handle, offset, frames)) < 0)) { - if ((r = try_recover(u, "snd_pcm_mmap_commit", err)) == 0) + if ((r = try_recover(u, "snd_pcm_mmap_commit", (int) sframes)) == 0) continue; return r; @@ -319,14 +320,14 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { work_done = 1; - u->frame_index += frames; + u->frame_index += (int64_t) frames; /* pa_log_debug("read %lu frames", (unsigned long) frames); */ if (frames >= (snd_pcm_uframes_t) n) break; - n -= frames; + n -= (snd_pcm_sframes_t) frames; } } @@ -353,7 +354,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec) { if (PA_UNLIKELY((n = snd_pcm_avail_update(u->pcm_handle)) < 0)) { - if ((r = try_recover(u, "snd_pcm_avail_update", n)) == 0) + if ((r = try_recover(u, "snd_pcm_avail_update", (int) n)) == 0) continue; return r; @@ -375,7 +376,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec) { chunk.memblock = pa_memblock_new(u->core->mempool, (size_t) -1); - frames = pa_memblock_get_length(chunk.memblock) / u->frame_size; + frames = (snd_pcm_sframes_t) (pa_memblock_get_length(chunk.memblock) / u->frame_size); if (frames > n) frames = n; @@ -383,7 +384,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec) { /* pa_log_debug("%lu frames to read", (unsigned long) n); */ p = pa_memblock_acquire(chunk.memblock); - frames = snd_pcm_readi(u->pcm_handle, (uint8_t*) p, frames); + frames = snd_pcm_readi(u->pcm_handle, (uint8_t*) p, (snd_pcm_uframes_t) frames); pa_memblock_release(chunk.memblock); pa_assert(frames != 0); @@ -391,14 +392,14 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec) { if (PA_UNLIKELY(frames < 0)) { pa_memblock_unref(chunk.memblock); - if ((r = try_recover(u, "snd_pcm_readi", n)) == 0) + if ((r = try_recover(u, "snd_pcm_readi", (int) (frames))) == 0) continue; return r; } chunk.index = 0; - chunk.length = frames * u->frame_size; + chunk.length = (size_t) frames * u->frame_size; pa_source_post(u->source, &chunk); pa_memblock_unref(chunk.memblock); @@ -442,7 +443,7 @@ static void update_smoother(struct userdata *u) { frames = u->frame_index + delay; now1 = pa_rtclock_usec(); - now2 = pa_bytes_to_usec(frames * u->frame_size, &u->source->sample_spec); + now2 = pa_bytes_to_usec((uint64_t) frames * u->frame_size, &u->source->sample_spec); pa_smoother_put(u->smoother, now1, now2); } @@ -457,7 +458,7 @@ static pa_usec_t source_get_latency(struct userdata *u) { now1 = pa_rtclock_usec(); now2 = pa_smoother_get(u->smoother, now1); - delay = (int64_t) now2 - pa_bytes_to_usec(u->frame_index * u->frame_size, &u->source->sample_spec); + delay = (int64_t) now2 - (int64_t) pa_bytes_to_usec((uint64_t) u->frame_index * u->frame_size, &u->source->sample_spec); if (delay > 0) r = (pa_usec_t) delay; @@ -522,9 +523,9 @@ static int update_sw_params(struct userdata *u) { if (PA_UNLIKELY(b < u->frame_size)) b = u->frame_size; - u->hwbuf_unused_frames = - PA_LIKELY(b < u->hwbuf_size) ? - ((u->hwbuf_size - b) / u->frame_size) : 0; + u->hwbuf_unused_frames = (snd_pcm_sframes_t) + (PA_LIKELY(b < u->hwbuf_size) ? + ((u->hwbuf_size - b) / u->frame_size) : 0); fix_tsched_watermark(u); } @@ -724,7 +725,7 @@ static int source_get_volume_cb(pa_source *s) { if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) goto fail; - r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (double) (u->hw_volume_max - u->hw_volume_min)); } } @@ -800,7 +801,7 @@ static int source_set_volume_cb(pa_source *s) { r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); } else { - alsa_vol = (long) round(((double) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; + alsa_vol = (long) round(((double) vol * (double) (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max); if ((err = snd_mixer_selem_set_capture_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0) @@ -809,7 +810,7 @@ static int source_set_volume_cb(pa_source *s) { if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) goto fail; - r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (double) (u->hw_volume_max - u->hw_volume_min)); } } @@ -1043,11 +1044,11 @@ int pa__init(pa_module*m) { frame_size = pa_frame_size(&ss); nfrags = m->core->default_n_fragments; - frag_size = pa_usec_to_bytes(m->core->default_fragment_size_msec*PA_USEC_PER_MSEC, &ss); + frag_size = (uint32_t) pa_usec_to_bytes(m->core->default_fragment_size_msec*PA_USEC_PER_MSEC, &ss); if (frag_size <= 0) - frag_size = frame_size; - tsched_size = pa_usec_to_bytes(DEFAULT_TSCHED_BUFFER_USEC, &ss); - tsched_watermark = pa_usec_to_bytes(DEFAULT_TSCHED_WATERMARK_USEC, &ss); + frag_size = (uint32_t) frame_size; + tsched_size = (uint32_t) pa_usec_to_bytes(DEFAULT_TSCHED_BUFFER_USEC, &ss); + tsched_watermark = (uint32_t) pa_usec_to_bytes(DEFAULT_TSCHED_WATERMARK_USEC, &ss); if (pa_modargs_get_value_u32(ma, "fragments", &nfrags) < 0 || pa_modargs_get_value_u32(ma, "fragment_size", &frag_size) < 0 || @@ -1220,7 +1221,7 @@ int pa__init(pa_module*m) { pa_source_set_rtpoll(u->source, u->rtpoll); u->frame_size = frame_size; - u->fragment_size = frag_size = period_frames * frame_size; + u->fragment_size = frag_size = (uint32_t) (period_frames * frame_size); u->nfragments = nfrags; u->hwbuf_size = u->fragment_size * nfrags; u->hwbuf_unused_frames = 0; @@ -1272,7 +1273,7 @@ int pa__init(pa_module*m) { VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max)); #endif - pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); + pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0); pa_assert(u->hw_dB_min < u->hw_dB_max); u->hw_dB_supported = TRUE; } -- cgit