summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
Diffstat (limited to 'audio')
-rw-r--r--audio/aframe.c65
-rw-r--r--audio/aframe.h1
-rw-r--r--audio/chmap.c17
-rw-r--r--audio/chmap.h15
-rw-r--r--audio/chmap_avchannel.c51
-rw-r--r--audio/chmap_avchannel.h32
-rw-r--r--audio/decode/ad_lavc.c22
-rw-r--r--audio/filter/af_lavcac3enc.c123
-rw-r--r--audio/filter/af_rubberband.c17
-rw-r--r--audio/filter/af_scaletempo2.c2
-rw-r--r--audio/filter/af_scaletempo2_internals.c13
-rw-r--r--audio/filter/af_scaletempo2_internals.h4
-rw-r--r--audio/out/ao.c46
-rw-r--r--audio/out/ao.h11
-rw-r--r--audio/out/ao_audiotrack.c148
-rw-r--r--audio/out/ao_audiounit.m90
-rw-r--r--audio/out/ao_coreaudio_properties.c2
-rw-r--r--audio/out/ao_lavc.c6
-rw-r--r--audio/out/ao_openal.c12
-rw-r--r--audio/out/ao_opensles.c2
-rw-r--r--audio/out/ao_oss.c1
-rw-r--r--audio/out/ao_pipewire.c759
-rw-r--r--audio/out/ao_sndio.c318
-rw-r--r--audio/out/buffer.c4
24 files changed, 1663 insertions, 98 deletions
diff --git a/audio/aframe.c b/audio/aframe.c
index c2c0df7c9b..9b0827f64c 100644
--- a/audio/aframe.c
+++ b/audio/aframe.c
@@ -18,9 +18,12 @@
#include <libavutil/frame.h>
#include <libavutil/mem.h>
+#include "config.h"
+
#include "common/common.h"
#include "chmap.h"
+#include "chmap_avchannel.h"
#include "fmt-conversion.h"
#include "format.h"
#include "aframe.h"
@@ -121,6 +124,16 @@ struct mp_aframe *mp_aframe_from_avframe(struct AVFrame *av_frame)
if (!av_frame || av_frame->width > 0 || av_frame->height > 0)
return NULL;
+#if HAVE_AV_CHANNEL_LAYOUT
+ if (!av_channel_layout_check(&av_frame->ch_layout))
+ return NULL;
+
+ struct mp_chmap converted_map = { 0 };
+ if (!mp_chmap_from_av_layout(&converted_map, &av_frame->ch_layout)) {
+ return NULL;
+ }
+#endif
+
int format = af_from_avformat(av_frame->format);
if (!format && av_frame->format != AV_SAMPLE_FMT_NONE)
return NULL;
@@ -132,11 +145,15 @@ struct mp_aframe *mp_aframe_from_avframe(struct AVFrame *av_frame)
abort();
frame->format = format;
+#if !HAVE_AV_CHANNEL_LAYOUT
mp_chmap_from_lavc(&frame->chmap, frame->av_frame->channel_layout);
// FFmpeg being a stupid POS again
if (frame->chmap.num != frame->av_frame->channels)
mp_chmap_from_channels(&frame->chmap, av_frame->channels);
+#else
+ frame->chmap = converted_map;
+#endif
if (av_frame->opaque_ref) {
struct avframe_opaque *op = (void *)av_frame->opaque_ref->data;
@@ -204,9 +221,16 @@ void mp_aframe_config_copy(struct mp_aframe *dst, struct mp_aframe *src)
dst->av_frame->sample_rate = src->av_frame->sample_rate;
dst->av_frame->format = src->av_frame->format;
+
+#if !HAVE_AV_CHANNEL_LAYOUT
dst->av_frame->channel_layout = src->av_frame->channel_layout;
// FFmpeg being a stupid POS again
dst->av_frame->channels = src->av_frame->channels;
+#else
+ if (av_channel_layout_copy(&dst->av_frame->ch_layout,
+ &src->av_frame->ch_layout) < 0)
+ abort();
+#endif
}
// Copy "soft" attributes from src to dst, excluding things which affect
@@ -315,13 +339,21 @@ bool mp_aframe_set_chmap(struct mp_aframe *frame, struct mp_chmap *in)
return false;
if (mp_aframe_is_allocated(frame) && in->num != frame->chmap.num)
return false;
+
+#if !HAVE_AV_CHANNEL_LAYOUT
uint64_t lavc_layout = mp_chmap_to_lavc_unchecked(in);
if (!lavc_layout && in->num)
return false;
+#endif
frame->chmap = *in;
+
+#if !HAVE_AV_CHANNEL_LAYOUT
frame->av_frame->channel_layout = lavc_layout;
// FFmpeg being a stupid POS again
frame->av_frame->channels = frame->chmap.num;
+#else
+ mp_chmap_to_av_layout(&frame->av_frame->ch_layout, in);
+#endif
return true;
}
@@ -434,6 +466,37 @@ void mp_aframe_skip_samples(struct mp_aframe *f, int samples)
f->pts += samples / mp_aframe_get_effective_rate(f);
}
+// sanitize a floating point sample value
+#define sanitizef(f) do { \
+ if (!isnormal(f)) \
+ (f) = 0; \
+} while (0)
+
+void mp_aframe_sanitize_float(struct mp_aframe *mpa)
+{
+ int format = af_fmt_from_planar(mp_aframe_get_format(mpa));
+ if (format != AF_FORMAT_FLOAT && format != AF_FORMAT_DOUBLE)
+ return;
+ int num_planes = mp_aframe_get_planes(mpa);
+ uint8_t **planes = mp_aframe_get_data_rw(mpa);
+ if (!planes)
+ return;
+ for (int p = 0; p < num_planes; p++) {
+ void *ptr = planes[p];
+ int total = mp_aframe_get_total_plane_samples(mpa);
+ switch (format) {
+ case AF_FORMAT_FLOAT:
+ for (int s = 0; s < total; s++)
+ sanitizef(((float *)ptr)[s]);
+ break;
+ case AF_FORMAT_DOUBLE:
+ for (int s = 0; s < total; s++)
+ sanitizef(((double *)ptr)[s]);
+ break;
+ }
+ }
+}
+
// Return the timestamp of the sample just after the end of this frame.
double mp_aframe_end_pts(struct mp_aframe *f)
{
@@ -637,7 +700,7 @@ int mp_aframe_pool_allocate(struct mp_aframe_pool *pool, struct mp_aframe *frame
av_freep(&av_frame->extended_data); // sigh
if (planes > AV_NUM_DATA_POINTERS) {
av_frame->extended_data =
- av_mallocz_array(planes, sizeof(av_frame->extended_data[0]));
+ av_calloc(planes, sizeof(av_frame->extended_data[0]));
if (!av_frame->extended_data)
abort();
} else {
diff --git a/audio/aframe.h b/audio/aframe.h
index be456a3dd1..d19c7e8bcb 100644
--- a/audio/aframe.h
+++ b/audio/aframe.h
@@ -60,6 +60,7 @@ char *mp_aframe_format_str_buf(char *buf, size_t buf_size, struct mp_aframe *fmt
#define mp_aframe_format_str(fmt) mp_aframe_format_str_buf((char[32]){0}, 32, (fmt))
void mp_aframe_skip_samples(struct mp_aframe *f, int samples);
+void mp_aframe_sanitize_float(struct mp_aframe *f);
double mp_aframe_end_pts(struct mp_aframe *f);
double mp_aframe_duration(struct mp_aframe *f);
void mp_aframe_clip_timestamps(struct mp_aframe *f, double start, double end);
diff --git a/audio/chmap.c b/audio/chmap.c
index edbe83eb68..cd8c767c47 100644
--- a/audio/chmap.c
+++ b/audio/chmap.c
@@ -470,6 +470,23 @@ char *mp_chmap_to_str_hr_buf(char *buf, size_t buf_size, const struct mp_chmap *
return mp_chmap_to_str_buf(buf, buf_size, &map);
}
+mp_ch_layout_tuple *mp_iterate_builtin_layouts(void **opaque)
+{
+ uintptr_t i = (uintptr_t)*opaque;
+
+ if (i >= MP_ARRAY_SIZE(std_layout_names) ||
+ !std_layout_names[i][0])
+ return NULL;
+
+ *opaque = (void *)(i + 1);
+
+ if (std_layout_names[i][1][0] == '\0') {
+ return mp_iterate_builtin_layouts(opaque);
+ }
+
+ return &std_layout_names[i];
+}
+
void mp_chmap_print_help(struct mp_log *log)
{
mp_info(log, "Speakers:\n");
diff --git a/audio/chmap.h b/audio/chmap.h
index dff69336d6..6fbb60d025 100644
--- a/audio/chmap.h
+++ b/audio/chmap.h
@@ -75,6 +75,8 @@ struct mp_chmap {
uint8_t speaker[MP_NUM_CHANNELS];
};
+typedef const char * const (mp_ch_layout_tuple)[2];
+
#define MP_SP(speaker) MP_SPEAKER_ID_ ## speaker
#define MP_CHMAP2(a, b) \
@@ -129,6 +131,19 @@ char *mp_chmap_to_str_hr_buf(char *buf, size_t buf_size, const struct mp_chmap *
bool mp_chmap_from_str(struct mp_chmap *dst, bstr src);
+/**
+ * Iterate over all built-in channel layouts which have mapped channels.
+ *
+ * @param opaque a pointer where the iteration state is stored. Must point
+ * to nullptr to start the iteration.
+ *
+ * @return nullptr when the iteration is finished.
+ * Otherwise a pointer to an array of two char pointers.
+ * - [0] being the human-readable layout name.
+ * - [1] being the string representation of the layout.
+ */
+mp_ch_layout_tuple *mp_iterate_builtin_layouts(void **opaque);
+
struct mp_log;
void mp_chmap_print_help(struct mp_log *log);
diff --git a/audio/chmap_avchannel.c b/audio/chmap_avchannel.c
new file mode 100644
index 0000000000..ec961de422
--- /dev/null
+++ b/audio/chmap_avchannel.c
@@ -0,0 +1,51 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libavutil/channel_layout.h>
+
+#include "chmap.h"
+#include "chmap_avchannel.h"
+
+bool mp_chmap_from_av_layout(struct mp_chmap *dst, const AVChannelLayout *src)
+{
+ *dst = (struct mp_chmap) {0};
+
+ switch (src->order) {
+ case AV_CHANNEL_ORDER_UNSPEC:
+ mp_chmap_from_channels(dst, src->nb_channels);
+ return dst->num == src->nb_channels;
+ case AV_CHANNEL_ORDER_NATIVE:
+ mp_chmap_from_lavc(dst, src->u.mask);
+ return dst->num == src->nb_channels;
+ default:
+ // TODO: handle custom layouts
+ return false;
+ }
+}
+
+void mp_chmap_to_av_layout(AVChannelLayout *dst, const struct mp_chmap *src)
+{
+ *dst = (AVChannelLayout){
+ .order = AV_CHANNEL_ORDER_UNSPEC,
+ .nb_channels = src->num,
+ };
+
+ // TODO: handle custom layouts
+ if (!mp_chmap_is_unknown(src)) {
+ av_channel_layout_from_mask(dst, mp_chmap_to_lavc(src));
+ }
+}
diff --git a/audio/chmap_avchannel.h b/audio/chmap_avchannel.h
new file mode 100644
index 0000000000..e136ccc7ce
--- /dev/null
+++ b/audio/chmap_avchannel.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <libavutil/channel_layout.h>
+
+#include "config.h"
+
+#include "chmap.h"
+
+#if HAVE_AV_CHANNEL_LAYOUT
+
+bool mp_chmap_from_av_layout(struct mp_chmap *dst, const AVChannelLayout *src);
+
+void mp_chmap_to_av_layout(AVChannelLayout *dst, const struct mp_chmap *src);
+
+#endif
diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c
index 228054e8d6..6ae7d80bf5 100644
--- a/audio/decode/ad_lavc.c
+++ b/audio/decode/ad_lavc.c
@@ -26,8 +26,11 @@
#include <libavutil/common.h>
#include <libavutil/intreadwrite.h>
+#include "config.h"
+
#include "mpv_talloc.h"
#include "audio/aframe.h"
+#include "audio/chmap_avchannel.h"
#include "audio/fmt-conversion.h"
#include "common/av_common.h"
#include "common/codecs.h"
@@ -106,8 +109,22 @@ static bool init(struct mp_filter *da, struct mp_codec_params *codec,
lavc_context->pkt_timebase = ctx->codec_timebase;
if (opts->downmix && mpopts->audio_output_channels.num_chmaps == 1) {
+ const struct mp_chmap *requested_layout =
+ &mpopts->audio_output_channels.chmaps[0];
+#if !HAVE_AV_CHANNEL_LAYOUT
lavc_context->request_channel_layout =
- mp_chmap_to_lavc(&mpopts->audio_output_channels.chmaps[0]);
+ mp_chmap_to_lavc(requested_layout);
+#else
+ AVChannelLayout av_layout = { 0 };
+ mp_chmap_to_av_layout(&av_layout, requested_layout);
+
+ // Always try to set requested output layout - currently only something
+ // supported by AC3, MLP/TrueHD, DTS and the fdk-aac wrapper.
+ av_opt_set_chlayout(lavc_context, "downmix", &av_layout,
+ AV_OPT_SEARCH_CHILDREN);
+
+ av_channel_layout_uninit(&av_layout);
+#endif
}
// Always try to set - option only exists for AC3 at the moment
@@ -243,6 +260,9 @@ static int receive_frame(struct mp_filter *da, struct mp_frame *out)
priv->trim_samples -= trim;
}
+ // Strip possibly bogus float values like Infinity, NaN, denormalized
+ mp_aframe_sanitize_float(mpframe);
+
if (mp_aframe_get_size(mpframe) > 0) {
*out = MAKE_FRAME(MP_FRAME_AUDIO, mpframe);
} else {
diff --git a/audio/filter/af_lavcac3enc.c b/audio/filter/af_lavcac3enc.c
index 45e0aa64a2..86c34a1278 100644
--- a/audio/filter/af_lavcac3enc.c
+++ b/audio/filter/af_lavcac3enc.c
@@ -31,7 +31,10 @@
#include <libavutil/bswap.h>
#include <libavutil/mem.h>
+#include "config.h"
+
#include "audio/aframe.h"
+#include "audio/chmap_avchannel.h"
#include "audio/chmap_sel.h"
#include "audio/fmt-conversion.h"
#include "audio/format.h"
@@ -47,7 +50,7 @@
#define AC3_MAX_CHANNELS 6
#define AC3_MAX_CODED_FRAME_SIZE 3840
#define AC3_FRAME_SIZE (6 * 256)
-const uint16_t ac3_bitrate_tab[19] = {
+const static uint16_t ac3_bitrate_tab[19] = {
32, 40, 48, 56, 64, 80, 96, 112, 128,
160, 192, 224, 256, 320, 384, 448, 512, 576, 640
};
@@ -70,6 +73,7 @@ struct priv {
const struct AVCodec *lavc_acodec;
struct AVCodecContext *lavc_actx;
+ AVPacket *lavc_pkt;
int bit_rate;
int out_samples; // upper bound on encoded output per AC3 frame
};
@@ -103,8 +107,13 @@ static bool reinit(struct mp_filter *f)
// Put sample parameters
s->lavc_actx->sample_fmt = af_to_avformat(format);
+
+#if !HAVE_AV_CHANNEL_LAYOUT
s->lavc_actx->channels = chmap.num;
s->lavc_actx->channel_layout = mp_chmap_to_lavc(&chmap);
+#else
+ mp_chmap_to_av_layout(&s->lavc_actx->ch_layout, &chmap);
+#endif
s->lavc_actx->sample_rate = rate;
s->lavc_actx->bit_rate = bit_rate;
@@ -134,6 +143,7 @@ static void destroy(struct mp_filter *f)
struct priv *s = f->priv;
reset(f);
+ av_packet_free(&s->lavc_pkt);
avcodec_free_context(&s->lavc_actx);
}
@@ -152,57 +162,57 @@ static void process(struct mp_filter *f)
bool err = true;
struct mp_aframe *out = NULL;
- AVPacket pkt = {0};
- av_init_packet(&pkt);
+ AVPacket *pkt = s->lavc_pkt;
// Send input as long as it wants.
while (1) {
if (avcodec_is_open(s->lavc_actx)) {
- int lavc_ret = avcodec_receive_packet(s->lavc_actx, &pkt);
+ int lavc_ret = avcodec_receive_packet(s->lavc_actx, pkt);
if (lavc_ret >= 0)
break;
if (lavc_ret < 0 && lavc_ret != AVERROR(EAGAIN)) {
MP_FATAL(f, "Encode failed (receive).\n");
- goto done;
+ goto error;
}
}
AVFrame *frame = NULL;
struct mp_frame input = mp_pin_out_read(s->in_pin);
// The following code assumes no sample data buffering in the encoder.
- if (input.type == MP_FRAME_EOF) {
+ switch (input.type) {
+ case MP_FRAME_NONE:
+ goto done; // no data yet
+ case MP_FRAME_EOF:
mp_pin_in_write(f->ppins[1], input);
- return;
- } else if (input.type == MP_FRAME_AUDIO) {
+ goto done;
+ case MP_FRAME_AUDIO:
TA_FREEP(&s->in_frame);
s->in_frame = input.data;
frame = mp_frame_to_av(input, NULL);
if (!frame)
- goto done;
+ goto error;
if (mp_aframe_get_channels(s->in_frame) < s->opts->min_channel_num) {
// Just pass it through.
s->in_frame = NULL;
mp_pin_in_write(f->ppins[1], input);
- return;
+ goto done;
}
if (!mp_aframe_config_equals(s->in_frame, s->cur_format)) {
if (!reinit(f))
- goto done;
+ goto error;
}
- } else if (input.type) {
- goto done;
- } else {
- return; // no data yet
+ break;
+ default: goto error; // unexpected packet type
}
int lavc_ret = avcodec_send_frame(s->lavc_actx, frame);
av_frame_free(&frame);
if (lavc_ret < 0 && lavc_ret != AVERROR(EAGAIN)) {
MP_FATAL(f, "Encode failed (send).\n");
- goto done;
+ goto error;
}
}
if (!s->in_frame)
- goto done;
+ goto error;
out = mp_aframe_create();
mp_aframe_set_format(out, AF_FORMAT_S_AC3);
@@ -210,18 +220,18 @@ static void process(struct mp_filter *f)
mp_aframe_set_rate(out, 48000);
if (mp_aframe_pool_allocate(s->out_pool, out, s->out_samples) < 0)
- goto done;
+ goto error;
int sstride = mp_aframe_get_sstride(out);
mp_aframe_copy_attributes(out, s->in_frame);
- int frame_size = pkt.size;
+ int frame_size = pkt->size;
int header_len = 0;
char hdr[8];
- if (s->opts->add_iec61937_header && pkt.size > 5) {
- int bsmod = pkt.data[5] & 0x7;
+ if (s->opts->add_iec61937_header && pkt->size > 5) {
+ int bsmod = pkt->data[5] & 0x7;
int len = frame_size;
frame_size = AC3_FRAME_SIZE * 2 * 2;
@@ -239,20 +249,22 @@ static void process(struct mp_filter *f)
uint8_t **planes = mp_aframe_get_data_rw(out);
if (!planes)
- goto done;
+ goto error;
char *buf = planes[0];
memcpy(buf, hdr, header_len);
- memcpy(buf + header_len, pkt.data, pkt.size);
- memset(buf + header_len + pkt.size, 0,
- frame_size - (header_len + pkt.size));
- swap_16((uint16_t *)(buf + header_len), pkt.size / 2);
+ memcpy(buf + header_len, pkt->data, pkt->size);
+ memset(buf + header_len + pkt->size, 0,
+ frame_size - (header_len + pkt->size));
+ swap_16((uint16_t *)(buf + header_len), pkt->size / 2);
mp_aframe_set_size(out, frame_size / sstride);
mp_pin_in_write(f->ppins[1], MAKE_FRAME(MP_FRAME_AUDIO, out));
out = NULL;
- err = 0;
done:
- av_packet_unref(&pkt);
+ err = false;
+ // fall through
+error:
+ av_packet_unref(pkt);
talloc_free(out);
if (err)
mp_filter_internal_mark_failed(f);
@@ -266,6 +278,38 @@ static const struct mp_filter_info af_lavcac3enc_filter = {
.destroy = destroy,
};
+static void add_chmaps_to_autoconv(struct mp_filter *f,
+ struct mp_autoconvert *conv,
+ const struct AVCodec *codec)
+{
+#if !HAVE_AV_CHANNEL_LAYOUT
+ const uint64_t *lch = codec->channel_layouts;
+ for (int n = 0; lch && lch[n]; n++) {
+ struct mp_chmap chmap = {0};
+ mp_chmap_from_lavc(&chmap, lch[n]);
+ if (mp_chmap_is_valid(&chmap))
+ mp_autoconvert_add_chmap(conv, &chmap);
+ }
+#else
+ const AVChannelLayout *lch = codec->ch_layouts;
+ for (int n = 0; lch && lch[n].nb_channels; n++) {
+ struct mp_chmap chmap = {0};
+
+ if (!mp_chmap_from_av_layout(&chmap, &lch[n])) {
+ char layout[128] = {0};
+ MP_VERBOSE(f, "Skipping unsupported channel layout: %s\n",
+ av_channel_layout_describe(&lch[n],
+ layout, 128) < 0 ?
+ "undefined" : layout);
+ continue;
+ }
+
+ if (mp_chmap_is_valid(&chmap))
+ mp_autoconvert_add_chmap(conv, &chmap);
+ }
+#endif
+}
+
static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent,
void *options)
{
@@ -295,14 +339,23 @@ static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent,
goto error;
}
+ s->lavc_pkt = av_packet_alloc();
+ if (!s->lavc_pkt)
+ goto error;
+
if (mp_set_avopts(f->log, s->lavc_actx, s->opts->avopts) < 0)
goto error;
- // For this one, we require the decoder to expert lists of all supported
+ // For this one, we require the decoder to export lists of all supported
// parameters. (Not all decoders do that, but the ones we're interested
// in do.)
if (!s->lavc_acodec->sample_fmts ||
- !s->lavc_acodec->channel_layouts)
+#if !HAVE_AV_CHANNEL_LAYOUT
+ !s->lavc_acodec->channel_layouts
+#else
+ !s->lavc_acodec->ch_layouts
+#endif
+ )
{
MP_ERR(f, "Audio encoder doesn't list supported parameters.\n");
goto error;
@@ -334,13 +387,7 @@ static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent,
mp_autoconvert_add_afmt(conv, mpfmt);
}
- const uint64_t *lch = s->lavc_acodec->channel_layouts;
- for (int n = 0; lch && lch[n]; n++) {
- struct mp_chmap chmap = {0};
- mp_chmap_from_lavc(&chmap, lch[n]);
- if (mp_chmap_is_valid(&chmap))
- mp_autoconvert_add_chmap(conv, &chmap);
- }
+ add_chmaps_to_autoconv(f, conv, s->lavc_acodec);
// At least currently, the AC3 encoder doesn't export sample rates.
mp_autoconvert_add_srate(conv, 48000);
@@ -357,6 +404,8 @@ static struct mp_filter *af_lavcac3enc_create(struct mp_filter *parent,
return f;
error:
+ av_packet_free(&s->lavc_pkt);
+ avcodec_free_context(&s->lavc_actx);
talloc_free(f);
return NULL;
}
diff --git a/audio/filter/af_rubberband.c b/audio/filter/af_rubberband.c
index 4df2001c49..40b0c7188b 100644
--- a/audio/filter/af_rubberband.c
+++ b/audio/filter/af_rubberband.c
@@ -20,6 +20,8 @@
#include <rubberband/rubberband-c.h>
+#include "config.h"
+
#include "audio/aframe.h"
#include "audio/format.h"
#include "common/common.h"
@@ -31,7 +33,7 @@
// command line options
struct f_opts {
int transients, detector, phase, window,
- smoothing, formant, pitch, channels;
+ smoothing, formant, pitch, channels, engine;
double scale;
};
@@ -78,7 +80,10 @@ static bool init_rubberband(struct mp_filter *f)
int opts = p->opts->transients | p->opts->detector | p->opts->phase |
p->opts->window | p->opts->smoothing | p->opts->formant |
- p->opts->pitch | p-> opts->channels |
+ p->opts->pitch | p->opts->channels |
+#if HAVE_RUBBERBAND_3
+ p->opts->engine |
+#endif
RubberBandOptionProcessRealTime;
int rate = mp_aframe_get_rate(p->pending);
@@ -331,6 +336,9 @@ const struct mp_user_filter_entry af_rubberband = {
.transients = RubberBandOptionTransientsMixed,
.formant = RubberBandOptionFormantPreserved,
.channels = RubberBandOptionChannelsTogether,
+#if HAVE_RUBBERBAND_3
+ .engine = RubberBandOptionEngineFiner,
+#endif
},
.options = (const struct m_option[]) {
{"transients", OPT_CHOICE(transients,
@@ -361,6 +369,11 @@ const struct mp_user_filter_entry af_rubberband = {
{"channels", OPT_CHOICE(channels,
{"apart", RubberBandOptionChannelsApart},
{"together", RubberBandOptionChannelsTogether})},
+#if HAVE_RUBBERBAND_3
+ {"engine", OPT_CHOICE(engine,
+ {"finer", RubberBandOptionEngineFiner},
+ {"faster", RubberBandOptionEngineFaster})},
+#endif
{"pitch-scale", OPT_DOUBLE(scale), M_RANGE(0.01, 100)},
{0}
},
diff --git a/audio/filter/af_scaletempo2.c b/audio/filter/af_scaletempo2.c
index ceac919d5d..1a822ecd50 100644
--- a/audio/filter/af_scaletempo2.c
+++ b/audio/filter/af_scaletempo2.c
@@ -230,7 +230,7 @@ const struct mp_user_filter_entry af_scaletempo2 = {
.wsola_search_interval_ms = 30,
},
.options = (const struct m_option[]) {
- {"search-interval",
+ {"search-interval",
OPT_FLOAT(wsola_search_interval_ms), M_RANGE(1, 1000)},
{"window-size",
OPT_FLOAT(ola_window_size_ms), M_RANGE(1, 1000)},
diff --git a/audio/filter/af_scaletempo2_internals.c b/audio/filter/af_scaletempo2_internals.c
index 1cee7e469f..6cfa540e93 100644
--- a/audio/filter/af_scaletempo2_internals.c
+++ b/audio/filter/af_scaletempo2_internals.c
@@ -472,10 +472,8 @@ static int frames_needed(struct mp_scaletempo2 *p)
static void resize_input_buffer(struct mp_scaletempo2 *p, int size)
{
- if (size > p->input_buffer_size) {
- p->input_buffer_size = size;
- p->input_buffer = realloc_2d(p->input_buffer, p->channels, size);
- }
+ p->input_buffer_size = size;
+ p->input_buffer = realloc_2d(p->input_buffer, p->channels, size);
}
int mp_scaletempo2_fill_input_buffer(struct mp_scaletempo2 *p,
@@ -487,7 +485,8 @@ int mp_scaletempo2_fill_input_buffer(struct mp_scaletempo2 *p,
if (total_fill == 0) return 0;
int required_size = total_fill + p->input_buffer_frames;
- resize_input_buffer(p, required_size);
+ if (required_size > p->input_buffer_size)
+ resize_input_buffer(p, required_size);
for (int i = 0; i < p->channels; ++i) {
memcpy(p->input_buffer[i] + p->input_buffer_frames,
@@ -743,9 +742,9 @@ void mp_scaletempo2_init(struct mp_scaletempo2 *p, int channels, int rate)
p->channels = channels;
p->samples_per_second = rate;
- p->num_candidate_blocks = (int)(p->opts->wsola_search_interval_ms
+ p->num_candidate_blocks = (int)(p->opts->wsola_search_interval_ms
* p->samples_per_second / 1000);
- p->ola_window_size = (int)(p->opts->ola_window_size_ms
+ p->ola_window_size = (int)(p->opts->ola_window_size_ms
* p->samples_per_second / 1000);
// Make sure window size in an even number.
p->ola_window_size += p->ola_window_size & 1;
diff --git a/audio/filter/af_scaletempo2_internals.h b/audio/filter/af_scaletempo2_internals.h
index 3557cd3bd1..c95256b199 100644
--- a/audio/filter/af_scaletempo2_internals.h
+++ b/audio/filter/af_scaletempo2_internals.h
@@ -1,4 +1,4 @@
-// This filter was ported from Chromium
+// This filter was ported from Chromium
// (https://chromium.googlesource.com/chromium/chromium/+/51ed77e3f37a9a9b80d6d0a8259e84a8ca635259/media/filters/audio_renderer_algorithm.cc)
//
// Copyright 2015 The Chromium Authors. All rights reserved.
@@ -118,4 +118,4 @@ int mp_scaletempo2_fill_input_buffer(struct mp_scaletempo2 *p,
uint8_t **planes, int frame_size, bool final);
int mp_scaletempo2_fill_buffer(struct mp_scaletempo2 *p,
float **dest, int dest_size, float playback_rate);
-bool mp_scaletempo2_frames_available(struct mp_scaletempo2 *p); \ No newline at end of file
+bool mp_scaletempo2_frames_available(struct mp_scaletempo2 *p);
diff --git a/audio/out/ao.c b/audio/out/ao.c
index 7c347cb138..397af50a78 100644
--- a/audio/out/ao.c
+++ b/audio/out/ao.c
@@ -41,6 +41,8 @@ extern const struct ao_driver audio_out_audiounit;
extern const struct ao_driver audio_out_coreaudio;
extern const struct ao_driver audio_out_coreaudio_exclusive;
extern const struct ao_driver audio_out_rsound;
+extern const struct ao_driver audio_out_pipewire;
+extern const struct ao_driver audio_out_sndio;
extern const struct ao_driver audio_out_pulse;
extern const struct ao_driver audio_out_jack;
extern const struct ao_driver audio_out_openal;
@@ -88,6 +90,12 @@ static const struct ao_driver * const audio_out_drivers[] = {
#if HAVE_SDL2_AUDIO
&audio_out_sdl,
#endif
+#if HAVE_PIPEWIRE
+ &audio_out_pipewire,
+#endif
+#if HAVE_SNDIO
+ &audio_out_sndio,
+#endif
&audio_out_null,
#if HAVE_COREAUDIO
&audio_out_coreaudio_exclusive,
@@ -120,7 +128,6 @@ static bool get_desc(struct m_obj_desc *dst, int index)
static const struct m_obj_list ao_obj_list = {
.get_desc = get_desc,
.description = "audio outputs",
- .allow_unknown_entries = true,
.allow_trailer = true,
.disallow_positional_parameters = true,
.use_global_options = true,
@@ -446,8 +453,9 @@ struct ao_hotplug {
void *wakeup_ctx;
// A single AO instance is used to listen to hotplug events. It wouldn't
// make much sense to allow multiple AO drivers; all sane platforms have
- // a single such audio API.
- // This is _not_ the same AO instance as used for playing audio.
+ // a single audio API providing all events.
+ // This is _not_ necessarily the same AO instance as used for playing
+ // audio.
struct ao *ao;
// cached
struct ao_device_list *list;
@@ -487,7 +495,8 @@ bool ao_hotplug_check_update(struct ao_hotplug *hp)
}