pacat: Handle holes in recording streams.

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.
This commit is contained in:
Tanu Kaskinen 2012-11-07 16:52:40 +02:00
parent 94ac039b87
commit 8cb34c6960
2 changed files with 30 additions and 15 deletions

View file

@ -586,6 +586,7 @@ libpulsecommon_@PA_MAJORMINOR@_la_SOURCES = \
pulsecore/dynarray.c pulsecore/dynarray.h \ pulsecore/dynarray.c pulsecore/dynarray.h \
pulsecore/endianmacros.h \ pulsecore/endianmacros.h \
pulsecore/flist.c pulsecore/flist.h \ pulsecore/flist.c pulsecore/flist.h \
pulsecore/g711.c pulsecore/g711.h \
pulsecore/hashmap.c pulsecore/hashmap.h \ pulsecore/hashmap.c pulsecore/hashmap.h \
pulsecore/i18n.c pulsecore/i18n.h \ pulsecore/i18n.c pulsecore/i18n.h \
pulsecore/idxset.c pulsecore/idxset.h \ pulsecore/idxset.c pulsecore/idxset.h \
@ -617,6 +618,7 @@ libpulsecommon_@PA_MAJORMINOR@_la_SOURCES = \
pulsecore/queue.c pulsecore/queue.h \ pulsecore/queue.c pulsecore/queue.h \
pulsecore/random.c pulsecore/random.h \ pulsecore/random.c pulsecore/random.h \
pulsecore/refcnt.h \ pulsecore/refcnt.h \
pulsecore/sample-util.c pulsecore/sample-util.h \
pulsecore/shm.c pulsecore/shm.h \ pulsecore/shm.c pulsecore/shm.h \
pulsecore/bitset.c pulsecore/bitset.h \ pulsecore/bitset.c pulsecore/bitset.h \
pulsecore/socket-client.c pulsecore/socket-client.h \ pulsecore/socket-client.c pulsecore/socket-client.h \
@ -624,6 +626,8 @@ libpulsecommon_@PA_MAJORMINOR@_la_SOURCES = \
pulsecore/socket-util.c pulsecore/socket-util.h \ pulsecore/socket-util.c pulsecore/socket-util.h \
pulsecore/strbuf.c pulsecore/strbuf.h \ pulsecore/strbuf.c pulsecore/strbuf.h \
pulsecore/strlist.c pulsecore/strlist.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/tagstruct.c pulsecore/tagstruct.h \
pulsecore/time-smoother.c pulsecore/time-smoother.h \ pulsecore/time-smoother.c pulsecore/time-smoother.h \
pulsecore/tokenizer.c pulsecore/tokenizer.h \ pulsecore/tokenizer.c pulsecore/tokenizer.h \
@ -838,7 +842,6 @@ libpulsecore_@PA_MAJORMINOR@_la_SOURCES = \
pulsecore/core-subscribe.c pulsecore/core-subscribe.h \ pulsecore/core-subscribe.c pulsecore/core-subscribe.h \
pulsecore/core.c pulsecore/core.h \ pulsecore/core.c pulsecore/core.h \
pulsecore/fdsem.c pulsecore/fdsem.h \ pulsecore/fdsem.c pulsecore/fdsem.h \
pulsecore/g711.c pulsecore/g711.h \
pulsecore/hook-list.c pulsecore/hook-list.h \ pulsecore/hook-list.c pulsecore/hook-list.h \
pulsecore/ltdl-helper.c pulsecore/ltdl-helper.h \ pulsecore/ltdl-helper.c pulsecore/ltdl-helper.h \
pulsecore/modargs.c pulsecore/modargs.h \ pulsecore/modargs.c pulsecore/modargs.h \
@ -853,13 +856,10 @@ libpulsecore_@PA_MAJORMINOR@_la_SOURCES = \
pulsecore/remap_mmx.c pulsecore/remap_sse.c \ pulsecore/remap_mmx.c pulsecore/remap_sse.c \
pulsecore/resampler.c pulsecore/resampler.h \ pulsecore/resampler.c pulsecore/resampler.h \
pulsecore/rtpoll.c pulsecore/rtpoll.h \ pulsecore/rtpoll.c pulsecore/rtpoll.h \
pulsecore/sample-util.c pulsecore/sample-util.h \
pulsecore/cpu.h \ pulsecore/cpu.h \
pulsecore/cpu-arm.c pulsecore/cpu-arm.h \ pulsecore/cpu-arm.c pulsecore/cpu-arm.h \
pulsecore/cpu-x86.c pulsecore/cpu-x86.h \ pulsecore/cpu-x86.c pulsecore/cpu-x86.h \
pulsecore/cpu-orc.c pulsecore/cpu-orc.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-s16be.c pulsecore/sconv-s16be.h \
pulsecore/sconv-s16le.c pulsecore/sconv-s16le.h \ pulsecore/sconv-s16le.c pulsecore/sconv-s16le.h \
pulsecore/sconv_sse.c \ pulsecore/sconv_sse.c \

View file

@ -45,6 +45,7 @@
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/sndfile-util.h> #include <pulsecore/sndfile-util.h>
#include <pulsecore/sample-util.h>
#define TIME_EVENT_USEC 50000 #define TIME_EVENT_USEC 50000
@ -59,6 +60,9 @@ static pa_mainloop_api *mainloop_api = NULL;
static void *buffer = NULL; static void *buffer = NULL;
static size_t buffer_length = 0, buffer_index = 0; 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_io_event* stdio_event = NULL;
static pa_proplist *proplist = NULL; static pa_proplist *proplist = NULL;
@ -257,18 +261,18 @@ static void stream_read_callback(pa_stream *s, size_t length, void *userdata) {
return; return;
} }
pa_assert(data);
pa_assert(length > 0); 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); 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; buffer_length += length;
} else {
buffer = pa_xmalloc(length);
memcpy(buffer, data, length);
buffer_length = length;
buffer_index = 0;
} }
pa_stream_drop(s); pa_stream_drop(s);
@ -287,17 +291,27 @@ static void stream_read_callback(pa_stream *s, size_t length, void *userdata) {
return; return;
} }
pa_assert(data);
pa_assert(length > 0); 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) { if (writef_function) {
size_t k = pa_frame_size(&sample_spec); 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; bytes *= (sf_count_t) k;
} else } 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) if (bytes < (sf_count_t) length)
quit(1); quit(1);
@ -1193,6 +1207,7 @@ quit:
pa_mainloop_free(m); pa_mainloop_free(m);
} }
pa_xfree(silence_buffer);
pa_xfree(buffer); pa_xfree(buffer);
pa_xfree(server); pa_xfree(server);