swresample: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
b2d6e7a289
commit
8a5896ec1f
8 changed files with 501 additions and 180 deletions
|
|
@ -26,39 +26,79 @@
|
|||
|
||||
int swr_config_frame(SwrContext *s, const AVFrame *out, const AVFrame *in)
|
||||
{
|
||||
AVChannelLayout ch_layout = { 0 };
|
||||
int ret;
|
||||
|
||||
swr_close(s);
|
||||
|
||||
if (in) {
|
||||
if (av_opt_set_int(s, "icl", in->channel_layout, 0) < 0)
|
||||
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
// if the old/new fields are set inconsistently, prefer the old ones
|
||||
if ((in->channel_layout && (in->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
|
||||
in->ch_layout.u.mask != in->channel_layout))) {
|
||||
av_channel_layout_from_mask(&ch_layout, in->channel_layout);
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
} else
|
||||
#endif
|
||||
if ((ret = av_channel_layout_copy(&ch_layout, &in->ch_layout)) < 0)
|
||||
goto fail;
|
||||
if (av_opt_set_int(s, "isf", in->format, 0) < 0)
|
||||
if ((ret = av_opt_set_chlayout(s, "ichl", &ch_layout, 0)) < 0)
|
||||
goto fail;
|
||||
if (av_opt_set_int(s, "isr", in->sample_rate, 0) < 0)
|
||||
if ((ret = av_opt_set_int(s, "isf", in->format, 0)) < 0)
|
||||
goto fail;
|
||||
if ((ret = av_opt_set_int(s, "isr", in->sample_rate, 0)) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (out) {
|
||||
if (av_opt_set_int(s, "ocl", out->channel_layout, 0) < 0)
|
||||
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
// if the old/new fields are set inconsistently, prefer the old ones
|
||||
if ((out->channel_layout && (out->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
|
||||
out->ch_layout.u.mask != out->channel_layout))) {
|
||||
av_channel_layout_uninit(&ch_layout);
|
||||
av_channel_layout_from_mask(&ch_layout, out->channel_layout);
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
} else
|
||||
#endif
|
||||
if ((ret = av_channel_layout_copy(&ch_layout, &out->ch_layout)) < 0)
|
||||
goto fail;
|
||||
if (av_opt_set_int(s, "osf", out->format, 0) < 0)
|
||||
if ((ret = av_opt_set_chlayout(s, "ochl", &ch_layout, 0)) < 0)
|
||||
goto fail;
|
||||
if (av_opt_set_int(s, "osr", out->sample_rate, 0) < 0)
|
||||
if ((ret = av_opt_set_int(s, "osf", out->format, 0)) < 0)
|
||||
goto fail;
|
||||
if ((ret = av_opt_set_int(s, "osr", out->sample_rate, 0)) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return 0;
|
||||
ret = 0;
|
||||
fail:
|
||||
av_log(s, AV_LOG_ERROR, "Failed to set option\n");
|
||||
return AVERROR(EINVAL);
|
||||
if (ret < 0)
|
||||
av_log(s, AV_LOG_ERROR, "Failed to set option\n");
|
||||
av_channel_layout_uninit(&ch_layout);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int config_changed(SwrContext *s,
|
||||
const AVFrame *out, const AVFrame *in)
|
||||
{
|
||||
AVChannelLayout ch_layout = { 0 };
|
||||
int ret = 0;
|
||||
|
||||
if (in) {
|
||||
if (s->in_ch_layout != in->channel_layout ||
|
||||
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
// if the old/new fields are set inconsistently, prefer the old ones
|
||||
if ((in->channel_layout && (in->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
|
||||
in->ch_layout.u.mask != in->channel_layout))) {
|
||||
av_channel_layout_from_mask(&ch_layout, in->channel_layout);
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
} else
|
||||
#endif
|
||||
if ((ret = av_channel_layout_copy(&ch_layout, &in->ch_layout)) < 0)
|
||||
return ret;
|
||||
if (av_channel_layout_compare(&s->in_ch_layout, &ch_layout) ||
|
||||
s->in_sample_rate != in->sample_rate ||
|
||||
s->in_sample_fmt != in->format) {
|
||||
ret |= AVERROR_INPUT_CHANGED;
|
||||
|
|
@ -66,12 +106,25 @@ static int config_changed(SwrContext *s,
|
|||
}
|
||||
|
||||
if (out) {
|
||||
if (s->out_ch_layout != out->channel_layout ||
|
||||
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
// if the old/new fields are set inconsistently, prefer the old ones
|
||||
if ((out->channel_layout && (out->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
|
||||
out->ch_layout.u.mask != out->channel_layout))) {
|
||||
av_channel_layout_uninit(&ch_layout);
|
||||
av_channel_layout_from_mask(&ch_layout, out->channel_layout);
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
} else
|
||||
#endif
|
||||
if ((ret = av_channel_layout_copy(&ch_layout, &out->ch_layout)) < 0)
|
||||
return ret;
|
||||
if (av_channel_layout_compare(&s->out_ch_layout, &ch_layout) ||
|
||||
s->out_sample_rate != out->sample_rate ||
|
||||
s->out_sample_fmt != out->format) {
|
||||
ret |= AVERROR_OUTPUT_CHANGED;
|
||||
}
|
||||
}
|
||||
av_channel_layout_uninit(&ch_layout);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -116,7 +169,14 @@ static inline int available_samples(AVFrame *out)
|
|||
if (av_sample_fmt_is_planar(out->format)) {
|
||||
return samples;
|
||||
} else {
|
||||
int channels = av_get_channel_layout_nb_channels(out->channel_layout);
|
||||
int channels;
|
||||
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||
FF_DISABLE_DEPRECATION_WARNINGS
|
||||
channels = av_get_channel_layout_nb_channels(out->channel_layout);
|
||||
FF_ENABLE_DEPRECATION_WARNINGS
|
||||
if (!channels)
|
||||
#endif
|
||||
channels = out->ch_layout.nb_channels;
|
||||
return samples / channels;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue