Re: [libav-devel] [PATCH 04/25] avframe: switch to the new channel layout API
On Sat, Jul 22, 2017 at 10:13 AM, Anton Khirnovwrote: > Quoting Vittorio Giovara (2017-06-29 00:10:48) > > From: Anton Khirnov > > > > Signed-off-by: Vittorio Giovara > > --- > > libavcodec/decode.c | 67 > > libavcodec/encode.c | 9 ++ > > libavutil/frame.c | 88 ++ > +-- > > libavutil/frame.h | 12 +++- > > 4 files changed, 146 insertions(+), 30 deletions(-) > > > > diff --git a/libavcodec/decode.c b/libavcodec/decode.c > > index a49cd77e51..b0d6b9fb33 100644 > > --- a/libavcodec/decode.c > > +++ b/libavcodec/decode.c > > @@ -132,7 +132,7 @@ static int unrefcount_frame(AVCodecInternal *avci, > AVFrame *frame) > > memcpy(frame->data, avci->to_free->data, > sizeof(frame->data)); > > memcpy(frame->linesize, avci->to_free->linesize, > sizeof(frame->linesize)); > > if (avci->to_free->extended_data != avci->to_free->data) { > > -int planes = av_get_channel_layout_nb_channels(avci->to_free-> > channel_layout); > > +int planes = avci->to_free->ch_layout.nb_channels; > > int size = planes * sizeof(*frame->extended_data); > > > > if (!size) { > > @@ -153,9 +153,19 @@ static int unrefcount_frame(AVCodecInternal *avci, > AVFrame *frame) > > frame->format = avci->to_free->format; > > frame->width = avci->to_free->width; > > frame->height = avci->to_free->height; > > +#if FF_API_OLD_CHANNEL_LAYOUT > > +FF_DISABLE_DEPRECATION_WARNINGS > > frame->channel_layout = avci->to_free->channel_layout; > > +FF_ENABLE_DEPRECATION_WARNINGS > > +#endif > > frame->nb_samples = avci->to_free->nb_samples; > > > > +ret = av_channel_layout_copy(>ch_layout, > >to_free->ch_layout); > > +if (ret < 0) { > > +av_frame_unref(frame); > > +return ret; > > +} > > + > > return 0; > > } > > > > @@ -887,10 +897,20 @@ static int update_frame_pool(AVCodecContext > *avctx, AVFrame *frame) > > break; > > } > > case AVMEDIA_TYPE_AUDIO: { > > -int ch = av_get_channel_layout_nb_channels(frame->channel_ > layout); > > +int ch = frame->ch_layout.nb_channels; > > int planar = av_sample_fmt_is_planar(frame->format); > > int planes = planar ? ch : 1; > > > > +#if FF_API_OLD_CHANNEL_LAYOUT > > +FF_DISABLE_DEPRECATION_WARNINGS > > +if (!ch && frame->channel_layout) { > > +av_channel_layout_from_mask(>ch_layout, > frame->channel_layout); > > +ch = frame->ch_layout.nb_channels; > > +planes = planar ? ch : 1; > > +} > > +FF_ENABLE_DEPRECATION_WARNINGS > > +#endif > > What is this for? This code is the internal get_buffer2() > implementation, so the new channel layout API should always be used. > Yes this chunk is unneeded I'll drop it. > > + > > if (pool->format == frame->format && pool->planes == planes && > > pool->channels == ch && frame->nb_samples == pool->samples) > > return 0; > > @@ -,28 +1131,35 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame > *frame, int flags) > > frame->sample_rate= avctx->sample_rate; > > if (frame->format < 0) > > frame->format = avctx->sample_fmt; > > +if (!frame->ch_layout.nb_channels) { > > +if (avctx->channel_layout) > > +av_channel_layout_from_mask(>ch_layout, > avctx->channel_layout); > > +else > > +av_channel_layout_default(>ch_layout, > avctx->channels); > > +} > > Same, why the deprecated API use. > This chunk is actually needed because some decoders don't set the channel layout fully before ff_get_buffer. Besides this use is going to be dropped in a later patch, as the AVCodecContext is fully ported to the new API. -- Vittorio ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
Re: [libav-devel] [PATCH 04/25] avframe: switch to the new channel layout API
On Sat, Jul 22, 2017 at 10:02 AM, Anton Khirnovwrote: > Quoting Vittorio Giovara (2017-06-29 00:10:48) > > From: Anton Khirnov > > > > Signed-off-by: Vittorio Giovara > > --- > > libavcodec/decode.c | 67 > > libavcodec/encode.c | 9 ++ > > Why are there lavc changes in this patch. Should they not come after > lavc conversion? I'd expect this patch to break FATE. > I'll split this patch in two. No this does not break FATE in the current incarnation. -- Vittorio ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
Re: [libav-devel] [PATCH 04/25] avframe: switch to the new channel layout API
Quoting Vittorio Giovara (2017-06-29 00:10:48) > From: Anton Khirnov> > Signed-off-by: Vittorio Giovara > --- > libavcodec/decode.c | 67 > libavcodec/encode.c | 9 ++ > libavutil/frame.c | 88 > +++-- > libavutil/frame.h | 12 +++- > 4 files changed, 146 insertions(+), 30 deletions(-) > > diff --git a/libavcodec/decode.c b/libavcodec/decode.c > index a49cd77e51..b0d6b9fb33 100644 > --- a/libavcodec/decode.c > +++ b/libavcodec/decode.c > @@ -132,7 +132,7 @@ static int unrefcount_frame(AVCodecInternal *avci, > AVFrame *frame) > memcpy(frame->data, avci->to_free->data, sizeof(frame->data)); > memcpy(frame->linesize, avci->to_free->linesize, > sizeof(frame->linesize)); > if (avci->to_free->extended_data != avci->to_free->data) { > -int planes = > av_get_channel_layout_nb_channels(avci->to_free->channel_layout); > +int planes = avci->to_free->ch_layout.nb_channels; > int size = planes * sizeof(*frame->extended_data); > > if (!size) { > @@ -153,9 +153,19 @@ static int unrefcount_frame(AVCodecInternal *avci, > AVFrame *frame) > frame->format = avci->to_free->format; > frame->width = avci->to_free->width; > frame->height = avci->to_free->height; > +#if FF_API_OLD_CHANNEL_LAYOUT > +FF_DISABLE_DEPRECATION_WARNINGS > frame->channel_layout = avci->to_free->channel_layout; > +FF_ENABLE_DEPRECATION_WARNINGS > +#endif > frame->nb_samples = avci->to_free->nb_samples; > > +ret = av_channel_layout_copy(>ch_layout, > >to_free->ch_layout); > +if (ret < 0) { > +av_frame_unref(frame); > +return ret; > +} > + > return 0; > } > > @@ -887,10 +897,20 @@ static int update_frame_pool(AVCodecContext *avctx, > AVFrame *frame) > break; > } > case AVMEDIA_TYPE_AUDIO: { > -int ch = > av_get_channel_layout_nb_channels(frame->channel_layout); > +int ch = frame->ch_layout.nb_channels; > int planar = av_sample_fmt_is_planar(frame->format); > int planes = planar ? ch : 1; > > +#if FF_API_OLD_CHANNEL_LAYOUT > +FF_DISABLE_DEPRECATION_WARNINGS > +if (!ch && frame->channel_layout) { > +av_channel_layout_from_mask(>ch_layout, > frame->channel_layout); > +ch = frame->ch_layout.nb_channels; > +planes = planar ? ch : 1; > +} > +FF_ENABLE_DEPRECATION_WARNINGS > +#endif What is this for? This code is the internal get_buffer2() implementation, so the new channel layout API should always be used. > + > if (pool->format == frame->format && pool->planes == planes && > pool->channels == ch && frame->nb_samples == pool->samples) > return 0; > @@ -,28 +1131,35 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame > *frame, int flags) > frame->sample_rate= avctx->sample_rate; > if (frame->format < 0) > frame->format = avctx->sample_fmt; > +if (!frame->ch_layout.nb_channels) { > +if (avctx->channel_layout) > +av_channel_layout_from_mask(>ch_layout, > avctx->channel_layout); > +else > +av_channel_layout_default(>ch_layout, > avctx->channels); > +} Same, why the deprecated API use. -- Anton Khirnov ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
Re: [libav-devel] [PATCH 04/25] avframe: switch to the new channel layout API
Quoting Vittorio Giovara (2017-06-29 00:10:48) > From: Anton Khirnov> > Signed-off-by: Vittorio Giovara > --- > libavcodec/decode.c | 67 > libavcodec/encode.c | 9 ++ Why are there lavc changes in this patch. Should they not come after lavc conversion? I'd expect this patch to break FATE. -- Anton Khirnov ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
Re: [libav-devel] [PATCH 04/25] avframe: switch to the new channel layout API
On 6/29/17 12:10 AM, Vittorio Giovara wrote: > From: Anton Khirnov> > Signed-off-by: Vittorio Giovara > --- > libavcodec/decode.c | 67 > libavcodec/encode.c | 9 ++ > libavutil/frame.c | 88 > +++-- > libavutil/frame.h | 12 +++- > 4 files changed, 146 insertions(+), 30 deletions(-) > Seems fine. ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
[libav-devel] [PATCH 04/25] avframe: switch to the new channel layout API
From: Anton KhirnovSigned-off-by: Vittorio Giovara --- libavcodec/decode.c | 67 libavcodec/encode.c | 9 ++ libavutil/frame.c | 88 +++-- libavutil/frame.h | 12 +++- 4 files changed, 146 insertions(+), 30 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index a49cd77e51..b0d6b9fb33 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -132,7 +132,7 @@ static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame) memcpy(frame->data, avci->to_free->data, sizeof(frame->data)); memcpy(frame->linesize, avci->to_free->linesize, sizeof(frame->linesize)); if (avci->to_free->extended_data != avci->to_free->data) { -int planes = av_get_channel_layout_nb_channels(avci->to_free->channel_layout); +int planes = avci->to_free->ch_layout.nb_channels; int size = planes * sizeof(*frame->extended_data); if (!size) { @@ -153,9 +153,19 @@ static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame) frame->format = avci->to_free->format; frame->width = avci->to_free->width; frame->height = avci->to_free->height; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS frame->channel_layout = avci->to_free->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif frame->nb_samples = avci->to_free->nb_samples; +ret = av_channel_layout_copy(>ch_layout, >to_free->ch_layout); +if (ret < 0) { +av_frame_unref(frame); +return ret; +} + return 0; } @@ -887,10 +897,20 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame) break; } case AVMEDIA_TYPE_AUDIO: { -int ch = av_get_channel_layout_nb_channels(frame->channel_layout); +int ch = frame->ch_layout.nb_channels; int planar = av_sample_fmt_is_planar(frame->format); int planes = planar ? ch : 1; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS +if (!ch && frame->channel_layout) { +av_channel_layout_from_mask(>ch_layout, frame->channel_layout); +ch = frame->ch_layout.nb_channels; +planes = planar ? ch : 1; +} +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (pool->format == frame->format && pool->planes == planes && pool->channels == ch && frame->nb_samples == pool->samples) return 0; @@ -,28 +1131,35 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) frame->sample_rate= avctx->sample_rate; if (frame->format < 0) frame->format = avctx->sample_fmt; +if (!frame->ch_layout.nb_channels) { +if (avctx->channel_layout) +av_channel_layout_from_mask(>ch_layout, avctx->channel_layout); +else +av_channel_layout_default(>ch_layout, avctx->channels); +} +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS +/* set the deprecated channel_layout field for callers + * that didn't update to the new API yet */ +if (frame->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) { +av_log(avctx, AV_LOG_ERROR, "Too many channels.\n"); +return AVERROR(EINVAL); +} if (!frame->channel_layout) { -if (avctx->channel_layout) { - if (av_get_channel_layout_nb_channels(avctx->channel_layout) != - avctx->channels) { - av_log(avctx, AV_LOG_ERROR, "Inconsistent channel " -"configuration.\n"); - return AVERROR(EINVAL); - } - -frame->channel_layout = avctx->channel_layout; -} else { -if (avctx->channels > FF_SANE_NB_CHANNELS) { -av_log(avctx, AV_LOG_ERROR, "Too many channels: %d.\n", - avctx->channels); -return AVERROR(ENOSYS); -} - -frame->channel_layout = av_get_default_channel_layout(avctx->channels); +if (frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) +frame->channel_layout = frame->ch_layout.u.mask; +else { +frame->channel_layout = av_get_default_channel_layout(frame->ch_layout.nb_channels); if (!frame->channel_layout) -frame->channel_layout = (1ULL << avctx->channels) - 1; +frame->channel_layout = (1ULL << frame->ch_layout.nb_channels) - 1; } } +FF_ENABLE_DEPRECATION_WARNINGS +#endif +if (!av_channel_layout_check(>ch_layout)) { +av_log(avctx, AV_LOG_ERROR, "Invalid channel layout.\n"); +return AVERROR_INVALIDDATA; +}