summaryrefslogtreecommitdiffstats
path: root/filters/f_swresample.c
diff options
context:
space:
mode:
Diffstat (limited to 'filters/f_swresample.c')
-rw-r--r--filters/f_swresample.c73
1 files changed, 33 insertions, 40 deletions
diff --git a/filters/f_swresample.c b/filters/f_swresample.c
index 0f4033b26a..0d88a07af1 100644
--- a/filters/f_swresample.c
+++ b/filters/f_swresample.c
@@ -22,9 +22,8 @@
#include <libavutil/mathematics.h>
#include <libswresample/swresample.h>
-#include "config.h"
-
#include "audio/aframe.h"
+#include "audio/chmap_avchannel.h"
#include "audio/fmt-conversion.h"
#include "audio/format.h"
#include "common/common.h"
@@ -71,14 +70,13 @@ struct priv {
#define OPT_BASE_STRUCT struct mp_resample_opts
const struct m_sub_options resample_conf = {
.opts = (const m_option_t[]) {
- OPT_INTRANGE("audio-resample-filter-size", filter_size, 0, 0, 32),
- OPT_INTRANGE("audio-resample-phase-shift", phase_shift, 0, 0, 30),
- OPT_FLAG("audio-resample-linear", linear, 0),
- OPT_DOUBLE("audio-resample-cutoff", cutoff, M_OPT_RANGE,
- .min = 0, .max = 1),
- OPT_FLAG("audio-normalize-downmix", normalize, 0),
- OPT_DOUBLE("audio-resample-max-output-size", max_output_frame_size, 0),
- OPT_KEYVALUELIST("audio-swresample-o", avopts, 0),
+ {"audio-resample-filter-size", OPT_INT(filter_size), M_RANGE(0, 32)},
+ {"audio-resample-phase-shift", OPT_INT(phase_shift), M_RANGE(0, 30)},
+ {"audio-resample-linear", OPT_BOOL(linear)},
+ {"audio-resample-cutoff", OPT_DOUBLE(cutoff), M_RANGE(0, 1)},
+ {"audio-normalize-downmix", OPT_BOOL(normalize)},
+ {"audio-resample-max-output-size", OPT_DOUBLE(max_output_frame_size)},
+ {"audio-swresample-o", OPT_KEYVALUELIST(avopts)},
{0}
},
.size = sizeof(struct mp_resample_opts),
@@ -272,14 +270,28 @@ static bool configure_lavrr(struct priv *p, bool verbose)
out_ch_layout = fudge_layout_conversion(p, in_ch_layout, out_ch_layout);
+#if HAVE_AV_CHANNEL_LAYOUT
// Real conversion; output is input to avrctx_out.
+ AVChannelLayout in_layout, out_layout;
+ mp_chmap_to_av_layout(&in_layout, &in_lavc);
+ mp_chmap_to_av_layout(&out_layout, &out_lavc);
+ av_opt_set_chlayout(p->avrctx, "in_chlayout", &in_layout, 0);
+ av_opt_set_chlayout(p->avrctx, "out_chlayout", &out_layout, 0);
+#else
av_opt_set_int(p->avrctx, "in_channel_layout", in_ch_layout, 0);
av_opt_set_int(p->avrctx, "out_channel_layout", out_ch_layout, 0);
+#endif
av_opt_set_int(p->avrctx, "in_sample_rate", p->in_rate, 0);
av_opt_set_int(p->avrctx, "out_sample_rate", p->out_rate, 0);
av_opt_set_int(p->avrctx, "in_sample_fmt", in_samplefmt, 0);
av_opt_set_int(p->avrctx, "out_sample_fmt", out_samplefmtp, 0);
+#if HAVE_AV_CHANNEL_LAYOUT
+ AVChannelLayout fake_layout;
+ av_channel_layout_default(&fake_layout, map_out.num);
+ av_opt_set_chlayout(p->avrctx_out, "in_chlayout", &fake_layout, 0);
+ av_opt_set_chlayout(p->avrctx_out, "out_chlayout", &fake_layout, 0);
+#else
// Just needs the correct number of channels for deplanarization.
struct mp_chmap fake_chmap;
mp_chmap_set_unknown(&fake_chmap, map_out.num);
@@ -288,6 +300,7 @@ static bool configure_lavrr(struct priv *p, bool verbose)
goto error;
av_opt_set_int(p->avrctx_out, "in_channel_layout", fake_out_ch_layout, 0);
av_opt_set_int(p->avrctx_out, "out_channel_layout", fake_out_ch_layout, 0);
+#endif
av_opt_set_int(p->avrctx_out, "in_sample_fmt", out_samplefmtp, 0);
av_opt_set_int(p->avrctx_out, "out_sample_fmt", out_samplefmt, 0);
@@ -314,7 +327,7 @@ error:
return false;
}
-static void reset(struct mp_filter *f)
+static void swresample_reset(struct mp_filter *f)
{
struct priv *p = f->priv;
@@ -328,26 +341,6 @@ static void reset(struct mp_filter *f)
close_lavrr(p);
}
-static void extra_output_conversion(struct mp_aframe *mpa)
-{
- int format = af_fmt_from_planar(mp_aframe_get_format(mpa));
- 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);
- if (format == AF_FORMAT_FLOAT) {
- for (int s = 0; s < total; s++)
- ((float *)ptr)[s] = av_clipf(((float *)ptr)[s], -1.0f, 1.0f);
- } else if (format == AF_FORMAT_DOUBLE) {
- for (int s = 0; s < total; s++)
- ((double *)ptr)[s] = MPCLAMP(((double *)ptr)[s], -1.0, 1.0);
- }
- }
-}
-
// This relies on the tricky way mpa was allocated.
static bool reorder_planes(struct mp_aframe *mpa, int *reorder,
struct mp_chmap *newmap)
@@ -357,6 +350,8 @@ static bool reorder_planes(struct mp_aframe *mpa, int *reorder,
int num_planes = mp_aframe_get_planes(mpa);
uint8_t **planes = mp_aframe_get_data_rw(mpa);
+ if (num_planes && !planes)
+ return false;
uint8_t *old_planes[MP_NUM_CHANNELS];
assert(num_planes <= MP_NUM_CHANNELS);
for (int n = 0; n < num_planes; n++)
@@ -452,8 +447,6 @@ static struct mp_frame filter_resample_output(struct priv *p,
goto error;
}
- extra_output_conversion(out);
-
if (in) {
mp_aframe_copy_attributes(out, in);
p->current_pts = mp_aframe_end_pts(in);
@@ -480,7 +473,7 @@ error:
return MP_NO_FRAME;
}
-static void process(struct mp_filter *f)
+static void swresample_process(struct mp_filter *f)
{
struct priv *p = f->priv;
@@ -641,7 +634,7 @@ double mp_swresample_get_delay(struct mp_swresample *s)
return get_delay(p);
}
-static bool command(struct mp_filter *f, struct mp_filter_command *cmd)
+static bool swresample_command(struct mp_filter *f, struct mp_filter_command *cmd)
{
struct priv *p = f->priv;
@@ -653,7 +646,7 @@ static bool command(struct mp_filter *f, struct mp_filter_command *cmd)
return false;
}
-static void destroy(struct mp_filter *f)
+static void swresample_destroy(struct mp_filter *f)
{
struct priv *p = f->priv;
@@ -664,10 +657,10 @@ static void destroy(struct mp_filter *f)
static const struct mp_filter_info swresample_filter = {
.name = "swresample",
.priv_size = sizeof(struct priv),
- .process = process,
- .command = command,
- .reset = reset,
- .destroy = destroy,
+ .process = swresample_process,
+ .command = swresample_command,
+ .reset = swresample_reset,
+ .destroy = swresample_destroy,
};
struct mp_swresample *mp_swresample_create(struct mp_filter *parent,