From 25e43ba6a07139428fa6b6cd311b4c7c29f3cafb Mon Sep 17 00:00:00 2001 From: Leonid Pliushch Date: Thu, 4 Oct 2018 15:25:46 +0300 Subject: [PATCH] mpv-x: sync build.sh with one from https://github.com/termux/termux-packages --- x11-packages/mpv-x/android.patch | 123 +++++++++++++++++++++++ x11-packages/mpv-x/build.sh | 10 +- x11-packages/mpv-x/mpv.conf | 16 ++- x11-packages/mpv-x/pulse_buffer.patch | 19 ++++ x11-packages/mpv-x/sles_enqueue.patch | 115 +++++++++++++++++++++ x11-packages/mpv-x/sles_float.patch | 70 +++++++++++++ x11-packages/mpv-x/sles_numbuffers.patch | 13 +++ x11-packages/mpv-x/strnlen.h.patch | 16 --- 8 files changed, 359 insertions(+), 23 deletions(-) create mode 100644 x11-packages/mpv-x/android.patch create mode 100644 x11-packages/mpv-x/pulse_buffer.patch create mode 100644 x11-packages/mpv-x/sles_enqueue.patch create mode 100644 x11-packages/mpv-x/sles_float.patch create mode 100644 x11-packages/mpv-x/sles_numbuffers.patch delete mode 100644 x11-packages/mpv-x/strnlen.h.patch diff --git a/x11-packages/mpv-x/android.patch b/x11-packages/mpv-x/android.patch new file mode 100644 index 000000000..c4600e81a --- /dev/null +++ b/x11-packages/mpv-x/android.patch @@ -0,0 +1,123 @@ +diff --git a/options/options.c b/options/options.c +index 1f9f1ee2c0..a98f03a7da 100644 +--- a/options/options.c ++++ b/options/options.c +@@ -740,7 +740,7 @@ const m_option_t mp_opts[] = { + OPT_SUBSTRUCT("", macos_opts, macos_conf, 0), + #endif + +-#if HAVE_ANDROID ++#if HAVE_EGL_ANDROID + OPT_SUBSTRUCT("", android_opts, android_conf, 0), + #endif + +diff --git a/osdep/io.h b/osdep/io.h +index e0d6284baa..7e8a267541 100644 +--- a/osdep/io.h ++++ b/osdep/io.h +@@ -33,7 +33,7 @@ + #include + #endif + +-#ifdef __ANDROID__ ++#if HAVE_ANDROID + # include + # include + +@@ -58,7 +58,7 @@ static inline int mp_fseeko(FILE* fp, off64_t offset, int whence) { + } + #define fseeko(f,p,w) mp_fseeko((f), (p), (w)) + +-#endif // __ANDROID__ ++#endif // HAVE_ANDROID + + #ifndef O_BINARY + #define O_BINARY 0 +diff --git a/osdep/posix-spawn.h b/osdep/posix-spawn.h +index d8bf874c98..fdba50149c 100644 +--- a/osdep/posix-spawn.h ++++ b/osdep/posix-spawn.h +@@ -19,7 +19,9 @@ + + #pragma once + +-#ifdef __ANDROID__ ++#include "config.h" ++ ++#if HAVE_ANDROID + // posix_spawn(p) does not exist at all on Android + #include "osdep/android/posix-spawn.h" + #else +diff --git a/osdep/strnlen.h b/osdep/strnlen.h +index 0a971d0ab0..e66932a89a 100644 +--- a/osdep/strnlen.h ++++ b/osdep/strnlen.h +@@ -20,7 +20,9 @@ + #ifndef MP_OSDEP_STRNLEN + #define MP_OSDEP_STRNLEN + +-#ifdef __ANDROID__ ++#include "config.h" ++ ++#if HAVE_ANDROID + // strnlen is broken on current android ndk, see https://code.google.com/p/android/issues/detail?id=74741 + #include "osdep/android/strnlen.h" + #define strnlen freebsd_strnlen +diff --git a/video/out/gpu/context.c b/video/out/gpu/context.c +index 36f9c2dad5..7964e12623 100644 +--- a/video/out/gpu/context.c ++++ b/video/out/gpu/context.c +@@ -62,7 +62,7 @@ static const struct ra_ctx_fns *contexts[] = { + #endif + + // OpenGL contexts: +-#if HAVE_ANDROID ++#if HAVE_EGL_ANDROID + &ra_ctx_android, + #endif + #if HAVE_RPI +diff --git a/wscript b/wscript +index e0dbeab322..eaeb091a52 100644 +--- a/wscript ++++ b/wscript +@@ -155,11 +155,13 @@ main_dependencies = [ + }, { + 'name': '--android', + 'desc': 'Android environment', +- 'func': compose_checks( +- check_statement('android/api-level.h', '(void)__ANDROID__'), # arbitrary android-specific header +- check_cc(lib="android"), +- check_cc(lib="EGL"), +- ) ++ 'func': check_statement('android/api-level.h', '(void)__ANDROID__'), # arbitrary android-specific header ++ }, { ++ 'name': '--egl-android', ++ 'desc': 'Android EGL support', ++ 'deps': 'android', ++ 'groups': [ 'gl' ], ++ 'func': check_cc(lib=['android', 'EGL']), + }, { + 'name': 'posix-or-mingw', + 'desc': 'development environment', +@@ -804,7 +806,7 @@ video_output_features = [ + 'name': 'egl-helpers', + 'desc': 'EGL helper functions', + 'deps': 'egl-x11 || mali-fbdev || rpi || gl-wayland || egl-drm || ' + +- 'egl-angle-win32 || android', ++ 'egl-angle-win32 || egl-android', + 'func': check_true + } + ] +diff --git a/wscript_build.py b/wscript_build.py +index 4d974fd9c3..35b16856ea 100644 +--- a/wscript_build.py ++++ b/wscript_build.py +@@ -442,7 +442,7 @@ def build(ctx): + ( "video/out/opengl/angle_dynamic.c", "egl-angle" ), + ( "video/out/opengl/common.c", "gl" ), + ( "video/out/opengl/context.c", "gl" ), +- ( "video/out/opengl/context_android.c", "android" ), ++ ( "video/out/opengl/context_android.c", "egl-android" ), + ( "video/out/opengl/context_angle.c", "egl-angle-win32" ), + ( "video/out/opengl/context_cocoa.c", "gl-cocoa" ), + ( "video/out/opengl/context_drm_egl.c", "egl-drm" ), diff --git a/x11-packages/mpv-x/build.sh b/x11-packages/mpv-x/build.sh index 0f119c236..c7c22b6f0 100644 --- a/x11-packages/mpv-x/build.sh +++ b/x11-packages/mpv-x/build.sh @@ -7,7 +7,7 @@ TERMUX_PKG_REVISION=7 TERMUX_PKG_SHA256=772af878cee5495dcd342788a6d120b90c5b1e677e225c7198f1e76506427319 TERMUX_PKG_SRCURL=https://github.com/mpv-player/mpv/archive/v${TERMUX_PKG_VERSION}.tar.gz -TERMUX_PKG_DEPENDS="ffmpeg, openal-soft, libandroid-glob, libandroid-shmem, libdrm, littlecms, libjpeg-turbo, libcaca, liblua52, libx11, libxext, libxinerama, libxss, libxrandr" +TERMUX_PKG_DEPENDS="ffmpeg, libandroid-glob, libandroid-shmem, libdrm, littlecms, libjpeg-turbo, libcaca, liblua52, libpulseaudio, libx11, libxext, libxinerama, libxss, libxrandr, openal-soft" TERMUX_PKG_CONFLICTS="mpv" TERMUX_PKG_REPLACES="mpv" @@ -25,18 +25,18 @@ termux_step_make_install () { ./waf configure \ --prefix=$TERMUX_PREFIX \ --disable-gl \ + --disable-libarchive \ --enable-jpeg \ --enable-lcms2 \ --disable-libass \ --enable-lua \ - --disable-pulse \ + --enable-pulse \ --enable-openal \ --enable-caca \ --disable-alsa \ - --enable-x11 \ - --disable-android + --enable-x11 - ./waf install + ./waf -v install # Use opensles audio out be default: mkdir -p $TERMUX_PREFIX/etc/mpv diff --git a/x11-packages/mpv-x/mpv.conf b/x11-packages/mpv-x/mpv.conf index c007889a8..bea47465d 100644 --- a/x11-packages/mpv-x/mpv.conf +++ b/x11-packages/mpv-x/mpv.conf @@ -3,5 +3,17 @@ # Enable OpenSL ES output, since this should work on all Android devices ao=opensles -# Increase audio buffer to help with stuttering with bluetooth devices. See #1127. -audio-buffer=0.5 +# Use the following option to increase or decrease audio buffer +# when necessary / desired. The default is 250ms (0.25s). + +# opensles-buffer-size-in-ms=250 + +# You can also use the generic audio-buffer option (which takes +# value in second instead), but it will only has effect on the +# opensles ao if the above option is explicitly set to 0. + +# By default mpv allows s32 and float output. If they aren't +# supported in your device (which should not happen with API +# 21 and above), disable them with the following option: + +# audio-format=s16 diff --git a/x11-packages/mpv-x/pulse_buffer.patch b/x11-packages/mpv-x/pulse_buffer.patch new file mode 100644 index 000000000..bc0633b84 --- /dev/null +++ b/x11-packages/mpv-x/pulse_buffer.patch @@ -0,0 +1,19 @@ +diff --git a/audio/out/ao_pulse.c b/audio/out/ao_pulse.c +index ed45ba6549..e288841788 100644 +--- a/audio/out/ao_pulse.c ++++ b/audio/out/ao_pulse.c +@@ -454,11 +454,11 @@ static int init(struct ao *ao) + pa_stream_set_write_callback(priv->stream, stream_request_cb, ao); + pa_stream_set_latency_update_callback(priv->stream, + stream_latency_update_cb, ao); +- int buf_size = af_fmt_seconds_to_bytes(ao->format, priv->cfg_buffer / 1000.0, +- ao->channels.num, ao->samplerate); ++ uint32_t buf_size = ao->samplerate * (priv->cfg_buffer / 1000.0) * ++ af_fmt_to_bytes(ao->format) * ao->channels.num; + pa_buffer_attr bufattr = { + .maxlength = -1, +- .tlength = buf_size > 0 ? buf_size : (uint32_t)-1, ++ .tlength = buf_size > 0 ? buf_size : -1, + .prebuf = -1, + .minreq = -1, + .fragsize = -1, diff --git a/x11-packages/mpv-x/sles_enqueue.patch b/x11-packages/mpv-x/sles_enqueue.patch new file mode 100644 index 000000000..121961613 --- /dev/null +++ b/x11-packages/mpv-x/sles_enqueue.patch @@ -0,0 +1,115 @@ +diff --git a/audio/out/ao_opensles.c b/audio/out/ao_opensles.c +index ea48de892e..9f984bed52 100644 +--- a/audio/out/ao_opensles.c ++++ b/audio/out/ao_opensles.c +@@ -35,12 +35,13 @@ struct priv { + SLBufferQueueItf buffer_queue; + SLEngineItf engine; + SLPlayItf play; +- char *buf; +- size_t buffer_size; ++ void *buf; ++ int bytes_per_enqueue; + pthread_mutex_t buffer_lock; + double audio_latency; + +- int cfg_frames_per_buffer; ++ int frames_per_enqueue; ++ int buffer_size_in_ms; + }; + + static const int fmtmap[][2] = { +@@ -71,7 +72,6 @@ static void uninit(struct ao *ao) + + free(p->buf); + p->buf = NULL; +- p->buffer_size = 0; + } + + #undef DESTROY +@@ -81,26 +81,22 @@ static void buffer_callback(SLBufferQueueItf buffer_queue, void *context) + struct ao *ao = context; + struct priv *p = ao->priv; + SLresult res; +- void *data[1]; + double delay; + + pthread_mutex_lock(&p->buffer_lock); + +- data[0] = p->buf; +- delay = 2 * p->buffer_size / (double)ao->bps; ++ delay = 2 * p->frames_per_enqueue / (double)ao->samplerate; + delay += p->audio_latency; +- ao_read_data(ao, data, p->buffer_size / ao->sstride, ++ ao_read_data(ao, &p->buf, p->frames_per_enqueue, + mp_time_us() + 1000000LL * delay); + +- res = (*buffer_queue)->Enqueue(buffer_queue, p->buf, p->buffer_size); ++ res = (*buffer_queue)->Enqueue(buffer_queue, p->buf, p->bytes_per_enqueue); + if (res != SL_RESULT_SUCCESS) + MP_ERR(ao, "Failed to Enqueue: %d\n", res); + + pthread_mutex_unlock(&p->buffer_lock); + } + +-#define DEFAULT_BUFFER_SIZE_MS 250 +- + #define CHK(stmt) \ + { \ + SLresult res = stmt; \ +@@ -155,17 +151,35 @@ static int init(struct ao *ao) + // samplesPerSec is misnamed, actually it's samples per ms + pcm.samplesPerSec = ao->samplerate * 1000; + +- if (p->cfg_frames_per_buffer) +- ao->device_buffer = p->cfg_frames_per_buffer; +- else +- ao->device_buffer = ao->samplerate * DEFAULT_BUFFER_SIZE_MS / 1000; +- p->buffer_size = ao->device_buffer * ao->channels.num * ++ if (p->buffer_size_in_ms) { ++ ao->device_buffer = ao->samplerate * p->buffer_size_in_ms / 1000; ++ // As the purpose of buffer_size_in_ms is to request a specific ++ // soft buffer size: ++ ao->def_buffer = 0; ++ } ++ ++ // But it does not make sense if it is smaller than the enqueue size: ++ if (p->frames_per_enqueue) { ++ ao->device_buffer = MPMAX(ao->device_buffer, p->frames_per_enqueue); ++ } else { ++ if (ao->device_buffer) { ++ p->frames_per_enqueue = ao->device_buffer; ++ } else if (ao->def_buffer) { ++ p->frames_per_enqueue = ao->def_buffer * ao->samplerate; ++ } else { ++ MP_ERR(ao, "Enqueue size is not set and can neither be derived\n"); ++ goto error; ++ } ++ } ++ ++ p->bytes_per_enqueue = p->frames_per_enqueue * ao->channels.num * + af_fmt_to_bytes(ao->format); +- p->buf = calloc(1, p->buffer_size); ++ p->buf = calloc(1, p->bytes_per_enqueue); + if (!p->buf) { + MP_ERR(ao, "Failed to allocate device buffer\n"); + goto error; + } ++ + int r = pthread_mutex_init(&p->buffer_lock, NULL); + if (r) { + MP_ERR(ao, "Failed to initialize the mutex: %d\n", r); +@@ -248,8 +262,12 @@ const struct ao_driver audio_out_opensles = { + .resume = resume, + + .priv_size = sizeof(struct priv), ++ .priv_defaults = &(const struct priv) { ++ .buffer_size_in_ms = 250, ++ }, + .options = (const struct m_option[]) { +- OPT_INTRANGE("frames-per-buffer", cfg_frames_per_buffer, 0, 1, 96000), ++ OPT_INTRANGE("frames-per-enqueue", frames_per_enqueue, 0, 1, 96000), ++ OPT_INTRANGE("buffer-size-in-ms", buffer_size_in_ms, 0, 0, 500), + {0} + }, + .options_prefix = "opensles", diff --git a/x11-packages/mpv-x/sles_float.patch b/x11-packages/mpv-x/sles_float.patch new file mode 100644 index 000000000..5525e5b31 --- /dev/null +++ b/x11-packages/mpv-x/sles_float.patch @@ -0,0 +1,70 @@ +diff --git a/audio/out/ao_opensles.c b/audio/out/ao_opensles.c +index ea48de892e..f3082a9aa6 100644 +--- a/audio/out/ao_opensles.c ++++ b/audio/out/ao_opensles.c +@@ -43,12 +43,6 @@ struct priv { + int cfg_frames_per_buffer; + }; + +-static const int fmtmap[][2] = { +- { AF_FORMAT_U8, SL_PCMSAMPLEFORMAT_FIXED_8 }, +- { AF_FORMAT_S16, SL_PCMSAMPLEFORMAT_FIXED_16 }, +- { 0 } +-}; +- + #define DESTROY(thing) \ + if (p->thing) { \ + (*p->thing)->Destroy(p->thing); \ +@@ -115,7 +109,7 @@ static int init(struct ao *ao) + struct priv *p = ao->priv; + SLDataLocator_BufferQueue locator_buffer_queue; + SLDataLocator_OutputMix locator_output_mix; +- SLDataFormat_PCM pcm; ++ SLAndroidDataFormat_PCM_EX pcm; + SLDataSource audio_source; + SLDataSink audio_sink; + +@@ -131,29 +125,23 @@ static int init(struct ao *ao) + locator_buffer_queue.locatorType = SL_DATALOCATOR_BUFFERQUEUE; + locator_buffer_queue.numBuffers = 1; + +- pcm.formatType = SL_DATAFORMAT_PCM; +- pcm.numChannels = 2; +- +- int compatible_formats[AF_FORMAT_COUNT + 1]; +- af_get_best_sample_formats(ao->format, compatible_formats); +- pcm.bitsPerSample = 0; +- for (int i = 0; compatible_formats[i] && !pcm.bitsPerSample; ++i) +- for (int j = 0; fmtmap[j][0]; ++j) +- if (compatible_formats[i] == fmtmap[j][0]) { +- ao->format = fmtmap[j][0]; +- pcm.bitsPerSample = fmtmap[j][1]; +- break; +- } +- if (!pcm.bitsPerSample) { +- MP_ERR(ao, "Cannot find compatible audio format\n"); +- goto error; ++ if (af_fmt_is_int(ao->format)) { ++ // Be future-proof ++ if (af_fmt_to_bytes(ao->format) > 2) ++ ao->format = AF_FORMAT_S32; ++ else ++ ao->format = af_fmt_from_planar(ao->format); ++ pcm.formatType = SL_DATAFORMAT_PCM; ++ } else { ++ ao->format = AF_FORMAT_FLOAT; ++ pcm.formatType = SL_ANDROID_DATAFORMAT_PCM_EX; ++ pcm.representation = SL_ANDROID_PCM_REPRESENTATION_FLOAT; + } +- pcm.containerSize = 8 * af_fmt_to_bytes(ao->format); ++ pcm.numChannels = ao->channels.num; ++ pcm.containerSize = pcm.bitsPerSample = 8 * af_fmt_to_bytes(ao->format); + pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; + pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; +- +- // samplesPerSec is misnamed, actually it's samples per ms +- pcm.samplesPerSec = ao->samplerate * 1000; ++ pcm.sampleRate = ao->samplerate * 1000; + + if (p->cfg_frames_per_buffer) + ao->device_buffer = p->cfg_frames_per_buffer; diff --git a/x11-packages/mpv-x/sles_numbuffers.patch b/x11-packages/mpv-x/sles_numbuffers.patch new file mode 100644 index 000000000..1daafce2d --- /dev/null +++ b/x11-packages/mpv-x/sles_numbuffers.patch @@ -0,0 +1,13 @@ +diff --git a/audio/out/ao_opensles.c b/audio/out/ao_opensles.c +index ea48de892e..2e637adf82 100644 +--- a/audio/out/ao_opensles.c ++++ b/audio/out/ao_opensles.c +@@ -129,7 +129,7 @@ static int init(struct ao *ao) + CHK((*p->output_mix)->Realize(p->output_mix, SL_BOOLEAN_FALSE)); + + locator_buffer_queue.locatorType = SL_DATALOCATOR_BUFFERQUEUE; +- locator_buffer_queue.numBuffers = 1; ++ locator_buffer_queue.numBuffers = 8; + + pcm.formatType = SL_DATAFORMAT_PCM; + pcm.numChannels = 2; diff --git a/x11-packages/mpv-x/strnlen.h.patch b/x11-packages/mpv-x/strnlen.h.patch deleted file mode 100644 index 66c841d76..000000000 --- a/x11-packages/mpv-x/strnlen.h.patch +++ /dev/null @@ -1,16 +0,0 @@ -diff --git a/osdep/strnlen.h b/osdep/strnlen.h -index 0a971d0ab0..9a8b2a104d 100644 ---- a/osdep/strnlen.h -+++ b/osdep/strnlen.h -@@ -19,11 +19,4 @@ - - #ifndef MP_OSDEP_STRNLEN - #define MP_OSDEP_STRNLEN -- --#ifdef __ANDROID__ --// strnlen is broken on current android ndk, see https://code.google.com/p/android/issues/detail?id=74741 --#include "osdep/android/strnlen.h" --#define strnlen freebsd_strnlen --#endif -- - #endif