From bf60281ffb6f47986fa6ef9ee559689be0075050 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 10 Nov 2013 23:15:02 +0100 Subject: audio/out: reject non-interleaved formats No AO can handle these, so it would be a problem if they get added later, and non-interleaved formats get accepted erroneously. Let them gracefully fall back to other formats. Most AOs actually would fall back, but to an unrelated formats. This is covered by this commit too, and if possible they should pick the interleaved variant if a non-interleaved format is requested. --- audio/out/ao_lavc.c | 1 + 1 file changed, 1 insertion(+) (limited to 'audio/out/ao_lavc.c') diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index 4364b9054d..b849f9b2b4 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -105,6 +105,7 @@ static int init(struct ao *ao) ac->stream->codec->channel_layout = mp_chmap_to_lavc(&ao->channels); ac->stream->codec->sample_fmt = AV_SAMPLE_FMT_NONE; + ao->format = af_fmt_from_planar(ao->format); { // first check if the selected format is somewhere in the list of -- cgit v1.2.3 From 380fc765e4ad4e3ff828c9b0bd4a565ea2ba79ed Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 10 Nov 2013 23:24:21 +0100 Subject: audio/out: prepare for non-interleaved audio This comes with two internal AO API changes: 1. ao_driver.play now can take non-interleaved audio. For this purpose, the data pointer is changed to void **data, where data[0] corresponds to the pointer in the old API. Also, the len argument as well as the return value are now in samples, not bytes. "Sample" in this context means the unit of the smallest possible audio frame, i.e. sample_size * channels. 2. ao_driver.get_space now returns samples instead of bytes. (Similar to the play function.) Change all AOs to use the new API. The AO API as exposed to the rest of the player still uses the old API. It's emulated in ao.c. This is purely to split the commits changing all AOs and the commits adding actual support for outputting N-I audio. --- audio/out/ao_lavc.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'audio/out/ao_lavc.c') diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index b849f9b2b4..9be3a7b6ae 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -296,8 +296,6 @@ static void fill_with_padding(void *buf, int cnt, int sz, const void *padding) } // close audio device -static int encode(struct ao *ao, double apts, void *data); -static int play(struct ao *ao, void *data, int len, int flags); static void uninit(struct ao *ao, bool cut_audio) { struct encode_lavc_context *ectx = ao->encode_lavc_ctx; @@ -315,7 +313,7 @@ static int get_space(struct ao *ao) { struct priv *ac = ao->priv; - return ac->aframesize * ac->sample_size * ao->channels.num * ac->framecount; + return ac->aframesize * ac->framecount; } // must get exactly ac->aframesize amount of data @@ -444,10 +442,10 @@ static int encode(struct ao *ao, double apts, void *data) return packet.size; } -// plays 'len' bytes of 'data' +// plays 'samples' samples of 'ni_data[0]' // it should round it down to frame sizes -// return: number of bytes played -static int play(struct ao *ao, void *data, int len, int flags) +// return: number of samples played +static int play(struct ao *ao, void **ni_data, int samples, int flags) { struct priv *ac = ao->priv; struct encode_lavc_context *ectx = ao->encode_lavc_ctx; @@ -457,6 +455,8 @@ static int play(struct ao *ao, void *data, int len, int flags) double nextpts; double pts = ao->pts; double outpts; + void *data = ni_data[0]; + int len = samples * ao->sstride; int bytelen = len; len /= ac->sample_size * ao->channels.num; @@ -477,8 +477,9 @@ static int play(struct ao *ao, void *data, int len, int flags) extralen / ac->sample_size, ac->sample_size, ac->sample_padding); // No danger of recursion, because AOPLAY_FINAL_CHUNK not set - written = play(ao, paddingbuf, bytelen + extralen, 0); - if (written < bytelen) { + written = + play(ao, &paddingbuf, (bytelen + extralen) / ao->sstride, 0); + if (written * ao->sstride < bytelen) { MP_ERR(ao, "did not write enough data at the end\n"); } talloc_free(paddingbuf); @@ -492,7 +493,7 @@ static int play(struct ao *ao, void *data, int len, int flags) while (encode(ao, outpts, NULL) > 0) ; - return FFMIN(written, bytelen); + return (FFMIN(written, bytelen)) / ao->sstride; } if (pts == MP_NOPTS_VALUE) { @@ -559,7 +560,7 @@ static int play(struct ao *ao, void *data, int len, int flags) if (ac->offset_left <= -len) { // skip whole frame ac->offset_left += len; - return len * ac->sample_size * ao->channels.num; + return len; } else { // skip part of this frame, buffer/encode the rest bufpos -= ac->offset_left; @@ -632,7 +633,7 @@ static int play(struct ao *ao, void *data, int len, int flags) ectx->next_in_pts = nextpts; } - return bufpos * ac->sample_size * ao->channels.num; + return bufpos; } const struct ao_driver audio_out_lavc = { -- cgit v1.2.3