[pulseaudio-discuss] [PATCH RFCv3 50/51] alsa: Precompute max_frames

Peter Meerwald pmeerw at pmeerw.net
Tue Nov 4 15:26:45 PST 2014


From: Peter Meerwald <p.meerwald at bct-electronic.com>

max_frames is the mempool's maximum block size in frames

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
 src/modules/alsa/alsa-sink.c   | 7 +++++--
 src/modules/alsa/alsa-source.c | 7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index aab7ee7..a637462 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -127,6 +127,8 @@ struct userdata {
         watermark_dec_threshold,
         rewind_safeguard;
 
+    snd_pcm_uframes_t max_frames;
+
     pa_usec_t watermark_dec_not_before;
     pa_usec_t min_latency_ref;
     pa_usec_t tsched_watermark_usec;
@@ -640,8 +642,8 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec, bool polled, bo
             }
 
             /* Make sure that if these memblocks need to be copied they will fit into one slot */
-            if (frames > pa_mempool_block_size_max(u->core->mempool)/u->frame_size)
-                frames = pa_mempool_block_size_max(u->core->mempool)/u->frame_size;
+            if (frames > u->max_frames)
+                frames = u->max_frames;
 
             if (!after_avail && frames == 0)
                 break;
@@ -2330,6 +2332,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     pa_sink_set_rtpoll(u->sink, u->rtpoll);
 
     u->frame_size = frame_size;
+    u->max_frames = pa_mempool_block_size_max(m->core->mempool) / frame_size;
     u->fragment_size = frag_size = (size_t) (period_frames * frame_size);
     u->hwbuf_size = buffer_size = (size_t) (buffer_frames * frame_size);
     pa_cvolume_mute(&u->hardware_volume, u->sink->sample_spec.channels);
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index ac88e4b..8a027b0 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -116,6 +116,8 @@ struct userdata {
         watermark_inc_threshold,
         watermark_dec_threshold;
 
+    snd_pcm_uframes_t max_frames;
+
     pa_usec_t watermark_dec_not_before;
     pa_usec_t min_latency_ref;
     pa_usec_t tsched_watermark_usec;
@@ -591,8 +593,8 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec, bool polled, boo
             }
 
             /* Make sure that if these memblocks need to be copied they will fit into one slot */
-            if (frames > pa_mempool_block_size_max(u->core->mempool)/u->frame_size)
-                frames = pa_mempool_block_size_max(u->core->mempool)/u->frame_size;
+            if (frames > u->max_frames)
+                frames = u->max_frames;
 
             if (!after_avail && frames == 0)
                 break;
@@ -2035,6 +2037,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     pa_source_set_rtpoll(u->source, u->rtpoll);
 
     u->frame_size = frame_size;
+    u->max_frames = pa_mempool_block_size_max(m->core->mempool) / frame_size;
     u->fragment_size = frag_size = (size_t) (period_frames * frame_size);
     u->hwbuf_size = buffer_size = (size_t) (buffer_frames * frame_size);
     pa_cvolume_mute(&u->hardware_volume, u->source->sample_spec.channels);
-- 
1.9.1



More information about the pulseaudio-discuss mailing list