Re: [libav-devel] [PATCH 12/25] lavc: switch to the new channel layout API

2017-06-30 Thread wm4
On Thu, 29 Jun 2017 14:44:52 -0400
Vittorio Giovara  wrote:

> On Thu, Jun 29, 2017 at 5:18 AM, wm4  wrote:
> > On Wed, 28 Jun 2017 18:10:56 -0400
> > Vittorio Giovara  wrote:
> >  
> >> Since the request_channel_layout is used only by a handful of codecs,
> >> move the option to codec private contexts.  
> >
> > Not sure if that is justified...  
> 
> I believe it is always good to move options out of the global state,
> and this seems to be a perfect opportunity: beside adding the new API,
> we are modifying the concept that a channel layout is not represented
> (simply) by a bitmask, but by a series of features, such as map,
> channel order, and count. The request_channel_layout is the last
> holdout of that concept, so I think it makes sense to change and allow
> for future expansion, for example an in-codec downmix from ambisonic
> to normal stereo.

+1 for less global state, -1 to more AVOption API
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH 12/25] lavc: switch to the new channel layout API

2017-06-29 Thread Vittorio Giovara
On Thu, Jun 29, 2017 at 5:18 AM, wm4  wrote:
> On Wed, 28 Jun 2017 18:10:56 -0400
> Vittorio Giovara  wrote:
>
>> Since the request_channel_layout is used only by a handful of codecs,
>> move the option to codec private contexts.
>
> Not sure if that is justified...

I believe it is always good to move options out of the global state,
and this seems to be a perfect opportunity: beside adding the new API,
we are modifying the concept that a channel layout is not represented
(simply) by a bitmask, but by a series of features, such as map,
channel order, and count. The request_channel_layout is the last
holdout of that concept, so I think it makes sense to change and allow
for future expansion, for example an in-codec downmix from ambisonic
to normal stereo.
-- 
Vittorio
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH 12/25] lavc: switch to the new channel layout API

2017-06-29 Thread wm4
On Wed, 28 Jun 2017 18:10:56 -0400
Vittorio Giovara  wrote:

> Since the request_channel_layout is used only by a handful of codecs,
> move the option to codec private contexts.

Not sure if that is justified...
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 12/25] lavc: switch to the new channel layout API

2017-06-28 Thread Vittorio Giovara
Since the request_channel_layout is used only by a handful of codecs,
move the option to codec private contexts.
---
 libavcodec/avcodec.h   |  31 +
 libavcodec/decode.c|  49 +-
 libavcodec/encode.c|   9 ++-
 libavcodec/internal.h  |   2 +
 libavcodec/options_table.h |   5 ++
 libavcodec/utils.c | 162 +
 libavformat/utils.c|  26 +++-
 7 files changed, 220 insertions(+), 64 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index bc7097c7bd..b0eac85f72 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1834,7 +1834,13 @@ typedef struct AVCodecContext {
 
 /* audio only */
 int sample_rate; ///< samples per second
+#if FF_API_OLD_CHANNEL_LAYOUT
+/**
+ * @deprecated use ch_layout.nb_channels
+ */
+attribute_deprecated
 int channels;///< number of audio channels
+#endif
 
 /**
  * audio sample format
@@ -1879,19 +1885,25 @@ typedef struct AVCodecContext {
  */
 int cutoff;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 /**
  * Audio channel layout.
  * - encoding: set by user.
  * - decoding: set by libavcodec.
+ *   @deprecated use ch_layout
  */
+attribute_deprecated
 uint64_t channel_layout;
 
 /**
  * Request decoder to use this channel layout if it can (0 for default)
  * - encoding: unused
  * - decoding: Set by user.
+ *   @deprecated use "downmix" codec private option
  */
+attribute_deprecated
 uint64_t request_channel_layout;
+#endif
 
 /**
  * Type of service that the audio stream conveys.
@@ -2730,6 +2742,14 @@ typedef struct AVCodecContext {
  * AVCodecContext.get_format callback)
  */
 int hwaccel_flags;
+
+/**
+ * Audio channel layout.
+ * - encoding: must be set by the caller, to one of AVCodec.ch_layouts.
+ * - decoding: may be set by the caller if known e.g. from the container.
+ * The decoder can then override during decoding as needed.
+ */
+AVChannelLayout ch_layout;
 } AVCodecContext;
 
 /**
@@ -2771,10 +2791,21 @@ typedef struct AVCodec {
 const enum AVPixelFormat *pix_fmts; ///< array of supported pixel 
formats, or NULL if unknown, array is terminated by -1
 const int *supported_samplerates;   ///< array of supported audio 
samplerates, or NULL if unknown, array is terminated by 0
 const enum AVSampleFormat *sample_fmts; ///< array of supported sample 
formats, or NULL if unknown, array is terminated by -1
+#if FF_API_OLD_CHANNEL_LAYOUT
+/**
+ * @deprecated use ch_layouts instead
+ */
+attribute_deprecated
 const uint64_t *channel_layouts; ///< array of support channel 
layouts, or NULL if unknown. array is terminated by 0
+#endif
 const AVClass *priv_class;  ///< AVClass for the private 
context
 const AVProfile *profiles;  ///< array of recognized profiles, 
or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
 
+/**
+ * Array of supported channel layouts, terminated with a zeroed layout.
+ */
+const AVChannelLayout *ch_layouts;
+
 /*
  * No fields below this line are part of the public API. They
  * may not be used outside of libavcodec and can be changed and
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index b0d6b9fb33..c4bcfb95df 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1131,27 +1131,42 @@ 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 FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+if (avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ||
+avctx->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
+if (!frame->ch_layout.nb_channels && (avctx->channel_layout || 
avctx->channels)) {
+if (avctx->channel_layout)
+av_channel_layout_from_mask(>ch_layout, 
avctx->channel_layout);
+else
+av_channel_layout_default(>ch_layout, 
avctx->channels);
+}
+}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 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);
+ret = av_channel_layout_copy(>ch_layout, >ch_layout);
+if (ret < 0)
+return ret;
 }
 #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