diff options
author | James Almer <jamrial@gmail.com> | 2021-08-27 00:37:53 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2022-03-15 09:42:46 -0300 |
commit | 8a5896ec1f635ccf0d726f7ba7a06649ebeebf25 (patch) | |
tree | 0bacc18f14f855caa2e4b9155cec9f6953d36fc3 /libswresample/swresample_frame.c | |
parent | b2d6e7a2892445ceb14947ae7c959d55e34aba1f (diff) | |
download | ffmpeg-8a5896ec1f635ccf0d726f7ba7a06649ebeebf25.tar.gz |
swresample: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libswresample/swresample_frame.c')
-rw-r--r-- | libswresample/swresample_frame.c | 84 |
1 files changed, 72 insertions, 12 deletions
diff --git a/libswresample/swresample_frame.c b/libswresample/swresample_frame.c index d95c1cc537..53ac487136 100644 --- a/libswresample/swresample_frame.c +++ b/libswresample/swresample_frame.c @@ -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 ((ret = av_opt_set_chlayout(s, "ochl", &ch_layout, 0)) < 0) goto fail; - if (av_opt_set_int(s, "osf", out->format, 0) < 0) + if ((ret = av_opt_set_int(s, "osf", out->format, 0)) < 0) goto fail; - if (av_opt_set_int(s, "osr", out->sample_rate, 0) < 0) + 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; } } |