diff options
Diffstat (limited to 'audio/out/ao_pcm.c')
-rw-r--r-- | audio/out/ao_pcm.c | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/audio/out/ao_pcm.c b/audio/out/ao_pcm.c index a36b71fa16..4097aa3bd6 100644 --- a/audio/out/ao_pcm.c +++ b/audio/out/ao_pcm.c @@ -19,8 +19,6 @@ * License along with mpv. If not, see <http://www.gnu.org/licenses/>. */ -#include "config.h" - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -44,8 +42,8 @@ struct priv { char *outputfilename; - int waveheader; - int append; + bool waveheader; + bool append; uint64_t data_length; FILE *fp; }; @@ -111,9 +109,11 @@ static int init(struct ao *ao) { struct priv *priv = ao->priv; - if (!priv->outputfilename) - priv->outputfilename = - talloc_strdup(priv, priv->waveheader ? "audiodump.wav" : "audiodump.pcm"); + char *outputfilename = priv->outputfilename; + if (!outputfilename) { + outputfilename = talloc_strdup(priv, priv->waveheader ? "audiodump.wav" + : "audiodump.pcm"); + } ao->format = af_fmt_from_planar(ao->format); @@ -148,18 +148,19 @@ static int init(struct ao *ao) ao->bps = ao->channels.num * ao->samplerate * af_fmt_to_bytes(ao->format); MP_INFO(ao, "File: %s (%s)\nPCM: Samplerate: %d Hz Channels: %d Format: %s\n", - priv->outputfilename, + outputfilename, priv->waveheader ? "WAVE" : "RAW PCM", ao->samplerate, ao->channels.num, af_fmt_to_str(ao->format)); - priv->fp = fopen(priv->outputfilename, priv->append ? "ab" : "wb"); + priv->fp = fopen(outputfilename, priv->append ? "ab" : "wb"); if (!priv->fp) { - MP_ERR(ao, "Failed to open %s for writing!\n", priv->outputfilename); + MP_ERR(ao, "Failed to open %s for writing!\n", outputfilename); return -1; } if (priv->waveheader) // Reserve space for wave header write_wave_header(ao, priv->fp, 0x7ffff000); ao->untimed = true; + ao->device_buffer = 1 << 16; return 0; } @@ -191,19 +192,36 @@ static void uninit(struct ao *ao) fclose(priv->fp); } -static int get_space(struct ao *ao) -{ - return 65536; -} - -static int play(struct ao *ao, void **data, int samples, int flags) +static bool audio_write(struct ao *ao, void **data, int samples) { struct priv *priv = ao->priv; int len = samples * ao->sstride; fwrite(data[0], len, 1, priv->fp); priv->data_length += len; - return samples; + + return true; +} + +static void get_state(struct ao *ao, struct mp_pcm_state *state) +{ + state->free_samples = ao->device_buffer; + state->queued_samples = 0; + state->delay = 0; +} + +static bool set_pause(struct ao *ao, bool paused) +{ + return true; // signal support so common code doesn't write silence +} + +static void start(struct ao *ao) +{ + // we use data immediately +} + +static void reset(struct ao *ao) +{ } #define OPT_BASE_STRUCT struct priv @@ -213,14 +231,17 @@ const struct ao_driver audio_out_pcm = { .name = "pcm", .init = init, .uninit = uninit, - .get_space = get_space, - .play = play, + .get_state = get_state, + .set_pause = set_pause, + .write = audio_write, + .start = start, + .reset = reset, .priv_size = sizeof(struct priv), - .priv_defaults = &(const struct priv) { .waveheader = 1 }, + .priv_defaults = &(const struct priv) { .waveheader = true }, .options = (const struct m_option[]) { - OPT_STRING("file", outputfilename, M_OPT_FILE), - OPT_FLAG("waveheader", waveheader, 0), - OPT_FLAG("append", append, 0), + {"file", OPT_STRING(outputfilename), .flags = M_OPT_FILE}, + {"waveheader", OPT_BOOL(waveheader)}, + {"append", OPT_BOOL(append)}, {0} }, .options_prefix = "ao-pcm", |