Re: [libav-devel] [PATCH 07/25] lavfi, buffersrc: switch to the new channel layout API
On Sat, Jul 22, 2017 at 12:02 PM, Anton Khirnovwrote: > Quoting Vittorio Giovara (2017-06-29 00:10:51) > > Signed-off-by: Vittorio Giovara > > --- > > libavfilter/audio.c | 17 +-- > > libavfilter/avfilter.c | 9 > > libavfilter/avfilter.h | 13 ++- > > libavfilter/avfiltergraph.c | 35 +++--- > > libavfilter/buffersink.c| 2 +- > > libavfilter/buffersrc.c | 53 -- > --- > > libavfilter/buffersrc.h | 12 +- > > libavfilter/fifo.c | 7 +++--- > > 8 files changed, 106 insertions(+), 42 deletions(-) > > > > diff --git a/libavfilter/audio.c b/libavfilter/audio.c > > index 5fe9da95c3..afd8bdc169 100644 > > --- a/libavfilter/audio.c > > +++ b/libavfilter/audio.c > > @@ -31,7 +31,7 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, > int nb_samples) > > AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int > nb_samples) > > { > > AVFrame *frame = av_frame_alloc(); > > -int channels = av_get_channel_layout_nb_ > channels(link->channel_layout); > > +int channels = link->ch_layout.nb_channels; > > int ret; > > > > if (!frame) > > @@ -39,7 +39,20 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink > *link, int nb_samples) > > > > frame->nb_samples = nb_samples; > > frame->format = link->format; > > -frame->channel_layout = link->channel_layout; > > + > > +ret = av_channel_layout_copy(>ch_layout, >ch_layout); > > +if (ret < 0) { > > +av_frame_free(); > > +return NULL; > > +} > > +#if FF_API_OLD_CHANNEL_LAYOUT > > +FF_DISABLE_DEPRECATION_WARNINGS > > +if (link->ch_layout.order == AV_CHANNEL_ORDER_NATIVE || > > +link->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) > > +frame->channel_layout = link->channel_layout; > > This is incomplete, the channel layout should always be set, at least to > (1< Right, I added this else as you suggested. else frame->channel_layout = (1 << channels) - 1; > > +FF_ENABLE_DEPRECATION_WARNINGS > > +#endif > > + > > frame->sample_rate= link->sample_rate; > > ret = av_frame_get_buffer(frame, 0); > > if (ret < 0) { > > diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c > > index 83c1a7c20d..f2adefff3d 100644 > > --- a/libavfilter/avfilter.c > > +++ b/libavfilter/avfilter.c > > @@ -247,16 +247,15 @@ void ff_dlog_link(void *ctx, AVFilterLink *link, > int end) > > link->dst ? link->dst->filter->name : "", > > end ? "\n" : ""); > > } else { > > -char buf[128]; > > -av_get_channel_layout_string(buf, sizeof(buf), -1, > link->channel_layout); > > - > > +char *chlstr = av_channel_layout_describe(>ch_layout); > > av_log(ctx, AV_LOG_TRACE, > > "link[%p r:%d cl:%s fmt:%-16s %-16s->%-16s]%s", > > -link, link->sample_rate, buf, > > +link, link->sample_rate, chlstr, > > av_get_sample_fmt_name(link->format), > > link->src ? link->src->filter->name : "", > > link->dst ? link->dst->filter->name : "", > > end ? "\n" : ""); > > +av_free(chlstr); > > } > > } > > > > @@ -683,7 +682,7 @@ int ff_filter_frame(AVFilterLink *link, AVFrame > *frame) > > case AVMEDIA_TYPE_AUDIO: > > av_samples_copy(out->extended_data, frame->extended_data, > > 0, 0, frame->nb_samples, > > -av_get_channel_layout_nb_ > channels(frame->channel_layout), > > +frame->ch_layout.nb_channels, > > frame->format); > > break; > > default: > > diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h > > index 6df69dbbbf..5d5edf0ed3 100644 > > --- a/libavfilter/avfilter.h > > +++ b/libavfilter/avfilter.h > > @@ -36,6 +36,7 @@ > > #include "libavutil/attributes.h" > > #include "libavutil/avutil.h" > > #include "libavutil/buffer.h" > > +#include "libavutil/channel_layout.h" > > #include "libavutil/frame.h" > > #include "libavutil/log.h" > > #include "libavutil/samplefmt.h" > > @@ -334,7 +335,12 @@ struct AVFilterLink { > > int h; ///< agreed upon image height > > AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio > > /* These two parameters apply only to audio */ > > -uint64_t channel_layout;///< channel layout of current buffer > (see libavutil/channel_layout.h) > > +#if FF_API_OLD_CHANNEL_LAYOUT > > +/** > > + * @deprecated use ch_layout instead > > + */ > > +attribute_deprecated uint64_t channel_layout; > > +#endif > > int sample_rate;///< samples per second > > > > int format; ///< agreed upon media format > > @@
Re: [libav-devel] [PATCH 07/25] lavfi, buffersrc: switch to the new channel layout API
Quoting Vittorio Giovara (2017-06-29 00:10:51) > Signed-off-by: Vittorio Giovara> --- > libavfilter/audio.c | 17 +-- > libavfilter/avfilter.c | 9 > libavfilter/avfilter.h | 13 ++- > libavfilter/avfiltergraph.c | 35 +++--- > libavfilter/buffersink.c| 2 +- > libavfilter/buffersrc.c | 53 > - > libavfilter/buffersrc.h | 12 +- > libavfilter/fifo.c | 7 +++--- > 8 files changed, 106 insertions(+), 42 deletions(-) > > diff --git a/libavfilter/audio.c b/libavfilter/audio.c > index 5fe9da95c3..afd8bdc169 100644 > --- a/libavfilter/audio.c > +++ b/libavfilter/audio.c > @@ -31,7 +31,7 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int > nb_samples) > AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) > { > AVFrame *frame = av_frame_alloc(); > -int channels = av_get_channel_layout_nb_channels(link->channel_layout); > +int channels = link->ch_layout.nb_channels; > int ret; > > if (!frame) > @@ -39,7 +39,20 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, > int nb_samples) > > frame->nb_samples = nb_samples; > frame->format = link->format; > -frame->channel_layout = link->channel_layout; > + > +ret = av_channel_layout_copy(>ch_layout, >ch_layout); > +if (ret < 0) { > +av_frame_free(); > +return NULL; > +} > +#if FF_API_OLD_CHANNEL_LAYOUT > +FF_DISABLE_DEPRECATION_WARNINGS > +if (link->ch_layout.order == AV_CHANNEL_ORDER_NATIVE || > +link->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) > +frame->channel_layout = link->channel_layout; This is incomplete, the channel layout should always be set, at least to (1< +FF_ENABLE_DEPRECATION_WARNINGS > +#endif > + > frame->sample_rate= link->sample_rate; > ret = av_frame_get_buffer(frame, 0); > if (ret < 0) { > diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c > index 83c1a7c20d..f2adefff3d 100644 > --- a/libavfilter/avfilter.c > +++ b/libavfilter/avfilter.c > @@ -247,16 +247,15 @@ void ff_dlog_link(void *ctx, AVFilterLink *link, int > end) > link->dst ? link->dst->filter->name : "", > end ? "\n" : ""); > } else { > -char buf[128]; > -av_get_channel_layout_string(buf, sizeof(buf), -1, > link->channel_layout); > - > +char *chlstr = av_channel_layout_describe(>ch_layout); > av_log(ctx, AV_LOG_TRACE, > "link[%p r:%d cl:%s fmt:%-16s %-16s->%-16s]%s", > -link, link->sample_rate, buf, > +link, link->sample_rate, chlstr, > av_get_sample_fmt_name(link->format), > link->src ? link->src->filter->name : "", > link->dst ? link->dst->filter->name : "", > end ? "\n" : ""); > +av_free(chlstr); > } > } > > @@ -683,7 +682,7 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame) > case AVMEDIA_TYPE_AUDIO: > av_samples_copy(out->extended_data, frame->extended_data, > 0, 0, frame->nb_samples, > - > av_get_channel_layout_nb_channels(frame->channel_layout), > +frame->ch_layout.nb_channels, > frame->format); > break; > default: > diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h > index 6df69dbbbf..5d5edf0ed3 100644 > --- a/libavfilter/avfilter.h > +++ b/libavfilter/avfilter.h > @@ -36,6 +36,7 @@ > #include "libavutil/attributes.h" > #include "libavutil/avutil.h" > #include "libavutil/buffer.h" > +#include "libavutil/channel_layout.h" > #include "libavutil/frame.h" > #include "libavutil/log.h" > #include "libavutil/samplefmt.h" > @@ -334,7 +335,12 @@ struct AVFilterLink { > int h; ///< agreed upon image height > AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio > /* These two parameters apply only to audio */ > -uint64_t channel_layout;///< channel layout of current buffer (see > libavutil/channel_layout.h) > +#if FF_API_OLD_CHANNEL_LAYOUT > +/** > + * @deprecated use ch_layout instead > + */ > +attribute_deprecated uint64_t channel_layout; > +#endif > int sample_rate;///< samples per second > > int format; ///< agreed upon media format > @@ -405,6 +411,11 @@ struct AVFilterLink { > * AVHWFramesContext describing the frames. > */ > AVBufferRef *hw_frames_ctx; > + > +/** > + * Channel layout of current buffer. What 'current buffer' is this talking about? > + */ > +AVChannelLayout ch_layout; > }; > > /** > diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c > index
Re: [libav-devel] [PATCH 07/25] lavfi, buffersrc: switch to the new channel layout API
On 6/29/17 12:10 AM, Vittorio Giovara wrote: > +ret = av_channel_layout_copy(>ch_layout, >ch_layout); Ok assuming this function wipes the destination before copying. lu ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
[libav-devel] [PATCH 07/25] lavfi, buffersrc: switch to the new channel layout API
Signed-off-by: Vittorio Giovara--- libavfilter/audio.c | 17 +-- libavfilter/avfilter.c | 9 libavfilter/avfilter.h | 13 ++- libavfilter/avfiltergraph.c | 35 +++--- libavfilter/buffersink.c| 2 +- libavfilter/buffersrc.c | 53 - libavfilter/buffersrc.h | 12 +- libavfilter/fifo.c | 7 +++--- 8 files changed, 106 insertions(+), 42 deletions(-) diff --git a/libavfilter/audio.c b/libavfilter/audio.c index 5fe9da95c3..afd8bdc169 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -31,7 +31,7 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples) AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) { AVFrame *frame = av_frame_alloc(); -int channels = av_get_channel_layout_nb_channels(link->channel_layout); +int channels = link->ch_layout.nb_channels; int ret; if (!frame) @@ -39,7 +39,20 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) frame->nb_samples = nb_samples; frame->format = link->format; -frame->channel_layout = link->channel_layout; + +ret = av_channel_layout_copy(>ch_layout, >ch_layout); +if (ret < 0) { +av_frame_free(); +return NULL; +} +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS +if (link->ch_layout.order == AV_CHANNEL_ORDER_NATIVE || +link->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) +frame->channel_layout = link->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + frame->sample_rate= link->sample_rate; ret = av_frame_get_buffer(frame, 0); if (ret < 0) { diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 83c1a7c20d..f2adefff3d 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -247,16 +247,15 @@ void ff_dlog_link(void *ctx, AVFilterLink *link, int end) link->dst ? link->dst->filter->name : "", end ? "\n" : ""); } else { -char buf[128]; -av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout); - +char *chlstr = av_channel_layout_describe(>ch_layout); av_log(ctx, AV_LOG_TRACE, "link[%p r:%d cl:%s fmt:%-16s %-16s->%-16s]%s", -link, link->sample_rate, buf, +link, link->sample_rate, chlstr, av_get_sample_fmt_name(link->format), link->src ? link->src->filter->name : "", link->dst ? link->dst->filter->name : "", end ? "\n" : ""); +av_free(chlstr); } } @@ -683,7 +682,7 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame) case AVMEDIA_TYPE_AUDIO: av_samples_copy(out->extended_data, frame->extended_data, 0, 0, frame->nb_samples, - av_get_channel_layout_nb_channels(frame->channel_layout), +frame->ch_layout.nb_channels, frame->format); break; default: diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 6df69dbbbf..5d5edf0ed3 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -36,6 +36,7 @@ #include "libavutil/attributes.h" #include "libavutil/avutil.h" #include "libavutil/buffer.h" +#include "libavutil/channel_layout.h" #include "libavutil/frame.h" #include "libavutil/log.h" #include "libavutil/samplefmt.h" @@ -334,7 +335,12 @@ struct AVFilterLink { int h; ///< agreed upon image height AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio /* These two parameters apply only to audio */ -uint64_t channel_layout;///< channel layout of current buffer (see libavutil/channel_layout.h) +#if FF_API_OLD_CHANNEL_LAYOUT +/** + * @deprecated use ch_layout instead + */ +attribute_deprecated uint64_t channel_layout; +#endif int sample_rate;///< samples per second int format; ///< agreed upon media format @@ -405,6 +411,11 @@ struct AVFilterLink { * AVHWFramesContext describing the frames. */ AVBufferRef *hw_frames_ctx; + +/** + * Channel layout of current buffer. + */ +AVChannelLayout ch_layout; }; /** diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index a0f797e283..c72016d2c8 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -397,7 +397,13 @@ static int pick_format(AVFilterLink *link) return AVERROR(EINVAL); } link->in_channel_layouts->nb_channel_layouts = 1; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS link->channel_layout = link->in_channel_layouts->channel_layouts[0]; +FF_ENABLE_DEPRECATION_WARNINGS +#endif +