pulse segfault fixed and changed default config (#2044)

This commit is contained in:
its-pointless 2018-02-02 08:24:34 +11:00 committed by Fredrik Fornwall
parent 2cd37154b3
commit 2e68ba7f34
6 changed files with 138 additions and 52 deletions

View File

@ -3,11 +3,12 @@ TERMUX_PKG_DESCRIPTION="Tools and libraries to manipulate a wide range of multim
# NOTE: mpv has to be rebuilt and version bumped after updating ffmpeg.
TERMUX_PKG_VERSION=3.4.1
TERMUX_PKG_SHA256=5a77278a63741efa74e26bf197b9bb09ac6381b9757391b922407210f0f991c0
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=https://www.ffmpeg.org/releases/ffmpeg-${TERMUX_PKG_VERSION}.tar.xz
# libbz2 is used by matroska decoder:
# libvpx is the VP8 & VP9 video encoder for WebM, see
# https://trac.ffmpeg.org/wiki/Encode/VP8 and https://trac.ffmpeg.org/wiki/Encode/VP9
TERMUX_PKG_DEPENDS="libbz2, libx264, libx265, xvidcore, libvorbis, libmp3lame, libopus, libvpx, libgnutls, libandroid-glob"
TERMUX_PKG_DEPENDS="libbz2, libsoxr, libx264, libx265, xvidcore, libvorbis, libmp3lame, libopus, libvpx, libgnutls, libandroid-glob"
TERMUX_PKG_INCLUDE_IN_DEVPACKAGE="share/ffmpeg/examples"
TERMUX_PKG_CONFLICTS="libav"
@ -59,6 +60,7 @@ termux_step_configure () {
--enable-libxvid \
--enable-libvpx \
--enable-shared \
--enable-libsoxr \
--prefix=$TERMUX_PREFIX \
--target-os=android \
--extra-libs="-landroid-glob" \

View File

@ -1,10 +1,10 @@
TERMUX_PKG_HOMEPAGE=https://www.freedesktop.org/wiki/Software/PulseAudio
TERMUX_PKG_DESCRIPTION="A featureful, general-purpose sound server - shared libraries"
TERMUX_PKG_VERSION=11.1
TERMUX_PKG_REVISION=3
TERMUX_PKG_REVISION=4
TERMUX_PKG_SHA256=f2521c525a77166189e3cb9169f75c2ee2b82fa3fcf9476024fbc2c3a6c9cd9e
TERMUX_PKG_SRCURL=https://www.freedesktop.org/software/pulseaudio/releases/pulseaudio-${TERMUX_PKG_VERSION}.tar.xz
TERMUX_PKG_DEPENDS="libltdl, libsndfile, libandroid-glob"
TERMUX_PKG_DEPENDS="libltdl, libsndfile, libandroid-glob, libsoxr"
TERMUX_PKG_BUILD_DEPENDS="libtool"
TERMUX_PKG_INCLUDE_IN_DEVPACKAGE="share/vala"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="--disable-neon-opt
@ -14,7 +14,8 @@ TERMUX_PKG_EXTRA_CONFIGURE_ARGS="--disable-neon-opt
--disable-openssl
--without-caps
--with-database=simple
--disable-memfd"
--disable-memfd
--bindir=$TERMUX_PREFIX/libexec"
TERMUX_PKG_CONFFILES="etc/pulse/client.conf etc/pulse/daemon.conf etc/pulse/default.pa etc/pulse/system.pa"
termux_step_pre_configure () {
@ -40,17 +41,18 @@ termux_step_post_make_install () {
sed -i $TERMUX_PREFIX/etc/pulse/default.pa \
-e '/^load-module module-detect$/s/^/#/'
echo "load-module module-sles-sink" >> $TERMUX_PREFIX/etc/pulse/default.pa
cd $TERMUX_PREFIX/bin
cd $TERMUX_PREFIX/libexec
for bin in esdcompat pacat pacmd pactl pasuspender pulseaudio; do
mv $bin ../libexec
rm -f ../bin/$bin
local PA_LIBS="" lib
for lib in android-glob pulse pulsecommon-11.1 pulsecore-11.1; do
if [ -n "$PA_LIBS" ]; then PA_LIBS+=":"; fi
PA_LIBS+="$TERMUX_PREFIX/lib/lib${lib}.so"
done
echo "#!$TERMUX_PREFIX/bin/sh" >> $TERMUX_PREFIX/bin/$bin
echo "export LD_PRELOAD=$PA_LIBS" >> $TERMUX_PREFIX/bin/$bin
echo "LD_LIBRARY_PATH=/system/$SYSTEM_LIB:/system/vendor/$SYSTEM_LIB:/data/data/com.termux/files/usr/lib /data/data/com.termux/files/usr/libexec/$bin \$@" >> $TERMUX_PREFIX/bin/$bin
chmod +x $bin
echo "LD_LIBRARY_PATH=/system/$SYSTEM_LIB:/system/vendor/$SYSTEM_LIB:$TERMUX_PREFIX/lib exec $TERMUX_PREFIX/libexec/$bin \$@" >> $TERMUX_PREFIX/bin/$bin
chmod +x $TERMUX_PREFIX/bin/$bin
done
}

View File

@ -0,0 +1,34 @@
--- ../cache/pulseaudio-11.1/src/daemon/daemon.conf.in 2017-09-05 09:33:12.000000000 +0000
+++ ./src/daemon/daemon.conf.in 2018-01-17 02:04:13.056075165 +0000
@@ -19,6 +19,7 @@
changequote(`[', `]')dnl Set up m4 quoting
; daemonize = no
+daemonize = yes
; fail = yes
; allow-module-loading = yes
; allow-exit = yes
@@ -28,6 +29,7 @@
; local-server-type = user
])dnl
; enable-shm = yes
+enable-shm = no
; enable-memfd = yes
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB
; lock-memory = no
@@ -41,13 +43,14 @@
; exit-idle-time = 20
; scache-idle-time = 20
-
+exit-idle-time = -1
; dl-search-path = (depends on architecture)
; load-default-script-file = yes
; default-script-file = @PA_DEFAULT_CONFIG_DIR@/default.pa
; log-target = auto
+log-target = stderr
; log-level = notice
; log-meta = no
; log-time = no

View File

@ -45,6 +45,12 @@
#include "module-sles-sink-symdef.h"
//Only certain interfaces are supported by the fast mixer. These are:
//SL_IID_ANDROIDSIMPLEBUFFERQUEUE
//SL_IID_VOLUME
//SL_IID_MUTESOLO
#define USE_ANDROID_SIMPLE_BUFFER_QUEUE
#ifdef USE_ANDROID_SIMPLE_BUFFER_QUEUE
#include <SLES/OpenSLES_Android.h>
#define DATALOCATOR_BUFFERQUEUE SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE
@ -69,10 +75,6 @@
else fprintf(stderr, "error %d at %s:%d\n", (int) r, __FILE__, __LINE__); \
} \
} while (0)
typedef struct {
short left;
short right;
} frame_t;
PA_MODULE_AUTHOR("Lennart Poettering, Nathan Martynov");
PA_MODULE_DESCRIPTION("Android OpenSL ES sink");
@ -86,6 +88,11 @@ PA_MODULE_USAGE(
#define DEFAULT_SINK_NAME "OpenSL ES sink"
#define BLOCK_USEC (PA_USEC_PER_SEC * 2)
typedef struct pa_memblock_queue_t {
pa_memblock *memblock;
struct pa_memblock_queue_t* next;
} pa_memblock_queue;
struct userdata {
pa_core *core;
pa_module *module;
@ -110,6 +117,9 @@ struct userdata {
SLObjectItf bqPlayerObject;
SLPlayItf bqPlayerPlay;
BufferQueueItf bqPlayerBufferQueue;
pa_memblock_queue* current;
pa_memblock_queue* last;
};
static const char* const valid_modargs[] = {
@ -168,6 +178,17 @@ static void sink_update_requested_latency_cb(pa_sink *s) {
pa_sink_set_max_request_within_thread(s, nbytes);
}
static void pa_sles_callback(BufferQueueItf bq, void *context){
struct userdata* s = (struct userdata*) context;
pa_memblock_queue* next;
if (s->current != NULL){
if (s->current->memblock != NULL) pa_memblock_unref(s->current->memblock);
next = s->current->next;
free(s->current);
s->current = next;
}
}
static int pa_init_sles_player(struct userdata *s, SLint32 sl_rate)
{
if (s == NULL) return -1;
@ -193,7 +214,7 @@ static int pa_init_sles_player(struct userdata *s, SLint32 sl_rate)
locator_bufferqueue.locatorType = DATALOCATOR_BUFFERQUEUE;
locator_bufferqueue.numBuffers = 50;
if (sl_rate < 0) {
if (sl_rate < SL_SAMPLINGRATE_8 || sl_rate > SL_SAMPLINGRATE_192) {
pa_log("Incompatible sample rate");
return -1;
}
@ -223,7 +244,10 @@ static int pa_init_sles_player(struct userdata *s, SLint32 sl_rate)
result = (*s->bqPlayerObject)->GetInterface(s->bqPlayerObject, SL_IID_PLAY, &s->bqPlayerPlay); checkResult(result);
result = (*s->bqPlayerObject)->GetInterface(s->bqPlayerObject, IID_BUFFERQUEUE_USED, &s->bqPlayerBufferQueue); checkResult(result);
result = (*s->bqPlayerBufferQueue)->RegisterCallback(s->bqPlayerBufferQueue, pa_sles_callback, s); checkResult(result);
result = (*s->bqPlayerPlay)->SetPlayState(s->bqPlayerPlay, SL_PLAYSTATE_PLAYING); checkResult(result);
return 0;
}
@ -236,6 +260,7 @@ static void pa_destroy_sles_player(struct userdata *s){
}
static void process_render(struct userdata *u, pa_usec_t now) {
pa_memblock_queue* current_block;
size_t ate = 0;
pa_assert(u);
@ -256,6 +281,20 @@ static void process_render(struct userdata *u, pa_usec_t now) {
u->timestamp += pa_bytes_to_usec(u->memchunk.length, &u->sink->sample_spec);
ate += u->memchunk.length;
current_block = malloc(sizeof(pa_memblock_queue));
memset(current_block, 0, sizeof(pa_memblock_queue));
current_block->memblock = u->memchunk.memblock;
if (u->current == NULL) { u->current = current_block; }
if (u->last == NULL) { u->last = current_block; }
else {
u->last->next = current_block;
u->last = current_block;
}
//pa_memblock_unref(u->memchunk.memblock);
pa_memchunk_reset(&u->memchunk);
if (ate >= u->sink->thread_info.max_request) break;
}
}
@ -308,38 +347,11 @@ finish:
pa_log_debug("Thread shutting down");
}
static SLint32 PA2SLrate(int32_t rate){
if (!(rate >= 8000 && rate <= 192000)) return -1;
switch(rate){
case 8000:
return SL_SAMPLINGRATE_8;
case 11025:
return SL_SAMPLINGRATE_11_025;
case 12000:
return SL_SAMPLINGRATE_12;
case 16000:
return SL_SAMPLINGRATE_16;
case 22050:
return SL_SAMPLINGRATE_22_05;
case 24000:
return SL_SAMPLINGRATE_24;
case 32000:
return SL_SAMPLINGRATE_32;
case 44100:
return SL_SAMPLINGRATE_44_1;
case 48000:
return SL_SAMPLINGRATE_48;
case 64000:
return SL_SAMPLINGRATE_64;
case 88200:
return SL_SAMPLINGRATE_88_2;
case 96000:
return SL_SAMPLINGRATE_96;
case 192000:
return SL_SAMPLINGRATE_192;
default:
return -1;
}
static int getenv_int(const char * env, size_t min_len){
char * got_env = getenv(env);
int ret = 0;
if (got_env != NULL && strlen(got_env) >= min_len) ret = atoi(got_env); //"8000" is 4 symbols
return ret;
}
int pa__init(pa_module*m) {
@ -373,20 +385,25 @@ int pa__init(pa_module*m) {
//Needed. Don't touch
ss.channels = 2;
ss.format = PA_SAMPLE_S16LE;
int forceFormat = atoi(getenv("PROPERTY_OUTPUT_SAMPLE_RATE"));
if (forceFormat >= 8000 && forceFormat <= 192000)
ss.rate = forceFormat;
m->userdata = u = pa_xnew0(struct userdata, 1);
int forceFormat = getenv_int("PROPERTY_OUTPUT_SAMPLE_RATE", 4); //"8000" is 4 symbols
if (forceFormat >= 8000 && forceFormat <= 192000) {
ss.rate = forceFormat;
pa_log_info("Sample rate was forced to be %u\n", ss.rate);
}
u->core = m->core;
u->module = m;
u->rtpoll = pa_rtpoll_new();
pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
if (pa_init_sles_player(u, PA2SLrate(ss.rate)) < 0)
//Pulseaudio uses samples per sec but OpenSL ES uses samples per ms
if (pa_init_sles_player(u, ss.rate * 1000) < 0)
goto fail;
int buff[2] = {0, 0};
(*u->bqPlayerBufferQueue)->Enqueue(u->bqPlayerBufferQueue, buff, 1);
//int buff[2] = {0, 0};
//(*u->bqPlayerBufferQueue)->Enqueue(u->bqPlayerBufferQueue, buff, 1);
pa_sink_new_data_init(&data);
data.driver = __FILE__;
@ -470,6 +487,10 @@ void pa__done(pa_module*m) {
pa_thread_free(u->thread);
}
if (u->engineObject){
pa_destroy_sles_player(u);
}
pa_thread_mq_done(&u->thread_mq);
if (u->sink)

15
packages/libsoxr/build.sh Normal file
View File

@ -0,0 +1,15 @@
TERMUX_PKG_HOMEPAGE=https://sourceforge.net/projects/soxr/
TERMUX_PKG_DESCRIPTION="High quality, one-dimensional sample-rate conversion library"
TERMUX_PKG_VERSION=0.1.2
TERMUX_PKG_SRCURL=https://sourceforge.net/projects/soxr/files/soxr-$TERMUX_PKG_VERSION-Source.tar.xz
TERMUX_PKG_SHA256=54e6f434f1c491388cd92f0e3c47f1ade082cc24327bdc43762f7d1eefe0c275
TERMUX_PKG_BUILD_IN_SRC=yes
termux_step_configure() {
return 0;
}
termux_step_make() {
termux_setup_cmake
./go
}

12
packages/libsoxr/go.patch Normal file
View File

@ -0,0 +1,12 @@
--- ../cache/soxr-0.1.2-Source/go 2015-08-27 07:53:52.000000000 +0000
+++ ./go 2018-01-18 23:39:51.044488639 +0000
@@ -12,6 +12,6 @@
mkdir -p $build
cd $build
-cmake -DCMAKE_BUILD_TYPE=$build -Wno-dev .. &&
- make $j &&
- (ctest $j || echo "FAILURE details in $build/Testing/Temporary/LastTest.log")
+cmake -DCMAKE_BUILD_TYPE=$build -DCMAKE_INSTALL_PREFIX=@TERMUX_PREFIX@ -DBUILD_TESTS=off -Wno-dev .. &&
+ make $j
+make install