[pulseaudio-discuss] [PATCH RFCv3 37/51] core: Make use of use inlineable macros
Peter Meerwald
pmeerw at pmeerw.net
Tue Nov 4 15:26:32 PST 2014
From: Peter Meerwald <p.meerwald at bct-electronic.com>
Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
src/modules/alsa/alsa-mixer.c | 4 +-
src/modules/alsa/alsa-sink.c | 58 ++++++++++++------------
src/modules/alsa/alsa-source.c | 50 ++++++++++-----------
src/modules/alsa/alsa-util.c | 32 +++++++-------
src/modules/echo-cancel/module-echo-cancel.c | 42 +++++++++---------
src/modules/echo-cancel/webrtc.cc | 10 ++---
src/pulse/context.c | 3 +-
src/pulse/stream.c | 21 ++++-----
src/pulsecore/memblockq.c | 5 ++-
src/pulsecore/protocol-native.c | 66 ++++++++++++++--------------
src/pulsecore/resampler.c | 8 ++--
src/pulsecore/sample-util.c | 8 ++--
src/pulsecore/sink-input.c | 2 +-
src/pulsecore/sink.c | 6 +--
src/pulsecore/source-output.c | 4 +-
15 files changed, 162 insertions(+), 157 deletions(-)
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 8b23d90..fd667ea 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -4375,8 +4375,8 @@ static snd_pcm_t* mapping_open_pcm(pa_alsa_mapping *m,
try_ss.channels = try_map.channels;
try_period_size =
- pa_usec_to_bytes(default_fragment_size_msec * PA_USEC_PER_MSEC, &try_ss) /
- pa_frame_size(&try_ss);
+ PA_USEC_TO_BYTES(default_fragment_size_msec * PA_USEC_PER_MSEC, &try_ss) /
+ PA_FRAME_SIZE(&try_ss);
try_buffer_size = default_n_fragments * try_period_size;
handle = pa_alsa_open_by_template(
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 3d1a8ed..3690d8d 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -300,10 +300,10 @@ static void fix_min_sleep_wakeup(struct userdata *u) {
max_use = u->hwbuf_size - u->hwbuf_unused;
max_use_2 = pa_frame_align(max_use/2, &u->sink->sample_spec);
- u->min_sleep = pa_usec_to_bytes(TSCHED_MIN_SLEEP_USEC, &u->sink->sample_spec);
+ u->min_sleep = PA_USEC_TO_BYTES(TSCHED_MIN_SLEEP_USEC, &u->sink->sample_spec);
u->min_sleep = PA_CLAMP(u->min_sleep, u->frame_size, max_use_2);
- u->min_wakeup = pa_usec_to_bytes(TSCHED_MIN_WAKEUP_USEC, &u->sink->sample_spec);
+ u->min_wakeup = PA_USEC_TO_BYTES(TSCHED_MIN_WAKEUP_USEC, &u->sink->sample_spec);
u->min_wakeup = PA_CLAMP(u->min_wakeup, u->frame_size, max_use_2);
}
@@ -320,7 +320,7 @@ static void fix_tsched_watermark(struct userdata *u) {
if (u->tsched_watermark < u->min_wakeup)
u->tsched_watermark = u->min_wakeup;
- u->tsched_watermark_usec = pa_bytes_to_usec(u->tsched_watermark, &u->sink->sample_spec);
+ u->tsched_watermark_usec = PA_BYTES_TO_USEC(u->tsched_watermark, &u->sink->sample_spec);
}
static void increase_watermark(struct userdata *u) {
@@ -407,7 +407,7 @@ static void hw_sleep_time(struct userdata *u, pa_usec_t *sleep_usec, pa_usec_t*p
usec = pa_sink_get_requested_latency_within_thread(u->sink);
if (usec == (pa_usec_t) -1)
- usec = pa_bytes_to_usec(u->hwbuf_size, &u->sink->sample_spec);
+ usec = PA_BYTES_TO_USEC(u->hwbuf_size, &u->sink->sample_spec);
wm = u->tsched_watermark_usec;
@@ -478,9 +478,9 @@ static size_t check_left_to_play(struct userdata *u, size_t n_bytes, bool on_tim
#ifdef DEBUG_TIMING
pa_log_debug("%0.2f ms left to play; inc threshold = %0.2f ms; dec threshold = %0.2f ms",
- (double) pa_bytes_to_usec(left_to_play, &u->sink->sample_spec) / PA_USEC_PER_MSEC,
- (double) pa_bytes_to_usec(u->watermark_inc_threshold, &u->sink->sample_spec) / PA_USEC_PER_MSEC,
- (double) pa_bytes_to_usec(u->watermark_dec_threshold, &u->sink->sample_spec) / PA_USEC_PER_MSEC);
+ (double) PA_BYTES_TO_USEC(left_to_play, &u->sink->sample_spec) / PA_USEC_PER_MSEC,
+ (double) PA_BYTES_TO_USEC(u->watermark_inc_threshold, &u->sink->sample_spec) / PA_USEC_PER_MSEC,
+ (double) PA_BYTES_TO_USEC(u->watermark_dec_threshold, &u->sink->sample_spec) / PA_USEC_PER_MSEC);
#endif
if (u->use_tsched) {
@@ -555,7 +555,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, bool polled, bo
* a single hw buffer length. */
if (!polled &&
- pa_bytes_to_usec(left_to_play, &u->sink->sample_spec) > process_usec+max_sleep_usec/2) {
+ PA_BYTES_TO_USEC(left_to_play, &u->sink->sample_spec) > process_usec+max_sleep_usec/2) {
#ifdef DEBUG_TIMING
pa_log_debug("Not filling up, because too early.");
#endif
@@ -678,7 +678,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, bool polled, bo
if (u->use_tsched) {
pa_usec_t underrun_sleep = pa_bytes_to_usec_round_up(input_underrun, &u->sink->sample_spec);
- *sleep_usec = pa_bytes_to_usec(left_to_play, &u->sink->sample_spec);
+ *sleep_usec = PA_BYTES_TO_USEC(left_to_play, &u->sink->sample_spec);
process_usec = u->tsched_watermark_usec;
if (*sleep_usec > process_usec)
@@ -737,7 +737,7 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, bool polled, bo
* a single hw buffer length. */
if (!polled &&
- pa_bytes_to_usec(left_to_play, &u->sink->sample_spec) > process_usec+max_sleep_usec/2)
+ PA_BYTES_TO_USEC(left_to_play, &u->sink->sample_spec) > process_usec+max_sleep_usec/2)
break;
if (PA_UNLIKELY(n_bytes <= u->hwbuf_unused)) {
@@ -832,7 +832,7 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec, bool polled, bo
if (u->use_tsched) {
pa_usec_t underrun_sleep = pa_bytes_to_usec_round_up(input_underrun, &u->sink->sample_spec);
- *sleep_usec = pa_bytes_to_usec(left_to_play, &u->sink->sample_spec);
+ *sleep_usec = PA_BYTES_TO_USEC(left_to_play, &u->sink->sample_spec);
process_usec = u->tsched_watermark_usec;
if (*sleep_usec > process_usec)
@@ -884,7 +884,7 @@ static void update_smoother(struct userdata *u) {
if (PA_UNLIKELY(position < 0))
position = 0;
- now2 = pa_bytes_to_usec((uint64_t) position, &u->sink->sample_spec);
+ now2 = PA_BYTES_TO_USEC((uint64_t) position, &u->sink->sample_spec);
pa_smoother_put(u->smoother, now1, now2);
@@ -903,12 +903,12 @@ static pa_usec_t sink_get_latency(struct userdata *u) {
now1 = pa_rtclock_now();
now2 = pa_smoother_get(u->smoother, now1);
- delay = (int64_t) pa_bytes_to_usec(u->write_count, &u->sink->sample_spec) - (int64_t) now2;
+ delay = (int64_t) PA_BYTES_TO_USEC(u->write_count, &u->sink->sample_spec) - (int64_t) now2;
r = delay >= 0 ? (pa_usec_t) delay : 0;
if (u->memchunk.memblock)
- r += pa_bytes_to_usec(u->memchunk.length, &u->sink->sample_spec);
+ r += PA_BYTES_TO_USEC(u->memchunk.length, &u->sink->sample_spec);
return r;
}
@@ -974,7 +974,7 @@ static int update_sw_params(struct userdata *u) {
pa_log_debug("Latency set to %0.2fms", (double) latency / PA_USEC_PER_MSEC);
- b = pa_usec_to_bytes(latency, &u->sink->sample_spec);
+ b = PA_USEC_TO_BYTES(latency, &u->sink->sample_spec);
/* We need at least one sample in our buffer */
@@ -997,7 +997,7 @@ static int update_sw_params(struct userdata *u) {
pa_usec_t sleep_usec, process_usec;
hw_sleep_time(u, &sleep_usec, &process_usec);
- avail_min += pa_usec_to_bytes(sleep_usec, &u->sink->sample_spec) / u->frame_size;
+ avail_min += PA_USEC_TO_BYTES(sleep_usec, &u->sink->sample_spec) / u->frame_size;
}
pa_log_debug("setting avail_min=%lu", (unsigned long) avail_min);
@@ -1024,8 +1024,8 @@ static void reset_watermark(struct userdata *u, size_t tsched_watermark, pa_samp
u->tsched_watermark = pa_usec_to_bytes_round_up(pa_bytes_to_usec_round_up(tsched_watermark, ss),
&u->sink->sample_spec);
- u->watermark_inc_step = pa_usec_to_bytes(TSCHED_WATERMARK_INC_STEP_USEC, &u->sink->sample_spec);
- u->watermark_dec_step = pa_usec_to_bytes(TSCHED_WATERMARK_DEC_STEP_USEC, &u->sink->sample_spec);
+ u->watermark_inc_step = PA_USEC_TO_BYTES(TSCHED_WATERMARK_INC_STEP_USEC, &u->sink->sample_spec);
+ u->watermark_dec_step = PA_USEC_TO_BYTES(TSCHED_WATERMARK_DEC_STEP_USEC, &u->sink->sample_spec);
u->watermark_inc_threshold = pa_usec_to_bytes_round_up(TSCHED_WATERMARK_INC_THRESHOLD_USEC, &u->sink->sample_spec);
u->watermark_dec_threshold = pa_usec_to_bytes_round_up(TSCHED_WATERMARK_DEC_THRESHOLD_USEC, &u->sink->sample_spec);
@@ -1036,11 +1036,11 @@ static void reset_watermark(struct userdata *u, size_t tsched_watermark, pa_samp
if (in_thread)
pa_sink_set_latency_range_within_thread(u->sink,
u->min_latency_ref,
- pa_bytes_to_usec(u->hwbuf_size, ss));
+ PA_BYTES_TO_USEC(u->hwbuf_size, ss));
else {
pa_sink_set_latency_range(u->sink,
0,
- pa_bytes_to_usec(u->hwbuf_size, ss));
+ PA_BYTES_TO_USEC(u->hwbuf_size, ss));
/* work-around assert in pa_sink_set_latency_within_thead,
keep track of min_latency and reuse it when
@@ -2049,14 +2049,14 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
goto fail;
}
- frame_size = pa_frame_size(&ss);
+ frame_size = PA_FRAME_SIZE(&ss);
nfrags = m->core->default_n_fragments;
- frag_size = (uint32_t) 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 = (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);
+ 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 ||
@@ -2087,7 +2087,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
goto fail;
}
- rewind_safeguard = PA_MAX(DEFAULT_REWIND_SAFEGUARD_BYTES, pa_usec_to_bytes(DEFAULT_REWIND_SAFEGUARD_USEC, &ss));
+ rewind_safeguard = PA_MAX(DEFAULT_REWIND_SAFEGUARD_BYTES, PA_USEC_TO_BYTES(DEFAULT_REWIND_SAFEGUARD_USEC, &ss));
if (pa_modargs_get_value_u32(ma, "rewind_safeguard", &rewind_safeguard) < 0) {
pa_log("Failed to parse rewind_safeguard argument");
goto fail;
@@ -2237,7 +2237,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
}
/* ALSA might tweak the sample spec, so recalculate the frame size */
- frame_size = pa_frame_size(&ss);
+ frame_size = PA_FRAME_SIZE(&ss);
if (!u->ucm_context)
find_mixer(u, mapping, pa_modargs_get_value(ma, "control", NULL), ignore_dB);
@@ -2338,9 +2338,9 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
pa_log_info("Using %0.1f fragments of size %lu bytes (%0.2fms), buffer size is %lu bytes (%0.2fms)",
(double) u->hwbuf_size / (double) u->fragment_size,
(long unsigned) u->fragment_size,
- (double) pa_bytes_to_usec(u->fragment_size, &ss) / PA_USEC_PER_MSEC,
+ (double) PA_BYTES_TO_USEC(u->fragment_size, &ss) / PA_USEC_PER_MSEC,
(long unsigned) u->hwbuf_size,
- (double) pa_bytes_to_usec(u->hwbuf_size, &ss) / PA_USEC_PER_MSEC);
+ (double) PA_BYTES_TO_USEC(u->hwbuf_size, &ss) / PA_USEC_PER_MSEC);
pa_sink_set_max_request(u->sink, u->hwbuf_size);
if (pa_alsa_pcm_is_hw(u->pcm_handle))
@@ -2354,7 +2354,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
u->tsched_watermark_ref = tsched_watermark;
reset_watermark(u, u->tsched_watermark_ref, &ss, false);
} else
- pa_sink_set_fixed_latency(u->sink, pa_bytes_to_usec(u->hwbuf_size, &ss));
+ pa_sink_set_fixed_latency(u->sink, PA_BYTES_TO_USEC(u->hwbuf_size, &ss));
reserve_update(u);
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index 4c7459a..f82f811 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -275,10 +275,10 @@ static void fix_min_sleep_wakeup(struct userdata *u) {
max_use = u->hwbuf_size - u->hwbuf_unused;
max_use_2 = pa_frame_align(max_use/2, &u->source->sample_spec);
- u->min_sleep = pa_usec_to_bytes(TSCHED_MIN_SLEEP_USEC, &u->source->sample_spec);
+ u->min_sleep = PA_USEC_TO_BYTES(TSCHED_MIN_SLEEP_USEC, &u->source->sample_spec);
u->min_sleep = PA_CLAMP(u->min_sleep, u->frame_size, max_use_2);
- u->min_wakeup = pa_usec_to_bytes(TSCHED_MIN_WAKEUP_USEC, &u->source->sample_spec);
+ u->min_wakeup = PA_USEC_TO_BYTES(TSCHED_MIN_WAKEUP_USEC, &u->source->sample_spec);
u->min_wakeup = PA_CLAMP(u->min_wakeup, u->frame_size, max_use_2);
}
@@ -295,7 +295,7 @@ static void fix_tsched_watermark(struct userdata *u) {
if (u->tsched_watermark < u->min_wakeup)
u->tsched_watermark = u->min_wakeup;
- u->tsched_watermark_usec = pa_bytes_to_usec(u->tsched_watermark, &u->source->sample_spec);
+ u->tsched_watermark_usec = PA_BYTES_TO_USEC(u->tsched_watermark, &u->source->sample_spec);
}
static void increase_watermark(struct userdata *u) {
@@ -382,7 +382,7 @@ static void hw_sleep_time(struct userdata *u, pa_usec_t *sleep_usec, pa_usec_t*p
usec = pa_source_get_requested_latency_within_thread(u->source);
if (usec == (pa_usec_t) -1)
- usec = pa_bytes_to_usec(u->hwbuf_size, &u->source->sample_spec);
+ usec = PA_BYTES_TO_USEC(u->hwbuf_size, &u->source->sample_spec);
wm = u->tsched_watermark_usec;
@@ -451,7 +451,7 @@ static size_t check_left_to_record(struct userdata *u, size_t n_bytes, bool on_t
}
#ifdef DEBUG_TIMING
- pa_log_debug("%0.2f ms left to record", (double) pa_bytes_to_usec(left_to_record, &u->source->sample_spec) / PA_USEC_PER_MSEC);
+ pa_log_debug("%0.2f ms left to record", (double) PA_BYTES_TO_USEC(left_to_record, &u->source->sample_spec) / PA_USEC_PER_MSEC);
#endif
if (u->use_tsched) {
@@ -514,7 +514,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, bool polled, boo
if (u->use_tsched)
if (!polled &&
- pa_bytes_to_usec(left_to_record, &u->source->sample_spec) > process_usec+max_sleep_usec/2) {
+ PA_BYTES_TO_USEC(left_to_record, &u->source->sample_spec) > process_usec+max_sleep_usec/2) {
#ifdef DEBUG_TIMING
pa_log_debug("Not reading, because too early.");
#endif
@@ -626,7 +626,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, bool polled, boo
}
if (u->use_tsched) {
- *sleep_usec = pa_bytes_to_usec(left_to_record, &u->source->sample_spec);
+ *sleep_usec = PA_BYTES_TO_USEC(left_to_record, &u->source->sample_spec);
process_usec = u->tsched_watermark_usec;
if (*sleep_usec > process_usec)
@@ -670,7 +670,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec, bool polled, boo
if (u->use_tsched)
if (!polled &&
- pa_bytes_to_usec(left_to_record, &u->source->sample_spec) > process_usec+max_sleep_usec/2)
+ PA_BYTES_TO_USEC(left_to_record, &u->source->sample_spec) > process_usec+max_sleep_usec/2)
break;
if (PA_UNLIKELY(n_bytes <= 0)) {
@@ -756,7 +756,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec, bool polled, boo
}
if (u->use_tsched) {
- *sleep_usec = pa_bytes_to_usec(left_to_record, &u->source->sample_spec);
+ *sleep_usec = PA_BYTES_TO_USEC(left_to_record, &u->source->sample_spec);
process_usec = u->tsched_watermark_usec;
if (*sleep_usec > process_usec)
@@ -801,7 +801,7 @@ static void update_smoother(struct userdata *u) {
return;
position = u->read_count + ((uint64_t) delay * (uint64_t) u->frame_size);
- now2 = pa_bytes_to_usec(position, &u->source->sample_spec);
+ now2 = PA_BYTES_TO_USEC(position, &u->source->sample_spec);
pa_smoother_put(u->smoother, now1, now2);
@@ -819,7 +819,7 @@ static pa_usec_t source_get_latency(struct userdata *u) {
now1 = pa_rtclock_now();
now2 = pa_smoother_get(u->smoother, now1);
- delay = (int64_t) now2 - (int64_t) pa_bytes_to_usec(u->read_count, &u->source->sample_spec);
+ delay = (int64_t) now2 - (int64_t) PA_BYTES_TO_USEC(u->read_count, &u->source->sample_spec);
return delay >= 0 ? (pa_usec_t) delay : 0;
}
@@ -876,7 +876,7 @@ static int update_sw_params(struct userdata *u) {
pa_log_debug("latency set to %0.2fms", (double) latency / PA_USEC_PER_MSEC);
- b = pa_usec_to_bytes(latency, &u->source->sample_spec);
+ b = PA_USEC_TO_BYTES(latency, &u->source->sample_spec);
/* We need at least one sample in our buffer */
@@ -898,7 +898,7 @@ static int update_sw_params(struct userdata *u) {
pa_usec_t sleep_usec, process_usec;
hw_sleep_time(u, &sleep_usec, &process_usec);
- avail_min += pa_usec_to_bytes(sleep_usec, &u->source->sample_spec) / u->frame_size;
+ avail_min += PA_USEC_TO_BYTES(sleep_usec, &u->source->sample_spec) / u->frame_size;
}
pa_log_debug("setting avail_min=%lu", (unsigned long) avail_min);
@@ -917,8 +917,8 @@ static void reset_watermark(struct userdata *u, size_t tsched_watermark, pa_samp
u->tsched_watermark = pa_usec_to_bytes_round_up(pa_bytes_to_usec_round_up(tsched_watermark, ss),
&u->source->sample_spec);
- u->watermark_inc_step = pa_usec_to_bytes(TSCHED_WATERMARK_INC_STEP_USEC, &u->source->sample_spec);
- u->watermark_dec_step = pa_usec_to_bytes(TSCHED_WATERMARK_DEC_STEP_USEC, &u->source->sample_spec);
+ u->watermark_inc_step = PA_USEC_TO_BYTES(TSCHED_WATERMARK_INC_STEP_USEC, &u->source->sample_spec);
+ u->watermark_dec_step = PA_USEC_TO_BYTES(TSCHED_WATERMARK_DEC_STEP_USEC, &u->source->sample_spec);
u->watermark_inc_threshold = pa_usec_to_bytes_round_up(TSCHED_WATERMARK_INC_THRESHOLD_USEC, &u->source->sample_spec);
u->watermark_dec_threshold = pa_usec_to_bytes_round_up(TSCHED_WATERMARK_DEC_THRESHOLD_USEC, &u->source->sample_spec);
@@ -929,11 +929,11 @@ static void reset_watermark(struct userdata *u, size_t tsched_watermark, pa_samp
if (in_thread)
pa_source_set_latency_range_within_thread(u->source,
u->min_latency_ref,
- pa_bytes_to_usec(u->hwbuf_size, ss));
+ PA_BYTES_TO_USEC(u->hwbuf_size, ss));
else {
pa_source_set_latency_range(u->source,
0,
- pa_bytes_to_usec(u->hwbuf_size, ss));
+ PA_BYTES_TO_USEC(u->hwbuf_size, ss));
/* work-around assert in pa_source_set_latency_within_thead,
keep track of min_latency and reuse it when
@@ -1766,14 +1766,14 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
goto fail;
}
- frame_size = pa_frame_size(&ss);
+ frame_size = PA_FRAME_SIZE(&ss);
nfrags = m->core->default_n_fragments;
- frag_size = (uint32_t) 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 = (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);
+ 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 ||
@@ -1943,7 +1943,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
}
/* ALSA might tweak the sample spec, so recalculate the frame size */
- frame_size = pa_frame_size(&ss);
+ frame_size = PA_FRAME_SIZE(&ss);
if (!u->ucm_context)
find_mixer(u, mapping, pa_modargs_get_value(ma, "control", NULL), ignore_dB);
@@ -2043,16 +2043,16 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
pa_log_info("Using %0.1f fragments of size %lu bytes (%0.2fms), buffer size is %lu bytes (%0.2fms)",
(double) u->hwbuf_size / (double) u->fragment_size,
(long unsigned) u->fragment_size,
- (double) pa_bytes_to_usec(u->fragment_size, &ss) / PA_USEC_PER_MSEC,
+ (double) PA_BYTES_TO_USEC(u->fragment_size, &ss) / PA_USEC_PER_MSEC,
(long unsigned) u->hwbuf_size,
- (double) pa_bytes_to_usec(u->hwbuf_size, &ss) / PA_USEC_PER_MSEC);
+ (double) PA_BYTES_TO_USEC(u->hwbuf_size, &ss) / PA_USEC_PER_MSEC);
if (u->use_tsched) {
u->tsched_watermark_ref = tsched_watermark;
reset_watermark(u, u->tsched_watermark_ref, &ss, false);
}
else
- pa_source_set_fixed_latency(u->source, pa_bytes_to_usec(u->hwbuf_size, &ss));
+ pa_source_set_fixed_latency(u->source, PA_BYTES_TO_USEC(u->hwbuf_size, &ss));
reserve_update(u);
diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index 0563c00..9263b0a 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -1125,24 +1125,24 @@ snd_pcm_sframes_t pa_alsa_safe_avail(snd_pcm_t *pcm, size_t hwbuf_size, const pa
if (n <= 0)
return n;
- k = (size_t) n * pa_frame_size(ss);
+ k = (size_t) n * PA_FRAME_SIZE(ss);
if (PA_UNLIKELY(k >= hwbuf_size * 5 ||
- k >= pa_bytes_per_second(ss)*10)) {
+ k >= PA_BYTES_PER_SECOND(ss)*10)) {
PA_ONCE_BEGIN {
char *dn = pa_alsa_get_driver_name_by_pcm(pcm);
pa_log(_("snd_pcm_avail() returned a value that is exceptionally large: %lu bytes (%lu ms).\n"
"Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers."),
(unsigned long) k,
- (unsigned long) (pa_bytes_to_usec(k, ss) / PA_USEC_PER_MSEC),
+ (unsigned long) (PA_BYTES_TO_USEC(k, ss) / PA_USEC_PER_MSEC),
pa_strnull(dn));
pa_xfree(dn);
pa_alsa_dump(PA_LOG_ERROR, pcm);
} PA_ONCE_END;
/* Mhmm, let's try not to fail completely */
- n = (snd_pcm_sframes_t) (hwbuf_size / pa_frame_size(ss));
+ n = (snd_pcm_sframes_t) (hwbuf_size / PA_FRAME_SIZE(ss));
}
return n;
@@ -1173,12 +1173,12 @@ int pa_alsa_safe_delay(snd_pcm_t *pcm, snd_pcm_status_t *status, snd_pcm_sframes
avail = snd_pcm_status_get_avail(status);
*delay = snd_pcm_status_get_delay(status);
- k = (ssize_t) *delay * (ssize_t) pa_frame_size(ss);
+ k = (ssize_t) *delay * (ssize_t) PA_FRAME_SIZE(ss);
abs_k = k >= 0 ? (size_t) k : (size_t) -k;
if (PA_UNLIKELY(abs_k >= hwbuf_size * 5 ||
- abs_k >= pa_bytes_per_second(ss)*10)) {
+ abs_k >= PA_BYTES_PER_SECOND(ss)*10)) {
PA_ONCE_BEGIN {
char *dn = pa_alsa_get_driver_name_by_pcm(pcm);
@@ -1186,7 +1186,7 @@ int pa_alsa_safe_delay(snd_pcm_t *pcm, snd_pcm_status_t *status, snd_pcm_sframes
"Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers."),
(signed long) k,
k < 0 ? "-" : "",
- (unsigned long) (pa_bytes_to_usec(abs_k, ss) / PA_USEC_PER_MSEC),
+ (unsigned long) (PA_BYTES_TO_USEC(abs_k, ss) / PA_USEC_PER_MSEC),
pa_strnull(dn));
pa_xfree(dn);
pa_alsa_dump(PA_LOG_ERROR, pcm);
@@ -1194,30 +1194,30 @@ int pa_alsa_safe_delay(snd_pcm_t *pcm, snd_pcm_status_t *status, snd_pcm_sframes
/* Mhmm, let's try not to fail completely */
if (k < 0)
- *delay = -(snd_pcm_sframes_t) (hwbuf_size / pa_frame_size(ss));
+ *delay = -(snd_pcm_sframes_t) (hwbuf_size / PA_FRAME_SIZE(ss));
else
- *delay = (snd_pcm_sframes_t) (hwbuf_size / pa_frame_size(ss));
+ *delay = (snd_pcm_sframes_t) (hwbuf_size / PA_FRAME_SIZE(ss));
}
if (capture) {
- abs_k = (size_t) avail * pa_frame_size(ss);
+ abs_k = (size_t) avail * PA_FRAME_SIZE(ss);
if (PA_UNLIKELY(abs_k >= hwbuf_size * 5 ||
- abs_k >= pa_bytes_per_second(ss)*10)) {
+ abs_k >= PA_BYTES_PER_SECOND(ss)*10)) {
PA_ONCE_BEGIN {
char *dn = pa_alsa_get_driver_name_by_pcm(pcm);
pa_log(_("snd_pcm_avail() returned a value that is exceptionally large: %lu bytes (%lu ms).\n"
"Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers."),
(unsigned long) k,
- (unsigned long) (pa_bytes_to_usec(k, ss) / PA_USEC_PER_MSEC),
+ (unsigned long) (PA_BYTES_TO_USEC(k, ss) / PA_USEC_PER_MSEC),
pa_strnull(dn));
pa_xfree(dn);
pa_alsa_dump(PA_LOG_ERROR, pcm);
} PA_ONCE_END;
/* Mhmm, let's try not to fail completely */
- avail = (snd_pcm_sframes_t) (hwbuf_size / pa_frame_size(ss));
+ avail = (snd_pcm_sframes_t) (hwbuf_size / PA_FRAME_SIZE(ss));
}
if (PA_UNLIKELY(*delay < avail)) {
@@ -1259,17 +1259,17 @@ int pa_alsa_safe_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas
if (r < 0)
return r;
- k = (size_t) *frames * pa_frame_size(ss);
+ k = (size_t) *frames * PA_FRAME_SIZE(ss);
if (PA_UNLIKELY(*frames > before ||
k >= hwbuf_size * 3 ||
- k >= pa_bytes_per_second(ss)*10))
+ k >= PA_BYTES_PER_SECOND(ss)*10))
PA_ONCE_BEGIN {
char *dn = pa_alsa_get_driver_name_by_pcm(pcm);
pa_log(_("snd_pcm_mmap_begin() returned a value that is exceptionally large: %lu bytes (%lu ms).\n"
"Most likely this is a bug in the ALSA driver '%s'. Please report this issue to the ALSA developers."),
(unsigned long) k,
- (unsigned long) (pa_bytes_to_usec(k, ss) / PA_USEC_PER_MSEC),
+ (unsigned long) (PA_BYTES_TO_USEC(k, ss) / PA_USEC_PER_MSEC),
pa_strnull(dn));
pa_xfree(dn);
pa_alsa_dump(PA_LOG_ERROR, pcm);
diff --git a/src/modules/echo-cancel/module-echo-cancel.c b/src/modules/echo-cancel/module-echo-cancel.c
index c755119..b5e7a8f 100644
--- a/src/modules/echo-cancel/module-echo-cancel.c
+++ b/src/modules/echo-cancel/module-echo-cancel.c
@@ -300,20 +300,20 @@ static int64_t calc_diff(struct userdata *u, struct snapshot *snapshot) {
pa_usec_t plen, rlen, source_delay, sink_delay, recv_counter, send_counter;
/* get latency difference between playback and record */
- plen = pa_bytes_to_usec(snapshot->plen, &u->sink_input->sample_spec);
- rlen = pa_bytes_to_usec(snapshot->rlen, &u->source_output->sample_spec);
+ plen = PA_BYTES_TO_USEC(snapshot->plen, &u->sink_input->sample_spec);
+ rlen = PA_BYTES_TO_USEC(snapshot->rlen, &u->source_output->sample_spec);
if (plen > rlen)
buffer_latency = plen - rlen;
else
buffer_latency = 0;
- source_delay = pa_bytes_to_usec(snapshot->source_delay, &u->source_output->sample_spec);
- sink_delay = pa_bytes_to_usec(snapshot->sink_delay, &u->sink_input->sample_spec);
+ source_delay = PA_BYTES_TO_USEC(snapshot->source_delay, &u->source_output->sample_spec);
+ sink_delay = PA_BYTES_TO_USEC(snapshot->sink_delay, &u->sink_input->sample_spec);
buffer_latency += source_delay + sink_delay;
/* add the latency difference due to samples not yet transferred */
- send_counter = pa_bytes_to_usec(snapshot->send_counter, &u->sink->sample_spec);
- recv_counter = pa_bytes_to_usec(snapshot->recv_counter, &u->sink->sample_spec);
+ send_counter = PA_BYTES_TO_USEC(snapshot->send_counter, &u->sink->sample_spec);
+ recv_counter = PA_BYTES_TO_USEC(snapshot->recv_counter, &u->sink->sample_spec);
if (recv_counter <= send_counter)
buffer_latency += (int64_t) (send_counter - recv_counter);
else
@@ -356,7 +356,7 @@ static void time_callback(pa_mainloop_api *a, pa_time_event *e, const struct tim
/* calculate drift between capture and playback */
diff_time = calc_diff(u, &latency_snapshot);
- /*fs = pa_frame_size(&u->source_output->sample_spec);*/
+ /* fs = PA_FRAME_SIZE(&u->source_output->sample_spec); */
old_rate = u->sink_input->sample_spec.rate;
base_rate = u->source_output->sample_spec.rate;
@@ -365,7 +365,7 @@ static void time_callback(pa_mainloop_api *a, pa_time_event *e, const struct tim
* canceller does not work in this case. */
pa_asyncmsgq_post(u->asyncmsgq, PA_MSGOBJECT(u->source_output), SOURCE_OUTPUT_MESSAGE_APPLY_DIFF_TIME,
NULL, diff_time, NULL, NULL);
- /*new_rate = base_rate - ((pa_usec_to_bytes(-diff_time, &u->source_output->sample_spec) / fs) * PA_USEC_PER_SEC) / u->adjust_time;*/
+ /*new_rate = base_rate - ((PA_USEC_TO_BYTES(-diff_time, &u->source_output->sample_spec) / fs) * PA_USEC_PER_SEC) / u->adjust_time;*/
new_rate = base_rate;
}
else {
@@ -376,7 +376,7 @@ static void time_callback(pa_mainloop_api *a, pa_time_event *e, const struct tim
}
/* recording behind playback, we need to slowly adjust the rate to match */
- /*new_rate = base_rate + ((pa_usec_to_bytes(diff_time, &u->source_output->sample_spec) / fs) * PA_USEC_PER_SEC) / u->adjust_time;*/
+ /*new_rate = base_rate + ((PA_USEC_TO_BYTES(diff_time, &u->source_output->sample_spec) / fs) * PA_USEC_PER_SEC) / u->adjust_time;*/
/* assume equal samplerates for now */
new_rate = base_rate;
@@ -417,9 +417,9 @@ static int source_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t
/* Get the latency of the master source */
pa_source_get_latency_within_thread(u->source_output->source) +
/* Add the latency internal to our source output on top */
- pa_bytes_to_usec(pa_memblockq_get_length(u->source_output->thread_info.delay_memblockq), &u->source_output->source->sample_spec) +
+ PA_BYTES_TO_USEC(pa_memblockq_get_length(u->source_output->thread_info.delay_memblockq), &u->source_output->source->sample_spec) +
/* and the buffering we do on the source */
- pa_bytes_to_usec(u->source_output_blocksize, &u->source_output->source->sample_spec);
+ PA_BYTES_TO_USEC(u->source_output_blocksize, &u->source_output->source->sample_spec);
return 0;
@@ -454,7 +454,7 @@ static int sink_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t of
pa_sink_get_latency_within_thread(u->sink_input->sink) +
/* Add the latency internal to our sink input on top */
- pa_bytes_to_usec(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
+ PA_BYTES_TO_USEC(pa_memblockq_get_length(u->sink_input->thread_info.render_memblockq), &u->sink_input->sink->sample_spec);
return 0;
}
@@ -651,12 +651,12 @@ static void apply_diff_time(struct userdata *u, int64_t diff_time) {
int64_t diff;
if (diff_time < 0) {
- diff = pa_usec_to_bytes(-diff_time, &u->sink_input->sample_spec);
+ diff = PA_USEC_TO_BYTES(-diff_time, &u->sink_input->sample_spec);
if (diff > 0) {
/* add some extra safety samples to compensate for jitter in the
* timings */
- diff += 10 * pa_frame_size (&u->sink_input->sample_spec);
+ diff += 10 * PA_FRAME_SIZE(&u->sink_input->sample_spec);
pa_log("Playback after capture (%lld), drop sink %lld", (long long) diff_time, (long long) diff);
@@ -664,7 +664,7 @@ static void apply_diff_time(struct userdata *u, int64_t diff_time) {
u->source_skip = 0;
}
} else if (diff_time > 0) {
- diff = pa_usec_to_bytes(diff_time, &u->source_output->sample_spec);
+ diff = PA_USEC_TO_BYTES(diff_time, &u->source_output->sample_spec);
if (diff > 0) {
pa_log("Playback too far ahead (%lld), drop source %lld", (long long) diff_time, (long long) diff);
@@ -1749,9 +1749,9 @@ int pa__init(pa_module*m) {
pa_assert(source_output_ss.rate == source_ss.rate);
pa_assert(sink_ss.rate == source_ss.rate);
- u->source_output_blocksize = nframes * pa_frame_size(&source_output_ss);
- u->source_blocksize = nframes * pa_frame_size(&source_ss);
- u->sink_blocksize = nframes * pa_frame_size(&sink_ss);
+ u->source_output_blocksize = nframes * PA_FRAME_SIZE(&source_output_ss);
+ u->source_blocksize = nframes * PA_FRAME_SIZE(&source_ss);
+ u->sink_blocksize = nframes * PA_FRAME_SIZE(&sink_ss);
if (u->ec->params.drift_compensation)
pa_assert(u->ec->set_drift);
@@ -2142,9 +2142,9 @@ int main(int argc, char* argv[]) {
pa_log("Failed to init AEC engine");
goto fail;
}
- u.source_output_blocksize = nframes * pa_frame_size(&source_output_ss);
- u.source_blocksize = nframes * pa_frame_size(&source_ss);
- u.sink_blocksize = nframes * pa_frame_size(&sink_ss);
+ u.source_output_blocksize = nframes * PA_FRAME_SIZE(&source_output_ss);
+ u.source_blocksize = nframes * PA_FRAME_SIZE(&source_ss);
+ u.sink_blocksize = nframes * PA_FRAME_SIZE(&sink_ss);
if (u.ec->params.drift_compensation) {
if (argc < 6) {
diff --git a/src/modules/echo-cancel/webrtc.cc b/src/modules/echo-cancel/webrtc.cc
index b1a7891..88c1af2 100644
--- a/src/modules/echo-cancel/webrtc.cc
+++ b/src/modules/echo-cancel/webrtc.cc
@@ -217,8 +217,8 @@ bool pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
ec->params.priv.webrtc.apm = apm;
ec->params.priv.webrtc.sample_spec = *out_ss;
- ec->params.priv.webrtc.blocksize = (uint64_t)pa_bytes_per_second(out_ss) * BLOCK_SIZE_US / PA_USEC_PER_SEC;
- *nframes = ec->params.priv.webrtc.blocksize / pa_frame_size(out_ss);
+ ec->params.priv.webrtc.blocksize = (uint64_t)PA_BYTES_PER_SECOND(out_ss) * BLOCK_SIZE_US / PA_USEC_PER_SEC;
+ *nframes = ec->params.priv.webrtc.blocksize / PA_FRAME_SIZE(out_ss);
pa_modargs_free(ma);
return true;
@@ -239,7 +239,7 @@ void pa_webrtc_ec_play(pa_echo_canceller *ec, const uint8_t *play) {
play_frame._audioChannel = ss->channels;
play_frame._frequencyInHz = ss->rate;
- play_frame._payloadDataLengthInSamples = ec->params.priv.webrtc.blocksize / pa_frame_size(ss);
+ play_frame._payloadDataLengthInSamples = ec->params.priv.webrtc.blocksize / PA_FRAME_SIZE(ss);
memcpy(play_frame._payloadData, play, ec->params.priv.webrtc.blocksize);
apm->AnalyzeReverseStream(&play_frame);
@@ -253,7 +253,7 @@ void pa_webrtc_ec_record(pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out
out_frame._audioChannel = ss->channels;
out_frame._frequencyInHz = ss->rate;
- out_frame._payloadDataLengthInSamples = ec->params.priv.webrtc.blocksize / pa_frame_size(ss);
+ out_frame._payloadDataLengthInSamples = ec->params.priv.webrtc.blocksize / PA_FRAME_SIZE(ss);
memcpy(out_frame._payloadData, rec, ec->params.priv.webrtc.blocksize);
if (ec->params.priv.webrtc.agc) {
@@ -277,7 +277,7 @@ void pa_webrtc_ec_set_drift(pa_echo_canceller *ec, float drift) {
webrtc::AudioProcessing *apm = (webrtc::AudioProcessing*)ec->params.priv.webrtc.apm;
const pa_sample_spec *ss = &ec->params.priv.webrtc.sample_spec;
- apm->echo_cancellation()->set_stream_drift_samples(drift * ec->params.priv.webrtc.blocksize / pa_frame_size(ss));
+ apm->echo_cancellation()->set_stream_drift_samples(drift * ec->params.priv.webrtc.blocksize / PA_FRAME_SIZE(ss));
}
void pa_webrtc_ec_run(pa_echo_canceller *ec, const uint8_t *rec, const uint8_t *play, uint8_t *out) {
diff --git a/src/pulse/context.c b/src/pulse/context.c
index 6f857ce..6157481 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -59,6 +59,7 @@
#include <pulsecore/pstream-util.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h>
+#include <pulsecore/sample-util.h>
#include <pulsecore/log.h>
#include <pulsecore/socket.h>
#include <pulsecore/creds.h>
@@ -1559,7 +1560,7 @@ size_t pa_context_get_tile_size(pa_context *c, const pa_sample_spec *ss) {
PA_CHECK_VALIDITY_RETURN_ANY(c, !pa_detect_fork(), PA_ERR_FORKED, (size_t) -1);
PA_CHECK_VALIDITY_RETURN_ANY(c, !ss || pa_sample_spec_valid(ss), PA_ERR_INVALID, (size_t) -1);
- fs = ss ? pa_frame_size(ss) : 1;
+ fs = ss ? PA_FRAME_SIZE(ss) : 1;
mbs = PA_ROUND_DOWN(pa_mempool_block_size_max(c->mempool), fs);
return PA_MAX(mbs, fs);
}
diff --git a/src/pulse/stream.c b/src/pulse/stream.c
index 408e569..e650c79 100644
--- a/src/pulse/stream.c
+++ b/src/pulse/stream.c
@@ -40,6 +40,7 @@
#include <pulsecore/macro.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h>
+#include <pulsecore/sample-util.h>
#include "internal.h"
#include "stream.h"
@@ -151,7 +152,7 @@ static pa_stream *pa_stream_new_with_proplist_internal(
s->buffer_attr.maxlength = (uint32_t) -1;
if (ss)
- s->buffer_attr.tlength = (uint32_t) pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */
+ s->buffer_attr.tlength = (uint32_t) PA_USEC_TO_BYTES(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */
else {
/* FIXME: We assume a worst-case compressed format corresponding to
* 48000 Hz, 2 ch, S16 PCM, but this can very well be incorrect */
@@ -160,7 +161,7 @@ static pa_stream *pa_stream_new_with_proplist_internal(
.rate = 48000,
.channels = 2,
};
- s->buffer_attr.tlength = (uint32_t) pa_usec_to_bytes(250*PA_USEC_PER_MSEC, &tmp_ss); /* 250ms of buffering */
+ s->buffer_attr.tlength = (uint32_t) PA_USEC_TO_BYTES(250*PA_USEC_PER_MSEC, &tmp_ss); /* 250ms of buffering */
}
s->buffer_attr.minreq = (uint32_t) -1;
s->buffer_attr.prebuf = (uint32_t) -1;
@@ -994,7 +995,7 @@ static void patch_buffer_attr(pa_stream *s, pa_buffer_attr *attr, pa_stream_flag
pa_log_debug("Failed to parse $PULSE_LATENCY_MSEC: %s", e);
else {
attr->maxlength = (uint32_t) -1;
- attr->tlength = pa_usec_to_bytes(ms * PA_USEC_PER_MSEC, &s->sample_spec);
+ attr->tlength = PA_USEC_TO_BYTES(ms * PA_USEC_PER_MSEC, &s->sample_spec);
attr->minreq = (uint32_t) -1;
attr->prebuf = (uint32_t) -1;
attr->fragsize = attr->tlength;
@@ -1425,7 +1426,7 @@ int pa_stream_begin_write(
size_t m, fs;
m = pa_mempool_block_size_max(s->context->mempool);
- fs = pa_frame_size(&s->sample_spec);
+ fs = PA_FRAME_SIZE(&s->sample_spec);
m = (m / fs) * fs;
if (*nbytes > m)
@@ -1487,8 +1488,8 @@ int pa_stream_write_ext_free(
((data >= s->write_data) &&
((const char*) data + length <= (const char*) s->write_data + pa_memblock_get_length(s->write_memblock))),
PA_ERR_INVALID);
- PA_CHECK_VALIDITY(s->context, offset % pa_frame_size(&s->sample_spec) == 0, PA_ERR_INVALID);
- PA_CHECK_VALIDITY(s->context, length % pa_frame_size(&s->sample_spec) == 0, PA_ERR_INVALID);
+ PA_CHECK_VALIDITY(s->context, offset % PA_FRAME_SIZE(&s->sample_spec) == 0, PA_ERR_INVALID);
+ PA_CHECK_VALIDITY(s->context, length % PA_FRAME_SIZE(&s->sample_spec) == 0, PA_ERR_INVALID);
PA_CHECK_VALIDITY(s->context, !free_cb || !s->write_memblock, PA_ERR_INVALID);
if (s->write_memblock) {
@@ -1734,7 +1735,7 @@ static pa_usec_t calc_time(pa_stream *s, bool ignore_transport) {
if (s->direction == PA_STREAM_PLAYBACK) {
/* The last byte that was written into the output device
* had this time value associated */
- usec = pa_bytes_to_usec(s->timing_info.read_index < 0 ? 0 : (uint64_t) s->timing_info.read_index, &s->sample_spec);
+ usec = PA_BYTES_TO_USEC(s->timing_info.read_index < 0 ? 0 : (uint64_t) s->timing_info.read_index, &s->sample_spec);
if (!s->corked && !s->suspended) {
@@ -1758,7 +1759,7 @@ static pa_usec_t calc_time(pa_stream *s, bool ignore_transport) {
/* The last byte written into the server side queue had
* this time value associated */
- usec = pa_bytes_to_usec(s->timing_info.write_index < 0 ? 0 : (uint64_t) s->timing_info.write_index, &s->sample_spec);
+ usec = PA_BYTES_TO_USEC(s->timing_info.write_index < 0 ? 0 : (uint64_t) s->timing_info.write_index, &s->sample_spec);
if (!s->corked && !s->suspended) {
@@ -1932,7 +1933,7 @@ static void stream_get_timing_info_callback(pa_pdispatch *pd, uint32_t command,
* speakers. Since we follow that timing here, we need
* to try to fix this up */
- su = pa_bytes_to_usec((uint64_t) i->since_underrun, &o->stream->sample_spec);
+ su = PA_BYTES_TO_USEC((uint64_t) i->since_underrun, &o->stream->sample_spec);
if (su < i->sink_usec)
x += i->sink_usec - su;
@@ -2519,7 +2520,7 @@ int pa_stream_get_latency(pa_stream *s, pa_usec_t *r_usec, int *negative) {
if (cindex < 0)
cindex = 0;
- c = pa_bytes_to_usec((uint64_t) cindex, &s->sample_spec);
+ c = PA_BYTES_TO_USEC((uint64_t) cindex, &s->sample_spec);
if (s->direction == PA_STREAM_PLAYBACK)
*r_usec = time_counter_diff(s, c, t, negative);
diff --git a/src/pulsecore/memblockq.c b/src/pulsecore/memblockq.c
index 16a62da..10e7586 100644
--- a/src/pulsecore/memblockq.c
+++ b/src/pulsecore/memblockq.c
@@ -33,6 +33,7 @@
#include <pulsecore/mcalign.h>
#include <pulsecore/macro.h>
#include <pulsecore/flist.h>
+#include <pulsecore/sample-util.h>
#include "memblockq.h"
@@ -73,14 +74,14 @@ pa_memblockq* pa_memblockq_new(
pa_memblockq* bq;
- pa_assert(sample_spec);
+ pa_assert(pa_sample_spec_valid(sample_spec));
pa_assert(name);
bq = pa_xnew0(pa_memblockq, 1);
bq->name = pa_xstrdup(name);
bq->sample_spec = *sample_spec;
- bq->base = pa_frame_size(sample_spec);
+ bq->base = PA_FRAME_SIZE(sample_spec);
bq->read_index = bq->write_index = idx;
pa_log_debug("memblockq requested: maxlength=%lu, tlength=%lu, base=%lu, prebuf=%lu, minreq=%lu maxrewind=%lu",
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 99164a4..a52f725 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -541,7 +541,7 @@ static void fix_record_buffer_attr_pre(record_stream *s) {
* pa_source_output_put()! That means it may not touch any
* ->thread_info data! */
- frame_size = pa_frame_size(&s->source_output->sample_spec);
+ frame_size = PA_FRAME_SIZE(&s->source_output->sample_spec);
s->buffer_attr = s->buffer_attr_req;
if (s->buffer_attr.maxlength == (uint32_t) -1 || s->buffer_attr.maxlength > MAX_MEMBLOCKQ_LENGTH)
@@ -550,11 +550,11 @@ static void fix_record_buffer_attr_pre(record_stream *s) {
s->buffer_attr.maxlength = (uint32_t) frame_size;
if (s->buffer_attr.fragsize == (uint32_t) -1)
- s->buffer_attr.fragsize = (uint32_t) pa_usec_to_bytes(DEFAULT_FRAGSIZE_MSEC*PA_USEC_PER_MSEC, &s->source_output->sample_spec);
+ s->buffer_attr.fragsize = (uint32_t) PA_USEC_TO_BYTES(DEFAULT_FRAGSIZE_MSEC*PA_USEC_PER_MSEC, &s->source_output->sample_spec);
if (s->buffer_attr.fragsize <= 0)
s->buffer_attr.fragsize = (uint32_t) frame_size;
- orig_fragsize_usec = fragsize_usec = pa_bytes_to_usec(s->buffer_attr.fragsize, &s->source_output->sample_spec);
+ orig_fragsize_usec = fragsize_usec = PA_BYTES_TO_USEC(s->buffer_attr.fragsize, &s->source_output->sample_spec);
if (s->early_requests) {
@@ -608,10 +608,10 @@ static void fix_record_buffer_attr_pre(record_stream *s) {
fragsize_usec = s->configured_source_latency;
}
- if (pa_usec_to_bytes(orig_fragsize_usec, &s->source_output->sample_spec) !=
- pa_usec_to_bytes(fragsize_usec, &s->source_output->sample_spec))
+ if (PA_USEC_TO_BYTES(orig_fragsize_usec, &s->source_output->sample_spec) !=
+ PA_USEC_TO_BYTES(fragsize_usec, &s->source_output->sample_spec))
- s->buffer_attr.fragsize = (uint32_t) pa_usec_to_bytes(fragsize_usec, &s->source_output->sample_spec);
+ s->buffer_attr.fragsize = (uint32_t) PA_USEC_TO_BYTES(fragsize_usec, &s->source_output->sample_spec);
if (s->buffer_attr.fragsize <= 0)
s->buffer_attr.fragsize = (uint32_t) frame_size;
@@ -628,7 +628,7 @@ static void fix_record_buffer_attr_post(record_stream *s) {
* pa_source_output_put()! That means it may not touch and
* ->thread_info data! */
- base = pa_frame_size(&s->source_output->sample_spec);
+ base = PA_FRAME_SIZE(&s->source_output->sample_spec);
s->buffer_attr.fragsize = (s->buffer_attr.fragsize/base)*base;
if (s->buffer_attr.fragsize <= 0)
@@ -746,8 +746,8 @@ static record_stream* record_stream_new(
pa_idxset_put(c->record_streams, s, &s->index);
pa_log_info("Final latency %0.2f ms = %0.2f ms + %0.2f ms",
- ((double) pa_bytes_to_usec(s->buffer_attr.fragsize, &source_output->sample_spec) + (double) s->configured_source_latency) / PA_USEC_PER_MSEC,
- (double) pa_bytes_to_usec(s->buffer_attr.fragsize, &source_output->sample_spec) / PA_USEC_PER_MSEC,
+ ((double) PA_BYTES_TO_USEC(s->buffer_attr.fragsize, &source_output->sample_spec) + (double) s->configured_source_latency) / PA_USEC_PER_MSEC,
+ (double) PA_BYTES_TO_USEC(s->buffer_attr.fragsize, &source_output->sample_spec) / PA_USEC_PER_MSEC,
(double) s->configured_source_latency / PA_USEC_PER_MSEC);
pa_source_output_put(s->source_output);
@@ -922,10 +922,10 @@ static void fix_playback_buffer_attr(playback_stream *s) {
(long) s->buffer_attr_req.prebuf);
pa_log("Client requested: maxlength=%lu ms tlength=%lu ms minreq=%lu ms prebuf=%lu ms",
- (unsigned long) (pa_bytes_to_usec(s->buffer_attr_req.maxlength, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
- (unsigned long) (pa_bytes_to_usec(s->buffer_attr_req.tlength, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
- (unsigned long) (pa_bytes_to_usec(s->buffer_attr_req.minreq, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
- (unsigned long) (pa_bytes_to_usec(s->buffer_attr_req.prebuf, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC));
+ (unsigned long) (PA_BYTES_TO_USEC(s->buffer_attr_req.maxlength, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
+ (unsigned long) (PA_BYTES_TO_USEC(s->buffer_attr_req.tlength, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
+ (unsigned long) (PA_BYTES_TO_USEC(s->buffer_attr_req.minreq, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
+ (unsigned long) (PA_BYTES_TO_USEC(s->buffer_attr_req.prebuf, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC));
#endif
/* This function will be called from the main thread, before as
@@ -933,7 +933,7 @@ static void fix_playback_buffer_attr(playback_stream *s) {
* pa_sink_input_put()! That means it may not touch any
* ->thread_info data, such as the memblockq! */
- frame_size = pa_frame_size(&s->sink_input->sample_spec);
+ frame_size = PA_FRAME_SIZE(&s->sink_input->sample_spec);
s->buffer_attr = s->buffer_attr_req;
if (s->buffer_attr.maxlength == (uint32_t) -1 || s->buffer_attr.maxlength > MAX_MEMBLOCKQ_LENGTH)
@@ -962,8 +962,8 @@ static void fix_playback_buffer_attr(playback_stream *s) {
if (s->buffer_attr.tlength < s->buffer_attr.minreq+frame_size)
s->buffer_attr.tlength = s->buffer_attr.minreq+(uint32_t) frame_size;
- orig_tlength_usec = tlength_usec = pa_bytes_to_usec(s->buffer_attr.tlength, &s->sink_input->sample_spec);
- orig_minreq_usec = minreq_usec = pa_bytes_to_usec(s->buffer_attr.minreq, &s->sink_input->sample_spec);
+ orig_tlength_usec = tlength_usec = PA_BYTES_TO_USEC(s->buffer_attr.tlength, &s->sink_input->sample_spec);
+ orig_minreq_usec = minreq_usec = PA_BYTES_TO_USEC(s->buffer_attr.minreq, &s->sink_input->sample_spec);
pa_log_info("Requested tlength=%0.2f ms, minreq=%0.2f ms",
(double) tlength_usec / PA_USEC_PER_MSEC,
@@ -1055,9 +1055,9 @@ static void fix_playback_buffer_attr(playback_stream *s) {
pa_usec_to_bytes_round_up(tlength_usec, &s->sink_input->sample_spec))
s->buffer_attr.tlength = (uint32_t) pa_usec_to_bytes_round_up(tlength_usec, &s->sink_input->sample_spec);
- if (pa_usec_to_bytes(orig_minreq_usec, &s->sink_input->sample_spec) !=
- pa_usec_to_bytes(minreq_usec, &s->sink_input->sample_spec))
- s->buffer_attr.minreq = (uint32_t) pa_usec_to_bytes(minreq_usec, &s->sink_input->sample_spec);
+ if (PA_USEC_TO_BYTES(orig_minreq_usec, &s->sink_input->sample_spec) !=
+ PA_USEC_TO_BYTES(minreq_usec, &s->sink_input->sample_spec))
+ s->buffer_attr.minreq = (uint32_t) PA_USEC_TO_BYTES(minreq_usec, &s->sink_input->sample_spec);
if (s->buffer_attr.minreq <= 0) {
s->buffer_attr.minreq = (uint32_t) frame_size;
@@ -1075,10 +1075,10 @@ static void fix_playback_buffer_attr(playback_stream *s) {
#ifdef PROTOCOL_NATIVE_DEBUG
pa_log("Client accepted: maxlength=%lu ms tlength=%lu ms minreq=%lu ms prebuf=%lu ms",
- (unsigned long) (pa_bytes_to_usec(s->buffer_attr.maxlength, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
- (unsigned long) (pa_bytes_to_usec(s->buffer_attr.tlength, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
- (unsigned long) (pa_bytes_to_usec(s->buffer_attr.minreq, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
- (unsigned long) (pa_bytes_to_usec(s->buffer_attr.prebuf, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC));
+ (unsigned long) (PA_BYTES_TO_USEC(s->buffer_attr.maxlength, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
+ (unsigned long) (PA_BYTES_TO_USEC(s->buffer_attr.tlength, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
+ (unsigned long) (PA_BYTES_TO_USEC(s->buffer_attr.minreq, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC),
+ (unsigned long) (PA_BYTES_TO_USEC(s->buffer_attr.prebuf, &s->sink_input->sample_spec) / PA_USEC_PER_MSEC));
#endif
}
@@ -1237,9 +1237,9 @@ static playback_stream* playback_stream_new(
pa_idxset_put(c->output_streams, s, &s->index);
pa_log_info("Final latency %0.2f ms = %0.2f ms + 2*%0.2f ms + %0.2f ms",
- ((double) pa_bytes_to_usec(s->buffer_attr.tlength, &sink_input->sample_spec) + (double) s->configured_sink_latency) / PA_USEC_PER_MSEC,
- (double) pa_bytes_to_usec(s->buffer_attr.tlength-s->buffer_attr.minreq*2, &sink_input->sample_spec) / PA_USEC_PER_MSEC,
- (double) pa_bytes_to_usec(s->buffer_attr.minreq, &sink_input->sample_spec) / PA_USEC_PER_MSEC,
+ ((double) PA_BYTES_TO_USEC(s->buffer_attr.tlength, &sink_input->sample_spec) + (double) s->configured_sink_latency) / PA_USEC_PER_MSEC,
+ (double) PA_BYTES_TO_USEC(s->buffer_attr.tlength-s->buffer_attr.minreq*2, &sink_input->sample_spec) / PA_USEC_PER_MSEC,
+ (double) PA_BYTES_TO_USEC(s->buffer_attr.minreq, &sink_input->sample_spec) / PA_USEC_PER_MSEC,
(double) s->configured_sink_latency / PA_USEC_PER_MSEC);
pa_sink_input_put(s->sink_input);
@@ -1589,7 +1589,7 @@ static int sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int
case PA_SINK_INPUT_MESSAGE_GET_LATENCY: {
pa_usec_t *r = userdata;
- *r = pa_bytes_to_usec(pa_memblockq_get_length(s->memblockq), &i->sample_spec);
+ *r = PA_BYTES_TO_USEC(pa_memblockq_get_length(s->memblockq), &i->sample_spec);
/* Fall through, the default handler will add in the extra
* latency added by the resampler */
@@ -1872,7 +1872,7 @@ static pa_usec_t source_output_get_latency_cb(pa_source_output *o) {
/*pa_log("get_latency: %u", pa_memblockq_get_length(s->memblockq));*/
- return pa_bytes_to_usec(pa_memblockq_get_length(s->memblockq), &o->sample_spec);
+ return PA_BYTES_TO_USEC(pa_memblockq_get_length(s->memblockq), &o->sample_spec);
}
/* Called from main context */
@@ -2935,7 +2935,7 @@ static void command_get_playback_latency(pa_pdispatch *pd, uint32_t command, uin
reply = reply_new(tag);
pa_tagstruct_put_usec(reply,
s->current_sink_latency +
- pa_bytes_to_usec(s->render_memblockq_length, &s->sink_input->sink->sample_spec));
+ PA_BYTES_TO_USEC(s->render_memblockq_length, &s->sink_input->sink->sample_spec));
pa_tagstruct_put_usec(reply, 0);
pa_tagstruct_put_boolean(reply,
s->playing_for > 0 &&
@@ -2982,7 +2982,7 @@ static void command_get_record_latency(pa_pdispatch *pd, uint32_t command, uint3
pa_tagstruct_put_usec(reply, s->current_monitor_latency);
pa_tagstruct_put_usec(reply,
s->current_source_latency +
- pa_bytes_to_usec(s->on_the_fly_snapshot, &s->source_output->source->sample_spec));
+ PA_BYTES_TO_USEC(s->on_the_fly_snapshot, &s->source_output->source->sample_spec));
pa_tagstruct_put_boolean(reply,
pa_source_get_state(s->source_output->source) == PA_SOURCE_RUNNING &&
pa_source_output_get_state(s->source_output) == PA_SOURCE_OUTPUT_RUNNING);
@@ -3018,7 +3018,7 @@ static void command_create_upload_stream(pa_pdispatch *pd, uint32_t command, uin
CHECK_VALIDITY(c->pstream, pa_sample_spec_valid(&ss), tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, pa_channel_map_valid(&map), tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, map.channels == ss.channels, tag, PA_ERR_INVALID);
- CHECK_VALIDITY(c->pstream, (length % pa_frame_size(&ss)) == 0 && length > 0, tag, PA_ERR_INVALID);
+ CHECK_VALIDITY(c->pstream, (length % PA_FRAME_SIZE(&ss)) == 0 && length > 0, tag, PA_ERR_INVALID);
CHECK_VALIDITY(c->pstream, length <= PA_SCACHE_ENTRY_SIZE_MAX, tag, PA_ERR_TOOLARGE);
p = pa_proplist_new();
@@ -3523,7 +3523,7 @@ static void scache_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_s
pa_cvolume_init(&v);
pa_tagstruct_put_cvolume(t, &v);
- pa_tagstruct_put_usec(t, e->memchunk.memblock ? pa_bytes_to_usec(e->memchunk.length, &e->sample_spec) : 0);
+ pa_tagstruct_put_usec(t, e->memchunk.memblock ? PA_BYTES_TO_USEC(e->memchunk.length, &e->sample_spec) : 0);
pa_tagstruct_put_sample_spec(t, &fixed_ss);
pa_tagstruct_put_channel_map(t, &e->channel_map);
pa_tagstruct_putu32(t, (uint32_t) e->memchunk.length);
@@ -4922,7 +4922,7 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o
if (playback_stream_isinstance(stream)) {
playback_stream *ps = PLAYBACK_STREAM(stream);
- size_t frame_size = pa_frame_size(&ps->sink_input->sample_spec);
+ size_t frame_size = PA_FRAME_SIZE(&ps->sink_input->sample_spec);
if (chunk->index % frame_size != 0 || chunk->length % frame_size != 0) {
pa_log_warn("Client sent non-aligned memblock: index %d, length %d, frame size: %d",
(int) chunk->index, (int) chunk->length, (int) frame_size);
diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 8b30c24..79b463e 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -30,6 +30,7 @@
#include <pulsecore/macro.h>
#include <pulsecore/strbuf.h>
#include <pulsecore/core-util.h>
+#include <pulsecore/sample-util.h>
#include "resampler.h"
@@ -334,8 +335,8 @@ pa_resampler* pa_resampler_new(
else if (!pa_channel_map_init_auto(&r->o_cm, r->o_ss.channels, PA_CHANNEL_MAP_DEFAULT))
goto fail;
- r->i_fz = pa_frame_size(a);
- r->o_fz = pa_frame_size(b);
+ r->i_fz = PA_FRAME_SIZE(a);
+ r->o_fz = PA_FRAME_SIZE(b);
r->map_required = (r->i_ss.channels != r->o_ss.channels || (!(r->flags & PA_RESAMPLER_NO_REMAP) &&
!pa_channel_map_equal(&r->i_cm, &r->o_cm)));
@@ -503,8 +504,9 @@ size_t pa_resampler_max_block_size(pa_resampler *r) {
max_ss.format = PA_MAX(max_ss.format, r->work_format);
max_ss.rate = PA_MAX(r->i_ss.rate, r->o_ss.rate);
+ pa_assert(pa_sample_spec_valid(&max_ss));
- max_fs = pa_frame_size(&max_ss);
+ max_fs = PA_FRAME_SIZE(&max_ss);
frames = block_size_max / max_fs - EXTRA_FRAMES;
pa_assert(frames >= (r->leftover_buf->length / r->w_fz));
diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c
index 539f3b8..134e9a0 100644
--- a/src/pulsecore/sample-util.c
+++ b/src/pulsecore/sample-util.c
@@ -108,7 +108,7 @@ size_t pa_frame_align(size_t l, const pa_sample_spec *ss) {
pa_assert(ss);
- fs = pa_frame_size(ss);
+ fs = PA_FRAME_SIZE(ss);
return (l/fs) * fs;
}
@@ -118,7 +118,7 @@ bool pa_frame_aligned(size_t l, const pa_sample_spec *ss) {
pa_assert(ss);
- fs = pa_frame_size(ss);
+ fs = PA_FRAME_SIZE(ss);
return l % fs == 0;
}
@@ -314,7 +314,7 @@ pa_usec_t pa_bytes_to_usec_round_up(uint64_t length, const pa_sample_spec *spec)
pa_assert(spec);
- fs = pa_frame_size(spec);
+ fs = PA_FRAME_SIZE(spec);
length = (length + fs - 1) / fs;
usec = (pa_usec_t) length * PA_USEC_PER_SEC;
@@ -332,7 +332,7 @@ size_t pa_usec_to_bytes_round_up(pa_usec_t t, const pa_sample_spec *spec) {
u = (u + PA_USEC_PER_SEC - 1) / PA_USEC_PER_SEC;
- u *= pa_frame_size(spec);
+ u *= PA_FRAME_SIZE(spec);
return (size_t) u;
}
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index fa379ea..5d755ea 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -1941,7 +1941,7 @@ int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t
case PA_SINK_INPUT_MESSAGE_GET_LATENCY: {
pa_usec_t *r = userdata;
- r[0] += pa_bytes_to_usec(pa_memblockq_get_length(i->thread_info.render_memblockq), &i->sink->sample_spec);
+ r[0] += PA_BYTES_TO_USEC(pa_memblockq_get_length(i->thread_info.render_memblockq), &i->sink->sample_spec);
r[1] += pa_sink_get_latency_within_thread(i->sink);
return 0;
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 46b6eec..d034b54 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -2592,7 +2592,7 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
/* Get the latency of the sink */
usec = pa_sink_get_latency_within_thread(s);
- sink_nbytes = pa_usec_to_bytes(usec, &s->sample_spec);
+ sink_nbytes = PA_USEC_TO_BYTES(usec, &s->sample_spec);
total_nbytes = sink_nbytes + pa_memblockq_get_length(i->thread_info.render_memblockq);
if (total_nbytes > 0) {
@@ -2662,7 +2662,7 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
/* Get the latency of the sink */
usec = pa_sink_get_latency_within_thread(s);
- nbytes = pa_usec_to_bytes(usec, &s->sample_spec);
+ nbytes = PA_USEC_TO_BYTES(usec, &s->sample_spec);
if (nbytes > 0)
pa_sink_input_drop(i, nbytes);
@@ -3663,7 +3663,7 @@ static void pa_sink_volume_change_rewind(pa_sink *s, size_t nbytes) {
/* All the queued volume events later than current latency are shifted to happen earlier. */
pa_sink_volume_change *c;
pa_volume_t prev_vol = pa_cvolume_avg(&s->thread_info.current_hw_volume);
- pa_usec_t rewound = pa_bytes_to_usec(nbytes, &s->sample_spec);
+ pa_usec_t rewound = PA_BYTES_TO_USEC(nbytes, &s->sample_spec);
pa_usec_t limit = pa_sink_get_latency_within_thread(s);
pa_log_debug("latency = %lld", (long long) limit);
diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
index 90e86fe..c3a12ac 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -751,7 +751,7 @@ void pa_source_output_push(pa_source_output *o, const pa_memchunk *chunk) {
latency = pa_sink_get_latency_within_thread(o->source->monitor_of);
- n = pa_usec_to_bytes(latency, &o->source->sample_spec);
+ n = PA_USEC_TO_BYTES(latency, &o->source->sample_spec);
if (n < limit)
limit = n;
@@ -1525,7 +1525,7 @@ int pa_source_output_process_msg(pa_msgobject *mo, int code, void *userdata, int
case PA_SOURCE_OUTPUT_MESSAGE_GET_LATENCY: {
pa_usec_t *r = userdata;
- r[0] += pa_bytes_to_usec(pa_memblockq_get_length(o->thread_info.delay_memblockq), &o->source->sample_spec);
+ r[0] += PA_BYTES_TO_USEC(pa_memblockq_get_length(o->thread_info.delay_memblockq), &o->source->sample_spec);
r[1] += pa_source_get_latency_within_thread(o->source);
return 0;
--
1.9.1
More information about the pulseaudio-discuss
mailing list