[pulseaudio-discuss] [PATCH v2 4/4] pacat: Handle holes in recording streams.
Tanu Kaskinen
tanuk at iki.fi
Wed Nov 7 06:52:40 PST 2012
pa_silence_memory() pulls sample-util as a dependency, so it had to
be moved from libpulsecore to libpulsecommon. sample-util in turn
pulls some more stuff.
---
src/Makefile.am | 8 ++++----
src/utils/pacat.c | 37 ++++++++++++++++++++++++++-----------
2 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 155f908..f8a0230 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -586,6 +586,7 @@ libpulsecommon_ at PA_MAJORMINOR@_la_SOURCES = \
pulsecore/dynarray.c pulsecore/dynarray.h \
pulsecore/endianmacros.h \
pulsecore/flist.c pulsecore/flist.h \
+ pulsecore/g711.c pulsecore/g711.h \
pulsecore/hashmap.c pulsecore/hashmap.h \
pulsecore/i18n.c pulsecore/i18n.h \
pulsecore/idxset.c pulsecore/idxset.h \
@@ -617,6 +618,7 @@ libpulsecommon_ at PA_MAJORMINOR@_la_SOURCES = \
pulsecore/queue.c pulsecore/queue.h \
pulsecore/random.c pulsecore/random.h \
pulsecore/refcnt.h \
+ pulsecore/sample-util.c pulsecore/sample-util.h \
pulsecore/shm.c pulsecore/shm.h \
pulsecore/bitset.c pulsecore/bitset.h \
pulsecore/socket-client.c pulsecore/socket-client.h \
@@ -624,6 +626,8 @@ libpulsecommon_ at PA_MAJORMINOR@_la_SOURCES = \
pulsecore/socket-util.c pulsecore/socket-util.h \
pulsecore/strbuf.c pulsecore/strbuf.h \
pulsecore/strlist.c pulsecore/strlist.h \
+ pulsecore/svolume_c.c pulsecore/svolume_arm.c \
+ pulsecore/svolume_mmx.c pulsecore/svolume_sse.c \
pulsecore/tagstruct.c pulsecore/tagstruct.h \
pulsecore/time-smoother.c pulsecore/time-smoother.h \
pulsecore/tokenizer.c pulsecore/tokenizer.h \
@@ -838,7 +842,6 @@ libpulsecore_ at PA_MAJORMINOR@_la_SOURCES = \
pulsecore/core-subscribe.c pulsecore/core-subscribe.h \
pulsecore/core.c pulsecore/core.h \
pulsecore/fdsem.c pulsecore/fdsem.h \
- pulsecore/g711.c pulsecore/g711.h \
pulsecore/hook-list.c pulsecore/hook-list.h \
pulsecore/ltdl-helper.c pulsecore/ltdl-helper.h \
pulsecore/modargs.c pulsecore/modargs.h \
@@ -853,13 +856,10 @@ libpulsecore_ at PA_MAJORMINOR@_la_SOURCES = \
pulsecore/remap_mmx.c pulsecore/remap_sse.c \
pulsecore/resampler.c pulsecore/resampler.h \
pulsecore/rtpoll.c pulsecore/rtpoll.h \
- pulsecore/sample-util.c pulsecore/sample-util.h \
pulsecore/cpu.h \
pulsecore/cpu-arm.c pulsecore/cpu-arm.h \
pulsecore/cpu-x86.c pulsecore/cpu-x86.h \
pulsecore/cpu-orc.c pulsecore/cpu-orc.h \
- pulsecore/svolume_c.c pulsecore/svolume_arm.c \
- pulsecore/svolume_mmx.c pulsecore/svolume_sse.c \
pulsecore/sconv-s16be.c pulsecore/sconv-s16be.h \
pulsecore/sconv-s16le.c pulsecore/sconv-s16le.h \
pulsecore/sconv_sse.c \
diff --git a/src/utils/pacat.c b/src/utils/pacat.c
index 2cd8aa5..e7a4255 100644
--- a/src/utils/pacat.c
+++ b/src/utils/pacat.c
@@ -45,6 +45,7 @@
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/sndfile-util.h>
+#include <pulsecore/sample-util.h>
#define TIME_EVENT_USEC 50000
@@ -59,6 +60,9 @@ static pa_mainloop_api *mainloop_api = NULL;
static void *buffer = NULL;
static size_t buffer_length = 0, buffer_index = 0;
+static void *silence_buffer = NULL;
+static size_t silence_buffer_length = 0;
+
static pa_io_event* stdio_event = NULL;
static pa_proplist *proplist = NULL;
@@ -257,18 +261,18 @@ static void stream_read_callback(pa_stream *s, size_t length, void *userdata) {
return;
}
- pa_assert(data);
pa_assert(length > 0);
- if (buffer) {
+ /* If there is a hole in the stream, we generate silence, except
+ * if it's a passthrough stream in which case we skip the hole. */
+ if (data || !(flags & PA_STREAM_PASSTHROUGH)) {
buffer = pa_xrealloc(buffer, buffer_length + length);
- memcpy((uint8_t*) buffer + buffer_length, data, length);
+ if (data)
+ memcpy((uint8_t *) buffer + buffer_length, data, length);
+ else
+ pa_silence_memory((uint8_t *) buffer + buffer_length, length, &sample_spec);
+
buffer_length += length;
- } else {
- buffer = pa_xmalloc(length);
- memcpy(buffer, data, length);
- buffer_length = length;
- buffer_index = 0;
}
pa_stream_drop(s);
@@ -287,17 +291,27 @@ static void stream_read_callback(pa_stream *s, size_t length, void *userdata) {
return;
}
- pa_assert(data);
pa_assert(length > 0);
+ if (!data && (flags & PA_STREAM_PASSTHROUGH)) {
+ pa_stream_drop(s);
+ continue;
+ }
+
+ if (!data && length > silence_buffer_length) {
+ silence_buffer = pa_xrealloc(silence_buffer, length);
+ pa_silence_memory((uint8_t *) silence_buffer + silence_buffer_length, length - silence_buffer_length, &sample_spec);
+ silence_buffer_length = length;
+ }
+
if (writef_function) {
size_t k = pa_frame_size(&sample_spec);
- if ((bytes = writef_function(sndfile, data, (sf_count_t) (length/k))) > 0)
+ if ((bytes = writef_function(sndfile, data ? data : silence_buffer, (sf_count_t) (length/k))) > 0)
bytes *= (sf_count_t) k;
} else
- bytes = sf_write_raw(sndfile, data, (sf_count_t) length);
+ bytes = sf_write_raw(sndfile, data ? data : silence_buffer, (sf_count_t) length);
if (bytes < (sf_count_t) length)
quit(1);
@@ -1193,6 +1207,7 @@ quit:
pa_mainloop_free(m);
}
+ pa_xfree(silence_buffer);
pa_xfree(buffer);
pa_xfree(server);
--
1.7.10.4
More information about the pulseaudio-discuss
mailing list