summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
Diffstat (limited to 'audio')
-rw-r--r--audio/aframe.c6
-rw-r--r--audio/chmap.c20
-rw-r--r--audio/chmap.h13
-rw-r--r--audio/decode/ad_lavc.c33
-rw-r--r--audio/decode/ad_spdif.c70
-rw-r--r--audio/filter/af_drop.c18
-rw-r--r--audio/filter/af_format.c8
-rw-r--r--audio/filter/af_lavcac3enc.c38
-rw-r--r--audio/filter/af_rubberband.c18
-rw-r--r--audio/filter/af_scaletempo.c24
-rw-r--r--audio/filter/af_scaletempo2.c67
-rw-r--r--audio/filter/af_scaletempo2_internals.c188
-rw-r--r--audio/filter/af_scaletempo2_internals.h37
-rw-r--r--audio/format.c8
-rw-r--r--audio/out/ao.c21
-rw-r--r--audio/out/ao.h19
-rw-r--r--audio/out/ao_alsa.c36
-rw-r--r--audio/out/ao_audiotrack.c548
-rw-r--r--audio/out/ao_audiounit.m9
-rw-r--r--audio/out/ao_avfoundation.m372
-rw-r--r--audio/out/ao_coreaudio.c166
-rw-r--r--audio/out/ao_coreaudio_chmap.c232
-rw-r--r--audio/out/ao_coreaudio_chmap.h6
-rw-r--r--audio/out/ao_coreaudio_exclusive.c26
-rw-r--r--audio/out/ao_coreaudio_utils.c64
-rw-r--r--audio/out/ao_coreaudio_utils.h16
-rw-r--r--audio/out/ao_jack.c18
-rw-r--r--audio/out/ao_lavc.c23
-rw-r--r--audio/out/ao_null.c16
-rw-r--r--audio/out/ao_openal.c14
-rw-r--r--audio/out/ao_opensles.c15
-rw-r--r--audio/out/ao_oss.c38
-rw-r--r--audio/out/ao_pcm.c12
-rw-r--r--audio/out/ao_pipewire.c423
-rw-r--r--audio/out/ao_pulse.c39
-rw-r--r--audio/out/ao_sdl.c3
-rw-r--r--audio/out/ao_sndio.c19
-rw-r--r--audio/out/ao_wasapi.c146
-rw-r--r--audio/out/ao_wasapi.h9
-rw-r--r--audio/out/ao_wasapi_utils.c162
-rw-r--r--audio/out/buffer.c274
-rw-r--r--audio/out/internal.h21
42 files changed, 2194 insertions, 1101 deletions
diff --git a/audio/aframe.c b/audio/aframe.c
index 9b0827f64c..cb6ea17be3 100644
--- a/audio/aframe.c
+++ b/audio/aframe.c
@@ -52,8 +52,7 @@ struct mp_aframe *mp_aframe_create(void)
{
struct mp_aframe *frame = talloc_zero(NULL, struct mp_aframe);
frame->av_frame = av_frame_alloc();
- if (!frame->av_frame)
- abort();
+ MP_HANDLE_OOM(frame->av_frame);
talloc_set_destructor(frame, free_frame);
mp_aframe_reset(frame);
return frame;
@@ -701,8 +700,7 @@ int mp_aframe_pool_allocate(struct mp_aframe_pool *pool, struct mp_aframe *frame
if (planes > AV_NUM_DATA_POINTERS) {
av_frame->extended_data =
av_calloc(planes, sizeof(av_frame->extended_data[0]));
- if (!av_frame->extended_data)
- abort();
+ MP_HANDLE_OOM(av_frame->extended_data);
} else {
av_frame->extended_data = av_frame->data;
}
diff --git a/audio/chmap.c b/audio/chmap.c
index cd8c767c47..a56d78dfe2 100644
--- a/audio/chmap.c
+++ b/audio/chmap.c
@@ -52,6 +52,11 @@ static const char *const speaker_names[MP_SPEAKER_ID_COUNT][2] = {
[MP_SPEAKER_ID_SDL] = {"sdl", "surround direct left"},
[MP_SPEAKER_ID_SDR] = {"sdr", "surround direct right"},
[MP_SPEAKER_ID_LFE2] = {"lfe2", "low frequency 2"},
+ [MP_SPEAKER_ID_TSL] = {"tsl", "top side left"},
+ [MP_SPEAKER_ID_TSR] = {"tsr", "top side right"},
+ [MP_SPEAKER_ID_BFC] = {"bfc", "bottom front center"},
+ [MP_SPEAKER_ID_BFL] = {"bfl", "bottom front left"},
+ [MP_SPEAKER_ID_BFR] = {"bfr", "bottom front right"},
[MP_SPEAKER_ID_NA] = {"na", "not available"},
};
@@ -83,7 +88,7 @@ static const char *const std_layout_names[][2] = {
{"6.0(front)", "fl-fr-flc-frc-sl-sr"},
{"hexagonal", "fl-fr-fc-bl-br-bc"},
{"6.1", "fl-fr-fc-lfe-bc-sl-sr"},
- {"6.1(back)", "fl-fr-fc-lfe-bl-br-bc"}, // lavc calls this "6.1" too
+ {"6.1(back)", "fl-fr-fc-lfe-bl-br-bc"},
{"6.1(top)", "fl-fr-fc-lfe-bl-br-tc"}, // not in lavc
{"6.1(front)", "fl-fr-lfe-flc-frc-sl-sr"},
{"7.0", "fl-fr-fc-bl-br-sl-sr"},
@@ -93,8 +98,13 @@ static const char *const std_layout_names[][2] = {
{"7.1(alsa)", "fl-fr-bl-br-fc-lfe-sl-sr"}, // not in lavc
{"7.1(wide)", "fl-fr-fc-lfe-bl-br-flc-frc"},
{"7.1(wide-side)", "fl-fr-fc-lfe-flc-frc-sl-sr"},
+ {"7.1(top)", "fl-fr-fc-lfe-bl-br-tfl-tfr"},
{"7.1(rear)", "fl-fr-fc-lfe-bl-br-sdl-sdr"}, // not in lavc
{"octagonal", "fl-fr-fc-bl-br-bc-sl-sr"},
+ {"cube", "fl-fr-bl-br-tfl-tfr-tbl-tbr"},
+ {"hexadecagonal", "fl-fr-fc-bl-br-bc-sl-sr-tfc-tfl-tfr-tbl-tbc-tbr-wl-wr"},
+ {"downmix", "fl-fr"},
+ {"22.2", "fl-fr-fc-lfe-bl-br-flc-frc-bc-sl-sr-tc-tfl-tfc-tfr-tbl-tbc-tbr-lfe2-tsl-tsr-bfc-bfl-bfr"},
{"auto", ""}, // not in lavc
{0}
};
@@ -229,8 +239,8 @@ void mp_chmap_set_unknown(struct mp_chmap *dst, int num_channels)
}
}
-// Return the ffmpeg/libav channel layout as in <libavutil/channel_layout.h>.
-// Speakers not representable by ffmpeg/libav are dropped.
+// Return the ffmpeg channel layout as in <libavutil/channel_layout.h>.
+// Speakers not representable by ffmpeg are dropped.
// Warning: this ignores the order of the channels, and will return a channel
// mask even if the order is different from libavcodec's.
// Also, "unknown" channel maps are translated to non-sense channel
@@ -253,7 +263,7 @@ uint64_t mp_chmap_to_lavc_unchecked(const struct mp_chmap *src)
return mask;
}
-// Return the ffmpeg/libav channel layout as in <libavutil/channel_layout.h>.
+// Return the ffmpeg channel layout as in <libavutil/channel_layout.h>.
// Returns 0 if the channel order doesn't match lavc's or if it's invalid.
uint64_t mp_chmap_to_lavc(const struct mp_chmap *src)
{
@@ -262,7 +272,7 @@ uint64_t mp_chmap_to_lavc(const struct mp_chmap *src)
return mp_chmap_to_lavc_unchecked(src);
}
-// Set channel map from the ffmpeg/libav channel layout as in
+// Set channel map from the ffmpeg channel layout as in
// <libavutil/channel_layout.h>.
// If the number of channels exceed MP_NUM_CHANNELS, set dst to empty.
void mp_chmap_from_lavc(struct mp_chmap *dst, uint64_t src)
diff --git a/audio/chmap.h b/audio/chmap.h
index 6fbb60d025..58a3f71907 100644
--- a/audio/chmap.h
+++ b/audio/chmap.h
@@ -22,7 +22,7 @@
#include <stdbool.h>
#include "misc/bstr.h"
-#define MP_NUM_CHANNELS 16
+#define MP_NUM_CHANNELS 64
// Speaker a channel can be assigned to.
// This corresponds to WAVEFORMATEXTENSIBLE channel mask bit indexes.
@@ -55,6 +55,11 @@ enum mp_speaker_id {
MP_SPEAKER_ID_SDL, // SURROUND_DIRECT_LEFT
MP_SPEAKER_ID_SDR, // SURROUND_DIRECT_RIGHT
MP_SPEAKER_ID_LFE2, // LOW_FREQUENCY_2
+ MP_SPEAKER_ID_TSL, // TOP_SIDE_LEFT
+ MP_SPEAKER_ID_TSR, // TOP_SIDE_RIGHT,
+ MP_SPEAKER_ID_BFC, // BOTTOM_FRONT_CENTER
+ MP_SPEAKER_ID_BFL, // BOTTOM_FRONT_LEFT
+ MP_SPEAKER_ID_BFR, // BOTTOM_FRONT_RIGHT
// Speaker IDs >= 64 are not representable in WAVEFORMATEXTENSIBLE or libav*.
@@ -124,10 +129,12 @@ void mp_chmap_get_reorder(int src[MP_NUM_CHANNELS], const struct mp_chmap *from,
int mp_chmap_diffn(const struct mp_chmap *a, const struct mp_chmap *b);
char *mp_chmap_to_str_buf(char *buf, size_t buf_size, const struct mp_chmap *src);
-#define mp_chmap_to_str(m) mp_chmap_to_str_buf((char[64]){0}, 64, (m))
+#define mp_chmap_to_str_(m, sz) mp_chmap_to_str_buf((char[sz]){0}, sz, (m))
+#define mp_chmap_to_str(m) mp_chmap_to_str_(m, MP_NUM_CHANNELS * 4)
char *mp_chmap_to_str_hr_buf(char *buf, size_t buf_size, const struct mp_chmap *src);
-#define mp_chmap_to_str_hr(m) mp_chmap_to_str_hr_buf((char[128]){0}, 128, (m))
+#define mp_chmap_to_str_hr_(m, sz) mp_chmap_to_str_hr_buf((char[sz]){0}, sz, (m))
+#define mp_chmap_to_str_hr(m) mp_chmap_to_str_hr_(m, MP_NUM_CHANNELS * 4)
bool mp_chmap_from_str(struct mp_chmap *dst, bstr src);
diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c
index 6ae7d80bf5..9b5f1fb467 100644
--- a/audio/decode/ad_lavc.c
+++ b/audio/decode/ad_lavc.c
@@ -44,8 +44,10 @@
#include "options/options.h"
struct priv {
+ struct mp_codec_params *codec;
AVCodecContext *avctx;
AVFrame *avframe;
+ AVPacket *avpkt;
struct mp_chmap force_channel_map;
uint32_t skip_samples, trim_samples;
bool preroll_done;
@@ -59,7 +61,7 @@ struct priv {
#define OPT_BASE_STRUCT struct ad_lavc_params
struct ad_lavc_params {
float ac3drc;
- int downmix;
+ bool downmix;
int threads;
char **avopts;
};
@@ -67,7 +69,7 @@ struct ad_lavc_params {
const struct m_sub_options ad_lavc_conf = {
.opts = (const m_option_t[]) {
{"ac3drc", OPT_FLOAT(ac3drc), M_RANGE(0, 6)},
- {"downmix", OPT_FLAG(downmix)},
+ {"downmix", OPT_BOOL(downmix)},
{"threads", OPT_INT(threads), M_RANGE(0, 16)},
{"o", OPT_KEYVALUELIST(avopts)},
{0}
@@ -75,7 +77,6 @@ const struct m_sub_options ad_lavc_conf = {
.size = sizeof(struct ad_lavc_params),
.defaults = &(const struct ad_lavc_params){
.ac3drc = 0,
- .downmix = 0,
.threads = 1,
},
};
@@ -104,6 +105,8 @@ static bool init(struct mp_filter *da, struct mp_codec_params *codec,
lavc_context = avcodec_alloc_context3(lavc_codec);
ctx->avctx = lavc_context;
ctx->avframe = av_frame_alloc();
+ ctx->avpkt = av_packet_alloc();
+ MP_HANDLE_OOM(ctx->avctx && ctx->avframe && ctx->avpkt);
lavc_context->codec_type = AVMEDIA_TYPE_AUDIO;
lavc_context->codec_id = lavc_codec->id;
lavc_context->pkt_timebase = ctx->codec_timebase;
@@ -154,15 +157,16 @@ static bool init(struct mp_filter *da, struct mp_codec_params *codec,
return true;
}
-static void destroy(struct mp_filter *da)
+static void ad_lavc_destroy(struct mp_filter *da)
{
struct priv *ctx = da->priv;
avcodec_free_context(&ctx->avctx);
av_frame_free(&ctx->avframe);
+ mp_free_av_packet(&ctx->avpkt);
}
-static void reset(struct mp_filter *da)
+static void ad_lavc_reset(struct mp_filter *da)
{
struct priv *ctx = da->priv;
@@ -185,10 +189,9 @@ static int send_packet(struct mp_filter *da, struct demux_packet *mpkt)
if (mpkt && priv->next_pts == MP_NOPTS_VALUE)
priv->next_pts = mpkt->pts;
- AVPacket pkt;
- mp_set_av_packet(&pkt, mpkt, &priv->codec_timebase);
+ mp_set_av_packet(priv->avpkt, mpkt, &priv->codec_timebase);
- int ret = avcodec_send_packet(avctx, mpkt ? &pkt : NULL);
+ int ret = avcodec_send_packet(avctx, mpkt ? priv->avpkt : NULL);
if (ret < 0)
MP_ERR(da, "Error decoding audio.\n");
return ret;
@@ -217,6 +220,8 @@ static int receive_frame(struct mp_filter *da, struct mp_frame *out)
if (!priv->avframe->buf[0])
return ret;
+ mp_codec_info_from_av(avctx, priv->codec);
+
double out_pts = mp_pts_from_av(priv->avframe->pts, &priv->codec_timebase);
struct mp_aframe *mpframe = mp_aframe_from_avframe(priv->avframe);
@@ -274,7 +279,7 @@ static int receive_frame(struct mp_filter *da, struct mp_frame *out)
return ret;
}
-static void process(struct mp_filter *ad)
+static void ad_lavc_process(struct mp_filter *ad)
{
struct priv *priv = ad->priv;
@@ -284,9 +289,9 @@ static void process(struct mp_filter *ad)
static const struct mp_filter_info ad_lavc_filter = {
.name = "ad_lavc",
.priv_size = sizeof(struct priv),
- .process = process,
- .reset = reset,
- .destroy = destroy,
+ .process = ad_lavc_process,
+ .reset = ad_lavc_reset,
+ .destroy = ad_lavc_destroy,
};
static struct mp_decoder *create(struct mp_filter *parent,
@@ -303,12 +308,16 @@ static struct mp_decoder *create(struct mp_filter *parent,
da->log = mp_log_new(da, parent->log, NULL);
struct priv *priv = da->priv;
+ priv->codec = codec;
priv->public.f = da;
if (!init(da, codec, decoder)) {
talloc_free(da);
return NULL;
}
+
+ codec->codec_desc = priv->avctx->codec_descriptor->long_name;
+
return &priv->public;
}
diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c
index 520803c4b0..98a53f3ca0 100644
--- a/audio/decode/ad_spdif.c
+++ b/audio/decode/ad_spdif.c
@@ -37,10 +37,17 @@
#define OUTBUF_SIZE 65536
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 26, 100)
+#define AV_PROFILE_UNKNOWN FF_PROFILE_UNKNOWN
+#define AV_PROFILE_DTS_HD_HRA FF_PROFILE_DTS_HD_HRA
+#define AV_PROFILE_DTS_HD_MA FF_PROFILE_DTS_HD_MA
+#endif
+
struct spdifContext {
struct mp_log *log;
enum AVCodecID codec_id;
AVFormatContext *lavf_ctx;
+ AVPacket *avpkt;
int out_buffer_len;
uint8_t out_buffer[OUTBUF_SIZE];
bool need_close;
@@ -52,7 +59,11 @@ struct spdifContext {
struct mp_decoder public;
};
+#if LIBAVCODEC_VERSION_MAJOR < 61
static int write_packet(void *p, uint8_t *buf, int buf_size)
+#else
+static int write_packet(void *p, const uint8_t *buf, int buf_size)
+#endif
{
struct spdifContext *ctx = p;
@@ -68,7 +79,7 @@ static int write_packet(void *p, uint8_t *buf, int buf_size)
}
// (called on both filter destruction _and_ if lavf fails to init)
-static void destroy(struct mp_filter *da)
+static void ad_spdif_destroy(struct mp_filter *da)
{
struct spdifContext *spdif_ctx = da->priv;
AVFormatContext *lavf_ctx = spdif_ctx->lavf_ctx;
@@ -78,17 +89,18 @@ static void destroy(struct mp_filter *da)
av_write_trailer(lavf_ctx);
if (lavf_ctx->pb)
av_freep(&lavf_ctx->pb->buffer);
- av_freep(&lavf_ctx->pb);
+ avio_context_free(&lavf_ctx->pb);
avformat_free_context(lavf_ctx);
spdif_ctx->lavf_ctx = NULL;
}
+ mp_free_av_packet(&spdif_ctx->avpkt);
}
static void determine_codec_params(struct mp_filter *da, AVPacket *pkt,
int *out_profile, int *out_rate)
{
struct spdifContext *spdif_ctx = da->priv;
- int profile = FF_PROFILE_UNKNOWN;
+ int profile = AV_PROFILE_UNKNOWN;
AVCodecContext *ctx = NULL;
AVFrame *frame = NULL;
@@ -113,7 +125,7 @@ static void determine_codec_params(struct mp_filter *da, AVPacket *pkt,
av_parser_close(parser);
}
- if (profile != FF_PROFILE_UNKNOWN || spdif_ctx->codec_id != AV_CODEC_ID_DTS)
+ if (profile != AV_PROFILE_UNKNOWN || spdif_ctx->codec_id != AV_CODEC_ID_DTS)
return;
const AVCodec *codec = avcodec_find_decoder(spdif_ctx->codec_id);
@@ -143,15 +155,17 @@ done:
av_frame_free(&frame);
avcodec_free_context(&ctx);
- if (profile == FF_PROFILE_UNKNOWN)
+ if (profile == AV_PROFILE_UNKNOWN)
MP_WARN(da, "Failed to parse codec profile.\n");
}
-static int init_filter(struct mp_filter *da, AVPacket *pkt)
+static int init_filter(struct mp_filter *da)
{
struct spdifContext *spdif_ctx = da->priv;
- int profile = FF_PROFILE_UNKNOWN;
+ AVPacket *pkt = spdif_ctx->avpkt;
+
+ int profile = AV_PROFILE_UNKNOWN;
int c_rate = 0;
determine_codec_params(da, pkt, &profile, &c_rate);
MP_VERBOSE(da, "In: profile=%d samplerate=%d\n", profile, c_rate);
@@ -167,8 +181,7 @@ static int init_filter(struct mp_filter *da, AVPacket *pkt)
goto fail;
void *buffer = av_mallocz(OUTBUF_SIZE);
- if (!buffer)
- abort();
+ MP_HANDLE_OOM(buffer);
lavf_ctx->pb = avio_alloc_context(buffer, OUTBUF_SIZE, 1, spdif_ctx, NULL,
write_packet, NULL);
if (!lavf_ctx->pb) {
@@ -183,7 +196,8 @@ static int init_filter(struct mp_filter *da, AVPacket *pkt)
if (!stream)
goto fail;
- stream->codecpar->codec_id = spdif_ctx->codec_id;
+ stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+ stream->codecpar->codec_id = spdif_ctx->codec_id;
AVDictionary *format_opts = NULL;
@@ -205,15 +219,15 @@ static int init_filter(struct mp_filter *da, AVPacket *pkt)
num_channels = 2;
break;
case AV_CODEC_ID_DTS: {
- bool is_hd = profile == FF_PROFILE_DTS_HD_HRA ||
- profile == FF_PROFILE_DTS_HD_MA ||
- profile == FF_PROFILE_UNKNOWN;
+ bool is_hd = profile == AV_PROFILE_DTS_HD_HRA ||
+ profile == AV_PROFILE_DTS_HD_MA ||
+ profile == AV_PROFILE_UNKNOWN;
// Apparently, DTS-HD over SPDIF is specified to be 7.1 (8 channels)
// for DTS-HD MA, and stereo (2 channels) for DTS-HD HRA. The bit
// streaming rate as well as the signaled channel count are defined
// based on this value.
- int dts_hd_spdif_channel_count = profile == FF_PROFILE_DTS_HD_HRA ?
+ int dts_hd_spdif_channel_count = profile == AV_PROFILE_DTS_HD_HRA ?
2 : 8;
if (spdif_ctx->use_dts_hd && is_hd) {
av_dict_set_int(&format_opts, "dtshd_rate",
@@ -223,7 +237,7 @@ static int init_filter(struct mp_filter *da, AVPacket *pkt)
num_channels = dts_hd_spdif_channel_count;
} else {
sample_format = AF_FORMAT_S_DTS;
- samplerate = 48000;
+ samplerate = c_rate > 44100 ? 48000 : 44100;
num_channels = 2;
}
break;
@@ -247,6 +261,8 @@ static int init_filter(struct mp_filter *da, AVPacket *pkt)
abort();
}
+ stream->codecpar->sample_rate = samplerate;
+
struct mp_chmap chmap;
mp_chmap_from_channels(&chmap, num_channels);
mp_aframe_set_chmap(spdif_ctx->fmt, &chmap);
@@ -267,12 +283,12 @@ static int init_filter(struct mp_filter *da, AVPacket *pkt)
return 0;
fail:
- destroy(da);
+ ad_spdif_destroy(da);
mp_filter_internal_mark_failed(da);
return -1;
}
-static void process(struct mp_filter *da)
+static void ad_spdif_process(struct mp_filter *da)
{
struct spdifContext *spdif_ctx = da->priv;
@@ -295,15 +311,20 @@ static void process(struct mp_filter *da)
struct mp_aframe *out = NULL;
double pts = mpkt->pts;
- AVPacket pkt;
- mp_set_av_packet(&pkt, mpkt, NULL);
- pkt.pts = pkt.dts = 0;
+ if (!spdif_ctx->avpkt) {
+ spdif_ctx->avpkt = av_packet_alloc();
+ MP_HANDLE_OOM(spdif_ctx->avpkt);
+ }
+ mp_set_av_packet(spdif_ctx->avpkt, mpkt, NULL);
+ spdif_ctx->avpkt->pts = spdif_ctx->avpkt->dts = 0;
if (!spdif_ctx->lavf_ctx) {
- if (init_filter(da, &pkt) < 0)
+ if (init_filter(da) < 0)
goto done;
+ assert(spdif_ctx->avpkt);
}
+
spdif_ctx->out_buffer_len = 0;
- int ret = av_write_frame(spdif_ctx->lavf_ctx, &pkt);
+ int ret = av_write_frame(spdif_ctx->lavf_ctx, spdif_ctx->avpkt);
avio_flush(spdif_ctx->lavf_ctx->pb);
if (ret < 0) {
MP_ERR(da, "spdif mux error: '%s'\n", mp_strerror(AVUNERROR(ret)));
@@ -392,8 +413,8 @@ struct mp_decoder_list *select_spdif_codec(const char *codec, const char *pref)
static const struct mp_filter_info ad_spdif_filter = {
.name = "ad_spdif",
.priv_size = sizeof(struct spdifContext),
- .process = process,
- .destroy = destroy,
+ .process = ad_spdif_process,
+ .destroy = ad_spdif_destroy,
};
static struct mp_decoder *create(struct mp_filter *parent,
@@ -424,6 +445,7 @@ static struct mp_decoder *create(struct mp_filter *parent,
talloc_free(da);
return NULL;
}
+
return &spdif_ctx->public;
}
diff --git a/audio/filter/af_drop.c b/audio/filter/af_drop.c
index 724c482720..499389dd2b 100644
--- a/audio/filter/af_drop.c
+++ b/audio/filter/af_drop.c
@@ -11,7 +11,7 @@ struct priv {
struct mp_aframe *last; // for repeating
};
-static void process(struct mp_filter *f)
+static void af_drop_process(struct mp_filter *f)
{
struct priv *p = f->priv;
@@ -52,7 +52,7 @@ static void process(struct mp_filter *f)
mp_pin_in_write(f->ppins[1], frame);
}
-static bool command(struct mp_filter *f, struct mp_filter_command *cmd)
+static bool af_drop_command(struct mp_filter *f, struct mp_filter_command *cmd)
{
struct priv *p = f->priv;
@@ -65,7 +65,7 @@ static bool command(struct mp_filter *f, struct mp_filter_command *cmd)
return false;
}
-static void reset(struct mp_filter *f)
+static void af_drop_reset(struct mp_filter *f)
{
struct priv *p = f->priv;
@@ -73,18 +73,18 @@ static void reset(struct mp_filter *f)
p->diff = 0;
}
-static void destroy(struct mp_filter *f)
+static void af_drop_destroy(struct mp_filter *f)
{
- reset(f);
+ af_drop_reset(f);
}
static const struct mp_filter_info af_drop_filter = {
.name = "drop",
.priv_size = sizeof(struct priv),
- .process = process,
- .command = command,
- .reset = reset,
- .destroy = destroy,
+ .process = af_drop_process,
+ .command = af_drop_command,
+ .reset = af_drop_reset,
+ .destroy = af_drop_destroy,
};
static struct mp_filter *af_drop_create(struct mp_filter *parent, void *options)
diff --git a/audio/filter/af_format.c b/audio/filter/af_format.c
index 88ae99ed56..eddce6422f 100644
--- a/audio/filter/af_format.c
+++ b/audio/filter/af_format.c
@@ -30,7 +30,7 @@ struct f_opts {
int out_srate;
struct m_channels out_channels;
- int fail;
+ bool fail;
};
struct priv {
@@ -38,7 +38,7 @@ struct priv {
struct mp_pin *in_pin;
};
-static void process(struct mp_filter *f)
+static void af_format_process(struct mp_filter *f)
{
struct priv *p = f->priv;
@@ -85,7 +85,7 @@ error:
static const struct mp_filter_info af_format_filter = {
.name = "format",
.priv_size = sizeof(struct priv),
- .process = process,
+ .process = af_format_process,
};
static struct mp_filter *af_format_create(struct mp_filter *parent,
@@ -135,7 +135,7 @@ const struct mp_user_filter_entry af_format = {
{"out-srate", OPT_INT(out_srate), M_RANGE(1000, 8*48000)},
{"out-channels", OPT_CHANNELS(out_channels),
.flags = M_OPT_CHANNELS_LIMITED},
- {"fail", OPT_FLAG(fail)},
+ {"fail", OPT_BOOL(fail)},
{0}
},
},
diff --git a/audio/filter/af_lavcac3enc.c b/audio/filter/af_lavcac3enc.c
index 86c34a1278..def9700d18 100644
--- a/audio/filter/af_lavcac3enc.c
+++ b/audio/filter/af_lavcac3enc.c
@@ -50,13 +50,13 @@
#define AC3_MAX_CHANNELS 6
#define AC3_MAX_CODED_FRAME_SIZE 3840
#define AC3_FRAME_SIZE (6 * 256)
-const static uint16_t ac3_bitrate_tab[19] = {
+static const 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
};
struct f_opts {
- int add_iec61937_header;
+ bool add_iec61937_header;
int bit_rate;
int min_channel_num;
char *encoder;
@@ -103,7 +103,15 @@ static bool reinit(struct mp_filter *f)
if (!bit_rate && chmap.num < AC3_MAX_CHANNELS + 1)
bit_rate = default_bit_rate[chmap.num];
- avcodec_close(s->lavc_actx);
+ avcodec_free_context(&s->lavc_actx);
+ s->lavc_actx = avcodec_alloc_context3(s->lavc_acodec);
+ if (!s->lavc_actx) {
+ MP_ERR(f, "Audio LAVC, couldn't reallocate context!\n");
+ return false;
+ }
+
+ if (mp_set_avopts(f->log, s->lavc_actx, s->opts->avopts) < 0)
+ return false;
// Put sample parameters
s->lavc_actx->sample_fmt = af_to_avformat(format);
@@ -131,18 +139,18 @@ static bool reinit(struct mp_filter *f)
return true;
}
-static void reset(struct mp_filter *f)
+static void af_lavcac3enc_reset(struct mp_filter *f)
{
struct priv *s = f->priv;
TA_FREEP(&s->in_frame);
}
-static void destroy(struct mp_filter *f)
+static void af_lavcac3enc_destroy(struct mp_filter *f)
{
struct priv *s = f->priv;
- reset(f);
+ af_lavcac3enc_reset(f);
av_packet_free(&s->lavc_pkt);
avcodec_free_context(&s->lavc_actx);
}
@@ -153,7 +161,7 @@ static void swap_16(uint16_t *ptr, size_t size)
ptr[n] = av_bswap16(ptr[n]);
}
-static void process(struct mp_filter *f)
+static void af_lavcac3enc_process(struct mp_filter *f)
{
struct priv *s = f->priv;
@@ -187,9 +195,6 @@ static void process(struct mp_filter *f)
case MP_FRAME_AUDIO:
TA_FREEP(&s->in_frame);
s->in_frame = input.data;
- frame = mp_frame_to_av(input, NULL);
- if (!frame)
- goto error;
if (mp_aframe_get_channels(s->in_frame) < s->opts->min_channel_num) {
// Just pass it through.
s->in_frame = NULL;
@@ -200,6 +205,9 @@ static void process(struct mp_filter *f)
if (!reinit(f))
goto error;
}
+ frame = mp_frame_to_av(input, NULL);
+ if (!frame)
+ goto error;
break;
default: goto error; // unexpected packet type
}
@@ -273,9 +281,9 @@ error:
static const struct mp_filter_info af_lavcac3enc_filter = {
.name = "lavcac3enc",
.priv_size = sizeof(struct priv),
- .process = process,
- .reset = reset,
- .destroy = destroy,
+ .process = af_lavcac3enc_process,
+ .reset = af_lavcac3enc_reset,
+ .destroy = af_lavcac3enc_destroy,
};
static void add_chmaps_to_autoconv(struct mp_filter *f,
@@ -418,13 +426,13 @@ const struct mp_user_filter_entry af_lavcac3enc = {
.name = "lavcac3enc",
.priv_size = sizeof(OPT_BASE_STRUCT),
.priv_defaults = &(const OPT_BASE_STRUCT) {
- .add_iec61937_header = 1,
+ .add_iec61937_header = true,
.bit_rate = 640,
.min_channel_num = 3,
.encoder = "ac3",
},
.options = (const struct m_option[]) {
- {"tospdif", OPT_FLAG(add_iec61937_header)},
+ {"tospdif", OPT_BOOL(add_iec61937_header)},
{"bitrate", OPT_CHOICE(bit_rate,
{"auto", 0}, {"default", 0}), M_RANGE(32, 640)},
{"minch", OPT_INT(min_channel_num), M_RANGE(2, 6)},
diff --git a/audio/filter/af_rubberband.c b/audio/filter/af_rubberband.c
index 40b0c7188b..e71937fcb2 100644
--- a/audio/filter/af_rubberband.c
+++ b/audio/filter/af_rubberband.c
@@ -80,7 +80,7 @@ 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
@@ -105,7 +105,7 @@ static bool init_rubberband(struct mp_filter *f)
return true;
}
-sta