From a7d737a6986446ba921690cc985468534ed8caab Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 4 Sep 2014 23:48:27 +0200 Subject: audio: make buffer size configurable Really only for testing. --- DOCS/man/options.rst | 14 ++++++++++++++ audio/out/ao.c | 3 ++- audio/out/internal.h | 4 +--- audio/out/push.c | 4 ++-- options/options.c | 3 +++ options/options.h | 1 + 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 18391ae118..901dc74889 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -994,6 +994,20 @@ Audio Do not use. +``--audio-buffer=`` + Set the audio output minimum buffer. The audio device might actually create + a larger buffer if it pleases. If the device creates a smaller buffer, + additional audio is buffered in an additional software buffer. + + Making this larger will make soft-volume and other filters react slower, + introduce additional issues on playback speed change, and block the + player on audio format changes. A smaller buffer might lead to audio + dropouts. + + This option should be used for testing only. If a non-default value helps + significantly, the mpv developers should be contacted. + + Default: 0.2 (200 ms). Subtitles --------- diff --git a/audio/out/ao.c b/audio/out/ao.c index 8e1ceb4bf1..f63f3fd09b 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -152,6 +152,7 @@ static struct ao *ao_create(bool probing, struct mpv_global *global, .channels = channels, .format = format, .log = mp_log_new(ao, log, name), + .def_buffer = global->opts->audio_buffer, }; if (ao->driver->encode != !!ao->encode_lavc_ctx) goto error; @@ -187,7 +188,7 @@ static struct ao *ao_create(bool probing, struct mpv_global *global, ao->device_buffer = ao->driver->get_space(ao); MP_VERBOSE(ao, "device buffer: %d samples.\n", ao->device_buffer); } - ao->buffer = MPMAX(ao->device_buffer, MIN_BUFFER * ao->samplerate); + ao->buffer = MPMAX(ao->device_buffer, ao->def_buffer * ao->samplerate); MP_VERBOSE(ao, "using soft-buffer of %d samples.\n", ao->buffer); if (ao->api->init(ao) < 0) diff --git a/audio/out/internal.h b/audio/out/internal.h index 75f5798bff..4ee7f00f8a 100644 --- a/audio/out/internal.h +++ b/audio/out/internal.h @@ -25,9 +25,6 @@ #include "audio/chmap.h" #include "audio/chmap_sel.h" -// Minimum buffer size in seconds. -#define MIN_BUFFER 0.2 - // If ao_get_delay() reaches this value after ao_play() was called with the // AOPLAY_FINAL_CHUNK flag set, the playback core expects that the audio has // all been played. @@ -56,6 +53,7 @@ struct ao { struct mp_log *log; // Using e.g. "[ao/coreaudio]" as prefix int buffer; + double def_buffer; void *api_priv; }; diff --git a/audio/out/push.c b/audio/out/push.c index 95df7dfb56..4a1f2a06c4 100644 --- a/audio/out/push.c +++ b/audio/out/push.c @@ -168,11 +168,11 @@ static int unlocked_get_space(struct ao *ao) int space = mp_audio_buffer_get_write_available(p->buffer); if (ao->driver->get_space) { // The following code attempts to keep the total buffered audio to - // MIN_BUFFER/2+device_buffer in order to improve latency. + // def_buffer/2+device_buffer in order to improve latency. int device_space = ao->driver->get_space(ao); int device_buffered = ao->device_buffer - device_space; int soft_buffered = mp_audio_buffer_samples(p->buffer); - int min_buffer = MIN_BUFFER / 2 * ao->samplerate + ao->device_buffer; + int min_buffer = ao->def_buffer / 2 * ao->samplerate + ao->device_buffer; int total_buffer = device_buffered + soft_buffered; int missing = min_buffer - total_buffer; space = MPMIN(space, missing); diff --git a/options/options.c b/options/options.c index 2523146feb..e44b9877a4 100644 --- a/options/options.c +++ b/options/options.c @@ -371,6 +371,8 @@ const m_option_t mp_opts[] = { ({"no", 0}, {"yes", 1}, {"", 1}, {"weak", -1})), + OPT_DOUBLE("audio-buffer", audio_buffer, M_OPT_MIN | M_OPT_MAX, + .min = 0, .max = 10), OPT_GEOMETRY("geometry", vo.geometry, 0), OPT_SIZE_BOX("autofit", vo.autofit, 0), @@ -558,6 +560,7 @@ const struct MPOpts mp_default_opts = { .mixer_init_mute = -1, .volstep = 3, .gapless_audio = -1, + .audio_buffer = 0.2, .vo = { .video_driver_list = NULL, .monitor_pixel_aspect = 1.0, diff --git a/options/options.h b/options/options.h index b1a7ec0952..967982ea5c 100644 --- a/options/options.h +++ b/options/options.h @@ -74,6 +74,7 @@ typedef struct MPOpts { int volstep; float softvol_max; int gapless_audio; + double audio_buffer; mp_vo_opts vo; int allow_win_drag; -- cgit v1.2.3