Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API
@ 2022-01-13  1:49 James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 001/281] Add a new " James Almer
                   ` (282 more replies)
  0 siblings, 283 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

Several fixes since v2, including using '+' as separator for channels instead
of '|', as the latter is used to separate layouts.
Like last time custom layouts contain an opaque pointer and fixed size array
per channel to hold a user defined name that helpers will use to identify the
channel (find by name, describe as part of a layout, etc). There's also an
opaque pointer for the layout regardless of order.

This time i'm sending the whole set, but it can also be found in
https://github.com/jamrial/FFmpeg/commits/channel_layout4

Anton Khirnov (136):
  Add a new channel layout API
  lavu: support AVChannelLayout AVOptions
  lavc: deprecate channel count/layout changing side data
  avframe: switch to the new channel layout API
  lavf: add a temporary compat layer for the channel layout API change
  lavf: convert the generic layer to the new channel layout
  3dostr: convert to new channel layout API
  aa: convert to new channel layout API
  acm: convert to new channel layout API
  act: convert to new channel layout API
  adp: convert to new channel layout API
  ads: convert to new channel layout API
  afc: convert to new channel layout API
  aixdec: convert to new channel layout API
  aptxdec: convert to new channel layout API
  argo: convert to new channel layout API
  ast: convert to new channel layout API
  avr: convert to new channel layout API
  bit: convert to new channel layout API
  boa: convert to new channel layout API
  brstm: convert to new channel layout API
  codec2: convert to new channel layout API
  dcstr: convert to new channel layout API
  dhav: convert to new channel layout API
  dtshddec: convert to new channel layout API
  dsfdec: convert to new channel layout API
  epafdec: convert to new channel layout API
  framehash: convert to new channel layout API
  fsb: convert to new channel layout API
  g726: convert to new channel layout API
  gdv: convert to new channel layout API
  genh: convert to new channel layout API
  hcom: convert to new channel layout API
  ifv: convert to new channel layout API
  ircam: convert to new channel layout API
  jack: port to new channel layout API
  libcdio: port to new channel layout API
  lvf: convert to new channel layout API
  mpeg: convert to new channel layout API
  mpegtsenc: convert to new channel layout API
  msf: convert to new channel layout API
  mtaf: convert to new channel layout API
  musx: convert to new channel layout API
  nistspheredec: convert to new channel layout API
  nspdec: convert to new channel layout API
  oss: port to new channel layout API
  pvf: convert to new channel layout API
  rawenc: convert to new channel layout API
  redspark: convert to new channel layout API
  rsd: convert to new channel layout API
  sbg: convert to new channel layout API
  sdr2: convert to new channel layout API
  sds: convert to new channel layout API
  sdx: convert to new channel layout API
  svag: convert to new channel layout API
  vag: convert to new channel layout API
  vividas: convert to new channel layout API
  vivo: convert to new channel layout API
  vpk: convert to new channel layout API
  lavf: drop the channel layout compat layer for old-style (de)muxers
  8svx: convert to new channel layout API
  aac: convert to new channel layout API
  adpcm: convert to new channel layout API
  alac: convert to new channel layout API
  amr: convert to new channel layout API
  aptx: convert to new channel layout API
  atrac9: convert to new channel layout API
  apedec: convert to new channel layout API
  audiotoolbox: convert to new channel layout API
  binkaudio: convert to new channel layout API
  bmvaudio: convert to new channel layout API
  cng: convert to new channel layout API
  cook: convert to new channel layout API
  dca: convert to new channel layout API
  dolby_e: convert to new channel layout API
  dsd: convert to new channel layout API
  dsicinav: convert to new channel layout API
  dst: convert to new channel layout API
  dvaudio: convert to new channel layout API
  evrc: convert to new channel layout API
  ffwavesynth: convert to new channel layout API
  flac: convert to new channel layout API
  g722: convert to new channel layout API
  g723_1: convert to new channel layout API
  g726: convert to new channel layout API
  g729: convert to new channel layout API
  gsmdec: convert to new channel layout API
  hcom: convert to new channel layout API
  ilbc: convert to new channel layout API
  imc: convert to new channel layout API
  interplayacm: convert to new channel layout API
  libcelt: convert to new channel layout API
  libcodec2: convert to new channel layout API
  libilbc: convert to new channel layout API
  libgsm: convert to new channel layout API
  libmp3lame: convert to new channel layout API
  libopencore-amr: convert to new channel layout API
  libopus: convert to new channel layout API
  libshine: convert to new channel layout API
  libspeexdec: convert to new channel layout API
  libtwolame: convert to new channel layout API
  libvo-amrwbenc: convert to new channel layout API
  libvorbis: convert to new channel layout API
  mace: convert to new channel layout API
  metasound: convert to new channel layout API
  mlp: convert to new channel layout API
  mpc7: convert to new channel layout API
  mpc8: convert to new channel layout API
  mpegaudio: convert to new channel layout API
  nellymoser: convert to new channel layout API
  on2avc: convert to new channel layout API
  opus: convert to new channel layout API
  pcm: convert to new channel layout API
  qcelpdec: convert to new channel layout API
  qdmc: convert to new channel layout API
  qdm2: convert to new channel layout API
  ra144: convert to new channel layout API
  ra288: convert to new channel layout API
  ralf: convert to new channel layout API
  roqaudioenc: convert to new channel layout API
  s302m: convert to new channel layout API
  sbc: convert to new channel layout API
  shorten: convert to new channel layout API
  sipr: convert to new channel layout API
  smacker: convert to new channel layout API
  sonic: convert to new channel layout API
  tak: convert to new channel layout API
  truespeech: convert to new channel layout API
  tta: convert to new channel layout API
  vmdaudio: convert to new channel layout API
  vorbis: convert to new channel layout API
  wavpack: convert to new channel layout API
  wma: convert to new channel layout API
  ws-snd1: convert to new channel layout API
  lavc: drop temporary compat wrappers for channel layout API change
  opus: export mapping family 2 (Ambisonic) as Ambisonic layout

James Almer (32):
  fate: add a channel_layout API test
  aax: convert to new channel layout API
  ace: convert to new channel layout API
  alsa: convert to new channel layout API
  alp: convert to new channel layout API
  amv: convert to new channel layout API
  apm: convert to new channel layout API
  derf: convert to new channel layout API
  dshow: convert to new channel layout API
  fwse: convert to new channel layout API
  hca: convert to new channel layout API
  hls_sample_encryption: convert to new channel layout API
  imx: convert to new channel layout API
  kvag: convert to new channel layout API
  avdevice/lavfi: convert to new channel layout API
  mca: convert to new channel layout API
  moflex: convert to new channel layout API
  pp_bnk: convert to new channel layout API
  scd: convert to new channel layout API
  sga: convert to new channel layout API
  svs: convert to new channel layout API
  uncodedframecrcenc: convert to new channel layout API
  fastaudio: convert to new channel layout API
  hca: convert to new channel layout API
  mf: convert to new channel layout API
  siren: convert to new channel layout API
  speex: convert to new channel layout API
  swresample: convert to new channel layout API
  avfilter: convert to new channel layout API
  avdevice/lavfi: remove call to deprecated function
    av_buffersink_get_channel_layout()
  ffmpeg: convert to new channel layout-API
  ffprobe: convert to new channel layout-API

Vittorio Giovara (113):
  avcodecpar: switch to the new channel layout API
  4xm: convert to new channel layout API
  adxdec: convert to new channel layout API
  aea: convert to new channel layout API
  aiff: convert to new channel layout API
  amr: convert to new channel layout API
  apc: convert to new channel layout API
  ape: convert to new channel layout API
  au: convert to new channel layout API
  bethsoftvid: convert to new channel layout API
  bfi: convert to new channel layout API
  bink: convert to new channel layout API
  bmv: convert to new channel layout API
  caf: convert to new channel layout API
  cdxl: convert to new channel layout API
  dash: convert to new channel layout API
  dsicin: convert to new channel layout API
  dss: convert to new channel layout API
  dv: convert to new channel layout API
  eac: convert to new channel layout API
  electronicarts: convert to new channel layout API
  flac: convert to new channel layout API
  flic: convert to new channel layout API
  flv: convert to new channel layout API
  g722: convert to new channel layout API
  g723_1: convert to new channel layout API
  g729: convert to new channel layout API
  gsm: convert to new channel layout API
  gxf: convert to new channel layout API
  idcin: convert to new channel layout API
  idroq: convert to new channel layout API
  iff: convert to new channel layout API
  ilbc: convert to new channel layout API
  ipmovie: convert to new channel layout API
  iss: convert to new channel layout API
  jvdec: convert to new channel layout API
  lxfdec: convert to new channel layout API
  matroska: convert to new channel layout API
  mm: convert to new channel layout API
  mmf: convert to new channel layout API
  mov: convert to new channel layout API
  movenc-test: convert to new channel layout API
  mp3: convert to new channel layout API
  mpc: convert to new channel layout API
  mpc8: convert to new channel layout API
  mpegenc: convert to new channel layout API
  mvdec: convert to new channel layout API
  mvi: convert to new channel layout API
  mxf: convert to new channel layout API
  mxg: convert to new channel layout API
  nsvdec: convert to new channel layout API
  nutdec: convert to new channel layout API
  nuv: convert to new channel layout API
  ogg: convert to new channel layout API
  oma: convert to new channel layout API
  paf: convert to new channel layout API
  pcm: convert to new channel layout API
  pmp: convert to new channel layout API
  psxstr: convert to new channel layout API
  qcp: convert to new channel layout API
  r3d: convert to new channel layout API
  riff: convert to new channel layout API
  rl2: convert to new channel layout API
  rm: convert to new channel layout API
  rpl: convert to new channel layout API
  rso: convert to new channel layout API
  rtp: convert to new channel layout API
  sdp: convert to new channel layout API
  segafilm: convert to new channel layout API
  sierravmd: convert to new channel layout API
  siff: convert to new channel layout API
  smacker: convert to new channel layout API
  smjpegenc: convert to new channel layout API
  smoothstreaming: convert to new channel layout API
  smush: convert to new channel layout API
  sol: convert to new channel layout API
  sox: convert to new channel layout API
  swf: convert to new channel layout API
  tak: convert to new channel layout API
  thp: convert to new channel layout API
  tiertexseq: convert to new channel layout API
  tmv: convert to new channel layout API
  tta: convert to new channel layout API
  voc: convert to new channel layout API
  vqf: convert to new channel layout API
  wav: convert to new channel layout API
  wc3movie: convert to new channel layout API
  westwood: convert to new channel layout API
  wtv: convert to new channel layout API
  wv: convert to new channel layout API
  xa: convert to new channel layout API
  xmv: convert to new channel layout API
  xwma: convert to new channel layout API
  yop: convert to new channel layout API
  wsd: convert to new channel layout API
  wve: convert to new channel layout API
  xvag: convert to new channel layout API
  lavc: switch to the new channel layout API
  ac3: convert to new channel layout API
  adx: convert to new channel layout API
  als: convert to new channel layout API
  atrac1: convert to new channel layout API
  atrac3: convert to new channel layout API
  atrac3plus: convert to new channel layout API
  dpcm: convert to new channel layout API
  dss_sp: convert to new channel layout API
  libfdk-aac: convert to new channel layout API
  pafaudio: convert to new channel layout API
  twinvq: convert to new channel layout API
  vima: convert to new channel layout API
  lavf: Add non diegetic stream disposition flag
  channel_layout: add support for Ambisonic
  mov: Implement spatial audio support

 fftools/cmdutils.c                            |  42 +-
 fftools/cmdutils.h                            |   8 -
 fftools/ffmpeg.c                              |  47 +-
 fftools/ffmpeg.h                              |   7 +-
 fftools/ffmpeg_filter.c                       |  52 +-
 fftools/ffmpeg_opt.c                          |  62 +-
 fftools/ffprobe.c                             |  19 +-
 libavcodec/8svx.c                             |  19 +-
 libavcodec/aac.h                              |  11 +-
 libavcodec/aac_ac3_parser.c                   |  13 +-
 libavcodec/aaccoder.c                         |  10 +-
 libavcodec/aaccoder_twoloop.h                 |   4 +-
 libavcodec/aacdec.c                           |   6 +
 libavcodec/aacdec_fixed.c                     |   3 +
 libavcodec/aacdec_template.c                  |  52 +-
 libavcodec/aacdectab.h                        |  20 +
 libavcodec/aacenc.c                           |  13 +-
 libavcodec/aacenc.h                           |  64 +-
 libavcodec/aacenctab.h                        |  16 +-
 libavcodec/aacpsy.c                           |   8 +-
 libavcodec/ac3dec.c                           |  57 +-
 libavcodec/ac3dec.h                           |   2 +
 libavcodec/ac3dec_fixed.c                     |   1 +
 libavcodec/ac3dec_float.c                     |   2 +
 libavcodec/ac3enc.c                           |  78 +-
 libavcodec/ac3enc.h                           |   4 +-
 libavcodec/ac3enc_fixed.c                     |   5 +
 libavcodec/ac3enc_float.c                     |   5 +
 libavcodec/adpcm.c                            | 151 ++--
 libavcodec/adpcmenc.c                         | 122 +--
 libavcodec/adx.c                              |  16 +-
 libavcodec/adxdec.c                           |   6 +-
 libavcodec/adxenc.c                           |  11 +-
 libavcodec/alac.c                             |  16 +-
 libavcodec/alac_data.c                        |  20 +-
 libavcodec/alac_data.h                        |   6 +
 libavcodec/alacenc.c                          |  37 +-
 libavcodec/alsdec.c                           |  90 +-
 libavcodec/amr_parser.c                       |  10 +-
 libavcodec/amrnbdec.c                         |  12 +-
 libavcodec/amrwbdec.c                         |  12 +-
 libavcodec/apedec.c                           |   9 +-
 libavcodec/aptx.c                             |   2 +-
 libavcodec/aptxdec.c                          |   8 +-
 libavcodec/aptxenc.c                          |   6 +
 libavcodec/atrac1.c                           |  10 +-
 libavcodec/atrac3.c                           |  41 +-
 libavcodec/atrac3plusdec.c                    |  25 +-
 libavcodec/atrac9dec.c                        |   4 +-
 libavcodec/atrac9tab.h                        |  14 +-
 libavcodec/audiotoolboxdec.c                  |  27 +-
 libavcodec/audiotoolboxenc.c                  |  95 +--
 libavcodec/avcodec.c                          |  53 +-
 libavcodec/avcodec.h                          |  24 +-
 libavcodec/binkaudio.c                        |  19 +-
 libavcodec/bmvaudio.c                         |   4 +-
 libavcodec/cngdec.c                           |   3 +-
 libavcodec/cngenc.c                           |   6 +-
 libavcodec/codec.h                            |  11 +
 libavcodec/codec_par.c                        |  65 +-
 libavcodec/codec_par.h                        |  12 +
 libavcodec/cook.c                             |  25 +-
 libavcodec/cook_parser.c                      |   4 +-
 libavcodec/dca_core.c                         |   6 +-
 libavcodec/dca_lbr.c                          |  13 +-
 libavcodec/dca_xll.c                          |   2 +-
 libavcodec/dcadec.c                           |  63 +-
 libavcodec/dcadec.h                           |   7 +
 libavcodec/dcaenc.c                           |  39 +-
 libavcodec/decode.c                           |  78 +-
 libavcodec/dolby_e.c                          |  52 +-
 libavcodec/dolby_e.h                          |   2 +
 libavcodec/dolby_e_parser.c                   |  11 +-
 libavcodec/dpcm.c                             |  16 +-
 libavcodec/dsddec.c                           |  14 +-
 libavcodec/dsicinaudio.c                      |   4 +-
 libavcodec/dss_sp.c                           |   4 +-
 libavcodec/dstdec.c                           |   8 +-
 libavcodec/dvaudiodec.c                       |   8 +-
 libavcodec/eac3enc.c                          |   5 +
 libavcodec/encode.c                           |  43 +-
 libavcodec/evrcdec.c                          |   4 +-
 libavcodec/fastaudio.c                        |   6 +-
 libavcodec/ffwavesynth.c                      |   6 +-
 libavcodec/flac.c                             |  39 +-
 libavcodec/flac.h                             |   2 +-
 libavcodec/flac_parser.c                      |   7 +-
 libavcodec/flacdec.c                          |   9 +-
 libavcodec/flacenc.c                          |  26 +-
 libavcodec/g722dec.c                          |   4 +-
 libavcodec/g722enc.c                          |   5 +
 libavcodec/g723_1_parser.c                    |   2 +-
 libavcodec/g723_1dec.c                        |  19 +-
 libavcodec/g723_1enc.c                        |   8 +-
 libavcodec/g726.c                             |   8 +-
 libavcodec/g729_parser.c                      |   2 +-
 libavcodec/g729dec.c                          |  20 +-
 libavcodec/gsmdec.c                           |   4 +-
 libavcodec/hcadec.c                           |  16 +-
 libavcodec/hcom.c                             |   2 +-
 libavcodec/ilbcdec.c                          |   4 +-
 libavcodec/imc.c                              |  22 +-
 libavcodec/internal.h                         |   3 +
 libavcodec/interplayacm.c                     |  10 +-
 libavcodec/libcelt_dec.c                      |  10 +-
 libavcodec/libcodec2.c                        |   4 +-
 libavcodec/libfdk-aacdec.c                    |  32 +-
 libavcodec/libfdk-aacenc.c                    |  35 +-
 libavcodec/libgsmdec.c                        |   4 +-
 libavcodec/libgsmenc.c                        |   4 +-
 libavcodec/libilbc.c                          |   6 +-
 libavcodec/libmp3lame.c                       |   9 +-
 libavcodec/libopencore-amr.c                  |   8 +-
 libavcodec/libopusdec.c                       |  39 +-
 libavcodec/libopusenc.c                       |  65 +-
 libavcodec/libshine.c                         |   6 +-
 libavcodec/libspeexdec.c                      |  19 +-
 libavcodec/libspeexenc.c                      |  17 +-
 libavcodec/libtwolame.c                       |   2 +-
 libavcodec/libvo-amrwbenc.c                   |   2 +-
 libavcodec/libvorbisdec.c                     |   4 +-
 libavcodec/libvorbisenc.c                     |  42 +-
 libavcodec/mace.c                             |  15 +-
 libavcodec/metasound.c                        |  31 +-
 libavcodec/mfenc.c                            |   8 +-
 libavcodec/mlp.c                              |   9 +
 libavcodec/mlp.h                              |   5 +
 libavcodec/mlp_parser.c                       |  12 +-
 libavcodec/mlpdec.c                           | 120 ++-
 libavcodec/mlpenc.c                           | 106 +--
 libavcodec/mp3_header_decompress_bsf.c        |   2 +-
 libavcodec/mpc7.c                             |   7 +-
 libavcodec/mpc8.c                             |   6 +-
 libavcodec/mpegaudio_parser.c                 |   4 +-
 libavcodec/mpegaudiodec_template.c            |  22 +-
 libavcodec/mpegaudioenc_fixed.c               |   5 +
 libavcodec/mpegaudioenc_float.c               |   5 +
 libavcodec/mpegaudioenc_template.c            |   2 +-
 libavcodec/nellymoserdec.c                    |   4 +-
 libavcodec/nellymoserenc.c                    |   6 +-
 libavcodec/on2avc.c                           |  20 +-
 libavcodec/options.c                          |   2 +
 libavcodec/options_table.h                    |   5 +
 libavcodec/opus.c                             |  73 +-
 libavcodec/opusdec.c                          |   4 +-
 libavcodec/opusenc.c                          |  15 +-
 libavcodec/opusenc_psy.c                      |  20 +-
 libavcodec/packet.h                           |   5 +
 libavcodec/pafaudio.c                         |   5 +-
 libavcodec/pcm-bluray.c                       |  36 +-
 libavcodec/pcm-dvd.c                          |  28 +-
 libavcodec/pcm-dvdenc.c                       |  27 +-
 libavcodec/pcm.c                              |  39 +-
 libavcodec/pcm_rechunk_bsf.c                  |   5 +-
 libavcodec/psymodel.c                         |   8 +-
 libavcodec/psymodel.h                         |   2 +-
 libavcodec/pthread_frame.c                    |  10 +-
 libavcodec/qcelpdec.c                         |   4 +-
 libavcodec/qdm2.c                             |   6 +-
 libavcodec/qdmc.c                             |   9 +-
 libavcodec/ra144dec.c                         |   4 +-
 libavcodec/ra144enc.c                         |   8 +-
 libavcodec/ra288.c                            |   4 +-
 libavcodec/ralf.c                             |  18 +-
 libavcodec/roqaudioenc.c                      |  20 +-
 libavcodec/s302m.c                            |  31 +-
 libavcodec/s302menc.c                         |  18 +-
 libavcodec/sbc_parser.c                       |   8 +-
 libavcodec/sbcdec.c                           |   9 +-
 libavcodec/sbcenc.c                           |  15 +-
 libavcodec/shorten.c                          |   6 +-
 libavcodec/sipr.c                             |   4 +-
 libavcodec/siren.c                            |   4 +-
 libavcodec/smacker.c                          |  12 +-
 libavcodec/sonic.c                            |  14 +-
 libavcodec/speexdec.c                         |  10 +-
 libavcodec/takdec.c                           |  41 +-
 libavcodec/truespeech.c                       |   7 +-
 libavcodec/tta.c                              |  18 +-
 libavcodec/ttaenc.c                           |  14 +-
 libavcodec/twinvq.c                           |  20 +-
 libavcodec/twinvqdec.c                        |  18 +-
 libavcodec/utils.c                            |  24 +-
 libavcodec/vima.c                             |   5 +-
 libavcodec/vmdaudio.c                         |  26 +-
 libavcodec/vorbis.h                           |   3 +
 libavcodec/vorbis_data.c                      |  18 +
 libavcodec/vorbisdec.c                        |  27 +-
 libavcodec/vorbisenc.c                        |   7 +-
 libavcodec/wavpack.c                          |  51 +-
 libavcodec/wavpackenc.c                       |  29 +-
 libavcodec/wma.c                              |  11 +-
 libavcodec/wmadec.c                           |  29 +-
 libavcodec/wmaenc.c                           |  27 +-
 libavcodec/wmalosslessdec.c                   |  13 +-
 libavcodec/wmaprodec.c                        |  30 +-
 libavcodec/wmavoice.c                         |   4 +-
 libavcodec/ws-snd1.c                          |   4 +-
 libavdevice/alsa.c                            |  19 +-
 libavdevice/alsa_dec.c                        |   3 +-
 libavdevice/alsa_enc.c                        |   2 +-
 libavdevice/dshow.c                           |   3 +-
 libavdevice/jack.c                            |   3 +-
 libavdevice/lavfi.c                           |   7 +-
 libavdevice/libcdio.c                         |   5 +-
 libavdevice/oss_dec.c                         |   3 +-
 libavdevice/oss_enc.c                         |   2 +-
 libavfilter/aeval.c                           |  35 +-
 libavfilter/af_acontrast.c                    |   2 +-
 libavfilter/af_acrossover.c                   |   6 +-
 libavfilter/af_acrusher.c                     |   4 +-
 libavfilter/af_adeclick.c                     |  14 +-
 libavfilter/af_adecorrelate.c                 |  12 +-
 libavfilter/af_adelay.c                       |   8 +-
 libavfilter/af_adenorm.c                      |   6 +-
 libavfilter/af_aderivative.c                  |   2 +-
 libavfilter/af_adynamicequalizer.c            |   6 +-
 libavfilter/af_adynamicsmooth.c               |   2 +-
 libavfilter/af_aecho.c                        |   8 +-
 libavfilter/af_aemphasis.c                    |   6 +-
 libavfilter/af_aexciter.c                     |  10 +-
 libavfilter/af_afade.c                        |  10 +-
 libavfilter/af_afftdn.c                       |  26 +-
 libavfilter/af_afftfilt.c                     |  30 +-
 libavfilter/af_afir.c                         |  49 +-
 libavfilter/af_aformat.c                      |  33 +-
 libavfilter/af_afreqshift.c                   |   6 +-
 libavfilter/af_afwtdn.c                       |   8 +-
 libavfilter/af_agate.c                        |  14 +-
 libavfilter/af_aiir.c                         |  34 +-
 libavfilter/af_alimiter.c                     |  10 +-
 libavfilter/af_amerge.c                       |  40 +-
 libavfilter/af_amix.c                         |   4 +-
 libavfilter/af_amultiply.c                    |   4 +-
 libavfilter/af_anequalizer.c                  |  14 +-
 libavfilter/af_anlmdn.c                       |   4 +-
 libavfilter/af_anlms.c                        |   6 +-
 libavfilter/af_apad.c                         |   2 +-
 libavfilter/af_aphaser.c                      |   4 +-
 libavfilter/af_apsyclip.c                     |   8 +-
 libavfilter/af_apulsator.c                    |   2 +-
 libavfilter/af_aresample.c                    |  52 +-
 libavfilter/af_arnndn.c                       |   8 +-
 libavfilter/af_asdr.c                         |   8 +-
 libavfilter/af_asetnsamples.c                 |   4 +-
 libavfilter/af_ashowinfo.c                    |  17 +-
 libavfilter/af_asoftclip.c                    |   2 +-
 libavfilter/af_aspectralstats.c               |   4 +-
 libavfilter/af_asr.c                          |   2 +-
 libavfilter/af_astats.c                       |  10 +-
 libavfilter/af_asubboost.c                    |   8 +-
 libavfilter/af_asupercut.c                    |   6 +-
 libavfilter/af_atempo.c                       |   2 +-
 libavfilter/af_atilt.c                        |   6 +-
 libavfilter/af_axcorrelate.c                  |   8 +-
 libavfilter/af_biquads.c                      |  54 +-
 libavfilter/af_bs2b.c                         |   2 +-
 libavfilter/af_channelmap.c                   |  90 +-
 libavfilter/af_channelsplit.c                 |  42 +-
 libavfilter/af_chorus.c                       |  14 +-
 libavfilter/af_compand.c                      |  14 +-
 libavfilter/af_compensationdelay.c            |   9 +-
 libavfilter/af_crossfeed.c                    |   2 +-
 libavfilter/af_crystalizer.c                  |   4 +-
 libavfilter/af_dcshift.c                      |   4 +-
 libavfilter/af_deesser.c                      |   6 +-
 libavfilter/af_drmeter.c                      |   4 +-
 libavfilter/af_dynaudnorm.c                   |  24 +-
 libavfilter/af_earwax.c                       |   2 +-
 libavfilter/af_extrastereo.c                  |   2 +-
 libavfilter/af_firequalizer.c                 |  31 +-
 libavfilter/af_flanger.c                      |   6 +-
 libavfilter/af_haas.c                         |   2 +-
 libavfilter/af_hdcd.c                         |  28 +-
 libavfilter/af_headphone.c                    |  40 +-
 libavfilter/af_join.c                         | 270 +++---
 libavfilter/af_ladspa.c                       |  18 +-
 libavfilter/af_loudnorm.c                     |  86 +-
 libavfilter/af_lv2.c                          |  19 +-
 libavfilter/af_mcompand.c                     |  16 +-
 libavfilter/af_pan.c                          |  74 +-
 libavfilter/af_replaygain.c                   |   2 +-
 libavfilter/af_rubberband.c                   |   2 +-
 libavfilter/af_sidechaincompress.c            |  18 +-
 libavfilter/af_silencedetect.c                |   8 +-
 libavfilter/af_silenceremove.c                |  76 +-
 libavfilter/af_sofalizer.c                    |  96 +--
 libavfilter/af_speechnorm.c                   |  28 +-
 libavfilter/af_stereotools.c                  |   2 +-
 libavfilter/af_stereowiden.c                  |   2 +-
 libavfilter/af_superequalizer.c               |   2 +-
 libavfilter/af_surround.c                     |  90 +-
 libavfilter/af_tremolo.c                      |   2 +-
 libavfilter/af_vibrato.c                      |   6 +-
 libavfilter/af_volume.c                       |   4 +-
 libavfilter/af_volumedetect.c                 |   2 +-
 libavfilter/asrc_afirsrc.c                    |   2 +-
 libavfilter/asrc_anoisesrc.c                  |   2 +-
 libavfilter/asrc_anullsrc.c                   |  13 +-
 libavfilter/asrc_flite.c                      |   6 +-
 libavfilter/asrc_hilbert.c                    |   2 +-
 libavfilter/asrc_sinc.c                       |   2 +-
 libavfilter/asrc_sine.c                       |   2 +-
 libavfilter/audio.c                           |  18 +-
 libavfilter/avf_abitscope.c                   |  10 +-
 libavfilter/avf_ahistogram.c                  |   6 +-
 libavfilter/avf_aphasemeter.c                 |   2 +-
 libavfilter/avf_avectorscope.c                |   2 +-
 libavfilter/avf_concat.c                      |   2 +-
 libavfilter/avf_showcqt.c                     |   3 +-
 libavfilter/avf_showfreqs.c                   |   4 +-
 libavfilter/avf_showspatial.c                 |   4 +-
 libavfilter/avf_showspectrum.c                |  15 +-
 libavfilter/avf_showvolume.c                  |  31 +-
 libavfilter/avf_showwaves.c                   |  12 +-
 libavfilter/avfilter.c                        |  21 +-
 libavfilter/avfilter.h                        |  16 +-
 libavfilter/avfiltergraph.c                   |  84 +-
 libavfilter/buffersink.c                      |  36 +-
 libavfilter/buffersink.h                      |   7 +-
 libavfilter/buffersrc.c                       |  94 ++-
 libavfilter/buffersrc.h                       |   9 +
 libavfilter/f_ebur128.c                       |  10 +-
 libavfilter/f_graphmonitor.c                  |   2 +-
 libavfilter/f_loop.c                          |   4 +-
 libavfilter/f_reverse.c                       |   4 +-
 libavfilter/f_streamselect.c                  |   6 +-
 libavfilter/formats.c                         | 151 +++-
 libavfilter/formats.h                         |  16 +-
 libavfilter/framepool.c                       |   5 +
 libavfilter/framequeue.c                      |   4 +-
 libavfilter/graphdump.c                       |   4 +-
 libavfilter/internal.h                        |   2 +-
 libavfilter/src_movie.c                       |  19 +-
 libavfilter/tests/filtfmts.c                  |   3 +-
 libavfilter/tests/formats.c                   |   4 +-
 libavfilter/trim.c                            |   2 +-
 libavfilter/vaf_spectrumsynth.c               |   2 +-
 libavformat/3dostr.c                          |  13 +-
 libavformat/4xm.c                             |   7 +-
 libavformat/aadec.c                           |   6 +-
 libavformat/aaxdec.c                          |   7 +-
 libavformat/acedec.c                          |   5 +-
 libavformat/acm.c                             |   7 +-
 libavformat/act.c                             |   3 +-
 libavformat/adp.c                             |   3 +-
 libavformat/ads.c                             |  11 +-
 libavformat/adxdec.c                          |  22 +-
 libavformat/aea.c                             |  11 +-
 libavformat/afc.c                             |   5 +-
 libavformat/aiffdec.c                         |  13 +-
 libavformat/aiffenc.c                         |   8 +-
 libavformat/aixdec.c                          |   3 +-
 libavformat/alp.c                             |  16 +-
 libavformat/amr.c                             |  20 +-
 libavformat/amvenc.c                          |   4 +-
 libavformat/apc.c                             |  12 +-
 libavformat/ape.c                             |   3 +-
 libavformat/apm.c                             |  22 +-
 libavformat/aptxdec.c                         |   3 +-
 libavformat/argo_asf.c                        |  18 +-
 libavformat/argo_cvg.c                        |   5 +-
 libavformat/astdec.c                          |  18 +-
 libavformat/astenc.c                          |   4 +-
 libavformat/au.c                              |   9 +-
 libavformat/avformat.h                        |   7 +
 libavformat/avr.c                             |   7 +-
 libavformat/bethsoftvid.c                     |   3 +-
 libavformat/bfi.c                             |   3 +-
 libavformat/bink.c                            |   8 +-
 libavformat/binka.c                           |   3 +-
 libavformat/bit.c                             |   7 +-
 libavformat/bmv.c                             |   3 +-
 libavformat/boadec.c                          |   8 +-
 libavformat/brstm.c                           |  44 +-
 libavformat/cafdec.c                          |   7 +-
 libavformat/cafenc.c                          |  12 +-
 libavformat/cdxl.c                            |   4 +-
 libavformat/codec2.c                          |   3 +-
 libavformat/dashenc.c                         |   2 +-
 libavformat/dauddec.c                         |   3 +-
 libavformat/daudenc.c                         |   2 +-
 libavformat/dcstr.c                           |  15 +-
 libavformat/demux.c                           |  18 +-
 libavformat/derf.c                            |  12 +-
 libavformat/dhav.c                            |   3 +-
 libavformat/dsfdec.c                          |  60 +-
 libavformat/dsicin.c                          |   7 +-
 libavformat/dss.c                             |   3 +-
 libavformat/dtshddec.c                        |   3 +-
 libavformat/dump.c                            |  11 +-
 libavformat/dv.c                              |   3 +-
 libavformat/dvenc.c                           |   2 +-
 libavformat/eacdata.c                         |  22 +-
 libavformat/electronicarts.c                  |   7 +-
 libavformat/epafdec.c                         |   6 +-
 libavformat/flacdec.c                         |   3 +-
 libavformat/flacenc.c                         |   7 +-
 libavformat/flic.c                            |   4 +-
 libavformat/flvdec.c                          |  15 +-
 libavformat/flvenc.c                          |  10 +-
 libavformat/framehash.c                       |   8 +-
 libavformat/fsb.c                             |  36 +-
 libavformat/fwse.c                            |  10 +-
 libavformat/g722.c                            |   2 +-
 libavformat/g723_1.c                          |   3 +-
 libavformat/g726.c                            |   3 +-
 libavformat/g729dec.c                         |   2 +-
 libavformat/gdv.c                             |   6 +-
 libavformat/genh.c                            |  38 +-
 libavformat/gsmdec.c                          |   3 +-
 libavformat/gxf.c                             |   9 +-
 libavformat/gxfenc.c                          |   2 +-
 libavformat/hca.c                             |   3 +-
 libavformat/hcom.c                            |   3 +-
 libavformat/hls_sample_encryption.c           |  12 +-
 libavformat/idcin.c                           |   4 +-
 libavformat/idroqdec.c                        |  12 +-
 libavformat/iff.c                             |  63 +-
 libavformat/ifv.c                             |   3 +-
 libavformat/ilbc.c                            |   2 +-
 libavformat/imx.c                             |   3 +-
 libavformat/ipmovie.c                         |   8 +-
 libavformat/ircamdec.c                        |   8 +-
 libavformat/ircamenc.c                        |   2 +-
 libavformat/isom.c                            |   5 +-
 libavformat/iss.c                             |  17 +-
 libavformat/jvdec.c                           |   3 +-
 libavformat/kvag.c                            |  19 +-
 libavformat/lvfdec.c                          |   3 +-
 libavformat/lxfdec.c                          |   3 +-
 libavformat/matroskadec.c                     |   8 +-
 libavformat/matroskaenc.c                     |  10 +-
 libavformat/mca.c                             |  25 +-
 libavformat/mm.c                              |   3 +-
 libavformat/mmf.c                             |   5 +-
 libavformat/moflex.c                          |   3 +-
 libavformat/mov.c                             | 176 +++-
 libavformat/mov_chan.c                        |  21 +-
 libavformat/mov_chan.h                        |   3 +-
 libavformat/movenc.c                          |  25 +-
 libavformat/mp3enc.c                          |   2 +-
 libavformat/mpc.c                             |   3 +-
 libavformat/mpc8.c                            |   5 +-
 libavformat/mpeg.c                            |   3 +-
 libavformat/mpegenc.c                         |  10 +-
 libavformat/mpegtsenc.c                       |  30 +-
 libavformat/msf.c                             |  16 +-
 libavformat/mtaf.c                            |   5 +-
 libavformat/musx.c                            |  49 +-
 libavformat/mux.c                             |  19 +-
 libavformat/mvdec.c                           |  10 +-
 libavformat/mvi.c                             |   3 +-
 libavformat/mxfdec.c                          |  34 +-
 libavformat/mxfenc.c                          |  20 +-
 libavformat/mxg.c                             |   3 +-
 libavformat/nistspheredec.c                   |   8 +-
 libavformat/nspdec.c                          |   3 +-
 libavformat/nsvdec.c                          |   2 +-
 libavformat/nutdec.c                          |   5 +-
 libavformat/nutenc.c                          |   4 +-
 libavformat/nuv.c                             |  11 +-
 libavformat/oggparsecelt.c                    |   3 +-
 libavformat/oggparseogm.c                     |   6 +-
 libavformat/oggparseopus.c                    |   3 +-
 libavformat/oggparsespeex.c                   |   8 +-
 libavformat/oggparsevorbis.c                  |   6 +-
 libavformat/oma.h                             |   2 +
 libavformat/omadec.c                          |  35 +-
 libavformat/omaenc.c                          |   4 +-
 libavformat/paf.c                             |   3 +-
 libavformat/pcm.c                             |   2 +-
 libavformat/pcmdec.c                          |   7 +-
 libavformat/pmpdec.c                          |   3 +-
 libavformat/pp_bnk.c                          |  12 +-
 libavformat/psxstr.c                          |  10 +-
 libavformat/pvfdec.c                          |   5 +-
 libavformat/qcp.c                             |   3 +-
 libavformat/r3d.c                             |   3 +-
 libavformat/rawenc.c                          |   2 +-
 libavformat/redspark.c                        |  15 +-
 libavformat/riffdec.c                         |  20 +-
 libavformat/riffenc.c                         |  18 +-
 libavformat/rl2.c                             |   7 +-
 libavformat/rmdec.c                           |   6 +-
 libavformat/rmenc.c                           |   2 +-
 libavformat/rpl.c                             |   7 +-
 libavformat/rsd.c                             |  27 +-
 libavformat/rsodec.c                          |   3 +-
 libavformat/rsoenc.c                          |   2 +-
 libavformat/rtp.c                             |  10 +-
 libavformat/rtpdec.c                          |   4 +-
 libavformat/rtpdec_amr.c                      |   3 +-
 libavformat/rtpenc.c                          |  14 +-
 libavformat/rtsp.c                            |   6 +-
 libavformat/rtsp.h                            |   1 -
 libavformat/sbgdec.c                          |   3 +-
 libavformat/scd.c                             |   9 +-
 libavformat/sdp.c                             |  32 +-
 libavformat/sdr2.c                            |   3 +-
 libavformat/sdsdec.c                          |   3 +-
 libavformat/sdxdec.c                          |   3 +-
 libavformat/segafilm.c                        |   9 +-
 libavformat/segafilmenc.c                     |   2 +-
 libavformat/sga.c                             |   3 +-
 libavformat/sierravmd.c                       |  15 +-
 libavformat/siff.c                            |   3 +-
 libavformat/smacker.c                         |  11 +-
 libavformat/smjpegdec.c                       |   3 +-
 libavformat/smjpegenc.c                       |   2 +-
 libavformat/smoothstreamingenc.c              |   4 +-
 libavformat/smush.c                           |   4 +-
 libavformat/sol.c                             |   4 +-
 libavformat/soxdec.c                          |  14 +-
 libavformat/soxenc.c                          |   4 +-
 libavformat/svag.c                            |  12 +-
 libavformat/svs.c                             |   3 +-
 libavformat/swfdec.c                          |   8 +-
 libavformat/swfenc.c                          |   2 +-
 libavformat/takdec.c                          |   7 +-
 libavformat/tests/movenc.c                    |   2 +-
 libavformat/thp.c                             |   3 +-
 libavformat/tiertexseq.c                      |   7 +-
 libavformat/tmv.c                             |  10 +-
 libavformat/tta.c                             |   3 +-
 libavformat/ttaenc.c                          |   2 +-
 libavformat/uncodedframecrcenc.c              |   2 +-
 libavformat/utils.c                           |  13 +-
 libavformat/vag.c                             |  11 +-
 libavformat/vividas.c                         |   8 +-
 libavformat/vivo.c                            |   3 +-
 libavformat/voc_packet.c                      |   9 +-
 libavformat/vocenc.c                          |   9 +-
 libavformat/vpk.c                             |  15 +-
 libavformat/vqf.c                             |  13 +-
 libavformat/wavdec.c                          |  32 +-
 libavformat/wavenc.c                          |  14 +-
 libavformat/wc3movie.c                        |   8 +-
 libavformat/westwood_aud.c                    |  10 +-
 libavformat/westwood_audenc.c                 |   2 +-
 libavformat/westwood_vqa.c                    |   2 +-
 libavformat/wsddec.c                          |  12 +-
 libavformat/wtvdec.c                          |   6 +-
 libavformat/wvdec.c                           |   3 +-
 libavformat/wvedec.c                          |   6 +-
 libavformat/xa.c                              |   9 +-
 libavformat/xmv.c                             |   3 +-
 libavformat/xvag.c                            |  10 +-
 libavformat/xwma.c                            |  10 +-
 libavformat/yop.c                             |   3 +-
 libavutil/Makefile                            |   1 +
 libavutil/channel_layout.c                    | 789 ++++++++++++++++--
 libavutil/channel_layout.h                    | 592 ++++++++++++-
 libavutil/frame.c                             | 116 ++-
 libavutil/frame.h                             |  16 +-
 libavutil/opt.c                               | 126 ++-
 libavutil/opt.h                               |  12 +
 libavutil/tests/channel_layout.c              | 253 ++++++
 libavutil/tests/opt.c                         |   8 +-
 libavutil/version.h                           |   1 +
 libswresample/options.c                       |  33 +-
 libswresample/rematrix.c                      | 237 ++++--
 libswresample/rematrix_template.c             |   7 +-
 libswresample/swresample.c                    | 152 +++-
 libswresample/swresample.h                    |  63 ++
 libswresample/swresample_frame.c              |  65 +-
 libswresample/swresample_internal.h           |  10 +-
 tests/fate/aac.mak                            |   2 +-
 tests/fate/ac3.mak                            |  16 +-
 tests/fate/lavf-container.mak                 |   2 +-
 tests/fate/libavutil.mak                      |   4 +
 tests/ref/fate/8bps                           |   1 -
 tests/ref/fate/aa-demux                       |   1 -
 tests/ref/fate/aac-autobsf-adtstoasc          |   1 -
 tests/ref/fate/adpcm-4xm                      |   1 -
 tests/ref/fate/adpcm-afc                      |   1 -
 tests/ref/fate/adpcm-dtk                      |   1 -
 tests/ref/fate/adpcm-ea-1                     |   1 -
 tests/ref/fate/adpcm-ea-2                     |   1 -
 tests/ref/fate/adpcm-ea-maxis-xa              |   1 -
 tests/ref/fate/adpcm-ea-r1                    |   1 -
 tests/ref/fate/adpcm-ima-amv                  |   1 -
 tests/ref/fate/adpcm-ima-ea-eacs              |   1 -
 tests/ref/fate/adpcm-ima-ea-sead              |   1 -
 tests/ref/fate/adpcm-ima-smjpeg               |   1 -
 tests/ref/fate/adpcm-ima-ws                   |   1 -
 tests/ref/fate/adpcm-ima-ws-vqa3              |   1 -
 tests/ref/fate/adpcm-ms-mono                  |   1 -
 tests/ref/fate/adpcm-thp                      |   1 -
 tests/ref/fate/adpcm-vima                     |   1 -
 tests/ref/fate/adpcm-xa                       |   1 -
 tests/ref/fate/adts-id3v1-demux               |   1 -
 tests/ref/fate/adts-id3v2-demux               |   1 -
 tests/ref/fate/adts-id3v2-two-tags-demux      |   1 -
 tests/ref/fate/adtstoasc_ticket3715           |   1 -
 tests/ref/fate/amrnb-remux                    |   1 -
 tests/ref/fate/amrwb-remux                    |   1 -
 tests/ref/fate/armovie-escape124              |   1 -
 tests/ref/fate/bethsoft-vid                   |   1 -
 tests/ref/fate/bfi                            |   1 -
 tests/ref/fate/bmv-audio                      |   1 -
 tests/ref/fate/caf-alac-remux                 |   1 -
 tests/ref/fate/caf-amr_nb-remux               |   1 -
 tests/ref/fate/caf-mace6-remux                |   1 -
 tests/ref/fate/caf-pcm_s24-remux              |   1 -
 tests/ref/fate/caf-pcm_s24le-remux            |   1 -
 tests/ref/fate/caf-qdm2-remux                 |   1 -
 tests/ref/fate/cdxl-demux                     |   1 -
 tests/ref/fate/channel_layout                 | 111 +++
 tests/ref/fate/copy-psp                       |   1 -
 tests/ref/fate/copy-shortest1                 |   1 -
 tests/ref/fate/copy-shortest2                 |   1 -
 tests/ref/fate/copy-trac236                   |   1 -
 tests/ref/fate/copy-trac3074                  |   1 -
 tests/ref/fate/copy-trac4914                  |   1 -
 tests/ref/fate/copy-trac4914-avi              |   1 -
 tests/ref/fate/corepng                        |   1 -
 tests/ref/fate/cover-art-aiff-id3v2-remux     |   1 -
 tests/ref/fate/cover-art-flac-remux           |   6 +-
 tests/ref/fate/cover-art-mp3-id3v2-remux      |   1 -
 tests/ref/fate/creatureshock-avs              |   1 -
 tests/ref/fate/cyberia-c93                    |   1 -
 tests/ref/fate/d-cinema-demux                 |   1 -
 tests/ref/fate/dca-xll_51_16_192_768_0        |   1 -
 tests/ref/fate/dca-xll_51_16_192_768_0-dmix_2 |   1 -
 tests/ref/fate/dca-xll_51_16_192_768_0-dmix_6 |   1 -
 tests/ref/fate/dca-xll_51_16_192_768_1        |   1 -
 tests/ref/fate/dca-xll_51_16_192_768_1-dmix_2 |   1 -
 tests/ref/fate/dca-xll_51_16_192_768_1-dmix_6 |   1 -
 tests/ref/fate/dca-xll_51_24_48_768           |   1 -
 tests/ref/fate/dca-xll_51_24_48_768-dmix_2    |   1 -
 tests/ref/fate/dca-xll_51_24_48_768-dmix_6    |   1 -
 tests/ref/fate/dca-xll_51_24_48_none          |   1 -
 tests/ref/fate/dca-xll_51_24_48_none-dmix_2   |   1 -
 tests/ref/fate/dca-xll_51_24_48_none-dmix_6   |   1 -
 tests/ref/fate/dca-xll_71_24_48_768_0         |   1 -
 tests/ref/fate/dca-xll_71_24_48_768_0-dmix_2  |   1 -
 tests/ref/fate/dca-xll_71_24_48_768_0-dmix_6  |   1 -
 tests/ref/fate/dca-xll_71_24_48_768_1         |   1 -
 tests/ref/fate/dca-xll_71_24_48_768_1-dmix_2  |   1 -
 tests/ref/fate/dca-xll_71_24_48_768_1-dmix_6  |   1 -
 tests/ref/fate/dca-xll_71_24_96_768           |   1 -
 tests/ref/fate/dca-xll_71_24_96_768-dmix_2    |   1 -
 tests/ref/fate/dca-xll_71_24_96_768-dmix_6    |   1 -
 tests/ref/fate/dca-xll_x96_51_24_96_1509      |   1 -
 .../ref/fate/dca-xll_x96_51_24_96_1509-dmix_2 |   1 -
 .../ref/fate/dca-xll_x96_51_24_96_1509-dmix_6 |   1 -
 tests/ref/fate/dca-xll_xch_61_24_48_768       |   1 -
 .../ref/fate/dca-xll_xch_61_24_48_768-dmix_2  |   1 -
 .../ref/fate/dca-xll_xch_61_24_48_768-dmix_6  |   1 -
 tests/ref/fate/dcinema-encode                 |   1 -
 tests/ref/fate/delphine-cin-audio             |   1 -
 tests/ref/fate/dpcm-idroq                     |   1 -
 tests/ref/fate/dpcm-interplay                 |   1 -
 tests/ref/fate/dss-lp                         |   1 -
 tests/ref/fate/dss-sp                         |   1 -
 tests/ref/fate/ffmpeg-attached_pics           |   1 -
 tests/ref/fate/ffmpeg-filter_complex_audio    |   1 -
 tests/ref/fate/filter-acrossfade              |   1 -
 tests/ref/fate/filter-adelay                  |   1 -
 tests/ref/fate/filter-aecho                   |   1 -
 tests/ref/fate/filter-aemphasis               |   2 -
 tests/ref/fate/filter-aemphasis-50fm          |   1 -
 tests/ref/fate/filter-aemphasis-75kf          |   1 -
 tests/ref/fate/filter-afade-esin              |   1 -
 tests/ref/fate/filter-afade-exp               |   1 -
 tests/ref/fate/filter-afade-hsin              |   1 -
 tests/ref/fate/filter-afade-iqsin             |   1 -
 tests/ref/fate/filter-afade-log               |   1 -
 tests/ref/fate/filter-afade-qsin              |   1 -
 tests/ref/fate/filter-agate                   |   1 -
 tests/ref/fate/filter-alimiter                |   1 -
 tests/ref/fate/filter-amerge                  |   1 -
 tests/ref/fate/filter-anequalizer             |   1 -
 tests/ref/fate/filter-apad                    |   1 -
 tests/ref/fate/filter-asetnsamples-nopad      |   1 -
 tests/ref/fate/filter-asetnsamples-pad        |   1 -
 tests/ref/fate/filter-asetrate                |   1 -
 tests/ref/fate/filter-atrim-duration          |   1 -
 tests/ref/fate/filter-atrim-mixed             |   1 -
 tests/ref/fate/filter-atrim-samples           |   1 -
 tests/ref/fate/filter-atrim-time              |   1 -
 tests/ref/fate/filter-chorus                  |   1 -
 tests/ref/fate/filter-compand                 |   1 -
 tests/ref/fate/filter-concat                  |   1 -
 tests/ref/fate/filter-concat-vfr              |   1 -
 tests/ref/fate/filter-dcshift                 |   1 -
 tests/ref/fate/filter-earwax                  |   1 -
 tests/ref/fate/filter-extrastereo             |   1 -
 tests/ref/fate/filter-formats                 |  20 +-
 tests/ref/fate/filter-hls                     |   1 -
 tests/ref/fate/filter-hls-append              |   1 -
 tests/ref/fate/filter-meta-4560-rotate0       |   1 -
 tests/ref/fate/filter-overlay-dvdsub-2397     |   1 -
 tests/ref/fate/filter-pan-downmix1            |   1 -
 tests/ref/fate/filter-pan-downmix2            |   1 -
 tests/ref/fate/filter-pan-mono1               |   1 -
 tests/ref/fate/filter-pan-mono2               |   1 -
 tests/ref/fate/filter-pan-stereo1             |   1 -
 tests/ref/fate/filter-pan-stereo2             |   1 -
 tests/ref/fate/filter-pan-stereo3             |   1 -
 tests/ref/fate/filter-pan-stereo4             |   1 -
 tests/ref/fate/filter-pan-upmix1              |   1 -
 tests/ref/fate/filter-pan-upmix2              |   1 -
 tests/ref/fate/filter-silenceremove           |   1 -
 tests/ref/fate/filter-stereotools             |   1 -
 tests/ref/fate/g722-encode                    |   1 -
 tests/ref/fate/g722dec-1                      |   1 -
 tests/ref/fate/g723_1-dec-1                   |   1 -
 tests/ref/fate/g723_1-dec-2                   |   1 -
 tests/ref/fate/g723_1-dec-3                   |   1 -
 tests/ref/fate/g723_1-dec-4                   |   1 -
 tests/ref/fate/g723_1-dec-5                   |   1 -
 tests/ref/fate/g723_1-dec-6                   |   1 -
 tests/ref/fate/g723_1-dec-7                   |   1 -
 tests/ref/fate/g723_1-dec-8                   |   1 -
 tests/ref/fate/g726-encode-2bit               |   1 -
 tests/ref/fate/g726-encode-3bit               |   1 -
 tests/ref/fate/g726-encode-4bit               |   1 -
 tests/ref/fate/g726-encode-5bit               |   1 -
 tests/ref/fate/gapless-mp3                    |   6 +-
 tests/ref/fate/gsm-ms                         |   1 -
 tests/ref/fate/gsm-toast                      |   1 -
 tests/ref/fate/h264-skip-nointra              |   1 -
 tests/ref/fate/h264-skip-nokey                |   1 -
 tests/ref/fate/h264-xavc-4389                 |   1 -
 tests/ref/fate/hls-fmp4                       |   1 -
 tests/ref/fate/hls-init-time                  |   1 -
 tests/ref/fate/hls-list-size                  |   1 -
 tests/ref/fate/hls-segment-single             |   1 -
 tests/ref/fate/hls-segment-size               |   1 -
 tests/ref/fate/id-cin-video                   |   1 -
 tests/ref/fate/id3v2-chapters                 |   1 -
 tests/ref/fate/id3v2-priv-remux               |   1 -
 tests/ref/fate/jv-demux                       |   1 -
 tests/ref/fate/lmlm4-demux                    |   1 -
 tests/ref/fate/matroska-flac-channel-mapping  |   2 -
 tests/ref/fate/matroska-flac-extradata-update |   3 -
 tests/ref/fate/matroska-lzo-decompression     |   1 -
 .../fate/matroska-mastering-display-metadata  |   2 -
 tests/ref/fate/matroska-mpegts-remux          |   2 -
 .../matroska-wavpack-missing-codecprivate     |   1 -
 tests/ref/fate/matroska-xiph-lacing           |   1 -
 tests/ref/fate/maxis-xa                       |   1 -
 tests/ref/fate/mkv                            |   1 -
 tests/ref/fate/mkv-1242                       |   1 -
 tests/ref/fate/mov-440hz-10ms                 |   1 -
 tests/ref/fate/mov-bbi-elst-starts-b          |   1 -
 tests/ref/fate/mov-cover-image                |   1 -
 tests/ref/fate/mov-mp3-demux                  |   1 -
 .../ref/fate/mov-mp4-disposition-mpegts-remux |   2 -
 tests/ref/fate/mpegps-remuxed-pcm-demux       |   1 -
 tests/ref/fate/mtv                            |   1 -
 tests/ref/fate/mxf-demux                      |   1 -
 tests/ref/fate/nsv-demux                      |   1 -
 tests/ref/fate/oma-atrac3-remux               |   1 -
 tests/ref/fate/oma-atrac3p-remux              |   1 -
 tests/ref/fate/on2avc                         |   1 -
 tests/ref/fate/opt                            |  16 +-
 tests/ref/fate/paf-audio                      |   1 -
 tests/ref/fate/paf-demux                      |   1 -
 tests/ref/fate/pcm-planar                     |   1 -
 tests/ref/fate/pcm_dvd                        |   1 -
 tests/ref/fate/pmp-demux                      |   1 -
 tests/ref/fate/prores-gray                    |   1 -
 tests/ref/fate/prores-transparency            |   1 -
 tests/ref/fate/prores-transparency_skip       |   1 -
 tests/ref/fate/psx-str-demux                  |   1 -
 tests/ref/fate/pva-demux                      |   1 -
 tests/ref/fate/ra3-144                        |   1 -
 tests/ref/fate/redcode-demux                  |   1 -
 tests/ref/fate/s337m-demux                    |   1 -
 tests/ref/fate/segment-adts-to-mkv-header-000 |   1 -
 tests/ref/fate/segment-adts-to-mkv-header-001 |   1 -
 tests/ref/fate/segment-adts-to-mkv-header-002 |   1 -
 tests/ref/fate/segment-adts-to-mkv-header-all |   1 -
 tests/ref/fate/shortest                       |   1 -
 tests/ref/fate/sierra-vmd-audio               |   1 -
 tests/ref/fate/siff-demux                     |   1 -
 tests/ref/fate/smacker-audio                  |   1 -
 tests/ref/fate/smjpeg-demux                   |   1 -
 tests/ref/fate/sp5x                           |   1 -
 tests/ref/fate/tiertex-seq                    |   1 -
 tests/ref/fate/tmv                            |   1 -
 tests/ref/fate/tscc-15bit                     |   1 -
 tests/ref/fate/vqf-demux                      |   2 +-
 tests/ref/fate/wav-ac3                        |   1 -
 tests/ref/fate/wc3movie-xan                   |   1 -
 tests/ref/fate/webm-dash-chapters             |   1 -
 tests/ref/fate/westwood-aud                   |   1 -
 tests/ref/fate/wmv3-drm-nodec                 |   1 -
 tests/ref/fate/wtv-demux                      |   1 -
 tests/ref/fate/xmv-demux                      |   1 -
 793 files changed, 7311 insertions(+), 3936 deletions(-)
 create mode 100644 libavutil/tests/channel_layout.c
 create mode 100644 tests/ref/fate/channel_layout

-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13 14:08   ` Lynne
  2022-01-16 11:27   ` Nicolas George
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 002/281] fate: add a channel_layout API test James Almer
                   ` (281 subsequent siblings)
  282 siblings, 2 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

The new API is more extensible and allows for custom layouts.
More accurate information is exported, eg for decoders that do not
set a channel layout, lavc will not make one up for them.

Deprecate the old API working with just uint64_t bitmasks.

Expanded and completed by Vittorio Giovara <vittorio.giovara@gmail.com>
and James Almer <jamrial@gmail.com>.
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/channel_layout.c | 629 ++++++++++++++++++++++++++++++++-----
 libavutil/channel_layout.h | 542 ++++++++++++++++++++++++++++++--
 libavutil/version.h        |   1 +
 3 files changed, 1069 insertions(+), 103 deletions(-)

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index ac773a9e63..68b40cc37c 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -37,81 +37,151 @@ struct channel_name {
 };
 
 static const struct channel_name channel_names[] = {
-     [0] = { "FL",        "front left"            },
-     [1] = { "FR",        "front right"           },
-     [2] = { "FC",        "front center"          },
-     [3] = { "LFE",       "low frequency"         },
-     [4] = { "BL",        "back left"             },
-     [5] = { "BR",        "back right"            },
-     [6] = { "FLC",       "front left-of-center"  },
-     [7] = { "FRC",       "front right-of-center" },
-     [8] = { "BC",        "back center"           },
-     [9] = { "SL",        "side left"             },
-    [10] = { "SR",        "side right"            },
-    [11] = { "TC",        "top center"            },
-    [12] = { "TFL",       "top front left"        },
-    [13] = { "TFC",       "top front center"      },
-    [14] = { "TFR",       "top front right"       },
-    [15] = { "TBL",       "top back left"         },
-    [16] = { "TBC",       "top back center"       },
-    [17] = { "TBR",       "top back right"        },
-    [29] = { "DL",        "downmix left"          },
-    [30] = { "DR",        "downmix right"         },
-    [31] = { "WL",        "wide left"             },
-    [32] = { "WR",        "wide right"            },
-    [33] = { "SDL",       "surround direct left"  },
-    [34] = { "SDR",       "surround direct right" },
-    [35] = { "LFE2",      "low frequency 2"       },
-    [36] = { "TSL",       "top side left"         },
-    [37] = { "TSR",       "top side right"        },
-    [38] = { "BFC",       "bottom front center"   },
-    [39] = { "BFL",       "bottom front left"     },
-    [40] = { "BFR",       "bottom front right"    },
+    [AV_CHAN_FRONT_LEFT           ] = { "FL",        "front left"            },
+    [AV_CHAN_FRONT_RIGHT          ] = { "FR",        "front right"           },
+    [AV_CHAN_FRONT_CENTER         ] = { "FC",        "front center"          },
+    [AV_CHAN_LOW_FREQUENCY        ] = { "LFE",       "low frequency"         },
+    [AV_CHAN_BACK_LEFT            ] = { "BL",        "back left"             },
+    [AV_CHAN_BACK_RIGHT           ] = { "BR",        "back right"            },
+    [AV_CHAN_FRONT_LEFT_OF_CENTER ] = { "FLC",       "front left-of-center"  },
+    [AV_CHAN_FRONT_RIGHT_OF_CENTER] = { "FRC",       "front right-of-center" },
+    [AV_CHAN_BACK_CENTER          ] = { "BC",        "back center"           },
+    [AV_CHAN_SIDE_LEFT            ] = { "SL",        "side left"             },
+    [AV_CHAN_SIDE_RIGHT           ] = { "SR",        "side right"            },
+    [AV_CHAN_TOP_CENTER           ] = { "TC",        "top center"            },
+    [AV_CHAN_TOP_FRONT_LEFT       ] = { "TFL",       "top front left"        },
+    [AV_CHAN_TOP_FRONT_CENTER     ] = { "TFC",       "top front center"      },
+    [AV_CHAN_TOP_FRONT_RIGHT      ] = { "TFR",       "top front right"       },
+    [AV_CHAN_TOP_BACK_LEFT        ] = { "TBL",       "top back left"         },
+    [AV_CHAN_TOP_BACK_CENTER      ] = { "TBC",       "top back center"       },
+    [AV_CHAN_TOP_BACK_RIGHT       ] = { "TBR",       "top back right"        },
+    [AV_CHAN_STEREO_LEFT          ] = { "DL",        "downmix left"          },
+    [AV_CHAN_STEREO_RIGHT         ] = { "DR",        "downmix right"         },
+    [AV_CHAN_WIDE_LEFT            ] = { "WL",        "wide left"             },
+    [AV_CHAN_WIDE_RIGHT           ] = { "WR",        "wide right"            },
+    [AV_CHAN_SURROUND_DIRECT_LEFT ] = { "SDL",       "surround direct left"  },
+    [AV_CHAN_SURROUND_DIRECT_RIGHT] = { "SDR",       "surround direct right" },
+    [AV_CHAN_LOW_FREQUENCY_2      ] = { "LFE2",      "low frequency 2"       },
+    [AV_CHAN_TOP_SIDE_LEFT        ] = { "TSL",       "top side left"         },
+    [AV_CHAN_TOP_SIDE_RIGHT       ] = { "TSR",       "top side right"        },
+    [AV_CHAN_BOTTOM_FRONT_CENTER  ] = { "BFC",       "bottom front center"   },
+    [AV_CHAN_BOTTOM_FRONT_LEFT    ] = { "BFL",       "bottom front left"     },
+    [AV_CHAN_BOTTOM_FRONT_RIGHT   ] = { "BFR",       "bottom front right"    },
 };
 
-static const char *get_channel_name(int channel_id)
+static const char *get_channel_name(enum AVChannel channel_id)
 {
-    if (channel_id < 0 || channel_id >= FF_ARRAY_ELEMS(channel_names))
+    if ((unsigned) channel_id >= FF_ARRAY_ELEMS(channel_names) ||
+        !channel_names[channel_id].name)
         return NULL;
     return channel_names[channel_id].name;
 }
 
-static const struct {
+void av_channel_name_bprint(AVBPrint *bp, enum AVChannel channel_id)
+{
+    av_bprint_clear(bp);
+
+    if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names))
+        av_bprintf(bp, "%s", channel_names[channel_id].name);
+    else
+        av_bprintf(bp, "USR%d", channel_id);
+}
+
+int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel_id)
+{
+    AVBPrint bp;
+
+    if (!buf && buf_size)
+        return AVERROR(EINVAL);
+
+    av_bprint_init_for_buffer(&bp, buf, buf_size);
+    av_channel_name_bprint(&bp, channel_id);
+
+    return bp.len;
+}
+
+void av_channel_description_bprint(AVBPrint *bp, enum AVChannel channel_id)
+{
+    av_bprint_clear(bp);
+
+    if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names))
+        av_bprintf(bp, "%s", channel_names[channel_id].description);
+    else
+        av_bprintf(bp, "user %d", channel_id);
+}
+
+int av_channel_description(char *buf, size_t buf_size, enum AVChannel channel_id)
+{
+    AVBPrint bp;
+
+    if (!buf && buf_size)
+        return AVERROR(EINVAL);
+
+    av_bprint_init_for_buffer(&bp, buf, buf_size);
+    av_channel_description_bprint(&bp, channel_id);
+
+    return bp.len;
+}
+
+enum AVChannel av_channel_from_string(const char *str)
+{
+    int i;
+    char *endptr = (char *)str;
+    enum AVChannel id = AV_CHAN_NONE;
+    for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) {
+        if (channel_names[i].name && !strcmp(str, channel_names[i].name))
+            return i;
+    }
+    if (!strncmp(str, "USR", 3)) {
+        const char *p = str + 3;
+        id = strtol(p, &endptr, 0);
+    }
+    if (id >= 0 && !*endptr)
+        return id;
+
+    return AV_CHAN_NONE;
+}
+
+struct channel_layout_name {
     const char *name;
-    int         nb_channels;
-    uint64_t     layout;
-} channel_layout_map[] = {
-    { "mono",        1,  AV_CH_LAYOUT_MONO },
-    { "stereo",      2,  AV_CH_LAYOUT_STEREO },
-    { "2.1",         3,  AV_CH_LAYOUT_2POINT1 },
-    { "3.0",         3,  AV_CH_LAYOUT_SURROUND },
-    { "3.0(back)",   3,  AV_CH_LAYOUT_2_1 },
-    { "4.0",         4,  AV_CH_LAYOUT_4POINT0 },
-    { "quad",        4,  AV_CH_LAYOUT_QUAD },
-    { "quad(side)",  4,  AV_CH_LAYOUT_2_2 },
-    { "3.1",         4,  AV_CH_LAYOUT_3POINT1 },
-    { "5.0",         5,  AV_CH_LAYOUT_5POINT0_BACK },
-    { "5.0(side)",   5,  AV_CH_LAYOUT_5POINT0 },
-    { "4.1",         5,  AV_CH_LAYOUT_4POINT1 },
-    { "5.1",         6,  AV_CH_LAYOUT_5POINT1_BACK },
-    { "5.1(side)",   6,  AV_CH_LAYOUT_5POINT1 },
-    { "6.0",         6,  AV_CH_LAYOUT_6POINT0 },
-    { "6.0(front)",  6,  AV_CH_LAYOUT_6POINT0_FRONT },
-    { "hexagonal",   6,  AV_CH_LAYOUT_HEXAGONAL },
-    { "6.1",         7,  AV_CH_LAYOUT_6POINT1 },
-    { "6.1(back)",   7,  AV_CH_LAYOUT_6POINT1_BACK },
-    { "6.1(front)",  7,  AV_CH_LAYOUT_6POINT1_FRONT },
-    { "7.0",         7,  AV_CH_LAYOUT_7POINT0 },
-    { "7.0(front)",  7,  AV_CH_LAYOUT_7POINT0_FRONT },
-    { "7.1",         8,  AV_CH_LAYOUT_7POINT1 },
-    { "7.1(wide)",   8,  AV_CH_LAYOUT_7POINT1_WIDE_BACK },
-    { "7.1(wide-side)",   8,  AV_CH_LAYOUT_7POINT1_WIDE },
-    { "octagonal",   8,  AV_CH_LAYOUT_OCTAGONAL },
-    { "hexadecagonal", 16, AV_CH_LAYOUT_HEXADECAGONAL },
-    { "downmix",     2,  AV_CH_LAYOUT_STEREO_DOWNMIX, },
-    { "22.2",          24, AV_CH_LAYOUT_22POINT2, },
+    AVChannelLayout layout;
+};
+
+static const struct channel_layout_name channel_layout_map[] = {
+    { "mono",           AV_CHANNEL_LAYOUT_MONO                },
+    { "stereo",         AV_CHANNEL_LAYOUT_STEREO              },
+    { "stereo",         AV_CHANNEL_LAYOUT_STEREO_DOWNMIX      },
+    { "2.1",            AV_CHANNEL_LAYOUT_2POINT1             },
+    { "3.0",            AV_CHANNEL_LAYOUT_SURROUND            },
+    { "3.0(back)",      AV_CHANNEL_LAYOUT_2_1                 },
+    { "4.0",            AV_CHANNEL_LAYOUT_4POINT0             },
+    { "quad",           AV_CHANNEL_LAYOUT_QUAD                },
+    { "quad(side)",     AV_CHANNEL_LAYOUT_2_2                 },
+    { "3.1",            AV_CHANNEL_LAYOUT_3POINT1             },
+    { "5.0",            AV_CHANNEL_LAYOUT_5POINT0_BACK        },
+    { "5.0(side)",      AV_CHANNEL_LAYOUT_5POINT0             },
+    { "4.1",            AV_CHANNEL_LAYOUT_4POINT1             },
+    { "5.1",            AV_CHANNEL_LAYOUT_5POINT1_BACK        },
+    { "5.1(side)",      AV_CHANNEL_LAYOUT_5POINT1             },
+    { "6.0",            AV_CHANNEL_LAYOUT_6POINT0             },
+    { "6.0(front)",     AV_CHANNEL_LAYOUT_6POINT0_FRONT       },
+    { "hexagonal",      AV_CHANNEL_LAYOUT_HEXAGONAL           },
+    { "6.1",            AV_CHANNEL_LAYOUT_6POINT1             },
+    { "6.1(back)",      AV_CHANNEL_LAYOUT_6POINT1_BACK        },
+    { "6.1(front)",     AV_CHANNEL_LAYOUT_6POINT1_FRONT       },
+    { "7.0",            AV_CHANNEL_LAYOUT_7POINT0             },
+    { "7.0(front)",     AV_CHANNEL_LAYOUT_7POINT0_FRONT       },
+    { "7.1",            AV_CHANNEL_LAYOUT_7POINT1             },
+    { "7.1(wide)",      AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK   },
+    { "7.1(wide-side)", AV_CHANNEL_LAYOUT_7POINT1_WIDE        },
+    { "octagonal",      AV_CHANNEL_LAYOUT_OCTAGONAL           },
+    { "hexadecagonal",  AV_CHANNEL_LAYOUT_HEXADECAGONAL       },
+    { "downmix",        AV_CHANNEL_LAYOUT_STEREO_DOWNMIX,     },
+    { "22.2",           AV_CHANNEL_LAYOUT_22POINT2,           },
 };
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 static uint64_t get_channel_layout_single(const char *name, int name_len)
 {
     int i;
@@ -121,7 +191,7 @@ static uint64_t get_channel_layout_single(const char *name, int name_len)
     for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) {
         if (strlen(channel_layout_map[i].name) == name_len &&
             !memcmp(channel_layout_map[i].name, name, name_len))
-            return channel_layout_map[i].layout;
+            return channel_layout_map[i].layout.u.mask;
     }
     for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++)
         if (channel_names[i].name &&
@@ -189,8 +259,8 @@ void av_bprint_channel_layout(struct AVBPrint *bp,
         nb_channels = av_get_channel_layout_nb_channels(channel_layout);
 
     for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
-        if (nb_channels    == channel_layout_map[i].nb_channels &&
-            channel_layout == channel_layout_map[i].layout) {
+        if (nb_channels    == channel_layout_map[i].layout.nb_channels &&
+            channel_layout == channel_layout_map[i].layout.u.mask) {
             av_bprintf(bp, "%s", channel_layout_map[i].name);
             return;
         }
@@ -231,8 +301,8 @@ int av_get_channel_layout_nb_channels(uint64_t channel_layout)
 int64_t av_get_default_channel_layout(int nb_channels) {
     int i;
     for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
-        if (nb_channels == channel_layout_map[i].nb_channels)
-            return channel_layout_map[i].layout;
+        if (nb_channels == channel_layout_map[i].layout.nb_channels)
+            return channel_layout_map[i].layout.u.mask;
     return 0;
 }
 
@@ -287,7 +357,424 @@ int av_get_standard_channel_layout(unsigned index, uint64_t *layout,
 {
     if (index >= FF_ARRAY_ELEMS(channel_layout_map))
         return AVERROR_EOF;
-    if (layout) *layout = channel_layout_map[index].layout;
+    if (layout) *layout = channel_layout_map[index].layout.u.mask;
     if (name)   *name   = channel_layout_map[index].name;
     return 0;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+int av_channel_layout_from_mask(AVChannelLayout *channel_layout,
+                                uint64_t mask)
+{
+    if (!mask)
+        return AVERROR(EINVAL);
+
+    channel_layout->order       = AV_CHANNEL_ORDER_NATIVE;
+    channel_layout->nb_channels = av_popcount64(mask);
+    channel_layout->u.mask      = mask;
+
+    return 0;
+}
+
+int av_channel_layout_from_string(AVChannelLayout *channel_layout,
+                                  const char *str)
+{
+    int i;
+    int channels = 0, native = 1;
+    enum AVChannel highest_channel = AV_CHAN_NONE;
+    const char *dup = str;
+    char *end;
+    uint64_t mask = 0;
+
+    /* channel layout names */
+    for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) {
+        if (channel_layout_map[i].name && !strcmp(str, channel_layout_map[i].name)) {
+            *channel_layout = channel_layout_map[i].layout;
+            return 0;
+        }
+    }
+
+    /* channel names */
+    while (*dup) {
+        char *chname = av_get_token(&dup, "+");
+        if (!chname)
+            return AVERROR(ENOMEM);
+        if (*dup)
+            dup++; // skip separator
+        for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) {
+            if (channel_names[i].name && !strcmp(chname, channel_names[i].name)) {
+                if (i < highest_channel)
+                    native = 0; // Not a native layout, use a custom one
+                highest_channel = i;
+                mask |= 1ULL << i;
+                break;
+            }
+        }
+
+        if (i >= FF_ARRAY_ELEMS(channel_names)) {
+            char *endptr = chname;
+            enum AVChannel id = AV_CHAN_NONE;
+
+            if (!strncmp(chname, "USR", 3)) {
+                const char *p = chname + 3;
+                id = strtol(p, &endptr, 0);
+            }
+            if (id < 0 || *endptr) {
+                native = 0; // Unknown channel name
+                channels = 0;
+                mask = 0;
+                av_free(chname);
+                break;
+            }
+            if (id > 63)
+                native = 0; // Not a native layout, use a custom one
+            else {
+                if (id < highest_channel)
+                    native = 0; // Not a native layout, use a custom one
+                highest_channel = id;
+                mask |= 1ULL << id;
+            }
+        }
+        channels++;
+        av_free(chname);
+    }
+    if (mask && native) {
+        av_channel_layout_from_mask(channel_layout, mask);
+        return 0;
+    }
+
+    /* custom layout of channel names */
+    if (channels && !native) {
+        int idx = 0;
+
+        channel_layout->u.map = av_calloc(channels, sizeof(*channel_layout->u.map));
+        if (!channel_layout->u.map)
+            return AVERROR(ENOMEM);
+
+        channel_layout->order = AV_CHANNEL_ORDER_CUSTOM;
+        channel_layout->nb_channels = channels;
+
+        dup = str;
+        while (*dup) {
+            char *chname = av_get_token(&dup, "+");
+            if (!chname) {
+                av_freep(&channel_layout->u.map);
+                return AVERROR(ENOMEM);
+            }
+            if (*dup)
+                dup++; // skip separator
+            for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) {
+                if (channel_names[i].name && !strcmp(chname, channel_names[i].name)) {
+                    channel_layout->u.map[idx++].id = i;
+                    break;
+                }
+            }
+            if (i >= FF_ARRAY_ELEMS(channel_names)) {
+                const char *p = chname + 3;
+                channel_layout->u.map[idx++].id = strtol(p, NULL, 0);
+            }
+            av_free(chname);
+        }
+
+        return 0;
+    }
+
+    /* channel layout mask */
+    if (!strncmp(str, "0x", 2) && sscanf(str + 2, "%"SCNx64, &mask) == 1) {
+        av_channel_layout_from_mask(channel_layout, mask);
+        return 0;
+    }
+
+    errno = 0;
+    channels = strtol(str, &end, 10);
+
+    /* number of channels */
+    if (!errno && *end == 'c' && !*(end + 1) && channels >= 0) {
+        av_channel_layout_default(channel_layout, channels);
+        return 0;
+    }
+
+    /* number of unordered channels */
+    if (!errno && (!*end || (*end == 'C' && !*(end + 1)) || av_strnstr(str, "channels", strlen(str)))
+        && channels >= 0) {
+        channel_layout->order = AV_CHANNEL_ORDER_UNSPEC;
+        channel_layout->nb_channels = channels;
+        return 0;
+    }
+
+    return AVERROR_INVALIDDATA;
+}
+
+void av_channel_layout_uninit(AVChannelLayout *channel_layout)
+{
+    if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM)
+        av_freep(&channel_layout->u.map);
+    memset(channel_layout, 0, sizeof(*channel_layout));
+}
+
+int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
+{
+    av_channel_layout_uninit(dst);
+    *dst = *src;
+    if (src->order == AV_CHANNEL_ORDER_CUSTOM) {
+        dst->u.map = av_malloc_array(src->nb_channels, sizeof(*dst->u.map));
+        if (!dst->u.map)
+            return AVERROR(ENOMEM);
+        memcpy(dst->u.map, src->u.map, src->nb_channels * sizeof(*src->u.map));
+    }
+    return 0;
+}
+
+int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout,
+                                      AVBPrint *bp)
+{
+    int i;
+
+    av_bprint_clear(bp);
+
+    switch (channel_layout->order) {
+    case AV_CHANNEL_ORDER_NATIVE:
+        for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
+            if (channel_layout->u.mask == channel_layout_map[i].layout.u.mask) {
+                av_bprintf(bp, "%s", channel_layout_map[i].name);
+                return 0;
+            }
+        // fall-through
+    case AV_CHANNEL_ORDER_CUSTOM:
+        for (i = 0; i < channel_layout->nb_channels; i++) {
+            const char *ch_name = NULL;
+            enum AVChannel ch = AV_CHAN_NONE;
+
+            if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM &&
+                channel_layout->u.map[i].name[0])
+                ch_name = channel_layout->u.map[i].name;
+            if (channel_layout->order == AV_CHANNEL_ORDER_NATIVE || !ch_name) {
+                ch = av_channel_layout_channel_from_index(channel_layout, i);
+                ch_name = get_channel_name(ch);
+            }
+
+            if (i)
+                av_bprintf(bp, "+");
+            if (ch_name)
+                av_bprintf(bp, "%s", ch_name);
+            else
+                av_bprintf(bp, "USR%d", ch);
+        }
+        if (channel_layout->nb_channels)
+            return 0;
+        // fall-through
+    case AV_CHANNEL_ORDER_UNSPEC:
+        av_bprintf(bp, "%d channels", channel_layout->nb_channels);
+        return 0;
+    default:
+        return AVERROR(EINVAL);
+    }
+}
+
+int av_channel_layout_describe(const AVChannelLayout *channel_layout,
+                               char *buf, size_t buf_size)
+{
+    AVBPrint bp;
+    int ret;
+
+    if (!buf && buf_size)
+        return AVERROR(EINVAL);
+
+    av_bprint_init_for_buffer(&bp, buf, buf_size);
+    ret = av_channel_layout_describe_bprint(channel_layout, &bp);
+    if (ret < 0)
+        return ret;
+
+    return bp.len;
+}
+
+enum AVChannel
+av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout,
+                                     unsigned int idx)
+{
+    int i;
+
+    if (idx >= channel_layout->nb_channels)
+        return AV_CHAN_NONE;
+
+    switch (channel_layout->order) {
+    case AV_CHANNEL_ORDER_CUSTOM:
+        return channel_layout->u.map[idx].id;
+    case AV_CHANNEL_ORDER_NATIVE:
+        for (i = 0; i < 64; i++) {
+            if ((1ULL << i) & channel_layout->u.mask && !idx--)
+                return i;
+        }
+    default:
+        return AV_CHAN_NONE;
+    }
+}
+
+enum AVChannel
+av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout,
+                                      const char *name)
+{
+    int channel, ret;
+
+    switch (channel_layout->order) {
+    case AV_CHANNEL_ORDER_CUSTOM:
+        for (int i = 0; i < channel_layout->nb_channels; i++) {
+            if (channel_layout->u.map[i].name[0] && !strcmp(name, channel_layout->u.map[i].name))
+                return channel_layout->u.map[i].id;
+        }
+        // fall-through
+    case AV_CHANNEL_ORDER_NATIVE:
+        channel = av_channel_from_string(name);
+        if (channel == AV_CHAN_NONE)
+            return channel;
+        ret = av_channel_layout_index_from_channel(channel_layout, channel);
+        if (ret < 0)
+            return AV_CHAN_NONE;
+        return channel;
+    }
+
+    return AV_CHAN_NONE;
+}
+
+int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout,
+                                         enum AVChannel channel)
+{
+    int i;
+
+    if (channel == AV_CHAN_NONE)
+        return AVERROR(EINVAL);
+
+    switch (channel_layout->order) {
+    case AV_CHANNEL_ORDER_CUSTOM:
+        for (i = 0; i < channel_layout->nb_channels; i++)
+            if (channel_layout->u.map[i].id == channel)
+                return i;
+        return AVERROR(EINVAL);
+    case AV_CHANNEL_ORDER_NATIVE: {
+        uint64_t mask = channel_layout->u.mask;
+        if (!(mask & (1ULL << channel)))
+            return AVERROR(EINVAL);
+        mask &= (1ULL << channel) - 1;
+        return av_popcount64(mask);
+        }
+    default:
+        return AVERROR(EINVAL);
+    }
+}
+
+int av_channel_layout_index_from_string(const AVChannelLayout *channel_layout,
+                                        const char *name)
+{
+    enum AVChannel ch;
+
+    switch (channel_layout->order) {
+    case AV_CHANNEL_ORDER_CUSTOM:
+        for (int i = 0; i < channel_layout->nb_channels; i++) {
+            if (channel_layout->u.map[i].name[0] && !strcmp(name, channel_layout->u.map[i].name))
+                return i;
+        }
+        // fall-through
+    case AV_CHANNEL_ORDER_NATIVE:
+        ch = av_channel_from_string(name);
+        if (ch == AV_CHAN_NONE)
+            return AVERROR(EINVAL);
+        return av_channel_layout_index_from_channel(channel_layout, ch);
+    }
+
+    return AVERROR(EINVAL);
+}
+
+int av_channel_layout_check(const AVChannelLayout *channel_layout)
+{
+    if (channel_layout->nb_channels <= 0)
+        return 0;
+
+    switch (channel_layout->order) {
+    case AV_CHANNEL_ORDER_NATIVE:
+        return av_popcount64(channel_layout->u.mask) == channel_layout->nb_channels;
+    case AV_CHANNEL_ORDER_CUSTOM:
+        if (!channel_layout->u.map)
+            return 0;
+        for (int i = 0; i < channel_layout->nb_channels; i++) {
+            if (channel_layout->u.map[i].id == AV_CHAN_NONE)
+                return 0;
+        }
+        return 1;
+    case AV_CHANNEL_ORDER_UNSPEC:
+        return 1;
+    default:
+        return 0;
+    }
+}
+
+int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
+{
+    int i;
+
+    /* different channel counts -> not equal */
+    if (chl->nb_channels != chl1->nb_channels)
+        return 1;
+
+    /* if only one is unspecified -> not equal */
+    if ((chl->order  == AV_CHANNEL_ORDER_UNSPEC) !=
+        (chl1->order == AV_CHANNEL_ORDER_UNSPEC))
+        return 1;
+    /* both are unspecified -> equal */
+    else if (chl->order == AV_CHANNEL_ORDER_UNSPEC)
+        return 0;
+
+    /* can compare masks directly */
+    if (chl->order != AV_CHANNEL_ORDER_CUSTOM &&
+        chl->order == chl1->order)
+        return chl->u.mask != chl1->u.mask;
+
+    /* compare channel by channel */
+    for (i = 0; i < chl->nb_channels; i++)
+        if (av_channel_layout_channel_from_index(chl,  i) !=
+            av_channel_layout_channel_from_index(chl1, i))
+            return 1;
+    return 0;
+}
+
+void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
+{
+    int i;
+    for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
+        if (nb_channels == channel_layout_map[i].layout.nb_channels) {
+            *ch_layout = channel_layout_map[i].layout;
+            return;
+        }
+
+    ch_layout->order       = AV_CHANNEL_ORDER_UNSPEC;
+    ch_layout->nb_channels = nb_channels;
+}
+
+const AVChannelLayout *av_channel_layout_standard(void **opaque)
+{
+    uintptr_t i = (uintptr_t)*opaque;
+    const AVChannelLayout *ch_layout = NULL;
+
+    if (i < FF_ARRAY_ELEMS(channel_layout_map)) {
+        ch_layout = &channel_layout_map[i].layout;
+        *opaque = (void*)(i + 1);
+    }
+
+    return ch_layout;
+}
+
+uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout,
+                                  uint64_t mask)
+{
+    uint64_t ret = 0;
+    int i;
+
+    if (channel_layout->order == AV_CHANNEL_ORDER_NATIVE)
+        return channel_layout->u.mask & mask;
+
+    for (i = 0; i < 64; i++)
+        if (mask & (1ULL << i) && av_channel_layout_index_from_channel(channel_layout, i) >= 0)
+            ret |= (1ULL << i);
+
+    return ret;
+}
diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h
index d39ae1177a..6356a9a38a 100644
--- a/libavutil/channel_layout.h
+++ b/libavutil/channel_layout.h
@@ -23,6 +23,10 @@
 #define AVUTIL_CHANNEL_LAYOUT_H
 
 #include <stdint.h>
+#include <stdlib.h>
+
+#include "version.h"
+#include "attributes.h"
 
 /**
  * @file
@@ -34,6 +38,71 @@
  * @{
  */
 
+enum AVChannel {
+    ///< Invalid channel index
+    AV_CHAN_NONE = -1,
+    AV_CHAN_FRONT_LEFT,
+    AV_CHAN_FRONT_RIGHT,
+    AV_CHAN_FRONT_CENTER,
+    AV_CHAN_LOW_FREQUENCY,
+    AV_CHAN_BACK_LEFT,
+    AV_CHAN_BACK_RIGHT,
+    AV_CHAN_FRONT_LEFT_OF_CENTER,
+    AV_CHAN_FRONT_RIGHT_OF_CENTER,
+    AV_CHAN_BACK_CENTER,
+    AV_CHAN_SIDE_LEFT,
+    AV_CHAN_SIDE_RIGHT,
+    AV_CHAN_TOP_CENTER,
+    AV_CHAN_TOP_FRONT_LEFT,
+    AV_CHAN_TOP_FRONT_CENTER,
+    AV_CHAN_TOP_FRONT_RIGHT,
+    AV_CHAN_TOP_BACK_LEFT,
+    AV_CHAN_TOP_BACK_CENTER,
+    AV_CHAN_TOP_BACK_RIGHT,
+    /** Stereo downmix. */
+    AV_CHAN_STEREO_LEFT = 29,
+    /** See above. */
+    AV_CHAN_STEREO_RIGHT,
+    AV_CHAN_WIDE_LEFT,
+    AV_CHAN_WIDE_RIGHT,
+    AV_CHAN_SURROUND_DIRECT_LEFT,
+    AV_CHAN_SURROUND_DIRECT_RIGHT,
+    AV_CHAN_LOW_FREQUENCY_2,
+    AV_CHAN_TOP_SIDE_LEFT,
+    AV_CHAN_TOP_SIDE_RIGHT,
+    AV_CHAN_BOTTOM_FRONT_CENTER,
+    AV_CHAN_BOTTOM_FRONT_LEFT,
+    AV_CHAN_BOTTOM_FRONT_RIGHT,
+
+    /** Channel is empty can be safely skipped. */
+    AV_CHAN_UNUSED = 64,
+
+    /** Channel contains data, but its position is unknown. */
+    AV_CHAN_UNKWNOWN = 128,
+};
+
+enum AVChannelOrder {
+    /**
+     * Only the channel count is specified, without any further information
+     * about the channel order.
+     */
+    AV_CHANNEL_ORDER_UNSPEC,
+    /**
+     * The native channel order, i.e. the channels are in the same order in
+     * which they are defined in the AVChannel enum. This supports up to 63
+     * different channels.
+     */
+    AV_CHANNEL_ORDER_NATIVE,
+    /**
+     * The channel order does not correspond to any other predefined order and
+     * is stored as an explicit map. For example, this could be used to support
+     * layouts with 64 or more channels, or with empty/skipped (AV_CHAN_SILENCE)
+     * channels at arbitrary positions.
+     */
+    AV_CHANNEL_ORDER_CUSTOM,
+};
+
+
 /**
  * @defgroup channel_masks Audio channel masks
  *
@@ -46,41 +115,46 @@
  *
  * @{
  */
-#define AV_CH_FRONT_LEFT             0x00000001
-#define AV_CH_FRONT_RIGHT            0x00000002
-#define AV_CH_FRONT_CENTER           0x00000004
-#define AV_CH_LOW_FREQUENCY          0x00000008
-#define AV_CH_BACK_LEFT              0x00000010
-#define AV_CH_BACK_RIGHT             0x00000020
-#define AV_CH_FRONT_LEFT_OF_CENTER   0x00000040
-#define AV_CH_FRONT_RIGHT_OF_CENTER  0x00000080
-#define AV_CH_BACK_CENTER            0x00000100
-#define AV_CH_SIDE_LEFT              0x00000200
-#define AV_CH_SIDE_RIGHT             0x00000400
-#define AV_CH_TOP_CENTER             0x00000800
-#define AV_CH_TOP_FRONT_LEFT         0x00001000
-#define AV_CH_TOP_FRONT_CENTER       0x00002000
-#define AV_CH_TOP_FRONT_RIGHT        0x00004000
-#define AV_CH_TOP_BACK_LEFT          0x00008000
-#define AV_CH_TOP_BACK_CENTER        0x00010000
-#define AV_CH_TOP_BACK_RIGHT         0x00020000
-#define AV_CH_STEREO_LEFT            0x20000000  ///< Stereo downmix.
-#define AV_CH_STEREO_RIGHT           0x40000000  ///< See AV_CH_STEREO_LEFT.
-#define AV_CH_WIDE_LEFT              0x0000000080000000ULL
-#define AV_CH_WIDE_RIGHT             0x0000000100000000ULL
-#define AV_CH_SURROUND_DIRECT_LEFT   0x0000000200000000ULL
-#define AV_CH_SURROUND_DIRECT_RIGHT  0x0000000400000000ULL
-#define AV_CH_LOW_FREQUENCY_2        0x0000000800000000ULL
-#define AV_CH_TOP_SIDE_LEFT          0x0000001000000000ULL
-#define AV_CH_TOP_SIDE_RIGHT         0x0000002000000000ULL
-#define AV_CH_BOTTOM_FRONT_CENTER    0x0000004000000000ULL
-#define AV_CH_BOTTOM_FRONT_LEFT      0x0000008000000000ULL
-#define AV_CH_BOTTOM_FRONT_RIGHT     0x0000010000000000ULL
+#define AV_CH_FRONT_LEFT             (1ULL << AV_CHAN_FRONT_LEFT           )
+#define AV_CH_FRONT_RIGHT            (1ULL << AV_CHAN_FRONT_RIGHT          )
+#define AV_CH_FRONT_CENTER           (1ULL << AV_CHAN_FRONT_CENTER         )
+#define AV_CH_LOW_FREQUENCY          (1ULL << AV_CHAN_LOW_FREQUENCY        )
+#define AV_CH_BACK_LEFT              (1ULL << AV_CHAN_BACK_LEFT            )
+#define AV_CH_BACK_RIGHT             (1ULL << AV_CHAN_BACK_RIGHT           )
+#define AV_CH_FRONT_LEFT_OF_CENTER   (1ULL << AV_CHAN_FRONT_LEFT_OF_CENTER )
+#define AV_CH_FRONT_RIGHT_OF_CENTER  (1ULL << AV_CHAN_FRONT_RIGHT_OF_CENTER)
+#define AV_CH_BACK_CENTER            (1ULL << AV_CHAN_BACK_CENTER          )
+#define AV_CH_SIDE_LEFT              (1ULL << AV_CHAN_SIDE_LEFT            )
+#define AV_CH_SIDE_RIGHT             (1ULL << AV_CHAN_SIDE_RIGHT           )
+#define AV_CH_TOP_CENTER             (1ULL << AV_CHAN_TOP_CENTER           )
+#define AV_CH_TOP_FRONT_LEFT         (1ULL << AV_CHAN_TOP_FRONT_LEFT       )
+#define AV_CH_TOP_FRONT_CENTER       (1ULL << AV_CHAN_TOP_FRONT_CENTER     )
+#define AV_CH_TOP_FRONT_RIGHT        (1ULL << AV_CHAN_TOP_FRONT_RIGHT      )
+#define AV_CH_TOP_BACK_LEFT          (1ULL << AV_CHAN_TOP_BACK_LEFT        )
+#define AV_CH_TOP_BACK_CENTER        (1ULL << AV_CHAN_TOP_BACK_CENTER      )
+#define AV_CH_TOP_BACK_RIGHT         (1ULL << AV_CHAN_TOP_BACK_RIGHT       )
+#define AV_CH_STEREO_LEFT            (1ULL << AV_CHAN_STEREO_LEFT          )
+#define AV_CH_STEREO_RIGHT           (1ULL << AV_CHAN_STEREO_RIGHT         )
+#define AV_CH_WIDE_LEFT              (1ULL << AV_CHAN_WIDE_LEFT            )
+#define AV_CH_WIDE_RIGHT             (1ULL << AV_CHAN_WIDE_RIGHT           )
+#define AV_CH_SURROUND_DIRECT_LEFT   (1ULL << AV_CHAN_SURROUND_DIRECT_LEFT )
+#define AV_CH_SURROUND_DIRECT_RIGHT  (1ULL << AV_CHAN_SURROUND_DIRECT_RIGHT)
+#define AV_CH_LOW_FREQUENCY_2        (1ULL << AV_CHAN_LOW_FREQUENCY_2      )
+#define AV_CH_TOP_SIDE_LEFT          (1ULL << AV_CHAN_TOP_SIDE_LEFT        )
+#define AV_CH_TOP_SIDE_RIGHT         (1ULL << AV_CHAN_TOP_SIDE_RIGHT       )
+#define AV_CH_BOTTOM_FRONT_CENTER    (1ULL << AV_CHAN_BOTTOM_FRONT_CENTER  )
+#define AV_CH_BOTTOM_FRONT_LEFT      (1ULL << AV_CHAN_BOTTOM_FRONT_LEFT    )
+#define AV_CH_BOTTOM_FRONT_RIGHT     (1ULL << AV_CHAN_BOTTOM_FRONT_RIGHT   )
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 /** Channel mask value used for AVCodecContext.request_channel_layout
     to indicate that the user requests the channel order of the decoder output
-    to be the native codec channel order. */
+    to be the native codec channel order.
+    @deprecated channel order is now indicated in a special field in
+                AVChannelLayout
+    */
 #define AV_CH_LAYOUT_NATIVE          0x8000000000000000ULL
+#endif
 
 /**
  * @}
@@ -128,6 +202,167 @@ enum AVMatrixEncoding {
     AV_MATRIX_ENCODING_NB
 };
 
+/**
+ * @}
+ */
+
+/**
+ * An AVChannelCustom defines a single channel within a custom order layout
+ *
+ * Unlike most structures in FFmpeg, sizeof(AVChannelCustom) is a part of the
+ * public ABI.
+ *
+ * No new fields may be added to it without a major version bump.
+ */
+typedef struct AVChannelCustom {
+    enum AVChannel id;
+    char name[16];
+    void *opaque;
+} AVChannelCustom;
+
+/**
+ * An AVChannelLayout holds information about the channel layout of audio data.
+ *
+ * A channel layout here is defined as a set of channels ordered in a specific
+ * way (unless the channel order is AV_CHANNEL_ORDER_UNSPEC, in which case an
+ * AVChannelLayout carries only the channel count).
+ *
+ * Unlike most structures in Libav, sizeof(AVChannelLayout) is a part of the
+ * public ABI and may be used by the caller. E.g. it may be allocated on stack
+ * or embedded in caller-defined structs.
+ *
+ * AVChannelLayout can be initialized as follows:
+ * - default initialization with {0}, followed by by setting all used fields
+ *   correctly;
+ * - by assigning one of the predefined AV_CHANNEL_LAYOUT_* initializers;
+ * - with a constructor function, such as av_channel_layout_default(),
+ *   av_channel_layout_from_mask() or av_channel_layout_from_string().
+ *
+ * The channel layout must be unitialized with av_channel_layout_uninit()
+ *
+ * Copying an AVChannelLayout via assigning is forbidden,
+ * av_channel_layout_copy() must be used. instead (and its return value should
+ * be checked)
+ *
+ * No new fields may be added to it without a major version bump, except for
+ * new elements of the union fitting in sizeof(uint64_t).
+ */
+typedef struct AVChannelLayout {
+    /**
+     * Channel order used in this layout.
+     * This is a mandatory field.
+     */
+    enum AVChannelOrder order;
+
+    /**
+     * Number of channels in this layout. Mandatory field.
+     */
+    int nb_channels;
+
+    /**
+     * Details about which channels are present in this layout.
+     * For AV_CHANNEL_ORDER_UNSPEC, this field is undefined and must not be
+     * used.
+     */
+    union {
+        /**
+         * This member must be used for AV_CHANNEL_ORDER_NATIVE.
+         * It is a bitmask, where the position of each set bit means that the
+         * AVChannel with the corresponding value is present.
+         *
+         * I.e. when (mask & (1 << AV_CHAN_FOO)) is non-zero, then AV_CHAN_FOO
+         * is present in the layout. Otherwise it is not present.
+         *
+         * @note when a channel layout using a bitmask is constructed or
+         * modified manually (i.e.  not using any of the av_channel_layout_*
+         * functions), the code doing it must ensure that the number of set bits
+         * is equal to nb_channels.
+         */
+        uint64_t mask;
+        /**
+         * This member must be used when the channel order is
+         * AV_CHANNEL_ORDER_CUSTOM. It is a nb_channels-sized array, with each
+         * element signalling the presence of the AVChannel with the
+         * corresponding value in map[i].id.
+         *
+         * I.e. when map[i].id is equal to AV_CHAN_FOO, then AV_CH_FOO is the
+         * i-th channel in the audio data.
+         *
+         * map[i].name may be filled with a 0-terminated string, in which case
+         * it will be used for the purpose of identifying the channel with the
+         * convenience functions below. Otherise it must be zeroed.
+         */
+        AVChannelCustom *map;
+    } u;
+
+    /**
+     * For some private data of the user.
+     */
+    void *opaque;
+} AVChannelLayout;
+
+#define AV_CHANNEL_LAYOUT_MONO \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 1,  .u = { .mask = AV_CH_LAYOUT_MONO }}
+#define AV_CHANNEL_LAYOUT_STEREO \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 2,  .u = { .mask = AV_CH_LAYOUT_STEREO }}
+#define AV_CHANNEL_LAYOUT_2POINT1 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 3,  .u = { .mask = AV_CH_LAYOUT_2POINT1 }}
+#define AV_CHANNEL_LAYOUT_2_1 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 3,  .u = { .mask = AV_CH_LAYOUT_2_1 }}
+#define AV_CHANNEL_LAYOUT_SURROUND \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 3,  .u = { .mask = AV_CH_LAYOUT_SURROUND }}
+#define AV_CHANNEL_LAYOUT_3POINT1 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 4,  .u = { .mask = AV_CH_LAYOUT_3POINT1 }}
+#define AV_CHANNEL_LAYOUT_4POINT0 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 4,  .u = { .mask = AV_CH_LAYOUT_4POINT0 }}
+#define AV_CHANNEL_LAYOUT_4POINT1 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 5,  .u = { .mask = AV_CH_LAYOUT_4POINT1 }}
+#define AV_CHANNEL_LAYOUT_2_2 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 4,  .u = { .mask = AV_CH_LAYOUT_2_2 }}
+#define AV_CHANNEL_LAYOUT_QUAD \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 4,  .u = { .mask = AV_CH_LAYOUT_QUAD }}
+#define AV_CHANNEL_LAYOUT_5POINT0 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 5,  .u = { .mask = AV_CH_LAYOUT_5POINT0 }}
+#define AV_CHANNEL_LAYOUT_5POINT1 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 6,  .u = { .mask = AV_CH_LAYOUT_5POINT1 }}
+#define AV_CHANNEL_LAYOUT_5POINT0_BACK \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 5,  .u = { .mask = AV_CH_LAYOUT_5POINT0_BACK }}
+#define AV_CHANNEL_LAYOUT_5POINT1_BACK \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 6,  .u = { .mask = AV_CH_LAYOUT_5POINT1_BACK }}
+#define AV_CHANNEL_LAYOUT_6POINT0 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 6,  .u = { .mask = AV_CH_LAYOUT_6POINT0 }}
+#define AV_CHANNEL_LAYOUT_6POINT0_FRONT \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 6,  .u = { .mask = AV_CH_LAYOUT_6POINT0_FRONT }}
+#define AV_CHANNEL_LAYOUT_HEXAGONAL \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 6,  .u = { .mask = AV_CH_LAYOUT_HEXAGONAL }}
+#define AV_CHANNEL_LAYOUT_6POINT1 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 7,  .u = { .mask = AV_CH_LAYOUT_6POINT1 }}
+#define AV_CHANNEL_LAYOUT_6POINT1_BACK \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 7,  .u = { .mask = AV_CH_LAYOUT_6POINT1_BACK }}
+#define AV_CHANNEL_LAYOUT_6POINT1_FRONT \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 7,  .u = { .mask = AV_CH_LAYOUT_6POINT1_FRONT }}
+#define AV_CHANNEL_LAYOUT_7POINT0 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 7,  .u = { .mask = AV_CH_LAYOUT_7POINT0 }}
+#define AV_CHANNEL_LAYOUT_7POINT0_FRONT \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 7,  .u = { .mask = AV_CH_LAYOUT_7POINT0_FRONT }}
+#define AV_CHANNEL_LAYOUT_7POINT1 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 8,  .u = { .mask = AV_CH_LAYOUT_7POINT1 }}
+#define AV_CHANNEL_LAYOUT_7POINT1_WIDE \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 8,  .u = { .mask = AV_CH_LAYOUT_7POINT1_WIDE }}
+#define AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 8,  .u = { .mask = AV_CH_LAYOUT_7POINT1_WIDE_BACK }}
+#define AV_CHANNEL_LAYOUT_OCTAGONAL \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 8,  .u = { .mask = AV_CH_LAYOUT_OCTAGONAL }}
+#define AV_CHANNEL_LAYOUT_HEXADECAGONAL \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 16, .u = { .mask = AV_CH_LAYOUT_HEXAGONAL }}
+#define AV_CHANNEL_LAYOUT_STEREO_DOWNMIX \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 2,  .u = { .mask = AV_CH_LAYOUT_STEREO_DOWNMIX }}
+#define AV_CHANNEL_LAYOUT_22POINT2 \
+    { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 24, .u = { .mask = AV_CH_LAYOUT_22POINT2 }}
+
+struct AVBPrint;
+
+#if FF_API_OLD_CHANNEL_LAYOUT
 /**
  * Return a channel layout id that matches name, or 0 if no match is found.
  *
@@ -144,7 +379,10 @@ enum AVMatrixEncoding {
  *   AV_CH_* macros).
  *
  * Example: "stereo+FC" = "2c+FC" = "2c+1c" = "0x7"
+ *
+ * @deprecated use av_channel_layout_from_string()
  */
+attribute_deprecated
 uint64_t av_get_channel_layout(const char *name);
 
 /**
@@ -158,7 +396,9 @@ uint64_t av_get_channel_layout(const char *name);
  * @param[out] nb_channels      number of channels
  *
  * @return 0 on success, AVERROR(EINVAL) if the parsing fails.
+ * @deprecated use av_channel_layout_from_string()
  */
+attribute_deprecated
 int av_get_extended_channel_layout(const char *name, uint64_t* channel_layout, int* nb_channels);
 
 /**
@@ -167,23 +407,31 @@ int av_get_extended_channel_layout(const char *name, uint64_t* channel_layout, i
  *
  * @param buf put here the string containing the channel layout
  * @param buf_size size in bytes of the buffer
+ * @deprecated use av_channel_layout_describe()
  */
+attribute_deprecated
 void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout);
 
-struct AVBPrint;
 /**
  * Append a description of a channel layout to a bprint buffer.
+ * @deprecated use av_channel_layout_describe()
  */
+attribute_deprecated
 void av_bprint_channel_layout(struct AVBPrint *bp, int nb_channels, uint64_t channel_layout);
 
 /**
  * Return the number of channels in the channel layout.
+ * @deprecated use AVChannelLayout.nb_channels
  */
+attribute_deprecated
 int av_get_channel_layout_nb_channels(uint64_t channel_layout);
 
 /**
  * Return default channel layout for a given number of channels.
+ *
+ * @deprecated use av_channel_layout_default()
  */
+attribute_deprecated
 int64_t av_get_default_channel_layout(int nb_channels);
 
 /**
@@ -194,20 +442,28 @@ int64_t av_get_default_channel_layout(int nb_channels);
  *
  * @return index of channel in channel_layout on success, a negative AVERROR
  *         on error.
+ *
+ * @deprecated use av_channel_layout_index_from_channel()
  */
+attribute_deprecated
 int av_get_channel_layout_channel_index(uint64_t channel_layout,
                                         uint64_t channel);
 
 /**
  * Get the channel with the given index in channel_layout.
+ * @deprecated use av_channel_layout_channel_from_index()
  */
+attribute_deprecated
 uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index);
 
 /**
  * Get the name of a given channel.
  *
  * @return channel name on success, NULL on error.
+ *
+ * @deprecated use av_channel_name()
  */
+attribute_deprecated
 const char *av_get_channel_name(uint64_t channel);
 
 /**
@@ -215,7 +471,9 @@ const char *av_get_channel_name(uint64_t channel);
  *
  * @param channel  a channel layout with a single channel
  * @return  channel description on success, NULL on error
+ * @deprecated use av_channel_description()
  */
+attribute_deprecated
 const char *av_get_channel_description(uint64_t channel);
 
 /**
@@ -226,9 +484,229 @@ const char *av_get_channel_description(uint64_t channel);
  * @param[out] name    name of the layout
  * @return  0  if the layout exists,
  *          <0 if index is beyond the limits
+ * @deprecated use av_channel_layout_standard()
  */
+attribute_deprecated
 int av_get_standard_channel_layout(unsigned index, uint64_t *layout,
                                    const char **name);
+#endif
+
+/**
+ * Get a human readable string in an abbreviated form describing a given channel,
+ * or "?" if not found.
+ * This is the inverse function of @ref av_channel_from_string().
+ *
+ * @param buf pre-allocated buffer where to put the generated string
+ * @param buf_size size in bytes of the buffer.
+ * @return amount of bytes needed to hold the output string, or a negative AVERROR
+ *         on failure. If the returned value is bigger than buf_size, then the
+ *         string was truncated.
+ */
+int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel);
+
+/**
+ * bprint variant of av_channel_name().
+ */
+void av_channel_name_bprint(struct AVBPrint *bp, enum AVChannel channel_id);
+
+/**
+ * Get a human readable string describing a given channel, or "?" if not found.
+ *
+ * @param buf pre-allocated buffer where to put the generated string
+ * @param buf_size size in bytes of the buffer.
+ * @return amount of bytes needed to hold the output string, or a negative AVERROR
+ *         on failure. If the returned value is bigger than buf_size, then the
+ *         string was truncated.
+ */
+int av_channel_description(char *buf, size_t buf_size, enum AVChannel channel);
+
+/**
+ * bprint variant of av_channel_description().
+ */
+void av_channel_description_bprint(struct AVBPrint *bp, enum AVChannel channel_id);
+
+/**
+ * This is the inverse function of @ref av_channel_name().
+ *
+ * @return the channel with the given name
+ *         AV_CHAN_NONE when name does not identify a known channel
+ */
+enum AVChannel av_channel_from_string(const char *name);
+
+/**
+ * Initialize a native channel layout from a bitmask indicating which channels
+ * are present.
+ *
+ * @param channel_layout the layout structure to be initialized
+ * @param mask bitmask describing the channel layout
+ *
+ * @return 0 on success
+ *         AVERROR(EINVAL) for invalid mask values
+ */
+int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask);
+
+/**
+ * Initialize a channel layout from a given string description.
+ * The input string can be represented by:
+ *  - the formal channel layout name (returned by av_channel_layout_describe())
+ *  - single or multiple channel names (returned by av_channel_name()
+ *    or concatenated with "+")
+ *  - a hexadecimal value of a channel layout (eg. "0x4")
+ *  - the number of channels with default layout (eg. "5c")
+ *  - the number of unordered channels (eg. "4", "4C", or "4 channels")
+ *
+ * @param channel_layout input channel layout
+ * @param str string describing the channel layout
+ * @return 0 channel layout was detected, AVERROR_INVALIDATATA otherwise
+ */
+int av_channel_layout_from_string(AVChannelLayout *channel_layout,
+                                  const char *str);
+
+/**
+ * Get the default channel layout for a given number of channels.
+ *
+ * @param channel_layout the layout structure to be initialized
+ * @param nb_channels number of channels
+ */
+void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels);
+
+/**
+ * Iterate over all standard channel layouts.
+ *
+ * @param opaque a pointer where libavutil will store the iteration state. Must
+ *               point to NULL to start the iteration.
+ *
+ * @return the standard channel layout or NULL when the iteration is
+ *         finished
+ */
+const AVChannelLayout *av_channel_layout_standard(void **opaque);
+
+/**
+ * Free any allocated data in the channel layout and reset the channel
+ * count to 0.
+ *
+ * @param channel_layout the layout structure to be uninitialized
+ */
+void av_channel_layout_uninit(AVChannelLayout *channel_layout);
+
+/**
+ * Make a copy of a channel layout. This differs from just assigning src to dst
+ * in that it allocates and copies the map for AV_CHANNEL_ORDER_CUSTOM.
+ *
+ * @note the destination channel_layout will be always uninitialized before copy.
+ *
+ * @param dst destination channel layout
+ * @param src source channel layout
+ * @return 0 on success, a negative AVERROR on error.
+ */
+int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src);
+
+/**
+ * Get a human-readable string describing the channel layout properties.
+ * The string will be in the same format that is accepted by
+ * @ref av_channel_layout_from_string().
+ *
+ * @param channel_layout channel layout to be described
+ * @param buf pre-allocated buffer where to put the generated string
+ * @param buf_size size in bytes of the buffer.
+ * @return amount of bytes needed to hold the output string, or a negative AVERROR
+ *         on failure. If the returned value is bigger than buf_size, then the
+ *         string was truncated.
+ */
+int av_channel_layout_describe(const AVChannelLayout *channel_layout,
+                               char *buf, size_t buf_size);
+
+/**
+ * bprint variant of av_channel_layout_describe().
+ *
+ * @return 0 on success, or a negative AVERROR value on failure.
+ */
+int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout,
+                                      struct AVBPrint *bp);
+
+/**
+ * Get the channel with the given index in a channel layout.
+ *
+ * @param channel_layout input channel layout
+ * @return channel with the index idx in channel_layout on success or
+ *         AV_CHAN_NONE on failure (if idx is not valid or the channel order is
+ *         unspecified)
+ */
+enum AVChannel
+av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx);
+
+/**
+ * Get the index of a given channel in a channel layout. In case multiple
+ * channels are found, only the first match will be returned.
+ *
+ * @param channel_layout input channel layout
+ * @return index of channel in channel_layout on success or a negative number if
+ *         channel is not present in channel_layout.
+ */
+int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout,
+                                         enum AVChannel channel);
+
+/**
+ * Get the index in a channel layout of a channel described by the given string.
+ * In case multiple channels are found, only the first match will be returned.
+ *
+ * This function accepts channel names in the same format as
+ * @ref av_channel_from_string().
+ *
+ * @param channel_layout input channel layout
+ * @return a channel index described by the given string, or a negative AVERROR
+ *         value.
+ */
+int av_channel_layout_index_from_string(const AVChannelLayout *channel_layout,
+                                        const char *name);
+
+/**
+ * Get a channel described by the given string.
+ *
+ * This function accepts channel names in the same format as
+ * @ref av_channel_from_string().
+ *
+ * @param channel_layout input channel layout
+ * @return a channel described by the given string, or a negative AVERROR value.
+ */
+int av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout,
+                                          const char *name);
+
+/**
+ * Find out what channels from a given set are present in a channel layout,
+ * without regard for their positions.
+ *
+ * @param channel_layout input channel layout
+ * @param mask a combination of AV_CH_* representing a set of channels
+ * @return a bitfield representing all the channels from mask that are present
+ *         in channel_layout
+ */
+uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout,
+                                  uint64_t mask);
+
+/**
+ * Check whether a channel layout is valid, i.e. can possibly describe audio
+ * data.
+ *
+ * @param channel_layout input channel layout
+ * @return 1 if channel_layout is valid, 0 otherwise.
+ */
+int av_channel_layout_check(const AVChannelLayout *channel_layout);
+
+/**
+ * Check whether two channel layouts are semantically the same, i.e. the same
+ * channels are present on the same positions in both.
+ *
+ * If one of the channel layouts is AV_CHANNEL_ORDER_UNSPEC, while the other is
+ * not, they are considered to be unequal. If both are AV_CHANNEL_ORDER_UNSPEC,
+ * they are considered equal iff the channel counts are the same in both.
+ *
+ * @param chl input channel layout
+ * @param chl1 input channel layout
+ * @return 0 if chl and chl1 are equal, 1 if they are not equal. A negative
+ *         AVERROR code if one or both are invalid.
+ */
+int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1);
 
 /**
  * @}
diff --git a/libavutil/version.h b/libavutil/version.h
index 953aac9d94..4da667b923 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -110,6 +110,7 @@
 #define FF_API_COLORSPACE_NAME          (LIBAVUTIL_VERSION_MAJOR < 58)
 #define FF_API_AV_MALLOCZ_ARRAY         (LIBAVUTIL_VERSION_MAJOR < 58)
 #define FF_API_FIFO_PEEK2               (LIBAVUTIL_VERSION_MAJOR < 58)
+#define FF_API_OLD_CHANNEL_LAYOUT       (LIBAVUTIL_VERSION_MAJOR < 58)
 
 /**
  * @}
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 002/281] fate: add a channel_layout API test
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 001/281] Add a new " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 003/281] lavu: support AVChannelLayout AVOptions James Almer
                   ` (280 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/Makefile               |   1 +
 libavutil/tests/channel_layout.c | 233 +++++++++++++++++++++++++++++++
 tests/fate/libavutil.mak         |   4 +
 tests/ref/fate/channel_layout    |  98 +++++++++++++
 4 files changed, 336 insertions(+)
 create mode 100644 libavutil/tests/channel_layout.c
 create mode 100644 tests/ref/fate/channel_layout

diff --git a/libavutil/Makefile b/libavutil/Makefile
index d17876df1a..8e14d4cf3d 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -220,6 +220,7 @@ TESTPROGS = adler32                                                     \
             bprint                                                      \
             cast5                                                       \
             camellia                                                    \
+            channel_layout                                              \
             color_utils                                                 \
             cpu                                                         \
             crc                                                         \
diff --git a/libavutil/tests/channel_layout.c b/libavutil/tests/channel_layout.c
new file mode 100644
index 0000000000..7e6be0be17
--- /dev/null
+++ b/libavutil/tests/channel_layout.c
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 2021 James Almer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/channel_layout.c"
+
+#define CHANNEL_LAYOUT_FROM_MASK(layout, x)                                \
+    av_channel_layout_uninit(&layout);                                     \
+    if (!av_channel_layout_from_mask(&layout, x))                          \
+        av_channel_layout_describe_bprint(&layout, &bp);
+
+#define CHANNEL_LAYOUT_FROM_STRING(layout, x)                              \
+    av_channel_layout_uninit(&layout);                                     \
+    if (!av_channel_layout_from_string(&layout, x))                        \
+        av_channel_layout_describe_bprint(&layout, &bp);
+
+#define CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(layout, x)                       \
+    ret = av_channel_layout_channel_from_index(&layout, x);                \
+    if (ret < 0)                                                           \
+        ret = -1
+
+#define CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(layout, x)                       \
+    ret = av_channel_layout_index_from_channel(&layout, x);                \
+    if (ret < 0)                                                           \
+        ret = -1
+
+#define CHANNEL_LAYOUT_CHANNEL_FROM_STRING(layout, x)                      \
+    ret = av_channel_layout_channel_from_string(&layout, x);               \
+    if (ret < 0)                                                           \
+        ret = -1
+
+#define CHANNEL_LAYOUT_INDEX_FROM_STRING(layout, x)                        \
+    ret = av_channel_layout_index_from_string(&layout, x);                 \
+    if (ret < 0)                                                           \
+        ret = -1
+
+int main(void)
+{
+    AVChannelLayout surround = { 0 };
+    AVChannelLayout custom = { 0 };
+    AVBPrint bp;
+    int ret;
+
+    av_bprint_init(&bp, 64, AV_BPRINT_SIZE_AUTOMATIC);
+
+    printf("Testing av_channel_name\n");
+    av_channel_name_bprint(&bp, AV_CHAN_FRONT_LEFT);
+    printf("With AV_CHAN_FRONT_LEFT: %27s\n", bp.str);
+    av_channel_name_bprint(&bp, AV_CHAN_FRONT_RIGHT);
+    printf("With AV_CHAN_FRONT_RIGHT: %26s\n", bp.str);
+    av_channel_name_bprint(&bp, 63);
+    printf("With 63: %43s\n", bp.str);
+
+    printf("Testing av_channel_description\n");
+    av_channel_description_bprint(&bp, AV_CHAN_FRONT_LEFT);
+    printf("With AV_CHAN_FRONT_LEFT: %27s\n", bp.str);
+    av_channel_description_bprint(&bp, AV_CHAN_FRONT_RIGHT);
+    printf("With AV_CHAN_FRONT_RIGHT: %26s\n", bp.str);
+    av_channel_description_bprint(&bp, 63);
+    printf("With 63: %43s\n", bp.str);
+
+    printf("\nTesting av_channel_from_string\n");
+    printf("With \"FL\": %41d\n", av_channel_from_string("FL"));
+    printf("With \"FR\": %41d\n", av_channel_from_string("FR"));
+    printf("With \"USR63\": %38d\n", av_channel_from_string("USR63"));
+
+    printf("\n==Native layouts==\n");
+
+    printf("\nTesting av_channel_layout_from_string\n");
+    CHANNEL_LAYOUT_FROM_STRING(surround, "0x3f");
+    printf("With \"0x3f\": %39s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(surround, "6c");
+    printf("With \"6c\": %41s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(surround, "6C");
+    printf("With \"6C\": %41s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(surround, "6");
+    printf("With \"6\": %42s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(surround, "6 channels");
+    printf("With \"6 channels\": %33s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(surround, "FL+FR+FC+LFE+BL+BR");
+    printf("With \"FL+FR+FC+LFE+BL+BR\": %25s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(surround, "5.1");
+    printf("With \"5.1\": %40s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(surround, "FL+FR+USR63");
+    printf("With \"FL+FR+USR63\": %32s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(surround, "FL+FR+FC+LFE+SL+SR");
+    printf("With \"FL+FR+FC+LFE+SL+SR\": %25s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(surround, "5.1(side)");
+    printf("With \"5.1(side)\": %34s\n", bp.str);
+
+    printf("\nTesting av_channel_layout_from_mask\n");
+    CHANNEL_LAYOUT_FROM_MASK(surround, AV_CH_LAYOUT_5POINT1);
+    printf("With AV_CH_LAYOUT_5POINT1: %25s\n", bp.str);
+
+    printf("\nTesting av_channel_layout_channel_from_index\n");
+    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 0);
+    printf("On 5.1(side) layout with 0: %24d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 1);
+    printf("On 5.1(side) layout with 1: %24d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 2);
+    printf("On 5.1(side) layout with 2: %24d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 3);
+    printf("On 5.1(side) layout with 3: %24d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 4);
+    printf("On 5.1(side) layout with 4: %24d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 5);
+    printf("On 5.1(side) layout with 5: %24d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(surround, 6);
+    printf("On 5.1(side) layout with 6: %24d\n", ret);
+
+    printf("\nTesting av_channel_layout_index_from_channel\n");
+    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_FRONT_LEFT);
+    printf("On 5.1(side) layout with AV_CHAN_FRONT_LEFT: %7d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_FRONT_RIGHT);
+    printf("On 5.1(side) layout with AV_CHAN_FRONT_RIGHT: %6d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_FRONT_CENTER);
+    printf("On 5.1(side) layout with AV_CHAN_FRONT_CENTER: %5d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_LOW_FREQUENCY);
+    printf("On 5.1(side) layout with AV_CHAN_LOW_FREQUENCY: %4d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_SIDE_LEFT);
+    printf("On 5.1(side) layout with AV_CHAN_SIDE_LEFT: %8d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_SIDE_RIGHT);
+    printf("On 5.1(side) layout with AV_CHAN_SIDE_RIGHT: %7d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(surround, AV_CHAN_BACK_CENTER);
+    printf("On 5.1(side) layout with AV_CHAN_BACK_CENTER: %6d\n", ret);
+
+    printf("\nTesting av_channel_layout_channel_from_string\n");
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "FL");
+    printf("On 5.1(side) layout with \"FL\": %21d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "FR");
+    printf("On 5.1(side) layout with \"FR\": %21d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "FC");
+    printf("On 5.1(side) layout with \"FC\": %21d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "LFE");
+    printf("On 5.1(side) layout with \"LFE\": %20d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "SL");
+    printf("On 5.1(side) layout with \"SL\": %21d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "SR");
+    printf("On 5.1(side) layout with \"SR\": %21d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(surround, "BC");
+    printf("On 5.1(side) layout with \"BC\": %21d\n", ret);
+
+    printf("\nTesting av_channel_layout_index_from_string\n");
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "FL");
+    printf("On 5.1(side) layout with \"FL\": %21d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "FR");
+    printf("On 5.1(side) layout with \"FR\": %21d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "FC");
+    printf("On 5.1(side) layout with \"FC\": %21d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "LFE");
+    printf("On 5.1(side) layout with \"LFE\": %20d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "SL");
+    printf("On 5.1(side) layout with \"SL\": %21d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "SR");
+    printf("On 5.1(side) layout with \"SR\": %21d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(surround, "BC");
+    printf("On 5.1(side) layout with \"BC\": %21d\n", ret);
+
+    printf("\n==Custom layouts==\n");
+
+    printf("\nTesting av_channel_layout_from_string\n");
+    CHANNEL_LAYOUT_FROM_STRING(custom, "FL+FR+FC+BL+BR+LFE");
+    printf("With \"FL+FR+FC+BL+BR+LFE\": %25s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(custom, "FR+FL+USR63");
+    printf("With \"FR+FL+USR63\" layout: %25s\n", bp.str);
+
+    av_strlcpy(custom.u.map[2].name, "CUS", sizeof(custom.u.map[2].name));
+    printf("\nTesting av_channel_layout_index_from_string\n");
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(custom, "FR");
+    printf("On \"FR+FL+USR63\" layout with \"FR\": %17d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(custom, "FL");
+    printf("On \"FR+FL+USR63\" layout with \"FL\": %17d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(custom, "USR63");
+    printf("On \"FR+FL+USR63\" layout with \"USR63\": %14d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(custom, "CUS");
+    printf("On \"FR+FL+USR63\" layout with custom label \"CUS\": %3d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_STRING(custom, "BC");
+    printf("On \"FR+FL+USR63\" layout with \"BC\": %17d\n", ret);
+
+    printf("\nTesting av_channel_layout_channel_from_string\n");
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(custom, "FR");
+    printf("On \"FR+FL+USR63\" layout with \"FR\": %17d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(custom, "FL");
+    printf("On \"FR+FL+USR63\" layout with \"FL\": %17d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(custom, "USR63");
+    printf("On \"FR+FL+USR63\" layout with \"USR63\": %14d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(custom, "CUS");
+    printf("On \"FR+FL+USR63\" layout with custom label \"CUS\": %3d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_STRING(custom, "BC");
+    printf("On \"FR+FL+USR63\" layout with \"BC\": %17d\n", ret);
+
+    printf("\nTesting av_channel_layout_index_from_channel\n");
+    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(custom, AV_CHAN_FRONT_RIGHT);
+    printf("On \"FR+FL+USR63\" layout with AV_CHAN_FRONT_RIGHT: %2d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(custom, AV_CHAN_FRONT_LEFT);
+    printf("On \"FR+FL+USR63\" layout with AV_CHAN_FRONT_LEFT: %3d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(custom, 63);
+    printf("On \"FR+FL+USR63\" layout with 63: %19d\n", ret);
+    CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(custom, AV_CHAN_BACK_CENTER);
+    printf("On \"FR+FL+USR63\" layout with AV_CHAN_BACK_CENTER: %2d\n", ret);
+
+    printf("\nTesting av_channel_layout_channel_from_index\n");
+    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(custom, 0);
+    printf("On \"FR+FL+USR63\" layout with 0: %20d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(custom, 1);
+    printf("On \"FR+FL+USR63\" layout with 1: %20d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(custom, 2);
+    printf("On \"FR+FL+USR63\" layout with 2: %20d\n", ret);
+    CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(custom, 3);
+    printf("On \"FR+FL+USR63\" layout with 3: %20d\n", ret);
+
+    av_channel_layout_uninit(&surround);
+    av_channel_layout_uninit(&custom);
+    av_bprint_finalize(&bp, NULL);
+
+    return 0;
+}
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index 1ec9ed00ad..c32cf2e706 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -23,6 +23,10 @@ fate-cast5: libavutil/tests/cast5$(EXESUF)
 fate-cast5: CMD = run libavutil/tests/cast5$(EXESUF)
 fate-cast5: CMP = null
 
+FATE_LIBAVUTIL += fate-channel_layout
+fate-channel_layout: libavutil/tests/channel_layout$(EXESUF)
+fate-channel_layout: CMD = run libavutil/tests/channel_layout$(EXESUF)
+
 FATE_LIBAVUTIL += fate-audio_fifo
 fate-audio_fifo: libavutil/tests/audio_fifo$(EXESUF)
 fate-audio_fifo: CMD = run libavutil/tests/audio_fifo$(EXESUF)
diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout
new file mode 100644
index 0000000000..bac00086d6
--- /dev/null
+++ b/tests/ref/fate/channel_layout
@@ -0,0 +1,98 @@
+Testing av_channel_name
+With AV_CHAN_FRONT_LEFT:                          FL
+With AV_CHAN_FRONT_RIGHT:                         FR
+With 63:                                       USR63
+Testing av_channel_description
+With AV_CHAN_FRONT_LEFT:                  front left
+With AV_CHAN_FRONT_RIGHT:                front right
+With 63:                                     user 63
+
+Testing av_channel_from_string
+With "FL":                                         0
+With "FR":                                         1
+With "USR63":                                     63
+
+==Native layouts==
+
+Testing av_channel_layout_from_string
+With "0x3f":                                     5.1
+With "6c":                                       5.1
+With "6C":                                6 channels
+With "6":                                 6 channels
+With "6 channels":                        6 channels
+With "FL+FR+FC+LFE+BL+BR":                       5.1
+With "5.1":                                      5.1
+With "FL+FR+USR63":                      FL+FR+USR63
+With "FL+FR+FC+LFE+SL+SR":                 5.1(side)
+With "5.1(side)":                          5.1(side)
+
+Testing av_channel_layout_from_mask
+With AV_CH_LAYOUT_5POINT1:                 5.1(side)
+
+Testing av_channel_layout_channel_from_index
+On 5.1(side) layout with 0:                        0
+On 5.1(side) layout with 1:                        1
+On 5.1(side) layout with 2:                        2
+On 5.1(side) layout with 3:                        3
+On 5.1(side) layout with 4:                        9
+On 5.1(side) layout with 5:                       10
+On 5.1(side) layout with 6:                       -1
+
+Testing av_channel_layout_index_from_channel
+On 5.1(side) layout with AV_CHAN_FRONT_LEFT:       0
+On 5.1(side) layout with AV_CHAN_FRONT_RIGHT:      1
+On 5.1(side) layout with AV_CHAN_FRONT_CENTER:     2
+On 5.1(side) layout with AV_CHAN_LOW_FREQUENCY:    3
+On 5.1(side) layout with AV_CHAN_SIDE_LEFT:        4
+On 5.1(side) layout with AV_CHAN_SIDE_RIGHT:       5
+On 5.1(side) layout with AV_CHAN_BACK_CENTER:     -1
+
+Testing av_channel_layout_channel_from_string
+On 5.1(side) layout with "FL":                     0
+On 5.1(side) layout with "FR":                     1
+On 5.1(side) layout with "FC":                     2
+On 5.1(side) layout with "LFE":                    3
+On 5.1(side) layout with "SL":                     9
+On 5.1(side) layout with "SR":                    10
+On 5.1(side) layout with "BC":                    -1
+
+Testing av_channel_layout_index_from_string
+On 5.1(side) layout with "FL":                     0
+On 5.1(side) layout with "FR":                     1
+On 5.1(side) layout with "FC":                     2
+On 5.1(side) layout with "LFE":                    3
+On 5.1(side) layout with "SL":                     4
+On 5.1(side) layout with "SR":                     5
+On 5.1(side) layout with "BC":                    -1
+
+==Custom layouts==
+
+Testing av_channel_layout_from_string
+With "FL+FR+FC+BL+BR+LFE":        FL+FR+FC+BL+BR+LFE
+With "FR+FL+USR63" layout:               FR+FL+USR63
+
+Testing av_channel_layout_index_from_string
+On "FR+FL+USR63" layout with "FR":                 0
+On "FR+FL+USR63" layout with "FL":                 1
+On "FR+FL+USR63" layout with "USR63":              2
+On "FR+FL+USR63" layout with custom label "CUS":   2
+On "FR+FL+USR63" layout with "BC":                -1
+
+Testing av_channel_layout_channel_from_string
+On "FR+FL+USR63" layout with "FR":                 1
+On "FR+FL+USR63" layout with "FL":                 0
+On "FR+FL+USR63" layout with "USR63":             63
+On "FR+FL+USR63" layout with custom label "CUS":  63
+On "FR+FL+USR63" layout with "BC":                -1
+
+Testing av_channel_layout_index_from_channel
+On "FR+FL+USR63" layout with AV_CHAN_FRONT_RIGHT:  0
+On "FR+FL+USR63" layout with AV_CHAN_FRONT_LEFT:   1
+On "FR+FL+USR63" layout with 63:                   2
+On "FR+FL+USR63" layout with AV_CHAN_BACK_CENTER: -1
+
+Testing av_channel_layout_channel_from_index
+On "FR+FL+USR63" layout with 0:                    1
+On "FR+FL+USR63" layout with 1:                    0
+On "FR+FL+USR63" layout with 2:                   63
+On "FR+FL+USR63" layout with 3:                   -1
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 003/281] lavu: support AVChannelLayout AVOptions
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 001/281] Add a new " James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 002/281] fate: add a channel_layout API test James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 004/281] lavc: deprecate channel count/layout changing side data James Almer
                   ` (279 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/opt.c       | 126 +++++++++++++++++++++++++++++++++++++++++-
 libavutil/opt.h       |  12 ++++
 libavutil/tests/opt.c |   8 +--
 tests/ref/fate/opt    |  16 +++---
 4 files changed, 149 insertions(+), 13 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index d951edca9d..445537fbad 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -39,6 +39,7 @@
 #include "opt.h"
 #include "samplefmt.h"
 #include "bprint.h"
+#include "version.h"
 
 #include <float.h>
 
@@ -71,7 +72,11 @@ static int read_number(const AVOption *o, const void *dst, double *num, int *den
     case AV_OPT_TYPE_INT:
         *intnum = *(int *)dst;
         return 0;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     case AV_OPT_TYPE_DURATION:
     case AV_OPT_TYPE_INT64:
     case AV_OPT_TYPE_UINT64:
@@ -126,7 +131,11 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
         *(int *)dst = llrint(num / den) * intnum;
         break;
     case AV_OPT_TYPE_DURATION:
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     case AV_OPT_TYPE_INT64:{
         double d = num / den;
         if (intnum == 1 && d == (double)INT64_MAX) {
@@ -465,6 +474,16 @@ static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_
     return 0;
 }
 
+static int set_string_channel_layout(void *obj, const AVOption *o,
+                                     const char *val, void *dst)
+{
+    AVChannelLayout *channel_layout = dst;
+    av_channel_layout_uninit(channel_layout);
+    if (!val)
+        return 0;
+    return av_channel_layout_from_string(channel_layout, val);
+}
+
 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
 {
     int ret = 0;
@@ -472,12 +491,17 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
     const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
     if (!o || !target_obj)
         return AVERROR_OPTION_NOT_FOUND;
+FF_DISABLE_DEPRECATION_WARNINGS
     if (!val && (o->type != AV_OPT_TYPE_STRING &&
                  o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_SAMPLE_FMT &&
                  o->type != AV_OPT_TYPE_IMAGE_SIZE &&
                  o->type != AV_OPT_TYPE_DURATION && o->type != AV_OPT_TYPE_COLOR &&
-                 o->type != AV_OPT_TYPE_CHANNEL_LAYOUT && o->type != AV_OPT_TYPE_BOOL))
+#if FF_API_OLD_CHANNEL_LAYOUT
+                 o->type != AV_OPT_TYPE_CHANNEL_LAYOUT &&
+#endif
+                 o->type != AV_OPT_TYPE_BOOL))
         return AVERROR(EINVAL);
+FF_ENABLE_DEPRECATION_WARNINGS
 
     if (o->flags & AV_OPT_FLAG_READONLY)
         return AVERROR(EINVAL);
@@ -533,6 +557,8 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
         }
     case AV_OPT_TYPE_COLOR:
         return set_string_color(obj, o, val, dst);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
         if (!val || !strcmp(val, "none")) {
             *(int64_t *)dst = 0;
@@ -546,6 +572,15 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
             return ret;
         }
         break;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    case AV_OPT_TYPE_CHLAYOUT:
+        ret = set_string_channel_layout(obj, o, val, dst);
+        if (ret < 0) {
+            av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val);
+            ret = AVERROR(EINVAL);
+        }
+        return ret;
     case AV_OPT_TYPE_DICT:
         return set_string_dict(obj, o, val, dst);
     }
@@ -709,6 +744,8 @@ int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt,
     return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int search_flags)
 {
     void *target_obj;
@@ -724,6 +761,8 @@ int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int searc
     *(int64_t *)(((uint8_t *)target_obj) + o->offset) = cl;
     return 0;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
                         int search_flags)
@@ -744,6 +783,22 @@ int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
     return 0;
 }
 
+int av_opt_set_chlayout(void *obj, const char *name,
+                        const AVChannelLayout *channel_layout,
+                        int search_flags)
+{
+    void *target_obj;
+    const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
+    AVChannelLayout *dst;
+
+    if (!o || !target_obj)
+        return AVERROR_OPTION_NOT_FOUND;
+
+    dst = (AVChannelLayout*)((uint8_t*)target_obj + o->offset);
+
+    return av_channel_layout_copy(dst, channel_layout);
+}
+
 static void format_duration(char *buf, size_t size, int64_t d)
 {
     char *e;
@@ -872,10 +927,18 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
                        (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
                        (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
         break;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
+
         i64 = *(int64_t *)dst;
         ret = snprintf(buf, sizeof(buf), "0x%"PRIx64, i64);
         break;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    case AV_OPT_TYPE_CHLAYOUT:
+        ret = av_channel_layout_describe(dst, buf, sizeof(buf));
+        break;
     case AV_OPT_TYPE_DICT:
         if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
             *out_val = NULL;
@@ -1017,6 +1080,8 @@ int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AV
     return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample");
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int64_t *cl)
 {
     void *dst, *target_obj;
@@ -1033,6 +1098,24 @@ int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int
     *cl = *(int64_t *)dst;
     return 0;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
+{
+    void *dst, *target_obj;
+    const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
+    if (!o || !target_obj)
+        return AVERROR_OPTION_NOT_FOUND;
+    if (o->type != AV_OPT_TYPE_CHLAYOUT) {
+        av_log(obj, AV_LOG_ERROR,
+               "The value for option '%s' is not a channel layout.\n", name);
+        return AVERROR(EINVAL);
+    }
+
+    dst = ((uint8_t*)target_obj) + o->offset;
+    return av_channel_layout_copy(cl, dst);
+}
 
 int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
 {
@@ -1225,7 +1308,12 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
             case AV_OPT_TYPE_COLOR:
                 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<color>");
                 break;
+            case AV_OPT_TYPE_CHLAYOUT:
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             case AV_OPT_TYPE_CHANNEL_LAYOUT:
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
                 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<channel_layout>");
                 break;
             case AV_OPT_TYPE_BOOL:
@@ -1282,6 +1370,7 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
                    opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
                    opt->type == AV_OPT_TYPE_STRING     ||
                    opt->type == AV_OPT_TYPE_DICT       ||
+                   opt->type == AV_OPT_TYPE_CHLAYOUT   ||
                    opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
                   !opt->default_val.str)) {
             av_log(av_log_obj, AV_LOG_INFO, " (default ");
@@ -1334,11 +1423,16 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
             case AV_OPT_TYPE_STRING:
             case AV_OPT_TYPE_DICT:
             case AV_OPT_TYPE_VIDEO_RATE:
+            case AV_OPT_TYPE_CHLAYOUT:
                 av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
                 break;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             case AV_OPT_TYPE_CHANNEL_LAYOUT:
                 av_log(av_log_obj, AV_LOG_INFO, "0x%"PRIx64, opt->default_val.i64);
                 break;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             }
             av_log(av_log_obj, AV_LOG_INFO, ")");
         }
@@ -1388,7 +1482,11 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
             case AV_OPT_TYPE_INT64:
             case AV_OPT_TYPE_UINT64:
             case AV_OPT_TYPE_DURATION:
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             case AV_OPT_TYPE_CHANNEL_LAYOUT:
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             case AV_OPT_TYPE_PIXEL_FMT:
             case AV_OPT_TYPE_SAMPLE_FMT:
                 write_number(s, opt, dst, 1, 1, opt->default_val.i64);
@@ -1421,6 +1519,9 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
             case AV_OPT_TYPE_BINARY:
                 set_string_binary(s, opt, opt->default_val.str, dst);
                 break;
+            case AV_OPT_TYPE_CHLAYOUT:
+                set_string_channel_layout(s, opt, opt->default_val.str, dst);
+                break;
             case AV_OPT_TYPE_DICT:
                 set_string_dict(s, opt, opt->default_val.str, dst);
                 break;
@@ -1745,7 +1846,11 @@ static int opt_size(enum AVOptionType type)
     case AV_OPT_TYPE_FLAGS:
         return sizeof(int);
     case AV_OPT_TYPE_DURATION:
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     case AV_OPT_TYPE_INT64:
     case AV_OPT_TYPE_UINT64:
         return sizeof(int64_t);
@@ -1819,6 +1924,9 @@ int av_opt_copy(void *dst, const void *src)
             ret2 = av_dict_copy(ddict, *sdict, 0);
             if (ret2 < 0)
                 ret = ret2;
+        } else if (o->type == AV_OPT_TYPE_CHLAYOUT) {
+            if (field_dst != field_src)
+                ret = av_channel_layout_copy(field_dst, field_src);
         } else {
             int size = opt_size(o->type);
             if (size < 0)
@@ -1882,7 +1990,11 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch
     case AV_OPT_TYPE_DOUBLE:
     case AV_OPT_TYPE_DURATION:
     case AV_OPT_TYPE_COLOR:
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         break;
     case AV_OPT_TYPE_STRING:
         range->component_min = 0;
@@ -1962,12 +2074,24 @@ int av_opt_is_set_to_default(void *obj, const AVOption *o)
     case AV_OPT_TYPE_PIXEL_FMT:
     case AV_OPT_TYPE_SAMPLE_FMT:
     case AV_OPT_TYPE_INT:
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     case AV_OPT_TYPE_CHANNEL_LAYOUT:
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     case AV_OPT_TYPE_DURATION:
     case AV_OPT_TYPE_INT64:
     case AV_OPT_TYPE_UINT64:
         read_number(o, dst, NULL, NULL, &i64);
         return o->default_val.i64 == i64;
+    case AV_OPT_TYPE_CHLAYOUT: {
+        AVChannelLayout ch_layout = { 0 };
+        if (o->default_val.str) {
+            if ((ret = av_channel_layout_from_string(&ch_layout, o->default_val.str)) < 0)
+                return ret;
+        }
+        return !av_channel_layout_compare((AVChannelLayout *)dst, &ch_layout);
+    }
     case AV_OPT_TYPE_STRING:
         str = *(char **)dst;
         if (str == o->default_val.str) //2 NULLs
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 2820435eec..461b5d3b6b 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -29,6 +29,7 @@
 
 #include "rational.h"
 #include "avutil.h"
+#include "channel_layout.h"
 #include "dict.h"
 #include "log.h"
 #include "pixfmt.h"
@@ -237,8 +238,11 @@ enum AVOptionType{
     AV_OPT_TYPE_VIDEO_RATE, ///< offset must point to AVRational
     AV_OPT_TYPE_DURATION,
     AV_OPT_TYPE_COLOR,
+#if FF_API_OLD_CHANNEL_LAYOUT
     AV_OPT_TYPE_CHANNEL_LAYOUT,
+#endif
     AV_OPT_TYPE_BOOL,
+    AV_OPT_TYPE_CHLAYOUT,
 };
 
 /**
@@ -693,7 +697,11 @@ int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_
 int av_opt_set_pixel_fmt (void *obj, const char *name, enum AVPixelFormat fmt, int search_flags);
 int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags);
 int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags);
+#if FF_API_OLD_CHANNEL_LAYOUT
+attribute_deprecated
 int av_opt_set_channel_layout(void *obj, const char *name, int64_t ch_layout, int search_flags);
+#endif
+int av_opt_set_chlayout(void *obj, const char *name, const AVChannelLayout *layout, int search_flags);
 /**
  * @note Any old dictionary present is discarded and replaced with a copy of the new one. The
  * caller still owns val is and responsible for freeing it.
@@ -748,7 +756,11 @@ int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_
 int av_opt_get_pixel_fmt (void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt);
 int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt);
 int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val);
+#if FF_API_OLD_CHANNEL_LAYOUT
+attribute_deprecated
 int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int64_t *ch_layout);
+#endif
+int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *layout);
 /**
  * @param[out] out_val The returned dictionary is a copy of the actual value and must
  * be freed with av_dict_free() by the caller
diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
index e6ea892373..5799e45c6a 100644
--- a/libavutil/tests/opt.c
+++ b/libavutil/tests/opt.c
@@ -41,7 +41,7 @@ typedef struct TestContext {
     enum AVSampleFormat sample_fmt;
     int64_t duration;
     uint8_t color[4];
-    int64_t channel_layout;
+    AVChannelLayout channel_layout;
     void *binary;
     int binary_size;
     void *binary1;
@@ -81,7 +81,7 @@ static const AVOption test_options[]= {
     {"video_rate", "set videorate",      OFFSET(video_rate),     AV_OPT_TYPE_VIDEO_RATE,     { .str = "25" },                   0,         INT_MAX, 1 },
     {"duration",   "set duration",       OFFSET(duration),       AV_OPT_TYPE_DURATION,       { .i64 = 1000 },                   0, INT64_MAX, 1 },
     {"color",      "set color",          OFFSET(color),          AV_OPT_TYPE_COLOR,          { .str = "pink" },                 0,         0, 1 },
-    {"cl",         "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, { .i64 = AV_CH_LAYOUT_HEXAGONAL }, 0, INT64_MAX, 1 },
+    {"cl",         "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHLAYOUT,       { .str = "hexagonal" },            0,         0, 1 },
     {"bin",        "set binary value",   OFFSET(binary),         AV_OPT_TYPE_BINARY,         { .str="62696e00" },               0,         0, 1 },
     {"bin1",       "set binary value",   OFFSET(binary1),        AV_OPT_TYPE_BINARY,         { .str=NULL },                     0,         0, 1 },
     {"bin2",       "set binary value",   OFFSET(binary2),        AV_OPT_TYPE_BINARY,         { .str="" },                       0,         0, 1 },
@@ -138,7 +138,7 @@ int main(void)
         printf("sample_fmt=%s\n", av_get_sample_fmt_name(test_ctx.sample_fmt));
         printf("duration=%"PRId64"\n", test_ctx.duration);
         printf("color=%d %d %d %d\n", test_ctx.color[0], test_ctx.color[1], test_ctx.color[2], test_ctx.color[3]);
-        printf("channel_layout=%"PRId64"=%"PRId64"\n", test_ctx.channel_layout, (int64_t)AV_CH_LAYOUT_HEXAGONAL);
+        printf("channel_layout=%"PRId64"=%"PRId64"\n", test_ctx.channel_layout.u.mask, (int64_t)AV_CH_LAYOUT_HEXAGONAL);
         if (test_ctx.binary)
             printf("binary=%x %x %x %x\n", ((uint8_t*)test_ctx.binary)[0], ((uint8_t*)test_ctx.binary)[1], ((uint8_t*)test_ctx.binary)[2], ((uint8_t*)test_ctx.binary)[3]);
         printf("binary_size=%d\n", test_ctx.binary_size);
@@ -280,7 +280,7 @@ int main(void)
             "color=blue",
             "color=0x223300",
             "color=0x42FF07AA",
-            "cl=stereo+downmix",
+            "cl=FL+FR",
             "cl=foo",
             "bin=boguss",
             "bin=111",
diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt
index aac3fa0e7e..832f9cc8a9 100644
--- a/tests/ref/fate/opt
+++ b/tests/ref/fate/opt
@@ -33,7 +33,7 @@ TestContext AVOptions:
   -video_rate        <video_rate> E.......... set videorate (default "25")
   -duration          <duration>   E.......... set duration (default 0.001)
   -color             <color>      E.......... set color (default "pink")
-  -cl                <channel_layout> E.......... set channel layout (default 0x137)
+  -cl                <channel_layout> E.......... set channel layout (default "hexagonal")
   -bin               <binary>     E.......... set binary value
   -bin1              <binary>     E.......... set binary value
   -bin2              <binary>     E.......... set binary value
@@ -115,7 +115,7 @@ name: sample_fmt  get: s16              set: OK               get: s16
 name: video_rate  get: 25/1             set: OK               get: 25/1             OK
 name: duration    get: 0.001            set: OK               get: 0.001            OK
 name: color       get: 0xffc0cbff       set: OK               get: 0xffc0cbff       OK
-name: cl          get: 0x137            set: OK               get: 0x137            OK
+name: cl          get: hexagonal        set: OK               get: hexagonal        OK
 name: bin         get: 62696E00         set: OK               get: 62696E00         OK
 name: bin1        get:                  set: OK               get:                  OK
 name: bin2        get:                  set: OK               get:                  OK
@@ -129,7 +129,7 @@ name: dict1       get:                  set: OK               get:
 name: dict2       get: happy=\:-)       set: OK               get: happy=\:-)       OK
 
 Test av_opt_serialize()
-num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=0x137,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
+num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
 Setting entry with key 'num' to value '0'
 Setting entry with key 'toggle' to value '1'
 Setting entry with key 'rational' to value '1/1'
@@ -142,7 +142,7 @@ Setting entry with key 'sample_fmt' to value 's16'
 Setting entry with key 'video_rate' to value '25/1'
 Setting entry with key 'duration' to value '0.001'
 Setting entry with key 'color' to value '0xffc0cbff'
-Setting entry with key 'cl' to value '0x137'
+Setting entry with key 'cl' to value 'hexagonal'
 Setting entry with key 'bin' to value '62696E00'
 Setting entry with key 'bin1' to value ''
 Setting entry with key 'bin2' to value ''
@@ -154,7 +154,7 @@ Setting entry with key 'bool2' to value 'true'
 Setting entry with key 'bool3' to value 'false'
 Setting entry with key 'dict1' to value ''
 Setting entry with key 'dict2' to value 'happy=\:-)'
-num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=0x137,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
+num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
 
 Testing av_set_options_string()
 Setting options string ''
@@ -296,9 +296,9 @@ OK    'color=0x223300'
 Setting options string 'color=0x42FF07AA'
 Setting entry with key 'color' to value '0x42FF07AA'
 OK    'color=0x42FF07AA'
-Setting options string 'cl=stereo+downmix'
-Setting entry with key 'cl' to value 'stereo+downmix'
-OK    'cl=stereo+downmix'
+Setting options string 'cl=FL+FR'
+Setting entry with key 'cl' to value 'FL+FR'
+OK    'cl=FL+FR'
 Setting options string 'cl=foo'
 Setting entry with key 'cl' to value 'foo'
 Unable to parse option value "foo" as channel layout
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 004/281] lavc: deprecate channel count/layout changing side data
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (2 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 003/281] lavu: support AVChannelLayout AVOptions James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 005/281] avframe: switch to the new channel layout API James Almer
                   ` (278 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

They are incompatible with the new channel layout scheme and no decoder
uses them.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/decode.c  | 4 ++++
 libavcodec/packet.h  | 5 +++++
 libavformat/dump.c   | 9 ++++++++-
 libavformat/nutenc.c | 2 ++
 libavformat/utils.c  | 9 +++++++++
 5 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0912f86a14..60127e95fc 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -91,6 +91,8 @@ static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
     flags = bytestream_get_le32(&data);
     size -= 4;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
         if (size < 4)
             goto fail;
@@ -109,6 +111,8 @@ static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
         avctx->channel_layout = bytestream_get_le64(&data);
         size -= 8;
     }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
         if (size < 4)
             goto fail;
diff --git a/libavcodec/packet.h b/libavcodec/packet.h
index 4a349fe051..0c3729f32c 100644
--- a/libavcodec/packet.h
+++ b/libavcodec/packet.h
@@ -447,8 +447,13 @@ typedef struct AVPacketList {
 #define AV_PKT_FLAG_DISPOSABLE 0x0010
 
 enum AVSideDataParamChangeFlags {
+#if FF_API_OLD_CHANNEL_LAYOUT
+    /**
+     * @deprecated those are not used by any decoder
+     */
     AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT  = 0x0001,
     AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
+#endif
     AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE    = 0x0004,
     AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS     = 0x0008,
 };
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 4824965ee9..69b838fbc7 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -164,8 +164,11 @@ static void dump_paramchange(void *ctx, const AVPacketSideData *sd)
 {
     int size = sd->size;
     const uint8_t *data = sd->data;
-    uint32_t flags, channels, sample_rate, width, height;
+    uint32_t flags, sample_rate, width, height;
+#if FF_API_OLD_CHANNEL_LAYOUT
+    uint32_t channels;
     uint64_t layout;
+#endif
 
     if (!data || sd->size < 4)
         goto fail;
@@ -174,6 +177,8 @@ static void dump_paramchange(void *ctx, const AVPacketSideData *sd)
     data += 4;
     size -= 4;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
         if (size < 4)
             goto fail;
@@ -191,6 +196,8 @@ static void dump_paramchange(void *ctx, const AVPacketSideData *sd)
         av_log(ctx, AV_LOG_INFO,
                "channel layout: %s, ", av_get_channel_name(layout));
     }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif /* FF_API_OLD_CHANNEL_LAYOUT */
     if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
         if (size < 4)
             goto fail;
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 585ce953ca..9d5eb4ed99 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -894,6 +894,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int
                 break;
             case AV_PKT_DATA_PARAM_CHANGE:
                 flags = bytestream_get_le32(&data);
+#if FF_API_OLD_CHANNEL_LAYOUT
                 if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
                     put_str(dyn_bc, "Channels");
                     put_s(dyn_bc, bytestream_get_le32(&data));
@@ -907,6 +908,7 @@ static int write_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int
                     avio_write(dyn_bc, data, 8); data+=8;
                     sm_data_count++;
                 }
+#endif
                 if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
                     put_str(dyn_bc, "SampleRate");
                     put_s(dyn_bc, bytestream_get_le32(&data));
diff --git a/libavformat/utils.c b/libavformat/utils.c
index e643821fc9..7468ec301d 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1328,6 +1328,9 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
     uint8_t *data;
     if (!pkt)
         return AVERROR(EINVAL);
+
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     if (channels) {
         size  += 4;
         flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT;
@@ -1336,6 +1339,8 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
         size  += 8;
         flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT;
     }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     if (sample_rate) {
         size  += 4;
         flags |= AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE;
@@ -1348,10 +1353,14 @@ int ff_add_param_change(AVPacket *pkt, int32_t channels,
     if (!data)
         return AVERROR(ENOMEM);
     bytestream_put_le32(&data, flags);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     if (channels)
         bytestream_put_le32(&data, channels);
     if (channel_layout)
         bytestream_put_le64(&data, channel_layout);
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     if (sample_rate)
         bytestream_put_le32(&data, sample_rate);
     if (width || height) {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 005/281] avframe: switch to the new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (3 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 004/281] lavc: deprecate channel count/layout changing side data James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 006/281] avcodecpar: " James Almer
                   ` (277 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/frame.c | 116 +++++++++++++++++++++++++++++++++++++---------
 libavutil/frame.h |  16 ++++++-
 2 files changed, 109 insertions(+), 23 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 8997c85e35..6bb72943d1 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -28,10 +28,12 @@
 #include "samplefmt.h"
 #include "hwcontext.h"
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 #define CHECK_CHANNELS_CONSISTENCY(frame) \
     av_assert2(!(frame)->channel_layout || \
                (frame)->channels == \
                av_get_channel_layout_nb_channels((frame)->channel_layout))
+#endif
 
 #if FF_API_COLORSPACE_NAME
 const char *av_get_colorspace_name(enum AVColorSpace val)
@@ -186,18 +188,27 @@ fail:
 
 static int get_audio_buffer(AVFrame *frame, int align)
 {
-    int channels;
     int planar   = av_sample_fmt_is_planar(frame->format);
-    int planes;
+    int channels, planes;
     int ret, i;
 
-    if (!frame->channels)
-        frame->channels = av_get_channel_layout_nb_channels(frame->channel_layout);
-
-    channels = frame->channels;
-    planes = planar ? channels : 1;
-
-    CHECK_CHANNELS_CONSISTENCY(frame);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (!frame->ch_layout.nb_channels) {
+        if (frame->channel_layout) {
+            av_channel_layout_from_mask(&frame->ch_layout, frame->channel_layout);
+        } else {
+            frame->ch_layout.nb_channels = frame->channels;
+            frame->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        }
+    }
+    frame->channels = frame->ch_layout.nb_channels;
+    frame->channel_layout = frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                            frame->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    channels = frame->ch_layout.nb_channels;
+    planes   = planar ? channels : 1;
     if (!frame->linesize[0]) {
         ret = av_samples_get_buffer_size(&frame->linesize[0], channels,
                                          frame->nb_samples, frame->format,
@@ -245,10 +256,17 @@ int av_frame_get_buffer(AVFrame *frame, int align)
     if (frame->format < 0)
         return AVERROR(EINVAL);
 
+FF_DISABLE_DEPRECATION_WARNINGS
     if (frame->width > 0 && frame->height > 0)
         return get_video_buffer(frame, align);
-    else if (frame->nb_samples > 0 && (frame->channel_layout || frame->channels > 0))
+    else if (frame->nb_samples > 0 &&
+             (av_channel_layout_check(&frame->ch_layout)
+#if FF_API_OLD_CHANNEL_LAYOUT
+              || frame->channel_layout || frame->channels > 0
+#endif
+             ))
         return get_audio_buffer(frame, align);
+FF_ENABLE_DEPRECATION_WARNINGS
 
     return AVERROR(EINVAL);
 }
@@ -332,14 +350,33 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src)
     dst->format         = src->format;
     dst->width          = src->width;
     dst->height         = src->height;
+    dst->nb_samples     = src->nb_samples;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     dst->channels       = src->channels;
     dst->channel_layout = src->channel_layout;
-    dst->nb_samples     = src->nb_samples;
+    if (!av_channel_layout_check(&src->ch_layout)) {
+        if (src->channel_layout)
+            av_channel_layout_from_mask(&dst->ch_layout, src->channel_layout);
+        else {
+            dst->ch_layout.nb_channels = src->channels;
+            dst->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        }
+    }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     ret = frame_copy_props(dst, src, 0);
     if (ret < 0)
         goto fail;
 
+    // this check is needed only until FF_API_OLD_CHANNEL_LAYOUT is out
+    if (av_channel_layout_check(&src->ch_layout)) {
+        ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
+        if (ret < 0)
+            goto fail;
+    }
+
     /* duplicate the frame data if it's not refcounted */
     if (!src->buf[0]) {
         ret = av_frame_get_buffer(dst, 0);
@@ -392,13 +429,12 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src)
 
     /* duplicate extended data */
     if (src->extended_data != src->data) {
-        int ch = src->channels;
+        int ch = dst->ch_layout.nb_channels;
 
         if (!ch) {
             ret = AVERROR(EINVAL);
             goto fail;
         }
-        CHECK_CHANNELS_CONSISTENCY(src);
 
         dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch);
         if (!dst->extended_data) {
@@ -456,6 +492,8 @@ void av_frame_unref(AVFrame *frame)
     if (frame->extended_data != frame->data)
         av_freep(&frame->extended_data);
 
+    av_channel_layout_uninit(&frame->ch_layout);
+
     get_frame_defaults(frame);
 }
 
@@ -502,9 +540,18 @@ int av_frame_make_writable(AVFrame *frame)
     tmp.format         = frame->format;
     tmp.width          = frame->width;
     tmp.height         = frame->height;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     tmp.channels       = frame->channels;
     tmp.channel_layout = frame->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     tmp.nb_samples     = frame->nb_samples;
+    ret = av_channel_layout_copy(&tmp.ch_layout, &frame->ch_layout);
+    if (ret < 0) {
+        av_frame_unref(&tmp);
+        return ret;
+    }
 
     if (frame->hw_frames_ctx)
         ret = av_hwframe_get_buffer(frame->hw_frames_ctx, &tmp, 0);
@@ -545,10 +592,18 @@ AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane)
     int planes, i;
 
     if (frame->nb_samples) {
-        int channels = frame->channels;
+        int channels = frame->ch_layout.nb_channels;
+
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        if (!channels) {
+            channels = frame->channels;
+            CHECK_CHANNELS_CONSISTENCY(frame);
+        }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         if (!channels)
             return NULL;
-        CHECK_CHANNELS_CONSISTENCY(frame);
         planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
     } else
         planes = 4;
@@ -654,16 +709,26 @@ static int frame_copy_video(AVFrame *dst, const AVFrame *src)
 static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
 {
     int planar   = av_sample_fmt_is_planar(dst->format);
-    int channels = dst->channels;
+    int channels = dst->ch_layout.nb_channels;
     int planes   = planar ? channels : 1;
     int i;
 
-    if (dst->nb_samples     != src->nb_samples ||
-        dst->channels       != src->channels ||
-        dst->channel_layout != src->channel_layout)
-        return AVERROR(EINVAL);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (!channels) {
+        if (dst->channels       != src->channels ||
+            dst->channel_layout != src->channel_layout)
+            return AVERROR(EINVAL);
+        channels = dst->channels;
+        planes = planar ? channels : 1;
+        CHECK_CHANNELS_CONSISTENCY(src);
+    }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
-    CHECK_CHANNELS_CONSISTENCY(src);
+    if (dst->nb_samples != src->nb_samples ||
+        av_channel_layout_compare(&dst->ch_layout, &src->ch_layout))
+        return AVERROR(EINVAL);
 
     for (i = 0; i < planes; i++)
         if (!dst->extended_data[i] || !src->extended_data[i])
@@ -680,10 +745,17 @@ int av_frame_copy(AVFrame *dst, const AVFrame *src)
     if (dst->format != src->format || dst->format < 0)
         return AVERROR(EINVAL);
 
+FF_DISABLE_DEPRECATION_WARNINGS
     if (dst->width > 0 && dst->height > 0)
         return frame_copy_video(dst, src);
-    else if (dst->nb_samples > 0 && dst->channels > 0)
+    else if (dst->nb_samples > 0 &&
+             (av_channel_layout_check(&dst->ch_layout)
+#if FF_API_OLD_CHANNEL_LAYOUT
+              || dst->channel_layout || dst->channels
+#endif
+            ))
         return frame_copy_audio(dst, src);
+FF_ENABLE_DEPRECATION_WARNINGS
 
     return AVERROR(EINVAL);
 }
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 18e239f870..7443f1a9b1 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -30,6 +30,7 @@
 
 #include "avutil.h"
 #include "buffer.h"
+#include "channel_layout.h"
 #include "dict.h"
 #include "rational.h"
 #include "samplefmt.h"
@@ -493,10 +494,14 @@ typedef struct AVFrame {
      */
     int sample_rate;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
     /**
      * Channel layout of the audio data.
+     * @deprecated use ch_layout instead
      */
+    attribute_deprecated
     uint64_t channel_layout;
+#endif
 
     /**
      * AVBuffer references backing the data for this frame. All the pointers in
@@ -620,12 +625,16 @@ typedef struct AVFrame {
 #define FF_DECODE_ERROR_CONCEALMENT_ACTIVE  4
 #define FF_DECODE_ERROR_DECODE_SLICES       8
 
+#if FF_API_OLD_CHANNEL_LAYOUT
     /**
      * number of audio channels, only used for audio.
      * - encoding: unused
      * - decoding: Read by user.
+     * @deprecated use ch_layout instead
      */
+    attribute_deprecated
     int channels;
+#endif
 
     /**
      * size of the corresponding packet containing the compressed
@@ -681,6 +690,11 @@ typedef struct AVFrame {
      * for the target frame's private_ref field.
      */
     AVBufferRef *private_ref;
+
+    /**
+     * Channel layout of the audio data.
+     */
+    AVChannelLayout ch_layout;
 } AVFrame;
 
 
@@ -760,7 +774,7 @@ void av_frame_move_ref(AVFrame *dst, AVFrame *src);
  * The following fields must be set on frame before calling this function:
  * - format (pixel format for video, sample format for audio)
  * - width and height for video
- * - nb_samples and channel_layout for audio
+ * - nb_samples and ch_layout for audio
  *
  * This function will fill AVFrame.data and AVFrame.buf arrays and, if
  * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 006/281] avcodecpar: switch to the new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (4 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 005/281] avframe: switch to the new channel layout API James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 007/281] lavf: add a temporary compat layer for the channel layout API change James Almer
                   ` (276 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/codec_par.c | 37 +++++++++++++++++++++++++++++++++----
 libavcodec/codec_par.h | 12 ++++++++++++
 libavcodec/utils.c     | 12 ++++++++++--
 3 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c
index 1a5168a04b..9d43af1db4 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -31,6 +31,7 @@
 static void codec_parameters_reset(AVCodecParameters *par)
 {
     av_freep(&par->extradata);
+    av_channel_layout_uninit(&par->ch_layout);
 
     memset(par, 0, sizeof(*par));
 
@@ -71,6 +72,8 @@ void avcodec_parameters_free(AVCodecParameters **ppar)
 
 int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
 {
+    int ret;
+
     codec_parameters_reset(dst);
     memcpy(dst, src, sizeof(*dst));
 
@@ -84,6 +87,10 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src
         dst->extradata_size = src->extradata_size;
     }
 
+    ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
+    if (ret < 0)
+        return ret;
+
     return 0;
 }
 
@@ -118,8 +125,19 @@ int avcodec_parameters_from_context(AVCodecParameters *par,
         break;
     case AVMEDIA_TYPE_AUDIO:
         par->format           = codec->sample_fmt;
-        par->channel_layout   = codec->channel_layout;
-        par->channels         = codec->channels;
+        if (codec->channel_layout)
+            av_channel_layout_from_mask(&par->ch_layout, codec->channel_layout);
+        else {
+            par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            par->ch_layout.nb_channels = codec->channels;
+        }
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        par->channel_layout  = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                               par->ch_layout.u.mask : 0;
+        par->channels        = par->ch_layout.nb_channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         par->sample_rate      = codec->sample_rate;
         par->block_align      = codec->block_align;
         par->frame_size       = codec->frame_size;
@@ -173,8 +191,19 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
         break;
     case AVMEDIA_TYPE_AUDIO:
         codec->sample_fmt       = par->format;
-        codec->channel_layout   = par->channel_layout;
-        codec->channels         = par->channels;
+        if (par->ch_layout.nb_channels) {
+            codec->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                    par->ch_layout.u.mask : 0;
+            codec->channels       = par->ch_layout.nb_channels;
+        }
+#if FF_API_OLD_CHANNEL_LAYOUT
+        else {
+FF_DISABLE_DEPRECATION_WARNINGS
+            codec->channel_layout = par->channel_layout;
+            codec->channels       = par->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+        }
+#endif
         codec->sample_rate      = par->sample_rate;
         codec->block_align      = par->block_align;
         codec->frame_size       = par->frame_size;
diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h
index 10cf79dff1..7660791a12 100644
--- a/libavcodec/codec_par.h
+++ b/libavcodec/codec_par.h
@@ -24,6 +24,7 @@
 #include <stdint.h>
 
 #include "libavutil/avutil.h"
+#include "libavutil/channel_layout.h"
 #include "libavutil/rational.h"
 #include "libavutil/pixfmt.h"
 
@@ -154,16 +155,22 @@ typedef struct AVCodecParameters {
      */
     int video_delay;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
     /**
      * Audio only. The channel layout bitmask. May be 0 if the channel layout is
      * unknown or unspecified, otherwise the number of bits set must be equal to
      * the channels field.
+     * @deprecated use ch_layout
      */
+    attribute_deprecated
     uint64_t channel_layout;
     /**
      * Audio only. The number of audio channels.
+     * @deprecated use ch_layout.nb_channels
      */
+    attribute_deprecated
     int      channels;
+#endif
     /**
      * Audio only. The number of audio samples per second.
      */
@@ -198,6 +205,11 @@ typedef struct AVCodecParameters {
      * Audio only. Number of samples to skip after a discontinuity.
      */
     int seek_preroll;
+
+    /**
+     * Audio only. The channel layout and number of channels.
+     */
+    AVChannelLayout ch_layout;
 } AVCodecParameters;
 
 /**
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index b19befef21..0505ea6ba2 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -815,8 +815,16 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
 
 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
 {
-    int duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
-                                    par->channels, par->block_align,
+   int channels = par->ch_layout.nb_channels;
+   int duration;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (!channels)
+        channels = par->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
+                                    channels, par->block_align,
                                     par->codec_tag, par->bits_per_coded_sample,
                                     par->bit_rate, par->extradata, par->frame_size,
                                     frame_bytes);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 007/281] lavf: add a temporary compat layer for the channel layout API change
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (5 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 006/281] avcodecpar: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 008/281] lavf: convert the generic layer to the new channel layout James Almer
                   ` (275 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Mediates between old-style (de)muxers and new-style callers. Will be
removed once all the (de)muxers are converted to the new API.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/demux.c | 12 ++++++++++++
 libavformat/mux.c   | 10 ++++++++++
 2 files changed, 22 insertions(+)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index f895f0ba85..c78c6c16a2 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -194,6 +194,18 @@ static int update_stream_avctx(AVFormatContext *s)
             sti->parser = NULL;
         }
 
+        /* if the demuxer exports old channel layouts, convert it to new */
+        if (!st->codecpar->ch_layout.nb_channels &&
+            st->codecpar->channels) {
+            if (st->codecpar->channel_layout) {
+                av_channel_layout_from_mask(&st->codecpar->ch_layout,
+                                            st->codecpar->channel_layout);
+            } else {
+                st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+                st->codecpar->ch_layout.nb_channels = st->codecpar->channels;
+            }
+        }
+
         /* update internal codec context, for the parser */
         ret = avcodec_parameters_to_context(sti->avctx, st->codecpar);
         if (ret < 0)
diff --git a/libavformat/mux.c b/libavformat/mux.c
index c387f8ec6e..775e3e0d76 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -272,6 +272,16 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options)
                 ret = AVERROR(EINVAL);
                 goto fail;
             }
+
+            /* if the new-style channel layout is set, convert it to old one
+             * for old-style muxers */
+            if (par->ch_layout.nb_channels &&
+                !par->channels) {
+                par->channels       = par->ch_layout.nb_channels;
+                par->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                      par->ch_layout.u.mask : 0;
+            }
+
             if (!par->block_align)
                 par->block_align = par->channels *
                                    av_get_bits_per_sample(par->codec_id) >> 3;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 008/281] lavf: convert the generic layer to the new channel layout
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (6 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 007/281] lavf: add a temporary compat layer for the channel layout API change James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 009/281] 3dostr: convert to new channel layout API James Almer
                   ` (274 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/demux.c | 16 ++++++++++++++++
 libavformat/mux.c   | 18 +++++++++++++++++-
 libavformat/utils.c |  4 ++--
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index c78c6c16a2..29c5f7539c 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -206,6 +206,18 @@ static int update_stream_avctx(AVFormatContext *s)
             }
         }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        if (st->codecpar->ch_layout.nb_channels &&
+            !st->codecpar->channels) {
+            st->codecpar->channels = st->codecpar->ch_layout.nb_channels;
+            st->codecpar->channel_layout = st->codecpar->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                           st->codecpar->ch_layout.u.mask : 0;
+
+        }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
         /* update internal codec context, for the parser */
         ret = avcodec_parameters_to_context(sti->avctx, st->codecpar);
         if (ret < 0)
@@ -1333,8 +1345,12 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
                 return ret;
             st->codecpar->sample_rate = sti->avctx->sample_rate;
             st->codecpar->bit_rate = sti->avctx->bit_rate;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             st->codecpar->channels = sti->avctx->channels;
             st->codecpar->channel_layout = sti->avctx->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             st->codecpar->codec_id = sti->avctx->codec_id;
         } else {
             /* free packet */
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 775e3e0d76..68983c773f 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -282,8 +282,24 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options)
                                       par->ch_layout.u.mask : 0;
             }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+            /* if the caller is using the deprecated channel layout API,
+             * convert it to the new style */
+            if (!par->ch_layout.nb_channels &&
+                par->channels) {
+                if (par->channel_layout) {
+                    av_channel_layout_from_mask(&par->ch_layout, par->channel_layout);
+                } else {
+                    par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+                    par->ch_layout.nb_channels = par->channels;
+                }
+            }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
             if (!par->block_align)
-                par->block_align = par->channels *
+                par->block_align = par->ch_layout.nb_channels *
                                    av_get_bits_per_sample(par->codec_id) >> 3;
             break;
         case AVMEDIA_TYPE_VIDEO:
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 7468ec301d..1667d6f6f5 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -525,7 +525,7 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type,
             continue;
         if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
             continue;
-        if (type == AVMEDIA_TYPE_AUDIO && !(par->channels && par->sample_rate))
+        if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && par->sample_rate))
             continue;
         if (decoder_ret) {
             decoder = ff_find_decoder(ic, st, par->codec_id);
@@ -1522,7 +1522,7 @@ static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
             int val;
             switch (par->codec_type) {
             case AVMEDIA_TYPE_AUDIO:
-                val = par->sample_rate && par->channels;
+                val = par->sample_rate && par->ch_layout.nb_channels;
                 if (par->format == AV_SAMPLE_FMT_NONE)
                     return 0;
                 break;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 009/281] 3dostr: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (7 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 008/281] lavf: convert the generic layer to the new channel layout James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 010/281] 4xm: " James Almer
                   ` (273 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/3dostr.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavformat/3dostr.c b/libavformat/3dostr.c
index 0c136c9ea0..9b6a4d1d86 100644
--- a/libavformat/3dostr.c
+++ b/libavformat/3dostr.c
@@ -102,15 +102,16 @@ static int threedostr_read_header(AVFormatContext *s)
 
             st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
             st->codecpar->sample_rate = avio_rb32(s->pb);
-            st->codecpar->channels    = avio_rb32(s->pb);
-            if (st->codecpar->channels <= 0 || st->codecpar->sample_rate <= 0)
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = avio_rb32(s->pb);
+            if (st->codecpar->ch_layout.nb_channels <= 0 || st->codecpar->sample_rate <= 0)
                 return AVERROR_INVALIDDATA;
             codec                  = avio_rl32(s->pb);
             avio_skip(s->pb, 4);
             if (ctrl_size == 20 || ctrl_size == 3 || ctrl_size == -1)
-                st->duration       = (avio_rb32(s->pb) - 1) / st->codecpar->channels;
+                st->duration       = (avio_rb32(s->pb) - 1) / st->codecpar->ch_layout.nb_channels;
             else
-                st->duration       = avio_rb32(s->pb) * 16 / st->codecpar->channels;
+                st->duration       = avio_rb32(s->pb) * 16 / st->codecpar->ch_layout.nb_channels;
             size -= 56;
             found_shdr = 1;
             break;
@@ -135,7 +136,7 @@ static int threedostr_read_header(AVFormatContext *s)
     switch (codec) {
     case MKTAG('S','D','X','2'):
         st->codecpar->codec_id    = AV_CODEC_ID_SDX2_DPCM;
-        st->codecpar->block_align = 1 * st->codecpar->channels;
+        st->codecpar->block_align = 1 * st->codecpar->ch_layout.nb_channels;
         break;
     default:
         avpriv_request_sample(s, "codec %X", codec);
@@ -178,7 +179,7 @@ static int threedostr_read_packet(AVFormatContext *s, AVPacket *pkt)
             ret = av_get_packet(s->pb, pkt, size);
             pkt->pos = pos;
             pkt->stream_index = 0;
-            pkt->duration = size / st->codecpar->channels;
+            pkt->duration = size / st->codecpar->ch_layout.nb_channels;
             return ret;
         default:
             av_log(s, AV_LOG_DEBUG, "skipping unknown chunk: %X\n", chunk);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 010/281] 4xm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (8 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 009/281] 3dostr: convert to new channel layout API James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 011/281] aa: " James Almer
                   ` (272 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/4xm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/4xm.c b/libavformat/4xm.c
index e307560014..4d735a1a6f 100644
--- a/libavformat/4xm.c
+++ b/libavformat/4xm.c
@@ -190,13 +190,14 @@ static int parse_strk(AVFormatContext *s,
 
     st->codecpar->codec_type            = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_tag             = 0;
-    st->codecpar->channels              = fourxm->tracks[track].channels;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = fourxm->tracks[track].channels;
     st->codecpar->sample_rate           = fourxm->tracks[track].sample_rate;
     st->codecpar->bits_per_coded_sample = fourxm->tracks[track].bits;
-    st->codecpar->bit_rate              = (int64_t)st->codecpar->channels *
+    st->codecpar->bit_rate              = (int64_t)st->codecpar->ch_layout.nb_channels *
                                           st->codecpar->sample_rate *
                                           st->codecpar->bits_per_coded_sample;
-    st->codecpar->block_align           = st->codecpar->channels *
+    st->codecpar->block_align           = st->codecpar->ch_layout.nb_channels *
                                           st->codecpar->bits_per_coded_sample;
 
     if (fourxm->tracks[track].adpcm){
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 011/281] aa: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (9 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 010/281] 4xm: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 012/281] aax: " James Almer
                   ` (271 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/aadec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/aadec.c b/libavformat/aadec.c
index b8a5428f1f..cd275aa2f1 100644
--- a/libavformat/aadec.c
+++ b/libavformat/aadec.c
@@ -178,7 +178,8 @@ static int aa_read_header(AVFormatContext *s)
     } else if (!strcmp(codec_name, "acelp85")) {
         st->codecpar->codec_id = AV_CODEC_ID_SIPR;
         st->codecpar->block_align = 19;
-        st->codecpar->channels = 1;
+        st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = 1;
         st->codecpar->sample_rate = 8500;
         st->codecpar->bit_rate = 8500;
         sti->need_parsing = AVSTREAM_PARSE_FULL_RAW;
@@ -186,7 +187,8 @@ static int aa_read_header(AVFormatContext *s)
     } else if (!strcmp(codec_name, "acelp16")) {
         st->codecpar->codec_id = AV_CODEC_ID_SIPR;
         st->codecpar->block_align = 20;
-        st->codecpar->channels = 1;
+        st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = 1;
         st->codecpar->sample_rate = 16000;
         st->codecpar->bit_rate = 16000;
         sti->need_parsing = AVSTREAM_PARSE_FULL_RAW;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 012/281] aax: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (10 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 011/281] aa: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 013/281] ace: " James Almer
                   ` (270 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/aaxdec.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/aaxdec.c b/libavformat/aaxdec.c
index b08ee036ed..8eb2540407 100644
--- a/libavformat/aaxdec.c
+++ b/libavformat/aaxdec.c
@@ -279,9 +279,10 @@ static int aax_read_header(AVFormatContext *s)
         ret = ff_get_extradata(s, par, pb, extradata_size);
         if (ret < 0)
             return ret;
-        par->channels    = AV_RB8 (par->extradata + 7);
+        par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        par->ch_layout.nb_channels = AV_RB8 (par->extradata + 7);
         par->sample_rate = AV_RB32(par->extradata + 8);
-        if (!par->channels || !par->sample_rate)
+        if (!par->ch_layout.nb_channels || !par->sample_rate)
             return AVERROR_INVALIDDATA;
 
         avpriv_set_pts_info(st, 64, 32, par->sample_rate);
@@ -299,7 +300,7 @@ static int aax_read_packet(AVFormatContext *s, AVPacket *pkt)
     AAXContext *a = s->priv_data;
     AVCodecParameters *par = s->streams[0]->codecpar;
     AVIOContext *pb = s->pb;
-    const int size = 18 * par->channels;
+    const int size = 18 * par->ch_layout.nb_channels;
     int ret, extradata_size = 0;
     uint8_t *extradata = NULL;
     int skip = 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 013/281] ace: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (11 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 012/281] aax: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 014/281] acm: " James Almer
                   ` (269 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/acedec.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/acedec.c b/libavformat/acedec.c
index a52a0f0e54..74128e0a6a 100644
--- a/libavformat/acedec.c
+++ b/libavformat/acedec.c
@@ -74,7 +74,8 @@ static int ace_read_header(AVFormatContext *s)
     st->start_time = 0;
     par = st->codecpar;
     par->codec_type  = AVMEDIA_TYPE_AUDIO;
-    par->channels    = nb_channels;
+    par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    par->ch_layout.nb_channels = nb_channels;
     par->sample_rate = rate;
     par->block_align = (codec == 4 ? 0x60 : codec == 5 ? 0x98 : 0xC0) * nb_channels;
     st->duration     = (size / par->block_align) * 1024LL;
@@ -85,7 +86,7 @@ static int ace_read_header(AVFormatContext *s)
         return ret;
 
     AV_WL16(st->codecpar->extradata, 1);
-    AV_WL16(st->codecpar->extradata+2, 2048 * par->channels);
+    AV_WL16(st->codecpar->extradata+2, 2048 * nb_channels);
     AV_WL16(st->codecpar->extradata+4, 0);
     AV_WL16(st->codecpar->extradata+6, codec == 4 ? 1 : 0);
     AV_WL16(st->codecpar->extradata+8, codec == 4 ? 1 : 0);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 014/281] acm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (12 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 013/281] ace: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 015/281] act: " James Almer
                   ` (268 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/acm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/acm.c b/libavformat/acm.c
index 0ee9114f70..a6da000130 100644
--- a/libavformat/acm.c
+++ b/libavformat/acm.c
@@ -48,12 +48,13 @@ static int acm_read_header(AVFormatContext *s)
     if (ret < 0)
         return ret;
 
-    st->codecpar->channels    = AV_RL16(st->codecpar->extradata +  8);
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = AV_RL16(st->codecpar->extradata +  8);
     st->codecpar->sample_rate = AV_RL16(st->codecpar->extradata + 10);
-    if (st->codecpar->channels <= 0 || st->codecpar->sample_rate <= 0)
+    if (st->codecpar->ch_layout.nb_channels <= 0 || st->codecpar->sample_rate <= 0)
         return AVERROR_INVALIDDATA;
     st->start_time         = 0;
-    st->duration           = AV_RL32(st->codecpar->extradata +  4) / st->codecpar->channels;
+    st->duration           = AV_RL32(st->codecpar->extradata +  4) / st->codecpar->ch_layout.nb_channels;
     ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW;
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 015/281] act: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (13 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 014/281] acm: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 016/281] adp: " James Almer
                   ` (267 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/act.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/act.c b/libavformat/act.c
index a369157647..49639acfcc 100644
--- a/libavformat/act.c
+++ b/libavformat/act.c
@@ -88,7 +88,8 @@ static int read_header(AVFormatContext *s)
     }
 
     st->codecpar->frame_size=80;
-    st->codecpar->channels=1;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = 1;
     avpriv_set_pts_info(st, 64, 1, 100);
 
     st->codecpar->codec_id=AV_CODEC_ID_G729;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 016/281] adp: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (14 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 015/281] act: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 017/281] ads: " James Almer
                   ` (266 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/adp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/adp.c b/libavformat/adp.c
index 6d5f9d274e..c9a5a04507 100644
--- a/libavformat/adp.c
+++ b/libavformat/adp.c
@@ -55,8 +55,7 @@ static int adp_read_header(AVFormatContext *s)
 
     st->codecpar->codec_type     = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id       = AV_CODEC_ID_ADPCM_DTK;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-    st->codecpar->channels       = 2;
+    st->codecpar->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     st->codecpar->sample_rate    = 48000;
     st->start_time            = 0;
     if (s->pb->seekable & AVIO_SEEKABLE_NORMAL)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 017/281] ads: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (15 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 016/281] adp: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 018/281] adxdec: " James Almer
                   ` (265 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/ads.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavformat/ads.c b/libavformat/ads.c
index e7b419ce8d..ee329bb403 100644
--- a/libavformat/ads.c
+++ b/libavformat/ads.c
@@ -48,11 +48,12 @@ static int ads_read_header(AVFormatContext *s)
     st->codecpar->sample_rate = avio_rl32(s->pb);
     if (st->codecpar->sample_rate <= 0)
         return AVERROR_INVALIDDATA;
-    st->codecpar->channels    = avio_rl32(s->pb);
-    if (st->codecpar->channels <= 0)
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_rl32(s->pb);
+    if (st->codecpar->ch_layout.nb_channels <= 0)
         return AVERROR_INVALIDDATA;
     align                  = avio_rl32(s->pb);
-    if (align <= 0 || align > INT_MAX / st->codecpar->channels)
+    if (align <= 0 || align > INT_MAX / st->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
 
     if (codec == 1)
@@ -60,11 +61,11 @@ static int ads_read_header(AVFormatContext *s)
     else
         st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX;
 
-    st->codecpar->block_align = st->codecpar->channels * align;
+    st->codecpar->block_align = st->codecpar->ch_layout.nb_channels * align;
     avio_skip(s->pb, 12);
     size = avio_rl32(s->pb);
     if (st->codecpar->codec_id == AV_CODEC_ID_ADPCM_PSX && size >= 0x40)
-        st->duration = (size - 0x40) / 16 / st->codecpar->channels * 28;
+        st->duration = (size - 0x40) / 16 / st->codecpar->ch_layout.nb_channels * 28;
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 018/281] adxdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (16 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 017/281] ads: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 019/281] aea: " James Almer
                   ` (264 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/adxdec.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/libavformat/adxdec.c b/libavformat/adxdec.c
index d91d43d114..fa91080f41 100644
--- a/libavformat/adxdec.c
+++ b/libavformat/adxdec.c
@@ -56,12 +56,12 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)
     if (avio_feof(s->pb))
         return AVERROR_EOF;
 
-    if (par->channels <= 0) {
-        av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", par->channels);
+    if (par->ch_layout.nb_channels <= 0) {
+        av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", par->ch_layout.nb_channels);
         return AVERROR_INVALIDDATA;
     }
 
-    size = BLOCK_SIZE * par->channels;
+    size = BLOCK_SIZE * par->ch_layout.nb_channels;
 
     pkt->pos = avio_tell(s->pb);
     pkt->stream_index = 0;
@@ -79,8 +79,8 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)
         size = ret;
     }
 
-    pkt->duration = size / (BLOCK_SIZE * par->channels);
-    pkt->pts      = (pkt->pos - c->header_size) / (BLOCK_SIZE * par->channels);
+    pkt->duration = size / (BLOCK_SIZE * par->ch_layout.nb_channels);
+    pkt->pts      = (pkt->pos - c->header_size) / (BLOCK_SIZE * par->ch_layout.nb_channels);
 
     return 0;
 }
@@ -90,6 +90,8 @@ static int adx_read_header(AVFormatContext *s)
     ADXDemuxerContext *c = s->priv_data;
     AVCodecParameters *par;
     int ret;
+    int channels;
+
     AVStream *st = avformat_new_stream(s, NULL);
     if (!st)
         return AVERROR(ENOMEM);
@@ -107,11 +109,11 @@ static int adx_read_header(AVFormatContext *s)
         av_log(s, AV_LOG_ERROR, "Invalid extradata size.\n");
         return AVERROR_INVALIDDATA;
     }
-    par->channels    = AV_RB8 (par->extradata + 7);
+    channels = AV_RB8 (par->extradata + 7);
     par->sample_rate = AV_RB32(par->extradata + 8);
 
-    if (par->channels <= 0) {
-        av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", par->channels);
+    if (channels <= 0) {
+        av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", channels);
         return AVERROR_INVALIDDATA;
     }
 
@@ -120,9 +122,11 @@ static int adx_read_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
     }
 
+    par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    par->ch_layout.nb_channels = channels;
     par->codec_type  = AVMEDIA_TYPE_AUDIO;
     par->codec_id    = s->iformat->raw_codec_id;
-    par->bit_rate    = (int64_t)par->sample_rate * par->channels * BLOCK_SIZE * 8LL / BLOCK_SAMPLES;
+    par->bit_rate    = (int64_t)par->sample_rate * par->ch_layout.nb_channels * BLOCK_SIZE * 8LL / BLOCK_SAMPLES;
 
     avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, par->sample_rate);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 019/281] aea: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (17 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 018/281] adxdec: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 020/281] afc: " James Almer
                   ` (263 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/aea.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavformat/aea.c b/libavformat/aea.c
index 14d0840cf3..f4b39e4f9e 100644
--- a/libavformat/aea.c
+++ b/libavformat/aea.c
@@ -62,12 +62,13 @@ static int aea_read_probe(const AVProbeData *p)
 static int aea_read_header(AVFormatContext *s)
 {
     AVStream *st = avformat_new_stream(s, NULL);
+    int channels;
     if (!st)
         return AVERROR(ENOMEM);
 
     /* Parse the amount of channels and skip to pos 2048(0x800) */
     avio_skip(s->pb, 264);
-    st->codecpar->channels = avio_r8(s->pb);
+    channels = avio_r8(s->pb);
     avio_skip(s->pb, 1783);
 
 
@@ -76,14 +77,14 @@ static int aea_read_header(AVFormatContext *s)
     st->codecpar->sample_rate    = 44100;
     st->codecpar->bit_rate       = 292000;
 
-    if (st->codecpar->channels != 1 && st->codecpar->channels != 2) {
-        av_log(s, AV_LOG_ERROR, "Channels %d not supported!\n", st->codecpar->channels);
+    if (channels != 1 && channels != 2) {
+        av_log(s, AV_LOG_ERROR, "Channels %d not supported!\n", channels);
         return AVERROR_INVALIDDATA;
     }
 
-    st->codecpar->channel_layout = (st->codecpar->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
+    av_channel_layout_default(&st->codecpar->ch_layout, channels);
 
-    st->codecpar->block_align = AT1_SU_SIZE * st->codecpar->channels;
+    st->codecpar->block_align = AT1_SU_SIZE * st->codecpar->ch_layout.nb_channels;
     return 0;
 }
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 020/281] afc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (18 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 019/281] aea: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 021/281] aiff: " James Almer
                   ` (262 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/afc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/afc.c b/libavformat/afc.c
index 102b74baeb..898c7d03eb 100644
--- a/libavformat/afc.c
+++ b/libavformat/afc.c
@@ -38,12 +38,11 @@ static int afc_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id   = AV_CODEC_ID_ADPCM_AFC;
-    st->codecpar->channels   = 2;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+    st->codecpar->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 
     if ((ret = ff_alloc_extradata(st->codecpar, 1)) < 0)
         return ret;
-    st->codecpar->extradata[0] = 8 * st->codecpar->channels;
+    st->codecpar->extradata[0] = 8 * st->codecpar->ch_layout.nb_channels;
 
     c->data_end = avio_rb32(s->pb) + 32LL;
     st->duration = avio_rb32(s->pb);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 021/281] aiff: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (19 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 020/281] afc: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 022/281] aixdec: " James Almer
                   ` (261 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/aiffdec.c | 13 ++++++++-----
 libavformat/aiffenc.c |  8 ++++----
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index 7afadeb085..c56949bef9 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -99,6 +99,7 @@ static int get_aiff_header(AVFormatContext *s, int size,
     uint64_t val;
     int sample_rate;
     unsigned int num_frames;
+    int channels;
 
     if (size == INT_MAX)
         return AVERROR_INVALIDDATA;
@@ -106,7 +107,9 @@ static int get_aiff_header(AVFormatContext *s, int size,
     if (size & 1)
         size++;
     par->codec_type = AVMEDIA_TYPE_AUDIO;
-    par->channels = avio_rb16(pb);
+    channels = avio_rb16(pb);
+    par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    par->ch_layout.nb_channels = channels;
     num_frames = avio_rb32(pb);
     par->bits_per_coded_sample = avio_rb16(pb);
 
@@ -154,10 +157,10 @@ static int get_aiff_header(AVFormatContext *s, int size,
             aiff->block_duration = 1;
             break;
         case AV_CODEC_ID_ADPCM_IMA_QT:
-            par->block_align = 34 * par->channels;
+            par->block_align = 34 * channels;
             break;
         case AV_CODEC_ID_MACE3:
-            par->block_align = 2 * par->channels;
+            par->block_align = 2 * channels;
             break;
         case AV_CODEC_ID_ADPCM_G726LE:
             par->bits_per_coded_sample = 5;
@@ -165,7 +168,7 @@ static int get_aiff_header(AVFormatContext *s, int size,
         case AV_CODEC_ID_ADPCM_G722:
         case AV_CODEC_ID_MACE6:
         case AV_CODEC_ID_SDX2_DPCM:
-            par->block_align = 1 * par->channels;
+            par->block_align = 1 * channels;
             break;
         case AV_CODEC_ID_GSM:
             par->block_align = 33;
@@ -182,7 +185,7 @@ static int get_aiff_header(AVFormatContext *s, int size,
     /* Block align needs to be computed in all cases, as the definition
      * is specific to applications -> here we use the WAVE format definition */
     if (!par->block_align)
-        par->block_align = (av_get_bits_per_sample(par->codec_id) * par->channels) >> 3;
+        par->block_align = (av_get_bits_per_sample(par->codec_id) * channels) >> 3;
 
     if (aiff->block_duration) {
         par->bit_rate = av_rescale(par->sample_rate, par->block_align * 8LL,
diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c
index 1fd6b8a70b..bdaf5c2c3e 100644
--- a/libavformat/aiffenc.c
+++ b/libavformat/aiffenc.c
@@ -144,10 +144,10 @@ static int aiff_write_header(AVFormatContext *s)
         avio_wb32(pb, 0xA2805140);
     }
 
-    if (par->channels > 2 && par->channel_layout) {
+    if (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE && par->ch_layout.nb_channels > 2) {
         ffio_wfourcc(pb, "CHAN");
         avio_wb32(pb, 12);
-        ff_mov_write_chan(pb, par->channel_layout);
+        ff_mov_write_chan(pb, par->ch_layout.u.mask);
     }
 
     put_meta(s, "title",     MKTAG('N', 'A', 'M', 'E'));
@@ -158,7 +158,7 @@ static int aiff_write_header(AVFormatContext *s)
     /* Common chunk */
     ffio_wfourcc(pb, "COMM");
     avio_wb32(pb, aifc ? 24 : 18); /* size */
-    avio_wb16(pb, par->channels);  /* Number of channels */
+    avio_wb16(pb, par->ch_layout.nb_channels);  /* Number of channels */
 
     aiff->frames = avio_tell(pb);
     avio_wb32(pb, 0);              /* Number of frames */
@@ -170,7 +170,7 @@ static int aiff_write_header(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
     if (!par->block_align)
-        par->block_align = (par->bits_per_coded_sample * par->channels) >> 3;
+        par->block_align = (par->bits_per_coded_sample * par->ch_layout.nb_channels) >> 3;
 
     avio_wb16(pb, par->bits_per_coded_sample); /* Sample size */
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 022/281] aixdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (20 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 021/281] aiff: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 023/281] alsa: " James Almer
                   ` (260 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/aixdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/aixdec.c b/libavformat/aixdec.c
index 59c3d60da3..a1ee370a6d 100644
--- a/libavformat/aixdec.c
+++ b/libavformat/aixdec.c
@@ -64,7 +64,8 @@ static int aix_read_header(AVFormatContext *s)
         st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_ADX;
         st->codecpar->sample_rate = avio_rb32(s->pb);
-        st->codecpar->channels    = avio_r8(s->pb);
+        st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = avio_r8(s->pb);
         avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
         avio_skip(s->pb, 3);
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 023/281] alsa: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (21 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 022/281] aixdec: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 024/281] alp: " James Almer
                   ` (259 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavdevice/alsa.c     | 19 +++++++++++--------
 libavdevice/alsa_dec.c |  3 ++-
 libavdevice/alsa_enc.c |  2 +-
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/libavdevice/alsa.c b/libavdevice/alsa.c
index ee282fac16..5396858427 100644
--- a/libavdevice/alsa.c
+++ b/libavdevice/alsa.c
@@ -124,7 +124,7 @@ switch(format) {\
     case FORMAT_F32: s->reorder_func = alsa_reorder_f32_out_ ##layout;   break;\
 }
 
-static av_cold int find_reorder_func(AlsaData *s, int codec_id, uint64_t layout, int out)
+static av_cold int find_reorder_func(AlsaData *s, int codec_id, AVChannelLayout *layout, int out)
 {
     int format;
 
@@ -133,7 +133,8 @@ static av_cold int find_reorder_func(AlsaData *s, int codec_id, uint64_t layout,
         return AVERROR(ENOSYS);
 
     /* reordering is not needed for QUAD or 2_2 layout */
-    if (layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2)
+    if (!av_channel_layout_compare(layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD) ||
+        !av_channel_layout_compare(layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2))
         return 0;
 
     switch (codec_id) {
@@ -154,11 +155,13 @@ static av_cold int find_reorder_func(AlsaData *s, int codec_id, uint64_t layout,
     default:                 return AVERROR(ENOSYS);
     }
 
-    if      (layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0)
+    if (!av_channel_layout_compare(layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0_BACK) ||
+        !av_channel_layout_compare(layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0))
         PICK_REORDER(50)
-    else if (layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1)
+    else if (!av_channel_layout_compare(layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK) ||
+             !av_channel_layout_compare(layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1))
         PICK_REORDER(51)
-    else if (layout == AV_CH_LAYOUT_7POINT1)
+    else if (!av_channel_layout_compare(layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1))
         PICK_REORDER(71)
 
     return s->reorder_func ? 0 : AVERROR(ENOSYS);
@@ -169,13 +172,13 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
                          int channels, enum AVCodecID *codec_id)
 {
     AlsaData *s = ctx->priv_data;
+    AVChannelLayout *layout = &ctx->streams[0]->codecpar->ch_layout;
     const char *audio_device;
     int res, flags = 0;
     snd_pcm_format_t format;
     snd_pcm_t *h;
     snd_pcm_hw_params_t *hw_params;
     snd_pcm_uframes_t buffer_size, period_size;
-    uint64_t layout = ctx->streams[0]->codecpar->channel_layout;
 
     if (ctx->url[0] == 0) audio_device = "default";
     else                  audio_device = ctx->url;
@@ -271,10 +274,10 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
 
     snd_pcm_hw_params_free(hw_params);
 
-    if (channels > 2 && layout) {
+    if (channels > 2 && layout->order != AV_CHANNEL_ORDER_UNSPEC) {
         if (find_reorder_func(s, *codec_id, layout, mode == SND_PCM_STREAM_PLAYBACK) < 0) {
             char name[128];
-            av_get_channel_layout_string(name, sizeof(name), channels, layout);
+            av_channel_layout_describe(layout, name, sizeof(name));
             av_log(ctx, AV_LOG_WARNING, "ALSA channel layout unknown or unimplemented for %s %s.\n",
                    name, mode == SND_PCM_STREAM_PLAYBACK ? "playback" : "capture");
         }
diff --git a/libavdevice/alsa_dec.c b/libavdevice/alsa_dec.c
index e93f31b146..79d37b5f56 100644
--- a/libavdevice/alsa_dec.c
+++ b/libavdevice/alsa_dec.c
@@ -82,7 +82,8 @@ static av_cold int audio_read_header(AVFormatContext *s1)
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id    = codec_id;
     st->codecpar->sample_rate = s->sample_rate;
-    st->codecpar->channels    = s->channels;
+    st->codecpar->ch_layout.nb_channels = s->channels;
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
     st->codecpar->frame_size = s->frame_size;
     avpriv_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
     /* microseconds instead of seconds, MHz instead of Hz */
diff --git a/libavdevice/alsa_enc.c b/libavdevice/alsa_enc.c
index a783d8eca1..fc5e5d9c94 100644
--- a/libavdevice/alsa_enc.c
+++ b/libavdevice/alsa_enc.c
@@ -64,7 +64,7 @@ static av_cold int audio_write_header(AVFormatContext *s1)
     sample_rate = st->codecpar->sample_rate;
     codec_id    = st->codecpar->codec_id;
     res = ff_alsa_open(s1, SND_PCM_STREAM_PLAYBACK, &sample_rate,
-        st->codecpar->channels, &codec_id);
+        st->codecpar->ch_layout.nb_channels, &codec_id);
     if (sample_rate != st->codecpar->sample_rate) {
         av_log(s1, AV_LOG_ERROR,
                "sample rate %d not available, nearest is %d\n",
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 024/281] alp: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (22 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 023/281] alsa: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 025/281] amr: " James Almer
                   ` (258 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/alp.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/libavformat/alp.c b/libavformat/alp.c
index f46bdb4511..444b55dd77 100644
--- a/libavformat/alp.c
+++ b/libavformat/alp.c
@@ -119,18 +119,14 @@ static int alp_read_header(AVFormatContext *s)
     par->codec_id               = AV_CODEC_ID_ADPCM_IMA_ALP;
     par->format                 = AV_SAMPLE_FMT_S16;
     par->sample_rate            = hdr->sample_rate;
-    par->channels               = hdr->num_channels;
 
-    if (hdr->num_channels == 1)
-        par->channel_layout     = AV_CH_LAYOUT_MONO;
-    else if (hdr->num_channels == 2)
-        par->channel_layout     = AV_CH_LAYOUT_STEREO;
-    else
+    if (hdr->num_channels > 2)
         return AVERROR_INVALIDDATA;
 
+    av_channel_layout_default(&par->ch_layout, hdr->num_channels);
     par->bits_per_coded_sample  = 4;
     par->block_align            = 1;
-    par->bit_rate               = par->channels *
+    par->bit_rate               = par->ch_layout.nb_channels *
                                   par->sample_rate *
                                   par->bits_per_coded_sample;
 
@@ -148,7 +144,7 @@ static int alp_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     pkt->flags         &= ~AV_PKT_FLAG_CORRUPT;
     pkt->stream_index   = 0;
-    pkt->duration       = ret * 2 / par->channels;
+    pkt->duration       = ret * 2 / par->ch_layout.nb_channels;
 
     return 0;
 }
@@ -202,7 +198,7 @@ static int alp_write_init(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    if (par->channels > 2) {
+    if (par->ch_layout.nb_channels > 2) {
         av_log(s, AV_LOG_ERROR, "A maximum of 2 channels are supported\n");
         return AVERROR(EINVAL);
     }
@@ -228,7 +224,7 @@ static int alp_write_header(AVFormatContext *s)
     avio_wl32(s->pb,  alp->type == ALP_TYPE_PCM ? 12 : 8);
     avio_write(s->pb, "ADPCM", 6);
     avio_w8(s->pb,    0);
-    avio_w8(s->pb,    par->channels);
+    avio_w8(s->pb,    par->ch_layout.nb_channels);
     if (alp->type == ALP_TYPE_PCM)
         avio_wl32(s->pb, par->sample_rate);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 025/281] amr: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (23 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 024/281] alp: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 026/281] amv: " James Almer
                   ` (257 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/amr.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/libavformat/amr.c b/libavformat/amr.c
index bc22c2f84f..91322976ec 100644
--- a/libavformat/amr.c
+++ b/libavformat/amr.c
@@ -100,33 +100,33 @@ static int amr_read_header(AVFormatContext *s)
         st->codecpar->codec_tag   = MKTAG('s', 'a', 'm', 'r');
         st->codecpar->codec_id    = AV_CODEC_ID_AMR_NB;
         st->codecpar->sample_rate = 8000;
-        st->codecpar->channels = 1;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         back = read - sizeof(AMR_header);
     } else if (!memcmp(header, AMRWB_header, sizeof(AMRWB_header))) {
         st->codecpar->codec_tag   = MKTAG('s', 'a', 'w', 'b');
         st->codecpar->codec_id    = AV_CODEC_ID_AMR_WB;
         st->codecpar->sample_rate = 16000;
-        st->codecpar->channels = 1;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+        st->codecpar->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         back = read - sizeof(AMRWB_header);
     } else if (!memcmp(header, AMRMC_header, sizeof(AMRMC_header))) {
         st->codecpar->codec_tag   = MKTAG('s', 'a', 'm', 'r');
         st->codecpar->codec_id    = AV_CODEC_ID_AMR_NB;
         st->codecpar->sample_rate = 8000;
-        st->codecpar->channels    = AV_RL32(header + 12);
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = AV_RL32(header + 12);
         back = read - 4 - sizeof(AMRMC_header);
     } else if (!memcmp(header, AMRWBMC_header, sizeof(AMRWBMC_header))) {
         st->codecpar->codec_tag   = MKTAG('s', 'a', 'w', 'b');
         st->codecpar->codec_id    = AV_CODEC_ID_AMR_WB;
         st->codecpar->sample_rate = 16000;
-        st->codecpar->channels    = AV_RL32(header + 15);
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = AV_RL32(header + 15);
         back = read - 4 - sizeof(AMRWBMC_header);
     } else {
         return AVERROR_INVALIDDATA;
     }
 
-    if (st->codecpar->channels < 1)
+    if (st->codecpar->ch_layout.nb_channels < 1)
         return AVERROR_INVALIDDATA;
 
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -188,8 +188,7 @@ static int amrnb_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
     st->codecpar->codec_id       = AV_CODEC_ID_AMR_NB;
     st->codecpar->sample_rate    = 8000;
-    st->codecpar->channels       = 1;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    st->codecpar->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     st->codecpar->codec_type     = AVMEDIA_TYPE_AUDIO;
     ffstream(st)->need_parsing   = AVSTREAM_PARSE_FULL_RAW;
     avpriv_set_pts_info(st, 64, 1, 8000);
@@ -246,8 +245,7 @@ static int amrwb_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
     st->codecpar->codec_id       = AV_CODEC_ID_AMR_WB;
     st->codecpar->sample_rate    = 16000;
-    st->codecpar->channels       = 1;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    st->codecpar->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     st->codecpar->codec_type     = AVMEDIA_TYPE_AUDIO;
     ffstream(st)->need_parsing   = AVSTREAM_PARSE_FULL_RAW;
     avpriv_set_pts_info(st, 64, 1, 16000);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 026/281] amv: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (24 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 025/281] amr: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 027/281] apc: " James Almer
                   ` (256 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/amvenc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/amvenc.c b/libavformat/amvenc.c
index fece2f49b1..28d4879b19 100644
--- a/libavformat/amvenc.c
+++ b/libavformat/amvenc.c
@@ -244,9 +244,9 @@ static void amv_write_alist(AVFormatContext *s, AVCodecParameters *par)
     /* Bodge an (incorrect) WAVEFORMATEX (+2 pad bytes) */
     tag_str = ff_start_tag(pb, "strf");
     AV_WL16(buf +  0, 1);
-    AV_WL16(buf +  2, par->channels);
+    AV_WL16(buf +  2, par->ch_layout.nb_channels);
     AV_WL32(buf +  4, par->sample_rate);
-    AV_WL32(buf +  8, par->sample_rate * par->channels * 2);
+    AV_WL32(buf +  8, par->sample_rate * par->ch_layout.nb_channels * 2);
     AV_WL16(buf + 12, 2);
     AV_WL16(buf + 14, 16);
     AV_WL16(buf + 16, 0);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 027/281] apc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (25 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 026/281] amv: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-26 13:41   ` Anton Khirnov
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 028/281] ape: " James Almer
                   ` (255 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/apc.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/libavformat/apc.c b/libavformat/apc.c
index 56151bb59a..192e115278 100644
--- a/libavformat/apc.c
+++ b/libavformat/apc.c
@@ -38,6 +38,7 @@ static int apc_read_header(AVFormatContext *s)
     AVIOContext *pb = s->pb;
     AVStream *st;
     int ret;
+    int channels;
 
     avio_rl32(pb); /* CRYO */
     avio_rl32(pb); /* _APC */
@@ -57,16 +58,11 @@ static int apc_read_header(AVFormatContext *s)
     if ((ret = ff_get_extradata(s, st->codecpar, pb, 2 * 4)) < 0)
         return ret;
 
-    if (avio_rl32(pb)) {
-        st->codecpar->channels       = 2;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-    } else {
-        st->codecpar->channels       = 1;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
-    }
+    channels = avio_rl32(pb) + 1;
+    av_channel_layout_default(&st->codecpar->ch_layout, channels);
 
     st->codecpar->bits_per_coded_sample = 4;
-    st->codecpar->bit_rate = (int64_t)st->codecpar->bits_per_coded_sample * st->codecpar->channels
+    st->codecpar->bit_rate = (int64_t)st->codecpar->bits_per_coded_sample * channels
                           * st->codecpar->sample_rate;
     st->codecpar->block_align = 1;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 028/281] ape: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (26 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 027/281] apc: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 029/281] apm: " James Almer
                   ` (254 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/ape.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/ape.c b/libavformat/ape.c
index b1222d9ce0..a6029affed 100644
--- a/libavformat/ape.c
+++ b/libavformat/ape.c
@@ -331,7 +331,8 @@ static int ape_read_header(AVFormatContext * s)
     st->codecpar->codec_type      = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id        = AV_CODEC_ID_APE;
     st->codecpar->codec_tag       = MKTAG('A', 'P', 'E', ' ');
-    st->codecpar->channels        = ape->channels;
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = ape->channels;
     st->codecpar->sample_rate     = ape->samplerate;
     st->codecpar->bits_per_coded_sample = ape->bps;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 029/281] apm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (27 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 028/281] ape: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 030/281] aptxdec: " James Almer
                   ` (253 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/apm.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/libavformat/apm.c b/libavformat/apm.c
index 1ced771745..6af0e1bdcb 100644
--- a/libavformat/apm.c
+++ b/libavformat/apm.c
@@ -104,6 +104,7 @@ static int apm_read_header(AVFormatContext *s)
     APMExtraData extradata;
     AVCodecParameters *par;
     uint8_t buf[APM_FILE_EXTRADATA_SIZE];
+    int channels;
 
     if (!(st = avformat_new_stream(s, NULL)))
         return AVERROR(ENOMEM);
@@ -116,7 +117,7 @@ static int apm_read_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
 
     par = st->codecpar;
-    par->channels              = avio_rl16(s->pb);
+    channels                   = avio_rl16(s->pb);
     par->sample_rate           = avio_rl32(s->pb);
 
     /* Skip the bitrate, it's usually wrong anyway. */
@@ -136,17 +137,14 @@ static int apm_read_header(AVFormatContext *s)
     if (par->bits_per_coded_sample != 4)
         return AVERROR_INVALIDDATA;
 
-    if (par->channels == 2)
-        par->channel_layout    = AV_CH_LAYOUT_STEREO;
-    else if (par->channels == 1)
-        par->channel_layout    = AV_CH_LAYOUT_MONO;
-    else
+    if (channels > 2)
         return AVERROR_INVALIDDATA;
 
+    av_channel_layout_default(&par->ch_layout, channels);
     par->codec_type            = AVMEDIA_TYPE_AUDIO;
     par->codec_id              = AV_CODEC_ID_ADPCM_IMA_APM;
     par->format                = AV_SAMPLE_FMT_S16;
-    par->bit_rate              = par->channels *
+    par->bit_rate              = par->ch_layout.nb_channels *
                                  par->sample_rate *
                                  par->bits_per_coded_sample;
 
@@ -175,7 +173,7 @@ static int apm_read_header(AVFormatContext *s)
     st->start_time  = 0;
     st->duration    = extradata.data_size *
                       (8 / par->bits_per_coded_sample) /
-                      par->channels;
+                      par->ch_layout.nb_channels;
     return 0;
 }
 
@@ -195,7 +193,7 @@ static int apm_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     pkt->flags          &= ~AV_PKT_FLAG_CORRUPT;
     pkt->stream_index   = 0;
-    pkt->duration       = ret * (8 / par->bits_per_coded_sample) / par->channels;
+    pkt->duration       = ret * (8 / par->bits_per_coded_sample) / par->ch_layout.nb_channels;
 
     return 0;
 }
@@ -227,7 +225,7 @@ static int apm_write_init(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    if (par->channels > 2) {
+    if (par->ch_layout.nb_channels > 2) {
         av_log(s, AV_LOG_ERROR, "APM files only support up to 2 channels\n");
         return AVERROR(EINVAL);
     }
@@ -260,10 +258,10 @@ static int apm_write_header(AVFormatContext *s)
      * be used because of the extra 2 bytes.
      */
     avio_wl16(s->pb, APM_TAG_CODEC);
-    avio_wl16(s->pb, par->channels);
+    avio_wl16(s->pb, par->ch_layout.nb_channels);
     avio_wl32(s->pb, par->sample_rate);
     /* This is the wrong calculation, but it's what the orginal files have. */
-    avio_wl32(s->pb, par->sample_rate * par->channels * 2);
+    avio_wl32(s->pb, par->sample_rate * par->ch_layout.nb_channels * 2);
     avio_wl16(s->pb, par->block_align);
     avio_wl16(s->pb, par->bits_per_coded_sample);
     avio_wl32(s->pb, APM_FILE_EXTRADATA_SIZE);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 030/281] aptxdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (28 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 029/281] apm: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 031/281] argo: " James Almer
                   ` (252 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/aptxdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/aptxdec.c b/libavformat/aptxdec.c
index 7153e262a1..ff1aa32bd8 100644
--- a/libavformat/aptxdec.c
+++ b/libavformat/aptxdec.c
@@ -42,7 +42,8 @@ static AVStream *aptx_read_header_common(AVFormatContext *s)
         return NULL;
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->format = AV_SAMPLE_FMT_S32P;
-    st->codecpar->channels = 2;
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = 2;
     st->codecpar->sample_rate = s1->sample_rate;
     st->start_time = 0;
     return st;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 031/281] argo: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (29 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 030/281] aptxdec: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 032/281] ast: " James Almer
                   ` (251 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/argo_asf.c | 18 ++++++++----------
 libavformat/argo_cvg.c |  5 ++---
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index 2b3569ebc3..cb598b3e04 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -96,11 +96,9 @@ int ff_argo_asf_fill_stream(AVFormatContext *s, AVStream *st, const ArgoASFFileH
     st->codecpar->format                    = AV_SAMPLE_FMT_S16P;
 
     if (ckhdr->flags & ASF_CF_STEREO) {
-        st->codecpar->channel_layout        = AV_CH_LAYOUT_STEREO;
-        st->codecpar->channels              = 2;
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     } else {
-        st->codecpar->channel_layout        = AV_CH_LAYOUT_MONO;
-        st->codecpar->channels              = 1;
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     }
 
     /* v1.1 files (FX Fighter) are all marked as 44100, but are actually 22050. */
@@ -121,11 +119,11 @@ int ff_argo_asf_fill_stream(AVFormatContext *s, AVStream *st, const ArgoASFFileH
      * (nchannel control bytes) + ((bytes_per_channel) * nchannel)
      * For mono, this is 17. For stereo, this is 34.
      */
-    st->codecpar->block_align           = st->codecpar->channels +
+    st->codecpar->block_align           = st->codecpar->ch_layout.nb_channels +
                                           (ckhdr->num_samples / 2) *
-                                          st->codecpar->channels;
+                                          st->codecpar->ch_layout.nb_channels;
 
-    st->codecpar->bit_rate              = st->codecpar->channels *
+    st->codecpar->bit_rate              = st->codecpar->ch_layout.nb_channels *
                                           st->codecpar->sample_rate *
                                           st->codecpar->bits_per_coded_sample;
 
@@ -305,12 +303,12 @@ static int argo_asf_write_init(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    if (par->channels > 2) {
+    if (par->ch_layout.nb_channels > 2) {
         av_log(s, AV_LOG_ERROR, "ASF files only support up to 2 channels\n");
         return AVERROR(EINVAL);
     }
 
-    if (par->block_align != 17 * par->channels)
+    if (par->block_align != 17 * par->ch_layout.nb_channels)
         return AVERROR(EINVAL);
 
     if (par->sample_rate > UINT16_MAX) {
@@ -392,7 +390,7 @@ static int argo_asf_write_header(AVFormatContext *s)
     chdr.unk2          = ~0;
     chdr.flags         = ASF_CF_BITS_PER_SAMPLE | ASF_CF_ALWAYS1;
 
-    if (par->channels == 2)
+    if (par->ch_layout.nb_channels == 2)
         chdr.flags |= ASF_CF_STEREO;
 
     argo_asf_write_file_header(&fhdr, s->pb);
diff --git a/libavformat/argo_cvg.c b/libavformat/argo_cvg.c
index e1854b4493..cdf13016a8 100644
--- a/libavformat/argo_cvg.c
+++ b/libavformat/argo_cvg.c
@@ -182,8 +182,7 @@ static int argo_cvg_read_header(AVFormatContext *s)
         break;
     }
 
-    par->channels               = 1;
-    par->channel_layout         = AV_CH_LAYOUT_MONO;
+    par->ch_layout              = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     par->bits_per_coded_sample  = 4;
     par->block_align            = ARGO_CVG_BLOCK_ALIGN;
@@ -275,7 +274,7 @@ static int argo_cvg_write_init(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    if (par->channels != 1) {
+    if (par->ch_layout.nb_channels != 1) {
         av_log(s, AV_LOG_ERROR, "CVG files only support 1 channel\n");
         return AVERROR(EINVAL);
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 032/281] ast: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (30 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 031/281] argo: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 033/281] au: " James Almer
                   ` (250 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/astdec.c | 18 ++++++++++--------
 libavformat/astenc.c |  4 ++--
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/libavformat/astdec.c b/libavformat/astdec.c
index 629372acf1..3d460ce827 100644
--- a/libavformat/astdec.c
+++ b/libavformat/astdec.c
@@ -57,14 +57,15 @@ static int ast_read_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
     }
 
-    st->codecpar->channels = avio_rb16(s->pb);
-    if (!st->codecpar->channels)
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_rb16(s->pb);
+    if (!st->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
 
-    if (st->codecpar->channels == 2)
-        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-    else if (st->codecpar->channels == 4)
-        st->codecpar->channel_layout = AV_CH_LAYOUT_4POINT0;
+    if (st->codecpar->ch_layout.nb_channels == 2)
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+    else if (st->codecpar->ch_layout.nb_channels == 4)
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0;
 
     avio_skip(s->pb, 2);
     st->codecpar->sample_rate = avio_rb32(s->pb);
@@ -90,10 +91,11 @@ static int ast_read_packet(AVFormatContext *s, AVPacket *pkt)
     pos  = avio_tell(s->pb);
     type = avio_rl32(s->pb);
     size = avio_rb32(s->pb);
-    if (!s->streams[0]->codecpar->channels || size > INT_MAX / s->streams[0]->codecpar->channels)
+    if (!s->streams[0]->codecpar->ch_layout.nb_channels ||
+        size > INT_MAX / s->streams[0]->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
 
-    size *= s->streams[0]->codecpar->channels;
+    size *= s->streams[0]->codecpar->ch_layout.nb_channels;
     if ((ret = avio_skip(s->pb, 24)) < 0) // padding
         return ret;
 
diff --git a/libavformat/astenc.c b/libavformat/astenc.c
index a5792e0b07..b29cfc4aaf 100644
--- a/libavformat/astenc.c
+++ b/libavformat/astenc.c
@@ -84,7 +84,7 @@ static int ast_write_header(AVFormatContext *s)
     avio_wb32(pb, 0); /* File size minus header */
     avio_wb16(pb, codec_tag);
     avio_wb16(pb, 16); /* Bit depth */
-    avio_wb16(pb, par->channels);
+    avio_wb16(pb, par->ch_layout.nb_channels);
     avio_wb16(pb, 0); /* Loop flag */
     avio_wb32(pb, par->sample_rate);
 
@@ -109,7 +109,7 @@ static int ast_write_packet(AVFormatContext *s, AVPacket *pkt)
     AVIOContext *pb = s->pb;
     ASTMuxContext *ast = s->priv_data;
     AVCodecParameters *par = s->streams[0]->codecpar;
-    int size = pkt->size / par->channels;
+    int size = pkt->size / par->ch_layout.nb_channels;
 
     if (s->streams[0]->nb_frames == 0)
         ast->fbs = size;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 033/281] au: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (31 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 032/281] ast: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 034/281] avr: " James Almer
                   ` (249 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/au.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavformat/au.c b/libavformat/au.c
index 9bd408f65c..1de941e555 100644
--- a/libavformat/au.c
+++ b/libavformat/au.c
@@ -213,13 +213,14 @@ static int au_read_header(AVFormatContext *s)
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_tag   = id;
     st->codecpar->codec_id    = codec;
-    st->codecpar->channels    = channels;
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = channels;
     st->codecpar->sample_rate = rate;
     st->codecpar->bits_per_coded_sample = bps;
     st->codecpar->bit_rate    = channels * rate * bps;
-    st->codecpar->block_align = ba ? ba : FFMAX(bps * st->codecpar->channels / 8, 1);
+    st->codecpar->block_align = ba ? ba : FFMAX(bps * channels / 8, 1);
     if (data_size != AU_UNKNOWN_SIZE)
-        st->duration = (((int64_t)data_size)<<3) / (st->codecpar->channels * (int64_t)bps);
+        st->duration = (((int64_t)data_size)<<3) / (channels * (int64_t)bps);
 
     st->start_time = 0;
     avpriv_set_pts_info(st, 64, 1, rate);
@@ -304,7 +305,7 @@ static int au_write_header(AVFormatContext *s)
     avio_wb32(pb, AU_UNKNOWN_SIZE);             /* data size */
     avio_wb32(pb, par->codec_tag);              /* codec ID */
     avio_wb32(pb, par->sample_rate);
-    avio_wb32(pb, par->channels);
+    avio_wb32(pb, par->ch_layout.nb_channels);
     avio_write(pb, annotations.str, annotations.len & ~7);
 
 fail:
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 034/281] avr: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (32 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 033/281] au: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 035/281] bethsoftvid: " James Almer
                   ` (248 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/avr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/avr.c b/libavformat/avr.c
index 6fdcf68952..14a633ea5d 100644
--- a/libavformat/avr.c
+++ b/libavformat/avr.c
@@ -52,10 +52,11 @@ static int avr_read_header(AVFormatContext *s)
     avio_skip(s->pb, 8); // sample_name
 
     chan = avio_rb16(s->pb);
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
     if (!chan) {
-        st->codecpar->channels = 1;
+        st->codecpar->ch_layout.nb_channels = 1;
     } else if (chan == 0xFFFFu) {
-        st->codecpar->channels = 2;
+        st->codecpar->ch_layout.nb_channels = 2;
     } else {
         avpriv_request_sample(s, "chan %d", chan);
         return AVERROR_PATCHWELCOME;
@@ -81,7 +82,7 @@ static int avr_read_header(AVFormatContext *s)
         return AVERROR_PATCHWELCOME;
     }
 
-    st->codecpar->block_align = bps * st->codecpar->channels / 8;
+    st->codecpar->block_align = bps * st->codecpar->ch_layout.nb_channels / 8;
 
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 035/281] bethsoftvid: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (33 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 034/281] avr: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 036/281] bfi: " James Almer
                   ` (247 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/bethsoftvid.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/bethsoftvid.c b/libavformat/bethsoftvid.c
index 65aab11ad6..cfb7d57332 100644
--- a/libavformat/bethsoftvid.c
+++ b/libavformat/bethsoftvid.c
@@ -254,8 +254,7 @@ static int vid_read_packet(AVFormatContext *s,
                 vid->audio_index                 = st->index;
                 st->codecpar->codec_type            = AVMEDIA_TYPE_AUDIO;
                 st->codecpar->codec_id              = AV_CODEC_ID_PCM_U8;
-                st->codecpar->channels              = 1;
-                st->codecpar->channel_layout        = AV_CH_LAYOUT_MONO;
+                st->codecpar->ch_layout             = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
                 st->codecpar->bits_per_coded_sample = 8;
                 st->codecpar->sample_rate           = vid->sample_rate;
                 st->codecpar->bit_rate              = 8 * st->codecpar->sample_rate;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 036/281] bfi: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (34 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 035/281] bethsoftvid: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 037/281] bink: " James Almer
                   ` (246 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/bfi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/bfi.c b/libavformat/bfi.c
index 69000118fa..a42b78b8c0 100644
--- a/libavformat/bfi.c
+++ b/libavformat/bfi.c
@@ -106,8 +106,7 @@ static int bfi_read_header(AVFormatContext * s)
     /* Set up the audio codec now... */
     astream->codecpar->codec_type      = AVMEDIA_TYPE_AUDIO;
     astream->codecpar->codec_id        = AV_CODEC_ID_PCM_U8;
-    astream->codecpar->channels        = 1;
-    astream->codecpar->channel_layout  = AV_CH_LAYOUT_MONO;
+    astream->codecpar->ch_layout       = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     astream->codecpar->bits_per_coded_sample = 8;
     astream->codecpar->bit_rate        =
         (int64_t)astream->codecpar->sample_rate * astream->codecpar->bits_per_coded_sample;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 037/281] bink: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (35 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 036/281] bfi: " James Almer
@ 2022-01-13  1:49 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 038/281] bit: " James Almer
                   ` (245 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:49 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/bink.c  | 8 +++-----
 libavformat/binka.c | 3 ++-
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/libavformat/bink.c b/libavformat/bink.c
index 6627a17e71..4f413bd986 100644
--- a/libavformat/bink.c
+++ b/libavformat/bink.c
@@ -186,11 +186,9 @@ static int read_header(AVFormatContext *s)
             ast->codecpar->codec_id = flags & BINK_AUD_USEDCT ?
                                    AV_CODEC_ID_BINKAUDIO_DCT : AV_CODEC_ID_BINKAUDIO_RDFT;
             if (flags & BINK_AUD_STEREO) {
-                ast->codecpar->channels       = 2;
-                ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+                ast->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
             } else {
-                ast->codecpar->channels       = 1;
-                ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+                ast->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
             }
             if ((ret = ff_alloc_extradata(ast->codecpar, 4)) < 0)
                 return ret;
@@ -283,7 +281,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
                (in bytes). We use this value to calculate the audio PTS */
             if (pkt->size >= 4)
                 bink->audio_pts[bink->current_track -1] +=
-                    AV_RL32(pkt->data) / (2 * s->streams[bink->current_track]->codecpar->channels);
+                    AV_RL32(pkt->data) / (2 * s->streams[bink->current_track]->codecpar->ch_layout.nb_channels);
             return 0;
         } else {
             avio_skip(pb, audio_size);
diff --git a/libavformat/binka.c b/libavformat/binka.c
index d4cfee0368..babd5e240a 100644
--- a/libavformat/binka.c
+++ b/libavformat/binka.c
@@ -44,7 +44,8 @@ static int binka_read_header(AVFormatContext *s)
 
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = AV_CODEC_ID_BINKAUDIO_DCT;
-    st->codecpar->channels = avio_r8(pb);
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_r8(pb);
     st->codecpar->sample_rate = avio_rl16(pb);
     st->duration = avio_rl32(pb);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 038/281] bit: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (36 preceding siblings ...)
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 037/281] bink: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 039/281] bmv: " James Almer
                   ` (244 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/bit.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/bit.c b/libavformat/bit.c
index 380cbd37cd..c8d02c6bb8 100644
--- a/libavformat/bit.c
+++ b/libavformat/bit.c
@@ -63,7 +63,8 @@ static int read_header(AVFormatContext *s)
     st->codecpar->codec_id=AV_CODEC_ID_G729;
     st->codecpar->sample_rate=8000;
     st->codecpar->block_align = 16;
-    st->codecpar->channels=1;
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = 1;
 
     avpriv_set_pts_info(st, 64, 1, 100);
     return 0;
@@ -124,14 +125,14 @@ static int write_header(AVFormatContext *s)
 {
     AVCodecParameters *par = s->streams[0]->codecpar;
 
-    if ((par->codec_id != AV_CODEC_ID_G729) || par->channels != 1) {
+    if ((par->codec_id != AV_CODEC_ID_G729) || par->ch_layout.nb_channels != 1) {
         av_log(s, AV_LOG_ERROR,
                "only codec g729 with 1 channel is supported by this format\n");
         return AVERROR(EINVAL);
     }
 
     par->bits_per_coded_sample = 16;
-    par->block_align = (par->bits_per_coded_sample * par->channels) >> 3;
+    par->block_align = (par->bits_per_coded_sample * par->ch_layout.nb_channels) >> 3;
 
     return 0;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 039/281] bmv: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (37 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 038/281] bit: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 040/281] boa: " James Almer
                   ` (243 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/bmv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/bmv.c b/libavformat/bmv.c
index 873ecb027c..e1f667076e 100644
--- a/libavformat/bmv.c
+++ b/libavformat/bmv.c
@@ -58,8 +58,7 @@ static int bmv_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
     ast->codecpar->codec_type      = AVMEDIA_TYPE_AUDIO;
     ast->codecpar->codec_id        = AV_CODEC_ID_BMV_AUDIO;
-    ast->codecpar->channels        = 2;
-    ast->codecpar->channel_layout  = AV_CH_LAYOUT_STEREO;
+    ast->codecpar->ch_layout       = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     ast->codecpar->sample_rate     = 22050;
     avpriv_set_pts_info(ast, 16, 1, 22050);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 040/281] boa: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (38 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 039/281] bmv: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 041/281] brstm: " James Almer
                   ` (242 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/boadec.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavformat/boadec.c b/libavformat/boadec.c
index 536300a895..a5104bbed0 100644
--- a/libavformat/boadec.c
+++ b/libavformat/boadec.c
@@ -55,15 +55,17 @@ static int read_header(AVFormatContext *s)
     avio_rl32(s->pb);
     avio_rl32(s->pb);
     st->codecpar->sample_rate = avio_rl32(s->pb);
-    st->codecpar->channels    = avio_rl32(s->pb);
-    if (st->codecpar->channels > FF_SANE_NB_CHANNELS || st->codecpar->channels <= 0)
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels    = avio_rl32(s->pb);
+    if (st->codecpar->ch_layout.nb_channels > FF_SANE_NB_CHANNELS ||
+        st->codecpar->ch_layout.order <= 0)
         return AVERROR(ENOSYS);
     ffformatcontext(s)->data_offset = data_offset = avio_rl32(s->pb);
     avio_r8(s->pb);
     st->codecpar->block_align = avio_rl32(s->pb);
     if (st->codecpar->block_align > INT_MAX / FF_SANE_NB_CHANNELS || st->codecpar->block_align <= 0)
         return AVERROR_INVALIDDATA;
-    st->codecpar->block_align *= st->codecpar->channels;
+    st->codecpar->block_align *= st->codecpar->ch_layout.nb_channels;
 
     avio_seek(s->pb, data_offset, SEEK_SET);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 041/281] brstm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (39 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 040/281] boa: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 042/281] caf: " James Almer
                   ` (241 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/brstm.c | 44 +++++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/libavformat/brstm.c b/libavformat/brstm.c
index 338491d9ef..89d5dcc344 100644
--- a/libavformat/brstm.c
+++ b/libavformat/brstm.c
@@ -209,8 +209,9 @@ static int read_header(AVFormatContext *s)
 
     loop = avio_r8(s->pb); // loop flag
     st->codecpar->codec_id = codec;
-    st->codecpar->channels = avio_r8(s->pb);
-    if (!st->codecpar->channels)
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_r8(s->pb);
+    if (!st->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
 
     avio_skip(s->pb, 1); // padding
@@ -246,14 +247,14 @@ static int read_header(AVFormatContext *s)
     }
 
     b->block_size = read32(s);
-    if (b->block_size > UINT32_MAX / st->codecpar->channels)
+    if (b->block_size > UINT32_MAX / st->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
 
     b->samples_per_block = read32(s);
     b->last_block_used_bytes = read32(s);
     b->last_block_samples = read32(s);
     b->last_block_size = read32(s);
-    if (b->last_block_size > UINT32_MAX / st->codecpar->channels)
+    if (b->last_block_size > UINT32_MAX / st->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
     if (b->last_block_used_bytes > b->last_block_size)
         return AVERROR_INVALIDDATA;
@@ -266,24 +267,24 @@ static int read_header(AVFormatContext *s)
         if (!bfstm)
             toffset = read32(s) + 16LL;
         else
-            toffset = toffset + read32(s) + st->codecpar->channels * 8 - 8;
+            toffset = toffset + read32(s) + st->codecpar->ch_layout.nb_channels * 8 - 8;
         if (toffset > size)
             return AVERROR_INVALIDDATA;
 
         if (!bfstm) {
-            avio_skip(s->pb, pos + toffset - avio_tell(s->pb) - 8LL * (st->codecpar->channels + 1));
-            for (ch = 0; ch < st->codecpar->channels; ch++) {
+            avio_skip(s->pb, pos + toffset - avio_tell(s->pb) - 8LL * (st->codecpar->ch_layout.nb_channels + 1));
+            for (ch = 0; ch < st->codecpar->ch_layout.nb_channels; ch++) {
                 avio_skip(s->pb, 4);
                 b->offsets[ch].channel = ch;
                 b->offsets[ch].offset = read32(s);
             }
 
-            qsort(b->offsets, st->codecpar->channels, sizeof(*b->offsets), sort_offsets);
+            qsort(b->offsets, st->codecpar->ch_layout.nb_channels, sizeof(*b->offsets), sort_offsets);
         }
 
         avio_skip(s->pb, pos + toffset - avio_tell(s->pb));
 
-        for (ch = 0; ch < st->codecpar->channels; ch++) {
+        for (ch = 0; ch < st->codecpar->ch_layout.nb_channels; ch++) {
             if (!bfstm)
                 avio_skip(s->pb, pos + 16LL + b->offsets[ch].offset - avio_tell(s->pb));
 
@@ -313,7 +314,7 @@ static int read_header(AVFormatContext *s)
                 codec != AV_CODEC_ID_ADPCM_THP_LE)
                 goto skip;
 
-            asize = b->block_count * st->codecpar->channels * 4;
+            asize = b->block_count * st->codecpar->ch_layout.nb_channels * 4;
             if (size < asize)
                 return AVERROR_INVALIDDATA;
             if (b->adpc) {
@@ -369,6 +370,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
     AVCodecParameters *par = s->streams[0]->codecpar;
     BRSTMDemuxContext *b = s->priv_data;
     uint32_t samples, size, skip = 0;
+    int channels = par->ch_layout.nb_channels;
     int ret, i;
 
     if (avio_feof(s->pb))
@@ -404,24 +406,24 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
         }
 
         if (size > (INT_MAX - 32 - 4) ||
-            (32 + 4 + size) > (INT_MAX / par->channels) ||
-            (32 + 4 + size) * par->channels > INT_MAX - 8)
+            (32 + 4 + size) > (INT_MAX / channels) ||
+            (32 + 4 + size) * channels > INT_MAX - 8)
             return AVERROR_INVALIDDATA;
-        if ((ret = av_new_packet(pkt, 8 + (32 + 4 + size) * par->channels)) < 0)
+        if ((ret = av_new_packet(pkt, 8 + (32 + 4 + size) * channels)) < 0)
             return ret;
         dst = pkt->data;
         if (par->codec_id == AV_CODEC_ID_ADPCM_THP_LE) {
-            bytestream_put_le32(&dst, size * par->channels);
+            bytestream_put_le32(&dst, size * channels);
             bytestream_put_le32(&dst, samples);
         } else {
-            bytestream_put_be32(&dst, size * par->channels);
+            bytestream_put_be32(&dst, size * channels);
             bytestream_put_be32(&dst, samples);
         }
-        bytestream_put_buffer(&dst, b->table, 32 * par->channels);
-        bytestream_put_buffer(&dst, b->adpc + 4 * par->channels *
-                                    (b->current_block - 1), 4 * par->channels);
+        bytestream_put_buffer(&dst, b->table, 32 * channels);
+        bytestream_put_buffer(&dst, b->adpc + 4 * channels *
+                                    (b->current_block - 1), 4 * channels);
 
-        for (i = 0; i < par->channels; i++) {
+        for (i = 0; i < channels; i++) {
             ret = avio_read(s->pb, dst, size);
             dst += size;
             avio_skip(s->pb, skip);
@@ -431,7 +433,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
         }
         pkt->duration = samples;
     } else {
-        size *= par->channels;
+        size *= channels;
         ret = av_get_packet(s->pb, pkt, size);
     }
 
@@ -456,7 +458,7 @@ static int read_seek(AVFormatContext *s, int stream_index,
     if (timestamp >= b->block_count)
         timestamp = b->block_count - 1;
     ret = avio_seek(s->pb, b->data_start + timestamp * b->block_size *
-                           st->codecpar->channels, SEEK_SET);
+                           st->codecpar->ch_layout.nb_channels, SEEK_SET);
     if (ret < 0)
         return ret;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 042/281] caf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (40 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 041/281] brstm: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 043/281] cdxl: " James Almer
                   ` (240 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/cafdec.c |  7 ++++---
 libavformat/cafenc.c | 12 ++++++------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index 4b5b15b58d..6d57bc4058 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -76,10 +76,11 @@ static int read_desc_chunk(AVFormatContext *s)
     caf->bytes_per_packet  = avio_rb32(pb);
     st->codecpar->block_align = caf->bytes_per_packet;
     caf->frames_per_packet = avio_rb32(pb);
-    st->codecpar->channels    = avio_rb32(pb);
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_rb32(pb);
     st->codecpar->bits_per_coded_sample = avio_rb32(pb);
 
-    if (caf->bytes_per_packet < 0 || caf->frames_per_packet < 0 || st->codecpar->channels < 0)
+    if (caf->bytes_per_packet < 0 || caf->frames_per_packet < 0 || st->codecpar->ch_layout.nb_channels < 0)
         return AVERROR_INVALIDDATA;
 
     /* calculate bit rate for constant size packets */
@@ -172,7 +173,7 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size)
     } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) {
         // The data layout for Opus is currently unknown, so we do not export
         // extradata at all. Multichannel streams are not supported.
-        if (st->codecpar->channels > 2) {
+        if (st->codecpar->ch_layout.nb_channels > 2) {
             avpriv_request_sample(s, "multichannel Opus in CAF");
             return AVERROR_PATCHWELCOME;
         }
diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c
index 412b3230e3..396e946ceb 100644
--- a/libavformat/cafenc.c
+++ b/libavformat/cafenc.c
@@ -122,7 +122,7 @@ static int caf_write_header(AVFormatContext *s)
         return AVERROR_PATCHWELCOME;
     }
 
-    if (par->codec_id == AV_CODEC_ID_OPUS && par->channels > 2) {
+    if (par->codec_id == AV_CODEC_ID_OPUS && par->ch_layout.nb_channels > 2) {
         av_log(s, AV_LOG_ERROR, "Only mono and stereo are supported for Opus\n");
         return AVERROR_INVALIDDATA;
     }
@@ -138,7 +138,7 @@ static int caf_write_header(AVFormatContext *s)
     }
 
     if (par->codec_id != AV_CODEC_ID_MP3 || frame_size != 576)
-        frame_size = samples_per_packet(par->codec_id, par->channels, par->block_align);
+        frame_size = samples_per_packet(par->codec_id, par->ch_layout.nb_channels, par->block_align);
 
     ffio_wfourcc(pb, "caff"); //< mFileType
     avio_wb16(pb, 1);         //< mFileVersion
@@ -151,13 +151,13 @@ static int caf_write_header(AVFormatContext *s)
     avio_wb32(pb, codec_flags(par->codec_id));        //< mFormatFlags
     avio_wb32(pb, par->block_align);                  //< mBytesPerPacket
     avio_wb32(pb, frame_size);                        //< mFramesPerPacket
-    avio_wb32(pb, par->channels);                     //< mChannelsPerFrame
+    avio_wb32(pb, par->ch_layout.nb_channels);        //< mChannelsPerFrame
     avio_wb32(pb, av_get_bits_per_sample(par->codec_id)); //< mBitsPerChannel
 
-    if (par->channel_layout) {
+    if (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) {
         ffio_wfourcc(pb, "chan");
         avio_wb64(pb, 12);
-        ff_mov_write_chan(pb, par->channel_layout);
+        ff_mov_write_chan(pb, par->ch_layout.u.mask);
     }
 
     if (par->codec_id == AV_CODEC_ID_ALAC) {
@@ -247,7 +247,7 @@ static int caf_write_trailer(AVFormatContext *s)
         avio_seek(pb, caf->data, SEEK_SET);
         avio_wb64(pb, file_size - caf->data - 8);
         if (!par->block_align) {
-            int packet_size = samples_per_packet(par->codec_id, par->channels, par->block_align);
+            int packet_size = samples_per_packet(par->codec_id, par->ch_layout.nb_channels, par->block_align);
             if (!packet_size) {
                 packet_size = st->duration / (caf->packets - 1);
                 avio_seek(pb, FRAME_SIZE_OFFSET, SEEK_SET);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 043/281] cdxl: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (41 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 042/281] caf: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-26 13:53   ` Anton Khirnov
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 044/281] codec2: " James Almer
                   ` (239 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/cdxl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/cdxl.c b/libavformat/cdxl.c
index c42e0d3545..76dc1d18c9 100644
--- a/libavformat/cdxl.c
+++ b/libavformat/cdxl.c
@@ -171,6 +171,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     if (cdxl->read_chunk && audio_size) {
         if (cdxl->audio_stream_index == -1) {
+            int channels = !!(cdxl->header[1] & 0x10) + 1;
             AVStream *st = avformat_new_stream(s, NULL);
             if (!st)
                 return AVERROR(ENOMEM);
@@ -178,8 +179,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
             st->codecpar->codec_type    = AVMEDIA_TYPE_AUDIO;
             st->codecpar->codec_tag     = 0;
             st->codecpar->codec_id      = AV_CODEC_ID_PCM_S8_PLANAR;
-            st->codecpar->channels      = channels;
-            st->codecpar->channel_layout = channels == 2 ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
+            av_channel_layout_default(&st->codecpar->ch_layout, channels);
             st->codecpar->sample_rate= cdxl->srate;
             st->start_time           = 0;
             cdxl->audio_stream_index = st->index;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 044/281] codec2: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (42 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 043/281] cdxl: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 045/281] dash: " James Almer
                   ` (238 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/codec2.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/codec2.c b/libavformat/codec2.c
index 0b992836b3..9d7f424292 100644
--- a/libavformat/codec2.c
+++ b/libavformat/codec2.c
@@ -129,9 +129,8 @@ static int codec2_read_header_common(AVFormatContext *s, AVStream *st)
     st->codecpar->codec_type        = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id          = AV_CODEC_ID_CODEC2;
     st->codecpar->sample_rate       = 8000;
-    st->codecpar->channels          = 1;
     st->codecpar->format            = AV_SAMPLE_FMT_S16;
-    st->codecpar->channel_layout    = AV_CH_LAYOUT_MONO;
+    st->codecpar->ch_layout         = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     st->codecpar->bit_rate          = codec2_mode_bit_rate(s, mode);
     st->codecpar->frame_size        = codec2_mode_frame_size(s, mode);
     st->codecpar->block_align       = codec2_mode_block_align(s, mode);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 045/281] dash: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (43 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 044/281] codec2: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-26 13:56   ` Anton Khirnov
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 046/281] dcstr: " James Almer
                   ` (237 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/dashenc.c | 2 +-
 libavformat/dauddec.c | 3 +--
 libavformat/daudenc.c | 2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 4709bc6615..9a97838f5c 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -859,7 +859,7 @@ static int write_adaptation_set(AVFormatContext *s, AVIOContext *out, int as_ind
             avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"audio/%s\" codecs=\"%s\"%s audioSamplingRate=\"%d\">\n",
                 i, os->format_name, os->codec_str, bandwidth_str, s->streams[i]->codecpar->sample_rate);
             avio_printf(out, "\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n",
-                s->streams[i]->codecpar->channels);
+                s->streams[i]->codecpar->ch_layout.nb_channels);
         }
         if (!final && c->write_prft && os->producer_reference_time_str[0]) {
             avio_printf(out, "\t\t\t\t<ProducerReferenceTime id=\"%d\" inband=\"true\" type=\"%s\" wallClockTime=\"%s\" presentationTime=\"%"PRId64"\">\n",
diff --git a/libavformat/dauddec.c b/libavformat/dauddec.c
index 6a5962c238..dbbd39a3b4 100644
--- a/libavformat/dauddec.c
+++ b/libavformat/dauddec.c
@@ -29,8 +29,7 @@ static int daud_header(AVFormatContext *s) {
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = AV_CODEC_ID_PCM_S24DAUD;
     st->codecpar->codec_tag = MKTAG('d', 'a', 'u', 'd');
-    st->codecpar->channels = 6;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_5POINT1;
+    st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1;
     st->codecpar->sample_rate = 96000;
     st->codecpar->bit_rate = 3 * 6 * 96000 * 8;
     st->codecpar->block_align = 3 * 6;
diff --git a/libavformat/daudenc.c b/libavformat/daudenc.c
index 183a08ba30..2e252449e9 100644
--- a/libavformat/daudenc.c
+++ b/libavformat/daudenc.c
@@ -24,7 +24,7 @@
 static int daud_init(struct AVFormatContext *s)
 {
     AVCodecParameters *par = s->streams[0]->codecpar;
-    if (par->channels!=6 || par->sample_rate!=96000)
+    if (par->ch_layout.nb_channels != 6 || par->sample_rate != 96000)
         return AVERROR(EINVAL);
     return 0;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 046/281] dcstr: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (44 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 045/281] dash: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 047/281] derf: " James Almer
                   ` (236 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/dcstr.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavformat/dcstr.c b/libavformat/dcstr.c
index 71dce08bf7..10f41ebf4e 100644
--- a/libavformat/dcstr.c
+++ b/libavformat/dcstr.c
@@ -41,7 +41,8 @@ static int dcstr_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
 
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels    = avio_rl32(s->pb);
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_rl32(s->pb);
     st->codecpar->sample_rate = avio_rl32(s->pb);
     if (st->codecpar->sample_rate <= 0)
         return AVERROR_INVALIDDATA;
@@ -50,14 +51,16 @@ static int dcstr_read_header(AVFormatContext *s)
     avio_skip(s->pb, 4);
     st->duration           = avio_rl32(s->pb);
     mult                   = avio_rl32(s->pb);
-    if (st->codecpar->channels <= 0 || mult <= 0 || mult > INT_MAX / st->codecpar->channels) {
-        av_log(s, AV_LOG_ERROR, "invalid number of channels %d x %d\n", st->codecpar->channels, mult);
+    if (st->codecpar->ch_layout.nb_channels <= 0 || mult <= 0 ||
+        mult > INT_MAX / st->codecpar->ch_layout.nb_channels) {
+        av_log(s, AV_LOG_ERROR, "invalid number of channels %d x %d\n",
+               st->codecpar->ch_layout.nb_channels, mult);
         return AVERROR_INVALIDDATA;
     }
-    st->codecpar->channels *= mult;
-    if (!align || align > INT_MAX / st->codecpar->channels)
+    st->codecpar->ch_layout.nb_channels *= mult;
+    if (!align || align > INT_MAX / st->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
-    st->codecpar->block_align = align * st->codecpar->channels;
+    st->codecpar->block_align = align * st->codecpar->ch_layout.nb_channels;
 
     switch (codec) {
     case  4: st->codecpar->codec_id = AV_CODEC_ID_ADPCM_AICA;       break;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 047/281] derf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (45 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 046/281] dcstr: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 048/281] dhav: " James Almer
                   ` (235 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/derf.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/libavformat/derf.c b/libavformat/derf.c
index d50a853194..9da7fc4f19 100644
--- a/libavformat/derf.c
+++ b/libavformat/derf.c
@@ -38,6 +38,7 @@ static int derf_probe(const AVProbeData *p)
 static int derf_read_header(AVFormatContext *s)
 {
     unsigned data_size;
+    int channels;
     AVIOContext *pb = s->pb;
     AVCodecParameters *par;
     AVStream *st;
@@ -52,15 +53,12 @@ static int derf_read_header(AVFormatContext *s)
     par->codec_type  = AVMEDIA_TYPE_AUDIO;
     par->codec_id    = AV_CODEC_ID_DERF_DPCM;
     par->format      = AV_SAMPLE_FMT_S16;
-    par->channels    = avio_rl32(pb);
-    if (par->channels != 1 && par->channels != 2)
+    channels         = avio_rl32(pb);
+    if (channels != 1 && channels != 2)
         return AVERROR_INVALIDDATA;
-    if (par->channels == 1)
-        par->channel_layout = AV_CH_LAYOUT_MONO;
-    else if (par->channels == 2)
-        par->channel_layout = AV_CH_LAYOUT_STEREO;
+    av_channel_layout_default(&par->ch_layout, channels);
     data_size = avio_rl32(pb);
-    st->duration = data_size / par->channels;
+    st->duration = data_size / channels;
     par->sample_rate = 22050;
     par->block_align = 1;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 048/281] dhav: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (46 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 047/281] derf: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 049/281] dtshddec: " James Almer
                   ` (234 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/dhav.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/dhav.c b/libavformat/dhav.c
index 6c1cdde32c..935f805632 100644
--- a/libavformat/dhav.c
+++ b/libavformat/dhav.c
@@ -395,7 +395,8 @@ retry:
         default: avpriv_request_sample(s, "Unknown audio codec %X", dhav->audio_codec);
         }
         st->duration              = dhav->duration;
-        st->codecpar->channels    = dhav->audio_channels;
+        st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = dhav->audio_channels;
         st->codecpar->sample_rate = dhav->sample_rate;
         st->priv_data = dst = av_mallocz(sizeof(DHAVStream));
         if (!st->priv_data)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 049/281] dtshddec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (47 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 048/281] dhav: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 050/281] dsicin: " James Almer
                   ` (233 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/dtshddec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/dtshddec.c b/libavformat/dtshddec.c
index b84588af7c..a3b3b92055 100644
--- a/libavformat/dtshddec.c
+++ b/libavformat/dtshddec.c
@@ -104,7 +104,8 @@ static int dtshd_read_header(AVFormatContext *s)
             duration *= avio_rb16(pb); // samples_per_frames
             st->duration = duration;
             avio_skip(pb, 5);
-            st->codecpar->channels = ff_dca_count_chs_for_mask(avio_rb16(pb));
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = ff_dca_count_chs_for_mask(avio_rb16(pb));
             st->codecpar->initial_padding = avio_rb16(pb);
             avio_skip(pb, chunk_size - 21);
             break;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 050/281] dsicin: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (48 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 049/281] dtshddec: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 051/281] dshow: " James Almer
                   ` (232 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/dsicin.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/dsicin.c b/libavformat/dsicin.c
index 481f365a53..13ee9f87bb 100644
--- a/libavformat/dsicin.c
+++ b/libavformat/dsicin.c
@@ -132,11 +132,12 @@ static int cin_read_header(AVFormatContext *s)
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = AV_CODEC_ID_DSICINAUDIO;
     st->codecpar->codec_tag = 0;  /* no tag */
-    st->codecpar->channels = 1;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     st->codecpar->sample_rate = 22050;
     st->codecpar->bits_per_coded_sample = 8;
-    st->codecpar->bit_rate = st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample * st->codecpar->channels;
+    st->codecpar->bit_rate = st->codecpar->sample_rate *
+                             st->codecpar->bits_per_coded_sample *
+                             st->codecpar->ch_layout.nb_channels;
 
     return 0;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 051/281] dshow: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (49 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 050/281] dsicin: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 052/281] dss: " James Almer
                   ` (231 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavdevice/dshow.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index 3a16f3720f..c0a060dc0c 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -1632,7 +1632,8 @@ dshow_add_device(AVFormatContext *avctx,
         par->format      = sample_fmt_bits_per_sample(fmt_info->sample_size);
         par->codec_id    = waveform_codec_id(par->format);
         par->sample_rate = fmt_info->sample_rate;
-        par->channels    = fmt_info->channels;
+        par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        par->ch_layout.nb_channels = fmt_info->channels;
     }
 
     avpriv_set_pts_info(st, 64, 1, 10000000);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 052/281] dss: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (50 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 051/281] dshow: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 053/281] dsfdec: " James Almer
                   ` (230 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/dss.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/dss.c b/libavformat/dss.c
index ee3a099a95..d619ea00d7 100644
--- a/libavformat/dss.c
+++ b/libavformat/dss.c
@@ -155,8 +155,7 @@ static int dss_read_header(AVFormatContext *s)
     }
 
     st->codecpar->codec_type     = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
-    st->codecpar->channels       = 1;
+    st->codecpar->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
     st->start_time = 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 053/281] dsfdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (51 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 052/281] dss: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 054/281] dv: " James Almer
                   ` (229 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/dsfdec.c | 60 ++++++++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 25 deletions(-)

diff --git a/libavformat/dsfdec.c b/libavformat/dsfdec.c
index 40c8210a0f..3c00b07ff1 100644
--- a/libavformat/dsfdec.c
+++ b/libavformat/dsfdec.c
@@ -38,15 +38,15 @@ static int dsf_probe(const AVProbeData *p)
     return AVPROBE_SCORE_MAX;
 }
 
-static const uint64_t dsf_channel_layout[] = {
-    0,
-    AV_CH_LAYOUT_MONO,
-    AV_CH_LAYOUT_STEREO,
-    AV_CH_LAYOUT_SURROUND,
-    AV_CH_LAYOUT_QUAD,
-    AV_CH_LAYOUT_4POINT0,
-    AV_CH_LAYOUT_5POINT0_BACK,
-    AV_CH_LAYOUT_5POINT1_BACK,
+static const AVChannelLayout dsf_channel_layout[] = {
+    { .order = AV_CHANNEL_ORDER_UNSPEC },
+    AV_CHANNEL_LAYOUT_MONO,
+    AV_CHANNEL_LAYOUT_STEREO,
+    AV_CHANNEL_LAYOUT_SURROUND,
+    AV_CHANNEL_LAYOUT_QUAD,
+    AV_CHANNEL_LAYOUT_4POINT0,
+    AV_CHANNEL_LAYOUT_5POINT0_BACK,
+    AV_CHANNEL_LAYOUT_5POINT1_BACK,
 };
 
 static void read_id3(AVFormatContext *s, uint64_t id3pos)
@@ -70,6 +70,7 @@ static int dsf_read_header(AVFormatContext *s)
     AVStream *st;
     uint64_t id3pos;
     unsigned int channel_type;
+    int channels;
 
     avio_skip(pb, 4);
     if (avio_rl64(pb) != 28)
@@ -104,15 +105,22 @@ static int dsf_read_header(AVFormatContext *s)
 
     channel_type = avio_rl32(pb);
     if (channel_type < FF_ARRAY_ELEMS(dsf_channel_layout))
-        st->codecpar->channel_layout = dsf_channel_layout[channel_type];
-    if (!st->codecpar->channel_layout)
+        st->codecpar->ch_layout = dsf_channel_layout[channel_type];
+    if (!st->codecpar->ch_layout.nb_channels)
         avpriv_request_sample(s, "channel type %i", channel_type);
 
     st->codecpar->codec_type   = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels     = avio_rl32(pb);
+    channels = avio_rl32(pb);
+    if (!st->codecpar->ch_layout.nb_channels) {
+        st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = channels;
+    } else if (channels != st->codecpar->ch_layout.nb_channels) {
+        av_log(s, AV_LOG_ERROR, "Channel count mismatch\n");
+        return AVERROR(EINVAL);
+    }
     st->codecpar->sample_rate  = avio_rl32(pb) / 8;
 
-    if (st->codecpar->channels <= 0)
+    if (st->codecpar->ch_layout.nb_channels <= 0)
         return AVERROR_INVALIDDATA;
 
     switch(avio_rl32(pb)) {
@@ -123,14 +131,15 @@ static int dsf_read_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
     }
 
-    dsf->audio_size = avio_rl64(pb) / 8 * st->codecpar->channels;
+    dsf->audio_size = avio_rl64(pb) / 8 * st->codecpar->ch_layout.nb_channels;
     st->codecpar->block_align = avio_rl32(pb);
-    if (st->codecpar->block_align > INT_MAX / st->codecpar->channels || st->codecpar->block_align <= 0) {
+    if (st->codecpar->block_align > INT_MAX / st->codecpar->ch_layout.nb_channels ||
+        st->codecpar->block_align <= 0) {
         avpriv_request_sample(s, "block_align invalid");
         return AVERROR_INVALIDDATA;
     }
-    st->codecpar->block_align *= st->codecpar->channels;
-    st->codecpar->bit_rate = st->codecpar->channels * 8LL * st->codecpar->sample_rate;
+    st->codecpar->block_align *= st->codecpar->ch_layout.nb_channels;
+    st->codecpar->bit_rate = st->codecpar->ch_layout.nb_channels * 8LL * st->codecpar->sample_rate;
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
     avio_skip(pb, 4);
 
@@ -152,6 +161,7 @@ static int dsf_read_packet(AVFormatContext *s, AVPacket *pkt)
     AVIOContext *pb = s->pb;
     AVStream *st = s->streams[0];
     int64_t pos = avio_tell(pb);
+    int channels = st->codecpar->ch_layout.nb_channels;
     int ret;
 
     if (pos >= dsf->data_end)
@@ -173,19 +183,19 @@ static int dsf_read_packet(AVFormatContext *s, AVPacket *pkt)
             if ((ret = av_new_packet(pkt, packet_size)) < 0)
                 return ret;
             dst = pkt->data;
-            for (ch = 0; ch < st->codecpar->channels; ch++) {
-                ret = avio_read(pb, dst,  packet_size / st->codecpar->channels);
-                if (ret < packet_size / st->codecpar->channels)
+            for (ch = 0; ch < st->codecpar->ch_layout.nb_channels; ch++) {
+                ret = avio_read(pb, dst,  packet_size / st->codecpar->ch_layout.nb_channels);
+                if (ret < packet_size / st->codecpar->ch_layout.nb_channels)
                     return AVERROR_EOF;
 
                 dst += ret;
-                avio_skip(pb, skip_size / st->codecpar->channels);
+                avio_skip(pb, skip_size / st->codecpar->ch_layout.nb_channels);
             }
 
             pkt->pos = pos;
             pkt->stream_index = 0;
-            pkt->pts = (pos - si->data_offset) / st->codecpar->channels;
-            pkt->duration = packet_size / st->codecpar->channels;
+            pkt->pts = (pos - si->data_offset) / channels;
+            pkt->duration = packet_size / channels;
             return 0;
         }
     }
@@ -194,8 +204,8 @@ static int dsf_read_packet(AVFormatContext *s, AVPacket *pkt)
         return ret;
 
     pkt->stream_index = 0;
-    pkt->pts = (pos - si->data_offset) / st->codecpar->channels;
-    pkt->duration = st->codecpar->block_align / st->codecpar->channels;
+    pkt->pts = (pos - si->data_offset) / channels;
+    pkt->duration = st->codecpar->block_align / channels;
 
     return 0;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 054/281] dv: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (52 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 053/281] dsfdec: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 055/281] eac: " James Almer
                   ` (228 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/dv.c    | 3 +--
 libavformat/dvenc.c | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/dv.c b/libavformat/dv.c
index 77a6ede37b..1dadaf6e62 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -281,8 +281,7 @@ static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame)
             c->audio_pkt[i].pos          = -1;
         }
         c->ast[i]->codecpar->sample_rate    = dv_audio_frequency[freq];
-        c->ast[i]->codecpar->channels       = 2;
-        c->ast[i]->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+        c->ast[i]->codecpar->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
         c->ast[i]->codecpar->bit_rate       = 2 * dv_audio_frequency[freq] * 16;
         c->ast[i]->start_time            = 0;
     }
diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index b76539b59f..6e5e6c6a36 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -329,7 +329,7 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s)
             if (c->n_ast > 1) return NULL;
             /* Some checks -- DV format is very picky about its incoming streams */
             if(st->codecpar->codec_id    != AV_CODEC_ID_PCM_S16LE ||
-               st->codecpar->channels    != 2)
+               st->codecpar->ch_layout.nb_channels    != 2)
                 goto bail_out;
             if (st->codecpar->sample_rate != 48000 &&
                 st->codecpar->sample_rate != 44100 &&
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 055/281] eac: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (53 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 054/281] dv: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 056/281] electronicarts: " James Almer
                   ` (227 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/eacdata.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/libavformat/eacdata.c b/libavformat/eacdata.c
index 0ad1c937a9..ebc98d274f 100644
--- a/libavformat/eacdata.c
+++ b/libavformat/eacdata.c
@@ -32,6 +32,8 @@
 #include "avformat.h"
 #include "internal.h"
 
+#include "libavutil/channel_layout.h"
+
 typedef struct CdataDemuxContext {
   unsigned int channels;
   unsigned int audio_pts;
@@ -52,18 +54,25 @@ static int cdata_read_header(AVFormatContext *s)
     AVIOContext *pb = s->pb;
     unsigned int sample_rate, header;
     AVStream *st;
-    int64_t channel_layout = 0;
+    AVChannelLayout channel_layout;
 
     header = avio_rb16(pb);
     switch (header) {
-        case 0x0400: cdata->channels = 1; break;
-        case 0x0404: cdata->channels = 2; break;
-        case 0x040C: cdata->channels = 4; channel_layout = AV_CH_LAYOUT_QUAD;         break;
-        case 0x0414: cdata->channels = 6; channel_layout = AV_CH_LAYOUT_5POINT1_BACK; break;
+        case 0x0400:
+            channel_layout = (AVChannelLayout){ .nb_channels = 1, .order = AV_CHANNEL_ORDER_UNSPEC };
+            break;
+        case 0x0404:
+            channel_layout  = (AVChannelLayout){ .nb_channels = 2, .order = AV_CHANNEL_ORDER_UNSPEC };
+            break;
+        case 0x040C:
+            channel_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD;         break;
+        case 0x0414:
+            channel_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK; break;
         default:
             av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
             return -1;
     };
+    cdata->channels = channel_layout.nb_channels;
 
     sample_rate = avio_rb16(pb);
     avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11);
@@ -74,8 +83,7 @@ static int cdata_read_header(AVFormatContext *s)
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_tag = 0; /* no fourcc */
     st->codecpar->codec_id = AV_CODEC_ID_ADPCM_EA_XAS;
-    st->codecpar->channels = cdata->channels;
-    st->codecpar->channel_layout = channel_layout;
+    st->codecpar->ch_layout = channel_layout;
     st->codecpar->sample_rate = sample_rate;
     avpriv_set_pts_info(st, 64, 1, sample_rate);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 056/281] electronicarts: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (54 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 055/281] eac: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 057/281] epafdec: " James Almer
                   ` (226 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/electronicarts.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c
index 2fb09b34ca..811f8705e5 100644
--- a/libavformat/electronicarts.c
+++ b/libavformat/electronicarts.c
@@ -551,13 +551,14 @@ static int ea_read_header(AVFormatContext *s)
         st->codecpar->codec_type            = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id              = ea->audio_codec;
         st->codecpar->codec_tag             = 0;   /* no tag */
-        st->codecpar->channels              = ea->num_channels;
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = ea->num_channels;
         st->codecpar->sample_rate           = ea->sample_rate;
         st->codecpar->bits_per_coded_sample = ea->bytes * 8;
-        st->codecpar->bit_rate              = (int64_t)st->codecpar->channels *
+        st->codecpar->bit_rate              = (int64_t)ea->num_channels *
                                               st->codecpar->sample_rate *
                                               st->codecpar->bits_per_coded_sample / 4;
-        st->codecpar->block_align           = st->codecpar->channels *
+        st->codecpar->block_align           = ea->num_channels *
                                               st->codecpar->bits_per_coded_sample;
         ea->audio_stream_index           = st->index;
         st->start_time                   = 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 057/281] epafdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (55 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 056/281] electronicarts: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 058/281] flac: " James Almer
                   ` (225 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/epafdec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/epafdec.c b/libavformat/epafdec.c
index 8b94278c01..1e5f1f887d 100644
--- a/libavformat/epafdec.c
+++ b/libavformat/epafdec.c
@@ -68,7 +68,8 @@ static int epaf_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
 
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels    = channels;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = channels;
     st->codecpar->sample_rate = sample_rate;
     switch (codec) {
     case 0:
@@ -84,7 +85,8 @@ static int epaf_read_header(AVFormatContext *s)
     }
 
     st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id);
-    st->codecpar->block_align = st->codecpar->bits_per_coded_sample * st->codecpar->channels / 8;
+    st->codecpar->block_align = st->codecpar->bits_per_coded_sample *
+                                st->codecpar->ch_layout.nb_channels / 8;
 
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 058/281] flac: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (56 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 057/281] epafdec: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 059/281] flic: " James Almer
                   ` (224 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/flacdec.c | 3 +--
 libavformat/flacenc.c | 7 +++----
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 3401aebe8d..bfae5a2af1 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -191,8 +191,7 @@ static int flac_read_header(AVFormatContext *s)
                         av_log(s, AV_LOG_WARNING,
                                "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n");
                     } else {
-                        st->codecpar->channel_layout = mask;
-                        st->codecpar->channels       = av_get_channel_layout_nb_channels(mask);
+                        av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
                         av_dict_set(&s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", NULL, 0);
                     }
                 }
diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index b267197ccc..eaaf774f9e 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -238,9 +238,8 @@ static int flac_init(struct AVFormatContext *s)
     }
 
     /* add the channel layout tag */
-    if (par->channel_layout &&
-        !(par->channel_layout & ~0x3ffffULL) &&
-        !ff_flac_is_native_layout(par->channel_layout)) {
+    if (!av_channel_layout_subset(&par->ch_layout, ~0x3ffffULL) &&
+        !ff_flac_is_native_layout(par->ch_layout.u.mask)) {
         AVDictionaryEntry *chmask = av_dict_get(s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK",
                                                 NULL, 0);
 
@@ -249,7 +248,7 @@ static int flac_init(struct AVFormatContext *s)
                    "already present, this muxer will not overwrite it.\n");
         } else {
             uint8_t buf[32];
-            snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout);
+            snprintf(buf, sizeof(buf), "0x%"PRIx64, par->ch_layout.u.mask);
             av_dict_set(&s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
         }
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 059/281] flic: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (57 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 058/281] flac: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-27  7:46   ` Anton Khirnov
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 060/281] flv: " James Almer
                   ` (223 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/flic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/flic.c b/libavformat/flic.c
index 44ed696421..496402aa94 100644
--- a/libavformat/flic.c
+++ b/libavformat/flic.c
@@ -157,10 +157,10 @@ static int flic_read_header(AVFormatContext *s)
         ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
         ast->codecpar->codec_tag = 0;
         ast->codecpar->sample_rate = FLIC_TFTD_SAMPLE_RATE;
-        ast->codecpar->channels = 1;
+        ast->codecpar->format   = AV_SAMPLE_FMT_U8;
         ast->codecpar->bit_rate = st->codecpar->sample_rate * 8;
         ast->codecpar->bits_per_coded_sample = 8;
-        ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+        ast->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         ast->codecpar->extradata_size = 0;
 
         /* Since the header information is incorrect we have to figure out the
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 060/281] flv: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (58 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 059/281] flic: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 061/281] framehash: " James Almer
                   ` (222 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/flvdec.c | 15 +++++----------
 libavformat/flvenc.c | 10 +++++-----
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index b9e36b3ff1..cb24b1cc26 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -629,10 +629,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
                     } else if (!strcmp(key, "audiosamplesize") && apar) {
                         apar->bits_per_coded_sample = num_val;
                     } else if (!strcmp(key, "stereo") && apar) {
-                        apar->channels       = num_val + 1;
-                        apar->channel_layout = apar->channels == 2 ?
-                                               AV_CH_LAYOUT_STEREO :
-                                               AV_CH_LAYOUT_MONO;
+                        av_channel_layout_default(&apar->ch_layout, num_val + 1);
                     } else if (!strcmp(key, "width") && vpar) {
                         vpar->width = num_val;
                     } else if (!strcmp(key, "height") && vpar) {
@@ -1202,12 +1199,10 @@ retry_duration:
         sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >>
                                 FLV_AUDIO_SAMPLERATE_OFFSET) >> 3;
         bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
-        if (!st->codecpar->channels || !st->codecpar->sample_rate ||
+        if (!av_channel_layout_check(&st->codecpar->ch_layout) ||
+            !st->codecpar->sample_rate ||
             !st->codecpar->bits_per_coded_sample) {
-            st->codecpar->channels              = channels;
-            st->codecpar->channel_layout        = channels == 1
-                                               ? AV_CH_LAYOUT_MONO
-                                               : AV_CH_LAYOUT_STEREO;
+            av_channel_layout_default(&st->codecpar->ch_layout, channels);
             st->codecpar->sample_rate           = sample_rate;
             st->codecpar->bits_per_coded_sample = bits_per_coded_sample;
         }
@@ -1217,7 +1212,7 @@ retry_duration:
             flv->last_sample_rate =
             sample_rate           = st->codecpar->sample_rate;
             flv->last_channels    =
-            channels              = st->codecpar->channels;
+            channels              = st->codecpar->ch_layout.nb_channels;
         } else {
             AVCodecParameters *par = avcodec_parameters_alloc();
             if (!par) {
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 66c530a2ff..429732297d 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -138,7 +138,7 @@ static int get_audio_flags(AVFormatContext *s, AVCodecParameters *par)
                    "FLV only supports wideband (16kHz) Speex audio\n");
             return AVERROR(EINVAL);
         }
-        if (par->channels != 1) {
+        if (par->ch_layout.nb_channels != 1) {
             av_log(s, AV_LOG_ERROR, "FLV only supports mono Speex audio\n");
             return AVERROR(EINVAL);
         }
@@ -178,7 +178,7 @@ error:
         }
     }
 
-    if (par->channels > 1)
+    if (par->ch_layout.nb_channels > 1)
         flags |= FLV_STEREO;
 
     switch (par->codec_id) {
@@ -342,7 +342,7 @@ static void write_metadata(AVFormatContext *s, unsigned int ts)
         put_amf_double(pb, flv->audio_par->codec_id == AV_CODEC_ID_PCM_U8 ? 8 : 16);
 
         put_amf_string(pb, "stereo");
-        put_amf_bool(pb, flv->audio_par->channels == 2);
+        put_amf_bool(pb, flv->audio_par->ch_layout.nb_channels == 2);
 
         put_amf_string(pb, "audiocodecid");
         put_amf_double(pb, flv->audio_par->codec_tag);
@@ -507,8 +507,8 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i
             if (!par->extradata_size && (flv->flags & FLV_AAC_SEQ_HEADER_DETECT)) {
                 PutBitContext pbc;
                 int samplerate_index;
-                int channels = flv->audio_par->channels
-                        - (flv->audio_par->channels == 8 ? 1 : 0);
+                int channels = flv->audio_par->ch_layout.nb_channels
+                        - (flv->audio_par->ch_layout.nb_channels == 8 ? 1 : 0);
                 uint8_t data[2];
 
                 for (samplerate_index = 0; samplerate_index < 16;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 061/281] framehash: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (59 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 060/281] flv: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 062/281] fsb: " James Almer
                   ` (221 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/framehash.c                              | 8 +++++---
 tests/ref/fate/8bps                                  | 1 -
 tests/ref/fate/aa-demux                              | 1 -
 tests/ref/fate/aac-autobsf-adtstoasc                 | 1 -
 tests/ref/fate/adpcm-4xm                             | 1 -
 tests/ref/fate/adpcm-afc                             | 1 -
 tests/ref/fate/adpcm-dtk                             | 1 -
 tests/ref/fate/adpcm-ea-1                            | 1 -
 tests/ref/fate/adpcm-ea-2                            | 1 -
 tests/ref/fate/adpcm-ea-maxis-xa                     | 1 -
 tests/ref/fate/adpcm-ea-r1                           | 1 -
 tests/ref/fate/adpcm-ima-amv                         | 1 -
 tests/ref/fate/adpcm-ima-ea-eacs                     | 1 -
 tests/ref/fate/adpcm-ima-ea-sead                     | 1 -
 tests/ref/fate/adpcm-ima-smjpeg                      | 1 -
 tests/ref/fate/adpcm-ima-ws                          | 1 -
 tests/ref/fate/adpcm-ima-ws-vqa3                     | 1 -
 tests/ref/fate/adpcm-ms-mono                         | 1 -
 tests/ref/fate/adpcm-thp                             | 1 -
 tests/ref/fate/adpcm-vima                            | 1 -
 tests/ref/fate/adpcm-xa                              | 1 -
 tests/ref/fate/adts-id3v1-demux                      | 1 -
 tests/ref/fate/adts-id3v2-demux                      | 1 -
 tests/ref/fate/adts-id3v2-two-tags-demux             | 1 -
 tests/ref/fate/adtstoasc_ticket3715                  | 1 -
 tests/ref/fate/amrnb-remux                           | 1 -
 tests/ref/fate/amrwb-remux                           | 1 -
 tests/ref/fate/armovie-escape124                     | 1 -
 tests/ref/fate/bethsoft-vid                          | 1 -
 tests/ref/fate/bfi                                   | 1 -
 tests/ref/fate/bmv-audio                             | 1 -
 tests/ref/fate/caf-alac-remux                        | 1 -
 tests/ref/fate/caf-amr_nb-remux                      | 1 -
 tests/ref/fate/caf-mace6-remux                       | 1 -
 tests/ref/fate/caf-pcm_s24-remux                     | 1 -
 tests/ref/fate/caf-pcm_s24le-remux                   | 1 -
 tests/ref/fate/caf-qdm2-remux                        | 1 -
 tests/ref/fate/cdxl-demux                            | 1 -
 tests/ref/fate/copy-psp                              | 1 -
 tests/ref/fate/copy-shortest1                        | 1 -
 tests/ref/fate/copy-shortest2                        | 1 -
 tests/ref/fate/copy-trac236                          | 1 -
 tests/ref/fate/copy-trac3074                         | 1 -
 tests/ref/fate/copy-trac4914                         | 1 -
 tests/ref/fate/copy-trac4914-avi                     | 1 -
 tests/ref/fate/corepng                               | 1 -
 tests/ref/fate/cover-art-aiff-id3v2-remux            | 1 -
 tests/ref/fate/cover-art-flac-remux                  | 6 ++----
 tests/ref/fate/cover-art-mp3-id3v2-remux             | 1 -
 tests/ref/fate/creatureshock-avs                     | 1 -
 tests/ref/fate/cyberia-c93                           | 1 -
 tests/ref/fate/d-cinema-demux                        | 1 -
 tests/ref/fate/dca-xll_51_16_192_768_0               | 1 -
 tests/ref/fate/dca-xll_51_16_192_768_0-dmix_2        | 1 -
 tests/ref/fate/dca-xll_51_16_192_768_0-dmix_6        | 1 -
 tests/ref/fate/dca-xll_51_16_192_768_1               | 1 -
 tests/ref/fate/dca-xll_51_16_192_768_1-dmix_2        | 1 -
 tests/ref/fate/dca-xll_51_16_192_768_1-dmix_6        | 1 -
 tests/ref/fate/dca-xll_51_24_48_768                  | 1 -
 tests/ref/fate/dca-xll_51_24_48_768-dmix_2           | 1 -
 tests/ref/fate/dca-xll_51_24_48_768-dmix_6           | 1 -
 tests/ref/fate/dca-xll_51_24_48_none                 | 1 -
 tests/ref/fate/dca-xll_51_24_48_none-dmix_2          | 1 -
 tests/ref/fate/dca-xll_51_24_48_none-dmix_6          | 1 -
 tests/ref/fate/dca-xll_71_24_48_768_0                | 1 -
 tests/ref/fate/dca-xll_71_24_48_768_0-dmix_2         | 1 -
 tests/ref/fate/dca-xll_71_24_48_768_0-dmix_6         | 1 -
 tests/ref/fate/dca-xll_71_24_48_768_1                | 1 -
 tests/ref/fate/dca-xll_71_24_48_768_1-dmix_2         | 1 -
 tests/ref/fate/dca-xll_71_24_48_768_1-dmix_6         | 1 -
 tests/ref/fate/dca-xll_71_24_96_768                  | 1 -
 tests/ref/fate/dca-xll_71_24_96_768-dmix_2           | 1 -
 tests/ref/fate/dca-xll_71_24_96_768-dmix_6           | 1 -
 tests/ref/fate/dca-xll_x96_51_24_96_1509             | 1 -
 tests/ref/fate/dca-xll_x96_51_24_96_1509-dmix_2      | 1 -
 tests/ref/fate/dca-xll_x96_51_24_96_1509-dmix_6      | 1 -
 tests/ref/fate/dca-xll_xch_61_24_48_768              | 1 -
 tests/ref/fate/dca-xll_xch_61_24_48_768-dmix_2       | 1 -
 tests/ref/fate/dca-xll_xch_61_24_48_768-dmix_6       | 1 -
 tests/ref/fate/dcinema-encode                        | 1 -
 tests/ref/fate/delphine-cin-audio                    | 1 -
 tests/ref/fate/dpcm-idroq                            | 1 -
 tests/ref/fate/dpcm-interplay                        | 1 -
 tests/ref/fate/dss-lp                                | 1 -
 tests/ref/fate/dss-sp                                | 1 -
 tests/ref/fate/ffmpeg-attached_pics                  | 1 -
 tests/ref/fate/ffmpeg-filter_complex_audio           | 1 -
 tests/ref/fate/filter-acrossfade                     | 1 -
 tests/ref/fate/filter-adelay                         | 1 -
 tests/ref/fate/filter-aecho                          | 1 -
 tests/ref/fate/filter-aemphasis                      | 2 --
 tests/ref/fate/filter-aemphasis-50fm                 | 1 -
 tests/ref/fate/filter-aemphasis-75kf                 | 1 -
 tests/ref/fate/filter-afade-esin                     | 1 -
 tests/ref/fate/filter-afade-exp                      | 1 -
 tests/ref/fate/filter-afade-hsin                     | 1 -
 tests/ref/fate/filter-afade-iqsin                    | 1 -
 tests/ref/fate/filter-afade-log                      | 1 -
 tests/ref/fate/filter-afade-qsin                     | 1 -
 tests/ref/fate/filter-agate                          | 1 -
 tests/ref/fate/filter-alimiter                       | 1 -
 tests/ref/fate/filter-amerge                         | 1 -
 tests/ref/fate/filter-anequalizer                    | 1 -
 tests/ref/fate/filter-apad                           | 1 -
 tests/ref/fate/filter-asetnsamples-nopad             | 1 -
 tests/ref/fate/filter-asetnsamples-pad               | 1 -
 tests/ref/fate/filter-asetrate                       | 1 -
 tests/ref/fate/filter-atrim-duration                 | 1 -
 tests/ref/fate/filter-atrim-mixed                    | 1 -
 tests/ref/fate/filter-atrim-samples                  | 1 -
 tests/ref/fate/filter-atrim-time                     | 1 -
 tests/ref/fate/filter-chorus                         | 1 -
 tests/ref/fate/filter-compand                        | 1 -
 tests/ref/fate/filter-concat                         | 1 -
 tests/ref/fate/filter-concat-vfr                     | 1 -
 tests/ref/fate/filter-dcshift                        | 1 -
 tests/ref/fate/filter-earwax                         | 1 -
 tests/ref/fate/filter-extrastereo                    | 1 -
 tests/ref/fate/filter-hls                            | 1 -
 tests/ref/fate/filter-hls-append                     | 1 -
 tests/ref/fate/filter-meta-4560-rotate0              | 1 -
 tests/ref/fate/filter-overlay-dvdsub-2397            | 1 -
 tests/ref/fate/filter-pan-downmix1                   | 1 -
 tests/ref/fate/filter-pan-downmix2                   | 1 -
 tests/ref/fate/filter-pan-mono1                      | 1 -
 tests/ref/fate/filter-pan-mono2                      | 1 -
 tests/ref/fate/filter-pan-stereo1                    | 1 -
 tests/ref/fate/filter-pan-stereo2                    | 1 -
 tests/ref/fate/filter-pan-stereo3                    | 1 -
 tests/ref/fate/filter-pan-stereo4                    | 1 -
 tests/ref/fate/filter-pan-upmix1                     | 1 -
 tests/ref/fate/filter-pan-upmix2                     | 1 -
 tests/ref/fate/filter-silenceremove                  | 1 -
 tests/ref/fate/filter-stereotools                    | 1 -
 tests/ref/fate/g722-encode                           | 1 -
 tests/ref/fate/g722dec-1                             | 1 -
 tests/ref/fate/g723_1-dec-1                          | 1 -
 tests/ref/fate/g723_1-dec-2                          | 1 -
 tests/ref/fate/g723_1-dec-3                          | 1 -
 tests/ref/fate/g723_1-dec-4                          | 1 -
 tests/ref/fate/g723_1-dec-5                          | 1 -
 tests/ref/fate/g723_1-dec-6                          | 1 -
 tests/ref/fate/g723_1-dec-7                          | 1 -
 tests/ref/fate/g723_1-dec-8                          | 1 -
 tests/ref/fate/g726-encode-2bit                      | 1 -
 tests/ref/fate/g726-encode-3bit                      | 1 -
 tests/ref/fate/g726-encode-4bit                      | 1 -
 tests/ref/fate/g726-encode-5bit                      | 1 -
 tests/ref/fate/gapless-mp3                           | 6 +++---
 tests/ref/fate/gsm-ms                                | 1 -
 tests/ref/fate/gsm-toast                             | 1 -
 tests/ref/fate/h264-skip-nointra                     | 1 -
 tests/ref/fate/h264-skip-nokey                       | 1 -
 tests/ref/fate/h264-xavc-4389                        | 1 -
 tests/ref/fate/hls-fmp4                              | 1 -
 tests/ref/fate/hls-init-time                         | 1 -
 tests/ref/fate/hls-list-size                         | 1 -
 tests/ref/fate/hls-segment-single                    | 1 -
 tests/ref/fate/hls-segment-size                      | 1 -
 tests/ref/fate/id-cin-video                          | 1 -
 tests/ref/fate/id3v2-chapters                        | 1 -
 tests/ref/fate/id3v2-priv-remux                      | 1 -
 tests/ref/fate/jv-demux                              | 1 -
 tests/ref/fate/lmlm4-demux                           | 1 -
 tests/ref/fate/matroska-flac-channel-mapping         | 2 --
 tests/ref/fate/matroska-flac-extradata-update        | 3 ---
 tests/ref/fate/matroska-lzo-decompression            | 1 -
 tests/ref/fate/matroska-mastering-display-metadata   | 2 --
 tests/ref/fate/matroska-mpegts-remux                 | 2 --
 tests/ref/fate/matroska-wavpack-missing-codecprivate | 1 -
 tests/ref/fate/matroska-xiph-lacing                  | 1 -
 tests/ref/fate/maxis-xa                              | 1 -
 tests/ref/fate/mkv                                   | 1 -
 tests/ref/fate/mkv-1242                              | 1 -
 tests/ref/fate/mov-440hz-10ms                        | 1 -
 tests/ref/fate/mov-bbi-elst-starts-b                 | 1 -
 tests/ref/fate/mov-cover-image                       | 1 -
 tests/ref/fate/mov-mp3-demux                         | 1 -
 tests/ref/fate/mov-mp4-disposition-mpegts-remux      | 2 --
 tests/ref/fate/mpegps-remuxed-pcm-demux              | 1 -
 tests/ref/fate/mtv                                   | 1 -
 tests/ref/fate/mxf-demux                             | 1 -
 tests/ref/fate/nsv-demux                             | 1 -
 tests/ref/fate/oma-atrac3-remux                      | 1 -
 tests/ref/fate/oma-atrac3p-remux                     | 1 -
 tests/ref/fate/on2avc                                | 1 -
 tests/ref/fate/paf-audio                             | 1 -
 tests/ref/fate/paf-demux                             | 1 -
 tests/ref/fate/pcm-planar                            | 1 -
 tests/ref/fate/pcm_dvd                               | 1 -
 tests/ref/fate/pmp-demux                             | 1 -
 tests/ref/fate/prores-gray                           | 1 -
 tests/ref/fate/prores-transparency                   | 1 -
 tests/ref/fate/prores-transparency_skip              | 1 -
 tests/ref/fate/psx-str-demux                         | 1 -
 tests/ref/fate/pva-demux                             | 1 -
 tests/ref/fate/ra3-144                               | 1 -
 tests/ref/fate/redcode-demux                         | 1 -
 tests/ref/fate/s337m-demux                           | 1 -
 tests/ref/fate/segment-adts-to-mkv-header-000        | 1 -
 tests/ref/fate/segment-adts-to-mkv-header-001        | 1 -
 tests/ref/fate/segment-adts-to-mkv-header-002        | 1 -
 tests/ref/fate/segment-adts-to-mkv-header-all        | 1 -
 tests/ref/fate/shortest                              | 1 -
 tests/ref/fate/sierra-vmd-audio                      | 1 -
 tests/ref/fate/siff-demux                            | 1 -
 tests/ref/fate/smacker-audio                         | 1 -
 tests/ref/fate/smjpeg-demux                          | 1 -
 tests/ref/fate/sp5x                                  | 1 -
 tests/ref/fate/tiertex-seq                           | 1 -
 tests/ref/fate/tmv                                   | 1 -
 tests/ref/fate/tscc-15bit                            | 1 -
 tests/ref/fate/vqf-demux                             | 2 +-
 tests/ref/fate/wav-ac3                               | 1 -
 tests/ref/fate/wc3movie-xan                          | 1 -
 tests/ref/fate/webm-dash-chapters                    | 1 -
 tests/ref/fate/westwood-aud                          | 1 -
 tests/ref/fate/wmv3-drm-nodec                        | 1 -
 tests/ref/fate/wtv-demux                             | 1 -
 tests/ref/fate/xmv-demux                             | 1 -
 220 files changed, 11 insertions(+), 234 deletions(-)

diff --git a/libavformat/framehash.c b/libavformat/framehash.c
index 04c40825b9..abe565548c 100644
--- a/libavformat/framehash.c
+++ b/libavformat/framehash.c
@@ -35,12 +35,14 @@ int ff_framehash_write_header(AVFormatContext *s)
         avio_printf(s->pb, "#media_type %d: %s\n", i, av_get_media_type_string(avctx->codec_type));
         avio_printf(s->pb, "#codec_id %d: %s\n", i, avcodec_get_name(avctx->codec_id));
         switch (avctx->codec_type) {
-        case AVMEDIA_TYPE_AUDIO:
-            av_get_channel_layout_string(buf, sizeof(buf), avctx->channels, avctx->channel_layout);
+        case AVMEDIA_TYPE_AUDIO: {
+            int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf));
+            if (ret < 0)
+                return ret;
             avio_printf(s->pb, "#sample_rate %d: %d\n", i,avctx->sample_rate);
-            avio_printf(s->pb, "#channel_layout %d: %"PRIx64"\n", i,avctx->channel_layout);
             avio_printf(s->pb, "#channel_layout_name %d: %s\n", i, buf);
             break;
+            }
         case AVMEDIA_TYPE_VIDEO:
             avio_printf(s->pb, "#dimensions %d: %dx%d\n", i, avctx->width, avctx->height);
             avio_printf(s->pb, "#sar %d: %d/%d\n", i, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
diff --git a/tests/ref/fate/8bps b/tests/ref/fate/8bps
index dab2b908db..f736bb0b9a 100644
--- a/tests/ref/fate/8bps
+++ b/tests/ref/fate/8bps
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 22050
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   259200, 0x7e91df07
 1,          0,          0,     1024,     2048, 0x3d042426
diff --git a/tests/ref/fate/aa-demux b/tests/ref/fate/aa-demux
index 89350b8803..9534c82eef 100644
--- a/tests/ref/fate/aa-demux
+++ b/tests/ref/fate/aa-demux
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: sipr
 #sample_rate 0: 8500
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,    18000,       19, 0x36e10529
 0,      18000,      18000,    18000,       19, 0x70810a69
diff --git a/tests/ref/fate/aac-autobsf-adtstoasc b/tests/ref/fate/aac-autobsf-adtstoasc
index 2a2823ef9a..b9bfb37142 100644
--- a/tests/ref/fate/aac-autobsf-adtstoasc
+++ b/tests/ref/fate/aac-autobsf-adtstoasc
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: aac
 #sample_rate 0: 16000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,       64,        4, 0x02f70117
 0,         64,         64,       64,      163, 0xd5f85007
diff --git a/tests/ref/fate/adpcm-4xm b/tests/ref/fate/adpcm-4xm
index cfde412da8..6278639b27 100644
--- a/tests/ref/fate/adpcm-4xm
+++ b/tests/ref/fate/adpcm-4xm
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1472,     5888, 0x9086e310
 0,       1476,       1476,     1472,     5888, 0xac8491f5
diff --git a/tests/ref/fate/adpcm-afc b/tests/ref/fate/adpcm-afc
index 6d8e732454..4caf7a8f93 100644
--- a/tests/ref/fate/adpcm-afc
+++ b/tests/ref/fate/adpcm-afc
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,    17920,    71680, 0x52373bc9
 0,      17920,      17920,    17920,    71680, 0x1f854b27
diff --git a/tests/ref/fate/adpcm-dtk b/tests/ref/fate/adpcm-dtk
index f3ade6d505..58305d6bd8 100644
--- a/tests/ref/fate/adpcm-dtk
+++ b/tests/ref/fate/adpcm-dtk
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 48000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      896,     3584, 0xdae789d5
 0,        896,        896,      896,     3584, 0x168ed9b6
diff --git a/tests/ref/fate/adpcm-ea-1 b/tests/ref/fate/adpcm-ea-1
index 76be8e8511..ea0ba2b04f 100644
--- a/tests/ref/fate/adpcm-ea-1
+++ b/tests/ref/fate/adpcm-ea-1
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1484,     5936, 0x00000000
 0,       1484,       1484,     1456,     5824, 0x00000000
diff --git a/tests/ref/fate/adpcm-ea-2 b/tests/ref/fate/adpcm-ea-2
index 91440874a0..e0dc9dccfe 100644
--- a/tests/ref/fate/adpcm-ea-2
+++ b/tests/ref/fate/adpcm-ea-2
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1484,     5936, 0xea261a29
 0,       1484,       1484,     1456,     5824, 0x253df061
diff --git a/tests/ref/fate/adpcm-ea-maxis-xa b/tests/ref/fate/adpcm-ea-maxis-xa
index c919a67545..be2218424c 100644
--- a/tests/ref/fate/adpcm-ea-maxis-xa
+++ b/tests/ref/fate/adpcm-ea-maxis-xa
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,       28,      112, 0x291d1be4
 0,         28,         28,       28,      112, 0xf08d33cc
diff --git a/tests/ref/fate/adpcm-ea-r1 b/tests/ref/fate/adpcm-ea-r1
index 4e5fb6788f..46415e72a4 100644
--- a/tests/ref/fate/adpcm-ea-r1
+++ b/tests/ref/fate/adpcm-ea-r1
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 48000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1624,     6496, 0x00000000
 0,       1624,       1624,     1596,     6384, 0x00000000
diff --git a/tests/ref/fate/adpcm-ima-amv b/tests/ref/fate/adpcm-ima-amv
index 2f8c0a2cdf..37583cf810 100644
--- a/tests/ref/fate/adpcm-ima-amv
+++ b/tests/ref/fate/adpcm-ima-amv
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1378,     2756, 0x0af35034
 0,       1378,       1378,     1378,     2756, 0x8462443f
diff --git a/tests/ref/fate/adpcm-ima-ea-eacs b/tests/ref/fate/adpcm-ima-ea-eacs
index fcfcbeb175..62da571d7f 100644
--- a/tests/ref/fate/adpcm-ima-ea-eacs
+++ b/tests/ref/fate/adpcm-ima-ea-eacs
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1468,     5872, 0x00000000
 0,       1468,       1468,     1468,     5872, 0x00000000
diff --git a/tests/ref/fate/adpcm-ima-ea-sead b/tests/ref/fate/adpcm-ima-ea-sead
index 2d52efe3c0..f78bbe8431 100644
--- a/tests/ref/fate/adpcm-ima-ea-sead
+++ b/tests/ref/fate/adpcm-ima-ea-sead
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      736,     2944, 0x00000000
 0,        736,        736,     1472,     5888, 0x5ae3c2a4
diff --git a/tests/ref/fate/adpcm-ima-smjpeg b/tests/ref/fate/adpcm-ima-smjpeg
index a216e3ab5e..723fa2336e 100644
--- a/tests/ref/fate/adpcm-ima-smjpeg
+++ b/tests/ref/fate/adpcm-ima-smjpeg
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      512,     1024, 0x00000000
 0,        512,        512,      512,     1024, 0x00000000
diff --git a/tests/ref/fate/adpcm-ima-ws b/tests/ref/fate/adpcm-ima-ws
index b382812d22..5431538bf4 100644
--- a/tests/ref/fate/adpcm-ima-ws
+++ b/tests/ref/fate/adpcm-ima-ws
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,    11024,    22048, 0x0843bbad
 0,      11024,      11024,     1470,     2940, 0x16ff454e
diff --git a/tests/ref/fate/adpcm-ima-ws-vqa3 b/tests/ref/fate/adpcm-ima-ws-vqa3
index c2f14cd1a8..9c2c6b175b 100644
--- a/tests/ref/fate/adpcm-ima-ws-vqa3
+++ b/tests/ref/fate/adpcm-ima-ws-vqa3
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1470,     2940, 0xca80b853
 0,       1470,       1470,     1470,     2940, 0x250c9f84
diff --git a/tests/ref/fate/adpcm-ms-mono b/tests/ref/fate/adpcm-ms-mono
index e3f217d18e..9823ba77b5 100644
--- a/tests/ref/fate/adpcm-ms-mono
+++ b/tests/ref/fate/adpcm-ms-mono
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 11025
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      500,     1000, 0x64cd9403
 0,        500,        500,      500,     1000, 0xa4ef8a9d
diff --git a/tests/ref/fate/adpcm-thp b/tests/ref/fate/adpcm-thp
index 592c6610ad..221b2b90b3 100644
--- a/tests/ref/fate/adpcm-thp
+++ b/tests/ref/fate/adpcm-thp
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 32000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1078,     4312, 0x469714f6
 0,       1078,       1078,     1064,     4256, 0x6ca28f25
diff --git a/tests/ref/fate/adpcm-vima b/tests/ref/fate/adpcm-vima
index b22f128be5..21b8cc4a58 100644
--- a/tests/ref/fate/adpcm-vima
+++ b/tests/ref/fate/adpcm-vima
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,    73500,   294000, 0x37d439ee
 0,      73500,      73500,     1470,     5880, 0xe524b177
diff --git a/tests/ref/fate/adpcm-xa b/tests/ref/fate/adpcm-xa
index 15b62ec4a5..5207fe743e 100644
--- a/tests/ref/fate/adpcm-xa
+++ b/tests/ref/fate/adpcm-xa
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 37800
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     2016,     8064, 0xa307ed8c
 0,       2016,       2016,     2016,     8064, 0xd2551927
diff --git a/tests/ref/fate/adts-id3v1-demux b/tests/ref/fate/adts-id3v1-demux
index 7caa5d6870..bd8f5b1193 100644
--- a/tests/ref/fate/adts-id3v1-demux
+++ b/tests/ref/fate/adts-id3v1-demux
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: aac
 #sample_rate 0: 48000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,   602112,      474, 0x4c90e7c4
 0,     602112,     602112,   602112,      471, 0xb8b5e75d
diff --git a/tests/ref/fate/adts-id3v2-demux b/tests/ref/fate/adts-id3v2-demux
index db00e3b81e..710350988a 100644
--- a/tests/ref/fate/adts-id3v2-demux
+++ b/tests/ref/fate/adts-id3v2-demux
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: aac
 #sample_rate 0: 48000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,   602112,      126, 0x639a3a5b
 0,     602112,     602112,   602112,      135, 0x5b1f3ced
diff --git a/tests/ref/fate/adts-id3v2-two-tags-demux b/tests/ref/fate/adts-id3v2-two-tags-demux
index 4fffd2e767..5fd8c52f28 100644
--- a/tests/ref/fate/adts-id3v2-two-tags-demux
+++ b/tests/ref/fate/adts-id3v2-two-tags-demux
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: aac
 #sample_rate 0: 48000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,   602112,      128, 0x23291993
 0,     602112,     602112,   602112,      128, 0x23291993
diff --git a/tests/ref/fate/adtstoasc_ticket3715 b/tests/ref/fate/adtstoasc_ticket3715
index fbdeeb0582..78d9e71979 100644
--- a/tests/ref/fate/adtstoasc_ticket3715
+++ b/tests/ref/fate/adtstoasc_ticket3715
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: aac
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,      371, 0x14b11a4f
 0,       1024,       1024,     1024,      402, 0x2f00c487
diff --git a/tests/ref/fate/amrnb-remux b/tests/ref/fate/amrnb-remux
index 4a78c479f2..31d20981a2 100644
--- a/tests/ref/fate/amrnb-remux
+++ b/tests/ref/fate/amrnb-remux
@@ -4,7 +4,6 @@
 #media_type 0: audio
 #codec_id 0: amr_nb
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      160,       27, 0xc9970c51
 0,        160,        160,      160,       27, 0xbaa00d05
diff --git a/tests/ref/fate/amrwb-remux b/tests/ref/fate/amrwb-remux
index c350fc0b61..0fd3e457f2 100644
--- a/tests/ref/fate/amrwb-remux
+++ b/tests/ref/fate/amrwb-remux
@@ -4,7 +4,6 @@
 #media_type 0: audio
 #codec_id 0: amr_wb
 #sample_rate 0: 16000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      320,       61, 0xc8891fe9
 0,        320,        320,      320,       61, 0xc2562027
diff --git a/tests/ref/fate/armovie-escape124 b/tests/ref/fate/armovie-escape124
index 398ff767b6..ce99446191 100644
--- a/tests/ref/fate/armovie-escape124
+++ b/tests/ref/fate/armovie-escape124
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 44100
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        1,   230400, 0xd133e177
 1,          0,          0,    44100,   176400, 0xdd61578c
diff --git a/tests/ref/fate/bethsoft-vid b/tests/ref/fate/bethsoft-vid
index 25a62ae515..a6a0f41af8 100644
--- a/tests/ref/fate/bethsoft-vid
+++ b/tests/ref/fate/bethsoft-vid
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 11111
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   192000, 0x00000000
 1,          0,          0,      740,     1480, 0x00000000
diff --git a/tests/ref/fate/bfi b/tests/ref/fate/bfi
index 277c93543e..e7583a7cd2 100644
--- a/tests/ref/fate/bfi
+++ b/tests/ref/fate/bfi
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 11025
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   134400, 0xc218b00c
 1,          0,          0,     8884,    17768, 0x07df135c
diff --git a/tests/ref/fate/bmv-audio b/tests/ref/fate/bmv-audio
index 6e1a4c2fe9..6de8b995cc 100644
--- a/tests/ref/fate/bmv-audio
+++ b/tests/ref/fate/bmv-audio
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1856,     7424, 0x18540b36
 0,       1856,       1856,     1824,     7296, 0x5acd2484
diff --git a/tests/ref/fate/caf-alac-remux b/tests/ref/fate/caf-alac-remux
index 97275fd317..f33182b721 100644
--- a/tests/ref/fate/caf-alac-remux
+++ b/tests/ref/fate/caf-alac-remux
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: alac
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,        0,       32, 0xa0af0dfe
 0,       4096,       4096,        0,     6701, 0xa9ddc14e
diff --git a/tests/ref/fate/caf-amr_nb-remux b/tests/ref/fate/caf-amr_nb-remux
index 0eed36a5cb..7ae3a74741 100644
--- a/tests/ref/fate/caf-amr_nb-remux
+++ b/tests/ref/fate/caf-amr_nb-remux
@@ -5,7 +5,6 @@ a00bd18f70b66286e67d84f0df034a48 *tests/data/fate/caf-amr_nb-remux.caf
 #media_type 0: audio
 #codec_id 0: amr_nb
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      160,       13, 0x2bf906f6
 0,        160,        160,      160,       13, 0x28bd0756
diff --git a/tests/ref/fate/caf-mace6-remux b/tests/ref/fate/caf-mace6-remux
index 3a0499d793..e674365b3d 100644
--- a/tests/ref/fate/caf-mace6-remux
+++ b/tests/ref/fate/caf-mace6-remux
@@ -4,7 +4,6 @@
 #media_type 0: audio
 #codec_id 0: mace6
 #sample_rate 0: 22050
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,        6,        1, 0x00900090
 0,          6,          6,        6,        1, 0x00870087
diff --git a/tests/ref/fate/caf-pcm_s24-remux b/tests/ref/fate/caf-pcm_s24-remux
index bb3136ef7d..618f6f73e4 100644
--- a/tests/ref/fate/caf-pcm_s24-remux
+++ b/tests/ref/fate/caf-pcm_s24-remux
@@ -4,7 +4,6 @@ d696d9dc23a82c51c4761f5792e7fa37 *tests/data/fate/caf-pcm_s24-remux.caf
 #media_type 0: audio
 #codec_id 0: pcm_s24be
 #sample_rate 0: 192000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      682,     4092, 0x71f10ea0
 0,        682,        682,      682,     4092, 0x51852317
diff --git a/tests/ref/fate/caf-pcm_s24le-remux b/tests/ref/fate/caf-pcm_s24le-remux
index 9520e423cd..bab814c5e3 100644
--- a/tests/ref/fate/caf-pcm_s24le-remux
+++ b/tests/ref/fate/caf-pcm_s24le-remux
@@ -4,7 +4,6 @@ ee0072a92044cbad68795cf93546c517 *tests/data/fate/caf-pcm_s24le-remux.caf
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 192000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      682,     4092, 0xa6320ea0
 0,        682,        682,      682,     4092, 0x27732317
diff --git a/tests/ref/fate/caf-qdm2-remux b/tests/ref/fate/caf-qdm2-remux
index a3bde1264b..d4f658c163 100644
--- a/tests/ref/fate/caf-qdm2-remux
+++ b/tests/ref/fate/caf-qdm2-remux
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: qdm2
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,        0,      370, 0x4d1897fc
 0,       4096,       4096,        0,      370, 0xea999da0
diff --git a/tests/ref/fate/cdxl-demux b/tests/ref/fate/cdxl-demux
index 324a40f2dc..9b71b18910 100644
--- a/tests/ref/fate/cdxl-demux
+++ b/tests/ref/fate/cdxl-demux
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s8_planar
 #sample_rate 1: 11025
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,    22688, 0xc954a244
 1,          0,          0,     1884,     1884, 0x06925e3e
diff --git a/tests/ref/fate/copy-psp b/tests/ref/fate/copy-psp
index 8b2cef87fa..977bef5c3e 100644
--- a/tests/ref/fate/copy-psp
+++ b/tests/ref/fate/copy-psp
@@ -11,7 +11,6 @@
 #media_type 1: audio
 #codec_id 1: aac
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,     3003,    37084, 0x021a0d3f
 1,          0,          0,     1024,       10, 0x0e270398
diff --git a/tests/ref/fate/copy-shortest1 b/tests/ref/fate/copy-shortest1
index 69204b373a..5038973e4e 100644
--- a/tests/ref/fate/copy-shortest1
+++ b/tests/ref/fate/copy-shortest1
@@ -11,7 +11,6 @@
 #media_type 1: audio
 #codec_id 1: ac3
 #sample_rate 1: 44100
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 #stream#, dts,        pts, duration,     size, hash
 1,       -256,       -256,     1536,      416, e3bd415f62aa927e9273151fdf21ebce
diff --git a/tests/ref/fate/copy-shortest2 b/tests/ref/fate/copy-shortest2
index 69204b373a..5038973e4e 100644
--- a/tests/ref/fate/copy-shortest2
+++ b/tests/ref/fate/copy-shortest2
@@ -11,7 +11,6 @@
 #media_type 1: audio
 #codec_id 1: ac3
 #sample_rate 1: 44100
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 #stream#, dts,        pts, duration,     size, hash
 1,       -256,       -256,     1536,      416, e3bd415f62aa927e9273151fdf21ebce
diff --git a/tests/ref/fate/copy-trac236 b/tests/ref/fate/copy-trac236
index c34b309b3f..5a9e08ad0c 100644
--- a/tests/ref/fate/copy-trac236
+++ b/tests/ref/fate/copy-trac236
@@ -9,7 +9,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        1,   518400, 0x81ab2140
 1,          0,          0,     1024,     4096, 0x67dc99a3
diff --git a/tests/ref/fate/copy-trac3074 b/tests/ref/fate/copy-trac3074
index 2ef7e702cd..b6d23f8c1c 100644
--- a/tests/ref/fate/copy-trac3074
+++ b/tests/ref/fate/copy-trac3074
@@ -4,7 +4,6 @@
 #media_type 0: audio
 #codec_id 0: eac3
 #sample_rate 0: 48000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1536,      512, 0x2beaf79f, S=1,        4
 0,       1536,       1536,     1536,      512, 0x29ddf9d6
diff --git a/tests/ref/fate/copy-trac4914 b/tests/ref/fate/copy-trac4914
index 743dc8c055..b80db6522f 100644
--- a/tests/ref/fate/copy-trac4914
+++ b/tests/ref/fate/copy-trac4914
@@ -9,7 +9,6 @@ f5150fb82c1bb5a90906fce93dcc3f76 *tests/data/fate/copy-trac4914.mxf
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        1,   259200, 0xf36957da
 1,          0,          0,     1602,     6408, 0x1dd7b37c
diff --git a/tests/ref/fate/copy-trac4914-avi b/tests/ref/fate/copy-trac4914-avi
index 0358ead6b8..20006ea05c 100644
--- a/tests/ref/fate/copy-trac4914-avi
+++ b/tests/ref/fate/copy-trac4914-avi
@@ -9,7 +9,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 1,          0,          0,     1152,     4608, 0xb24f5c9d
 1,       1152,       1152,     1152,     4608, 0xe2da5c32
diff --git a/tests/ref/fate/corepng b/tests/ref/fate/corepng
index 74bb920108..942ceceb95 100644
--- a/tests/ref/fate/corepng
+++ b/tests/ref/fate/corepng
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 11025
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   230400, 0x03e25ead
 1,          0,          0,     5513,    11026, 0x27ad637c
diff --git a/tests/ref/fate/cover-art-aiff-id3v2-remux b/tests/ref/fate/cover-art-aiff-id3v2-remux
index c294c5013e..3ca2855eb8 100644
--- a/tests/ref/fate/cover-art-aiff-id3v2-remux
+++ b/tests/ref/fate/cover-art-aiff-id3v2-remux
@@ -4,7 +4,6 @@ d4a9481090a8bab1a3f072a8108a1d6a *tests/data/fate/cover-art-aiff-id3v2-remux.aif
 #media_type 0: audio
 #codec_id 0: pcm_s16be
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 #tb 1: 1/90000
 #media_type 1: video
diff --git a/tests/ref/fate/cover-art-flac-remux b/tests/ref/fate/cover-art-flac-remux
index 3f779828ae..aeb229f853 100644
--- a/tests/ref/fate/cover-art-flac-remux
+++ b/tests/ref/fate/cover-art-flac-remux
@@ -5,8 +5,7 @@
 #media_type 0: audio
 #codec_id 0: flac
 #sample_rate 0: 44100
-#channel_layout 0: 5
-#channel_layout_name 0: 2 channels (FL+FC)
+#channel_layout_name 0: FL+FC
 #tb 1: 1/90000
 #media_type 1: video
 #codec_id 1: png
@@ -36,8 +35,7 @@
 #media_type 6: audio
 #codec_id 6: pcm_s16le
 #sample_rate 6: 44100
-#channel_layout 6: 5
-#channel_layout_name 6: 2 channels (FL+FC)
+#channel_layout_name 6: FL+FC
 0,          0,          0,     4608,       14, 0x242b036d
 1,          0,          0,        0,    66888, 0x1fd72743
 2,          0,          0,        0,   438706, 0x8bcb753b
diff --git a/tests/ref/fate/cover-art-mp3-id3v2-remux b/tests/ref/fate/cover-art-mp3-id3v2-remux
index 457f1d5a08..906a646799 100644
--- a/tests/ref/fate/cover-art-mp3-id3v2-remux
+++ b/tests/ref/fate/cover-art-mp3-id3v2-remux
@@ -4,7 +4,6 @@ c1b55a9a92226cd72d3f53ccd830d127 *tests/data/fate/cover-art-mp3-id3v2-remux.mp3
 #media_type 0: audio
 #codec_id 0: mp3
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 #tb 1: 1/90000
 #media_type 1: video
diff --git a/tests/ref/fate/creatureshock-avs b/tests/ref/fate/creatureshock-avs
index c8e08c9ff7..19648202b8 100644
--- a/tests/ref/fate/creatureshock-avs
+++ b/tests/ref/fate/creatureshock-avs
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 22222
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   188892, 0x9f47a5ec
 1,          0,          0,     8186,    16372, 0xfaaab59d
diff --git a/tests/ref/fate/cyberia-c93 b/tests/ref/fate/cyberia-c93
index e7a5b5a08d..813ef46829 100644
--- a/tests/ref/fate/cyberia-c93
+++ b/tests/ref/fate/cyberia-c93
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 16129
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   184320, 0x8433f0f8
 1,          0,          0,    14184,    28368, 0xaacc96a5
diff --git a/tests/ref/fate/d-cinema-demux b/tests/ref/fate/d-cinema-demux
index 74d00f7bb2..f1e8b5f755 100644
--- a/tests/ref/fate/d-cinema-demux
+++ b/tests/ref/fate/d-cinema-demux
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24daud
 #sample_rate 0: 96000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 0,          0,          0,     1875,    36000, 0xd592781d
 0,       1875,       1875,     1875,    36000, 0xd592781d
diff --git a/tests/ref/fate/dca-xll_51_16_192_768_0 b/tests/ref/fate/dca-xll_51_16_192_768_0
index 6e62c616e2..756d11d868 100644
--- a/tests/ref/fate/dca-xll_51_16_192_768_0
+++ b/tests/ref/fate/dca-xll_51_16_192_768_0
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 192000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     2048,    24576, 91ff0dac5df86e798bfef5e573536b08
diff --git a/tests/ref/fate/dca-xll_51_16_192_768_0-dmix_2 b/tests/ref/fate/dca-xll_51_16_192_768_0-dmix_2
index 6e62c616e2..756d11d868 100644
--- a/tests/ref/fate/dca-xll_51_16_192_768_0-dmix_2
+++ b/tests/ref/fate/dca-xll_51_16_192_768_0-dmix_2
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 192000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     2048,    24576, 91ff0dac5df86e798bfef5e573536b08
diff --git a/tests/ref/fate/dca-xll_51_16_192_768_0-dmix_6 b/tests/ref/fate/dca-xll_51_16_192_768_0-dmix_6
index 6e62c616e2..756d11d868 100644
--- a/tests/ref/fate/dca-xll_51_16_192_768_0-dmix_6
+++ b/tests/ref/fate/dca-xll_51_16_192_768_0-dmix_6
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 192000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     2048,    24576, 91ff0dac5df86e798bfef5e573536b08
diff --git a/tests/ref/fate/dca-xll_51_16_192_768_1 b/tests/ref/fate/dca-xll_51_16_192_768_1
index 6e62c616e2..756d11d868 100644
--- a/tests/ref/fate/dca-xll_51_16_192_768_1
+++ b/tests/ref/fate/dca-xll_51_16_192_768_1
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 192000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     2048,    24576, 91ff0dac5df86e798bfef5e573536b08
diff --git a/tests/ref/fate/dca-xll_51_16_192_768_1-dmix_2 b/tests/ref/fate/dca-xll_51_16_192_768_1-dmix_2
index 17896a7cca..21a574fd90 100644
--- a/tests/ref/fate/dca-xll_51_16_192_768_1-dmix_2
+++ b/tests/ref/fate/dca-xll_51_16_192_768_1-dmix_2
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 192000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     2048,     8192, 0829f71740aab1ab98b33eae21dee122
diff --git a/tests/ref/fate/dca-xll_51_16_192_768_1-dmix_6 b/tests/ref/fate/dca-xll_51_16_192_768_1-dmix_6
index 6e62c616e2..756d11d868 100644
--- a/tests/ref/fate/dca-xll_51_16_192_768_1-dmix_6
+++ b/tests/ref/fate/dca-xll_51_16_192_768_1-dmix_6
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 192000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     2048,    24576, 91ff0dac5df86e798bfef5e573536b08
diff --git a/tests/ref/fate/dca-xll_51_24_48_768 b/tests/ref/fate/dca-xll_51_24_48_768
index 2d10583b49..96c936bdc2 100644
--- a/tests/ref/fate/dca-xll_51_24_48_768
+++ b/tests/ref/fate/dca-xll_51_24_48_768
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,     9216, 13a95890b5f0947d6f058ca9c30a3e01
diff --git a/tests/ref/fate/dca-xll_51_24_48_768-dmix_2 b/tests/ref/fate/dca-xll_51_24_48_768-dmix_2
index be22d7d98e..0527069aef 100644
--- a/tests/ref/fate/dca-xll_51_24_48_768-dmix_2
+++ b/tests/ref/fate/dca-xll_51_24_48_768-dmix_2
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,     3072, d2a70550489de356a2cd6bfc40711204
diff --git a/tests/ref/fate/dca-xll_51_24_48_768-dmix_6 b/tests/ref/fate/dca-xll_51_24_48_768-dmix_6
index 2d10583b49..96c936bdc2 100644
--- a/tests/ref/fate/dca-xll_51_24_48_768-dmix_6
+++ b/tests/ref/fate/dca-xll_51_24_48_768-dmix_6
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,     9216, 13a95890b5f0947d6f058ca9c30a3e01
diff --git a/tests/ref/fate/dca-xll_51_24_48_none b/tests/ref/fate/dca-xll_51_24_48_none
index 17cfd0edb2..6c5b48b26b 100644
--- a/tests/ref/fate/dca-xll_51_24_48_none
+++ b/tests/ref/fate/dca-xll_51_24_48_none
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     1024,    18432, f9debe3f07be68533bf0295e3d2ba68a
diff --git a/tests/ref/fate/dca-xll_51_24_48_none-dmix_2 b/tests/ref/fate/dca-xll_51_24_48_none-dmix_2
index 17cfd0edb2..6c5b48b26b 100644
--- a/tests/ref/fate/dca-xll_51_24_48_none-dmix_2
+++ b/tests/ref/fate/dca-xll_51_24_48_none-dmix_2
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     1024,    18432, f9debe3f07be68533bf0295e3d2ba68a
diff --git a/tests/ref/fate/dca-xll_51_24_48_none-dmix_6 b/tests/ref/fate/dca-xll_51_24_48_none-dmix_6
index 17cfd0edb2..6c5b48b26b 100644
--- a/tests/ref/fate/dca-xll_51_24_48_none-dmix_6
+++ b/tests/ref/fate/dca-xll_51_24_48_none-dmix_6
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     1024,    18432, f9debe3f07be68533bf0295e3d2ba68a
diff --git a/tests/ref/fate/dca-xll_71_24_48_768_0 b/tests/ref/fate/dca-xll_71_24_48_768_0
index a295d41a92..e74e54d44e 100644
--- a/tests/ref/fate/dca-xll_71_24_48_768_0
+++ b/tests/ref/fate/dca-xll_71_24_48_768_0
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 63f
 #channel_layout_name 0: 7.1
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,    12288, ca9f8c8eb1b9b311cb79999fa376c7f0
diff --git a/tests/ref/fate/dca-xll_71_24_48_768_0-dmix_2 b/tests/ref/fate/dca-xll_71_24_48_768_0-dmix_2
index f9b7b655a5..2787b6751d 100644
--- a/tests/ref/fate/dca-xll_71_24_48_768_0-dmix_2
+++ b/tests/ref/fate/dca-xll_71_24_48_768_0-dmix_2
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,     9216, a2b724b146069938f0e2cb82490dea54
diff --git a/tests/ref/fate/dca-xll_71_24_48_768_0-dmix_6 b/tests/ref/fate/dca-xll_71_24_48_768_0-dmix_6
index f9b7b655a5..2787b6751d 100644
--- a/tests/ref/fate/dca-xll_71_24_48_768_0-dmix_6
+++ b/tests/ref/fate/dca-xll_71_24_48_768_0-dmix_6
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,     9216, a2b724b146069938f0e2cb82490dea54
diff --git a/tests/ref/fate/dca-xll_71_24_48_768_1 b/tests/ref/fate/dca-xll_71_24_48_768_1
index a295d41a92..e74e54d44e 100644
--- a/tests/ref/fate/dca-xll_71_24_48_768_1
+++ b/tests/ref/fate/dca-xll_71_24_48_768_1
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 63f
 #channel_layout_name 0: 7.1
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,    12288, ca9f8c8eb1b9b311cb79999fa376c7f0
diff --git a/tests/ref/fate/dca-xll_71_24_48_768_1-dmix_2 b/tests/ref/fate/dca-xll_71_24_48_768_1-dmix_2
index 5b01746258..57f1dab0b1 100644
--- a/tests/ref/fate/dca-xll_71_24_48_768_1-dmix_2
+++ b/tests/ref/fate/dca-xll_71_24_48_768_1-dmix_2
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,     3072, d2a70550489de356a2cd6bfc40711204
diff --git a/tests/ref/fate/dca-xll_71_24_48_768_1-dmix_6 b/tests/ref/fate/dca-xll_71_24_48_768_1-dmix_6
index 246b5e0133..5f847e65c4 100644
--- a/tests/ref/fate/dca-xll_71_24_48_768_1-dmix_6
+++ b/tests/ref/fate/dca-xll_71_24_48_768_1-dmix_6
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,     9216, a2b724b146069938f0e2cb82490dea54
diff --git a/tests/ref/fate/dca-xll_71_24_96_768 b/tests/ref/fate/dca-xll_71_24_96_768
index 418b4b136d..df8ec4da7b 100644
--- a/tests/ref/fate/dca-xll_71_24_96_768
+++ b/tests/ref/fate/dca-xll_71_24_96_768
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 96000
-#channel_layout 0: 63f
 #channel_layout_name 0: 7.1
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     1024,    24576, 0b24a527d66f2b0cab97f37e4cd79987
diff --git a/tests/ref/fate/dca-xll_71_24_96_768-dmix_2 b/tests/ref/fate/dca-xll_71_24_96_768-dmix_2
index 9bd0256c31..b57af93a10 100644
--- a/tests/ref/fate/dca-xll_71_24_96_768-dmix_2
+++ b/tests/ref/fate/dca-xll_71_24_96_768-dmix_2
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 96000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     1024,    18432, 0a675f172b0e1a171c46dfaa4f1d0f00
diff --git a/tests/ref/fate/dca-xll_71_24_96_768-dmix_6 b/tests/ref/fate/dca-xll_71_24_96_768-dmix_6
index 9bd0256c31..b57af93a10 100644
--- a/tests/ref/fate/dca-xll_71_24_96_768-dmix_6
+++ b/tests/ref/fate/dca-xll_71_24_96_768-dmix_6
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 96000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     1024,    18432, 0a675f172b0e1a171c46dfaa4f1d0f00
diff --git a/tests/ref/fate/dca-xll_x96_51_24_96_1509 b/tests/ref/fate/dca-xll_x96_51_24_96_1509
index bc83f793a0..838b1dea54 100644
--- a/tests/ref/fate/dca-xll_x96_51_24_96_1509
+++ b/tests/ref/fate/dca-xll_x96_51_24_96_1509
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 96000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     1024,    18432, f9debe3f07be68533bf0295e3d2ba68a
diff --git a/tests/ref/fate/dca-xll_x96_51_24_96_1509-dmix_2 b/tests/ref/fate/dca-xll_x96_51_24_96_1509-dmix_2
index bc83f793a0..838b1dea54 100644
--- a/tests/ref/fate/dca-xll_x96_51_24_96_1509-dmix_2
+++ b/tests/ref/fate/dca-xll_x96_51_24_96_1509-dmix_2
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 96000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     1024,    18432, f9debe3f07be68533bf0295e3d2ba68a
diff --git a/tests/ref/fate/dca-xll_x96_51_24_96_1509-dmix_6 b/tests/ref/fate/dca-xll_x96_51_24_96_1509-dmix_6
index bc83f793a0..838b1dea54 100644
--- a/tests/ref/fate/dca-xll_x96_51_24_96_1509-dmix_6
+++ b/tests/ref/fate/dca-xll_x96_51_24_96_1509-dmix_6
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 96000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     1024,    18432, f9debe3f07be68533bf0295e3d2ba68a
diff --git a/tests/ref/fate/dca-xll_xch_61_24_48_768 b/tests/ref/fate/dca-xll_xch_61_24_48_768
index 19816d93d3..c0eb4aed5f 100644
--- a/tests/ref/fate/dca-xll_xch_61_24_48_768
+++ b/tests/ref/fate/dca-xll_xch_61_24_48_768
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 70f
 #channel_layout_name 0: 6.1
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,    10752, c3c5b236c266a9090378def1ad497a21
diff --git a/tests/ref/fate/dca-xll_xch_61_24_48_768-dmix_2 b/tests/ref/fate/dca-xll_xch_61_24_48_768-dmix_2
index 1f6989fbe4..0e69ebcf94 100644
--- a/tests/ref/fate/dca-xll_xch_61_24_48_768-dmix_2
+++ b/tests/ref/fate/dca-xll_xch_61_24_48_768-dmix_2
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,     9216, 652c4e61f9abe9fba9de792242e2d31d
diff --git a/tests/ref/fate/dca-xll_xch_61_24_48_768-dmix_6 b/tests/ref/fate/dca-xll_xch_61_24_48_768-dmix_6
index 1f6989fbe4..0e69ebcf94 100644
--- a/tests/ref/fate/dca-xll_xch_61_24_48_768-dmix_6
+++ b/tests/ref/fate/dca-xll_xch_61_24_48_768-dmix_6
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s24le
 #sample_rate 0: 48000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      512,     9216, 652c4e61f9abe9fba9de792242e2d31d
diff --git a/tests/ref/fate/dcinema-encode b/tests/ref/fate/dcinema-encode
index cc53488be1..471820dbda 100644
--- a/tests/ref/fate/dcinema-encode
+++ b/tests/ref/fate/dcinema-encode
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 96000
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      341,     4092, 697cddfcd0e21f24782af0705b7048f3
diff --git a/tests/ref/fate/delphine-cin-audio b/tests/ref/fate/delphine-cin-audio
index 6fdc8048e4..c144dc68f7 100644
--- a/tests/ref/fate/delphine-cin-audio
+++ b/tests/ref/fate/delphine-cin-audio
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,    88224,   176448, 0x541ddc55
 0,      88224,      88224,     1838,     3676, 0xaf455081
diff --git a/tests/ref/fate/dpcm-idroq b/tests/ref/fate/dpcm-idroq
index fb45ace2c6..98b50a1f8f 100644
--- a/tests/ref/fate/dpcm-idroq
+++ b/tests/ref/fate/dpcm-idroq
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     7456,    29824, 0x77e265b7
 0,       7456,       7456,      736,     2944, 0x8dcdf50b
diff --git a/tests/ref/fate/dpcm-interplay b/tests/ref/fate/dpcm-interplay
index 720a98f389..207ef48e91 100644
--- a/tests/ref/fate/dpcm-interplay
+++ b/tests/ref/fate/dpcm-interplay
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1462,     5848, 0xea04292b
 0,       1462,       1462,     1472,     5888, 0x0e59e942
diff --git a/tests/ref/fate/dss-lp b/tests/ref/fate/dss-lp
index ab1d5344b5..9b08345d05 100644
--- a/tests/ref/fate/dss-lp
+++ b/tests/ref/fate/dss-lp
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      240,      480, 0xf1107658
 0,        240,        240,      240,      480, 0x50dee179
diff --git a/tests/ref/fate/dss-sp b/tests/ref/fate/dss-sp
index f407ce7da0..0984f11ebc 100644
--- a/tests/ref/fate/dss-sp
+++ b/tests/ref/fate/dss-sp
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 11025
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      264,      528, 0xa2579e96
 0,        264,        264,      264,      528, 0xf9b23172
diff --git a/tests/ref/fate/ffmpeg-attached_pics b/tests/ref/fate/ffmpeg-attached_pics
index 48c7ced363..515bef3ca4 100644
--- a/tests/ref/fate/ffmpeg-attached_pics
+++ b/tests/ref/fate/ffmpeg-attached_pics
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 44100
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        1,   120000, 0x748cc771
 1,          0,          0,     4096,    16384, 0x00000000
diff --git a/tests/ref/fate/ffmpeg-filter_complex_audio b/tests/ref/fate/ffmpeg-filter_complex_audio
index c424675061..0d1f650040 100644
--- a/tests/ref/fate/ffmpeg-filter_complex_audio
+++ b/tests/ref/fate/ffmpeg-filter_complex_audio
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: ac3
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,       -256,       -256,     1536,      416, 0x3001fb2d
 0,       1280,       1280,     1536,      418, 0xba72fc16
diff --git a/tests/ref/fate/filter-acrossfade b/tests/ref/fate/filter-acrossfade
index 8d524c4d2e..8737d9da57 100644
--- a/tests/ref/fate/filter-acrossfade
+++ b/tests/ref/fate/filter-acrossfade
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      888,     3552, 0x592ce6cc
 0,        888,        888,     1024,     4096, 0x20f6f6a9
diff --git a/tests/ref/fate/filter-adelay b/tests/ref/fate/filter-adelay
index e3ff763602..6370f66f71 100644
--- a/tests/ref/fate/filter-adelay
+++ b/tests/ref/fate/filter-adelay
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x9d7bf760
 0,       1024,       1024,     1024,     4096, 0xdf42c46b
diff --git a/tests/ref/fate/filter-aecho b/tests/ref/fate/filter-aecho
index 2c88c37fbc..706e17e10c 100644
--- a/tests/ref/fate/filter-aecho
+++ b/tests/ref/fate/filter-aecho
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x3019edd5
 0,       1024,       1024,     1024,     4096, 0x2df2fe2f
diff --git a/tests/ref/fate/filter-aemphasis b/tests/ref/fate/filter-aemphasis
index 9509e4319a..143a434972 100644
--- a/tests/ref/fate/filter-aemphasis
+++ b/tests/ref/fate/filter-aemphasis
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 0,          0,          0,     1024,     4096, 0xb9c5fefd
 0,       1024,       1024,     1024,     4096, 0xb2ae0a90
 0,       2048,       2048,     1024,     4096, 0x97e6e9f3
@@ -266,7 +265,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 0,          0,          0,     1024,     4096, 0xfd510c8e
 0,       1024,       1024,     1024,     4096, 0x09dcf895
 0,       2048,       2048,     1024,     4096, 0xd8cbe29f
diff --git a/tests/ref/fate/filter-aemphasis-50fm b/tests/ref/fate/filter-aemphasis-50fm
index 649cd449be..d28a7538bf 100644
--- a/tests/ref/fate/filter-aemphasis-50fm
+++ b/tests/ref/fate/filter-aemphasis-50fm
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0xb9c5fefd
 0,       1024,       1024,     1024,     4096, 0xb2ae0a90
diff --git a/tests/ref/fate/filter-aemphasis-75kf b/tests/ref/fate/filter-aemphasis-75kf
index 5705e98338..765f32ec4c 100644
--- a/tests/ref/fate/filter-aemphasis-75kf
+++ b/tests/ref/fate/filter-aemphasis-75kf
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x7b2101ec
 0,       1024,       1024,     1024,     4096, 0x5c16fc93
diff --git a/tests/ref/fate/filter-afade-esin b/tests/ref/fate/filter-afade-esin
index f9b910c693..41dfaeb565 100644
--- a/tests/ref/fate/filter-afade-esin
+++ b/tests/ref/fate/filter-afade-esin
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x06e0d68a
 0,       1024,       1024,     1024,     4096, 0xb325d915
diff --git a/tests/ref/fate/filter-afade-exp b/tests/ref/fate/filter-afade-exp
index a0c519cd8b..2a75db1986 100644
--- a/tests/ref/fate/filter-afade-exp
+++ b/tests/ref/fate/filter-afade-exp
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x00000000
 0,       1024,       1024,     1024,     4096, 0x00000000
diff --git a/tests/ref/fate/filter-afade-hsin b/tests/ref/fate/filter-afade-hsin
index 2c6a0e3a1e..b95bac047c 100644
--- a/tests/ref/fate/filter-afade-hsin
+++ b/tests/ref/fate/filter-afade-hsin
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x2042232e
 0,       1024,       1024,     1024,     4096, 0x2c073cf7
diff --git a/tests/ref/fate/filter-afade-iqsin b/tests/ref/fate/filter-afade-iqsin
index fc22baf913..9caa3203a9 100644
--- a/tests/ref/fate/filter-afade-iqsin
+++ b/tests/ref/fate/filter-afade-iqsin
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x220e908d
 0,       1024,       1024,     1024,     4096, 0xdd65002e
diff --git a/tests/ref/fate/filter-afade-log b/tests/ref/fate/filter-afade-log
index 99ac0b36d8..f3ba265a68 100644
--- a/tests/ref/fate/filter-afade-log
+++ b/tests/ref/fate/filter-afade-log
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0xf01adbd3
 0,       1024,       1024,     1024,     4096, 0xbbe10f8e
diff --git a/tests/ref/fate/filter-afade-qsin b/tests/ref/fate/filter-afade-qsin
index 026fbbcc44..df3005edbc 100644
--- a/tests/ref/fate/filter-afade-qsin
+++ b/tests/ref/fate/filter-afade-qsin
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0xd977ce0f
 0,       1024,       1024,     1024,     4096, 0x9333f5b1
diff --git a/tests/ref/fate/filter-agate b/tests/ref/fate/filter-agate
index b6e732a86e..e2d9c2ac24 100644
--- a/tests/ref/fate/filter-agate
+++ b/tests/ref/fate/filter-agate
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x1af20090
 0,       1024,       1024,     1024,     4096, 0x0b05ef2d
diff --git a/tests/ref/fate/filter-alimiter b/tests/ref/fate/filter-alimiter
index aef9765a83..56cfb614da 100644
--- a/tests/ref/fate/filter-alimiter
+++ b/tests/ref/fate/filter-alimiter
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0xd4194af4
 0,       1024,       1024,     1024,     4096, 0x686af4ab
diff --git a/tests/ref/fate/filter-amerge b/tests/ref/fate/filter-amerge
index b3e5eb50cc..89c07029fd 100644
--- a/tests/ref/fate/filter-amerge
+++ b/tests/ref/fate/filter-amerge
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     2048,     8192, 0x120efa65
 0,       2048,       2048,     2048,     8192, 0x7b3cebf7
diff --git a/tests/ref/fate/filter-anequalizer b/tests/ref/fate/filter-anequalizer
index caed836bdf..250c9ede91 100644
--- a/tests/ref/fate/filter-anequalizer
+++ b/tests/ref/fate/filter-anequalizer
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x8e1bf8e0
 0,       1024,       1024,     1024,     4096, 0xe315f564
diff --git a/tests/ref/fate/filter-apad b/tests/ref/fate/filter-apad
index 9bf662d46a..79ed050a4b 100644
--- a/tests/ref/fate/filter-apad
+++ b/tests/ref/fate/filter-apad
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x29e3eecf
 0,       1024,       1024,     1024,     4096, 0x18390b96
diff --git a/tests/ref/fate/filter-asetnsamples-nopad b/tests/ref/fate/filter-asetnsamples-nopad
index c1cc01a710..e5306d4516 100644
--- a/tests/ref/fate/filter-asetnsamples-nopad
+++ b/tests/ref/fate/filter-asetnsamples-nopad
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      512,     2048, 0xd2dbf701
 0,        512,        512,      512,     2048, 0xdb22f7bf
diff --git a/tests/ref/fate/filter-asetnsamples-pad b/tests/ref/fate/filter-asetnsamples-pad
index 23cf11b8af..80f6e1d574 100644
--- a/tests/ref/fate/filter-asetnsamples-pad
+++ b/tests/ref/fate/filter-asetnsamples-pad
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      512,     2048, 0xd2dbf701
 0,        512,        512,      512,     2048, 0xdb22f7bf
diff --git a/tests/ref/fate/filter-asetrate b/tests/ref/fate/filter-asetrate
index 6ffa940361..4b5e87d69e 100644
--- a/tests/ref/fate/filter-asetrate
+++ b/tests/ref/fate/filter-asetrate
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 20000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x29e3eecf
 0,       1024,       1024,     1024,     4096, 0x18390b96
diff --git a/tests/ref/fate/filter-atrim-duration b/tests/ref/fate/filter-atrim-duration
index fafda1717f..1c4cf57128 100644
--- a/tests/ref/fate/filter-atrim-duration
+++ b/tests/ref/fate/filter-atrim-duration
@@ -2,6 +2,5 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,       4410,       4410,      441,     1764, 0x61e374f7
diff --git a/tests/ref/fate/filter-atrim-mixed b/tests/ref/fate/filter-atrim-mixed
index 4cd1d8004f..7f16639406 100644
--- a/tests/ref/fate/filter-atrim-mixed
+++ b/tests/ref/fate/filter-atrim-mixed
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,       1025,       1025,     1023,     4092, 0x78560a4c
 0,       2048,       2048,     1024,     4096, 0xc477fa99
diff --git a/tests/ref/fate/filter-atrim-samples b/tests/ref/fate/filter-atrim-samples
index 2d8c9a5235..74dc5d3b26 100644
--- a/tests/ref/fate/filter-atrim-samples
+++ b/tests/ref/fate/filter-atrim-samples
@@ -2,6 +2,5 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,         26,         26,       54,      216, 0x6b376c6c
diff --git a/tests/ref/fate/filter-atrim-time b/tests/ref/fate/filter-atrim-time
index a0c626c4ba..2f8d87ecbe 100644
--- a/tests/ref/fate/filter-atrim-time
+++ b/tests/ref/fate/filter-atrim-time
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,       4410,       4410,      710,     2840, 0x658982a3
 0,       5120,       5120,     1024,     4096, 0xfd6a0070
diff --git a/tests/ref/fate/filter-chorus b/tests/ref/fate/filter-chorus
index 211e60ecb1..97c7919655 100644
--- a/tests/ref/fate/filter-chorus
+++ b/tests/ref/fate/filter-chorus
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     2048,     4096, 0x1fc6f1f1
 0,       2048,       2048,     2048,     4096, 0xe5f7f442
diff --git a/tests/ref/fate/filter-compand b/tests/ref/fate/filter-compand
index ac9095f4e3..285416172e 100644
--- a/tests/ref/fate/filter-compand
+++ b/tests/ref/fate/filter-compand
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0xfc10e61b
 0,       1024,       1024,     1024,     4096, 0x8801ef13
diff --git a/tests/ref/fate/filter-concat b/tests/ref/fate/filter-concat
index 022697ec5b..42879a45e0 100644
--- a/tests/ref/fate/filter-concat
+++ b/tests/ref/fate/filter-concat
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 44100
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   230400, 0x88c4d19a
 1,          0,          0,     1024,     2048, 0xb3f10192
diff --git a/tests/ref/fate/filter-concat-vfr b/tests/ref/fate/filter-concat-vfr
index 0dece67a07..7c5e12e093 100644
--- a/tests/ref/fate/filter-concat-vfr
+++ b/tests/ref/fate/filter-concat-vfr
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 44100
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        0,   230400, 0x88c4d19a
 1,          0,          0,     1024,     2048, 0xb3f10192
diff --git a/tests/ref/fate/filter-dcshift b/tests/ref/fate/filter-dcshift
index dad3df3ff0..4ad1401a9e 100644
--- a/tests/ref/fate/filter-dcshift
+++ b/tests/ref/fate/filter-dcshift
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x96868842
 0,       1024,       1024,     1024,     4096, 0xeff98700
diff --git a/tests/ref/fate/filter-earwax b/tests/ref/fate/filter-earwax
index 6bfa725b64..7626482899 100644
--- a/tests/ref/fate/filter-earwax
+++ b/tests/ref/fate/filter-earwax
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0xb7e1f437
 0,       1024,       1024,     1024,     4096, 0xa031042a
diff --git a/tests/ref/fate/filter-extrastereo b/tests/ref/fate/filter-extrastereo
index 179c167792..a94d5f2e95 100644
--- a/tests/ref/fate/filter-extrastereo
+++ b/tests/ref/fate/filter-extrastereo
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x29e3eecf
 0,       1024,       1024,     1024,     4096, 0x18390b96
diff --git a/tests/ref/fate/filter-hls b/tests/ref/fate/filter-hls
index ee3c7b2c62..ed0ecc8e76 100644
--- a/tests/ref/fate/filter-hls
+++ b/tests/ref/fate/filter-hls
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1152,     2304, 0x907cb7fa
 0,       1152,       1152,     1152,     2304, 0xb8dc7525
diff --git a/tests/ref/fate/filter-hls-append b/tests/ref/fate/filter-hls-append
index 52b7dff480..902571cb52 100644
--- a/tests/ref/fate/filter-hls-append
+++ b/tests/ref/fate/filter-hls-append
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1152,     2304, 0x907cb7fa
 0,      26496,      26496,     1152,     2304, 0xb8dc7525
diff --git a/tests/ref/fate/filter-meta-4560-rotate0 b/tests/ref/fate/filter-meta-4560-rotate0
index 97552ffb97..0c33709b77 100644
--- a/tests/ref/fate/filter-meta-4560-rotate0
+++ b/tests/ref/fate/filter-meta-4560-rotate0
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 44100
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   195840, 0x0602351d
 1,          0,          0,     1024,     2048, 0x00000000
diff --git a/tests/ref/fate/filter-overlay-dvdsub-2397 b/tests/ref/fate/filter-overlay-dvdsub-2397
index 483e5fa4e0..7df4f50776 100644
--- a/tests/ref/fate/filter-overlay-dvdsub-2397
+++ b/tests/ref/fate/filter-overlay-dvdsub-2397
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: dts
 #sample_rate 1: 48000
-#channel_layout 1: 60f
 #channel_layout_name 1: 5.1(side)
 0,          0,          0,        1,   518400, 0x6b05d48a
 1,         27,         27,       10,     2013, 0x68e7b03a
diff --git a/tests/ref/fate/filter-pan-downmix1 b/tests/ref/fate/filter-pan-downmix1
index 47d5044dac..85630ab179 100644
--- a/tests/ref/fate/filter-pan-downmix1
+++ b/tests/ref/fate/filter-pan-downmix1
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      512,     2048, 0xccb10170
 0,        512,        512,      512,     2048, 0xc51cf8e7
diff --git a/tests/ref/fate/filter-pan-downmix2 b/tests/ref/fate/filter-pan-downmix2
index 8d3ee10812..4ec18fc7dd 100644
--- a/tests/ref/fate/filter-pan-downmix2
+++ b/tests/ref/fate/filter-pan-downmix2
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 0
 #channel_layout_name 0: 5 channels
 0,          0,          0,      186,     1860, 0x2480a20e
 0,        186,        186,      186,     1860, 0xde9e9c40
diff --git a/tests/ref/fate/filter-pan-mono1 b/tests/ref/fate/filter-pan-mono1
index 3bd7c25bc1..80afee20a3 100644
--- a/tests/ref/fate/filter-pan-mono1
+++ b/tests/ref/fate/filter-pan-mono1
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1024,     2048, 0x750f0a66
 0,       1024,       1024,     1024,     2048, 0x155cf063
diff --git a/tests/ref/fate/filter-pan-mono2 b/tests/ref/fate/filter-pan-mono2
index 0867ca9a13..02046aebe2 100644
--- a/tests/ref/fate/filter-pan-mono2
+++ b/tests/ref/fate/filter-pan-mono2
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 0
 #channel_layout_name 0: 1 channels
 0,          0,          0,     1024,     2048, 0x6130fb80
 0,       1024,       1024,     1024,     2048, 0xd5ef0930
diff --git a/tests/ref/fate/filter-pan-stereo1 b/tests/ref/fate/filter-pan-stereo1
index 3125d4e570..b4270bb113 100644
--- a/tests/ref/fate/filter-pan-stereo1
+++ b/tests/ref/fate/filter-pan-stereo1
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      682,     2728, 0xaf365458
 0,        682,        682,      682,     2728, 0xcd684898
diff --git a/tests/ref/fate/filter-pan-stereo2 b/tests/ref/fate/filter-pan-stereo2
index 7f96799e2c..dcd429a0ce 100644
--- a/tests/ref/fate/filter-pan-stereo2
+++ b/tests/ref/fate/filter-pan-stereo2
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      682,     2728, 0x35c15e81
 0,        682,        682,      682,     2728, 0x770f2e2d
diff --git a/tests/ref/fate/filter-pan-stereo3 b/tests/ref/fate/filter-pan-stereo3
index effe11c785..726608b2bc 100644
--- a/tests/ref/fate/filter-pan-stereo3
+++ b/tests/ref/fate/filter-pan-stereo3
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0xa0d1fbb3
 0,       1024,       1024,     1024,     4096, 0x598a056c
diff --git a/tests/ref/fate/filter-pan-stereo4 b/tests/ref/fate/filter-pan-stereo4
index 6d10ed62a8..92ed0685fe 100644
--- a/tests/ref/fate/filter-pan-stereo4
+++ b/tests/ref/fate/filter-pan-stereo4
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 0
 #channel_layout_name 0: 2 channels
 0,          0,          0,     1024,     4096, 0x7bd6fc44
 0,       1024,       1024,     1024,     4096, 0xed38ec37
diff --git a/tests/ref/fate/filter-pan-upmix1 b/tests/ref/fate/filter-pan-upmix1
index 87c70a7f1f..c36192c22a 100644
--- a/tests/ref/fate/filter-pan-upmix1
+++ b/tests/ref/fate/filter-pan-upmix1
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 0
 #channel_layout_name 0: 4 channels
 0,          0,          0,     1024,     8192, 0xdaadfc44
 0,       1024,       1024,     1024,     8192, 0xe6d9ec37
diff --git a/tests/ref/fate/filter-pan-upmix2 b/tests/ref/fate/filter-pan-upmix2
index 56db1c17e1..1084a8f68c 100644
--- a/tests/ref/fate/filter-pan-upmix2
+++ b/tests/ref/fate/filter-pan-upmix2
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 0
 #channel_layout_name 0: 9 channels
 0,          0,          0,      512,     9216, 0xd561bb2b
 0,        512,        512,      512,     9216, 0x591805f9
diff --git a/tests/ref/fate/filter-silenceremove b/tests/ref/fate/filter-silenceremove
index 58b5a38607..26f5651672 100644
--- a/tests/ref/fate/filter-silenceremove
+++ b/tests/ref/fate/filter-silenceremove
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     8192,    16384, 0x00000000
 0,       8192,       8192,     8192,    16384, 0x00000000
diff --git a/tests/ref/fate/filter-stereotools b/tests/ref/fate/filter-stereotools
index 60acaf81b2..60a74893bd 100644
--- a/tests/ref/fate/filter-stereotools
+++ b/tests/ref/fate/filter-stereotools
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0x48b6d241
 0,       1024,       1024,     1024,     4096, 0xe0c4ca9a
diff --git a/tests/ref/fate/g722-encode b/tests/ref/fate/g722-encode
index d84d62701c..f178c8ca35 100644
--- a/tests/ref/fate/g722-encode
+++ b/tests/ref/fate/g722-encode
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 16000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     8192,    16384, 1dd9c285eb608038f3257d1a8e02eb75
diff --git a/tests/ref/fate/g722dec-1 b/tests/ref/fate/g722dec-1
index a97fc81fb0..9859984a54 100644
--- a/tests/ref/fate/g722dec-1
+++ b/tests/ref/fate/g722dec-1
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 16000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     2048,     4096, 0x4f9228b3
 0,       2048,       2048,     2048,     4096, 0xfab58157
diff --git a/tests/ref/fate/g723_1-dec-1 b/tests/ref/fate/g723_1-dec-1
index f7daad1b49..e0adff2754 100644
--- a/tests/ref/fate/g723_1-dec-1
+++ b/tests/ref/fate/g723_1-dec-1
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      240,      480, 0x7f6f3970
 0,        240,        240,      240,      480, 0x1105a0d3
diff --git a/tests/ref/fate/g723_1-dec-2 b/tests/ref/fate/g723_1-dec-2
index a403e565d0..04c1ca7385 100644
--- a/tests/ref/fate/g723_1-dec-2
+++ b/tests/ref/fate/g723_1-dec-2
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      240,      480, 0x5d9d9091
 0,        240,        240,      240,      480, 0x425095b7
diff --git a/tests/ref/fate/g723_1-dec-3 b/tests/ref/fate/g723_1-dec-3
index e3d3978138..f4a95d13ce 100644
--- a/tests/ref/fate/g723_1-dec-3
+++ b/tests/ref/fate/g723_1-dec-3
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      240,      480, 0xce908869
 0,        240,        240,      240,      480, 0xfa63588e
diff --git a/tests/ref/fate/g723_1-dec-4 b/tests/ref/fate/g723_1-dec-4
index 309b3afea5..7b092dca16 100644
--- a/tests/ref/fate/g723_1-dec-4
+++ b/tests/ref/fate/g723_1-dec-4
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      240,      480, 0xa697b314
 0,        240,        240,      240,      480, 0x43c5dc5a
diff --git a/tests/ref/fate/g723_1-dec-5 b/tests/ref/fate/g723_1-dec-5
index 9e37c861a2..9e0b6e4cd5 100644
--- a/tests/ref/fate/g723_1-dec-5
+++ b/tests/ref/fate/g723_1-dec-5
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      240,      480, 0x4dce9773
 0,        240,        240,      240,      480, 0xe6367ab8
diff --git a/tests/ref/fate/g723_1-dec-6 b/tests/ref/fate/g723_1-dec-6
index a51e8df9c8..f0e67b14db 100644
--- a/tests/ref/fate/g723_1-dec-6
+++ b/tests/ref/fate/g723_1-dec-6
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      240,      480, 0x4fa1aed9
 0,        240,        240,      240,      480, 0x6d7ef391
diff --git a/tests/ref/fate/g723_1-dec-7 b/tests/ref/fate/g723_1-dec-7
index db0ceb85ef..34be011d8e 100644
--- a/tests/ref/fate/g723_1-dec-7
+++ b/tests/ref/fate/g723_1-dec-7
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      240,      480, 0x35e4a1fd
 0,        240,        240,      240,      480, 0x2f7bdd60
diff --git a/tests/ref/fate/g723_1-dec-8 b/tests/ref/fate/g723_1-dec-8
index 740ed2b4c7..80ad39498a 100644
--- a/tests/ref/fate/g723_1-dec-8
+++ b/tests/ref/fate/g723_1-dec-8
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      240,      480, 0x17930e0f
 0,        240,        240,      240,      480, 0x7c7f4247
diff --git a/tests/ref/fate/g726-encode-2bit b/tests/ref/fate/g726-encode-2bit
index 4a83c95760..2aafcc8bf2 100644
--- a/tests/ref/fate/g726-encode-2bit
+++ b/tests/ref/fate/g726-encode-2bit
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,    16384,    32768, b28b116d2315323aeba6b66b58b7f4ed
diff --git a/tests/ref/fate/g726-encode-3bit b/tests/ref/fate/g726-encode-3bit
index c551ae608f..96c6b9447b 100644
--- a/tests/ref/fate/g726-encode-3bit
+++ b/tests/ref/fate/g726-encode-3bit
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,    10920,    21840, 517dd6d1ce566b998251f0d215fa69c0
diff --git a/tests/ref/fate/g726-encode-4bit b/tests/ref/fate/g726-encode-4bit
index ea277e12c5..28e9ee0284 100644
--- a/tests/ref/fate/g726-encode-4bit
+++ b/tests/ref/fate/g726-encode-4bit
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     8192,    16384, a0cf3a0953adce1a1032a4fd2da00a52
diff --git a/tests/ref/fate/g726-encode-5bit b/tests/ref/fate/g726-encode-5bit
index 30c456e864..c7cd7dd1d9 100644
--- a/tests/ref/fate/g726-encode-5bit
+++ b/tests/ref/fate/g726-encode-5bit
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,     6552,    13104, 6fe3f75df1262c5f956887de9c32df40
diff --git a/tests/ref/fate/gapless-mp3 b/tests/ref/fate/gapless-mp3
index 0b4937792a..578db55534 100644
--- a/tests/ref/fate/gapless-mp3
+++ b/tests/ref/fate/gapless-mp3
@@ -1,5 +1,5 @@
-77ef234e382c15b8afc416ca9c80024b *tests/data/fate/gapless-mp3.out-1
+d7e884aea266b63f1547f1ad10188c08 *tests/data/fate/gapless-mp3.out-1
 c96c3ae7bd3300fd2f4debac222de5b7
-c594be833fb94ae91f2734bcba56c359 *tests/data/fate/gapless-mp3.out-2
+75bc539914297a191f40af2d737d7380 *tests/data/fate/gapless-mp3.out-2
 c96c3ae7bd3300fd2f4debac222de5b7
-5a285806cad6524a3d6184775e097d24 *tests/data/fate/gapless-mp3.out-3
+ab21e0bd0c2d84426153d4cde919a1e3 *tests/data/fate/gapless-mp3.out-3
diff --git a/tests/ref/fate/gsm-ms b/tests/ref/fate/gsm-ms
index 0acf9f6e69..a7bebac0fe 100644
--- a/tests/ref/fate/gsm-ms
+++ b/tests/ref/fate/gsm-ms
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      320,      640, 0xf79c59ee
 0,        320,        320,      320,      640, 0x6e6248be
diff --git a/tests/ref/fate/gsm-toast b/tests/ref/fate/gsm-toast
index df5e824408..6b272433de 100644
--- a/tests/ref/fate/gsm-toast
+++ b/tests/ref/fate/gsm-toast
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,       64,      128, 0x3ef33f6f
 0,         64,         64,      160,      320, 0x2052a4e7
diff --git a/tests/ref/fate/h264-skip-nointra b/tests/ref/fate/h264-skip-nointra
index 0259902927..82977ce674 100644
--- a/tests/ref/fate/h264-skip-nointra
+++ b/tests/ref/fate/h264-skip-nointra
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 1,          0,          0,     1152,     4608, 0x00000000
 1,       1152,       1152,     1152,     4608, 0x00000000
diff --git a/tests/ref/fate/h264-skip-nokey b/tests/ref/fate/h264-skip-nokey
index 0259902927..82977ce674 100644
--- a/tests/ref/fate/h264-skip-nokey
+++ b/tests/ref/fate/h264-skip-nokey
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 1,          0,          0,     1152,     4608, 0x00000000
 1,       1152,       1152,     1152,     4608, 0x00000000
diff --git a/tests/ref/fate/h264-xavc-4389 b/tests/ref/fate/h264-xavc-4389
index 5c76bc222f..b8d957d963 100644
--- a/tests/ref/fate/h264-xavc-4389
+++ b/tests/ref/fate/h264-xavc-4389
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 48000
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,  8294400, 0x9a02ecf2
 1,          0,          0,     1920,     3840, 0x38074ac8
diff --git a/tests/ref/fate/hls-fmp4 b/tests/ref/fate/hls-fmp4
index 98b037fc8f..df11c55540 100644
--- a/tests/ref/fate/hls-fmp4
+++ b/tests/ref/fate/hls-fmp4
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1152,     2304, 0x907cb7fa
 0,       1152,       1152,     1152,     2304, 0xb8dc7525
diff --git a/tests/ref/fate/hls-init-time b/tests/ref/fate/hls-init-time
index 5bc12272cc..f1c62d551f 100644
--- a/tests/ref/fate/hls-init-time
+++ b/tests/ref/fate/hls-init-time
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1152,     2304, 0x28123557
 0,       1152,       1152,     1152,     2304, 0x838c7e81
diff --git a/tests/ref/fate/hls-list-size b/tests/ref/fate/hls-list-size
index cf7fb9fe3a..2dd6ef8426 100644
--- a/tests/ref/fate/hls-list-size
+++ b/tests/ref/fate/hls-list-size
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1152,     2304, 0x9ce3278a
 0,       1152,       1152,     1152,     2304, 0x5cd17b17
diff --git a/tests/ref/fate/hls-segment-single b/tests/ref/fate/hls-segment-single
index ee3c7b2c62..ed0ecc8e76 100644
--- a/tests/ref/fate/hls-segment-single
+++ b/tests/ref/fate/hls-segment-single
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1152,     2304, 0x907cb7fa
 0,       1152,       1152,     1152,     2304, 0xb8dc7525
diff --git a/tests/ref/fate/hls-segment-size b/tests/ref/fate/hls-segment-size
index ee3c7b2c62..ed0ecc8e76 100644
--- a/tests/ref/fate/hls-segment-size
+++ b/tests/ref/fate/hls-segment-size
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1152,     2304, 0x907cb7fa
 0,       1152,       1152,     1152,     2304, 0xb8dc7525
diff --git a/tests/ref/fate/id-cin-video b/tests/ref/fate/id-cin-video
index 671b396a11..e3da4aa071 100644
--- a/tests/ref/fate/id-cin-video
+++ b/tests/ref/fate/id-cin-video
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 22050
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        1,   230400, 0x00000000
 1,          0,          0,     1575,     6300, 0xdd759df8
diff --git a/tests/ref/fate/id3v2-chapters b/tests/ref/fate/id3v2-chapters
index 5aa8f82af9..c845e88821 100644
--- a/tests/ref/fate/id3v2-chapters
+++ b/tests/ref/fate/id3v2-chapters
@@ -4,7 +4,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 48000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,     4096, 0xc5b6547b
 0,       1024,       1024,     1024,     4096, 0x0f27633e
diff --git a/tests/ref/fate/id3v2-priv-remux b/tests/ref/fate/id3v2-priv-remux
index a30f68a256..a0f370142e 100644
--- a/tests/ref/fate/id3v2-priv-remux
+++ b/tests/ref/fate/id3v2-priv-remux
@@ -4,7 +4,6 @@ bb2816e3a05ce136e9ac14479c1ebe24 *tests/data/fate/id3v2-priv-remux.mp3
 #media_type 0: audio
 #codec_id 0: mp3
 #sample_rate 0: 48000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,    -155528,    -155528,   338688,      192, 0x3774510e, S=1,       10
 0,     183160,     183160,   338688,      192, 0x856c5b02
diff --git a/tests/ref/fate/jv-demux b/tests/ref/fate/jv-demux
index bf8211074c..b5d3196cf5 100644
--- a/tests/ref/fate/jv-demux
+++ b/tests/ref/fate/jv-demux
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_u8
 #sample_rate 1: 22050
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,        6, 0x000a0003
 1,          0,          0,   131072,   131072, 0x14c664d6
diff --git a/tests/ref/fate/lmlm4-demux b/tests/ref/fate/lmlm4-demux
index b0276d53e9..9bddf58408 100644
--- a/tests/ref/fate/lmlm4-demux
+++ b/tests/ref/fate/lmlm4-demux
@@ -8,7 +8,6 @@
 #media_type 1: audio
 #codec_id 1: mp2
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0, -9223372036854775808,        1,     5951, 0xe9118e0d
 1,          0,          0,     2160,      768, 0xaebcbebb
diff --git a/tests/ref/fate/matroska-flac-channel-mapping b/tests/ref/fate/matroska-flac-channel-mapping
index 6d901600e5..25627d6570 100644
--- a/tests/ref/fate/matroska-flac-channel-mapping
+++ b/tests/ref/fate/matroska-flac-channel-mapping
@@ -4,13 +4,11 @@
 #media_type 0: audio
 #codec_id 0: flac
 #sample_rate 0: 48000
-#channel_layout 0: 3f
 #channel_layout_name 0: 5.1
 #tb 1: 651/31250000
 #media_type 1: audio
 #codec_id 1: flac
 #sample_rate 1: 48000
-#channel_layout 1: 60f
 #channel_layout_name 1: 5.1(side)
 0,          0,          0,     4096,       26, 0x50f80431
 1,          0,          0,     4096,       26, 0x50f80431
diff --git a/tests/ref/fate/matroska-flac-extradata-update b/tests/ref/fate/matroska-flac-extradata-update
index 1a8add7736..42d550b580 100644
--- a/tests/ref/fate/matroska-flac-extradata-update
+++ b/tests/ref/fate/matroska-flac-extradata-update
@@ -7,19 +7,16 @@ c2b76d47a9f0e9626a4999bd395cae08 *tests/data/fate/matroska-flac-extradata-update
 #media_type 0: audio
 #codec_id 0: flac
 #sample_rate 0: 48000
-#channel_layout 0: 3f
 #channel_layout_name 0: 5.1
 #tb 1: 1/1000
 #media_type 1: audio
 #codec_id 1: flac
 #sample_rate 1: 48000
-#channel_layout 1: 60f
 #channel_layout_name 1: 5.1(side)
 #tb 2: 1/1000
 #media_type 2: audio
 #codec_id 2: flac
 #sample_rate 2: 48000
-#channel_layout 2: 3f
 #channel_layout_name 2: 5.1
 0,          0,          0,       96,       26, 0x4e160341
 1,          0,          0,       96,       26, 0x4e160341
diff --git a/tests/ref/fate/matroska-lzo-decompression b/tests/ref/fate/matroska-lzo-decompression
index 241d5adf44..568e32eccc 100644
--- a/tests/ref/fate/matroska-lzo-decompression
+++ b/tests/ref/fate/matroska-lzo-decompression
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     4096,    16384, 0x00000000
 0,       4096,       4096,     4096,    16384, 0xad7eebf4
diff --git a/tests/ref/fate/matroska-mastering-display-metadata b/tests/ref/fate/matroska-mastering-display-metadata
index 8f5d7b6a22..1701f81281 100644
--- a/tests/ref/fate/matroska-mastering-display-metadata
+++ b/tests/ref/fate/matroska-mastering-display-metadata
@@ -11,13 +11,11 @@
 #media_type 1: audio
 #codec_id 1: pcm_s24le
 #sample_rate 1: 48000
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 #tb 2: 1/1000
 #media_type 2: audio
 #codec_id 2: pcm_s16be
 #sample_rate 2: 48000
-#channel_layout 2: 4
 #channel_layout_name 2: mono
 #tb 3: 1/1000
 #media_type 3: video
diff --git a/tests/ref/fate/matroska-mpegts-remux b/tests/ref/fate/matroska-mpegts-remux
index 9478294b8e..148bc0ffbc 100644
--- a/tests/ref/fate/matroska-mpegts-remux
+++ b/tests/ref/fate/matroska-mpegts-remux
@@ -4,13 +4,11 @@
 #media_type 0: audio
 #codec_id 0: ac3
 #sample_rate 0: 48000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 #tb 1: 1/1000
 #media_type 1: audio
 #codec_id 1: ac3
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,       32,      768, 0xa63778d4
 1,          0,          0,       32,      768, 0xa63778d4
diff --git a/tests/ref/fate/matroska-wavpack-missing-codecprivate b/tests/ref/fate/matroska-wavpack-missing-codecprivate
index 4645a86ff6..2a91f1c9ca 100644
--- a/tests/ref/fate/matroska-wavpack-missing-codecprivate
+++ b/tests/ref/fate/matroska-wavpack-missing-codecprivate
@@ -3,7 +3,6 @@
 #media_type 0: audio
 #codec_id 0: wavpack
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,    22051,    14778, 0x02819286
 0,      22051,      22051,    22052,    14756, 0x21976243
diff --git a/tests/ref/fate/matroska-xiph-lacing b/tests/ref/fate/matroska-xiph-lacing
index c74cf9900d..dd00f21e93 100644
--- a/tests/ref/fate/matroska-xiph-lacing
+++ b/tests/ref/fate/matroska-xiph-lacing
@@ -3,7 +3,6 @@
 #media_type 0: audio
 #codec_id 0: vorbis
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      128,       84, 0x1beb2cc9
 0,        128,        128,      576,      533, 0xa5d425e9
diff --git a/tests/ref/fate/maxis-xa b/tests/ref/fate/maxis-xa
index ad9d73278b..120ec9e603 100644
--- a/tests/ref/fate/maxis-xa
+++ b/tests/ref/fate/maxis-xa
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: adpcm_ea_maxis_xa
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,       28,       30, 0x51750711
 0,         28,         28,       28,       30, 0x9ca20c2a
diff --git a/tests/ref/fate/mkv b/tests/ref/fate/mkv
index f9c3037f09..d3dfef76b1 100644
--- a/tests/ref/fate/mkv
+++ b/tests/ref/fate/mkv
@@ -9,7 +9,6 @@
 #media_type 1: audio
 #codec_id 1: aac
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,        -42,          0,       41,    63501, 0x139d4c99
 0,          0,         84,       41,     5368, 0xd964b678, F=0x0
diff --git a/tests/ref/fate/mkv-1242 b/tests/ref/fate/mkv-1242
index 34e5b4aa9c..e025701093 100644
--- a/tests/ref/fate/mkv-1242
+++ b/tests/ref/fate/mkv-1242
@@ -9,7 +9,6 @@
 #media_type 1: audio
 #codec_id 1: aac
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,        -42,          0,       41,     2969, 0xa7016742
 0,          0,         42,       41,      135, 0x33af1a9e, F=0x0
diff --git a/tests/ref/fate/mov-440hz-10ms b/tests/ref/fate/mov-440hz-10ms
index 498879e52d..77b50d262c 100644
--- a/tests/ref/fate/mov-440hz-10ms
+++ b/tests/ref/fate/mov-440hz-10ms
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,      960,     1920, 44e7e48ff08835ce30e93c7971dae7df
diff --git a/tests/ref/fate/mov-bbi-elst-starts-b b/tests/ref/fate/mov-bbi-elst-starts-b
index 3ba28b5e75..f6c2c56eb2 100644
--- a/tests/ref/fate/mov-bbi-elst-starts-b
+++ b/tests/ref/fate/mov-bbi-elst-starts-b
@@ -10,7 +10,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 #stream#, dts,        pts, duration,     size, hash
 0,          0,          0,        1,  3110400, e9454409af76038dbe56e834921d2fa8
diff --git a/tests/ref/fate/mov-cover-image b/tests/ref/fate/mov-cover-image
index 6141646afa..5f65c630ea 100644
--- a/tests/ref/fate/mov-cover-image
+++ b/tests/ref/fate/mov-cover-image
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: aac
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 #tb 1: 1/90000
 #media_type 1: video
diff --git a/tests/ref/fate/mov-mp3-demux b/tests/ref/fate/mov-mp3-demux
index 1930960640..77ec4acedf 100644
--- a/tests/ref/fate/mov-mp3-demux
+++ b/tests/ref/fate/mov-mp3-demux
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: mp3
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1152,       36, 0x8e260589
 0,       1152,       1152,     1152,       36, 0x8e260589
diff --git a/tests/ref/fate/mov-mp4-disposition-mpegts-remux b/tests/ref/fate/mov-mp4-disposition-mpegts-remux
index 184b952e04..efef043074 100644
--- a/tests/ref/fate/mov-mp4-disposition-mpegts-remux
+++ b/tests/ref/fate/mov-mp4-disposition-mpegts-remux
@@ -4,13 +4,11 @@ adb3b95c07a5f3e0c86641dd62f01dae *tests/data/fate/mov-mp4-disposition-mpegts-rem
 #media_type 0: audio
 #codec_id 0: ac3
 #sample_rate 0: 48000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 #tb 1: 1/48000
 #media_type 1: audio
 #codec_id 1: ac3
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 1,          0,          0,     1536,      768, 0xa63778d4, S=1,        4
 1,       1536,       1536,     1536,      768, 0x7d577f3f
diff --git a/tests/ref/fate/mpegps-remuxed-pcm-demux b/tests/ref/fate/mpegps-remuxed-pcm-demux
index b5b277868f..20173d3a44 100644
--- a/tests/ref/fate/mpegps-remuxed-pcm-demux
+++ b/tests/ref/fate/mpegps-remuxed-pcm-demux
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_dvd
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     2040,     2005, 0x8e98e563
 0,       2090,       2090,     2069,     2033, 0xd6f2f455
diff --git a/tests/ref/fate/mtv b/tests/ref/fate/mtv
index 7b17bc1b6c..a4647a39ac 100644
--- a/tests/ref/fate/mtv
+++ b/tests/ref/fate/mtv
@@ -8,7 +8,6 @@
 #media_type 1: audio
 #codec_id 1: mp3
 #sample_rate 1: 44100
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        1,    12288, 0xc2258ebc
 1,          0,          0,     1152,      417, 0xae1cc66a
diff --git a/tests/ref/fate/mxf-demux b/tests/ref/fate/mxf-demux
index 906a6d0638..3010ca2177 100644
--- a/tests/ref/fate/mxf-demux
+++ b/tests/ref/fate/mxf-demux
@@ -8,7 +8,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_alaw
 #sample_rate 1: 8000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0, -9223372036854775808,        1,     8468, 0xc0855553
 1,          0,          0,    16000,    32000, 0x479155e6
diff --git a/tests/ref/fate/nsv-demux b/tests/ref/fate/nsv-demux
index bff871dabe..540079ad44 100644
--- a/tests/ref/fate/nsv-demux
+++ b/tests/ref/fate/nsv-demux
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: mp3
 #sample_rate 1: 11025
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,       12, 0x1396035f
 0,          1,          1,        1,       24, 0x8ab80ac7, F=0x0
diff --git a/tests/ref/fate/oma-atrac3-remux b/tests/ref/fate/oma-atrac3-remux
index fb402c43c6..d807c6cfb0 100644
--- a/tests/ref/fate/oma-atrac3-remux
+++ b/tests/ref/fate/oma-atrac3-remux
@@ -5,7 +5,6 @@
 #media_type 0: audio
 #codec_id 0: atrac3
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1024,      384, 0xdfded1b5
 0,       1024,       1024,     1024,      384, 0xd8e3badd
diff --git a/tests/ref/fate/oma-atrac3p-remux b/tests/ref/fate/oma-atrac3p-remux
index d909fdaee9..7d1cd962e5 100644
--- a/tests/ref/fate/oma-atrac3p-remux
+++ b/tests/ref/fate/oma-atrac3p-remux
@@ -4,7 +4,6 @@
 #media_type 0: audio
 #codec_id 0: atrac3p
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     2048,     1488, 0x69b7fad9
 0,       2048,       2048,     2048,     1488, 0x3c43fdb8
diff --git a/tests/ref/fate/on2avc b/tests/ref/fate/on2avc
index a9d6cbcea9..2475c1498a 100644
--- a/tests/ref/fate/on2avc
+++ b/tests/ref/fate/on2avc
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 16000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1024,     2048, 0x00000000
 0,       1024,       1024,     1024,     2048, 0x96ee1301
diff --git a/tests/ref/fate/paf-audio b/tests/ref/fate/paf-audio
index a9ed9e99fe..b2fbc094eb 100644
--- a/tests/ref/fate/paf-audio
+++ b/tests/ref/fate/paf-audio
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,    57330,   229320, 0x062508b4
 0,      57330,      57330,    57330,   229320, 0x0a966cbf
diff --git a/tests/ref/fate/paf-demux b/tests/ref/fate/paf-demux
index 6a66697af8..a0d1f44843 100644
--- a/tests/ref/fate/paf-demux
+++ b/tests/ref/fate/paf-demux
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: paf_audio
 #sample_rate 1: 22050
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        1,   262144, 0x7f9a3c6a
 1,          0,          0,    57330,   131072, 0x255a6ac2
diff --git a/tests/ref/fate/pcm-planar b/tests/ref/fate/pcm-planar
index 8b6c96181a..b1d988bb75 100644
--- a/tests/ref/fate/pcm-planar
+++ b/tests/ref/fate/pcm-planar
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1471,     5884, 0x00000000
 0,       1471,       1471,     1471,     5884, 0x00000000
diff --git a/tests/ref/fate/pcm_dvd b/tests/ref/fate/pcm_dvd
index 2a24156284..61ddcaef17 100644
--- a/tests/ref/fate/pcm_dvd
+++ b/tests/ref/fate/pcm_dvd
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 48000
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,      334,     1336, 0x8e3c0abc
 0,        400,        400,      334,     1336, 0x99c41108
diff --git a/tests/ref/fate/pmp-demux b/tests/ref/fate/pmp-demux
index 5c51b8b453..90475e398d 100644
--- a/tests/ref/fate/pmp-demux
+++ b/tests/ref/fate/pmp-demux
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: mp3
 #sample_rate 0: 44100
-#channel_layout 0: 3
 #channel_layout_name 0: stereo
 0,          0,          0,     1152,      417, 0xcb873fba
 0,       1152,       1152,     1152,      104, 0x6d521c5a
diff --git a/tests/ref/fate/prores-gray b/tests/ref/fate/prores-gray
index a1a63fa945..08fcf2473d 100644
--- a/tests/ref/fate/prores-gray
+++ b/tests/ref/fate/prores-gray
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        1,  1658880, 0x43d9c9e2
 1,          0,          0,     1024,     4096, 0x6c8a9a18
diff --git a/tests/ref/fate/prores-transparency b/tests/ref/fate/prores-transparency
index 4e88152834..246e0b26aa 100644
--- a/tests/ref/fate/prores-transparency
+++ b/tests/ref/fate/prores-transparency
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        1, 16588800, 0xcfb3d806
 1,          0,          0,     1024,     4096, 0x00000000
diff --git a/tests/ref/fate/prores-transparency_skip b/tests/ref/fate/prores-transparency_skip
index 82c180d174..3f5fa0a13f 100644
--- a/tests/ref/fate/prores-transparency_skip
+++ b/tests/ref/fate/prores-transparency_skip
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        1, 12441600, 0x74f53304
 1,          0,          0,     1024,     4096, 0x00000000
diff --git a/tests/ref/fate/psx-str-demux b/tests/ref/fate/psx-str-demux
index a47c86952f..18a21b0bb6 100644
--- a/tests/ref/fate/psx-str-demux
+++ b/tests/ref/fate/psx-str-demux
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: adpcm_xa
 #sample_rate 1: 37800
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        1,     8832, 0x01ad3eeb
 1,          0,          0,        1,     2304, 0xf0ad1000
diff --git a/tests/ref/fate/pva-demux b/tests/ref/fate/pva-demux
index 3f1c74f366..5c0e1c1ea0 100644
--- a/tests/ref/fate/pva-demux
+++ b/tests/ref/fate/pva-demux
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: mp2
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 1,          0,          0,     2160,      384, 0x071abcc8
 1,       2160,       2160,     2160,      384, 0x31c9aee0
diff --git a/tests/ref/fate/ra3-144 b/tests/ref/fate/ra3-144
index 75e7bbfc7a..3068227cb9 100644
--- a/tests/ref/fate/ra3-144
+++ b/tests/ref/fate/ra3-144
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 8000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,      160,      320, 0x00000000
 0,        160,        160,      160,      320, 0x4cfd5d74
diff --git a/tests/ref/fate/redcode-demux b/tests/ref/fate/redcode-demux
index 45119ec71e..4815a8b8c7 100644
--- a/tests/ref/fate/redcode-demux
+++ b/tests/ref/fate/redcode-demux
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s32be
 #sample_rate 1: 48000
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,    10010,  1626280, 0x5768c7d6
 1,          0,          0,    18140,    14816, 0xd185e8c7
diff --git a/tests/ref/fate/s337m-demux b/tests/ref/fate/s337m-demux
index 2857c65aee..42ef4df275 100644
--- a/tests/ref/fate/s337m-demux
+++ b/tests/ref/fate/s337m-demux
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: dolby_e
 #sample_rate 0: 44800
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 0,          0,          0,     3600,     7664, 0x7e73f2fd
 0,       3600,       3600,     3600,     7664, 0x8b980ec8
diff --git a/tests/ref/fate/segment-adts-to-mkv-header-000 b/tests/ref/fate/segment-adts-to-mkv-header-000
index 294aa2346f..91729811fc 100644
--- a/tests/ref/fate/segment-adts-to-mkv-header-000
+++ b/tests/ref/fate/segment-adts-to-mkv-header-000
@@ -3,7 +3,6 @@
 #media_type 0: audio
 #codec_id 0: aac
 #sample_rate 0: 16000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,       64,        4, 0x02f70117
 0,         64,         64,       64,      163, 0xd5f85007
diff --git a/tests/ref/fate/segment-adts-to-mkv-header-001 b/tests/ref/fate/segment-adts-to-mkv-header-001
index ec4669f12c..e24282e3e4 100644
--- a/tests/ref/fate/segment-adts-to-mkv-header-001
+++ b/tests/ref/fate/segment-adts-to-mkv-header-001
@@ -3,7 +3,6 @@
 #media_type 0: audio
 #codec_id 0: aac
 #sample_rate 0: 16000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,       64,      153, 0xbb6e432f
 0,         64,         64,       64,      185, 0xa01f4ff3
diff --git a/tests/ref/fate/segment-adts-to-mkv-header-002 b/tests/ref/fate/segment-adts-to-mkv-header-002
index 06df824565..fc42d8ad00 100644
--- a/tests/ref/fate/segment-adts-to-mkv-header-002
+++ b/tests/ref/fate/segment-adts-to-mkv-header-002
@@ -3,7 +3,6 @@
 #media_type 0: audio
 #codec_id 0: aac
 #sample_rate 0: 16000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,       64,      156, 0x867d4f3a
 0,         64,         64,       64,      201, 0x62745ff9
diff --git a/tests/ref/fate/segment-adts-to-mkv-header-all b/tests/ref/fate/segment-adts-to-mkv-header-all
index 9c78d33477..dd2ec9a99e 100644
--- a/tests/ref/fate/segment-adts-to-mkv-header-all
+++ b/tests/ref/fate/segment-adts-to-mkv-header-all
@@ -3,7 +3,6 @@
 #media_type 0: audio
 #codec_id 0: aac
 #sample_rate 0: 16000
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,       64,        4, 0x02f70117
 0,         64,         64,       64,      163, 0xd5f85007
diff --git a/tests/ref/fate/shortest b/tests/ref/fate/shortest
index 64b5bed312..a527bfd544 100644
--- a/tests/ref/fate/shortest
+++ b/tests/ref/fate/shortest
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: ac3
 #sample_rate 1: 44100
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 1,       -256,       -256,     1536,      416, 0xef8ccbe3
 0,          0,          0,        1,     8749, 0x57039d10, S=1,        8
diff --git a/tests/ref/fate/sierra-vmd-audio b/tests/ref/fate/sierra-vmd-audio
index 9c0e6b2db1..7bed6e64ae 100644
--- a/tests/ref/fate/sierra-vmd-audio
+++ b/tests/ref/fate/sierra-vmd-audio
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,    61740,   123480, 0x3a794c13
 0,      61740,      61740,     2205,     4410, 0x109d04e0
diff --git a/tests/ref/fate/siff-demux b/tests/ref/fate/siff-demux
index f8e9897931..a6d47cee66 100644
--- a/tests/ref/fate/siff-demux
+++ b/tests/ref/fate/siff-demux
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_u8
 #sample_rate 1: 22050
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,    15152, 0x14fc0f1f
 1,          0,          0,    22050,    22050, 0xa7d60d27
diff --git a/tests/ref/fate/smacker-audio b/tests/ref/fate/smacker-audio
index 6b867874d9..4703501bcb 100644
--- a/tests/ref/fate/smacker-audio
+++ b/tests/ref/fate/smacker-audio
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: pcm_s16le
 #sample_rate 0: 22050
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,    23620,    47240, 0x9974897c
 0,      23620,      23620,     1564,     3128, 0x7e4064b4
diff --git a/tests/ref/fate/smjpeg-demux b/tests/ref/fate/smjpeg-demux
index cb2da6909d..e394f3839e 100644
--- a/tests/ref/fate/smjpeg-demux
+++ b/tests/ref/fate/smjpeg-demux
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: adpcm_ima_smjpeg
 #sample_rate 1: 22050
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,      111,      734, 0x5a042c2c
 1,          0,          0,       23,      260, 0x00000000
diff --git a/tests/ref/fate/sp5x b/tests/ref/fate/sp5x
index 2ca79815ee..6b8fbfc3d8 100644
--- a/tests/ref/fate/sp5x
+++ b/tests/ref/fate/sp5x
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 8000
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   115200, 0x8ebcb7f8
 1,          0,          0,     1024,     2048, 0x366ee71c
diff --git a/tests/ref/fate/tiertex-seq b/tests/ref/fate/tiertex-seq
index 1db906ad33..8bd0b50539 100644
--- a/tests/ref/fate/tiertex-seq
+++ b/tests/ref/fate/tiertex-seq
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 22050
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 1,          0,          0,      882,     1764, 0x00000000
 1,        882,        882,      882,     1764, 0x80a253d9
diff --git a/tests/ref/fate/tmv b/tests/ref/fate/tmv
index 09198fab2b..ccfaa0d980 100644
--- a/tests/ref/fate/tmv
+++ b/tests/ref/fate/tmv
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 22058
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   192000, 0xc698297a
 1,          0,          0,      368,      736, 0xf63db497
diff --git a/tests/ref/fate/tscc-15bit b/tests/ref/fate/tscc-15bit
index ded8ad43e0..be81d891e2 100644
--- a/tests/ref/fate/tscc-15bit
+++ b/tests/ref/fate/tscc-15bit
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 11025
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   657600, 0x50b3a0c2
 1,          0,          0,    11025,    22050, 0x1740aaec
diff --git a/tests/ref/fate/vqf-demux b/tests/ref/fate/vqf-demux
index d768ddbb69..2669d8cc18 100644
--- a/tests/ref/fate/vqf-demux
+++ b/tests/ref/fate/vqf-demux
@@ -1 +1 @@
-5f4cd9a6a8bea0040db6732a7830e9d7
+e42a45601a4a7c39436907c5cdfde5ee
diff --git a/tests/ref/fate/wav-ac3 b/tests/ref/fate/wav-ac3
index 039e155daf..b20403e612 100644
--- a/tests/ref/fate/wav-ac3
+++ b/tests/ref/fate/wav-ac3
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: ac3
 #sample_rate 0: 44100
-#channel_layout 0: 60f
 #channel_layout_name 0: 5.1(side)
 0,          0,          0,     1536,     2786, 0xe2fd0f40
 0,       1536,       1536,     1536,     2786, 0x7a6207c2
diff --git a/tests/ref/fate/wc3movie-xan b/tests/ref/fate/wc3movie-xan
index 052dbbce7d..4acb0a3b59 100644
--- a/tests/ref/fate/wc3movie-xan
+++ b/tests/ref/fate/wc3movie-xan
@@ -7,7 +7,6 @@
 #media_type 1: audio
 #codec_id 1: pcm_s16le
 #sample_rate 1: 22050
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        1,   158400, 0x25aec781
 1,          0,          0,     1470,     2940, 0x92cee2a6
diff --git a/tests/ref/fate/webm-dash-chapters b/tests/ref/fate/webm-dash-chapters
index c04fc6a3ee..33ba3c7bf3 100644
--- a/tests/ref/fate/webm-dash-chapters
+++ b/tests/ref/fate/webm-dash-chapters
@@ -5,7 +5,6 @@ c39ad75ef516d1d2e1332d960ad1057b *tests/data/fate/webm-dash-chapters.webm
 #media_type 0: audio
 #codec_id 0: vorbis
 #sample_rate 0: 44100
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,        5,       28, 0xefcf103e
 0,          6,          6,       26,      198, 0xfbbe5eb5
diff --git a/tests/ref/fate/westwood-aud b/tests/ref/fate/westwood-aud
index b719c50a4d..cc9d1f0460 100644
--- a/tests/ref/fate/westwood-aud
+++ b/tests/ref/fate/westwood-aud
@@ -2,7 +2,6 @@
 #media_type 0: audio
 #codec_id 0: adpcm_ima_ws
 #sample_rate 0: 22050
-#channel_layout 0: 4
 #channel_layout_name 0: mono
 0,          0,          0,     1024,      512, 0x6694cc55
 0,       1024,       1024,     1024,      512, 0xdbc5cb22
diff --git a/tests/ref/fate/wmv3-drm-nodec b/tests/ref/fate/wmv3-drm-nodec
index a46c338d54..9ed8bc8575 100644
--- a/tests/ref/fate/wmv3-drm-nodec
+++ b/tests/ref/fate/wmv3-drm-nodec
@@ -9,7 +9,6 @@
 #media_type 1: audio
 #codec_id 1: wmavoice
 #sample_rate 1: 22050
-#channel_layout 1: 4
 #channel_layout_name 1: mono
 0,          0,          0,        0,      282, 0x000d949a
 1,          0,          0,        0,     1088, 0x5cd379bb
diff --git a/tests/ref/fate/wtv-demux b/tests/ref/fate/wtv-demux
index abe85a4ab6..5d1a02fc6e 100644
--- a/tests/ref/fate/wtv-demux
+++ b/tests/ref/fate/wtv-demux
@@ -9,7 +9,6 @@
 #media_type 1: audio
 #codec_id 1: mp2
 #sample_rate 1: 48000
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 1,         -2,         -2,   240000,      576, 0x9b6e1638
 1,     239998,     239998,   240000,      576, 0x0ca91183
diff --git a/tests/ref/fate/xmv-demux b/tests/ref/fate/xmv-demux
index 6da2b1a701..9cc26e41c3 100644
--- a/tests/ref/fate/xmv-demux
+++ b/tests/ref/fate/xmv-demux
@@ -8,7 +8,6 @@
 #media_type 1: audio
 #codec_id 1: adpcm_ima_wav
 #sample_rate 1: 44100
-#channel_layout 1: 3
 #channel_layout_name 1: stereo
 0,          0,          0,        0,     1508, 0xefceba48
 1,          0,          0,       83,     5976, 0xfa2c2db9
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 062/281] fsb: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (60 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 061/281] framehash: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 063/281] fwse: " James Almer
                   ` (220 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/fsb.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/libavformat/fsb.c b/libavformat/fsb.c
index 9e8b9ca6b1..3faae6974b 100644
--- a/libavformat/fsb.c
+++ b/libavformat/fsb.c
@@ -68,30 +68,31 @@ static int fsb_read_header(AVFormatContext *s)
         if (par->sample_rate <= 0)
             return AVERROR_INVALIDDATA;
         avio_skip(pb, 6);
-        par->channels    = avio_rl16(pb);
-        if (!par->channels)
+        par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        par->ch_layout.nb_channels = avio_rl16(pb);
+        if (!par->ch_layout.nb_channels)
             return AVERROR_INVALIDDATA;
 
         if (format & 0x00000100) {
             par->codec_id    = AV_CODEC_ID_PCM_S16LE;
-            par->block_align = 4096 * par->channels;
+            par->block_align = 4096 * par->ch_layout.nb_channels;
         } else if (format & 0x00400000) {
             par->bits_per_coded_sample = 4;
             par->codec_id    = AV_CODEC_ID_ADPCM_IMA_WAV;
-            par->block_align = 36 * par->channels;
+            par->block_align = 36 * par->ch_layout.nb_channels;
         } else if (format & 0x00800000) {
             par->codec_id    = AV_CODEC_ID_ADPCM_PSX;
-            par->block_align = 16 * par->channels;
+            par->block_align = 16 * par->ch_layout.nb_channels;
         } else if (format & 0x02000000) {
             par->codec_id    = AV_CODEC_ID_ADPCM_THP;
-            par->block_align = 8 * par->channels;
-            if (par->channels > INT_MAX / 32)
+            par->block_align = 8 * par->ch_layout.nb_channels;
+            if (par->ch_layout.nb_channels > INT_MAX / 32)
                 return AVERROR_INVALIDDATA;
-            ret = ff_alloc_extradata(par, 32 * par->channels);
+            ret = ff_alloc_extradata(par, 32 * par->ch_layout.nb_channels);
             if (ret < 0)
                 return ret;
             avio_seek(pb, 0x68, SEEK_SET);
-            for (c = 0; c < par->channels; c++) {
+            for (c = 0; c < par->ch_layout.nb_channels; c++) {
                 avio_read(pb, par->extradata + 32 * c, 32);
                 avio_skip(pb, 14);
             }
@@ -125,8 +126,9 @@ static int fsb_read_header(AVFormatContext *s)
             return AVERROR_INVALIDDATA;
         avio_skip(pb, 6);
 
-        par->channels    = avio_rl16(pb);
-        if (!par->channels)
+        par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        par->ch_layout.nb_channels = avio_rl16(pb);
+        if (!par->ch_layout.nb_channels)
             return AVERROR_INVALIDDATA;
 
         switch (par->codec_id) {
@@ -138,17 +140,17 @@ static int fsb_read_header(AVFormatContext *s)
             par->block_align = 2048;
             break;
         case AV_CODEC_ID_ADPCM_THP:
-            if (par->channels > INT_MAX / 32)
+            if (par->ch_layout.nb_channels > INT_MAX / 32)
                 return AVERROR_INVALIDDATA;
-            ret = ff_alloc_extradata(par, 32 * par->channels);
+            ret = ff_alloc_extradata(par, 32 * par->ch_layout.nb_channels);
             if (ret < 0)
                 return ret;
             avio_seek(pb, 0x80, SEEK_SET);
-            for (c = 0; c < par->channels; c++) {
+            for (c = 0; c < par->ch_layout.nb_channels; c++) {
                 avio_read(pb, par->extradata + 32 * c, 32);
                 avio_skip(pb, 14);
             }
-            par->block_align = 8 * par->channels;
+            par->block_align = 8 * par->ch_layout.nb_channels;
             break;
         }
     } else {
@@ -174,14 +176,14 @@ static int fsb_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     pos = avio_tell(s->pb);
     if (par->codec_id == AV_CODEC_ID_ADPCM_THP &&
-               par->channels > 1) {
+        par->ch_layout.nb_channels > 1) {
         int i, ch;
 
         ret = av_new_packet(pkt, par->block_align);
         if (ret < 0)
             return ret;
         for (i = 0; i < 4; i++) {
-            for (ch = 0; ch < par->channels; ch++) {
+            for (ch = 0; ch < par->ch_layout.nb_channels; ch++) {
                 pkt->data[ch * 8 + i * 2 + 0] = avio_r8(s->pb);
                 pkt->data[ch * 8 + i * 2 + 1] = avio_r8(s->pb);
             }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 063/281] fwse: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (61 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 062/281] fsb: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 064/281] g722: " James Almer
                   ` (219 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/fwse.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavformat/fwse.c b/libavformat/fwse.c
index ed8cd3a6db..28a322d9d6 100644
--- a/libavformat/fwse.c
+++ b/libavformat/fwse.c
@@ -40,6 +40,7 @@ static int fwse_probe(const AVProbeData *p)
 static int fwse_read_header(AVFormatContext *s)
 {
     unsigned start_offset, version;
+    int channels;
     AVIOContext *pb = s->pb;
     AVCodecParameters *par;
     AVStream *st;
@@ -59,13 +60,10 @@ static int fwse_read_header(AVFormatContext *s)
     par->codec_type  = AVMEDIA_TYPE_AUDIO;
     par->codec_id    = AV_CODEC_ID_ADPCM_IMA_MTF;
     par->format      = AV_SAMPLE_FMT_S16;
-    par->channels    = avio_rl32(pb);
-    if (par->channels != 1 && par->channels != 2)
+    channels         = avio_rl32(pb);
+    if (channels != 1 && channels != 2)
         return AVERROR_INVALIDDATA;
-    if (par->channels == 1)
-        par->channel_layout = AV_CH_LAYOUT_MONO;
-    else if (par->channels == 2)
-        par->channel_layout = AV_CH_LAYOUT_STEREO;
+    av_channel_layout_default(&par->ch_layout, channels);
     st->duration = avio_rl32(pb);
     par->sample_rate = avio_rl32(pb);
     if (par->sample_rate <= 0 || par->sample_rate > INT_MAX)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 064/281] g722: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (62 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 063/281] fwse: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 065/281] g723_1: " James Almer
                   ` (218 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/g722.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/g722.c b/libavformat/g722.c
index 3bfe05ea6f..08cd2cbc87 100644
--- a/libavformat/g722.c
+++ b/libavformat/g722.c
@@ -35,7 +35,7 @@ static int g722_read_header(AVFormatContext *s)
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_G722;
     st->codecpar->sample_rate = 16000;
-    st->codecpar->channels    = 1;
+    st->codecpar->ch_layout   = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     st->codecpar->bits_per_coded_sample =
         av_get_bits_per_sample(st->codecpar->codec_id);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 065/281] g723_1: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (63 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 064/281] g722: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 066/281] g726: " James Almer
                   ` (217 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/g723_1.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/g723_1.c b/libavformat/g723_1.c
index f38064b5b2..e35b4ed503 100644
--- a/libavformat/g723_1.c
+++ b/libavformat/g723_1.c
@@ -41,8 +41,7 @@ static av_cold int g723_1_init(AVFormatContext *s)
 
     st->codecpar->codec_type     = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id       = AV_CODEC_ID_G723_1;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
-    st->codecpar->channels       = 1;
+    st->codecpar->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     st->codecpar->sample_rate    = 8000;
 
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 066/281] g726: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (64 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 065/281] g723_1: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 067/281] g729: " James Almer
                   ` (216 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/g726.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/g726.c b/libavformat/g726.c
index 4b08d0a9f7..ce88fe6b23 100644
--- a/libavformat/g726.c
+++ b/libavformat/g726.c
@@ -42,7 +42,8 @@ static int g726_read_header(AVFormatContext *s)
     st->codecpar->sample_rate           = c->sample_rate;
     st->codecpar->bits_per_coded_sample = c->code_size;
     st->codecpar->bit_rate              = ((int[]){ 16000, 24000, 32000, 40000 })[c->code_size - 2];
-    st->codecpar->channels              = 1;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = 1;
 
     return 0;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 067/281] g729: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (65 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 066/281] g726: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 068/281] gdv: " James Almer
                   ` (215 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/g729dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/g729dec.c b/libavformat/g729dec.c
index 51112f5618..9c92ea4fcf 100644
--- a/libavformat/g729dec.c
+++ b/libavformat/g729dec.c
@@ -43,7 +43,7 @@ static int g729_read_header(AVFormatContext *s)
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id    = AV_CODEC_ID_G729;
     st->codecpar->sample_rate = 8000;
-    st->codecpar->channels    = 1;
+    st->codecpar->ch_layout   = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     if (s1 && s1->bit_rate)
         s->bit_rate = s1->bit_rate;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 068/281] gdv: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (66 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 067/281] g729: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 069/281] genh: " James Almer
                   ` (214 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/gdv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/gdv.c b/libavformat/gdv.c
index b20691a2a4..f2e0748b6b 100644
--- a/libavformat/gdv.c
+++ b/libavformat/gdv.c
@@ -99,7 +99,8 @@ static int gdv_read_header(AVFormatContext *ctx)
         ast->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
         ast->codecpar->codec_tag   = 0;
         ast->codecpar->sample_rate = avio_rl16(pb);
-        ast->codecpar->channels    = 1 + !!(snd_flags & 2);
+        ast->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        ast->codecpar->ch_layout.nb_channels = 1 + !!(snd_flags & 2);
         if (snd_flags & 8) {
             ast->codecpar->codec_id = AV_CODEC_ID_GREMLIN_DPCM;
         } else {
@@ -108,7 +109,8 @@ static int gdv_read_header(AVFormatContext *ctx)
 
         avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate);
         gdv->audio_size = (ast->codecpar->sample_rate / fps) *
-                           ast->codecpar->channels * (1 + !!(snd_flags & 4)) / (1 + !!(snd_flags & 8));
+                           ast->codecpar->ch_layout.nb_channels *
+                           (1 + !!(snd_flags & 4)) / (1 + !!(snd_flags & 8));
         gdv->is_audio = 1;
     } else {
         avio_skip(pb, 2);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 069/281] genh: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (67 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 068/281] gdv: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 070/281] gsm: " James Almer
                   ` (213 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/genh.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/libavformat/genh.c b/libavformat/genh.c
index f9b222d8cd..139205ecc5 100644
--- a/libavformat/genh.c
+++ b/libavformat/genh.c
@@ -55,18 +55,19 @@ static int genh_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
 
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels    = avio_rl32(s->pb);
-    if (st->codecpar->channels <= 0 || st->codecpar->channels > FF_SANE_NB_CHANNELS)
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels    = avio_rl32(s->pb);
+    if (st->codecpar->ch_layout.nb_channels <= 0)
         return AVERROR_INVALIDDATA;
-    if (st->codecpar->channels == 1)
-        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
-    else if (st->codecpar->channels == 2)
-        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+    if (st->codecpar->ch_layout.nb_channels == 1)
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+    else if (st->codecpar->ch_layout.nb_channels == 2)
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     align                  =
     c->interleave_size     = avio_rl32(s->pb);
-    if (align < 0 || align > INT_MAX / st->codecpar->channels)
+    if (align < 0 || align > INT_MAX / st->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
-    st->codecpar->block_align = align * st->codecpar->channels;
+    st->codecpar->block_align = align * st->codecpar->ch_layout.nb_channels;
     st->codecpar->sample_rate = avio_rl32(s->pb);
     avio_skip(s->pb, 4);
     st->duration = avio_rl32(s->pb);
@@ -76,7 +77,7 @@ static int genh_read_header(AVFormatContext *s)
     case  0: st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX;        break;
     case  1:
     case 11: st->codecpar->bits_per_coded_sample = 4;
-             st->codecpar->block_align = 36 * st->codecpar->channels;
+             st->codecpar->block_align = 36 * st->codecpar->ch_layout.nb_channels;
              st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_WAV;    break;
     case  2: st->codecpar->codec_id = AV_CODEC_ID_ADPCM_DTK;        break;
     case  3: st->codecpar->codec_id = st->codecpar->block_align > 0 ?
@@ -122,13 +123,13 @@ static int genh_read_header(AVFormatContext *s)
     coef_splitted[1] = avio_rl32(s->pb);
 
     if (st->codecpar->codec_id == AV_CODEC_ID_ADPCM_THP) {
-        if (st->codecpar->channels > 2) {
-            avpriv_request_sample(s, "channels %d>2", st->codecpar->channels);
+        if (st->codecpar->ch_layout.nb_channels > 2) {
+            avpriv_request_sample(s, "channels %d>2", st->codecpar->ch_layout.nb_channels);
             return AVERROR_PATCHWELCOME;
         }
 
-        ff_alloc_extradata(st->codecpar, 32 * st->codecpar->channels);
-        for (ch = 0; ch < st->codecpar->channels; ch++) {
+        ff_alloc_extradata(st->codecpar, 32 * st->codecpar->ch_layout.nb_channels);
+        for (ch = 0; ch < st->codecpar->ch_layout.nb_channels; ch++) {
             if (coef_type & 1) {
                 avpriv_request_sample(s, "coef_type & 1");
                 return AVERROR_PATCHWELCOME;
@@ -139,7 +140,7 @@ static int genh_read_header(AVFormatContext *s)
         }
 
         if (c->dsp_int_type == 1) {
-            st->codecpar->block_align = 8 * st->codecpar->channels;
+            st->codecpar->block_align = 8 * st->codecpar->ch_layout.nb_channels;
             if (c->interleave_size != 1 &&
                 c->interleave_size != 2 &&
                 c->interleave_size != 4)
@@ -164,16 +165,16 @@ static int genh_read_packet(AVFormatContext *s, AVPacket *pkt)
     int ret;
 
     if (c->dsp_int_type == 1 && par->codec_id == AV_CODEC_ID_ADPCM_THP &&
-        par->channels > 1) {
+        par->ch_layout.nb_channels > 1) {
         int i, ch;
 
         if (avio_feof(s->pb))
             return AVERROR_EOF;
-        ret = av_new_packet(pkt, 8 * par->channels);
+        ret = av_new_packet(pkt, 8 * par->ch_layout.nb_channels);
         if (ret < 0)
             return ret;
         for (i = 0; i < 8 / c->interleave_size; i++) {
-            for (ch = 0; ch < par->channels; ch++) {
+            for (ch = 0; ch < par->ch_layout.nb_channels; ch++) {
                 pkt->data[ch * 8 + i*c->interleave_size+0] = avio_r8(s->pb);
                 pkt->data[ch * 8 + i*c->interleave_size+1] = avio_r8(s->pb);
             }
@@ -183,7 +184,8 @@ static int genh_read_packet(AVFormatContext *s, AVPacket *pkt)
         ret = av_get_packet(s->pb, pkt, par->block_align * 1024);
 
     } else {
-        ret = av_get_packet(s->pb, pkt, par->block_align ? par->block_align : 1024 * par->channels);
+        ret = av_get_packet(s->pb, pkt, par->block_align ? par->block_align :
+                                                           1024 * par->ch_layout.nb_channels);
     }
 
     pkt->stream_index = 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 070/281] gsm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (68 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 069/281] genh: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 071/281] gxf: " James Almer
                   ` (212 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/gsmdec.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/gsmdec.c b/libavformat/gsmdec.c
index e14e9aa217..09dc0e0fb3 100644
--- a/libavformat/gsmdec.c
+++ b/libavformat/gsmdec.c
@@ -79,8 +79,7 @@ static int gsm_read_header(AVFormatContext *s)
 
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id    = s->iformat->raw_codec_id;
-    st->codecpar->channels    = 1;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    st->codecpar->ch_layout   = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     st->codecpar->sample_rate = c->sample_rate;
     st->codecpar->bit_rate    = GSM_BLOCK_SIZE * 8 * c->sample_rate / GSM_BLOCK_SAMPLES;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 071/281] gxf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (69 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 070/281] gsm: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 072/281] hca: " James Almer
                   ` (211 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/gxf.c    | 9 +++------
 libavformat/gxfenc.c | 2 +-
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/libavformat/gxf.c b/libavformat/gxf.c
index 6f370c1b57..d96e0796f4 100644
--- a/libavformat/gxf.c
+++ b/libavformat/gxf.c
@@ -143,8 +143,7 @@ static int get_sindex(AVFormatContext *s, int id, int format) {
         case 9:
             st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
             st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE;
-            st->codecpar->channels = 1;
-            st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+            st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
             st->codecpar->sample_rate = 48000;
             st->codecpar->bit_rate = 3 * 1 * 48000 * 8;
             st->codecpar->block_align = 3 * 1;
@@ -153,8 +152,7 @@ static int get_sindex(AVFormatContext *s, int id, int format) {
         case 10:
             st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
             st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
-            st->codecpar->channels = 1;
-            st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+            st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
             st->codecpar->sample_rate = 48000;
             st->codecpar->bit_rate = 2 * 1 * 48000 * 8;
             st->codecpar->block_align = 2 * 1;
@@ -163,8 +161,7 @@ static int get_sindex(AVFormatContext *s, int id, int format) {
         case 17:
             st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
             st->codecpar->codec_id = AV_CODEC_ID_AC3;
-            st->codecpar->channels = 2;
-            st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+            st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
             st->codecpar->sample_rate = 48000;
             break;
         case 26: /* AVCi50 / AVCi100 (AVC Intra) */
diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
index 133d1e9fb3..e25d8764ba 100644
--- a/libavformat/gxfenc.c
+++ b/libavformat/gxfenc.c
@@ -714,7 +714,7 @@ static int gxf_write_header(AVFormatContext *s)
                 av_log(s, AV_LOG_ERROR, "only 48000hz sampling rate is allowed\n");
                 return -1;
             }
-            if (st->codecpar->channels != 1) {
+            if (st->codecpar->ch_layout.nb_channels != 1) {
                 av_log(s, AV_LOG_ERROR, "only mono tracks are allowed\n");
                 return -1;
             }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 072/281] hca: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (70 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 071/281] gxf: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 073/281] hcom: " James Almer
                   ` (210 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/hca.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/hca.c b/libavformat/hca.c
index eaa96a9b17..3c9e549e38 100644
--- a/libavformat/hca.c
+++ b/libavformat/hca.c
@@ -79,7 +79,8 @@ static int hca_read_header(AVFormatContext *s)
     par->codec_type  = AVMEDIA_TYPE_AUDIO;
     par->codec_id    = AV_CODEC_ID_HCA;
     par->codec_tag   = 0;
-    par->channels    = bytestream2_get_byte(&gb);
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = bytestream2_get_byte(&gb);
     par->sample_rate = bytestream2_get_be24(&gb);
     block_count      = bytestream2_get_be32(&gb);
     bytestream2_skip(&gb, 4);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 073/281] hcom: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (71 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 072/281] hca: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 074/281] hls_sample_encryption: " James Almer
                   ` (209 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/hcom.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/hcom.c b/libavformat/hcom.c
index b7fb7314c8..579f0b707e 100644
--- a/libavformat/hcom.c
+++ b/libavformat/hcom.c
@@ -62,7 +62,8 @@ static int hcom_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
 
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels    = 1;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = 1;
     st->codecpar->sample_rate = 22050 / divisor;
     st->codecpar->codec_id    = AV_CODEC_ID_HCOM;
     st->codecpar->bits_per_coded_sample = 8;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 074/281] hls_sample_encryption: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (72 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 073/281] hcom: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 075/281] idcin: " James Almer
                   ` (208 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/hls_sample_encryption.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavformat/hls_sample_encryption.c b/libavformat/hls_sample_encryption.c
index 3dbaff717e..159a6edc6e 100644
--- a/libavformat/hls_sample_encryption.c
+++ b/libavformat/hls_sample_encryption.c
@@ -109,13 +109,14 @@ int ff_hls_senc_parse_audio_setup_info(AVStream *st, HLSAudioSetupInfo *info)
         }
 
         st->codecpar->sample_rate       = ac3hdr->sample_rate;
-        st->codecpar->channels          = ac3hdr->channels;
-        st->codecpar->channel_layout    = ac3hdr->channel_layout;
+        av_channel_layout_uninit(&st->codecpar->ch_layout);
+        av_channel_layout_from_mask(&st->codecpar->ch_layout, ac3hdr->channel_layout);
         st->codecpar->bit_rate          = ac3hdr->bit_rate;
 
         av_free(ac3hdr);
     } else {  /*  Parse 'dec3' EC3SpecificBox */
         GetBitContext gb;
+        uint64_t mask;
         int data_rate, fscod, acmod, lfeon;
 
         ret = init_get_bits8(&gb, info->setup_data, info->setup_data_length);
@@ -131,11 +132,12 @@ int ff_hls_senc_parse_audio_setup_info(AVStream *st, HLSAudioSetupInfo *info)
 
         st->codecpar->sample_rate = eac3_sample_rate_tab[fscod];
 
-        st->codecpar->channel_layout = ff_ac3_channel_layout_tab[acmod];
+        mask = ff_ac3_channel_layout_tab[acmod];
         if (lfeon)
-            st->codecpar->channel_layout |= AV_CH_LOW_FREQUENCY;
+            mask |= AV_CH_LOW_FREQUENCY;
 
-        st->codecpar->channels = av_get_channel_layout_nb_channels(st->codecpar->channel_layout);
+        av_channel_layout_uninit(&st->codecpar->ch_layout);
+        av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
 
         st->codecpar->bit_rate = data_rate*1000;
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 075/281] idcin: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (73 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 074/281] hls_sample_encryption: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 076/281] idroq: " James Almer
                   ` (207 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/idcin.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavformat/idcin.c b/libavformat/idcin.c
index b7402107da..c92ed2c237 100644
--- a/libavformat/idcin.c
+++ b/libavformat/idcin.c
@@ -218,9 +218,7 @@ static int idcin_read_header(AVFormatContext *s)
         idcin->audio_stream_index = st->index;
         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_tag = 1;
-        st->codecpar->channels = channels;
-        st->codecpar->channel_layout = channels > 1 ? AV_CH_LAYOUT_STEREO :
-                                                      AV_CH_LAYOUT_MONO;
+        av_channel_layout_default(&st->codecpar->ch_layout, channels);
         st->codecpar->sample_rate = sample_rate;
         st->codecpar->bits_per_coded_sample = bytes_per_sample * 8;
         st->codecpar->bit_rate = sample_rate * bytes_per_sample * 8 * channels;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 076/281] idroq: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (74 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 075/281] idcin: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 077/281] iff: " James Almer
                   ` (206 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/idroqdec.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/libavformat/idroqdec.c b/libavformat/idroqdec.c
index 0c8b7278e9..c9fc972780 100644
--- a/libavformat/idroqdec.c
+++ b/libavformat/idroqdec.c
@@ -185,18 +185,16 @@ static int roq_read_packet(AVFormatContext *s,
                 st->codecpar->codec_id = AV_CODEC_ID_ROQ_DPCM;
                 st->codecpar->codec_tag = 0;  /* no tag */
                 if (chunk_type == RoQ_SOUND_STEREO) {
-                    st->codecpar->channels       = 2;
-                    st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+                    st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
                 } else {
-                    st->codecpar->channels       = 1;
-                    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+                    st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
                 }
-                roq->audio_channels    = st->codecpar->channels;
+                roq->audio_channels = st->codecpar->ch_layout.nb_channels;
                 st->codecpar->sample_rate = RoQ_AUDIO_SAMPLE_RATE;
                 st->codecpar->bits_per_coded_sample = 16;
-                st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate *
+                st->codecpar->bit_rate = roq->audio_channels * st->codecpar->sample_rate *
                     st->codecpar->bits_per_coded_sample;
-                st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample;
+                st->codecpar->block_align = roq->audio_channels * st->codecpar->bits_per_coded_sample;
             }
         case RoQ_QUAD_VQ:
             if (chunk_type == RoQ_QUAD_VQ) {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 077/281] iff: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (75 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 076/281] idroq: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 078/281] ifv: " James Almer
                   ` (205 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/iff.c | 63 ++++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 31 deletions(-)

diff --git a/libavformat/iff.c b/libavformat/iff.c
index 078406b7e3..3c861ef34d 100644
--- a/libavformat/iff.c
+++ b/libavformat/iff.c
@@ -183,20 +183,20 @@ static const uint32_t dsd_5point0[] = { DSD_MLFT, DSD_MRGT, DSD_C, DSD_LS, DSD_R
 static const uint32_t dsd_5point1[] = { DSD_MLFT, DSD_MRGT, DSD_C, DSD_LFE, DSD_LS, DSD_RS };
 
 typedef struct {
-    uint64_t layout;
+    AVChannelLayout layout;
     const uint32_t * dsd_layout;
 } DSDLayoutDesc;
 
 static const DSDLayoutDesc dsd_channel_layout[] = {
-    { AV_CH_LAYOUT_STEREO,  dsd_stereo },
-    { AV_CH_LAYOUT_5POINT0, dsd_5point0 },
-    { AV_CH_LAYOUT_5POINT1, dsd_5point1 },
+    { AV_CHANNEL_LAYOUT_STEREO,  dsd_stereo },
+    { AV_CHANNEL_LAYOUT_5POINT0, dsd_5point0 },
+    { AV_CHANNEL_LAYOUT_5POINT1, dsd_5point1 },
 };
 
-static const uint64_t dsd_loudspeaker_config[] = {
-    AV_CH_LAYOUT_STEREO,
-    0, 0,
-    AV_CH_LAYOUT_5POINT0, AV_CH_LAYOUT_5POINT1,
+static const AVChannelLayout dsd_loudspeaker_config[] = {
+    AV_CHANNEL_LAYOUT_STEREO,
+    { 0 }, { 0 },
+    AV_CHANNEL_LAYOUT_5POINT0, AV_CHANNEL_LAYOUT_5POINT1,
 };
 
 static const char * dsd_source_comment[] = {
@@ -276,21 +276,21 @@ static int parse_dsd_prop(AVFormatContext *s, AVStream *st, uint64_t eof)
         case MKTAG('C','H','N','L'):
             if (size < 2)
                 return AVERROR_INVALIDDATA;
-            st->codecpar->channels       = avio_rb16(pb);
-            if (size < 2 + st->codecpar->channels * 4)
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = avio_rb16(pb);
+            if (size < 2 + st->codecpar->ch_layout.nb_channels * 4)
                 return AVERROR_INVALIDDATA;
-            st->codecpar->channel_layout = 0;
-            if (st->codecpar->channels > FF_ARRAY_ELEMS(dsd_layout)) {
+            if (st->codecpar->ch_layout.nb_channels > FF_ARRAY_ELEMS(dsd_layout)) {
                 avpriv_request_sample(s, "channel layout");
                 break;
             }
-            for (i = 0; i < st->codecpar->channels; i++)
+            for (i = 0; i < st->codecpar->ch_layout.nb_channels; i++)
                 dsd_layout[i] = avio_rl32(pb);
             for (i = 0; i < FF_ARRAY_ELEMS(dsd_channel_layout); i++) {
                 const DSDLayoutDesc * d = &dsd_channel_layout[i];
-                if (av_get_channel_layout_nb_channels(d->layout) == st->codecpar->channels &&
-                    !memcmp(d->dsd_layout, dsd_layout, st->codecpar->channels * sizeof(uint32_t))) {
-                    st->codecpar->channel_layout = d->layout;
+                if (d->layout.nb_channels == st->codecpar->ch_layout.nb_channels &&
+                    !memcmp(d->dsd_layout, dsd_layout, d->layout.nb_channels * sizeof(uint32_t))) {
+                    st->codecpar->ch_layout = d->layout;
                     break;
                 }
             }
@@ -337,8 +337,8 @@ static int parse_dsd_prop(AVFormatContext *s, AVStream *st, uint64_t eof)
             config = avio_rb16(pb);
             if (config != 0xFFFF) {
                 if (config < FF_ARRAY_ELEMS(dsd_loudspeaker_config))
-                    st->codecpar->channel_layout = dsd_loudspeaker_config[config];
-                if (!st->codecpar->channel_layout)
+                    st->codecpar->ch_layout = dsd_loudspeaker_config[config];
+                if (!st->codecpar->ch_layout.nb_channels)
                     avpriv_request_sample(s, "loudspeaker configuration %d", config);
             }
             break;
@@ -431,8 +431,7 @@ static int iff_read_header(AVFormatContext *s)
     if (!st)
         return AVERROR(ENOMEM);
 
-    st->codecpar->channels = 1;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     iff->is_64bit = avio_rl32(pb) == ID_FRM8;
     avio_skip(pb, iff->is_64bit ? 8 : 4);
     // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content
@@ -485,12 +484,13 @@ static int iff_read_header(AVFormatContext *s)
                 return AVERROR_INVALIDDATA;
             avio_skip(pb, 2);
             st->codecpar->sample_rate = num / den;
-            st->codecpar->channels = avio_rb16(pb);
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = avio_rb16(pb);
             iff->maud_compression = avio_rb16(pb);
-            if (st->codecpar->channels == 1)
-                st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
-            else if (st->codecpar->channels == 2)
-                st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+            if (st->codecpar->ch_layout.nb_channels == 1)
+                st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+            else if (st->codecpar->ch_layout.nb_channels == 2)
+                st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
             break;
 
         case ID_ABIT:
@@ -513,11 +513,9 @@ static int iff_read_header(AVFormatContext *s)
             if (data_size < 4)
                 return AVERROR_INVALIDDATA;
             if (avio_rb32(pb) < 6) {
-                st->codecpar->channels       = 1;
-                st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+                st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
             } else {
-                st->codecpar->channels       = 2;
-                st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+                st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
             }
             break;
 
@@ -760,8 +758,11 @@ static int iff_read_header(AVFormatContext *s)
         }
 
         st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id);
-        st->codecpar->bit_rate = (int64_t)st->codecpar->channels * st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample;
-        st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample;
+        st->codecpar->bit_rate    = (int64_t)st->codecpar->ch_layout.nb_channels *
+                                    st->codecpar->sample_rate *
+                                    st->codecpar->bits_per_coded_sample;
+        st->codecpar->block_align = st->codecpar->ch_layout.nb_channels *
+                                    st->codecpar->bits_per_coded_sample;
         if ((st->codecpar->codec_tag == ID_DSD || st->codecpar->codec_tag == ID_MAUD) && st->codecpar->block_align <= 0)
             return AVERROR_INVALIDDATA;
         break;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 078/281] ifv: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (76 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 077/281] iff: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 079/281] ilbc: " James Almer
                   ` (204 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/ifv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/ifv.c b/libavformat/ifv.c
index d38c3ef5a2..490608c5de 100644
--- a/libavformat/ifv.c
+++ b/libavformat/ifv.c
@@ -155,8 +155,7 @@ static int ifv_read_header(AVFormatContext *s)
 
         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
-        st->codecpar->channels = 1;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         st->codecpar->sample_rate = ifv->sample_rate;
         ifv->audio_stream_index = st->index;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 079/281] ilbc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (77 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 078/281] ifv: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 080/281] imx: " James Almer
                   ` (203 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/ilbc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/ilbc.c b/libavformat/ilbc.c
index 0cbdd3d5b8..361116571f 100644
--- a/libavformat/ilbc.c
+++ b/libavformat/ilbc.c
@@ -75,7 +75,7 @@ static int ilbc_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
     st->codecpar->codec_id = AV_CODEC_ID_ILBC;
     st->codecpar->sample_rate = 8000;
-    st->codecpar->channels = 1;
+    st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->start_time = 0;
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 080/281] imx: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (78 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 079/281] ilbc: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 081/281] ircam: " James Almer
                   ` (202 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/imx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/imx.c b/libavformat/imx.c
index e8ca79d057..c8b1a3b2ad 100644
--- a/libavformat/imx.c
+++ b/libavformat/imx.c
@@ -76,8 +76,7 @@ static int simbiosis_imx_read_header(AVFormatContext *s)
     ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     ast->codecpar->codec_tag  = 0;
     ast->codecpar->codec_id   = AV_CODEC_ID_PCM_U8;
-    ast->codecpar->channels   = 1;
-    ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    ast->codecpar->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     ast->codecpar->sample_rate = 22050;
     ast->start_time = 0;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 081/281] ircam: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (79 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 080/281] imx: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 082/281] ipmovie: " James Almer
                   ` (201 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/ircamdec.c | 8 +++++---
 libavformat/ircamenc.c | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavformat/ircamdec.c b/libavformat/ircamdec.c
index a05ca5c9c7..a8927a3733 100644
--- a/libavformat/ircamdec.c
+++ b/libavformat/ircamdec.c
@@ -87,8 +87,9 @@ static int ircam_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
 
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels    = channels;
-    if (st->codecpar->channels > FF_SANE_NB_CHANNELS)
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = channels;
+    if (st->codecpar->ch_layout.nb_channels > FF_SANE_NB_CHANNELS)
         return AVERROR(ENOSYS);
     st->codecpar->sample_rate = sample_rate;
 
@@ -99,7 +100,8 @@ static int ircam_read_header(AVFormatContext *s)
     }
 
     st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id);
-    st->codecpar->block_align = st->codecpar->bits_per_coded_sample * st->codecpar->channels / 8;
+    st->codecpar->block_align = st->codecpar->bits_per_coded_sample *
+                                st->codecpar->ch_layout.nb_channels / 8;
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
     avio_skip(s->pb, 1008);
 
diff --git a/libavformat/ircamenc.c b/libavformat/ircamenc.c
index d49a427b25..df1494b2b8 100644
--- a/libavformat/ircamenc.c
+++ b/libavformat/ircamenc.c
@@ -44,7 +44,7 @@ static int ircam_write_header(AVFormatContext *s)
 
     avio_wl32(s->pb, 0x0001A364);
     avio_wl32(s->pb, av_q2intfloat((AVRational){par->sample_rate, 1}));
-    avio_wl32(s->pb, par->channels);
+    avio_wl32(s->pb, par->ch_layout.nb_channels);
     avio_wl32(s->pb, tag);
     ffio_fill(s->pb, 0, 1008);
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 082/281] ipmovie: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (80 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 081/281] ircam: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 083/281] iss: " James Almer
                   ` (200 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/ipmovie.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c
index 9c996d4a98..793f1f6fee 100644
--- a/libavformat/ipmovie.c
+++ b/libavformat/ipmovie.c
@@ -254,16 +254,14 @@ static int init_audio(AVFormatContext *s)
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = ipmovie->audio_type;
     st->codecpar->codec_tag = 0;  /* no tag */
-    st->codecpar->channels = ipmovie->audio_channels;
-    st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO :
-                                                            AV_CH_LAYOUT_STEREO;
+    av_channel_layout_default(&st->codecpar->ch_layout, ipmovie->audio_channels);
     st->codecpar->sample_rate = ipmovie->audio_sample_rate;
     st->codecpar->bits_per_coded_sample = ipmovie->audio_bits;
-    st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate *
+    st->codecpar->bit_rate = ipmovie->audio_channels * st->codecpar->sample_rate *
         st->codecpar->bits_per_coded_sample;
     if (st->codecpar->codec_id == AV_CODEC_ID_INTERPLAY_DPCM)
         st->codecpar->bit_rate /= 2;
-    st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample;
+    st->codecpar->block_align = ipmovie->audio_channels * st->codecpar->bits_per_coded_sample;
 
     return 0;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 083/281] iss: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (81 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 082/281] ipmovie: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 084/281] jack: port " James Almer
                   ` (199 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/iss.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavformat/iss.c b/libavformat/iss.c
index c58c5923ba..f54ff8b0de 100644
--- a/libavformat/iss.c
+++ b/libavformat/iss.c
@@ -109,19 +109,20 @@ static av_cold int iss_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_ISS;
+
     if (stereo) {
-        st->codecpar->channels       = 2;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     } else {
-        st->codecpar->channels       = 1;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     }
+
     st->codecpar->sample_rate = 44100;
     if(rate_divisor > 0)
          st->codecpar->sample_rate /= rate_divisor;
     st->codecpar->bits_per_coded_sample = 4;
-    st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate
-                                      * st->codecpar->bits_per_coded_sample;
+    st->codecpar->bit_rate = st->codecpar->ch_layout.nb_channels *
+                             st->codecpar->sample_rate *
+                             st->codecpar->bits_per_coded_sample;
     st->codecpar->block_align = iss->packet_size;
     avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate);
 
@@ -138,8 +139,8 @@ static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     pkt->stream_index = 0;
     pkt->pts = avio_tell(s->pb) - iss->sample_start_pos;
-    if(s->streams[0]->codecpar->channels > 0)
-        pkt->pts /= s->streams[0]->codecpar->channels*2;
+    if (s->streams[0]->codecpar->ch_layout.nb_channels > 0)
+        pkt->pts /= s->streams[0]->codecpar->ch_layout.nb_channels * 2;
     return 0;
 }
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 084/281] jack: port to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (82 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 083/281] iss: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 085/281] jvdec: convert " James Almer
                   ` (198 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavdevice/jack.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavdevice/jack.c b/libavdevice/jack.c
index 0d5465e407..53ce029dfd 100644
--- a/libavdevice/jack.c
+++ b/libavdevice/jack.c
@@ -255,7 +255,8 @@ static int audio_read_header(AVFormatContext *context)
     stream->codecpar->codec_id     = AV_CODEC_ID_PCM_F32LE;
 #endif
     stream->codecpar->sample_rate  = self->sample_rate;
-    stream->codecpar->channels     = self->nports;
+    stream->codecpar->ch_layout.nb_channels = self->nports;
+    stream->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
 
     avpriv_set_pts_info(stream, 64, 1, 1000000);  /* 64 bits pts in us */
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 085/281] jvdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (83 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 084/281] jack: port " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 086/281] kvag: " James Almer
                   ` (197 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/jvdec.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/jvdec.c b/libavformat/jvdec.c
index 93569c87df..14e53e5c70 100644
--- a/libavformat/jvdec.c
+++ b/libavformat/jvdec.c
@@ -102,8 +102,7 @@ static int read_header(AVFormatContext *s)
     ast->codecpar->codec_id       = AV_CODEC_ID_PCM_U8;
     ast->codecpar->codec_tag      = 0; /* no fourcc */
     ast->codecpar->sample_rate    = avio_rl16(pb);
-    ast->codecpar->channels       = 1;
-    ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    ast->codecpar->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;;
     avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate);
 
     avio_skip(pb, 10);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 086/281] kvag: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (84 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 085/281] jvdec: convert " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 087/281] avdevice/lavfi: " James Almer
                   ` (196 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/kvag.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/libavformat/kvag.c b/libavformat/kvag.c
index a277c28128..5cb856cf07 100644
--- a/libavformat/kvag.c
+++ b/libavformat/kvag.c
@@ -71,18 +71,11 @@ static int kvag_read_header(AVFormatContext *s)
     par->codec_id               = AV_CODEC_ID_ADPCM_IMA_SSI;
     par->format                 = AV_SAMPLE_FMT_S16;
 
-    if (hdr.stereo) {
-        par->channel_layout     = AV_CH_LAYOUT_STEREO;
-        par->channels           = 2;
-    } else {
-        par->channel_layout     = AV_CH_LAYOUT_MONO;
-        par->channels           = 1;
-    }
-
+    av_channel_layout_default(&par->ch_layout, !!hdr.stereo + 1);
     par->sample_rate            = hdr.sample_rate;
     par->bits_per_coded_sample  = 4;
     par->block_align            = 1;
-    par->bit_rate               = par->channels *
+    par->bit_rate               = par->ch_layout.nb_channels *
                                   (uint64_t)par->sample_rate *
                                   par->bits_per_coded_sample;
 
@@ -90,7 +83,7 @@ static int kvag_read_header(AVFormatContext *s)
     st->start_time              = 0;
     st->duration                = hdr.data_size *
                                   (8 / par->bits_per_coded_sample) /
-                                  par->channels;
+                                  par->ch_layout.nb_channels;
 
     return 0;
 }
@@ -105,7 +98,7 @@ static int kvag_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     pkt->flags          &= ~AV_PKT_FLAG_CORRUPT;
     pkt->stream_index   = 0;
-    pkt->duration       = ret * (8 / par->bits_per_coded_sample) / par->channels;
+    pkt->duration       = ret * (8 / par->bits_per_coded_sample) / par->ch_layout.nb_channels;
 
     return 0;
 }
@@ -147,7 +140,7 @@ static int kvag_write_init(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    if (par->channels > 2) {
+    if (par->ch_layout.nb_channels > 2) {
         av_log(s, AV_LOG_ERROR, "KVAG files only support up to 2 channels\n");
         return AVERROR(EINVAL);
     }
@@ -168,7 +161,7 @@ static int kvag_write_header(AVFormatContext *s)
     AV_WL32(buf +  0, KVAG_TAG);
     AV_WL32(buf +  4, 0); /* Data size, we fix this up later. */
     AV_WL32(buf +  8, par->sample_rate);
-    AV_WL16(buf + 12, par->channels == 2);
+    AV_WL16(buf + 12, par->ch_layout.nb_channels == 2);
 
     avio_write(s->pb, buf, sizeof(buf));
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 087/281] avdevice/lavfi: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (85 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 086/281] kvag: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 088/281] libcdio: port " James Almer
                   ` (195 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavdevice/lavfi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index 710ad7c530..fdb93b835f 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -332,9 +332,12 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx)
             st       ->sample_aspect_ratio =
             par->sample_aspect_ratio = av_buffersink_get_sample_aspect_ratio(sink);
         } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
-            par->channels    = av_buffersink_get_channels(sink);
             par->sample_rate = av_buffersink_get_sample_rate(sink);
-            par->channel_layout = av_buffersink_get_channel_layout(sink);
+            ret = av_channel_layout_from_mask(&par->ch_layout, av_buffersink_get_channel_layout(sink));
+            if (ret < 0) {
+                par->ch_layout.nb_channels = av_buffersink_get_channels(sink);
+                par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+            }
             par->format      = av_buffersink_get_format(sink);
             par->codec_id    = av_get_pcm_codec(par->format, -1);
             if (par->codec_id == AV_CODEC_ID_NONE)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 088/281] libcdio: port to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (86 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 087/281] avdevice/lavfi: " James Almer
@ 2022-01-13  1:50 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 089/281] lvf: convert " James Almer
                   ` (194 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:50 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavdevice/libcdio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavdevice/libcdio.c b/libavdevice/libcdio.c
index 623878fe7f..4417523c57 100644
--- a/libavdevice/libcdio.c
+++ b/libavdevice/libcdio.c
@@ -90,13 +90,14 @@ static av_cold int read_header(AVFormatContext *ctx)
     else
         st->codecpar->codec_id    = AV_CODEC_ID_PCM_S16LE;
     st->codecpar->sample_rate     = 44100;
-    st->codecpar->channels        = 2;
+    st->codecpar->ch_layout       = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     if (s->drive->audio_last_sector != CDIO_INVALID_LSN &&
         s->drive->audio_first_sector != CDIO_INVALID_LSN)
         st->duration           = s->drive->audio_last_sector - s->drive->audio_first_sector;
     else if (s->drive->tracks)
         st->duration = s->drive->disc_toc[s->drive->tracks].dwStartSector;
-    avpriv_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW, 2 * st->codecpar->channels * st->codecpar->sample_rate);
+    avpriv_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW,
+                        2 * st->codecpar->ch_layout.nb_channels * st->codecpar->sample_rate);
 
     for (i = 0; i < s->drive->tracks; i++) {
         char title[16];
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 089/281] lvf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (87 preceding siblings ...)
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 088/281] libcdio: port " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 090/281] lxfdec: " James Almer
                   ` (193 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/lvfdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/lvfdec.c b/libavformat/lvfdec.c
index cd64fb9aee..d060b3b0aa 100644
--- a/libavformat/lvfdec.c
+++ b/libavformat/lvfdec.c
@@ -79,7 +79,8 @@ static int lvf_read_header(AVFormatContext *s)
 
             st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
             st->codecpar->codec_tag   = avio_rl16(s->pb);
-            st->codecpar->channels    = avio_rl16(s->pb);
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = avio_rl16(s->pb);
             st->codecpar->sample_rate = avio_rl16(s->pb);
             avio_skip(s->pb, 8);
             st->codecpar->bits_per_coded_sample = avio_r8(s->pb);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 090/281] lxfdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (88 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 089/281] lvf: convert " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-27 15:19   ` Tomas Härdin
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 091/281] matroska: " James Almer
                   ` (192 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/lxfdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/lxfdec.c b/libavformat/lxfdec.c
index 7889abb2c9..9e0d265f6a 100644
--- a/libavformat/lxfdec.c
+++ b/libavformat/lxfdec.c
@@ -281,7 +281,8 @@ static int lxf_read_header(AVFormatContext *s)
 
         st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
         st->codecpar->sample_rate = LXF_SAMPLERATE;
-        st->codecpar->channels    = lxf->channels;
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = lxf->channels;
 
         avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 091/281] matroska: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (89 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 090/281] lxfdec: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-21 19:52   ` Andreas Rheinhardt
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 092/281] mca: " James Almer
                   ` (191 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/matroskadec.c |  8 ++++++--
 libavformat/matroskaenc.c | 10 +++++-----
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 78e5a4a203..62a36cbb8c 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2083,7 +2083,7 @@ static int matroska_parse_flac(AVFormatContext *s,
                     av_log(s, AV_LOG_WARNING,
                            "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n");
                 } else
-                    st->codecpar->channel_layout = mask;
+                    av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
             }
             av_dict_free(&dict);
         }
@@ -2911,7 +2911,11 @@ static int matroska_parse_tracks(AVFormatContext *s)
             st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
             st->codecpar->codec_tag   = fourcc;
             st->codecpar->sample_rate = track->audio.out_samplerate;
-            st->codecpar->channels    = track->audio.channels;
+            // channel layout may be already set by codec private checks above
+            if (st->codecpar->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
+                !st->codecpar->ch_layout.u.mask)
+                st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = track->audio.channels;
             if (!st->codecpar->bits_per_coded_sample)
                 st->codecpar->bits_per_coded_sample = track->audio.bitdepth;
             if (st->codecpar->codec_id == AV_CODEC_ID_MP3 ||
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 152312102a..5278166e8c 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -657,9 +657,9 @@ static int put_wv_codecpriv(AVIOContext *pb, const AVCodecParameters *par)
 static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb,
                               const AVCodecParameters *par)
 {
-    int write_comment = (par->channel_layout &&
-                         !(par->channel_layout & ~0x3ffffULL) &&
-                         !ff_flac_is_native_layout(par->channel_layout));
+    int write_comment = (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE && par->ch_layout.u.mask &&
+                         !av_channel_layout_subset(&par->ch_layout, ~0x3ffffULL) &&
+                         !ff_flac_is_native_layout(par->ch_layout.u.mask));
     int ret = ff_flac_write_header(pb, par->extradata, par->extradata_size,
                                    !write_comment);
 
@@ -673,7 +673,7 @@ static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb,
         uint8_t buf[32];
         int64_t len;
 
-        snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout);
+        snprintf(buf, sizeof(buf), "0x%"PRIx64, par->ch_layout.u.mask);
         av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
 
         len = ff_vorbiscomment_length(dict, vendor, NULL, 0);
@@ -1396,7 +1396,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
             put_ebml_string(pb, MATROSKA_ID_CODECID, "A_MS/ACM");
 
         subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 6 + 4 * 9);
-        put_ebml_uint  (pb, MATROSKA_ID_AUDIOCHANNELS    , par->channels);
+        put_ebml_uint(pb, MATROSKA_ID_AUDIOCHANNELS, par->ch_layout.nb_channels);
 
         track->sample_rate_offset = avio_tell(pb);
         put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 092/281] mca: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (90 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 091/281] matroska: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 093/281] mm: " James Almer
                   ` (190 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mca.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/libavformat/mca.c b/libavformat/mca.c
index ca0f76d6bf..feda65dd85 100644
--- a/libavformat/mca.c
+++ b/libavformat/mca.c
@@ -62,7 +62,8 @@ static int read_header(AVFormatContext *s)
     avio_skip(s->pb, 0x4);      // skip the file magic
     version          = avio_rl16(s->pb);
     avio_skip(s->pb, 0x2);      // padding
-    par->channels    = avio_r8(s->pb);
+    par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    par->ch_layout.nb_channels = avio_r8(s->pb);
     avio_skip(s->pb, 0x1);      // padding
     m->block_size    = avio_rl16(s->pb);
     nb_samples       = avio_rl32(s->pb);
@@ -85,7 +86,7 @@ static int read_header(AVFormatContext *s)
     st->duration = nb_samples;
 
     // sanity checks
-    if (!par->channels || par->sample_rate <= 0
+    if (!par->ch_layout.nb_channels || par->sample_rate <= 0
         || loop_start > loop_end || m->block_count < 1)
         return AVERROR_INVALIDDATA;
     if ((ret = av_dict_set_int(&s->metadata, "loop_start",
@@ -96,8 +97,8 @@ static int read_header(AVFormatContext *s)
                         av_rescale(loop_end, AV_TIME_BASE,
                                    par->sample_rate), 0)) < 0)
         return ret;
-    if ((32 + 4 + m->block_size) > (INT_MAX / par->channels) ||
-        (32 + 4 + m->block_size) * par->channels > INT_MAX - 8)
+    if ((32 + 4 + m->block_size) > (INT_MAX / par->ch_layout.nb_channels) ||
+        (32 + 4 + m->block_size) * par->ch_layout.nb_channels > INT_MAX - 8)
         return AVERROR_INVALIDDATA;
     avpriv_set_pts_info(st, 64, 1, par->sample_rate);
 
@@ -116,9 +117,9 @@ static int read_header(AVFormatContext *s)
         }
     } else if (version == 5) {
         // read data_start location from the header
-        if (0x30 * par->channels + 0x4 > header_size)
+        if (0x30 * par->ch_layout.nb_channels + 0x4 > header_size)
             return AVERROR_INVALIDDATA;
-        data_offset = header_size - 0x30 * par->channels - 0x4;
+        data_offset = header_size - 0x30 * par->ch_layout.nb_channels - 0x4;
         if ((ret_size = avio_seek(s->pb, data_offset, SEEK_SET)) < 0)
             return ret_size;
         m->data_start = avio_rl32(s->pb);
@@ -144,21 +145,21 @@ static int read_header(AVFormatContext *s)
     }
 
     // coefficient alignment = 0x30; metadata size = 0x14
-    if (0x30 * par->channels + nb_metadata * 0x14 > header_size)
+    if (0x30 * par->ch_layout.nb_channels + nb_metadata * 0x14 > header_size)
         return AVERROR_INVALIDDATA;
     coef_offset =
-        header_size - 0x30 * par->channels + nb_metadata * 0x14;
+        header_size - 0x30 * par->ch_layout.nb_channels + nb_metadata * 0x14;
 
     st->start_time = 0;
     par->codec_id = AV_CODEC_ID_ADPCM_THP_LE;
 
-    ret = ff_alloc_extradata(st->codecpar, 32 * par->channels);
+    ret = ff_alloc_extradata(st->codecpar, 32 * par->ch_layout.nb_channels);
     if (ret < 0)
         return ret;
 
     if ((ret_size = avio_seek(s->pb, coef_offset, SEEK_SET)) < 0)
         return ret_size;
-    for (ch = 0; ch < par->channels; ch++) {
+    for (ch = 0; ch < par->ch_layout.nb_channels; ch++) {
         if ((ret = ffio_read_size(s->pb, par->extradata + ch * 32, 32)) < 0)
             return ret;
         // 0x30 (alignment) - 0x20 (actual size, 32) = 0x10 (padding)
@@ -187,7 +188,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
     if (m->current_block > m->block_count)
         return AVERROR_EOF;
 
-    if ((ret = av_get_packet(s->pb, pkt, size * par->channels)) < 0)
+    if ((ret = av_get_packet(s->pb, pkt, size * par->ch_layout.nb_channels)) < 0)
         return ret;
     pkt->duration = samples;
     pkt->stream_index = 0;
@@ -208,7 +209,7 @@ static int read_seek(AVFormatContext *s, int stream_index,
     if (timestamp >= m->block_count)
         timestamp = m->block_count - 1;
     ret = avio_seek(s->pb, m->data_start + timestamp * m->block_size *
-                    st->codecpar->channels, SEEK_SET);
+                    st->codecpar->ch_layout.nb_channels, SEEK_SET);
     if (ret < 0)
         return ret;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 093/281] mm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (91 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 092/281] mca: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 094/281] mmf: " James Almer
                   ` (189 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/mm.c b/libavformat/mm.c
index d1acfef445..1d44f41a94 100644
--- a/libavformat/mm.c
+++ b/libavformat/mm.c
@@ -124,8 +124,7 @@ static int read_header(AVFormatContext *s)
         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_tag = 0; /* no fourcc */
         st->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
-        st->codecpar->channels = 1;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         st->codecpar->sample_rate = 8000;
         avpriv_set_pts_info(st, 64, 1, 8000); /* 8000 hz */
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 094/281] mmf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (92 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 093/281] mm: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 095/281] moflex: " James Almer
                   ` (188 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mmf.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/mmf.c b/libavformat/mmf.c
index 0c067a1025..4c3ef3456b 100644
--- a/libavformat/mmf.c
+++ b/libavformat/mmf.c
@@ -80,7 +80,7 @@ static int mmf_write_header(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    mmf->stereo = s->streams[0]->codecpar->channels > 1;
+    mmf->stereo = s->streams[0]->codecpar->ch_layout.nb_channels > 1;
     if (mmf->stereo &&
         s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
         av_log(s, AV_LOG_ERROR, "Yamaha SMAF stereo is experimental, "
@@ -261,8 +261,7 @@ static int mmf_read_header(AVFormatContext *s)
     st->codecpar->codec_type            = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id              = AV_CODEC_ID_ADPCM_YAMAHA;
     st->codecpar->sample_rate           = rate;
-    st->codecpar->channels              = (params >> 7) + 1;
-    st->codecpar->channel_layout        = params >> 7 ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
+    av_channel_layout_default(&st->codecpar->ch_layout, (params >> 7) + 1);
     st->codecpar->bits_per_coded_sample = 4;
     st->codecpar->bit_rate              = st->codecpar->sample_rate *
                                           st->codecpar->bits_per_coded_sample;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 095/281] moflex: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (93 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 094/281] mmf: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 096/281] mov: " James Almer
                   ` (187 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/moflex.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/moflex.c b/libavformat/moflex.c
index 1d342417f7..0b628add6c 100644
--- a/libavformat/moflex.c
+++ b/libavformat/moflex.c
@@ -233,7 +233,8 @@ static int moflex_read_sync(AVFormatContext *s)
             st->codecpar->width      = width;
             st->codecpar->height     = height;
             st->codecpar->sample_rate= sample_rate;
-            st->codecpar->channels   = channels;
+            st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = channels;
             st->priv_data            = av_packet_alloc();
             if (!st->priv_data)
                 return AVERROR(ENOMEM);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 096/281] mov: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (94 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 095/281] moflex: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-28 10:08   ` Anton Khirnov
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 097/281] movenc-test: " James Almer
                   ` (186 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/isom.c     |  5 +--
 libavformat/mov.c      | 80 +++++++++++++++++++++++++++---------------
 libavformat/mov_chan.c | 21 +++++++----
 libavformat/mov_chan.h |  3 +-
 libavformat/movenc.c   | 25 +++++++------
 5 files changed, 85 insertions(+), 49 deletions(-)

diff --git a/libavformat/isom.c b/libavformat/isom.c
index 015c82e1bb..e6569dfb68 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -360,7 +360,8 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext
                                                 st->codecpar->extradata_size, 1, fc);
             if (ret < 0)
                 return ret;
-            st->codecpar->channels = cfg.channels;
+            st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = cfg.channels;
             if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4
                 st->codecpar->sample_rate = ff_mpa_freq_tab[cfg.sampling_index];
             else if (cfg.ext_sample_rate)
@@ -368,7 +369,7 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext
             else
                 st->codecpar->sample_rate = cfg.sample_rate;
             av_log(fc, AV_LOG_TRACE, "mp4a config channels %d obj %d ext obj %d "
-                    "sample rate %d ext sample rate %d\n", st->codecpar->channels,
+                    "sample rate %d ext sample rate %d\n", cfg.channels,
                     cfg.object_type, cfg.ext_object_type,
                     cfg.sample_rate, cfg.ext_sample_rate);
             if (!(st->codecpar->codec_id = ff_codec_get_id(mp4_audio_types,
diff --git a/libavformat/mov.c b/libavformat/mov.c
index e401cd39b5..e307df8e3c 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -798,6 +798,7 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     AVStream *st;
     enum AVAudioServiceType *ast;
     int ac3info, acmod, lfeon, bsmod;
+    uint64_t mask;
 
     if (c->fc->nb_streams < 1)
         return 0;
@@ -812,12 +813,15 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     bsmod = (ac3info >> 14) & 0x7;
     acmod = (ac3info >> 11) & 0x7;
     lfeon = (ac3info >> 10) & 0x1;
-    st->codecpar->channels = ((int[]){2,1,2,3,3,4,4,5})[acmod] + lfeon;
-    st->codecpar->channel_layout = ff_ac3_channel_layout_tab[acmod];
+
+    mask = ff_ac3_channel_layout_tab[acmod];
     if (lfeon)
-        st->codecpar->channel_layout |= AV_CH_LOW_FREQUENCY;
+        mask |= AV_CH_LOW_FREQUENCY;
+    av_channel_layout_uninit(&st->codecpar->ch_layout);
+    av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
+
     *ast = bsmod;
-    if (st->codecpar->channels > 1 && bsmod == 0x7)
+    if (st->codecpar->ch_layout.nb_channels > 1 && bsmod == 0x7)
         *ast = AV_AUDIO_SERVICE_TYPE_KARAOKE;
 
     return 0;
@@ -828,6 +832,7 @@ static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     AVStream *st;
     enum AVAudioServiceType *ast;
     int eac3info, acmod, lfeon, bsmod;
+    uint64_t mask;
 
     if (c->fc->nb_streams < 1)
         return 0;
@@ -846,12 +851,15 @@ static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     bsmod = (eac3info >> 12) & 0x1f;
     acmod = (eac3info >>  9) & 0x7;
     lfeon = (eac3info >>  8) & 0x1;
-    st->codecpar->channel_layout = ff_ac3_channel_layout_tab[acmod];
+
+    mask = ff_ac3_channel_layout_tab[acmod];
     if (lfeon)
-        st->codecpar->channel_layout |= AV_CH_LOW_FREQUENCY;
-    st->codecpar->channels = av_get_channel_layout_nb_channels(st->codecpar->channel_layout);
+        mask |= AV_CH_LOW_FREQUENCY;
+    av_channel_layout_uninit(&st->codecpar->ch_layout);
+    av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
+
     *ast = bsmod;
-    if (st->codecpar->channels > 1 && bsmod == 0x7)
+    if (st->codecpar->ch_layout.nb_channels > 1 && bsmod == 0x7)
         *ast = AV_AUDIO_SERVICE_TYPE_KARAOKE;
 
     return 0;
@@ -898,15 +906,14 @@ static int mov_read_ddts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     if (channel_layout_code > 0xff) {
         av_log(c->fc, AV_LOG_WARNING, "Unsupported DTS audio channel layout\n");
     }
-    st->codecpar->channel_layout =
+    av_channel_layout_uninit(&st->codecpar->ch_layout);
+    av_channel_layout_from_mask(&st->codecpar->ch_layout,
             ((channel_layout_code & 0x1) ? AV_CH_FRONT_CENTER : 0) |
             ((channel_layout_code & 0x2) ? AV_CH_FRONT_LEFT : 0) |
             ((channel_layout_code & 0x2) ? AV_CH_FRONT_RIGHT : 0) |
             ((channel_layout_code & 0x4) ? AV_CH_SIDE_LEFT : 0) |
             ((channel_layout_code & 0x4) ? AV_CH_SIDE_RIGHT : 0) |
-            ((channel_layout_code & 0x8) ? AV_CH_LOW_FREQUENCY : 0);
-
-    st->codecpar->channels = av_get_channel_layout_nb_channels(st->codecpar->channel_layout);
+            ((channel_layout_code & 0x8) ? AV_CH_LOW_FREQUENCY : 0));
 
     return 0;
 }
@@ -2162,14 +2169,18 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb,
     uint16_t version = avio_rb16(pb);
     uint32_t id = 0;
     AVDictionaryEntry *compatible_brands = av_dict_get(c->fc->metadata, "compatible_brands", NULL, AV_DICT_MATCH_CASE);
+    int channel_count;
 
     avio_rb16(pb); /* revision level */
     id = avio_rl32(pb); /* vendor */
     av_dict_set(&st->metadata, "vendor_id", av_fourcc2str(id), 0);
 
-    st->codecpar->channels              = avio_rb16(pb); /* channel count */
+    channel_count = avio_rb16(pb);
+
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = channel_count;
     st->codecpar->bits_per_coded_sample = avio_rb16(pb); /* sample size */
-    av_log(c->fc, AV_LOG_TRACE, "audio channels %d\n", st->codecpar->channels);
+    av_log(c->fc, AV_LOG_TRACE, "audio channels %d\n", channel_count);
 
     sc->audio_cid = avio_rb16(pb);
     avio_rb16(pb); /* packet size = 0 */
@@ -2189,7 +2200,9 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb,
         } else if (version == 2) {
             avio_rb32(pb); /* sizeof struct only */
             st->codecpar->sample_rate = av_int2double(avio_rb64(pb));
-            st->codecpar->channels    = avio_rb32(pb);
+            channel_count = avio_rb32(pb);
+            st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = channel_count;
             avio_rb32(pb); /* always 0x7F000000 */
             st->codecpar->bits_per_coded_sample = avio_rb32(pb);
 
@@ -2241,15 +2254,15 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb,
     /* set values for old format before stsd version 1 appeared */
     case AV_CODEC_ID_MACE3:
         sc->samples_per_frame = 6;
-        sc->bytes_per_frame   = 2 * st->codecpar->channels;
+        sc->bytes_per_frame   = 2 * st->codecpar->ch_layout.nb_channels;
         break;
     case AV_CODEC_ID_MACE6:
         sc->samples_per_frame = 6;
-        sc->bytes_per_frame   = 1 * st->codecpar->channels;
+        sc->bytes_per_frame   = 1 * st->codecpar->ch_layout.nb_channels;
         break;
     case AV_CODEC_ID_ADPCM_IMA_QT:
         sc->samples_per_frame = 64;
-        sc->bytes_per_frame   = 34 * st->codecpar->channels;
+        sc->bytes_per_frame   = 34 * st->codecpar->ch_layout.nb_channels;
         break;
     case AV_CODEC_ID_GSM:
         sc->samples_per_frame = 160;
@@ -2260,9 +2273,9 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb,
     }
 
     bits_per_sample = av_get_bits_per_sample(st->codecpar->codec_id);
-    if (bits_per_sample && (bits_per_sample >> 3) * (uint64_t)st->codecpar->channels <= INT_MAX) {
+    if (bits_per_sample && (bits_per_sample >> 3) * (uint64_t)st->codecpar->ch_layout.nb_channels <= INT_MAX) {
         st->codecpar->bits_per_coded_sample = bits_per_sample;
-        sc->sample_size = (bits_per_sample >> 3) * st->codecpar->channels;
+        sc->sample_size = (bits_per_sample >> 3) * st->codecpar->ch_layout.nb_channels;
     }
 }
 
@@ -2402,7 +2415,8 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb,
 #endif
     /* no ifdef since parameters are always those */
     case AV_CODEC_ID_QCELP:
-        st->codecpar->channels = 1;
+        av_channel_layout_uninit(&st->codecpar->ch_layout);
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         // force sample rate for qcelp when not stored in mov
         if (st->codecpar->codec_tag != MKTAG('Q','c','l','p'))
             st->codecpar->sample_rate = 8000;
@@ -2412,12 +2426,14 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb,
             sc->bytes_per_frame = 35;
         break;
     case AV_CODEC_ID_AMR_NB:
-        st->codecpar->channels    = 1;
+        av_channel_layout_uninit(&st->codecpar->ch_layout);
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         /* force sample rate for amr, stsd in 3gp does not store sample rate */
         st->codecpar->sample_rate = 8000;
         break;
     case AV_CODEC_ID_AMR_WB:
-        st->codecpar->channels    = 1;
+        av_channel_layout_uninit(&st->codecpar->ch_layout);
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         st->codecpar->sample_rate = 16000;
         break;
     case AV_CODEC_ID_MP2:
@@ -2436,7 +2452,12 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb,
         break;
     case AV_CODEC_ID_ALAC:
         if (st->codecpar->extradata_size == 36) {
-            st->codecpar->channels    = AV_RB8 (st->codecpar->extradata + 21);
+            int channel_count = AV_RB8(st->codecpar->extradata + 21);
+            if (st->codecpar->ch_layout.nb_channels != channel_count) {
+                av_channel_layout_uninit(&st->codecpar->ch_layout);
+                st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+                st->codecpar->ch_layout.nb_channels = channel_count;
+            }
             st->codecpar->sample_rate = AV_RB32(st->codecpar->extradata + 32);
         }
         break;
@@ -2543,8 +2564,8 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
                 av_log(c->fc, AV_LOG_ERROR, "Invalid sample rate %d\n", st->codecpar->sample_rate);
                 return AVERROR_INVALIDDATA;
             }
-            if (st->codecpar->channels < 0) {
-                av_log(c->fc, AV_LOG_ERROR, "Invalid channels %d\n", st->codecpar->channels);
+            if (st->codecpar->ch_layout.nb_channels < 0) {
+                av_log(c->fc, AV_LOG_ERROR, "Invalid channels %d\n", st->codecpar->ch_layout.nb_channels);
                 return AVERROR_INVALIDDATA;
             }
         } else if (st->codecpar->codec_type==AVMEDIA_TYPE_SUBTITLE){
@@ -7034,6 +7055,7 @@ static int mov_read_dmlp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     unsigned format_info;
     int channel_assignment, channel_assignment1, channel_assignment2;
     int ratebits;
+    uint64_t chmask;
 
     if (c->fc->nb_streams < 1)
         return 0;
@@ -7054,8 +7076,10 @@ static int mov_read_dmlp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 
     st->codecpar->frame_size = 40 << (ratebits & 0x7);
     st->codecpar->sample_rate = mlp_samplerate(ratebits);
-    st->codecpar->channels = truehd_channels(channel_assignment);
-    st->codecpar->channel_layout = truehd_layout(channel_assignment);
+
+    av_channel_layout_uninit(&st->codecpar->ch_layout);
+    chmask = truehd_layout(channel_assignment);
+    av_channel_layout_from_mask(&st->codecpar->ch_layout, chmask);
 
     return 0;
 }
diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c
index 349634094c..5894bb8ce2 100644
--- a/libavformat/mov_chan.c
+++ b/libavformat/mov_chan.c
@@ -499,7 +499,7 @@ static uint32_t mov_get_channel_label(uint32_t label)
 }
 
 uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id,
-                                       uint64_t channel_layout,
+                                       AVChannelLayout *ch_layout,
                                        uint32_t *bitmap)
 {
     int i, j;
@@ -519,7 +519,7 @@ uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id,
         const struct MovChannelLayoutMap *layout_map;
 
         /* get the layout map based on the channel count */
-        channels = av_get_channel_layout_nb_channels(channel_layout);
+        channels = ch_layout->nb_channels;
         if (channels > 9)
             channels = 0;
         layout_map = mov_ch_layout_map[channels];
@@ -530,7 +530,8 @@ uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id,
                 continue;
             for (j = 0; layout_map[j].tag != 0; j++) {
                 if (layout_map[j].tag    == layouts[i] &&
-                    layout_map[j].layout == channel_layout)
+                    (ch_layout->order == AV_CHANNEL_ORDER_NATIVE &&
+                     layout_map[j].layout == ch_layout->u.mask))
                     break;
             }
             if (layout_map[j].tag)
@@ -540,9 +541,9 @@ uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id,
     }
 
     /* if no tag was found, use channel bitmap as a backup if possible */
-    if (tag == 0 && channel_layout > 0 && channel_layout < 0x40000) {
+    if (tag == 0 && av_channel_layout_check(ch_layout) && ch_layout->u.mask < 0x40000) {
         tag     = MOV_CH_LAYOUT_USE_BITMAP;
-        *bitmap = (uint32_t)channel_layout;
+        *bitmap = (uint32_t)ch_layout->u.mask;
     } else
         *bitmap = 0;
 
@@ -555,6 +556,7 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st,
                      int64_t size)
 {
     uint32_t layout_tag, bitmap, num_descr, label_mask;
+    uint64_t mask = 0;
     int i;
 
     if (size < 12)
@@ -596,9 +598,14 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st,
     }
     if (layout_tag == 0) {
         if (label_mask)
-            st->codecpar->channel_layout = label_mask;
+            mask = label_mask;
     } else
-        st->codecpar->channel_layout = mov_get_channel_layout(layout_tag, bitmap);
+        mask = mov_get_channel_layout(layout_tag, bitmap);
+
+    if (mask) {
+        av_channel_layout_uninit(&st->codecpar->ch_layout);
+        av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
+    }
     avio_skip(pb, size - 12);
 
     return 0;
diff --git a/libavformat/mov_chan.h b/libavformat/mov_chan.h
index f7916e9899..a9bc9f80d4 100644
--- a/libavformat/mov_chan.h
+++ b/libavformat/mov_chan.h
@@ -28,6 +28,7 @@
 
 #include <stdint.h>
 
+#include "libavutil/channel_layout.h"
 #include "libavcodec/codec_id.h"
 #include "avformat.h"
 
@@ -41,7 +42,7 @@
  * @return                     channel layout tag
  */
 uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id,
-                                       uint64_t channel_layout,
+                                       AVChannelLayout *ch_layout,
                                        uint32_t *bitmap);
 
 /**
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 4c868919ae..6d02a9ea39 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -868,7 +868,7 @@ static int mov_write_chan_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra
     int64_t pos = avio_tell(pb);
 
     layout_tag = ff_mov_get_channel_layout_tag(track->par->codec_id,
-                                               track->par->channel_layout,
+                                               &track->par->ch_layout,
                                                &bitmap);
     if (!layout_tag) {
         av_log(s, AV_LOG_WARNING, "not writing 'chan' tag due to "
@@ -1137,7 +1137,7 @@ static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex
     int ret = 0;
 
     if (track->mode == MODE_MOV) {
-        if (track->timescale > UINT16_MAX || !track->par->channels) {
+        if (track->timescale > UINT16_MAX || !track->par->ch_layout.nb_channels) {
             if (mov_get_lpcm_flags(track->par->codec_id))
                 tag = AV_RL32("lpcm");
             version = 2;
@@ -1173,7 +1173,7 @@ static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex
         avio_wb32(pb, 0x00010000);
         avio_wb32(pb, 72);
         avio_wb64(pb, av_double2int(track->par->sample_rate));
-        avio_wb32(pb, track->par->channels);
+        avio_wb32(pb, track->par->ch_layout.nb_channels);
         avio_wb32(pb, 0x7F000000);
         avio_wb32(pb, av_get_bits_per_sample(track->par->codec_id));
         avio_wb32(pb, mov_get_lpcm_flags(track->par->codec_id));
@@ -1181,7 +1181,7 @@ static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex
         avio_wb32(pb, get_samples_per_packet(track));
     } else {
         if (track->mode == MODE_MOV) {
-            avio_wb16(pb, track->par->channels);
+            avio_wb16(pb, track->par->ch_layout.nb_channels);
             if (track->par->codec_id == AV_CODEC_ID_PCM_U8 ||
                 track->par->codec_id == AV_CODEC_ID_PCM_S8)
                 avio_wb16(pb, 8); /* bits per sample */
@@ -1194,7 +1194,7 @@ static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex
             if (track->par->codec_id == AV_CODEC_ID_FLAC ||
                 track->par->codec_id == AV_CODEC_ID_ALAC ||
                 track->par->codec_id == AV_CODEC_ID_OPUS) {
-                avio_wb16(pb, track->par->channels);
+                avio_wb16(pb, track->par->ch_layout.nb_channels);
             } else {
                 avio_wb16(pb, 2);
             }
@@ -1226,7 +1226,7 @@ static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex
             avio_wb32(pb, 1); /*  must be 1 for  uncompressed formats */
         else
             avio_wb32(pb, track->par->frame_size); /* Samples per packet */
-        avio_wb32(pb, track->sample_size / track->par->channels); /* Bytes per packet */
+        avio_wb32(pb, track->sample_size / track->par->ch_layout.nb_channels); /* Bytes per packet */
         avio_wb32(pb, track->sample_size); /* Bytes per frame */
         avio_wb32(pb, 2); /* Bytes per sample */
     }
@@ -4392,7 +4392,7 @@ static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov, AVFormat
                             track->par->extradata_size);
             param_write_int(pb, "AudioTag", ff_codec_get_tag(ff_codec_wav_tags,
                                                              track->par->codec_id));
-            param_write_int(pb, "Channels", track->par->channels);
+            param_write_int(pb, "Channels", track->par->ch_layout.nb_channels);
             param_write_int(pb, "SamplingRate", track->par->sample_rate);
             param_write_int(pb, "BitsPerSample", 16);
             param_write_int(pb, "PacketSize", track->par->block_align ?
@@ -5150,7 +5150,7 @@ static int mov_write_uuidprof_tag(AVIOContext *pb, AVFormatContext *s)
     avio_wb32(pb, audio_kbitrate);
     avio_wb32(pb, audio_kbitrate);
     avio_wb32(pb, audio_rate);
-    avio_wb32(pb, audio_par->channels);
+    avio_wb32(pb, audio_par->ch_layout.nb_channels);
 
     avio_wb32(pb, 0x34);  /* size */
     ffio_wfourcc(pb, "VPRF");   /* video */
@@ -6830,7 +6830,8 @@ static int mov_init(AVFormatContext *s)
             }else if (st->codecpar->frame_size > 1){ /* assume compressed audio */
                 track->audio_vbr = 1;
             }else{
-                track->sample_size = (av_get_bits_per_sample(st->codecpar->codec_id) >> 3) * st->codecpar->channels;
+                track->sample_size = (av_get_bits_per_sample(st->codecpar->codec_id) >> 3) *
+                                     st->codecpar->ch_layout.nb_channels;
             }
             if (st->codecpar->codec_id == AV_CODEC_ID_ILBC ||
                 st->codecpar->codec_id == AV_CODEC_ID_ADPCM_IMA_QT) {
@@ -6966,7 +6967,8 @@ static int mov_write_header(AVFormatContext *s)
         }
 
         if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO ||
-            track->par->channel_layout != AV_CH_LAYOUT_MONO)
+            av_channel_layout_compare(&track->par->ch_layout,
+                                      &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO))
             continue;
 
         for (j = 0; j < s->nb_streams; j++) {
@@ -6976,7 +6978,8 @@ static int mov_write_header(AVFormatContext *s)
                 continue;
 
             if (stj->codecpar->codec_type != AVMEDIA_TYPE_AUDIO ||
-                trackj->par->channel_layout != AV_CH_LAYOUT_MONO ||
+                av_channel_layout_compare(&trackj->par->ch_layout,
+                                          &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO) ||
                 trackj->language != track->language ||
                 trackj->tag != track->tag
             )
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 097/281] movenc-test: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (95 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 096/281] mov: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 098/281] mp3: " James Almer
                   ` (185 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/tests/movenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/tests/movenc.c b/libavformat/tests/movenc.c
index 2af72f11c7..1d45725318 100644
--- a/libavformat/tests/movenc.c
+++ b/libavformat/tests/movenc.c
@@ -214,7 +214,7 @@ static void init_fps(int bf, int audio_preroll, int fps)
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = AV_CODEC_ID_AAC;
     st->codecpar->sample_rate = 44100;
-    st->codecpar->channels = 2;
+    st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     st->time_base.num = 1;
     st->time_base.den = 44100;
     st->codecpar->extradata_size = sizeof(aac_extradata);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 098/281] mp3: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (96 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 097/281] movenc-test: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 099/281] mpc: " James Almer
                   ` (184 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mp3enc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index 3ff19da274..91874fa14e 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -175,7 +175,7 @@ static int mp3_write_xing(AVFormatContext *s)
         return -1;
     }
 
-    switch (par->channels) {
+    switch (par->ch_layout.nb_channels) {
     case 1:  channels = MPA_MONO;                                          break;
     case 2:  channels = MPA_STEREO;                                        break;
     default: av_log(s, AV_LOG_WARNING, "Unsupported number of channels, "
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 099/281] mpc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (97 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 098/281] mp3: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 100/281] mpc8: " James Almer
                   ` (183 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mpc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/mpc.c b/libavformat/mpc.c
index b5b2bab33c..f36768b5ff 100644
--- a/libavformat/mpc.c
+++ b/libavformat/mpc.c
@@ -95,8 +95,7 @@ static int mpc_read_header(AVFormatContext *s)
 
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = AV_CODEC_ID_MUSEPACK7;
-    st->codecpar->channels = 2;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+    st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     st->codecpar->bits_per_coded_sample = 16;
 
     if ((ret = ff_get_extradata(s, st->codecpar, s->pb, 16)) < 0)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 100/281] mpc8: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (98 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 099/281] mpc: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 101/281] mpeg: " James Almer
                   ` (182 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mpc8.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c
index 0cf46b36a0..c5f05e08a2 100644
--- a/libavformat/mpc8.c
+++ b/libavformat/mpc8.c
@@ -230,6 +230,7 @@ static int mpc8_read_header(AVFormatContext *s)
     AVIOContext *pb = s->pb;
     AVStream *st;
     int tag = 0, ret;
+    int channels;
     int64_t size, pos;
 
     c->header_pos = avio_tell(pb);
@@ -273,7 +274,9 @@ static int mpc8_read_header(AVFormatContext *s)
     if ((ret = ff_get_extradata(s, st->codecpar, pb, 2)) < 0)
         return ret;
 
-    st->codecpar->channels = (st->codecpar->extradata[1] >> 4) + 1;
+    channels = (st->codecpar->extradata[1] >> 4) + 1;
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = channels;
     st->codecpar->sample_rate = mpc8_rate[st->codecpar->extradata[0] >> 5];
     avpriv_set_pts_info(st, 64, 1152  << (st->codecpar->extradata[1]&3)*2, st->codecpar->sample_rate);
     st->start_time = 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 101/281] mpeg: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (99 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 100/281] mpc8: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 102/281] mpegenc: " James Almer
                   ` (181 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mpeg.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index ca15d9f241..34c1b74a4e 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -621,8 +621,7 @@ skip:
     st->codecpar->codec_id   = codec_id;
     if (   st->codecpar->codec_id == AV_CODEC_ID_PCM_MULAW
         || st->codecpar->codec_id == AV_CODEC_ID_PCM_ALAW) {
-        st->codecpar->channels = 1;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         st->codecpar->sample_rate = 8000;
     }
     sti->request_probe = request_probe;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 102/281] mpegenc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (100 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 101/281] mpeg: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 103/281] mpegtsenc: " James Almer
                   ` (180 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mpegenc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index b1d8bf9c38..3b5aefeb30 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -380,14 +380,14 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx)
                     av_log(ctx, AV_LOG_INFO, "\n");
                     return AVERROR(EINVAL);
                 }
-                if (st->codecpar->channels > 8) {
+                if (st->codecpar->ch_layout.nb_channels > 8) {
                     av_log(ctx, AV_LOG_ERROR, "At most 8 channels allowed for LPCM streams.\n");
                     return AVERROR(EINVAL);
                 }
                 stream->lpcm_header[0] = 0x0c;
-                stream->lpcm_header[1] = (st->codecpar->channels - 1) | (j << 4);
+                stream->lpcm_header[1] = (st->codecpar->ch_layout.nb_channels - 1) | (j << 4);
                 stream->lpcm_header[2] = 0x80;
-                stream->lpcm_align     = st->codecpar->channels * 2;
+                stream->lpcm_align     = st->codecpar->ch_layout.nb_channels * 2;
             } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
                 int freq;
 
@@ -404,10 +404,10 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx)
                 stream->lpcm_header[0] = 0x0c;
                 stream->lpcm_header[1] = (freq << 4) |
                                          (((st->codecpar->bits_per_coded_sample - 16) / 4) << 6) |
-                                         st->codecpar->channels - 1;
+                                         st->codecpar->ch_layout.nb_channels - 1;
                 stream->lpcm_header[2] = 0x80;
                 stream->id = lpcm_id++;
-                stream->lpcm_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample / 8;
+                stream->lpcm_align = st->codecpar->ch_layout.nb_channels * st->codecpar->bits_per_coded_sample / 8;
             } else if (st->codecpar->codec_id == AV_CODEC_ID_MLP ||
                        st->codecpar->codec_id == AV_CODEC_ID_TRUEHD) {
                        av_log(ctx, AV_LOG_ERROR, "Support for muxing audio codec %s not implemented.\n",
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 103/281] mpegtsenc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (101 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 102/281] mpegenc: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 104/281] msf: " James Almer
                   ` (179 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mpegtsenc.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 92b4cc8087..018baf5d1b 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -466,7 +466,7 @@ static int get_m2ts_stream_type(AVFormatContext *s, AVStream *st)
         stream_type = 0x81;
         break;
     case AV_CODEC_ID_DTS:
-        stream_type = (st->codecpar->channels > 6) ? 0x85 : 0x82;
+        stream_type = (st->codecpar->ch_layout.nb_channels > 6) ? 0x85 : 0x82;
         break;
     case AV_CODEC_ID_TRUEHD:
         stream_type = 0x83;
@@ -592,6 +592,8 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
             if (codec_id == AV_CODEC_ID_S302M)
                 put_registration_descriptor(&q, MKTAG('B', 'S', 'S', 'D'));
             if (codec_id == AV_CODEC_ID_OPUS) {
+                int ch = st->codecpar->ch_layout.nb_channels;
+
                 /* 6 bytes registration descriptor, 4 bytes Opus audio descriptor */
                 if (q - data > SECTION_LENGTH - 6 - 4) {
                     err = 1;
@@ -605,11 +607,11 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
                 *q++ = 0x80;
 
                 if (st->codecpar->extradata && st->codecpar->extradata_size >= 19) {
-                    if (st->codecpar->extradata[18] == 0 && st->codecpar->channels <= 2) {
+                    if (st->codecpar->extradata[18] == 0 && ch <= 2) {
                         /* RTP mapping family */
-                        *q++ = st->codecpar->channels;
-                    } else if (st->codecpar->extradata[18] == 1 && st->codecpar->channels <= 8 &&
-                               st->codecpar->extradata_size >= 21 + st->codecpar->channels) {
+                        *q++ = ch;
+                    } else if (st->codecpar->extradata[18] == 1 && ch <= 8 &&
+                               st->codecpar->extradata_size >= 21 + ch) {
                         static const uint8_t coupled_stream_counts[9] = {
                             1, 0, 1, 1, 2, 2, 2, 3, 3
                         };
@@ -635,14 +637,14 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
                         };
                         /* Vorbis mapping family */
 
-                        if (st->codecpar->extradata[19] == st->codecpar->channels - coupled_stream_counts[st->codecpar->channels] &&
-                            st->codecpar->extradata[20] == coupled_stream_counts[st->codecpar->channels] &&
-                            memcmp(&st->codecpar->extradata[21], channel_map_a[st->codecpar->channels-1], st->codecpar->channels) == 0) {
-                            *q++ = st->codecpar->channels;
-                        } else if (st->codecpar->channels >= 2 && st->codecpar->extradata[19] == st->codecpar->channels &&
+                        if (st->codecpar->extradata[19] == ch - coupled_stream_counts[ch] &&
+                            st->codecpar->extradata[20] == coupled_stream_counts[ch] &&
+                            memcmp(&st->codecpar->extradata[21], channel_map_a[ch - 1], ch) == 0) {
+                            *q++ = ch;
+                        } else if (ch >= 2 && st->codecpar->extradata[19] == ch &&
                                    st->codecpar->extradata[20] == 0 &&
-                                   memcmp(&st->codecpar->extradata[21], channel_map_b[st->codecpar->channels-1], st->codecpar->channels) == 0) {
-                            *q++ = st->codecpar->channels | 0x80;
+                                   memcmp(&st->codecpar->extradata[21], channel_map_b[ch - 1], ch) == 0) {
+                            *q++ = ch | 0x80;
                         } else {
                             /* Unsupported, could write an extended descriptor here */
                             av_log(s, AV_LOG_ERROR, "Unsupported Opus Vorbis-style channel mapping");
@@ -653,9 +655,9 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
                         av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping for family %d", st->codecpar->extradata[18]);
                         *q++ = 0xff;
                     }
-                } else if (st->codecpar->channels <= 2) {
+                } else if (ch <= 2) {
                     /* Assume RTP mapping family */
-                    *q++ = st->codecpar->channels;
+                    *q++ = ch;
                 } else {
                     /* Unsupported */
                     av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping");
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 104/281] msf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (102 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 103/281] mpegtsenc: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 105/281] mtaf: " James Almer
                   ` (178 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/msf.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavformat/msf.c b/libavformat/msf.c
index 98a7ca11c3..ab3812b0fc 100644
--- a/libavformat/msf.c
+++ b/libavformat/msf.c
@@ -54,8 +54,10 @@ static int msf_read_header(AVFormatContext *s)
 
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
     codec                  = avio_rb32(s->pb);
-    st->codecpar->channels    = avio_rb32(s->pb);
-    if (st->codecpar->channels <= 0 || st->codecpar->channels >= INT_MAX / 1024)
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_rb32(s->pb);
+    if (st->codecpar->ch_layout.nb_channels <= 0 ||
+        st->codecpar->ch_layout.nb_channels >= INT_MAX / 1024)
         return AVERROR_INVALIDDATA;
     size = avio_rb32(s->pb);
     st->codecpar->sample_rate = avio_rb32(s->pb);
@@ -65,19 +67,19 @@ static int msf_read_header(AVFormatContext *s)
     switch (codec) {
     case 0: st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; break;
     case 1: st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; break;
-    case 3: st->codecpar->block_align = 16 * st->codecpar->channels;
+    case 3: st->codecpar->block_align = 16 * st->codecpar->ch_layout.nb_channels;
             st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX; break;
     case 4:
     case 5:
-    case 6: st->codecpar->block_align = (codec == 4 ? 96 : codec == 5 ? 152 : 192) * st->codecpar->channels;
-            if (st->codecpar->channels > UINT16_MAX / 2048)
+    case 6: st->codecpar->block_align = (codec == 4 ? 96 : codec == 5 ? 152 : 192) * st->codecpar->ch_layout.nb_channels;
+            if (st->codecpar->ch_layout.nb_channels > UINT16_MAX / 2048)
                 return AVERROR_INVALIDDATA;
             ret = ff_alloc_extradata(st->codecpar, 14);
             if (ret < 0)
                 return ret;
             memset(st->codecpar->extradata, 0, st->codecpar->extradata_size);
             AV_WL16(st->codecpar->extradata, 1); /* version */
-            AV_WL16(st->codecpar->extradata+2, 2048 * st->codecpar->channels); /* unknown size */
+            AV_WL16(st->codecpar->extradata+2, 2048 * st->codecpar->ch_layout.nb_channels); /* unknown size */
             AV_WL16(st->codecpar->extradata+6, codec == 4 ? 1 : 0); /* joint stereo */
             AV_WL16(st->codecpar->extradata+8, codec == 4 ? 1 : 0); /* joint stereo (repeat?) */
             AV_WL16(st->codecpar->extradata+10, 1);
@@ -99,7 +101,7 @@ static int msf_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     AVCodecParameters *par = s->streams[0]->codecpar;
 
-    return av_get_packet(s->pb, pkt, par->block_align ? par->block_align : 1024 * par->channels);
+    return av_get_packet(s->pb, pkt, par->block_align ? par->block_align : 1024 * par->ch_layout.nb_channels);
 }
 
 const AVInputFormat ff_msf_demuxer = {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 105/281] mtaf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (103 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 104/281] msf: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 106/281] musx: " James Almer
                   ` (177 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mtaf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/mtaf.c b/libavformat/mtaf.c
index 5da82e713b..fcca684866 100644
--- a/libavformat/mtaf.c
+++ b/libavformat/mtaf.c
@@ -54,9 +54,10 @@ static int mtaf_read_header(AVFormatContext *s)
 
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_MTAF;
-    st->codecpar->channels    = 2 * stream_count;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = 2 * stream_count;
     st->codecpar->sample_rate = 48000;
-    st->codecpar->block_align = 0x110 * st->codecpar->channels / 2;
+    st->codecpar->block_align = 0x110 * st->codecpar->ch_layout.nb_channels / 2;
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
     avio_seek(s->pb, 0x800, SEEK_SET);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 106/281] musx: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (104 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 105/281] mtaf: " James Almer
@ 2022-01-13  1:55 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 107/281] mvdec: " James Almer
                   ` (176 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:55 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/musx.c | 49 ++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/libavformat/musx.c b/libavformat/musx.c
index fd5a9297f9..edb65ccf86 100644
--- a/libavformat/musx.c
+++ b/libavformat/musx.c
@@ -68,30 +68,32 @@ static int musx_read_header(AVFormatContext *s)
         offset = avio_rl32(s->pb);
         st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_PSX;
-        st->codecpar->channels    = 2;
+        st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = 2;
         st->codecpar->sample_rate = 32000;
-        st->codecpar->block_align = 0x80 * st->codecpar->channels;
+        st->codecpar->block_align = 0x80 * st->codecpar->ch_layout.nb_channels;
     }  else if (version == 10) {
         type = avio_rl32(s->pb);
         st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
         offset = 0x800;
         switch (type) {
         case MKTAG('P', 'S', '3', '_'):
-            st->codecpar->channels    = 2;
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = 2;
             st->codecpar->sample_rate = 44100;
             avio_skip(s->pb, 44);
             coding = avio_rl32(s->pb);
             if (coding == MKTAG('D', 'A', 'T', '4') ||
                 coding == MKTAG('D', 'A', 'T', '8')) {
                 avio_skip(s->pb, 4);
-                st->codecpar->channels   = avio_rl32(s->pb);
-                if (st->codecpar->channels <= 0 ||
-                    st->codecpar->channels > INT_MAX / 0x20)
+                st->codecpar->ch_layout.nb_channels   = avio_rl32(s->pb);
+                if (st->codecpar->ch_layout.nb_channels <= 0 ||
+                    st->codecpar->ch_layout.nb_channels > INT_MAX / 0x20)
                     return AVERROR_INVALIDDATA;
                 st->codecpar->sample_rate = avio_rl32(s->pb);
             }
             st->codecpar->codec_id   = AV_CODEC_ID_ADPCM_IMA_DAT4;
-            st->codecpar->block_align = 0x20 * st->codecpar->channels;
+            st->codecpar->block_align = 0x20 * st->codecpar->ch_layout.nb_channels;
             break;
         case MKTAG('W', 'I', 'I', '_'):
             avio_skip(s->pb, 44);
@@ -103,30 +105,34 @@ static int musx_read_header(AVFormatContext *s)
             }
             avio_skip(s->pb, 4);
             st->codecpar->codec_id   = AV_CODEC_ID_ADPCM_IMA_DAT4;
-            st->codecpar->channels   = avio_rl32(s->pb);
-            if (st->codecpar->channels <= 0 ||
-                st->codecpar->channels > INT_MAX / 0x20)
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = avio_rl32(s->pb);
+            if (st->codecpar->ch_layout.nb_channels <= 0 ||
+                st->codecpar->ch_layout.nb_channels > INT_MAX / 0x20)
                 return AVERROR_INVALIDDATA;
             st->codecpar->sample_rate = avio_rl32(s->pb);
-            st->codecpar->block_align = 0x20 * st->codecpar->channels;
+            st->codecpar->block_align = 0x20 * st->codecpar->ch_layout.nb_channels;
             break;
         case MKTAG('X', 'E', '_', '_'):
             st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_IMA_DAT4;
-            st->codecpar->channels    = 2;
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = 2;
             st->codecpar->sample_rate = 32000;
-            st->codecpar->block_align = 0x20 * st->codecpar->channels;
+            st->codecpar->block_align = 0x20 * st->codecpar->ch_layout.nb_channels;
             break;
         case MKTAG('P', 'S', 'P', '_'):
             st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_PSX;
-            st->codecpar->channels    = 2;
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = 2;
             st->codecpar->sample_rate = 32768;
-            st->codecpar->block_align = 0x80 * st->codecpar->channels;
+            st->codecpar->block_align = 0x80 * st->codecpar->ch_layout.nb_channels;
             break;
         case MKTAG('P', 'S', '2', '_'):
             st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_PSX;
-            st->codecpar->channels    = 2;
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = 2;
             st->codecpar->sample_rate = 32000;
-            st->codecpar->block_align = 0x80 * st->codecpar->channels;
+            st->codecpar->block_align = 0x80 * st->codecpar->ch_layout.nb_channels;
             break;
         default:
             avpriv_request_sample(s, "Unsupported type: %X", type);
@@ -136,23 +142,24 @@ static int musx_read_header(AVFormatContext *s)
         type = avio_rl32(s->pb);
         avio_skip(s->pb, 20);
         st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-        st->codecpar->channels    = 2;
+        st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = 2;
         switch (type) {
         case MKTAG('G', 'C', '_', '_'):
             st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_IMA_DAT4;
-            st->codecpar->block_align = 0x20 * st->codecpar->channels;
+            st->codecpar->block_align = 0x20 * st->codecpar->ch_layout.nb_channels;
             st->codecpar->sample_rate = 32000;
             offset = avio_rb32(s->pb);
             break;
         case MKTAG('P', 'S', '2', '_'):
             st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_PSX;
-            st->codecpar->block_align = 0x80 * st->codecpar->channels;
+            st->codecpar->block_align = 0x80 * st->codecpar->ch_layout.nb_channels;
             st->codecpar->sample_rate = 32000;
             offset = avio_rl32(s->pb);
             break;
         case MKTAG('X', 'B', '_', '_'):
             st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_IMA_DAT4;
-            st->codecpar->block_align = 0x20 * st->codecpar->channels;
+            st->codecpar->block_align = 0x20 * st->codecpar->ch_layout.nb_channels;
             st->codecpar->sample_rate = 44100;
             offset = avio_rl32(s->pb);
             break;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 107/281] mvdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (105 preceding siblings ...)
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 106/281] musx: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 108/281] mvi: " James Almer
                   ` (175 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mvdec.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c
index 4f233aff5f..b37fe2ce69 100644
--- a/libavformat/mvdec.c
+++ b/libavformat/mvdec.c
@@ -111,9 +111,7 @@ static int set_channels(AVFormatContext *avctx, AVStream *st, int channels)
         av_log(avctx, AV_LOG_ERROR, "Channel count %d invalid.\n", channels);
         return AVERROR_INVALIDDATA;
     }
-    st->codecpar->channels       = channels;
-    st->codecpar->channel_layout = (st->codecpar->channels == 1) ? AV_CH_LAYOUT_MONO
-                                                                 : AV_CH_LAYOUT_STEREO;
+    av_channel_layout_default(&st->codecpar->ch_layout, channels);
     return 0;
 }
 
@@ -283,7 +281,7 @@ static void read_index(AVIOContext *pb, AVStream *st)
             return ;
         av_add_index_entry(st, pos, timestamp, size, 0, AVINDEX_KEYFRAME);
         if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
-            timestamp += size / (st->codecpar->channels * 2LL);
+            timestamp += size / (st->codecpar->ch_layout.nb_channels * 2LL);
         } else {
             timestamp++;
         }
@@ -402,7 +400,7 @@ static int mv_read_header(AVFormatContext *avctx)
             avio_skip(pb, 8);
             if (ast) {
                 av_add_index_entry(ast, pos, timestamp, asize, 0, AVINDEX_KEYFRAME);
-                timestamp += asize / (ast->codecpar->channels * (uint64_t)bytes_per_sample);
+                timestamp += asize / (ast->codecpar->ch_layout.nb_channels * (uint64_t)bytes_per_sample);
             }
             av_add_index_entry(vst, pos + asize, i, vsize, 0, AVINDEX_KEYFRAME);
         }
@@ -439,7 +437,7 @@ static int mv_read_header(AVFormatContext *avctx)
                                       ast->codecpar->bits_per_coded_sample);
                 ast->codecpar->codec_id = AV_CODEC_ID_NONE;
             }
-            if (ast->codecpar->channels <= 0) {
+            if (ast->codecpar->ch_layout.nb_channels <= 0) {
                 av_log(avctx, AV_LOG_ERROR, "No valid channel count found.\n");
                 return AVERROR_INVALIDDATA;
             }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 108/281] mvi: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (106 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 107/281] mvdec: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 109/281] mxf: " James Almer
                   ` (174 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mvi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/mvi.c b/libavformat/mvi.c
index 4c67e3569d..b2d6a92a4b 100644
--- a/libavformat/mvi.c
+++ b/libavformat/mvi.c
@@ -84,8 +84,7 @@ static int read_header(AVFormatContext *s)
     avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate);
     ast->codecpar->codec_type      = AVMEDIA_TYPE_AUDIO;
     ast->codecpar->codec_id        = AV_CODEC_ID_PCM_U8;
-    ast->codecpar->channels        = 1;
-    ast->codecpar->channel_layout  = AV_CH_LAYOUT_MONO;
+    ast->codecpar->ch_layout       = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     ast->codecpar->bits_per_coded_sample = 8;
     ast->codecpar->bit_rate        = ast->codecpar->sample_rate * 8;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 109/281] mxf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (107 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 108/281] mvi: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-19 19:06   ` Tomas Härdin
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 110/281] mxg: " James Almer
                   ` (173 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mxfdec.c | 34 +++++++++++++++++++++-------------
 libavformat/mxfenc.c | 20 +++++++++++---------
 2 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index b85c10bf19..2db32255ab 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -591,18 +591,19 @@ static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket *pkt,
     end_ptr = pkt->data + length;
     buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */
 
-    if (st->codecpar->channels > 8)
+    if (st->codecpar->ch_layout.nb_channels > 8)
         return AVERROR_INVALIDDATA;
 
-    for (; end_ptr - buf_ptr >= st->codecpar->channels * 4; ) {
-        for (i = 0; i < st->codecpar->channels; i++) {
+    for (; end_ptr - buf_ptr >= st->codecpar->ch_layout.nb_channels * 4; ) {
+        for (i = 0; i < st->codecpar->ch_layout.nb_channels; i++) {
             uint32_t sample = bytestream_get_le32(&buf_ptr);
             if (st->codecpar->bits_per_coded_sample == 24)
                 bytestream_put_le24(&data_ptr, (sample >> 4) & 0xffffff);
             else
                 bytestream_put_le16(&data_ptr, (sample >> 12) & 0xffff);
         }
-        buf_ptr += 32 - st->codecpar->channels*4; // always 8 channels stored SMPTE 331M
+        // always 8 channels stored SMPTE 331M
+        buf_ptr += 32 - st->codecpar->ch_layout.nb_channels * 4;
     }
     av_shrink_packet(pkt, data_ptr - pkt->data);
     return 0;
@@ -2536,6 +2537,7 @@ static int parse_mca_labels(MXFContext *mxf, MXFTrack *source_track, MXFDescript
 
     if (has_channel_label) {
         uint64_t channel_layout = 0;
+        int ret;
 
         for (int i = 0; i < descriptor->channels; i++) {
             if (!routing[i]) {
@@ -2544,9 +2546,11 @@ static int parse_mca_labels(MXFContext *mxf, MXFTrack *source_track, MXFDescript
                 return 0;
             }
             if (channel_layout & routing[i]) {
+                char buf[32];
+                av_channel_name(buf, sizeof(buf), routing[i]);
                 av_log(mxf->fc, AV_LOG_WARNING, "%s audio channel is used multiple times in stream #%d, "
                                                 "falling back to unknown channel layout\n",
-                                                av_get_channel_name(routing[i]), st->index);
+                                                buf, st->index);
                 return 0;
             }
             if (routing[i] < channel_layout) {
@@ -2557,9 +2561,11 @@ static int parse_mca_labels(MXFContext *mxf, MXFTrack *source_track, MXFDescript
             channel_layout |= routing[i];
         }
 
-        av_assert0(descriptor->channels == av_get_channel_layout_nb_channels(channel_layout));
+        av_assert0(descriptor->channels == av_popcount64(channel_layout));
 
-        st->codecpar->channel_layout = channel_layout;
+        ret = av_channel_layout_from_mask(&st->codecpar->ch_layout, channel_layout);
+        if (ret < 0)
+            return ret;
     }
 
     return 0;
@@ -2927,7 +2933,8 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
             /* Only overwrite existing codec ID if it is unset or A-law, which is the default according to SMPTE RP 224. */
             if (st->codecpar->codec_id == AV_CODEC_ID_NONE || (st->codecpar->codec_id == AV_CODEC_ID_PCM_ALAW && (enum AVCodecID)container_ul->id != AV_CODEC_ID_NONE))
                 st->codecpar->codec_id = (enum AVCodecID)container_ul->id;
-            st->codecpar->channels = descriptor->channels;
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = descriptor->channels;
 
             if (descriptor->sample_rate.den > 0) {
                 st->codecpar->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den;
@@ -3553,7 +3560,8 @@ static int mxf_handle_missing_index_segment(MXFContext *mxf, AVStream *st)
         return 0;
 
     if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && is_pcm(st->codecpar->codec_id)) {
-        edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3;
+        edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) *
+                                st->codecpar->ch_layout.nb_channels) >> 3;
     } else if (st->duration > 0 && p->first_essence_klv.length > 0 && p->first_essence_klv.length % st->duration == 0) {
         edit_unit_byte_count = p->first_essence_klv.length / st->duration;
     }
@@ -3858,12 +3866,12 @@ static int mxf_set_audio_pts(MXFContext *mxf, AVCodecParameters *par,
 
     pkt->pts = track->sample_count;
 
-    if (   par->channels <= 0
-        || bits_per_sample <= 0
-        || par->channels * (int64_t)bits_per_sample < 8)
+    if (par->ch_layout.nb_channels <= 0 ||
+        bits_per_sample <= 0            ||
+        par->ch_layout.nb_channels * (int64_t)bits_per_sample < 8)
         track->sample_count = mxf_compute_sample_count(mxf, st, av_rescale_q(track->sample_count, st->time_base, av_inv_q(track->edit_rate)) + 1);
     else
-        track->sample_count += pkt->size / (par->channels * (int64_t)bits_per_sample / 8);
+        track->sample_count += pkt->size / (par->ch_layout.nb_channels * (int64_t)bits_per_sample / 8);
 
     return 0;
 }
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 5e068c8220..5fa234c5c0 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -1455,17 +1455,19 @@ static int64_t mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st,
 
     mxf_write_local_tag(s, 4, 0x3D07);
     if (mxf->channel_count == -1) {
-        if (show_warnings && (s->oformat == &ff_mxf_d10_muxer) && (st->codecpar->channels != 4) && (st->codecpar->channels != 8))
+        if (show_warnings && (s->oformat == &ff_mxf_d10_muxer) &&
+            (st->codecpar->ch_layout.nb_channels != 4) &&
+            (st->codecpar->ch_layout.nb_channels != 8))
             av_log(s, AV_LOG_WARNING, "the number of audio channels shall be 4 or 8 : the output will not comply to MXF D-10 specs, use -d10_channelcount to fix this\n");
-        avio_wb32(pb, st->codecpar->channels);
+        avio_wb32(pb, st->codecpar->ch_layout.nb_channels);
     } else if (s->oformat == &ff_mxf_d10_muxer) {
-        if (show_warnings && (mxf->channel_count < st->codecpar->channels))
+        if (show_warnings && (mxf->channel_count < st->codecpar->ch_layout.nb_channels))
             av_log(s, AV_LOG_WARNING, "d10_channelcount < actual number of audio channels : some channels will be discarded\n");
         if (show_warnings && (mxf->channel_count != 4) && (mxf->channel_count != 8))
             av_log(s, AV_LOG_WARNING, "d10_channelcount shall be set to 4 or 8 : the output will not comply to MXF D-10 specs\n");
         avio_wb32(pb, mxf->channel_count);
     } else {
-        avio_wb32(pb, st->codecpar->channels);
+        avio_wb32(pb, st->codecpar->ch_layout.nb_channels);
     }
 
     mxf_write_local_tag(s, 4, 0x3D01);
@@ -2624,7 +2626,7 @@ static int mxf_init(AVFormatContext *s)
                     av_log(s, AV_LOG_ERROR, "Only pcm_s16le and pcm_s24le audio codecs are implemented\n");
                     return AVERROR_PATCHWELCOME;
                 }
-                if (st->codecpar->channels != 1) {
+                if (st->codecpar->ch_layout.nb_channels != 1) {
                     av_log(s, AV_LOG_ERROR, "MXF OPAtom only supports single channel audio\n");
                     return AVERROR(EINVAL);
                 }
@@ -2633,11 +2635,11 @@ static int mxf_init(AVFormatContext *s)
                 if((ret = mxf_init_timecode(s, st, tbc)) < 0)
                     return ret;
 
-                mxf->edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3;
+                mxf->edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->ch_layout.nb_channels) >> 3;
                 sc->index = INDEX_WAV;
             } else {
                 mxf->slice_count = 1;
-                sc->frame_size = st->codecpar->channels *
+                sc->frame_size = st->codecpar->ch_layout.nb_channels *
                                  av_rescale_rnd(st->codecpar->sample_rate, mxf->time_base.num, mxf->time_base.den, AV_ROUND_UP) *
                                  av_get_bits_per_sample(st->codecpar->codec_id) / 8;
             }
@@ -2783,10 +2785,10 @@ static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacke
 
     avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1));
     avio_wl16(pb, frame_size);
-    avio_w8(pb, (1<<st->codecpar->channels)-1);
+    avio_w8(pb, (1 << st->codecpar->ch_layout.nb_channels)-1);
 
     while (samples < end) {
-        for (i = 0; i < st->codecpar->channels; i++) {
+        for (i = 0; i < st->codecpar->ch_layout.nb_channels; i++) {
             uint32_t sample;
             if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE) {
                 sample = AV_RL24(samples)<< 4;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 110/281] mxg: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (108 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 109/281] mxf: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 111/281] nistspheredec: " James Almer
                   ` (172 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mxg.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/mxg.c b/libavformat/mxg.c
index d5c1d666fc..b160ccb9f9 100644
--- a/libavformat/mxg.c
+++ b/libavformat/mxg.c
@@ -57,8 +57,7 @@ static int mxg_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
     audio_st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     audio_st->codecpar->codec_id = AV_CODEC_ID_PCM_ALAW;
-    audio_st->codecpar->channels = 1;
-    audio_st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    audio_st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     audio_st->codecpar->sample_rate = 8000;
     audio_st->codecpar->bits_per_coded_sample = 8;
     audio_st->codecpar->block_align = 1;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 111/281] nistspheredec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (109 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 110/281] mxg: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 112/281] nspdec: " James Almer
                   ` (171 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/nistspheredec.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavformat/nistspheredec.c b/libavformat/nistspheredec.c
index b606ce72aa..43b7d9bc47 100644
--- a/libavformat/nistspheredec.c
+++ b/libavformat/nistspheredec.c
@@ -80,7 +80,8 @@ static int nist_read_header(AVFormatContext *s)
 
             avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
-            st->codecpar->block_align = st->codecpar->bits_per_coded_sample * st->codecpar->channels / 8;
+            st->codecpar->block_align = st->codecpar->bits_per_coded_sample *
+                                        st->codecpar->ch_layout.nb_channels / 8;
 
             if (avio_tell(s->pb) > header_size)
                 return AVERROR_INVALIDDATA;
@@ -89,8 +90,9 @@ static int nist_read_header(AVFormatContext *s)
 
             return 0;
         } else if (!memcmp(buffer, "channel_count", 13)) {
-            sscanf(buffer, "%*s %*s %u", &st->codecpar->channels);
-            if (st->codecpar->channels <= 0 || st->codecpar->channels > INT16_MAX)
+            st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+            sscanf(buffer, "%*s %*s %u", &st->codecpar->ch_layout.nb_channels);
+            if (st->codecpar->ch_layout.nb_channels <= 0 || st->codecpar->ch_layout.nb_channels > INT16_MAX)
                 return AVERROR_INVALIDDATA;
         } else if (!memcmp(buffer, "sample_byte_format", 18)) {
             sscanf(buffer, "%*s %*s %31s", format);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 112/281] nspdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (110 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 111/281] nistspheredec: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 113/281] nsvdec: " James Almer
                   ` (170 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/nspdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/nspdec.c b/libavformat/nspdec.c
index 3aaf887746..8d221efea9 100644
--- a/libavformat/nspdec.c
+++ b/libavformat/nspdec.c
@@ -88,7 +88,8 @@ static int nsp_read_header(AVFormatContext *s)
     }
 
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels    = channels;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = channels;
     st->codecpar->sample_rate = rate;
     st->codecpar->codec_id    = AV_CODEC_ID_PCM_S16LE;
     st->codecpar->block_align = 2 * channels;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 113/281] nsvdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (111 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 112/281] nspdec: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 114/281] nutdec: " James Almer
                   ` (169 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/nsvdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c
index 27471125ff..852e6194b0 100644
--- a/libavformat/nsvdec.c
+++ b/libavformat/nsvdec.c
@@ -618,7 +618,7 @@ null_chunk_retry:
                     st[NSV_ST_AUDIO]->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
                 samplerate /= 4;/* UGH ??? XXX */
                 channels = 1;
-                st[NSV_ST_AUDIO]->codecpar->channels = channels;
+                st[NSV_ST_AUDIO]->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
                 st[NSV_ST_AUDIO]->codecpar->sample_rate = samplerate;
                 av_log(s, AV_LOG_TRACE, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate);
             }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 114/281] nutdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (112 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 113/281] nsvdec: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 115/281] nuv: " James Almer
                   ` (168 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/nutdec.c | 5 ++++-
 libavformat/nutenc.c | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 0a8a700acf..8beec503e2 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -453,7 +453,8 @@ static int decode_stream_header(NUTContext *nut)
     } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
         GET_V(st->codecpar->sample_rate, tmp > 0);
         ffio_read_varlen(bc); // samplerate_den
-        GET_V(st->codecpar->channels, tmp > 0);
+        GET_V(st->codecpar->ch_layout.nb_channels, tmp > 0);
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
     }
     if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
         av_log(s, AV_LOG_ERROR,
@@ -953,8 +954,10 @@ static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int
         if (!dst)
             return AVERROR(ENOMEM);
         bytestream_put_le32(&dst,
+#if FF_API_OLD_CHANNEL_LAYOUT
                             AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT*(!!channels) +
                             AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT*(!!channel_layout) +
+#endif
                             AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE*(!!sample_rate) +
                             AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS*(!!(width|height))
                            );
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 9d5eb4ed99..f88b424429 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -461,7 +461,7 @@ static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc,
     case AVMEDIA_TYPE_AUDIO:
         put_v(bc, par->sample_rate);
         put_v(bc, 1);
-        put_v(bc, par->channels);
+        put_v(bc, par->ch_layout.nb_channels);
         break;
     case AVMEDIA_TYPE_VIDEO:
         put_v(bc, par->width);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 115/281] nuv: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (113 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 114/281] nutdec: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 116/281] ogg: " James Almer
                   ` (167 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/nuv.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libavformat/nuv.c b/libavformat/nuv.c
index 5f5cc50302..2cb1df368f 100644
--- a/libavformat/nuv.c
+++ b/libavformat/nuv.c
@@ -116,10 +116,10 @@ static int get_codec_data(AVFormatContext *s, AVIOContext *pb, AVStream *vst,
                     return AVERROR_INVALIDDATA;
                 }
                 ast->codecpar->bits_per_coded_sample = avio_rl32(pb);
-                ast->codecpar->channels              = avio_rl32(pb);
-                ast->codecpar->channel_layout        = 0;
-                if (ast->codecpar->channels <= 0) {
-                    av_log(s, AV_LOG_ERROR, "Invalid channels %d\n", ast->codecpar->channels);
+                ast->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+                ast->codecpar->ch_layout.nb_channels = avio_rl32(pb);
+                if (ast->codecpar->ch_layout.nb_channels <= 0) {
+                    av_log(s, AV_LOG_ERROR, "Invalid channels %d\n", ast->codecpar->ch_layout.nb_channels);
                     return AVERROR_INVALIDDATA;
                 }
 
@@ -227,8 +227,7 @@ static int nuv_header(AVFormatContext *s)
 
         ast->codecpar->codec_type            = AVMEDIA_TYPE_AUDIO;
         ast->codecpar->codec_id              = AV_CODEC_ID_PCM_S16LE;
-        ast->codecpar->channels              = 2;
-        ast->codecpar->channel_layout        = AV_CH_LAYOUT_STEREO;
+        ast->codecpar->ch_layout             = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
         ast->codecpar->sample_rate           = 44100;
         ast->codecpar->bit_rate              = 2 * 2 * 44100 * 8;
         ast->codecpar->block_align           = 2 * 2;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 116/281] ogg: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (114 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 115/281] nuv: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 117/281] oma: " James Almer
                   ` (166 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/oggparsecelt.c   | 3 ++-
 libavformat/oggparseogm.c    | 6 ++++--
 libavformat/oggparseopus.c   | 3 ++-
 libavformat/oggparsespeex.c  | 8 ++++----
 libavformat/oggparsevorbis.c | 6 ++++--
 5 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/libavformat/oggparsecelt.c b/libavformat/oggparsecelt.c
index f7a88af616..af15c07443 100644
--- a/libavformat/oggparsecelt.c
+++ b/libavformat/oggparsecelt.c
@@ -64,7 +64,8 @@ static int celt_header(AVFormatContext *s, int idx)
         st->codecpar->codec_type     = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id       = AV_CODEC_ID_CELT;
         st->codecpar->sample_rate    = sample_rate;
-        st->codecpar->channels       = nb_channels;
+        st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = nb_channels;
         if (sample_rate)
             avpriv_set_pts_info(st, 64, 1, sample_rate);
 
diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c
index f777790523..c30e0324ae 100644
--- a/libavformat/oggparseogm.c
+++ b/libavformat/oggparseogm.c
@@ -97,7 +97,8 @@ ogm_header(AVFormatContext *s, int idx)
             st->codecpar->height = bytestream2_get_le32(&p);
             avpriv_set_pts_info(st, 64, time_unit, spu * 10000000);
         } else {
-            st->codecpar->channels = bytestream2_get_le16(&p);
+            st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = bytestream2_get_le16(&p);
             bytestream2_skip(&p, 2); /* block_align */
             st->codecpar->bit_rate = bytestream2_get_le32(&p) * 8;
             st->codecpar->sample_rate = spu * 10000000 / time_unit;
@@ -160,7 +161,8 @@ ogm_dshow_header(AVFormatContext *s, int idx)
 
         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id = ff_codec_get_id(ff_codec_wav_tags, AV_RL16(p + 124));
-        st->codecpar->channels = AV_RL16(p + 126);
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = AV_RL16(p + 126);
         st->codecpar->sample_rate = AV_RL32(p + 128);
         st->codecpar->bit_rate = AV_RL32(p + 132) * 8;
     }
diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c
index 36d691e9aa..adeda95fdb 100644
--- a/libavformat/oggparseopus.c
+++ b/libavformat/oggparseopus.c
@@ -55,7 +55,8 @@ static int opus_header(AVFormatContext *avf, int idx)
             return AVERROR_INVALIDDATA;
         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id   = AV_CODEC_ID_OPUS;
-        st->codecpar->channels   = AV_RL8(packet + 9);
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = AV_RL8(packet + 9);
 
         priv->pre_skip        = AV_RL16(packet + 10);
         st->codecpar->initial_padding = priv->pre_skip;
diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c
index c4fee7e076..7d3d653384 100644
--- a/libavformat/oggparsespeex.c
+++ b/libavformat/oggparsespeex.c
@@ -60,6 +60,7 @@ static int speex_header(AVFormatContext *s, int idx) {
 
     if (spxp->seq == 0) {
         int frames_per_packet;
+        int channels;
         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id = AV_CODEC_ID_SPEEX;
 
@@ -73,13 +74,12 @@ static int speex_header(AVFormatContext *s, int idx) {
             av_log(s, AV_LOG_ERROR, "Invalid sample rate %d\n", st->codecpar->sample_rate);
             return AVERROR_INVALIDDATA;
         }
-        st->codecpar->channels = AV_RL32(p + 48);
-        if (st->codecpar->channels < 1 || st->codecpar->channels > 2) {
+        channels = AV_RL32(p + 48);
+        if (channels < 1 || channels > 2) {
             av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\n");
             return AVERROR_INVALIDDATA;
         }
-        st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO :
-                                                                     AV_CH_LAYOUT_STEREO;
+        av_channel_layout_default(&st->codecpar->ch_layout, channels);
 
         spxp->packet_size  = AV_RL32(p + 56);
         frames_per_packet  = AV_RL32(p + 64);
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index e1ef510892..7e94054f19 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -336,11 +336,13 @@ static int vorbis_header(AVFormatContext *s, int idx)
             return AVERROR_INVALIDDATA;
 
         channels = bytestream_get_byte(&p);
-        if (st->codecpar->channels && channels != st->codecpar->channels) {
+        if (st->codecpar->ch_layout.nb_channels &&
+            channels != st->codecpar->ch_layout.nb_channels) {
             av_log(s, AV_LOG_ERROR, "Channel change is not supported\n");
             return AVERROR_PATCHWELCOME;
         }
-        st->codecpar->channels = channels;
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = channels;
         srate               = bytestream_get_le32(&p);
         p += 4; // skip maximum bitrate
         st->codecpar->bit_rate = bytestream_get_le32(&p); // nominal bitrate
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 117/281] oma: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (115 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 116/281] ogg: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 118/281] oss: port " James Almer
                   ` (165 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/oma.h    |  2 ++
 libavformat/omadec.c | 35 ++++++++++++++---------------------
 libavformat/omaenc.c |  4 ++--
 3 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/libavformat/oma.h b/libavformat/oma.h
index 85d5932f1d..1a8e16f6d6 100644
--- a/libavformat/oma.h
+++ b/libavformat/oma.h
@@ -23,6 +23,8 @@
 
 #include <stdint.h>
 
+#include "libavutil/channel_layout.h"
+
 #include "internal.h"
 
 #define EA3_HEADER_SIZE 96
diff --git a/libavformat/omadec.c b/libavformat/omadec.c
index 4c418a5ff2..066b2d85bd 100644
--- a/libavformat/omadec.c
+++ b/libavformat/omadec.c
@@ -60,19 +60,16 @@ static const uint64_t leaf_table[] = {
 };
 
 /** map ATRAC-X channel id to internal channel layout */
-static const uint64_t oma_chid_to_native_layout[7] = {
-    AV_CH_LAYOUT_MONO,
-    AV_CH_LAYOUT_STEREO,
-    AV_CH_LAYOUT_SURROUND,
-    AV_CH_LAYOUT_4POINT0,
-    AV_CH_LAYOUT_5POINT1_BACK,
-    AV_CH_LAYOUT_6POINT1_BACK,
-    AV_CH_LAYOUT_7POINT1
+static const AVChannelLayout  oma_chid_to_native_layout[7] = {
+    AV_CHANNEL_LAYOUT_MONO,
+    AV_CHANNEL_LAYOUT_STEREO,
+    AV_CHANNEL_LAYOUT_SURROUND,
+    AV_CHANNEL_LAYOUT_4POINT0,
+    AV_CHANNEL_LAYOUT_5POINT1_BACK,
+    AV_CHANNEL_LAYOUT_6POINT1_BACK,
+    AV_CHANNEL_LAYOUT_7POINT1
 };
 
-/** map ATRAC-X channel id to total number of channels */
-static const int oma_chid_to_num_channels[7] = { 1, 2, 3, 4, 6, 7, 8 };
-
 typedef struct OMAContext {
     uint64_t content_start;
     int encrypted;
@@ -474,8 +471,7 @@ static int oma_read_header(AVFormatContext *s)
         /* get stereo coding mode, 1 for joint-stereo */
         jsflag = (codec_params >> 17) & 1;
 
-        st->codecpar->channels    = 2;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+        st->codecpar->ch_layout   = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
         st->codecpar->sample_rate = samplerate;
         st->codecpar->bit_rate    = st->codecpar->sample_rate * framesize / (1024 / 8);
 
@@ -501,8 +497,8 @@ static int oma_read_header(AVFormatContext *s)
                    "Invalid ATRAC-X channel id: %"PRIu32"\n", channel_id);
             return AVERROR_INVALIDDATA;
         }
-        st->codecpar->channel_layout = oma_chid_to_native_layout[channel_id - 1];
-        st->codecpar->channels       = oma_chid_to_num_channels[channel_id - 1];
+        av_channel_layout_copy(&st->codecpar->ch_layout,
+                               &oma_chid_to_native_layout[channel_id - 1]);
         framesize = ((codec_params & 0x3FF) * 8) + 8;
         samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7] * 100;
         if (!samplerate) {
@@ -519,8 +515,7 @@ static int oma_read_header(AVFormatContext *s)
         break;
     case OMA_CODECID_LPCM:
         /* PCM 44.1 kHz 16 bit stereo big-endian */
-        st->codecpar->channels = 2;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+        st->codecpar->ch_layout   = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
         st->codecpar->sample_rate = 44100;
         framesize = 1024;
         /* bit rate = sample rate x PCM block align (= 4) x 8 */
@@ -530,16 +525,14 @@ static int oma_read_header(AVFormatContext *s)
         avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
         break;
     case OMA_CODECID_ATRAC3AL:
-        st->codecpar->channels    = 2;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
         st->codecpar->sample_rate = 44100;
         avpriv_set_pts_info(st, 64, 1, 44100);
         oc->read_packet = aal_read_packet;
         framesize = 4096;
         break;
     case OMA_CODECID_ATRAC3PAL:
-        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-        st->codecpar->channels       = 2;
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
         st->codecpar->sample_rate = 44100;
         avpriv_set_pts_info(st, 64, 1, 44100);
         oc->read_packet = aal_read_packet;
diff --git a/libavformat/omaenc.c b/libavformat/omaenc.c
index 1c4edcac5c..246f5195fb 100644
--- a/libavformat/omaenc.c
+++ b/libavformat/omaenc.c
@@ -58,7 +58,7 @@ static av_cold int oma_write_header(AVFormatContext *s)
 
     switch (par->codec_tag) {
     case OMA_CODECID_ATRAC3:
-        if (par->channels != 2) {
+        if (par->ch_layout.nb_channels != 2) {
             av_log(s, AV_LOG_ERROR, "ATRAC3 in OMA is only supported with 2 channels\n");
             return AVERROR(EINVAL);
         }
@@ -78,7 +78,7 @@ static av_cold int oma_write_header(AVFormatContext *s)
     case OMA_CODECID_ATRAC3P:
         avio_wb32(s->pb, (OMA_CODECID_ATRAC3P << 24) |
                          (srate_index << 13) |
-                         (par->channels << 10) |
+                         (par->ch_layout.nb_channels << 10) |
                          (par->block_align/8 - 1));
         break;
     default:
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 118/281] oss: port to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (116 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 117/281] oma: " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 119/281] paf: convert " James Almer
                   ` (164 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavdevice/oss_dec.c | 3 ++-
 libavdevice/oss_enc.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavdevice/oss_dec.c b/libavdevice/oss_dec.c
index 4f3772c1f5..d3fc59d0ea 100644
--- a/libavdevice/oss_dec.c
+++ b/libavdevice/oss_dec.c
@@ -59,7 +59,8 @@ static int audio_read_header(AVFormatContext *s1)
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = s->codec_id;
     st->codecpar->sample_rate = s->sample_rate;
-    st->codecpar->channels = s->channels;
+    st->codecpar->ch_layout.nb_channels = s->channels;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
 
     avpriv_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
     return 0;
diff --git a/libavdevice/oss_enc.c b/libavdevice/oss_enc.c
index 3103d2de9a..d6a512a264 100644
--- a/libavdevice/oss_enc.c
+++ b/libavdevice/oss_enc.c
@@ -43,7 +43,7 @@ static int audio_write_header(AVFormatContext *s1)
 
     st = s1->streams[0];
     s->sample_rate = st->codecpar->sample_rate;
-    s->channels = st->codecpar->channels;
+    s->channels = st->codecpar->ch_layout.nb_channels;
     ret = ff_oss_audio_open(s1, 1, s1->url);
     if (ret < 0) {
         return AVERROR(EIO);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 119/281] paf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (117 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 118/281] oss: port " James Almer
@ 2022-01-13  1:56 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 089/281] lvf: " James Almer
                   ` (163 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:56 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/paf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/paf.c b/libavformat/paf.c
index 140e0567e1..d48cf57645 100644
--- a/libavformat/paf.c
+++ b/libavformat/paf.c
@@ -127,8 +127,7 @@ static int read_header(AVFormatContext *s)
     ast->codecpar->codec_type     = AVMEDIA_TYPE_AUDIO;
     ast->codecpar->codec_tag      = 0;
     ast->codecpar->codec_id       = AV_CODEC_ID_PAF_AUDIO;
-    ast->codecpar->channels       = 2;
-    ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+    ast->codecpar->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     ast->codecpar->sample_rate    = 22050;
     avpriv_set_pts_info(ast, 64, 1, 22050);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 089/281] lvf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (118 preceding siblings ...)
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 119/281] paf: convert " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 120/281] pcm: " James Almer
                   ` (162 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/lvfdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/lvfdec.c b/libavformat/lvfdec.c
index cd64fb9aee..d060b3b0aa 100644
--- a/libavformat/lvfdec.c
+++ b/libavformat/lvfdec.c
@@ -79,7 +79,8 @@ static int lvf_read_header(AVFormatContext *s)
 
             st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
             st->codecpar->codec_tag   = avio_rl16(s->pb);
-            st->codecpar->channels    = avio_rl16(s->pb);
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = avio_rl16(s->pb);
             st->codecpar->sample_rate = avio_rl16(s->pb);
             avio_skip(s->pb, 8);
             st->codecpar->bits_per_coded_sample = avio_r8(s->pb);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 120/281] pcm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (119 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 089/281] lvf: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 121/281] pmp: " James Almer
                   ` (161 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/pcm.c    | 2 +-
 libavformat/pcmdec.c | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavformat/pcm.c b/libavformat/pcm.c
index e91117ce5a..9741f73667 100644
--- a/libavformat/pcm.c
+++ b/libavformat/pcm.c
@@ -63,7 +63,7 @@ int ff_pcm_read_seek(AVFormatContext *s,
     st = s->streams[0];
 
     block_align = st->codecpar->block_align ? st->codecpar->block_align :
-        (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3;
+        (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->ch_layout.nb_channels) >> 3;
     byte_rate = st->codecpar->bit_rate ? st->codecpar->bit_rate >> 3 :
         block_align * st->codecpar->sample_rate;
 
diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c
index 63539a47c0..34e60da1df 100644
--- a/libavformat/pcmdec.c
+++ b/libavformat/pcmdec.c
@@ -48,7 +48,8 @@ static int pcm_read_header(AVFormatContext *s)
     par->codec_type  = AVMEDIA_TYPE_AUDIO;
     par->codec_id    = s->iformat->raw_codec_id;
     par->sample_rate = s1->sample_rate;
-    par->channels    = s1->channels;
+    par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    par->ch_layout.nb_channels = s1->channels;
 
     av_opt_get(s->pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type);
     if (mime_type && s->iformat->mime_type) {
@@ -77,7 +78,7 @@ static int pcm_read_header(AVFormatContext *s)
             }
             par->sample_rate = rate;
             if (channels > 0)
-                par->channels = channels;
+                par->ch_layout.nb_channels = channels;
             if (little_endian)
                 par->codec_id = AV_CODEC_ID_PCM_S16LE;
         }
@@ -88,7 +89,7 @@ static int pcm_read_header(AVFormatContext *s)
 
     av_assert0(par->bits_per_coded_sample > 0);
 
-    par->block_align = par->bits_per_coded_sample * par->channels / 8;
+    par->block_align = par->bits_per_coded_sample * par->ch_layout.nb_channels / 8;
 
     avpriv_set_pts_info(st, 64, 1, par->sample_rate);
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 121/281] pmp: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (120 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 120/281] pcm: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 122/281] pp_bnk: " James Almer
                   ` (160 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/pmpdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/pmpdec.c b/libavformat/pmpdec.c
index ce8e89515a..d63c856770 100644
--- a/libavformat/pmpdec.c
+++ b/libavformat/pmpdec.c
@@ -119,7 +119,8 @@ static int pmp_header(AVFormatContext *s)
             return AVERROR(ENOMEM);
         ast->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
         ast->codecpar->codec_id    = audio_codec_id;
-        ast->codecpar->channels    = channels;
+        ast->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        ast->codecpar->ch_layout.nb_channels = channels;
         ast->codecpar->sample_rate = srate;
         avpriv_set_pts_info(ast, 32, 1, srate);
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 122/281] pp_bnk: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (121 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 121/281] pmp: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 123/281] psxstr: " James Almer
                   ` (159 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/pp_bnk.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/libavformat/pp_bnk.c b/libavformat/pp_bnk.c
index b1e1b6115e..c4172e2260 100644
--- a/libavformat/pp_bnk.c
+++ b/libavformat/pp_bnk.c
@@ -205,18 +205,12 @@ static int pp_bnk_read_header(AVFormatContext *s)
         par->codec_id               = AV_CODEC_ID_ADPCM_IMA_CUNNING;
         par->format                 = AV_SAMPLE_FMT_S16P;
 
-        if (ctx->is_music) {
-            par->channel_layout     = AV_CH_LAYOUT_STEREO;
-            par->channels           = 2;
-        } else {
-            par->channel_layout     = AV_CH_LAYOUT_MONO;
-            par->channels           = 1;
-        }
-
+        av_channel_layout_default(&par->ch_layout, ctx->is_music + 1);
         par->sample_rate            = hdr.sample_rate;
         par->bits_per_coded_sample  = 4;
         par->block_align            = 1;
-        par->bit_rate               = par->sample_rate * (int64_t)par->bits_per_coded_sample * par->channels;
+        par->bit_rate               = par->sample_rate * (int64_t)par->bits_per_coded_sample *
+                                      par->ch_layout.nb_channels;
 
         avpriv_set_pts_info(st, 64, 1, par->sample_rate);
         st->start_time              = 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 123/281] psxstr: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (122 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 122/281] pp_bnk: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 124/281] pvf: " James Almer
                   ` (158 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/psxstr.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c
index e649ba3ab4..bb56b05688 100644
--- a/libavformat/psxstr.c
+++ b/libavformat/psxstr.c
@@ -252,18 +252,12 @@ static int str_read_packet(AVFormatContext *s,
                 st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
                 st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_XA;
                 st->codecpar->codec_tag   = 0;  /* no fourcc */
-                if (fmt & 1) {
-                    st->codecpar->channels       = 2;
-                    st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-                } else {
-                    st->codecpar->channels       = 1;
-                    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
-                }
+                av_channel_layout_default(&st->codecpar->ch_layout, (fmt & 1) + 1);
                 st->codecpar->sample_rate = (fmt&4)?18900:37800;
             //    st->codecpar->bit_rate = 0; //FIXME;
                 st->codecpar->block_align = 128;
 
-                avpriv_set_pts_info(st, 64, 18 * 224 / st->codecpar->channels,
+                avpriv_set_pts_info(st, 64, 18 * 224 / st->codecpar->ch_layout.nb_channels,
                                     st->codecpar->sample_rate);
                 st->start_time = 0;
             }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 124/281] pvf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (123 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 123/281] psxstr: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 125/281] qcp: " James Almer
                   ` (157 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/pvfdec.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/pvfdec.c b/libavformat/pvfdec.c
index 7205b0b37d..1654bcbc83 100644
--- a/libavformat/pvfdec.c
+++ b/libavformat/pvfdec.c
@@ -54,11 +54,12 @@ static int pvf_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
 
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels    = channels;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = channels;
     st->codecpar->sample_rate = sample_rate;
     st->codecpar->codec_id    = ff_get_pcm_codec_id(bps, 0, 1, 0xFFFF);
     st->codecpar->bits_per_coded_sample = bps;
-    st->codecpar->block_align = bps * st->codecpar->channels / 8;
+    st->codecpar->block_align = bps * st->codecpar->ch_layout.nb_channels / 8;
 
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 125/281] qcp: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (124 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 124/281] pvf: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 126/281] r3d: " James Almer
                   ` (156 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/qcp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/qcp.c b/libavformat/qcp.c
index 7e0d9b9b8c..8d80b726a5 100644
--- a/libavformat/qcp.c
+++ b/libavformat/qcp.c
@@ -103,8 +103,7 @@ static int qcp_read_header(AVFormatContext *s)
     avio_skip(pb, 4 + 8 + 4 + 1 + 1);    // filesize + "QLCMfmt " + chunk-size + major-version + minor-version
 
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels   = 1;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    st->codecpar->ch_layout  = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avio_read(pb, buf, 16);
     if (is_qcelp_13k_guid(buf)) {
         st->codecpar->codec_id = AV_CODEC_ID_QCELP;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 126/281] r3d: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (125 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 125/281] qcp: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 127/281] rawenc: " James Almer
                   ` (155 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/r3d.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/r3d.c b/libavformat/r3d.c
index c98e3dbc66..cd8b4c14bc 100644
--- a/libavformat/r3d.c
+++ b/libavformat/r3d.c
@@ -286,7 +286,8 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom)
             return AVERROR(ENOMEM);
         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE;
-        st->codecpar->channels = r3d->audio_channels;
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = r3d->audio_channels;
         avpriv_set_pts_info(st, 32, 1, s->streams[0]->time_base.den);
     } else {
         st = s->streams[1];
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 127/281] rawenc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (126 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 126/281] r3d: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 128/281] redspark: " James Almer
                   ` (154 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/rawenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index 4bbae7717b..54a0c2fa78 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -79,7 +79,7 @@ static int adx_write_trailer(AVFormatContext *s)
 
     if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
         int64_t file_size = avio_tell(pb);
-        uint64_t sample_count = (file_size - 36) / par->channels / 18 * 32;
+        uint64_t sample_count = (file_size - 36) / par->ch_layout.nb_channels / 18 * 32;
         if (sample_count <= UINT32_MAX) {
             avio_seek(pb, 12, SEEK_SET);
             avio_wb32(pb, sample_count);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 128/281] redspark: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (127 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 127/281] rawenc: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 129/281] riff: " James Almer
                   ` (153 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/redspark.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavformat/redspark.c b/libavformat/redspark.c
index eca182c3a7..f4386d7759 100644
--- a/libavformat/redspark.c
+++ b/libavformat/redspark.c
@@ -97,26 +97,27 @@ static int redspark_read_header(AVFormatContext *s)
     st->duration = bytestream2_get_be32u(&gbc) * 14;
     redspark->samples_count = 0;
     bytestream2_skipu(&gbc, 10);
-    par->channels = bytestream2_get_byteu(&gbc);
-    if (!par->channels) {
+    par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    par->ch_layout.nb_channels = bytestream2_get_byteu(&gbc);
+    if (!par->ch_layout.nb_channels) {
         return AVERROR_INVALIDDATA;
     }
 
-    coef_off = 0x54 + par->channels * 8;
+    coef_off = 0x54 + par->ch_layout.nb_channels * 8;
     if (bytestream2_get_byteu(&gbc)) // Loop flag
         coef_off += 16;
 
-    if (coef_off + par->channels * (32 + 14) > HEADER_SIZE) {
+    if (coef_off + par->ch_layout.nb_channels * (32 + 14) > HEADER_SIZE) {
         return AVERROR_INVALIDDATA;
     }
 
-    if (ff_alloc_extradata(par, 32 * par->channels)) {
+    if (ff_alloc_extradata(par, 32 * par->ch_layout.nb_channels)) {
         return AVERROR_INVALIDDATA;
     }
 
     /* Get the ADPCM table */
     bytestream2_seek(&gbc, coef_off, SEEK_SET);
-    for (i = 0; i < par->channels; i++) {
+    for (i = 0; i < par->ch_layout.nb_channels; i++) {
         if (bytestream2_get_bufferu(&gbc, par->extradata + i * 32, 32) != 32) {
             return AVERROR_INVALIDDATA;
         }
@@ -132,7 +133,7 @@ static int redspark_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     AVCodecParameters *par = s->streams[0]->codecpar;
     RedSparkContext *redspark = s->priv_data;
-    uint32_t size = 8 * par->channels;
+    uint32_t size = 8 * par->ch_layout.nb_channels;
     int ret;
 
     if (avio_feof(s->pb) || redspark->samples_count == s->streams[0]->duration)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 129/281] riff: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (128 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 128/281] redspark: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 130/281] rl2: " James Almer
                   ` (152 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/riffdec.c | 20 +++++++++++++-------
 libavformat/riffenc.c | 18 +++++++++---------
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c
index bd32e59837..a62e9c070f 100644
--- a/libavformat/riffdec.c
+++ b/libavformat/riffdec.c
@@ -61,11 +61,14 @@ static void parse_waveformatex(AVFormatContext *s, AVIOContext *pb, AVCodecParam
 {
     ff_asf_guid subformat;
     int bps;
+    uint64_t mask;
 
     bps = avio_rl16(pb);
     if (bps)
         par->bits_per_coded_sample = bps;
-    par->channel_layout        = avio_rl32(pb); /* dwChannelMask */
+
+    mask = avio_rl32(pb); /* dwChannelMask */
+    av_channel_layout_from_mask(&par->ch_layout, mask);
 
     ff_get_guid(pb, &subformat);
     if (!memcmp(subformat + 4,
@@ -90,7 +93,7 @@ static void parse_waveformatex(AVFormatContext *s, AVIOContext *pb, AVCodecParam
 int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,
                       AVCodecParameters *par, int size, int big_endian)
 {
-    int id;
+    int id, channels;
     uint64_t bitrate = 0;
 
     if (size < 14) {
@@ -102,14 +105,14 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,
     if (!big_endian) {
         id                 = avio_rl16(pb);
         if (id != 0x0165) {
-            par->channels    = avio_rl16(pb);
+            channels         = avio_rl16(pb);
             par->sample_rate = avio_rl32(pb);
             bitrate            = avio_rl32(pb) * 8LL;
             par->block_align = avio_rl16(pb);
         }
     } else {
         id                 = avio_rb16(pb);
-        par->channels    = avio_rb16(pb);
+        channels           = avio_rb16(pb);
         par->sample_rate = avio_rb32(pb);
         bitrate            = avio_rb32(pb) * 8LL;
         par->block_align = avio_rb16(pb);
@@ -160,12 +163,12 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,
             return AVERROR(ENOMEM);
         nb_streams         = AV_RL16(par->extradata + 4);
         par->sample_rate   = AV_RL32(par->extradata + 12);
-        par->channels      = 0;
+        channels           = 0;
         bitrate            = 0;
         if (size < 8 + nb_streams * 20)
             return AVERROR_INVALIDDATA;
         for (i = 0; i < nb_streams; i++)
-            par->channels += par->extradata[8 + i * 20 + 17];
+            channels += par->extradata[8 + i * 20 + 17];
     }
 
     par->bit_rate = bitrate;
@@ -178,13 +181,16 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb,
     if (par->codec_id == AV_CODEC_ID_AAC_LATM) {
         /* Channels and sample_rate values are those prior to applying SBR
          * and/or PS. */
-        par->channels    = 0;
+        channels         = 0;
         par->sample_rate = 0;
     }
     /* override bits_per_coded_sample for G.726 */
     if (par->codec_id == AV_CODEC_ID_ADPCM_G726 && par->sample_rate)
         par->bits_per_coded_sample = par->bit_rate / par->sample_rate;
 
+    par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    par->ch_layout.nb_channels = channels;
+
     return 0;
 }
 
diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
index ffccfa3d48..04cde7b37f 100644
--- a/libavformat/riffenc.c
+++ b/libavformat/riffenc.c
@@ -77,9 +77,9 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb,
      * for indicating packet duration. */
     frame_size = av_get_audio_frame_duration2(par, par->block_align);
 
-    waveformatextensible = (par->channels > 2 && par->channel_layout) ||
-                           par->channels == 1 && par->channel_layout && par->channel_layout != AV_CH_LAYOUT_MONO ||
-                           par->channels == 2 && par->channel_layout && par->channel_layout != AV_CH_LAYOUT_STEREO ||
+    waveformatextensible = (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
+                            av_channel_layout_compare(&par->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO) &&
+                            av_channel_layout_compare(&par->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) ||
                            par->sample_rate > 48000 ||
                            par->codec_id == AV_CODEC_ID_EAC3 ||
                            av_get_bits_per_sample(par->codec_id) > 16;
@@ -89,7 +89,7 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb,
     else
         avio_wl16(pb, par->codec_tag);
 
-    avio_wl16(pb, par->channels);
+    avio_wl16(pb, par->ch_layout.nb_channels);
     avio_wl32(pb, par->sample_rate);
     if (par->codec_id == AV_CODEC_ID_ATRAC3 ||
         par->codec_id == AV_CODEC_ID_G723_1 ||
@@ -119,13 +119,13 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb,
     } else if (par->codec_id == AV_CODEC_ID_AC3) {
         blkalign = 3840;                /* maximum bytes per frame */
     } else if (par->codec_id == AV_CODEC_ID_AAC) {
-        blkalign = 768 * par->channels; /* maximum bytes per frame */
+        blkalign = 768 * par->ch_layout.nb_channels; /* maximum bytes per frame */
     } else if (par->codec_id == AV_CODEC_ID_G723_1) {
         blkalign = 24;
     } else if (par->block_align != 0) { /* specified by the codec */
         blkalign = par->block_align;
     } else
-        blkalign = bps * par->channels / av_gcd(8, bps);
+        blkalign = bps * par->ch_layout.nb_channels / av_gcd(8, bps);
     if (par->codec_id == AV_CODEC_ID_PCM_U8 ||
         par->codec_id == AV_CODEC_ID_PCM_S24LE ||
         par->codec_id == AV_CODEC_ID_PCM_S32LE ||
@@ -153,7 +153,7 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb,
         /* dwHeadBitrate */
         bytestream_put_le32(&riff_extradata, par->bit_rate);
         /* fwHeadMode */
-        bytestream_put_le16(&riff_extradata, par->channels == 2 ? 1 : 8);
+        bytestream_put_le16(&riff_extradata, par->ch_layout.nb_channels == 2 ? 1 : 8);
         /* fwHeadModeExt */
         bytestream_put_le16(&riff_extradata, 0);
         /* wHeadEmphasis */
@@ -180,13 +180,13 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb,
     if (waveformatextensible) {
         int write_channel_mask = !(flags & FF_PUT_WAV_HEADER_SKIP_CHANNELMASK) &&
                                  (s->strict_std_compliance < FF_COMPLIANCE_NORMAL ||
-                                  par->channel_layout < 0x40000);
+                                  par->ch_layout.u.mask < 0x40000);
         /* 22 is WAVEFORMATEXTENSIBLE size */
         avio_wl16(pb, riff_extradata - riff_extradata_start + 22);
         /* ValidBitsPerSample || SamplesPerBlock || Reserved */
         avio_wl16(pb, bps);
         /* dwChannelMask */
-        avio_wl32(pb, write_channel_mask ? par->channel_layout : 0);
+        avio_wl32(pb, write_channel_mask ? par->ch_layout.u.mask : 0);
         /* GUID + next 3 */
         if (par->codec_id == AV_CODEC_ID_EAC3) {
             ff_put_guid(pb, ff_get_codec_guid(par->codec_id, ff_codec_wav_guids));
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 130/281] rl2: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (129 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 129/281] riff: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 131/281] rm: " James Almer
                   ` (151 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/rl2.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/rl2.c b/libavformat/rl2.c
index 6a559c7294..7b4b8d0ba7 100644
--- a/libavformat/rl2.c
+++ b/libavformat/rl2.c
@@ -147,12 +147,13 @@ static av_cold int rl2_read_header(AVFormatContext *s)
         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
         st->codecpar->codec_tag = 1;
-        st->codecpar->channels = channels;
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = channels;
         st->codecpar->bits_per_coded_sample = 8;
         st->codecpar->sample_rate = rate;
-        st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate *
+        st->codecpar->bit_rate = channels * st->codecpar->sample_rate *
             st->codecpar->bits_per_coded_sample;
-        st->codecpar->block_align = st->codecpar->channels *
+        st->codecpar->block_align = channels *
             st->codecpar->bits_per_coded_sample / 8;
         avpriv_set_pts_info(st,32,1,rate);
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 131/281] rm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (130 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 130/281] rl2: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 132/281] rpl: " James Almer
                   ` (150 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/rmdec.c | 6 +++---
 libavformat/rmenc.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 3a3f6aaf09..49c2645ecf 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -152,8 +152,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
         if (bytes_per_minute)
             st->codecpar->bit_rate = 8LL * bytes_per_minute / 60;
         st->codecpar->sample_rate = 8000;
-        st->codecpar->channels = 1;
-        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+        st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id = AV_CODEC_ID_RA_144;
         ast->deint_id = DEINT_ID_INT0;
@@ -189,7 +188,8 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
         }
         st->codecpar->sample_rate = avio_rb16(pb);
         avio_rb32(pb);
-        st->codecpar->channels = avio_rb16(pb);
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = avio_rb16(pb);
         if (version == 5) {
             ast->deint_id = avio_rl32(pb);
             avio_read(pb, buf, 4);
diff --git a/libavformat/rmenc.c b/libavformat/rmenc.c
index 1b2b0ecf38..1fba092b88 100644
--- a/libavformat/rmenc.c
+++ b/libavformat/rmenc.c
@@ -228,7 +228,7 @@ static int rv10_write_header(AVFormatContext *ctx,
             avio_wb32(s, 0); /* unknown */
             avio_wb16(s, stream->par->sample_rate); /* sample rate */
             avio_wb32(s, 0x10); /* unknown */
-            avio_wb16(s, stream->par->channels);
+            avio_wb16(s, stream->par->ch_layout.nb_channels);
             put_str8(s, "Int0"); /* codec name */
             if (stream->par->codec_tag) {
                 avio_w8(s, 4); /* tag length */
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 132/281] rpl: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (131 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 131/281] rm: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 133/281] rsd: " James Almer
                   ` (149 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/rpl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/rpl.c b/libavformat/rpl.c
index 459791ffd3..b6eaaab768 100644
--- a/libavformat/rpl.c
+++ b/libavformat/rpl.c
@@ -194,23 +194,26 @@ static int rpl_read_header(AVFormatContext *s)
     audio_format = read_int(line, &endptr, &error);  // audio format ID
     av_strlcpy(audio_codec, endptr, RPL_LINE_LENGTH);
     if (audio_format) {
+        int channels;
         ast = avformat_new_stream(s, NULL);
         if (!ast)
             return AVERROR(ENOMEM);
         ast->codecpar->codec_type      = AVMEDIA_TYPE_AUDIO;
         ast->codecpar->codec_tag       = audio_format;
         ast->codecpar->sample_rate     = read_line_and_int(pb, &error);  // audio bitrate
-        ast->codecpar->channels        = read_line_and_int(pb, &error);  // number of audio channels
+        channels                       = read_line_and_int(pb, &error);  // number of audio channels
         error |= read_line(pb, line, sizeof(line));
         ast->codecpar->bits_per_coded_sample = read_int(line, &endptr, &error);  // audio bits per sample
         av_strlcpy(audio_type, endptr, RPL_LINE_LENGTH);
+        ast->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        ast->codecpar->ch_layout.nb_channels = channels;
         // At least one sample uses 0 for ADPCM, which is really 4 bits
         // per sample.
         if (ast->codecpar->bits_per_coded_sample == 0)
             ast->codecpar->bits_per_coded_sample = 4;
 
         ast->codecpar->bit_rate = ast->codecpar->sample_rate *
-                                  (int64_t)ast->codecpar->channels;
+                                  (int64_t)ast->codecpar->ch_layout.nb_channels;
         if (ast->codecpar->bit_rate > INT64_MAX / ast->codecpar->bits_per_coded_sample)
             return AVERROR_INVALIDDATA;
         ast->codecpar->bit_rate *= ast->codecpar->bits_per_coded_sample;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 133/281] rsd: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (132 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 132/281] rpl: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 134/281] rso: " James Almer
                   ` (148 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/rsd.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/libavformat/rsd.c b/libavformat/rsd.c
index ba3b3429b9..bd6dc3351e 100644
--- a/libavformat/rsd.c
+++ b/libavformat/rsd.c
@@ -81,9 +81,10 @@ static int rsd_read_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
     }
 
-    par->channels = avio_rl32(pb);
-    if (par->channels <= 0 || par->channels > INT_MAX / 36) {
-        av_log(s, AV_LOG_ERROR, "Invalid number of channels: %d\n", par->channels);
+    par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    par->ch_layout.nb_channels = avio_rl32(pb);
+    if (par->ch_layout.nb_channels <= 0 || par->ch_layout.nb_channels > INT_MAX / 36) {
+        av_log(s, AV_LOG_ERROR, "Invalid number of channels: %d\n", par->ch_layout.nb_channels);
         return AVERROR_INVALIDDATA;
     }
 
@@ -102,17 +103,17 @@ static int rsd_read_header(AVFormatContext *s)
         memset(par->extradata, 0, 34);
         break;
     case AV_CODEC_ID_ADPCM_PSX:
-        par->block_align = 16 * par->channels;
+        par->block_align = 16 * par->ch_layout.nb_channels;
         break;
     case AV_CODEC_ID_ADPCM_IMA_RAD:
-        par->block_align = 20 * par->channels;
+        par->block_align = 20 * par->ch_layout.nb_channels;
         break;
     case AV_CODEC_ID_ADPCM_IMA_WAV:
         if (version == 2)
             start = avio_rl32(pb);
 
         par->bits_per_coded_sample = 4;
-        par->block_align = 36 * par->channels;
+        par->block_align = 36 * par->ch_layout.nb_channels;
         break;
     case AV_CODEC_ID_ADPCM_THP_LE:
         /* RSD3GADP is mono, so only alloc enough memory
@@ -124,13 +125,13 @@ static int rsd_read_header(AVFormatContext *s)
             return ret;
         break;
     case AV_CODEC_ID_ADPCM_THP:
-        par->block_align = 8 * par->channels;
+        par->block_align = 8 * par->ch_layout.nb_channels;
         avio_skip(s->pb, 0x1A4 - avio_tell(s->pb));
 
-        if ((ret = ff_alloc_extradata(st->codecpar, 32 * par->channels)) < 0)
+        if ((ret = ff_alloc_extradata(st->codecpar, 32 * par->ch_layout.nb_channels)) < 0)
             return ret;
 
-        for (i = 0; i < par->channels; i++) {
+        for (i = 0; i < par->ch_layout.nb_channels; i++) {
             if (avio_feof(pb))
                 return AVERROR_EOF;
             avio_read(s->pb, st->codecpar->extradata + 32 * i, 32);
@@ -159,11 +160,11 @@ static int rsd_read_header(AVFormatContext *s)
                 st->duration = av_get_audio_frame_duration2(par, remaining - start);
                 break;
             case AV_CODEC_ID_ADPCM_THP:
-                st->duration = (remaining - start) / (8 * par->channels) * 14;
+                st->duration = (remaining - start) / (8 * par->ch_layout.nb_channels) * 14;
                 break;
             case AV_CODEC_ID_PCM_S16LE:
             case AV_CODEC_ID_PCM_S16BE:
-                st->duration = (remaining - start) / 2 / par->channels;
+                st->duration = (remaining - start) / 2 / par->ch_layout.nb_channels;
             }
     }
 
@@ -194,14 +195,14 @@ static int rsd_read_packet(AVFormatContext *s, AVPacket *pkt)
         par->codec_id == AV_CODEC_ID_XMA2) {
         ret = av_get_packet(s->pb, pkt, par->block_align);
     } else if (par->codec_tag == MKTAG('W','A','D','P') &&
-               par->channels > 1) {
+               par->ch_layout.nb_channels > 1) {
         int i, ch;
 
         ret = av_new_packet(pkt, par->block_align);
         if (ret < 0)
             return ret;
         for (i = 0; i < 4; i++) {
-            for (ch = 0; ch < par->channels; ch++) {
+            for (ch = 0; ch < par->ch_layout.nb_channels; ch++) {
                 pkt->data[ch * 8 + i * 2 + 0] = avio_r8(s->pb);
                 pkt->data[ch * 8 + i * 2 + 1] = avio_r8(s->pb);
             }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 134/281] rso: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (133 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 133/281] rsd: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 135/281] rtp: " James Almer
                   ` (147 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/rsodec.c | 3 +--
 libavformat/rsoenc.c | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavformat/rsodec.c b/libavformat/rsodec.c
index ffd0fdff0d..569368b422 100644
--- a/libavformat/rsodec.c
+++ b/libavformat/rsodec.c
@@ -62,8 +62,7 @@ static int rso_read_header(AVFormatContext *s)
     st->codecpar->codec_type   = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_tag    = id;
     st->codecpar->codec_id     = codec;
-    st->codecpar->channels     = 1;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    st->codecpar->ch_layout    = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     st->codecpar->sample_rate  = rate;
     st->codecpar->block_align  = 1;
 
diff --git a/libavformat/rsoenc.c b/libavformat/rsoenc.c
index fc327d8a2f..858b53f6c6 100644
--- a/libavformat/rsoenc.c
+++ b/libavformat/rsoenc.c
@@ -34,7 +34,7 @@ static int rso_write_header(AVFormatContext *s)
     if (!par->codec_tag)
         return AVERROR_INVALIDDATA;
 
-    if (par->channels != 1) {
+    if (par->ch_layout.nb_channels != 1) {
         av_log(s, AV_LOG_ERROR, "RSO only supports mono\n");
         return AVERROR_INVALIDDATA;
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 135/281] rtp: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (134 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 134/281] rso: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-28 14:15   ` Anton Khirnov
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 136/281] sbg: " James Almer
                   ` (146 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/rtp.c        | 10 ++++++----
 libavformat/rtpdec.c     |  4 ++--
 libavformat/rtpdec_amr.c |  3 +--
 libavformat/rtpenc.c     | 14 +++++++-------
 libavformat/rtsp.c       |  6 +++---
 libavformat/rtsp.h       |  1 -
 6 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/libavformat/rtp.c b/libavformat/rtp.c
index c536a6f082..004191a550 100644
--- a/libavformat/rtp.c
+++ b/libavformat/rtp.c
@@ -77,8 +77,10 @@ int ff_rtp_get_codec_info(AVCodecParameters *par, int payload_type)
             if (rtp_payload_types[i].codec_id != AV_CODEC_ID_NONE) {
                 par->codec_type = rtp_payload_types[i].codec_type;
                 par->codec_id = rtp_payload_types[i].codec_id;
-                if (rtp_payload_types[i].audio_channels > 0)
-                    par->channels = rtp_payload_types[i].audio_channels;
+                if (rtp_payload_types[i].audio_channels > 0) {
+                    par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+                    par->ch_layout.nb_channels = rtp_payload_types[i].audio_channels;
+                }
                 if (rtp_payload_types[i].clock_rate > 0)
                     par->sample_rate = rtp_payload_types[i].clock_rate;
                 return 0;
@@ -111,13 +113,13 @@ int ff_rtp_get_payload_type(const AVFormatContext *fmt,
             /* G722 has 8000 as nominal rate even if the sample rate is 16000,
              * see section 4.5.2 in RFC 3551. */
             if (par->codec_id == AV_CODEC_ID_ADPCM_G722 &&
-                par->sample_rate == 16000 && par->channels == 1)
+                par->sample_rate == 16000 && par->ch_layout.nb_channels == 1)
                 return rtp_payload_types[i].pt;
             if (par->codec_type == AVMEDIA_TYPE_AUDIO &&
                 ((rtp_payload_types[i].clock_rate > 0 &&
                   par->sample_rate != rtp_payload_types[i].clock_rate) ||
                  (rtp_payload_types[i].audio_channels > 0 &&
-                  par->channels != rtp_payload_types[i].audio_channels)))
+                  par->ch_layout.nb_channels != rtp_payload_types[i].audio_channels)))
                 continue;
             return rtp_payload_types[i].pt;
         }
diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index 20fe2b82d7..e56fde9d48 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -538,7 +538,7 @@ static int opus_write_extradata(AVCodecParameters *codecpar)
      * This mapping family only supports mono and stereo layouts. And RFC7587
      * specifies that the number of channels in the SDP must be 2.
      */
-    if (codecpar->channels > 2) {
+    if (codecpar->ch_layout.nb_channels > 2) {
         return AVERROR_INVALIDDATA;
     }
 
@@ -553,7 +553,7 @@ static int opus_write_extradata(AVCodecParameters *codecpar)
     /* Version */
     bytestream_put_byte  (&bs, 0x1);
     /* Channel count */
-    bytestream_put_byte  (&bs, codecpar->channels);
+    bytestream_put_byte  (&bs, codecpar->ch_layout.nb_channels);
     /* Pre skip */
     bytestream_put_le16  (&bs, 0);
     /* Input sample rate */
diff --git a/libavformat/rtpdec_amr.c b/libavformat/rtpdec_amr.c
index 988b7bddfd..20b435039c 100644
--- a/libavformat/rtpdec_amr.c
+++ b/libavformat/rtpdec_amr.c
@@ -64,11 +64,10 @@ static int amr_handle_packet(AVFormatContext *ctx, PayloadContext *data,
         return AVERROR_INVALIDDATA;
     }
 
-    if (st->codecpar->channels != 1) {
+    if (st->codecpar->ch_layout.nb_channels != 1) {
         av_log(ctx, AV_LOG_ERROR, "Only mono AMR is supported\n");
         return AVERROR_INVALIDDATA;
     }
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
 
     /* The AMR RTP packet consists of one header byte, followed
      * by one TOC byte for each AMR frame in the packet, followed
diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index 6be67b5885..ce629a8095 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -236,7 +236,7 @@ static int rtp_write_header(AVFormatContext *s1)
         avpriv_set_pts_info(st, 32, 1, 8000);
         break;
     case AV_CODEC_ID_OPUS:
-        if (st->codecpar->channels > 2) {
+        if (st->codecpar->ch_layout.nb_channels > 2) {
             av_log(s1, AV_LOG_ERROR, "Multistream opus not supported in RTP\n");
             goto fail;
         }
@@ -264,7 +264,7 @@ static int rtp_write_header(AVFormatContext *s1)
             av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for AMR\n");
             goto fail;
         }
-        if (st->codecpar->channels != 1) {
+        if (st->codecpar->ch_layout.nb_channels != 1) {
             av_log(s1, AV_LOG_ERROR, "Only mono is supported\n");
             goto fail;
         }
@@ -541,24 +541,24 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
     case AV_CODEC_ID_PCM_ALAW:
     case AV_CODEC_ID_PCM_U8:
     case AV_CODEC_ID_PCM_S8:
-        return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels);
+        return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->ch_layout.nb_channels);
     case AV_CODEC_ID_PCM_U16BE:
     case AV_CODEC_ID_PCM_U16LE:
     case AV_CODEC_ID_PCM_S16BE:
     case AV_CODEC_ID_PCM_S16LE:
-        return rtp_send_samples(s1, pkt->data, size, 16 * st->codecpar->channels);
+        return rtp_send_samples(s1, pkt->data, size, 16 * st->codecpar->ch_layout.nb_channels);
     case AV_CODEC_ID_PCM_S24BE:
-        return rtp_send_samples(s1, pkt->data, size, 24 * st->codecpar->channels);
+        return rtp_send_samples(s1, pkt->data, size, 24 * st->codecpar->ch_layout.nb_channels);
     case AV_CODEC_ID_ADPCM_G722:
         /* The actual sample size is half a byte per sample, but since the
          * stream clock rate is 8000 Hz while the sample rate is 16000 Hz,
          * the correct parameter for send_samples_bits is 8 bits per stream
          * clock. */
-        return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels);
+        return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->ch_layout.nb_channels);
     case AV_CODEC_ID_ADPCM_G726:
     case AV_CODEC_ID_ADPCM_G726LE:
         return rtp_send_samples(s1, pkt->data, size,
-                                st->codecpar->bits_per_coded_sample * st->codecpar->channels);
+                                st->codecpar->bits_per_coded_sample * st->codecpar->ch_layout.nb_channels);
     case AV_CODEC_ID_MP2:
     case AV_CODEC_ID_MP3:
         rtp_send_mpegaudio(s1, pkt->data, size);
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 70c18941ca..5fa756bf5c 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -323,19 +323,19 @@ static int sdp_parse_rtpmap(AVFormatContext *s,
     case AVMEDIA_TYPE_AUDIO:
         av_log(s, AV_LOG_DEBUG, "audio codec set to: %s\n", c_name);
         par->sample_rate = RTSP_DEFAULT_AUDIO_SAMPLERATE;
-        par->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS;
+        par->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         if (i > 0) {
             par->sample_rate = i;
             avpriv_set_pts_info(st, 32, 1, par->sample_rate);
             get_word_sep(buf, sizeof(buf), "/", &p);
             i = atoi(buf);
             if (i > 0)
-                par->channels = i;
+                av_channel_layout_default(&par->ch_layout, i);
         }
         av_log(s, AV_LOG_DEBUG, "audio samplerate set to: %i\n",
                par->sample_rate);
         av_log(s, AV_LOG_DEBUG, "audio channels set to: %i\n",
-               par->channels);
+               par->ch_layout.nb_channels);
         break;
     case AVMEDIA_TYPE_VIDEO:
         av_log(s, AV_LOG_DEBUG, "video codec set to: %s\n", c_name);
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 8b64e29d70..3133bf61c1 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -75,7 +75,6 @@ enum RTSPControlTransport {
 #define RTSPS_DEFAULT_PORT  322
 #define RTSP_MAX_TRANSPORTS 8
 #define RTSP_TCP_MAX_PACKET_SIZE 1472
-#define RTSP_DEFAULT_NB_AUDIO_CHANNELS 1
 #define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100
 #define RTSP_RTP_PORT_MIN 5000
 #define RTSP_RTP_PORT_MAX 65000
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 136/281] sbg: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (135 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 135/281] rtp: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 137/281] scd: " James Almer
                   ` (145 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/sbgdec.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/sbgdec.c b/libavformat/sbgdec.c
index baffbbd6fd..8a6d679056 100644
--- a/libavformat/sbgdec.c
+++ b/libavformat/sbgdec.c
@@ -1446,8 +1446,7 @@ static av_cold int sbg_read_header(AVFormatContext *avf)
     sti = ffstream(st);
     st->codecpar->codec_type     = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id       = AV_CODEC_ID_FFWAVESYNTH;
-    st->codecpar->channels       = 2;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+    st->codecpar->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     st->codecpar->sample_rate    = sbg->sample_rate;
     st->codecpar->frame_size     = sbg->frame_size;
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 137/281] scd: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (136 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 136/281] sbg: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 138/281] sdp: " James Almer
                   ` (144 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/scd.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavformat/scd.c b/libavformat/scd.c
index 0ed5322a14..d59d72e1d9 100644
--- a/libavformat/scd.c
+++ b/libavformat/scd.c
@@ -194,7 +194,8 @@ static int scd_read_track(AVFormatContext *s, SCDTrackHeader *track, int index)
 
     par               = st->codecpar;
     par->codec_type   = AVMEDIA_TYPE_AUDIO;
-    par->channels     = (int)track->num_channels;
+    par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    par->ch_layout.nb_channels = (int)track->num_channels;
     par->sample_rate  = (int)track->sample_rate;
     st->index         = index;
     st->start_time    = 0;
@@ -218,7 +219,7 @@ static int scd_read_track(AVFormatContext *s, SCDTrackHeader *track, int index)
         case SCD_TRACK_ID_PCM:
             par->codec_id              = AV_CODEC_ID_PCM_S16BE;
             par->bits_per_coded_sample = 16;
-            par->block_align           = par->bits_per_coded_sample * par->channels / 8;
+            par->block_align           = par->bits_per_coded_sample * par->ch_layout.nb_channels / 8;
             break;
         case SCD_TRACK_ID_MP3:
             par->codec_id              = AV_CODEC_ID_MP3;
@@ -325,8 +326,8 @@ static int scd_read_packet(AVFormatContext *s, AVPacket *pkt)
         }
 
         if (trk->data_type == SCD_TRACK_ID_PCM) {
-            pkt->pts      = trk->bytes_read / (par->channels * sizeof(uint16_t));
-            pkt->duration = size / (par->channels * sizeof(int16_t));
+            pkt->pts      = trk->bytes_read / (par->ch_layout.nb_channels * sizeof(uint16_t));
+            pkt->duration = size / (par->ch_layout.nb_channels * sizeof(int16_t));
         }
 
         trk->bytes_read   += ret;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 138/281] sdp: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (137 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 137/281] scd: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 139/281] sdr2: " James Almer
                   ` (143 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/sdp.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index d63a0b34c4..0802b99af7 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -450,16 +450,16 @@ static int latm_context2profilelevel(const AVCodecParameters *par)
      * Different Object Types should implement different Profile Levels */
 
     if (par->sample_rate <= 24000) {
-        if (par->channels <= 2)
+        if (par->ch_layout.nb_channels <= 2)
             profile_level = 0x28; // AAC Profile, Level 1
     } else if (par->sample_rate <= 48000) {
-        if (par->channels <= 2) {
+        if (par->ch_layout.nb_channels <= 2) {
             profile_level = 0x29; // AAC Profile, Level 2
-        } else if (par->channels <= 5) {
+        } else if (par->ch_layout.nb_channels <= 5) {
             profile_level = 0x2A; // AAC Profile, Level 4
         }
     } else if (par->sample_rate <= 96000) {
-        if (par->channels <= 5) {
+        if (par->ch_layout.nb_channels <= 5) {
             profile_level = 0x2B; // AAC Profile, Level 5
         }
     }
@@ -491,7 +491,7 @@ static int latm_context2config(AVFormatContext *s, const AVCodecParameters *par,
     config_byte[0] = 0x40;
     config_byte[1] = 0;
     config_byte[2] = 0x20 | rate_index;
-    config_byte[3] = par->channels << 4;
+    config_byte[3] = par->ch_layout.nb_channels << 4;
     config_byte[4] = 0x3f;
     config_byte[5] = 0xc0;
 
@@ -591,7 +591,7 @@ static int sdp_write_media_attributes(char *buff, int size, const AVStream *st,
                 return ret;
             av_strlcatf(buff, size, "a=rtpmap:%d MP4A-LATM/%d/%d\r\n"
                                     "a=fmtp:%d profile-level-id=%d;cpresent=0;config=%s\r\n",
-                                     payload_type, p->sample_rate, p->channels,
+                                     payload_type, p->sample_rate, p->ch_layout.nb_channels,
                                      payload_type, latm_context2profilelevel(p), config);
         } else {
             if (p->extradata_size) {
@@ -609,7 +609,7 @@ static int sdp_write_media_attributes(char *buff, int size, const AVStream *st,
                                     "a=fmtp:%d profile-level-id=1;"
                                     "mode=AAC-hbr;sizelength=13;indexlength=3;"
                                     "indexdeltalength=3%s\r\n",
-                                     payload_type, p->sample_rate, p->channels,
+                                     payload_type, p->sample_rate, p->ch_layout.nb_channels,
                                      payload_type, config);
         }
         break;
@@ -617,36 +617,36 @@ static int sdp_write_media_attributes(char *buff, int size, const AVStream *st,
         if (payload_type >= RTP_PT_PRIVATE)
             av_strlcatf(buff, size, "a=rtpmap:%d L16/%d/%d\r\n",
                                      payload_type,
-                                     p->sample_rate, p->channels);
+                                     p->sample_rate, p->ch_layout.nb_channels);
         break;
     case AV_CODEC_ID_PCM_S24BE:
         if (payload_type >= RTP_PT_PRIVATE)
             av_strlcatf(buff, size, "a=rtpmap:%d L24/%d/%d\r\n",
                                      payload_type,
-                                     p->sample_rate, p->channels);
+                                     p->sample_rate, p->ch_layout.nb_channels);
         break;
     case AV_CODEC_ID_PCM_MULAW:
         if (payload_type >= RTP_PT_PRIVATE)
             av_strlcatf(buff, size, "a=rtpmap:%d PCMU/%d/%d\r\n",
                                      payload_type,
-                                     p->sample_rate, p->channels);
+                                     p->sample_rate, p->ch_layout.nb_channels);
         break;
     case AV_CODEC_ID_PCM_ALAW:
         if (payload_type >= RTP_PT_PRIVATE)
             av_strlcatf(buff, size, "a=rtpmap:%d PCMA/%d/%d\r\n",
                                      payload_type,
-                                     p->sample_rate, p->channels);
+                                     p->sample_rate, p->ch_layout.nb_channels);
         break;
     case AV_CODEC_ID_AMR_NB:
         av_strlcatf(buff, size, "a=rtpmap:%d AMR/%d/%d\r\n"
                                 "a=fmtp:%d octet-align=1\r\n",
-                                 payload_type, p->sample_rate, p->channels,
+                                 payload_type, p->sample_rate, p->ch_layout.nb_channels,
                                  payload_type);
         break;
     case AV_CODEC_ID_AMR_WB:
         av_strlcatf(buff, size, "a=rtpmap:%d AMR-WB/%d/%d\r\n"
                                 "a=fmtp:%d octet-align=1\r\n",
-                                 payload_type, p->sample_rate, p->channels,
+                                 payload_type, p->sample_rate, p->ch_layout.nb_channels,
                                  payload_type);
         break;
     case AV_CODEC_ID_VORBIS:
@@ -661,7 +661,7 @@ static int sdp_write_media_attributes(char *buff, int size, const AVStream *st,
 
         av_strlcatf(buff, size, "a=rtpmap:%d vorbis/%d/%d\r\n"
                                 "a=fmtp:%d configuration=%s\r\n",
-                                payload_type, p->sample_rate, p->channels,
+                                payload_type, p->sample_rate, p->ch_layout.nb_channels,
                                 payload_type, config);
         break;
     case AV_CODEC_ID_THEORA: {
@@ -754,7 +754,7 @@ static int sdp_write_media_attributes(char *buff, int size, const AVStream *st,
         if (payload_type >= RTP_PT_PRIVATE)
             av_strlcatf(buff, size, "a=rtpmap:%d G722/%d/%d\r\n",
                                      payload_type,
-                                     8000, p->channels);
+                                     8000, p->ch_layout.nb_channels);
         break;
     case AV_CODEC_ID_ADPCM_G726: {
         if (payload_type >= RTP_PT_PRIVATE)
@@ -791,7 +791,7 @@ static int sdp_write_media_attributes(char *buff, int size, const AVStream *st,
            receivers MUST be able to receive and process stereo packets. */
         av_strlcatf(buff, size, "a=rtpmap:%d opus/48000/2\r\n",
                                  payload_type);
-        if (p->channels == 2) {
+        if (p->ch_layout.nb_channels == 2) {
             av_strlcatf(buff, size, "a=fmtp:%d sprop-stereo=1\r\n",
                                      payload_type);
         }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 139/281] sdr2: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (138 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 138/281] sdp: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 140/281] sds: " James Almer
                   ` (142 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/sdr2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/sdr2.c b/libavformat/sdr2.c
index 6799339420..8b99419bc4 100644
--- a/libavformat/sdr2.c
+++ b/libavformat/sdr2.c
@@ -54,7 +54,8 @@ static int sdr2_read_header(AVFormatContext *s)
     ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL;
 
     ast->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-    ast->codecpar->channels    = 1;
+    ast->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    ast->codecpar->ch_layout.nb_channels = 1;
     ast->codecpar->sample_rate = 8000;
     ast->codecpar->codec_id    = AV_CODEC_ID_PCM_S16LE;
     avpriv_set_pts_info(ast, 64, 1, 8000);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 140/281] sds: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (139 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 139/281] sdr2: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 141/281] sdx: " James Almer
                   ` (141 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/sdsdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/sdsdec.c b/libavformat/sdsdec.c
index 073dadafbb..3b7f95421f 100644
--- a/libavformat/sdsdec.c
+++ b/libavformat/sdsdec.c
@@ -110,7 +110,8 @@ static int sds_read_header(AVFormatContext *ctx)
     avio_skip(pb, 11);
 
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels = 1;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = 1;
     st->codecpar->sample_rate = sample_period ? 1000000000 / sample_period : 16000;
     st->duration = (avio_size(pb) - 21) / (127) * s->size / 4;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 141/281] sdx: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (140 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 140/281] sds: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 142/281] segafilm: " James Almer
                   ` (140 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/sdxdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/sdxdec.c b/libavformat/sdxdec.c
index 76fd2caa00..45edd62976 100644
--- a/libavformat/sdxdec.c
+++ b/libavformat/sdxdec.c
@@ -54,7 +54,8 @@ static int sdx_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
 
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels = 1;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = 1;
     st->codecpar->sample_rate = avio_rl32(s->pb);
     switch (depth) {
     case 8:
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 142/281] segafilm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (141 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 141/281] sdx: " James Almer
@ 2022-01-13  1:57 ` James Almer
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 143/281] sga: " James Almer
                   ` (139 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:57 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/segafilm.c    | 9 +++++----
 libavformat/segafilmenc.c | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavformat/segafilm.c b/libavformat/segafilm.c
index 3af7518d03..6c563a85af 100644
--- a/libavformat/segafilm.c
+++ b/libavformat/segafilm.c
@@ -177,20 +177,21 @@ static int film_read_header(AVFormatContext *s)
         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_id = film->audio_type;
         st->codecpar->codec_tag = 1;
-        st->codecpar->channels = film->audio_channels;
+        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = film->audio_channels;
         st->codecpar->sample_rate = film->audio_samplerate;
 
         if (film->audio_type == AV_CODEC_ID_ADPCM_ADX) {
             st->codecpar->bits_per_coded_sample = 18 * 8 / 32;
-            st->codecpar->block_align = st->codecpar->channels * 18;
+            st->codecpar->block_align = film->audio_channels * 18;
             ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL;
         } else {
             st->codecpar->bits_per_coded_sample = film->audio_bits;
-            st->codecpar->block_align = st->codecpar->channels *
+            st->codecpar->block_align = film->audio_channels *
                 st->codecpar->bits_per_coded_sample / 8;
         }
 
-        st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate *
+        st->codecpar->bit_rate = film->audio_channels * st->codecpar->sample_rate *
             st->codecpar->bits_per_coded_sample;
     }
 
diff --git a/libavformat/segafilmenc.c b/libavformat/segafilmenc.c
index 737805faa6..7a412fe9cc 100644
--- a/libavformat/segafilmenc.c
+++ b/libavformat/segafilmenc.c
@@ -236,7 +236,7 @@ static int film_write_header(AVFormatContext *format_context)
         AVStream *audio = format_context->streams[film->audio_index];
         int audio_codec = get_audio_codec_id(audio->codecpar->codec_id);
 
-        bytestream_put_byte(&ptr, audio->codecpar->channels); /* Audio channels */
+        bytestream_put_byte(&ptr, audio->codecpar->ch_layout.nb_channels); /* Audio channels */
         bytestream_put_byte(&ptr, audio->codecpar->bits_per_coded_sample); /* Audio bit depth */
         bytestream_put_byte(&ptr, audio_codec); /* Compression - 0 is PCM, 2 is ADX */
         bytestream_put_be16(&ptr, audio->codecpar->sample_rate); /* Audio sampling rate */
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 143/281] sga: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (142 preceding siblings ...)
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 142/281] segafilm: " James Almer
@ 2022-01-13  1:58 ` James Almer
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 144/281] sierravmd: " James Almer
                   ` (138 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:58 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/sga.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/sga.c b/libavformat/sga.c
index 16e8fe516d..12e9cc1441 100644
--- a/libavformat/sga.c
+++ b/libavformat/sga.c
@@ -323,8 +323,7 @@ static int sga_audio_packet(AVFormatContext *s, AVPacket *pkt)
         st->codecpar->codec_type    = AVMEDIA_TYPE_AUDIO;
         st->codecpar->codec_tag     = 0;
         st->codecpar->codec_id      = AV_CODEC_ID_PCM_SGA;
-        st->codecpar->channels      = 1;
-        st->codecpar->channel_layout= AV_CH_LAYOUT_MONO;
+        st->codecpar->ch_layout     = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         st->codecpar->sample_rate   = av_rescale(AV_RB16(sga->sector + 8),
                                                  SEGA_CD_PCM_NUM,
                                                  SEGA_CD_PCM_DEN);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 144/281] sierravmd: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (143 preceding siblings ...)
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 143/281] sga: " James Almer
@ 2022-01-13  1:58 ` James Almer
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 145/281] siff: " James Almer
                   ` (137 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:58 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/sierravmd.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavformat/sierravmd.c b/libavformat/sierravmd.c
index e35faae50d..d110457ec9 100644
--- a/libavformat/sierravmd.c
+++ b/libavformat/sierravmd.c
@@ -134,6 +134,7 @@ static int vmd_read_header(AVFormatContext *s)
     /* if sample rate is 0, assume no audio */
     vmd->sample_rate = AV_RL16(&vmd->vmd_header[804]);
     if (vmd->sample_rate) {
+        int channels;
         st = avformat_new_stream(s, NULL);
         if (!st)
             return AVERROR(ENOMEM);
@@ -150,24 +151,22 @@ static int vmd_read_header(AVFormatContext *s)
             st->codecpar->bits_per_coded_sample = 8;
         }
         if (vmd->vmd_header[811] & 0x80) {
-            st->codecpar->channels       = 2;
-            st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+            channels = 2;
         } else if (vmd->vmd_header[811] & 0x2) {
             /* Shivers 2 stereo audio */
             /* Frame length is for 1 channel */
-            st->codecpar->channels       = 2;
-            st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+            channels        = 2;
             st->codecpar->block_align = st->codecpar->block_align << 1;
         } else {
-            st->codecpar->channels       = 1;
-            st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+            channels = 1;
         }
+        av_channel_layout_default(&st->codecpar->ch_layout, channels);
         st->codecpar->bit_rate = st->codecpar->sample_rate *
-            st->codecpar->bits_per_coded_sample * st->codecpar->channels;
+            st->codecpar->bits_per_coded_sample * channels;
 
         /* calculate pts */
         num = st->codecpar->block_align;
-        den = st->codecpar->sample_rate * st->codecpar->channels;
+        den = st->codecpar->sample_rate * channels;
         av_reduce(&num, &den, num, den, (1UL<<31)-1);
         if (vst)
             avpriv_set_pts_info(vst, 33, num, den);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 145/281] siff: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (144 preceding siblings ...)
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 144/281] sierravmd: " James Almer
@ 2022-01-13  1:58 ` James Almer
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 146/281] smacker: " James Almer
                   ` (136 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:58 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/siff.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/siff.c b/libavformat/siff.c
index a34de24ec8..99756574b4 100644
--- a/libavformat/siff.c
+++ b/libavformat/siff.c
@@ -80,8 +80,7 @@ static int create_audio_stream(AVFormatContext *s, SIFFContext *c)
         return AVERROR(ENOMEM);
     ast->codecpar->codec_type            = AVMEDIA_TYPE_AUDIO;
     ast->codecpar->codec_id              = AV_CODEC_ID_PCM_U8;
-    ast->codecpar->channels              = 1;
-    ast->codecpar->channel_layout        = AV_CH_LAYOUT_MONO;
+    ast->codecpar->ch_layout             = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     ast->codecpar->bits_per_coded_sample = 8;
     ast->codecpar->sample_rate           = c->rate;
     avpriv_set_pts_info(ast, 16, 1, c->rate);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 146/281] smacker: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (145 preceding siblings ...)
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 145/281] siff: " James Almer
@ 2022-01-13  1:58 ` James Almer
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 147/281] smjpegenc: " James Almer
                   ` (135 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:58 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/smacker.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index 98436bd708..80d36f2f40 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -186,13 +186,8 @@ static int smacker_read_header(AVFormatContext *s)
             } else {
                 par->codec_id  = AV_CODEC_ID_PCM_U8;
             }
-            if (aflag & SMK_AUD_STEREO) {
-                par->channels       = 2;
-                par->channel_layout = AV_CH_LAYOUT_STEREO;
-            } else {
-                par->channels       = 1;
-                par->channel_layout = AV_CH_LAYOUT_MONO;
-            }
+            av_channel_layout_default(&par->ch_layout,
+                                      !!(aflag & SMK_AUD_STEREO) + 1);
             par->sample_rate = rate;
             par->bits_per_coded_sample = (aflag & SMK_AUD_16BITS) ? 16 : 8;
             if (par->bits_per_coded_sample == 16 &&
@@ -200,7 +195,7 @@ static int smacker_read_header(AVFormatContext *s)
                 par->codec_id = AV_CODEC_ID_PCM_S16LE;
             else
                 smk->duration_size[i] = 4;
-            avpriv_set_pts_info(ast, 64, 1, par->sample_rate * par->channels
+            avpriv_set_pts_info(ast, 64, 1, par->sample_rate * par->ch_layout.nb_channels
                                             * par->bits_per_coded_sample / 8);
         }
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 147/281] smjpegenc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (146 preceding siblings ...)
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 146/281] smacker: " James Almer
@ 2022-01-13  1:58 ` James Almer
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 148/281] smoothstreaming: " James Almer
                   ` (134 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:58 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/smjpegdec.c | 3 ++-
 libavformat/smjpegenc.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/smjpegdec.c b/libavformat/smjpegdec.c
index dc95a822c5..d449162705 100644
--- a/libavformat/smjpegdec.c
+++ b/libavformat/smjpegdec.c
@@ -94,7 +94,8 @@ static int smjpeg_read_header(AVFormatContext *s)
             ast->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
             ast->codecpar->sample_rate = avio_rb16(pb);
             ast->codecpar->bits_per_coded_sample = avio_r8(pb);
-            ast->codecpar->channels    = avio_r8(pb);
+            ast->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+            ast->codecpar->ch_layout.nb_channels = avio_r8(pb);
             ast->codecpar->codec_tag   = avio_rl32(pb);
             ast->codecpar->codec_id    = ff_codec_get_id(ff_codec_smjpeg_audio_tags,
                                                          ast->codecpar->codec_tag);
diff --git a/libavformat/smjpegenc.c b/libavformat/smjpegenc.c
index ac5576fa76..8b40c09329 100644
--- a/libavformat/smjpegenc.c
+++ b/libavformat/smjpegenc.c
@@ -68,7 +68,7 @@ static int smjpeg_write_header(AVFormatContext *s)
             avio_wb32(pb, 8);
             avio_wb16(pb, par->sample_rate);
             avio_w8(pb, par->bits_per_coded_sample);
-            avio_w8(pb, par->channels);
+            avio_w8(pb, par->ch_layout.nb_channels);
             avio_wl32(pb, tag);
             avpriv_set_pts_info(st, 32, 1, 1000);
         } else if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 148/281] smoothstreaming: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (147 preceding siblings ...)
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 147/281] smjpegenc: " James Almer
@ 2022-01-13  1:58 ` James Almer
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 149/281] smush: " James Almer
                   ` (133 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:58 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/smoothstreamingenc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index a0ea5b8fa8..c67f0cba43 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -267,7 +267,9 @@ static int write_manifest(AVFormatContext *s, int final)
             if (s->streams[i]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)
                 continue;
             last = i;
-            avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%"PRId64"\" FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" BitsPerSample=\"16\" PacketSize=\"%d\" AudioTag=\"%d\" CodecPrivateData=\"%s\" />\n", index, s->streams[i]->codecpar->bit_rate, os->fourcc, s->streams[i]->codecpar->sample_rate, s->streams[i]->codecpar->channels, os->packet_size, os->audio_tag, os->private_str);
+            avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%"PRId64"\" FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" BitsPerSample=\"16\" PacketSize=\"%d\" AudioTag=\"%d\" CodecPrivateData=\"%s\" />\n",
+                        index, s->streams[i]->codecpar->bit_rate, os->fourcc, s->streams[i]->codecpar->sample_rate,
+                        s->streams[i]->codecpar->ch_layout.nb_channels, os->packet_size, os->audio_tag, os->private_str);
             index++;
         }
         output_chunk_list(&c->streams[last], out, final, c->lookahead_count, c->window_size);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 149/281] smush: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (148 preceding siblings ...)
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 148/281] smoothstreaming: " James Almer
@ 2022-01-13  1:58 ` James Almer
  2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 089/281] lvf: " James Almer
                   ` (132 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:58 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/smush.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/smush.c b/libavformat/smush.c
index 59807ab963..a0a6971e30 100644
--- a/libavformat/smush.c
+++ b/libavformat/smush.c
@@ -178,8 +178,8 @@ static int smush_read_header(AVFormatContext *ctx)
         ast->codecpar->codec_id    = AV_CODEC_ID_ADPCM_VIMA;
         ast->codecpar->codec_tag   = 0;
         ast->codecpar->sample_rate = sample_rate;
-        ast->codecpar->channels    = channels;
-
+        ast->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        ast->codecpar->ch_layout.nb_channels = channels;
         avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate);
     }
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 089/281] lvf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (149 preceding siblings ...)
  2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 149/281] smush: " James Almer
@ 2022-01-13  1:59 ` James Almer
  2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 150/281] sol: " James Almer
                   ` (131 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:59 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/lvfdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/lvfdec.c b/libavformat/lvfdec.c
index cd64fb9aee..d060b3b0aa 100644
--- a/libavformat/lvfdec.c
+++ b/libavformat/lvfdec.c
@@ -79,7 +79,8 @@ static int lvf_read_header(AVFormatContext *s)
 
             st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
             st->codecpar->codec_tag   = avio_rl16(s->pb);
-            st->codecpar->channels    = avio_rl16(s->pb);
+            st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = avio_rl16(s->pb);
             st->codecpar->sample_rate = avio_rl16(s->pb);
             avio_skip(s->pb, 8);
             st->codecpar->bits_per_coded_sample = avio_r8(s->pb);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 150/281] sol: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (150 preceding siblings ...)
  2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 089/281] lvf: " James Almer
@ 2022-01-13  1:59 ` James Almer
  2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 151/281] sox: " James Almer
                   ` (130 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:59 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/sol.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavformat/sol.c b/libavformat/sol.c
index 42498492b6..b92cfb36fe 100644
--- a/libavformat/sol.c
+++ b/libavformat/sol.c
@@ -113,9 +113,7 @@ static int sol_read_header(AVFormatContext *s)
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_tag = id;
     st->codecpar->codec_id = codec;
-    st->codecpar->channels = channels;
-    st->codecpar->channel_layout = channels == 1 ? AV_CH_LAYOUT_MONO :
-                                                   AV_CH_LAYOUT_STEREO;
+    av_channel_layout_default(&st->codecpar->ch_layout,channels);
     st->codecpar->sample_rate = rate;
     avpriv_set_pts_info(st, 64, 1, rate);
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 151/281] sox: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (151 preceding siblings ...)
  2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 150/281] sol: " James Almer
@ 2022-01-13  1:59 ` James Almer
  2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 152/281] svag: " James Almer
                   ` (129 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:59 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/soxdec.c | 14 +++++++++-----
 libavformat/soxenc.c |  4 ++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/libavformat/soxdec.c b/libavformat/soxdec.c
index 83fb5e3758..c747cdb9eb 100644
--- a/libavformat/soxdec.c
+++ b/libavformat/soxdec.c
@@ -49,6 +49,7 @@ static int sox_read_header(AVFormatContext *s)
     AVIOContext *pb = s->pb;
     unsigned header_size, comment_size;
     double sample_rate, sample_rate_frac;
+    int channels;
     AVStream *st;
 
     st = avformat_new_stream(s, NULL);
@@ -62,17 +63,20 @@ static int sox_read_header(AVFormatContext *s)
         header_size         = avio_rl32(pb);
         avio_skip(pb, 8); /* sample count */
         sample_rate         = av_int2double(avio_rl64(pb));
-        st->codecpar->channels = avio_rl32(pb);
+        channels            = avio_rl32(pb);
         comment_size        = avio_rl32(pb);
     } else {
         st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE;
         header_size         = avio_rb32(pb);
         avio_skip(pb, 8); /* sample count */
         sample_rate         = av_int2double(avio_rb64(pb));
-        st->codecpar->channels = avio_rb32(pb);
+        channels            = avio_rb32(pb);
         comment_size        = avio_rb32(pb);
     }
 
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = channels;
+
     if (comment_size > 0xFFFFFFFFU - SOX_FIXED_HDR - 4U) {
         av_log(s, AV_LOG_ERROR, "invalid comment size (%u)\n", comment_size);
         return AVERROR_INVALIDDATA;
@@ -90,7 +94,7 @@ static int sox_read_header(AVFormatContext *s)
                sample_rate_frac);
 
     if ((header_size + 4) & 7 || header_size < SOX_FIXED_HDR + comment_size
-        || st->codecpar->channels > 65535 || st->codecpar->channels <= 0) /* Reserve top 16 bits */ {
+        || channels > 65535 || channels <= 0) /* Reserve top 16 bits */ {
         av_log(s, AV_LOG_ERROR, "invalid header\n");
         return AVERROR_INVALIDDATA;
     }
@@ -115,9 +119,9 @@ static int sox_read_header(AVFormatContext *s)
     st->codecpar->bits_per_coded_sample = 32;
     st->codecpar->bit_rate              = (int64_t)st->codecpar->sample_rate *
                                           st->codecpar->bits_per_coded_sample *
-                                          st->codecpar->channels;
+                                          channels;
     st->codecpar->block_align           = st->codecpar->bits_per_coded_sample *
-                                          st->codecpar->channels / 8;
+                                          channels / 8;
 
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
diff --git a/libavformat/soxenc.c b/libavformat/soxenc.c
index e24501bacd..ac01f97df5 100644
--- a/libavformat/soxenc.c
+++ b/libavformat/soxenc.c
@@ -61,14 +61,14 @@ static int sox_write_header(AVFormatContext *s)
         avio_wl32(pb, sox->header_size);
         avio_wl64(pb, 0); /* number of samples */
         avio_wl64(pb, av_double2int(par->sample_rate));
-        avio_wl32(pb, par->channels);
+        avio_wl32(pb, par->ch_layout.nb_channels);
         avio_wl32(pb, comment_size);
     } else if (par->codec_id == AV_CODEC_ID_PCM_S32BE) {
         ffio_wfourcc(pb, "XoS.");
         avio_wb32(pb, sox->header_size);
         avio_wb64(pb, 0); /* number of samples */
         avio_wb64(pb, av_double2int(par->sample_rate));
-        avio_wb32(pb, par->channels);
+        avio_wb32(pb, par->ch_layout.nb_channels);
         avio_wb32(pb, comment_size);
     } else {
         av_log(s, AV_LOG_ERROR, "invalid codec; use pcm_s32le or pcm_s32be\n");
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 152/281] svag: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (152 preceding siblings ...)
  2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 151/281] sox: " James Almer
@ 2022-01-13  1:59 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 153/281] svs: " James Almer
                   ` (128 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  1:59 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/svag.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavformat/svag.c b/libavformat/svag.c
index 0774eae112..e907dc6adc 100644
--- a/libavformat/svag.c
+++ b/libavformat/svag.c
@@ -47,14 +47,16 @@ static int svag_read_header(AVFormatContext *s)
     st->codecpar->sample_rate = avio_rl32(s->pb);
     if (st->codecpar->sample_rate <= 0)
         return AVERROR_INVALIDDATA;
-    st->codecpar->channels    = avio_rl32(s->pb);
-    if (st->codecpar->channels <= 0 || st->codecpar->channels > 8)
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_rl32(s->pb);
+    if (st->codecpar->ch_layout.nb_channels <= 0 ||
+        st->codecpar->ch_layout.nb_channels > 8)
         return AVERROR_INVALIDDATA;
-    st->duration           = size / (16 * st->codecpar->channels) * 28;
+    st->duration           = size / (16 * st->codecpar->ch_layout.nb_channels) * 28;
     align                  = avio_rl32(s->pb);
-    if (align <= 0 || align > INT_MAX / st->codecpar->channels)
+    if (align <= 0 || align > INT_MAX / st->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
-    st->codecpar->block_align = align * st->codecpar->channels;
+    st->codecpar->block_align = align * st->codecpar->ch_layout.nb_channels;
     avio_skip(s->pb, 0x800 - avio_tell(s->pb));
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 153/281] svs: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (153 preceding siblings ...)
  2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 152/281] svag: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 154/281] swf: " James Almer
                   ` (127 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/svs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/svs.c b/libavformat/svs.c
index e5300203f5..b91d29f5a6 100644
--- a/libavformat/svs.c
+++ b/libavformat/svs.c
@@ -53,8 +53,7 @@ static int svs_read_header(AVFormatContext *s)
 
     st->codecpar->codec_type     = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id       = AV_CODEC_ID_ADPCM_PSX;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-    st->codecpar->channels       = 2;
+    st->codecpar->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     st->codecpar->sample_rate    = av_rescale_rnd(pitch, 48000, 4096, AV_ROUND_INF);
     st->codecpar->block_align    = 32;
     st->start_time               = 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 154/281] swf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (154 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 153/281] svs: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 155/281] tak: " James Almer
                   ` (126 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/swfdec.c | 8 +-------
 libavformat/swfenc.c | 2 +-
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c
index e549e4f50b..52c5e5c480 100644
--- a/libavformat/swfdec.c
+++ b/libavformat/swfdec.c
@@ -195,13 +195,7 @@ static AVStream *create_new_audio_stream(AVFormatContext *s, int id, int info)
     if (!ast)
         return NULL;
     ast->id = id;
-    if (info & 1) {
-        ast->codecpar->channels       = 2;
-        ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-    } else {
-        ast->codecpar->channels       = 1;
-        ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
-    }
+    av_channel_layout_default(&ast->codecpar->ch_layout, 1 + (info & 1));
     ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     ast->codecpar->codec_id   = ff_codec_get_id(swf_audio_codec_tags, info>>4 & 15);
     ffstream(ast)->need_parsing = AVSTREAM_PARSE_FULL;
diff --git a/libavformat/swfenc.c b/libavformat/swfenc.c
index 1fd2ad81a3..d12fb59348 100644
--- a/libavformat/swfenc.c
+++ b/libavformat/swfenc.c
@@ -348,7 +348,7 @@ static int swf_write_header(AVFormatContext *s)
             return -1;
         }
         v |= 0x02; /* 16 bit playback */
-        if (swf->audio_par->channels == 2)
+        if (swf->audio_par->ch_layout.nb_channels == 2)
             v |= 0x01; /* stereo playback */
         avio_w8(s->pb, v);
         v |= 0x20; /* mp3 compressed */
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 155/281] tak: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (155 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 154/281] swf: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 156/281] thp: " James Almer
                   ` (125 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/takdec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/takdec.c b/libavformat/takdec.c
index cc1f049512..51e4679fd1 100644
--- a/libavformat/takdec.c
+++ b/libavformat/takdec.c
@@ -152,9 +152,12 @@ static int tak_read_header(AVFormatContext *s)
                 st->duration = ti.samples;
             st->codecpar->bits_per_coded_sample = ti.bps;
             if (ti.ch_layout)
-                st->codecpar->channel_layout = ti.ch_layout;
+                av_channel_layout_from_mask(&st->codecpar->ch_layout, ti.ch_layout);
+            else {
+                st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+                st->codecpar->ch_layout.nb_channels = ti.channels;
+            }
             st->codecpar->sample_rate           = ti.sample_rate;
-            st->codecpar->channels              = ti.channels;
             st->start_time                   = 0;
             avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
             st->codecpar->extradata             = buffer;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 156/281] thp: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (156 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 155/281] tak: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 157/281] tiertexseq: " James Almer
                   ` (124 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/thp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/thp.c b/libavformat/thp.c
index 7103cf4f8a..2dd8b4d618 100644
--- a/libavformat/thp.c
+++ b/libavformat/thp.c
@@ -142,7 +142,8 @@ static int thp_read_header(AVFormatContext *s)
             st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
             st->codecpar->codec_id = AV_CODEC_ID_ADPCM_THP;
             st->codecpar->codec_tag = 0;  /* no fourcc */
-            st->codecpar->channels    = avio_rb32(pb); /* numChannels.  */
+            st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = avio_rb32(pb);
             st->codecpar->sample_rate = avio_rb32(pb); /* Frequency.  */
             st->duration           = avio_rb32(pb);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 157/281] tiertexseq: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (157 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 156/281] thp: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 158/281] tmv: " James Almer
                   ` (123 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/tiertexseq.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavformat/tiertexseq.c b/libavformat/tiertexseq.c
index ecc15e4039..d06853d0d6 100644
--- a/libavformat/tiertexseq.c
+++ b/libavformat/tiertexseq.c
@@ -242,12 +242,11 @@ static int seq_read_header(AVFormatContext *s)
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE;
     st->codecpar->codec_tag = 0;  /* no tag */
-    st->codecpar->channels = 1;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     st->codecpar->sample_rate = SEQ_SAMPLE_RATE;
     st->codecpar->bits_per_coded_sample = 16;
-    st->codecpar->bit_rate = st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample * st->codecpar->channels;
-    st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample / 8;
+    st->codecpar->bit_rate = st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample * st->codecpar->ch_layout.nb_channels;
+    st->codecpar->block_align = st->codecpar->ch_layout.nb_channels * st->codecpar->bits_per_coded_sample / 8;
 
     return 0;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 158/281] tmv: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (158 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 157/281] tiertexseq: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 159/281] tta: " James Almer
                   ` (122 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/tmv.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/libavformat/tmv.c b/libavformat/tmv.c
index 507f6cd032..ea39954190 100644
--- a/libavformat/tmv.c
+++ b/libavformat/tmv.c
@@ -113,19 +113,13 @@ static int tmv_read_header(AVFormatContext *s)
 
     ast->codecpar->codec_type            = AVMEDIA_TYPE_AUDIO;
     ast->codecpar->codec_id              = AV_CODEC_ID_PCM_U8;
-    if (features & TMV_STEREO) {
-        ast->codecpar->channels       = 2;
-        ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
-    } else {
-        ast->codecpar->channels       = 1;
-        ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
-    }
+    av_channel_layout_default(&ast->codecpar->ch_layout, !!(features & TMV_STEREO) + 1);
     ast->codecpar->bits_per_coded_sample = 8;
     ast->codecpar->bit_rate              = ast->codecpar->sample_rate *
                                            ast->codecpar->bits_per_coded_sample;
     avpriv_set_pts_info(ast, 32, 1, ast->codecpar->sample_rate);
 
-    fps.num = ast->codecpar->sample_rate * ast->codecpar->channels;
+    fps.num = ast->codecpar->sample_rate * ast->codecpar->ch_layout.nb_channels;
     fps.den = tmv->audio_chunk_size;
     av_reduce(&fps.num, &fps.den, fps.num, fps.den, 0xFFFFFFFFLL);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 159/281] tta: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (159 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 158/281] tmv: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 160/281] uncodedframecrcenc: " James Almer
                   ` (121 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/tta.c    | 3 ++-
 libavformat/ttaenc.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/tta.c b/libavformat/tta.c
index 6de8c620a6..d2be9548b8 100644
--- a/libavformat/tta.c
+++ b/libavformat/tta.c
@@ -134,7 +134,8 @@ static int tta_read_header(AVFormatContext *s)
 
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = AV_CODEC_ID_TTA;
-    st->codecpar->channels = channels;
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = channels;
     st->codecpar->sample_rate = samplerate;
     st->codecpar->bits_per_coded_sample = bps;
 
diff --git a/libavformat/ttaenc.c b/libavformat/ttaenc.c
index 486f8bdd10..1938582bb3 100644
--- a/libavformat/ttaenc.c
+++ b/libavformat/ttaenc.c
@@ -82,7 +82,7 @@ static int tta_write_header(AVFormatContext *s)
     ffio_init_checksum(tta->seek_table, ff_crcEDB88320_update, UINT32_MAX);
     avio_write(s->pb, "TTA1", 4);
     avio_wl16(s->pb, par->extradata ? AV_RL16(par->extradata + 4) : 1);
-    avio_wl16(s->pb, par->channels);
+    avio_wl16(s->pb, par->ch_layout.nb_channels);
     avio_wl16(s->pb, par->bits_per_raw_sample);
     avio_wl32(s->pb, par->sample_rate);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 160/281] uncodedframecrcenc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (160 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 159/281] tta: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 161/281] vag: " James Almer
                   ` (120 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/uncodedframecrcenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/uncodedframecrcenc.c b/libavformat/uncodedframecrcenc.c
index e30fe4ddb9..1ad37071a6 100644
--- a/libavformat/uncodedframecrcenc.c
+++ b/libavformat/uncodedframecrcenc.c
@@ -79,7 +79,7 @@ static void audio_frame_cksum(AVBPrint *bp, AVFrame *frame)
     int nb_planes, nb_samples, p;
     const char *name;
 
-    nb_planes  = frame->channels;
+    nb_planes  = frame->ch_layout.nb_channels;
     nb_samples = frame->nb_samples;
     if (!av_sample_fmt_is_planar(frame->format)) {
         nb_samples *= nb_planes;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 161/281] vag: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (161 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 160/281] uncodedframecrcenc: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 162/281] vividas: " James Almer
                   ` (119 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/vag.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavformat/vag.c b/libavformat/vag.c
index 9ef5466e39..624ae9df35 100644
--- a/libavformat/vag.c
+++ b/libavformat/vag.c
@@ -42,9 +42,10 @@ static int vag_read_header(AVFormatContext *s)
     avio_skip(s->pb, 4);
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_PSX;
-    st->codecpar->channels    = 1 + (avio_rb32(s->pb) == 0x00000004);
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = 1 + (avio_rb32(s->pb) == 0x00000004);
     avio_skip(s->pb, 4);
-    if (st->codecpar->channels > 1) {
+    if (st->codecpar->ch_layout.nb_channels > 1) {
         st->duration       = avio_rb32(s->pb);
     } else {
         st->duration       = avio_rb32(s->pb) / 16 * 28;
@@ -54,12 +55,12 @@ static int vag_read_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
     avio_seek(s->pb, 0x1000, SEEK_SET);
     if (avio_rl32(s->pb) == MKTAG('V','A','G','p')) {
-        st->codecpar->block_align = 0x1000 * st->codecpar->channels;
+        st->codecpar->block_align = 0x1000 * st->codecpar->ch_layout.nb_channels;
         avio_seek(s->pb, 0, SEEK_SET);
         st->duration = st->duration / 16 * 28;
     } else {
-        st->codecpar->block_align = 16 * st->codecpar->channels;
-        avio_seek(s->pb, st->codecpar->channels > 1 ? 0x80 : 0x30, SEEK_SET);
+        st->codecpar->block_align = 16 * st->codecpar->ch_layout.nb_channels;
+        avio_seek(s->pb, st->codecpar->ch_layout.nb_channels > 1 ? 0x80 : 0x30, SEEK_SET);
     }
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 162/281] vividas: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (162 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 161/281] vag: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 163/281] vivo: " James Almer
                   ` (118 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/vividas.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavformat/vividas.c b/libavformat/vividas.c
index d7a6e74650..5d0d11b222 100644
--- a/libavformat/vividas.c
+++ b/libavformat/vividas.c
@@ -372,9 +372,10 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s,  uint8_t *
         avio_r8(pb); // '5'
         avio_r8(pb); //codec_id
         avio_rl16(pb); //codec_subid
-        st->codecpar->channels = avio_rl16(pb); // channels
+        st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        st->codecpar->ch_layout.nb_channels = avio_rl16(pb); // channels
         st->codecpar->sample_rate = avio_rl32(pb); // sample_rate
-        if (st->codecpar->sample_rate <= 0 || st->codecpar->channels <= 0)
+        if (st->codecpar->sample_rate <= 0 || st->codecpar->ch_layout.nb_channels <= 0)
             return AVERROR_INVALIDDATA;
         avio_seek(pb, 10, SEEK_CUR); // data_1
         q = avio_r8(pb);
@@ -655,7 +656,8 @@ static int viv_read_packet(AVFormatContext *s,
         astream = s->streams[pkt->stream_index];
 
         pkt->pts = av_rescale_q(viv->audio_sample, av_make_q(1, astream->codecpar->sample_rate), astream->time_base);
-        viv->audio_sample += viv->audio_subpackets[viv->current_audio_subpacket].pcm_bytes / 2 / astream->codecpar->channels;
+        viv->audio_sample += viv->audio_subpackets[viv->current_audio_subpacket].pcm_bytes / 2 /
+                             astream->codecpar->ch_layout.nb_channels;
         pkt->flags |= AV_PKT_FLAG_KEY;
         viv->current_audio_subpacket++;
         return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 163/281] vivo: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (163 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 162/281] vividas: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 164/281] voc: " James Almer
                   ` (117 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/vivo.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/vivo.c b/libavformat/vivo.c
index 2a08e1df03..114eb212e5 100644
--- a/libavformat/vivo.c
+++ b/libavformat/vivo.c
@@ -249,7 +249,8 @@ static int vivo_read_header(AVFormatContext *s)
     ast->start_time        = 0;
     ast->codecpar->codec_tag  = 0;
     ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
-    ast->codecpar->channels = 1;
+    ast->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    ast->codecpar->ch_layout.nb_channels = 1;
 
     return 0;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 164/281] voc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (164 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 163/281] vivo: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 165/281] vpk: " James Almer
                   ` (116 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/voc_packet.c | 9 ++++++---
 libavformat/vocenc.c     | 9 +++++----
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/libavformat/voc_packet.c b/libavformat/voc_packet.c
index e5ae0be1de..a7ce2707a0 100644
--- a/libavformat/voc_packet.c
+++ b/libavformat/voc_packet.c
@@ -72,7 +72,8 @@ ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
                 if (sample_rate)
                     par->sample_rate = sample_rate;
                 avpriv_set_pts_info(st, 64, 1, par->sample_rate);
-                par->channels = channels;
+                par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+                par->ch_layout.nb_channels = channels;
                 par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id);
             } else
                 avio_skip(pb, 1);
@@ -103,7 +104,9 @@ ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
                 par->sample_rate = avio_rl32(pb);
                 avpriv_set_pts_info(st, 64, 1, par->sample_rate);
                 par->bits_per_coded_sample = avio_r8(pb);
-                par->channels = avio_r8(pb);
+                channels = avio_r8(pb);
+                par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+                par->ch_layout.nb_channels = channels;
             } else
                 avio_skip(pb, 6);
             tmp_codec = avio_rl16(pb);
@@ -140,7 +143,7 @@ ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
         }
     }
 
-    par->bit_rate = (int64_t)par->sample_rate * par->channels * par->bits_per_coded_sample;
+    par->bit_rate = (int64_t)par->sample_rate * par->ch_layout.nb_channels * par->bits_per_coded_sample;
 
     if (max_size <= 0)
         max_size = 2048;
diff --git a/libavformat/vocenc.c b/libavformat/vocenc.c
index 798b463a82..59c2bbba7b 100644
--- a/libavformat/vocenc.c
+++ b/libavformat/vocenc.c
@@ -63,16 +63,17 @@ static int voc_write_packet(AVFormatContext *s, AVPacket *pkt)
             avio_wl24(pb, pkt->size + 12);
             avio_wl32(pb, par->sample_rate);
             avio_w8(pb, par->bits_per_coded_sample);
-            avio_w8(pb, par->channels);
+            avio_w8(pb, par->ch_layout.nb_channels);
             avio_wl16(pb, par->codec_tag);
             avio_wl32(pb, 0);
         } else {
-            if (s->streams[0]->codecpar->channels > 1) {
+            if (s->streams[0]->codecpar->ch_layout.nb_channels > 1) {
                 avio_w8(pb, VOC_TYPE_EXTENDED);
                 avio_wl24(pb, 4);
-                avio_wl16(pb, 65536-(256000000 + par->sample_rate*par->channels/2)/(par->sample_rate*par->channels));
+                avio_wl16(pb, 65536 - (256000000 + par->sample_rate * par->ch_layout.nb_channels / 2) /
+                                      (par->sample_rate * par->ch_layout.nb_channels));
                 avio_w8(pb, par->codec_tag);
-                avio_w8(pb, par->channels - 1);
+                avio_w8(pb, par->ch_layout.nb_channels - 1);
             }
             avio_w8(pb, VOC_TYPE_VOICE_DATA);
             avio_wl24(pb, pkt->size + 2);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 165/281] vpk: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (165 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 164/281] voc: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 166/281] vqf: " James Almer
                   ` (115 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/vpk.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavformat/vpk.c b/libavformat/vpk.c
index d542a0806d..3968ee981e 100644
--- a/libavformat/vpk.c
+++ b/libavformat/vpk.c
@@ -59,14 +59,15 @@ static int vpk_read_header(AVFormatContext *s)
     st->codecpar->sample_rate = avio_rl32(s->pb);
     if (st->codecpar->sample_rate <= 0 || st->codecpar->block_align <= 0)
         return AVERROR_INVALIDDATA;
-    st->codecpar->channels    = avio_rl32(s->pb);
-    if (st->codecpar->channels <= 0)
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_rl32(s->pb);
+    if (st->codecpar->ch_layout.nb_channels <= 0)
         return AVERROR_INVALIDDATA;
-    samples_per_block      = ((st->codecpar->block_align / st->codecpar->channels) * 28LL) / 16;
+    samples_per_block      = ((st->codecpar->block_align / st->codecpar->ch_layout.nb_channels) * 28LL) / 16;
     if (samples_per_block <= 0)
         return AVERROR_INVALIDDATA;
     vpk->block_count       = (st->duration + (samples_per_block - 1)) / samples_per_block;
-    vpk->last_block_size   = (st->duration % samples_per_block) * 16 * st->codecpar->channels / 28;
+    vpk->last_block_size   = (st->duration % samples_per_block) * 16 * st->codecpar->ch_layout.nb_channels / 28;
 
     if (offset < avio_tell(s->pb))
         return AVERROR_INVALIDDATA;
@@ -85,14 +86,14 @@ static int vpk_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     vpk->current_block++;
     if (vpk->current_block == vpk->block_count) {
-        unsigned size = vpk->last_block_size / par->channels;
-        unsigned skip = (par->block_align - vpk->last_block_size) / par->channels;
+        unsigned size = vpk->last_block_size / par->ch_layout.nb_channels;
+        unsigned skip = (par->block_align - vpk->last_block_size) / par->ch_layout.nb_channels;
         uint64_t pos = avio_tell(s->pb);
 
         ret = av_new_packet(pkt, vpk->last_block_size);
         if (ret < 0)
             return ret;
-        for (i = 0; i < par->channels; i++) {
+        for (i = 0; i < par->ch_layout.nb_channels; i++) {
             ret = avio_read(s->pb, pkt->data + i * size, size);
             avio_skip(s->pb, skip);
             if (ret != size) {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 166/281] vqf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (166 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 165/281] vpk: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 167/281] wav: " James Almer
                   ` (114 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/vqf.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/libavformat/vqf.c b/libavformat/vqf.c
index 76131cdc55..d6e4016bc8 100644
--- a/libavformat/vqf.c
+++ b/libavformat/vqf.c
@@ -136,12 +136,13 @@ static int vqf_read_header(AVFormatContext *s)
                 return AVERROR_INVALIDDATA;
 
             avio_read(s->pb, comm_chunk, 12);
-            st->codecpar->channels = AV_RB32(comm_chunk    ) + 1;
+            st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+            st->codecpar->ch_layout.nb_channels = AV_RB32(comm_chunk) + 1;
             read_bitrate        = AV_RB32(comm_chunk + 4);
             rate_flag           = AV_RB32(comm_chunk + 8);
             avio_skip(s->pb, len-12);
 
-            if (st->codecpar->channels <= 0) {
+            if (st->codecpar->ch_layout.nb_channels <= 0) {
                 av_log(s, AV_LOG_ERROR, "Invalid number of channels\n");
                 return AVERROR_INVALIDDATA;
             }
@@ -192,15 +193,15 @@ static int vqf_read_header(AVFormatContext *s)
         break;
     }
 
-    if (read_bitrate / st->codecpar->channels <  8 ||
-        read_bitrate / st->codecpar->channels > 48) {
+    if (read_bitrate / st->codecpar->ch_layout.nb_channels <  8 ||
+        read_bitrate / st->codecpar->ch_layout.nb_channels > 48) {
         av_log(s, AV_LOG_ERROR, "Invalid bitrate per channel %d\n",
-               read_bitrate / st->codecpar->channels);
+               read_bitrate / st->codecpar->ch_layout.nb_channels);
         return AVERROR_INVALIDDATA;
     }
 
     switch (((st->codecpar->sample_rate/1000) << 8) +
-            read_bitrate/st->codecpar->channels) {
+            read_bitrate/st->codecpar->ch_layout.nb_channels) {
     case (11<<8) + 8 :
     case (8 <<8) + 8 :
     case (11<<8) + 10:
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 167/281] wav: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (167 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 166/281] vqf: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 168/281] wc3movie: " James Almer
                   ` (113 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/wavdec.c | 32 +++++++++++++++++---------------
 libavformat/wavenc.c | 14 +++++++-------
 2 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index 01090b6947..74f7a4d9aa 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -221,9 +221,11 @@ static int wav_parse_xma2_tag(AVFormatContext *s, int64_t size, AVStream *st)
         channels += avio_r8(pb);
         avio_skip(pb, 3);
     }
-    st->codecpar->channels = channels;
+    av_channel_layout_uninit(&st->codecpar->ch_layout);
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = channels;
 
-    if (st->codecpar->channels <= 0 || st->codecpar->sample_rate <= 0)
+    if (st->codecpar->ch_layout.nb_channels <= 0 || st->codecpar->sample_rate <= 0)
         return AVERROR_INVALIDDATA;
 
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
@@ -611,15 +613,15 @@ break_loop:
 
     if (   st->codecpar->bit_rate > 0 && data_size > 0
         && st->codecpar->sample_rate > 0
-        && sample_count > 0 && st->codecpar->channels > 1
-        && sample_count % st->codecpar->channels == 0) {
-        if (fabs(8.0 * data_size * st->codecpar->channels * st->codecpar->sample_rate /
+        && sample_count > 0 && st->codecpar->ch_layout.nb_channels > 1
+        && sample_count % st->codecpar->ch_layout.nb_channels == 0) {
+        if (fabs(8.0 * data_size * st->codecpar->ch_layout.nb_channels * st->codecpar->sample_rate /
             sample_count /st->codecpar->bit_rate - 1.0) < 0.3)
-            sample_count /= st->codecpar->channels;
+            sample_count /= st->codecpar->ch_layout.nb_channels;
     }
 
-    if (   data_size > 0 && sample_count && st->codecpar->channels
-        && (data_size << 3) / sample_count / st->codecpar->channels > st->codecpar->bits_per_coded_sample  + 1) {
+    if (data_size > 0 && sample_count && st->codecpar->ch_layout.nb_channels &&
+        (data_size << 3) / sample_count / st->codecpar->ch_layout.nb_channels > st->codecpar->bits_per_coded_sample  + 1) {
         av_log(s, AV_LOG_WARNING, "ignoring wrong sample_count %"PRId64"\n", sample_count);
         sample_count = 0;
     }
@@ -632,34 +634,34 @@ break_loop:
     }
 
     if (!sample_count || av_get_exact_bits_per_sample(st->codecpar->codec_id) > 0)
-        if (   st->codecpar->channels
+        if (   st->codecpar->ch_layout.nb_channels
             && data_size
             && av_get_bits_per_sample(st->codecpar->codec_id)
             && wav->data_end <= avio_size(pb))
             sample_count = (data_size << 3)
                                   /
-                (st->codecpar->channels * (uint64_t)av_get_bits_per_sample(st->codecpar->codec_id));
+                (st->codecpar->ch_layout.nb_channels * (uint64_t)av_get_bits_per_sample(st->codecpar->codec_id));
 
     if (sample_count)
         st->duration = sample_count;
 
     if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S32LE &&
-        st->codecpar->block_align == st->codecpar->channels * 4 &&
+        st->codecpar->block_align == st->codecpar->ch_layout.nb_channels * 4 &&
         st->codecpar->bits_per_coded_sample == 32 &&
         st->codecpar->extradata_size == 2 &&
         AV_RL16(st->codecpar->extradata) == 1) {
         st->codecpar->codec_id = AV_CODEC_ID_PCM_F16LE;
         st->codecpar->bits_per_coded_sample = 16;
     } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE &&
-               st->codecpar->block_align == st->codecpar->channels * 4 &&
+               st->codecpar->block_align == st->codecpar->ch_layout.nb_channels * 4 &&
                st->codecpar->bits_per_coded_sample == 24) {
         st->codecpar->codec_id = AV_CODEC_ID_PCM_F24LE;
     } else if (st->codecpar->codec_id == AV_CODEC_ID_XMA1 ||
                st->codecpar->codec_id == AV_CODEC_ID_XMA2) {
         st->codecpar->block_align = 2048;
-    } else if (st->codecpar->codec_id == AV_CODEC_ID_ADPCM_MS && st->codecpar->channels > 2 &&
-               st->codecpar->block_align < INT_MAX / st->codecpar->channels) {
-        st->codecpar->block_align *= st->codecpar->channels;
+    } else if (st->codecpar->codec_id == AV_CODEC_ID_ADPCM_MS && st->codecpar->ch_layout.nb_channels > 2 &&
+               st->codecpar->block_align < INT_MAX / st->codecpar->ch_layout.nb_channels) {
+        st->codecpar->block_align *= st->codecpar->ch_layout.nb_channels;
     }
 
     ff_metadata_conv_ctx(s, NULL, wav_metadata_conv);
diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c
index 2317700be1..5629bd487d 100644
--- a/libavformat/wavenc.c
+++ b/libavformat/wavenc.c
@@ -170,12 +170,12 @@ static av_cold int peak_init_writer(AVFormatContext *s)
                "Writing 16 bit peak for 8 bit audio does not make sense\n");
         return AVERROR(EINVAL);
     }
-    if (par->channels > INT_MAX / (wav->peak_bps * wav->peak_ppv))
+    if (par->ch_layout.nb_channels > INT_MAX / (wav->peak_bps * wav->peak_ppv))
         return AVERROR(ERANGE);
-    wav->size_increment = par->channels * wav->peak_bps * wav->peak_ppv;
+    wav->size_increment = par->ch_layout.nb_channels * wav->peak_bps * wav->peak_ppv;
 
-    wav->peak_maxpos = av_calloc(par->channels, sizeof(*wav->peak_maxpos));
-    wav->peak_maxneg = av_calloc(par->channels, sizeof(*wav->peak_maxneg));
+    wav->peak_maxpos = av_calloc(par->ch_layout.nb_channels, sizeof(*wav->peak_maxpos));
+    wav->peak_maxneg = av_calloc(par->ch_layout.nb_channels, sizeof(*wav->peak_maxneg));
     if (!wav->peak_maxpos || !wav->peak_maxneg)
         goto nomem;
 
@@ -205,7 +205,7 @@ static int peak_write_frame(AVFormatContext *s)
     }
     wav->peak_output = tmp;
 
-    for (c = 0; c < par->channels; c++) {
+    for (c = 0; c < par->ch_layout.nb_channels; c++) {
         wav->peak_maxneg[c] = -wav->peak_maxneg[c];
 
         if (wav->peak_bps == 2 && wav->peak_format == PEAK_FORMAT_UINT8) {
@@ -277,7 +277,7 @@ static int peak_write_chunk(AVFormatContext *s)
     avio_wl32(pb, wav->peak_format);            /* 8 or 16 bit */
     avio_wl32(pb, wav->peak_ppv);               /* positive and negative */
     avio_wl32(pb, wav->peak_block_size);        /* frames per value */
-    avio_wl32(pb, par->channels);               /* number of channels */
+    avio_wl32(pb, par->ch_layout.nb_channels);  /* number of channels */
     avio_wl32(pb, wav->peak_num_frames);        /* number of peak frames */
     avio_wl32(pb, -1);                          /* audio sample frame position (not implemented) */
     avio_wl32(pb, 128);                         /* equal to size of header */
@@ -384,7 +384,7 @@ static int wav_write_packet(AVFormatContext *s, AVPacket *pkt)
                 wav->peak_maxpos[c] = FFMAX(wav->peak_maxpos[c], (int16_t)AV_RL16(pkt->data + i));
                 wav->peak_maxneg[c] = FFMIN(wav->peak_maxneg[c], (int16_t)AV_RL16(pkt->data + i));
             }
-            if (++c == s->streams[0]->codecpar->channels) {
+            if (++c == s->streams[0]->codecpar->ch_layout.nb_channels) {
                 c = 0;
                 if (++wav->peak_block_pos == wav->peak_block_size) {
                     int ret = peak_write_frame(s);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 168/281] wc3movie: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (168 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 167/281] wav: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 169/281] westwood: " James Almer
                   ` (112 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/wc3movie.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c
index fe2d0d4245..8f5c2f18cd 100644
--- a/libavformat/wc3movie.c
+++ b/libavformat/wc3movie.c
@@ -54,7 +54,6 @@
 
 /* always use the same PCM audio parameters */
 #define WC3_SAMPLE_RATE 22050
-#define WC3_AUDIO_CHANNELS 1
 #define WC3_AUDIO_BITS 16
 
 /* nice, constant framerate */
@@ -195,13 +194,12 @@ static int wc3_read_header(AVFormatContext *s)
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
     st->codecpar->codec_tag = 1;
-    st->codecpar->channels = WC3_AUDIO_CHANNELS;
-    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     st->codecpar->bits_per_coded_sample = WC3_AUDIO_BITS;
     st->codecpar->sample_rate = WC3_SAMPLE_RATE;
-    st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate *
+    st->codecpar->bit_rate = st->codecpar->ch_layout.nb_channels * st->codecpar->sample_rate *
         st->codecpar->bits_per_coded_sample;
-    st->codecpar->block_align = WC3_AUDIO_BITS * WC3_AUDIO_CHANNELS;
+    st->codecpar->block_align = WC3_AUDIO_BITS * st->codecpar->ch_layout.nb_channels;
 
     return 0;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 169/281] westwood: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (169 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 168/281] wc3movie: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 170/281] wtv: " James Almer
                   ` (111 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/westwood_aud.c    | 10 ++++------
 libavformat/westwood_audenc.c |  2 +-
 libavformat/westwood_vqa.c    |  2 +-
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/libavformat/westwood_aud.c b/libavformat/westwood_aud.c
index ff51e8bd36..9896bd46df 100644
--- a/libavformat/westwood_aud.c
+++ b/libavformat/westwood_aud.c
@@ -118,9 +118,7 @@ static int wsaud_read_header(AVFormatContext *s)
     }
     avpriv_set_pts_info(st, 64, 1, sample_rate);
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->channels    = channels;
-    st->codecpar->channel_layout = channels == 1 ? AV_CH_LAYOUT_MONO :
-                                                   AV_CH_LAYOUT_STEREO;
+    av_channel_layout_default(&st->codecpar->ch_layout, channels);
     st->codecpar->sample_rate = sample_rate;
 
     return 0;
@@ -164,14 +162,14 @@ static int wsaud_read_packet(AVFormatContext *s,
         if (ret != chunk_size)
             return AVERROR(EIO);
 
-        if (st->codecpar->channels <= 0) {
+        if (st->codecpar->ch_layout.nb_channels <= 0) {
             av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n",
-                   st->codecpar->channels);
+                   st->codecpar->ch_layout.nb_channels);
             return AVERROR_INVALIDDATA;
         }
 
         /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */
-        pkt->duration = (chunk_size * 2) / st->codecpar->channels;
+        pkt->duration = (chunk_size * 2) / st->codecpar->ch_layout.nb_channels;
     }
     pkt->stream_index = st->index;
 
diff --git a/libavformat/westwood_audenc.c b/libavformat/westwood_audenc.c
index 597d68350f..a2401eff5a 100644
--- a/libavformat/westwood_audenc.c
+++ b/libavformat/westwood_audenc.c
@@ -77,7 +77,7 @@ static int wsaud_write_header(AVFormatContext *ctx)
     a->size = 0;
 
     /* Flag if we have stereo data. */
-    if (st->codecpar->channels == 2)
+    if (st->codecpar->ch_layout.nb_channels == 2)
         flags |= 1;
 
     /* This flags that the file contains 16 bit samples rather than 8 bit
diff --git a/libavformat/westwood_vqa.c b/libavformat/westwood_vqa.c
index 9d116060a3..ed5c1a3416 100644
--- a/libavformat/westwood_vqa.c
+++ b/libavformat/westwood_vqa.c
@@ -226,7 +226,7 @@ static int wsvqa_read_packet(AVFormatContext *s,
                         wsvqa->bps = 8;
                     st->codecpar->sample_rate = wsvqa->sample_rate;
                     st->codecpar->bits_per_coded_sample = wsvqa->bps;
-                    st->codecpar->channels = wsvqa->channels;
+                    av_channel_layout_default(&st->codecpar->ch_layout, wsvqa->channels);
                     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
 
                     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 170/281] wtv: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (170 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 169/281] westwood: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 171/281] wv: " James Almer
                   ` (110 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/wtvdec.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
index 22e4c92565..087b44273e 100644
--- a/libavformat/wtvdec.c
+++ b/libavformat/wtvdec.c
@@ -584,11 +584,9 @@ static void parse_mpeg1waveformatex(AVStream *st)
     switch (AV_RL16(st->codecpar->extradata + 6)) {
     case 1 :
     case 2 :
-    case 4 : st->codecpar->channels       = 2;
-             st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+    case 4 : st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
              break;
-    case 8 : st->codecpar->channels       = 1;
-             st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+    case 8 : st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
              break;
     }
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 171/281] wv: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (171 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 170/281] wtv: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 172/281] xa: " James Almer
                   ` (109 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/wvdec.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/wvdec.c b/libavformat/wvdec.c
index 0d5a86953d..61a683a85e 100644
--- a/libavformat/wvdec.c
+++ b/libavformat/wvdec.c
@@ -256,8 +256,7 @@ static int wv_read_header(AVFormatContext *s)
     AV_WL16(st->codecpar->extradata, wc->header.version);
     st->codecpar->codec_type            = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id              = AV_CODEC_ID_WAVPACK;
-    st->codecpar->channels              = wc->chan;
-    st->codecpar->channel_layout        = wc->chmask;
+    av_channel_layout_from_mask(&st->codecpar->ch_layout, wc->chmask);
     st->codecpar->sample_rate           = wc->rate;
     st->codecpar->bits_per_coded_sample = wc->bpp;
     avpriv_set_pts_info(st, 64, 1, wc->rate);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 172/281] xa: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (172 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 171/281] wv: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 173/281] xmv: " James Almer
                   ` (108 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/xa.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavformat/xa.c b/libavformat/xa.c
index 762e90246a..af99c1f327 100644
--- a/libavformat/xa.c
+++ b/libavformat/xa.c
@@ -78,16 +78,17 @@ static int xa_read_header(AVFormatContext *s)
     avio_skip(pb, 4);       /* Skip the XA ID */
     xa->out_size            =  avio_rl32(pb);
     avio_skip(pb, 2);       /* Skip the tag */
-    st->codecpar->channels     = avio_rl16(pb);
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_rl16(pb);
     st->codecpar->sample_rate  = avio_rl32(pb);
     avio_skip(pb, 4);       /* Skip average byte rate */
     avio_skip(pb, 2);       /* Skip block align */
     avio_skip(pb, 2);       /* Skip bits-per-sample */
 
-    if (!st->codecpar->channels || !st->codecpar->sample_rate)
+    if (!st->codecpar->ch_layout.nb_channels || !st->codecpar->sample_rate)
         return AVERROR_INVALIDDATA;
 
-    st->codecpar->bit_rate = av_clip(15LL * st->codecpar->channels * 8 *
+    st->codecpar->bit_rate = av_clip(15LL * st->codecpar->ch_layout.nb_channels * 8 *
                                   st->codecpar->sample_rate / 28, 0, INT_MAX);
 
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
@@ -108,7 +109,7 @@ static int xa_read_packet(AVFormatContext *s,
     if (xa->sent_bytes >= xa->out_size)
         return AVERROR_EOF;
     /* 1 byte header and 14 bytes worth of samples * number channels per block */
-    packet_size = 15*st->codecpar->channels;
+    packet_size = 15*st->codecpar->ch_layout.nb_channels;
 
     ret = av_get_packet(pb, pkt, packet_size);
     if(ret < 0)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 173/281] xmv: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (173 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 172/281] xa: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 174/281] xwma: " James Almer
                   ` (107 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/xmv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/xmv.c b/libavformat/xmv.c
index ec21a4f853..fd0dedb637 100644
--- a/libavformat/xmv.c
+++ b/libavformat/xmv.c
@@ -332,7 +332,8 @@ static int xmv_process_packet_header(AVFormatContext *s)
             ast->codecpar->codec_type            = AVMEDIA_TYPE_AUDIO;
             ast->codecpar->codec_id              = packet->codec_id;
             ast->codecpar->codec_tag             = packet->compression;
-            ast->codecpar->channels              = packet->channels;
+            ast->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            ast->codecpar->ch_layout.nb_channels = packet->channels;
             ast->codecpar->sample_rate           = packet->sample_rate;
             ast->codecpar->bits_per_coded_sample = packet->bits_per_sample;
             ast->codecpar->bit_rate              = packet->bit_rate;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 174/281] xwma: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (174 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 173/281] xmv: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 175/281] yop: " James Almer
                   ` (106 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/xwma.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavformat/xwma.c b/libavformat/xwma.c
index 37ab3a1ec0..c16ff1be63 100644
--- a/libavformat/xwma.c
+++ b/libavformat/xwma.c
@@ -85,7 +85,7 @@ static int xwma_read_header(AVFormatContext *s)
      * 20/48/192kbps are all 20kbps, with the exact same codec data).
      * Decoder needs correct bitrate to work, so it's normalized here. */
     if (st->codecpar->codec_id == AV_CODEC_ID_WMAV2) {
-        int ch = st->codecpar->channels;
+        int ch = st->codecpar->ch_layout.nb_channels;
         int sr = st->codecpar->sample_rate;
         int br = st->codecpar->bit_rate;
 
@@ -146,9 +146,9 @@ static int xwma_read_header(AVFormatContext *s)
         }
     }
 
-    if (!st->codecpar->channels) {
+    if (!av_channel_layout_check(&st->codecpar->ch_layout)) {
         av_log(s, AV_LOG_WARNING, "Invalid channel count: %d\n",
-               st->codecpar->channels);
+               st->codecpar->ch_layout.nb_channels);
         return AVERROR_INVALIDDATA;
     }
     if (!st->codecpar->bits_per_coded_sample) {
@@ -236,7 +236,7 @@ static int xwma_read_header(AVFormatContext *s)
     if (dpds_table && dpds_table_size) {
         int64_t cur_pos;
         const uint32_t bytes_per_sample
-                = (st->codecpar->channels * st->codecpar->bits_per_coded_sample) >> 3;
+                = (st->codecpar->ch_layout.nb_channels * st->codecpar->bits_per_coded_sample) >> 3;
 
         /* Estimate the duration from the total number of output bytes. */
         const uint64_t total_decoded_bytes = dpds_table[dpds_table_size - 1];
@@ -244,7 +244,7 @@ static int xwma_read_header(AVFormatContext *s)
         if (!bytes_per_sample) {
             av_log(s, AV_LOG_ERROR,
                    "Invalid bits_per_coded_sample %d for %d channels\n",
-                   st->codecpar->bits_per_coded_sample, st->codecpar->channels);
+                   st->codecpar->bits_per_coded_sample, st->codecpar->ch_layout.nb_channels);
             ret = AVERROR_INVALIDDATA;
             goto fail;
         }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 175/281] yop: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (175 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 174/281] xwma: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 176/281] wsd: " James Almer
                   ` (105 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/yop.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/yop.c b/libavformat/yop.c
index f65e4f8b16..b0aa0bb64b 100644
--- a/libavformat/yop.c
+++ b/libavformat/yop.c
@@ -72,8 +72,7 @@ static int yop_read_header(AVFormatContext *s)
     audio_par                 = audio_stream->codecpar;
     audio_par->codec_type     = AVMEDIA_TYPE_AUDIO;
     audio_par->codec_id       = AV_CODEC_ID_ADPCM_IMA_APC;
-    audio_par->channels       = 1;
-    audio_par->channel_layout = AV_CH_LAYOUT_MONO;
+    audio_par->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     audio_par->sample_rate    = 22050;
 
     // Video
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 176/281] wsd: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (176 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 175/281] yop: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 177/281] wve: " James Almer
                   ` (104 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/wsddec.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavformat/wsddec.c b/libavformat/wsddec.c
index 1f90f5b467..a8754f84e4 100644
--- a/libavformat/wsddec.c
+++ b/libavformat/wsddec.c
@@ -128,18 +128,22 @@ static int wsd_read_header(AVFormatContext *s)
     st->codecpar->codec_id    = s->iformat->raw_codec_id;
     st->codecpar->sample_rate = avio_rb32(pb) / 8;
     avio_skip(pb, 4);
-    st->codecpar->channels    = avio_r8(pb) & 0xF;
-    st->codecpar->bit_rate    = (int64_t)st->codecpar->channels * st->codecpar->sample_rate * 8LL;
-    if (!st->codecpar->channels)
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = avio_r8(pb) & 0xF;
+    st->codecpar->bit_rate    = (int64_t)st->codecpar->ch_layout.nb_channels *
+                                st->codecpar->sample_rate * 8LL;
+    if (!st->codecpar->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
 
     avio_skip(pb, 3);
     channel_assign         = avio_rb32(pb);
     if (!(channel_assign & 1)) {
+        uint64_t ch_mask = 0;
         int i;
         for (i = 1; i < 32; i++)
             if ((channel_assign >> i) & 1)
-                st->codecpar->channel_layout |= wsd_to_av_channel_layoyt(s, i);
+                ch_mask |= wsd_to_av_channel_layoyt(s, i);
+        av_channel_layout_from_mask(&st->codecpar->ch_layout, ch_mask);
     }
 
     avio_skip(pb, 16);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 177/281] wve: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (177 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 176/281] wsd: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 178/281] xvag: " James Almer
                   ` (103 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/wvedec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/wvedec.c b/libavformat/wvedec.c
index f133da3c87..9b2f7036e0 100644
--- a/libavformat/wvedec.c
+++ b/libavformat/wvedec.c
@@ -43,9 +43,11 @@ static int wve_read_header(AVFormatContext *s)
     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
     st->codecpar->codec_id    = AV_CODEC_ID_PCM_ALAW;
     st->codecpar->sample_rate = 8000;
-    st->codecpar->channels    = 1;
+    st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    st->codecpar->ch_layout.nb_channels = 1;
     st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id);
-    st->codecpar->block_align = st->codecpar->bits_per_coded_sample * st->codecpar->channels / 8;
+    st->codecpar->block_align = st->codecpar->bits_per_coded_sample *
+                                st->codecpar->ch_layout.nb_channels / 8;
     avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
     avio_skip(s->pb, 10);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 178/281] xvag: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (178 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 177/281] wve: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 179/281] lavf: drop the channel layout compat layer for old-style (de)muxers James Almer
                   ` (102 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/xvag.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavformat/xvag.c b/libavformat/xvag.c
index 994b710f8d..61f33ddaf8 100644
--- a/libavformat/xvag.c
+++ b/libavformat/xvag.c
@@ -45,6 +45,7 @@ static int xvag_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
 
     st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
 
     offset     = avio_rl32(s->pb);
     big_endian = offset > av_bswap32(offset);
@@ -52,7 +53,7 @@ static int xvag_read_header(AVFormatContext *s)
         offset                 = av_bswap32(offset);
         avio_skip(s->pb, 28);
         codec                  = avio_rb32(s->pb);
-        st->codecpar->channels = avio_rb32(s->pb);
+        st->codecpar->ch_layout.nb_channels = avio_rb32(s->pb);
         avio_skip(s->pb, 4);
         st->duration           = avio_rb32(s->pb);
         avio_skip(s->pb, 8);
@@ -60,7 +61,7 @@ static int xvag_read_header(AVFormatContext *s)
     } else {
         avio_skip(s->pb, 28);
         codec                  = avio_rl32(s->pb);
-        st->codecpar->channels = avio_rl32(s->pb);
+        st->codecpar->ch_layout.nb_channels = avio_rl32(s->pb);
         avio_skip(s->pb, 4);
         st->duration           = avio_rl32(s->pb);
         avio_skip(s->pb, 8);
@@ -69,13 +70,14 @@ static int xvag_read_header(AVFormatContext *s)
 
     if (st->codecpar->sample_rate <= 0)
         return AVERROR_INVALIDDATA;
-    if (st->codecpar->channels <= 0 || st->codecpar->channels > FF_SANE_NB_CHANNELS)
+    if (st->codecpar->ch_layout.nb_channels <= 0 ||
+        st->codecpar->ch_layout.nb_channels > FF_SANE_NB_CHANNELS)
         return AVERROR_INVALIDDATA;
 
     switch (codec) {
     case 0x1c:
         st->codecpar->codec_id    = AV_CODEC_ID_ADPCM_PSX;
-        st->codecpar->block_align = 16 * st->codecpar->channels;
+        st->codecpar->block_align = 16 * st->codecpar->ch_layout.nb_channels;
         break;
     default:
         avpriv_request_sample(s, "codec %X", codec);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 179/281] lavf: drop the channel layout compat layer for old-style (de)muxers
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (179 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 178/281] xvag: " James Almer
@ 2022-01-13  2:00 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 180/281] lavc: switch to the new channel layout API James Almer
                   ` (101 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:00 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

All the (de)muxers have been converted to the new API.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/demux.c | 12 ------------
 libavformat/mux.c   |  9 ---------
 2 files changed, 21 deletions(-)

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 29c5f7539c..a9682a5949 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -194,18 +194,6 @@ static int update_stream_avctx(AVFormatContext *s)
             sti->parser = NULL;
         }
 
-        /* if the demuxer exports old channel layouts, convert it to new */
-        if (!st->codecpar->ch_layout.nb_channels &&
-            st->codecpar->channels) {
-            if (st->codecpar->channel_layout) {
-                av_channel_layout_from_mask(&st->codecpar->ch_layout,
-                                            st->codecpar->channel_layout);
-            } else {
-                st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
-                st->codecpar->ch_layout.nb_channels = st->codecpar->channels;
-            }
-        }
-
 #if FF_API_OLD_CHANNEL_LAYOUT
 FF_DISABLE_DEPRECATION_WARNINGS
         if (st->codecpar->ch_layout.nb_channels &&
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 68983c773f..e68738e5c6 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -273,15 +273,6 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options)
                 goto fail;
             }
 
-            /* if the new-style channel layout is set, convert it to old one
-             * for old-style muxers */
-            if (par->ch_layout.nb_channels &&
-                !par->channels) {
-                par->channels       = par->ch_layout.nb_channels;
-                par->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
-                                      par->ch_layout.u.mask : 0;
-            }
-
 #if FF_API_OLD_CHANNEL_LAYOUT
 FF_DISABLE_DEPRECATION_WARNINGS
             /* if the caller is using the deprecated channel layout API,
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 180/281] lavc: switch to the new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (180 preceding siblings ...)
  2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 179/281] lavf: drop the channel layout compat layer for old-style (de)muxers James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 181/281] 8svx: convert to " James Almer
                   ` (100 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

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

Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/avcodec.c       | 82 +++++++++++++++++++++++++++++----
 libavcodec/avcodec.h       | 24 +++++++++-
 libavcodec/codec.h         | 11 +++++
 libavcodec/codec_par.c     | 52 ++++++++++++++++-----
 libavcodec/decode.c        | 94 ++++++++++++++++++++++++++++----------
 libavcodec/encode.c        | 36 ++++++++++++---
 libavcodec/internal.h      |  3 ++
 libavcodec/options.c       |  2 +
 libavcodec/options_table.h |  5 ++
 libavcodec/pthread_frame.c | 10 +++-
 libavcodec/utils.c         | 12 ++++-
 libavformat/demux.c        |  2 +-
 12 files changed, 278 insertions(+), 55 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index c00a9b2af8..0436a6d0bd 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -119,7 +119,7 @@ static int64_t get_bit_rate(AVCodecContext *ctx)
     case AVMEDIA_TYPE_AUDIO:
         bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
         if (bits_per_sample) {
-            bit_rate = ctx->sample_rate * (int64_t)ctx->channels;
+            bit_rate = ctx->sample_rate * (int64_t)ctx->ch_layout.nb_channels;
             if (bit_rate > INT64_MAX / bits_per_sample) {
                 bit_rate = 0;
             } else
@@ -137,6 +137,8 @@ static int64_t get_bit_rate(AVCodecContext *ctx)
 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
 {
     int ret = 0;
+    int orig_channels;
+    uint64_t orig_channel_layout;
     AVCodecInternal *avci;
 
     if (avcodec_is_open(avctx))
@@ -247,12 +249,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
         }
     }
 
-    if (avctx->channels > FF_SANE_NB_CHANNELS || avctx->channels < 0) {
-        av_log(avctx, AV_LOG_ERROR, "Too many or invalid channels: %d\n", avctx->channels);
-        ret = AVERROR(EINVAL);
-        goto free_and_end;
-    }
-
     if (avctx->sample_rate < 0) {
         av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate);
         ret = AVERROR(EINVAL);
@@ -264,6 +260,38 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
         goto free_and_end;
     }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    /* compat wrapper for old-style callers */
+    if (avctx->channel_layout && !avctx->channels)
+        avctx->channels = av_popcount64(avctx->channel_layout);
+
+    if ((avctx->channels && avctx->channels != avctx->ch_layout.nb_channels) ||
+        (avctx->channel_layout && avctx->ch_layout.order != AV_CHANNEL_ORDER_NATIVE)) {
+        if (avctx->channel_layout) {
+            av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout);
+        } else {
+            avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            avctx->ch_layout.nb_channels = avctx->channels;
+        }
+    }
+
+    /* temporary compat wrapper for new-style callers and old-style codecs;
+     * to be removed once all the codecs have been converted */
+    if (avctx->ch_layout.nb_channels) {
+        avctx->channels = avctx->ch_layout.nb_channels;
+        avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                avctx->ch_layout.u.mask : 0;
+    }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+    if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
+        av_log(avctx, AV_LOG_ERROR, "Too many channels: %d\n", avctx->ch_layout.nb_channels);
+        ret = AVERROR(EINVAL);
+        goto free_and_end;
+    }
+
     avctx->frame_number = 0;
     avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id);
 
@@ -317,6 +345,13 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
     if (!HAVE_THREADS && !(codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS))
         avctx->thread_count = 1;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    orig_channels = avctx->channels;
+    orig_channel_layout = avctx->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
     if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
         avci->frame_thread_encoder) {
         if (avctx->codec->init) {
@@ -334,6 +369,26 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
     if (av_codec_is_decoder(avctx->codec)) {
         if (!avctx->bit_rate)
             avctx->bit_rate = get_bit_rate(avctx);
+
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        /* decoder setting the old-style fields */
+        if (avctx->channels != orig_channels ||
+            avctx->channel_layout != orig_channel_layout) {
+            av_channel_layout_uninit(&avctx->ch_layout);
+            if (avctx->channel_layout) {
+                av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout);
+            } else {
+                avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+                avctx->ch_layout.nb_channels = avctx->channels;
+            }
+        }
+
+        /* update the deprecated fields for old-style callers */
+        avctx->channels = avctx->ch_layout.nb_channels;
+        avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                avctx->ch_layout.u.mask : 0;
+
         /* validate channel layout from the decoder */
         if (avctx->channel_layout) {
             int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
@@ -358,6 +413,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
             ret = AVERROR(EINVAL);
             goto free_and_end;
         }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 #if FF_API_AVCTX_TIMEBASE
         if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
@@ -484,9 +541,13 @@ av_cold int avcodec_close(AVCodecContext *avctx)
 
         av_bsf_free(&avci->bsf);
 
+        av_channel_layout_uninit(&avci->initial_ch_layout);
+
         av_freep(&avctx->internal);
     }
 
+    av_channel_layout_uninit(&avctx->ch_layout);
+
     for (i = 0; i < avctx->nb_coded_side_data; i++)
         av_freep(&avctx->coded_side_data[i].data);
     av_freep(&avctx->coded_side_data);
@@ -666,7 +727,12 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
         if (enc->sample_rate) {
             av_bprintf(&bprint, "%d Hz, ", enc->sample_rate);
         }
-        av_bprint_channel_layout(&bprint, enc->channels, enc->channel_layout);
+        {
+            char buf[512];
+            int ret = av_channel_layout_describe(&enc->ch_layout, buf, sizeof(buf));
+            if (ret >= 0)
+                av_bprintf(&bprint, "%s", buf);
+        }
         if (enc->sample_fmt != AV_SAMPLE_FMT_NONE &&
             (str = av_get_sample_fmt_name(enc->sample_fmt))) {
             av_bprintf(&bprint, ", %s", str);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ec1a0566a4..8c72c77985 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -990,7 +990,15 @@ typedef struct AVCodecContext {
 
     /* audio only */
     int sample_rate; ///< samples per second
-    int channels;    ///< number of audio channels
+
+#if FF_API_OLD_CHANNEL_LAYOUT
+    /**
+     * number of audio channels
+     * @deprecated use ch_layout.nb_channels
+     */
+    attribute_deprecated
+    int channels;
+#endif
 
     /**
      * audio sample format
@@ -1035,19 +1043,25 @@ typedef struct AVCodecContext {
      */
     int cutoff;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
     /**
      * Audio channel layout.
      * - encoding: set by user.
      * - decoding: set by user, may be overwritten 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.
@@ -2024,6 +2038,14 @@ typedef struct AVCodecContext {
      * - decoding: unused
      */
     int (*get_encode_buffer)(struct AVCodecContext *s, AVPacket *pkt, int 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;
 
 struct MpegEncContext;
diff --git a/libavcodec/codec.h b/libavcodec/codec.h
index a8147ec21f..204a558798 100644
--- a/libavcodec/codec.h
+++ b/libavcodec/codec.h
@@ -224,7 +224,13 @@ 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}
 
@@ -240,6 +246,11 @@ typedef struct AVCodec {
      */
     const char *wrapper_name;
 
+    /**
+     * 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/codec_par.c b/libavcodec/codec_par.c
index 9d43af1db4..052c64a315 100644
--- a/libavcodec/codec_par.c
+++ b/libavcodec/codec_par.c
@@ -125,11 +125,25 @@ int avcodec_parameters_from_context(AVCodecParameters *par,
         break;
     case AVMEDIA_TYPE_AUDIO:
         par->format           = codec->sample_fmt;
-        if (codec->channel_layout)
-            av_channel_layout_from_mask(&par->ch_layout, codec->channel_layout);
-        else {
-            par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
-            par->ch_layout.nb_channels = codec->channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        // if the old/new fields are set inconsistently, prefer the old ones
+        if ((codec->channels && codec->channels != codec->ch_layout.nb_channels) ||
+            (codec->channel_layout && (codec->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
+                                       codec->ch_layout.u.mask != codec->channel_layout))) {
+            if (codec->channel_layout)
+                av_channel_layout_from_mask(&par->ch_layout, codec->channel_layout);
+            else {
+                par->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+                par->ch_layout.nb_channels = codec->channels;
+            }
+FF_ENABLE_DEPRECATION_WARNINGS
+        } else
+#endif
+        if (codec->ch_layout.nb_channels) {
+            int ret = av_channel_layout_copy(&par->ch_layout, &codec->ch_layout);
+            if (ret < 0)
+                return ret;
         }
 #if FF_API_OLD_CHANNEL_LAYOUT
 FF_DISABLE_DEPRECATION_WARNINGS
@@ -191,18 +205,32 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
         break;
     case AVMEDIA_TYPE_AUDIO:
         codec->sample_fmt       = par->format;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        // if the old/new fields are set inconsistently, prefer the old ones
+        if ((par->channels && par->channels != par->ch_layout.nb_channels) ||
+            (par->channel_layout && (par->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
+                                     par->ch_layout.u.mask != par->channel_layout))) {
+            if (par->channel_layout)
+                av_channel_layout_from_mask(&codec->ch_layout, par->channel_layout);
+            else {
+                codec->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+                codec->ch_layout.nb_channels = par->channels;
+            }
+FF_ENABLE_DEPRECATION_WARNINGS
+        } else
+#endif
         if (par->ch_layout.nb_channels) {
-            codec->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
-                                    par->ch_layout.u.mask : 0;
-            codec->channels       = par->ch_layout.nb_channels;
+            int ret = av_channel_layout_copy(&codec->ch_layout, &par->ch_layout);
+            if (ret < 0)
+                return ret;
         }
 #if FF_API_OLD_CHANNEL_LAYOUT
-        else {
 FF_DISABLE_DEPRECATION_WARNINGS
-            codec->channel_layout = par->channel_layout;
-            codec->channels       = par->channels;
+        codec->channel_layout = codec->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                codec->ch_layout.u.mask : 0;
+        codec->channels       = codec->ch_layout.nb_channels;
 FF_ENABLE_DEPRECATION_WARNINGS
-        }
 #endif
         codec->sample_rate      = par->sample_rate;
         codec->block_align      = par->block_align;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 60127e95fc..6381ec68e1 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -359,10 +359,14 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
         if (ret >= 0 && got_frame) {
             if (frame->format == AV_SAMPLE_FMT_NONE)
                 frame->format = avctx->sample_fmt;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             if (!frame->channel_layout)
                 frame->channel_layout = avctx->channel_layout;
             if (!frame->channels)
                 frame->channels = avctx->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             if (!frame->sample_rate)
                 frame->sample_rate = avctx->sample_rate;
         }
@@ -394,7 +398,7 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
                        avci->skip_samples);
             } else {
                 av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples,
-                                frame->nb_samples - avci->skip_samples, avctx->channels, frame->format);
+                                frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
                 if(avctx->pkt_timebase.num && avctx->sample_rate) {
                     int64_t diff_ts = av_rescale_q(avci->skip_samples,
                                                    (AVRational){1, avctx->sample_rate},
@@ -683,8 +687,17 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
             case AVMEDIA_TYPE_AUDIO:
                 avci->initial_sample_rate = frame->sample_rate ? frame->sample_rate :
                                                                  avctx->sample_rate;
-                avci->initial_channels       = frame->channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+                avci->initial_channels       = frame->ch_layout.nb_channels;
                 avci->initial_channel_layout = frame->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+                ret = av_channel_layout_copy(&avci->initial_ch_layout, &frame->ch_layout);
+                if (ret < 0) {
+                    av_frame_unref(frame);
+                    return ret;
+                }
                 break;
             }
         }
@@ -698,10 +711,15 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
                            avci->initial_height != frame->height;
                 break;
             case AVMEDIA_TYPE_AUDIO:
+FF_DISABLE_DEPRECATION_WARNINGS
                 changed |= avci->initial_sample_rate    != frame->sample_rate ||
                            avci->initial_sample_rate    != avctx->sample_rate ||
+#if FF_API_OLD_CHANNEL_LAYOUT
                            avci->initial_channels       != frame->channels ||
-                           avci->initial_channel_layout != frame->channel_layout;
+                           avci->initial_channel_layout != frame->channel_layout ||
+#endif
+                           av_channel_layout_compare(&avci->initial_ch_layout, &frame->ch_layout);
+FF_ENABLE_DEPRECATION_WARNINGS
                 break;
             }
 
@@ -1263,7 +1281,13 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
 
     if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
         int planar = av_sample_fmt_is_planar(frame->format);
-        ch     = frame->channels;
+        ch     = frame->ch_layout.nb_channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        if (!ch)
+            ch = frame->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         planes = planar ? ch : 1;
     }
 
@@ -1571,25 +1595,18 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
             frame->sample_rate    = avctx->sample_rate;
         if (frame->format < 0)
             frame->format         = avctx->sample_fmt;
-        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);
-                }
-            }
+        if (!frame->ch_layout.nb_channels) {
+            int ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
+            if (ret < 0)
+                return ret;
         }
-        frame->channels = avctx->channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        frame->channels = frame->ch_layout.nb_channels;
+        frame->channel_layout = frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                frame->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         break;
     }
     return 0;
@@ -1679,7 +1696,36 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
             goto fail;
         }
     } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
-        if (frame->nb_samples * (int64_t)avctx->channels > avctx->max_samples) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        /* temporary compat layer for decoders setting the old-style channel
+         * layout fields; shall be removed after all the decoders are converted
+         * to the new API */
+        if ((avctx->channels > 0 && avctx->ch_layout.nb_channels != avctx->channels) ||
+            (avctx->channel_layout && (avctx->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
+                                       avctx->ch_layout.u.mask != avctx->channel_layout))) {
+            av_channel_layout_uninit(&avctx->ch_layout);
+            if (avctx->channel_layout) {
+                if (av_popcount64(avctx->channel_layout) != avctx->channels) {
+                    av_log(avctx, AV_LOG_ERROR, "Inconsistent channel layout/channels\n");
+                    ret = AVERROR(EINVAL);
+                    goto fail;
+                }
+                av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout);
+            } else {
+                avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+                avctx->ch_layout.nb_channels = avctx->channels;
+            }
+        }
+
+        /* compat layer for old-style get_buffer() implementations */
+        avctx->channels = avctx->ch_layout.nb_channels;
+        avctx->channel_layout = (avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) ?
+                                avctx->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+        if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) {
             av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples);
             ret = AVERROR(EINVAL);
             goto fail;
@@ -1789,7 +1835,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
-    if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && avctx->channels == 0 &&
+    if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && avctx->ch_layout.nb_channels == 0 &&
         !(avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {
         av_log(avctx, AV_LOG_ERROR, "Decoder requires channel count but channels not set\n");
         return AVERROR(EINVAL);
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 618be0573d..f9f8879b8e 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -114,9 +114,10 @@ static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame *src)
     int ret;
 
     frame->format         = src->format;
-    frame->channel_layout = src->channel_layout;
-    frame->channels       = src->channels;
     frame->nb_samples     = s->frame_size;
+    ret = av_channel_layout_copy(&frame->ch_layout, &s->ch_layout);
+    if (ret < 0)
+        goto fail;
     ret = av_frame_get_buffer(frame, 0);
     if (ret < 0)
         goto fail;
@@ -126,11 +127,12 @@ static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame *src)
         goto fail;
 
     if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
-                               src->nb_samples, s->channels, s->sample_fmt)) < 0)
+                               src->nb_samples, s->ch_layout.nb_channels,
+                               s->sample_fmt)) < 0)
         goto fail;
     if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
                                       frame->nb_samples - src->nb_samples,
-                                      s->channels, s->sample_fmt)) < 0)
+                                      s->ch_layout.nb_channels, s->sample_fmt)) < 0)
         goto fail;
 
     return 0;
@@ -419,7 +421,7 @@ int ff_encode_preinit(AVCodecContext *avctx)
         for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
             if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
                 break;
-            if (avctx->channels == 1 &&
+            if (avctx->ch_layout.nb_channels == 1 &&
                 av_get_planar_sample_fmt(avctx->sample_fmt) ==
                 av_get_planar_sample_fmt(avctx->codec->sample_fmts[i])) {
                 avctx->sample_fmt = avctx->codec->sample_fmts[i];
@@ -467,7 +469,27 @@ int ff_encode_preinit(AVCodecContext *avctx)
                 avctx->sample_rate);
         return AVERROR(EINVAL);
     }
-    if (avctx->codec->channel_layouts) {
+    if (avctx->codec->ch_layouts) {
+        if (!av_channel_layout_check(&avctx->ch_layout)) {
+            av_log(avctx, AV_LOG_WARNING, "Channel layout not specified correctly\n");
+            return AVERROR(EINVAL);
+        }
+
+        for (i = 0; avctx->codec->ch_layouts[i].nb_channels; i++) {
+            if (!av_channel_layout_compare(&avctx->ch_layout, &avctx->codec->ch_layouts[i]))
+                break;
+        }
+        if (!avctx->codec->ch_layouts[i].nb_channels) {
+            char buf[512];
+            int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf));
+            if (ret > 0)
+                av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
+            return AVERROR(EINVAL);
+        }
+FF_DISABLE_DEPRECATION_WARNINGS
+    }
+#if FF_API_OLD_CHANNEL_LAYOUT
+    else if (avctx->codec->channel_layouts) {
         if (!avctx->channel_layout) {
             av_log(avctx, AV_LOG_WARNING, "Channel layout not specified\n");
         } else {
@@ -500,6 +522,8 @@ int ff_encode_preinit(AVCodecContext *avctx)
                 avctx->channels);
         return AVERROR(EINVAL);
     }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     if(avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
         const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
         if (    avctx->bits_per_raw_sample < 0
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 72ca1553f6..51d827c1fe 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -208,8 +208,11 @@ typedef struct AVCodecInternal {
     int initial_format;
     int initial_width, initial_height;
     int initial_sample_rate;
+#if FF_API_OLD_CHANNEL_LAYOUT
     int initial_channels;
     uint64_t initial_channel_layout;
+#endif
+    AVChannelLayout initial_ch_layout;
 } AVCodecInternal;
 
 struct AVCodecDefault {
diff --git a/libavcodec/options.c b/libavcodec/options.c
index bba6078b62..c0b874fa05 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -187,7 +187,9 @@ static const AVOption frame_options[]={
 {"width", "", FOFFSET(width), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, 0},
 {"height", "", FOFFSET(height), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, 0},
 {"format", "", FOFFSET(format), AV_OPT_TYPE_INT, {.i64 = -1 }, 0, INT_MAX, 0},
+#if FF_API_OLD_CHANNEL_LAYOUT
 {"channel_layout", "", FOFFSET(channel_layout), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, 0},
+#endif
 {"sample_rate", "", FOFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, 0},
 {NULL},
 };
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 130341a2ec..4dca85747e 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -89,7 +89,9 @@ static const AVOption avcodec_options[] = {
 {"time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, INT_MAX},
 {"g", "set the group of picture (GOP) size", OFFSET(gop_size), AV_OPT_TYPE_INT, {.i64 = 12 }, INT_MIN, INT_MAX, V|E},
 {"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, A|D|E},
+#if FF_API_OLD_CHANNEL_LAYOUT
 {"ac", "set number of audio channels", OFFSET(channels), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, A|D|E},
+#endif
 {"cutoff", "set cutoff bandwidth", OFFSET(cutoff), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, A|E},
 {"frame_size", NULL, OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, A|E},
 {"frame_number", NULL, OFFSET(frame_number), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX},
@@ -262,8 +264,11 @@ static const AVOption avcodec_options[] = {
 {"mv0_threshold", NULL, OFFSET(mv0_threshold), AV_OPT_TYPE_INT, {.i64 = 256 }, 0, INT_MAX, V|E},
 {"compression_level", NULL, OFFSET(compression_level), AV_OPT_TYPE_INT, {.i64 = FF_COMPRESSION_DEFAULT }, INT_MIN, INT_MAX, V|A|E},
 {"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX},
+{"ch_layout", NULL, OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL }, 0, 0, A|E|D, "ch_layout"},
+#if FF_API_OLD_CHANNEL_LAYOUT
 {"channel_layout", NULL, OFFSET(channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64 = DEFAULT }, 0, UINT64_MAX, A|E|D, "channel_layout"},
 {"request_channel_layout", NULL, OFFSET(request_channel_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64 = DEFAULT }, 0, UINT64_MAX, A|D, "request_channel_layout"},
+#endif
 {"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0.0, FLT_MAX, V|E},
 {"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use),  AV_OPT_TYPE_FLOAT, {.dbl = 3 },     0.0, FLT_MAX, V|E},
 {"ticks_per_frame", NULL, OFFSET(ticks_per_frame), AV_OPT_TYPE_INT, {.i64 = 1 }, 1, INT_MAX, A|V|E|D},
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 85a6bc98c1..c051f43e4a 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -297,10 +297,18 @@ static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src,
         dst->hwaccel = src->hwaccel;
         dst->hwaccel_context = src->hwaccel_context;
 
-        dst->channels       = src->channels;
         dst->sample_rate    = src->sample_rate;
         dst->sample_fmt     = src->sample_fmt;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        dst->channels       = src->channels;
         dst->channel_layout = src->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+        err = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
+        if (err < 0)
+            return err;
+
         dst->internal->hwaccel_priv_data = src->internal->hwaccel_priv_data;
 
         if (!!dst->hw_frames_ctx != !!src->hw_frames_ctx ||
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 0505ea6ba2..373fb56357 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -805,8 +805,16 @@ static int get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
 
 int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
 {
-    int duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
-                                    avctx->channels, avctx->block_align,
+   int channels = avctx->ch_layout.nb_channels;
+   int duration;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (!channels)
+        channels = avctx->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    duration = get_audio_frame_duration(avctx->codec_id, avctx->sample_rate,
+                                    channels, avctx->block_align,
                                     avctx->codec_tag, avctx->bits_per_coded_sample,
                                     avctx->bit_rate, avctx->extradata, avctx->frame_size,
                                     frame_bytes);
diff --git a/libavformat/demux.c b/libavformat/demux.c
index a9682a5949..c7710a5a7b 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1946,7 +1946,7 @@ static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr)
             FAIL("unspecified sample format");
         if (!avctx->sample_rate)
             FAIL("unspecified sample rate");
-        if (!avctx->channels)
+        if (!avctx->ch_layout.nb_channels)
             FAIL("unspecified number of channels");
         if (sti->info->found_decoder >= 0 && !sti->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS)
             FAIL("no decodable DTS frames");
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 181/281] 8svx: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (181 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 180/281] lavc: switch to the new channel layout API James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 182/281] aac: " James Almer
                   ` (99 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/8svx.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c
index 6ef8cd73fe..6ef7921274 100644
--- a/libavcodec/8svx.c
+++ b/libavcodec/8svx.c
@@ -88,38 +88,39 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
 {
     EightSvxContext *esc = avctx->priv_data;
     AVFrame *frame       = data;
+    int channels         = avctx->ch_layout.nb_channels;
     int buf_size;
     int ch, ret;
     int hdr_size = 2;
 
     /* decode and interleave the first packet */
     if (!esc->data[0] && avpkt) {
-        int chan_size = avpkt->size / avctx->channels - hdr_size;
+        int chan_size = avpkt->size / channels - hdr_size;
 
-        if (avpkt->size % avctx->channels) {
+        if (avpkt->size % channels) {
             av_log(avctx, AV_LOG_WARNING, "Packet with odd size, ignoring last byte\n");
         }
-        if (avpkt->size < (hdr_size + 1) * avctx->channels) {
+        if (avpkt->size < (hdr_size + 1) * channels) {
             av_log(avctx, AV_LOG_ERROR, "packet size is too small\n");
             return AVERROR_INVALIDDATA;
         }
 
         esc->fib_acc[0] = avpkt->data[1] + 128;
-        if (avctx->channels == 2)
+        if (channels == 2)
             esc->fib_acc[1] = avpkt->data[2+chan_size+1] + 128;
 
         esc->data_idx  = 0;
         esc->data_size = chan_size;
         if (!(esc->data[0] = av_malloc(chan_size)))
             return AVERROR(ENOMEM);
-        if (avctx->channels == 2) {
+        if (channels == 2) {
             if (!(esc->data[1] = av_malloc(chan_size))) {
                 av_freep(&esc->data[0]);
                 return AVERROR(ENOMEM);
             }
         }
         memcpy(esc->data[0], &avpkt->data[hdr_size], chan_size);
-        if (avctx->channels == 2)
+        if (channels == 2)
             memcpy(esc->data[1], &avpkt->data[2*hdr_size+chan_size], chan_size);
     }
     if (!esc->data[0]) {
@@ -139,7 +140,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
-    for (ch = 0; ch < avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         delta_decode(frame->data[ch], &esc->data[ch][esc->data_idx],
                      buf_size, &esc->fib_acc[ch], esc->table);
     }
@@ -148,14 +149,14 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
 
     *got_frame_ptr = 1;
 
-    return ((avctx->frame_number == 0)*hdr_size + buf_size)*avctx->channels;
+    return ((avctx->frame_number == 0) * hdr_size + buf_size) * channels;
 }
 
 static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
 {
     EightSvxContext *esc = avctx->priv_data;
 
-    if (avctx->channels < 1 || avctx->channels > 2) {
+    if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "8SVX does not support more than 2 channels\n");
         return AVERROR_INVALIDDATA;
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 182/281] aac: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (182 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 181/281] 8svx: convert to " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 183/281] ac3: " James Almer
                   ` (98 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/aac.h              | 11 ++++--
 libavcodec/aac_ac3_parser.c   |  9 +++--
 libavcodec/aaccoder.c         | 10 +++---
 libavcodec/aaccoder_twoloop.h |  4 +--
 libavcodec/aacdec.c           |  6 ++++
 libavcodec/aacdec_fixed.c     |  3 ++
 libavcodec/aacdec_template.c  | 59 ++++++++++++++++++++++++--------
 libavcodec/aacdectab.h        | 20 +++++++++++
 libavcodec/aacenc.c           | 13 ++++---
 libavcodec/aacenc.h           | 64 ++++++++++++++++++-----------------
 libavcodec/aacenctab.h        | 16 ++++-----
 libavcodec/aacpsy.c           |  8 ++---
 libavcodec/psymodel.c         |  8 ++---
 libavcodec/psymodel.h         |  2 +-
 14 files changed, 154 insertions(+), 79 deletions(-)

diff --git a/libavcodec/aac.h b/libavcodec/aac.h
index 1e82f56ca9..53be546857 100644
--- a/libavcodec/aac.h
+++ b/libavcodec/aac.h
@@ -32,6 +32,7 @@
 
 
 #include "aac_defines.h"
+#include "libavutil/channel_layout.h"
 #include "libavutil/float_dsp.h"
 #include "libavutil/fixed_dsp.h"
 #include "libavutil/mem_internal.h"
@@ -125,8 +126,7 @@ typedef struct OutputConfiguration {
     MPEG4AudioConfig m4ac;
     uint8_t layout_map[MAX_ELEM_ID*4][3];
     int layout_map_tags;
-    int channels;
-    uint64_t channel_layout;
+    AVChannelLayout ch_layout;
     enum OCStatus status;
 } OutputConfiguration;
 
@@ -288,6 +288,11 @@ typedef struct ChannelElement {
     SpectralBandReplication sbr;
 } ChannelElement;
 
+enum AACOutputChannelOrder {
+    CHANNEL_ORDER_DEFAULT,
+    CHANNEL_ORDER_CODED,
+};
+
 /**
  * main AAC context
  */
@@ -352,6 +357,8 @@ struct AACContext {
     int dmono_mode;      ///< 0->not dmono, 1->use first channel, 2->use second channel
     /** @} */
 
+    enum AACOutputChannelOrder output_channel_order;
+
     DECLARE_ALIGNED(32, INTFLOAT, temp)[128];
 
     OutputConfiguration oc[2];
diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index e84d30aea2..cd54a0a3e2 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -90,8 +90,13 @@ get_next:
         if (avctx->codec_id != AV_CODEC_ID_AAC) {
             avctx->sample_rate = s->sample_rate;
             if (!CONFIG_EAC3_DECODER || avctx->codec_id != AV_CODEC_ID_EAC3) {
-                avctx->channels = s->channels;
-                avctx->channel_layout = s->channel_layout;
+                av_channel_layout_uninit(&avctx->ch_layout);
+                if (s->channel_layout) {
+                    av_channel_layout_from_mask(&avctx->ch_layout, s->channel_layout);
+                } else {
+                    avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+                    avctx->ch_layout.nb_channels = s->channels;
+                }
             }
             s1->duration = s->samples;
             avctx->audio_service_type = s->service_type;
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c
index 7bbd4d5b2e..f460479498 100644
--- a/libavcodec/aaccoder.c
+++ b/libavcodec/aaccoder.c
@@ -397,7 +397,7 @@ static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s,
                                        const float lambda)
 {
     int start = 0, i, w, w2, g;
-    int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels * (lambda / 120.f);
+    int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->ch_layout.nb_channels * (lambda / 120.f);
     float dists[128] = { 0 }, uplims[128] = { 0 };
     float maxvals[128];
     int fflag, minscaler;
@@ -556,7 +556,7 @@ static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChanne
     const float pns_transient_energy_r = FFMIN(0.7f, lambda / 140.f);
 
     int refbits = avctx->bit_rate * 1024.0 / avctx->sample_rate
-        / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->channels)
+        / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->ch_layout.nb_channels)
         * (lambda / 120.f);
 
     /** Keep this in sync with twoloop's cutoff selection */
@@ -564,7 +564,7 @@ static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChanne
     int prev = -1000, prev_sf = -1;
     int frame_bit_rate = (avctx->flags & AV_CODEC_FLAG_QSCALE)
         ? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024)
-        : (avctx->bit_rate / avctx->channels);
+        : (avctx->bit_rate / avctx->ch_layout.nb_channels);
 
     frame_bit_rate *= 1.15f;
 
@@ -693,14 +693,14 @@ static void mark_pns(AACEncContext *s, AVCodecContext *avctx, SingleChannelEleme
     const float pns_transient_energy_r = FFMIN(0.7f, lambda / 140.f);
 
     int refbits = avctx->bit_rate * 1024.0 / avctx->sample_rate
-        / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->channels)
+        / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->ch_layout.nb_channels)
         * (lambda / 120.f);
 
     /** Keep this in sync with twoloop's cutoff selection */
     float rate_bandwidth_multiplier = 1.5f;
     int frame_bit_rate = (avctx->flags & AV_CODEC_FLAG_QSCALE)
         ? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024)
-        : (avctx->bit_rate / avctx->channels);
+        : (avctx->bit_rate / avctx->ch_layout.nb_channels);
 
     frame_bit_rate *= 1.15f;
 
diff --git a/libavcodec/aaccoder_twoloop.h b/libavcodec/aaccoder_twoloop.h
index 8e1bc88a85..0504a916ad 100644
--- a/libavcodec/aaccoder_twoloop.h
+++ b/libavcodec/aaccoder_twoloop.h
@@ -71,7 +71,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx,
 {
     int start = 0, i, w, w2, g, recomprd;
     int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate
-        / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->channels)
+        / ((avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : avctx->ch_layout.nb_channels)
         * (lambda / 120.f);
     int refbits = destbits;
     int toomanybits, toofewbits;
@@ -186,7 +186,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx,
         float rate_bandwidth_multiplier = 1.5f;
         int frame_bit_rate = (avctx->flags & AV_CODEC_FLAG_QSCALE)
             ? (refbits * rate_bandwidth_multiplier * avctx->sample_rate / 1024)
-            : (avctx->bit_rate / avctx->channels);
+            : (avctx->bit_rate / avctx->ch_layout.nb_channels);
 
         /** Compensate for extensions that increase efficiency */
         if (s->options.pns || s->options.intensity_stereo)
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 4dfb38ac83..611f9e4be1 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -566,7 +566,10 @@ const AVCodec ff_aac_decoder = {
     },
     .capabilities    = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1,
     .caps_internal   = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts = aac_channel_layout,
+#endif
+    .ch_layouts      = aac_ch_layout,
     .flush = flush,
     .priv_class      = &aac_decoder_class,
     .profiles        = NULL_IF_CONFIG_SMALL(ff_aac_profiles),
@@ -591,7 +594,10 @@ const AVCodec ff_aac_latm_decoder = {
     },
     .capabilities    = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1,
     .caps_internal   = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts = aac_channel_layout,
+#endif
+    .ch_layouts      = aac_ch_layout,
     .flush = flush,
     .profiles        = NULL_IF_CONFIG_SMALL(ff_aac_profiles),
 };
diff --git a/libavcodec/aacdec_fixed.c b/libavcodec/aacdec_fixed.c
index cad2fd6adc..8af7e994ae 100644
--- a/libavcodec/aacdec_fixed.c
+++ b/libavcodec/aacdec_fixed.c
@@ -464,7 +464,10 @@ const AVCodec ff_aac_fixed_decoder = {
     },
     .capabilities    = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1,
     .caps_internal   = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts = aac_channel_layout,
+#endif
+    .ch_layouts      = aac_ch_layout,
     .profiles        = NULL_IF_CONFIG_SMALL(ff_aac_profiles),
     .flush = flush,
 };
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 7149b331ae..387a4acfce 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -174,7 +174,7 @@ static int frame_configure_elements(AVCodecContext *avctx)
 
     /* get output buffer */
     av_frame_unref(ac->frame);
-    if (!avctx->channels)
+    if (!avctx->ch_layout.nb_channels)
         return 1;
 
     ac->frame->nb_samples = 2048;
@@ -182,7 +182,7 @@ static int frame_configure_elements(AVCodecContext *avctx)
         return ret;
 
     /* map output channel pointers to AVFrame data */
-    for (ch = 0; ch < avctx->channels; ch++) {
+    for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
         if (ac->output_element[ch])
             ac->output_element[ch]->ret = (INTFLOAT *)ac->frame->extended_data[ch];
     }
@@ -517,8 +517,7 @@ static int push_output_configuration(AACContext *ac) {
 static void pop_output_configuration(AACContext *ac) {
     if (ac->oc[1].status != OC_LOCKED && ac->oc[0].status != OC_NONE) {
         ac->oc[1] = ac->oc[0];
-        ac->avctx->channels = ac->oc[1].channels;
-        ac->avctx->channel_layout = ac->oc[1].channel_layout;
+        ac->avctx->ch_layout = ac->oc[1].ch_layout;
         output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags,
                          ac->oc[1].status, 0);
     }
@@ -555,7 +554,14 @@ static int output_configure(AACContext *ac,
     }
     // Try to sniff a reasonable channel order, otherwise output the
     // channels in the order the PCE declared them.
-    if (avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE)
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (avctx->request_channel_layout == AV_CH_LAYOUT_NATIVE)
+        ac->output_channel_order = CHANNEL_ORDER_CODED;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+    if (ac->output_channel_order == CHANNEL_ORDER_DEFAULT)
         layout = sniff_channel_order(layout_map, tags);
     for (i = 0; i < tags; i++) {
         int type =     layout_map[i][0];
@@ -577,9 +583,22 @@ static int output_configure(AACContext *ac,
         }
     }
 
-    if (layout) avctx->channel_layout = layout;
-                            ac->oc[1].channel_layout = layout;
-    avctx->channels       = ac->oc[1].channels       = channels;
+    av_channel_layout_uninit(&ac->oc[1].ch_layout);
+    if (layout)
+        av_channel_layout_from_mask(&ac->oc[1].ch_layout, layout);
+    else {
+        ac->oc[1].ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        ac->oc[1].ch_layout.nb_channels = channels;
+    }
+
+    av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    avctx->channels = avctx->ch_layout.nb_channels;
+    avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                            avctx->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     ac->oc[1].status = oc_type;
 
     if (get_new_frame) {
@@ -1292,12 +1311,12 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
 
         sr = sample_rate_idx(avctx->sample_rate);
         ac->oc[1].m4ac.sampling_index = sr;
-        ac->oc[1].m4ac.channels = avctx->channels;
+        ac->oc[1].m4ac.channels = avctx->ch_layout.nb_channels;
         ac->oc[1].m4ac.sbr = -1;
         ac->oc[1].m4ac.ps = -1;
 
         for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++)
-            if (ff_mpeg4audio_channels[i] == avctx->channels)
+            if (ff_mpeg4audio_channels[i] == avctx->ch_layout.nb_channels)
                 break;
         if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) {
             i = 0;
@@ -1315,7 +1334,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
         }
     }
 
-    if (avctx->channels > MAX_CHANNELS) {
+    if (avctx->ch_layout.nb_channels > MAX_CHANNELS) {
         av_log(avctx, AV_LOG_ERROR, "Too many channels\n");
         return AVERROR_INVALIDDATA;
     }
@@ -2556,7 +2575,8 @@ static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt,
             av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n");
             skip_bits_long(gb, 8 * cnt - 4);
             return res;
-        } else if (ac->oc[1].m4ac.ps == -1 && ac->oc[1].status < OC_LOCKED && ac->avctx->channels == 1) {
+        } else if (ac->oc[1].m4ac.ps == -1 && ac->oc[1].status < OC_LOCKED &&
+                   ac->avctx->ch_layout.nb_channels == 1) {
             ac->oc[1].m4ac.sbr = 1;
             ac->oc[1].m4ac.ps = 1;
             ac->avctx->profile = FF_PROFILE_AAC_HE_V2;
@@ -3264,7 +3284,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
         if (avctx->debug & FF_DEBUG_STARTCODE)
             av_log(avctx, AV_LOG_DEBUG, "Elem type:%x id:%x\n", elem_type, elem_id);
 
-        if (!avctx->channels && elem_type != TYPE_PCE) {
+        if (!avctx->ch_layout.nb_channels && elem_type != TYPE_PCE) {
             err = AVERROR_INVALIDDATA;
             goto fail;
         }
@@ -3385,7 +3405,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
         }
     }
 
-    if (!avctx->channels) {
+    if (!avctx->ch_layout.nb_channels) {
         *got_frame_ptr = 0;
         return 0;
     }
@@ -3419,7 +3439,8 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
 
     /* for dual-mono audio (SCE + SCE) */
     is_dmono = ac->dmono_mode && sce_count == 2 &&
-               ac->oc[1].channel_layout == (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT);
+               !av_channel_layout_compare(&ac->oc[1].ch_layout,
+                                          &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
     if (is_dmono) {
         if (ac->dmono_mode == 1)
             ((AVFrame *)data)->data[1] =((AVFrame *)data)->data[0];
@@ -3553,6 +3574,14 @@ static const AVOption options[] = {
     {"sub" , "Select Sub/Right channel", 0, AV_OPT_TYPE_CONST, {.i64= 2}, INT_MIN, INT_MAX, AACDEC_FLAGS, "dual_mono_mode"},
     {"both", "Select both channels",     0, AV_OPT_TYPE_CONST, {.i64= 0}, INT_MIN, INT_MAX, AACDEC_FLAGS, "dual_mono_mode"},
 
+    { "channel_order", "Order in which the channels are to be exported",
+        offsetof(AACContext, output_channel_order), AV_OPT_TYPE_INT,
+        { .i64 = CHANNEL_ORDER_DEFAULT }, 0, 1, AACDEC_FLAGS, "channel_order" },
+      { "default", "normal libavcodec channel order", 0, AV_OPT_TYPE_CONST,
+        { .i64 = CHANNEL_ORDER_DEFAULT }, .flags = AACDEC_FLAGS, "channel_order" },
+      { "coded",    "order in which the channels are coded in the bitstream",
+        0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = AACDEC_FLAGS, "channel_order" },
+
     {NULL},
 };
 
diff --git a/libavcodec/aacdectab.h b/libavcodec/aacdectab.h
index c54a3eb943..e03026806d 100644
--- a/libavcodec/aacdectab.h
+++ b/libavcodec/aacdectab.h
@@ -72,6 +72,7 @@ static const uint8_t aac_channel_layout_map[16][16][3] = {
     /* TODO: Add 7+1 TOP configuration */
 };
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 static const uint64_t aac_channel_layout[16] = {
     AV_CH_LAYOUT_MONO,
     AV_CH_LAYOUT_STEREO,
@@ -89,5 +90,24 @@ static const uint64_t aac_channel_layout[16] = {
     0,
     /* AV_CH_LAYOUT_7POINT1_TOP, */
 };
+#endif
+
+static const AVChannelLayout aac_ch_layout[16] = {
+    AV_CHANNEL_LAYOUT_MONO,
+    AV_CHANNEL_LAYOUT_STEREO,
+    AV_CHANNEL_LAYOUT_SURROUND,
+    AV_CHANNEL_LAYOUT_4POINT0,
+    AV_CHANNEL_LAYOUT_5POINT0_BACK,
+    AV_CHANNEL_LAYOUT_5POINT1_BACK,
+    AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK,
+    { 0 },
+    { 0 },
+    { 0 },
+    AV_CHANNEL_LAYOUT_6POINT1,
+    AV_CHANNEL_LAYOUT_7POINT1,
+    AV_CHANNEL_LAYOUT_22POINT2,
+    { 0 },
+    /* AV_CHANNEL_LAYOUT_7POINT1_TOP, */
+};
 
 #endif /* AVCODEC_AACDECTAB_H */
diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index a1004c3e98..be157bb709 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -962,11 +962,11 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
     s->lambda = avctx->global_quality > 0 ? avctx->global_quality : 120;
 
     /* Channel map and unspecified bitrate guessing */
-    s->channels = avctx->channels;
+    s->channels = avctx->ch_layout.nb_channels;
 
     s->needs_pce = 1;
     for (i = 0; i < FF_ARRAY_ELEMS(aac_normal_chan_layouts); i++) {
-        if (avctx->channel_layout == aac_normal_chan_layouts[i]) {
+        if (!av_channel_layout_compare(&avctx->ch_layout, &aac_normal_chan_layouts[i])) {
             s->needs_pce = s->options.pce;
             break;
         }
@@ -975,10 +975,13 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
     if (s->needs_pce) {
         char buf[64];
         for (i = 0; i < FF_ARRAY_ELEMS(aac_pce_configs); i++)
-            if (avctx->channel_layout == aac_pce_configs[i].layout)
+            if (!av_channel_layout_compare(&avctx->ch_layout, &aac_pce_configs[i].layout))
                 break;
-        av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
-        ERROR_IF(i == FF_ARRAY_ELEMS(aac_pce_configs), "Unsupported channel layout \"%s\"\n", buf);
+        av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf));
+        if (i == FF_ARRAY_ELEMS(aac_pce_configs)) {
+            av_log(avctx, AV_LOG_ERROR, "Unsupported channel layout \"%s\"\n", buf);
+            return AVERROR(EINVAL);
+        }
         av_log(avctx, AV_LOG_INFO, "Using a PCE to encode channel layout \"%s\"\n", buf);
         s->pce = aac_pce_configs[i];
         s->reorder_map = s->pce.reorder_map;
diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h
index b106910ce0..a001c7ca60 100644
--- a/libavcodec/aacenc.h
+++ b/libavcodec/aacenc.h
@@ -94,7 +94,7 @@ typedef struct AACQuantizeBandCostCacheEntry {
 } AACQuantizeBandCostCacheEntry;
 
 typedef struct AACPCEInfo {
-    int64_t layout;
+    AVChannelLayout layout;
     int num_ele[4];                              ///< front, side, back, lfe
     int pairing[3][8];                           ///< front, side, back
     int index[4][8];                             ///< front, side, back, lfe
@@ -139,7 +139,7 @@ typedef struct AACPCEInfo {
  */
 static const AACPCEInfo aac_pce_configs[] = {
     {
-        .layout = AV_CH_LAYOUT_MONO,
+        .layout = AV_CHANNEL_LAYOUT_MONO,
         .num_ele = { 1, 0, 0, 0 },
         .pairing = { { 0 }, },
         .index = { { 0 }, },
@@ -147,7 +147,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0 },
     },
     {
-        .layout = AV_CH_LAYOUT_STEREO,
+        .layout = AV_CHANNEL_LAYOUT_STEREO,
         .num_ele = { 1, 0, 0, 0 },
         .pairing = { { 1 }, },
         .index = { { 0 }, },
@@ -155,7 +155,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1 },
     },
     {
-        .layout = AV_CH_LAYOUT_2POINT1,
+        .layout = AV_CHANNEL_LAYOUT_2POINT1,
         .num_ele = { 1, 0, 0, 1 },
         .pairing = { { 1 }, },
         .index = { { 0 },{ 0 },{ 0 },{ 0 } },
@@ -163,7 +163,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2 },
     },
     {
-        .layout = AV_CH_LAYOUT_2_1,
+        .layout = AV_CHANNEL_LAYOUT_2_1,
         .num_ele = { 1, 0, 1, 0 },
         .pairing = { { 1 },{ 0 },{ 0 } },
         .index = { { 0 },{ 0 },{ 0 }, },
@@ -171,7 +171,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2 },
     },
     {
-        .layout = AV_CH_LAYOUT_SURROUND,
+        .layout = AV_CHANNEL_LAYOUT_SURROUND,
         .num_ele = { 2, 0, 0, 0 },
         .pairing = { { 1, 0 }, },
         .index = { { 0, 0 }, },
@@ -179,7 +179,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2 },
     },
     {
-        .layout = AV_CH_LAYOUT_3POINT1,
+        .layout = AV_CHANNEL_LAYOUT_3POINT1,
         .num_ele = { 2, 0, 0, 1 },
         .pairing = { { 1, 0 }, },
         .index = { { 0, 0 }, { 0 }, { 0 }, { 0 }, },
@@ -187,7 +187,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3 },
     },
     {
-        .layout = AV_CH_LAYOUT_4POINT0,
+        .layout = AV_CHANNEL_LAYOUT_4POINT0,
         .num_ele = { 2, 0, 1, 0 },
         .pairing = { { 1, 0 }, { 0 }, { 0 }, },
         .index = { { 0, 0 }, { 0 }, { 1 } },
@@ -195,7 +195,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = {  0, 1, 2, 3 },
     },
     {
-        .layout = AV_CH_LAYOUT_4POINT1,
+        .layout = AV_CHANNEL_LAYOUT_4POINT1,
         .num_ele = { 2, 1, 1, 0 },
         .pairing = { { 1, 0 }, { 0 }, { 0 }, },
         .index = { { 0, 0 }, { 1 }, { 2 }, { 0 } },
@@ -203,7 +203,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4 },
     },
     {
-        .layout = AV_CH_LAYOUT_2_2,
+        .layout = AV_CHANNEL_LAYOUT_2_2,
         .num_ele = { 1, 1, 0, 0 },
         .pairing = { { 1 }, { 1 }, },
         .index = { { 0 }, { 1 }, },
@@ -211,7 +211,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3 },
     },
     {
-        .layout = AV_CH_LAYOUT_QUAD,
+        .layout = AV_CHANNEL_LAYOUT_QUAD,
         .num_ele = { 1, 0, 1, 0 },
         .pairing = { { 1 }, { 0 }, { 1 }, },
         .index = { { 0 }, { 0 }, { 1 } },
@@ -219,7 +219,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3 },
     },
     {
-        .layout = AV_CH_LAYOUT_5POINT0,
+        .layout = AV_CHANNEL_LAYOUT_5POINT0,
         .num_ele = { 2, 1, 0, 0 },
         .pairing = { { 1, 0 }, { 1 }, },
         .index = { { 0, 0 }, { 1 } },
@@ -227,7 +227,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4 },
     },
     {
-        .layout = AV_CH_LAYOUT_5POINT1,
+        .layout = AV_CHANNEL_LAYOUT_5POINT1,
         .num_ele = { 2, 1, 1, 0 },
         .pairing = { { 1, 0 }, { 0 }, { 1 }, },
         .index = { { 0, 0 }, { 1 }, { 1 } },
@@ -235,7 +235,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5 },
     },
     {
-        .layout = AV_CH_LAYOUT_5POINT0_BACK,
+        .layout = AV_CHANNEL_LAYOUT_5POINT0_BACK,
         .num_ele = { 2, 0, 1, 0 },
         .pairing = { { 1, 0 }, { 0 }, { 1 } },
         .index = { { 0, 0 }, { 0 }, { 1 } },
@@ -243,7 +243,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4 },
     },
     {
-        .layout = AV_CH_LAYOUT_5POINT1_BACK,
+        .layout = AV_CHANNEL_LAYOUT_5POINT1_BACK,
         .num_ele = { 2, 1, 1, 0 },
         .pairing = { { 1, 0 }, { 0 }, { 1 }, },
         .index = { { 0, 0 }, { 1 }, { 1 } },
@@ -251,7 +251,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5 },
     },
     {
-        .layout = AV_CH_LAYOUT_6POINT0,
+        .layout = AV_CHANNEL_LAYOUT_6POINT0,
         .num_ele = { 2, 1, 1, 0 },
         .pairing = { { 1, 0 }, { 1 }, { 0 }, },
         .index = { { 0, 0 }, { 1 }, { 1 } },
@@ -259,7 +259,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5 },
     },
     {
-        .layout = AV_CH_LAYOUT_6POINT0_FRONT,
+        .layout = AV_CHANNEL_LAYOUT_6POINT0_FRONT,
         .num_ele = { 2, 1, 0, 0 },
         .pairing = { { 1, 1 }, { 1 } },
         .index = { { 1, 0 }, { 2 }, },
@@ -267,7 +267,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5 },
     },
     {
-        .layout = AV_CH_LAYOUT_HEXAGONAL,
+        .layout = AV_CHANNEL_LAYOUT_HEXAGONAL,
         .num_ele = { 2, 0, 2, 0 },
         .pairing = { { 1, 0 },{ 0 },{ 1, 0 }, },
         .index = { { 0, 0 },{ 0 },{ 1, 1 } },
@@ -275,7 +275,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5 },
     },
     {
-        .layout = AV_CH_LAYOUT_6POINT1,
+        .layout = AV_CHANNEL_LAYOUT_6POINT1,
         .num_ele = { 2, 1, 2, 0 },
         .pairing = { { 1, 0 },{ 0 },{ 1, 0 }, },
         .index = { { 0, 0 },{ 1 },{ 1, 2 } },
@@ -283,7 +283,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5, 6 },
     },
     {
-        .layout = AV_CH_LAYOUT_6POINT1_BACK,
+        .layout = AV_CHANNEL_LAYOUT_6POINT1_BACK,
         .num_ele = { 2, 1, 2, 0 },
         .pairing = { { 1, 0 }, { 0 }, { 1, 0 }, },
         .index = { { 0, 0 }, { 1 }, { 1, 2 } },
@@ -291,7 +291,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5, 6 },
     },
     {
-        .layout = AV_CH_LAYOUT_6POINT1_FRONT,
+        .layout = AV_CHANNEL_LAYOUT_6POINT1_FRONT,
         .num_ele = { 2, 1, 2, 0 },
         .pairing = { { 1, 0 }, { 0 }, { 1, 0 }, },
         .index = { { 0, 0 }, { 1 }, { 1, 2 } },
@@ -299,7 +299,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5, 6 },
     },
     {
-        .layout = AV_CH_LAYOUT_7POINT0,
+        .layout = AV_CHANNEL_LAYOUT_7POINT0,
         .num_ele = { 2, 1, 1, 0 },
         .pairing = { { 1, 0 }, { 1 }, { 1 }, },
         .index = { { 0, 0 }, { 1 }, { 2 }, },
@@ -307,7 +307,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5, 6 },
     },
     {
-        .layout = AV_CH_LAYOUT_7POINT0_FRONT,
+        .layout = AV_CHANNEL_LAYOUT_7POINT0_FRONT,
         .num_ele = { 2, 1, 1, 0 },
         .pairing = { { 1, 0 }, { 1 }, { 1 }, },
         .index = { { 0, 0 }, { 1 }, { 2 }, },
@@ -315,7 +315,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5, 6 },
     },
     {
-        .layout = AV_CH_LAYOUT_7POINT1,
+        .layout = AV_CHANNEL_LAYOUT_7POINT1,
         .num_ele = { 2, 1, 2, 0 },
         .pairing = { { 1, 0 }, { 0 }, { 1, 1 }, },
         .index = { { 0, 0 }, { 1 }, { 1, 2 }, { 0 } },
@@ -323,7 +323,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7 },
     },
     {
-        .layout = AV_CH_LAYOUT_7POINT1_WIDE,
+        .layout = AV_CHANNEL_LAYOUT_7POINT1_WIDE,
         .num_ele = { 2, 1, 2, 0 },
         .pairing = { { 1, 0 }, { 0 },{  1, 1 }, },
         .index = { { 0, 0 }, { 1 }, { 1, 2 }, { 0 } },
@@ -331,7 +331,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7 },
     },
     {
-        .layout = AV_CH_LAYOUT_7POINT1_WIDE_BACK,
+        .layout = AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK,
         .num_ele = { 2, 1, 2, 0 },
         .pairing = { { 1, 0 }, { 0 }, { 1, 1 }, },
         .index = { { 0, 0 }, { 1 }, { 1, 2 }, { 0 } },
@@ -339,7 +339,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7 },
     },
     {
-        .layout = AV_CH_LAYOUT_OCTAGONAL,
+        .layout = AV_CHANNEL_LAYOUT_OCTAGONAL,
         .num_ele = { 2, 1, 2, 0 },
         .pairing = { { 1, 0 }, { 1 }, { 1, 0 }, },
         .index = { { 0, 0 }, { 1 }, { 2, 1 } },
@@ -347,7 +347,8 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7 },
     },
     {   /* Meant for order 2/mixed ambisonics */
-        .layout = AV_CH_LAYOUT_OCTAGONAL | AV_CH_TOP_CENTER,
+        .layout = { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 9,
+                    .u.mask = AV_CH_LAYOUT_OCTAGONAL | AV_CH_TOP_CENTER },
         .num_ele = { 2, 2, 2, 0 },
         .pairing = { { 1, 0 }, { 1, 0 }, { 1, 0 }, },
         .index = { { 0, 0 }, { 1, 1 }, { 2, 2 } },
@@ -355,8 +356,9 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7, 8 },
     },
     {   /* Meant for order 2/mixed ambisonics */
-        .layout = AV_CH_LAYOUT_6POINT0_FRONT | AV_CH_BACK_CENTER |
-                  AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT | AV_CH_TOP_CENTER,
+        .layout = { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 10,
+                    .u.mask = AV_CH_LAYOUT_6POINT0_FRONT | AV_CH_BACK_CENTER |
+                              AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT | AV_CH_TOP_CENTER },
         .num_ele = { 2, 2, 2, 0 },
         .pairing = { { 1, 1 }, { 1, 0 }, { 1, 0 }, },
         .index = { { 0, 1 }, { 2, 0 }, { 3, 1 } },
@@ -364,7 +366,7 @@ static const AACPCEInfo aac_pce_configs[] = {
         .reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
     },
     {
-        .layout = AV_CH_LAYOUT_HEXADECAGONAL,
+        .layout = AV_CHANNEL_LAYOUT_HEXADECAGONAL,
         .num_ele = { 4, 2, 4, 0 },
         .pairing = { { 1, 0, 1, 0 }, { 1, 1 }, { 1, 0, 1, 0 }, },
         .index = { { 0, 0, 1, 1 }, { 2, 3 }, { 4, 2, 5, 3 } },
diff --git a/libavcodec/aacenctab.h b/libavcodec/aacenctab.h
index 33cb7ae95b..2d96621945 100644
--- a/libavcodec/aacenctab.h
+++ b/libavcodec/aacenctab.h
@@ -45,14 +45,14 @@ extern const uint8_t *const ff_aac_swb_size_128[];
 extern const int      ff_aac_swb_size_128_len;
 
 /* Supported layouts without using a PCE */
-static const int64_t aac_normal_chan_layouts[7] = {
-    AV_CH_LAYOUT_MONO,
-    AV_CH_LAYOUT_STEREO,
-    AV_CH_LAYOUT_SURROUND,
-    AV_CH_LAYOUT_4POINT0,
-    AV_CH_LAYOUT_5POINT0_BACK,
-    AV_CH_LAYOUT_5POINT1_BACK,
-    AV_CH_LAYOUT_7POINT1,
+static const AVChannelLayout aac_normal_chan_layouts[7] = {
+    AV_CHANNEL_LAYOUT_MONO,
+    AV_CHANNEL_LAYOUT_STEREO,
+    AV_CHANNEL_LAYOUT_SURROUND,
+    AV_CHANNEL_LAYOUT_4POINT0,
+    AV_CHANNEL_LAYOUT_5POINT0_BACK,
+    AV_CHANNEL_LAYOUT_5POINT1_BACK,
+    AV_CHANNEL_LAYOUT_7POINT1,
 };
 
 /** default channel configurations */
diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
index 0c64f2c7b0..4c5ab2c9d5 100644
--- a/libavcodec/aacpsy.c
+++ b/libavcodec/aacpsy.c
@@ -263,13 +263,13 @@ static av_cold void lame_window_init(AacPsyContext *ctx, AVCodecContext *avctx)
 {
     int i, j;
 
-    for (i = 0; i < avctx->channels; i++) {
+    for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
         AacPsyChannel *pch = &ctx->ch[i];
 
         if (avctx->flags & AV_CODEC_FLAG_QSCALE)
             pch->attack_threshold = psy_vbr_map[avctx->global_quality / FF_QP2LAMBDA].st_lrm;
         else
-            pch->attack_threshold = lame_calc_attack_threshold(avctx->bit_rate / avctx->channels / 1000);
+            pch->attack_threshold = lame_calc_attack_threshold(avctx->bit_rate / avctx->ch_layout.nb_channels / 1000);
 
         for (j = 0; j < AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS; j++)
             pch->prev_energy_subshort[j] = 10.0f;
@@ -303,7 +303,7 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) {
     float bark;
     int i, j, g, start;
     float prev, minscale, minath, minsnr, pe_min;
-    int chan_bitrate = ctx->avctx->bit_rate / ((ctx->avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : ctx->avctx->channels);
+    int chan_bitrate = ctx->avctx->bit_rate / ((ctx->avctx->flags & AV_CODEC_FLAG_QSCALE) ? 2.0f : ctx->avctx->ch_layout.nb_channels);
 
     const int bandwidth    = ctx->cutoff ? ctx->cutoff : AAC_CUTOFF(ctx->avctx);
     const float num_bark   = calc_bark((float)bandwidth);
@@ -370,7 +370,7 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) {
         }
     }
 
-    pctx->ch = av_calloc(ctx->avctx->channels, sizeof(*pctx->ch));
+    pctx->ch = av_calloc(ctx->avctx->ch_layout.nb_channels, sizeof(*pctx->ch));
     if (!pctx->ch) {
         av_freep(&ctx->model_priv_data);
         return AVERROR(ENOMEM);
diff --git a/libavcodec/psymodel.c b/libavcodec/psymodel.c
index 93c8408297..890b13e1c8 100644
--- a/libavcodec/psymodel.c
+++ b/libavcodec/psymodel.c
@@ -35,7 +35,7 @@ av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens,
     int i, j, k = 0;
 
     ctx->avctx = avctx;
-    ctx->ch        = av_calloc(avctx->channels, 2 * sizeof(ctx->ch[0]));
+    ctx->ch        = av_calloc(avctx->ch_layout.nb_channels, 2 * sizeof(ctx->ch[0]));
     ctx->group     = av_calloc(num_groups, sizeof(ctx->group[0]));
     ctx->bands     = av_malloc_array (sizeof(ctx->bands[0]),      num_lens);
     ctx->num_bands = av_malloc_array (sizeof(ctx->num_bands[0]),  num_lens);
@@ -120,13 +120,13 @@ av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *av
                                                  FF_FILTER_MODE_LOWPASS, FILT_ORDER,
                                                  cutoff_coeff, 0.0, 0.0);
         if (ctx->fcoeffs) {
-            ctx->fstate = av_calloc(avctx->channels, sizeof(ctx->fstate[0]));
+            ctx->fstate = av_calloc(avctx->ch_layout.nb_channels, sizeof(ctx->fstate[0]));
             if (!ctx->fstate) {
                 av_free(ctx->fcoeffs);
                 av_free(ctx);
                 return NULL;
             }
-            for (i = 0; i < avctx->channels; i++)
+            for (i = 0; i < avctx->ch_layout.nb_channels; i++)
                 ctx->fstate[i] = ff_iir_filter_init_state(FILT_ORDER);
         }
     }
@@ -154,7 +154,7 @@ av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx)
     int i;
     ff_iir_filter_free_coeffsp(&ctx->fcoeffs);
     if (ctx->fstate)
-        for (i = 0; i < ctx->avctx->channels; i++)
+        for (i = 0; i < ctx->avctx->ch_layout.nb_channels; i++)
             ff_iir_filter_free_statep(&ctx->fstate[i]);
     av_freep(&ctx->fstate);
     av_free(ctx);
diff --git a/libavcodec/psymodel.h b/libavcodec/psymodel.h
index e5f917d495..22899a38d9 100644
--- a/libavcodec/psymodel.h
+++ b/libavcodec/psymodel.h
@@ -41,7 +41,7 @@
 #define AAC_CUTOFF(s) ( \
     (s->flags & AV_CODEC_FLAG_QSCALE) \
     ? s->sample_rate / 2 \
-    : AAC_CUTOFF_FROM_BITRATE(s->bit_rate, s->channels, s->sample_rate) \
+    : AAC_CUTOFF_FROM_BITRATE(s->bit_rate, s->ch_layout.nb_channels, s->sample_rate) \
 )
 
 /**
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 183/281] ac3: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (183 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 182/281] aac: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 184/281] adpcm: " James Almer
                   ` (97 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/aac_ac3_parser.c |  6 +++
 libavcodec/ac3dec.c         | 57 +++++++++++++++++----------
 libavcodec/ac3dec.h         |  2 +
 libavcodec/ac3dec_fixed.c   |  1 +
 libavcodec/ac3dec_float.c   |  2 +
 libavcodec/ac3enc.c         | 78 +++++++++++++++++++++++++++++--------
 libavcodec/ac3enc.h         |  4 +-
 libavcodec/ac3enc_fixed.c   |  5 +++
 libavcodec/ac3enc_float.c   |  5 +++
 libavcodec/eac3enc.c        |  5 +++
 tests/fate/ac3.mak          | 16 ++++----
 11 files changed, 135 insertions(+), 46 deletions(-)

diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index cd54a0a3e2..4ce7a73972 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -97,6 +97,12 @@ get_next:
                     avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
                     avctx->ch_layout.nb_channels = s->channels;
                 }
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+                avctx->channels = avctx->ch_layout.nb_channels;
+                avctx->channel_layout = s->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             }
             s1->duration = s->samples;
             avctx->audio_service_type = s->service_type;
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index ae00373dcb..70b35c170f 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -32,6 +32,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/crc.h"
 #include "libavutil/downmix_info.h"
+#include "libavutil/intmath.h"
 #include "libavutil/opt.h"
 #include "libavutil/thread.h"
 #include "bswapdsp.h"
@@ -186,6 +187,8 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
 {
     static AVOnce init_static_once = AV_ONCE_INIT;
     AC3DecodeContext *s = avctx->priv_data;
+    const AVChannelLayout mono   = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+    const AVChannelLayout stereo = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     int i, ret;
 
     s->avctx = avctx;
@@ -214,12 +217,23 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
         avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 
     /* allow downmixing to stereo or mono */
-    if (avctx->channels > 1 &&
-        avctx->request_channel_layout == AV_CH_LAYOUT_MONO)
-        avctx->channels = 1;
-    else if (avctx->channels > 2 &&
-             avctx->request_channel_layout == AV_CH_LAYOUT_STEREO)
-        avctx->channels = 2;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (avctx->request_channel_layout) {
+        av_channel_layout_uninit(&s->downmix_layout);
+        av_channel_layout_from_mask(&s->downmix_layout, avctx->request_channel_layout);
+    }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if (avctx->ch_layout.nb_channels > 1 &&
+        !av_channel_layout_compare(&s->downmix_layout, &mono)) {
+        av_channel_layout_uninit(&avctx->ch_layout);
+        avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+    } else if (avctx->ch_layout.nb_channels > 2 &&
+             !av_channel_layout_compare(&s->downmix_layout, &stereo)) {
+        av_channel_layout_uninit(&avctx->ch_layout);
+        avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+    }
     s->downmixed = 1;
 
     for (i = 0; i < AC3_MAX_CHANNELS; i++) {
@@ -1480,6 +1494,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
     const SHORTFLOAT *output[AC3_MAX_CHANNELS];
     enum AVMatrixEncoding matrix_encoding;
     AVDownmixInfo *downmix_info;
+    uint64_t mask;
 
     s->superframe_size = 0;
 
@@ -1590,11 +1605,11 @@ dependent_frame:
         if (s->lfe_on)
             s->output_mode |= AC3_OUTPUT_LFEON;
         if (s->channels > 1 &&
-            avctx->request_channel_layout == AV_CH_LAYOUT_MONO) {
+            !av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) {
             s->out_channels = 1;
             s->output_mode  = AC3_CHMODE_MONO;
         } else if (s->channels > 2 &&
-                   avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
+                   !av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) {
             s->out_channels = 2;
             s->output_mode  = AC3_CHMODE_STEREO;
         }
@@ -1615,10 +1630,13 @@ dependent_frame:
         av_log(avctx, AV_LOG_ERROR, "unable to determine channel mode\n");
         return AVERROR_INVALIDDATA;
     }
-    avctx->channels = s->out_channels;
-    avctx->channel_layout = ff_ac3_channel_layout_tab[s->output_mode & ~AC3_OUTPUT_LFEON];
+
+    mask = ff_ac3_channel_layout_tab[s->output_mode & ~AC3_OUTPUT_LFEON];
     if (s->output_mode & AC3_OUTPUT_LFEON)
-        avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
+        mask |= AV_CH_LOW_FREQUENCY;
+
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_from_mask(&avctx->ch_layout, mask);
 
     /* set audio service type based on bitstream mode for AC-3 */
     avctx->audio_service_type = s->bitstream_mode;
@@ -1714,20 +1732,20 @@ skip:
                 channel_layout |= ff_eac3_custom_channel_map_locations[ch][1];
             }
         }
-        if (av_get_channel_layout_nb_channels(channel_layout) > EAC3_MAX_CHANNELS) {
+        if (av_popcount64(channel_layout) > EAC3_MAX_CHANNELS) {
             av_log(avctx, AV_LOG_ERROR, "Too many channels (%d) coded\n",
-                   av_get_channel_layout_nb_channels(channel_layout));
+                   av_popcount64(channel_layout));
             return AVERROR_INVALIDDATA;
         }
 
-        avctx->channel_layout = channel_layout;
-        avctx->channels = av_get_channel_layout_nb_channels(channel_layout);
+        av_channel_layout_uninit(&avctx->ch_layout);
+        av_channel_layout_from_mask(&avctx->ch_layout, channel_layout);
 
         for (ch = 0; ch < EAC3_MAX_CHANNELS; ch++) {
             if (s->channel_map & (1 << (EAC3_MAX_CHANNELS - ch - 1))) {
                 if (ff_eac3_custom_channel_map_locations[ch][0]) {
-                    int index = av_get_channel_layout_channel_index(channel_layout,
-                                                                    ff_eac3_custom_channel_map_locations[ch][1]);
+                    int index = av_channel_layout_index_from_channel(&avctx->ch_layout,
+                                                                     ff_ctzll(ff_eac3_custom_channel_map_locations[ch][1]));
                     if (index < 0)
                         return AVERROR_INVALIDDATA;
                     if (extend >= channel_map_size)
@@ -1739,8 +1757,7 @@ skip:
 
                     for (i = 0; i < 64; i++) {
                         if ((1ULL << i) & ff_eac3_custom_channel_map_locations[ch][1]) {
-                            int index = av_get_channel_layout_channel_index(channel_layout,
-                                                                            1ULL << i);
+                            int index = av_channel_layout_index_from_channel(&avctx->ch_layout, i);
                             if (index < 0)
                                 return AVERROR_INVALIDDATA;
                             if (extend >= channel_map_size)
@@ -1759,7 +1776,7 @@ skip:
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
-    for (ch = 0; ch < avctx->channels; ch++) {
+    for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
         int map = extended_channel_map[ch];
         av_assert0(ch>=AV_NUM_DATA_POINTERS || frame->extended_data[ch] == frame->data[ch]);
         memcpy((SHORTFLOAT *)frame->extended_data[ch],
diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h
index 85653990cf..9444124974 100644
--- a/libavcodec/ac3dec.h
+++ b/libavcodec/ac3dec.h
@@ -251,6 +251,8 @@ typedef struct AC3DecodeContext {
     DECLARE_ALIGNED(32, uint8_t, input_buffer)[AC3_FRAME_BUFFER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; ///< temp buffer to prevent overread
     DECLARE_ALIGNED(32, SHORTFLOAT, output_buffer)[EAC3_MAX_CHANNELS][AC3_BLOCK_SIZE * 6];  ///< final output buffer
 ///@}
+
+    AVChannelLayout downmix_layout;
 } AC3DecodeContext;
 
 /**
diff --git a/libavcodec/ac3dec_fixed.c b/libavcodec/ac3dec_fixed.c
index 8645952621..ae433c5cc7 100644
--- a/libavcodec/ac3dec_fixed.c
+++ b/libavcodec/ac3dec_fixed.c
@@ -157,6 +157,7 @@ static const AVOption options[] = {
     { "cons_noisegen", "enable consistent noise generation", OFFSET(consistent_noise_generation), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR },
     { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 6.0, PAR },
     { "heavy_compr", "enable heavy dynamic range compression", OFFSET(heavy_compression), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR },
+    { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = PAR },
     { NULL},
 };
 
diff --git a/libavcodec/ac3dec_float.c b/libavcodec/ac3dec_float.c
index 573fbe75b6..2b1b359a0c 100644
--- a/libavcodec/ac3dec_float.c
+++ b/libavcodec/ac3dec_float.c
@@ -43,6 +43,8 @@ static const AVOption options[] = {
 {"loro_cmixlev",   "Lo/Ro Center Mix Level",   OFFSET(loro_center_mix_level),    AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
 {"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level),  AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
 
+    { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = PAR },
+
     { NULL},
 };
 
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 034aa0beb9..30ba8bfecd 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -147,6 +147,7 @@ static uint8_t exponent_group_tab[2][3][256];
 /**
  * List of supported channel layouts.
  */
+#if FF_API_OLD_CHANNEL_LAYOUT
 const uint64_t ff_ac3_channel_layouts[19] = {
      AV_CH_LAYOUT_MONO,
      AV_CH_LAYOUT_STEREO,
@@ -168,6 +169,47 @@ const uint64_t ff_ac3_channel_layouts[19] = {
      AV_CH_LAYOUT_5POINT1_BACK,
      0
 };
+#endif
+
+const AVChannelLayout ff_ac3_ch_layouts[19] = {
+    AV_CHANNEL_LAYOUT_MONO,
+    AV_CHANNEL_LAYOUT_STEREO,
+    AV_CHANNEL_LAYOUT_2_1,
+    AV_CHANNEL_LAYOUT_SURROUND,
+    AV_CHANNEL_LAYOUT_2_2,
+    AV_CHANNEL_LAYOUT_QUAD,
+    AV_CHANNEL_LAYOUT_4POINT0,
+    AV_CHANNEL_LAYOUT_5POINT0,
+    AV_CHANNEL_LAYOUT_5POINT0_BACK,
+    {
+        .nb_channels = 2,
+        .order       = AV_CHANNEL_ORDER_NATIVE,
+        .u.mask      = AV_CH_LAYOUT_MONO | AV_CH_LOW_FREQUENCY,
+    },
+    {
+        .nb_channels = 3,
+        .order       = AV_CHANNEL_ORDER_NATIVE,
+        .u.mask      = AV_CH_LAYOUT_STEREO | AV_CH_LOW_FREQUENCY,
+    },
+    {
+        .nb_channels = 4,
+        .order       = AV_CHANNEL_ORDER_NATIVE,
+        .u.mask      = AV_CH_LAYOUT_2_1 | AV_CH_LOW_FREQUENCY,
+    },
+    {
+        .nb_channels = 4,
+        .order       = AV_CHANNEL_ORDER_NATIVE,
+        .u.mask      = AV_CH_LAYOUT_SURROUND | AV_CH_LOW_FREQUENCY,
+    },
+    {
+        .nb_channels = 5,
+        .order       = AV_CHANNEL_ORDER_NATIVE,
+        .u.mask      = AV_CH_LAYOUT_4POINT0 | AV_CH_LOW_FREQUENCY,
+    },
+    AV_CHANNEL_LAYOUT_5POINT1,
+    AV_CHANNEL_LAYOUT_5POINT1_BACK,
+    { 0 },
+};
 
 /**
  * Table to remap channels from SMPTE order to AC-3 order.
@@ -1797,7 +1839,7 @@ static void dprint_options(AC3EncodeContext *s)
     }
     ff_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id);
     ff_dlog(avctx, "sample_fmt: %s\n", av_get_sample_fmt_name(avctx->sample_fmt));
-    av_get_channel_layout_string(strbuf, 32, s->channels, avctx->channel_layout);
+    av_channel_layout_describe(&avctx->ch_layout, strbuf, sizeof(strbuf));
     ff_dlog(avctx, "channel_layout: %s\n", strbuf);
     ff_dlog(avctx, "sample_rate: %d\n", s->sample_rate);
     ff_dlog(avctx, "bit_rate: %d\n", s->bit_rate);
@@ -2041,11 +2083,11 @@ int ff_ac3_validate_metadata(AC3EncodeContext *s)
 
     /* validate audio service type / channels combination */
     if ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_KARAOKE &&
-         avctx->channels == 1) ||
+         avctx->ch_layout.nb_channels == 1) ||
         ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_COMMENTARY ||
           avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_EMERGENCY  ||
           avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_VOICE_OVER)
-         && avctx->channels > 1)) {
+         && avctx->ch_layout.nb_channels > 1)) {
         av_log(avctx, AV_LOG_ERROR, "invalid audio service type for the "
                                     "specified number of channels\n");
         return AVERROR(EINVAL);
@@ -2167,27 +2209,29 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
 /*
  * Set channel information during initialization.
  */
-static av_cold int set_channel_info(AC3EncodeContext *s, int channels,
-                                    uint64_t *channel_layout)
+static av_cold int set_channel_info(AVCodecContext *avctx)
 {
-    int ch_layout;
+    AC3EncodeContext *s = avctx->priv_data;
+    int channels = avctx->ch_layout.nb_channels;
+    uint64_t mask = avctx->ch_layout.u.mask;
 
     if (channels < 1 || channels > AC3_MAX_CHANNELS)
         return AVERROR(EINVAL);
-    if (*channel_layout > 0x7FF)
+    if (mask > 0x7FF)
         return AVERROR(EINVAL);
-    ch_layout = *channel_layout;
-    if (!ch_layout)
-        ch_layout = av_get_default_channel_layout(channels);
 
-    s->lfe_on       = !!(ch_layout & AV_CH_LOW_FREQUENCY);
+    if (!mask)
+        av_channel_layout_default(&avctx->ch_layout, channels);
+    mask = avctx->ch_layout.u.mask;
+
+    s->lfe_on       = !!(mask & AV_CH_LOW_FREQUENCY);
     s->channels     = channels;
     s->fbw_channels = channels - s->lfe_on;
     s->lfe_channel  = s->lfe_on ? s->fbw_channels + 1 : -1;
     if (s->lfe_on)
-        ch_layout -= AV_CH_LOW_FREQUENCY;
+        mask -= AV_CH_LOW_FREQUENCY;
 
-    switch (ch_layout) {
+    switch (mask) {
     case AV_CH_LAYOUT_MONO:           s->channel_mode = AC3_CHMODE_MONO;   break;
     case AV_CH_LAYOUT_STEREO:         s->channel_mode = AC3_CHMODE_STEREO; break;
     case AV_CH_LAYOUT_SURROUND:       s->channel_mode = AC3_CHMODE_3F;     break;
@@ -2204,9 +2248,9 @@ static av_cold int set_channel_info(AC3EncodeContext *s, int channels,
     s->has_surround =  s->channel_mode & 0x04;
 
     s->channel_map  = ac3_enc_channel_map[s->channel_mode][s->lfe_on];
-    *channel_layout = ch_layout;
     if (s->lfe_on)
-        *channel_layout |= AV_CH_LOW_FREQUENCY;
+        mask |= AV_CH_LOW_FREQUENCY;
+    av_channel_layout_from_mask(&avctx->ch_layout, mask);
 
     return 0;
 }
@@ -2218,12 +2262,12 @@ static av_cold int validate_options(AC3EncodeContext *s)
     int i, ret, max_sr;
 
     /* validate channel layout */
-    if (!avctx->channel_layout) {
+    if (!avctx->ch_layout.nb_channels) {
         av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
                                       "encoder will guess the layout, but it "
                                       "might be incorrect.\n");
     }
-    ret = set_channel_info(s, avctx->channels, &avctx->channel_layout);
+    ret = set_channel_info(avctx);
     if (ret) {
         av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");
         return ret;
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 39a41fe0b0..647a7769ec 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -266,8 +266,10 @@ typedef struct AC3EncodeContext {
     void (*output_frame_header)(struct AC3EncodeContext *s);
 } AC3EncodeContext;
 
-
+#if FF_API_OLD_CHANNEL_LAYOUT
 extern const uint64_t ff_ac3_channel_layouts[19];
+#endif
+extern const AVChannelLayout ff_ac3_ch_layouts[19];
 extern const AVOption ff_ac3_enc_options[];
 extern const AVClass ff_ac3enc_class;
 extern const AVCodecDefault ff_ac3_enc_defaults[];
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index 80aa98c691..6e0abf4a26 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -119,6 +119,7 @@ static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx)
 }
 
 
+FF_DISABLE_DEPRECATION_WARNINGS
 const AVCodec ff_ac3_fixed_encoder = {
     .name            = "ac3_fixed",
     .long_name       = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
@@ -134,6 +135,10 @@ const AVCodec ff_ac3_fixed_encoder = {
     .priv_class      = &ff_ac3enc_class,
     .caps_internal   = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
     .supported_samplerates = ff_ac3_sample_rate_tab,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts = ff_ac3_channel_layouts,
+#endif
+    .ch_layouts      = ff_ac3_ch_layouts,
     .defaults        = ff_ac3_enc_defaults,
 };
+FF_ENABLE_DEPRECATION_WARNINGS
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index e4a3794dd8..0e605cdf2c 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -123,6 +123,7 @@ av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx)
     return ff_ac3_encode_init(avctx);
 }
 
+FF_DISABLE_DEPRECATION_WARNINGS
 const AVCodec ff_ac3_encoder = {
     .name            = "ac3",
     .long_name       = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
@@ -137,7 +138,11 @@ const AVCodec ff_ac3_encoder = {
                                                       AV_SAMPLE_FMT_NONE },
     .priv_class      = &ff_ac3enc_class,
     .supported_samplerates = ff_ac3_sample_rate_tab,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts = ff_ac3_channel_layouts,
+#endif
+    .ch_layouts      = ff_ac3_ch_layouts,
     .defaults        = ff_ac3_enc_defaults,
     .caps_internal   = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
+FF_ENABLE_DEPRECATION_WARNINGS
diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c
index 96ef00ea4f..c959aec55c 100644
--- a/libavcodec/eac3enc.c
+++ b/libavcodec/eac3enc.c
@@ -248,6 +248,7 @@ void ff_eac3_output_frame_header(AC3EncodeContext *s)
 }
 
 
+FF_DISABLE_DEPRECATION_WARNINGS
 const AVCodec ff_eac3_encoder = {
     .name            = "eac3",
     .long_name       = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"),
@@ -262,7 +263,11 @@ const AVCodec ff_eac3_encoder = {
                                                       AV_SAMPLE_FMT_NONE },
     .priv_class      = &eac3enc_class,
     .supported_samplerates = ff_ac3_sample_rate_tab,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts = ff_ac3_channel_layouts,
+#endif
+    .ch_layouts      = ff_ac3_ch_layouts,
     .defaults        = ff_ac3_enc_defaults,
     .caps_internal   = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
+FF_ENABLE_DEPRECATION_WARNINGS
diff --git a/tests/fate/ac3.mak b/tests/fate/ac3.mak
index 39b555161d..f0c3d18049 100644
--- a/tests/fate/ac3.mak
+++ b/tests/fate/ac3.mak
@@ -6,13 +6,13 @@ FATE_AC3 += fate-ac3-4.0
 fate-ac3-4.0: CMD = pcm -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3
 fate-ac3-4.0: REF = $(SAMPLES)/ac3/millers_crossing_4.0_v2.pcm
 
-#request_channel_layout 4 -> front channel
+#downmix 4.0 -> front channel
 FATE_AC3 += fate-ac3-4.0-downmix-mono
-fate-ac3-4.0-downmix-mono: CMD = pcm -request_channel_layout 4 -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3
+fate-ac3-4.0-downmix-mono: CMD = pcm -downmix mono -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3
 fate-ac3-4.0-downmix-mono: REF = $(SAMPLES)/ac3/millers_crossing_4.0_mono_v2.pcm
 
 FATE_AC3 += fate-ac3-4.0-downmix-stereo
-fate-ac3-4.0-downmix-stereo: CMD = pcm -request_channel_layout stereo -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3
+fate-ac3-4.0-downmix-stereo: CMD = pcm -downmix stereo -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3
 fate-ac3-4.0-downmix-stereo: REF = $(SAMPLES)/ac3/millers_crossing_4.0_stereo_v2.pcm
 
 FATE_AC3 += fate-ac3-5.1
@@ -20,11 +20,11 @@ fate-ac3-5.1: CMD = pcm -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
 fate-ac3-5.1: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_v2.pcm
 
 FATE_AC3 += fate-ac3-5.1-downmix-mono
-fate-ac3-5.1-downmix-mono: CMD = pcm -request_channel_layout FC -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
+fate-ac3-5.1-downmix-mono: CMD = pcm -downmix FC -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
 fate-ac3-5.1-downmix-mono: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_mono_v2.pcm
 
 FATE_AC3 += fate-ac3-5.1-downmix-stereo
-fate-ac3-5.1-downmix-stereo: CMD = pcm -request_channel_layout 2c -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
+fate-ac3-5.1-downmix-stereo: CMD = pcm -downmix stereo -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
 fate-ac3-5.1-downmix-stereo: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_stereo_v2.pcm
 
 FATE_AC3 += fate-ac3-fixed-2.0
@@ -32,15 +32,15 @@ fate-ac3-fixed-2.0: CMD = pcm -c ac3_fixed -i $(TARGET_SAMPLES)/ac3/monsters_inc
 fate-ac3-fixed-2.0: REF = $(SAMPLES)/ac3/monsters_inc_2.0_192_small_v2.pcm
 
 FATE_AC3 += fate-ac3-fixed-4.0-downmix-mono
-fate-ac3-fixed-4.0-downmix-mono: CMD = pcm -c ac3_fixed -request_channel_layout mono -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3
+fate-ac3-fixed-4.0-downmix-mono: CMD = pcm -c ac3_fixed -downmix mono -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3
 fate-ac3-fixed-4.0-downmix-mono: REF = $(SAMPLES)/ac3/millers_crossing_4.0_mono_v2.pcm
 
 FATE_AC3 += fate-ac3-fixed-5.1-downmix-mono
-fate-ac3-fixed-5.1-downmix-mono: CMD = pcm -c ac3_fixed -request_channel_layout 4 -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
+fate-ac3-fixed-5.1-downmix-mono: CMD = pcm -c ac3_fixed -downmix mono -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
 fate-ac3-fixed-5.1-downmix-mono: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_mono_v2.pcm
 
 FATE_AC3 += fate-ac3-fixed-5.1-downmix-stereo
-fate-ac3-fixed-5.1-downmix-stereo: CMD = pcm -c ac3_fixed -request_channel_layout 3 -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
+fate-ac3-fixed-5.1-downmix-stereo: CMD = pcm -c ac3_fixed -downmix stereo -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3
 fate-ac3-fixed-5.1-downmix-stereo: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_stereo_v2.pcm
 
 FATE_EAC3 += fate-eac3-1
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 184/281] adpcm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (184 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 183/281] ac3: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 185/281] adx: " James Almer
                   ` (96 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/adpcm.c    | 151 ++++++++++++++++++++++--------------------
 libavcodec/adpcmenc.c | 122 +++++++++++++++++-----------------
 2 files changed, 141 insertions(+), 132 deletions(-)

diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index cfde5f58b9..0591314302 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -271,14 +271,15 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
     case AV_CODEC_ID_ADPCM_MTAF:
         min_channels = 2;
         max_channels = 8;
-        if (avctx->channels & 1) {
-            avpriv_request_sample(avctx, "channel count %d", avctx->channels);
+        if (avctx->ch_layout.nb_channels & 1) {
+            avpriv_request_sample(avctx, "channel count %d", avctx->ch_layout.nb_channels);
             return AVERROR_PATCHWELCOME;
         }
         break;
     case AV_CODEC_ID_ADPCM_PSX:
         max_channels = 8;
-        if (avctx->channels <= 0 || avctx->block_align % (16 * avctx->channels))
+        if (avctx->ch_layout.nb_channels <= 0 ||
+            avctx->block_align % (16 * avctx->ch_layout.nb_channels))
             return AVERROR_INVALIDDATA;
         break;
     case AV_CODEC_ID_ADPCM_IMA_DAT4:
@@ -287,7 +288,8 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
         max_channels = 14;
         break;
     }
-    if (avctx->channels < min_channels || avctx->channels > max_channels) {
+    if (avctx->ch_layout.nb_channels < min_channels ||
+        avctx->ch_layout.nb_channels > max_channels) {
         av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
         return AVERROR(EINVAL);
     }
@@ -298,7 +300,8 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
             return AVERROR_INVALIDDATA;
         break;
     case AV_CODEC_ID_ADPCM_ARGO:
-        if (avctx->bits_per_coded_sample != 4 || avctx->block_align != 17 * avctx->channels)
+        if (avctx->bits_per_coded_sample != 4 ||
+            avctx->block_align != 17 * avctx->ch_layout.nb_channels)
             return AVERROR_INVALIDDATA;
         break;
     case AV_CODEC_ID_ADPCM_ZORK:
@@ -336,7 +339,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
                                                   AV_SAMPLE_FMT_S16;
         break;
     case AV_CODEC_ID_ADPCM_MS:
-        avctx->sample_fmt = avctx->channels > 2 ? AV_SAMPLE_FMT_S16P :
+        avctx->sample_fmt = avctx->ch_layout.nb_channels > 2 ? AV_SAMPLE_FMT_S16P :
                                                   AV_SAMPLE_FMT_S16;
         break;
     default:
@@ -755,6 +758,7 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_
     ADPCMDecodeContext *c = avctx->priv_data;
     GetBitContext gb;
     const int8_t *table;
+    int channels = avctx->ch_layout.nb_channels;
     int k0, signmask, nb_bits, count;
     int size = buf_size*8;
     int i;
@@ -767,16 +771,16 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_
     k0 = 1 << (nb_bits-2);
     signmask = 1 << (nb_bits-1);
 
-    while (get_bits_count(&gb) <= size - 22*avctx->channels) {
-        for (i = 0; i < avctx->channels; i++) {
+    while (get_bits_count(&gb) <= size - 22 * channels) {
+        for (i = 0; i < channels; i++) {
             *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
             c->status[i].step_index = get_bits(&gb, 6);
         }
 
-        for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
+        for (count = 0; get_bits_count(&gb) <= size - nb_bits * channels && count < 4095; count++) {
             int i;
 
-            for (i = 0; i < avctx->channels; i++) {
+            for (i = 0; i < channels; i++) {
                 // similar to IMA adpcm
                 int delta = get_bits(&gb, nb_bits);
                 int step = ff_adpcm_step_table[c->status[i].step_index];
@@ -840,7 +844,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
 {
     ADPCMDecodeContext *s = avctx->priv_data;
     int nb_samples        = 0;
-    int ch                = avctx->channels;
+    int ch                = avctx->ch_layout.nb_channels;
     int has_coded_samples = 0;
     int header_size;
 
@@ -1061,6 +1065,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     ADPCMDecodeContext *c = avctx->priv_data;
+    int channels = avctx->ch_layout.nb_channels;
     int16_t *samples;
     int16_t **samples_p;
     int st; /* stereo */
@@ -1089,13 +1094,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         frame->nb_samples = nb_samples = coded_samples;
     }
 
-    st = avctx->channels == 2 ? 1 : 0;
+    st = channels == 2 ? 1 : 0;
 
     switch(avctx->codec->id) {
     CASE(ADPCM_IMA_QT,
         /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
            Channel data is interleaved per-chunk. */
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < channels; channel++) {
             ADPCMChannelStatus *cs = &c->status[channel];
             int predictor;
             int step_index;
@@ -1134,7 +1139,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_WAV,
-        for (int i = 0; i < avctx->channels; i++) {
+        for (int i = 0; i < channels; i++) {
             ADPCMChannelStatus *cs = &c->status[i];
             cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
 
@@ -1153,12 +1158,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
             GetBitContext g;
 
             for (int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
-                for (int i = 0; i < avctx->channels; i++) {
+                for (int i = 0; i < channels; i++) {
                     ADPCMChannelStatus *cs = &c->status[i];
                     samples = &samples_p[i][1 + n * samples_per_block];
                     for (int j = 0; j < block_size; j++) {
-                        temp[j] = buf[4 * avctx->channels + block_size * n * avctx->channels +
-                                        (j % 4) + (j / 4) * (avctx->channels * 4) + i * 4];
+                        temp[j] = buf[4 * channels + block_size * n * channels +
+                                        (j % 4) + (j / 4) * (channels * 4) + i * 4];
                     }
                     ret = init_get_bits8(&g, (const uint8_t *)&temp, block_size);
                     if (ret < 0)
@@ -1169,10 +1174,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
                     }
                 }
             }
-            bytestream2_skip(&gb, avctx->block_align - avctx->channels * 4);
+            bytestream2_skip(&gb, avctx->block_align - channels * 4);
         } else {
             for (int n = 0; n < (nb_samples - 1) / 8; n++) {
-                for (int i = 0; i < avctx->channels; i++) {
+                for (int i = 0; i < channels; i++) {
                     ADPCMChannelStatus *cs = &c->status[i];
                     samples = &samples_p[i][1 + n * 8];
                     for (int m = 0; m < 8; m += 2) {
@@ -1185,10 +1190,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_4XM,
-        for (int i = 0; i < avctx->channels; i++)
+        for (int i = 0; i < channels; i++)
             c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
 
-        for (int i = 0; i < avctx->channels; i++) {
+        for (int i = 0; i < channels; i++) {
             c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
             if (c->status[i].step_index > 88u) {
                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
@@ -1197,7 +1202,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
             }
         }
 
-        for (int i = 0; i < avctx->channels; i++) {
+        for (int i = 0; i < channels; i++) {
             ADPCMChannelStatus *cs = &c->status[i];
             samples = (int16_t *)frame->data[i];
             for (int n = nb_samples >> 1; n > 0; n--) {
@@ -1208,9 +1213,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_AGM,
-        for (int i = 0; i < avctx->channels; i++)
+        for (int i = 0; i < channels; i++)
             c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
-        for (int i = 0; i < avctx->channels; i++)
+        for (int i = 0; i < channels; i++)
             c->status[i].step = sign_extend(bytestream2_get_le16u(&gb), 16);
 
         for (int n = 0; n < nb_samples >> (1 - st); n++) {
@@ -1222,8 +1227,8 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
     CASE(ADPCM_MS,
         int block_predictor;
 
-        if (avctx->channels > 2) {
-            for (int channel = 0; channel < avctx->channels; channel++) {
+        if (avctx->ch_layout.nb_channels > 2) {
+            for (int channel = 0; channel < avctx->ch_layout.nb_channels; channel++) {
                 samples = samples_p[channel];
                 block_predictor = bytestream2_get_byteu(&gb);
                 if (block_predictor > 6) {
@@ -1285,7 +1290,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_MTAF,
-        for (int channel = 0; channel < avctx->channels; channel += 2) {
+        for (int channel = 0; channel < channels; channel += 2) {
             bytestream2_skipu(&gb, 4);
             c->status[channel    ].step      = bytestream2_get_le16u(&gb) & 0x1f;
             c->status[channel + 1].step      = bytestream2_get_le16u(&gb) & 0x1f;
@@ -1306,7 +1311,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_DK4,
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < channels; channel++) {
             ADPCMChannelStatus *cs = &c->status[channel];
             cs->predictor  = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
             cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1338,7 +1343,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         int nibble;
         int decode_top_nibble_next = 0;
         int diff_channel;
-        const int16_t *samples_end = samples + avctx->channels * nb_samples;
+        const int16_t *samples_end = samples + channels * nb_samples;
 
         bytestream2_skipu(&gb, 10);
         c->status[0].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1385,7 +1390,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
             bytestream2_skip(&gb, 1);
         ) /* End of CASE */
     CASE(ADPCM_IMA_ISS,
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < channels; channel++) {
             ADPCMChannelStatus *cs = &c->status[channel];
             cs->predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);
             cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1412,7 +1417,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_MOFLEX,
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < channels; channel++) {
             ADPCMChannelStatus *cs = &c->status[channel];
             cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
             cs->predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1424,7 +1429,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
 
         for (int subframe = 0; subframe < nb_samples / 256; subframe++) {
-            for (int channel = 0; channel < avctx->channels; channel++) {
+            for (int channel = 0; channel < channels; channel++) {
                 samples = samples_p[channel] + 256 * subframe;
                 for (int n = 0; n < 256; n += 2) {
                     int v = bytestream2_get_byteu(&gb);
@@ -1435,7 +1440,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_DAT4,
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < channels; channel++) {
             ADPCMChannelStatus *cs = &c->status[channel];
             samples = samples_p[channel];
             bytestream2_skip(&gb, 4);
@@ -1462,26 +1467,26 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         ) /* End of CASE */
     CASE(ADPCM_IMA_APM,
         for (int n = nb_samples / 2; n > 0; n--) {
-            for (int channel = 0; channel < avctx->channels; channel++) {
+            for (int channel = 0; channel < channels; channel++) {
                 int v = bytestream2_get_byteu(&gb);
                 *samples++  = adpcm_ima_qt_expand_nibble(&c->status[channel], v >> 4  );
                 samples[st] = adpcm_ima_qt_expand_nibble(&c->status[channel], v & 0x0F);
             }
-            samples += avctx->channels;
+            samples += channels;
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_ALP,
         for (int n = nb_samples / 2; n > 0; n--) {
-            for (int channel = 0; channel < avctx->channels; channel++) {
+            for (int channel = 0; channel < channels; channel++) {
                 int v = bytestream2_get_byteu(&gb);
                 *samples++  = adpcm_ima_alp_expand_nibble(&c->status[channel], v >> 4  , 2);
                 samples[st] = adpcm_ima_alp_expand_nibble(&c->status[channel], v & 0x0F, 2);
             }
-            samples += avctx->channels;
+            samples += channels;
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_CUNNING,
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < channels; channel++) {
             int16_t *smp = samples_p[channel];
             for (int n = 0; n < nb_samples / 2; n++) {
                 int v = bytestream2_get_byteu(&gb);
@@ -1498,7 +1503,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_RAD,
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < channels; channel++) {
             ADPCMChannelStatus *cs = &c->status[channel];
             cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
             cs->predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1514,17 +1519,17 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
             byte[0] = bytestream2_get_byteu(&gb);
             if (st)
                 byte[1] = bytestream2_get_byteu(&gb);
-            for (int channel = 0; channel < avctx->channels; channel++) {
+            for (int channel = 0; channel < channels; channel++) {
                 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] & 0x0F, 3);
             }
-            for (int channel = 0; channel < avctx->channels; channel++) {
+            for (int channel = 0; channel < channels; channel++) {
                 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] >> 4  , 3);
             }
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_WS,
         if (c->vqa_version == 3) {
-            for (int channel = 0; channel < avctx->channels; channel++) {
+            for (int channel = 0; channel < channels; channel++) {
                 int16_t *smp = samples_p[channel];
 
                 for (int n = nb_samples / 2; n > 0; n--) {
@@ -1535,12 +1540,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
             }
         } else {
             for (int n = nb_samples / 2; n > 0; n--) {
-                for (int channel = 0; channel < avctx->channels; channel++) {
+                for (int channel = 0; channel < channels; channel++) {
                     int v = bytestream2_get_byteu(&gb);
                     *samples++  = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
                     samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v >> 4  , 3);
                 }
-                samples += avctx->channels;
+                samples += channels;
             }
         }
         bytestream2_seek(&gb, 0, SEEK_END);
@@ -1548,13 +1553,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
     CASE(ADPCM_XA,
         int16_t *out0 = samples_p[0];
         int16_t *out1 = samples_p[1];
-        int samples_per_block = 28 * (3 - avctx->channels) * 4;
+        int samples_per_block = 28 * (3 - channels) * 4;
         int sample_offset = 0;
         int bytes_remaining;
         while (bytestream2_get_bytes_left(&gb) >= 128) {
             if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),
                                  &c->status[0], &c->status[1],
-                                 avctx->channels, sample_offset)) < 0)
+                                 channels, sample_offset)) < 0)
                 return ret;
             bytestream2_skipu(&gb, 128);
             sample_offset += samples_per_block;
@@ -1604,7 +1609,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,
            each coding 28 stereo samples. */
 
-        if(avctx->channels != 2)
+        if (channels != 2)
             return AVERROR_INVALIDDATA;
 
         current_left_sample   = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1649,7 +1654,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
     CASE(ADPCM_EA_MAXIS_XA,
         int coeff[2][2], shift[2];
 
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < channels; channel++) {
             int byte = bytestream2_get_byteu(&gb);
             for (int i = 0; i < 2; i++)
                 coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];
@@ -1661,7 +1666,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
             byte[0] = bytestream2_get_byteu(&gb);
             if (st) byte[1] = bytestream2_get_byteu(&gb);
             for (int i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
-                for (int channel = 0; channel < avctx->channels; channel++) {
+                for (int channel = 0; channel < channels; channel++) {
                     int sample = sign_extend(byte[channel] >> i, 4) * (1 << shift[channel]);
                     sample = (sample +
                              c->status[channel].sample1 * coeff[channel][0] +
@@ -1690,12 +1695,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         int count = 0;
         int offsets[6];
 
-        for (unsigned channel = 0; channel < avctx->channels; channel++)
+        for (unsigned channel = 0; channel < channels; channel++)
             offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
                                              bytestream2_get_le32(&gb)) +
-                               (avctx->channels + 1) * 4;
+                               (channels + 1) * 4;
 
-        for (unsigned channel = 0; channel < avctx->channels; channel++) {
+        for (unsigned channel = 0; channel < channels; channel++) {
             int count1;
 
             bytestream2_seek(&gb, offsets[channel], SEEK_SET);
@@ -1759,7 +1764,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
     }
 #endif /* CONFIG_ADPCM_EA_Rx_DECODER */
     CASE(ADPCM_EA_XAS,
-        for (int channel=0; channel < avctx->channels; channel++) {
+        for (int channel=0; channel < channels; channel++) {
             int coeff[2][4], shift[4];
             int16_t *s = samples_p[channel];
             for (int n = 0; n < 4; n++, s += 32) {
@@ -1791,7 +1796,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_ACORN,
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < channels; channel++) {
             ADPCMChannelStatus *cs = &c->status[channel];
             cs->predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);
             cs->step_index = bytestream2_get_le16u(&gb) & 0xFF;
@@ -1808,7 +1813,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_AMV,
-        av_assert0(avctx->channels == 1);
+        av_assert0(channels == 1);
 
         /*
          * Header format:
@@ -1848,7 +1853,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_SMJPEG,
-        for (int i = 0; i < avctx->channels; i++) {
+        for (int i = 0; i < channels; i++) {
             c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
             c->status[i].step_index = bytestream2_get_byteu(&gb);
             bytestream2_skipu(&gb, 1);
@@ -1931,7 +1936,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_AICA,
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < channels; channel++) {
             samples = samples_p[channel];
             for (int n = nb_samples >> 1; n > 0; n--) {
                 int v = bytestream2_get_byteu(&gb);
@@ -1953,7 +1958,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
 
         for (int m = 0; m < blocks; m++) {
-            for (int channel = 0; channel < avctx->channels; channel++) {
+            for (int channel = 0; channel < channels; channel++) {
                 int prev1 = c->status[channel].sample1;
                 int prev2 = c->status[channel].sample2;
 
@@ -2005,33 +2010,33 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
 
         if (avctx->extradata) {
             GetByteContext tb;
-            if (avctx->extradata_size < 32 * avctx->channels) {
+            if (avctx->extradata_size < 32 * channels) {
                 av_log(avctx, AV_LOG_ERROR, "Missing coeff table\n");
                 return AVERROR_INVALIDDATA;
             }
 
             bytestream2_init(&tb, avctx->extradata, avctx->extradata_size);
-            for (int i = 0; i < avctx->channels; i++)
+            for (int i = 0; i < channels; i++)
                 for (int n = 0; n < 16; n++)
                     table[i][n] = THP_GET16(tb);
         } else {
-            for (int i = 0; i < avctx->channels; i++)
+            for (int i = 0; i < channels; i++)
                 for (int n = 0; n < 16; n++)
                     table[i][n] = THP_GET16(gb);
 
             if (!c->has_status) {
                 /* Initialize the previous sample.  */
-                for (int i = 0; i < avctx->channels; i++) {
+                for (int i = 0; i < channels; i++) {
                     c->status[i].sample1 = THP_GET16(gb);
                     c->status[i].sample2 = THP_GET16(gb);
                 }
                 c->has_status = 1;
             } else {
-                bytestream2_skip(&gb, avctx->channels * 4);
+                bytestream2_skip(&gb, channels * 4);
             }
         }
 
-        for (int ch = 0; ch < avctx->channels; ch++) {
+        for (int ch = 0; ch < channels; ch++) {
             samples = samples_p[ch];
 
             /* Read in every sample for this channel.  */
@@ -2065,7 +2070,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
     }
 #endif /* CONFIG_ADPCM_THP(_LE)_DECODER */
     CASE(ADPCM_DTK,
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < channels; channel++) {
             samples = samples_p[channel];
 
             /* Read in every sample for this channel.  */
@@ -2113,9 +2118,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_PSX,
-        for (int block = 0; block < avpkt->size / FFMAX(avctx->block_align, 16 * avctx->channels); block++) {
-            int nb_samples_per_block = 28 * FFMAX(avctx->block_align, 16 * avctx->channels) / (16 * avctx->channels);
-            for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int block = 0; block < avpkt->size / FFMAX(avctx->block_align, 16 * channels); block++) {
+            int nb_samples_per_block = 28 * FFMAX(avctx->block_align, 16 * channels) / (16 * channels);
+            for (int channel = 0; channel < channels; channel++) {
                 samples = samples_p[channel] + block * nb_samples_per_block;
                 av_assert0((block + 1) * nb_samples_per_block <= nb_samples);
 
@@ -2172,7 +2177,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
          * They should be 0 initially.
          */
         for (int block = 0; block < avpkt->size / avctx->block_align; block++) {
-            for (int channel = 0; channel < avctx->channels; channel++) {
+            for (int channel = 0; channel < avctx->ch_layout.nb_channels; channel++) {
                 ADPCMChannelStatus *cs = c->status + channel;
                 int control, shift;
 
@@ -2191,19 +2196,19 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         ) /* End of CASE */
     CASE(ADPCM_ZORK,
-        for (int n = 0; n < nb_samples * avctx->channels; n++) {
+        for (int n = 0; n < nb_samples * channels; n++) {
             int v = bytestream2_get_byteu(&gb);
-            *samples++ = adpcm_zork_expand_nibble(&c->status[n % avctx->channels], v);
+            *samples++ = adpcm_zork_expand_nibble(&c->status[n % channels], v);
         }
         ) /* End of CASE */
     CASE(ADPCM_IMA_MTF,
         for (int n = nb_samples / 2; n > 0; n--) {
-            for (int channel = 0; channel < avctx->channels; channel++) {
+            for (int channel = 0; channel < channels; channel++) {
                 int v = bytestream2_get_byteu(&gb);
                 *samples++  = adpcm_ima_mtf_expand_nibble(&c->status[channel], v >> 4);
                 samples[st] = adpcm_ima_mtf_expand_nibble(&c->status[channel], v & 0x0F);
             }
-            samples += avctx->channels;
+            samples += channels;
         }
         ) /* End of CASE */
     default:
diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
index b0f6f209b7..92c31b4841 100644
--- a/libavcodec/adpcmenc.c
+++ b/libavcodec/adpcmenc.c
@@ -79,11 +79,7 @@ typedef struct ADPCMEncodeContext {
 static av_cold int adpcm_encode_init(AVCodecContext *avctx)
 {
     ADPCMEncodeContext *s = avctx->priv_data;
-
-    if (avctx->channels > 2) {
-        av_log(avctx, AV_LOG_ERROR, "only stereo or mono is supported\n");
-        return AVERROR(EINVAL);
-    }
+    int channels = avctx->ch_layout.nb_channels;
 
     /*
      * AMV's block size has to match that of the corresponding video
@@ -130,8 +126,8 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
     CASE(ADPCM_IMA_WAV,
         /* each 16 bits sample gives one nibble
            and we have 4 bytes per channel overhead */
-        avctx->frame_size = (s->block_size - 4 * avctx->channels) * 8 /
-                            (4 * avctx->channels) + 1;
+        avctx->frame_size = (s->block_size - 4 * channels) * 8 /
+                            (4 * channels) + 1;
         /* seems frame_size isn't taken into account...
            have to buffer the samples :-( */
         avctx->block_align = s->block_size;
@@ -139,13 +135,13 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
         ) /* End of CASE */
     CASE(ADPCM_IMA_QT,
         avctx->frame_size  = 64;
-        avctx->block_align = 34 * avctx->channels;
+        avctx->block_align = 34 * channels;
         ) /* End of CASE */
     CASE(ADPCM_MS,
         uint8_t *extradata;
         /* each 16 bits sample gives one nibble
            and we have 7 bytes per channel overhead */
-        avctx->frame_size = (s->block_size - 7 * avctx->channels) * 2 / avctx->channels + 2;
+        avctx->frame_size = (s->block_size - 7 * channels) * 2 / channels + 2;
         avctx->bits_per_coded_sample = 4;
         avctx->block_align     = s->block_size;
         if (!(avctx->extradata = av_malloc(32 + AV_INPUT_BUFFER_PADDING_SIZE)))
@@ -160,7 +156,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
         }
         ) /* End of CASE */
     CASE(ADPCM_YAMAHA,
-        avctx->frame_size  = s->block_size * 2 / avctx->channels;
+        avctx->frame_size  = s->block_size * 2 / channels;
         avctx->block_align = s->block_size;
         ) /* End of CASE */
     CASE(ADPCM_SWF,
@@ -172,11 +168,11 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
             return AVERROR(EINVAL);
         }
         avctx->frame_size  = 4096; /* Hardcoded according to the SWF spec. */
-        avctx->block_align = (2 + avctx->channels * (22 + 4 * (avctx->frame_size - 1)) + 7) / 8;
+        avctx->block_align = (2 + channels * (22 + 4 * (avctx->frame_size - 1)) + 7) / 8;
         ) /* End of CASE */
     case AV_CODEC_ID_ADPCM_IMA_SSI:
     case AV_CODEC_ID_ADPCM_IMA_ALP:
-        avctx->frame_size  = s->block_size * 2 / avctx->channels;
+        avctx->frame_size  = s->block_size * 2 / channels;
         avctx->block_align = s->block_size;
         break;
     CASE(ADPCM_IMA_AMV,
@@ -185,7 +181,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
             return AVERROR(EINVAL);
         }
 
-        if (avctx->channels != 1) {
+        if (channels != 1) {
             av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n");
             return AVERROR(EINVAL);
         }
@@ -194,7 +190,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
         avctx->block_align = 8 + (FFALIGN(avctx->frame_size, 2) / 2);
         ) /* End of CASE */
     CASE(ADPCM_IMA_APM,
-        avctx->frame_size  = s->block_size * 2 / avctx->channels;
+        avctx->frame_size  = s->block_size * 2 / channels;
         avctx->block_align = s->block_size;
 
         if (!(avctx->extradata = av_mallocz(28 + AV_INPUT_BUFFER_PADDING_SIZE)))
@@ -203,11 +199,11 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
         ) /* End of CASE */
     CASE(ADPCM_ARGO,
         avctx->frame_size = 32;
-        avctx->block_align = 17 * avctx->channels;
+        avctx->block_align = 17 * channels;
         ) /* End of CASE */
     CASE(ADPCM_IMA_WS,
         /* each 16 bits sample gives one nibble */
-        avctx->frame_size = s->block_size * 2 / avctx->channels;
+        avctx->frame_size = s->block_size * 2 / channels;
         avctx->block_align = s->block_size;
         ) /* End of CASE */
     default:
@@ -606,16 +602,17 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     int16_t **samples_p;
     uint8_t *dst;
     ADPCMEncodeContext *c = avctx->priv_data;
+    int channels = avctx->ch_layout.nb_channels;
 
     samples = (const int16_t *)frame->data[0];
     samples_p = (int16_t **)frame->extended_data;
-    st = avctx->channels == 2;
+    st = channels == 2;
 
     if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_SSI ||
         avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_ALP ||
         avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_APM ||
         avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_WS)
-        pkt_size = (frame->nb_samples * avctx->channels) / 2;
+        pkt_size = (frame->nb_samples * channels) / 2;
     else
         pkt_size = avctx->block_align;
     if ((ret = ff_get_encode_buffer(avctx, avpkt, pkt_size, 0)) < 0)
@@ -626,7 +623,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     CASE(ADPCM_IMA_WAV,
         int blocks = (frame->nb_samples - 1) / 8;
 
-        for (int ch = 0; ch < avctx->channels; ch++) {
+        for (int ch = 0; ch < channels; ch++) {
             ADPCMChannelStatus *status = &c->status[ch];
             status->prev_sample = samples_p[ch][0];
             /* status->step_index = 0;
@@ -639,15 +636,15 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         /* stereo: 4 bytes (8 samples) for left, 4 bytes for right */
         if (avctx->trellis > 0) {
             uint8_t *buf;
-            if (!FF_ALLOC_TYPED_ARRAY(buf, avctx->channels * blocks * 8))
+            if (!FF_ALLOC_TYPED_ARRAY(buf, channels * blocks * 8))
                 return AVERROR(ENOMEM);
-            for (int ch = 0; ch < avctx->channels; ch++) {
+            for (int ch = 0; ch < channels; ch++) {
                 adpcm_compress_trellis(avctx, &samples_p[ch][1],
                                        buf + ch * blocks * 8, &c->status[ch],
                                        blocks * 8, 1);
             }
             for (int i = 0; i < blocks; i++) {
-                for (int ch = 0; ch < avctx->channels; ch++) {
+                for (int ch = 0; ch < channels; ch++) {
                     uint8_t *buf1 = buf + ch * blocks * 8 + i * 8;
                     for (int j = 0; j < 8; j += 2)
                         *dst++ = buf1[j] | (buf1[j + 1] << 4);
@@ -656,7 +653,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
             av_free(buf);
         } else {
             for (int i = 0; i < blocks; i++) {
-                for (int ch = 0; ch < avctx->channels; ch++) {
+                for (int ch = 0; ch < channels; ch++) {
                     ADPCMChannelStatus *status = &c->status[ch];
                     const int16_t *smp = &samples_p[ch][1 + i * 8];
                     for (int j = 0; j < 8; j += 2) {
@@ -672,7 +669,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         PutBitContext pb;
         init_put_bits(&pb, dst, pkt_size);
 
-        for (int ch = 0; ch < avctx->channels; ch++) {
+        for (int ch = 0; ch < channels; ch++) {
             ADPCMChannelStatus *status = &c->status[ch];
             put_bits(&pb, 9, (status->prev_sample & 0xFFFF) >> 7);
             put_bits(&pb, 7,  status->step_index);
@@ -703,7 +700,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         av_assert0(avctx->trellis == 0);
 
         for (int i = 0; i < frame->nb_samples; i++) {
-            for (int ch = 0; ch < avctx->channels; ch++) {
+            for (int ch = 0; ch < channels; ch++) {
                 put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, *samples++));
             }
         }
@@ -717,11 +714,11 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         av_assert0(avctx->trellis == 0);
 
         for (int n = frame->nb_samples / 2; n > 0; n--) {
-            for (int ch = 0; ch < avctx->channels; ch++) {
+            for (int ch = 0; ch < channels; ch++) {
                 put_bits(&pb, 4, adpcm_ima_alp_compress_sample(c->status + ch, *samples++));
                 put_bits(&pb, 4, adpcm_ima_alp_compress_sample(c->status + ch, samples[st]));
             }
-            samples += avctx->channels;
+            samples += channels;
         }
 
         flush_put_bits(&pb);
@@ -738,7 +735,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         put_bits(&pb, 2, 2);    // set 4-bit flash adpcm format
 
         // init the encoder state
-        for (int i = 0; i < avctx->channels; i++) {
+        for (int i = 0; i < channels; i++) {
             // clip step so it fits 6 bits
             c->status[i].step_index = av_clip_uintp2(c->status[i].step_index, 6);
             put_sbits(&pb, 16, samples[i]);
@@ -748,22 +745,22 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
         if (avctx->trellis > 0) {
             uint8_t buf[8190 /* = 2 * n */];
-            adpcm_compress_trellis(avctx, samples + avctx->channels, buf,
-                                   &c->status[0], n, avctx->channels);
-            if (avctx->channels == 2)
-                adpcm_compress_trellis(avctx, samples + avctx->channels + 1,
+            adpcm_compress_trellis(avctx, samples + channels, buf,
+                                   &c->status[0], n, channels);
+            if (channels == 2)
+                adpcm_compress_trellis(avctx, samples + channels + 1,
                                        buf + n, &c->status[1], n,
-                                       avctx->channels);
+                                       channels);
             for (int i = 0; i < n; i++) {
                 put_bits(&pb, 4, buf[i]);
-                if (avctx->channels == 2)
+                if (channels == 2)
                     put_bits(&pb, 4, buf[n + i]);
             }
         } else {
             for (int i = 1; i < frame->nb_samples; i++) {
                 put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0],
-                         samples[avctx->channels * i]));
-                if (avctx->channels == 2)
+                         samples[channels * i]));
+                if (channels == 2)
                     put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1],
                              samples[2 * i + 1]));
             }
@@ -771,47 +768,47 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         flush_put_bits(&pb);
         ) /* End of CASE */
     CASE(ADPCM_MS,
-        for (int i = 0; i < avctx->channels; i++) {
+        for (int i = 0; i < channels; i++) {
             int predictor = 0;
             *dst++ = predictor;
             c->status[i].coeff1 = ff_adpcm_AdaptCoeff1[predictor];
             c->status[i].coeff2 = ff_adpcm_AdaptCoeff2[predictor];
         }
-        for (int i = 0; i < avctx->channels; i++) {
+        for (int i = 0; i < channels; i++) {
             if (c->status[i].idelta < 16)
                 c->status[i].idelta = 16;
             bytestream_put_le16(&dst, c->status[i].idelta);
         }
-        for (int i = 0; i < avctx->channels; i++)
+        for (int i = 0; i < channels; i++)
             c->status[i].sample2= *samples++;
-        for (int i = 0; i < avctx->channels; i++) {
+        for (int i = 0; i < channels; i++) {
             c->status[i].sample1 = *samples++;
             bytestream_put_le16(&dst, c->status[i].sample1);
         }
-        for (int i = 0; i < avctx->channels; i++)
+        for (int i = 0; i < channels; i++)
             bytestream_put_le16(&dst, c->status[i].sample2);
 
         if (avctx->trellis > 0) {
-            const int n  = avctx->block_align - 7 * avctx->channels;
+            const int n  = avctx->block_align - 7 * channels;
             uint8_t *buf = av_malloc(2 * n);
             if (!buf)
                 return AVERROR(ENOMEM);
-            if (avctx->channels == 1) {
+            if (channels == 1) {
                 adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n,
-                                       avctx->channels);
+                                       channels);
                 for (int i = 0; i < n; i += 2)
                     *dst++ = (buf[i] << 4) | buf[i + 1];
             } else {
                 adpcm_compress_trellis(avctx, samples,     buf,
-                                       &c->status[0], n, avctx->channels);
+                                       &c->status[0], n, channels);
                 adpcm_compress_trellis(avctx, samples + 1, buf + n,
-                                       &c->status[1], n, avctx->channels);
+                                       &c->status[1], n, channels);
                 for (int i = 0; i < n; i++)
                     *dst++ = (buf[i] << 4) | buf[n + i];
             }
             av_free(buf);
         } else {
-            for (int i = 7 * avctx->channels; i < avctx->block_align; i++) {
+            for (int i = 7 * channels; i < avctx->block_align; i++) {
                 int nibble;
                 nibble  = adpcm_ms_compress_sample(&c->status[ 0], *samples++) << 4;
                 nibble |= adpcm_ms_compress_sample(&c->status[st], *samples++);
@@ -826,22 +823,22 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
             if (!buf)
                 return AVERROR(ENOMEM);
             n *= 2;
-            if (avctx->channels == 1) {
+            if (channels == 1) {
                 adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n,
-                                       avctx->channels);
+                                       channels);
                 for (int i = 0; i < n; i += 2)
                     *dst++ = buf[i] | (buf[i + 1] << 4);
             } else {
                 adpcm_compress_trellis(avctx, samples,     buf,
-                                       &c->status[0], n, avctx->channels);
+                                       &c->status[0], n, channels);
                 adpcm_compress_trellis(avctx, samples + 1, buf + n,
-                                       &c->status[1], n, avctx->channels);
+                                       &c->status[1], n, channels);
                 for (int i = 0; i < n; i++)
                     *dst++ = buf[i] | (buf[n + i] << 4);
             }
             av_free(buf);
         } else
-            for (n *= avctx->channels; n > 0; n--) {
+            for (n *= channels; n > 0; n--) {
                 int nibble;
                 nibble  = adpcm_yamaha_compress_sample(&c->status[ 0], *samples++);
                 nibble |= adpcm_yamaha_compress_sample(&c->status[st], *samples++) << 4;
@@ -855,17 +852,17 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         av_assert0(avctx->trellis == 0);
 
         for (int n = frame->nb_samples / 2; n > 0; n--) {
-            for (int ch = 0; ch < avctx->channels; ch++) {
+            for (int ch = 0; ch < channels; ch++) {
                 put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, *samples++));
                 put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, samples[st]));
             }
-            samples += avctx->channels;
+            samples += channels;
         }
 
         flush_put_bits(&pb);
         ) /* End of CASE */
     CASE(ADPCM_IMA_AMV,
-        av_assert0(avctx->channels == 1);
+        av_assert0(channels == 1);
 
         c->status[0].prev_sample = *samples;
         bytestream_put_le16(&dst, c->status[0].prev_sample);
@@ -880,7 +877,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
             if (!buf)
                 return AVERROR(ENOMEM);
 
-            adpcm_compress_trellis(avctx, samples, buf, &c->status[0], 2 * n, avctx->channels);
+            adpcm_compress_trellis(avctx, samples, buf, &c->status[0], 2 * n, channels);
             for (int i = 0; i < n; i++)
                 bytestream_put_byte(&dst, (buf[2 * i] << 4) | buf[2 * i + 1]);
 
@@ -904,7 +901,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
         av_assert0(frame->nb_samples == 32);
 
-        for (int ch = 0; ch < avctx->channels; ch++) {
+        for (int ch = 0; ch < channels; ch++) {
             int64_t error  = INT64_MAX, tmperr = INT64_MAX;
             int     shift  = 2, flag = 0;
             int     saved1 = c->status[ch].sample1;
@@ -941,14 +938,14 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         av_assert0(avctx->trellis == 0);
         for (int n = frame->nb_samples / 2; n > 0; n--) {
             /* stereo: 1 byte (2 samples) for left, 1 byte for right */
-            for (int ch = 0; ch < avctx->channels; ch++) {
+            for (int ch = 0; ch < channels; ch++) {
                 int t1, t2;
                 t1 = adpcm_ima_compress_sample(&c->status[ch], *samples++);
                 t2 = adpcm_ima_compress_sample(&c->status[ch], samples[st]);
                 put_bits(&pb, 4, t2);
                 put_bits(&pb, 4, t1);
             }
-            samples += avctx->channels;
+            samples += channels;
         }
         flush_put_bits(&pb);
         ) /* End of CASE */
@@ -968,6 +965,12 @@ static const enum AVSampleFormat sample_fmts_p[] = {
     AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE
 };
 
+static const AVChannelLayout ch_layouts[] = {
+    AV_CHANNEL_LAYOUT_MONO,
+    AV_CHANNEL_LAYOUT_STEREO,
+    { 0 },
+};
+
 static const AVOption options[] = {
     {
         .name        = "block_size",
@@ -1001,6 +1004,7 @@ const AVCodec ff_ ## name_ ## _encoder = {                                 \
     .encode2        = adpcm_encode_frame,                                  \
     .close          = adpcm_encode_close,                                  \
     .sample_fmts    = sample_fmts_,                                        \
+    .ch_layouts     = ch_layouts,                                          \
     .capabilities   = capabilities_ | AV_CODEC_CAP_DR1,                    \
     .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, \
     .priv_class     = &adpcm_encoder_class,                                \
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 185/281] adx: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (185 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 184/281] adpcm: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 186/281] alac: " James Almer
                   ` (95 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/adx.c    | 16 +++++++++++-----
 libavcodec/adxdec.c |  6 +++---
 libavcodec/adxenc.c | 11 ++++++-----
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/libavcodec/adx.c b/libavcodec/adx.c
index cd88b16660..c60fabb40b 100644
--- a/libavcodec/adx.c
+++ b/libavcodec/adx.c
@@ -38,7 +38,7 @@ void ff_adx_calculate_coeffs(int cutoff, int sample_rate, int bits, int *coeff)
 int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf,
                          int bufsize, int *header_size, int *coeff)
 {
-    int offset, cutoff;
+    int offset, cutoff, channels;
 
     if (bufsize < 24)
         return AVERROR_INVALIDDATA;
@@ -58,18 +58,24 @@ int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf,
     }
 
     /* channels */
-    avctx->channels = buf[7];
-    if (avctx->channels <= 0 || avctx->channels > 2)
+    channels = buf[7];
+    if (channels <= 0 || channels > 2)
         return AVERROR_INVALIDDATA;
 
+    if (avctx->ch_layout.nb_channels != channels) {
+        av_channel_layout_uninit(&avctx->ch_layout);
+        avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        avctx->ch_layout.nb_channels = channels;
+    }
+
     /* sample rate */
     avctx->sample_rate = AV_RB32(buf + 8);
     if (avctx->sample_rate < 1 ||
-        avctx->sample_rate > INT_MAX / (avctx->channels * BLOCK_SIZE * 8))
+        avctx->sample_rate > INT_MAX / (channels * BLOCK_SIZE * 8))
         return AVERROR_INVALIDDATA;
 
     /* bit rate */
-    avctx->bit_rate = avctx->sample_rate * avctx->channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES;
+    avctx->bit_rate = avctx->sample_rate * channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES;
 
     /* LPC coefficients */
     if (coeff) {
diff --git a/libavcodec/adxdec.c b/libavcodec/adxdec.c
index 20256a092e..b3d946e81c 100644
--- a/libavcodec/adxdec.c
+++ b/libavcodec/adxdec.c
@@ -46,7 +46,7 @@ static av_cold int adx_decode_init(AVCodecContext *avctx)
             av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n");
             return AVERROR_INVALIDDATA;
         }
-        c->channels      = avctx->channels;
+        c->channels      = avctx->ch_layout.nb_channels;
         c->header_parsed = 1;
     }
 
@@ -132,7 +132,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data,
             av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n");
             return AVERROR_INVALIDDATA;
         }
-        c->channels      = avctx->channels;
+        c->channels      = avctx->ch_layout.nb_channels;
         c->header_parsed = 1;
         if (buf_size < header_size)
             return AVERROR_INVALIDDATA;
@@ -147,7 +147,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data,
 
     /* if the packet is not an even multiple of BLOCK_SIZE, check for an EOF
        packet */
-    if (!num_blocks || buf_size % (BLOCK_SIZE * avctx->channels)) {
+    if (!num_blocks || buf_size % (BLOCK_SIZE * c->channels)) {
         if (buf_size >= 4 && (AV_RB16(buf) & 0x8000)) {
             c->eof = 1;
             *got_frame_ptr = 0;
diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
index c5849a40a1..3736e746a9 100644
--- a/libavcodec/adxenc.c
+++ b/libavcodec/adxenc.c
@@ -107,7 +107,7 @@ static int adx_encode_header(AVCodecContext *avctx, uint8_t *buf, int bufsize)
     bytestream_put_byte(&buf, 3);                   /* encoding */
     bytestream_put_byte(&buf, BLOCK_SIZE);          /* block size */
     bytestream_put_byte(&buf, 4);                   /* sample size */
-    bytestream_put_byte(&buf, avctx->channels);     /* channels */
+    bytestream_put_byte(&buf, avctx->ch_layout.nb_channels); /* channels */
     bytestream_put_be32(&buf, avctx->sample_rate);  /* sample rate */
     bytestream_put_be32(&buf, 0);                   /* total sample count */
     bytestream_put_be16(&buf, c->cutoff);           /* cutoff frequency */
@@ -125,7 +125,7 @@ static av_cold int adx_encode_init(AVCodecContext *avctx)
 {
     ADXContext *c = avctx->priv_data;
 
-    if (avctx->channels > 2) {
+    if (avctx->ch_layout.nb_channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
         return AVERROR(EINVAL);
     }
@@ -144,6 +144,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     ADXContext *c          = avctx->priv_data;
     const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL;
     uint8_t *dst;
+    int channels = avctx->ch_layout.nb_channels;
     int ch, out_size, ret;
 
     if (!samples) {
@@ -162,7 +163,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         return 0;
     }
 
-    out_size = BLOCK_SIZE * avctx->channels + !c->header_parsed * HEADER_SIZE;
+    out_size = BLOCK_SIZE * channels + !c->header_parsed * HEADER_SIZE;
     if ((ret = ff_get_encode_buffer(avctx, avpkt, out_size, 0)) < 0)
         return ret;
     dst = avpkt->data;
@@ -177,8 +178,8 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         c->header_parsed = 1;
     }
 
-    for (ch = 0; ch < avctx->channels; ch++) {
-        adx_encode(c, dst, samples + ch, &c->prev[ch], avctx->channels);
+    for (ch = 0; ch < channels; ch++) {
+        adx_encode(c, dst, samples + ch, &c->prev[ch], channels);
         dst += BLOCK_SIZE;
     }
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 186/281] alac: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (186 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 185/281] adx: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-02-09  9:40   ` Anton Khirnov
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 187/281] als: " James Almer
                   ` (94 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/alac.c      | 16 ++++++----------
 libavcodec/alac_data.c | 20 ++++++++++----------
 libavcodec/alac_data.h |  6 ++++++
 libavcodec/alacenc.c   | 37 +++++++++++++++++++++++++++++--------
 4 files changed, 51 insertions(+), 28 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 67fc2a3e41..db1e725f66 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -576,21 +576,17 @@ static av_cold int alac_decode_init(AVCodecContext * avctx)
     avctx->bits_per_raw_sample = alac->sample_size;
     avctx->sample_rate         = alac->sample_rate;
 
-    if (alac->channels < 1) {
+    if (alac->channels < 1 || alac->channels > ALAC_MAX_CHANNELS) {
         av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n");
-        alac->channels = avctx->channels;
-    } else {
-        if (alac->channels > ALAC_MAX_CHANNELS)
-            alac->channels = avctx->channels;
-        else
-            avctx->channels = alac->channels;
+        alac->channels = avctx->ch_layout.nb_channels;
     }
-    if (avctx->channels > ALAC_MAX_CHANNELS || avctx->channels <= 0 ) {
+    if (avctx->ch_layout.nb_channels > ALAC_MAX_CHANNELS || avctx->ch_layout.nb_channels <= 0 ) {
         avpriv_report_missing_feature(avctx, "Channel count %d",
-                                      avctx->channels);
+                                      avctx->ch_layout.nb_channels);
         return AVERROR_PATCHWELCOME;
     }
-    avctx->channel_layout = ff_alac_channel_layouts[alac->channels - 1];
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = ff_alac_ch_layouts[alac->channels - 1];
 
     if ((ret = allocate_buffers(alac)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "Error allocating buffers\n");
diff --git a/libavcodec/alac_data.c b/libavcodec/alac_data.c
index 0bcb06c075..d8ed53f444 100644
--- a/libavcodec/alac_data.c
+++ b/libavcodec/alac_data.c
@@ -32,16 +32,16 @@ const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNEL
     { 2, 6, 7, 0, 1, 4, 5, 3 }
 };
 
-const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1] = {
-    AV_CH_LAYOUT_MONO,
-    AV_CH_LAYOUT_STEREO,
-    AV_CH_LAYOUT_SURROUND,
-    AV_CH_LAYOUT_4POINT0,
-    AV_CH_LAYOUT_5POINT0_BACK,
-    AV_CH_LAYOUT_5POINT1_BACK,
-    AV_CH_LAYOUT_6POINT1_BACK,
-    AV_CH_LAYOUT_7POINT1_WIDE_BACK,
-    0
+const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1] = {
+    AV_CHANNEL_LAYOUT_MONO,
+    AV_CHANNEL_LAYOUT_STEREO,
+    AV_CHANNEL_LAYOUT_SURROUND,
+    AV_CHANNEL_LAYOUT_4POINT0,
+    AV_CHANNEL_LAYOUT_5POINT0_BACK,
+    AV_CHANNEL_LAYOUT_5POINT1_BACK,
+    AV_CHANNEL_LAYOUT_6POINT1_BACK,
+    AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK,
+    { 0 }
 };
 
 const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5] = {
diff --git a/libavcodec/alac_data.h b/libavcodec/alac_data.h
index 650d6dcd15..a68a5f2648 100644
--- a/libavcodec/alac_data.h
+++ b/libavcodec/alac_data.h
@@ -23,6 +23,8 @@
 
 #include <stdint.h>
 
+#include "libavutil/channel_layout.h"
+
 enum AlacRawDataBlockType {
     /* At the moment, only SCE, CPE, LFE, and END are recognized. */
     TYPE_SCE,
@@ -39,7 +41,11 @@ enum AlacRawDataBlockType {
 
 extern const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNELS];
 
+extern const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1];
+
+#if FF_API_OLD_CHANNEL_LAYOUT
 extern const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1];
+#endif
 
 extern const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5];
 
diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c
index a38aa6e7d7..09af0584bc 100644
--- a/libavcodec/alacenc.c
+++ b/libavcodec/alacenc.c
@@ -462,14 +462,15 @@ static int write_frame(AlacEncodeContext *s, AVPacket *avpkt,
                        uint8_t * const *samples)
 {
     PutBitContext *pb = &s->pbctx;
-    const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[s->avctx->channels - 1];
-    const uint8_t *ch_map = ff_alac_channel_layout_offsets[s->avctx->channels - 1];
+    int channels = s->avctx->ch_layout.nb_channels;
+    const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[channels - 1];
+    const uint8_t *ch_map = ff_alac_channel_layout_offsets[channels - 1];
     int ch, element, sce, cpe;
 
     init_put_bits(pb, avpkt->data, avpkt->size);
 
     ch = element = sce = cpe = 0;
-    while (ch < s->avctx->channels) {
+    while (ch < channels) {
         if (ch_elements[element] == TYPE_CPE) {
             write_element(s, TYPE_CPE, cpe, samples[ch_map[ch]],
                           samples[ch_map[ch + 1]]);
@@ -532,7 +533,7 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
     s->rc.rice_modifier   = 4;
 
     s->max_coded_frame_size = get_max_frame_size(avctx->frame_size,
-                                                 avctx->channels,
+                                                 avctx->ch_layout.nb_channels,
                                                  avctx->bits_per_raw_sample);
 
     avctx->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE);
@@ -545,10 +546,10 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
     AV_WB32(alac_extradata+4,  MKBETAG('a','l','a','c'));
     AV_WB32(alac_extradata+12, avctx->frame_size);
     AV_WB8 (alac_extradata+17, avctx->bits_per_raw_sample);
-    AV_WB8 (alac_extradata+21, avctx->channels);
+    AV_WB8 (alac_extradata+21, avctx->ch_layout.nb_channels);
     AV_WB32(alac_extradata+24, s->max_coded_frame_size);
     AV_WB32(alac_extradata+28,
-            avctx->sample_rate * avctx->channels * avctx->bits_per_raw_sample); // average bitrate
+            avctx->sample_rate * avctx->ch_layout.nb_channels * avctx->bits_per_raw_sample); // average bitrate
     AV_WB32(alac_extradata+32, avctx->sample_rate);
 
     // Set relevant extradata fields
@@ -585,7 +586,7 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     s->frame_size = frame->nb_samples;
 
     if (frame->nb_samples < DEFAULT_FRAME_SIZE)
-        max_frame_size = get_max_frame_size(s->frame_size, avctx->channels,
+        max_frame_size = get_max_frame_size(s->frame_size, avctx->ch_layout.nb_channels,
                                             avctx->bits_per_raw_sample);
     else
         max_frame_size = s->max_coded_frame_size;
@@ -616,6 +617,21 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     return 0;
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+const uint64_t alac_channel_layouts[ALAC_MAX_CHANNELS + 1] = {
+    AV_CH_LAYOUT_MONO,
+    AV_CH_LAYOUT_STEREO,
+    AV_CH_LAYOUT_SURROUND,
+    AV_CH_LAYOUT_4POINT0,
+    AV_CH_LAYOUT_5POINT0_BACK,
+    AV_CH_LAYOUT_5POINT1_BACK,
+    AV_CH_LAYOUT_6POINT1_BACK,
+    AV_CH_LAYOUT_7POINT1_WIDE_BACK,
+    0
+};
+#endif
+
+
 #define OFFSET(x) offsetof(AlacEncodeContext, x)
 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
@@ -632,6 +648,7 @@ static const AVClass alacenc_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
+FF_DISABLE_DEPRECATION_WARNINGS
 const AVCodec ff_alac_encoder = {
     .name           = "alac",
     .long_name      = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
@@ -643,9 +660,13 @@ const AVCodec ff_alac_encoder = {
     .encode2        = alac_encode_frame,
     .close          = alac_encode_close,
     .capabilities   = AV_CODEC_CAP_SMALL_LAST_FRAME,
-    .channel_layouts = ff_alac_channel_layouts,
+#if FF_API_OLD_CHANNEL_LAYOUT
+    .channel_layouts = alac_channel_layouts,
+#endif
+    .ch_layouts     = ff_alac_ch_layouts,
     .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P,
                                                      AV_SAMPLE_FMT_S16P,
                                                      AV_SAMPLE_FMT_NONE },
     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
+FF_ENABLE_DEPRECATION_WARNINGS
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 187/281] als: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (187 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 186/281] alac: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 188/281] amr: " James Almer
                   ` (93 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/alsdec.c | 90 ++++++++++++++++++++++++---------------------
 1 file changed, 49 insertions(+), 41 deletions(-)

diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c
index 9e1aaf065a..599c621366 100644
--- a/libavcodec/alsdec.c
+++ b/libavcodec/alsdec.c
@@ -319,7 +319,13 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
     avctx->sample_rate          = m4ac.sample_rate;
     skip_bits_long(&gb, 32); // sample rate already known
     sconf->samples              = get_bits_long(&gb, 32);
-    avctx->channels             = m4ac.channels;
+
+    if (avctx->ch_layout.nb_channels != m4ac.channels) {
+        av_channel_layout_uninit(&avctx->ch_layout);
+        avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+        avctx->ch_layout.nb_channels = m4ac.channels;
+    }
+
     skip_bits(&gb, 16);      // number of channels already known
     skip_bits(&gb, 3);       // skip file_type
     sconf->resolution           = get_bits(&gb, 3);
@@ -349,7 +355,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
     if (als_id != MKBETAG('A','L','S','\0'))
         return AVERROR_INVALIDDATA;
 
-    if (avctx->channels > FF_SANE_NB_CHANNELS) {
+    if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
         avpriv_request_sample(avctx, "Huge number of channels");
         return AVERROR_PATCHWELCOME;
     }
@@ -363,26 +369,26 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
 
 
     // read channel sorting
-    if (sconf->chan_sort && avctx->channels > 1) {
-        int chan_pos_bits = av_ceil_log2(avctx->channels);
-        int bits_needed  = avctx->channels * chan_pos_bits + 7;
+    if (sconf->chan_sort && avctx->ch_layout.nb_channels > 1) {
+        int chan_pos_bits = av_ceil_log2(avctx->ch_layout.nb_channels);
+        int bits_needed  = avctx->ch_layout.nb_channels * chan_pos_bits + 7;
         if (get_bits_left(&gb) < bits_needed)
             return AVERROR_INVALIDDATA;
 
-        if (!(sconf->chan_pos = av_malloc_array(avctx->channels, sizeof(*sconf->chan_pos))))
+        if (!(sconf->chan_pos = av_malloc_array(avctx->ch_layout.nb_channels, sizeof(*sconf->chan_pos))))
             return AVERROR(ENOMEM);
 
         ctx->cs_switch = 1;
 
-        for (i = 0; i < avctx->channels; i++) {
+        for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
             sconf->chan_pos[i] = -1;
         }
 
-        for (i = 0; i < avctx->channels; i++) {
+        for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
             int idx;
 
             idx = get_bits(&gb, chan_pos_bits);
-            if (idx >= avctx->channels || sconf->chan_pos[idx] != -1) {
+            if (idx >= avctx->ch_layout.nb_channels || sconf->chan_pos[idx] != -1) {
                 av_log(avctx, AV_LOG_WARNING, "Invalid channel reordering.\n");
                 ctx->cs_switch = 0;
                 break;
@@ -1228,7 +1234,7 @@ static int read_channel_data(ALSDecContext *ctx, ALSChannelData *cd, int c)
 {
     GetBitContext *gb       = &ctx->gb;
     ALSChannelData *current = cd;
-    unsigned int channels   = ctx->avctx->channels;
+    unsigned int channels   = ctx->avctx->ch_layout.nb_channels;
     int entries             = 0;
 
     while (entries < channels && !(current->stop_flag = get_bits1(gb))) {
@@ -1277,7 +1283,7 @@ static int revert_channel_correlation(ALSDecContext *ctx, ALSBlockData *bd,
 {
     ALSChannelData *ch = cd[c];
     unsigned int   dep = 0;
-    unsigned int channels = ctx->avctx->channels;
+    unsigned int channels = ctx->avctx->ch_layout.nb_channels;
     unsigned int channel_size = ctx->sconf.frame_length + ctx->sconf.max_order;
 
     if (reverted[c])
@@ -1475,15 +1481,15 @@ static int read_diff_float_data(ALSDecContext *ctx, unsigned int ra_frame) {
     use_acf = get_bits1(gb);
 
     if (ra_frame) {
-        memset(last_acf_mantissa, 0, avctx->channels * sizeof(*last_acf_mantissa));
-        memset(last_shift_value,  0, avctx->channels * sizeof(*last_shift_value) );
+        memset(last_acf_mantissa, 0, avctx->ch_layout.nb_channels * sizeof(*last_acf_mantissa));
+        memset(last_shift_value,  0, avctx->ch_layout.nb_channels * sizeof(*last_shift_value) );
         ff_mlz_flush_dict(ctx->mlz);
     }
 
-    if (avctx->channels * 8 > get_bits_left(gb))
+    if (avctx->ch_layout.nb_channels * 8 > get_bits_left(gb))
         return AVERROR_INVALIDDATA;
 
-    for (c = 0; c < avctx->channels; ++c) {
+    for (c = 0; c < avctx->ch_layout.nb_channels; ++c) {
         if (use_acf) {
             //acf_flag
             if (get_bits1(gb)) {
@@ -1634,6 +1640,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
     unsigned int div_blocks[32];                ///< block sizes.
     int c;
     unsigned int js_blocks[2];
+    int channels = avctx->ch_layout.nb_channels;
     uint32_t bs_info = 0;
     int ret;
 
@@ -1649,7 +1656,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
     if (!sconf->mc_coding || ctx->js_switch) {
         int independent_bs = !sconf->joint_stereo;
 
-        for (c = 0; c < avctx->channels; c++) {
+        for (c = 0; c < channels; c++) {
             js_blocks[0] = 0;
             js_blocks[1] = 0;
 
@@ -1662,7 +1669,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
                     independent_bs = 2;
 
             // if this is the last channel, it has to be decoded independently
-            if (c == avctx->channels - 1 || (c & 1))
+            if (c == channels - 1 || (c & 1))
                 independent_bs = 1;
 
             if (independent_bs) {
@@ -1691,13 +1698,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
         int            *reverted_channels = ctx->reverted_channels;
         unsigned int   offset             = 0;
 
-        for (c = 0; c < avctx->channels; c++)
+        for (c = 0; c < channels; c++)
             if (ctx->chan_data[c] < ctx->chan_data_buffer) {
                 av_log(ctx->avctx, AV_LOG_ERROR, "Invalid channel data.\n");
                 return AVERROR_INVALIDDATA;
             }
 
-        memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels);
+        memset(reverted_channels, 0, sizeof(*reverted_channels) * channels);
 
         bd.ra_block         = ra_frame;
         bd.prev_raw_samples = ctx->prev_raw_samples;
@@ -1713,7 +1720,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
                 continue;
             }
 
-            for (c = 0; c < avctx->channels; c++) {
+            for (c = 0; c < channels; c++) {
                 bd.const_block = ctx->const_block + c;
                 bd.shift_lsbs  = ctx->shift_lsbs + c;
                 bd.opt_order   = ctx->opt_order + c;
@@ -1732,13 +1739,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
                     return ret;
             }
 
-            for (c = 0; c < avctx->channels; c++) {
+            for (c = 0; c < channels; c++) {
                 ret = revert_channel_correlation(ctx, &bd, ctx->chan_data,
                                                  reverted_channels, offset, c);
                 if (ret < 0)
                     return ret;
             }
-            for (c = 0; c < avctx->channels; c++) {
+            for (c = 0; c < channels; c++) {
                 bd.const_block = ctx->const_block + c;
                 bd.shift_lsbs  = ctx->shift_lsbs + c;
                 bd.opt_order   = ctx->opt_order + c;
@@ -1756,13 +1763,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
                 ctx->highest_decoded_channel = FFMAX(ctx->highest_decoded_channel, c);
             }
 
-            memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels));
+            memset(reverted_channels, 0, channels * sizeof(*reverted_channels));
             offset      += div_blocks[b];
             bd.ra_block  = 0;
         }
 
         // store carryover raw samples
-        for (c = 0; c < avctx->channels; c++)
+        for (c = 0; c < channels; c++)
             memmove(ctx->raw_samples[c] - sconf->max_order,
                     ctx->raw_samples[c] - sconf->max_order + sconf->frame_length,
                     sizeof(*ctx->raw_samples[c]) * sconf->max_order);
@@ -1792,6 +1799,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
     const uint8_t *buffer    = avpkt->data;
     int buffer_size          = avpkt->size;
     int invalid_frame, ret;
+    int channels = avctx->ch_layout.nb_channels;
     unsigned int c, sample, ra_frame, bytes_read, shift;
 
     if ((ret = init_get_bits8(&ctx->gb, buffer, buffer_size)) < 0)
@@ -1833,7 +1841,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
     #define INTERLEAVE_OUTPUT(bps)                                                   \
     {                                                                                \
         int##bps##_t *dest = (int##bps##_t*)frame->data[0];                          \
-        int channels = avctx->channels;                                              \
         int32_t *raw_samples = ctx->raw_samples[0];                                  \
         int raw_step = channels > 1 ? ctx->raw_samples[1] - raw_samples : 1;         \
         shift = bps - ctx->avctx->bits_per_raw_sample;                               \
@@ -1862,7 +1869,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
             int32_t *src = (int32_t *)frame->data[0];
 
             for (sample = 0;
-                 sample < ctx->cur_frame_length * avctx->channels;
+                 sample < ctx->cur_frame_length * channels;
                  sample++) {
                 int32_t v;
 
@@ -1883,13 +1890,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
                     int16_t *src  = (int16_t*) frame->data[0];
                     int16_t *dest = (int16_t*) ctx->crc_buffer;
                     for (sample = 0;
-                         sample < ctx->cur_frame_length * avctx->channels;
+                         sample < ctx->cur_frame_length * channels;
                          sample++)
                         *dest++ = av_bswap16(src[sample]);
                 } else {
                     ctx->bdsp.bswap_buf((uint32_t *) ctx->crc_buffer,
                                         (uint32_t *) frame->data[0],
-                                        ctx->cur_frame_length * avctx->channels);
+                                        ctx->cur_frame_length * channels);
                 }
                 crc_source = ctx->crc_buffer;
             } else {
@@ -1897,7 +1904,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
             }
 
             ctx->crc = av_crc(ctx->crc_table, ctx->crc, crc_source,
-                              ctx->cur_frame_length * avctx->channels *
+                              ctx->cur_frame_length * channels *
                               av_get_bytes_per_sample(avctx->sample_fmt));
         }
 
@@ -1960,7 +1967,7 @@ static av_cold int decode_end(AVCodecContext *avctx)
     av_freep(&ctx->shift_value);
     av_freep(&ctx->last_shift_value);
     if (ctx->raw_mantissa) {
-        for (i = 0; i < avctx->channels; i++) {
+        for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
             av_freep(&ctx->raw_mantissa[i]);
         }
         av_freep(&ctx->raw_mantissa);
@@ -1979,6 +1986,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     unsigned int c;
     unsigned int channel_size;
     int num_buffers, ret;
+    int channels = avctx->ch_layout.nb_channels;
     ALSDecContext *ctx = avctx->priv_data;
     ALSSpecificConfig *sconf = &ctx->sconf;
     ctx->avctx = avctx;
@@ -2027,7 +2035,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
                               (avctx->sample_rate >= 192000);
 
     // allocate quantized parcor coefficient buffer
-    num_buffers = sconf->mc_coding ? avctx->channels : 1;
+    num_buffers = sconf->mc_coding ? channels : 1;
     if (num_buffers * (uint64_t)num_buffers > INT_MAX) // protect chan_data_buffer allocation
         return AVERROR_INVALIDDATA;
 
@@ -2101,15 +2109,15 @@ static av_cold int decode_init(AVCodecContext *avctx)
     channel_size      = sconf->frame_length + sconf->max_order;
 
     ctx->prev_raw_samples = av_malloc_array(sconf->max_order, sizeof(*ctx->prev_raw_samples));
-    ctx->raw_buffer       = av_calloc(avctx->channels * channel_size, sizeof(*ctx->raw_buffer));
-    ctx->raw_samples      = av_malloc_array(avctx->channels, sizeof(*ctx->raw_samples));
+    ctx->raw_buffer       = av_calloc(channels * channel_size, sizeof(*ctx->raw_buffer));
+    ctx->raw_samples      = av_malloc_array(channels, sizeof(*ctx->raw_samples));
 
     if (sconf->floating) {
-        ctx->acf               = av_malloc_array(avctx->channels, sizeof(*ctx->acf));
-        ctx->shift_value       = av_malloc_array(avctx->channels, sizeof(*ctx->shift_value));
-        ctx->last_shift_value  = av_malloc_array(avctx->channels, sizeof(*ctx->last_shift_value));
-        ctx->last_acf_mantissa = av_malloc_array(avctx->channels, sizeof(*ctx->last_acf_mantissa));
-        ctx->raw_mantissa      = av_calloc(avctx->channels, sizeof(*ctx->raw_mantissa));
+        ctx->acf               = av_malloc_array(channels, sizeof(*ctx->acf));
+        ctx->shift_value       = av_malloc_array(channels, sizeof(*ctx->shift_value));
+        ctx->last_shift_value  = av_malloc_array(channels, sizeof(*ctx->last_shift_value));
+        ctx->last_acf_mantissa = av_malloc_array(channels, sizeof(*ctx->last_acf_mantissa));
+        ctx->raw_mantissa      = av_calloc(channels, sizeof(*ctx->raw_mantissa));
 
         ctx->larray = av_malloc_array(ctx->cur_frame_length * 4, sizeof(*ctx->larray));
         ctx->nbits  = av_malloc_array(ctx->cur_frame_length, sizeof(*ctx->nbits));
@@ -2125,7 +2133,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
         ff_mlz_init_dict(avctx, ctx->mlz);
         ff_mlz_flush_dict(ctx->mlz);
 
-        for (c = 0; c < avctx->channels; ++c) {
+        for (c = 0; c < channels; ++c) {
             ctx->raw_mantissa[c] = av_calloc(ctx->cur_frame_length, sizeof(**ctx->raw_mantissa));
         }
     }
@@ -2139,14 +2147,14 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     // assign raw samples buffers
     ctx->raw_samples[0] = ctx->raw_buffer + sconf->max_order;
-    for (c = 1; c < avctx->channels; c++)
+    for (c = 1; c < channels; c++)
         ctx->raw_samples[c] = ctx->raw_samples[c - 1] + channel_size;
 
     // allocate crc buffer
     if (HAVE_BIGENDIAN != sconf->msb_first && sconf->crc_enabled &&
         (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL))) {
         ctx->crc_buffer = av_malloc_array(ctx->cur_frame_length *
-                                          avctx->channels *
+                                          channels *
                                           av_get_bytes_per_sample(avctx->sample_fmt),
                                           sizeof(*ctx->crc_buffer));
         if (!ctx->crc_buffer) {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 188/281] amr: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (188 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 187/281] als: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 189/281] aptx: " James Almer
                   ` (92 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/amr_parser.c | 10 +++++-----
 libavcodec/amrnbdec.c   | 12 ++++++------
 libavcodec/amrwbdec.c   | 12 ++++++------
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavcodec/amr_parser.c b/libavcodec/amr_parser.c
index c0b14700e2..9484d720ee 100644
--- a/libavcodec/amr_parser.c
+++ b/libavcodec/amr_parser.c
@@ -63,9 +63,9 @@ static int amr_parse(AVCodecParserContext *s1,
     *poutbuf_size = 0;
     *poutbuf = NULL;
 
-    if (!avctx->channels) {
-        avctx->channels       = 1;
-        avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    if (!avctx->ch_layout.nb_channels) {
+        av_channel_layout_uninit(&avctx->ch_layout);
+        avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     }
 
     if (s1->flags & PARSER_FLAG_COMPLETE_FRAMES) {
@@ -73,7 +73,7 @@ static int amr_parse(AVCodecParserContext *s1,
     } else {
         int ch, offset = 0;
 
-        for (ch = s->current_channel; ch < avctx->channels; ch++) {
+        for (ch = s->current_channel; ch < avctx->ch_layout.nb_channels; ch++) {
             if (s->remaining >= 0) {
                 next = s->remaining;
             } else {
@@ -96,7 +96,7 @@ static int amr_parse(AVCodecParserContext *s1,
             }
         }
 
-        s->current_channel = ch % avctx->channels;
+        s->current_channel = ch % avctx->ch_layout.nb_channels;
         if (s->remaining < 0)
             next = offset;
 
diff --git a/libavcodec/amrnbdec.c b/libavcodec/amrnbdec.c
index d8e0370a3b..c6df87bffa 100644
--- a/libavcodec/amrnbdec.c
+++ b/libavcodec/amrnbdec.c
@@ -166,20 +166,20 @@ static av_cold int amrnb_decode_init(AVCodecContext *avctx)
     AMRChannelsContext *s = avctx->priv_data;
     int i;
 
-    if (avctx->channels > 2) {
+    if (avctx->ch_layout.nb_channels > 2) {
         avpriv_report_missing_feature(avctx, ">2 channel AMR");
         return AVERROR_PATCHWELCOME;
     }
 
-    if (!avctx->channels) {
-        avctx->channels       = 1;
-        avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    if (!avctx->ch_layout.nb_channels) {
+        av_channel_layout_uninit(&avctx->ch_layout);
+        avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     }
     if (!avctx->sample_rate)
         avctx->sample_rate = 8000;
     avctx->sample_fmt     = AV_SAMPLE_FMT_FLTP;
 
-    for (int ch = 0; ch < avctx->channels; ch++) {
+    for (int ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
         AMRContext *p = &s->ch[ch];
         // p->excitation always points to the same position in p->excitation_buf
         p->excitation = &p->excitation_buf[PITCH_DELAY_MAX + LP_FILTER_ORDER + 1];
@@ -969,7 +969,7 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
-    for (int ch = 0; ch < avctx->channels; ch++) {
+    for (int ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
         AMRContext *p = &s->ch[ch];
         float fixed_gain_factor;
         AMRFixed fixed_sparse = {0};             // fixed vector up to anti-sparseness processing
diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index 3ff4077f7f..ad62c541c5 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -102,20 +102,20 @@ static av_cold int amrwb_decode_init(AVCodecContext *avctx)
     AMRWBChannelsContext *s = avctx->priv_data;
     int i;
 
-    if (avctx->channels > 2) {
+    if (avctx->ch_layout.nb_channels > 2) {
         avpriv_report_missing_feature(avctx, ">2 channel AMR");
         return AVERROR_PATCHWELCOME;
     }
 
-    if (!avctx->channels) {
-        avctx->channels       = 1;
-        avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    if (!avctx->ch_layout.nb_channels) {
+        av_channel_layout_uninit(&avctx->ch_layout);
+        avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     }
     if (!avctx->sample_rate)
         avctx->sample_rate = 16000;
     avctx->sample_fmt     = AV_SAMPLE_FMT_FLTP;
 
-    for (int ch = 0; ch < avctx->channels; ch++) {
+    for (int ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
         AMRWBContext *ctx = &s->ch[ch];
 
         av_lfg_init(&ctx->prng, 1);
@@ -1115,7 +1115,7 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
-    for (int ch = 0; ch < avctx->channels; ch++) {
+    for (int ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
         AMRWBContext *ctx  = &s->ch[ch];
         AMRWBFrame   *cf   = &ctx->frame;
         int expected_fr_size, header_size;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 189/281] aptx: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (189 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 188/281] amr: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 190/281] atrac1: " James Almer
                   ` (91 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/aptx.c    | 2 +-
 libavcodec/aptxdec.c | 8 +++++++-
 libavcodec/aptxenc.c | 6 ++++++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/libavcodec/aptx.c b/libavcodec/aptx.c
index 3aeee1907c..d8e0c207cf 100644
--- a/libavcodec/aptx.c
+++ b/libavcodec/aptx.c
@@ -509,7 +509,7 @@ av_cold int ff_aptx_init(AVCodecContext *avctx)
     AptXContext *s = avctx->priv_data;
     int chan, subband;
 
-    if (avctx->channels != 2)
+    if (avctx->ch_layout.nb_channels != 2)
         return AVERROR_INVALIDDATA;
 
     s->hd = avctx->codec->id == AV_CODEC_ID_APTX_HD;
diff --git a/libavcodec/aptxdec.c b/libavcodec/aptxdec.c
index bdcc076c41..1d862e8e6b 100644
--- a/libavcodec/aptxdec.c
+++ b/libavcodec/aptxdec.c
@@ -146,7 +146,7 @@ static int aptx_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     /* get output buffer */
-    frame->channels = NB_CHANNELS;
+    frame->ch_layout.nb_channels = NB_CHANNELS;
     frame->format = AV_SAMPLE_FMT_S32P;
     frame->nb_samples = 4 * avpkt->size / s->block_size;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
@@ -181,7 +181,10 @@ const AVCodec ff_aptx_decoder = {
     .decode                = aptx_decode_frame,
     .capabilities          = AV_CODEC_CAP_DR1,
     .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_STEREO, 0},
+#endif
+    .ch_layouts            = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_STEREO, { 0 } },
     .sample_fmts           = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S32P,
                                                              AV_SAMPLE_FMT_NONE },
 };
@@ -198,7 +201,10 @@ const AVCodec ff_aptx_hd_decoder = {
     .decode                = aptx_decode_frame,
     .capabilities          = AV_CODEC_CAP_DR1,
     .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_STEREO, 0},
+#endif
+    .ch_layouts            = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_STEREO, { 0 } },
     .sample_fmts           = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S32P,
                                                              AV_SAMPLE_FMT_NONE },
 };
diff --git a/libavcodec/aptxenc.c b/libavcodec/aptxenc.c
index 5ea6053c26..1230ee306d 100644
--- a/libavcodec/aptxenc.c
+++ b/libavcodec/aptxenc.c
@@ -253,7 +253,10 @@ const AVCodec ff_aptx_encoder = {
     .encode2               = aptx_encode_frame,
     .close                 = aptx_close,
     .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_STEREO, 0},
+#endif
+    .ch_layouts            = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_STEREO, { 0 } },
     .sample_fmts           = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S32P,
                                                              AV_SAMPLE_FMT_NONE },
     .supported_samplerates = (const int[]) {8000, 16000, 24000, 32000, 44100, 48000, 0},
@@ -272,7 +275,10 @@ const AVCodec ff_aptx_hd_encoder = {
     .encode2               = aptx_encode_frame,
     .close                 = aptx_close,
     .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_STEREO, 0},
+#endif
+    .ch_layouts            = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_STEREO, { 0 } },
     .sample_fmts           = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S32P,
                                                              AV_SAMPLE_FMT_NONE },
     .supported_samplerates = (const int[]) {8000, 16000, 24000, 32000, 44100, 48000, 0},
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 190/281] atrac1: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (190 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 189/281] aptx: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 191/281] atrac3: " James Almer
                   ` (90 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/atrac1.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavcodec/atrac1.c b/libavcodec/atrac1.c
index 228477d778..6ec96a4644 100644
--- a/libavcodec/atrac1.c
+++ b/libavcodec/atrac1.c
@@ -279,11 +279,12 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
     AT1Ctx *q          = avctx->priv_data;
+    int channels       = avctx->ch_layout.nb_channels;
     int ch, ret;
     GetBitContext gb;
 
 
-    if (buf_size < 212 * avctx->channels) {
+    if (buf_size < 212 * channels) {
         av_log(avctx, AV_LOG_ERROR, "Not enough data to decode!\n");
         return AVERROR_INVALIDDATA;
     }
@@ -293,7 +294,7 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
-    for (ch = 0; ch < avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         AT1SUCtx* su = &q->SUs[ch];
 
         init_get_bits(&gb, &buf[212 * ch], 212 * 8);
@@ -335,13 +336,14 @@ static av_cold int atrac1_decode_init(AVCodecContext *avctx)
 {
     AT1Ctx *q = avctx->priv_data;
     AVFloatDSPContext *fdsp;
+    int channels = avctx->ch_layout.nb_channels;
     int ret;
 
     avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 
-    if (avctx->channels < 1 || avctx->channels > AT1_MAX_CHANNELS) {
+    if (channels < 1 || channels > AT1_MAX_CHANNELS) {
         av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\n",
-               avctx->channels);
+               channels);
         return AVERROR(EINVAL);
     }
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 191/281] atrac3: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (191 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 190/281] atrac1: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 192/281] atrac3plus: " James Almer
                   ` (89 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/atrac3.c | 41 ++++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
index 2376a7cd02..772937f5a3 100644
--- a/libavcodec/atrac3.c
+++ b/libavcodec/atrac3.c
@@ -646,6 +646,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
     ATRAC3Context *q = avctx->priv_data;
     int ret, i, ch;
     uint8_t *ptr1;
+    int channels = avctx->ch_layout.nb_channels;
 
     if (q->coding_mode == JOINT_STEREO) {
         /* channel coupling mode */
@@ -655,9 +656,9 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
         const uint8_t *js_databuf;
         int js_pair, js_block_align;
 
-        js_block_align = (avctx->block_align / avctx->channels) * 2; /* block pair */
+        js_block_align = (avctx->block_align / channels) * 2; /* block pair */
 
-        for (ch = 0; ch < avctx->channels; ch = ch + 2) {
+        for (ch = 0; ch < channels; ch = ch + 2) {
             js_pair = ch/2;
             js_databuf = databuf + js_pair * js_block_align; /* align to current pair */
 
@@ -726,11 +727,11 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
     } else {
         /* single channels */
         /* Decode the channel sound units. */
-        for (i = 0; i < avctx->channels; i++) {
+        for (i = 0; i < channels; i++) {
             /* Set the bitstream reader at the start of a channel sound unit. */
             init_get_bits(&q->gb,
-                          databuf + i * avctx->block_align / avctx->channels,
-                          avctx->block_align * 8 / avctx->channels);
+                          databuf + i * avctx->block_align / channels,
+                          avctx->block_align * 8 / channels);
 
             ret = decode_channel_sound_unit(q, &q->gb, &q->units[i],
                                             out_samples[i], i, q->coding_mode);
@@ -740,7 +741,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
     }
 
     /* Apply the iQMF synthesis filter. */
-    for (i = 0; i < avctx->channels; i++) {
+    for (i = 0; i < channels; i++) {
         float *p1 = out_samples[i];
         float *p2 = p1 + 256;
         float *p3 = p2 + 256;
@@ -757,24 +758,25 @@ static int al_decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
                            int size, float **out_samples)
 {
     ATRAC3Context *q = avctx->priv_data;
+    int channels = avctx->ch_layout.nb_channels;
     int ret, i;
 
     /* Set the bitstream reader at the start of a channel sound unit. */
     init_get_bits(&q->gb, databuf, size * 8);
     /* single channels */
     /* Decode the channel sound units. */
-    for (i = 0; i < avctx->channels; i++) {
+    for (i = 0; i < channels; i++) {
         ret = decode_channel_sound_unit(q, &q->gb, &q->units[i],
                                         out_samples[i], i, q->coding_mode);
         if (ret != 0)
             return ret;
-        while (i < avctx->channels && get_bits_left(&q->gb) > 6 && show_bits(&q->gb, 6) != 0x28) {
+        while (i < channels && get_bits_left(&q->gb) > 6 && show_bits(&q->gb, 6) != 0x28) {
             skip_bits(&q->gb, 1);
         }
     }
 
     /* Apply the iQMF synthesis filter. */
-    for (i = 0; i < avctx->channels; i++) {
+    for (i = 0; i < channels; i++) {
         float *p1 = out_samples[i];
         float *p2 = p1 + 256;
         float *p3 = p2 + 256;
@@ -879,8 +881,9 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
     const uint8_t *edata_ptr = avctx->extradata;
     ATRAC3Context *q = avctx->priv_data;
     AVFloatDSPContext *fdsp;
+    int channels = avctx->ch_layout.nb_channels;
 
-    if (avctx->channels < MIN_CHANNELS || avctx->channels > MAX_CHANNELS) {
+    if (channels < MIN_CHANNELS || channels > MAX_CHANNELS) {
         av_log(avctx, AV_LOG_ERROR, "Channel configuration error!\n");
         return AVERROR(EINVAL);
     }
@@ -888,7 +891,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
     /* Take care of the codec-specific extradata. */
     if (avctx->codec_id == AV_CODEC_ID_ATRAC3AL) {
         version           = 4;
-        samples_per_frame = SAMPLES_PER_FRAME * avctx->channels;
+        samples_per_frame = SAMPLES_PER_FRAME * channels;
         delay             = 0x88E;
         q->coding_mode    = SINGLE;
     } else if (avctx->extradata_size == 14) {
@@ -904,18 +907,18 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
                bytestream_get_le16(&edata_ptr));  // Unknown always 0
 
         /* setup */
-        samples_per_frame    = SAMPLES_PER_FRAME * avctx->channels;
+        samples_per_frame    = SAMPLES_PER_FRAME * channels;
         version              = 4;
         delay                = 0x88E;
         q->coding_mode       = q->coding_mode ? JOINT_STEREO : SINGLE;
         q->scrambled_stream  = 0;
 
-        if (avctx->block_align !=  96 * avctx->channels * frame_factor &&
-            avctx->block_align != 152 * avctx->channels * frame_factor &&
-            avctx->block_align != 192 * avctx->channels * frame_factor) {
+        if (avctx->block_align !=  96 * channels * frame_factor &&
+            avctx->block_align != 152 * channels * frame_factor &&
+            avctx->block_align != 192 * channels * frame_factor) {
             av_log(avctx, AV_LOG_ERROR, "Unknown frame/channel/frame_factor "
                    "configuration %d/%d/%d\n", avctx->block_align,
-                   avctx->channels, frame_factor);
+                   channels, frame_factor);
             return AVERROR_INVALIDDATA;
         }
     } else if (avctx->extradata_size == 12 || avctx->extradata_size == 10) {
@@ -939,7 +942,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
         return AVERROR_INVALIDDATA;
     }
 
-    if (samples_per_frame != SAMPLES_PER_FRAME * avctx->channels) {
+    if (samples_per_frame != SAMPLES_PER_FRAME * channels) {
         av_log(avctx, AV_LOG_ERROR, "Unknown amount of samples per frame %d.\n",
                samples_per_frame);
         return AVERROR_INVALIDDATA;
@@ -954,7 +957,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
     if (q->coding_mode == SINGLE)
         av_log(avctx, AV_LOG_DEBUG, "Single channels detected.\n");
     else if (q->coding_mode == JOINT_STEREO) {
-        if (avctx->channels % 2 == 1) { /* Joint stereo channels must be even */
+        if (channels % 2 == 1) { /* Joint stereo channels must be even */
             av_log(avctx, AV_LOG_ERROR, "Invalid joint stereo channel configuration.\n");
             return AVERROR_INVALIDDATA;
         }
@@ -1004,7 +1007,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
     q->vector_fmul = fdsp->vector_fmul;
     av_free(fdsp);
 
-    q->units = av_calloc(avctx->channels, sizeof(*q->units));
+    q->units = av_calloc(channels, sizeof(*q->units));
     if (!q->units)
         return AVERROR(ENOMEM);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 192/281] atrac3plus: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (192 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 191/281] atrac3: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 193/281] atrac9: " James Almer
                   ` (88 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/atrac3plusdec.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/libavcodec/atrac3plusdec.c b/libavcodec/atrac3plusdec.c
index e342f09fdb..3f0f08ee00 100644
--- a/libavcodec/atrac3plusdec.c
+++ b/libavcodec/atrac3plusdec.c
@@ -64,7 +64,6 @@ typedef struct ATRAC3PContext {
 
     int num_channel_blocks;     ///< number of channel blocks
     uint8_t channel_blocks[5];  ///< channel configuration descriptor
-    uint64_t my_channel_layout; ///< current channel layout
 } ATRAC3PContext;
 
 static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
@@ -83,36 +82,36 @@ static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
 static av_cold int set_channel_params(ATRAC3PContext *ctx,
                                       AVCodecContext *avctx)
 {
+    int channels = avctx->ch_layout.nb_channels;
     memset(ctx->channel_blocks, 0, sizeof(ctx->channel_blocks));
 
-    switch (avctx->channels) {
+    av_channel_layout_uninit(&avctx->ch_layout);
+    switch (channels) {
     case 1:
-        if (avctx->channel_layout != AV_CH_FRONT_LEFT)
-            avctx->channel_layout = AV_CH_LAYOUT_MONO;
-
+        avctx->ch_layout        = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
         ctx->num_channel_blocks = 1;
         ctx->channel_blocks[0]  = CH_UNIT_MONO;
         break;
     case 2:
-        avctx->channel_layout   = AV_CH_LAYOUT_STEREO;
+        avctx->ch_layout        = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
         ctx->num_channel_blocks = 1;
         ctx->channel_blocks[0]  = CH_UNIT_STEREO;
         break;
     case 3:
-        avctx->channel_layout   = AV_CH_LAYOUT_SURROUND;
+        avctx->ch_layout        = (AVChannelLayout)AV_CHANNEL_LAYOUT_SURROUND;
         ctx->num_channel_blocks = 2;
         ctx->channel_blocks[0]  = CH_UNIT_STEREO;
         ctx->channel_blocks[1]  = CH_UNIT_MONO;
         break;
     case 4:
-        avctx->channel_layout   = AV_CH_LAYOUT_4POINT0;
+        avctx->ch_layout        = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0;
         ctx->num_channel_blocks = 3;
         ctx->channel_blocks[0]  = CH_UNIT_STEREO;
         ctx->channel_blocks[1]  = CH_UNIT_MONO;
         ctx->channel_blocks[2]  = CH_UNIT_MONO;
         break;
     case 6:
-        avctx->channel_layout   = AV_CH_LAYOUT_5POINT1_BACK;
+        avctx->ch_layout        = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK;
         ctx->num_channel_blocks = 4;
         ctx->channel_blocks[0]  = CH_UNIT_STEREO;
         ctx->channel_blocks[1]  = CH_UNIT_MONO;
@@ -120,7 +119,7 @@ static av_cold int set_channel_params(ATRAC3PContext *ctx,
         ctx->channel_blocks[3]  = CH_UNIT_MONO;
         break;
     case 7:
-        avctx->channel_layout   = AV_CH_LAYOUT_6POINT1_BACK;
+        avctx->ch_layout        = (AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT1_BACK;
         ctx->num_channel_blocks = 5;
         ctx->channel_blocks[0]  = CH_UNIT_STEREO;
         ctx->channel_blocks[1]  = CH_UNIT_MONO;
@@ -129,7 +128,7 @@ static av_cold int set_channel_params(ATRAC3PContext *ctx,
         ctx->channel_blocks[4]  = CH_UNIT_MONO;
         break;
     case 8:
-        avctx->channel_layout   = AV_CH_LAYOUT_7POINT1;
+        avctx->ch_layout        = (AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1;
         ctx->num_channel_blocks = 5;
         ctx->channel_blocks[0]  = CH_UNIT_STEREO;
         ctx->channel_blocks[1]  = CH_UNIT_MONO;
@@ -139,7 +138,7 @@ static av_cold int set_channel_params(ATRAC3PContext *ctx,
         break;
     default:
         av_log(avctx, AV_LOG_ERROR,
-               "Unsupported channel count: %d!\n", avctx->channels);
+               "Unsupported channel count: %d!\n", channels);
         return AVERROR_INVALIDDATA;
     }
 
@@ -173,8 +172,6 @@ static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
     if ((ret = set_channel_params(ctx, avctx)) < 0)
         return ret;
 
-    ctx->my_channel_layout = avctx->channel_layout;
-
     ctx->ch_units = av_calloc(ctx->num_channel_blocks, sizeof(*ctx->ch_units));
     ctx->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 193/281] atrac9: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (193 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 192/281] atrac3plus: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 194/281] apedec: " James Almer
                   ` (87 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/atrac9dec.c |  4 ++--
 libavcodec/atrac9tab.h | 14 +++++++-------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/atrac9dec.c b/libavcodec/atrac9dec.c
index 1063044815..b13235cfb9 100644
--- a/libavcodec/atrac9dec.c
+++ b/libavcodec/atrac9dec.c
@@ -938,8 +938,8 @@ static av_cold int atrac9_decode_init(AVCodecContext *avctx)
     }
     s->block_config = &at9_block_layout[block_config_idx];
 
-    avctx->channel_layout = s->block_config->channel_layout;
-    avctx->channels       = av_get_channel_layout_nb_channels(avctx->channel_layout);
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = s->block_config->channel_layout;
     avctx->sample_fmt     = AV_SAMPLE_FMT_FLTP;
 
     if (get_bits1(&gb)) {
diff --git a/libavcodec/atrac9tab.h b/libavcodec/atrac9tab.h
index b169035aad..bdd051221e 100644
--- a/libavcodec/atrac9tab.h
+++ b/libavcodec/atrac9tab.h
@@ -33,7 +33,7 @@ enum ATRAC9BlockType {
 };
 
 typedef struct ATRAC9BlockConfig {
-    uint64_t channel_layout;
+    AVChannelLayout channel_layout;
     enum ATRAC9BlockType type[5];
     int plane_map[5][2];
     int count;
@@ -41,25 +41,25 @@ typedef struct ATRAC9BlockConfig {
 
 static const ATRAC9BlockConfig at9_block_layout[] = {
     { /* Mono */
-        .channel_layout  = AV_CH_LAYOUT_MONO,
+        .channel_layout  = AV_CHANNEL_LAYOUT_MONO,
         .type            = { ATRAC9_BLOCK_TYPE_SCE, },
         .count           = 1,
     },
     { /* Dual Mono */
-        .channel_layout  = AV_CH_LAYOUT_STEREO,
+        .channel_layout  = AV_CHANNEL_LAYOUT_STEREO,
         .type            = { ATRAC9_BLOCK_TYPE_SCE,
                              ATRAC9_BLOCK_TYPE_SCE, },
         .plane_map       = { { 0 }, { 1 }, },
         .count           = 2,
     },
     { /* Stereo */
-        .channel_layout  = AV_CH_LAYOUT_STEREO,
+        .channel_layout  = AV_CHANNEL_LAYOUT_STEREO,
         .type            = { ATRAC9_BLOCK_TYPE_CPE, },
         .plane_map       = { { 0, 1 }, },
         .count           = 1,
     },
     { /* 5.1 */
-        .channel_layout  = AV_CH_LAYOUT_5POINT1,
+        .channel_layout  = AV_CHANNEL_LAYOUT_5POINT1,
         .type            = { ATRAC9_BLOCK_TYPE_CPE,
                              ATRAC9_BLOCK_TYPE_SCE,
                              ATRAC9_BLOCK_TYPE_LFE,
@@ -68,7 +68,7 @@ static const ATRAC9BlockConfig at9_block_layout[] = {
         .count           = 4,
     },
     { /* 7.1 */
-        .channel_layout  = AV_CH_LAYOUT_7POINT1,
+        .channel_layout  = AV_CHANNEL_LAYOUT_7POINT1,
         .type            = { ATRAC9_BLOCK_TYPE_CPE,
                              ATRAC9_BLOCK_TYPE_SCE,
                              ATRAC9_BLOCK_TYPE_LFE,
@@ -78,7 +78,7 @@ static const ATRAC9BlockConfig at9_block_layout[] = {
         .count           = 5,
     },
     { /* Quad */
-        .channel_layout  = AV_CH_LAYOUT_QUAD,
+        .channel_layout  = AV_CHANNEL_LAYOUT_QUAD,
         .type            = { ATRAC9_BLOCK_TYPE_CPE,
                              ATRAC9_BLOCK_TYPE_CPE, },
         .plane_map       = { { 0, 1 }, { 2, 3 }, },
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 194/281] apedec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (194 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 193/281] atrac9: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 195/281] audiotoolbox: " James Almer
                   ` (86 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/apedec.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index 607304fe36..46a53bc52d 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -233,13 +233,14 @@ static av_cold int ape_decode_close(AVCodecContext *avctx)
 static av_cold int ape_decode_init(AVCodecContext *avctx)
 {
     APEContext *s = avctx->priv_data;
+    int channels = avctx->ch_layout.nb_channels;
     int i;
 
     if (avctx->extradata_size != 6) {
         av_log(avctx, AV_LOG_ERROR, "Incorrect extradata\n");
         return AVERROR(EINVAL);
     }
-    if (avctx->channels > 2) {
+    if (channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "Only mono and stereo is supported\n");
         return AVERROR(EINVAL);
     }
@@ -261,7 +262,7 @@ static av_cold int ape_decode_init(AVCodecContext *avctx)
         return AVERROR_PATCHWELCOME;
     }
     s->avctx             = avctx;
-    s->channels          = avctx->channels;
+    s->channels          = channels;
     s->fileversion       = AV_RL16(avctx->extradata);
     s->compression_level = AV_RL16(avctx->extradata + 2);
     s->flags             = AV_RL16(avctx->extradata + 4);
@@ -313,7 +314,9 @@ static av_cold int ape_decode_init(AVCodecContext *avctx)
 
     ff_bswapdsp_init(&s->bdsp);
     ff_llauddsp_init(&s->adsp);
-    avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = (channels == 2) ? (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO
+                                       : (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     return 0;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 195/281] audiotoolbox: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (195 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 194/281] apedec: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-02-21 14:22   ` Anton Khirnov
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 196/281] binkaudio: " James Almer
                   ` (85 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/audiotoolboxdec.c | 27 +++++-----
 libavcodec/audiotoolboxenc.c | 95 ++++++++++++++++--------------------
 2 files changed, 57 insertions(+), 65 deletions(-)

diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c
index 9939fef218..8edf9bd463 100644
--- a/libavcodec/audiotoolboxdec.c
+++ b/libavcodec/audiotoolboxdec.c
@@ -166,8 +166,8 @@ static int ffat_update_ctx(AVCodecContext *avctx)
                                    &size, &format)) {
         if (format.mSampleRate)
             avctx->sample_rate = format.mSampleRate;
-        avctx->channels = format.mChannelsPerFrame;
-        avctx->channel_layout = av_get_default_channel_layout(avctx->channels);
+        av_channel_layout_uninit(&avctx->ch_layout);
+        av_get_default_channel_layout(&avctx->ch_layout, format.mChannelsPerFrame);
         avctx->frame_size = format.mFramesPerPacket;
     }
 
@@ -175,7 +175,7 @@ static int ffat_update_ctx(AVCodecContext *avctx)
                                    kAudioConverterCurrentOutputStreamDescription,
                                    &size, &format)) {
         format.mSampleRate = avctx->sample_rate;
-        format.mChannelsPerFrame = avctx->channels;
+        format.mChannelsPerFrame = avctx->ch_layout.nb_channels;
         AudioConverterSetProperty(at->converter,
                                   kAudioConverterCurrentOutputStreamDescription,
                                   size, &format);
@@ -201,7 +201,8 @@ static int ffat_update_ctx(AVCodecContext *avctx)
             layout_mask |= 1 << id;
             layout->mChannelDescriptions[i].mChannelFlags = i; // Abusing flags as index
         }
-        avctx->channel_layout = layout_mask;
+        av_channel_layout_uninit(&avctx->ch_layout);
+        av_channel_layout_from_mask(&avctx->ch_layout, layout_mask);
         qsort(layout->mChannelDescriptions, layout->mNumberChannelDescriptions,
               sizeof(AudioChannelDescription), &ffat_compare_channel_descriptions);
         for (i = 0; i < layout->mNumberChannelDescriptions; i++)
@@ -364,11 +365,11 @@ static av_cold int ffat_create_decoder(AVCodecContext *avctx,
 #endif
     } else {
         in_format.mSampleRate = avctx->sample_rate ? avctx->sample_rate : 44100;
-        in_format.mChannelsPerFrame = avctx->channels ? avctx->channels : 1;
+        in_format.mChannelsPerFrame = avctx->ch_layout.nb_channels ? avctx->ch_layout.nb_channels : 1;
     }
 
     avctx->sample_rate = out_format.mSampleRate = in_format.mSampleRate;
-    avctx->channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
+    avctx->ch_layout.nb_channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
 
     if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_QT)
         in_format.mFramesPerPacket = 64;
@@ -389,7 +390,7 @@ static av_cold int ffat_create_decoder(AVCodecContext *avctx,
     ffat_update_ctx(avctx);
 
     if(!(at->decoded_data = av_malloc(av_get_bytes_per_sample(avctx->sample_fmt)
-                                      * avctx->frame_size * avctx->channels)))
+                                      * avctx->frame_size * avctx->ch_layout.nb_channels)))
         return AVERROR(ENOMEM);
 
     at->last_pts = AV_NOPTS_VALUE;
@@ -408,7 +409,7 @@ static av_cold int ffat_init_decoder(AVCodecContext *avctx)
         memcpy(at->extradata, avctx->extradata, avctx->extradata_size);
     }
 
-    if ((avctx->channels && avctx->sample_rate) || ffat_usable_extradata(avctx))
+    if ((avctx->ch_layout.nb_channels && avctx->sample_rate) || ffat_usable_extradata(avctx))
         return ffat_create_decoder(avctx, NULL);
     else
         return 0;
@@ -455,11 +456,11 @@ static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_pac
 
 #define COPY_SAMPLES(type) \
     type *in_ptr = (type*)at->decoded_data; \
-    type *end_ptr = in_ptr + frame->nb_samples * avctx->channels; \
+    type *end_ptr = in_ptr + frame->nb_samples * avctx->ch_layout.nb_channels; \
     type *out_ptr = (type*)frame->data[0]; \
-    for (; in_ptr < end_ptr; in_ptr += avctx->channels, out_ptr += avctx->channels) { \
+    for (; in_ptr < end_ptr; in_ptr += avctx->ch_layout.nb_channels, out_ptr += avctx->ch_layout.nb_channels) { \
         int c; \
-        for (c = 0; c < avctx->channels; c++) \
+        for (c = 0; c < avctx->ch_layout.nb_channels; c++) \
             out_ptr[c] = in_ptr[at->channel_map[c]]; \
     }
 
@@ -509,9 +510,9 @@ static int ffat_decode(AVCodecContext *avctx, void *data,
         .mNumberBuffers = 1,
         .mBuffers = {
             {
-                .mNumberChannels = avctx->channels,
+                .mNumberChannels = avctx->ch_layout.nb_channels,
                 .mDataByteSize = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->frame_size
-                                 * avctx->channels,
+                                 * avctx->ch_layout.nb_channels,
             }
         }
     };
diff --git a/libavcodec/audiotoolboxenc.c b/libavcodec/audiotoolboxenc.c
index 9245aa9dc4..aeda1c36fd 100644
--- a/libavcodec/audiotoolboxenc.c
+++ b/libavcodec/audiotoolboxenc.c
@@ -178,18 +178,17 @@ static av_cold int get_channel_label(int channel)
         return -1;
 }
 
-static int remap_layout(AudioChannelLayout *layout, uint64_t in_layout, int count)
+static int remap_layout(AudioChannelLayout *layout, const AVChannelLayout *in_layout)
 {
     int i;
-    int c = 0;
     layout->mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelDescriptions;
-    layout->mNumberChannelDescriptions = count;
-    for (i = 0; i < count; i++) {
-        int label;
-        while (!(in_layout & (1 << c)) && c < 64)
-            c++;
-        if (c == 64)
-            return AVERROR(EINVAL); // This should never happen
+    layout->mNumberChannelDescriptions = in_layout->nb_channels;
+    for (i = 0; i < in_layout->nb_channels; i++) {
+        int c, label;
+
+        c = av_channel_layout_get_channel(in_layout, i);
+        if (c < 0 || c >= 64)
+            return AVERROR(EINVAL);
         label = get_channel_label(c);
         layout->mChannelDescriptions[i].mChannelLabel = label;
         if (label < 0)
@@ -199,38 +198,33 @@ static int remap_layout(AudioChannelLayout *layout, uint64_t in_layout, int coun
     return 0;
 }
 
-static int get_aac_tag(uint64_t in_layout)
+static int get_aac_tag(const AVChannelLayout *in_layout)
 {
-    switch (in_layout) {
-    case AV_CH_LAYOUT_MONO:
-        return kAudioChannelLayoutTag_Mono;
-    case AV_CH_LAYOUT_STEREO:
-        return kAudioChannelLayoutTag_Stereo;
-    case AV_CH_LAYOUT_QUAD:
-        return kAudioChannelLayoutTag_AAC_Quadraphonic;
-    case AV_CH_LAYOUT_OCTAGONAL:
-        return kAudioChannelLayoutTag_AAC_Octagonal;
-    case AV_CH_LAYOUT_SURROUND:
-        return kAudioChannelLayoutTag_AAC_3_0;
-    case AV_CH_LAYOUT_4POINT0:
-        return kAudioChannelLayoutTag_AAC_4_0;
-    case AV_CH_LAYOUT_5POINT0:
-        return kAudioChannelLayoutTag_AAC_5_0;
-    case AV_CH_LAYOUT_5POINT1:
-        return kAudioChannelLayoutTag_AAC_5_1;
-    case AV_CH_LAYOUT_6POINT0:
-        return kAudioChannelLayoutTag_AAC_6_0;
-    case AV_CH_LAYOUT_6POINT1:
-        return kAudioChannelLayoutTag_AAC_6_1;
-    case AV_CH_LAYOUT_7POINT0:
-        return kAudioChannelLayoutTag_AAC_7_0;
-    case AV_CH_LAYOUT_7POINT1_WIDE_BACK:
-        return kAudioChannelLayoutTag_AAC_7_1;
-    case AV_CH_LAYOUT_7POINT1:
-        return kAudioChannelLayoutTag_MPEG_7_1_C;
-    default:
-        return 0;
-    }
+    static const struct {
+        AVChannelLayout chl;
+        int tag;
+    } map[] = {
+        { AV_CH_LAYOUT_MONO,              kAudioChannelLayoutTag_Mono },
+        { AV_CH_LAYOUT_STEREO,            kAudioChannelLayoutTag_Stereo },
+        { AV_CH_LAYOUT_QUAD,              kAudioChannelLayoutTag_AAC_Quadraphonic },
+        { AV_CH_LAYOUT_OCTAGONAL,         kAudioChannelLayoutTag_AAC_Octagonal },
+        { AV_CH_LAYOUT_SURROUND,          kAudioChannelLayoutTag_AAC_3_0 },
+        { AV_CH_LAYOUT_4POINT0,           kAudioChannelLayoutTag_AAC_4_0 },
+        { AV_CH_LAYOUT_5POINT0,           kAudioChannelLayoutTag_AAC_5_0 },
+        { AV_CH_LAYOUT_5POINT1,           kAudioChannelLayoutTag_AAC_5_1 },
+        { AV_CH_LAYOUT_6POINT0,           kAudioChannelLayoutTag_AAC_6_0 },
+        { AV_CH_LAYOUT_6POINT1,           kAudioChannelLayoutTag_AAC_6_1 },
+        { AV_CH_LAYOUT_7POINT0,           kAudioChannelLayoutTag_AAC_7_0 },
+        { AV_CH_LAYOUT_7POINT1_WIDE_BACK, kAudioChannelLayoutTag_AAC_7_1 },
+        { AV_CH_LAYOUT_7POINT1,           kAudioChannelLayoutTag_MPEG_7_1_C },
+    };
+    int i;
+
+    for (i = 0; i < FF_ARRAY_ELEMS; i++)
+        if (!av_channel_layout_compare(in_layout, &map[i].chl))
+            return map[i].tag;
+
+    return 0;
 }
 
 static av_cold int ffat_init_encoder(AVCodecContext *avctx)
@@ -246,10 +240,10 @@ static av_cold int ffat_init_encoder(AVCodecContext *avctx)
                         : avctx->sample_fmt == AV_SAMPLE_FMT_U8 ? 0
                         : kAudioFormatFlagIsSignedInteger)
                         | kAudioFormatFlagIsPacked,
-        .mBytesPerPacket = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->channels,
+        .mBytesPerPacket = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->ch_layout.nb_channels,
         .mFramesPerPacket = 1,
-        .mBytesPerFrame = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->channels,
-        .mChannelsPerFrame = avctx->channels,
+        .mBytesPerFrame = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->ch_layout.nb_channels,
+        .mChannelsPerFrame = avctx->ch_layout.nb_channels,
         .mBitsPerChannel = av_get_bytes_per_sample(avctx->sample_fmt) * 8,
     };
     AudioStreamBasicDescription out_format = {
@@ -258,7 +252,7 @@ static av_cold int ffat_init_encoder(AVCodecContext *avctx)
         .mChannelsPerFrame = in_format.mChannelsPerFrame,
     };
     UInt32 layout_size = sizeof(AudioChannelLayout) +
-                         sizeof(AudioChannelDescription) * avctx->channels;
+                         sizeof(AudioChannelDescription) * avctx->ch_layout.nb_channels;
     AudioChannelLayout *channel_layout = av_malloc(layout_size);
 
     if (!channel_layout)
@@ -278,10 +272,7 @@ static av_cold int ffat_init_encoder(AVCodecContext *avctx)
         return AVERROR_UNKNOWN;
     }
 
-    if (!avctx->channel_layout)
-        avctx->channel_layout = av_get_default_channel_layout(avctx->channels);
-
-    if ((status = remap_layout(channel_layout, avctx->channel_layout, avctx->channels)) < 0) {
+    if ((status = remap_layout(channel_layout, &avctx->ch_layout)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "Invalid channel layout\n");
         av_free(channel_layout);
         return status;
@@ -294,7 +285,7 @@ static av_cold int ffat_init_encoder(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
     if (avctx->codec_id == AV_CODEC_ID_AAC) {
-        int tag = get_aac_tag(avctx->channel_layout);
+        int tag = get_aac_tag(&avctx->ch_layout);
         if (tag) {
             channel_layout->mChannelLayoutTag = tag;
             channel_layout->mNumberChannelDescriptions = 0;
@@ -476,10 +467,10 @@ static OSStatus ffat_encode_callback(AudioConverterRef converter, UInt32 *nb_pac
     frame = ff_bufqueue_get(&at->frame_queue);
 
     data->mNumberBuffers              = 1;
-    data->mBuffers[0].mNumberChannels = avctx->channels;
+    data->mBuffers[0].mNumberChannels = avctx->ch_layout.nb_channels;
     data->mBuffers[0].mDataByteSize   = frame->nb_samples *
                                         av_get_bytes_per_sample(avctx->sample_fmt) *
-                                        avctx->channels;
+                                        avctx->ch_layout.nb_channels;
     data->mBuffers[0].mData           = frame->data[0];
     if (*nb_packets > frame->nb_samples)
         *nb_packets = frame->nb_samples;
@@ -506,7 +497,7 @@ static int ffat_encode(AVCodecContext *avctx, AVPacket *avpkt,
         .mNumberBuffers = 1,
         .mBuffers = {
             {
-                .mNumberChannels = avctx->channels,
+                .mNumberChannels = avctx->ch_layout.nb_channels,
                 .mDataByteSize = at->pkt_size,
             }
         }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 196/281] binkaudio: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (196 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 195/281] audiotoolbox: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 197/281] bmvaudio: " James Almer
                   ` (84 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/binkaudio.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c
index f808141ba5..be321233c8 100644
--- a/libavcodec/binkaudio.c
+++ b/libavcodec/binkaudio.c
@@ -72,6 +72,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     int sample_rate_half;
     int i, ret;
     int frame_len_bits;
+    int channels = avctx->ch_layout.nb_channels;
 
     /* determine frame length */
     if (avctx->sample_rate < 22050) {
@@ -82,26 +83,26 @@ static av_cold int decode_init(AVCodecContext *avctx)
         frame_len_bits = 11;
     }
 
-    if (avctx->channels < 1 || avctx->channels > MAX_CHANNELS) {
-        av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", avctx->channels);
+    if (channels < 1 || channels > MAX_CHANNELS) {
+        av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", channels);
         return AVERROR_INVALIDDATA;
     }
-    avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
-                                                   AV_CH_LAYOUT_STEREO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_default(&avctx->ch_layout, channels);
 
     s->version_b = avctx->extradata_size >= 4 && avctx->extradata[3] == 'b';
 
     if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT) {
         // audio is already interleaved for the RDFT format variant
         avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
-        if (sample_rate > INT_MAX / avctx->channels)
+        if (sample_rate > INT_MAX / channels)
             return AVERROR_INVALIDDATA;
-        sample_rate  *= avctx->channels;
+        sample_rate  *= channels;
         s->channels = 1;
         if (!s->version_b)
-            frame_len_bits += av_log2(avctx->channels);
+            frame_len_bits += av_log2(channels);
     } else {
-        s->channels = avctx->channels;
+        s->channels = channels;
         avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
     }
 
@@ -325,7 +326,7 @@ static int binkaudio_receive_frame(AVCodecContext *avctx, AVFrame *frame)
         av_packet_unref(s->pkt);
     }
 
-    frame->nb_samples = s->block_size / avctx->channels;
+    frame->nb_samples = s->block_size / avctx->ch_layout.nb_channels;
 
     return 0;
 fail:
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 197/281] bmvaudio: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (197 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 196/281] binkaudio: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 198/281] cng: " James Almer
                   ` (83 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/bmvaudio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/bmvaudio.c b/libavcodec/bmvaudio.c
index a7eae46103..d81dba8821 100644
--- a/libavcodec/bmvaudio.c
+++ b/libavcodec/bmvaudio.c
@@ -31,8 +31,8 @@ static const int bmv_aud_mults[16] = {
 
 static av_cold int bmv_aud_decode_init(AVCodecContext *avctx)
 {
-    avctx->channels       = 2;
-    avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
 
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 198/281] cng: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (198 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 197/281] bmvaudio: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 199/281] cook: " James Almer
                   ` (82 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cngdec.c | 3 ++-
 libavcodec/cngenc.c | 6 +-----
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/libavcodec/cngdec.c b/libavcodec/cngdec.c
index ecfd4abfc9..30d36f7326 100644
--- a/libavcodec/cngdec.c
+++ b/libavcodec/cngdec.c
@@ -56,7 +56,8 @@ static av_cold int cng_decode_init(AVCodecContext *avctx)
     CNGContext *p = avctx->priv_data;
 
     avctx->sample_fmt  = AV_SAMPLE_FMT_S16;
-    avctx->channels    = 1;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout   = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_rate = 8000;
 
     p->order            = 12;
diff --git a/libavcodec/cngenc.c b/libavcodec/cngenc.c
index 830311f955..d77bbac40e 100644
--- a/libavcodec/cngenc.c
+++ b/libavcodec/cngenc.c
@@ -48,11 +48,6 @@ static av_cold int cng_encode_init(AVCodecContext *avctx)
     CNGContext *p = avctx->priv_data;
     int ret;
 
-    if (avctx->channels != 1) {
-        av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
-        return AVERROR(EINVAL);
-    }
-
     avctx->frame_size = 640;
     p->order = 10;
     if ((ret = ff_lpc_init(&p->lpc, avctx->frame_size, p->order, FF_LPC_TYPE_LEVINSON)) < 0)
@@ -113,5 +108,6 @@ const AVCodec ff_comfortnoise_encoder = {
     .close          = cng_encode_close,
     .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
                                                      AV_SAMPLE_FMT_NONE },
+    .ch_layouts     = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO, { 0 } },
     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 199/281] cook: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (199 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 198/281] cng: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 200/281] dca: " James Almer
                   ` (81 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cook.c        | 25 ++++++++++++++-----------
 libavcodec/cook_parser.c |  4 ++--
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index 3720772102..6f9bdb55e0 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -1054,7 +1054,7 @@ static void dump_cook_context(COOKContext *q)
         PRINT("js_vlc_bits", q->subpacket[0].js_vlc_bits);
     }
     ff_dlog(q->avctx, "COOKContext\n");
-    PRINT("nb_channels", q->avctx->channels);
+    PRINT("nb_channels", q->avctx->ch_layout.nb_channels);
     PRINT("bit_rate", (int)q->avctx->bit_rate);
     PRINT("sample_rate", q->avctx->sample_rate);
     PRINT("samples_per_channel", q->subpacket[0].samples_per_channel);
@@ -1079,6 +1079,8 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
     unsigned int channel_mask = 0;
     int samples_per_frame = 0;
     int ret;
+    int channels = avctx->ch_layout.nb_channels;
+
     q->avctx = avctx;
 
     /* Take care of the codec specific extradata. */
@@ -1091,7 +1093,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
     bytestream2_init(&gb, avctx->extradata, avctx->extradata_size);
 
     /* Take data from the AVCodecContext (RM container). */
-    if (!avctx->channels) {
+    if (!channels) {
         av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
         return AVERROR_INVALIDDATA;
     }
@@ -1123,7 +1125,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
         q->subpacket[s].js_vlc_bits      = bytestream2_get_be16(&gb);
 
         /* Initialize extradata related variables. */
-        q->subpacket[s].samples_per_channel = samples_per_frame / avctx->channels;
+        q->subpacket[s].samples_per_channel = samples_per_frame / channels;
         q->subpacket[s].bits_per_subpacket = avctx->block_align * 8;
 
         /* Initialize default data states. */
@@ -1138,21 +1140,21 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
         q->subpacket[s].joint_stereo = 0;
         switch (q->subpacket[s].cookversion) {
         case MONO:
-            if (avctx->channels != 1) {
+            if (channels != 1) {
                 avpriv_request_sample(avctx, "Container channels != 1");
                 return AVERROR_PATCHWELCOME;
             }
             av_log(avctx, AV_LOG_DEBUG, "MONO\n");
             break;
         case STEREO:
-            if (avctx->channels != 1) {
+            if (channels != 1) {
                 q->subpacket[s].bits_per_subpdiv = 1;
                 q->subpacket[s].num_channels = 2;
             }
             av_log(avctx, AV_LOG_DEBUG, "STEREO\n");
             break;
         case JOINT_STEREO:
-            if (avctx->channels != 2) {
+            if (channels != 2) {
                 avpriv_request_sample(avctx, "Container channels != 2");
                 return AVERROR_PATCHWELCOME;
             }
@@ -1174,7 +1176,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
             av_log(avctx, AV_LOG_DEBUG, "MULTI_CHANNEL\n");
             channel_mask |= q->subpacket[s].channel_mask = bytestream2_get_be32(&gb);
 
-            if (av_get_channel_layout_nb_channels(q->subpacket[s].channel_mask) > 1) {
+            if (channels > 1) {
                 q->subpacket[s].total_subbands = q->subpacket[s].subbands +
                                                  q->subpacket[s].js_subband_start;
                 q->subpacket[s].joint_stereo = 1;
@@ -1233,8 +1235,8 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
         q->subpacket[s].gains2.now      = q->subpacket[s].gain_3;
         q->subpacket[s].gains2.previous = q->subpacket[s].gain_4;
 
-        if (q->num_subpackets + q->subpacket[s].num_channels > q->avctx->channels) {
-            av_log(avctx, AV_LOG_ERROR, "Too many subpackets %d for channels %d\n", q->num_subpackets, q->avctx->channels);
+        if (q->num_subpackets + q->subpacket[s].num_channels > channels) {
+            av_log(avctx, AV_LOG_ERROR, "Too many subpackets %d for channels %d\n", q->num_subpackets, channels);
             return AVERROR_INVALIDDATA;
         }
 
@@ -1282,10 +1284,11 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
     }
 
     avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
+    av_channel_layout_uninit(&avctx->ch_layout);
     if (channel_mask)
-        avctx->channel_layout = channel_mask;
+        av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
     else
-        avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
+        av_channel_layout_default(&avctx->ch_layout, channels);
 
 
     dump_cook_context(q);
diff --git a/libavcodec/cook_parser.c b/libavcodec/cook_parser.c
index a05ebf94b8..0d9473845e 100644
--- a/libavcodec/cook_parser.c
+++ b/libavcodec/cook_parser.c
@@ -41,8 +41,8 @@ static int cook_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
     CookParseContext *s = s1->priv_data;
 
     if (!s->duration &&
-                avctx->extradata && avctx->extradata_size >= 8 && avctx->channels)
-        s->duration = AV_RB16(avctx->extradata + 4) / avctx->channels;
+        avctx->extradata && avctx->extradata_size >= 8 && avctx->ch_layout.nb_channels)
+        s->duration = AV_RB16(avctx->extradata + 4) / avctx->ch_layout.nb_channels;
 
     s1->duration = s->duration;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 200/281] dca: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (200 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 199/281] cook: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 201/281] dolby_e: " James Almer
                   ` (80 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/dca_core.c |  6 ++--
 libavcodec/dca_lbr.c  | 20 +++++++-----
 libavcodec/dca_xll.c  |  2 +-
 libavcodec/dcadec.c   | 71 ++++++++++++++++++++++++++++++-------------
 libavcodec/dcadec.h   |  7 +++++
 libavcodec/dcaenc.c   | 39 ++++++++++++++++--------
 6 files changed, 100 insertions(+), 45 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 758e3447a6..ebe44c2d15 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -2148,7 +2148,7 @@ static int filter_frame_fixed(DCACoreDecoder *s, AVFrame *frame)
                                        nsamples, s->ch_mask);
     }
 
-    for (i = 0; i < avctx->channels; i++) {
+    for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
         int32_t *samples = s->output_samples[s->ch_remap[i]];
         int32_t *plane = (int32_t *)frame->extended_data[i];
         for (n = 0; n < nsamples; n++)
@@ -2180,11 +2180,11 @@ static int filter_frame_float(DCACoreDecoder *s, AVFrame *frame)
         return ret;
 
     // Build reverse speaker to channel mapping
-    for (i = 0; i < avctx->channels; i++)
+    for (i = 0; i < avctx->ch_layout.nb_channels; i++)
         output_samples[s->ch_remap[i]] = (float *)frame->extended_data[i];
 
     // Allocate space for extra channels
-    nchannels = av_popcount(s->ch_mask) - avctx->channels;
+    nchannels = av_popcount(s->ch_mask) - avctx->ch_layout.nb_channels;
     if (nchannels > 0) {
         av_fast_malloc(&s->output_buffer, &s->output_size,
                        nsamples * nchannels * sizeof(float));
diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index 481a8df7e6..c11f2f7e18 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -107,10 +107,6 @@ static const uint8_t lfe_index[7] = {
     1, 2, 3, 0, 1, 2, 3
 };
 
-static const uint8_t channel_counts[7] = {
-    1, 2, 3, 2, 3, 4, 5
-};
-
 static const uint16_t channel_layouts[7] = {
     AV_CH_LAYOUT_MONO,
     AV_CH_LAYOUT_STEREO,
@@ -1731,9 +1727,8 @@ int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame)
     AVCodecContext *avctx = s->avctx;
     int i, ret, nchannels, ch_conf = (s->ch_mask & 0x7) - 1;
     const int8_t *reorder;
+    uint64_t channel_mask = channel_layouts[ch_conf];
 
-    avctx->channel_layout = channel_layouts[ch_conf];
-    avctx->channels = nchannels = channel_counts[ch_conf];
     avctx->sample_rate = s->sample_rate;
     avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
     avctx->bits_per_raw_sample = 0;
@@ -1741,13 +1736,22 @@ int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame)
     avctx->bit_rate = s->bit_rate_scaled;
 
     if (s->flags & LBR_FLAG_LFE_PRESENT) {
-        avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
-        avctx->channels++;
+        channel_mask |= AV_CH_LOW_FREQUENCY;
         reorder = channel_reorder_lfe[ch_conf];
     } else {
         reorder = channel_reorder_nolfe[ch_conf];
     }
 
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    avctx->channels = avctx->ch_layout.nb_channels;
+    avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                            avctx->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
     frame->nb_samples = 1024 << s->freq_range;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index ab14dbcc88..a4ff3f9aa2 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -1442,7 +1442,7 @@ int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame *frame)
                                        s->output_mask);
     }
 
-    for (i = 0; i < avctx->channels; i++) {
+    for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
         int32_t *samples = s->output_samples[ch_remap[i]];
         if (frame->format == AV_SAMPLE_FMT_S16P) {
             int16_t *plane = (int16_t *)frame->extended_data[i];
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 43694b51f7..239ed9ac91 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -42,13 +42,17 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask
         13, 14, 3, 9, 10, 11, 12, 14, 16, 15, 17, 8, 4,  5,
     };
 
+    DCAContext *s = avctx->priv_data;
+
     int dca_ch, wav_ch, nchannels = 0;
 
-    if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) {
+    av_channel_layout_uninit(&avctx->ch_layout);
+    if (s->output_channel_order == CHANNEL_ORDER_CODED) {
         for (dca_ch = 0; dca_ch < DCA_SPEAKER_COUNT; dca_ch++)
             if (dca_mask & (1U << dca_ch))
                 ch_remap[nchannels++] = dca_ch;
-        avctx->channel_layout = dca_mask;
+        avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        avctx->ch_layout.nb_channels = nchannels;
     } else {
         int wav_mask = 0;
         int wav_map[18];
@@ -70,10 +74,18 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask
         for (wav_ch = 0; wav_ch < 18; wav_ch++)
             if (wav_mask & (1 << wav_ch))
                 ch_remap[nchannels++] = wav_map[wav_ch];
-        avctx->channel_layout = wav_mask;
+
+        av_channel_layout_from_mask(&avctx->ch_layout, wav_mask);
     }
 
-    avctx->channels = nchannels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    avctx->channels = avctx->ch_layout.nb_channels;
+    avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                            avctx->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
     return nchannels;
 }
 
@@ -349,23 +361,28 @@ static av_cold int dcadec_init(AVCodecContext *avctx)
 
     s->crctab = av_crc_get_table(AV_CRC_16_CCITT);
 
-    switch (avctx->request_channel_layout & ~AV_CH_LAYOUT_NATIVE) {
-    case 0:
-        s->request_channel_layout = 0;
-        break;
-    case AV_CH_LAYOUT_STEREO:
-    case AV_CH_LAYOUT_STEREO_DOWNMIX:
-        s->request_channel_layout = DCA_SPEAKER_LAYOUT_STEREO;
-        break;
-    case AV_CH_LAYOUT_5POINT0:
-        s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT0;
-        break;
-    case AV_CH_LAYOUT_5POINT1:
-        s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT1;
-        break;
-    default:
-        av_log(avctx, AV_LOG_WARNING, "Invalid request_channel_layout\n");
-        break;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE)
+        s->output_channel_order = CHANNEL_ORDER_CODED;
+
+    if (avctx->request_channel_layout & ~AV_CH_LAYOUT_NATIVE) {
+        av_channel_layout_uninit(&s->downmix_layout);
+        av_channel_layout_from_mask(&s->downmix_layout, avctx->request_channel_layout & ~AV_CH_LAYOUT_NATIVE);
+    }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+    if (s->downmix_layout.nb_channels) {
+        if (!av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO) ||
+            !av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX))
+            s->request_channel_layout = DCA_SPEAKER_LAYOUT_STEREO;
+        else if (!av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0))
+            s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT0;
+        else if (!av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1))
+            s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT1;
+        else
+            av_log(avctx, AV_LOG_WARNING, "Invalid downmix layout\n");
     }
 
     ff_thread_once(&init_static_once, dcadec_init_static);
@@ -378,6 +395,18 @@ static av_cold int dcadec_init(AVCodecContext *avctx)
 
 static const AVOption dcadec_options[] = {
     { "core_only", "Decode core only without extensions", OFFSET(core_only), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, PARAM },
+
+    { "channel_order", "Order in which the channels are to be exported",
+        OFFSET(output_channel_order), AV_OPT_TYPE_INT,
+        { .i64 = CHANNEL_ORDER_DEFAULT }, 0, 1, PARAM, "channel_order" },
+      { "default", "normal libavcodec channel order", 0, AV_OPT_TYPE_CONST,
+        { .i64 = CHANNEL_ORDER_DEFAULT }, .flags = PARAM, "channel_order" },
+      { "coded",    "order in which the channels are coded in the bitstream",
+        0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = PARAM, "channel_order" },
+
+    { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout),
+        AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = PARAM },
+
     { NULL }
 };
 
diff --git a/libavcodec/dcadec.h b/libavcodec/dcadec.h
index 9da8d3b444..7fdb62d310 100644
--- a/libavcodec/dcadec.h
+++ b/libavcodec/dcadec.h
@@ -43,6 +43,11 @@
 #define DCA_PACKET_RECOVERY     0x10    ///< Sync error recovery flag
 #define DCA_PACKET_RESIDUAL     0x20    ///< Core valid for residual decoding
 
+enum DCAOutputChannelOrder {
+    CHANNEL_ORDER_DEFAULT,
+    CHANNEL_ORDER_CODED,
+};
+
 typedef struct DCAContext {
     const AVClass   *class;       ///< class for AVOptions
     AVCodecContext  *avctx;
@@ -63,6 +68,8 @@ typedef struct DCAContext {
 
     int     request_channel_layout; ///< Converted from avctx.request_channel_layout
     int     core_only;              ///< Core only decoding flag
+    int     output_channel_order;
+    AVChannelLayout downmix_layout;
 } DCAContext;
 
 int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask);
diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index 884ac896d3..a3aae93dc9 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -163,15 +163,15 @@ static void subband_bufer_free(DCAEncContext *c)
 static int encode_init(AVCodecContext *avctx)
 {
     DCAEncContext *c = avctx->priv_data;
-    uint64_t layout = avctx->channel_layout;
+    AVChannelLayout layout = avctx->ch_layout;
     int i, j, k, min_frame_bits;
     int ret;
 
     if ((ret = subband_bufer_alloc(c)) < 0)
         return ret;
 
-    c->fullband_channels = c->channels = avctx->channels;
-    c->lfe_channel = (avctx->channels == 3 || avctx->channels == 6);
+    c->fullband_channels = c->channels = layout.nb_channels;
+    c->lfe_channel = (c->channels == 3 || c->channels == 6);
     c->band_interpolation = c->band_interpolation_tab[1];
     c->band_spectrum = c->band_spectrum_tab[1];
     c->worst_quantization_noise = -2047;
@@ -181,19 +181,24 @@ static int encode_init(AVCodecContext *avctx)
     if (ff_dcaadpcm_init(&c->adpcm_ctx))
         return AVERROR(ENOMEM);
 
-    if (!layout) {
+    if (layout.order == AV_CHANNEL_ORDER_UNSPEC) {
         av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
                                       "encoder will guess the layout, but it "
                                       "might be incorrect.\n");
-        layout = av_get_default_channel_layout(avctx->channels);
+        av_channel_layout_default(&layout, layout.nb_channels);
     }
-    switch (layout) {
-    case AV_CH_LAYOUT_MONO:         c->channel_config = 0; break;
-    case AV_CH_LAYOUT_STEREO:       c->channel_config = 2; break;
-    case AV_CH_LAYOUT_2_2:          c->channel_config = 8; break;
-    case AV_CH_LAYOUT_5POINT0:      c->channel_config = 9; break;
-    case AV_CH_LAYOUT_5POINT1:      c->channel_config = 9; break;
-    default:
+
+    if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO))
+        c->channel_config = 0;
+    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO))
+        c->channel_config = 2;
+    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2))
+        c->channel_config = 8;
+    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0))
+        c->channel_config = 9;
+    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1))
+        c->channel_config = 9;
+    else {
         av_log(avctx, AV_LOG_ERROR, "Unsupported channel layout!\n");
         return AVERROR_PATCHWELCOME;
     }
@@ -1248,12 +1253,22 @@ const AVCodec ff_dca_encoder = {
     .sample_fmts           = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32,
                                                             AV_SAMPLE_FMT_NONE },
     .supported_samplerates = sample_rates,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
                                                   AV_CH_LAYOUT_STEREO,
                                                   AV_CH_LAYOUT_2_2,
                                                   AV_CH_LAYOUT_5POINT0,
                                                   AV_CH_LAYOUT_5POINT1,
                                                   0 },
+#endif
+    .ch_layouts       = (const AVChannelLayout[]){
+        AV_CHANNEL_LAYOUT_MONO,
+        AV_CHANNEL_LAYOUT_STEREO,
+        AV_CHANNEL_LAYOUT_2_2,
+        AV_CHANNEL_LAYOUT_5POINT0,
+        AV_CHANNEL_LAYOUT_5POINT1,
+        { 0 },
+    },
     .defaults              = defaults,
     .priv_class            = &dcaenc_class,
 };
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 201/281] dolby_e: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (201 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 200/281] dca: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 202/281] dpcm: " James Almer
                   ` (79 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/dolby_e.c        | 52 ++++++++++++++++++++++++++++++++-----
 libavcodec/dolby_e.h        |  2 ++
 libavcodec/dolby_e_parser.c | 11 +++++---
 3 files changed, 55 insertions(+), 10 deletions(-)

diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c
index 6c0d54be4c..a9106a7632 100644
--- a/libavcodec/dolby_e.c
+++ b/libavcodec/dolby_e.c
@@ -23,6 +23,7 @@
 #include "libavutil/thread.h"
 #include "libavutil/mem.h"
 #include "libavutil/mem_internal.h"
+#include "libavutil/opt.h"
 
 #include "internal.h"
 #include "get_bits.h"
@@ -39,6 +40,11 @@
 #define MAX_MSTR_EXP    2
 #define MAX_BIAS_EXP    50
 
+enum DBEOutputChannelOrder {
+    CHANNEL_ORDER_DEFAULT,
+    CHANNEL_ORDER_CODED,
+};
+
 typedef struct DBEGroup {
     uint8_t         nb_exponent;
     uint8_t         nb_bias_exp[MAX_MSTR_EXP];
@@ -70,6 +76,7 @@ typedef struct DBEChannel {
 } DBEChannel;
 
 typedef struct DBEDecodeContext {
+    const AVClass   *class;
     AVCodecContext  *avctx;
     DBEContext  dectx;
 
@@ -1057,7 +1064,7 @@ static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
         reorder = ch_reorder_4;
     else if (metadata->nb_channels == 6)
         reorder = ch_reorder_6;
-    else if (metadata->nb_programs == 1 && !(s->avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE))
+    else if (metadata->nb_programs == 1 && metadata->output_channel_order == CHANNEL_ORDER_DEFAULT)
         reorder = ch_reorder_8;
     else
         reorder = ch_reorder_n;
@@ -1093,19 +1100,23 @@ static int dolby_e_decode_frame(AVCodecContext *avctx, void *data,
         s->metadata.multi_prog_warned = 1;
     }
 
+    av_channel_layout_uninit(&avctx->ch_layout);
     switch (s->metadata.nb_channels) {
     case 4:
-        avctx->channel_layout = AV_CH_LAYOUT_4POINT0;
+        avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0;
         break;
     case 6:
-        avctx->channel_layout = AV_CH_LAYOUT_5POINT1;
+        avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1;
         break;
     case 8:
-        avctx->channel_layout = AV_CH_LAYOUT_7POINT1;
+        avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1;
+        break;
+    default:
+        avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        avctx->ch_layout.nb_channels = s->metadata.nb_channels;
         break;
     }
 
-    avctx->channels    = s->metadata.nb_channels;
     avctx->sample_rate = s->metadata.sample_rate;
     avctx->sample_fmt  = AV_SAMPLE_FMT_FLTP;
 
@@ -1252,17 +1263,46 @@ static av_cold int dolby_e_init(AVCodecContext *avctx)
     if (!(s->fdsp = avpriv_float_dsp_alloc(0)))
         return AVERROR(ENOMEM);
 
-    s->dectx.metadata.multi_prog_warned = !!(avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE)
+        s->dectx.metadata.output_channel_order = CHANNEL_ORDER_CODED;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+    s->dectx.metadata.multi_prog_warned = s->dectx.metadata.output_channel_order == CHANNEL_ORDER_CODED;
     s->dectx.avctx = s->avctx = avctx;
     return 0;
 }
 
+#define OFFSET(x) offsetof(DBEDecodeContext, x)
+#define FLAGS (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
+static const AVOption options[] = {
+    { "channel_order", "Order in which the channels are to be exported",
+        OFFSET(dectx.metadata.output_channel_order), AV_OPT_TYPE_INT,
+        { .i64 = CHANNEL_ORDER_DEFAULT }, 0, 1, FLAGS, "channel_order" },
+      { "default", "normal libavcodec channel order", 0, AV_OPT_TYPE_CONST,
+        { .i64 = CHANNEL_ORDER_DEFAULT }, .flags = FLAGS, "channel_order" },
+      { "coded",    "order in which the channels are coded in the bitstream",
+        0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = FLAGS, "channel_order" },
+
+      { NULL },
+};
+
+static const AVClass dolby_e_decoder_class = {
+    .class_name = "Dolby E decoder",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 const AVCodec ff_dolby_e_decoder = {
     .name           = "dolby_e",
     .long_name      = NULL_IF_CONFIG_SMALL("Dolby E"),
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_DOLBY_E,
     .priv_data_size = sizeof(DBEDecodeContext),
+    .priv_class     = &dolby_e_decoder_class,
     .init           = dolby_e_init,
     .decode         = dolby_e_decode_frame,
     .close          = dolby_e_close,
diff --git a/libavcodec/dolby_e.h b/libavcodec/dolby_e.h
index 9f0c065729..b2eadfea4a 100644
--- a/libavcodec/dolby_e.h
+++ b/libavcodec/dolby_e.h
@@ -59,6 +59,8 @@ typedef struct DolbyEHeaderInfo {
      */
     int         multi_prog_warned;
 
+    int         output_channel_order;
+
     int         sample_rate;
     /** @} */
 } DolbyEHeaderInfo;
diff --git a/libavcodec/dolby_e_parser.c b/libavcodec/dolby_e_parser.c
index 23bddd14f3..9f54627356 100644
--- a/libavcodec/dolby_e_parser.c
+++ b/libavcodec/dolby_e_parser.c
@@ -42,17 +42,20 @@ static int dolby_e_parse(AVCodecParserContext *s2, AVCodecContext *avctx,
     s2->duration = FRAME_SAMPLES;
     switch (s->metadata.nb_channels) {
     case 4:
-        avctx->channel_layout = AV_CH_LAYOUT_4POINT0;
+        avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0;
         break;
     case 6:
-        avctx->channel_layout = AV_CH_LAYOUT_5POINT1;
+        avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1;
         break;
     case 8:
-        avctx->channel_layout = AV_CH_LAYOUT_7POINT1;
+        avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1;
+        break;
+    default:
+        avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        avctx->ch_layout.nb_channels = s->metadata.nb_channels;
         break;
     }
 
-    avctx->channels    = s->metadata.nb_channels;
     avctx->sample_rate = s->metadata.sample_rate;
     avctx->sample_fmt  = AV_SAMPLE_FMT_FLTP;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 202/281] dpcm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (202 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 201/281] dolby_e: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 203/281] dsd: " James Almer
                   ` (78 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/dpcm.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/dpcm.c b/libavcodec/dpcm.c
index d9ea23adb3..95052282ae 100644
--- a/libavcodec/dpcm.c
+++ b/libavcodec/dpcm.c
@@ -132,7 +132,7 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx)
     DPCMContext *s = avctx->priv_data;
     int i;
 
-    if (avctx->channels < 1 || avctx->channels > 2) {
+    if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
         return AVERROR(EINVAL);
     }
@@ -215,7 +215,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
     int out = 0, ret;
     int predictor[2];
     int ch = 0;
-    int stereo = avctx->channels - 1;
+    int stereo = avctx->ch_layout.nb_channels - 1;
     int16_t *output_samples, *samples_end;
     GetByteContext gb;
 
@@ -229,10 +229,10 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
         out = buf_size - 8;
         break;
     case AV_CODEC_ID_INTERPLAY_DPCM:
-        out = buf_size - 6 - avctx->channels;
+        out = buf_size - 6 - avctx->ch_layout.nb_channels;
         break;
     case AV_CODEC_ID_XAN_DPCM:
-        out = buf_size - 2 * avctx->channels;
+        out = buf_size - 2 * avctx->ch_layout.nb_channels;
         break;
     case AV_CODEC_ID_SOL_DPCM:
         if (avctx->codec_tag != 3)
@@ -250,12 +250,12 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
         av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
         return AVERROR(EINVAL);
     }
-    if (out % avctx->channels) {
+    if (out % avctx->ch_layout.nb_channels) {
         av_log(avctx, AV_LOG_WARNING, "channels have differing number of samples\n");
     }
 
     /* get output buffer */
-    frame->nb_samples = (out + avctx->channels - 1) / avctx->channels;
+    frame->nb_samples = (out + avctx->ch_layout.nb_channels - 1) / avctx->ch_layout.nb_channels;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
     output_samples = (int16_t *)frame->data[0];
@@ -287,7 +287,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
     case AV_CODEC_ID_INTERPLAY_DPCM:
         bytestream2_skipu(&gb, 6);  /* skip over the stream mask and stream length */
 
-        for (ch = 0; ch < avctx->channels; ch++) {
+        for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
             predictor[ch] = sign_extend(bytestream2_get_le16u(&gb), 16);
             *output_samples++ = predictor[ch];
         }
@@ -307,7 +307,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
     {
         int shift[2] = { 4, 4 };
 
-        for (ch = 0; ch < avctx->channels; ch++)
+        for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
             predictor[ch] = sign_extend(bytestream2_get_le16u(&gb), 16);
 
         ch = 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 203/281] dsd: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (203 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 202/281] dpcm: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 204/281] dsicinav: " James Almer
                   ` (77 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/dsddec.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/dsddec.c b/libavcodec/dsddec.c
index 19fb75ee85..02698ee116 100644
--- a/libavcodec/dsddec.c
+++ b/libavcodec/dsddec.c
@@ -44,17 +44,17 @@ static av_cold int decode_init(AVCodecContext *avctx)
     int i;
     uint8_t silence;
 
-    if (!avctx->channels)
+    if (!avctx->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
 
     ff_init_dsd_data();
 
-    s = av_malloc_array(sizeof(DSDContext), avctx->channels);
+    s = av_malloc_array(sizeof(DSDContext), avctx->ch_layout.nb_channels);
     if (!s)
         return AVERROR(ENOMEM);
 
     silence = avctx->codec_id == AV_CODEC_ID_DSD_LSBF || avctx->codec_id == AV_CODEC_ID_DSD_LSBF_PLANAR ? DSD_SILENCE_REVERSED : DSD_SILENCE;
-    for (i = 0; i < avctx->channels; i++) {
+    for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
         s[i].pos = 0;
         memset(s[i].buf, silence, sizeof(s[i].buf));
     }
@@ -84,7 +84,7 @@ static int dsd_channel(AVCodecContext *avctx, void *tdata, int j, int threadnr)
         src_stride = 1;
     } else {
         src_next   = 1;
-        src_stride = avctx->channels;
+        src_stride = avctx->ch_layout.nb_channels;
     }
 
     ff_dsd2pcm_translate(&s[j], frame->nb_samples, lsbf,
@@ -101,17 +101,17 @@ static int decode_frame(AVCodecContext *avctx, void *data,
     AVFrame *frame = data;
     int ret;
 
-    frame->nb_samples = avpkt->size / avctx->channels;
+    frame->nb_samples = avpkt->size / avctx->ch_layout.nb_channels;
 
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
     td.frame = frame;
     td.avpkt = avpkt;
-    avctx->execute2(avctx, dsd_channel, &td, NULL, avctx->channels);
+    avctx->execute2(avctx, dsd_channel, &td, NULL, avctx->ch_layout.nb_channels);
 
     *got_frame_ptr = 1;
-    return frame->nb_samples * avctx->channels;
+    return frame->nb_samples * avctx->ch_layout.nb_channels;
 }
 
 #define DSD_DECODER(id_, name_, long_name_) \
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 204/281] dsicinav: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (204 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 203/281] dsd: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 205/281] dss_sp: " James Almer
                   ` (76 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/dsicinaudio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dsicinaudio.c b/libavcodec/dsicinaudio.c
index 39869ac0cd..a543f6dd09 100644
--- a/libavcodec/dsicinaudio.c
+++ b/libavcodec/dsicinaudio.c
@@ -80,8 +80,8 @@ static av_cold int cinaudio_decode_init(AVCodecContext *avctx)
     cin->initial_decode_frame = 1;
     cin->delta                = 0;
     avctx->sample_fmt         = AV_SAMPLE_FMT_S16;
-    avctx->channels           = 1;
-    avctx->channel_layout     = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout          = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     return 0;
 }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 205/281] dss_sp: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (205 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 204/281] dsicinav: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 206/281] dst: " James Almer
                   ` (75 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/dss_sp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dss_sp.c b/libavcodec/dss_sp.c
index 050b412496..c8da3bffaf 100644
--- a/libavcodec/dss_sp.c
+++ b/libavcodec/dss_sp.c
@@ -290,10 +290,10 @@ static const int32_t dss_sp_sinc[67] = {
 static av_cold int dss_sp_decode_init(AVCodecContext *avctx)
 {
     DssSpContext *p = avctx->priv_data;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
-    avctx->channels       = 1;
     avctx->sample_rate    = 11025;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     p->pulse_dec_mode = 1;
     p->avctx          = avctx;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 206/281] dst: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (206 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 205/281] dss_sp: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 207/281] dvaudio: " James Almer
                   ` (74 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/dstdec.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/dstdec.c b/libavcodec/dstdec.c
index 6d0b25f4c3..78427bd15c 100644
--- a/libavcodec/dstdec.c
+++ b/libavcodec/dstdec.c
@@ -80,8 +80,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
     DSTContext *s = avctx->priv_data;
     int i;
 
-    if (avctx->channels > DST_MAX_CHANNELS) {
-        avpriv_request_sample(avctx, "Channel count %d", avctx->channels);
+    if (avctx->ch_layout.nb_channels > DST_MAX_CHANNELS) {
+        avpriv_request_sample(avctx, "Channel count %d", avctx->ch_layout.nb_channels);
         return AVERROR_PATCHWELCOME;
     }
 
@@ -97,7 +97,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
-    for (i = 0; i < avctx->channels; i++)
+    for (i = 0; i < avctx->ch_layout.nb_channels; i++)
         memset(s->dsdctx[i].buf, 0x69, sizeof(s->dsdctx[i].buf));
 
     ff_init_dsd_data();
@@ -243,7 +243,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
     unsigned map_ch_to_pelem[DST_MAX_CHANNELS];
     unsigned i, ch, same_map, dst_x_bit;
     unsigned half_prob[DST_MAX_CHANNELS];
-    const int channels = avctx->channels;
+    const int channels = avctx->ch_layout.nb_channels;
     DSTContext *s = avctx->priv_data;
     GetBitContext *gb = &s->gb;
     ArithCoder *ac = &s->ac;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 207/281] dvaudio: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (207 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 206/281] dst: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 208/281] evrc: " James Almer
                   ` (73 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/dvaudiodec.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/libavcodec/dvaudiodec.c b/libavcodec/dvaudiodec.c
index 82e6dbe36c..f3b1dee075 100644
--- a/libavcodec/dvaudiodec.c
+++ b/libavcodec/dvaudiodec.c
@@ -36,11 +36,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
     DVAudioContext *s = avctx->priv_data;
     int i;
 
-    if (avctx->channels != 2) {
-        av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
-        return AVERROR(EINVAL);
-    }
-
     if (avctx->codec_tag == 0x0215) {
         s->block_size = 7200;
     } else if (avctx->codec_tag == 0x0216) {
@@ -55,7 +50,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
     s->is_pal = s->block_size == 8640;
     s->is_12bit = avctx->bits_per_coded_sample == 12;
     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
-    avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 
     for (i = 0; i < FF_ARRAY_ELEMS(s->shuffle); i++) {
         const unsigned a = s->is_pal ? 18 : 15;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 208/281] evrc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (208 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 207/281] dvaudio: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 209/281] fastaudio: " James Almer
                   ` (72 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evrcdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/evrcdec.c b/libavcodec/evrcdec.c
index 59fcb14c52..a17f3bc2be 100644
--- a/libavcodec/evrcdec.c
+++ b/libavcodec/evrcdec.c
@@ -235,8 +235,8 @@ static av_cold int evrc_decode_init(AVCodecContext *avctx)
     int i, n, idx = 0;
     float denom = 2.0 / (2.0 * 8.0 + 1.0);
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_FLT;
 
     for (i = 0; i < FILTER_ORDER; i++) {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 209/281] fastaudio: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (209 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 208/281] evrc: " James Almer
@ 2022-01-13  2:02 ` James Almer
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 210/281] ffwavesynth: " James Almer
                   ` (71 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:02 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/fastaudio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/fastaudio.c b/libavcodec/fastaudio.c
index a07c5e60a7..7a8ff7dec3 100644
--- a/libavcodec/fastaudio.c
+++ b/libavcodec/fastaudio.c
@@ -78,7 +78,7 @@ static av_cold int fastaudio_init(AVCodecContext *avctx)
     for (int i = 0; i < 8; i++)
         s->table[7][i] = i * 0.34f / 3.f - 0.2f;
 
-    s->ch = av_calloc(avctx->channels, sizeof(*s->ch));
+    s->ch = av_calloc(avctx->ch_layout.nb_channels, sizeof(*s->ch));
     if (!s->ch)
         return AVERROR(ENOMEM);
 
@@ -113,7 +113,7 @@ static int fastaudio_decode(AVCodecContext *avctx, void *data,
     int subframes;
     int ret;
 
-    subframes = pkt->size / (40 * avctx->channels);
+    subframes = pkt->size / (40 * avctx->ch_layout.nb_channels);
     frame->nb_samples = subframes * 256;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
@@ -121,7 +121,7 @@ static int fastaudio_decode(AVCodecContext *avctx, void *data,
     bytestream2_init(&gb, pkt->data, pkt->size);
 
     for (int subframe = 0; subframe < subframes; subframe++) {
-        for (int channel = 0; channel < avctx->channels; channel++) {
+        for (int channel = 0; channel < avctx->ch_layout.nb_channels; channel++) {
             ChannelItems *ch = &s->ch[channel];
             float result[256] = { 0 };
             unsigned src[10];
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 210/281] ffwavesynth: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (210 preceding siblings ...)
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 209/281] fastaudio: " James Almer
@ 2022-01-13  2:04 ` James Almer
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 211/281] flac: " James Almer
                   ` (70 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:04 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/ffwavesynth.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ffwavesynth.c b/libavcodec/ffwavesynth.c
index a1211facb9..229a89663d 100644
--- a/libavcodec/ffwavesynth.c
+++ b/libavcodec/ffwavesynth.c
@@ -314,7 +314,7 @@ static av_cold int wavesynth_init(AVCodecContext *avc)
     struct wavesynth_context *ws = avc->priv_data;
     int i, r;
 
-    if (avc->channels > WS_MAX_CHANNELS) {
+    if (avc->ch_layout.nb_channels > WS_MAX_CHANNELS) {
         av_log(avc, AV_LOG_ERROR,
                "This implementation is limited to %d channels.\n",
                WS_MAX_CHANNELS);
@@ -438,11 +438,11 @@ static int wavesynth_decode(AVCodecContext *avc, void *rframe, int *rgot_frame,
         return r;
     pcm = (int16_t *)frame->data[0];
     for (s = 0; s < duration; s++, ts+=(uint64_t)1) {
-        memset(channels, 0, avc->channels * sizeof(*channels));
+        memset(channels, 0, avc->ch_layout.nb_channels * sizeof(*channels));
         if (ts >= ws->next_ts)
             wavesynth_enter_intervals(ws, ts);
         wavesynth_synth_sample(ws, ts, channels);
-        for (c = 0; c < avc->channels; c++)
+        for (c = 0; c < avc->ch_layout.nb_channels; c++)
             *(pcm++) = channels[c] >> 16;
     }
     ws->cur_ts += (uint64_t)duration;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 211/281] flac: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (211 preceding siblings ...)
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 210/281] ffwavesynth: " James Almer
@ 2022-01-13  2:04 ` James Almer
  2022-02-23 10:24   ` Anton Khirnov
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 212/281] g722: " James Almer
                   ` (69 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  2:04 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/flac.c        | 39 +++++++++++++++++++++------------------
 libavcodec/flac.h        |  2 +-
 libavcodec/flac_parser.c |  7 ++-----
 libavcodec/flacdec.c     |  9 ++++-----
 libavcodec/flacenc.c     | 26 +++++++++++++-------------
 5 files changed, 41 insertions(+), 42 deletions(-)

diff --git a/libavcodec/flac.c b/libavcodec/flac.c
index 7b075d4bd3..51014faea1 100644
--- a/libavcodec/flac.c
+++ b/libavcodec/flac.c
@@ -29,15 +29,15 @@
 
 static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 };
 
-static const uint64_t flac_channel_layouts[8] = {
-    AV_CH_LAYOUT_MONO,
-    AV_CH_LAYOUT_STEREO,
-    AV_CH_LAYOUT_SURROUND,
-    AV_CH_LAYOUT_QUAD,
-    AV_CH_LAYOUT_5POINT0,
-    AV_CH_LAYOUT_5POINT1,
-    AV_CH_LAYOUT_6POINT1,
-    AV_CH_LAYOUT_7POINT1
+static const AVChannelLayout flac_channel_layouts[8] = {
+    AV_CHANNEL_LAYOUT_MONO,
+    AV_CHANNEL_LAYOUT_STEREO,
+    AV_CHANNEL_LAYOUT_SURROUND,
+    AV_CHANNEL_LAYOUT_QUAD,
+    AV_CHANNEL_LAYOUT_5POINT0,
+    AV_CHANNEL_LAYOUT_5POINT1,
+    AV_CHANNEL_LAYOUT_6POINT1,
+    AV_CHANNEL_LAYOUT_7POINT1
 };
 
 static int64_t get_utf8(GetBitContext *gb)
@@ -193,12 +193,19 @@ int ff_flac_is_extradata_valid(AVCodecContext *avctx,
     return 1;
 }
 
-void ff_flac_set_channel_layout(AVCodecContext *avctx)
+void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels)
 {
-    if (avctx->channels <= FF_ARRAY_ELEMS(flac_channel_layouts))
-        avctx->channel_layout = flac_channel_layouts[avctx->channels - 1];
+    if (channels == avctx->ch_layout.nb_channels &&
+        avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
+        avctx->ch_layout.u.mask)
+        return;
+
+    av_channel_layout_uninit(&avctx->ch_layout);
+    if (channels <= FF_ARRAY_ELEMS(flac_channel_layouts))
+        avctx->ch_layout = flac_channel_layouts[channels - 1];
     else
-        avctx->channel_layout = 0;
+        avctx->ch_layout = (AVChannelLayout){ .order = AV_CHANNEL_ORDER_UNSPEC,
+                                              .nb_channels = channels };
 }
 
 int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
@@ -229,13 +236,9 @@ int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
         return AVERROR_INVALIDDATA;
     }
 
-    avctx->channels = s->channels;
     avctx->sample_rate = s->samplerate;
     avctx->bits_per_raw_sample = s->bps;
-
-    if (!avctx->channel_layout ||
-        av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels)
-        ff_flac_set_channel_layout(avctx);
+    ff_flac_set_channel_layout(avctx, s->channels);
 
     s->samples = get_bits64(&gb, 36);
 
diff --git a/libavcodec/flac.h b/libavcodec/flac.h
index 991ab43f3c..cb220ab4c0 100644
--- a/libavcodec/flac.h
+++ b/libavcodec/flac.h
@@ -131,7 +131,7 @@ int ff_flac_get_max_frame_size(int blocksize, int ch, int bps);
 int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
                                 FLACFrameInfo *fi, int log_level_offset);
 
-void ff_flac_set_channel_layout(AVCodecContext *avctx);
+void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels);
 
 /**
  * Parse the metadata block parameters from the header.
diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c
index cd9a2cb574..81b6f12ab3 100644
--- a/libavcodec/flac_parser.c
+++ b/libavcodec/flac_parser.c
@@ -628,11 +628,8 @@ static int get_best_header(FLACParseContext *fpc, const uint8_t **poutbuf,
         check_header_mismatch(fpc, header, child, 0);
     }
 
-    if (header->fi.channels != fpc->avctx->channels ||
-        !fpc->avctx->channel_layout) {
-        fpc->avctx->channels = header->fi.channels;
-        ff_flac_set_channel_layout(fpc->avctx);
-    }
+    ff_flac_set_channel_layout(fpc->avctx, header->fi.channels);
+
     fpc->avctx->sample_rate = header->fi.samplerate;
     fpc->pc->duration       = header->fi.blocksize;
     *poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size,
diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
index 09051cc663..eaa2dc6cf1 100644
--- a/libavcodec/flacdec.c
+++ b/libavcodec/flacdec.c
@@ -483,15 +483,14 @@ static int decode_frame(FLACContext *s)
     if (   s->flac_stream_info.channels
         && fi.channels != s->flac_stream_info.channels
         && s->got_streaminfo) {
-        s->flac_stream_info.channels = s->avctx->channels = fi.channels;
-        ff_flac_set_channel_layout(s->avctx);
+        s->flac_stream_info.channels = fi.channels;
+        ff_flac_set_channel_layout(s->avctx, fi.channels);
         ret = allocate_buffers(s);
         if (ret < 0)
             return ret;
     }
-    s->flac_stream_info.channels = s->avctx->channels = fi.channels;
-    if (!s->avctx->channel_layout)
-        ff_flac_set_channel_layout(s->avctx);
+    s->flac_stream_info.channels = fi.channels;
+    ff_flac_set_channel_layout(s->avctx, fi.channels);
     s->ch_mode = fi.ch_mode;
 
     if (!s->flac_stream_info.bps && !fi.bps) {
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index 9f6f449323..0912ca2f47 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -241,7 +241,7 @@ static av_cold void dprint_compression_options(FlacEncodeContext *s)
 static av_cold int flac_encode_init(AVCodecContext *avctx)
 {
     int freq = avctx->sample_rate;
-    int channels = avctx->channels;
+    int channels = avctx->ch_layout.nb_channels;
     FlacEncodeContext *s = avctx->priv_data;
     int i, level, ret;
     uint8_t *streaminfo;
@@ -398,18 +398,18 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
     s->frame_count   = 0;
     s->min_framesize = s->max_framesize;
 
-    if (channels == 3 &&
-            avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ||
-        channels == 4 &&
-            avctx->channel_layout != AV_CH_LAYOUT_2_2 &&
-            avctx->channel_layout != AV_CH_LAYOUT_QUAD ||
-        channels == 5 &&
-            avctx->channel_layout != AV_CH_LAYOUT_5POINT0 &&
-            avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||
-        channels == 6 &&
-            avctx->channel_layout != AV_CH_LAYOUT_5POINT1 &&
-            avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK) {
-        if (avctx->channel_layout) {
+    if ((channels == 3 &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_SURROUND)) ||
+        (channels == 4 &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2) &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD)) ||
+        (channels == 5 &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0) &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0_BACK)) ||
+        (channels == 6 &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1) &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK))) {
+        if (avctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
             av_log(avctx, AV_LOG_ERROR, "Channel layout not supported by Flac, "
                                              "output stream will have incorrect "
                                              "channel layout.\n");
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 212/281] g722: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (212 preceding siblings ...)
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 211/281] flac: " James Almer
@ 2022-01-13  2:04 ` James Almer
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 213/281] g723_1: " James Almer
                   ` (68 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:04 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/g722dec.c | 4 ++--
 libavcodec/g722enc.c | 5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/g722dec.c b/libavcodec/g722dec.c
index 5ca0d0e2b1..879ea296cb 100644
--- a/libavcodec/g722dec.c
+++ b/libavcodec/g722dec.c
@@ -59,8 +59,8 @@ static av_cold int g722_decode_init(AVCodecContext * avctx)
 {
     G722Context *c = avctx->priv_data;
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
 
     c->band[0].scale_factor = 8;
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index 75b926ef8e..6010a6d5ae 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -381,6 +381,11 @@ const AVCodec ff_adpcm_g722_encoder = {
     .close           = g722_encode_close,
     .encode2         = g722_encode_frame,
     .sample_fmts     = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE },
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts = (const uint64_t[]){ AV_CH_LAYOUT_MONO, 0 },
+#endif
+    .ch_layouts     = (const AVChannelLayout[]){
+        AV_CHANNEL_LAYOUT_MONO, { 0 }
+    },
     .caps_internal   = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 213/281] g723_1: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (213 preceding siblings ...)
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 212/281] g722: " James Almer
@ 2022-01-13  2:04 ` James Almer
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 214/281] g726: " James Almer
                   ` (67 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:04 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/g723_1_parser.c |  2 +-
 libavcodec/g723_1dec.c     | 19 ++++++++++---------
 libavcodec/g723_1enc.c     |  8 +++-----
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/libavcodec/g723_1_parser.c b/libavcodec/g723_1_parser.c
index b6b3fcb84b..2ed1a8ab19 100644
--- a/libavcodec/g723_1_parser.c
+++ b/libavcodec/g723_1_parser.c
@@ -37,7 +37,7 @@ static int g723_1_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
     int next = END_NOT_FOUND;
 
     if (buf_size > 0)
-        next = frame_size[buf[0] & 3] * FFMAX(1, avctx->channels);
+        next = frame_size[buf[0] & 3] * FFMAX(1, avctx->ch_layout.nb_channels);
 
     if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) {
         *poutbuf      = NULL;
diff --git a/libavcodec/g723_1dec.c b/libavcodec/g723_1dec.c
index 7d75adbd7a..8f381b1331 100644
--- a/libavcodec/g723_1dec.c
+++ b/libavcodec/g723_1dec.c
@@ -117,12 +117,12 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx)
     G723_1_Context *s = avctx->priv_data;
 
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16P;
-    if (avctx->channels < 1 || avctx->channels > 2) {
-        av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n", avctx->channels);
+    if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) {
+        av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n",
+               avctx->ch_layout.nb_channels);
         return AVERROR(EINVAL);
     }
-    avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
-    for (int ch = 0; ch < avctx->channels; ch++) {
+    for (int ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
         G723_1_ChannelContext *p = &s->ch[ch];
 
         p->pf_gain = 1 << 12;
@@ -932,6 +932,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
     int dec_mode       = buf[0] & 3;
+    int channels       = avctx->ch_layout.nb_channels;
 
     PPFParam ppf[SUBFRAMES];
     int16_t cur_lsp[LPC_ORDER];
@@ -940,7 +941,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
     int16_t *out;
     int bad_frame = 0, i, j, ret;
 
-    if (buf_size < frame_size[dec_mode] * avctx->channels) {
+    if (buf_size < frame_size[dec_mode] * channels) {
         if (buf_size)
             av_log(avctx, AV_LOG_WARNING,
                    "Expected %d bytes, got %d - skipping packet\n",
@@ -953,12 +954,12 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
-    for (int ch = 0; ch < avctx->channels; ch++) {
+    for (int ch = 0; ch < channels; ch++) {
         G723_1_ChannelContext *p = &s->ch[ch];
         int16_t *audio = p->audio;
 
-        if (unpack_bitstream(p, buf + ch * (buf_size / avctx->channels),
-                             buf_size / avctx->channels) < 0) {
+        if (unpack_bitstream(p, buf + ch * (buf_size / channels),
+                             buf_size / channels) < 0) {
             bad_frame = 1;
             if (p->past_frame_type == ACTIVE_FRAME)
                 p->cur_frame_type = ACTIVE_FRAME;
@@ -1090,7 +1091,7 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
 
     *got_frame_ptr = 1;
 
-    return frame_size[dec_mode] * avctx->channels;
+    return frame_size[dec_mode] * channels;
 }
 
 #define OFFSET(x) offsetof(G723_1_Context, x)
diff --git a/libavcodec/g723_1enc.c b/libavcodec/g723_1enc.c
index 2a8149b4cd..7e893fafc7 100644
--- a/libavcodec/g723_1enc.c
+++ b/libavcodec/g723_1enc.c
@@ -99,11 +99,6 @@ static av_cold int g723_1_encode_init(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
-    if (avctx->channels != 1) {
-        av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
-        return AVERROR(EINVAL);
-    }
-
     if (avctx->bit_rate == 6300) {
         p->cur_rate = RATE_6300;
     } else if (avctx->bit_rate == 5300) {
@@ -1256,5 +1251,8 @@ const AVCodec ff_g723_1_encoder = {
     .sample_fmts    = (const enum AVSampleFormat[]) {
         AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
     },
+    .ch_layouts     = (const AVChannelLayout[]){
+        AV_CHANNEL_LAYOUT_MONO, { 0 }
+    },
     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 214/281] g726: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (214 preceding siblings ...)
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 213/281] g723_1: " James Almer
@ 2022-01-13  2:04 ` James Almer
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 215/281] g729: " James Almer
                   ` (66 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:04 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/g726.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index 2a0148c1d5..082f9b07ad 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -324,7 +324,7 @@ static av_cold int g726_encode_init(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
-    if(avctx->channels != 1){
+    if (avctx->ch_layout.nb_channels != 1) {
         av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n");
         return AVERROR(EINVAL);
     }
@@ -436,12 +436,12 @@ static av_cold int g726_decode_init(AVCodecContext *avctx)
 {
     G726Context* c = avctx->priv_data;
 
-    if(avctx->channels > 1){
+    if (avctx->ch_layout.nb_channels > 1){
         avpriv_request_sample(avctx, "Decoding more than one channel");
         return AVERROR_PATCHWELCOME;
     }
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     c->little_endian = !strcmp(avctx->codec->name, "g726le");
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 215/281] g729: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (215 preceding siblings ...)
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 214/281] g726: " James Almer
@ 2022-01-13  2:04 ` James Almer
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 216/281] gsmdec: " James Almer
                   ` (65 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:04 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/g729_parser.c |  2 +-
 libavcodec/g729dec.c     | 20 +++++++++++---------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/libavcodec/g729_parser.c b/libavcodec/g729_parser.c
index 8c06ce4ee6..d66df141f9 100644
--- a/libavcodec/g729_parser.c
+++ b/libavcodec/g729_parser.c
@@ -48,7 +48,7 @@ static int g729_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
         s->block_size = (avctx->bit_rate < 8000) ? G729D_6K4_BLOCK_SIZE : G729_8K_BLOCK_SIZE;
         if (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)
             s->block_size++;
-        s->block_size *= avctx->channels;
+        s->block_size *= avctx->ch_layout.nb_channels;
         s->duration   = avctx->frame_size;
     }
 
diff --git a/libavcodec/g729dec.c b/libavcodec/g729dec.c
index 7525ab7491..5a90f9fc1c 100644
--- a/libavcodec/g729dec.c
+++ b/libavcodec/g729dec.c
@@ -350,10 +350,11 @@ static av_cold int decoder_init(AVCodecContext * avctx)
 {
     G729Context *s = avctx->priv_data;
     G729ChannelContext *ctx;
+    int channels = avctx->ch_layout.nb_channels;
     int c,i,k;
 
-    if (avctx->channels < 1 || avctx->channels > 2) {
-        av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n", avctx->channels);
+    if (channels < 1 || channels > 2) {
+        av_log(avctx, AV_LOG_ERROR, "Only mono and stereo are supported (requested channels: %d).\n", channels);
         return AVERROR(EINVAL);
     }
     avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
@@ -362,11 +363,11 @@ static av_cold int decoder_init(AVCodecContext * avctx)
     avctx->frame_size = SUBFRAME_SIZE << 1;
 
     ctx =
-    s->channel_context = av_mallocz(sizeof(G729ChannelContext) * avctx->channels);
+    s->channel_context = av_mallocz(sizeof(G729ChannelContext) * channels);
     if (!ctx)
         return AVERROR(ENOMEM);
 
-    for (c = 0; c < avctx->channels; c++) {
+    for (c = 0; c < channels; c++) {
         ctx->gain_coeff = 16384; // 1.0 in (1.14)
 
         for (k = 0; k < MA_NP + 1; k++) {
@@ -412,6 +413,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
     G729Formats packet_type;
     G729Context *s = avctx->priv_data;
     G729ChannelContext *ctx = s->channel_context;
+    int channels = avctx->ch_layout.nb_channels;
     int16_t lp[2][11];           // (3.12)
     uint8_t ma_predictor;     ///< switched MA predictor of LSP quantizer
     uint8_t quantizer_1st;    ///< first stage vector of quantizer
@@ -430,14 +432,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
-    if (buf_size && buf_size % ((G729_8K_BLOCK_SIZE + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * avctx->channels) == 0) {
+    if (buf_size && buf_size % ((G729_8K_BLOCK_SIZE + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * channels) == 0) {
         packet_type = FORMAT_G729_8K;
         format = &format_g729_8k;
         //Reset voice decision
         ctx->onset = 0;
         ctx->voice_decision = DECISION_VOICE;
         av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729 @ 8kbit/s");
-    } else if (buf_size == G729D_6K4_BLOCK_SIZE * avctx->channels && avctx->codec_id != AV_CODEC_ID_ACELP_KELVIN) {
+    } else if (buf_size == G729D_6K4_BLOCK_SIZE * channels && avctx->codec_id != AV_CODEC_ID_ACELP_KELVIN) {
         packet_type = FORMAT_G729D_6K4;
         format = &format_g729d_6k4;
         av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729D @ 6.4kbit/s");
@@ -446,13 +448,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
         return AVERROR_INVALIDDATA;
     }
 
-    for (c = 0; c < avctx->channels; c++) {
+    for (c = 0; c < channels; c++) {
         int frame_erasure = 0; ///< frame erasure detected during decoding
         int bad_pitch = 0;     ///< parity check failed
         int is_periodic = 0;   ///< whether one of the subframes is declared as periodic or not
         out_frame = (int16_t*)frame->data[c];
         if (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN) {
-            if (*buf != ((avctx->channels - 1 - c) * 0x80 | 2))
+            if (*buf != ((avctx->ch_layout.nb_channels - 1 - c) * 0x80 | 2))
                 avpriv_request_sample(avctx, "First byte value %x for channel %d", *buf, c);
             buf++;
         }
@@ -739,7 +741,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
     }
 
     *got_frame_ptr = 1;
-    return (format->block_size + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * avctx->channels;
+    return (format->block_size + (avctx->codec_id == AV_CODEC_ID_ACELP_KELVIN)) * channels;
 }
 
 static av_cold int decode_close(AVCodecContext *avctx)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 216/281] gsmdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (216 preceding siblings ...)
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 215/281] g729: " James Almer
@ 2022-01-13  2:04 ` James Almer
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 217/281] hca: " James Almer
                   ` (64 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:04 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/gsmdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/gsmdec.c b/libavcodec/gsmdec.c
index c169112311..e3c87af513 100644
--- a/libavcodec/gsmdec.c
+++ b/libavcodec/gsmdec.c
@@ -34,8 +34,8 @@
 
 static av_cold int gsm_init(AVCodecContext *avctx)
 {
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     if (!avctx->sample_rate)
         avctx->sample_rate = 8000;
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 217/281] hca: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (217 preceding siblings ...)
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 216/281] gsmdec: " James Almer
@ 2022-01-13  2:04 ` James Almer
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 218/281] hcom: " James Almer
                   ` (63 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:04 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/hcadec.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hcadec.c b/libavcodec/hcadec.c
index c98f8eb379..9757fcc74b 100644
--- a/libavcodec/hcadec.c
+++ b/libavcodec/hcadec.c
@@ -114,7 +114,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
     c->crc_table = av_crc_get_table(AV_CRC_16_ANSI);
 
-    if (avctx->channels <= 0 || avctx->channels > 16)
+    if (avctx->ch_layout.nb_channels <= 0 || avctx->ch_layout.nb_channels > 16)
         return AVERROR(EINVAL);
 
     ret = init_get_bits8(gb, avctx->extradata, avctx->extradata_size);
@@ -194,7 +194,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     if (!c->track_count)
         c->track_count = 1;
 
-    b = avctx->channels / c->track_count;
+    b = avctx->ch_layout.nb_channels / c->track_count;
     if (c->stereo_band_count && b > 1) {
         int8_t *x = r;
 
@@ -239,7 +239,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     if (c->base_band_count + c->stereo_band_count + (unsigned long)c->hfr_group_count > 128ULL)
         return AVERROR_INVALIDDATA;
 
-    for (int i = 0; i < avctx->channels; i++) {
+    for (int i = 0; i < avctx->ch_layout.nb_channels; i++) {
         c->ch[i].chan_type = r[i];
         c->ch[i].count     = c->base_band_count + ((r[i] != 2) ? c->stereo_band_count : 0);
         c->ch[i].hfr_scale = &c->ch[i].scale_factors[c->base_band_count + c->stereo_band_count];
@@ -413,20 +413,20 @@ static int decode_frame(AVCodecContext *avctx, void *data,
 
     packed_noise_level = (get_bits(gb, 9) << 8) - get_bits(gb, 7);
 
-    for (ch = 0; ch < avctx->channels; ch++)
+    for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
         unpack(c, &c->ch[ch], c->hfr_group_count, packed_noise_level, c->ath);
 
     for (int i = 0; i < 8; i++) {
-        for (ch = 0; ch < avctx->channels; ch++)
+        for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
             dequantize_coefficients(c, &c->ch[ch]);
-        for (ch = 0; ch < avctx->channels; ch++)
+        for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
             reconstruct_hfr(c, &c->ch[ch], c->hfr_group_count, c->bands_per_hfr_group,
                             c->stereo_band_count + c->base_band_count, c->total_band_count);
-        for (ch = 0; ch < avctx->channels - 1; ch++)
+        for (ch = 0; ch < avctx->ch_layout.nb_channels - 1; ch++)
             apply_intensity_stereo(c, &c->ch[ch], &c->ch[ch+1], i,
                                    c->total_band_count - c->base_band_count,
                                    c->base_band_count, c->stereo_band_count);
-        for (ch = 0; ch < avctx->channels; ch++)
+        for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
             run_imdct(c, &c->ch[ch], i, samples[ch] + i * 128);
     }
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 218/281] hcom: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (218 preceding siblings ...)
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 217/281] hca: " James Almer
@ 2022-01-13  2:04 ` James Almer
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 219/281] ilbc: " James Almer
                   ` (62 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:04 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/hcom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/hcom.c b/libavcodec/hcom.c
index 3030e37d46..d30d6402d1 100644
--- a/libavcodec/hcom.c
+++ b/libavcodec/hcom.c
@@ -44,7 +44,7 @@ static av_cold int hcom_init(AVCodecContext *avctx)
 {
     HCOMContext *s = avctx->priv_data;
 
-    if (avctx->channels != 1) {
+    if (avctx->ch_layout.nb_channels != 1) {
         av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
         return AVERROR_INVALIDDATA;
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 219/281] ilbc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (219 preceding siblings ...)
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 218/281] hcom: " James Almer
@ 2022-01-13  2:04 ` James Almer
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 220/281] imc: " James Almer
                   ` (61 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:04 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/ilbcdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ilbcdec.c b/libavcodec/ilbcdec.c
index 4d0465087f..27423d12f8 100644
--- a/libavcodec/ilbcdec.c
+++ b/libavcodec/ilbcdec.c
@@ -1456,8 +1456,8 @@ static av_cold int ilbc_decode_init(AVCodecContext *avctx)
     else
         return AVERROR_INVALIDDATA;
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_rate    = 8000;
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 220/281] imc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (220 preceding siblings ...)
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 219/281] ilbc: " James Almer
@ 2022-01-13  2:04 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 221/281] interplayacm: " James Almer
                   ` (60 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:04 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/imc.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index 116c273ba0..89b2ac33e6 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -206,15 +206,17 @@ static av_cold int imc_decode_init(AVCodecContext *avctx)
         return AVERROR_PATCHWELCOME;
     }
 
-    if (avctx->codec_id == AV_CODEC_ID_IMC)
-        avctx->channels = 1;
+    if (avctx->codec_id == AV_CODEC_ID_IMC) {
+        av_channel_layout_uninit(&avctx->ch_layout);
+        avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+    }
 
-    if (avctx->channels > 2) {
+    if (avctx->ch_layout.nb_channels > 2) {
         avpriv_request_sample(avctx, "Number of channels > 2");
         return AVERROR_PATCHWELCOME;
     }
 
-    for (j = 0; j < avctx->channels; j++) {
+    for (j = 0; j < avctx->ch_layout.nb_channels; j++) {
         q->chctx[j].decoder_reset = 1;
 
         for (i = 0; i < BANDS; i++)
@@ -270,8 +272,6 @@ static av_cold int imc_decode_init(AVCodecContext *avctx)
     ff_bswapdsp_init(&q->bdsp);
 
     avctx->sample_fmt     = AV_SAMPLE_FMT_FLTP;
-    avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
-                                                 : AV_CH_LAYOUT_STEREO;
 
     ff_thread_once(&init_static_once, imc_init_static);
 
@@ -1013,7 +1013,7 @@ static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
 
     memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags));
 
-    imc_imdct256(q, chctx, avctx->channels);
+    imc_imdct256(q, chctx, avctx->ch_layout.nb_channels);
 
     return 0;
 }
@@ -1032,7 +1032,7 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data,
 
     q->avctx = avctx;
 
-    if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
+    if (buf_size < IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels) {
         av_log(avctx, AV_LOG_ERROR, "frame too small!\n");
         return AVERROR_INVALIDDATA;
     }
@@ -1042,7 +1042,7 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data,
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
-    for (i = 0; i < avctx->channels; i++) {
+    for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
         q->out_samples = (float *)frame->extended_data[i];
 
         q->bdsp.bswap16_buf(buf16, (const uint16_t *) buf, IMC_BLOCK_SIZE / 2);
@@ -1055,14 +1055,14 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data,
             return ret;
     }
 
-    if (avctx->channels == 2) {
+    if (avctx->ch_layout.nb_channels == 2) {
         q->butterflies_float((float *)frame->extended_data[0],
                              (float *)frame->extended_data[1], COEFFS);
     }
 
     *got_frame_ptr = 1;
 
-    return IMC_BLOCK_SIZE * avctx->channels;
+    return IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels;
 }
 
 static av_cold int imc_decode_close(AVCodecContext * avctx)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 221/281] interplayacm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (221 preceding siblings ...)
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 220/281] imc: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 222/281] libcelt: " James Almer
                   ` (59 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/interplayacm.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/interplayacm.c b/libavcodec/interplayacm.c
index c11178a9ee..7b4e539239 100644
--- a/libavcodec/interplayacm.c
+++ b/libavcodec/interplayacm.c
@@ -79,12 +79,12 @@ static av_cold int decode_init(AVCodecContext *avctx)
     if (avctx->extradata_size < 14)
         return AVERROR_INVALIDDATA;
 
-    if (avctx->channels <= 0) {
-        av_log(avctx, AV_LOG_ERROR, "Invalid number of channels: %d\n", avctx->channels);
+    if (avctx->ch_layout.nb_channels <= 0) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid number of channels: %d\n", avctx->ch_layout.nb_channels);
         return AVERROR_INVALIDDATA;
     }
 
-    s->max_samples = AV_RL32(avctx->extradata + 4) / avctx->channels;
+    s->max_samples = AV_RL32(avctx->extradata + 4) / avctx->ch_layout.nb_channels;
     if (s->max_samples == 0)
         s->max_samples = UINT64_MAX;
     s->level = AV_RL16(avctx->extradata + 12) & 0xf;
@@ -585,7 +585,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
     if ((ret = init_get_bits8(gb, buf, buf_size)) < 0)
         return ret;
 
-    frame->nb_samples = FFMIN(s->block_len / avctx->channels, s->max_samples);
+    frame->nb_samples = FFMIN(s->block_len / avctx->ch_layout.nb_channels, s->max_samples);
     s->max_samples -= FFMIN(frame->nb_samples, s->max_samples);
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
@@ -596,7 +596,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
         return ret;
 
     samples = (int16_t *)frame->data[0];
-    for (n = 0; n < frame->nb_samples * avctx->channels; n++) {
+    for (n = 0; n < frame->nb_samples * avctx->ch_layout.nb_channels; n++) {
         int val = s->block[n] >> s->level;
         *samples++ = val;
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 222/281] libcelt: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (222 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 221/281] interplayacm: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 223/281] libcodec2: " James Almer
                   ` (58 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libcelt_dec.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/libcelt_dec.c b/libavcodec/libcelt_dec.c
index c0fb4013c9..6ee6e29443 100644
--- a/libavcodec/libcelt_dec.c
+++ b/libavcodec/libcelt_dec.c
@@ -61,13 +61,13 @@ static av_cold int libcelt_dec_init(AVCodecContext *c)
     struct libcelt_context *celt = c->priv_data;
     int err;
 
-    if (!c->channels || !c->frame_size ||
-        c->frame_size > INT_MAX / sizeof(int16_t) / c->channels)
+    if (!c->ch_layout.nb_channels || !c->frame_size ||
+        c->frame_size > INT_MAX / sizeof(int16_t) / c->ch_layout.nb_channels)
         return AVERROR(EINVAL);
     celt->mode = celt_mode_create(c->sample_rate, c->frame_size, &err);
     if (!celt->mode)
         return ff_celt_error_to_averror(err);
-    celt->dec = celt_decoder_create_custom(celt->mode, c->channels, &err);
+    celt->dec = celt_decoder_create_custom(celt->mode, c->ch_layout.nb_channels, &err);
     if (!celt->dec) {
         celt_mode_destroy(celt->mode);
         return ff_celt_error_to_averror(err);
@@ -119,8 +119,8 @@ static int libcelt_dec_decode(AVCodecContext *c, void *data,
         return ff_celt_error_to_averror(err);
     if (celt->discard) {
         frame->nb_samples -= celt->discard;
-        memmove(pcm, pcm + celt->discard * c->channels,
-                frame->nb_samples * c->channels * sizeof(int16_t));
+        memmove(pcm, pcm + celt->discard * c->ch_layout.nb_channels,
+                frame->nb_samples * c->ch_layout.nb_channels * sizeof(int16_t));
         celt->discard = 0;
     }
     *got_frame_ptr = 1;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 223/281] libcodec2: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (223 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 222/281] libcelt: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 224/281] libfdk-aac: " James Almer
                   ` (57 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libcodec2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/libcodec2.c b/libavcodec/libcodec2.c
index eb66867f82..da9e170d21 100644
--- a/libavcodec/libcodec2.c
+++ b/libavcodec/libcodec2.c
@@ -85,9 +85,9 @@ libcodec2_init_common_error:
 static av_cold int libcodec2_init_decoder(AVCodecContext *avctx)
 {
     avctx->sample_rate      = 8000;
-    avctx->channels         = 1;
     avctx->sample_fmt       = AV_SAMPLE_FMT_S16;
-    avctx->channel_layout   = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     if (avctx->extradata_size != CODEC2_EXTRADATA_SIZE) {
         av_log(avctx, AV_LOG_ERROR, "must have exactly %i bytes of extradata (got %i)\n",
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 224/281] libfdk-aac: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (224 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 223/281] libcodec2: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-02-25 11:18   ` Anton Khirnov
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 225/281] libilbc: " James Almer
                   ` (56 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libfdk-aacdec.c | 32 ++++++++++++++++++++------------
 libavcodec/libfdk-aacenc.c | 35 +++++++++++++++++++++++++++--------
 2 files changed, 47 insertions(+), 20 deletions(-)

diff --git a/libavcodec/libfdk-aacdec.c b/libavcodec/libfdk-aacdec.c
index ffa1fdcce3..1a38aefff9 100644
--- a/libavcodec/libfdk-aacdec.c
+++ b/libavcodec/libfdk-aacdec.c
@@ -58,6 +58,7 @@ typedef struct FDKAACDecContext {
     int drc_cut;
     int level_limit;
     int output_delay;
+    AVChannelLayout downmix_layout;
 } FDKAACDecContext;
 
 
@@ -88,6 +89,7 @@ static const AVOption fdk_aac_dec_options[] = {
     { "drc_effect","Dynamic Range Control: effect type, where e.g. [0] is none and [6] is general",
                      OFFSET(drc_effect),     AV_OPT_TYPE_INT,   { .i64 = -1},  -1, 8,   AD, NULL    },
 #endif
+    { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = AD },
     { NULL }
 };
 
@@ -197,17 +199,15 @@ static int get_stream_info(AVCodecContext *avctx)
             ch_error = 1;
         }
     }
-    if (!ch_error &&
-        av_get_channel_layout_nb_channels(ch_layout) != info->numChannels) {
+
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_from_mask(&avctx->ch_layout, ch_layout);
+    if (!ch_error && avctx->ch_layout.nb_channels != info->numChannels) {
         av_log(avctx, AV_LOG_WARNING, "unsupported channel configuration\n");
         ch_error = 1;
     }
     if (ch_error)
-        avctx->channel_layout = 0;
-    else
-        avctx->channel_layout = ch_layout;
-
-    avctx->channels = info->numChannels;
+        avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
 
     return 0;
 }
@@ -249,11 +249,19 @@ static av_cold int fdk_aac_decode_init(AVCodecContext *avctx)
         return AVERROR_UNKNOWN;
     }
 
-    if (avctx->request_channel_layout > 0 &&
-        avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (avctx->request_channel_layout) {
+        av_channel_layout_uninit(&s->downmix_layout);
+        av_channel_layout_from_mask(&s->downmix_layout, avctx->request_channel_layout);
+    }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if (s->downmix_layout.nb_channels > 0 &&
+        s->downmix_layout.order != AV_CHANNEL_ORDER_NATIVE) {
         int downmix_channels = -1;
 
-        switch (avctx->request_channel_layout) {
+        switch (s->downmix_layout.u.mask) {
         case AV_CH_LAYOUT_STEREO:
         case AV_CH_LAYOUT_STEREO_DOWNMIX:
             downmix_channels = 2;
@@ -262,7 +270,7 @@ static av_cold int fdk_aac_decode_init(AVCodecContext *avctx)
             downmix_channels = 1;
             break;
         default:
-            av_log(avctx, AV_LOG_WARNING, "Invalid request_channel_layout\n");
+            av_log(avctx, AV_LOG_WARNING, "Invalid downmix option\n");
             break;
         }
 
@@ -385,7 +393,7 @@ static int fdk_aac_decode_frame(AVCodecContext *avctx, void *data,
                                    avctx->time_base);
 
     memcpy(frame->extended_data[0], s->decoder_buffer,
-           avctx->channels * avctx->frame_size *
+           avctx->ch_layout.nb_channels * avctx->frame_size *
            av_get_bytes_per_sample(avctx->sample_fmt));
 
     *got_frame_ptr = 1;
diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index 7ee2f13ac7..d43f45d9ee 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -128,7 +128,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
     int aot = FF_PROFILE_AAC_LOW + 1;
     int sce = 0, cpe = 0;
 
-    if ((err = aacEncOpen(&s->handle, 0, avctx->channels)) != AACENC_OK) {
+    if ((err = aacEncOpen(&s->handle, 0, avctx->ch_layout.nb_channels)) != AACENC_OK) {
         av_log(avctx, AV_LOG_ERROR, "Unable to open the encoder: %s\n",
                aac_get_error(err));
         goto error;
@@ -159,7 +159,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
         goto error;
     }
 
-    switch (avctx->channels) {
+    switch (avctx->ch_layout.nb_channels) {
     case 1: mode = MODE_1;       sce = 1; cpe = 0; break;
     case 2:
 #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
@@ -193,7 +193,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
     case 8:
         sce = 2;
         cpe = 3;
-        if (avctx->channel_layout == AV_CH_LAYOUT_7POINT1) {
+        if (avctx->ch_layout.u.mask == AV_CH_LAYOUT_7POINT1) {
             mode = MODE_7_1_REAR_SURROUND;
         } else {
             // MODE_1_2_2_2_1 and MODE_7_1_FRONT_CENTER use the same channel layout
@@ -203,7 +203,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
 #endif
     default:
         av_log(avctx, AV_LOG_ERROR,
-               "Unsupported number of channels %d\n", avctx->channels);
+               "Unsupported number of channels %d\n", avctx->ch_layout.nb_channels);
         goto error;
     }
 
@@ -375,9 +375,9 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         in_args.numInSamples = -1;
     } else {
         in_ptr               = frame->data[0];
-        in_buffer_size       = 2 * avctx->channels * frame->nb_samples;
+        in_buffer_size       = 2 * avctx->ch_layout.nb_channels * frame->nb_samples;
 
-        in_args.numInSamples = avctx->channels * frame->nb_samples;
+        in_args.numInSamples = avctx->ch_layout.nb_channels * frame->nb_samples;
 
         /* add current frame to the queue */
         if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
@@ -392,7 +392,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     in_buf.bufElSizes        = &in_buffer_element_size;
 
     /* The maximum packet size is 6144 bits aka 768 bytes per channel. */
-    ret = ff_alloc_packet(avctx, avpkt, FFMAX(8192, 768 * avctx->channels));
+    ret = ff_alloc_packet(avctx, avpkt, FFMAX(8192, 768 * avctx->ch_layout.nb_channels));
     if (ret < 0)
         return ret;
 
@@ -440,6 +440,7 @@ static const AVCodecDefault aac_encode_defaults[] = {
     { NULL }
 };
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 static const uint64_t aac_channel_layout[] = {
     AV_CH_LAYOUT_MONO,
     AV_CH_LAYOUT_STEREO,
@@ -453,6 +454,21 @@ static const uint64_t aac_channel_layout[] = {
 #endif
     0,
 };
+#endif /* FF_API_OLD_CHANNEL_LAYOUT */
+
+static const AVChannelLayout aac_ch_layouts[16] = {
+    AV_CHANNEL_LAYOUT_MONO,
+    AV_CHANNEL_LAYOUT_STEREO,
+    AV_CHANNEL_LAYOUT_SURROUND,
+    AV_CHANNEL_LAYOUT_4POINT0,
+    AV_CHANNEL_LAYOUT_5POINT0_BACK,
+    AV_CHANNEL_LAYOUT_5POINT1_BACK,
+#ifdef AACENCODER_LIB_VL0
+    AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK,
+    AV_CHANNEL_LAYOUT_7POINT1,
+#endif
+    { 0 },
+};
 
 static const int aac_sample_rates[] = {
     96000, 88200, 64000, 48000, 44100, 32000,
@@ -475,6 +491,9 @@ const AVCodec ff_libfdk_aac_encoder = {
     .defaults              = aac_encode_defaults,
     .profiles              = profiles,
     .supported_samplerates = aac_sample_rates,
-    .channel_layouts       = aac_channel_layout,
     .wrapper_name          = "libfdk",
+#if FF_API_OLD_CHANNEL_LAYOUT
+    .channel_layouts       = aac_channel_layout,
+#endif
+    .ch_layouts            = aac_ch_layouts,
 };
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 225/281] libilbc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (225 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 224/281] libfdk-aac: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 226/281] libgsm: " James Almer
                   ` (55 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libilbc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libilbc.c b/libavcodec/libilbc.c
index 04192e3045..cfffe7d520 100644
--- a/libavcodec/libilbc.c
+++ b/libavcodec/libilbc.c
@@ -78,8 +78,8 @@ static av_cold int ilbc_decode_init(AVCodecContext *avctx)
 
     WebRtcIlbcfix_InitDecode(&s->decoder, mode, s->enhance);
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_rate    = 8000;
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
 
@@ -161,7 +161,7 @@ static av_cold int ilbc_encode_init(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
-    if (avctx->channels != 1) {
+    if (avctx->ch_layout.nb_channels != 1) {
         av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
         return AVERROR(EINVAL);
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 226/281] libgsm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (226 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 225/281] libilbc: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-02-25 11:20   ` Anton Khirnov
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 227/281] libmp3lame: " James Almer
                   ` (54 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libgsmdec.c | 4 ++--
 libavcodec/libgsmenc.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/libgsmdec.c b/libavcodec/libgsmdec.c
index ae4a952d99..aa028bc262 100644
--- a/libavcodec/libgsmdec.c
+++ b/libavcodec/libgsmdec.c
@@ -48,8 +48,8 @@ typedef struct LibGSMDecodeContext {
 static av_cold int libgsm_decode_init(AVCodecContext *avctx) {
     LibGSMDecodeContext *s = avctx->priv_data;
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     if (!avctx->sample_rate)
         avctx->sample_rate = 8000;
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
diff --git a/libavcodec/libgsmenc.c b/libavcodec/libgsmenc.c
index a2f6c1c62e..f73f254d50 100644
--- a/libavcodec/libgsmenc.c
+++ b/libavcodec/libgsmenc.c
@@ -49,9 +49,9 @@ static av_cold int libgsm_encode_close(AVCodecContext *avctx) {
 }
 
 static av_cold int libgsm_encode_init(AVCodecContext *avctx) {
-    if (avctx->channels > 1) {
+    if (avctx->ch_layout.nb_channels > 1) {
         av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n",
-               avctx->channels);
+               avctx->ch_layout.nb_channels);
         return -1;
     }
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 227/281] libmp3lame: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (227 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 226/281] libgsm: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 228/281] libopencore-amr: " James Almer
                   ` (53 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libmp3lame.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 5675864bb2..36ae57eb83 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -101,8 +101,9 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx)
         return AVERROR(ENOMEM);
 
 
-    lame_set_num_channels(s->gfp, avctx->channels);
-    lame_set_mode(s->gfp, avctx->channels > 1 ? s->joint_stereo ? JOINT_STEREO : STEREO : MONO);
+    lame_set_num_channels(s->gfp, avctx->ch_layout.nb_channels);
+    lame_set_mode(s->gfp, avctx->ch_layout.nb_channels > 1 ?
+                          s->joint_stereo ? JOINT_STEREO : STEREO : MONO);
 
     /* sample rate */
     lame_set_in_samplerate (s->gfp, avctx->sample_rate);
@@ -151,7 +152,7 @@ static av_cold int mp3lame_encode_init(AVCodecContext *avctx)
     /* allocate float sample buffers */
     if (avctx->sample_fmt == AV_SAMPLE_FMT_FLTP) {
         int ch;
-        for (ch = 0; ch < avctx->channels; ch++) {
+        for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
             s->samples_flt[ch] = av_malloc_array(avctx->frame_size,
                                            sizeof(*s->samples_flt[ch]));
             if (!s->samples_flt[ch]) {
@@ -208,7 +209,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
                 av_log(avctx, AV_LOG_ERROR, "inadequate AVFrame plane padding\n");
                 return AVERROR(EINVAL);
             }
-            for (ch = 0; ch < avctx->channels; ch++) {
+            for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
                 s->fdsp->vector_fmul_scalar(s->samples_flt[ch],
                                            (const float *)frame->data[ch],
                                            32768.0f,
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 228/281] libopencore-amr: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (228 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 227/281] libmp3lame: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 229/281] libopus: " James Almer
                   ` (52 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libopencore-amr.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index 2df1c5090f..aa5f0e774e 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -38,13 +38,13 @@ static int amr_decode_fix_avctx(AVCodecContext *avctx)
     if (!avctx->sample_rate)
         avctx->sample_rate = 8000 * is_amr_wb;
 
-    if (avctx->channels > 1) {
+    if (avctx->ch_layout.nb_channels > 1) {
         avpriv_report_missing_feature(avctx, "multi-channel AMR");
         return AVERROR_PATCHWELCOME;
     }
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
     return 0;
 }
@@ -201,7 +201,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
         return AVERROR(ENOSYS);
     }
 
-    if (avctx->channels != 1) {
+    if (avctx->ch_layout.nb_channels != 1) {
         av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
         return AVERROR(ENOSYS);
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 229/281] libopus: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (229 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 228/281] libopencore-amr: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-02-25 11:46   ` Anton Khirnov
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 230/281] libshine: " James Almer
                   ` (51 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libopusdec.c  | 39 +++++++++++++-----------
 libavcodec/libopusenc.c  | 65 ++++++++++++++++++++++------------------
 libavcodec/vorbis.h      |  3 ++
 libavcodec/vorbis_data.c | 18 +++++++++++
 4 files changed, 79 insertions(+), 46 deletions(-)

diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c
index 86ef715205..abffd5f463 100644
--- a/libavcodec/libopusdec.c
+++ b/libavcodec/libopusdec.c
@@ -50,55 +50,60 @@ struct libopus_context {
 static av_cold int libopus_decode_init(AVCodecContext *avc)
 {
     struct libopus_context *opus = avc->priv_data;
-    int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
+    int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled, channels;
     uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
 
-    avc->channels = avc->extradata_size >= 10 ? avc->extradata[9] : (avc->channels == 1) ? 1 : 2;
-    if (avc->channels <= 0) {
+    channels = avc->extradata_size >= 10 ? avc->extradata[9] : (channels == 1) ? 1 : 2;
+    if (channels <= 0) {
         av_log(avc, AV_LOG_WARNING,
-               "Invalid number of channels %d, defaulting to stereo\n", avc->channels);
-        avc->channels = 2;
+               "Invalid number of channels %d, defaulting to stereo\n", channels);
+        channels = 2;
     }
 
     avc->sample_rate    = 48000;
     avc->sample_fmt     = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
                           AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;
-    avc->channel_layout = avc->channels > 8 ? 0 :
-                          ff_vorbis_channel_layouts[avc->channels - 1];
+    av_channel_layout_uninit(&avc->ch_layout);
+    if (channels > 8) {
+        avc->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        avc->ch_layout.nb_channels = channels;
+    } else {
+        av_channel_layout_copy(&avc->ch_layout, &ff_vorbis_ch_layouts[channels - 1]);
+    }
 
     if (avc->extradata_size >= OPUS_HEAD_SIZE) {
         opus->pre_skip = AV_RL16(avc->extradata + 10);
         gain_db     = sign_extend(AV_RL16(avc->extradata + 16), 16);
         channel_map = AV_RL8 (avc->extradata + 18);
     }
-    if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + avc->channels) {
+    if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + channels) {
         nb_streams = avc->extradata[OPUS_HEAD_SIZE + 0];
         nb_coupled = avc->extradata[OPUS_HEAD_SIZE + 1];
-        if (nb_streams + nb_coupled != avc->channels)
+        if (nb_streams + nb_coupled != channels)
             av_log(avc, AV_LOG_WARNING, "Inconsistent channel mapping.\n");
         mapping = avc->extradata + OPUS_HEAD_SIZE + 2;
     } else {
-        if (avc->channels > 2 || channel_map) {
+        if (channels > 2 || channel_map) {
             av_log(avc, AV_LOG_ERROR,
-                   "No channel mapping for %d channels.\n", avc->channels);
+                   "No channel mapping for %d channels.\n", channels);
             return AVERROR(EINVAL);
         }
         nb_streams = 1;
-        nb_coupled = avc->channels > 1;
+        nb_coupled = channels > 1;
         mapping    = mapping_arr;
     }
 
-    if (avc->channels > 2 && avc->channels <= 8) {
-        const uint8_t *vorbis_offset = ff_vorbis_channel_layout_offsets[avc->channels - 1];
+    if (channels > 2 && channels <= 8) {
+        const uint8_t *vorbis_offset = ff_vorbis_channel_layout_offsets[channels - 1];
         int ch;
 
         /* Remap channels from Vorbis order to ffmpeg order */
-        for (ch = 0; ch < avc->channels; ch++)
+        for (ch = 0; ch < channels; ch++)
             mapping_arr[ch] = mapping[vorbis_offset[ch]];
         mapping = mapping_arr;
     }
 
-    opus->dec = opus_multistream_decoder_create(avc->sample_rate, avc->channels,
+    opus->dec = opus_multistream_decoder_create(avc->sample_rate, channels,
                                                 nb_streams, nb_coupled,
                                                 mapping, &ret);
     if (!opus->dec) {
@@ -178,7 +183,7 @@ static int libopus_decode(AVCodecContext *avc, void *data,
 
 #ifndef OPUS_SET_GAIN
     {
-        int i = avc->channels * nb_samples;
+        int i = avc->ch_layout.nb_channels * nb_samples;
         if (avc->sample_fmt == AV_SAMPLE_FMT_FLT) {
             float *pcm = (float *)frame->data[0];
             for (; i > 0; i--, pcm++)
diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index 45b23fcbb5..401a2c17c8 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -91,7 +91,7 @@ static void libopus_write_header(AVCodecContext *avctx, int stream_count,
                                  const uint8_t *channel_mapping)
 {
     uint8_t *p   = avctx->extradata;
-    int channels = avctx->channels;
+    int channels = avctx->ch_layout.nb_channels;
 
     bytestream_put_buffer(&p, "OpusHead", 8);
     bytestream_put_byte(&p, 1); /* Version */
@@ -180,9 +180,9 @@ static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc,
 
 static int libopus_check_max_channels(AVCodecContext *avctx,
                                       int max_channels) {
-    if (avctx->channels > max_channels) {
+    if (avctx->ch_layout.nb_channels > max_channels) {
         av_log(avctx, AV_LOG_ERROR, "Opus mapping family undefined for %d channels.\n",
-               avctx->channels);
+               avctx->ch_layout.nb_channels);
         return AVERROR(EINVAL);
     }
 
@@ -190,21 +190,26 @@ static int libopus_check_max_channels(AVCodecContext *avctx,
 }
 
 static int libopus_check_vorbis_layout(AVCodecContext *avctx, int mapping_family) {
-    av_assert2(avctx->channels < FF_ARRAY_ELEMS(ff_vorbis_channel_layouts));
+    av_assert2(avctx->ch_layout.nb_channels < FF_ARRAY_ELEMS(ff_vorbis_ch_layouts));
 
-    if (!avctx->channel_layout) {
+    if (avctx->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
         av_log(avctx, AV_LOG_WARNING,
                "No channel layout specified. Opus encoder will use Vorbis "
-               "channel layout for %d channels.\n", avctx->channels);
-    } else if (avctx->channel_layout != ff_vorbis_channel_layouts[avctx->channels - 1]) {
-        char name[32];
-        av_get_channel_layout_string(name, sizeof(name), avctx->channels,
-                                     avctx->channel_layout);
-        av_log(avctx, AV_LOG_ERROR,
-               "Invalid channel layout %s for specified mapping family %d.\n",
-               name, mapping_family);
+               "channel layout for %d channels.\n", avctx->ch_layout.nb_channels);
+    } else {
+        AVChannelLayout chl;
+        av_channel_layout_copy(&chl, &ff_vorbis_ch_layouts[avctx->ch_layout.nb_channels - 1]);
 
-        return AVERROR(EINVAL);
+        if (av_channel_layout_compare(&avctx->ch_layout, &chl)) {
+            char name[32];
+
+            av_channel_layout_describe(&avctx->ch_layout, name, sizeof(name));
+            av_log(avctx, AV_LOG_ERROR,
+                   "Invalid channel layout %s for specified mapping family %d.\n",
+                   name ? name : "", mapping_family);
+
+            return AVERROR(EINVAL);
+        }
     }
 
     return 0;
@@ -238,7 +243,7 @@ static int libopus_validate_layout_and_get_channel_map(
         ret = libopus_check_max_channels(avctx, 8);
         if (ret == 0) {
             ret = libopus_check_vorbis_layout(avctx, mapping_family);
-            channel_map = ff_vorbis_channel_layout_offsets[avctx->channels - 1];
+            channel_map = ff_vorbis_channel_layout_offsets[avctx->ch_layout.nb_channels - 1];
         }
         break;
     case 255:
@@ -261,6 +266,7 @@ static av_cold int libopus_encode_init(AVCodecContext *avctx)
     OpusMSEncoder *enc;
     uint8_t libopus_channel_mapping[255];
     int ret = OPUS_OK;
+    int channels = avctx->ch_layout.nb_channels;
     int av_ret;
     int coupled_stream_count, header_size, frame_size;
     int mapping_family;
@@ -348,17 +354,17 @@ static av_cold int libopus_encode_init(AVCodecContext *avctx)
          * libopus multistream API to avoid surround masking. */
 
         /* Set the mapping family so that the value is correct in the header */
-        mapping_family = avctx->channels > 2 ? 1 : 0;
-        coupled_stream_count = opus_coupled_streams[avctx->channels - 1];
-        opus->stream_count   = avctx->channels - coupled_stream_count;
+        mapping_family = channels > 2 ? 1 : 0;
+        coupled_stream_count = opus_coupled_streams[channels - 1];
+        opus->stream_count   = channels - coupled_stream_count;
         memcpy(libopus_channel_mapping,
-               opus_vorbis_channel_map[avctx->channels - 1],
-               avctx->channels * sizeof(*libopus_channel_mapping));
+               opus_vorbis_channel_map[channels - 1],
+               channels * sizeof(*libopus_channel_mapping));
 
         enc = opus_multistream_encoder_create(
-            avctx->sample_rate, avctx->channels, opus->stream_count,
+            avctx->sample_rate, channels, opus->stream_count,
             coupled_stream_count,
-            libavcodec_libopus_channel_map[avctx->channels - 1],
+            libavcodec_libopus_channel_map[channels - 1],
             opus->opts.application, &ret);
     } else {
         /* Use the newer multistream API. The encoder will set the channel
@@ -366,7 +372,7 @@ static av_cold int libopus_encode_init(AVCodecContext *avctx)
          * use surround masking analysis to save bits. */
         mapping_family = opus->opts.mapping_family;
         enc = opus_multistream_surround_encoder_create(
-            avctx->sample_rate, avctx->channels, mapping_family,
+            avctx->sample_rate, channels, mapping_family,
             &opus->stream_count, &coupled_stream_count, libopus_channel_mapping,
             opus->opts.application, &ret);
     }
@@ -385,10 +391,10 @@ static av_cold int libopus_encode_init(AVCodecContext *avctx)
                "No bit rate set. Defaulting to %"PRId64" bps.\n", avctx->bit_rate);
     }
 
-    if (avctx->bit_rate < 500 || avctx->bit_rate > 256000 * avctx->channels) {
+    if (avctx->bit_rate < 500 || avctx->bit_rate > 256000 * channels) {
         av_log(avctx, AV_LOG_ERROR, "The bit rate %"PRId64" bps is unsupported. "
                "Please choose a value between 500 and %d.\n", avctx->bit_rate,
-               256000 * avctx->channels);
+               256000 * channels);
         ret = AVERROR(EINVAL);
         goto fail;
     }
@@ -400,7 +406,7 @@ static av_cold int libopus_encode_init(AVCodecContext *avctx)
     }
 
     /* Header includes channel mapping table if and only if mapping family is NOT 0 */
-    header_size = 19 + (mapping_family == 0 ? 0 : 2 + avctx->channels);
+    header_size = 19 + (mapping_family == 0 ? 0 : 2 + channels);
     avctx->extradata = av_malloc(header_size + AV_INPUT_BUFFER_PADDING_SIZE);
     if (!avctx->extradata) {
         av_log(avctx, AV_LOG_ERROR, "Failed to allocate extradata.\n");
@@ -409,7 +415,7 @@ static av_cold int libopus_encode_init(AVCodecContext *avctx)
     }
     avctx->extradata_size = header_size;
 
-    opus->samples = av_calloc(frame_size, avctx->channels *
+    opus->samples = av_calloc(frame_size, channels *
                                av_get_bytes_per_sample(avctx->sample_fmt));
     if (!opus->samples) {
         av_log(avctx, AV_LOG_ERROR, "Failed to allocate samples buffer.\n");
@@ -456,7 +462,8 @@ static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt,
 {
     LibopusEncContext *opus = avctx->priv_data;
     const int bytes_per_sample = av_get_bytes_per_sample(avctx->sample_fmt);
-    const int sample_size      = avctx->channels * bytes_per_sample;
+    const int channels         = avctx->ch_layout.nb_channels;
+    const int sample_size      = channels * bytes_per_sample;
     uint8_t *audio;
     int ret;
     int discard_padding;
@@ -469,7 +476,7 @@ static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt,
             audio = opus->samples;
             libopus_copy_samples_with_channel_map(
                 audio, frame->data[0], opus->encoder_channel_map,
-                avctx->channels, frame->nb_samples, bytes_per_sample);
+                channels, frame->nb_samples, bytes_per_sample);
         } else if (frame->nb_samples < opus->opts.packet_size) {
             audio = opus->samples;
             memcpy(audio, frame->data[0], frame->nb_samples * sample_size);
diff --git a/libavcodec/vorbis.h b/libavcodec/vorbis.h
index 69ddbd2982..f80187feee 100644
--- a/libavcodec/vorbis.h
+++ b/libavcodec/vorbis.h
@@ -26,7 +26,10 @@
 extern const float ff_vorbis_floor1_inverse_db_table[256];
 extern const float * const ff_vorbis_vwin[8];
 extern const uint8_t ff_vorbis_channel_layout_offsets[8][8];
+#if FF_API_OLD_CHANNEL_LAYOUT
 extern const uint64_t ff_vorbis_channel_layouts[9];
+#endif
+extern const AVChannelLayout ff_vorbis_ch_layouts[9];
 
 typedef struct vorbis_floor1_entry {
     uint16_t x;
diff --git a/libavcodec/vorbis_data.c b/libavcodec/vorbis_data.c
index fd7e291de2..4f4ea03f15 100644
--- a/libavcodec/vorbis_data.c
+++ b/libavcodec/vorbis_data.c
@@ -34,6 +34,7 @@ const uint8_t ff_vorbis_channel_layout_offsets[8][8] = {
     { 0, 2, 1, 7, 5, 6, 3, 4 },
 };
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 const uint64_t ff_vorbis_channel_layouts[9] = {
     AV_CH_LAYOUT_MONO,
     AV_CH_LAYOUT_STEREO,
@@ -45,6 +46,23 @@ const uint64_t ff_vorbis_channel_layouts[9] = {
     AV_CH_LAYOUT_7POINT1,
     0
 };
+#endif
+
+const AVChannelLayout ff_vorbis_ch_layouts[9] = {
+    AV_CHANNEL_LAYOUT_MONO,
+    AV_CHANNEL_LAYOUT_STEREO,
+    AV_CHANNEL_LAYOUT_SURROUND,
+    AV_CHANNEL_LAYOUT_QUAD,
+    AV_CHANNEL_LAYOUT_5POINT0_BACK,
+    AV_CHANNEL_LAYOUT_5POINT1_BACK,
+    {
+        .nb_channels = 7,
+        .order       = AV_CHANNEL_ORDER_NATIVE,
+        .u.mask      = AV_CH_LAYOUT_5POINT1 | AV_CH_BACK_CENTER,
+    },
+    AV_CHANNEL_LAYOUT_7POINT1,
+    { 0 }
+};
 
 DECLARE_ALIGNED(16, static const float, vwin64)[32] = {
     0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 230/281] libshine: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (230 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 229/281] libopus: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 231/281] libspeexdec: " James Almer
                   ` (50 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libshine.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libshine.c b/libavcodec/libshine.c
index fbc84846ae..ee8a63d66b 100644
--- a/libavcodec/libshine.c
+++ b/libavcodec/libshine.c
@@ -44,7 +44,7 @@ static av_cold int libshine_encode_init(AVCodecContext *avctx)
 {
     SHINEContext *s = avctx->priv_data;
 
-    if (avctx->channels <= 0 || avctx->channels > 2){
+    if (avctx->ch_layout.nb_channels <= 0 || avctx->ch_layout.nb_channels > 2){
         av_log(avctx, AV_LOG_ERROR, "only mono or stereo is supported\n");
         return AVERROR(EINVAL);
     }
@@ -52,9 +52,9 @@ static av_cold int libshine_encode_init(AVCodecContext *avctx)
     shine_set_config_mpeg_defaults(&s->config.mpeg);
     if (avctx->bit_rate)
         s->config.mpeg.bitr = avctx->bit_rate / 1000;
-    s->config.mpeg.mode = avctx->channels == 2 ? STEREO : MONO;
+    s->config.mpeg.mode = avctx->ch_layout.nb_channels == 2 ? STEREO : MONO;
     s->config.wave.samplerate = avctx->sample_rate;
-    s->config.wave.channels   = avctx->channels == 2 ? PCM_STEREO : PCM_MONO;
+    s->config.wave.channels   = avctx->ch_layout.nb_channels == 2 ? PCM_STEREO : PCM_MONO;
     if (shine_check_config(s->config.wave.samplerate, s->config.mpeg.bitr) < 0) {
         av_log(avctx, AV_LOG_ERROR, "invalid configuration\n");
         return AVERROR(EINVAL);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 231/281] libspeexdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (231 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 230/281] libshine: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 232/281] libtwolame: " James Almer
                   ` (49 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libspeexdec.c | 19 ++++++++++---------
 libavcodec/libspeexenc.c | 17 +++++++++--------
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c
index 6f032907fc..8029786b1f 100644
--- a/libavcodec/libspeexdec.c
+++ b/libavcodec/libspeexdec.c
@@ -42,7 +42,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
     LibSpeexContext *s = avctx->priv_data;
     const SpeexMode *mode;
     SpeexHeader *header = NULL;
-    int spx_mode;
+    int spx_mode, channels;
 
     if (avctx->extradata && avctx->extradata_size >= 80) {
         header = speex_packet_to_header(avctx->extradata,
@@ -68,7 +68,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
         spx_mode           = 0;
     } else if (header) {
         avctx->sample_rate = header->rate;
-        avctx->channels    = header->nb_channels;
+        channels           = header->nb_channels;
         spx_mode           = header->mode;
         speex_header_free(header);
     } else {
@@ -94,14 +94,15 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
     if (!avctx->sample_rate)
         avctx->sample_rate = 8000 << spx_mode;
 
-    if (avctx->channels < 1 || avctx->channels > 2) {
+    if (channels < 1 || channels > 2) {
         /* libspeex can handle mono or stereo if initialized as stereo */
         av_log(avctx, AV_LOG_ERROR, "Invalid channel count: %d.\n"
-                                    "Decoding as stereo.\n", avctx->channels);
-        avctx->channels = 2;
+                                    "Decoding as stereo.\n", channels);
+        channels = 2;
     }
-    avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
-                                                   AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = channels == 2 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO :
+                                       (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     speex_bits_init(&s->bits);
     s->dec_state = speex_decoder_init(mode);
@@ -110,7 +111,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
         return -1;
     }
 
-    if (avctx->channels == 2) {
+    if (channels == 2) {
         SpeexCallback callback;
         callback.callback_id = SPEEX_INBAND_STEREO;
         callback.func = speex_std_stereo_request_handler;
@@ -163,7 +164,7 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data,
         av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame.\n");
         return AVERROR_INVALIDDATA;
     }
-    if (avctx->channels == 2)
+    if (avctx->ch_layout.nb_channels == 2)
         speex_decode_stereo_int(output, s->frame_size, &s->stereo);
 
     *got_frame_ptr = 1;
diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index d095b41bee..058dafad39 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -28,8 +28,8 @@
  * order to control various encoding parameters.
  *
  * Channels
- *     Speex only supports mono or stereo, so avctx->channels must be set to
- *     1 or 2.
+ *     Speex only supports mono or stereo, so avctx->ch_layout.nb_channels must
+ *     be set to 1 or 2.
  *
  * Sample Rate / Encoding Mode
  *     Speex has 3 modes, each of which uses a specific sample rate.
@@ -114,7 +114,7 @@ static av_cold void print_enc_params(AVCodecContext *avctx,
 {
     const char *mode_str = "unknown";
 
-    av_log(avctx, AV_LOG_DEBUG, "channels: %d\n", avctx->channels);
+    av_log(avctx, AV_LOG_DEBUG, "channels: %d\n", avctx->ch_layout.nb_channels);
     switch (s->header.mode) {
     case SPEEX_MODEID_NB:  mode_str = "narrowband";     break;
     case SPEEX_MODEID_WB:  mode_str = "wideband";       break;
@@ -146,15 +146,16 @@ static av_cold void print_enc_params(AVCodecContext *avctx,
 static av_cold int encode_init(AVCodecContext *avctx)
 {
     LibSpeexEncContext *s = avctx->priv_data;
+    int channels = avctx->ch_layout.nb_channels;
     const SpeexMode *mode;
     uint8_t *header_data;
     int header_size;
     int32_t complexity;
 
     /* channels */
-    if (avctx->channels < 1 || avctx->channels > 2) {
+    if (channels < 1 || channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "Invalid channels (%d). Only stereo and "
-               "mono are supported\n", avctx->channels);
+               "mono are supported\n", channels);
         return AVERROR(EINVAL);
     }
 
@@ -175,7 +176,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex\n");
         return -1;
     }
-    speex_init_header(&s->header, avctx->sample_rate, avctx->channels, mode);
+    speex_init_header(&s->header, avctx->sample_rate, channels, mode);
 
     /* rate control method and parameters */
     if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
@@ -210,7 +211,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
         }
         /* stereo side information adds about 800 bps to the base bitrate */
         /* TODO: this should be calculated exactly */
-        avctx->bit_rate = s->header.bitrate + (avctx->channels == 2 ? 800 : 0);
+        avctx->bit_rate = s->header.bitrate + (channels == 2 ? 800 : 0);
     }
 
     /* VAD is activated with VBR or can be turned on by itself */
@@ -275,7 +276,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
     if (samples) {
         /* encode Speex frame */
-        if (avctx->channels == 2)
+        if (avctx->ch_layout.nb_channels == 2)
             speex_encode_stereo_int(samples, s->header.frame_size, &s->bits);
         speex_encode_int(s->enc_state, samples, &s->bits);
         s->pkt_frame_count++;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 232/281] libtwolame: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (232 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 231/281] libspeexdec: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 233/281] libvo-amrwbenc: " James Almer
                   ` (48 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libtwolame.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/libtwolame.c b/libavcodec/libtwolame.c
index a71febc91f..9e1d589a0f 100644
--- a/libavcodec/libtwolame.c
+++ b/libavcodec/libtwolame.c
@@ -76,7 +76,7 @@ static av_cold int twolame_encode_init(AVCodecContext *avctx)
     twolame_set_copyright(s->glopts, s->copyright);
     twolame_set_original(s->glopts, s->original);
 
-    twolame_set_num_channels(s->glopts, avctx->channels);
+    twolame_set_num_channels(s->glopts, avctx->ch_layout.nb_channels);
     twolame_set_in_samplerate(s->glopts, avctx->sample_rate);
     twolame_set_out_samplerate(s->glopts, avctx->sample_rate);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 233/281] libvo-amrwbenc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (233 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 232/281] libtwolame: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 234/281] libvorbis: " James Almer
                   ` (47 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libvo-amrwbenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/libvo-amrwbenc.c b/libavcodec/libvo-amrwbenc.c
index 9c7c91b617..4beede0863 100644
--- a/libavcodec/libvo-amrwbenc.c
+++ b/libavcodec/libvo-amrwbenc.c
@@ -87,7 +87,7 @@ static av_cold int amr_wb_encode_init(AVCodecContext *avctx)
         return AVERROR(ENOSYS);
     }
 
-    if (avctx->channels != 1) {
+    if (avctx->ch_layout.nb_channels != 1) {
         av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
         return AVERROR(ENOSYS);
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 234/281] libvorbis: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (234 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 233/281] libvo-amrwbenc: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 235/281] mace: " James Almer
                   ` (46 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libvorbisdec.c |  4 +++-
 libavcodec/libvorbisenc.c | 42 +++++++++++++++++++--------------------
 2 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/libavcodec/libvorbisdec.c b/libavcodec/libvorbisdec.c
index 5686aaf096..7317b71ed6 100644
--- a/libavcodec/libvorbisdec.c
+++ b/libavcodec/libvorbisdec.c
@@ -112,7 +112,9 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) {
         }
     }
 
-    avccontext->channels = context->vi.channels;
+    av_channel_layout_uninit(&avccontext->ch_layout);
+    avccontext->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    avccontext->ch_layout.nb_channels = context->vi.channels;
     avccontext->sample_rate = context->vi.rate;
     avccontext->sample_fmt = AV_SAMPLE_FMT_S16;
     avccontext->time_base= (AVRational){1, avccontext->sample_rate};
diff --git a/libavcodec/libvorbisenc.c b/libavcodec/libvorbisenc.c
index fa0d5f4b42..640c7f1bf9 100644
--- a/libavcodec/libvorbisenc.c
+++ b/libavcodec/libvorbisenc.c
@@ -96,6 +96,7 @@ static int vorbis_error_to_averror(int ov_err)
 static av_cold int libvorbis_setup(vorbis_info *vi, AVCodecContext *avctx)
 {
     LibvorbisEncContext *s = avctx->priv_data;
+    int channels = avctx->ch_layout.nb_channels;
     double cfreq;
     int ret;
 
@@ -108,7 +109,7 @@ static av_cold int libvorbis_setup(vorbis_info *vi, AVCodecContext *avctx)
         /* default to 3 if the user did not set quality or bitrate */
         if (!(avctx->flags & AV_CODEC_FLAG_QSCALE))
             q = 3.0;
-        if ((ret = vorbis_encode_setup_vbr(vi, avctx->channels,
+        if ((ret = vorbis_encode_setup_vbr(vi, channels,
                                            avctx->sample_rate,
                                            q / 10.0)))
             goto error;
@@ -117,7 +118,7 @@ static av_cold int libvorbis_setup(vorbis_info *vi, AVCodecContext *avctx)
         int maxrate = avctx->rc_max_rate > 0 ? avctx->rc_max_rate : -1;
 
         /* average bitrate */
-        if ((ret = vorbis_encode_setup_managed(vi, avctx->channels,
+        if ((ret = vorbis_encode_setup_managed(vi, channels,
                                                avctx->sample_rate, maxrate,
                                                avctx->bit_rate, minrate)))
             goto error;
@@ -141,32 +142,31 @@ static av_cold int libvorbis_setup(vorbis_info *vi, AVCodecContext *avctx)
             goto error;
     }
 
-    if (avctx->channels == 3 &&
-            avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ||
-        avctx->channels == 4 &&
-            avctx->channel_layout != AV_CH_LAYOUT_2_2 &&
-            avctx->channel_layout != AV_CH_LAYOUT_QUAD ||
-        avctx->channels == 5 &&
-            avctx->channel_layout != AV_CH_LAYOUT_5POINT0 &&
-            avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK ||
-        avctx->channels == 6 &&
-            avctx->channel_layout != AV_CH_LAYOUT_5POINT1 &&
-            avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK ||
-        avctx->channels == 7 &&
-            avctx->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) ||
-        avctx->channels == 8 &&
-            avctx->channel_layout != AV_CH_LAYOUT_7POINT1) {
-        if (avctx->channel_layout) {
+    if ((channels == 3 &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_SURROUND)) ||
+        (channels == 4 &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2) &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD)) ||
+        (channels == 5 &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0) &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0_BACK)) ||
+        (channels == 6 &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1) &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK)) ||
+        (channels == 7 &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT1)) ||
+        (channels == 8 &&
+         av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1))) {
+        if (avctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
             char name[32];
-            av_get_channel_layout_string(name, sizeof(name), avctx->channels,
-                                         avctx->channel_layout);
+            av_channel_layout_describe(&avctx->ch_layout, name, sizeof(name));
             av_log(avctx, AV_LOG_ERROR, "%s not supported by Vorbis: "
                                              "output stream will have incorrect "
                                              "channel layout.\n", name);
         } else {
             av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The encoder "
                                                "will use Vorbis channel layout for "
-                                               "%d channels.\n", avctx->channels);
+                                               "%d channels.\n", channels);
         }
     }
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 235/281] mace: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (235 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 234/281] libvorbis: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 236/281] metasound: " James Almer
                   ` (45 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/mace.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavcodec/mace.c b/libavcodec/mace.c
index 506a0ddece..9ed4747ba9 100644
--- a/libavcodec/mace.c
+++ b/libavcodec/mace.c
@@ -226,7 +226,7 @@ static void chomp6(ChannelData *chd, int16_t *output, uint8_t val, int tab_idx)
 
 static av_cold int mace_decode_init(AVCodecContext * avctx)
 {
-    if (avctx->channels > 2 || avctx->channels < 1)
+    if (avctx->ch_layout.nb_channels > 2 || avctx->ch_layout.nb_channels < 1)
         return AVERROR(EINVAL);
     avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
 
@@ -239,31 +239,32 @@ static int mace_decode_frame(AVCodecContext *avctx, void *data,
     AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
+    int channels = avctx->ch_layout.nb_channels;
     int16_t **samples;
     MACEContext *ctx = avctx->priv_data;
     int i, j, k, l, ret;
     int is_mace3 = (avctx->codec_id == AV_CODEC_ID_MACE3);
 
-    if (buf_size % (avctx->channels << is_mace3)) {
+    if (buf_size % (channels << is_mace3)) {
         av_log(avctx, AV_LOG_ERROR, "buffer size %d is odd\n", buf_size);
-        buf_size -= buf_size % (avctx->channels << is_mace3);
+        buf_size -= buf_size % (channels << is_mace3);
         if (!buf_size)
             return AVERROR_INVALIDDATA;
     }
 
     /* get output buffer */
-    frame->nb_samples = 3 * (buf_size << (1 - is_mace3)) / avctx->channels;
+    frame->nb_samples = 3 * (buf_size << (1 - is_mace3)) / channels;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
     samples = (int16_t **)frame->extended_data;
 
-    for(i = 0; i < avctx->channels; i++) {
+    for(i = 0; i < channels; i++) {
         int16_t *output = samples[i];
 
-        for (j=0; j < buf_size / (avctx->channels << is_mace3); j++)
+        for (j=0; j < buf_size / (channels << is_mace3); j++)
             for (k=0; k < (1 << is_mace3); k++) {
                 uint8_t pkt = buf[(i << is_mace3) +
-                                  (j*avctx->channels << is_mace3) + k];
+                                  (j * channels << is_mace3) + k];
 
                 uint8_t val[2][3] = {{pkt >> 5, (pkt >> 3) & 3, pkt & 7 },
                                      {pkt & 7 , (pkt >> 3) & 3, pkt >> 5}};
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 236/281] metasound: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (236 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 235/281] mace: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 237/281] mf: " James Almer
                   ` (44 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/metasound.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/libavcodec/metasound.c b/libavcodec/metasound.c
index 57851a43c5..32d5e153be 100644
--- a/libavcodec/metasound.c
+++ b/libavcodec/metasound.c
@@ -65,8 +65,9 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
                        const float *shape, float *speech)
 {
     const TwinVQModeTab *mtab = tctx->mtab;
+    int channels     = tctx->avctx->ch_layout.nb_channels;
     int isampf       = tctx->avctx->sample_rate / 1000;
-    int ibps         = tctx->avctx->bit_rate / (1000 * tctx->avctx->channels);
+    int ibps         = tctx->avctx->bit_rate / (1000 * channels);
     int width;
 
     float ratio = (float)mtab->size / isampf;
@@ -75,7 +76,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
 
     float pgain_base, pgain_step, ppc_gain;
 
-    if (tctx->avctx->channels == 1) {
+    if (channels == 1) {
         min_period = log2(ratio * 0.2);
         max_period = min_period + log2(6);
     } else {
@@ -85,7 +86,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
     period_range = max_period - min_period;
     period       = min_period + period_coef * period_range /
                    ((1 << mtab->ppc_period_bit) - 1);
-    if (tctx->avctx->channels == 1)
+    if (channels == 1)
         period = powf(2.0, period);
     else
         period = (int)(period * 400 + 0.5) / 400.0;
@@ -103,7 +104,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
     if (isampf == 22 && ibps == 32)
         width = (int)((2.0 / period + 1) * width + 0.5);
 
-    pgain_base = tctx->avctx->channels == 2 ? 25000.0 : 20000.0;
+    pgain_base = channels == 2 ? 25000.0 : 20000.0;
     pgain_step = pgain_base / ((1 << mtab->pgain_bit) - 1);
     ppc_gain   = 1.0 / 8192 *
                  twinvq_mulawinv(pgain_step * g_coef + pgain_step / 2,
@@ -123,8 +124,9 @@ static void dec_bark_env(TwinVQContext *tctx, const uint8_t *in, int use_hist,
     int bark_n_coef = mtab->fmode[ftype].bark_n_coef;
     int fw_cb_len   = mtab->fmode[ftype].bark_env_size / bark_n_coef;
     int idx         = 0;
+    int channels    = tctx->avctx->ch_layout.nb_channels;
 
-    if (tctx->avctx->channels == 1)
+    if (channels == 1)
         val = 0.5;
     for (i = 0; i < fw_cb_len; i++)
         for (j = 0; j < bark_n_coef; j++, idx++) {
@@ -132,7 +134,7 @@ static void dec_bark_env(TwinVQContext *tctx, const uint8_t *in, int use_hist,
                          (1.0 / 2048);
             float st;
 
-            if (tctx->avctx->channels == 1)
+            if (channels == 1)
                 st = use_hist ?
                     tmp2 + val * hist[idx] + 1.0 : tmp2 + 1.0;
             else
@@ -167,7 +169,7 @@ static int metasound_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,
 {
     TwinVQFrameData     *bits;
     const TwinVQModeTab *mtab = tctx->mtab;
-    int channels              = tctx->avctx->channels;
+    int channels              = tctx->avctx->ch_layout.nb_channels;
     int sub;
     GetBitContext gb;
     int i, j, k, ret;
@@ -276,6 +278,7 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx)
     TwinVQContext *tctx = avctx->priv_data;
     uint32_t tag;
     const MetasoundProps *props = codec_props;
+    int channels;
 
     if (!avctx->extradata || avctx->extradata_size < 16) {
         av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n");
@@ -291,7 +294,7 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx)
         }
         if (props->tag == tag) {
             avctx->sample_rate = props->sample_rate;
-            avctx->channels    = props->channels;
+            channels           = props->channels;
             avctx->bit_rate    = props->bit_rate * 1000;
             isampf             = avctx->sample_rate / 1000;
             break;
@@ -299,17 +302,17 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx)
         props++;
     }
 
-    if (avctx->channels <= 0 || avctx->channels > TWINVQ_CHANNELS_MAX) {
+    if (channels <= 0 || channels > TWINVQ_CHANNELS_MAX) {
         av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n",
-               avctx->channels);
+               channels);
         return AVERROR_INVALIDDATA;
     }
-    avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
-                                                 : AV_CH_LAYOUT_STEREO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_default(&avctx->ch_layout, channels);
 
-    ibps = avctx->bit_rate / (1000 * avctx->channels);
+    ibps = avctx->bit_rate / (1000 * channels);
 
-    switch ((avctx->channels << 16) + (isampf << 8) + ibps) {
+    switch ((channels << 16) + (isampf << 8) + ibps) {
     case (1 << 16) + ( 8 << 8) +  6:
         tctx->mtab = &ff_metasound_mode0806;
         break;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 237/281] mf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (237 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 236/281] metasound: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 238/281] mlp: " James Almer
                   ` (43 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/mfenc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index 410ad64d8d..043026112a 100644
--- a/libavcodec/mfenc.c
+++ b/libavcodec/mfenc.c
@@ -288,7 +288,7 @@ static IMFSample *mf_a_avframe_to_sample(AVCodecContext *avctx, const AVFrame *f
     size_t bps;
     IMFSample *sample;
 
-    bps = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->channels;
+    bps = av_get_bytes_per_sample(avctx->sample_fmt) * avctx->ch_layout.nb_channels;
     len = frame->nb_samples * bps;
 
     sample = ff_create_memory_sample(frame->data[0], len, c->in_info.cbAlignment);
@@ -536,7 +536,7 @@ static int64_t mf_enca_output_score(AVCodecContext *avctx, IMFMediaType *type)
         score |= 1LL << 32;
 
     hr = IMFAttributes_GetUINT32(type, &MF_MT_AUDIO_NUM_CHANNELS, &t);
-    if (!FAILED(hr) && t == avctx->channels)
+    if (!FAILED(hr) && t == avctx->ch_layout.nb_channels)
         score |= 2LL << 32;
 
     hr = IMFAttributes_GetGUID(type, &MF_MT_SUBTYPE, &tg);
@@ -591,7 +591,7 @@ static int64_t mf_enca_input_score(AVCodecContext *avctx, IMFMediaType *type)
         score |= 2;
 
     hr = IMFAttributes_GetUINT32(type, &MF_MT_AUDIO_NUM_CHANNELS, &t);
-    if (!FAILED(hr) && t == avctx->channels)
+    if (!FAILED(hr) && t == avctx->ch_layout.nb_channels)
         score |= 4;
 
     return score;
@@ -615,7 +615,7 @@ static int mf_enca_input_adjust(AVCodecContext *avctx, IMFMediaType *type)
     }
 
     hr = IMFAttributes_GetUINT32(type, &MF_MT_AUDIO_NUM_CHANNELS, &t);
-    if (FAILED(hr) || t != avctx->channels) {
+    if (FAILED(hr) || t != avctx->ch_layout.nb_channels) {
         av_log(avctx, AV_LOG_ERROR, "unsupported input channel number set\n");
         return AVERROR(EINVAL);
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 238/281] mlp: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (238 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 237/281] mf: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 239/281] mpc7: " James Almer
                   ` (42 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/mlp.c        |   9 +++
 libavcodec/mlp.h        |   5 ++
 libavcodec/mlp_parser.c |  12 ++--
 libavcodec/mlpdec.c     | 120 +++++++++++++++++++++++++++-------------
 libavcodec/mlpenc.c     | 106 ++++++++++++++++++-----------------
 5 files changed, 153 insertions(+), 99 deletions(-)

diff --git a/libavcodec/mlp.c b/libavcodec/mlp.c
index dcec145eb0..3f54b2e448 100644
--- a/libavcodec/mlp.c
+++ b/libavcodec/mlp.c
@@ -57,12 +57,21 @@ const ChannelInformation ff_mlp_ch_info[21] = {
     { 0x3F, 0x04, 0x02, 0x00 },
 };
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 const uint64_t ff_mlp_channel_layouts[12] = {
     AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_2_1,
     AV_CH_LAYOUT_QUAD, AV_CH_LAYOUT_2POINT1, AV_CH_LAYOUT_SURROUND,
     AV_CH_LAYOUT_4POINT0, AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_3POINT1,
     AV_CH_LAYOUT_4POINT1, AV_CH_LAYOUT_5POINT1_BACK, 0,
 };
+#endif
+
+const AVChannelLayout ff_mlp_ch_layouts[12] = {
+    AV_CHANNEL_LAYOUT_MONO, AV_CHANNEL_LAYOUT_STEREO, AV_CHANNEL_LAYOUT_2_1,
+    AV_CHANNEL_LAYOUT_QUAD, AV_CHANNEL_LAYOUT_2POINT1, AV_CHANNEL_LAYOUT_SURROUND,
+    AV_CHANNEL_LAYOUT_4POINT0, AV_CHANNEL_LAYOUT_5POINT0_BACK, AV_CHANNEL_LAYOUT_3POINT1,
+    AV_CHANNEL_LAYOUT_4POINT1, AV_CHANNEL_LAYOUT_5POINT1_BACK, { 0 },
+};
 
 #if CONFIG_SMALL
 #define CRC_TABLE_SIZE 257
diff --git a/libavcodec/mlp.h b/libavcodec/mlp.h
index e45eba55ae..8a3e4566a3 100644
--- a/libavcodec/mlp.h
+++ b/libavcodec/mlp.h
@@ -24,6 +24,8 @@
 
 #include <stdint.h>
 
+#include "libavutil/channel_layout.h"
+
 #define SYNC_MLP        0xbb
 #define SYNC_TRUEHD     0xba
 
@@ -135,7 +137,10 @@ typedef struct {
  */
 extern const ChannelInformation ff_mlp_ch_info[21];
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 extern const uint64_t ff_mlp_channel_layouts[12];
+#endif
+extern const AVChannelLayout ff_mlp_ch_layouts[12];
 
 /** MLP uses checksums that seem to be based on the standard CRC algorithm, but
  *  are not (in implementation terms, the table lookup and XOR are reversed).
diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c
index 9fea7db955..d391390dd5 100644
--- a/libavcodec/mlp_parser.c
+++ b/libavcodec/mlp_parser.c
@@ -175,22 +175,18 @@ static int mlp_parse(AVCodecParserContext *s,
         avctx->frame_size =
         s->duration = mh.access_unit_size;
 
-        if(!avctx->channels || !avctx->channel_layout) {
+        av_channel_layout_uninit(&avctx->ch_layout);
         if (mh.stream_type == 0xbb) {
             /* MLP stream */
-            avctx->channels       = mh.channels_mlp;
-            avctx->channel_layout = mh.channel_layout_mlp;
+            av_channel_layout_from_mask(&avctx->ch_layout, mh.channel_layout_mlp);
         } else { /* mh.stream_type == 0xba */
             /* TrueHD stream */
             if (!mh.channels_thd_stream2) {
-                avctx->channels       = mh.channels_thd_stream1;
-                avctx->channel_layout = mh.channel_layout_thd_stream1;
+                av_channel_layout_from_mask(&avctx->ch_layout, mh.channel_layout_thd_stream1);
             } else {
-                avctx->channels       = mh.channels_thd_stream2;
-                avctx->channel_layout = mh.channel_layout_thd_stream2;
+                av_channel_layout_from_mask(&avctx->ch_layout, mh.channel_layout_thd_stream2);
             }
         }
-        }
 
         if (!mh.is_vbr) /* Stream is CBR */
             avctx->bit_rate = mh.peak_bitrate;
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index 29fac54542..d4b8226ec6 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -32,6 +32,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/mem_internal.h"
 #include "libavutil/thread.h"
+#include "libavutil/opt.h"
 #include "get_bits.h"
 #include "internal.h"
 #include "libavutil/crc.h"
@@ -132,8 +133,11 @@ typedef struct SubStream {
 } SubStream;
 
 typedef struct MLPDecodeContext {
+    const AVClass  *class;
     AVCodecContext *avctx;
 
+    AVChannelLayout downmix_layout;
+
     /// Current access unit being read has a major sync.
     int         is_major_sync_unit;
 
@@ -169,39 +173,41 @@ typedef struct MLPDecodeContext {
     MLPDSPContext dsp;
 } MLPDecodeContext;
 
-static const uint64_t thd_channel_order[] = {
-    AV_CH_FRONT_LEFT, AV_CH_FRONT_RIGHT,                     // LR
-    AV_CH_FRONT_CENTER,                                      // C
-    AV_CH_LOW_FREQUENCY,                                     // LFE
-    AV_CH_SIDE_LEFT, AV_CH_SIDE_RIGHT,                       // LRs
-    AV_CH_TOP_FRONT_LEFT, AV_CH_TOP_FRONT_RIGHT,             // LRvh
-    AV_CH_FRONT_LEFT_OF_CENTER, AV_CH_FRONT_RIGHT_OF_CENTER, // LRc
-    AV_CH_BACK_LEFT, AV_CH_BACK_RIGHT,                       // LRrs
-    AV_CH_BACK_CENTER,                                       // Cs
-    AV_CH_TOP_CENTER,                                        // Ts
-    AV_CH_SURROUND_DIRECT_LEFT, AV_CH_SURROUND_DIRECT_RIGHT, // LRsd
-    AV_CH_WIDE_LEFT, AV_CH_WIDE_RIGHT,                       // LRw
-    AV_CH_TOP_FRONT_CENTER,                                  // Cvh
-    AV_CH_LOW_FREQUENCY_2,                                   // LFE2
+static const enum AVChannel thd_channel_order[] = {
+    AV_CHAN_FRONT_LEFT, AV_CHAN_FRONT_RIGHT,                     // LR
+    AV_CHAN_FRONT_CENTER,                                        // C
+    AV_CHAN_LOW_FREQUENCY,                                       // LFE
+    AV_CHAN_SIDE_LEFT, AV_CHAN_SIDE_RIGHT,                       // LRs
+    AV_CHAN_TOP_FRONT_LEFT, AV_CHAN_TOP_FRONT_RIGHT,             // LRvh
+    AV_CHAN_FRONT_LEFT_OF_CENTER, AV_CHAN_FRONT_RIGHT_OF_CENTER, // LRc
+    AV_CHAN_BACK_LEFT, AV_CHAN_BACK_RIGHT,                       // LRrs
+    AV_CHAN_BACK_CENTER,                                         // Cs
+    AV_CHAN_TOP_CENTER,                                          // Ts
+    AV_CHAN_SURROUND_DIRECT_LEFT, AV_CHAN_SURROUND_DIRECT_RIGHT, // LRsd
+    AV_CHAN_WIDE_LEFT, AV_CHAN_WIDE_RIGHT,                       // LRw
+    AV_CHAN_TOP_FRONT_CENTER,                                    // Cvh
+    AV_CHAN_LOW_FREQUENCY_2,                                     // LFE2
 };
 
-static int mlp_channel_layout_subset(uint64_t channel_layout, uint64_t mask)
+static int mlp_channel_layout_subset(AVChannelLayout *layout, uint64_t mask)
 {
-    return channel_layout && ((channel_layout & mask) == channel_layout);
+    return av_channel_layout_check(layout) &&
+           av_channel_layout_subset(layout, mask) ==
+           av_channel_layout_subset(layout, UINT64_MAX);
 }
 
-static uint64_t thd_channel_layout_extract_channel(uint64_t channel_layout,
-                                                   int index)
+static enum AVChannel thd_channel_layout_extract_channel(uint64_t channel_layout,
+                                                         int index)
 {
     int i;
 
-    if (av_get_channel_layout_nb_channels(channel_layout) <= index)
-        return 0;
+    if (av_popcount64(channel_layout) <= index)
+        return AV_CHAN_NONE;
 
     for (i = 0; i < FF_ARRAY_ELEMS(thd_channel_order); i++)
-        if (channel_layout & thd_channel_order[i] && !index--)
+        if (channel_layout & (1 << thd_channel_order[i]) && !index--)
             return thd_channel_order[i];
-    return 0;
+    return AV_CHAN_NONE;
 }
 
 static VLC huff_vlc[3];
@@ -290,6 +296,14 @@ static av_cold int mlp_decode_init(AVCodecContext *avctx)
         m->substream[substr].lossless_check_data = 0xffffffff;
     ff_mlpdsp_init(&m->dsp);
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (avctx->request_channel_layout) {
+        av_channel_layout_uninit(&m->downmix_layout);
+        av_channel_layout_from_mask(&m->downmix_layout, avctx->request_channel_layout);
+    }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     ff_thread_once(&init_static_once, init_static);
 
     return 0;
@@ -410,7 +424,7 @@ static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb)
         }
         if (mh.channels_thd_stream1 == 2 &&
             mh.channels_thd_stream2 == 2 &&
-            m->avctx->channels == 2)
+            m->avctx->ch_layout.nb_channels == 2)
             m->substream[0].mask = AV_CH_LAYOUT_STEREO;
         if ((substr = (mh.num_substreams > 1)))
             m->substream[0].mask = AV_CH_LAYOUT_STEREO;
@@ -419,14 +433,17 @@ static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb)
                 m->substream[2].mask = mh.channel_layout_thd_stream2;
             else
                 m->substream[2].mask = mh.channel_layout_thd_stream1;
-        if (m->avctx->channels > 2)
+        if (m->avctx->ch_layout.nb_channels > 2)
             m->substream[mh.num_substreams > 1].mask = mh.channel_layout_thd_stream1;
 
-        if (m->avctx->channels<=2 && m->substream[substr].mask == AV_CH_LAYOUT_MONO && m->max_decoded_substream == 1) {
+        if (m->avctx->ch_layout.nb_channels <= 2 &&
+            m->substream[substr].mask == AV_CH_LAYOUT_MONO && m->max_decoded_substream == 1) {
             av_log(m->avctx, AV_LOG_DEBUG, "Mono stream with 2 substreams, ignoring 2nd\n");
             m->max_decoded_substream = 0;
-            if (m->avctx->channels==2)
-                m->avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+            if (m->avctx->ch_layout.nb_channels == 2) {
+                av_channel_layout_uninit(&m->avctx->ch_layout);
+                m->avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+            }
         }
     }
 
@@ -548,7 +565,7 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
     s->max_matrix_channel = max_matrix_channel;
     s->noise_type         = noise_type;
 
-    if (mlp_channel_layout_subset(m->avctx->request_channel_layout, s->mask) &&
+    if (mlp_channel_layout_subset(&m->downmix_layout, s->mask) &&
         m->max_decoded_substream > substr) {
         av_log(m->avctx, AV_LOG_DEBUG,
                "Extracting %d-channel downmix (0x%"PRIx64") from substream %d. "
@@ -580,10 +597,11 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
     for (ch = 0; ch <= s->max_matrix_channel; ch++) {
         int ch_assign = get_bits(gbp, 6);
         if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD) {
-            uint64_t channel = thd_channel_layout_extract_channel(s->mask,
-                                                                  ch_assign);
-            ch_assign = av_get_channel_layout_channel_index(s->mask,
-                                                            channel);
+            AVChannelLayout l;
+            enum AVChannel channel = thd_channel_layout_extract_channel(s->mask, ch_assign);
+
+            av_channel_layout_from_mask(&l, s->mask);
+            ch_assign = av_channel_layout_index_from_channel(&l, channel);
         }
         if (ch_assign < 0 || ch_assign > s->max_matrix_channel) {
             avpriv_request_sample(m->avctx,
@@ -623,21 +641,21 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
     }
 
     if (substr == m->max_decoded_substream) {
-        m->avctx->channels       = s->max_matrix_channel + 1;
-        m->avctx->channel_layout = s->mask;
+        av_channel_layout_uninit(&m->avctx->ch_layout);
+        av_channel_layout_from_mask(&m->avctx->ch_layout, s->mask);
         m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(s->ch_assign,
                                                                s->output_shift,
                                                                s->max_matrix_channel,
                                                                m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
 
         if (m->avctx->codec_id == AV_CODEC_ID_MLP && m->needs_reordering) {
-            if (m->avctx->channel_layout == (AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY) ||
-                m->avctx->channel_layout == AV_CH_LAYOUT_5POINT0_BACK) {
+            if (s->mask == (AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY) ||
+                s->mask == AV_CH_LAYOUT_5POINT0_BACK) {
                 int i = s->ch_assign[4];
                 s->ch_assign[4] = s->ch_assign[3];
                 s->ch_assign[3] = s->ch_assign[2];
                 s->ch_assign[2] = i;
-            } else if (m->avctx->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) {
+            } else if (s->mask == AV_CH_LAYOUT_5POINT1_BACK) {
                 FFSWAP(int, s->ch_assign[2], s->ch_assign[4]);
                 FFSWAP(int, s->ch_assign[3], s->ch_assign[5]);
             }
@@ -1078,7 +1096,7 @@ static int output_data(MLPDecodeContext *m, unsigned int substr,
     int ret;
     int is32 = (m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
 
-    if (m->avctx->channels != s->max_matrix_channel + 1) {
+    if (m->avctx->ch_layout.nb_channels != s->max_matrix_channel + 1) {
         av_log(m->avctx, AV_LOG_ERROR, "channel count mismatch\n");
         return AVERROR_INVALIDDATA;
     }
@@ -1255,7 +1273,7 @@ static int read_access_unit(AVCodecContext *avctx, void* data,
 
         if (substr != m->max_decoded_substream &&
             m->substream[m->max_decoded_substream].min_channel == 0 &&
-            m->substream[m->max_decoded_substream].max_channel == avctx->channels - 1)
+            m->substream[m->max_decoded_substream].max_channel == avctx->ch_layout.nb_channels - 1)
             goto skip_substr;
 
         init_get_bits(&gb, buf, substream_data_len[substr] * 8);
@@ -1372,6 +1390,28 @@ static void mlp_decode_flush(AVCodecContext *avctx)
     }
 }
 
+#define OFFSET(x) offsetof(MLPDecodeContext, x)
+#define FLAGS (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
+static const AVOption options[] = {
+    { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout),
+        AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = FLAGS },
+    { NULL },
+};
+
+static const AVClass mlp_decoder_class = {
+    .class_name = "MLP decoder",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+static const AVClass truehd_decoder_class = {
+    .class_name = "TrueHD decoder",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 #if CONFIG_MLP_DECODER
 const AVCodec ff_mlp_decoder = {
     .name           = "mlp",
@@ -1379,6 +1419,7 @@ const AVCodec ff_mlp_decoder = {
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_MLP,
     .priv_data_size = sizeof(MLPDecodeContext),
+    .priv_class     = &mlp_decoder_class,
     .init           = mlp_decode_init,
     .decode         = read_access_unit,
     .flush          = mlp_decode_flush,
@@ -1393,6 +1434,7 @@ const AVCodec ff_truehd_decoder = {
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_TRUEHD,
     .priv_data_size = sizeof(MLPDecodeContext),
+    .priv_class     = &truehd_decoder_class,
     .init           = mlp_decode_init,
     .decode         = read_access_unit,
     .flush          = mlp_decode_flush,
diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index d8783b6f56..80ebb72758 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -381,8 +381,8 @@ static void copy_restart_frame_params(MLPEncodeContext *ctx)
 
         copy_matrix_params(&dp->matrix_params, &ctx->cur_decoding_params->matrix_params);
 
-        for (unsigned int channel = 0; channel < ctx->avctx->channels; channel++) {
-            ChannelParams *cp = ctx->seq_channel_params + index*(ctx->avctx->channels) + channel;
+        for (unsigned int channel = 0; channel < ctx->avctx->ch_layout.nb_channels; channel++) {
+            ChannelParams *cp = ctx->seq_channel_params + index*(ctx->avctx->ch_layout.nb_channels) + channel;
 
             dp->quant_step_size[channel] = ctx->cur_decoding_params->quant_step_size[channel];
             dp->matrix_params.shift[channel] = ctx->cur_decoding_params->matrix_params.shift[channel];
@@ -528,13 +528,13 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
     ctx->coded_peak_bitrate = mlp_peak_bitrate(9600000, avctx->sample_rate);
 
     /* TODO support more channels. */
-    if (avctx->channels > 2) {
+    if (avctx->ch_layout.nb_channels > 2) {
         av_log(avctx, AV_LOG_WARNING,
                "Only mono and stereo are supported at the moment.\n");
     }
 
     ctx->substream_info |= SUBSTREAM_INFO_ALWAYS_SET;
-    if (avctx->channels <= 2) {
+    if (avctx->ch_layout.nb_channels <= 2) {
         ctx->substream_info |= SUBSTREAM_INFO_MAX_2_CHAN;
     }
 
@@ -559,7 +559,7 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
 
     ctx->dts = -avctx->frame_size;
 
-    ctx->num_channels = avctx->channels + 2; /* +2 noise channels */
+    ctx->num_channels = avctx->ch_layout.nb_channels + 2; /* +2 noise channels */
     ctx->one_sample_buffer_size = avctx->frame_size
                                 * ctx->num_channels;
     /* TODO Let user pass major header interval as parameter. */
@@ -588,59 +588,48 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
     ctx->num_substreams = 1; // TODO: change this after adding multi-channel support for TrueHD
 
     if (ctx->avctx->codec_id == AV_CODEC_ID_MLP) {
-        /* MLP */
-        switch(avctx->channel_layout) {
-        case AV_CH_LAYOUT_MONO:
-            ctx->channel_arrangement = 0; break;
-        case AV_CH_LAYOUT_STEREO:
-            ctx->channel_arrangement = 1; break;
-        case AV_CH_LAYOUT_2_1:
-            ctx->channel_arrangement = 2; break;
-        case AV_CH_LAYOUT_QUAD:
-            ctx->channel_arrangement = 3; break;
-        case AV_CH_LAYOUT_2POINT1:
-            ctx->channel_arrangement = 4; break;
-        case AV_CH_LAYOUT_SURROUND:
-            ctx->channel_arrangement = 7; break;
-        case AV_CH_LAYOUT_4POINT0:
-            ctx->channel_arrangement = 8; break;
-        case AV_CH_LAYOUT_5POINT0_BACK:
-            ctx->channel_arrangement = 9; break;
-        case AV_CH_LAYOUT_3POINT1:
-            ctx->channel_arrangement = 10; break;
-        case AV_CH_LAYOUT_4POINT1:
-            ctx->channel_arrangement = 11; break;
-        case AV_CH_LAYOUT_5POINT1_BACK:
-            ctx->channel_arrangement = 12; break;
-        default:
+        static const AVChannelLayout layout_arrangement[] = {
+            AV_CHANNEL_LAYOUT_MONO,         AV_CHANNEL_LAYOUT_STEREO,
+            AV_CHANNEL_LAYOUT_2_1,          AV_CHANNEL_LAYOUT_QUAD,
+            AV_CHANNEL_LAYOUT_2POINT1,      { 0 }, { 0 },
+            AV_CHANNEL_LAYOUT_SURROUND,     AV_CHANNEL_LAYOUT_4POINT0,
+            AV_CHANNEL_LAYOUT_5POINT0_BACK, AV_CHANNEL_LAYOUT_3POINT1,
+            AV_CHANNEL_LAYOUT_4POINT1,      AV_CHANNEL_LAYOUT_5POINT1_BACK,
+        };
+        int i;
+
+        for (i = 0; i < FF_ARRAY_ELEMS(layout_arrangement); i++)
+            if (!av_channel_layout_compare(&avctx->ch_layout, &layout_arrangement[i]))
+                break;
+        if (i == FF_ARRAY_ELEMS(layout_arrangement)) {
             av_log(avctx, AV_LOG_ERROR, "Unsupported channel arrangement\n");
             return AVERROR(EINVAL);
         }
+        ctx->channel_arrangement = i;
         ctx->flags = FLAGS_DVDA;
         ctx->channel_occupancy = ff_mlp_ch_info[ctx->channel_arrangement].channel_occupancy;
         ctx->summary_info      = ff_mlp_ch_info[ctx->channel_arrangement].summary_info     ;
     } else {
         /* TrueHD */
-        switch(avctx->channel_layout) {
-        case AV_CH_LAYOUT_STEREO:
+        if (!av_channel_layout_compare(&avctx->ch_layout,
+                                       &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) {
             ctx->ch_modifier_thd0    = 0;
             ctx->ch_modifier_thd1    = 0;
             ctx->ch_modifier_thd2    = 0;
             ctx->channel_arrangement = 1;
-            break;
-        case AV_CH_LAYOUT_5POINT0_BACK:
+        } else if (!av_channel_layout_compare(&avctx->ch_layout,
+                                              &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0_BACK)) {
             ctx->ch_modifier_thd0    = 1;
             ctx->ch_modifier_thd1    = 1;
             ctx->ch_modifier_thd2    = 1;
             ctx->channel_arrangement = 11;
-            break;
-        case AV_CH_LAYOUT_5POINT1_BACK:
+        } else if (!av_channel_layout_compare(&avctx->ch_layout,
+                                              &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK)) {
             ctx->ch_modifier_thd0    = 2;
             ctx->ch_modifier_thd1    = 1;
             ctx->ch_modifier_thd2    = 2;
             ctx->channel_arrangement = 15;
-            break;
-        default:
+        } else {
             av_log(avctx, AV_LOG_ERROR, "Unsupported channel arrangement\n");
             return AVERROR(EINVAL);
         }
@@ -665,7 +654,7 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
         sum += ctx->seq_size[index];
     }
     ctx->sequence_size = sum;
-    size = ctx->restart_intervals * ctx->sequence_size * ctx->avctx->channels;
+    size = ctx->restart_intervals * ctx->sequence_size * ctx->avctx->ch_layout.nb_channels;
     ctx->channel_params = av_calloc(size, sizeof(*ctx->channel_params));
     if (!ctx->channel_params)
         return AVERROR(ENOMEM);
@@ -679,7 +668,7 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
     rh->noisegen_seed      = 0;
 
     rh->min_channel        = 0;
-    rh->max_channel        = avctx->channels - 1;
+    rh->max_channel        = avctx->ch_layout.nb_channels - 1;
     /* FIXME: this works for 1 and 2 channels, but check for more */
     rh->max_matrix_channel = rh->max_channel;
 
@@ -1228,7 +1217,7 @@ static void input_to_sample_buffer(MLPEncodeContext *ctx)
         int32_t *input_buffer = ctx->inout_buffer + cur_index * ctx->one_sample_buffer_size;
 
         for (unsigned int i = 0; i < ctx->avctx->frame_size; i++) {
-            for (unsigned int channel = 0; channel < ctx->avctx->channels; channel++)
+            for (unsigned int channel = 0; channel < ctx->avctx->ch_layout.nb_channels; channel++)
                 *sample_buffer++ = *input_buffer++;
             sample_buffer += 2; /* noise_channels */
             input_buffer += 2; /* noise_channels */
@@ -1947,7 +1936,7 @@ static void set_best_codebook(MLPEncodeContext *ctx)
 
         /* Update context. */
         for (unsigned int index = 0; index < ctx->number_of_subblocks; index++) {
-            ChannelParams *cp = ctx->seq_channel_params + index*(ctx->avctx->channels) + channel;
+            ChannelParams *cp = ctx->seq_channel_params + index*(ctx->avctx->ch_layout.nb_channels) + channel;
 
             best_codebook = *best_path++;
             cur_bo = &ctx->best_offset[index][channel][best_codebook];
@@ -1968,17 +1957,18 @@ static void set_major_params(MLPEncodeContext *ctx)
     RestartHeader *rh = ctx->cur_restart_header;
     uint8_t max_huff_lsbs = 0;
     uint8_t max_output_bits = 0;
-    DecodingParams *seq_dp = ctx->decoding_params + ctx->seq_offset[0] * ctx->avctx->channels;
-    ChannelParams *seq_cp = ctx->channel_params + ctx->seq_offset[0] * ctx->avctx->channels;
+    int channels = ctx->avctx->ch_layout.nb_channels;
+    DecodingParams *seq_dp = ctx->decoding_params + ctx->seq_offset[0] * channels;
+    ChannelParams *seq_cp = ctx->channel_params + ctx->seq_offset[0] * channels;
 
     for (unsigned int index = 0; index < ctx->seq_size[ctx->restart_intervals-1]; index++) {
         memcpy(&ctx->major_decoding_params[index], seq_dp + index, sizeof(DecodingParams));
-        for (unsigned int channel = 0; channel < ctx->avctx->channels; channel++) {
-            uint8_t huff_lsbs = (seq_cp + index*(ctx->avctx->channels) + channel)->huff_lsbs;
+        for (unsigned int channel = 0; channel < channels; channel++) {
+            uint8_t huff_lsbs = (seq_cp + index*(channels) + channel)->huff_lsbs;
             if (max_huff_lsbs < huff_lsbs)
                 max_huff_lsbs = huff_lsbs;
             memcpy(&ctx->major_channel_params[index][channel],
-                   (seq_cp + index*(ctx->avctx->channels) + channel),
+                   (seq_cp + index*(channels) + channel),
                    sizeof(ChannelParams));
         }
     }
@@ -2017,7 +2007,7 @@ static void analyze_sample_buffer(MLPEncodeContext *ctx)
 
     ctx->cur_restart_header = &ctx->restart_header;
     ctx->cur_decoding_params = seq_dp + 1;
-    ctx->cur_channel_params = seq_cp + ctx->avctx->channels;
+    ctx->cur_channel_params = seq_cp + ctx->avctx->ch_layout.nb_channels;
 
     determine_quant_step_size(ctx);
     generate_2_noise_channels(ctx);
@@ -2044,7 +2034,7 @@ static void analyze_sample_buffer(MLPEncodeContext *ctx)
 
     for (unsigned int index = 0; index < ctx->number_of_subblocks; index++) {
         ctx->cur_decoding_params = seq_dp + index;
-        ctx->cur_channel_params = seq_cp + index*(ctx->avctx->channels);
+        ctx->cur_channel_params = seq_cp + index*(ctx->avctx->ch_layout.nb_channels);
         ctx->cur_best_offset = ctx->best_offset[index];
         determine_bits(ctx);
         ctx->sample_buffer += ctx->cur_decoding_params->blocksize * ctx->num_channels;
@@ -2078,13 +2068,14 @@ static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 {
     MLPEncodeContext *ctx = avctx->priv_data;
     int bytes_written = 0;
+    int channels = avctx->ch_layout.nb_channels;
     int restart_frame, ret;
     uint8_t *data;
 
     if (!frame && !ctx->last_frames--)
         return 0;
 
-    if ((ret = ff_alloc_packet(avctx, avpkt, 87500 * avctx->channels)) < 0)
+    if ((ret = ff_alloc_packet(avctx, avpkt, 87500 * channels)) < 0)
         return ret;
 
     if (frame) {
@@ -2149,7 +2140,7 @@ input_and_return:
             ctx->number_of_frames = ctx->next_major_number_of_frames;
             ctx->number_of_subblocks = ctx->next_major_number_of_frames + 1;
 
-            ctx->seq_channel_params = ctx->channel_params + ctx->seq_offset[seq_index] * ctx->avctx->channels;
+            ctx->seq_channel_params = ctx->channel_params + ctx->seq_offset[seq_index] * channels;
 
             ctx->seq_decoding_params = ctx->decoding_params + ctx->seq_offset[seq_index];
 
@@ -2157,7 +2148,7 @@ input_and_return:
             ctx->number_of_samples = number_of_samples;
 
             for (unsigned int index = 0; index < ctx->seq_size[seq_index]; index++) {
-                clear_channel_params(ctx->seq_channel_params + index * ctx->avctx->channels, ctx->avctx->channels);
+                clear_channel_params(ctx->seq_channel_params + index * channels, channels);
                 default_decoding_params(ctx, ctx->seq_decoding_params + index);
             }
 
@@ -2225,7 +2216,10 @@ const AVCodec ff_mlp_encoder = {
     .capabilities           = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_EXPERIMENTAL,
     .sample_fmts            = (const enum AVSampleFormat[]) {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE},
     .supported_samplerates  = (const int[]) {44100, 48000, 88200, 96000, 176400, 192000, 0},
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts        = ff_mlp_channel_layouts,
+#endif
+    .ch_layouts             = ff_mlp_ch_layouts,
     .caps_internal          = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
 #endif
@@ -2242,7 +2236,15 @@ const AVCodec ff_truehd_encoder = {
     .capabilities           = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_EXPERIMENTAL,
     .sample_fmts            = (const enum AVSampleFormat[]) {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE},
     .supported_samplerates  = (const int[]) {44100, 48000, 88200, 96000, 176400, 192000, 0},
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts        = (const uint64_t[]) {AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT0_BACK, AV_CH_LAYOUT_5POINT1_BACK, 0},
+#endif
+    .ch_layouts             = (const AVChannelLayout[]) {
+                                  AV_CHANNEL_LAYOUT_STEREO,
+                                  AV_CHANNEL_LAYOUT_5POINT0_BACK,
+                                  AV_CHANNEL_LAYOUT_5POINT1_BACK,
+                                  { 0 }
+                              },
     .caps_internal          = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
 #endif
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 239/281] mpc7: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (239 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 238/281] mlp: " James Almer
@ 2022-01-13  2:05 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 240/281] mpc8: " James Almer
                   ` (41 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:05 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/mpc7.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c
index c1a63203d6..c3ca9cfe31 100644
--- a/libavcodec/mpc7.c
+++ b/libavcodec/mpc7.c
@@ -79,8 +79,8 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
     LOCAL_ALIGNED_16(uint8_t, buf, [16]);
 
     /* Musepack SV7 is always stereo */
-    if (avctx->channels != 2) {
-        avpriv_request_sample(avctx, "%d channels", avctx->channels);
+    if (avctx->ch_layout.nb_channels != 2) {
+        avpriv_request_sample(avctx, "%d channels", avctx->ch_layout.nb_channels);
         return AVERROR_PATCHWELCOME;
     }
 
@@ -110,7 +110,8 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
     c->frames_to_skip = 0;
 
     avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
-    avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
 
     ff_thread_once(&init_static_once, mpc7_init_static);
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 240/281] mpc8: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (240 preceding siblings ...)
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 239/281] mpc7: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 241/281] mpegaudio: " James Almer
                   ` (40 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/mpc8.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c
index ae07093338..a0466ec135 100644
--- a/libavcodec/mpc8.c
+++ b/libavcodec/mpc8.c
@@ -169,8 +169,8 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
     c->frames = 1 << (get_bits(&gb, 3) * 2);
 
     avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
-    avctx->channel_layout = (channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
-    avctx->channels = channels;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_default(&avctx->ch_layout, channels);
 
     ff_thread_once(&init_static_once, mpc8_init_static);
 
@@ -358,7 +358,7 @@ static int mpc8_decode_frame(AVCodecContext * avctx, void *data,
 
     ff_mpc_dequantize_and_synth(c, maxband - 1,
                                 (int16_t **)frame->extended_data,
-                                avctx->channels);
+                                avctx->ch_layout.nb_channels);
 
     c->cur_frame++;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 241/281] mpegaudio: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (241 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 240/281] mpc8: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 242/281] nellymoser: " James Almer
                   ` (39 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/mp3_header_decompress_bsf.c |  2 +-
 libavcodec/mpegaudio_parser.c          |  4 +++-
 libavcodec/mpegaudiodec_template.c     | 22 ++++++++++++----------
 libavcodec/mpegaudioenc_fixed.c        |  5 +++++
 libavcodec/mpegaudioenc_float.c        |  5 +++++
 libavcodec/mpegaudioenc_template.c     |  2 +-
 6 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/libavcodec/mp3_header_decompress_bsf.c b/libavcodec/mp3_header_decompress_bsf.c
index ebf6bde1c2..0fd8b3a454 100644
--- a/libavcodec/mp3_header_decompress_bsf.c
+++ b/libavcodec/mp3_header_decompress_bsf.c
@@ -98,7 +98,7 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out)
     }
     memcpy(out->data + frame_size - buf_size, buf, buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
 
-    if(ctx->par_in->channels==2){
+    if (ctx->par_in->ch_layout.nb_channels == 2){
         uint8_t *p= out->data + frame_size - buf_size;
         if(lsf){
             FFSWAP(int, p[1], p[2]);
diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index 2549503d35..6f1272117b 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -84,7 +84,9 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
 
                     if (s->header_count > header_threshold) {
                         avctx->sample_rate= sr;
-                        avctx->channels   = channels;
+                        av_channel_layout_uninit(&avctx->ch_layout);
+                        avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+                        avctx->ch_layout.nb_channels = channels;
                         s1->duration      = frame_size;
                         avctx->codec_id   = codec_id;
                         if (s->no_bitrate || !avctx->bit_rate) {
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index bbb6ff1120..30b315c450 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -1580,8 +1580,9 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
         return AVERROR_INVALIDDATA;
     }
     /* update codec info */
-    avctx->channels       = s->nb_channels;
-    avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = s->nb_channels == 1 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
+                                             (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     if (!avctx->bit_rate)
         avctx->bit_rate = s->bit_rate;
 
@@ -1661,8 +1662,9 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data,
     }
     /* update codec info */
     avctx->sample_rate = s->sample_rate;
-    avctx->channels    = s->nb_channels;
-    avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = s->nb_channels == 1 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
+                                             (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     if (!avctx->bit_rate)
         avctx->bit_rate = s->bit_rate;
 
@@ -1756,8 +1758,8 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
     }
     s->frames             = mp3Frames[cfg.chan_config];
     s->coff               = chan_offset[cfg.chan_config];
-    avctx->channels       = ff_mpeg4audio_channels[cfg.chan_config];
-    avctx->channel_layout = chan_layout[cfg.chan_config];
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_from_mask(&avctx->ch_layout, chan_layout[cfg.chan_config]);
 
     if (cfg.sample_rate < 16000)
         s->syncword = 0xffe00000;
@@ -1854,8 +1856,8 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
             return AVERROR_INVALIDDATA;
         }
 
-        if (ch + m->nb_channels > avctx->channels ||
-            s->coff[fr] + m->nb_channels > avctx->channels) {
+        if (ch + m->nb_channels > avctx->ch_layout.nb_channels ||
+            s->coff[fr] + m->nb_channels > avctx->ch_layout.nb_channels) {
             av_log(avctx, AV_LOG_ERROR, "frame channel count exceeds codec "
                                         "channel count\n");
             return AVERROR_INVALIDDATA;
@@ -1880,7 +1882,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
 
         avctx->bit_rate += m->bit_rate;
     }
-    if (ch != avctx->channels) {
+    if (ch != avctx->ch_layout.nb_channels) {
         av_log(avctx, AV_LOG_ERROR, "failed to decode all channels\n");
         return AVERROR_INVALIDDATA;
     }
@@ -1888,7 +1890,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
     /* update codec info */
     avctx->sample_rate = s->mp3decctx[0]->sample_rate;
 
-    frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT));
+    frame->nb_samples = out_size / (avctx->ch_layout.nb_channels * sizeof(OUT_INT));
     *got_frame_ptr    = 1;
 
     return buf_size;
diff --git a/libavcodec/mpegaudioenc_fixed.c b/libavcodec/mpegaudioenc_fixed.c
index fb1ba4e1bf..23ee61fac5 100644
--- a/libavcodec/mpegaudioenc_fixed.c
+++ b/libavcodec/mpegaudioenc_fixed.c
@@ -35,9 +35,14 @@ const AVCodec ff_mp2fixed_encoder = {
     .supported_samplerates = (const int[]){
         44100, 48000,  32000, 22050, 24000, 16000, 0
     },
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts       = (const uint64_t[]){ AV_CH_LAYOUT_MONO,
                                                  AV_CH_LAYOUT_STEREO,
                                                  0 },
+#endif
+    .ch_layouts            = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO,
+                                                        AV_CHANNEL_LAYOUT_STEREO,
+                                                        { 0 } },
     .defaults              = mp2_defaults,
     .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/mpegaudioenc_float.c b/libavcodec/mpegaudioenc_float.c
index accb909a6f..9f9b885d21 100644
--- a/libavcodec/mpegaudioenc_float.c
+++ b/libavcodec/mpegaudioenc_float.c
@@ -36,9 +36,14 @@ const AVCodec ff_mp2_encoder = {
     .supported_samplerates = (const int[]){
         44100, 48000,  32000, 22050, 24000, 16000, 0
     },
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts       = (const uint64_t[]){ AV_CH_LAYOUT_MONO,
                                                  AV_CH_LAYOUT_STEREO,
                                                  0 },
+#endif
+    .ch_layouts            = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO,
+                                                        AV_CHANNEL_LAYOUT_STEREO,
+                                                        { 0 } },
     .defaults              = mp2_defaults,
     .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/mpegaudioenc_template.c b/libavcodec/mpegaudioenc_template.c
index 1ffd31f7cb..3299360f0c 100644
--- a/libavcodec/mpegaudioenc_template.c
+++ b/libavcodec/mpegaudioenc_template.c
@@ -79,7 +79,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
     MpegAudioContext *s = avctx->priv_data;
     int freq = avctx->sample_rate;
     int bitrate = avctx->bit_rate;
-    int channels = avctx->channels;
+    int channels = avctx->ch_layout.nb_channels;
     int i, v, table;
     float a;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 242/281] nellymoser: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (242 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 241/281] mpegaudio: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 243/281] on2avc: " James Almer
                   ` (38 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/nellymoserdec.c | 4 ++--
 libavcodec/nellymoserenc.c | 6 +-----
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c
index ccfe881790..6870ffea0e 100644
--- a/libavcodec/nellymoserdec.c
+++ b/libavcodec/nellymoserdec.c
@@ -129,8 +129,8 @@ static av_cold int decode_init(AVCodecContext * avctx) {
     s->scale_bias = 1.0/(32768*8);
     avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     /* Generate overlap window */
     ff_init_ff_sine_windows(7);
diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c
index 41d9117065..abf7d82160 100644
--- a/libavcodec/nellymoserenc.c
+++ b/libavcodec/nellymoserenc.c
@@ -171,11 +171,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
     NellyMoserEncodeContext *s = avctx->priv_data;
     int ret;
 
-    if (avctx->channels != 1) {
-        av_log(avctx, AV_LOG_ERROR, "Nellymoser supports only 1 channel\n");
-        return AVERROR(EINVAL);
-    }
-
     if (avctx->sample_rate != 8000 && avctx->sample_rate != 16000 &&
         avctx->sample_rate != 11025 &&
         avctx->sample_rate != 22050 && avctx->sample_rate != 44100 &&
@@ -431,5 +426,6 @@ const AVCodec ff_nellymoser_encoder = {
     .close          = encode_end,
     .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT,
                                                      AV_SAMPLE_FMT_NONE },
+    .ch_layouts     = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO, { 0 } },
     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
 };
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 243/281] on2avc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (243 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 242/281] nellymoser: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 244/281] opus: " James Almer
                   ` (37 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/on2avc.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/libavcodec/on2avc.c b/libavcodec/on2avc.c
index fa3eb4b219..1d5a9487b3 100644
--- a/libavcodec/on2avc.c
+++ b/libavcodec/on2avc.c
@@ -691,7 +691,7 @@ static int on2avc_reconstruct_channel_ext(On2AVCContext *c, AVFrame *dst, int of
 {
     int ch, i;
 
-    for (ch = 0; ch < c->avctx->channels; ch++) {
+    for (ch = 0; ch < c->avctx->ch_layout.nb_channels; ch++) {
         float *out   = (float*)dst->extended_data[ch] + offset;
         float *in    = c->coeffs[ch];
         float *saved = c->delay[ch];
@@ -823,13 +823,13 @@ static int on2avc_decode_subframe(On2AVCContext *c, const uint8_t *buf,
         c->grouping[i] = !get_bits1(&gb);
 
     on2avc_read_ms_info(c, &gb);
-    for (i = 0; i < c->avctx->channels; i++)
+    for (i = 0; i < c->avctx->ch_layout.nb_channels; i++)
         if ((ret = on2avc_read_channel_data(c, &gb, i)) < 0)
             return AVERROR_INVALIDDATA;
-    if (c->avctx->channels == 2 && c->ms_present)
+    if (c->avctx->ch_layout.nb_channels == 2 && c->ms_present)
         on2avc_apply_ms(c);
     if (c->window_type < WINDOW_TYPE_EXT4) {
-        for (i = 0; i < c->avctx->channels; i++)
+        for (i = 0; i < c->avctx->ch_layout.nb_channels; i++)
             on2avc_reconstruct_channel(c, i, dst, offset);
     } else {
         on2avc_reconstruct_channel_ext(c, dst, offset);
@@ -910,21 +910,23 @@ static av_cold int on2avc_decode_init(AVCodecContext *avctx)
     On2AVCContext *c = avctx->priv_data;
     const uint8_t  *lens = ff_on2avc_cb_lens;
     const uint16_t *syms = ff_on2avc_cb_syms;
+    int channels = avctx->ch_layout.nb_channels;
     int i, ret;
 
-    if (avctx->channels > 2U) {
+    if (channels > 2U) {
         avpriv_request_sample(avctx, "Decoding more than 2 channels");
         return AVERROR_PATCHWELCOME;
     }
 
     c->avctx = avctx;
     avctx->sample_fmt     = AV_SAMPLE_FMT_FLTP;
-    avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO
-                                                   : AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = (channels == 2) ? (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO :
+                                         (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     c->is_av500 = (avctx->codec_tag == 0x500);
 
-    if (avctx->channels == 2)
+    if (channels == 2)
         av_log(avctx, AV_LOG_WARNING,
                "Stereo mode support is not good, patch is welcome\n");
 
@@ -936,7 +938,7 @@ static av_cold int on2avc_decode_init(AVCodecContext *avctx)
     for (; i < 128; i++)
         c->scale_tab[i] = ceil(ff_exp10(i * 0.1) * 0.5 - 0.01);
 
-    if (avctx->sample_rate < 32000 || avctx->channels == 1)
+    if (avctx->sample_rate < 32000 || channels == 1)
         memcpy(c->long_win, ff_on2avc_window_long_24000,
                1024 * sizeof(*c->long_win));
     else
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 244/281] opus: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (244 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 243/281] on2avc: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 245/281] pafaudio: " James Almer
                   ` (36 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/opus.c        | 57 ++++++++++++++++++++++++++--------------
 libavcodec/opusdec.c     |  4 +--
 libavcodec/opusenc.c     | 15 ++++++++---
 libavcodec/opusenc_psy.c | 20 +++++++-------
 4 files changed, 61 insertions(+), 35 deletions(-)

diff --git a/libavcodec/opus.c b/libavcodec/opus.c
index df8ba93fa9..c18ff47f71 100644
--- a/libavcodec/opus.c
+++ b/libavcodec/opus.c
@@ -296,14 +296,15 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
     static const uint8_t default_channel_map[2] = { 0, 1 };
 
     int (*channel_reorder)(int, int) = channel_reorder_unknown;
+    int channels = avctx->ch_layout.nb_channels;
 
     const uint8_t *extradata, *channel_map;
     int extradata_size;
-    int version, channels, map_type, streams, stereo_streams, i, j;
-    uint64_t layout;
+    int version, map_type, streams, stereo_streams, i, j, ret;
+    AVChannelLayout layout = { 0 };
 
     if (!avctx->extradata) {
-        if (avctx->channels > 2) {
+        if (channels > 2) {
             av_log(avctx, AV_LOG_ERROR,
                    "Multichannel configuration without extradata.\n");
             return AVERROR(EINVAL);
@@ -331,7 +332,7 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
     if (avctx->internal)
         avctx->internal->skip_samples = avctx->delay;
 
-    channels = avctx->extradata ? extradata[9] : (avctx->channels == 1) ? 1 : 2;
+    channels = avctx->extradata ? extradata[9] : (channels == 1) ? 1 : 2;
     if (!channels) {
         av_log(avctx, AV_LOG_ERROR, "Zero channel count specified in the extradata\n");
         return AVERROR_INVALIDDATA;
@@ -346,9 +347,11 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
         if (channels > 2) {
             av_log(avctx, AV_LOG_ERROR,
                    "Channel mapping 0 is only specified for up to 2 channels\n");
-            return AVERROR_INVALIDDATA;
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
         }
-        layout         = (channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
+        layout         = (channels == 1) ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
+                                           (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
         streams        = 1;
         stereo_streams = channels - 1;
         channel_map    = default_channel_map;
@@ -356,7 +359,8 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
         if (extradata_size < 21 + channels) {
             av_log(avctx, AV_LOG_ERROR, "Invalid extradata size: %d\n",
                    extradata_size);
-            return AVERROR_INVALIDDATA;
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
         }
 
         streams        = extradata[19];
@@ -365,16 +369,18 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
             streams + stereo_streams > 255) {
             av_log(avctx, AV_LOG_ERROR,
                    "Invalid stream/stereo stream count: %d/%d\n", streams, stereo_streams);
-            return AVERROR_INVALIDDATA;
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
         }
 
         if (map_type == 1) {
             if (channels > 8) {
                 av_log(avctx, AV_LOG_ERROR,
                        "Channel mapping 1 is only specified for up to 8 channels\n");
-                return AVERROR_INVALIDDATA;
+                ret = AVERROR_INVALIDDATA;
+                goto fail;
             }
-            layout = ff_vorbis_channel_layouts[channels - 1];
+            av_channel_layout_copy(&layout, &ff_vorbis_ch_layouts[channels - 1]);
             channel_reorder = channel_reorder_vorbis;
         } else if (map_type == 2) {
             int ambisonic_order = ff_sqrt(channels) - 1;
@@ -384,15 +390,20 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
                        "Channel mapping 2 is only specified for channel counts"
                        " which can be written as (n + 1)^2 or (n + 1)^2 + 2"
                        " for nonnegative integer n\n");
-                return AVERROR_INVALIDDATA;
+                ret = AVERROR_INVALIDDATA;
+                goto fail;
             }
             if (channels > 227) {
                 av_log(avctx, AV_LOG_ERROR, "Too many channels\n");
-                return AVERROR_INVALIDDATA;
+                ret = AVERROR_INVALIDDATA;
+                goto fail;
             }
-            layout = 0;
-        } else
-            layout = 0;
+            layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            layout.nb_channels = channels;
+        } else {
+            layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            layout.nb_channels = channels;
+        }
 
         channel_map = extradata + 21;
     } else {
@@ -401,8 +412,10 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
     }
 
     s->channel_maps = av_calloc(channels, sizeof(*s->channel_maps));
-    if (!s->channel_maps)
-        return AVERROR(ENOMEM);
+    if (!s->channel_maps) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
 
     for (i = 0; i < channels; i++) {
         ChannelMap *map = &s->channel_maps[i];
@@ -415,7 +428,8 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
             av_log(avctx, AV_LOG_ERROR,
                    "Invalid channel map for output channel %d: %d\n", i, idx);
             av_freep(&s->channel_maps);
-            return AVERROR_INVALIDDATA;
+            ret = AVERROR_INVALIDDATA;
+            goto fail;
         }
 
         /* check that we did not see this index yet */
@@ -436,12 +450,15 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
         }
     }
 
-    avctx->channels       = channels;
-    avctx->channel_layout = layout;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = layout;
     s->nb_streams         = streams;
     s->nb_stereo_streams  = stereo_streams;
 
     return 0;
+fail:
+    av_channel_layout_uninit(&layout);
+    return ret;
 }
 
 void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc)
diff --git a/libavcodec/opusdec.c b/libavcodec/opusdec.c
index b063e0efeb..2133a4c63b 100644
--- a/libavcodec/opusdec.c
+++ b/libavcodec/opusdec.c
@@ -458,7 +458,7 @@ static int opus_decode_packet(AVCodecContext *avctx, void *data,
         return ret;
     frame->nb_samples = 0;
 
-    for (i = 0; i < avctx->channels; i++) {
+    for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
         ChannelMap *map = &c->channel_maps[i];
         if (!map->copy)
             c->streams[map->stream_idx].out[map->channel_idx] = (float*)frame->extended_data[i];
@@ -541,7 +541,7 @@ static int opus_decode_packet(AVCodecContext *avctx, void *data,
         }
     }
 
-    for (i = 0; i < avctx->channels; i++) {
+    for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
         ChannelMap *map = &c->channel_maps[i];
 
         /* handle copied channels */
diff --git a/libavcodec/opusenc.c b/libavcodec/opusenc.c
index b7f4760a25..a36f59bf23 100644
--- a/libavcodec/opusenc.c
+++ b/libavcodec/opusenc.c
@@ -66,7 +66,7 @@ static void opus_write_extradata(AVCodecContext *avctx)
 
     bytestream_put_buffer(&bs, "OpusHead", 8);
     bytestream_put_byte  (&bs, 0x1);
-    bytestream_put_byte  (&bs, avctx->channels);
+    bytestream_put_byte  (&bs, avctx->ch_layout.nb_channels);
     bytestream_put_le16  (&bs, avctx->initial_padding);
     bytestream_put_le32  (&bs, avctx->sample_rate);
     bytestream_put_le16  (&bs, 0x0);
@@ -518,11 +518,16 @@ static void opus_packet_assembler(OpusEncContext *s, AVPacket *avpkt)
 static AVFrame *spawn_empty_frame(OpusEncContext *s)
 {
     AVFrame *f = av_frame_alloc();
+    int ret;
     if (!f)
         return NULL;
     f->format         = s->avctx->sample_fmt;
     f->nb_samples     = s->avctx->frame_size;
-    f->channel_layout = s->avctx->channel_layout;
+    ret = av_channel_layout_copy(&f->ch_layout, &s->avctx->ch_layout);
+    if (ret < 0) {
+        av_frame_free(&f);
+        return NULL;
+    }
     if (av_frame_get_buffer(f, 4)) {
         av_frame_free(&f);
         return NULL;
@@ -626,7 +631,7 @@ static av_cold int opus_encode_init(AVCodecContext *avctx)
     OpusEncContext *s = avctx->priv_data;
 
     s->avctx = avctx;
-    s->channels = avctx->channels;
+    s->channels = avctx->ch_layout.nb_channels;
 
     /* Opus allows us to change the framesize on each packet (and each packet may
      * have multiple frames in it) but we can't change the codec's frame size on
@@ -734,8 +739,12 @@ const AVCodec ff_opus_encoder = {
     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
     .capabilities   = AV_CODEC_CAP_EXPERIMENTAL | AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY,
     .supported_samplerates = (const int []){ 48000, 0 },
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts = (const uint64_t []){ AV_CH_LAYOUT_MONO,
                                             AV_CH_LAYOUT_STEREO, 0 },
+#endif
+    .ch_layouts      = (const AVChannelLayout []){ AV_CHANNEL_LAYOUT_MONO,
+                                                   AV_CHANNEL_LAYOUT_STEREO, { 0 } },
     .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLTP,
                                                      AV_SAMPLE_FMT_NONE },
 };
diff --git a/libavcodec/opusenc_psy.c b/libavcodec/opusenc_psy.c
index 5a50db942f..1c8f69269c 100644
--- a/libavcodec/opusenc_psy.c
+++ b/libavcodec/opusenc_psy.c
@@ -83,7 +83,7 @@ static void step_collect_psy_metrics(OpusPsyContext *s, int index)
 
     st->index = index;
 
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
         const int lap_size = (1 << s->bsize_analysis);
         for (i = 1; i <= FFMIN(lap_size, index); i++) {
             const int offset = i*120;
@@ -105,7 +105,7 @@ static void step_collect_psy_metrics(OpusPsyContext *s, int index)
             st->bands[ch][i] = &st->coeffs[ch][ff_celt_freq_bands[i] << s->bsize_analysis];
     }
 
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
         for (i = 0; i < CELT_MAX_BANDS; i++) {
             float avg_c_s, energy = 0.0f, dist_dev = 0.0f;
             const int range = ff_celt_freq_range[i] << s->bsize_analysis;
@@ -128,7 +128,7 @@ static void step_collect_psy_metrics(OpusPsyContext *s, int index)
 
     st->silence = !silence;
 
-    if (s->avctx->channels > 1) {
+    if (s->avctx->ch_layout.nb_channels > 1) {
         for (i = 0; i < CELT_MAX_BANDS; i++) {
             float incompat = 0.0f;
             const float *coeffs1 = st->bands[0][i];
@@ -140,7 +140,7 @@ static void step_collect_psy_metrics(OpusPsyContext *s, int index)
         }
     }
 
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
         for (i = 0; i < CELT_MAX_BANDS; i++) {
             OpusBandExcitation *ex = &s->ex[ch][i];
             float bp_e = bessel_filter(&s->bfilter_lo[ch][i], st->energy[ch][i]);
@@ -259,7 +259,7 @@ void ff_opus_psy_celt_frame_init(OpusPsyContext *s, CeltFrame *f, int index)
 
     f->start_band = (s->p.mode == OPUS_MODE_HYBRID) ? 17 : 0;
     f->end_band   = ff_celt_band_end[s->p.bandwidth];
-    f->channels   = s->avctx->channels;
+    f->channels   = s->avctx->ch_layout.nb_channels;
     f->size       = s->p.framesize;
 
     for (i = 0; i < (1 << f->size); i++)
@@ -327,7 +327,7 @@ static void celt_gauge_psy_weight(OpusPsyContext *s, OpusPsyStep **start,
         float tonal_contrib = 0.0f;
         for (f = 0; f < (1 << s->p.framesize); f++) {
             weight = start[f]->stereo[i];
-            for (ch = 0; ch < s->avctx->channels; ch++) {
+            for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
                 weight += start[f]->change_amp[ch][i] + start[f]->tone[ch][i] + start[f]->energy[ch][i];
                 tonal_contrib += start[f]->tone[ch][i];
             }
@@ -384,7 +384,7 @@ static void celt_search_for_dual_stereo(OpusPsyContext *s, CeltFrame *f)
     float td1, td2;
     f->dual_stereo = 0;
 
-    if (s->avctx->channels < 2)
+    if (s->avctx->ch_layout.nb_channels < 2)
         return;
 
     bands_dist(s, f, &td1);
@@ -402,7 +402,7 @@ static void celt_search_for_intensity(OpusPsyContext *s, CeltFrame *f)
     /* TODO: fix, make some heuristic up here using the lambda value */
     float end_band = 0;
 
-    if (s->avctx->channels < 2)
+    if (s->avctx->ch_layout.nb_channels < 2)
         return;
 
     for (i = f->end_band; i >= end_band; i--) {
@@ -436,7 +436,7 @@ static int celt_search_for_tf(OpusPsyContext *s, OpusPsyStep **start, CeltFrame
             float iscore0 = 0.0f;
             float iscore1 = 0.0f;
             for (j = 0; j < (1 << f->size); j++) {
-                for (k = 0; k < s->avctx->channels; k++) {
+                for (k = 0; k < s->avctx->ch_layout.nb_channels; k++) {
                     iscore0 += start[j]->tone[k][i]*start[j]->change_amp[k][i]/mag[0];
                     iscore1 += start[j]->tone[k][i]*start[j]->change_amp[k][i]/mag[1];
                 }
@@ -540,7 +540,7 @@ av_cold int ff_opus_psy_init(OpusPsyContext *s, AVCodecContext *avctx,
         goto fail;
     }
 
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
         for (i = 0; i < CELT_MAX_BANDS; i++) {
             bessel_init(&s->bfilter_hi[ch][i], 1.0f, 19.0f, 100.0f, 1);
             bessel_init(&s->bfilter_lo[ch][i], 1.0f, 20.0f, 100.0f, 0);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 245/281] pafaudio: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (245 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 244/281] opus: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 246/281] pcm: " James Almer
                   ` (35 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/pafaudio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/pafaudio.c b/libavcodec/pafaudio.c
index 969eb7fa97..8d0e65a829 100644
--- a/libavcodec/pafaudio.c
+++ b/libavcodec/pafaudio.c
@@ -29,12 +29,13 @@
 
 static av_cold int paf_audio_init(AVCodecContext *avctx)
 {
-    if (avctx->channels != 2) {
+    if (avctx->ch_layout.nb_channels != 2) {
         av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
         return AVERROR_INVALIDDATA;
     }
 
-    avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
 
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 246/281] pcm: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (246 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 245/281] pafaudio: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 247/281] qcelpdec: " James Almer
                   ` (34 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/pcm-bluray.c      | 36 ++++++++++++++++-----------------
 libavcodec/pcm-dvd.c         | 28 +++++++++++++++-----------
 libavcodec/pcm-dvdenc.c      | 27 ++++++++++++++++---------
 libavcodec/pcm.c             | 39 ++++++++++++++++++------------------
 libavcodec/pcm_rechunk_bsf.c |  5 +++--
 5 files changed, 73 insertions(+), 62 deletions(-)

diff --git a/libavcodec/pcm-bluray.c b/libavcodec/pcm-bluray.c
index c2a6e82b1d..6250f25e72 100644
--- a/libavcodec/pcm-bluray.c
+++ b/libavcodec/pcm-bluray.c
@@ -54,14 +54,12 @@ static int pcm_bluray_parse_header(AVCodecContext *avctx,
                                    const uint8_t *header)
 {
     static const uint8_t bits_per_samples[4] = { 0, 16, 20, 24 };
-    static const uint32_t channel_layouts[16] = {
-        0, AV_CH_LAYOUT_MONO, 0, AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_SURROUND,
-        AV_CH_LAYOUT_2_1, AV_CH_LAYOUT_4POINT0, AV_CH_LAYOUT_2_2,
-        AV_CH_LAYOUT_5POINT0, AV_CH_LAYOUT_5POINT1, AV_CH_LAYOUT_7POINT0,
-        AV_CH_LAYOUT_7POINT1, 0, 0, 0, 0
-    };
-    static const uint8_t channels[16] = {
-        0, 1, 0, 2, 3, 3, 4, 4, 5, 6, 7, 8, 0, 0, 0, 0
+    static const AVChannelLayout channel_layouts[16] = {
+        { 0 },                     AV_CHANNEL_LAYOUT_MONO,     { 0 },
+        AV_CHANNEL_LAYOUT_STEREO,  AV_CHANNEL_LAYOUT_SURROUND, AV_CHANNEL_LAYOUT_2_1,
+        AV_CHANNEL_LAYOUT_4POINT0, AV_CHANNEL_LAYOUT_2_2,      AV_CHANNEL_LAYOUT_5POINT0,
+        AV_CHANNEL_LAYOUT_5POINT1, AV_CHANNEL_LAYOUT_7POINT0,  AV_CHANNEL_LAYOUT_7POINT1,
+        { 0 }, { 0 }, { 0 }, { 0 },
     };
     uint8_t channel_layout = header[2] >> 4;
 
@@ -104,21 +102,21 @@ static int pcm_bluray_parse_header(AVCodecContext *avctx,
      * differ from the actual meaningful number, e.g. mono audio still has two
      * channels, one being empty.
      */
-    avctx->channel_layout  = channel_layouts[channel_layout];
-    avctx->channels        =        channels[channel_layout];
-    if (!avctx->channels) {
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = channel_layouts[channel_layout];
+    if (!avctx->ch_layout.nb_channels) {
         av_log(avctx, AV_LOG_ERROR, "reserved channel configuration (%d)\n",
                channel_layout);
         return AVERROR_INVALIDDATA;
     }
 
-    avctx->bit_rate = FFALIGN(avctx->channels, 2) * avctx->sample_rate *
+    avctx->bit_rate = FFALIGN(avctx->ch_layout.nb_channels, 2) * avctx->sample_rate *
                       avctx->bits_per_coded_sample;
 
     if (avctx->debug & FF_DEBUG_PICT_INFO)
         ff_dlog(avctx,
                 "pcm_bluray_parse_header: %d channels, %d bits per sample, %d Hz, %"PRId64" bit/s\n",
-                avctx->channels, avctx->bits_per_coded_sample,
+                avctx->ch_layout.nb_channels, avctx->bits_per_coded_sample,
                 avctx->sample_rate, avctx->bit_rate);
     return 0;
 }
@@ -148,7 +146,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data,
     bytestream2_init(&gb, src, buf_size);
 
     /* There's always an even number of channels in the source */
-    num_source_channels = FFALIGN(avctx->channels, 2);
+    num_source_channels = FFALIGN(avctx->ch_layout.nb_channels, 2);
     sample_size = (num_source_channels *
                    (avctx->sample_fmt == AV_SAMPLE_FMT_S16 ? 16 : 24)) >> 3;
     samples = buf_size / sample_size;
@@ -161,7 +159,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data,
     dst32 = (int32_t *)frame->data[0];
 
     if (samples) {
-        switch (avctx->channel_layout) {
+        switch (avctx->ch_layout.u.mask) {
             /* cases with same number of source and coded channels */
         case AV_CH_LAYOUT_STEREO:
         case AV_CH_LAYOUT_4POINT0:
@@ -189,10 +187,10 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data,
             if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) {
                 do {
 #if HAVE_BIGENDIAN
-                    bytestream2_get_buffer(&gb, dst16, avctx->channels * 2);
-                    dst16 += avctx->channels;
+                    bytestream2_get_buffer(&gb, dst16, avctx->ch_layout.nb_channels * 2);
+                    dst16 += avctx->ch_layout.nb_channels;
 #else
-                    channel = avctx->channels;
+                    channel = avctx->ch_layout.nb_channels;
                     do {
                         *dst16++ = bytestream2_get_be16u(&gb);
                     } while (--channel);
@@ -201,7 +199,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data,
                 } while (--samples);
             } else {
                 do {
-                    channel = avctx->channels;
+                    channel = avctx->ch_layout.nb_channels;
                     do {
                         *dst32++ = bytestream2_get_be24u(&gb) << 8;
                     } while (--channel);
diff --git a/libavcodec/pcm-dvd.c b/libavcodec/pcm-dvd.c
index 775d342eaa..7f991bba65 100644
--- a/libavcodec/pcm-dvd.c
+++ b/libavcodec/pcm-dvd.c
@@ -55,6 +55,7 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
     static const uint32_t frequencies[4] = { 48000, 96000, 44100, 32000 };
     PCMDVDContext *s = avctx->priv_data;
     int header_int = (header[0] & 0xe0) | (header[1] << 8) | (header[2] << 16);
+    int channels;
 
     /* early exit if the header didn't change apart from the frame number */
     if (s->last_header == header_int)
@@ -89,9 +90,12 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
     avctx->sample_rate = frequencies[header[1] >> 4 & 3];
 
     /* get the number of channels */
-    avctx->channels = 1 + (header[1] & 7);
+    channels = 1 + (header[1] & 7);
+
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_default(&avctx->ch_layout, channels);
     /* calculate the bitrate */
-    avctx->bit_rate = avctx->channels *
+    avctx->bit_rate = channels *
                       avctx->sample_rate *
                       avctx->bits_per_coded_sample;
 
@@ -100,15 +104,15 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
      * needed to complete a set of samples for each channel. */
     if (avctx->bits_per_coded_sample == 16) {
         s->samples_per_block = 1;
-        s->block_size        = avctx->channels * 2;
+        s->block_size        = channels * 2;
     } else {
-        switch (avctx->channels) {
+        switch (channels) {
         case 1:
         case 2:
         case 4:
             /* one group has all the samples needed */
             s->block_size        = 4 * avctx->bits_per_coded_sample / 8;
-            s->samples_per_block = 4 / avctx->channels;
+            s->samples_per_block = 4 / channels;
             s->groups_per_block  = 1;
             break;
         case 8:
@@ -118,11 +122,11 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
             s->groups_per_block  = 2;
             break;
         default:
-            /* need avctx->channels groups */
-            s->block_size        = 4 * avctx->channels *
+            /* need channels groups */
+            s->block_size        = 4 * channels *
                                    avctx->bits_per_coded_sample / 8;
             s->samples_per_block = 4;
-            s->groups_per_block  = avctx->channels;
+            s->groups_per_block  = channels;
             break;
         }
     }
@@ -130,7 +134,7 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
     if (avctx->debug & FF_DEBUG_PICT_INFO)
         ff_dlog(avctx,
                 "pcm_dvd_parse_header: %d channels, %d bits per sample, %d Hz, %"PRId64" bit/s\n",
-                avctx->channels, avctx->bits_per_coded_sample,
+                avctx->ch_layout.nb_channels, avctx->bits_per_coded_sample,
                 avctx->sample_rate, avctx->bit_rate);
 
     s->last_header = header_int;
@@ -155,7 +159,7 @@ static void *pcm_dvd_decode_samples(AVCodecContext *avctx, const uint8_t *src,
         bytestream2_get_buffer(&gb, dst16, blocks * s->block_size);
         dst16 += blocks * s->block_size / 2;
 #else
-        int samples = blocks * avctx->channels;
+        int samples = blocks * avctx->ch_layout.nb_channels;
         do {
             *dst16++ = bytestream2_get_be16u(&gb);
         } while (--samples);
@@ -163,7 +167,7 @@ static void *pcm_dvd_decode_samples(AVCodecContext *avctx, const uint8_t *src,
         return dst16;
     }
     case 20:
-        if (avctx->channels == 1) {
+        if (avctx->ch_layout.nb_channels == 1) {
             do {
                 for (i = 2; i; i--) {
                     dst32[0] = bytestream2_get_be16u(&gb) << 16;
@@ -191,7 +195,7 @@ static void *pcm_dvd_decode_samples(AVCodecContext *avctx, const uint8_t *src,
         }
         return dst32;
     case 24:
-        if (avctx->channels == 1) {
+        if (avctx->ch_layout.nb_channels == 1) {
             do {
                 for (i = 2; i; i--) {
                     dst32[0] = bytestream2_get_be16u(&gb) << 16;
diff --git a/libavcodec/pcm-dvdenc.c b/libavcodec/pcm-dvdenc.c
index c9afac69d2..e16c2a5fe4 100644
--- a/libavcodec/pcm-dvdenc.c
+++ b/libavcodec/pcm-dvdenc.c
@@ -60,7 +60,7 @@ static av_cold int pcm_dvd_encode_init(AVCodecContext *avctx)
     }
 
     avctx->bits_per_coded_sample = 16 + quant * 4;
-    avctx->block_align           = avctx->channels * avctx->bits_per_coded_sample / 8;
+    avctx->block_align           = avctx->ch_layout.nb_channels * avctx->bits_per_coded_sample / 8;
     avctx->bit_rate              = avctx->block_align * 8LL * avctx->sample_rate;
     if (avctx->bit_rate > 9800000) {
         av_log(avctx, AV_LOG_ERROR, "Too big bitrate: reduce sample rate, bitdepth or channels.\n");
@@ -69,16 +69,16 @@ static av_cold int pcm_dvd_encode_init(AVCodecContext *avctx)
 
     if (avctx->sample_fmt == AV_SAMPLE_FMT_S16) {
         s->samples_per_block = 1;
-        s->block_size        = avctx->channels * 2;
+        s->block_size        = avctx->ch_layout.nb_channels * 2;
         frame_size           = 2008 / s->block_size;
     } else {
-        switch (avctx->channels) {
+        switch (avctx->ch_layout.nb_channels) {
         case 1:
         case 2:
         case 4:
             /* one group has all the samples needed */
             s->block_size        = 4 * avctx->bits_per_coded_sample / 8;
-            s->samples_per_block = 4 / avctx->channels;
+            s->samples_per_block = 4 / avctx->ch_layout.nb_channels;
             s->groups_per_block  = 1;
             break;
         case 8:
@@ -88,11 +88,11 @@ static av_cold int pcm_dvd_encode_init(AVCodecContext *avctx)
             s->groups_per_block  = 2;
             break;
         default:
-            /* need avctx->channels groups */
-            s->block_size        = 4 * avctx->channels *
+            /* need avctx->ch_layout.nb_channels groups */
+            s->block_size        = 4 * avctx->ch_layout.nb_channels *
                                    avctx->bits_per_coded_sample / 8;
             s->samples_per_block = 4;
-            s->groups_per_block  = avctx->channels;
+            s->groups_per_block  = avctx->ch_layout.nb_channels;
             break;
         }
 
@@ -100,7 +100,7 @@ static av_cold int pcm_dvd_encode_init(AVCodecContext *avctx)
     }
 
     s->header[0] = 0x0c;
-    s->header[1] = (quant << 6) | (freq << 4) | (avctx->channels - 1);
+    s->header[1] = (quant << 6) | (freq << 4) | (avctx->ch_layout.nb_channels - 1);
     s->header[2] = 0x80;
 
     if (!avctx->frame_size)
@@ -113,7 +113,7 @@ static int pcm_dvd_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
                                 const AVFrame *frame, int *got_packet_ptr)
 {
     PCMDVDContext *s = avctx->priv_data;
-    int samples = frame->nb_samples * avctx->channels;
+    int samples = frame->nb_samples * avctx->ch_layout.nb_channels;
     int64_t pkt_size = (frame->nb_samples / s->samples_per_block) * s->block_size + 3;
     int blocks = (pkt_size - 3) / s->block_size;
     const int16_t *src16;
@@ -138,7 +138,7 @@ static int pcm_dvd_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         } while (--samples);
         break;
     case AV_SAMPLE_FMT_S32:
-        if (avctx->channels == 1) {
+        if (avctx->ch_layout.nb_channels == 1) {
             do {
                 for (int i = 2; i; i--) {
                     bytestream2_put_be16(&pb, src32[0] >> 16);
@@ -181,11 +181,18 @@ const AVCodec ff_pcm_dvd_encoder = {
     .init           = pcm_dvd_encode_init,
     .encode2        = pcm_dvd_encode_frame,
     .supported_samplerates = (const int[]) { 48000, 96000, 0},
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
                                             AV_CH_LAYOUT_STEREO,
                                             AV_CH_LAYOUT_5POINT1,
                                             AV_CH_LAYOUT_7POINT1,
                                             0 },
+#endif
+    .ch_layouts     = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_MONO,
+                                                  AV_CHANNEL_LAYOUT_STEREO,
+                                                  AV_CHANNEL_LAYOUT_5POINT1,
+                                                  AV_CHANNEL_LAYOUT_7POINT1,
+                                                  { 0 } },
     .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
                                                      AV_SAMPLE_FMT_S32,
                                                      AV_SAMPLE_FMT_NONE },
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index e9b8eab484..f0f3d05e92 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -56,7 +56,7 @@ static av_cold int pcm_encode_init(AVCodecContext *avctx)
 #endif
 
     avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id);
-    avctx->block_align           = avctx->channels * avctx->bits_per_coded_sample / 8;
+    avctx->block_align           = avctx->ch_layout.nb_channels * avctx->bits_per_coded_sample / 8;
     avctx->bit_rate              = avctx->block_align * 8LL * avctx->sample_rate;
 
     return 0;
@@ -80,8 +80,8 @@ static av_cold int pcm_encode_init(AVCodecContext *avctx)
     }
 
 #define ENCODE_PLANAR(type, endian, dst, n, shift, offset)              \
-    n /= avctx->channels;                                               \
-    for (c = 0; c < avctx->channels; c++) {                             \
+    n /= avctx->ch_layout.nb_channels;                                  \
+    for (c = 0; c < avctx->ch_layout.nb_channels; c++) {                \
         int i;                                                          \
         samples_ ## type = (const type *) frame->extended_data[c];      \
         for (i = n; i > 0; i--) {                                       \
@@ -104,7 +104,7 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     const uint32_t *samples_uint32_t;
 
     sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;
-    n           = frame->nb_samples * avctx->channels;
+    n           = frame->nb_samples * avctx->ch_layout.nb_channels;
     samples     = (const short *)frame->data[0];
 
     if ((ret = ff_get_encode_buffer(avctx, avpkt, n * sample_size, 0)) < 0)
@@ -207,8 +207,8 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     case AV_CODEC_ID_PCM_S16LE_PLANAR:
     case AV_CODEC_ID_PCM_S32LE_PLANAR:
 #endif /* HAVE_BIGENDIAN */
-        n /= avctx->channels;
-        for (c = 0; c < avctx->channels; c++) {
+        n /= avctx->ch_layout.nb_channels;
+        for (c = 0; c < avctx->ch_layout.nb_channels; c++) {
             const uint8_t *src = frame->extended_data[c];
             bytestream_put_buffer(&dst, src, n * sample_size);
         }
@@ -252,7 +252,7 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx)
     AVFloatDSPContext *fdsp;
     int i;
 
-    if (avctx->channels <= 0) {
+    if (avctx->ch_layout.nb_channels <= 0) {
         av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
         return AVERROR(EINVAL);
     }
@@ -312,8 +312,8 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx)
     }
 
 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)                \
-    n /= avctx->channels;                                                      \
-    for (c = 0; c < avctx->channels; c++) {                                    \
+    n /= channels;                                                             \
+    for (c = 0; c < avctx->ch_layout.nb_channels; c++) {                       \
         int i;                                                                 \
         dst = frame->extended_data[c];                                         \
         for (i = n; i > 0; i--) {                                              \
@@ -330,6 +330,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
     int buf_size       = avpkt->size;
     PCMDecode *s       = avctx->priv_data;
     AVFrame *frame     = data;
+    int channels       = avctx->ch_layout.nb_channels;
     int sample_size, c, n, ret, samples_per_block;
     uint8_t *samples;
     int32_t *dst_int32_t;
@@ -349,7 +350,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
         return AVERROR(EINVAL);
     }
 
-    if (avctx->channels == 0) {
+    if (channels == 0) {
         av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
         return AVERROR(EINVAL);
     }
@@ -359,7 +360,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
         return AVERROR(EINVAL);
     }
 
-    n = avctx->channels * sample_size;
+    n = channels * sample_size;
 
     if (n && buf_size % n) {
         if (buf_size < n) {
@@ -374,7 +375,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
     n = buf_size / sample_size;
 
     /* get output buffer */
-    frame->nb_samples = n * samples_per_block / avctx->channels;
+    frame->nb_samples = n * samples_per_block / channels;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
     samples = frame->data[0];
@@ -429,8 +430,8 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
         }
         break;
     case AV_CODEC_ID_PCM_S8_PLANAR:
-        n /= avctx->channels;
-        for (c = 0; c < avctx->channels; c++) {
+        n /= avctx->ch_layout.nb_channels;
+        for (c = 0; c < avctx->ch_layout.nb_channels; c++) {
             int i;
             samples = frame->extended_data[c];
             for (i = n; i > 0; i--)
@@ -494,8 +495,8 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
     case AV_CODEC_ID_PCM_S16LE_PLANAR:
     case AV_CODEC_ID_PCM_S32LE_PLANAR:
 #endif /* HAVE_BIGENDIAN */
-        n /= avctx->channels;
-        for (c = 0; c < avctx->channels; c++) {
+        n /= avctx->ch_layout.nb_channels;
+        for (c = 0; c < avctx->ch_layout.nb_channels; c++) {
             samples = frame->extended_data[c];
             bytestream_get_buffer(&src, samples, n * sample_size);
         }
@@ -511,8 +512,8 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
     case AV_CODEC_ID_PCM_LXF:
     {
         int i;
-        n /= avctx->channels;
-        for (c = 0; c < avctx->channels; c++) {
+        n /= channels;
+        for (c = 0; c < channels; c++) {
             dst_int32_t = (int32_t *)frame->extended_data[c];
             for (i = 0; i < n; i++) {
                 // extract low 20 bits and expand to 32 bits
@@ -540,7 +541,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
         avctx->codec_id == AV_CODEC_ID_PCM_F24LE) {
         s->vector_fmul_scalar((float *)frame->extended_data[0],
                               (const float *)frame->extended_data[0],
-                              s->scale, FFALIGN(frame->nb_samples * avctx->channels, 4));
+                              s->scale, FFALIGN(frame->nb_samples * avctx->ch_layout.nb_channels, 4));
         emms_c();
     }
 
diff --git a/libavcodec/pcm_rechunk_bsf.c b/libavcodec/pcm_rechunk_bsf.c
index 7cf763359d..80727a1a91 100644
--- a/libavcodec/pcm_rechunk_bsf.c
+++ b/libavcodec/pcm_rechunk_bsf.c
@@ -42,11 +42,12 @@ static int init(AVBSFContext *ctx)
     AVRational sr = av_make_q(ctx->par_in->sample_rate, 1);
     int64_t min_samples;
 
-    if (ctx->par_in->channels <= 0 || ctx->par_in->sample_rate <= 0)
+    if (ctx->par_in->ch_layout.nb_channels <= 0 || ctx->par_in->sample_rate <= 0)
         return AVERROR(EINVAL);
 
     ctx->time_base_out = av_inv_q(sr);
-    s->sample_size = ctx->par_in->channels * av_get_bits_per_sample(ctx->par_in->codec_id) / 8;
+    s->sample_size = ctx->par_in->ch_layout.nb_channels *
+                     av_get_bits_per_sample(ctx->par_in->codec_id) / 8;
 
     if (s->frame_rate.num) {
         min_samples = av_rescale_q_rnd(1, sr, s->frame_rate, AV_ROUND_DOWN);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 247/281] qcelpdec: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (247 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 246/281] pcm: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 248/281] qdmc: " James Almer
                   ` (33 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/qcelpdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c
index b23013816b..9f3ef309db 100644
--- a/libavcodec/qcelpdec.c
+++ b/libavcodec/qcelpdec.c
@@ -87,8 +87,8 @@ static av_cold int qcelp_decode_init(AVCodecContext *avctx)
     QCELPContext *q = avctx->priv_data;
     int i;
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_FLT;
 
     for (i = 0; i < 10; i++)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 248/281] qdmc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (248 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 247/281] qcelpdec: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 249/281] qdm2: " James Almer
                   ` (32 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/qdmc.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/qdmc.c b/libavcodec/qdmc.c
index ae75ca524a..dfdd84870c 100644
--- a/libavcodec/qdmc.c
+++ b/libavcodec/qdmc.c
@@ -245,13 +245,14 @@ static av_cold int qdmc_decode_init(AVCodecContext *avctx)
     }
     bytestream2_skipu(&b, 4);
 
-    avctx->channels = s->nb_channels = bytestream2_get_be32u(&b);
+    s->nb_channels = bytestream2_get_be32u(&b);
     if (s->nb_channels <= 0 || s->nb_channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
         return AVERROR_INVALIDDATA;
     }
-    avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
-                                                   AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = s->nb_channels == 2 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO :
+                                             (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     avctx->sample_rate = bytestream2_get_be32u(&b);
     avctx->bit_rate = bytestream2_get_be32u(&b);
@@ -277,7 +278,7 @@ static av_cold int qdmc_decode_init(AVCodecContext *avctx)
     s->frame_size = 1 << s->frame_bits;
     s->subframe_size = s->frame_size >> 5;
 
-    if (avctx->channels == 2)
+    if (avctx->ch_layout.nb_channels == 2)
         x = 3 * x / 2;
     s->band_index = noise_bands_selector[FFMIN(6, llrint(floor(avctx->bit_rate * 3.0 / (double)x + 0.5)))];
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 249/281] qdm2: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (249 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 248/281] qdmc: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 250/281] ra144: " James Almer
                   ` (31 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/qdm2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index 5e4e741e59..de68e651cd 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -1687,13 +1687,13 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
 
     bytestream2_skip(&gb, 4);
 
-    avctx->channels = s->nb_channels = s->channels = bytestream2_get_be32(&gb);
+    s->nb_channels = s->channels = bytestream2_get_be32(&gb);
     if (s->channels <= 0 || s->channels > MPA_MAX_CHANNELS) {
         av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
         return AVERROR_INVALIDDATA;
     }
-    avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
-                                                   AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_default(&avctx->ch_layout, s->channels);
 
     avctx->sample_rate = bytestream2_get_be32(&gb);
     avctx->bit_rate = bytestream2_get_be32(&gb);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 250/281] ra144: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (250 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 249/281] qdm2: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 251/281] ra288: " James Almer
                   ` (30 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/ra144dec.c | 4 ++--
 libavcodec/ra144enc.c | 8 +++-----
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/libavcodec/ra144dec.c b/libavcodec/ra144dec.c
index b6272b343b..86d0d6e889 100644
--- a/libavcodec/ra144dec.c
+++ b/libavcodec/ra144dec.c
@@ -39,8 +39,8 @@ static av_cold int ra144_decode_init(AVCodecContext * avctx)
     ractx->lpc_coef[0] = ractx->lpc_tables[0];
     ractx->lpc_coef[1] = ractx->lpc_tables[1];
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
 
     return 0;
diff --git a/libavcodec/ra144enc.c b/libavcodec/ra144enc.c
index 7a96354633..19d46ffe0c 100644
--- a/libavcodec/ra144enc.c
+++ b/libavcodec/ra144enc.c
@@ -51,11 +51,6 @@ static av_cold int ra144_encode_init(AVCodecContext * avctx)
     RA144Context *ractx;
     int ret;
 
-    if (avctx->channels != 1) {
-        av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n",
-               avctx->channels);
-        return -1;
-    }
     avctx->frame_size = NBLOCKS * BLOCKSIZE;
     avctx->initial_padding = avctx->frame_size;
     avctx->bit_rate = 8000;
@@ -554,6 +549,9 @@ const AVCodec ff_ra_144_encoder = {
     .sample_fmts    = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
                                                      AV_SAMPLE_FMT_NONE },
     .supported_samplerates = (const int[]){ 8000, 0 },
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO, 0 },
+#endif
+    .ch_layouts     = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO, { 0 } },
     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 251/281] ra288: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (251 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 250/281] ra144: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 252/281] ralf: " James Almer
                   ` (29 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/ra288.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c
index 4310ccdf20..424601991a 100644
--- a/libavcodec/ra288.c
+++ b/libavcodec/ra288.c
@@ -67,8 +67,8 @@ static av_cold int ra288_decode_init(AVCodecContext *avctx)
     RA288Context *ractx = avctx->priv_data;
     AVFloatDSPContext *fdsp;
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_FLT;
 
     if (avctx->block_align != 38) {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 252/281] ralf: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (252 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 251/281] ra288: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 253/281] roqaudioenc: " James Almer
                   ` (28 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/ralf.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ralf.c b/libavcodec/ralf.c
index bb80119b0c..eac3e60371 100644
--- a/libavcodec/ralf.c
+++ b/libavcodec/ralf.c
@@ -128,7 +128,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 {
     RALFContext *ctx = avctx->priv_data;
     int i, j, k;
-    int ret;
+    int ret, channels;
 
     if (avctx->extradata_size < 24 || memcmp(avctx->extradata, "LSD:", 4)) {
         av_log(avctx, AV_LOG_ERROR, "Extradata is not groovy, dude\n");
@@ -141,17 +141,17 @@ static av_cold int decode_init(AVCodecContext *avctx)
         return AVERROR_PATCHWELCOME;
     }
 
-    avctx->channels    = AV_RB16(avctx->extradata + 8);
+    channels           = AV_RB16(avctx->extradata + 8);
     avctx->sample_rate = AV_RB32(avctx->extradata + 12);
-    if (avctx->channels < 1 || avctx->channels > 2
+    if (channels < 1 || channels > 2
         || avctx->sample_rate < 8000 || avctx->sample_rate > 96000) {
         av_log(avctx, AV_LOG_ERROR, "Invalid coding parameters %d Hz %d ch\n",
-               avctx->sample_rate, avctx->channels);
+               avctx->sample_rate, channels);
         return AVERROR_INVALIDDATA;
     }
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16P;
-    avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO
-                                                   : AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_default(&avctx->ch_layout, channels);
 
     ctx->max_frame_size = AV_RB32(avctx->extradata + 16);
     if (ctx->max_frame_size > (1 << 20) || !ctx->max_frame_size) {
@@ -358,7 +358,7 @@ static int decode_block(AVCodecContext *avctx, GetBitContext *gb,
         return AVERROR_INVALIDDATA;
     }
 
-    if (avctx->channels > 1)
+    if (avctx->ch_layout.nb_channels > 1)
         dmode = get_bits(gb, 2) + 1;
     else
         dmode = 0;
@@ -368,7 +368,7 @@ static int decode_block(AVCodecContext *avctx, GetBitContext *gb,
     bits[0] = 16;
     bits[1] = (mode[1] == 2) ? 17 : 16;
 
-    for (ch = 0; ch < avctx->channels; ch++) {
+    for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
         if ((ret = decode_channel(ctx, gb, ch, len, mode[ch], bits[ch])) < 0)
             return ret;
         if (ctx->filter_params > 1 && ctx->filter_params != FILTER_RAW) {
@@ -484,7 +484,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
     while (get_bits_left(&gb) > 0) {
         if (ctx->num_blocks >= FF_ARRAY_ELEMS(ctx->block_size))
             return AVERROR_INVALIDDATA;
-        ctx->block_size[ctx->num_blocks] = get_bits(&gb, 13 + avctx->channels);
+        ctx->block_size[ctx->num_blocks] = get_bits(&gb, 13 + avctx->ch_layout.nb_channels);
         if (get_bits1(&gb)) {
             ctx->block_pts[ctx->num_blocks] = get_bits(&gb, 9);
         } else {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 253/281] roqaudioenc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (253 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 252/281] ralf: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 254/281] s302m: " James Almer
                   ` (27 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/roqaudioenc.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/libavcodec/roqaudioenc.c b/libavcodec/roqaudioenc.c
index 530e6b68d8..d482fd213a 100644
--- a/libavcodec/roqaudioenc.c
+++ b/libavcodec/roqaudioenc.c
@@ -54,8 +54,9 @@ static av_cold int roq_dpcm_encode_close(AVCodecContext *avctx)
 static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx)
 {
     ROQDPCMContext *context = avctx->priv_data;
+    int channels = avctx->ch_layout.nb_channels;
 
-    if (avctx->channels > 2) {
+    if (channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "Audio must be mono or stereo\n");
         return AVERROR(EINVAL);
     }
@@ -65,10 +66,10 @@ static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx)
     }
 
     avctx->frame_size = ROQ_FRAME_SIZE;
-    avctx->bit_rate   = (ROQ_HEADER_SIZE + ROQ_FRAME_SIZE * avctx->channels) *
+    avctx->bit_rate   = (ROQ_HEADER_SIZE + ROQ_FRAME_SIZE * channels) *
                         (22050 / ROQ_FRAME_SIZE) * 8;
 
-    context->frame_buffer = av_malloc(8 * ROQ_FRAME_SIZE * avctx->channels *
+    context->frame_buffer = av_malloc(8 * ROQ_FRAME_SIZE * channels *
                                       sizeof(*context->frame_buffer));
     if (!context->frame_buffer)
         return AVERROR(ENOMEM);
@@ -123,17 +124,18 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 {
     int i, stereo, data_size, ret;
     const int16_t *in = frame ? (const int16_t *)frame->data[0] : NULL;
+    int channels = avctx->ch_layout.nb_channels;
     uint8_t *out;
     ROQDPCMContext *context = avctx->priv_data;
 
-    stereo = (avctx->channels == 2);
+    stereo = (channels == 2);
 
     if (!in && context->input_frames >= 8)
         return 0;
 
     if (in && context->input_frames < 8) {
-        memcpy(&context->frame_buffer[context->buffered_samples * avctx->channels],
-               in, avctx->frame_size * avctx->channels * sizeof(*in));
+        memcpy(&context->frame_buffer[context->buffered_samples * channels],
+               in, avctx->frame_size * channels * sizeof(*in));
         context->buffered_samples += avctx->frame_size;
         if (context->input_frames == 0)
             context->first_pts = frame->pts;
@@ -151,9 +153,9 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     }
 
     if (context->input_frames == 7)
-        data_size = avctx->channels * context->buffered_samples;
+        data_size = channels * context->buffered_samples;
     else
-        data_size = avctx->channels * avctx->frame_size;
+        data_size = channels * avctx->frame_size;
 
     ret = ff_get_encode_buffer(avctx, avpkt, ROQ_HEADER_SIZE + data_size, 0);
     if (ret < 0)
@@ -175,7 +177,7 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         *out++ = dpcm_predict(&context->lastSample[i & 1], *in++);
 
     avpkt->pts      = context->input_frames <= 7 ? context->first_pts : frame->pts;
-    avpkt->duration = data_size / avctx->channels;
+    avpkt->duration = data_size / channels;
 
     context->input_frames++;
     if (!in)
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 254/281] s302m: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (254 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 253/281] roqaudioenc: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 255/281] sbc: " James Almer
                   ` (26 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/s302m.c    | 31 +++++++++++++++++++------------
 libavcodec/s302menc.c | 18 +++++++++---------
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c
index b09c1293a0..868f2f99af 100644
--- a/libavcodec/s302m.c
+++ b/libavcodec/s302m.c
@@ -72,19 +72,25 @@ static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf,
     else
         avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
-    avctx->channels    = channels;
+    av_channel_layout_uninit(&avctx->ch_layout);
     switch(channels) {
         case 2:
-            avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+            avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
             break;
         case 4:
-            avctx->channel_layout = AV_CH_LAYOUT_QUAD;
+            avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD;
             break;
         case 6:
-            avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK;
+            avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK;
             break;
         case 8:
-            avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK | AV_CH_LAYOUT_STEREO_DOWNMIX;
+            av_channel_layout_from_mask(&avctx->ch_layout,
+                                        AV_CH_LAYOUT_5POINT1_BACK | AV_CH_LAYOUT_STEREO_DOWNMIX);
+            break;
+        default:
+            avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            avctx->ch_layout.nb_channels = channels;
+            break;
     }
 
     return frame_size;
@@ -97,7 +103,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
     AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
-    int block_size, ret;
+    int block_size, ret, channels;
     int i;
     int non_pcm_data_type = -1;
 
@@ -110,13 +116,14 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
 
     /* get output buffer */
     block_size = (avctx->bits_per_raw_sample + 4) / 4;
-    frame->nb_samples = 2 * (buf_size / block_size) / avctx->channels;
+    channels = avctx->ch_layout.nb_channels;
+    frame->nb_samples = 2 * (buf_size / block_size) / channels;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
 
-    avctx->bit_rate = 48000 * avctx->channels * (avctx->bits_per_raw_sample + 4) +
+    avctx->bit_rate = 48000 * channels * (avctx->bits_per_raw_sample + 4) +
                       32 * 48000 / frame->nb_samples;
-    buf_size = (frame->nb_samples * avctx->channels / 2) * block_size;
+    buf_size = (frame->nb_samples * channels / 2) * block_size;
 
     if (avctx->bits_per_raw_sample == 24) {
         uint32_t *o = (uint32_t *)frame->data[0];
@@ -131,7 +138,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
             buf += 7;
         }
         o = (uint32_t *)frame->data[0];
-        if (avctx->channels == 2)
+        if (channels == 2)
             for (i=0; i<frame->nb_samples * 2 - 6; i+=2) {
                 if (o[i] || o[i+1] || o[i+2] || o[i+3])
                     break;
@@ -152,7 +159,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
             buf += 6;
         }
         o = (uint32_t *)frame->data[0];
-        if (avctx->channels == 2)
+        if (channels == 2)
             for (i=0; i<frame->nb_samples * 2 - 6; i+=2) {
                 if (o[i] || o[i+1] || o[i+2] || o[i+3])
                     break;
@@ -172,7 +179,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
             buf += 5;
         }
         o = (uint16_t *)frame->data[0];
-        if (avctx->channels == 2)
+        if (channels == 2)
             for (i=0; i<frame->nb_samples * 2 - 6; i+=2) {
                 if (o[i] || o[i+1] || o[i+2] || o[i+3])
                     break;
diff --git a/libavcodec/s302menc.c b/libavcodec/s302menc.c
index 528d712e79..56db25c76b 100644
--- a/libavcodec/s302menc.c
+++ b/libavcodec/s302menc.c
@@ -37,10 +37,10 @@ static av_cold int s302m_encode_init(AVCodecContext *avctx)
 {
     S302MEncContext *s = avctx->priv_data;
 
-    if (avctx->channels & 1 || avctx->channels > 8) {
+    if (avctx->ch_layout.nb_channels & 1 || avctx->ch_layout.nb_channels > 8) {
         av_log(avctx, AV_LOG_ERROR,
                "Encoding %d channel(s) is not allowed. Only 2, 4, 6 and 8 channels are supported.\n",
-               avctx->channels);
+               avctx->ch_layout.nb_channels);
         return AVERROR(EINVAL);
     }
 
@@ -61,7 +61,7 @@ static av_cold int s302m_encode_init(AVCodecContext *avctx)
     }
 
     avctx->frame_size = 0;
-    avctx->bit_rate   = 48000 * avctx->channels *
+    avctx->bit_rate   = 48000 * avctx->ch_layout.nb_channels *
                        (avctx->bits_per_raw_sample + 4);
     s->framing_index  = 0;
 
@@ -72,9 +72,9 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt,
                                const AVFrame *frame, int *got_packet_ptr)
 {
     S302MEncContext *s = avctx->priv_data;
+    const int nb_channels = avctx->ch_layout.nb_channels;
     const int buf_size = AES3_HEADER_LEN +
-                        (frame->nb_samples *
-                         avctx->channels *
+                        (frame->nb_samples * nb_channels *
                         (avctx->bits_per_raw_sample + 4)) / 8;
     int ret, c, channels;
     uint8_t *o;
@@ -91,7 +91,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt,
     o = avpkt->data;
     init_put_bits(&pb, o, buf_size);
     put_bits(&pb, 16, buf_size - AES3_HEADER_LEN);
-    put_bits(&pb, 2, (avctx->channels - 2) >> 1);   // number of channels
+    put_bits(&pb, 2, (nb_channels - 2) >> 1);   // number of channels
     put_bits(&pb, 8, 0);                            // channel ID
     put_bits(&pb, 2, (avctx->bits_per_raw_sample - 16) / 4); // bits per samples (0 = 16bit, 1 = 20bit, 2 = 24bit)
     put_bits(&pb, 4, 0);                            // alignments
@@ -104,7 +104,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt,
         for (c = 0; c < frame->nb_samples; c++) {
             uint8_t vucf = s->framing_index == 0 ? 0x10: 0;
 
-            for (channels = 0; channels < avctx->channels; channels += 2) {
+            for (channels = 0; channels < nb_channels; channels += 2) {
                 o[0] = ff_reverse[(samples[0] & 0x0000FF00) >> 8];
                 o[1] = ff_reverse[(samples[0] & 0x00FF0000) >> 16];
                 o[2] = ff_reverse[(samples[0] & 0xFF000000) >> 24];
@@ -126,7 +126,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt,
         for (c = 0; c < frame->nb_samples; c++) {
             uint8_t vucf = s->framing_index == 0 ? 0x80: 0;
 
-            for (channels = 0; channels < avctx->channels; channels += 2) {
+            for (channels = 0; channels < nb_channels; channels += 2) {
                 o[0] = ff_reverse[ (samples[0] & 0x000FF000) >> 12];
                 o[1] = ff_reverse[ (samples[0] & 0x0FF00000) >> 20];
                 o[2] = ff_reverse[((samples[0] & 0xF0000000) >> 28) | vucf];
@@ -147,7 +147,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt,
         for (c = 0; c < frame->nb_samples; c++) {
             uint8_t vucf = s->framing_index == 0 ? 0x10 : 0;
 
-            for (channels = 0; channels < avctx->channels; channels += 2) {
+            for (channels = 0; channels < nb_channels; channels += 2) {
                 o[0] = ff_reverse[ samples[0] & 0xFF];
                 o[1] = ff_reverse[(samples[0] & 0xFF00) >>  8];
                 o[2] = ff_reverse[(samples[1] & 0x0F)   <<  4] | vucf;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 255/281] sbc: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (255 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 254/281] s302m: " James Almer
@ 2022-01-13  2:06 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 256/281] shorten: " James Almer
                   ` (25 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:06 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/sbc_parser.c |  8 ++++++--
 libavcodec/sbcdec.c     |  9 ++++++++-
 libavcodec/sbcenc.c     | 15 ++++++++++-----
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/libavcodec/sbc_parser.c b/libavcodec/sbc_parser.c
index 8bf726b39e..2d427cc7cb 100644
--- a/libavcodec/sbc_parser.c
+++ b/libavcodec/sbc_parser.c
@@ -41,7 +41,9 @@ static int sbc_parse_header(AVCodecParserContext *s, AVCodecContext *avctx,
         return -1;
 
     if (data[0] == MSBC_SYNCWORD && data[1] == 0 && data[2] == 0) {
-        avctx->channels = 1;
+        av_channel_layout_uninit(&avctx->ch_layout);
+        avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        avctx->ch_layout.nb_channels = 1;
         avctx->sample_rate = 16000;
         avctx->frame_size = 120;
         s->duration = avctx->frame_size;
@@ -64,7 +66,9 @@ static int sbc_parse_header(AVCodecParserContext *s, AVCodecContext *avctx,
              + ((((mode == SBC_MODE_DUAL_CHANNEL) + 1) * blocks * bitpool
                  + (joint * subbands)) + 7) / 8;
 
-    avctx->channels = channels;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    avctx->ch_layout.nb_channels = channels;
     avctx->sample_rate = sample_rates[sr];
     avctx->frame_size = subbands * blocks;
     s->duration = avctx->frame_size;
diff --git a/libavcodec/sbcdec.c b/libavcodec/sbcdec.c
index e14d8c8958..1c053ad9a7 100644
--- a/libavcodec/sbcdec.c
+++ b/libavcodec/sbcdec.c
@@ -351,7 +351,9 @@ static int sbc_decode_frame(AVCodecContext *avctx,
     if (frame_length <= 0)
         return frame_length;
 
-    avctx->channels = sbc->frame.channels;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    avctx->ch_layout.nb_channels = sbc->frame.channels;
 
     frame->nb_samples = sbc->frame.blocks * sbc->frame.subbands;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
@@ -374,8 +376,13 @@ const AVCodec ff_sbc_decoder = {
     .decode                = sbc_decode_frame,
     .capabilities          = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
     .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
                                                   AV_CH_LAYOUT_STEREO, 0},
+#endif
+    .ch_layouts            = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_MONO,
+                                                         AV_CHANNEL_LAYOUT_STEREO,
+                                                         { 0 } },
     .sample_fmts           = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
                                                              AV_SAMPLE_FMT_NONE },
     .supported_samplerates = (const int[]) { 16000, 32000, 44100, 48000, 0 },
diff --git a/libavcodec/sbcenc.c b/libavcodec/sbcenc.c
index 45156277b7..cff93e8917 100644
--- a/libavcodec/sbcenc.c
+++ b/libavcodec/sbcenc.c
@@ -202,7 +202,7 @@ static int sbc_encode_init(AVCodecContext *avctx)
         sbc->msbc = 1;
 
     if (sbc->msbc) {
-        if (avctx->channels != 1) {
+        if (avctx->ch_layout.nb_channels != 1) {
             av_log(avctx, AV_LOG_ERROR, "mSBC require mono channel.\n");
             return AVERROR(EINVAL);
         }
@@ -227,7 +227,7 @@ static int sbc_encode_init(AVCodecContext *avctx)
             return AVERROR(EINVAL);
         }
 
-        if (avctx->channels == 1) {
+        if (avctx->ch_layout.nb_channels == 1) {
             frame->mode = SBC_MODE_MONO;
             if (sbc->max_delay <= 3000 || avctx->bit_rate > 270000)
                 frame->subbands = 4;
@@ -251,7 +251,7 @@ static int sbc_encode_init(AVCodecContext *avctx)
 
         d = frame->blocks * ((frame->mode == SBC_MODE_DUAL_CHANNEL) + 1);
         frame->bitpool = (((avctx->bit_rate * frame->subbands * frame->blocks) / avctx->sample_rate)
-                          - 4 * frame->subbands * avctx->channels
+                          - 4 * frame->subbands * avctx->ch_layout.nb_channels
                           - (frame->mode == SBC_MODE_JOINT_STEREO)*frame->subbands - 32 + d/2) / d;
         if (avctx->global_quality > 0)
             frame->bitpool = avctx->global_quality / FF_QP2LAMBDA;
@@ -263,8 +263,8 @@ static int sbc_encode_init(AVCodecContext *avctx)
         if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
             frame->frequency = i;
 
-    frame->channels = avctx->channels;
-    frame->codesize = frame->subbands * frame->blocks * avctx->channels * 2;
+    frame->channels = avctx->ch_layout.nb_channels;
+    frame->codesize = frame->subbands * frame->blocks * avctx->ch_layout.nb_channels * 2;
     frame->crc_ctx = av_crc_get_table(AV_CRC_8_EBU);
 
     memset(&sbc->dsp.X, 0, sizeof(sbc->dsp.X));
@@ -353,8 +353,13 @@ const AVCodec ff_sbc_encoder = {
     .init                  = sbc_encode_init,
     .encode2               = sbc_encode_frame,
     .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
                                                   AV_CH_LAYOUT_STEREO, 0},
+#endif
+    .ch_layouts            = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_MONO,
+                                                         AV_CHANNEL_LAYOUT_STEREO,
+                                                         { 0 } },
     .sample_fmts           = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16,
                                                              AV_SAMPLE_FMT_NONE },
     .supported_samplerates = (const int[]) { 16000, 32000, 44100, 48000, 0 },
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 256/281] shorten: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (256 preceding siblings ...)
  2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 255/281] sbc: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 257/281] sipr: " James Almer
                   ` (24 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/shorten.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index fde5c4b982..6cce675c9f 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -428,7 +428,11 @@ static int read_header(ShortenContext *s)
         s->channels = 0;
         return AVERROR_INVALIDDATA;
     }
-    s->avctx->channels = s->channels;
+    if (s->avctx->ch_layout.nb_channels != s->channels) {
+        av_channel_layout_uninit(&s->avctx->ch_layout);
+        s->avctx->ch_layout.nb_channels = s->channels;
+        s->avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    }
 
     /* get blocksize if version > 0 */
     if (s->version > 0) {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 257/281] sipr: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (257 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 256/281] shorten: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 258/281] siren: " James Almer
                   ` (23 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/sipr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c
index a792b22c9f..6c7293b6ec 100644
--- a/libavcodec/sipr.c
+++ b/libavcodec/sipr.c
@@ -512,8 +512,8 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx)
     for (i = 0; i < 4; i++)
         ctx->energy_history[i] = -14;
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_FLT;
 
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 258/281] siren: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (258 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 257/281] sipr: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 259/281] smacker: " James Almer
                   ` (22 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/siren.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/siren.c b/libavcodec/siren.c
index bdb249144b..add1773069 100644
--- a/libavcodec/siren.c
+++ b/libavcodec/siren.c
@@ -398,8 +398,8 @@ static av_cold int siren_init(AVCodecContext *avctx)
     s->imdct_prev = s->imdct_buf[2];
     s->window     = s->imdct_buf[3];
 
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_FLT;
 
     s->rate_control_possibilities = 16;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 259/281] smacker: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (259 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 258/281] siren: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 260/281] sonic: " James Almer
                   ` (21 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/smacker.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 75ab5d7120..4a3999e4f1 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -572,11 +572,13 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
 static av_cold int smka_decode_init(AVCodecContext *avctx)
 {
-    if (avctx->channels < 1 || avctx->channels > 2) {
+    int channels = avctx->ch_layout.nb_channels;
+    if (channels < 1 || channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
         return AVERROR_INVALIDDATA;
     }
-    avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_default(&avctx->ch_layout, channels);
     avctx->sample_fmt = avctx->bits_per_coded_sample == 8 ? AV_SAMPLE_FMT_U8 : AV_SAMPLE_FMT_S16;
 
     return 0;
@@ -623,7 +625,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data,
     }
     stereo = get_bits1(&gb);
     bits = get_bits1(&gb);
-    if (stereo ^ (avctx->channels != 1)) {
+    if (stereo ^ (avctx->ch_layout.nb_channels != 1)) {
         av_log(avctx, AV_LOG_ERROR, "channels mismatch\n");
         return AVERROR_INVALIDDATA;
     }
@@ -633,8 +635,8 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     /* get output buffer */
-    frame->nb_samples = unp_size / (avctx->channels * (bits + 1));
-    if (unp_size % (avctx->channels * (bits + 1))) {
+    frame->nb_samples = unp_size / (avctx->ch_layout.nb_channels * (bits + 1));
+    if (unp_size % (avctx->ch_layout.nb_channels * (bits + 1))) {
         av_log(avctx, AV_LOG_ERROR,
                "The buffer does not contain an integer number of samples\n");
         return AVERROR_INVALIDDATA;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 260/281] sonic: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (260 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 259/281] smacker: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 261/281] speex: " James Almer
                   ` (20 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/sonic.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c
index cf1cfb1460..34f1605b29 100644
--- a/libavcodec/sonic.c
+++ b/libavcodec/sonic.c
@@ -598,13 +598,13 @@ static av_cold int sonic_encode_init(AVCodecContext *avctx)
 
     s->version = 2;
 
-    if (avctx->channels > MAX_CHANNELS)
+    if (avctx->ch_layout.nb_channels > MAX_CHANNELS)
     {
         av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
         return AVERROR(EINVAL); /* only stereo or mono for now */
     }
 
-    if (avctx->channels == 2)
+    if (avctx->ch_layout.nb_channels == 2)
         s->decorrelation = MID_SIDE;
     else
         s->decorrelation = 3;
@@ -637,7 +637,7 @@ static av_cold int sonic_encode_init(AVCodecContext *avctx)
     for (i = 0; i < s->num_taps; i++)
         s->tap_quant[i] = ff_sqrt(i+1);
 
-    s->channels = avctx->channels;
+    s->channels = avctx->ch_layout.nb_channels;
     s->samplerate = avctx->sample_rate;
 
     s->block_align = 2048LL*s->samplerate/(44100*s->downsampling);
@@ -853,7 +853,7 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx)
     int i;
     int ret;
 
-    s->channels = avctx->channels;
+    s->channels = avctx->ch_layout.nb_channels;
     s->samplerate = avctx->sample_rate;
 
     if (!avctx->extradata)
@@ -896,7 +896,9 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
         return AVERROR_INVALIDDATA;
     }
-    avctx->channels = s->channels;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    avctx->ch_layout.nb_channels = s->channels;
 
     s->lossless = get_bits1(&gb);
     if (!s->lossless)
@@ -989,7 +991,7 @@ static int sonic_decode_frame(AVCodecContext *avctx,
 
     if (buf_size == 0) return 0;
 
-    frame->nb_samples = s->frame_size / avctx->channels;
+    frame->nb_samples = s->frame_size / avctx->ch_layout.nb_channels;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
     samples = (int16_t *)frame->data[0];
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 261/281] speex: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (261 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 260/281] sonic: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 262/281] tak: " James Almer
                   ` (19 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/speexdec.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavcodec/speexdec.c b/libavcodec/speexdec.c
index dcbdf5e010..7b482f5390 100644
--- a/libavcodec/speexdec.c
+++ b/libavcodec/speexdec.c
@@ -1450,7 +1450,7 @@ static av_cold int speex_decode_init(AVCodecContext *avctx)
         if (s->rate <= 0)
             return AVERROR_INVALIDDATA;
 
-        s->nb_channels = avctx->channels;
+        s->nb_channels = avctx->ch_layout.nb_channels;
         if (s->nb_channels <= 0)
             return AVERROR_INVALIDDATA;
 
@@ -1492,7 +1492,9 @@ static av_cold int speex_decode_init(AVCodecContext *avctx)
 
     if (s->bitrate > 0)
         avctx->bit_rate = s->bitrate;
-    avctx->channels = s->nb_channels;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    avctx->ch_layout.nb_channels = s->nb_channels;
     avctx->sample_rate = s->rate;
     avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
 
@@ -1554,12 +1556,12 @@ static int speex_decode_frame(AVCodecContext *avctx, void *data,
         ret = speex_modes[s->mode].decode(avctx, &s->st[s->mode], &s->gb, dst + i * s->frame_size);
         if (ret < 0)
             return ret;
-        if (avctx->channels == 2)
+        if (avctx->ch_layout.nb_channels == 2)
             speex_decode_stereo(dst + i * s->frame_size, s->frame_size, &s->stereo);
     }
 
     dst = (float *)frame->extended_data[0];
-    s->fdsp->vector_fmul_scalar(dst, dst, scale, frame->nb_samples * frame->channels);
+    s->fdsp->vector_fmul_scalar(dst, dst, scale, frame->nb_samples * frame->ch_layout.nb_channels);
     frame->nb_samples = s->frame_size * s->frames_per_packet;
 
     *got_frame_ptr = 1;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 262/281] tak: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (262 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 261/281] speex: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 263/281] truespeech: " James Almer
                   ` (18 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/takdec.c | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c
index 926dbf611e..15543098b5 100644
--- a/libavcodec/takdec.c
+++ b/libavcodec/takdec.c
@@ -734,9 +734,14 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
         avctx->sample_rate = s->ti.sample_rate;
         set_sample_rate_params(avctx);
     }
-    if (s->ti.ch_layout)
-        avctx->channel_layout = s->ti.ch_layout;
-    avctx->channels = s->ti.channels;
+
+    av_channel_layout_uninit(&avctx->ch_layout);
+    if (s->ti.ch_layout) {
+        av_channel_layout_from_mask(&avctx->ch_layout, s->ti.ch_layout);
+    } else {
+        avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        avctx->ch_layout.nb_channels = s->ti.channels;
+    }
 
     s->nb_samples = s->ti.last_frame_samples ? s->ti.last_frame_samples
                                              : s->ti.frame_samples;
@@ -747,7 +752,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
     ff_thread_finish_setup(avctx);
 
     if (avctx->bits_per_raw_sample <= 16) {
-        int buf_size = av_samples_get_buffer_size(NULL, avctx->channels,
+        int buf_size = av_samples_get_buffer_size(NULL, avctx->ch_layout.nb_channels,
                                                   s->nb_samples,
                                                   AV_SAMPLE_FMT_S32P, 0);
         if (buf_size < 0)
@@ -756,28 +761,28 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
         if (!s->decode_buffer)
             return AVERROR(ENOMEM);
         ret = av_samples_fill_arrays((uint8_t **)s->decoded, NULL,
-                                     s->decode_buffer, avctx->channels,
+                                     s->decode_buffer, avctx->ch_layout.nb_channels,
                                      s->nb_samples, AV_SAMPLE_FMT_S32P, 0);
         if (ret < 0)
             return ret;
     } else {
-        for (chan = 0; chan < avctx->channels; chan++)
+        for (chan = 0; chan < avctx->ch_layout.nb_channels; chan++)
             s->decoded[chan] = (int32_t *)frame->extended_data[chan];
     }
 
     if (s->nb_samples < 16) {
-        for (chan = 0; chan < avctx->channels; chan++) {
+        for (chan = 0; chan < avctx->ch_layout.nb_channels; chan++) {
             int32_t *decoded = s->decoded[chan];
             for (i = 0; i < s->nb_samples; i++)
                 decoded[i] = get_sbits(gb, avctx->bits_per_raw_sample);
         }
     } else {
         if (s->ti.codec == TAK_CODEC_MONO_STEREO) {
-            for (chan = 0; chan < avctx->channels; chan++)
+            for (chan = 0; chan < avctx->ch_layout.nb_channels; chan++)
                 if (ret = decode_channel(s, chan))
                     return ret;
 
-            if (avctx->channels == 2) {
+            if (avctx->ch_layout.nb_channels == 2) {
                 s->nb_subframes = get_bits(gb, 1) + 1;
                 if (s->nb_subframes > 1) {
                     s->subframe_len[1] = get_bits(gb, 6);
@@ -792,13 +797,13 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
                 int ch_mask = 0;
 
                 chan = get_bits(gb, 4) + 1;
-                if (chan > avctx->channels)
+                if (chan > avctx->ch_layout.nb_channels)
                     return AVERROR_INVALIDDATA;
 
                 for (i = 0; i < chan; i++) {
                     int nbit = get_bits(gb, 4);
 
-                    if (nbit >= avctx->channels)
+                    if (nbit >= avctx->ch_layout.nb_channels)
                         return AVERROR_INVALIDDATA;
 
                     if (ch_mask & 1 << nbit)
@@ -808,10 +813,10 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
                     if (s->mcdparams[i].present) {
                         s->mcdparams[i].index = get_bits(gb, 2);
                         s->mcdparams[i].chan2 = get_bits(gb, 4);
-                        if (s->mcdparams[i].chan2 >= avctx->channels) {
+                        if (s->mcdparams[i].chan2 >= avctx->ch_layout.nb_channels) {
                             av_log(avctx, AV_LOG_ERROR,
                                    "invalid channel 2 (%d) for %d channel(s)\n",
-                                   s->mcdparams[i].chan2, avctx->channels);
+                                   s->mcdparams[i].chan2, avctx->ch_layout.nb_channels);
                             return AVERROR_INVALIDDATA;
                         }
                         if (s->mcdparams[i].index == 1) {
@@ -829,7 +834,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
                     ch_mask |= 1 << nbit;
                 }
             } else {
-                chan = avctx->channels;
+                chan = avctx->ch_layout.nb_channels;
                 for (i = 0; i < chan; i++) {
                     s->mcdparams[i].present = 0;
                     s->mcdparams[i].chan1   = i;
@@ -855,7 +860,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
             }
         }
 
-        for (chan = 0; chan < avctx->channels; chan++) {
+        for (chan = 0; chan < avctx->ch_layout.nb_channels; chan++) {
             int32_t *decoded = s->decoded[chan];
 
             if (s->lpc_mode[chan])
@@ -886,7 +891,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
     /* convert to output buffer */
     switch (avctx->sample_fmt) {
     case AV_SAMPLE_FMT_U8P:
-        for (chan = 0; chan < avctx->channels; chan++) {
+        for (chan = 0; chan < avctx->ch_layout.nb_channels; chan++) {
             uint8_t *samples = (uint8_t *)frame->extended_data[chan];
             int32_t *decoded = s->decoded[chan];
             for (i = 0; i < s->nb_samples; i++)
@@ -894,7 +899,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
         }
         break;
     case AV_SAMPLE_FMT_S16P:
-        for (chan = 0; chan < avctx->channels; chan++) {
+        for (chan = 0; chan < avctx->ch_layout.nb_channels; chan++) {
             int16_t *samples = (int16_t *)frame->extended_data[chan];
             int32_t *decoded = s->decoded[chan];
             for (i = 0; i < s->nb_samples; i++)
@@ -902,7 +907,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
         }
         break;
     case AV_SAMPLE_FMT_S32P:
-        for (chan = 0; chan < avctx->channels; chan++) {
+        for (chan = 0; chan < avctx->ch_layout.nb_channels; chan++) {
             int32_t *samples = (int32_t *)frame->extended_data[chan];
             for (i = 0; i < s->nb_samples; i++)
                 samples[i] *= 1U << 8;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 263/281] truespeech: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (263 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 262/281] tak: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 264/281] tta: " James Almer
                   ` (17 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/truespeech.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c
index a65ced15d7..30a7e86a75 100644
--- a/libavcodec/truespeech.c
+++ b/libavcodec/truespeech.c
@@ -64,12 +64,13 @@ static av_cold int truespeech_decode_init(AVCodecContext * avctx)
 {
     TSContext *c = avctx->priv_data;
 
-    if (avctx->channels != 1) {
-        avpriv_request_sample(avctx, "Channel count %d", avctx->channels);
+    if (avctx->ch_layout.nb_channels != 1) {
+        avpriv_request_sample(avctx, "Channel count %d", avctx->ch_layout.nb_channels);
         return AVERROR_PATCHWELCOME;
     }
 
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
 
     ff_bswapdsp_init(&c->bdsp);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 264/281] tta: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (264 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 263/281] truespeech: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 265/281] twinvq: " James Almer
                   ` (16 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/tta.c    | 18 +++++++++++++-----
 libavcodec/ttaenc.c | 14 +++++++-------
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/libavcodec/tta.c b/libavcodec/tta.c
index 17b4ca9032..fed18451eb 100644
--- a/libavcodec/tta.c
+++ b/libavcodec/tta.c
@@ -113,7 +113,7 @@ static int allocate_buffers(AVCodecContext *avctx)
             return AVERROR(ENOMEM);
     } else
         s->decode_buffer = NULL;
-    s->ch_ctx = av_malloc_array(avctx->channels, sizeof(*s->ch_ctx));
+    s->ch_ctx = av_malloc_array(avctx->ch_layout.nb_channels, sizeof(*s->ch_ctx));
     if (!s->ch_ctx) {
         av_freep(&s->decode_buffer);
         return AVERROR(ENOMEM);
@@ -156,9 +156,17 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
             }
             AV_WL64(s->crc_pass, tta_check_crc64(s->pass));
         }
-        avctx->channels = s->channels = get_bits(&gb, 16);
-        if (s->channels > 1 && s->channels < 9)
-            avctx->channel_layout = tta_channel_layouts[s->channels-2];
+
+        s->channels = get_bits(&gb, 16);
+
+        av_channel_layout_uninit(&avctx->ch_layout);
+        if (s->channels > 1 && s->channels < 9) {
+            av_channel_layout_from_mask(&avctx->ch_layout, tta_channel_layouts[s->channels-2]);
+        } else {
+            avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            avctx->ch_layout.nb_channels = s->channels;
+        }
+
         avctx->bits_per_raw_sample = get_bits(&gb, 16);
         s->bps = (avctx->bits_per_raw_sample + 7) / 8;
         avctx->sample_rate = get_bits_long(&gb, 32);
@@ -199,7 +207,7 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
                        (s->last_frame_length ? 1 : 0);
 
         av_log(avctx, AV_LOG_DEBUG, "format: %d chans: %d bps: %d rate: %d block: %d\n",
-            s->format, avctx->channels, avctx->bits_per_coded_sample, avctx->sample_rate,
+            s->format, avctx->ch_layout.nb_channels, avctx->bits_per_coded_sample, avctx->sample_rate,
             avctx->block_align);
         av_log(avctx, AV_LOG_DEBUG, "data_length: %d frame_length: %d last: %d total: %d\n",
             s->data_length, s->frame_length, s->last_frame_length, total_frames);
diff --git a/libavcodec/ttaenc.c b/libavcodec/ttaenc.c
index addaf30bb5..5717ec22d1 100644
--- a/libavcodec/ttaenc.c
+++ b/libavcodec/ttaenc.c
@@ -56,7 +56,7 @@ static av_cold int tta_encode_init(AVCodecContext *avctx)
     s->bps = avctx->bits_per_raw_sample >> 3;
     avctx->frame_size = 256 * avctx->sample_rate / 245;
 
-    s->ch_ctx = av_malloc_array(avctx->channels, sizeof(*s->ch_ctx));
+    s->ch_ctx = av_malloc_array(avctx->ch_layout.nb_channels, sizeof(*s->ch_ctx));
     if (!s->ch_ctx)
         return AVERROR(ENOMEM);
 
@@ -89,7 +89,7 @@ static int tta_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     TTAEncContext *s = avctx->priv_data;
     PutBitContext pb;
     int ret, i, out_bytes, cur_chan, res, samples;
-    int64_t pkt_size =  frame->nb_samples * 2LL * avctx->channels * s->bps;
+    int64_t pkt_size =  frame->nb_samples * 2LL * avctx->ch_layout.nb_channels * s->bps;
 
 pkt_alloc:
     cur_chan = 0, res = 0, samples = 0;
@@ -98,13 +98,13 @@ pkt_alloc:
     init_put_bits(&pb, avpkt->data, avpkt->size);
 
     // init per channel states
-    for (i = 0; i < avctx->channels; i++) {
+    for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
         s->ch_ctx[i].predictor = 0;
         ff_tta_filter_init(&s->ch_ctx[i].filter, ff_tta_filter_configs[s->bps - 1]);
         ff_tta_rice_init(&s->ch_ctx[i].rice, 10, 10);
     }
 
-    for (i = 0; i < frame->nb_samples * avctx->channels; i++) {
+    for (i = 0; i < frame->nb_samples * avctx->ch_layout.nb_channels; i++) {
         TTAChannel *c = &s->ch_ctx[cur_chan];
         TTAFilter *filter = &c->filter;
         TTARice *rice = &c->rice;
@@ -113,8 +113,8 @@ pkt_alloc:
 
         value = get_sample(frame, samples++, avctx->sample_fmt);
 
-        if (avctx->channels > 1) {
-            if (cur_chan < avctx->channels - 1)
+        if (avctx->ch_layout.nb_channels > 1) {
+            if (cur_chan < avctx->ch_layout.nb_channels - 1)
                 value  = res = get_sample(frame, samples, avctx->sample_fmt) - value;
             else
                 value -= res / 2;
@@ -176,7 +176,7 @@ pkt_alloc:
         if (k)
             put_bits(&pb, k, outval & (ff_tta_shift_1[k] - 1));
 
-        if (cur_chan < avctx->channels - 1)
+        if (cur_chan < avctx->ch_layout.nb_channels - 1)
             cur_chan++;
         else
             cur_chan = 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 265/281] twinvq: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (265 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 264/281] tta: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 266/281] vima: " James Almer
                   ` (15 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/twinvq.c    | 20 +++++++++++---------
 libavcodec/twinvqdec.c | 18 +++++++++---------
 2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/libavcodec/twinvq.c b/libavcodec/twinvq.c
index 6dfaf06b14..ba9672a41f 100644
--- a/libavcodec/twinvq.c
+++ b/libavcodec/twinvq.c
@@ -217,17 +217,18 @@ static void dec_gain(TwinVQContext *tctx,
     const TwinVQModeTab   *mtab =  tctx->mtab;
     const TwinVQFrameData *bits = &tctx->bits[tctx->cur_frame];
     int i, j;
+    int channels   = tctx->avctx->ch_layout.nb_channels;
     int sub        = mtab->fmode[ftype].sub;
     float step     = TWINVQ_AMP_MAX     / ((1 << TWINVQ_GAIN_BITS)     - 1);
     float sub_step = TWINVQ_SUB_AMP_MAX / ((1 << TWINVQ_SUB_GAIN_BITS) - 1);
 
     if (ftype == TWINVQ_FT_LONG) {
-        for (i = 0; i < tctx->avctx->channels; i++)
+        for (i = 0; i < channels; i++)
             out[i] = (1.0 / (1 << 13)) *
                      twinvq_mulawinv(step * 0.5 + step * bits->gain_bits[i],
                                      TWINVQ_AMP_MAX, TWINVQ_MULAW_MU);
     } else {
-        for (i = 0; i < tctx->avctx->channels; i++) {
+        for (i = 0; i < channels; i++) {
             float val = (1.0 / (1 << 23)) *
                         twinvq_mulawinv(step * 0.5 + step * bits->gain_bits[i],
                                         TWINVQ_AMP_MAX, TWINVQ_MULAW_MU);
@@ -380,10 +381,11 @@ static void imdct_output(TwinVQContext *tctx, enum TwinVQFrameType ftype,
 {
     const TwinVQModeTab *mtab = tctx->mtab;
     float *prev_buf           = tctx->prev_frame + tctx->last_block_pos[0];
+    int channels              = tctx->avctx->ch_layout.nb_channels;
     int size1, size2, i;
     float *out1, *out2;
 
-    for (i = 0; i < tctx->avctx->channels; i++)
+    for (i = 0; i < channels; i++)
         imdct_and_window(tctx, ftype, wtype,
                          tctx->spectrum + i * mtab->size,
                          prev_buf + 2 * i * mtab->size,
@@ -399,7 +401,7 @@ static void imdct_output(TwinVQContext *tctx, enum TwinVQFrameType ftype,
     memcpy(out1,         prev_buf,         size1 * sizeof(*out1));
     memcpy(out1 + size1, tctx->curr_frame, size2 * sizeof(*out1));
 
-    if (tctx->avctx->channels == 2) {
+    if (channels == 2) {
         out2 = &out[1][0] + offset;
         memcpy(out2, &prev_buf[2 * mtab->size],
                size1 * sizeof(*out2));
@@ -414,7 +416,7 @@ static void read_and_decode_spectrum(TwinVQContext *tctx, float *out,
 {
     const TwinVQModeTab *mtab = tctx->mtab;
     TwinVQFrameData *bits     = &tctx->bits[tctx->cur_frame];
-    int channels              = tctx->avctx->channels;
+    int channels              = tctx->avctx->ch_layout.nb_channels;
     int sub        = mtab->fmode[ftype].sub;
     int block_size = mtab->size / sub;
     float gain[TWINVQ_CHANNELS_MAX * TWINVQ_SUBBLOCKS_MAX];
@@ -536,7 +538,7 @@ static av_cold int init_mdct_win(TwinVQContext *tctx)
     const TwinVQModeTab *mtab = tctx->mtab;
     int size_s = mtab->size / mtab->fmode[TWINVQ_FT_SHORT].sub;
     int size_m = mtab->size / mtab->fmode[TWINVQ_FT_MEDIUM].sub;
-    int channels = tctx->avctx->channels;
+    int channels = tctx->avctx->ch_layout.nb_channels;
     float norm = channels == 1 ? 2.0 : 1.0;
     int table_size = 2 * mtab->size * channels;
 
@@ -645,10 +647,10 @@ static av_cold void construct_perm_table(TwinVQContext *tctx,
     int16_t *tmp_perm = (int16_t *)tctx->tmp_buf;
 
     if (ftype == TWINVQ_FT_PPC) {
-        size       = tctx->avctx->channels;
+        size       = tctx->avctx->ch_layout.nb_channels;
         block_size = mtab->ppc_shape_len;
     } else {
-        size       = tctx->avctx->channels * mtab->fmode[ftype].sub;
+        size       = tctx->avctx->ch_layout.nb_channels * mtab->fmode[ftype].sub;
         block_size = mtab->size / mtab->fmode[ftype].sub;
     }
 
@@ -666,7 +668,7 @@ static av_cold void construct_perm_table(TwinVQContext *tctx,
 static av_cold void init_bitstream_params(TwinVQContext *tctx)
 {
     const TwinVQModeTab *mtab = tctx->mtab;
-    int n_ch                  = tctx->avctx->channels;
+    int n_ch                  = tctx->avctx->ch_layout.nb_channels;
     int total_fr_bits         = tctx->avctx->bit_rate * mtab->size /
                                 tctx->avctx->sample_rate;
 
diff --git a/libavcodec/twinvqdec.c b/libavcodec/twinvqdec.c
index 1fbe0bc32e..98702c7ef2 100644
--- a/libavcodec/twinvqdec.c
+++ b/libavcodec/twinvqdec.c
@@ -181,7 +181,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
 {
     const TwinVQModeTab *mtab = tctx->mtab;
     int isampf = tctx->avctx->sample_rate /  1000;
-    int ibps   = tctx->avctx->bit_rate    / (1000 * tctx->avctx->channels);
+    int ibps   = tctx->avctx->bit_rate    / (1000 * tctx->avctx->ch_layout.nb_channels);
     int min_period   = ROUNDED_DIV(40 * 2 * mtab->size, isampf);
     int max_period   = ROUNDED_DIV(40 * 2 * mtab->size * 6, isampf);
     int period_range = max_period - min_period;
@@ -254,7 +254,7 @@ static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,
 {
     TwinVQFrameData     *bits = &tctx->bits[0];
     const TwinVQModeTab *mtab = tctx->mtab;
-    int channels              = tctx->avctx->channels;
+    int channels              = tctx->avctx->ch_layout.nb_channels;
     int sub;
     GetBitContext gb;
     int i, j, k, ret;
@@ -319,14 +319,14 @@ static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,
 
 static av_cold int twinvq_decode_init(AVCodecContext *avctx)
 {
-    int isampf, ibps;
+    int isampf, ibps, channels;
     TwinVQContext *tctx = avctx->priv_data;
 
     if (!avctx->extradata || avctx->extradata_size < 12) {
         av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n");
         return AVERROR_INVALIDDATA;
     }
-    avctx->channels = AV_RB32(avctx->extradata)     + 1;
+    channels        = AV_RB32(avctx->extradata)     + 1;
     avctx->bit_rate = AV_RB32(avctx->extradata + 4) * 1000;
     isampf          = AV_RB32(avctx->extradata + 8);
 
@@ -349,15 +349,15 @@ static av_cold int twinvq_decode_init(AVCodecContext *avctx)
         break;
     }
 
-    if (avctx->channels <= 0 || avctx->channels > TWINVQ_CHANNELS_MAX) {
+    if (channels <= 0 || channels > TWINVQ_CHANNELS_MAX) {
         av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n",
-               avctx->channels);
+               channels);
         return -1;
     }
-    avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
-                                                 : AV_CH_LAYOUT_STEREO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_default(&avctx->ch_layout, channels);
 
-    ibps = avctx->bit_rate / (1000 * avctx->channels);
+    ibps = avctx->bit_rate / (1000 * channels);
     if (ibps < 8 || ibps > 48) {
         av_log(avctx, AV_LOG_ERROR, "Bad bitrate per channel value %d\n", ibps);
         return AVERROR_INVALIDDATA;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 266/281] vima: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (266 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 265/281] twinvq: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 267/281] vmdaudio: " James Almer
                   ` (14 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/vima.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/vima.c b/libavcodec/vima.c
index c9a81e4401..5053feda90 100644
--- a/libavcodec/vima.c
+++ b/libavcodec/vima.c
@@ -147,9 +147,8 @@ static int decode_frame(AVCodecContext *avctx, void *data,
         channel_hint[0] = ~channel_hint[0];
         channels = 2;
     }
-    avctx->channels = channels;
-    avctx->channel_layout = (channels == 2) ? AV_CH_LAYOUT_STEREO
-                                            : AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_default(&avctx->ch_layout, channels);
     pcm_data[0] = get_sbits(&gb, 16);
     if (channels > 1) {
         channel_hint[1] = get_sbits(&gb, 8);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 267/281] vmdaudio: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (267 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 266/281] vima: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 268/281] vorbis: " James Almer
                   ` (13 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/vmdaudio.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/libavcodec/vmdaudio.c b/libavcodec/vmdaudio.c
index 53aef660ef..5e04686cb1 100644
--- a/libavcodec/vmdaudio.c
+++ b/libavcodec/vmdaudio.c
@@ -71,20 +71,20 @@ static const uint16_t vmdaudio_table[128] = {
 static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
 {
     VmdAudioContext *s = avctx->priv_data;
+    int channels = avctx->ch_layout.nb_channels;
 
-    if (avctx->channels < 1 || avctx->channels > 2) {
+    if (channels < 1 || channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
         return AVERROR(EINVAL);
     }
-    if (avctx->block_align < 1 || avctx->block_align % avctx->channels ||
-        avctx->block_align > INT_MAX - avctx->channels
-    ) {
+    if (avctx->block_align < 1 || avctx->block_align % channels ||
+        avctx->block_align > INT_MAX - channels) {
         av_log(avctx, AV_LOG_ERROR, "invalid block align\n");
         return AVERROR(EINVAL);
     }
 
-    avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
-                                                   AV_CH_LAYOUT_STEREO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_default(&avctx->ch_layout, channels == 1);
 
     if (avctx->bits_per_coded_sample == 16)
         avctx->sample_fmt = AV_SAMPLE_FMT_S16;
@@ -92,11 +92,11 @@ static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
         avctx->sample_fmt = AV_SAMPLE_FMT_U8;
     s->out_bps = av_get_bytes_per_sample(avctx->sample_fmt);
 
-    s->chunk_size = avctx->block_align + avctx->channels * (s->out_bps == 2);
+    s->chunk_size = avctx->block_align + channels * (s->out_bps == 2);
 
     av_log(avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, "
            "block align = %d, sample rate = %d\n",
-           avctx->channels, avctx->bits_per_coded_sample, avctx->block_align,
+           channels, avctx->bits_per_coded_sample, avctx->block_align,
            avctx->sample_rate);
 
     return 0;
@@ -143,6 +143,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
     int ret;
     uint8_t *output_samples_u8;
     int16_t *output_samples_s16;
+    int channels = avctx->ch_layout.nb_channels;
 
     if (buf_size < 16) {
         av_log(avctx, AV_LOG_WARNING, "skipping small junk packet\n");
@@ -186,7 +187,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
 
     /* get output buffer */
     frame->nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) /
-                        avctx->channels;
+                        avctx->ch_layout.nb_channels;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
     output_samples_u8  =            frame->data[0];
@@ -195,7 +196,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
     /* decode silent chunks */
     if (silent_chunks > 0) {
         int silent_size = avctx->block_align * silent_chunks;
-        av_assert0(avctx->block_align * silent_chunks <= frame->nb_samples * avctx->channels);
+        av_assert0(avctx->block_align * silent_chunks <= frame->nb_samples * avctx->ch_layout.nb_channels);
 
         if (s->out_bps == 2) {
             memset(output_samples_s16, 0x00, silent_size * 2);
@@ -209,11 +210,10 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
     /* decode audio chunks */
     if (audio_chunks > 0) {
         buf_end = buf + buf_size;
-        av_assert0((buf_size & (avctx->channels > 1)) == 0);
+        av_assert0((buf_size & (avctx->ch_layout.nb_channels > 1)) == 0);
         while (buf_end - buf >= s->chunk_size) {
             if (s->out_bps == 2) {
-                decode_audio_s16(output_samples_s16, buf, s->chunk_size,
-                                 avctx->channels);
+                decode_audio_s16(output_samples_s16, buf, s->chunk_size, channels);
                 output_samples_s16 += avctx->block_align;
             } else {
                 memcpy(output_samples_u8, buf, s->chunk_size);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 268/281] vorbis: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (268 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 267/281] vmdaudio: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 269/281] wavpack: " James Almer
                   ` (12 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/vorbisdec.c | 27 +++++++++++++++++----------
 libavcodec/vorbisenc.c |  7 ++++---
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index 6e07bc5a8a..d961dc37b9 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -1077,12 +1077,14 @@ static av_cold int vorbis_decode_init(AVCodecContext *avctx)
         return ret;
     }
 
-    if (vc->audio_channels > 8)
-        avctx->channel_layout = 0;
-    else
-        avctx->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 1];
+    av_channel_layout_uninit(&avctx->ch_layout);
+    if (vc->audio_channels > 8) {
+        avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        avctx->ch_layout.nb_channels = vc->audio_channels;
+    } else {
+        av_channel_layout_copy(&avctx->ch_layout, &ff_vorbis_ch_layouts[vc->audio_channels - 1]);
+    }
 
-    avctx->channels    = vc->audio_channels;
     avctx->sample_rate = vc->audio_samplerate;
 
     return 0;
@@ -1788,12 +1790,14 @@ static int vorbis_decode_frame(AVCodecContext *avctx, void *data,
             return ret;
         }
 
-        if (vc->audio_channels > 8)
-            avctx->channel_layout = 0;
-        else
-            avctx->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 1];
+        av_channel_layout_uninit(&avctx->ch_layout);
+        if (vc->audio_channels > 8) {
+            avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            avctx->ch_layout.nb_channels = vc->audio_channels;
+        } else {
+            av_channel_layout_copy(&avctx->ch_layout, &ff_vorbis_ch_layouts[vc->audio_channels - 1]);
+        }
 
-        avctx->channels    = vc->audio_channels;
         avctx->sample_rate = vc->audio_samplerate;
         return buf_size;
     }
@@ -1892,7 +1896,10 @@ const AVCodec ff_vorbis_decoder = {
     .flush           = vorbis_decode_flush,
     .capabilities    = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
     .caps_internal   = FF_CODEC_CAP_INIT_CLEANUP,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts = ff_vorbis_channel_layouts,
+#endif
+    .ch_layouts      = ff_vorbis_ch_layouts,
     .sample_fmts     = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
                                                        AV_SAMPLE_FMT_NONE },
 };
diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index 858c6ac6dd..30b75ab3f6 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -276,7 +276,7 @@ static int create_vorbis_context(vorbis_enc_context *venc,
     const uint8_t *clens, *quant;
     int i, book, ret;
 
-    venc->channels    = avctx->channels;
+    venc->channels    = avctx->ch_layout.nb_channels;
     venc->sample_rate = avctx->sample_rate;
     venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
 
@@ -1038,7 +1038,8 @@ static AVFrame *spawn_empty_frame(AVCodecContext *avctx, int channels)
 
     f->format = avctx->sample_fmt;
     f->nb_samples = avctx->frame_size;
-    f->channel_layout = avctx->channel_layout;
+    f->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    f->ch_layout.nb_channels = channels;
 
     if (av_frame_get_buffer(f, 4)) {
         av_frame_free(&f);
@@ -1267,7 +1268,7 @@ static av_cold int vorbis_encode_init(AVCodecContext *avctx)
     vorbis_enc_context *venc = avctx->priv_data;
     int ret;
 
-    if (avctx->channels != 2) {
+    if (avctx->ch_layout.nb_channels != 2) {
         av_log(avctx, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n");
         return -1;
     }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 269/281] wavpack: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (269 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 268/281] vorbis: " James Almer
@ 2022-01-13  2:07 ` James Almer
  2022-03-07 10:42   ` Anton Khirnov
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 270/281] wma: " James Almer
                   ` (11 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  2:07 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/wavpack.c    | 51 ++++++++++++++++++-----------------------
 libavcodec/wavpackenc.c | 29 ++++++++++++-----------
 2 files changed, 37 insertions(+), 43 deletions(-)

diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index 6b2ec19bf1..e0350ce732 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -1412,25 +1412,23 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
                 size = bytestream2_get_byte(&gb);
                 chan  |= (bytestream2_get_byte(&gb) & 0xF) << 8;
                 chan  += 1;
-                if (avctx->channels != chan)
+                if (avctx->ch_layout.nb_channels != chan)
                     av_log(avctx, AV_LOG_WARNING, "%i channels signalled"
-                           " instead of %i.\n", chan, avctx->channels);
+                           " instead of %i.\n", chan, avctx->ch_layout.nb_channels);
                 chmask = bytestream2_get_le24(&gb);
                 break;
             case 5:
                 size = bytestream2_get_byte(&gb);
                 chan  |= (bytestream2_get_byte(&gb) & 0xF) << 8;
                 chan  += 1;
-                if (avctx->channels != chan)
+                if (avctx->ch_layout.nb_channels != chan)
                     av_log(avctx, AV_LOG_WARNING, "%i channels signalled"
-                           " instead of %i.\n", chan, avctx->channels);
+                           " instead of %i.\n", chan, avctx->ch_layout.nb_channels);
                 chmask = bytestream2_get_le32(&gb);
                 break;
             default:
                 av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n",
                        size);
-                chan   = avctx->channels;
-                chmask = avctx->channel_layout;
             }
             break;
         case WP_ID_SAMPLE_RATE:
@@ -1494,8 +1492,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
     }
 
     if (!wc->ch_offset) {
-        int      new_channels = avctx->channels;
-        uint64_t new_chmask   = avctx->channel_layout;
+        AVChannelLayout new_ch_layout = { 0 };
         int new_samplerate;
         int sr = (s->frame_flags >> 23) & 0xf;
         if (sr == 0xf) {
@@ -1512,36 +1509,32 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
         new_samplerate *= rate_x;
 
         if (multiblock) {
-            if (chan)
-                new_channels = chan;
-            if (chmask)
-                new_chmask = chmask;
+            if (chmask) {
+                av_channel_layout_from_mask(&new_ch_layout, chmask);
+                if (chan && new_ch_layout.nb_channels != chan) {
+                    av_log(avctx, AV_LOG_ERROR, "Channel mask does not match the channel count\n");
+                    return AVERROR_INVALIDDATA;
+                }
+            } else
+                av_channel_layout_copy(&new_ch_layout, &avctx->ch_layout);
         } else {
-            new_channels = s->stereo ? 2 : 1;
-            new_chmask   = s->stereo ? AV_CH_LAYOUT_STEREO :
-                                       AV_CH_LAYOUT_MONO;
-        }
-
-        if (new_chmask &&
-            av_get_channel_layout_nb_channels(new_chmask) != new_channels) {
-            av_log(avctx, AV_LOG_ERROR, "Channel mask does not match the channel count\n");
-            return AVERROR_INVALIDDATA;
+            av_channel_layout_default(&new_ch_layout, s->stereo + 1);
         }
 
         /* clear DSD state if stream properties change */
-        if (new_channels   != wc->dsd_channels      ||
-            new_chmask     != avctx->channel_layout ||
+        if (new_ch_layout.nb_channels != wc->dsd_channels ||
+            av_channel_layout_compare(&new_ch_layout, &avctx->ch_layout) ||
             new_samplerate != avctx->sample_rate    ||
             !!got_dsd      != !!wc->dsdctx) {
-            ret = wv_dsd_reset(wc, got_dsd ? new_channels : 0);
+            ret = wv_dsd_reset(wc, got_dsd ? new_ch_layout.nb_channels : 0);
             if (ret < 0) {
                 av_log(avctx, AV_LOG_ERROR, "Error reinitializing the DSD context\n");
                 return ret;
             }
             ff_thread_release_buffer(avctx, &wc->curr_frame);
         }
-        avctx->channels            = new_channels;
-        avctx->channel_layout      = new_chmask;
+        av_channel_layout_uninit(&avctx->ch_layout);
+        av_channel_layout_copy(&avctx->ch_layout, &new_ch_layout);
         avctx->sample_rate         = new_samplerate;
         avctx->sample_fmt          = sample_fmt;
         avctx->bits_per_raw_sample = orig_bpp;
@@ -1558,7 +1551,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
         ff_thread_finish_setup(avctx);
     }
 
-    if (wc->ch_offset + s->stereo >= avctx->channels) {
+    if (wc->ch_offset + s->stereo >= avctx->ch_layout.nb_channels) {
         av_log(avctx, AV_LOG_WARNING, "Too many channels coded in a packet.\n");
         return ((avctx->err_recognition & AV_EF_EXPLODE) || !wc->ch_offset) ? AVERROR_INVALIDDATA : 0;
     }
@@ -1668,7 +1661,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
         buf_size -= frame_size;
     }
 
-    if (s->ch_offset != avctx->channels) {
+    if (s->ch_offset != avctx->ch_layout.nb_channels) {
         av_log(avctx, AV_LOG_ERROR, "Not enough channels coded in a packet.\n");
         ret = AVERROR_INVALIDDATA;
         goto error;
@@ -1678,7 +1671,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
     ff_thread_release_buffer(avctx, &s->prev_frame);
 
     if (s->modulation == MODULATION_DSD)
-        avctx->execute2(avctx, dsd_channel, s->frame, NULL, avctx->channels);
+        avctx->execute2(avctx, dsd_channel, s->frame, NULL, avctx->ch_layout.nb_channels);
 
     ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
 
diff --git a/libavcodec/wavpackenc.c b/libavcodec/wavpackenc.c
index dc4f4e303b..bc1049db0a 100644
--- a/libavcodec/wavpackenc.c
+++ b/libavcodec/wavpackenc.c
@@ -130,8 +130,8 @@ static av_cold int wavpack_encode_init(AVCodecContext *avctx)
 
     s->avctx = avctx;
 
-    if (avctx->channels > 255) {
-        av_log(avctx, AV_LOG_ERROR, "Invalid channel count: %d\n", avctx->channels);
+    if (avctx->ch_layout.nb_channels > 255) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid channel count: %d\n", avctx->ch_layout.nb_channels);
         return AVERROR(EINVAL);
     }
 
@@ -142,10 +142,10 @@ static av_cold int wavpack_encode_init(AVCodecContext *avctx)
         else
             block_samples = avctx->sample_rate;
 
-        while (block_samples * avctx->channels > WV_MAX_SAMPLES)
+        while (block_samples * avctx->ch_layout.nb_channels > WV_MAX_SAMPLES)
             block_samples /= 2;
 
-        while (block_samples * avctx->channels < 40000)
+        while (block_samples * avctx->ch_layout.nb_channels < 40000)
             block_samples *= 2;
         avctx->frame_size = block_samples;
     } else if (avctx->frame_size && (avctx->frame_size < 128 ||
@@ -2572,7 +2572,7 @@ static int wavpack_encode_block(WavPackEncodeContext *s,
 
     s->ch_offset += 1 + !(s->flags & WV_MONO);
 
-    if (s->ch_offset == s->avctx->channels)
+    if (s->ch_offset == s->avctx->ch_layout.nb_channels)
         s->flags |= WV_FINAL_BLOCK;
 
     bytestream2_init_writer(&pb, out, out_size);
@@ -2587,11 +2587,12 @@ static int wavpack_encode_block(WavPackEncodeContext *s,
     bytestream2_put_le32(&pb, crc);
 
     if (s->flags & WV_INITIAL_BLOCK &&
-        s->avctx->channel_layout != AV_CH_LAYOUT_MONO &&
-        s->avctx->channel_layout != AV_CH_LAYOUT_STEREO) {
+        s->avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
+        s->avctx->ch_layout.u.mask != AV_CH_LAYOUT_MONO &&
+        s->avctx->ch_layout.u.mask != AV_CH_LAYOUT_STEREO) {
         put_metadata_block(&pb, WP_ID_CHANINFO, 5);
-        bytestream2_put_byte(&pb, s->avctx->channels);
-        bytestream2_put_le32(&pb, s->avctx->channel_layout);
+        bytestream2_put_byte(&pb, s->avctx->ch_layout.nb_channels);
+        bytestream2_put_le32(&pb, s->avctx->ch_layout.u.mask);
         bytestream2_put_byte(&pb, 0);
     }
 
@@ -2862,20 +2863,20 @@ static int wavpack_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
                           sizeof(int32_t) * s->block_samples);
     if (!s->samples[0])
         return AVERROR(ENOMEM);
-    if (avctx->channels > 1) {
+    if (avctx->ch_layout.nb_channels > 1) {
         av_fast_padded_malloc(&s->samples[1], &s->samples_size[1],
                               sizeof(int32_t) * s->block_samples);
         if (!s->samples[1])
             return AVERROR(ENOMEM);
     }
 
-    buf_size = s->block_samples * avctx->channels * 8
-             + 200 * avctx->channels /* for headers */;
+    buf_size = s->block_samples * avctx->ch_layout.nb_channels * 8
+             + 200 * avctx->ch_layout.nb_channels /* for headers */;
     if ((ret = ff_alloc_packet(avctx, avpkt, buf_size)) < 0)
         return ret;
     buf = avpkt->data;
 
-    for (s->ch_offset = 0; s->ch_offset < avctx->channels;) {
+    for (s->ch_offset = 0; s->ch_offset < avctx->ch_layout.nb_channels;) {
         set_samplerate(s);
 
         switch (s->avctx->sample_fmt) {
@@ -2885,7 +2886,7 @@ static int wavpack_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
         }
 
         fill_buffer(s, frame->extended_data[s->ch_offset], s->samples[0], s->block_samples);
-        if (avctx->channels - s->ch_offset == 1) {
+        if (avctx->ch_layout.nb_channels - s->ch_offset == 1) {
             s->flags |= WV_MONO;
         } else {
             s->flags |= WV_CROSS_DECORR;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 270/281] wma: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (270 preceding siblings ...)
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 269/281] wavpack: " James Almer
@ 2022-01-13  2:09 ` James Almer
  2022-03-07 10:26   ` Anton Khirnov
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 271/281] ws-snd1: " James Almer
                   ` (10 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/wma.c            | 11 ++++++-----
 libavcodec/wmadec.c         | 29 +++++++++++++++--------------
 libavcodec/wmaenc.c         | 27 ++++++++++++++-------------
 libavcodec/wmalosslessdec.c | 13 +++++++------
 libavcodec/wmaprodec.c      | 30 ++++++++++++++++++++----------
 libavcodec/wmavoice.c       |  4 ++--
 6 files changed, 64 insertions(+), 50 deletions(-)

diff --git a/libavcodec/wma.c b/libavcodec/wma.c
index d9fda2dbfa..4cd60cc35e 100644
--- a/libavcodec/wma.c
+++ b/libavcodec/wma.c
@@ -79,6 +79,7 @@ static av_cold int init_coef_vlc(VLC *vlc, uint16_t **prun_table,
 av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
 {
     WMACodecContext *s = avctx->priv_data;
+    int channels = avctx->ch_layout.nb_channels;
     int i, ret;
     float bps1, high_freq;
     float bps;
@@ -86,7 +87,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
     int coef_vlc_table;
 
     if (avctx->sample_rate <= 0 || avctx->sample_rate > 50000 ||
-        avctx->channels    <= 0 || avctx->channels    > 2     ||
+        channels           <= 0 || channels    > 2            ||
         avctx->bit_rate    <= 0)
         return -1;
 
@@ -107,7 +108,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
     if (s->use_variable_block_len) {
         int nb_max, nb;
         nb = ((flags2 >> 3) & 3) + 1;
-        if ((avctx->bit_rate / avctx->channels) >= 32000)
+        if ((avctx->bit_rate / channels) >= 32000)
             nb += 2;
         nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
         if (nb > nb_max)
@@ -136,7 +137,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
     }
 
     bps                 = (float) avctx->bit_rate /
-                          (float) (avctx->channels * avctx->sample_rate);
+                          (float) (channels * avctx->sample_rate);
     s->byte_offset_bits = av_log2((int) (bps * s->frame_len / 8.0 + 0.5)) + 2;
     if (s->byte_offset_bits + 3 > MIN_CACHE_BITS) {
         av_log(avctx, AV_LOG_ERROR, "byte_offset_bits %d is too large\n", s->byte_offset_bits);
@@ -146,7 +147,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
     /* compute high frequency value and choose if noise coding should
      * be activated */
     bps1 = bps;
-    if (avctx->channels == 2)
+    if (channels == 2)
         bps1 = bps * 1.6;
     if (sample_rate1 == 44100) {
         if (bps1 >= 0.61)
@@ -184,7 +185,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
     }
     ff_dlog(s->avctx, "flags2=0x%x\n", flags2);
     ff_dlog(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%"PRId64" block_align=%d\n",
-            s->version, avctx->channels, avctx->sample_rate, avctx->bit_rate,
+            s->version, channels, avctx->sample_rate, avctx->bit_rate,
             avctx->block_align);
     ff_dlog(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
             bps, bps1, high_freq, s->byte_offset_bits);
diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index 9955aaa7d6..8b0893c74e 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -439,6 +439,7 @@ static void wma_window(WMACodecContext *s, float *out)
  */
 static int wma_decode_block(WMACodecContext *s)
 {
+    int channels = s->avctx->ch_layout.nb_channels;
     int n, v, a, ch, bsize;
     int coef_nb_bits, total_gain;
     int nb_coefs[MAX_CHANNELS];
@@ -504,10 +505,10 @@ static int wma_decode_block(WMACodecContext *s)
         return -1;
     }
 
-    if (s->avctx->channels == 2)
+    if (channels == 2)
         s->ms_stereo = get_bits1(&s->gb);
     v = 0;
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         a                    = get_bits1(&s->gb);
         s->channel_coded[ch] = a;
         v                   |= a;
@@ -538,12 +539,12 @@ static int wma_decode_block(WMACodecContext *s)
 
     /* compute number of coefficients */
     n = s->coefs_end[bsize] - s->coefs_start;
-    for (ch = 0; ch < s->avctx->channels; ch++)
+    for (ch = 0; ch < channels; ch++)
         nb_coefs[ch] = n;
 
     /* complex coding */
     if (s->use_noise_coding) {
-        for (ch = 0; ch < s->avctx->channels; ch++) {
+        for (ch = 0; ch < channels; ch++) {
             if (s->channel_coded[ch]) {
                 int i, n, a;
                 n = s->exponent_high_sizes[bsize];
@@ -556,7 +557,7 @@ static int wma_decode_block(WMACodecContext *s)
                 }
             }
         }
-        for (ch = 0; ch < s->avctx->channels; ch++) {
+        for (ch = 0; ch < channels; ch++) {
             if (s->channel_coded[ch]) {
                 int i, n, val;
 
@@ -579,7 +580,7 @@ static int wma_decode_block(WMACodecContext *s)
 
     /* exponents can be reused in short blocks. */
     if ((s->block_len_bits == s->frame_len_bits) || get_bits1(&s->gb)) {
-        for (ch = 0; ch < s->avctx->channels; ch++) {
+        for (ch = 0; ch < channels; ch++) {
             if (s->channel_coded[ch]) {
                 if (s->use_exp_vlc) {
                     if (decode_exp_vlc(s, ch) < 0)
@@ -593,13 +594,13 @@ static int wma_decode_block(WMACodecContext *s)
         }
     }
 
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         if (s->channel_coded[ch] && !s->exponents_initialized[ch])
             return AVERROR_INVALIDDATA;
     }
 
     /* parse spectral coefficients : just RLE encoding */
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         if (s->channel_coded[ch]) {
             int tindex;
             WMACoef *ptr = &s->coefs1[ch][0];
@@ -616,7 +617,7 @@ static int wma_decode_block(WMACodecContext *s)
             if (ret < 0)
                 return ret;
         }
-        if (s->version == 1 && s->avctx->channels >= 2)
+        if (s->version == 1 && channels >= 2)
             align_get_bits(&s->gb);
     }
 
@@ -629,7 +630,7 @@ static int wma_decode_block(WMACodecContext *s)
     }
 
     /* finally compute the MDCT coefficients */
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         if (s->channel_coded[ch]) {
             WMACoef *coefs1;
             float *coefs, *exponents, mult, mult1, noise;
@@ -730,7 +731,7 @@ static int wma_decode_block(WMACodecContext *s)
     }
 
 #ifdef TRACE
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         if (s->channel_coded[ch]) {
             dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len);
             dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);
@@ -754,7 +755,7 @@ static int wma_decode_block(WMACodecContext *s)
 next:
     mdct = &s->mdct_ctx[bsize];
 
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         int n4, index;
 
         n4 = s->block_len / 2;
@@ -799,7 +800,7 @@ static int wma_decode_frame(WMACodecContext *s, float **samples,
             break;
     }
 
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
         /* copy current block to output */
         memcpy(samples[ch] + samples_offset, s->frame_out[ch],
                s->frame_len * sizeof(*s->frame_out[ch]));
@@ -838,7 +839,7 @@ static int wma_decode_superframe(AVCodecContext *avctx, void *data,
         if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
             return ret;
 
-        for (i = 0; i < s->avctx->channels; i++)
+        for (i = 0; i < s->avctx->ch_layout.nb_channels; i++)
             memcpy(frame->extended_data[i], &s->frame_out[i][0],
                    frame->nb_samples * sizeof(s->frame_out[i][0]));
 
diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c
index 66e3537cb0..4eeaefffba 100644
--- a/libavcodec/wmaenc.c
+++ b/libavcodec/wmaenc.c
@@ -38,10 +38,10 @@ static av_cold int encode_init(AVCodecContext *avctx)
 
     s->avctx = avctx;
 
-    if (avctx->channels > MAX_CHANNELS) {
+    if (avctx->ch_layout.nb_channels > MAX_CHANNELS) {
         av_log(avctx, AV_LOG_ERROR,
                "too many channels: got %i, need %i or fewer\n",
-               avctx->channels, MAX_CHANNELS);
+               avctx->ch_layout.nb_channels, MAX_CHANNELS);
         return AVERROR(EINVAL);
     }
 
@@ -82,7 +82,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
     s->use_exp_vlc            = flags2 & 0x0001;
     s->use_bit_reservoir      = flags2 & 0x0002;
     s->use_variable_block_len = flags2 & 0x0004;
-    if (avctx->channels == 2)
+    if (avctx->ch_layout.nb_channels == 2)
         s->ms_stereo = 1;
 
     if ((ret = ff_wma_init(avctx, flags2)) < 0)
@@ -116,7 +116,7 @@ static int apply_window_and_mdct(AVCodecContext *avctx, const AVFrame *frame)
     int window_len     = 1 << s->block_len_bits;
     float n            = 2.0 * 32768.0 / window_len;
 
-    for (ch = 0; ch < avctx->channels; ch++) {
+    for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
         memcpy(s->output, s->frame_out[ch], window_len * sizeof(*s->output));
         s->fdsp->vector_fmul_scalar(s->frame_out[ch], audio[ch], n, len);
         s->fdsp->vector_fmul_reverse(&s->output[window_len], s->frame_out[ch],
@@ -186,6 +186,7 @@ static void encode_exp_vlc(WMACodecContext *s, int ch, const int *exp_param)
 static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
                         int total_gain)
 {
+    int channels = s->avctx->ch_layout.nb_channels;
     int v, bsize, ch, coef_nb_bits, parse_exponents;
     float mdct_norm;
     int nb_coefs[MAX_CHANNELS];
@@ -213,7 +214,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
 
     // FIXME factor
     v = s->coefs_end[bsize] - s->coefs_start;
-    for (ch = 0; ch < s->avctx->channels; ch++)
+    for (ch = 0; ch < channels; ch++)
         nb_coefs[ch] = v;
     {
         int n4 = s->block_len / 2;
@@ -222,17 +223,17 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
             mdct_norm *= sqrt(n4);
     }
 
-    if (s->avctx->channels == 2)
+    if (channels == 2)
         put_bits(&s->pb, 1, !!s->ms_stereo);
 
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         // FIXME only set channel_coded when needed, instead of always
         s->channel_coded[ch] = 1;
         if (s->channel_coded[ch])
             init_exp(s, ch, fixed_exp);
     }
 
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         if (s->channel_coded[ch]) {
             WMACoef *coefs1;
             float *coefs, *exponents, mult;
@@ -260,7 +261,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
     }
 
     v = 0;
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         int a = s->channel_coded[ch];
         put_bits(&s->pb, 1, a);
         v |= a;
@@ -276,7 +277,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
     coef_nb_bits = ff_wma_total_gain_to_bits(total_gain);
 
     if (s->use_noise_coding) {
-        for (ch = 0; ch < s->avctx->channels; ch++) {
+        for (ch = 0; ch < channels; ch++) {
             if (s->channel_coded[ch]) {
                 int i, n;
                 n = s->exponent_high_sizes[bsize];
@@ -294,7 +295,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
         put_bits(&s->pb, 1, parse_exponents);
 
     if (parse_exponents) {
-        for (ch = 0; ch < s->avctx->channels; ch++) {
+        for (ch = 0; ch < channels; ch++) {
             if (s->channel_coded[ch]) {
                 if (s->use_exp_vlc) {
                     encode_exp_vlc(s, ch, fixed_exp);
@@ -307,7 +308,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
     } else
         av_assert0(0); // FIXME not implemented
 
-    for (ch = 0; ch < s->avctx->channels; ch++) {
+    for (ch = 0; ch < channels; ch++) {
         if (s->channel_coded[ch]) {
             int run, tindex;
             WMACoef *ptr, *eptr;
@@ -346,7 +347,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
                 put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1],
                          s->coef_vlcs[tindex]->huffcodes[1]);
         }
-        if (s->version == 1 && s->avctx->channels >= 2)
+        if (s->version == 1 && channels >= 2)
             align_put_bits(&s->pb);
     }
     return 0;
diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c
index 74c91f4f7e..cd05b22689 100644
--- a/libavcodec/wmalosslessdec.c
+++ b/libavcodec/wmalosslessdec.c
@@ -190,14 +190,14 @@ static av_cold int decode_init(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
-    av_assert0(avctx->channels >= 0);
-    if (avctx->channels > WMALL_MAX_CHANNELS) {
+    av_assert0(avctx->ch_layout.nb_channels >= 0);
+    if (avctx->ch_layout.nb_channels > WMALL_MAX_CHANNELS) {
         avpriv_request_sample(avctx,
                               "More than " AV_STRINGIFY(WMALL_MAX_CHANNELS) " channels");
         return AVERROR_PATCHWELCOME;
     }
 
-    s->max_frame_size = MAX_FRAMESIZE * avctx->channels;
+    s->max_frame_size = MAX_FRAMESIZE * avctx->ch_layout.nb_channels;
     s->frame_data = av_mallocz(s->max_frame_size + AV_INPUT_BUFFER_PADDING_SIZE);
     if (!s->frame_data)
         return AVERROR(ENOMEM);
@@ -244,7 +244,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     av_assert0(s->samples_per_frame <= WMALL_BLOCK_MAX_SIZE);
 
     /* init previous block len */
-    for (i = 0; i < avctx->channels; i++)
+    for (i = 0; i < avctx->ch_layout.nb_channels; i++)
         s->channel[i].prev_block_len = s->samples_per_frame;
 
     /* subframe info */
@@ -263,7 +263,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
         return AVERROR_INVALIDDATA;
     }
 
-    s->num_channels = avctx->channels;
+    s->num_channels = avctx->ch_layout.nb_channels;
 
     /* extract lfe channel position */
     s->lfe_channel = -1;
@@ -279,7 +279,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
     if (!s->frame)
         return AVERROR(ENOMEM);
 
-    avctx->channel_layout = channel_mask;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
     return 0;
 }
 
diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
index ba7bddc51c..5c1d38eca5 100644
--- a/libavcodec/wmaprodec.c
+++ b/libavcodec/wmaprodec.c
@@ -384,7 +384,7 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu
         s->decode_flags    = 0x10d6;
         s->bits_per_sample = 16;
         channel_mask       = 0; //AV_RL32(edata_ptr+2); /* not always in expected order */
-        if ((num_stream+1) * XMA_MAX_CHANNELS_STREAM > avctx->channels) /* stream config is 2ch + 2ch + ... + 1/2ch */
+        if ((num_stream+1) * XMA_MAX_CHANNELS_STREAM > avctx->ch_layout.nb_channels) /* stream config is 2ch + 2ch + ... + 1/2ch */
             s->nb_channels = 1;
         else
             s->nb_channels = 2;
@@ -402,7 +402,7 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu
         s->decode_flags    = AV_RL16(edata_ptr+14);
         channel_mask       = AV_RL32(edata_ptr+2);
         s->bits_per_sample = AV_RL16(edata_ptr);
-        s->nb_channels     = avctx->channels;
+        s->nb_channels     = avctx->ch_layout.nb_channels;
 
         if (s->bits_per_sample > 32 || s->bits_per_sample < 1) {
             avpriv_request_sample(avctx, "bits per sample is %d", s->bits_per_sample);
@@ -474,7 +474,7 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu
         av_log(avctx, AV_LOG_ERROR, "invalid number of channels per XMA stream %d\n",
                s->nb_channels);
         return AVERROR_INVALIDDATA;
-    } else if (s->nb_channels > WMAPRO_MAX_CHANNELS || s->nb_channels > avctx->channels) {
+    } else if (s->nb_channels > WMAPRO_MAX_CHANNELS || s->nb_channels > avctx->ch_layout.nb_channels) {
         avpriv_request_sample(avctx,
                               "More than %d channels", WMAPRO_MAX_CHANNELS);
         return AVERROR_PATCHWELCOME;
@@ -575,8 +575,13 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu
     if (avctx->debug & FF_DEBUG_BITSTREAM)
         dump_context(s);
 
-    if (avctx->codec_id == AV_CODEC_ID_WMAPRO)
-        avctx->channel_layout = channel_mask;
+    if (avctx->codec_id == AV_CODEC_ID_WMAPRO) {
+        if (channel_mask) {
+            av_channel_layout_uninit(&avctx->ch_layout);
+            av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
+        } else
+            avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+    }
 
     ff_thread_once(&init_static_once, decode_init_static);
 
@@ -1775,7 +1780,7 @@ static int decode_packet(AVCodecContext *avctx, WMAProDecodeCtx *s,
         AVFrame *frame = data;
 
         if (s->trim_start < frame->nb_samples) {
-            for (int ch = 0; ch < frame->channels; ch++)
+            for (int ch = 0; ch < frame->ch_layout.nb_channels; ch++)
                 frame->extended_data[ch] += s->trim_start * 4;
 
             frame->nb_samples -= s->trim_start;
@@ -1952,13 +1957,18 @@ static av_cold int xma_decode_init(AVCodecContext *avctx)
     XMADecodeCtx *s = avctx->priv_data;
     int i, ret, start_channels = 0;
 
-    if (avctx->channels <= 0 || avctx->extradata_size == 0)
+    if (avctx->ch_layout.nb_channels <= 0 || avctx->extradata_size == 0)
         return AVERROR_INVALIDDATA;
 
     /* get stream config */
     if (avctx->codec_id == AV_CODEC_ID_XMA2 && avctx->extradata_size == 34) { /* XMA2WAVEFORMATEX */
+        unsigned int channel_mask = AV_RL32(avctx->extradata + 2);
+        if (channel_mask) {
+            av_channel_layout_uninit(&avctx->ch_layout);
+            av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
+        } else
+            avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
         s->num_streams = AV_RL16(avctx->extradata);
-        avctx->channel_layout = AV_RL32(avctx->extradata + 2);
     } else if (avctx->codec_id == AV_CODEC_ID_XMA2 && avctx->extradata_size >= 2) { /* XMA2WAVEFORMAT */
         s->num_streams = avctx->extradata[1];
         if (avctx->extradata_size != (32 + ((avctx->extradata[0]==3)?0:8) + 4*s->num_streams)) {
@@ -1979,7 +1989,7 @@ static av_cold int xma_decode_init(AVCodecContext *avctx)
     }
 
     /* encoder supports up to 64 streams / 64*2 channels (would have to alloc arrays) */
-    if (avctx->channels > XMA_MAX_CHANNELS || s->num_streams > XMA_MAX_STREAMS ||
+    if (avctx->ch_layout.nb_channels > XMA_MAX_CHANNELS || s->num_streams > XMA_MAX_STREAMS ||
         s->num_streams <= 0
     ) {
         avpriv_request_sample(avctx, "More than %d channels in %d streams", XMA_MAX_CHANNELS, s->num_streams);
@@ -1999,7 +2009,7 @@ static av_cold int xma_decode_init(AVCodecContext *avctx)
         s->start_channel[i] = start_channels;
         start_channels += s->xma[i].nb_channels;
     }
-    if (start_channels != avctx->channels)
+    if (start_channels != avctx->ch_layout.nb_channels)
         return AVERROR_INVALIDDATA;
 
     for (int i = 0; i < XMA_MAX_STREAMS; i++) {
diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
index e096b8029d..47fc0947c5 100644
--- a/libavcodec/wmavoice.c
+++ b/libavcodec/wmavoice.c
@@ -475,8 +475,8 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
                                   2 * (s->block_conv_table[1] - 2 * s->min_pitch_val);
     s->block_pitch_nbits        = av_ceil_log2(s->block_pitch_range);
 
-    ctx->channels               = 1;
-    ctx->channel_layout         = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&ctx->ch_layout);
+    ctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     ctx->sample_fmt             = AV_SAMPLE_FMT_FLT;
 
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 271/281] ws-snd1: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (271 preceding siblings ...)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 270/281] wma: " James Almer
@ 2022-01-13  2:09 ` James Almer
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 272/281] lavc: drop temporary compat wrappers for channel layout API change James Almer
                   ` (9 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/ws-snd1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ws-snd1.c b/libavcodec/ws-snd1.c
index aa8cd0f5f9..cd16445935 100644
--- a/libavcodec/ws-snd1.c
+++ b/libavcodec/ws-snd1.c
@@ -43,8 +43,8 @@ static const int8_t ws_adpcm_4bit[] = {
 
 static av_cold int ws_snd_decode_init(AVCodecContext *avctx)
 {
-    avctx->channels       = 1;
-    avctx->channel_layout = AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
     avctx->sample_fmt     = AV_SAMPLE_FMT_U8;
 
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 272/281] lavc: drop temporary compat wrappers for channel layout API change
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (272 preceding siblings ...)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 271/281] ws-snd1: " James Almer
@ 2022-01-13  2:09 ` James Almer
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 273/281] lavf: Add non diegetic stream disposition flag James Almer
                   ` (8 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/aacdec_template.c |  7 -------
 libavcodec/avcodec.c         | 29 -----------------------------
 libavcodec/dca_lbr.c         |  7 -------
 libavcodec/dcadec.c          |  8 --------
 libavcodec/decode.c          | 20 --------------------
 libavcodec/encode.c          | 17 +----------------
 6 files changed, 1 insertion(+), 87 deletions(-)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 387a4acfce..349ecdefb3 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -592,13 +592,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
     }
 
     av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout);
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-    avctx->channels = avctx->ch_layout.nb_channels;
-    avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
-                            avctx->ch_layout.u.mask : 0;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
     ac->oc[1].status = oc_type;
 
     if (get_new_frame) {
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 0436a6d0bd..5b68e799ec 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -137,8 +137,6 @@ static int64_t get_bit_rate(AVCodecContext *ctx)
 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
 {
     int ret = 0;
-    int orig_channels;
-    uint64_t orig_channel_layout;
     AVCodecInternal *avci;
 
     if (avcodec_is_open(avctx))
@@ -275,14 +273,6 @@ FF_DISABLE_DEPRECATION_WARNINGS
             avctx->ch_layout.nb_channels = avctx->channels;
         }
     }
-
-    /* temporary compat wrapper for new-style callers and old-style codecs;
-     * to be removed once all the codecs have been converted */
-    if (avctx->ch_layout.nb_channels) {
-        avctx->channels = avctx->ch_layout.nb_channels;
-        avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
-                                avctx->ch_layout.u.mask : 0;
-    }
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
@@ -345,13 +335,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
     if (!HAVE_THREADS && !(codec->caps_internal & FF_CODEC_CAP_AUTO_THREADS))
         avctx->thread_count = 1;
 
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-    orig_channels = avctx->channels;
-    orig_channel_layout = avctx->channel_layout;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-
     if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
         avci->frame_thread_encoder) {
         if (avctx->codec->init) {
@@ -372,18 +355,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 #if FF_API_OLD_CHANNEL_LAYOUT
 FF_DISABLE_DEPRECATION_WARNINGS
-        /* decoder setting the old-style fields */
-        if (avctx->channels != orig_channels ||
-            avctx->channel_layout != orig_channel_layout) {
-            av_channel_layout_uninit(&avctx->ch_layout);
-            if (avctx->channel_layout) {
-                av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout);
-            } else {
-                avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
-                avctx->ch_layout.nb_channels = avctx->channels;
-            }
-        }
-
         /* update the deprecated fields for old-style callers */
         avctx->channels = avctx->ch_layout.nb_channels;
         avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index c11f2f7e18..527bc8b7c0 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -1744,13 +1744,6 @@ int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame)
 
     av_channel_layout_uninit(&avctx->ch_layout);
     av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-    avctx->channels = avctx->ch_layout.nb_channels;
-    avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
-                            avctx->ch_layout.u.mask : 0;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
 
     frame->nb_samples = 1024 << s->freq_range;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 239ed9ac91..9f40da20fc 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -78,14 +78,6 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask
         av_channel_layout_from_mask(&avctx->ch_layout, wav_mask);
     }
 
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-    avctx->channels = avctx->ch_layout.nb_channels;
-    avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
-                            avctx->ch_layout.u.mask : 0;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-
     return nchannels;
 }
 
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6381ec68e1..a076a8884f 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1698,26 +1698,6 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
     } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
 #if FF_API_OLD_CHANNEL_LAYOUT
 FF_DISABLE_DEPRECATION_WARNINGS
-        /* temporary compat layer for decoders setting the old-style channel
-         * layout fields; shall be removed after all the decoders are converted
-         * to the new API */
-        if ((avctx->channels > 0 && avctx->ch_layout.nb_channels != avctx->channels) ||
-            (avctx->channel_layout && (avctx->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
-                                       avctx->ch_layout.u.mask != avctx->channel_layout))) {
-            av_channel_layout_uninit(&avctx->ch_layout);
-            if (avctx->channel_layout) {
-                if (av_popcount64(avctx->channel_layout) != avctx->channels) {
-                    av_log(avctx, AV_LOG_ERROR, "Inconsistent channel layout/channels\n");
-                    ret = AVERROR(EINVAL);
-                    goto fail;
-                }
-                av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout);
-            } else {
-                avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
-                avctx->ch_layout.nb_channels = avctx->channels;
-            }
-        }
-
         /* compat layer for old-style get_buffer() implementations */
         avctx->channels = avctx->ch_layout.nb_channels;
         avctx->channel_layout = (avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE) ?
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index f9f8879b8e..47fa3ac4bf 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -486,24 +486,9 @@ int ff_encode_preinit(AVCodecContext *avctx)
                 av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
             return AVERROR(EINVAL);
         }
-FF_DISABLE_DEPRECATION_WARNINGS
     }
 #if FF_API_OLD_CHANNEL_LAYOUT
-    else if (avctx->codec->channel_layouts) {
-        if (!avctx->channel_layout) {
-            av_log(avctx, AV_LOG_WARNING, "Channel layout not specified\n");
-        } else {
-            for (i = 0; avctx->codec->channel_layouts[i] != 0; i++)
-                if (avctx->channel_layout == avctx->codec->channel_layouts[i])
-                    break;
-            if (avctx->codec->channel_layouts[i] == 0) {
-                char buf[512];
-                av_get_channel_layout_string(buf, sizeof(buf), -1, avctx->channel_layout);
-                av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
-                return AVERROR(EINVAL);
-            }
-        }
-    }
+FF_DISABLE_DEPRECATION_WARNINGS
     if (avctx->channel_layout && avctx->channels) {
         int channels = av_get_channel_layout_nb_channels(avctx->channel_layout);
         if (channels != avctx->channels) {
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 273/281] lavf: Add non diegetic stream disposition flag
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (273 preceding siblings ...)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 272/281] lavc: drop temporary compat wrappers for channel layout API change James Almer
@ 2022-01-13  2:09 ` James Almer
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 274/281] swresample: convert to new channel layout API James Almer
                   ` (7 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/avformat.h | 7 +++++++
 libavformat/dump.c     | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 6ce367e854..182545e607 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -879,6 +879,13 @@ typedef struct AVIndexEntry {
  */
 #define AV_DISPOSITION_TIMED_THUMBNAILS     (1 << 11)
 
+/**
+ * The stream is intended to be mixed with a spatial audio track. For example,
+ * it could be used for narration or stereo music, and may remain unchanged by
+ * listener head rotation.
+ */
+#define AV_DISPOSITION_NON_DIEGETIC         (1 << 12)
+
 /**
  * The subtitle stream contains captions, providing a transcription and possibly
  * a translation of audio. Typically intended for hearing-impaired audiences.
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 69b838fbc7..e3f0056c20 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -618,6 +618,8 @@ static void dump_stream_format(const AVFormatContext *ic, int i,
         av_log(NULL, AV_LOG_INFO, " (dependent)");
     if (st->disposition & AV_DISPOSITION_STILL_IMAGE)
         av_log(NULL, AV_LOG_INFO, " (still image)");
+    if (st->disposition & AV_DISPOSITION_NON_DIEGETIC)
+        av_log(NULL, AV_LOG_INFO, " (non-diegetic)");
     av_log(NULL, AV_LOG_INFO, "\n");
 
     dump_metadata(NULL, st->metadata, "    ");
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 274/281] swresample: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (274 preceding siblings ...)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 273/281] lavf: Add non diegetic stream disposition flag James Almer
@ 2022-01-13  2:09 ` James Almer
  2022-01-19 17:20   ` Andreas Rheinhardt
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 275/281] avfilter: " James Almer
                   ` (6 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libswresample/options.c             |  33 +++-
 libswresample/rematrix.c            | 237 ++++++++++++++++++----------
 libswresample/rematrix_template.c   |   7 +-
 libswresample/swresample.c          | 152 +++++++++++++++---
 libswresample/swresample.h          |  63 ++++++++
 libswresample/swresample_frame.c    |  65 +++++++-
 libswresample/swresample_internal.h |  10 +-
 7 files changed, 445 insertions(+), 122 deletions(-)

diff --git a/libswresample/options.c b/libswresample/options.c
index 6911709157..ffa27c590d 100644
--- a/libswresample/options.c
+++ b/libswresample/options.c
@@ -34,12 +34,19 @@
 
 #define OFFSET(x) offsetof(SwrContext,x)
 #define PARAM AV_OPT_FLAG_AUDIO_PARAM
+#define DEPREC AV_OPT_FLAG_DEPRECATED
 
 static const AVOption options[]={
-{"ich"                  , "set input channel count"     , OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
-{"in_channel_count"     , "set input channel count"     , OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
-{"och"                  , "set output channel count"    , OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
-{"out_channel_count"    , "set output channel count"    , OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
+#if FF_API_OLD_CHANNEL_LAYOUT
+{"ich"                  , "set input channel count (Deprecated, use ichl)",
+                                                          OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
+{"in_channel_count"     , "set input channel count (Deprecated, use in_chlayout)",
+                                                          OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
+{"och"                  , "set output channel count (Deprecated, use ochl)",
+                                                          OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
+{"out_channel_count"    , "set output channel count (Deprecated, use out_chlayout)",
+                                                          OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
+#endif
 {"uch"                  , "set used channel count"      , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
 {"used_channel_count"   , "set used channel count"      , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
 {"isr"                  , "set input sample rate"       , OFFSET( in_sample_rate), AV_OPT_TYPE_INT  , {.i64=0                     }, 0      , INT_MAX   , PARAM},
@@ -52,10 +59,20 @@ static const AVOption options[]={
 {"out_sample_fmt"       , "set output sample format"    , OFFSET(out_sample_fmt ), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1   , INT_MAX, PARAM},
 {"tsf"                  , "set internal sample format"  , OFFSET(user_int_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1   , INT_MAX, PARAM},
 {"internal_sample_fmt"  , "set internal sample format"  , OFFSET(user_int_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1   , INT_MAX, PARAM},
-{"icl"                  , "set input channel layout"    , OFFSET(user_in_ch_layout ), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
-{"in_channel_layout"    , "set input channel layout"    , OFFSET(user_in_ch_layout ), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
-{"ocl"                  , "set output channel layout"   , OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
-{"out_channel_layout"   , "set output channel layout"   , OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
+#if FF_API_OLD_CHANNEL_LAYOUT
+{"icl"                  , "set input channel layout (Deprecated, use ichl)",
+                                                          OFFSET(user_in_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0          }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
+{"in_channel_layout"    , "set input channel layout (Deprecated, use in_chlayout)",
+                                                          OFFSET(user_in_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0          }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
+{"ocl"                  , "set output channel layout (Deprecated, use ochl)",
+                                                          OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0         }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
+{"out_channel_layout"   , "set output channel layout (Deprecated, use out_chlayout)",
+                                                          OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0         }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
+#endif
+{"ichl"                 , "set input channel layout"    , OFFSET(user_in_chlayout ), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
+{"in_chlayout"          , "set input channel layout"    , OFFSET(user_in_chlayout ), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
+{"ochl"                 , "set output channel layout"   , OFFSET(user_out_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
+{"out_chlayout"         , "set output channel layout"   , OFFSET(user_out_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
 {"clev"                 , "set center mix level"        , OFFSET(clev           ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB                }, -32    , 32        , PARAM},
 {"center_mix_level"     , "set center mix level"        , OFFSET(clev           ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB                }, -32    , 32        , PARAM},
 {"slev"                 , "set surround mix level"      , OFFSET(slev           ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB                }, -32    , 32        , PARAM},
diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index 94b3de88f6..35086c218d 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -64,15 +64,37 @@
 int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
 {
     int nb_in, nb_out, in, out;
+    int user_in_chlayout_nb_channels, user_out_chlayout_nb_channels;
 
     if (!s || s->in_convert) // s needs to be allocated but not initialized
         return AVERROR(EINVAL);
     memset(s->matrix, 0, sizeof(s->matrix));
     memset(s->matrix_flt, 0, sizeof(s->matrix_flt));
-    nb_in = (s->user_in_ch_count > 0) ? s->user_in_ch_count :
-        av_get_channel_layout_nb_channels(s->user_in_ch_layout);
-    nb_out = (s->user_out_ch_count > 0) ? s->user_out_ch_count :
-        av_get_channel_layout_nb_channels(s->user_out_ch_layout);
+
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    user_in_chlayout_nb_channels = av_get_channel_layout_nb_channels(s->user_in_ch_layout);
+FF_ENABLE_DEPRECATION_WARNINGS
+    if (!user_in_chlayout_nb_channels)
+#endif
+    user_in_chlayout_nb_channels = s->user_in_chlayout.nb_channels;
+    nb_in =
+#if FF_API_OLD_CHANNEL_LAYOUT
+            (s->user_in_ch_count > 0) ? s->user_in_ch_count :
+#endif
+            user_in_chlayout_nb_channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    user_out_chlayout_nb_channels = av_get_channel_layout_nb_channels(s->user_out_ch_layout);
+FF_ENABLE_DEPRECATION_WARNINGS
+    if (!user_out_chlayout_nb_channels)
+#endif
+    user_out_chlayout_nb_channels = s->user_out_chlayout.nb_channels;
+    nb_out =
+#if FF_API_OLD_CHANNEL_LAYOUT
+             (s->user_out_ch_count > 0) ? s->user_out_ch_count :
+#endif
+             user_out_chlayout_nb_channels;
     for (out = 0; out < nb_out; out++) {
         for (in = 0; in < nb_in; in++)
             s->matrix_flt[out][in] = s->matrix[out][in] = matrix[in];
@@ -88,95 +110,141 @@ static int even(int64_t layout){
     return 0;
 }
 
-static int64_t clean_layout(void *s, int64_t layout){
-    if(layout && layout != AV_CH_FRONT_CENTER && !(layout&(layout-1))) {
+static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void *s)
+{
+    int ret = 0;
+
+    if(av_channel_layout_index_from_channel(in, AV_CH_FRONT_CENTER) < 0 && in->nb_channels == 1) {
         char buf[128];
-        av_get_channel_layout_string(buf, sizeof(buf), -1, layout);
+        av_channel_layout_describe(in, buf, sizeof(buf));
         av_log(s, AV_LOG_VERBOSE, "Treating %s as mono\n", buf);
-        return AV_CH_FRONT_CENTER;
-    }
+        *out = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+    } else
+        ret = av_channel_layout_copy(out, in);
 
-    return layout;
+    return ret;
 }
 
-static int sane_layout(int64_t layout){
-    if(!(layout & AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker
+static int sane_layout(AVChannelLayout *ch_layout) {
+    if (ch_layout->order != AV_CHANNEL_ORDER_NATIVE)
+        return 0;
+    if(!av_channel_layout_subset(ch_layout, AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker
         return 0;
-    if(!even(layout & (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT))) // no asymetric front
+    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)))) // no asymetric front
         return 0;
-    if(!even(layout & (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)))   // no asymetric side
+    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT))))   // no asymetric side
         return 0;
-    if(!even(layout & (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)))
+    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT))))
         return 0;
-    if(!even(layout & (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)))
+    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER))))
         return 0;
-    if(av_get_channel_layout_nb_channels(layout) >= SWR_CH_MAX)
+    if(ch_layout->nb_channels >= SWR_CH_MAX)
         return 0;
 
     return 1;
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout_param,
                              double center_mix_level, double surround_mix_level,
                              double lfe_mix_level, double maxval,
                              double rematrix_volume, double *matrix_param,
                              int stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
 {
-    int i, j, out_i;
+    AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
+    int ret;
+
+    ret  = av_channel_layout_from_mask(&in_ch_layout, in_ch_layout_param);
+    ret |= av_channel_layout_from_mask(&out_ch_layout, out_ch_layout_param);
+    if (ret < 0)
+        return ret;
+
+    return swr_build_matrix2(&in_ch_layout, &out_ch_layout, center_mix_level, surround_mix_level,
+                             lfe_mix_level, maxval, rematrix_volume, matrix_param,
+                             stride, matrix_encoding, log_context);
+}
+#endif
+
+av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
+                              double center_mix_level, double surround_mix_level,
+                              double lfe_mix_level, double maxval,
+                              double rematrix_volume, double *matrix_param,
+                              ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
+{
+    int i, j, out_i, ret;
+    AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
     double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}};
-    int64_t unaccounted, in_ch_layout, out_ch_layout;
+    int64_t unaccounted;
     double maxcoef=0;
     char buf[128];
 
-     in_ch_layout = clean_layout(log_context,  in_ch_layout_param);
-    out_ch_layout = clean_layout(log_context, out_ch_layout_param);
-
-    if(   out_ch_layout == AV_CH_LAYOUT_STEREO_DOWNMIX
-       && (in_ch_layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == 0
-    )
-        out_ch_layout = AV_CH_LAYOUT_STEREO;
+    ret  = clean_layout(&in_ch_layout, in_layout, log_context);
+    ret |= clean_layout(&out_ch_layout, out_layout, log_context);
+    if (ret < 0)
+        goto fail;
 
-    if(    in_ch_layout == AV_CH_LAYOUT_STEREO_DOWNMIX
-       && (out_ch_layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == 0
-    )
-        in_ch_layout = AV_CH_LAYOUT_STEREO;
-
-    if (in_ch_layout == AV_CH_LAYOUT_22POINT2 &&
-        out_ch_layout != AV_CH_LAYOUT_22POINT2) {
-        in_ch_layout = (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER);
-        av_get_channel_layout_string(buf, sizeof(buf), -1, in_ch_layout);
+    if(   !av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
+       && !av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
+    ) {
+        av_channel_layout_uninit(&out_ch_layout);
+        out_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+    }
+    if(   !av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
+       && !av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
+    ) {
+        av_channel_layout_uninit(&in_ch_layout);
+        in_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+    }
+    if (!av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2) &&
+        av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2)) {
+        av_channel_layout_from_mask(&in_ch_layout, (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER));
+        av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
         av_log(log_context, AV_LOG_WARNING,
                "Full-on remixing from 22.2 has not yet been implemented! "
                "Processing the input as '%s'\n",
                buf);
     }
 
-    if(!sane_layout(in_ch_layout)){
-        av_get_channel_layout_string(buf, sizeof(buf), -1, in_ch_layout_param);
+    if(!av_channel_layout_check(&in_ch_layout)) {
+        av_log(log_context, AV_LOG_ERROR, "Input channel layout is invalid\n");
+        ret = AVERROR(EINVAL);
+        goto fail;
+    }
+    if(!sane_layout(&in_ch_layout)) {
+        av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
         av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
-        return AVERROR(EINVAL);
+        ret = AVERROR(EINVAL);
+        goto fail;
     }
 
-    if(!sane_layout(out_ch_layout)){
-        av_get_channel_layout_string(buf, sizeof(buf), -1, out_ch_layout_param);
+    if(!av_channel_layout_check(&out_ch_layout)) {
+        av_log(log_context, AV_LOG_ERROR, "Output channel layout is invalid\n");
+        ret = AVERROR(EINVAL);
+        goto fail;
+    }
+    if(!sane_layout(&out_ch_layout)) {
+        av_channel_layout_describe(&out_ch_layout, buf, sizeof(buf));
         av_log(log_context, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
-        return AVERROR(EINVAL);
+        ret = AVERROR(EINVAL);
+        goto fail;
     }
 
     for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){
-        if(in_ch_layout & out_ch_layout & (1ULL<<i))
+        int idx;
+        if(   (idx = av_channel_layout_index_from_channel(&in_ch_layout, i)) >= 0
+           && av_channel_layout_index_from_channel(&out_ch_layout, i) == idx)
             matrix[i][i]= 1.0;
     }
 
-    unaccounted= in_ch_layout & ~out_ch_layout;
+    unaccounted =  in_ch_layout.u.mask & ~out_ch_layout.u.mask;
 
 //FIXME implement dolby surround
 //FIXME implement full ac3
 
 
     if(unaccounted & AV_CH_FRONT_CENTER){
-        if((out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
-            if(in_ch_layout & AV_CH_LAYOUT_STEREO) {
+        if(av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
+            if(av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO)) {
                 matrix[ FRONT_LEFT][FRONT_CENTER]+= center_mix_level;
                 matrix[FRONT_RIGHT][FRONT_CENTER]+= center_mix_level;
             } else {
@@ -187,23 +255,23 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
             av_assert0(0);
     }
     if(unaccounted & AV_CH_LAYOUT_STEREO){
-        if(out_ch_layout & AV_CH_FRONT_CENTER){
+        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
             matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
             matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
-            if(in_ch_layout & AV_CH_FRONT_CENTER)
+            if(av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_FRONT_CENTER) >= 0)
                 matrix[FRONT_CENTER][ FRONT_CENTER] = center_mix_level*sqrt(2);
         }else
             av_assert0(0);
     }
 
     if(unaccounted & AV_CH_BACK_CENTER){
-        if(out_ch_layout & AV_CH_BACK_LEFT){
+        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0){
             matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
             matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
-        }else if(out_ch_layout & AV_CH_SIDE_LEFT){
+        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){
             matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;
             matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;
-        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
+        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
             if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
                 matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
                 if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
@@ -217,24 +285,24 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
                 matrix[ FRONT_LEFT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
                 matrix[FRONT_RIGHT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
             }
-        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
+        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
             matrix[ FRONT_CENTER][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
         }else
             av_assert0(0);
     }
     if(unaccounted & AV_CH_BACK_LEFT){
-        if(out_ch_layout & AV_CH_BACK_CENTER){
+        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0){
             matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
             matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
-        }else if(out_ch_layout & AV_CH_SIDE_LEFT){
-            if(in_ch_layout & AV_CH_SIDE_LEFT){
+        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){
+            if(av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){
                 matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
                 matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
             }else{
             matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
             matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
             }
-        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
+        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
             if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
                 matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * M_SQRT1_2;
                 matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;
@@ -249,7 +317,7 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
                 matrix[ FRONT_LEFT][ BACK_LEFT] += surround_mix_level;
                 matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level;
             }
-        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
+        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
             matrix[ FRONT_CENTER][BACK_LEFT ]+= surround_mix_level*M_SQRT1_2;
             matrix[ FRONT_CENTER][BACK_RIGHT]+= surround_mix_level*M_SQRT1_2;
         }else
@@ -257,20 +325,20 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
     }
 
     if(unaccounted & AV_CH_SIDE_LEFT){
-        if(out_ch_layout & AV_CH_BACK_LEFT){
+        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0){
             /* if back channels do not exist in the input, just copy side
                channels to back channels, otherwise mix side into back */
-            if (in_ch_layout & AV_CH_BACK_LEFT) {
+            if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
                 matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;
                 matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;
             } else {
                 matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
                 matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
             }
-        }else if(out_ch_layout & AV_CH_BACK_CENTER){
+        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0){
             matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;
             matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;
-        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
+        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
             if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
                 matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * M_SQRT1_2;
                 matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;
@@ -285,7 +353,7 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
                 matrix[ FRONT_LEFT][ SIDE_LEFT] += surround_mix_level;
                 matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level;
             }
-        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
+        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
             matrix[ FRONT_CENTER][SIDE_LEFT ]+= surround_mix_level * M_SQRT1_2;
             matrix[ FRONT_CENTER][SIDE_RIGHT]+= surround_mix_level * M_SQRT1_2;
         }else
@@ -293,10 +361,10 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
     }
 
     if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
-        if(out_ch_layout & AV_CH_FRONT_LEFT){
+        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
             matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
             matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
-        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
+        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
             matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
             matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
         }else
@@ -304,9 +372,9 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
     }
     /* mix LFE into front left/right or center */
     if (unaccounted & AV_CH_LOW_FREQUENCY) {
-        if (out_ch_layout & AV_CH_FRONT_CENTER) {
+        if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
             matrix[FRONT_CENTER][LOW_FREQUENCY] += lfe_mix_level;
-        } else if (out_ch_layout & AV_CH_FRONT_LEFT) {
+        } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
             matrix[FRONT_LEFT ][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
             matrix[FRONT_RIGHT][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
         } else
@@ -316,15 +384,19 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
     for(out_i=i=0; i<64; i++){
         double sum=0;
         int in_i=0;
-        if((out_ch_layout & (1ULL<<i)) == 0)
+        if(av_channel_layout_index_from_channel(&out_ch_layout, i) < 0)
             continue;
         for(j=0; j<64; j++){
-            if((in_ch_layout & (1ULL<<j)) == 0)
+            if(av_channel_layout_index_from_channel(&in_ch_layout, j) < 0)
                continue;
             if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0]))
                 matrix_param[stride*out_i + in_i] = matrix[i][j];
-            else
-                matrix_param[stride*out_i + in_i] = i == j && (in_ch_layout & out_ch_layout & (1ULL<<i));
+            else {
+                int idx;
+                matrix_param[stride*out_i + in_i] = i == j &&
+                (   (idx = av_channel_layout_index_from_channel(&in_ch_layout, i)) >= 0
+                 && av_channel_layout_index_from_channel(&out_ch_layout, i) == idx);
+            }
             sum += fabs(matrix_param[stride*out_i + in_i]);
             in_i++;
         }
@@ -350,17 +422,22 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
     }
 
     av_log(log_context, AV_LOG_DEBUG, "Matrix coefficients:\n");
-    for(i=0; i<av_get_channel_layout_nb_channels(out_ch_layout); i++){
-        const char *c =
-            av_get_channel_name(av_channel_layout_extract_channel(out_ch_layout, i));
-        av_log(log_context, AV_LOG_DEBUG, "%s: ", c ? c : "?");
-        for(j=0; j<av_get_channel_layout_nb_channels(in_ch_layout); j++){
-            c = av_get_channel_name(av_channel_layout_extract_channel(in_ch_layout, j));
-            av_log(log_context, AV_LOG_DEBUG, "%s:%f ", c ? c : "?", matrix_param[stride*i + j]);
+    for(i = 0; i < out_ch_layout.nb_channels; i++){
+        av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&out_ch_layout, i));
+        av_log(log_context, AV_LOG_DEBUG, "%s: ", buf);
+        for(j = 0; j < in_ch_layout.nb_channels; j++){
+            av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&in_ch_layout, j));
+            av_log(log_context, AV_LOG_DEBUG, "%s:%f ", buf, matrix_param[stride*i + j]);
         }
         av_log(log_context, AV_LOG_DEBUG, "\n");
     }
-    return 0;
+
+    ret = 0;
+fail:
+    av_channel_layout_uninit(&in_ch_layout);
+    av_channel_layout_uninit(&out_ch_layout);
+
+    return ret;
 }
 
 av_cold static int auto_matrix(SwrContext *s)
@@ -377,7 +454,7 @@ av_cold static int auto_matrix(SwrContext *s)
         maxval = INT_MAX;
 
     memset(s->matrix, 0, sizeof(s->matrix));
-    ret = swr_build_matrix(s->in_ch_layout, s->out_ch_layout,
+    ret = swr_build_matrix2(&s->in_ch_layout, &s->out_ch_layout,
                            s->clev, s->slev, s->lfe_mix_level,
                            maxval, s->rematrix_volume, (double*)s->matrix,
                            s->matrix[1] - s->matrix[0], s->matrix_encoding, s);
@@ -519,8 +596,8 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
         off = len1 * out->bps;
     }
 
-    av_assert0(!s->out_ch_layout || out->ch_count == av_get_channel_layout_nb_channels(s->out_ch_layout));
-    av_assert0(!s-> in_ch_layout || in ->ch_count == av_get_channel_layout_nb_channels(s-> in_ch_layout));
+    av_assert0(s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || out->ch_count == s->out_ch_layout.nb_channels);
+    av_assert0(s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || in ->ch_count == s->in_ch_layout.nb_channels);
 
     for(out_i=0; out_i<out->ch_count; out_i++){
         switch(s->matrix_ch[out_i][0]){
diff --git a/libswresample/rematrix_template.c b/libswresample/rematrix_template.c
index add65e3155..f5a508361c 100644
--- a/libswresample/rematrix_template.c
+++ b/libswresample/rematrix_template.c
@@ -88,13 +88,16 @@ static void RENAME(mix8to2)(SAMPLE **out, const SAMPLE **in, COEFF *coeffp, inte
 }
 
 static RENAME(mix_any_func_type) *RENAME(get_mix_any_func)(SwrContext *s){
-    if(   s->out_ch_layout == AV_CH_LAYOUT_STEREO && (s->in_ch_layout == AV_CH_LAYOUT_5POINT1 || s->in_ch_layout == AV_CH_LAYOUT_5POINT1_BACK)
+    if(   !av_channel_layout_compare(&s->out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)
+       && (   !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1)
+           || !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK))
        && s->matrix[0][2] == s->matrix[1][2] && s->matrix[0][3] == s->matrix[1][3]
        && !s->matrix[0][1] && !s->matrix[0][5] && !s->matrix[1][0] && !s->matrix[1][4]
     )
         return RENAME(mix6to2);
 
-    if(   s->out_ch_layout == AV_CH_LAYOUT_STEREO && s->in_ch_layout == AV_CH_LAYOUT_7POINT1
+    if(   !av_channel_layout_compare(&s->out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)
+       && !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1)
        && s->matrix[0][2] == s->matrix[1][2] && s->matrix[0][3] == s->matrix[1][3]
        && !s->matrix[0][1] && !s->matrix[0][5] && !s->matrix[1][0] && !s->matrix[1][4]
        && !s->matrix[0][7] && !s->matrix[1][6]
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 16734c9df9..f8fbd9134b 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -56,6 +56,8 @@ int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map){
     return 0;
 }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
                                       int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
                                       int64_t  in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
@@ -97,6 +99,58 @@ fail:
     swr_free(&s);
     return NULL;
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
+int swr_alloc_set_opts2(struct SwrContext **ps,
+                        AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
+                        AVChannelLayout *in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
+                        int log_offset, void *log_ctx) {
+    struct SwrContext *s = *ps;
+    int ret;
+
+    if (!s) s = swr_alloc();
+    if (!s) return AVERROR(ENOMEM);
+
+    s->log_level_offset= log_offset;
+    s->log_ctx= log_ctx;
+
+    if ((ret = av_opt_set_chlayout(s, "ochl", out_ch_layout, 0)) < 0)
+        goto fail;
+
+    if ((ret = av_opt_set_int(s, "osf", out_sample_fmt, 0)) < 0)
+        goto fail;
+
+    if ((ret = av_opt_set_int(s, "osr", out_sample_rate, 0)) < 0)
+        goto fail;
+
+    if ((ret = av_opt_set_chlayout(s, "ichl", in_ch_layout, 0)) < 0)
+        goto fail;
+
+    if ((ret = av_opt_set_int(s, "isf", in_sample_fmt, 0)) < 0)
+        goto fail;
+
+    if ((ret = av_opt_set_int(s, "isr", in_sample_rate, 0)) < 0)
+        goto fail;
+
+    av_opt_set_int(s, "uch", 0, 0);
+
+#if FF_API_OLD_CHANNEL_LAYOUT
+    // Clear old API values so they don't take precedence in swr_init()
+    av_opt_set_int(s, "icl", 0, 0);
+    av_opt_set_int(s, "ocl", 0, 0);
+    av_opt_set_int(s, "ich", 0, 0);
+    av_opt_set_int(s, "och", 0, 0);
+#endif
+
+    *ps = s;
+
+    return 0;
+fail:
+    av_log(s, AV_LOG_ERROR, "Failed to set option\n");
+    swr_free(ps);
+    return ret;
+}
 
 static void set_audiodata_fmt(AudioData *a, enum AVSampleFormat fmt){
     a->fmt   = fmt;
@@ -125,6 +179,8 @@ static void clear_context(SwrContext *s){
     free_temp(&s->drop_temp);
     free_temp(&s->dither.noise);
     free_temp(&s->dither.temp);
+    av_channel_layout_uninit(&s->in_ch_layout);
+    av_channel_layout_uninit(&s->out_ch_layout);
     swri_audio_convert_free(&s-> in_convert);
     swri_audio_convert_free(&s->out_convert);
     swri_audio_convert_free(&s->full_convert);
@@ -138,6 +194,9 @@ av_cold void swr_free(SwrContext **ss){
     SwrContext *s= *ss;
     if(s){
         clear_context(s);
+        av_channel_layout_uninit(&s->user_in_chlayout);
+        av_channel_layout_uninit(&s->user_out_chlayout);
+
         if (s->resampler)
             s->resampler->free(&s->resample);
     }
@@ -172,25 +231,66 @@ av_cold int swr_init(struct SwrContext *s){
         av_log(s, AV_LOG_ERROR, "Requested output sample rate %d is invalid\n", s->out_sample_rate);
         return AVERROR(EINVAL);
     }
+    s->used_ch_count = s->user_used_ch_count;
+#if FF_API_OLD_CHANNEL_LAYOUT
     s->out.ch_count  = s-> user_out_ch_count;
     s-> in.ch_count  = s->  user_in_ch_count;
-    s->used_ch_count = s->user_used_ch_count;
 
-    s-> in_ch_layout = s-> user_in_ch_layout;
-    s->out_ch_layout = s->user_out_ch_layout;
+    // if the old/new fields are set inconsistently, prefer the old ones
+    if ((s->user_in_ch_count && s->user_in_ch_count != s->user_in_chlayout.nb_channels) ||
+        (s->user_in_ch_layout && (s->user_in_chlayout.order != AV_CHANNEL_ORDER_NATIVE ||
+                                  s->user_in_chlayout.u.mask != s->user_in_ch_layout))) {
+        av_channel_layout_uninit(&s->in_ch_layout);
+        if (s->user_in_ch_layout)
+            av_channel_layout_from_mask(&s->in_ch_layout, s->user_in_ch_layout);
+        else {
+            s->in_ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            s->in_ch_layout.nb_channels = s->user_in_ch_count;
+        }
+    } else
+        av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout);
+
+    if ((s->user_out_ch_count && s->user_out_ch_count != s->user_out_chlayout.nb_channels) ||
+        (s->user_out_ch_layout && (s->user_out_chlayout.order != AV_CHANNEL_ORDER_NATIVE ||
+                                   s->user_out_chlayout.u.mask != s->user_out_ch_layout))) {
+        av_channel_layout_uninit(&s->out_ch_layout);
+        if (s->user_out_ch_layout)
+            av_channel_layout_from_mask(&s->out_ch_layout, s->user_out_ch_layout);
+        else {
+            s->out_ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            s->out_ch_layout.nb_channels = s->user_out_ch_count;
+        }
+    } else
+        av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout);
+
+    if (!s->out.ch_count && !s->user_out_ch_layout)
+        s->out.ch_count  = s->out_ch_layout.nb_channels;
+    if (!s-> in.ch_count && !s-> user_in_ch_layout)
+        s-> in.ch_count  = s->in_ch_layout.nb_channels;
+#else
+    s->out.ch_count  = s-> user_out_chlayout.nb_channels;
+    s-> in.ch_count  = s->  user_in_chlayout.nb_channels;
+
+    ret  = av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout);
+    ret |= av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout);
+    if (ret < 0)
+        return ret;
+#endif
 
     s->int_sample_fmt= s->user_int_sample_fmt;
 
     s->dither.method = s->user_dither_method;
 
-    if(av_get_channel_layout_nb_channels(s-> in_ch_layout) > SWR_CH_MAX) {
-        av_log(s, AV_LOG_WARNING, "Input channel layout 0x%"PRIx64" is invalid or unsupported.\n", s-> in_ch_layout);
-        s->in_ch_layout = 0;
+    if (!av_channel_layout_check(&s->in_ch_layout) || s->in_ch_layout.nb_channels > SWR_CH_MAX) {
+        av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1));
+        av_log(s, AV_LOG_WARNING, "Input channel layout \"%s\" is invalid or unsupported.\n", l1);
+        av_channel_layout_uninit(&s->in_ch_layout);
     }
 
-    if(av_get_channel_layout_nb_channels(s->out_ch_layout) > SWR_CH_MAX) {
-        av_log(s, AV_LOG_WARNING, "Output channel layout 0x%"PRIx64" is invalid or unsupported.\n", s->out_ch_layout);
-        s->out_ch_layout = 0;
+    if (!av_channel_layout_check(&s->out_ch_layout) || s->out_ch_layout.nb_channels > SWR_CH_MAX) {
+        av_channel_layout_describe(&s->out_ch_layout, l2, sizeof(l2));
+        av_log(s, AV_LOG_WARNING, "Output channel layout \"%s\" is invalid or unsupported.\n", l2);
+        av_channel_layout_uninit(&s->out_ch_layout);
     }
 
     switch(s->engine){
@@ -206,17 +306,18 @@ av_cold int swr_init(struct SwrContext *s){
     if(!s->used_ch_count)
         s->used_ch_count= s->in.ch_count;
 
-    if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){
+    if(s->used_ch_count && s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_ch_count != s->in_ch_layout.nb_channels){
         av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
-        s-> in_ch_layout= 0;
+        av_channel_layout_uninit(&s->in_ch_layout);
     }
 
-    if(!s-> in_ch_layout)
-        s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count);
-    if(!s->out_ch_layout)
-        s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count);
+    if(!s->in_ch_layout.nb_channels || s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
+        av_channel_layout_default(&s->in_ch_layout, s->used_ch_count);
+    if(!s->out_ch_layout.nb_channels || s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
+        av_channel_layout_default(&s->out_ch_layout, s->out.ch_count);
 
-    s->rematrix= s->out_ch_layout  !=s->in_ch_layout || s->rematrix_volume!=1.0 ||
+    s->rematrix= av_channel_layout_compare(&s->out_ch_layout, &s->in_ch_layout) ||
+                 s->rematrix_volume!=1.0 ||
                  s->rematrix_custom;
 
     if(s->int_sample_fmt == AV_SAMPLE_FMT_NONE){
@@ -291,33 +392,36 @@ av_cold int swr_init(struct SwrContext *s){
 
 #define RSC 1 //FIXME finetune
     if(!s-> in.ch_count)
-        s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout);
+        s-> in.ch_count = s->in_ch_layout.nb_channels;
     if(!s->used_ch_count)
         s->used_ch_count= s->in.ch_count;
     if(!s->out.ch_count)
-        s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout);
+        s->out.ch_count = s->out_ch_layout.nb_channels;
 
     if(!s-> in.ch_count){
-        av_assert0(!s->in_ch_layout);
+        av_assert0(s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC);
         av_log(s, AV_LOG_ERROR, "Input channel count and layout are unset\n");
         ret = AVERROR(EINVAL);
         goto fail;
     }
 
-    av_get_channel_layout_string(l1, sizeof(l1), s-> in.ch_count, s-> in_ch_layout);
-    av_get_channel_layout_string(l2, sizeof(l2), s->out.ch_count, s->out_ch_layout);
-    if (s->out_ch_layout && s->out.ch_count != av_get_channel_layout_nb_channels(s->out_ch_layout)) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+    av_channel_layout_describe(&s->out_ch_layout, l1, sizeof(l1));
+    if (s->out_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->out.ch_count != s->out_ch_layout.nb_channels) {
         av_log(s, AV_LOG_ERROR, "Output channel layout %s mismatches specified channel count %d\n", l2, s->out.ch_count);
         ret = AVERROR(EINVAL);
         goto fail;
     }
-    if (s->in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s->in_ch_layout)) {
+#endif
+    av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1));
+    if (s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_ch_count != s->in_ch_layout.nb_channels) {
         av_log(s, AV_LOG_ERROR, "Input channel layout %s mismatches specified channel count %d\n", l1, s->used_ch_count);
         ret = AVERROR(EINVAL);
         goto fail;
     }
 
-    if ((!s->out_ch_layout || !s->in_ch_layout) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) {
+    if ((   s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC
+         || s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) {
         av_log(s, AV_LOG_ERROR, "Rematrix is needed between %s and %s "
                "but there is not enough information to do it\n", l1, l2);
         ret = AVERROR(EINVAL);
diff --git a/libswresample/swresample.h b/libswresample/swresample.h
index c7b84fbcac..c6ff2345e9 100644
--- a/libswresample/swresample.h
+++ b/libswresample/swresample.h
@@ -227,6 +227,7 @@ int swr_init(struct SwrContext *s);
  */
 int swr_is_initialized(struct SwrContext *s);
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 /**
  * Allocate SwrContext if needed and set/reset common parameters.
  *
@@ -246,12 +247,40 @@ int swr_is_initialized(struct SwrContext *s);
  *
  * @see swr_init(), swr_free()
  * @return NULL on error, allocated context otherwise
+ * @deprecated use @ref swr_alloc_set_opts2()
  */
+attribute_deprecated
 struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
                                       int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
                                       int64_t  in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
                                       int log_offset, void *log_ctx);
+#endif
 
+/**
+ * Allocate SwrContext if needed and set/reset common parameters.
+ *
+ * This function does not require s to be allocated with swr_alloc(). On the
+ * other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters
+ * on the allocated context.
+ *
+ * @param ps              Pointer to an existing Swr context if available, or to NULL if not.
+ *                        On success, *ps will be set the allocated context.
+ * @param out_ch_layout   output channel layout (AV_CH_LAYOUT_*)
+ * @param out_sample_fmt  output sample format (AV_SAMPLE_FMT_*).
+ * @param out_sample_rate output sample rate (frequency in Hz)
+ * @param in_ch_layout    input channel layout (AV_CH_LAYOUT_*)
+ * @param in_sample_fmt   input sample format (AV_SAMPLE_FMT_*).
+ * @param in_sample_rate  input sample rate (frequency in Hz)
+ * @param log_offset      logging level offset
+ * @param log_ctx         parent logging context, can be NULL
+ *
+ * @see swr_init(), swr_free()
+ * @return 0 on success, a negative AVERROR code on error.
+ */
+int swr_alloc_set_opts2(struct SwrContext **ps,
+                        AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
+                        AVChannelLayout *in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
+                        int log_offset, void *log_ctx);
 /**
  * @}
  *
@@ -362,6 +391,7 @@ int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensatio
  */
 int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
 
+#if FF_API_OLD_CHANNEL_LAYOUT
 /**
  * Generate a channel mixing matrix.
  *
@@ -384,13 +414,46 @@ int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
  * @param matrix_encoding     matrixed stereo downmix mode (e.g. dplii)
  * @param log_ctx             parent logging context, can be NULL
  * @return                    0 on success, negative AVERROR code on failure
+ * @deprecated                use @ref swr_build_matrix2()
  */
+attribute_deprecated
 int swr_build_matrix(uint64_t in_layout, uint64_t out_layout,
                      double center_mix_level, double surround_mix_level,
                      double lfe_mix_level, double rematrix_maxval,
                      double rematrix_volume, double *matrix,
                      int stride, enum AVMatrixEncoding matrix_encoding,
                      void *log_ctx);
+#endif
+
+/**
+ * Generate a channel mixing matrix.
+ *
+ * This function is the one used internally by libswresample for building the
+ * default mixing matrix. It is made public just as a utility function for
+ * building custom matrices.
+ *
+ * @param in_layout           input channel layout
+ * @param out_layout          output channel layout
+ * @param center_mix_level    mix level for the center channel
+ * @param surround_mix_level  mix level for the surround channel(s)
+ * @param lfe_mix_level       mix level for the low-frequency effects channel
+ * @param rematrix_maxval     if 1.0, coefficients will be normalized to prevent
+ *                            overflow. if INT_MAX, coefficients will not be
+ *                            normalized.
+ * @param[out] matrix         mixing coefficients; matrix[i + stride * o] is
+ *                            the weight of input channel i in output channel o.
+ * @param stride              distance between adjacent input channels in the
+ *                            matrix array
+ * @param matrix_encoding     matrixed stereo downmix mode (e.g. dplii)
+ * @param log_ctx             parent logging context, can be NULL
+ * @return                    0 on success, negative AVERROR code on failure
+ */
+int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
+                      double center_mix_level, double surround_mix_level,
+                      double lfe_mix_level, double maxval,
+                      double rematrix_volume, double *matrix_param,
+                      ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding,
+                      void *log_context);
 
 /**
  * Set a customized remix matrix.
diff --git a/libswresample/swresample_frame.c b/libswresample/swresample_frame.c
index d95c1cc537..747cf119a9 100644
--- a/libswresample/swresample_frame.c
+++ b/libswresample/swresample_frame.c
@@ -29,7 +29,19 @@ int swr_config_frame(SwrContext *s, const AVFrame *out, const AVFrame *in)
     swr_close(s);
 
     if (in) {
-        if (av_opt_set_int(s, "icl", in->channel_layout, 0) < 0)
+        AVChannelLayout in_ch_layout = { 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(&in_ch_layout, in->channel_layout);
+FF_ENABLE_DEPRECATION_WARNINGS
+        } else
+#endif
+        if (av_channel_layout_copy(&in_ch_layout, &in->ch_layout) < 0)
+            goto fail;
+        if (av_opt_set_chlayout(s, "ichl", &in_ch_layout, 0) < 0)
             goto fail;
         if (av_opt_set_int(s, "isf", in->format, 0) < 0)
             goto fail;
@@ -38,7 +50,19 @@ int swr_config_frame(SwrContext *s, const AVFrame *out, const AVFrame *in)
     }
 
     if (out) {
-        if (av_opt_set_int(s, "ocl", out->channel_layout, 0) < 0)
+        AVChannelLayout out_ch_layout = { 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_from_mask(&out_ch_layout, out->channel_layout);
+FF_ENABLE_DEPRECATION_WARNINGS
+        } else
+#endif
+        if (av_channel_layout_copy(&out_ch_layout, &out->ch_layout) < 0)
+            goto fail;
+        if (av_opt_set_chlayout(s, "ochl", &out_ch_layout, 0) < 0)
             goto fail;
         if (av_opt_set_int(s, "osf", out->format,  0) < 0)
             goto fail;
@@ -58,7 +82,19 @@ static int config_changed(SwrContext *s,
     int ret = 0;
 
     if (in) {
-        if (s->in_ch_layout   != in->channel_layout ||
+        AVChannelLayout in_ch_layout = { 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(&in_ch_layout, in->channel_layout);
+FF_ENABLE_DEPRECATION_WARNINGS
+        } else
+#endif
+        if ((ret = av_channel_layout_copy(&in_ch_layout, &in->ch_layout)) < 0)
+            return ret;
+        if (av_channel_layout_compare(&s->in_ch_layout, &in_ch_layout) ||
             s->in_sample_rate != in->sample_rate ||
             s->in_sample_fmt  != in->format) {
             ret |= AVERROR_INPUT_CHANGED;
@@ -66,7 +102,19 @@ static int config_changed(SwrContext *s,
     }
 
     if (out) {
-        if (s->out_ch_layout   != out->channel_layout ||
+        AVChannelLayout out_ch_layout = { 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_from_mask(&out_ch_layout, out->channel_layout);
+FF_ENABLE_DEPRECATION_WARNINGS
+        } else
+#endif
+        if ((ret = av_channel_layout_copy(&out_ch_layout, &out->ch_layout)) < 0)
+            return ret;
+        if (av_channel_layout_compare(&s->out_ch_layout, &out_ch_layout) ||
             s->out_sample_rate != out->sample_rate ||
             s->out_sample_fmt  != out->format) {
             ret |= AVERROR_OUTPUT_CHANGED;
@@ -116,7 +164,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;
     }
 }
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
index f2ea5a226d..262a0e2b8c 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -99,8 +99,8 @@ struct SwrContext {
     enum AVSampleFormat  in_sample_fmt;             ///< input sample format
     enum AVSampleFormat int_sample_fmt;             ///< internal sample format (AV_SAMPLE_FMT_FLTP or AV_SAMPLE_FMT_S16P)
     enum AVSampleFormat out_sample_fmt;             ///< output sample format
-    int64_t  in_ch_layout;                          ///< input channel layout
-    int64_t out_ch_layout;                          ///< output channel layout
+    AVChannelLayout  in_ch_layout;                  ///< input channel layout
+    AVChannelLayout out_ch_layout;                  ///< output channel layout
     int      in_sample_rate;                        ///< input sample rate
     int     out_sample_rate;                        ///< output sample rate
     int flags;                                      ///< miscellaneous flags such as SWR_FLAG_RESAMPLE
@@ -114,11 +114,15 @@ struct SwrContext {
     int used_ch_count;                              ///< number of used input channels (mapped channel count if channel_map, otherwise in.ch_count)
     int engine;
 
+    int user_used_ch_count;                         ///< User set used channel count
+#if FF_API_OLD_CHANNEL_LAYOUT
     int user_in_ch_count;                           ///< User set input channel count
     int user_out_ch_count;                          ///< User set output channel count
-    int user_used_ch_count;                         ///< User set used channel count
     int64_t user_in_ch_layout;                      ///< User set input channel layout
     int64_t user_out_ch_layout;                     ///< User set output channel layout
+#endif
+    AVChannelLayout user_in_chlayout;               ///< User set input channel layout
+    AVChannelLayout user_out_chlayout;              ///< User set output channel layout
     enum AVSampleFormat user_int_sample_fmt;        ///< User set internal sample format
     int user_dither_method;                         ///< User set dither method
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 275/281] avfilter: convert to new channel layout API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (275 preceding siblings ...)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 274/281] swresample: convert to new channel layout API James Almer
@ 2022-01-13  2:09 ` James Almer
  2022-02-14 15:49   ` Anton Khirnov
                     ` (2 more replies)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 276/281] avdevice/lavfi: remove call to deprecated function av_buffersink_get_channel_layout() James Almer
                   ` (5 subsequent siblings)
  282 siblings, 3 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavfilter/aeval.c                |  35 ++--
 libavfilter/af_acontrast.c         |   2 +-
 libavfilter/af_acrossover.c        |   6 +-
 libavfilter/af_acrusher.c          |   4 +-
 libavfilter/af_adeclick.c          |  14 +-
 libavfilter/af_adecorrelate.c      |  12 +-
 libavfilter/af_adelay.c            |   8 +-
 libavfilter/af_adenorm.c           |   6 +-
 libavfilter/af_aderivative.c       |   2 +-
 libavfilter/af_adynamicequalizer.c |   6 +-
 libavfilter/af_adynamicsmooth.c    |   2 +-
 libavfilter/af_aecho.c             |   8 +-
 libavfilter/af_aemphasis.c         |   6 +-
 libavfilter/af_aexciter.c          |  10 +-
 libavfilter/af_afade.c             |  10 +-
 libavfilter/af_afftdn.c            |  26 +--
 libavfilter/af_afftfilt.c          |  30 ++--
 libavfilter/af_afir.c              |  49 +++---
 libavfilter/af_aformat.c           |  33 +++-
 libavfilter/af_afreqshift.c        |   6 +-
 libavfilter/af_afwtdn.c            |   8 +-
 libavfilter/af_agate.c             |  14 +-
 libavfilter/af_aiir.c              |  34 ++--
 libavfilter/af_alimiter.c          |  10 +-
 libavfilter/af_amerge.c            |  40 +++--
 libavfilter/af_amix.c              |   4 +-
 libavfilter/af_amultiply.c         |   4 +-
 libavfilter/af_anequalizer.c       |  14 +-
 libavfilter/af_anlmdn.c            |   4 +-
 libavfilter/af_anlms.c             |   6 +-
 libavfilter/af_apad.c              |   2 +-
 libavfilter/af_aphaser.c           |   4 +-
 libavfilter/af_apsyclip.c          |   8 +-
 libavfilter/af_apulsator.c         |   2 +-
 libavfilter/af_aresample.c         |  52 +++---
 libavfilter/af_arnndn.c            |   8 +-
 libavfilter/af_asdr.c              |   8 +-
 libavfilter/af_asetnsamples.c      |   4 +-
 libavfilter/af_ashowinfo.c         |  17 +-
 libavfilter/af_asoftclip.c         |   2 +-
 libavfilter/af_aspectralstats.c    |   4 +-
 libavfilter/af_asr.c               |   2 +-
 libavfilter/af_astats.c            |  10 +-
 libavfilter/af_asubboost.c         |   8 +-
 libavfilter/af_asupercut.c         |   6 +-
 libavfilter/af_atempo.c            |   2 +-
 libavfilter/af_atilt.c             |   6 +-
 libavfilter/af_axcorrelate.c       |   8 +-
 libavfilter/af_biquads.c           |  54 +++---
 libavfilter/af_bs2b.c              |   2 +-
 libavfilter/af_channelmap.c        |  90 ++++++----
 libavfilter/af_channelsplit.c      |  42 +++--
 libavfilter/af_chorus.c            |  14 +-
 libavfilter/af_compand.c           |  14 +-
 libavfilter/af_compensationdelay.c |   9 +-
 libavfilter/af_crossfeed.c         |   2 +-
 libavfilter/af_crystalizer.c       |   4 +-
 libavfilter/af_dcshift.c           |   4 +-
 libavfilter/af_deesser.c           |   6 +-
 libavfilter/af_drmeter.c           |   4 +-
 libavfilter/af_dynaudnorm.c        |  24 +--
 libavfilter/af_earwax.c            |   2 +-
 libavfilter/af_extrastereo.c       |   2 +-
 libavfilter/af_firequalizer.c      |  31 ++--
 libavfilter/af_flanger.c           |   6 +-
 libavfilter/af_haas.c              |   2 +-
 libavfilter/af_hdcd.c              |  28 +--
 libavfilter/af_headphone.c         |  40 ++---
 libavfilter/af_join.c              | 270 +++++++++++++++++++----------
 libavfilter/af_ladspa.c            |  18 +-
 libavfilter/af_loudnorm.c          |  86 ++++-----
 libavfilter/af_lv2.c               |  19 +-
 libavfilter/af_mcompand.c          |  16 +-
 libavfilter/af_pan.c               |  74 +++-----
 libavfilter/af_replaygain.c        |   2 +-
 libavfilter/af_rubberband.c        |   2 +-
 libavfilter/af_sidechaincompress.c |  18 +-
 libavfilter/af_silencedetect.c     |   8 +-
 libavfilter/af_silenceremove.c     |  76 ++++----
 libavfilter/af_sofalizer.c         |  96 +++++-----
 libavfilter/af_speechnorm.c        |  28 +--
 libavfilter/af_stereotools.c       |   2 +-
 libavfilter/af_stereowiden.c       |   2 +-
 libavfilter/af_superequalizer.c    |   2 +-
 libavfilter/af_surround.c          |  90 +++++-----
 libavfilter/af_tremolo.c           |   2 +-
 libavfilter/af_vibrato.c           |   6 +-
 libavfilter/af_volume.c            |   4 +-
 libavfilter/af_volumedetect.c      |   2 +-
 libavfilter/asrc_afirsrc.c         |   2 +-
 libavfilter/asrc_anoisesrc.c       |   2 +-
 libavfilter/asrc_anullsrc.c        |  13 +-
 libavfilter/asrc_flite.c           |   6 +-
 libavfilter/asrc_hilbert.c         |   2 +-
 libavfilter/asrc_sinc.c            |   2 +-
 libavfilter/asrc_sine.c            |   2 +-
 libavfilter/audio.c                |  18 +-
 libavfilter/avf_abitscope.c        |  10 +-
 libavfilter/avf_ahistogram.c       |   6 +-
 libavfilter/avf_aphasemeter.c      |   2 +-
 libavfilter/avf_avectorscope.c     |   2 +-
 libavfilter/avf_concat.c           |   2 +-
 libavfilter/avf_showcqt.c          |   3 +-
 libavfilter/avf_showfreqs.c        |   4 +-
 libavfilter/avf_showspatial.c      |   4 +-
 libavfilter/avf_showspectrum.c     |  15 +-
 libavfilter/avf_showvolume.c       |  31 ++--
 libavfilter/avf_showwaves.c        |  12 +-
 libavfilter/avfilter.c             |  21 ++-
 libavfilter/avfilter.h             |  16 +-
 libavfilter/avfiltergraph.c        |  84 +++++----
 libavfilter/buffersink.c           |  36 +++-
 libavfilter/buffersink.h           |   7 +-
 libavfilter/buffersrc.c            |  94 +++++++---
 libavfilter/buffersrc.h            |   9 +
 libavfilter/f_ebur128.c            |  10 +-
 libavfilter/f_graphmonitor.c       |   2 +-
 libavfilter/f_loop.c               |   4 +-
 libavfilter/f_reverse.c            |   4 +-
 libavfilter/f_streamselect.c       |   6 +-
 libavfilter/formats.c              | 151 +++++++++++-----
 libavfilter/formats.h              |  16 +-
 libavfilter/framepool.c            |   5 +
 libavfilter/framequeue.c           |   4 +-
 libavfilter/graphdump.c            |   4 +-
 libavfilter/internal.h             |   2 +-
 libavfilter/src_movie.c            |  19 +-
 libavfilter/tests/filtfmts.c       |   3 +-
 libavfilter/tests/formats.c        |   4 +-
 libavfilter/trim.c                 |   2 +-
 libavfilter/vaf_spectrumsynth.c    |   2 +-
 tests/ref/fate/filter-formats      |  20 +--
 132 files changed, 1413 insertions(+), 1019 deletions(-)

diff --git a/libavfilter/aeval.c b/libavfilter/aeval.c
index 42cfa81325..86cb0990dd 100644
--- a/libavfilter/aeval.c
+++ b/libavfilter/aeval.c
@@ -57,7 +57,7 @@ typedef struct EvalContext {
     const AVClass *class;
     char *sample_rate_str;
     int sample_rate;
-    int64_t chlayout;
+    AVChannelLayout chlayout;
     char *chlayout_str;
     int nb_channels;            ///< number of output channels
     int nb_in_channels;         ///< number of input channels
@@ -70,7 +70,6 @@ typedef struct EvalContext {
     uint64_t n;
     double var_values[VAR_VARS_NB];
     double *channel_values;
-    int64_t out_channel_layout;
 } EvalContext;
 
 static double val(void *priv, double ch)
@@ -181,7 +180,7 @@ static av_cold int init(AVFilterContext *ctx)
             if (ret < 0)
                 return ret;
 
-            ret = parse_channel_expressions(ctx, av_get_channel_layout_nb_channels(eval->chlayout));
+            ret = parse_channel_expressions(ctx, eval->chlayout.nb_channels);
             if (ret < 0)
                 return ret;
         }
@@ -190,8 +189,8 @@ static av_cold int init(AVFilterContext *ctx)
         if ((ret = parse_channel_expressions(ctx, -1)) < 0)
             return ret;
 
-        eval->chlayout = av_get_default_channel_layout(eval->nb_channels);
-        if (!eval->chlayout && eval->nb_channels <= 0) {
+        av_channel_layout_default(&eval->chlayout, eval->nb_channels);
+        if (eval->nb_channels <= 0) {
             av_log(ctx, AV_LOG_ERROR, "Invalid number of channels '%d' provided\n",
                    eval->nb_channels);
             return AVERROR(EINVAL);
@@ -217,6 +216,7 @@ static av_cold void uninit(AVFilterContext *ctx)
     }
     av_freep(&eval->expr);
     av_freep(&eval->channel_values);
+    av_channel_layout_uninit(&eval->chlayout);
 }
 
 static int config_props(AVFilterLink *outlink)
@@ -229,9 +229,9 @@ static int config_props(AVFilterLink *outlink)
 
     eval->var_values[VAR_S] = eval->sample_rate;
     eval->var_values[VAR_NB_IN_CHANNELS] = NAN;
-    eval->var_values[VAR_NB_OUT_CHANNELS] = outlink->channels;
+    eval->var_values[VAR_NB_OUT_CHANNELS] = outlink->ch_layout.nb_channels;
 
-    av_get_channel_layout_string(buf, sizeof(buf), 0, eval->chlayout);
+    av_channel_layout_describe(&eval->chlayout, buf, sizeof(buf));
 
     av_log(outlink->src, AV_LOG_VERBOSE,
            "sample_rate:%d chlayout:%s duration:%"PRId64"\n",
@@ -244,7 +244,7 @@ static int query_formats(AVFilterContext *ctx)
 {
     EvalContext *eval = ctx->priv;
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBLP, AV_SAMPLE_FMT_NONE };
-    int64_t chlayouts[] = { eval->chlayout ? eval->chlayout : FF_COUNT2LAYOUT(eval->nb_channels) , -1 };
+    AVChannelLayout chlayouts[] = { eval->chlayout.nb_channels ? eval->chlayout : FF_COUNT2LAYOUT(eval->nb_channels), { 0 } };
     int sample_rates[] = { eval->sample_rate, -1 };
     int ret;
 
@@ -365,9 +365,7 @@ static int aeval_query_formats(AVFilterContext *ctx)
     } else {
         // outlink supports only requested output channel layout
         layouts = NULL;
-        if ((ret = ff_add_channel_layout(&layouts,
-                              eval->out_channel_layout ? eval->out_channel_layout :
-                              FF_COUNT2LAYOUT(eval->nb_channels))) < 0)
+        if ((ret = ff_add_channel_layout(&layouts, &FF_COUNT2LAYOUT(eval->nb_channels))) < 0)
             return ret;
         if ((ret = ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts)) < 0)
             return ret;
@@ -387,20 +385,21 @@ static int aeval_config_output(AVFilterLink *outlink)
     int ret;
 
     if (eval->same_chlayout) {
-        eval->chlayout = inlink->channel_layout;
+        if ((ret = av_channel_layout_copy(&eval->chlayout, &inlink->ch_layout)) < 0)
+            return ret;
 
-        if ((ret = parse_channel_expressions(ctx, inlink->channels)) < 0)
+        if ((ret = parse_channel_expressions(ctx, inlink->ch_layout.nb_channels)) < 0)
             return ret;
     }
 
     eval->n = 0;
-    eval->nb_in_channels = eval->var_values[VAR_NB_IN_CHANNELS] = inlink->channels;
-    eval->var_values[VAR_NB_OUT_CHANNELS] = outlink->channels;
+    eval->nb_in_channels = eval->var_values[VAR_NB_IN_CHANNELS] = inlink->ch_layout.nb_channels;
+    eval->var_values[VAR_NB_OUT_CHANNELS] = outlink->ch_layout.nb_channels;
     eval->var_values[VAR_S] = inlink->sample_rate;
     eval->var_values[VAR_T] = NAN;
 
     eval->channel_values = av_realloc_f(eval->channel_values,
-                                        inlink->channels, sizeof(*eval->channel_values));
+                                        inlink->ch_layout.nb_channels, sizeof(*eval->channel_values));
     if (!eval->channel_values)
         return AVERROR(ENOMEM);
 
@@ -430,10 +429,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         eval->var_values[VAR_N] = eval->n;
         eval->var_values[VAR_T] = t0 + i * (double)1/inlink->sample_rate;
 
-        for (j = 0; j < inlink->channels; j++)
+        for (j = 0; j < inlink->ch_layout.nb_channels; j++)
             eval->channel_values[j] = *((double *) in->extended_data[j] + i);
 
-        for (j = 0; j < outlink->channels; j++) {
+        for (j = 0; j < outlink->ch_layout.nb_channels; j++) {
             eval->var_values[VAR_CH] = j;
             *((double *) out->extended_data[j] + i) =
                 av_expr_eval(eval->expr[j], eval->var_values, eval);
diff --git a/libavfilter/af_acontrast.c b/libavfilter/af_acontrast.c
index db7ff79d25..a4ed29e30a 100644
--- a/libavfilter/af_acontrast.c
+++ b/libavfilter/af_acontrast.c
@@ -152,7 +152,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     }
 
     s->filter((void **)out->extended_data, (const void **)in->extended_data,
-              in->nb_samples, in->channels, s->contrast / 750);
+              in->nb_samples, in->ch_layout.nb_channels, s->contrast / 750);
 
     if (out != in)
         av_frame_free(&in);
diff --git a/libavfilter/af_acrossover.c b/libavfilter/af_acrossover.c
index 9c00e1ddc2..05ea53fd83 100644
--- a/libavfilter/af_acrossover.c
+++ b/libavfilter/af_acrossover.c
@@ -356,8 +356,8 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, i
     AudioCrossoverContext *s = ctx->priv;                                                   \
     AVFrame *in = s->input_frame;                                                           \
     AVFrame **frames = s->frames;                                                           \
-    const int start = (in->channels * jobnr) / nb_jobs;                                     \
-    const int end = (in->channels * (jobnr+1)) / nb_jobs;                                   \
+    const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;                        \
+    const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;                      \
     const int nb_samples = in->nb_samples;                                                  \
     const int nb_outs = ctx->nb_outputs;                                                    \
     const int first_order = s->first_order;                                                 \
@@ -498,7 +498,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     s->input_frame = in;
     ff_filter_execute(ctx, s->filter_channels, NULL, NULL,
-                      FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     for (i = 0; i < ctx->nb_outputs; i++) {
         ret = ff_filter_frame(ctx->outputs[i], frames[i]);
diff --git a/libavfilter/af_acrusher.c b/libavfilter/af_acrusher.c
index 14d66e88ea..d59211ee29 100644
--- a/libavfilter/af_acrusher.c
+++ b/libavfilter/af_acrusher.c
@@ -244,7 +244,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
             s->round = round(s->samples);
         }
 
-        for (c = 0; c < inlink->channels; c++) {
+        for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
             double sample = src[c] * level_in;
 
             sample = mix * samplereduction(s, &s->sr[c], sample) + src[c] * (1. - mix) * level_in;
@@ -296,7 +296,7 @@ static int config_input(AVFilterLink *inlink)
     s->lfo.amount = .5;
 
     if (!s->sr)
-        s->sr = av_calloc(inlink->channels, sizeof(*s->sr));
+        s->sr = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->sr));
     if (!s->sr)
         return AVERROR(ENOMEM);
 
diff --git a/libavfilter/af_adeclick.c b/libavfilter/af_adeclick.c
index 77336e50bb..2db9a29fd3 100644
--- a/libavfilter/af_adeclick.c
+++ b/libavfilter/af_adeclick.c
@@ -151,7 +151,7 @@ static int config_input(AVFilterLink *inlink)
     s->efifo = av_audio_fifo_alloc(inlink->format, 1, s->window_size);
     if (!s->efifo)
         return AVERROR(ENOMEM);
-    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->window_size);
+    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->ch_layout.nb_channels, s->window_size);
     if (!s->fifo)
         return AVERROR(ENOMEM);
     s->overlap_skip = s->method ? (s->window_size - s->hop_size) / 2 : 0;
@@ -160,12 +160,12 @@ static int config_input(AVFilterLink *inlink)
                             s->overlap_skip);
     }
 
-    s->nb_channels = inlink->channels;
-    s->chan = av_calloc(inlink->channels, sizeof(*s->chan));
+    s->nb_channels = inlink->ch_layout.nb_channels;
+    s->chan = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->chan));
     if (!s->chan)
         return AVERROR(ENOMEM);
 
-    for (i = 0; i < inlink->channels; i++) {
+    for (i = 0; i < inlink->ch_layout.nb_channels; i++) {
         DeclickChannel *c = &s->chan[i];
 
         c->detection = av_calloc(s->window_size, sizeof(*c->detection));
@@ -557,11 +557,11 @@ static int filter_frame(AVFilterLink *inlink)
         goto fail;
 
     td.out = out;
-    ret = ff_filter_execute(ctx, filter_channel, &td, NULL, inlink->channels);
+    ret = ff_filter_execute(ctx, filter_channel, &td, NULL, inlink->ch_layout.nb_channels);
     if (ret < 0)
         goto fail;
 
-    for (ch = 0; ch < s->in->channels; ch++) {
+    for (ch = 0; ch < s->in->ch_layout.nb_channels; ch++) {
         double *is = (double *)s->is->extended_data[ch];
 
         for (j = 0; j < s->hop_size; j++) {
@@ -580,7 +580,7 @@ static int filter_frame(AVFilterLink *inlink)
     s->pts += av_rescale_q(s->hop_size, (AVRational){1, outlink->sample_rate}, outlink->time_base);
 
     s->detected_errors += detected_errors;
-    s->nb_samples += out->nb_samples * inlink->channels;
+    s->nb_samples += out->nb_samples * inlink->ch_layout.nb_channels;
 
     ret = ff_filter_frame(outlink, out);
     if (ret < 0)
diff --git a/libavfilter/af_adecorrelate.c b/libavfilter/af_adecorrelate.c
index bac7937c10..cadc62c1f7 100644
--- a/libavfilter/af_adecorrelate.c
+++ b/libavfilter/af_adecorrelate.c
@@ -131,12 +131,12 @@ static int config_input(AVFilterLink *inlink)
         s->seed = av_get_random_seed();
     av_lfg_init(&s->c, s->seed);
 
-    s->nb_channels = inlink->channels;
-    s->ap = av_calloc(inlink->channels, sizeof(*s->ap));
+    s->nb_channels = inlink->ch_layout.nb_channels;
+    s->ap = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->ap));
     if (!s->ap)
         return AVERROR(ENOMEM);
 
-    for (int i = 0; i < inlink->channels; i++) {
+    for (int i = 0; i < inlink->ch_layout.nb_channels; i++) {
         for (int j = 0; j < s->stages; j++) {
             ret = ap_init(&s->ap[i][j], inlink->sample_rate,
                           (double)av_lfg_get(&s->c) / 0xffffffff * 2.2917e-3 + 0.83333e-3);
@@ -160,8 +160,8 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo
     ThreadData *td = arg;
     AVFrame *out = td->out;
     AVFrame *in = td->in;
-    const int start = (in->channels * jobnr) / nb_jobs;
-    const int end = (in->channels * (jobnr+1)) / nb_jobs;
+    const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
 
     for (int ch = start; ch < end; ch++)
         s->filter_channel(ctx, ch, in, out);
@@ -189,7 +189,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     td.in = in; td.out = out;
     ff_filter_execute(ctx, filter_channels, &td, NULL,
-                      FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     if (out != in)
         av_frame_free(&in);
diff --git a/libavfilter/af_adelay.c b/libavfilter/af_adelay.c
index ed8a8ae739..c7a8763b36 100644
--- a/libavfilter/af_adelay.c
+++ b/libavfilter/af_adelay.c
@@ -103,10 +103,10 @@ static int config_input(AVFilterLink *inlink)
     char *p, *arg, *saveptr = NULL;
     int i;
 
-    s->chandelay = av_calloc(inlink->channels, sizeof(*s->chandelay));
+    s->chandelay = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->chandelay));
     if (!s->chandelay)
         return AVERROR(ENOMEM);
-    s->nb_delays = inlink->channels;
+    s->nb_delays = inlink->ch_layout.nb_channels;
     s->block_align = av_get_bytes_per_sample(inlink->format);
 
     p = s->delays;
@@ -242,7 +242,7 @@ static int activate(AVFilterContext *ctx)
 
         av_samples_set_silence(frame->extended_data, 0,
                                frame->nb_samples,
-                               outlink->channels,
+                               outlink->ch_layout.nb_channels,
                                frame->format);
 
         frame->pts = s->next_pts;
@@ -274,7 +274,7 @@ static int activate(AVFilterContext *ctx)
 
         av_samples_set_silence(frame->extended_data, 0,
                                frame->nb_samples,
-                               outlink->channels,
+                               outlink->ch_layout.nb_channels,
                                frame->format);
 
         frame->pts = s->next_pts;
diff --git a/libavfilter/af_adenorm.c b/libavfilter/af_adenorm.c
index 3ad1e7f594..04e3338b1a 100644
--- a/libavfilter/af_adenorm.c
+++ b/libavfilter/af_adenorm.c
@@ -200,8 +200,8 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo
     ThreadData *td = arg;
     AVFrame *out = td->out;
     AVFrame *in = td->in;
-    const int start = (in->channels * jobnr) / nb_jobs;
-    const int end = (in->channels * (jobnr+1)) / nb_jobs;
+    const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
 
     for (int ch = start; ch < end; ch++) {
         s->filter(ctx, out->extended_data[ch],
@@ -234,7 +234,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     s->level = exp(s->level_db / 20. * M_LN10);
     td.in = in; td.out = out;
     ff_filter_execute(ctx, filter_channels, &td, NULL,
-                      FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     s->in_samples += in->nb_samples;
 
diff --git a/libavfilter/af_aderivative.c b/libavfilter/af_aderivative.c
index baa272d609..0ebb233a58 100644
--- a/libavfilter/af_aderivative.c
+++ b/libavfilter/af_aderivative.c
@@ -120,7 +120,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     }
 
     s->filter((void **)out->extended_data, (void **)s->prev->extended_data, (const void **)in->extended_data,
-              in->nb_samples, in->channels);
+              in->nb_samples, in->ch_layout.nb_channels);
 
     av_frame_free(&in);
     return ff_filter_frame(outlink, out);
diff --git a/libavfilter/af_adynamicequalizer.c b/libavfilter/af_adynamicequalizer.c
index f377a5db3d..4ebdd1815d 100644
--- a/libavfilter/af_adynamicequalizer.c
+++ b/libavfilter/af_adynamicequalizer.c
@@ -157,8 +157,8 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo
     const double tqfactor = s->tqfactor;
     const double fg = tan(M_PI * tfrequency / sample_rate);
     const double dg = tan(M_PI * dfrequency / sample_rate);
-    const int start = (in->channels * jobnr) / nb_jobs;
-    const int end = (in->channels * (jobnr+1)) / nb_jobs;
+    const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
     const int mode = s->mode;
     const double knee = s->knee;
     const double slew = s->slew;
@@ -245,7 +245,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     td.in = in;
     td.out = out;
     ff_filter_execute(ctx, filter_channels, &td, NULL,
-                     FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
+                     FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     if (out != in)
         av_frame_free(&in);
diff --git a/libavfilter/af_adynamicsmooth.c b/libavfilter/af_adynamicsmooth.c
index 4e00fecc6a..3f98d09f5d 100644
--- a/libavfilter/af_adynamicsmooth.c
+++ b/libavfilter/af_adynamicsmooth.c
@@ -63,7 +63,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         av_frame_copy_props(out, in);
     }
 
-    for (int ch = 0; ch < out->channels; ch++) {
+    for (int ch = 0; ch < out->ch_layout.nb_channels; ch++) {
         const double *src = (const double *)in->extended_data[ch];
         double *dst = (double *)out->extended_data[ch];
         double *coeffs = (double *)s->coeffs->extended_data[ch];
diff --git a/libavfilter/af_aecho.c b/libavfilter/af_aecho.c
index 73d9f1ac7f..e610c30d59 100644
--- a/libavfilter/af_aecho.c
+++ b/libavfilter/af_aecho.c
@@ -236,7 +236,7 @@ static int config_output(AVFilterLink *outlink)
     av_freep(&s->delayptrs);
 
     return av_samples_alloc_array_and_samples(&s->delayptrs, NULL,
-                                              outlink->channels,
+                                              outlink->ch_layout.nb_channels,
                                               s->max_samples,
                                               outlink->format, 0);
 }
@@ -259,7 +259,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
     }
 
     s->echo_samples(s, s->delayptrs, frame->extended_data, out_frame->extended_data,
-                    frame->nb_samples, inlink->channels);
+                    frame->nb_samples, inlink->ch_layout.nb_channels);
 
     s->next_pts = frame->pts + av_rescale_q(frame->nb_samples, (AVRational){1, inlink->sample_rate}, inlink->time_base);
 
@@ -282,11 +282,11 @@ static int request_frame(AVFilterLink *outlink)
 
     av_samples_set_silence(frame->extended_data, 0,
                            frame->nb_samples,
-                           outlink->channels,
+                           outlink->ch_layout.nb_channels,
                            frame->format);
 
     s->echo_samples(s, s->delayptrs, frame->extended_data, frame->extended_data,
-                    frame->nb_samples, outlink->channels);
+                    frame->nb_samples, outlink->ch_layout.nb_channels);
 
     frame->pts = s->next_pts;
     if (s->next_pts != AV_NOPTS_VALUE)
diff --git a/libavfilter/af_aemphasis.c b/libavfilter/af_aemphasis.c
index 1adfcdb63b..91878987d3 100644
--- a/libavfilter/af_aemphasis.c
+++ b/libavfilter/af_aemphasis.c
@@ -105,8 +105,8 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo
     ThreadData *td = arg;
     AVFrame *out = td->out;
     AVFrame *in = td->in;
-    const int start = (in->channels * jobnr) / nb_jobs;
-    const int end = (in->channels * (jobnr+1)) / nb_jobs;
+    const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
 
     for (int ch = start; ch < end; ch++) {
         const double *src = (const double *)in->extended_data[ch];
@@ -144,7 +144,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     td.in = in; td.out = out;
     ff_filter_execute(ctx, filter_channels, &td, NULL,
-                      FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     if (in != out)
         av_frame_free(&in);
diff --git a/libavfilter/af_aexciter.c b/libavfilter/af_aexciter.c
index 5d76f290a0..8e829f992b 100644
--- a/libavfilter/af_aexciter.c
+++ b/libavfilter/af_aexciter.c
@@ -195,7 +195,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     dst = (double *)out->data[0];
     for (int n = 0; n < in->nb_samples; n++) {
-        for (int c = 0; c < inlink->channels; c++) {
+        for (int c = 0; c < inlink->ch_layout.nb_channels; c++) {
             double sample = src[c] * level_in;
 
             sample = distortion_process(s, &s->cp[c], sample);
@@ -208,8 +208,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
                 dst[c] = sample;
         }
 
-        src += inlink->channels;
-        dst += inlink->channels;
+        src += inlink->ch_layout.nb_channels;
+        dst += inlink->ch_layout.nb_channels;
     }
 
     if (in != out)
@@ -231,11 +231,11 @@ static int config_input(AVFilterLink *inlink)
     AExciterContext *s = ctx->priv;
 
     if (!s->cp)
-        s->cp = av_calloc(inlink->channels, sizeof(*s->cp));
+        s->cp = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->cp));
     if (!s->cp)
         return AVERROR(ENOMEM);
 
-    for (int i = 0; i < inlink->channels; i++)
+    for (int i = 0; i < inlink->ch_layout.nb_channels; i++)
         set_params(&s->cp[i], s->blend, s->drive, inlink->sample_rate,
                    s->freq, s->ceil);
 
diff --git a/libavfilter/af_afade.c b/libavfilter/af_afade.c
index c57709050e..e31467ee2b 100644
--- a/libavfilter/af_afade.c
+++ b/libavfilter/af_afade.c
@@ -289,7 +289,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
     if ((!s->type && (cur_sample + nb_samples < s->start_sample)) ||
         ( s->type && (s->start_sample + s->nb_samples < cur_sample))) {
         av_samples_set_silence(out_buf->extended_data, 0, nb_samples,
-                               out_buf->channels, out_buf->format);
+                               out_buf->ch_layout.nb_channels, out_buf->format);
     } else {
         int64_t start;
 
@@ -299,7 +299,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
             start = s->start_sample + s->nb_samples - cur_sample;
 
         s->fade_samples(out_buf->extended_data, buf->extended_data,
-                        nb_samples, buf->channels,
+                        nb_samples, buf->ch_layout.nb_channels,
                         s->type ? -1 : 1, start,
                         s->nb_samples, s->curve);
     }
@@ -502,7 +502,7 @@ static int activate(AVFilterContext *ctx)
 
             s->crossfade_samples(out->extended_data, cf[0]->extended_data,
                                  cf[1]->extended_data,
-                                 s->nb_samples, out->channels,
+                                 s->nb_samples, out->ch_layout.nb_channels,
                                  s->curve, s->curve2);
             out->pts = s->pts;
             s->pts += av_rescale_q(s->nb_samples,
@@ -523,7 +523,7 @@ static int activate(AVFilterContext *ctx)
             }
 
             s->fade_samples(out->extended_data, cf[0]->extended_data, s->nb_samples,
-                            outlink->channels, -1, s->nb_samples - 1, s->nb_samples, s->curve);
+                            outlink->ch_layout.nb_channels, -1, s->nb_samples - 1, s->nb_samples, s->curve);
             out->pts = s->pts;
             s->pts += av_rescale_q(s->nb_samples,
                 (AVRational){ 1, outlink->sample_rate }, outlink->time_base);
@@ -543,7 +543,7 @@ static int activate(AVFilterContext *ctx)
             }
 
             s->fade_samples(out->extended_data, cf[1]->extended_data, s->nb_samples,
-                            outlink->channels, 1, 0, s->nb_samples, s->curve2);
+                            outlink->ch_layout.nb_channels, 1, 0, s->nb_samples, s->curve2);
             out->pts = s->pts;
             s->pts += av_rescale_q(s->nb_samples,
                 (AVRational){ 1, outlink->sample_rate }, outlink->time_base);
diff --git a/libavfilter/af_afftdn.c b/libavfilter/af_afftdn.c
index d1dbbc667b..a70a969ab9 100644
--- a/libavfilter/af_afftdn.c
+++ b/libavfilter/af_afftdn.c
@@ -616,12 +616,12 @@ static int config_input(AVFilterLink *inlink)
     double wscale, sar, sum, sdiv;
     int i, j, k, m, n, ret;
 
-    s->dnch = av_calloc(inlink->channels, sizeof(*s->dnch));
+    s->dnch = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->dnch));
     if (!s->dnch)
         return AVERROR(ENOMEM);
 
     s->pts = AV_NOPTS_VALUE;
-    s->channels = inlink->channels;
+    s->channels = inlink->ch_layout.nb_channels;
     s->sample_rate = inlink->sample_rate;
     s->sample_advance = s->sample_rate / 80;
     s->window_length = 3 * s->sample_advance;
@@ -680,7 +680,7 @@ static int config_input(AVFilterLink *inlink)
     if (!s->band_alpha || !s->band_beta)
         return AVERROR(ENOMEM);
 
-    for (int ch = 0; ch < inlink->channels; ch++) {
+    for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         DeNoiseChannel *dnch = &s->dnch[ch];
         float scale;
 
@@ -761,7 +761,7 @@ static int config_input(AVFilterLink *inlink)
             return AVERROR(ENOMEM);
     }
 
-    for (int ch = 0; ch < inlink->channels; ch++) {
+    for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         DeNoiseChannel *dnch = &s->dnch[ch];
         double *prior_band_excit = dnch->prior_band_excit;
         double *prior = dnch->prior;
@@ -857,7 +857,7 @@ static int config_input(AVFilterLink *inlink)
     }
     s->noise_band_count = s->noise_band_edge[16];
 
-    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->fft_length);
+    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->ch_layout.nb_channels, s->fft_length);
     if (!s->fifo)
         return AVERROR(ENOMEM);
 
@@ -1095,8 +1095,8 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_job
     AudioFFTDeNoiseContext *s = ctx->priv;
     ThreadData *td = arg;
     AVFrame *in = td->in;
-    const int start = (in->channels * jobnr) / nb_jobs;
-    const int end = (in->channels * (jobnr+1)) / nb_jobs;
+    const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
 
     for (int ch = start; ch < end; ch++) {
         DeNoiseChannel *dnch = &s->dnch[ch];
@@ -1179,7 +1179,7 @@ static int output_frame(AVFilterLink *inlink)
         goto end;
 
     if (s->track_noise) {
-        for (int ch = 0; ch < inlink->channels; ch++) {
+        for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
             DeNoiseChannel *dnch = &s->dnch[ch];
             double levels[15];
 
@@ -1192,7 +1192,7 @@ static int output_frame(AVFilterLink *inlink)
     }
 
     if (s->sample_noise_start) {
-        for (int ch = 0; ch < inlink->channels; ch++) {
+        for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
             DeNoiseChannel *dnch = &s->dnch[ch];
 
             init_sample_noise(dnch);
@@ -1202,7 +1202,7 @@ static int output_frame(AVFilterLink *inlink)
     }
 
     if (s->sample_noise) {
-        for (int ch = 0; ch < inlink->channels; ch++) {
+        for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
             DeNoiseChannel *dnch = &s->dnch[ch];
 
             sample_noise_block(s, dnch, in, ch);
@@ -1210,7 +1210,7 @@ static int output_frame(AVFilterLink *inlink)
     }
 
     if (s->sample_noise_end) {
-        for (int ch = 0; ch < inlink->channels; ch++) {
+        for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
             DeNoiseChannel *dnch = &s->dnch[ch];
             double sample_noise[15];
 
@@ -1225,7 +1225,7 @@ static int output_frame(AVFilterLink *inlink)
     s->block_count++;
     td.in = in;
     ff_filter_execute(ctx, filter_channel, &td, NULL,
-                      FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     out = ff_get_audio_buffer(outlink, s->sample_advance);
     if (!out) {
@@ -1233,7 +1233,7 @@ static int output_frame(AVFilterLink *inlink)
         goto end;
     }
 
-    for (int ch = 0; ch < inlink->channels; ch++) {
+    for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         DeNoiseChannel *dnch = &s->dnch[ch];
         double *src = dnch->out_samples;
         float *orig = (float *)in->extended_data[ch];
diff --git a/libavfilter/af_afftfilt.c b/libavfilter/af_afftfilt.c
index 691feeae36..2e3b9a0eca 100644
--- a/libavfilter/af_afftfilt.c
+++ b/libavfilter/af_afftfilt.c
@@ -112,7 +112,7 @@ static int config_input(AVFilterLink *inlink)
     const char *last_expr = "1";
     int buf_size;
 
-    s->channels = inlink->channels;
+    s->channels = inlink->ch_layout.nb_channels;
     s->pts  = AV_NOPTS_VALUE;
     ret = av_tx_init(&s->fft, &s->tx_fn, AV_TX_FLOAT_FFT, 0, s->fft_size, &scale, 0);
     if (ret < 0)
@@ -125,19 +125,19 @@ static int config_input(AVFilterLink *inlink)
     s->window_size = s->fft_size;
     buf_size = FFALIGN(s->window_size, av_cpu_max_align());
 
-    s->fft_in = av_calloc(inlink->channels, sizeof(*s->fft_in));
+    s->fft_in = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->fft_in));
     if (!s->fft_in)
         return AVERROR(ENOMEM);
 
-    s->fft_out = av_calloc(inlink->channels, sizeof(*s->fft_out));
+    s->fft_out = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->fft_out));
     if (!s->fft_out)
         return AVERROR(ENOMEM);
 
-    s->fft_temp = av_calloc(inlink->channels, sizeof(*s->fft_temp));
+    s->fft_temp = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->fft_temp));
     if (!s->fft_temp)
         return AVERROR(ENOMEM);
 
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         s->fft_in[ch] = av_calloc(buf_size, sizeof(**s->fft_in));
         if (!s->fft_in[ch])
             return AVERROR(ENOMEM);
@@ -151,11 +151,11 @@ static int config_input(AVFilterLink *inlink)
             return AVERROR(ENOMEM);
     }
 
-    s->real = av_calloc(inlink->channels, sizeof(*s->real));
+    s->real = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->real));
     if (!s->real)
         return AVERROR(ENOMEM);
 
-    s->imag = av_calloc(inlink->channels, sizeof(*s->imag));
+    s->imag = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->imag));
     if (!s->imag)
         return AVERROR(ENOMEM);
 
@@ -163,7 +163,7 @@ static int config_input(AVFilterLink *inlink)
     if (!args)
         return AVERROR(ENOMEM);
 
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         char *arg = av_strtok(ch == 0 ? args : NULL, "|", &saveptr);
 
         ret = av_expr_parse(&s->real[ch], arg ? arg : last_expr, var_names,
@@ -183,7 +183,7 @@ static int config_input(AVFilterLink *inlink)
 
     saveptr = NULL;
     last_expr = "1";
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         char *arg = av_strtok(ch == 0 ? args : NULL, "|", &saveptr);
 
         ret = av_expr_parse(&s->imag[ch], arg ? arg : last_expr, var_names,
@@ -196,7 +196,7 @@ static int config_input(AVFilterLink *inlink)
 
     av_freep(&args);
 
-    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->window_size);
+    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->ch_layout.nb_channels, s->window_size);
     if (!s->fifo)
         return AVERROR(ENOMEM);
 
@@ -243,7 +243,7 @@ static int filter_frame(AVFilterLink *inlink)
     if (ret < 0)
         goto fail;
 
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         const float *src = (float *)in->extended_data[ch];
         AVComplexFloat *fft_in = s->fft_in[ch];
 
@@ -261,16 +261,16 @@ static int filter_frame(AVFilterLink *inlink)
     values[VAR_PTS]         = s->pts;
     values[VAR_SAMPLE_RATE] = inlink->sample_rate;
     values[VAR_NBBINS]      = window_size / 2;
-    values[VAR_CHANNELS]    = inlink->channels;
+    values[VAR_CHANNELS]    = inlink->ch_layout.nb_channels;
 
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         AVComplexFloat *fft_in = s->fft_in[ch];
         AVComplexFloat *fft_out = s->fft_out[ch];
 
         s->tx_fn(s->fft, fft_out, fft_in, sizeof(float));
     }
 
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         AVComplexFloat *fft_out = s->fft_out[ch];
         AVComplexFloat *fft_temp = s->fft_temp[ch];
         float *buf = (float *)s->buffer->extended_data[ch];
@@ -319,7 +319,7 @@ static int filter_frame(AVFilterLink *inlink)
     out->pts = s->pts;
     s->pts += av_rescale_q(s->hop_size, (AVRational){1, outlink->sample_rate}, outlink->time_base);
 
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         float *dst = (float *)out->extended_data[ch];
         float *buf = (float *)s->buffer->extended_data[ch];
 
diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
index ace5087e90..fa4cad82e2 100644
--- a/libavfilter/af_afir.c
+++ b/libavfilter/af_afir.c
@@ -201,8 +201,8 @@ static int fir_channel(AVFilterContext *ctx, AVFrame *out, int ch)
 static int fir_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 {
     AVFrame *out = arg;
-    const int start = (out->channels * jobnr) / nb_jobs;
-    const int end = (out->channels * (jobnr+1)) / nb_jobs;
+    const int start = (out->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (out->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
 
     for (int ch = start; ch < end; ch++) {
         fir_channel(ctx, out, ch);
@@ -226,7 +226,7 @@ static int fir_frame(AudioFIRContext *s, AVFrame *in, AVFilterLink *outlink)
         s->pts = in->pts;
     s->in = in;
     ff_filter_execute(ctx, fir_channels, out, NULL,
-                      FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     out->pts = s->pts;
     if (s->pts != AV_NOPTS_VALUE)
@@ -304,7 +304,7 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out)
     if (!mag || !phase || !delay)
         goto end;
 
-    channel = av_clip(s->ir_channel, 0, s->ir[s->selir]->channels - 1);
+    channel = av_clip(s->ir_channel, 0, s->ir[s->selir]->ch_layout.nb_channels - 1);
     for (i = 0; i < s->w; i++) {
         const float *src = (const float *)s->ir[s->selir]->extended_data[channel];
         double w = i * M_PI / (s->w - 1);
@@ -381,8 +381,8 @@ static int init_segment(AVFilterContext *ctx, AudioFIRSegment *seg,
 {
     AudioFIRContext *s = ctx->priv;
 
-    seg->rdft  = av_calloc(ctx->inputs[0]->channels, sizeof(*seg->rdft));
-    seg->irdft = av_calloc(ctx->inputs[0]->channels, sizeof(*seg->irdft));
+    seg->rdft  = av_calloc(ctx->inputs[0]->ch_layout.nb_channels, sizeof(*seg->rdft));
+    seg->irdft = av_calloc(ctx->inputs[0]->ch_layout.nb_channels, sizeof(*seg->irdft));
     if (!seg->rdft || !seg->irdft)
         return AVERROR(ENOMEM);
 
@@ -394,12 +394,12 @@ static int init_segment(AVFilterContext *ctx, AudioFIRSegment *seg,
     seg->input_size    = offset + s->min_part_size;
     seg->input_offset  = offset;
 
-    seg->part_index    = av_calloc(ctx->inputs[0]->channels, sizeof(*seg->part_index));
-    seg->output_offset = av_calloc(ctx->inputs[0]->channels, sizeof(*seg->output_offset));
+    seg->part_index    = av_calloc(ctx->inputs[0]->ch_layout.nb_channels, sizeof(*seg->part_index));
+    seg->output_offset = av_calloc(ctx->inputs[0]->ch_layout.nb_channels, sizeof(*seg->output_offset));
     if (!seg->part_index || !seg->output_offset)
         return AVERROR(ENOMEM);
 
-    for (int ch = 0; ch < ctx->inputs[0]->channels && part_size >= 8; ch++) {
+    for (int ch = 0; ch < ctx->inputs[0]->ch_layout.nb_channels && part_size >= 8; ch++) {
         seg->rdft[ch]  = av_rdft_init(av_log2(2 * part_size), DFT_R2C);
         seg->irdft[ch] = av_rdft_init(av_log2(2 * part_size), IDFT_C2R);
         if (!seg->rdft[ch] || !seg->irdft[ch])
@@ -506,25 +506,25 @@ static int convert_coeffs(AVFilterContext *ctx)
         /* nothing to do */
         break;
     case 0:
-        for (ch = 0; ch < ctx->inputs[1 + s->selir]->channels; ch++) {
+        for (ch = 0; ch < ctx->inputs[1 + s->selir]->ch_layout.nb_channels; ch++) {
             float *time = (float *)s->ir[s->selir]->extended_data[!s->one2many * ch];
 
             for (i = 0; i < cur_nb_taps; i++)
                 power += FFABS(time[i]);
         }
-        s->gain = ctx->inputs[1 + s->selir]->channels / power;
+        s->gain = ctx->inputs[1 + s->selir]->ch_layout.nb_channels / power;
         break;
     case 1:
-        for (ch = 0; ch < ctx->inputs[1 + s->selir]->channels; ch++) {
+        for (ch = 0; ch < ctx->inputs[1 + s->selir]->ch_layout.nb_channels; ch++) {
             float *time = (float *)s->ir[s->selir]->extended_data[!s->one2many * ch];
 
             for (i = 0; i < cur_nb_taps; i++)
                 power += time[i];
         }
-        s->gain = ctx->inputs[1 + s->selir]->channels / power;
+        s->gain = ctx->inputs[1 + s->selir]->ch_layout.nb_channels / power;
         break;
     case 2:
-        for (ch = 0; ch < ctx->inputs[1 + s->selir]->channels; ch++) {
+        for (ch = 0; ch < ctx->inputs[1 + s->selir]->ch_layout.nb_channels; ch++) {
             float *time = (float *)s->ir[s->selir]->extended_data[!s->one2many * ch];
 
             for (i = 0; i < cur_nb_taps; i++)
@@ -538,7 +538,7 @@ static int convert_coeffs(AVFilterContext *ctx)
 
     s->gain = FFMIN(s->gain * s->ir_gain, 1.f);
     av_log(ctx, AV_LOG_DEBUG, "power %f, gain %f\n", power, s->gain);
-    for (ch = 0; ch < ctx->inputs[1 + s->selir]->channels; ch++) {
+    for (ch = 0; ch < ctx->inputs[1 + s->selir]->ch_layout.nb_channels; ch++) {
         float *time = (float *)s->ir[s->selir]->extended_data[!s->one2many * ch];
 
         s->fdsp->vector_fmul_scalar(time, time, s->gain, FFALIGN(cur_nb_taps, 4));
@@ -547,7 +547,7 @@ static int convert_coeffs(AVFilterContext *ctx)
     av_log(ctx, AV_LOG_DEBUG, "nb_taps: %d\n", cur_nb_taps);
     av_log(ctx, AV_LOG_DEBUG, "nb_segments: %d\n", s->nb_segments);
 
-    for (ch = 0; ch < ctx->inputs[1 + s->selir]->channels; ch++) {
+    for (ch = 0; ch < ctx->inputs[1 + s->selir]->ch_layout.nb_channels; ch++) {
         float *time = (float *)s->ir[s->selir]->extended_data[!s->one2many * ch];
         int toffset = 0;
 
@@ -745,7 +745,7 @@ static int query_formats(AVFilterContext *ctx)
         if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0)
             return ret;
 
-        ret = ff_add_channel_layout(&mono, AV_CH_LAYOUT_MONO);
+        ret = ff_add_channel_layout(&mono, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO);
         if (ret)
             return ret;
         for (int i = 1; i < ctx->nb_inputs; i++) {
@@ -764,15 +764,22 @@ static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
     AudioFIRContext *s = ctx->priv;
+    int ret;
 
-    s->one2many = ctx->inputs[1 + s->selir]->channels == 1;
+    s->one2many = ctx->inputs[1 + s->selir]->ch_layout.nb_channels == 1;
     outlink->sample_rate = ctx->inputs[0]->sample_rate;
     outlink->time_base   = ctx->inputs[0]->time_base;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     outlink->channel_layout = ctx->inputs[0]->channel_layout;
-    outlink->channels = ctx->inputs[0]->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((ret = av_channel_layout_copy(&outlink->ch_layout, &ctx->inputs[0]->ch_layout)) < 0)
+        return ret;
+    outlink->ch_layout.nb_channels = ctx->inputs[0]->ch_layout.nb_channels;
 
-    s->nb_channels = outlink->channels;
-    s->nb_coef_channels = ctx->inputs[1 + s->selir]->channels;
+    s->nb_channels = outlink->ch_layout.nb_channels;
+    s->nb_coef_channels = ctx->inputs[1 + s->selir]->ch_layout.nb_channels;
     s->pts = AV_NOPTS_VALUE;
 
     return 0;
diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c
index ed3c75311a..96704e041c 100644
--- a/libavfilter/af_aformat.c
+++ b/libavfilter/af_aformat.c
@@ -104,9 +104,36 @@ static av_cold int init(AVFilterContext *ctx)
                   ff_add_format, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format");
     PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format,
                   get_sample_rate, 0, "sample rate");
-    PARSE_FORMATS(s->channel_layouts_str, uint64_t, s->channel_layouts,
-                  ff_add_channel_layout, av_get_channel_layout, 0,
-                  "channel layout");
+    {
+        AVChannelLayout fmt = { 0 };
+        const char *cur = s->channel_layouts_str;
+        int ret;
+
+        if (s->channel_layouts_str && strchr(s->channel_layouts_str, ',')) {
+            av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use '|' to "
+                   "separate channel layout.\n");
+        }
+
+        while (cur && *cur) {
+            char *chl = av_get_token(&cur, "|,");
+            if (!chl)
+                return AVERROR(ENOMEM);
+            if (*cur)
+                cur++;
+
+            ret = av_channel_layout_from_string(&fmt, chl);
+            if (ret < 0) {
+                av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: %s.\n", chl);
+                av_free(chl);
+                return ret;
+            }
+            ret = ff_add_channel_layout(&s->channel_layouts, &fmt);
+            av_channel_layout_uninit(&fmt);
+            av_free(chl);
+            if (ret < 0)
+                return ret;
+        }
+    }
 
     return 0;
 }
diff --git a/libavfilter/af_afreqshift.c b/libavfilter/af_afreqshift.c
index 731e97afef..70bf8e419f 100644
--- a/libavfilter/af_afreqshift.c
+++ b/libavfilter/af_afreqshift.c
@@ -290,8 +290,8 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo
     ThreadData *td = arg;
     AVFrame *out = td->out;
     AVFrame *in = td->in;
-    const int start = (in->channels * jobnr) / nb_jobs;
-    const int end = (in->channels * (jobnr+1)) / nb_jobs;
+    const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
 
     for (int ch = start; ch < end; ch++)
         s->filter_channel(ctx, ch, in, out);
@@ -324,7 +324,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     td.in = in; td.out = out;
     ff_filter_execute(ctx, filter_channels, &td, NULL,
-                      FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     s->in_samples += in->nb_samples;
 
diff --git a/libavfilter/af_afwtdn.c b/libavfilter/af_afwtdn.c
index 09b504d634..cf41b6f4bc 100644
--- a/libavfilter/af_afwtdn.c
+++ b/libavfilter/af_afwtdn.c
@@ -1037,14 +1037,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         s->padd_samples -= s->nb_samples - (in ? in->nb_samples: 0);
         if (in)
             av_samples_copy(new_in->extended_data, in->extended_data, 0, 0,
-                            in->nb_samples, in->channels, in->format);
+                            in->nb_samples, in->ch_layout.nb_channels, in->format);
         av_frame_free(&in);
         in = new_in;
     }
 
     td.in  = in;
     td.out = out;
-    ff_filter_execute(ctx, s->filter_channel, &td, NULL, inlink->channels);
+    ff_filter_execute(ctx, s->filter_channel, &td, NULL, inlink->ch_layout.nb_channels);
     if (s->need_profile)
         s->got_profile = 1;
 
@@ -1059,7 +1059,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         FF_FILTER_FORWARD_WANTED(outlink, inlink);
         return 0;
     } else if (s->drop_samples > 0) {
-        for (int ch = 0; ch < out->channels; ch++) {
+        for (int ch = 0; ch < out->ch_layout.nb_channels; ch++) {
             memmove(out->extended_data[ch],
                     out->extended_data[ch] + s->drop_samples * sizeof(double),
                     (in->nb_samples - s->drop_samples) * sizeof(double));
@@ -1164,7 +1164,7 @@ static int config_output(AVFilterLink *outlink)
         !s->new_stddev || !s->new_absmean)
         return AVERROR(ENOMEM);
 
-    s->channels = outlink->channels;
+    s->channels = outlink->ch_layout.nb_channels;
     s->overlap_length = max_left_ext(s->wavelet_length, s->levels);
     s->prev_length = s->overlap_length;
     s->drop_samples = s->overlap_length;
diff --git a/libavfilter/af_agate.c b/libavfilter/af_agate.c
index 682f17c7dd..8e93a3a82b 100644
--- a/libavfilter/af_agate.c
+++ b/libavfilter/af_agate.c
@@ -150,19 +150,19 @@ static void gate(AudioGateContext *s,
     const double release_coeff = s->release_coeff;
     int n, c;
 
-    for (n = 0; n < nb_samples; n++, src += inlink->channels, dst += inlink->channels, scsrc += sclink->channels) {
+    for (n = 0; n < nb_samples; n++, src += inlink->ch_layout.nb_channels, dst += inlink->ch_layout.nb_channels, scsrc += sclink->ch_layout.nb_channels) {
         double abs_sample = fabs(scsrc[0] * level_sc), gain = 1.0;
         double factor;
         int detected;
 
         if (s->link == 1) {
-            for (c = 1; c < sclink->channels; c++)
+            for (c = 1; c < sclink->ch_layout.nb_channels; c++)
                 abs_sample = FFMAX(fabs(scsrc[c] * level_sc), abs_sample);
         } else {
-            for (c = 1; c < sclink->channels; c++)
+            for (c = 1; c < sclink->ch_layout.nb_channels; c++)
                 abs_sample += fabs(scsrc[c] * level_sc);
 
-            abs_sample /= sclink->channels;
+            abs_sample /= sclink->ch_layout.nb_channels;
         }
 
         if (s->detection)
@@ -181,7 +181,7 @@ static void gate(AudioGateContext *s,
                                s->range, s->mode);
 
         factor = ctx->is_disabled ? 1.f : level_in * gain * makeup;
-        for (c = 0; c < inlink->channels; c++)
+        for (c = 0; c < inlink->ch_layout.nb_channels; c++)
             dst[c] = src[c] * factor;
     }
 }
@@ -344,8 +344,8 @@ static int scconfig_output(AVFilterLink *outlink)
 
     outlink->time_base   = ctx->inputs[0]->time_base;
 
-    s->fifo[0] = av_audio_fifo_alloc(ctx->inputs[0]->format, ctx->inputs[0]->channels, 1024);
-    s->fifo[1] = av_audio_fifo_alloc(ctx->inputs[1]->format, ctx->inputs[1]->channels, 1024);
+    s->fifo[0] = av_audio_fifo_alloc(ctx->inputs[0]->format, ctx->inputs[0]->ch_layout.nb_channels, 1024);
+    s->fifo[1] = av_audio_fifo_alloc(ctx->inputs[1]->format, ctx->inputs[1]->ch_layout.nb_channels, 1024);
     if (!s->fifo[0] || !s->fifo[1])
         return AVERROR(ENOMEM);
 
diff --git a/libavfilter/af_aiir.c b/libavfilter/af_aiir.c
index 8a4b4814f6..3e7ec78b63 100644
--- a/libavfilter/af_aiir.c
+++ b/libavfilter/af_aiir.c
@@ -1263,35 +1263,35 @@ static int config_output(AVFilterLink *outlink)
     AVFilterLink *inlink = ctx->inputs[0];
     int ch, ret, i;
 
-    s->channels = inlink->channels;
+    s->channels = inlink->ch_layout.nb_channels;
     s->iir = av_calloc(s->channels, sizeof(*s->iir));
     if (!s->iir)
         return AVERROR(ENOMEM);
 
-    ret = read_gains(ctx, s->g_str, inlink->channels);
+    ret = read_gains(ctx, s->g_str, inlink->ch_layout.nb_channels);
     if (ret < 0)
         return ret;
 
-    ret = read_channels(ctx, inlink->channels, s->a_str, 0);
+    ret = read_channels(ctx, inlink->ch_layout.nb_channels, s->a_str, 0);
     if (ret < 0)
         return ret;
 
-    ret = read_channels(ctx, inlink->channels, s->b_str, 1);
+    ret = read_channels(ctx, inlink->ch_layout.nb_channels, s->b_str, 1);
     if (ret < 0)
         return ret;
 
     if (s->format == -1) {
-        convert_sf2tf(ctx, inlink->channels);
+        convert_sf2tf(ctx, inlink->ch_layout.nb_channels);
         s->format = 0;
     } else if (s->format == 2) {
-        convert_pr2zp(ctx, inlink->channels);
+        convert_pr2zp(ctx, inlink->ch_layout.nb_channels);
     } else if (s->format == 3) {
-        convert_pd2zp(ctx, inlink->channels);
+        convert_pd2zp(ctx, inlink->ch_layout.nb_channels);
     } else if (s->format == 4) {
-        convert_sp2zp(ctx, inlink->channels);
+        convert_sp2zp(ctx, inlink->ch_layout.nb_channels);
     }
     if (s->format > 0) {
-        check_stability(ctx, inlink->channels);
+        check_stability(ctx, inlink->ch_layout.nb_channels);
     }
 
     av_frame_free(&s->video);
@@ -1309,7 +1309,7 @@ static int config_output(AVFilterLink *outlink)
     if (s->format > 0 && s->process == 0) {
         av_log(ctx, AV_LOG_WARNING, "Direct processsing is not recommended for zp coefficients format.\n");
 
-        ret = convert_zp2tf(ctx, inlink->channels);
+        ret = convert_zp2tf(ctx, inlink->ch_layout.nb_channels);
         if (ret < 0)
             return ret;
     } else if (s->format == -2 && s->process > 0) {
@@ -1322,21 +1322,21 @@ static int config_output(AVFilterLink *outlink)
         av_log(ctx, AV_LOG_ERROR, "Parallel processing is not implemented for transfer function.\n");
         return AVERROR_PATCHWELCOME;
     } else if (s->format > 0 && s->process == 1) {
-        ret = decompose_zp2biquads(ctx, inlink->channels);
+        ret = decompose_zp2biquads(ctx, inlink->ch_layout.nb_channels);
         if (ret < 0)
             return ret;
     } else if (s->format > 0 && s->process == 2) {
         if (s->precision > 1)
             av_log(ctx, AV_LOG_WARNING, "Parallel processing is not recommended for fixed-point precisions.\n");
-        ret = decompose_zp2biquads(ctx, inlink->channels);
+        ret = decompose_zp2biquads(ctx, inlink->ch_layout.nb_channels);
         if (ret < 0)
             return ret;
-        ret = convert_serial2parallel(ctx, inlink->channels);
+        ret = convert_serial2parallel(ctx, inlink->ch_layout.nb_channels);
         if (ret < 0)
             return ret;
     }
 
-    for (ch = 0; s->format == -2 && ch < inlink->channels; ch++) {
+    for (ch = 0; s->format == -2 && ch < inlink->ch_layout.nb_channels; ch++) {
         IIRChannel *iir = &s->iir[ch];
 
         if (iir->nb_ab[0] != iir->nb_ab[1] + 1) {
@@ -1345,7 +1345,7 @@ static int config_output(AVFilterLink *outlink)
         }
     }
 
-    for (ch = 0; s->format == 0 && ch < inlink->channels; ch++) {
+    for (ch = 0; s->format == 0 && ch < inlink->ch_layout.nb_channels; ch++) {
         IIRChannel *iir = &s->iir[ch];
 
         for (i = 1; i < iir->nb_ab[0]; i++) {
@@ -1401,9 +1401,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     td.in  = in;
     td.out = out;
-    ff_filter_execute(ctx, s->iir_channel, &td, NULL, outlink->channels);
+    ff_filter_execute(ctx, s->iir_channel, &td, NULL, outlink->ch_layout.nb_channels);
 
-    for (ch = 0; ch < outlink->channels; ch++) {
+    for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {
         if (s->iir[ch].clippings > 0)
             av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
                    ch, s->iir[ch].clippings);
diff --git a/libavfilter/af_alimiter.c b/libavfilter/af_alimiter.c
index 211941a511..133f98f165 100644
--- a/libavfilter/af_alimiter.c
+++ b/libavfilter/af_alimiter.c
@@ -116,7 +116,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     AudioLimiterContext *s = ctx->priv;
     AVFilterLink *outlink = ctx->outputs[0];
     const double *src = (const double *)in->data[0];
-    const int channels = inlink->channels;
+    const int channels = inlink->ch_layout.nb_channels;
     const int buffer_size = s->buffer_size;
     double *dst, *buffer = s->buffer;
     const double release = s->release;
@@ -281,8 +281,8 @@ static int config_input(AVFilterLink *inlink)
     AudioLimiterContext *s = ctx->priv;
     int obuffer_size;
 
-    obuffer_size = inlink->sample_rate * inlink->channels * 100 / 1000. + inlink->channels;
-    if (obuffer_size < inlink->channels)
+    obuffer_size = inlink->sample_rate * inlink->ch_layout.nb_channels * 100 / 1000. + inlink->ch_layout.nb_channels;
+    if (obuffer_size < inlink->ch_layout.nb_channels)
         return AVERROR(EINVAL);
 
     s->buffer = av_calloc(obuffer_size, sizeof(*s->buffer));
@@ -292,8 +292,8 @@ static int config_input(AVFilterLink *inlink)
         return AVERROR(ENOMEM);
 
     memset(s->nextpos, -1, obuffer_size * sizeof(*s->nextpos));
-    s->buffer_size = inlink->sample_rate * s->attack * inlink->channels;
-    s->buffer_size -= s->buffer_size % inlink->channels;
+    s->buffer_size = inlink->sample_rate * s->attack * inlink->ch_layout.nb_channels;
+    s->buffer_size -= s->buffer_size % inlink->ch_layout.nb_channels;
 
     if (s->buffer_size <= 0) {
         av_log(ctx, AV_LOG_ERROR, "Attack is too small.\n");
diff --git a/libavfilter/af_amerge.c b/libavfilter/af_amerge.c
index 9109af22c5..8bcc0ac5be 100644
--- a/libavfilter/af_amerge.c
+++ b/libavfilter/af_amerge.c
@@ -73,7 +73,8 @@ static int query_formats(AVFilterContext *ctx)
         AV_SAMPLE_FMT_NONE
     };
     AMergeContext *s = ctx->priv;
-    int64_t inlayout[SWR_CH_MAX], outlayout = 0;
+    AVChannelLayout *inlayout[SWR_CH_MAX] = { NULL }, outlayout = { 0 };
+    uint64_t outmask = 0;
     AVFilterChannelLayouts *layouts;
     int i, ret, overlap = 0, nb_ch = 0;
 
@@ -84,20 +85,21 @@ static int query_formats(AVFilterContext *ctx)
                    "No channel layout for input %d\n", i + 1);
             return AVERROR(EAGAIN);
         }
-        inlayout[i] = ctx->inputs[i]->incfg.channel_layouts->channel_layouts[0];
+        inlayout[i] = &ctx->inputs[i]->incfg.channel_layouts->channel_layouts[0];
         if (ctx->inputs[i]->incfg.channel_layouts->nb_channel_layouts > 1) {
             char buf[256];
-            av_get_channel_layout_string(buf, sizeof(buf), 0, inlayout[i]);
+            av_channel_layout_describe(inlayout[i], buf, sizeof(buf));
             av_log(ctx, AV_LOG_INFO, "Using \"%s\" for input %d\n", buf, i + 1);
         }
         s->in[i].nb_ch = FF_LAYOUT2COUNT(inlayout[i]);
         if (s->in[i].nb_ch) {
             overlap++;
         } else {
-            s->in[i].nb_ch = av_get_channel_layout_nb_channels(inlayout[i]);
-            if (outlayout & inlayout[i])
+            s->in[i].nb_ch = inlayout[i]->nb_channels;
+            if (av_channel_layout_subset(inlayout[i], outmask))
                 overlap++;
-            outlayout |= inlayout[i];
+            outmask |= inlayout[i]->order == AV_CHANNEL_ORDER_NATIVE ?
+                       inlayout[i]->u.mask : 0;
         }
         nb_ch += s->in[i].nb_ch;
     }
@@ -111,19 +113,20 @@ static int query_formats(AVFilterContext *ctx)
                "output layout will be determined by the number of distinct input channels\n");
         for (i = 0; i < nb_ch; i++)
             s->route[i] = i;
-        outlayout = av_get_default_channel_layout(nb_ch);
-        if (!outlayout && nb_ch)
-            outlayout = 0xFFFFFFFFFFFFFFFFULL >> (64 - nb_ch);
+        av_channel_layout_default(&outlayout, nb_ch);
+        if (!KNOWN(&outlayout) && nb_ch)
+            av_channel_layout_from_mask(&outlayout, 0xFFFFFFFFFFFFFFFFULL >> (64 - nb_ch));
     } else {
         int *route[SWR_CH_MAX];
         int c, out_ch_number = 0;
 
+        av_channel_layout_from_mask(&outlayout, outmask);
         route[0] = s->route;
         for (i = 1; i < s->nb_inputs; i++)
             route[i] = route[i - 1] + s->in[i - 1].nb_ch;
         for (c = 0; c < 64; c++)
             for (i = 0; i < s->nb_inputs; i++)
-                if ((inlayout[i] >> c) & 1)
+                if (av_channel_layout_index_from_channel(inlayout[i], c) >= 0)
                     *(route[i]++) = out_ch_number++;
     }
     if ((ret = ff_set_common_formats_from_list(ctx, packed_sample_fmts)) < 0)
@@ -136,7 +139,7 @@ static int query_formats(AVFilterContext *ctx)
             return ret;
     }
     layouts = NULL;
-    if ((ret = ff_add_channel_layout(&layouts, outlayout)) < 0)
+    if ((ret = ff_add_channel_layout(&layouts, &outlayout)) < 0)
         return ret;
     if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0)
         return ret;
@@ -149,6 +152,7 @@ static int config_output(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     AMergeContext *s = ctx->priv;
     AVBPrint bp;
+    char buf[128];
     int i;
 
     s->bps = av_get_bytes_per_sample(ctx->outputs[0]->format);
@@ -157,10 +161,12 @@ static int config_output(AVFilterLink *outlink)
     av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
     for (i = 0; i < s->nb_inputs; i++) {
         av_bprintf(&bp, "%sin%d:", i ? " + " : "", i);
-        av_bprint_channel_layout(&bp, -1, ctx->inputs[i]->channel_layout);
+        av_channel_layout_describe(&ctx->inputs[i]->ch_layout, buf, sizeof(buf));
+        av_bprintf(&bp, "%s", buf);
     }
     av_bprintf(&bp, " -> out:");
-    av_bprint_channel_layout(&bp, -1, ctx->outputs[0]->channel_layout);
+    av_channel_layout_describe(&ctx->outputs[0]->ch_layout, buf, sizeof(buf));
+    av_bprintf(&bp, "%s", buf);
     av_log(ctx, AV_LOG_VERBOSE, "%s\n", bp.str);
 
     return 0;
@@ -237,8 +243,14 @@ static int try_push_frame(AVFilterContext *ctx, int nb_samples)
     outbuf->pts = inbuf[0]->pts;
 
     outbuf->nb_samples     = nb_samples;
+    if ((ret = av_channel_layout_copy(&outbuf->ch_layout, &outlink->ch_layout)) < 0)
+        return ret;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     outbuf->channel_layout = outlink->channel_layout;
-    outbuf->channels       = outlink->channels;
+    outbuf->channels       = outlink->ch_layout.nb_channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     while (nb_samples) {
         /* Unroll the most common sample formats: speed +~350% for the loop,
diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index 3f51d43acd..d7e00ab1f1 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -261,7 +261,7 @@ static int config_output(AVFilterLink *outlink)
     if (!s->fifos)
         return AVERROR(ENOMEM);
 
-    s->nb_channels = outlink->channels;
+    s->nb_channels = outlink->ch_layout.nb_channels;
     for (i = 0; i < s->nb_inputs; i++) {
         s->fifos[i] = av_audio_fifo_alloc(outlink->format, s->nb_channels, 1024);
         if (!s->fifos[i])
@@ -282,7 +282,7 @@ static int config_output(AVFilterLink *outlink)
         s->scale_norm[i] = s->weight_sum / FFABS(s->weights[i]);
     calculate_scales(s, 0);
 
-    av_get_channel_layout_string(buf, sizeof(buf), -1, outlink->channel_layout);
+    av_channel_layout_describe(&outlink->ch_layout, buf, sizeof(buf));
 
     av_log(ctx, AV_LOG_VERBOSE,
            "inputs:%d fmt:%s srate:%d cl:%s\n", s->nb_inputs,
diff --git a/libavfilter/af_amultiply.c b/libavfilter/af_amultiply.c
index 5de711bade..97728954a5 100644
--- a/libavfilter/af_amultiply.c
+++ b/libavfilter/af_amultiply.c
@@ -128,8 +128,8 @@ static int config_output(AVFilterLink *outlink)
     AudioMultiplyContext *s = ctx->priv;
     AVFilterLink *inlink = ctx->inputs[0];
 
-    s->channels = inlink->channels;
-    s->planes = av_sample_fmt_is_planar(inlink->format) ? inlink->channels : 1;
+    s->channels = inlink->ch_layout.nb_channels;
+    s->planes = av_sample_fmt_is_planar(inlink->format) ? inlink->ch_layout.nb_channels : 1;
     s->samples_align = 16;
 
     return 0;
diff --git a/libavfilter/af_anequalizer.c b/libavfilter/af_anequalizer.c
index 57a9b7634b..c7b9a83d99 100644
--- a/libavfilter/af_anequalizer.c
+++ b/libavfilter/af_anequalizer.c
@@ -103,7 +103,7 @@ static void draw_curves(AVFilterContext *ctx, AVFilterLink *inlink, AVFrame *out
 
     memset(out->data[0], 0, s->h * out->linesize[0]);
 
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
         int prev_v = -1;
         double f;
@@ -577,8 +577,8 @@ static int config_input(AVFilterLink *inlink)
     if (!args)
         return AVERROR(ENOMEM);
 
-    s->nb_allocated = 32 * inlink->channels;
-    s->filters = av_calloc(inlink->channels, 32 * sizeof(*s->filters));
+    s->nb_allocated = 32 * inlink->ch_layout.nb_channels;
+    s->filters = av_calloc(inlink->ch_layout.nb_channels, 32 * sizeof(*s->filters));
     if (!s->filters) {
         s->nb_allocated = 0;
         av_free(args);
@@ -610,7 +610,7 @@ static int config_input(AVFilterLink *inlink)
             s->filters[s->nb_filters].ignore = 1;
 
         if (s->filters[s->nb_filters].channel < 0 ||
-            s->filters[s->nb_filters].channel >= inlink->channels)
+            s->filters[s->nb_filters].channel >= inlink->ch_layout.nb_channels)
             s->filters[s->nb_filters].ignore = 1;
 
         s->filters[s->nb_filters].type = av_clip(s->filters[s->nb_filters].type, 0, NB_TYPES - 1);
@@ -698,8 +698,8 @@ static int filter_channels(AVFilterContext *ctx, void *arg,
 {
     AudioNEqualizerContext *s = ctx->priv;
     AVFrame *buf = arg;
-    const int start = (buf->channels * jobnr) / nb_jobs;
-    const int end = (buf->channels * (jobnr+1)) / nb_jobs;
+    const int start = (buf->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (buf->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
 
     for (int i = 0; i < s->nb_filters; i++) {
         EqualizatorFilter *f = &s->filters[i];
@@ -731,7 +731,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
 
     if (!ctx->is_disabled)
         ff_filter_execute(ctx, filter_channels, buf, NULL,
-                          FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+                          FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     if (s->draw_curves) {
         AVFrame *clone;
diff --git a/libavfilter/af_anlmdn.c b/libavfilter/af_anlmdn.c
index 141e5f398e..6fcf9e9d66 100644
--- a/libavfilter/af_anlmdn.c
+++ b/libavfilter/af_anlmdn.c
@@ -189,7 +189,7 @@ static int config_output(AVFilterLink *outlink)
     if (ret < 0)
         return ret;
 
-    s->fifo = av_audio_fifo_alloc(outlink->format, outlink->channels, s->N);
+    s->fifo = av_audio_fifo_alloc(outlink->format, outlink->ch_layout.nb_channels, s->N);
     if (!s->fifo)
         return AVERROR(ENOMEM);
 
@@ -292,7 +292,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         if (ret < 0)
             break;
 
-        ff_filter_execute(ctx, filter_channel, out, NULL, inlink->channels);
+        ff_filter_execute(ctx, filter_channel, out, NULL, inlink->ch_layout.nb_channels);
 
         av_audio_fifo_drain(s->fifo, s->H);
 
diff --git a/libavfilter/af_anlms.c b/libavfilter/af_anlms.c
index f20e3c0e82..50bb0c7f42 100644
--- a/libavfilter/af_anlms.c
+++ b/libavfilter/af_anlms.c
@@ -156,8 +156,8 @@ static int process_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_j
 {
     AudioNLMSContext *s = ctx->priv;
     AVFrame *out = arg;
-    const int start = (out->channels * jobnr) / nb_jobs;
-    const int end = (out->channels * (jobnr+1)) / nb_jobs;
+    const int start = (out->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (out->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
 
     for (int c = start; c < end; c++) {
         const float *input = (const float *)s->frame[0]->extended_data[c];
@@ -208,7 +208,7 @@ static int activate(AVFilterContext *ctx)
         }
 
         ff_filter_execute(ctx, process_channels, out, NULL,
-                          FFMIN(ctx->outputs[0]->channels, ff_filter_get_nb_threads(ctx)));
+                          FFMIN(ctx->outputs[0]->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
         out->pts = s->frame[0]->pts;
 
diff --git a/libavfilter/af_apad.c b/libavfilter/af_apad.c
index ae73f0b6b1..df17c9a531 100644
--- a/libavfilter/af_apad.c
+++ b/libavfilter/af_apad.c
@@ -121,7 +121,7 @@ static int request_frame(AVFilterLink *outlink)
 
         av_samples_set_silence(outsamplesref->extended_data, 0,
                                n_out,
-                               outsamplesref->channels,
+                               outsamplesref->ch_layout.nb_channels,
                                outsamplesref->format);
 
         outsamplesref->pts = s->next_pts;
diff --git a/libavfilter/af_aphaser.c b/libavfilter/af_aphaser.c
index 2d95802677..1f5dcb1f9e 100644
--- a/libavfilter/af_aphaser.c
+++ b/libavfilter/af_aphaser.c
@@ -177,7 +177,7 @@ static int config_output(AVFilterLink *outlink)
         av_log(outlink->src, AV_LOG_ERROR, "delay is too small\n");
         return AVERROR(EINVAL);
     }
-    s->delay_buffer = av_calloc(s->delay_buffer_length, sizeof(*s->delay_buffer) * inlink->channels);
+    s->delay_buffer = av_calloc(s->delay_buffer_length, sizeof(*s->delay_buffer) * inlink->ch_layout.nb_channels);
     s->modulation_buffer_length = inlink->sample_rate / s->speed + 0.5;
     s->modulation_buffer = av_malloc_array(s->modulation_buffer_length, sizeof(*s->modulation_buffer));
 
@@ -223,7 +223,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inbuf)
     }
 
     s->phaser(s, inbuf->extended_data, outbuf->extended_data,
-              outbuf->nb_samples, outbuf->channels);
+              outbuf->nb_samples, outbuf->ch_layout.nb_channels);
 
     if (inbuf != outbuf)
         av_frame_free(&inbuf);
diff --git a/libavfilter/af_apsyclip.c b/libavfilter/af_apsyclip.c
index dc3a8e97e4..b8b0f0ad46 100644
--- a/libavfilter/af_apsyclip.c
+++ b/libavfilter/af_apsyclip.c
@@ -244,7 +244,7 @@ static int config_input(AVFilterLink *inlink)
 
     generate_spread_table(s);
 
-    s->channels = inlink->channels;
+    s->channels = inlink->ch_layout.nb_channels;
 
     s->tx_ctx = av_calloc(s->channels, sizeof(*s->tx_ctx));
     s->itx_ctx = av_calloc(s->channels, sizeof(*s->itx_ctx));
@@ -533,8 +533,8 @@ static int psy_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 {
     AudioPsyClipContext *s = ctx->priv;
     AVFrame *out = arg;
-    const int start = (out->channels * jobnr) / nb_jobs;
-    const int end = (out->channels * (jobnr+1)) / nb_jobs;
+    const int start = (out->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (out->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
 
     for (int ch = start; ch < end; ch++)
         psy_channel(ctx, s->in, out, ch);
@@ -558,7 +558,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     s->in = in;
     ff_filter_execute(ctx, psy_channels, out, NULL,
-                      FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     out->pts = in->pts;
     out->nb_samples = in->nb_samples;
diff --git a/libavfilter/af_apulsator.c b/libavfilter/af_apulsator.c
index c2a8de0e0b..c3ca752035 100644
--- a/libavfilter/af_apulsator.c
+++ b/libavfilter/af_apulsator.c
@@ -192,7 +192,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_DBL  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c
index 6e1be5b7eb..e4eccc847b 100644
--- a/libavfilter/af_aresample.c
+++ b/libavfilter/af_aresample.c
@@ -65,7 +65,8 @@ static int query_formats(AVFilterContext *ctx)
 {
     AResampleContext *aresample = ctx->priv;
     enum AVSampleFormat out_format;
-    int64_t out_rate, out_layout;
+    AVChannelLayout out_layout = { 0 };
+    int64_t out_rate;
 
     AVFilterLink *inlink  = ctx->inputs[0];
     AVFilterLink *outlink = ctx->outputs[0];
@@ -79,7 +80,6 @@ static int query_formats(AVFilterContext *ctx)
         av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0);
     av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format);
     av_opt_get_int(aresample->swr, "osr", 0, &out_rate);
-    av_opt_get_int(aresample->swr, "ocl", 0, &out_layout);
 
     in_formats      = ff_all_formats(AVMEDIA_TYPE_AUDIO);
     if ((ret = ff_formats_ref(in_formats, &inlink->outcfg.formats)) < 0)
@@ -111,11 +111,13 @@ static int query_formats(AVFilterContext *ctx)
     if ((ret = ff_formats_ref(out_formats, &outlink->incfg.formats)) < 0)
         return ret;
 
-    if(out_layout) {
-        int64_t layout_list[] = { out_layout, -1 };
+    av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout);
+    if (av_channel_layout_check(&out_layout)) {
+        const AVChannelLayout layout_list[] = { out_layout, { 0 } };
         out_layouts = ff_make_format64_list(layout_list);
     } else
         out_layouts = ff_all_channel_counts();
+    av_channel_layout_uninit(&out_layout);
 
     return ff_channel_layouts_ref(out_layouts, &outlink->incfg.channel_layouts);
 }
@@ -127,42 +129,41 @@ static int config_output(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     AVFilterLink *inlink = ctx->inputs[0];
     AResampleContext *aresample = ctx->priv;
-    int64_t out_rate, out_layout;
+    AVChannelLayout out_layout = { 0 };
+    int64_t out_rate;
     enum AVSampleFormat out_format;
     char inchl_buf[128], outchl_buf[128];
 
-    aresample->swr = swr_alloc_set_opts(aresample->swr,
-                                        outlink->channel_layout, outlink->format, outlink->sample_rate,
-                                        inlink->channel_layout, inlink->format, inlink->sample_rate,
-                                        0, ctx);
-    if (!aresample->swr)
-        return AVERROR(ENOMEM);
-    if (!inlink->channel_layout)
-        av_opt_set_int(aresample->swr, "ich", inlink->channels, 0);
-    if (!outlink->channel_layout)
-        av_opt_set_int(aresample->swr, "och", outlink->channels, 0);
+    ret = swr_alloc_set_opts2(&aresample->swr,
+                              &outlink->ch_layout, outlink->format, outlink->sample_rate,
+                              &inlink->ch_layout, inlink->format, inlink->sample_rate,
+                                         0, ctx);
+    if (ret < 0)
+        return ret;
 
     ret = swr_init(aresample->swr);
     if (ret < 0)
         return ret;
 
     av_opt_get_int(aresample->swr, "osr", 0, &out_rate);
-    av_opt_get_int(aresample->swr, "ocl", 0, &out_layout);
+    av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout);
     av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format);
     outlink->time_base = (AVRational) {1, out_rate};
 
     av_assert0(outlink->sample_rate == out_rate);
-    av_assert0(outlink->channel_layout == out_layout || !outlink->channel_layout);
+    av_assert0(!av_channel_layout_compare(&outlink->ch_layout, &out_layout));
     av_assert0(outlink->format == out_format);
 
+    av_channel_layout_uninit(&out_layout);
+
     aresample->ratio = (double)outlink->sample_rate / inlink->sample_rate;
 
-    av_get_channel_layout_string(inchl_buf,  sizeof(inchl_buf),  inlink ->channels, inlink ->channel_layout);
-    av_get_channel_layout_string(outchl_buf, sizeof(outchl_buf), outlink->channels, outlink->channel_layout);
+    av_channel_layout_describe(&inlink ->ch_layout, inchl_buf,  sizeof(inchl_buf));
+    av_channel_layout_describe(&outlink->ch_layout, outchl_buf, sizeof(outchl_buf));
 
     av_log(ctx, AV_LOG_VERBOSE, "ch:%d chl:%s fmt:%s r:%dHz -> ch:%d chl:%s fmt:%s r:%dHz\n",
-           inlink ->channels, inchl_buf,  av_get_sample_fmt_name(inlink->format),  inlink->sample_rate,
-           outlink->channels, outchl_buf, av_get_sample_fmt_name(outlink->format), outlink->sample_rate);
+           inlink ->ch_layout.nb_channels, inchl_buf,  av_get_sample_fmt_name(inlink->format),  inlink->sample_rate,
+           outlink->ch_layout.nb_channels, outchl_buf, av_get_sample_fmt_name(outlink->format), outlink->sample_rate);
     return 0;
 }
 
@@ -189,8 +190,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
 
     av_frame_copy_props(outsamplesref, insamplesref);
     outsamplesref->format                = outlink->format;
-    outsamplesref->channels              = outlink->channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    outsamplesref->channels              = outlink->ch_layout.nb_channels;
     outsamplesref->channel_layout        = outlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    ret = av_channel_layout_copy(&outsamplesref->ch_layout, &outlink->ch_layout);
+    if (ret < 0)
+        return ret;
     outsamplesref->sample_rate           = outlink->sample_rate;
 
     if(insamplesref->pts != AV_NOPTS_VALUE) {
diff --git a/libavfilter/af_arnndn.c b/libavfilter/af_arnndn.c
index 3115c4ae0c..fe562e81a1 100644
--- a/libavfilter/af_arnndn.c
+++ b/libavfilter/af_arnndn.c
@@ -353,7 +353,7 @@ static int config_input(AVFilterLink *inlink)
     AudioRNNContext *s = ctx->priv;
     int ret = 0;
 
-    s->channels = inlink->channels;
+    s->channels = inlink->ch_layout.nb_channels;
 
     if (!s->st)
         s->st = av_calloc(s->channels, sizeof(DenoiseState));
@@ -1413,8 +1413,8 @@ static int rnnoise_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_j
     ThreadData *td = arg;
     AVFrame *in = td->in;
     AVFrame *out = td->out;
-    const int start = (out->channels * jobnr) / nb_jobs;
-    const int end = (out->channels * (jobnr+1)) / nb_jobs;
+    const int start = (out->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (out->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
 
     for (int ch = start; ch < end; ch++) {
         rnnoise_channel(s, &s->st[ch],
@@ -1442,7 +1442,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     td.in = in; td.out = out;
     ff_filter_execute(ctx, rnnoise_channels, &td, NULL,
-                      FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     av_frame_free(&in);
     return ff_filter_frame(outlink, out);
diff --git a/libavfilter/af_asdr.c b/libavfilter/af_asdr.c
index addfe5f158..a40246f280 100644
--- a/libavfilter/af_asdr.c
+++ b/libavfilter/af_asdr.c
@@ -41,7 +41,7 @@ static void sdr(AVFilterContext *ctx, const AVFrame *u, const AVFrame *v)
 {
     AudioSDRContext *s = ctx->priv;
 
-    for (int ch = 0; ch < u->channels; ch++) {
+    for (int ch = 0; ch < u->ch_layout.nb_channels; ch++) {
         const double *const us = (double *)u->extended_data[ch];
         const double *const vs = (double *)v->extended_data[ch];
         double sum_uv = s->sum_uv[ch];
@@ -117,10 +117,10 @@ static int config_output(AVFilterLink *outlink)
 
     s->pts = AV_NOPTS_VALUE;
 
-    s->channels = inlink->channels;
+    s->channels = inlink->ch_layout.nb_channels;
 
-    s->sum_u  = av_calloc(outlink->channels, sizeof(*s->sum_u));
-    s->sum_uv = av_calloc(outlink->channels, sizeof(*s->sum_uv));
+    s->sum_u  = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->sum_u));
+    s->sum_uv = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->sum_uv));
     if (!s->sum_u || !s->sum_uv)
         return AVERROR(ENOMEM);
 
diff --git a/libavfilter/af_asetnsamples.c b/libavfilter/af_asetnsamples.c
index 71788f2a76..6fb646ace4 100644
--- a/libavfilter/af_asetnsamples.c
+++ b/libavfilter/af_asetnsamples.c
@@ -87,9 +87,9 @@ static int activate(AVFilterContext *ctx)
         }
 
         av_samples_copy(pad_frame->extended_data, frame->extended_data,
-                        0, 0, frame->nb_samples, frame->channels, frame->format);
+                        0, 0, frame->nb_samples, frame->ch_layout.nb_channels, frame->format);
         av_samples_set_silence(pad_frame->extended_data, frame->nb_samples,
-                               s->nb_out_samples - frame->nb_samples, frame->channels,
+                               s->nb_out_samples - frame->nb_samples, frame->ch_layout.nb_channels,
                                frame->format);
         av_frame_free(&frame);
         return ff_filter_frame(outlink, pad_frame);
diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c
index c76756db63..36ba38b478 100644
--- a/libavfilter/af_ashowinfo.c
+++ b/libavfilter/af_ashowinfo.c
@@ -178,9 +178,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
 {
     AVFilterContext *ctx = inlink->dst;
     AShowInfoContext *s  = ctx->priv;
+#if FF_API_OLD_CHANNEL_LAYOUT
+    AVChannelLayout layout = { 0 };
+#endif
     char chlayout_str[128];
     uint32_t checksum = 0;
-    int channels    = inlink->channels;
+    int channels    = inlink->ch_layout.nb_channels;
     int planar      = av_sample_fmt_is_planar(buf->format);
     int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
     int data_size   = buf->nb_samples * block_align;
@@ -200,8 +203,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
                        s->plane_checksums[0];
     }
 
-    av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), buf->channels,
-                                 buf->channel_layout);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (av_channel_layout_from_mask(&layout, buf->channel_layout)) {
+        av_channel_layout_describe(&layout, chlayout_str, sizeof(chlayout_str));
+FF_ENABLE_DEPRECATION_WARNINGS
+    } else if (buf->ch_layout.nb_channels)
+#endif
+    av_channel_layout_describe(&buf->ch_layout, chlayout_str, sizeof(chlayout_str));
 
     av_log(ctx, AV_LOG_INFO,
            "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
@@ -210,7 +219,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
            inlink->frame_count_out,
            av_ts2str(buf->pts), av_ts2timestr(buf->pts, &inlink->time_base),
            buf->pkt_pos,
-           av_get_sample_fmt_name(buf->format), buf->channels, chlayout_str,
+           av_get_sample_fmt_name(buf->format), buf->ch_layout.nb_channels, chlayout_str,
            buf->sample_rate, buf->nb_samples,
            checksum);
 
diff --git a/libavfilter/af_asoftclip.c b/libavfilter/af_asoftclip.c
index 6ffde4431a..6212e1d6fe 100644
--- a/libavfilter/af_asoftclip.c
+++ b/libavfilter/af_asoftclip.c
@@ -440,7 +440,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     }
 
     nb_samples = in->nb_samples;
-    channels = in->channels;
+    channels = in->ch_layout.nb_channels;
 
     td.in = in;
     td.out = out;
diff --git a/libavfilter/af_aspectralstats.c b/libavfilter/af_aspectralstats.c
index da418d22bf..642c1c88ca 100644
--- a/libavfilter/af_aspectralstats.c
+++ b/libavfilter/af_aspectralstats.c
@@ -84,7 +84,7 @@ static int config_output(AVFilterLink *outlink)
     float overlap, scale;
     int ret;
 
-    s->nb_channels = outlink->channels;
+    s->nb_channels = outlink->ch_layout.nb_channels;
     s->fifo = av_audio_fifo_alloc(outlink->format, s->nb_channels, s->win_size);
     if (!s->fifo)
         return AVERROR(ENOMEM);
@@ -474,7 +474,7 @@ static int filter_frame(AVFilterLink *inlink)
 
     metadata = &out->metadata;
     ff_filter_execute(ctx, filter_channel, in, NULL,
-                      FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     set_metadata(s, metadata);
 
diff --git a/libavfilter/af_asr.c b/libavfilter/af_asr.c
index 42250e79e2..b402f5ff26 100644
--- a/libavfilter/af_asr.c
+++ b/libavfilter/af_asr.c
@@ -131,7 +131,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_S16                 )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats                           )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_MONO                 )) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO )) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout                            )) < 0 ||
         (ret = ff_set_common_samplerates_from_list(ctx, sample_rates     )) < 0)
         return ret;
diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c
index 6c79257cb4..d59640a3fd 100644
--- a/libavfilter/af_astats.c
+++ b/libavfilter/af_astats.c
@@ -194,12 +194,12 @@ static int config_output(AVFilterLink *outlink)
 {
     AudioStatsContext *s = outlink->src->priv;
 
-    s->chstats = av_calloc(sizeof(*s->chstats), outlink->channels);
+    s->chstats = av_calloc(sizeof(*s->chstats), outlink->ch_layout.nb_channels);
     if (!s->chstats)
         return AVERROR(ENOMEM);
 
     s->tc_samples = FFMAX(s->time_constant * outlink->sample_rate + .5, 1);
-    s->nb_channels = outlink->channels;
+    s->nb_channels = outlink->ch_layout.nb_channels;
 
     for (int i = 0; i < s->nb_channels; i++) {
         ChannelStats *p = &s->chstats[i];
@@ -584,8 +584,8 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_job
     const uint8_t * const * const data = (const uint8_t * const *)buf->extended_data;
     const int channels = s->nb_channels;
     const int samples = buf->nb_samples;
-    const int start = (buf->channels * jobnr) / nb_jobs;
-    const int end = (buf->channels * (jobnr+1)) / nb_jobs;
+    const int start = (buf->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (buf->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
 
     switch (inlink->format) {
     case AV_SAMPLE_FMT_DBLP:
@@ -638,7 +638,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
     }
 
     ff_filter_execute(ctx, filter_channel, buf, NULL,
-                      FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     if (s->metadata)
         set_metadata(s, metadata);
diff --git a/libavfilter/af_asubboost.c b/libavfilter/af_asubboost.c
index da3e68e841..11b0825f97 100644
--- a/libavfilter/af_asubboost.c
+++ b/libavfilter/af_asubboost.c
@@ -76,7 +76,7 @@ static int config_input(AVFilterLink *inlink)
 
     s->buffer = ff_get_audio_buffer(inlink, inlink->sample_rate / 10);
     s->w = ff_get_audio_buffer(inlink, 2);
-    s->write_pos = av_calloc(inlink->channels, sizeof(*s->write_pos));
+    s->write_pos = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->write_pos));
     if (!s->buffer || !s->w || !s->write_pos)
         return AVERROR(ENOMEM);
 
@@ -102,8 +102,8 @@ static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo
     const double b2 = s->b2;
     const double a1 = -s->a1;
     const double a2 = -s->a2;
-    const int start = (in->channels * jobnr) / nb_jobs;
-    const int end = (in->channels * (jobnr+1)) / nb_jobs;
+    const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
     const int buffer_samples = s->buffer_samples;
 
     for (int ch = start; ch < end; ch++) {
@@ -153,7 +153,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     td.in = in; td.out = out;
     ff_filter_execute(ctx, filter_channels, &td, NULL,
-                      FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     if (out != in)
         av_frame_free(&in);
diff --git a/libavfilter/af_asupercut.c b/libavfilter/af_asupercut.c
index a4c2d15154..5c06d559ed 100644
--- a/libavfilter/af_asupercut.c
+++ b/libavfilter/af_asupercut.c
@@ -210,8 +210,8 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, \
     ThreadData *td = arg;                                           \
     AVFrame *out = td->out;                                         \
     AVFrame *in = td->in;                                           \
-    const int start = (in->channels * jobnr) / nb_jobs;             \
-    const int end = (in->channels * (jobnr+1)) / nb_jobs;           \
+    const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs; \
+    const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs; \
     const double level = s->level;                                  \
                                                                     \
     for (int ch = start; ch < end; ch++) {                          \
@@ -286,7 +286,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     td.in = in; td.out = out;
     ff_filter_execute(ctx, s->filter_channels, &td, NULL,
-                      FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     if (out != in)
         av_frame_free(&in);
diff --git a/libavfilter/af_atempo.c b/libavfilter/af_atempo.c
index e9a6da7970..e06277b804 100644
--- a/libavfilter/af_atempo.c
+++ b/libavfilter/af_atempo.c
@@ -1016,7 +1016,7 @@ static int config_props(AVFilterLink *inlink)
     enum AVSampleFormat format = inlink->format;
     int sample_rate = (int)inlink->sample_rate;
 
-    return yae_reset(atempo, format, sample_rate, inlink->channels);
+    return yae_reset(atempo, format, sample_rate, inlink->ch_layout.nb_channels);
 }
 
 static int push_samples(ATempoContext *atempo,
diff --git a/libavfilter/af_atilt.c b/libavfilter/af_atilt.c
index a6f7782af5..9ece531ea4 100644
--- a/libavfilter/af_atilt.c
+++ b/libavfilter/af_atilt.c
@@ -125,8 +125,8 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, \
     ThreadData *td = arg;                                           \
     AVFrame *out = td->out;                                         \
     AVFrame *in = td->in;                                           \
-    const int start = (in->channels * jobnr) / nb_jobs;             \
-    const int end = (in->channels * (jobnr+1)) / nb_jobs;           \
+    const int start = (in->ch_layout.nb_channels * jobnr) / nb_jobs; \
+    const int end = (in->ch_layout.nb_channels * (jobnr+1)) / nb_jobs; \
     const type level = s->level;                                    \
                                                                     \
     for (int ch = start; ch < end; ch++) {                          \
@@ -196,7 +196,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     }
 
     td.in = in; td.out = out;
-    ff_filter_execute(ctx, s->filter_channels, &td, NULL, FFMIN(inlink->channels,
+    ff_filter_execute(ctx, s->filter_channels, &td, NULL, FFMIN(inlink->ch_layout.nb_channels,
                                                                ff_filter_get_nb_threads(ctx)));
 
     if (out != in)
diff --git a/libavfilter/af_axcorrelate.c b/libavfilter/af_axcorrelate.c
index d0a91cd836..9be3f1c921 100644
--- a/libavfilter/af_axcorrelate.c
+++ b/libavfilter/af_axcorrelate.c
@@ -113,7 +113,7 @@ static int xcorrelate_slow_##suffix(AVFilterContext *ctx, \
     const int size = FFMIN(available, s->size);           \
     int used;                                             \
                                                           \
-    for (int ch = 0; ch < out->channels; ch++) {          \
+    for (int ch = 0; ch < out->ch_layout.nb_channels; ch++) {         \
         const type *x = (const type *)s->cache[0]->extended_data[ch]; \
         const type *y = (const type *)s->cache[1]->extended_data[ch]; \
         type *sumx = (type *)s->mean_sum[0]->extended_data[ch];       \
@@ -155,7 +155,7 @@ static int xcorrelate_fast_##suffix(AVFilterContext *ctx, AVFrame *out,        \
     const int size = FFMIN(available, s->size);                                \
     int used;                                                                  \
                                                                                \
-    for (int ch = 0; ch < out->channels; ch++) {                               \
+    for (int ch = 0; ch < out->ch_layout.nb_channels; ch++) {                  \
         const type *x = (const type *)s->cache[0]->extended_data[ch];          \
         const type *y = (const type *)s->cache[1]->extended_data[ch];          \
         type *num_sum = (type *)s->num_sum->extended_data[ch];                 \
@@ -299,8 +299,8 @@ static int config_output(AVFilterLink *outlink)
 
     s->pts = AV_NOPTS_VALUE;
 
-    s->fifo[0] = av_audio_fifo_alloc(outlink->format, outlink->channels, s->size);
-    s->fifo[1] = av_audio_fifo_alloc(outlink->format, outlink->channels, s->size);
+    s->fifo[0] = av_audio_fifo_alloc(outlink->format, outlink->ch_layout.nb_channels, s->size);
+    s->fifo[1] = av_audio_fifo_alloc(outlink->format, outlink->ch_layout.nb_channels, s->size);
     if (!s->fifo[0] || !s->fifo[1])
         return AVERROR(ENOMEM);
 
diff --git a/libavfilter/af_biquads.c b/libavfilter/af_biquads.c
index ee42b2a034..2a0747a037 100644
--- a/libavfilter/af_biquads.c
+++ b/libavfilter/af_biquads.c
@@ -125,7 +125,7 @@ typedef struct BiquadsContext {
     double frequency;
     double width;
     double mix;
-    uint64_t channels;
+    AVChannelLayout ch_layout;
     int normalize;
     int order;
 
@@ -716,11 +716,11 @@ static int config_filter(AVFilterLink *outlink, int reset)
         s->b2 *= factor;
     }
 
-    s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
+    s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->ch_layout.nb_channels);
     if (!s->cache)
         return AVERROR(ENOMEM);
     if (reset)
-        memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
+        memset(s->cache, 0, sizeof(ChanCache) * inlink->ch_layout.nb_channels);
 
     switch (s->transform_type) {
     case DI:
@@ -838,12 +838,14 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_job
     AVFrame *buf = td->in;
     AVFrame *out_buf = td->out;
     BiquadsContext *s = ctx->priv;
-    const int start = (buf->channels * jobnr) / nb_jobs;
-    const int end = (buf->channels * (jobnr+1)) / nb_jobs;
+    const int start = (buf->ch_layout.nb_channels * jobnr) / nb_jobs;
+    const int end = (buf->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
     int ch;
 
     for (ch = start; ch < end; ch++) {
-        if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
+        if (!(av_channel_layout_channel_from_index(&inlink->ch_layout, ch) >= 0 &&
+              av_channel_layout_channel_from_index(&s->ch_layout, ch) >= 0)) {
+
             if (buf != out_buf)
                 memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
                        buf->nb_samples * s->block_align);
@@ -884,9 +886,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
     td.in = buf;
     td.out = out_buf;
     ff_filter_execute(ctx, filter_channel, &td, NULL,
-                      FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
-    for (ch = 0; ch < outlink->channels; ch++) {
+    for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {
         if (s->cache[ch].clippings > 0)
             av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
                    ch, s->cache[ch].clippings);
@@ -982,8 +984,8 @@ static const AVOption equalizer_options[] = {
     {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1024,8 +1026,8 @@ static const AVOption bass_lowshelf_options[] = {
     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1073,8 +1075,8 @@ static const AVOption treble_highshelf_options[] = {
     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1121,8 +1123,8 @@ static const AVOption bandpass_options[] = {
     {"csg",   "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1159,8 +1161,8 @@ static const AVOption bandreject_options[] = {
     {"w",     "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1199,8 +1201,8 @@ static const AVOption lowpass_options[] = {
     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1239,8 +1241,8 @@ static const AVOption highpass_options[] = {
     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
@@ -1277,8 +1279,8 @@ static const AVOption allpass_options[] = {
     {"w",     "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
@@ -1312,8 +1314,8 @@ static const AVOption biquad_options[] = {
     {"b2", NULL, OFFSET(ob2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
     {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
     {"m",   "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
-    {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
-    {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
+    {"channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
+    {"c",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS},
     {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"n",         "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
diff --git a/libavfilter/af_bs2b.c b/libavfilter/af_bs2b.c
index 90ae846d95..20e6d8141a 100644
--- a/libavfilter/af_bs2b.c
+++ b/libavfilter/af_bs2b.c
@@ -104,7 +104,7 @@ static int query_formats(AVFilterContext *ctx)
     };
     int ret;
 
-    if (ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO) != 0)
+    if (ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO) != 0)
         return AVERROR(ENOMEM);
     ret = ff_set_common_channel_layouts(ctx, layouts);
     if (ret < 0)
diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c
index d3ab77920f..9e6cafbc24 100644
--- a/libavfilter/af_channelmap.c
+++ b/libavfilter/af_channelmap.c
@@ -38,8 +38,8 @@
 #include "internal.h"
 
 struct ChannelMap {
-    uint64_t in_channel;
-    uint64_t out_channel;
+    int in_channel;
+    int out_channel;
     int in_channel_idx;
     int out_channel_idx;
 };
@@ -59,7 +59,7 @@ typedef struct ChannelMapContext {
     const AVClass *class;
     char *mapping_str;
     char *channel_layout_str;
-    uint64_t output_layout;
+    AVChannelLayout output_layout;
     struct ChannelMap map[MAX_CH];
     int nch;
     enum MappingMode mode;
@@ -105,13 +105,13 @@ static int get_channel_idx(char **map, int *ch, char delim, int max_ch)
     return 0;
 }
 
-static int get_channel(char **map, uint64_t *ch, char delim)
+static int get_channel(char **map, int *ch, char delim)
 {
     char *next = split(*map, delim);
     if (!next && delim == '-')
         return AVERROR(EINVAL);
-    *ch = av_get_channel_layout(*map);
-    if (av_get_channel_layout_nb_channels(*ch) != 1)
+    *ch = av_channel_from_string(*map);
+    if (*ch < 0)
         return AVERROR(EINVAL);
     *map = next;
     return 0;
@@ -167,7 +167,7 @@ static av_cold int channelmap_init(AVFilterContext *ctx)
 
     for (i = 0; i < map_entries; i++) {
         int in_ch_idx = -1, out_ch_idx = -1;
-        uint64_t in_ch = 0, out_ch = 0;
+        int in_ch = 0, out_ch = 0;
         static const char err[] = "Failed to parse channel map\n";
         switch (mode) {
         case MAP_ONE_INT:
@@ -198,13 +198,13 @@ static av_cold int channelmap_init(AVFilterContext *ctx)
         case MAP_PAIR_INT_STR:
             if (get_channel_idx(&mapping, &in_ch_idx, '-', MAX_CH) < 0 ||
                 get_channel(&mapping, &out_ch, separator) < 0 ||
-                out_ch & out_ch_mask) {
+                (1ULL << out_ch) & out_ch_mask) {
                 av_log(ctx, AV_LOG_ERROR, err);
                 return AVERROR(EINVAL);
             }
             s->map[i].in_channel_idx  = in_ch_idx;
             s->map[i].out_channel     = out_ch;
-            out_ch_mask |= out_ch;
+            out_ch_mask |= 1ULL << out_ch;
             break;
         case MAP_PAIR_STR_INT:
             if (get_channel(&mapping, &in_ch, '-') < 0 ||
@@ -218,42 +218,57 @@ static av_cold int channelmap_init(AVFilterContext *ctx)
         case MAP_PAIR_STR_STR:
             if (get_channel(&mapping, &in_ch, '-') < 0 ||
                 get_channel(&mapping, &out_ch, separator) < 0 ||
-                out_ch & out_ch_mask) {
+                (1ULL << out_ch) & out_ch_mask) {
                 av_log(ctx, AV_LOG_ERROR, err);
                 return AVERROR(EINVAL);
             }
             s->map[i].in_channel = in_ch;
             s->map[i].out_channel = out_ch;
-            out_ch_mask |= out_ch;
+            out_ch_mask |= 1ULL << out_ch;
             break;
         }
     }
     s->mode          = mode;
     s->nch           = map_entries;
-    s->output_layout = out_ch_mask ? out_ch_mask :
-                       av_get_default_channel_layout(map_entries);
+    if (out_ch_mask)
+        av_channel_layout_from_mask(&s->output_layout, out_ch_mask);
+    else
+        av_channel_layout_default(&s->output_layout, map_entries);
 
     if (s->channel_layout_str) {
-        uint64_t fmt;
-        if ((fmt = av_get_channel_layout(s->channel_layout_str)) == 0) {
-            av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: '%s'.\n",
+        AVChannelLayout fmt = { 0 };
+        int ret;
+        if ((ret = av_channel_layout_from_string(&fmt, s->channel_layout_str)) < 0) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+            uint64_t mask;
+FF_DISABLE_DEPRECATION_WARNINGS
+            if ((mask = av_get_channel_layout(s->channel_layout_str)) == 0) {
+#endif
+                av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: '%s'.\n",
+                       s->channel_layout_str);
+                return AVERROR(EINVAL);
+#if FF_API_OLD_CHANNEL_LAYOUT
+            }
+FF_ENABLE_DEPRECATION_WARNINGS
+            av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
                    s->channel_layout_str);
-            return AVERROR(EINVAL);
+            av_channel_layout_from_mask(&fmt, mask);
+#endif
         }
         if (mode == MAP_NONE) {
             int i;
-            s->nch = av_get_channel_layout_nb_channels(fmt);
+            s->nch = fmt.nb_channels;
             for (i = 0; i < s->nch; i++) {
                 s->map[i].in_channel_idx  = i;
                 s->map[i].out_channel_idx = i;
             }
-        } else if (out_ch_mask && out_ch_mask != fmt) {
-            av_get_channel_layout_string(buf, sizeof(buf), 0, out_ch_mask);
+        } else if (out_ch_mask && av_channel_layout_compare(&s->output_layout, &fmt)) {
+            av_channel_layout_describe(&s->output_layout, buf, sizeof(buf));
             av_log(ctx, AV_LOG_ERROR,
                    "Output channel layout '%s' does not match the list of channel mapped: '%s'.\n",
                    s->channel_layout_str, buf);
             return AVERROR(EINVAL);
-        } else if (s->nch != av_get_channel_layout_nb_channels(fmt)) {
+        } else if (s->nch != fmt.nb_channels) {
             av_log(ctx, AV_LOG_ERROR,
                    "Output channel layout %s does not match the number of channels mapped %d.\n",
                    s->channel_layout_str, s->nch);
@@ -261,7 +276,7 @@ static av_cold int channelmap_init(AVFilterContext *ctx)
         }
         s->output_layout = fmt;
     }
-    if (!s->output_layout) {
+    if (!s->output_layout.nb_channels) {
         av_log(ctx, AV_LOG_ERROR, "Output channel layout is not set and "
                "cannot be guessed from the maps.\n");
         return AVERROR(EINVAL);
@@ -269,8 +284,8 @@ static av_cold int channelmap_init(AVFilterContext *ctx)
 
     if (mode == MAP_PAIR_INT_STR || mode == MAP_PAIR_STR_STR) {
         for (i = 0; i < s->nch; i++) {
-            s->map[i].out_channel_idx = av_get_channel_layout_channel_index(
-                s->output_layout, s->map[i].out_channel);
+            s->map[i].out_channel_idx = av_channel_layout_index_from_channel(
+                &s->output_layout, s->map[i].out_channel);
         }
     }
 
@@ -285,7 +300,7 @@ static int channelmap_query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_set_common_formats    (ctx,  ff_planar_sample_fmts()))  < 0 ||
         (ret = ff_set_common_all_samplerates(ctx                              )) < 0 ||
-        (ret = ff_add_channel_layout(&channel_layouts, s->output_layout)) < 0 ||
+        (ret = ff_add_channel_layout(&channel_layouts, &s->output_layout)) < 0 ||
         (ret = ff_channel_layouts_ref(channel_layouts,
                                       &ctx->outputs[0]->incfg.channel_layouts)) < 0)
         return ret;
@@ -299,9 +314,9 @@ static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf)
     AVFilterContext  *ctx = inlink->dst;
     AVFilterLink *outlink = ctx->outputs[0];
     const ChannelMapContext *s = ctx->priv;
-    const int nch_in = inlink->channels;
+    const int nch_in = inlink->ch_layout.nb_channels;
     const int nch_out = s->nch;
-    int ch;
+    int ch, ret;
     uint8_t *source_planes[MAX_CH];
 
     memcpy(source_planes, buf->extended_data,
@@ -336,8 +351,14 @@ static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf)
         memcpy(buf->data, buf->extended_data,
            FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0]));
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    buf->ch_layout.nb_channels = outlink->ch_layout.nb_channels;
     buf->channel_layout = outlink->channel_layout;
-    buf->channels       = outlink->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((ret = av_channel_layout_copy(&buf->ch_layout, &outlink->ch_layout)) < 0)
+        return ret;
 
     return ff_filter_frame(outlink, buf);
 }
@@ -346,24 +367,23 @@ static int channelmap_config_input(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     ChannelMapContext *s = ctx->priv;
-    int nb_channels = inlink->channels;
+    int nb_channels = inlink->ch_layout.nb_channels;
     int i, err = 0;
-    const char *channel_name;
+    char channel_name[64];
     char layout_name[256];
 
     for (i = 0; i < s->nch; i++) {
         struct ChannelMap *m = &s->map[i];
 
         if (s->mode == MAP_PAIR_STR_INT || s->mode == MAP_PAIR_STR_STR) {
-            m->in_channel_idx = av_get_channel_layout_channel_index(
-                inlink->channel_layout, m->in_channel);
+            m->in_channel_idx = av_channel_layout_index_from_channel(
+                &inlink->ch_layout, m->in_channel);
         }
 
         if (m->in_channel_idx < 0 || m->in_channel_idx >= nb_channels) {
-            av_get_channel_layout_string(layout_name, sizeof(layout_name),
-                                         nb_channels, inlink->channel_layout);
+            av_channel_layout_describe(&inlink->ch_layout, layout_name, sizeof(layout_name));
             if (m->in_channel) {
-                channel_name = av_get_channel_name(m->in_channel);
+                av_channel_name(channel_name, sizeof(channel_name), m->in_channel);
                 av_log(ctx, AV_LOG_ERROR,
                        "input channel '%s' not available from input layout '%s'\n",
                        channel_name, layout_name);
diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c
index 1a2519dd32..31453823c5 100644
--- a/libavfilter/af_channelsplit.c
+++ b/libavfilter/af_channelsplit.c
@@ -36,7 +36,7 @@
 typedef struct ChannelSplitContext {
     const AVClass *class;
 
-    uint64_t channel_layout;
+    AVChannelLayout channel_layout;
     char    *channel_layout_str;
     char    *channels_str;
 
@@ -57,11 +57,11 @@ AVFILTER_DEFINE_CLASS(channelsplit);
 static av_cold int init(AVFilterContext *ctx)
 {
     ChannelSplitContext *s = ctx->priv;
-    uint64_t channel_layout;
+    AVChannelLayout channel_layout = { 0 };
     int nb_channels;
     int all = 0, ret = 0, i;
 
-    if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) {
+    if ((ret = av_channel_layout_from_string(&s->channel_layout, s->channel_layout_str)) < 0) {
         av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
                s->channel_layout_str);
         ret = AVERROR(EINVAL);
@@ -70,27 +70,32 @@ static av_cold int init(AVFilterContext *ctx)
 
 
     if (!strcmp(s->channels_str, "all")) {
-        nb_channels = av_get_channel_layout_nb_channels(s->channel_layout);
+        nb_channels = s->channel_layout.nb_channels;
         channel_layout = s->channel_layout;
         all = 1;
     } else {
-        if ((ret = av_get_extended_channel_layout(s->channels_str, &channel_layout, &nb_channels)) < 0)
+        if ((ret = av_channel_layout_from_string(&channel_layout, s->channels_str)) < 0)
             return ret;
     }
 
     for (i = 0; i < nb_channels; i++) {
-        uint64_t channel = av_channel_layout_extract_channel(channel_layout, i);
-        AVFilterPad pad  = { 0 };
+        int channel = av_channel_layout_channel_from_index(&channel_layout, i);
+        char buf[64];
+        AVFilterPad pad = { .flags = AVFILTERPAD_FLAG_FREE_NAME };
 
+        av_channel_name(buf, sizeof(buf), channel);
         pad.type = AVMEDIA_TYPE_AUDIO;
-        pad.name = av_get_channel_name(channel);
+        pad.name = av_strdup(buf);
+        if (!pad.name)
+            return AVERROR(ENOMEM);
 
         if (all) {
             s->map[i] = i;
         } else {
-            if ((ret = av_get_channel_layout_channel_index(s->channel_layout, channel)) < 0) {
+            if ((ret = av_channel_layout_index_from_channel(&s->channel_layout, channel)) < 0) {
                 av_log(ctx, AV_LOG_ERROR, "Channel name '%s' not present in channel layout '%s'.\n",
-                       av_get_channel_name(channel), s->channel_layout_str);
+                       pad.name, s->channel_layout_str);
+                av_freep(&pad.name);
                 return ret;
             }
 
@@ -115,15 +120,18 @@ static int query_formats(AVFilterContext *ctx)
         (ret = ff_set_common_all_samplerates(ctx)) < 0)
         return ret;
 
-    if ((ret = ff_add_channel_layout(&in_layouts, s->channel_layout)) < 0 ||
+    if ((ret = ff_add_channel_layout(&in_layouts, &s->channel_layout)) < 0 ||
         (ret = ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->outcfg.channel_layouts)) < 0)
         return ret;
 
     for (i = 0; i < ctx->nb_outputs; i++) {
+        AVChannelLayout channel_layout = { 0 };
         AVFilterChannelLayouts *out_layouts = NULL;
-        uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, s->map[i]);
+        int channel = av_channel_layout_channel_from_index(&s->channel_layout, s->map[i]);
 
-        if ((ret = ff_add_channel_layout(&out_layouts, channel)) < 0 ||
+        if ((channel < 0) ||
+            (ret = av_channel_layout_from_mask(&channel_layout, 1ULL << channel)) < 0 ||
+            (ret = ff_add_channel_layout(&out_layouts, &channel_layout)) < 0 ||
             (ret = ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->incfg.channel_layouts)) < 0)
             return ret;
     }
@@ -139,6 +147,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
 
     for (i = 0; i < ctx->nb_outputs; i++) {
         AVFrame *buf_out = av_frame_clone(buf);
+        int channel = av_channel_layout_channel_from_index(&buf->ch_layout, s->map[i]);
 
         if (!buf_out) {
             ret = AVERROR(ENOMEM);
@@ -146,9 +155,16 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
         }
 
         buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[s->map[i]];
+        ret = av_channel_layout_from_mask(&buf_out->ch_layout, 1ULL << channel);
+        if (ret < 0)
+            break;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
         buf_out->channel_layout =
             av_channel_layout_extract_channel(buf->channel_layout, s->map[i]);
         buf_out->channels = 1;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
         ret = ff_filter_frame(ctx->outputs[i], buf_out);
         if (ret < 0)
diff --git a/libavfilter/af_chorus.c b/libavfilter/af_chorus.c
index 68de692c4b..19826cfb15 100644
--- a/libavfilter/af_chorus.c
+++ b/libavfilter/af_chorus.c
@@ -161,7 +161,7 @@ static int config_output(AVFilterLink *outlink)
     float sum_in_volume = 1.0;
     int n;
 
-    s->channels = outlink->channels;
+    s->channels = outlink->ch_layout.nb_channels;
 
     for (n = 0; n < s->num_chorus; n++) {
         int samples = (int) ((s->delays[n] + s->depths[n]) * outlink->sample_rate / 1000.0);
@@ -184,15 +184,15 @@ static int config_output(AVFilterLink *outlink)
     if (s->in_gain * (sum_in_volume) > 1.0 / s->out_gain)
         av_log(ctx, AV_LOG_WARNING, "output gain can cause saturation or clipping of output\n");
 
-    s->counter = av_calloc(outlink->channels, sizeof(*s->counter));
+    s->counter = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->counter));
     if (!s->counter)
         return AVERROR(ENOMEM);
 
-    s->phase = av_calloc(outlink->channels, sizeof(*s->phase));
+    s->phase = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->phase));
     if (!s->phase)
         return AVERROR(ENOMEM);
 
-    for (n = 0; n < outlink->channels; n++) {
+    for (n = 0; n < outlink->ch_layout.nb_channels; n++) {
         s->phase[n] = av_calloc(s->num_chorus, sizeof(int));
         if (!s->phase[n])
             return AVERROR(ENOMEM);
@@ -201,7 +201,7 @@ static int config_output(AVFilterLink *outlink)
     s->fade_out = s->max_samples;
 
     return av_samples_alloc_array_and_samples(&s->chorusbuf, NULL,
-                                              outlink->channels,
+                                              outlink->ch_layout.nb_channels,
                                               s->max_samples,
                                               outlink->format, 0);
 }
@@ -226,7 +226,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
         av_frame_copy_props(out_frame, frame);
     }
 
-    for (c = 0; c < inlink->channels; c++) {
+    for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
         const float *src = (const float *)frame->extended_data[c];
         float *dst = (float *)out_frame->extended_data[c];
         float *chorusbuf = (float *)s->chorusbuf[c];
@@ -280,7 +280,7 @@ static int request_frame(AVFilterLink *outlink)
 
         av_samples_set_silence(frame->extended_data, 0,
                                frame->nb_samples,
-                               outlink->channels,
+                               outlink->ch_layout.nb_channels,
                                frame->format);
 
         frame->pts = s->next_pts;
diff --git a/libavfilter/af_compand.c b/libavfilter/af_compand.c
index 2f8a580279..ba90d21ced 100644
--- a/libavfilter/af_compand.c
+++ b/libavfilter/af_compand.c
@@ -146,7 +146,7 @@ static int compand_nodelay(AVFilterContext *ctx, AVFrame *frame)
 {
     CompandContext *s    = ctx->priv;
     AVFilterLink *inlink = ctx->inputs[0];
-    const int channels   = inlink->channels;
+    const int channels   = inlink->ch_layout.nb_channels;
     const int nb_samples = frame->nb_samples;
     AVFrame *out_frame;
     int chan, i;
@@ -192,7 +192,7 @@ static int compand_delay(AVFilterContext *ctx, AVFrame *frame)
 {
     CompandContext *s    = ctx->priv;
     AVFilterLink *inlink = ctx->inputs[0];
-    const int channels = inlink->channels;
+    const int channels = inlink->ch_layout.nb_channels;
     const int nb_samples = frame->nb_samples;
     int chan, i, av_uninit(dindex), oindex, av_uninit(count);
     AVFrame *out_frame   = NULL;
@@ -264,7 +264,7 @@ static int compand_drain(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
     CompandContext *s    = ctx->priv;
-    const int channels   = outlink->channels;
+    const int channels   = outlink->ch_layout.nb_channels;
     AVFrame *frame       = NULL;
     int chan, i, dindex;
 
@@ -302,7 +302,7 @@ static int config_output(AVFilterLink *outlink)
     const int sample_rate = outlink->sample_rate;
     double radius         = s->curve_dB * M_LN10 / 20.0;
     char *p, *saveptr     = NULL;
-    const int channels    = outlink->channels;
+    const int channels    = outlink->ch_layout.nb_channels;
     int nb_attacks, nb_decays, nb_points;
     int new_nb_items, num;
     int i;
@@ -503,7 +503,13 @@ static int config_output(AVFilterLink *outlink)
 
     s->delay_frame->format         = outlink->format;
     s->delay_frame->nb_samples     = s->delay_samples;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     s->delay_frame->channel_layout = outlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((err = av_channel_layout_copy(&s->delay_frame->ch_layout, &outlink->ch_layout)) < 0)
+        return err;
 
     err = av_frame_get_buffer(s->delay_frame, 0);
     if (err)
diff --git a/libavfilter/af_compensationdelay.c b/libavfilter/af_compensationdelay.c
index 6a58fd21bd..ac5a342ddb 100644
--- a/libavfilter/af_compensationdelay.c
+++ b/libavfilter/af_compensationdelay.c
@@ -68,6 +68,7 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     CompensationDelayContext *s = ctx->priv;
     unsigned min_size, new_size = 1;
+    int ret;
 
     s->delay = (s->distance_m * 100. + s->distance_cm * 1. + s->distance_mm * .1) *
                COMP_DELAY_SOUND_FRONT_DELAY(s->temp) * inlink->sample_rate;
@@ -83,7 +84,13 @@ static int config_input(AVFilterLink *inlink)
     s->buf_size                    = new_size;
     s->delay_frame->format         = inlink->format;
     s->delay_frame->nb_samples     = new_size;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     s->delay_frame->channel_layout = inlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((ret = av_channel_layout_copy(&s->delay_frame->ch_layout, &inlink->ch_layout)) < 0)
+        return ret;
 
     return av_frame_get_buffer(s->delay_frame, 0);
 }
@@ -108,7 +115,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     }
     av_frame_copy_props(out, in);
 
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         const double *src = (const double *)in->extended_data[ch];
         double *dst = (double *)out->extended_data[ch];
         double *buffer = (double *)s->delay_frame->extended_data[ch];
diff --git a/libavfilter/af_crossfeed.c b/libavfilter/af_crossfeed.c
index ecfbb978d4..15990703e1 100644
--- a/libavfilter/af_crossfeed.c
+++ b/libavfilter/af_crossfeed.c
@@ -46,7 +46,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_DBL  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0 ||
         (ret = ff_set_common_all_samplerates (ctx                          )) < 0)
         return ret;
diff --git a/libavfilter/af_crystalizer.c b/libavfilter/af_crystalizer.c
index 8d967fd629..2d0ec50f21 100644
--- a/libavfilter/af_crystalizer.c
+++ b/libavfilter/af_crystalizer.c
@@ -312,10 +312,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     td.s = (const void **)in->extended_data;
     td.p = (void **)s->prev->extended_data;
     td.nb_samples = in->nb_samples;
-    td.channels = in->channels;
+    td.channels = in->ch_layout.nb_channels;
     td.mult = ctx->is_disabled ? 0.f : s->mult;
     ff_filter_execute(ctx, s->filter[td.mult >= 0.f][s->clip], &td, NULL,
-                      FFMIN(inlink->channels, ff_filter_get_nb_threads(ctx)));
+                      FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
     if (out != in)
         av_frame_free(&in);
diff --git a/libavfilter/af_dcshift.c b/libavfilter/af_dcshift.c
index da7c16550a..480f01f4a3 100644
--- a/libavfilter/af_dcshift.c
+++ b/libavfilter/af_dcshift.c
@@ -73,7 +73,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     }
 
     if (s->limitergain > 0) {
-        for (i = 0; i < inlink->channels; i++) {
+        for (i = 0; i < inlink->ch_layout.nb_channels; i++) {
             const int32_t *src = (int32_t *)in->extended_data[i];
             int32_t *dst = (int32_t *)out->extended_data[i];
 
@@ -98,7 +98,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
             }
         }
     } else {
-        for (i = 0; i < inlink->channels; i++) {
+        for (i = 0; i < inlink->ch_layout.nb_channels; i++) {
             const int32_t *src = (int32_t *)in->extended_data[i];
             int32_t *dst = (int32_t *)out->extended_data[i];
 
diff --git a/libavfilter/af_deesser.c b/libavfilter/af_deesser.c
index 1093e242d7..cdef837155 100644
--- a/libavfilter/af_deesser.c
+++ b/libavfilter/af_deesser.c
@@ -73,11 +73,11 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     DeesserContext *s = ctx->priv;
 
-    s->chan = av_calloc(inlink->channels, sizeof(*s->chan));
+    s->chan = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->chan));
     if (!s->chan)
         return AVERROR(ENOMEM);
 
-    for (int i = 0; i < inlink->channels; i++) {
+    for (int i = 0; i < inlink->ch_layout.nb_channels; i++) {
         DeesserChannel *chan = &s->chan[i];
 
         chan->ratioA = chan->ratioB = 1.0;
@@ -104,7 +104,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         av_frame_copy_props(out, in);
     }
 
-    for (int ch = 0; ch < inlink->channels; ch++) {
+    for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         DeesserChannel *dec = &s->chan[ch];
         double *src = (double *)in->extended_data[ch];
         double *dst = (double *)out->extended_data[ch];
diff --git a/libavfilter/af_drmeter.c b/libavfilter/af_drmeter.c
index 2021cab143..3e80691339 100644
--- a/libavfilter/af_drmeter.c
+++ b/libavfilter/af_drmeter.c
@@ -59,10 +59,10 @@ static int config_output(AVFilterLink *outlink)
 {
     DRMeterContext *s = outlink->src->priv;
 
-    s->chstats = av_calloc(sizeof(*s->chstats), outlink->channels);
+    s->chstats = av_calloc(sizeof(*s->chstats), outlink->ch_layout.nb_channels);
     if (!s->chstats)
         return AVERROR(ENOMEM);
-    s->nb_channels = outlink->channels;
+    s->nb_channels = outlink->ch_layout.nb_channels;
     s->tc_samples = s->time_constant * outlink->sample_rate + .5;
 
     return 0;
diff --git a/libavfilter/af_dynaudnorm.c b/libavfilter/af_dynaudnorm.c
index 783266f8c1..f154f54134 100644
--- a/libavfilter/af_dynaudnorm.c
+++ b/libavfilter/af_dynaudnorm.c
@@ -301,17 +301,17 @@ static int config_input(AVFilterLink *inlink)
 
     uninit(ctx);
 
-    s->channels = inlink->channels;
+    s->channels = inlink->ch_layout.nb_channels;
     s->frame_len = frame_size(inlink->sample_rate, s->frame_len_msec);
     av_log(ctx, AV_LOG_DEBUG, "frame len %d\n", s->frame_len);
 
-    s->prev_amplification_factor = av_malloc_array(inlink->channels, sizeof(*s->prev_amplification_factor));
-    s->dc_correction_value = av_calloc(inlink->channels, sizeof(*s->dc_correction_value));
-    s->compress_threshold = av_calloc(inlink->channels, sizeof(*s->compress_threshold));
-    s->gain_history_original = av_calloc(inlink->channels, sizeof(*s->gain_history_original));
-    s->gain_history_minimum = av_calloc(inlink->channels, sizeof(*s->gain_history_minimum));
-    s->gain_history_smoothed = av_calloc(inlink->channels, sizeof(*s->gain_history_smoothed));
-    s->threshold_history = av_calloc(inlink->channels, sizeof(*s->threshold_history));
+    s->prev_amplification_factor = av_malloc_array(inlink->ch_layout.nb_channels, sizeof(*s->prev_amplification_factor));
+    s->dc_correction_value = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->dc_correction_value));
+    s->compress_threshold = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->compress_threshold));
+    s->gain_history_original = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->gain_history_original));
+    s->gain_history_minimum = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->gain_history_minimum));
+    s->gain_history_smoothed = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->gain_history_smoothed));
+    s->threshold_history = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->threshold_history));
     s->weights = av_malloc_array(MAX_FILTER_SIZE, sizeof(*s->weights));
     s->is_enabled = cqueue_create(s->filter_size, MAX_FILTER_SIZE);
     if (!s->prev_amplification_factor || !s->dc_correction_value ||
@@ -321,7 +321,7 @@ static int config_input(AVFilterLink *inlink)
         !s->is_enabled || !s->weights)
         return AVERROR(ENOMEM);
 
-    for (c = 0; c < inlink->channels; c++) {
+    for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
         s->prev_amplification_factor[c] = 1.0;
 
         s->gain_history_original[c] = cqueue_create(s->filter_size, MAX_FILTER_SIZE);
@@ -364,7 +364,7 @@ static double find_peak_magnitude(AVFrame *frame, int channel)
     int c, i;
 
     if (channel == -1) {
-        for (c = 0; c < frame->channels; c++) {
+        for (c = 0; c < frame->ch_layout.nb_channels; c++) {
             double *data_ptr = (double *)frame->extended_data[c];
 
             for (i = 0; i < frame->nb_samples; i++)
@@ -386,7 +386,7 @@ static double compute_frame_rms(AVFrame *frame, int channel)
     int c, i;
 
     if (channel == -1) {
-        for (c = 0; c < frame->channels; c++) {
+        for (c = 0; c < frame->ch_layout.nb_channels; c++) {
             const double *data_ptr = (double *)frame->extended_data[c];
 
             for (i = 0; i < frame->nb_samples; i++) {
@@ -394,7 +394,7 @@ static double compute_frame_rms(AVFrame *frame, int channel)
             }
         }
 
-        rms_value /= frame->nb_samples * frame->channels;
+        rms_value /= frame->nb_samples * frame->ch_layout.nb_channels;
     } else {
         const double *data_ptr = (double *)frame->extended_data[channel];
         for (i = 0; i < frame->nb_samples; i++) {
diff --git a/libavfilter/af_earwax.c b/libavfilter/af_earwax.c
index fa0162abb2..f420a5ac55 100644
--- a/libavfilter/af_earwax.c
+++ b/libavfilter/af_earwax.c
@@ -88,7 +88,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_S16P                )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats                           )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO               )) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout                            )) < 0 ||
         (ret = ff_set_common_samplerates_from_list(ctx, sample_rates)) < 0)
         return ret;
diff --git a/libavfilter/af_extrastereo.c b/libavfilter/af_extrastereo.c
index 1645ccb944..6f1d691d8e 100644
--- a/libavfilter/af_extrastereo.c
+++ b/libavfilter/af_extrastereo.c
@@ -49,7 +49,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_FLT  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_firequalizer.c b/libavfilter/af_firequalizer.c
index 568b78117a..c19a2fe122 100644
--- a/libavfilter/af_firequalizer.c
+++ b/libavfilter/af_firequalizer.c
@@ -607,14 +607,15 @@ static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g
     if (s->dumpfile && (!s->dump_buf || !s->analysis_rdft || !(dump_fp = fopen(s->dumpfile, "w"))))
         av_log(ctx, AV_LOG_WARNING, "dumping failed.\n");
 
-    vars[VAR_CHS] = inlink->channels;
-    vars[VAR_CHLAYOUT] = inlink->channel_layout;
+    vars[VAR_CHS] = inlink->ch_layout.nb_channels;
+    vars[VAR_CHLAYOUT] = inlink->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                         inlink->ch_layout.u.mask : 0;
     vars[VAR_SR] = inlink->sample_rate;
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         float *rdft_buf = s->kernel_tmp_buf + ch * s->rdft_len;
         double result;
         vars[VAR_CH] = ch;
-        vars[VAR_CHID] = av_channel_layout_extract_channel(inlink->channel_layout, ch);
+        vars[VAR_CHID] = av_channel_layout_channel_from_index(&inlink->ch_layout, ch);
         vars[VAR_F] = 0.0;
         if (xlog)
             vars[VAR_F] = log2(0.05 * vars[VAR_F]);
@@ -715,7 +716,7 @@ static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g
             break;
     }
 
-    memcpy(s->kernel_buf, s->kernel_tmp_buf, (s->multi ? inlink->channels : 1) * s->rdft_len * sizeof(*s->kernel_buf));
+    memcpy(s->kernel_buf, s->kernel_tmp_buf, (s->multi ? inlink->ch_layout.nb_channels : 1) * s->rdft_len * sizeof(*s->kernel_buf));
     av_expr_free(gain_expr);
     if (dump_fp)
         fclose(dump_fp);
@@ -754,7 +755,7 @@ static int config_input(AVFilterLink *inlink)
     if (!(s->rdft = av_rdft_init(rdft_bits, DFT_R2C)) || !(s->irdft = av_rdft_init(rdft_bits, IDFT_C2R)))
         return AVERROR(ENOMEM);
 
-    if (s->fft2 && !s->multi && inlink->channels > 1 && !(s->fft_ctx = av_fft_init(rdft_bits, 0)))
+    if (s->fft2 && !s->multi && inlink->ch_layout.nb_channels > 1 && !(s->fft_ctx = av_fft_init(rdft_bits, 0)))
         return AVERROR(ENOMEM);
 
     if (s->min_phase) {
@@ -796,15 +797,15 @@ static int config_input(AVFilterLink *inlink)
     }
 
     s->analysis_buf = av_malloc_array(s->analysis_rdft_len, sizeof(*s->analysis_buf));
-    s->kernel_tmp_buf = av_malloc_array(s->rdft_len * (s->multi ? inlink->channels : 1), sizeof(*s->kernel_tmp_buf));
-    s->kernel_buf = av_malloc_array(s->rdft_len * (s->multi ? inlink->channels : 1), sizeof(*s->kernel_buf));
-    s->conv_buf   = av_calloc(2 * s->rdft_len * inlink->channels, sizeof(*s->conv_buf));
-    s->conv_idx   = av_calloc(inlink->channels, sizeof(*s->conv_idx));
+    s->kernel_tmp_buf = av_malloc_array(s->rdft_len * (s->multi ? inlink->ch_layout.nb_channels : 1), sizeof(*s->kernel_tmp_buf));
+    s->kernel_buf = av_malloc_array(s->rdft_len * (s->multi ? inlink->ch_layout.nb_channels : 1), sizeof(*s->kernel_buf));
+    s->conv_buf   = av_calloc(2 * s->rdft_len * inlink->ch_layout.nb_channels, sizeof(*s->conv_buf));
+    s->conv_idx   = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->conv_idx));
     if (!s->analysis_buf || !s->kernel_tmp_buf || !s->kernel_buf || !s->conv_buf || !s->conv_idx)
         return AVERROR(ENOMEM);
 
     av_log(ctx, AV_LOG_DEBUG, "sample_rate = %d, channels = %d, analysis_rdft_len = %d, rdft_len = %d, fir_len = %d, nsamples_max = %d.\n",
-           inlink->sample_rate, inlink->channels, s->analysis_rdft_len, s->rdft_len, s->fir_len, s->nsamples_max);
+           inlink->sample_rate, inlink->ch_layout.nb_channels, s->analysis_rdft_len, s->rdft_len, s->fir_len, s->nsamples_max);
 
     if (s->fixed)
         inlink->min_samples = inlink->max_samples = s->nsamples_max;
@@ -819,19 +820,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
     int ch;
 
     if (!s->min_phase) {
-        for (ch = 0; ch + 1 < inlink->channels && s->fft_ctx; ch += 2) {
+        for (ch = 0; ch + 1 < inlink->ch_layout.nb_channels && s->fft_ctx; ch += 2) {
             fast_convolute2(s, s->kernel_buf, (FFTComplex *)(s->conv_buf + 2 * ch * s->rdft_len),
                             s->conv_idx + ch, (float *) frame->extended_data[ch],
                             (float *) frame->extended_data[ch+1], frame->nb_samples);
         }
 
-        for ( ; ch < inlink->channels; ch++) {
+        for ( ; ch < inlink->ch_layout.nb_channels; ch++) {
             fast_convolute(s, s->kernel_buf + (s->multi ? ch * s->rdft_len : 0),
                         s->conv_buf + 2 * ch * s->rdft_len, s->conv_idx + ch,
                         (float *) frame->extended_data[ch], frame->nb_samples);
         }
     } else {
-        for (ch = 0; ch < inlink->channels; ch++) {
+        for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
             fast_convolute_nonlinear(s, s->kernel_buf + (s->multi ? ch * s->rdft_len : 0),
                                      s->conv_buf + 2 * ch * s->rdft_len, s->conv_idx + ch,
                                      (float *) frame->extended_data[ch], frame->nb_samples);
@@ -861,7 +862,7 @@ static int request_frame(AVFilterLink *outlink)
         if (!frame)
             return AVERROR(ENOMEM);
 
-        av_samples_set_silence(frame->extended_data, 0, frame->nb_samples, outlink->channels, frame->format);
+        av_samples_set_silence(frame->extended_data, 0, frame->nb_samples, outlink->ch_layout.nb_channels, frame->format);
         frame->pts = s->next_pts;
         s->remaining -= frame->nb_samples;
         ret = filter_frame(ctx->inputs[0], frame);
diff --git a/libavfilter/af_flanger.c b/libavfilter/af_flanger.c
index ba8d033ce8..452436a4b6 100644
--- a/libavfilter/af_flanger.c
+++ b/libavfilter/af_flanger.c
@@ -95,7 +95,7 @@ static int config_input(AVFilterLink *inlink)
 
     s->max_samples = (s->delay_min + s->delay_depth) * inlink->sample_rate + 2.5;
     s->lfo_length  = inlink->sample_rate / s->speed;
-    s->delay_last  = av_calloc(inlink->channels, sizeof(*s->delay_last));
+    s->delay_last  = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->delay_last));
     s->lfo         = av_calloc(s->lfo_length, sizeof(*s->lfo));
     if (!s->lfo || !s->delay_last)
         return AVERROR(ENOMEM);
@@ -105,7 +105,7 @@ static int config_input(AVFilterLink *inlink)
                            s->max_samples - 2., 3 * M_PI_2);
 
     return av_samples_alloc_array_and_samples(&s->delay_buffer, NULL,
-                                              inlink->channels, s->max_samples,
+                                              inlink->ch_layout.nb_channels, s->max_samples,
                                               inlink->format, 0);
 }
 
@@ -131,7 +131,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 
         s->delay_buf_pos = (s->delay_buf_pos + s->max_samples - 1) % s->max_samples;
 
-        for (chan = 0; chan < inlink->channels; chan++) {
+        for (chan = 0; chan < inlink->ch_layout.nb_channels; chan++) {
             double *src = (double *)frame->extended_data[chan];
             double *dst = (double *)out_frame->extended_data[chan];
             double delayed_0, delayed_1;
diff --git a/libavfilter/af_haas.c b/libavfilter/af_haas.c
index 281ec276f9..d283da7261 100644
--- a/libavfilter/af_haas.c
+++ b/libavfilter/af_haas.c
@@ -87,7 +87,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_DBL  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_hdcd.c b/libavfilter/af_hdcd.c
index 494642106d..49bfa1bfa8 100644
--- a/libavfilter/af_hdcd.c
+++ b/libavfilter/af_hdcd.c
@@ -1554,27 +1554,27 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     switch (inlink->format) {
         case AV_SAMPLE_FMT_S16P:
             for (n = 0; n < in->nb_samples; n++)
-                for (c = 0; c < in->channels; c++) {
+                for (c = 0; c < in->ch_layout.nb_channels; c++) {
                     in_data = (int16_t*)in->extended_data[c];
-                    out_data[(n * in->channels) + c] = in_data[n];
+                    out_data[(n * in->ch_layout.nb_channels) + c] = in_data[n];
                 }
             break;
         case AV_SAMPLE_FMT_S16:
             in_data  = (int16_t*)in->data[0];
-            for (n = 0; n < in->nb_samples * in->channels; n++)
+            for (n = 0; n < in->nb_samples * in->ch_layout.nb_channels; n++)
                 out_data[n] = in_data[n];
             break;
 
         case AV_SAMPLE_FMT_S32P:
             for (n = 0; n < in->nb_samples; n++)
-                for (c = 0; c < in->channels; c++) {
+                for (c = 0; c < in->ch_layout.nb_channels; c++) {
                     in_data32 = (int32_t*)in->extended_data[c];
-                    out_data[(n * in->channels) + c] = in_data32[n] >> a;
+                    out_data[(n * in->ch_layout.nb_channels) + c] = in_data32[n] >> a;
                 }
             break;
         case AV_SAMPLE_FMT_S32:
             in_data32  = (int32_t*)in->data[0];
-            for (n = 0; n < in->nb_samples * in->channels; n++)
+            for (n = 0; n < in->nb_samples * in->ch_layout.nb_channels; n++)
                 out_data[n] = in_data32[n] >> a;
             break;
     }
@@ -1587,14 +1587,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         hdcd_detect_end(&s->detect, 2);
     } else {
         hdcd_detect_start(&s->detect);
-        for (c = 0; c < in->channels; c++) {
-            hdcd_process(s, &s->state[c], out_data + c, in->nb_samples, in->channels);
+        for (c = 0; c < in->ch_layout.nb_channels; c++) {
+            hdcd_process(s, &s->state[c], out_data + c, in->nb_samples, in->ch_layout.nb_channels);
             hdcd_detect_onech(&s->state[c], &s->detect);
         }
-        hdcd_detect_end(&s->detect, in->channels);
+        hdcd_detect_end(&s->detect, in->ch_layout.nb_channels);
     }
 
-    s->sample_count += in->nb_samples * in->channels;
+    s->sample_count += in->nb_samples * in->ch_layout.nb_channels;
 
     av_frame_free(&in);
     return ff_filter_frame(outlink, out);
@@ -1627,10 +1627,10 @@ static int query_formats(AVFilterContext *ctx)
     };
     int ret;
 
-    ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_MONO);
+    ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO);
     if (ret < 0)
         return ret;
-    ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO);
+    ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
     if (ret < 0)
         return ret;
 
@@ -1739,8 +1739,8 @@ static int config_input(AVFilterLink *inlink) {
     av_log(ctx, AV_LOG_VERBOSE, "CDT period: %dms (%u samples @44100Hz)\n",
         s->cdt_ms, s->state[0].sustain_reset );
 
-    if (inlink->channels != 2 && s->process_stereo) {
-        av_log(ctx, AV_LOG_WARNING, "process_stereo disabled (channels = %d)\n", inlink->channels);
+    if (inlink->ch_layout.nb_channels != 2 && s->process_stereo) {
+        av_log(ctx, AV_LOG_WARNING, "process_stereo disabled (channels = %d)\n", inlink->ch_layout.nb_channels);
         s->process_stereo = 0;
     }
     av_log(ctx, AV_LOG_VERBOSE, "Process mode: %s\n",
diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index b2030dbbbb..2fe36368c1 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -85,13 +85,13 @@ typedef struct HeadphoneContext {
     uint64_t mapping[64];
 } HeadphoneContext;
 
-static int parse_channel_name(const char *arg, uint64_t *rchannel)
+static int parse_channel_name(const char *arg, int *rchannel)
 {
-    uint64_t layout = av_get_channel_layout(arg);
+    int channel = av_channel_from_string(arg);
 
-    if (av_get_channel_layout_nb_channels(layout) != 1)
+    if (channel < 0)
         return AVERROR(EINVAL);
-    *rchannel = layout;
+    *rchannel = channel;
     return 0;
 }
 
@@ -103,14 +103,14 @@ static void parse_map(AVFilterContext *ctx)
 
     p = s->map;
     while ((arg = av_strtok(p, "|", &tokenizer))) {
-        uint64_t out_channel;
+        int out_channel;
 
         p = NULL;
         if (parse_channel_name(arg, &out_channel)) {
             av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", arg);
             continue;
         }
-        if (used_channels & out_channel) {
+        if (used_channels & (1ULL << out_channel)) {
             av_log(ctx, AV_LOG_WARNING, "Ignoring duplicate channel '%s'.\n", arg);
             continue;
         }
@@ -152,7 +152,7 @@ static int headphone_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n
     const int air_len = s->air_len;
     const float *src = (const float *)in->data[0];
     float *dst = (float *)out->data[0];
-    const int in_channels = in->channels;
+    const int in_channels = in->ch_layout.nb_channels;
     const int buffer_length = s->buffer_length;
     const uint32_t modulo = (uint32_t)buffer_length - 1;
     float *buffer[64];
@@ -221,7 +221,7 @@ static int headphone_fast_convolute(AVFilterContext *ctx, void *arg, int jobnr,
     const int ir_len = s->ir_len;
     const float *src = (const float *)in->data[0];
     float *dst = (float *)out->data[0];
-    const int in_channels = in->channels;
+    const int in_channels = in->ch_layout.nb_channels;
     const int buffer_length = s->buffer_length;
     const uint32_t modulo = (uint32_t)buffer_length - 1;
     AVComplexFloat *fft_out = s->out_fft[jobnr];
@@ -360,7 +360,7 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
 {
     struct HeadphoneContext *s = ctx->priv;
     const int ir_len = s->ir_len;
-    int nb_input_channels = ctx->inputs[0]->channels;
+    int nb_input_channels = ctx->inputs[0]->ch_layout.nb_channels;
     float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10);
     AVFrame *frame;
     int ret = 0;
@@ -451,7 +451,7 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
         ptr = (float *)frame->extended_data[0];
 
         if (s->hrir_fmt == HRIR_STEREO) {
-            int idx = av_get_channel_layout_channel_index(inlink->channel_layout,
+            int idx = av_channel_layout_index_from_channel(&inlink->ch_layout,
                                                           s->mapping[i]);
             if (idx < 0)
                 continue;
@@ -478,10 +478,10 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
                 s->tx_fn[0](s->fft[0], fft_out_r, fft_in_r, sizeof(float));
             }
         } else {
-            int I, N = ctx->inputs[1]->channels;
+            int I, N = ctx->inputs[1]->ch_layout.nb_channels;
 
             for (k = 0; k < N / 2; k++) {
-                int idx = av_get_channel_layout_channel_index(inlink->channel_layout,
+                int idx = av_channel_layout_index_from_channel(&inlink->ch_layout,
                                                               s->mapping[k]);
                 if (idx < 0)
                     continue;
@@ -602,7 +602,7 @@ static int query_formats(AVFilterContext *ctx)
     if (ret)
         return ret;
 
-    ret = ff_add_channel_layout(&stereo_layout, AV_CH_LAYOUT_STEREO);
+    ret = ff_add_channel_layout(&stereo_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
     if (ret)
         return ret;
     ret = ff_channel_layouts_ref(stereo_layout, &ctx->outputs[0]->incfg.channel_layouts);
@@ -632,13 +632,13 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     HeadphoneContext *s = ctx->priv;
 
-    if (s->nb_irs < inlink->channels) {
-        av_log(ctx, AV_LOG_ERROR, "Number of HRIRs must be >= %d.\n", inlink->channels);
+    if (s->nb_irs < inlink->ch_layout.nb_channels) {
+        av_log(ctx, AV_LOG_ERROR, "Number of HRIRs must be >= %d.\n", inlink->ch_layout.nb_channels);
         return AVERROR(EINVAL);
     }
 
-    s->lfe_channel = av_get_channel_layout_channel_index(inlink->channel_layout,
-                                                         AV_CH_LOW_FREQUENCY);
+    s->lfe_channel = av_channel_layout_index_from_channel(&inlink->ch_layout,
+                                                          AV_CHAN_LOW_FREQUENCY);
     return 0;
 }
 
@@ -694,13 +694,13 @@ static int config_output(AVFilterLink *outlink)
     if (s->hrir_fmt == HRIR_MULTI) {
         AVFilterLink *hrir_link = ctx->inputs[1];
 
-        if (hrir_link->channels < inlink->channels * 2) {
-            av_log(ctx, AV_LOG_ERROR, "Number of channels in HRIR stream must be >= %d.\n", inlink->channels * 2);
+        if (hrir_link->ch_layout.nb_channels < inlink->ch_layout.nb_channels * 2) {
+            av_log(ctx, AV_LOG_ERROR, "Number of channels in HRIR stream must be >= %d.\n", inlink->ch_layout.nb_channels * 2);
             return AVERROR(EINVAL);
         }
     }
 
-    s->gain_lfe = expf((s->gain - 3 * inlink->channels + s->lfe_gain) / 20 * M_LN10);
+    s->gain_lfe = expf((s->gain - 3 * inlink->ch_layout.nb_channels + s->lfe_gain) / 20 * M_LN10);
 
     return 0;
 }
diff --git a/libavfilter/af_join.c b/libavfilter/af_join.c
index 6cc21f465c..3e272d9161 100644
--- a/libavfilter/af_join.c
+++ b/libavfilter/af_join.c
@@ -24,6 +24,7 @@
  * a single output
  */
 
+#include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
@@ -36,10 +37,10 @@
 #include "internal.h"
 
 typedef struct ChannelMap {
-    int input;                ///< input stream index
-    int       in_channel_idx; ///< index of in_channel in the input stream data
-    uint64_t  in_channel;     ///< layout describing the input channel
-    uint64_t out_channel;     ///< layout describing the output channel
+    int input;                     ///< input stream index
+    int            in_channel_idx; ///< index of in_channel in the input stream data
+    enum AVChannel in_channel;
+    enum AVChannel out_channel;
 } ChannelMap;
 
 typedef struct JoinContext {
@@ -48,11 +49,10 @@ typedef struct JoinContext {
     int inputs;
     char *map;
     char    *channel_layout_str;
-    uint64_t channel_layout;
+    AVChannelLayout ch_layout;
 
     int64_t  eof_pts;
 
-    int      nb_channels;
     ChannelMap *channels;
 
     /**
@@ -79,20 +79,21 @@ static const AVOption join_options[] = {
     { NULL }
 };
 
+#define MAP_SEPARATOR '|'
+
 AVFILTER_DEFINE_CLASS(join);
 
 static int parse_maps(AVFilterContext *ctx)
 {
     JoinContext *s = ctx->priv;
-    char separator = '|';
     char *cur      = s->map;
 
     while (cur && *cur) {
+        ChannelMap *map;
         char *sep, *next, *p;
-        uint64_t in_channel = 0, out_channel = 0;
-        int input_idx, out_ch_idx, in_ch_idx;
+        int input_idx, out_ch_idx;
 
-        next = strchr(cur, separator);
+        next = strchr(cur, MAP_SEPARATOR);
         if (next)
             *next++ = 0;
 
@@ -104,28 +105,16 @@ static int parse_maps(AVFilterContext *ctx)
         }
         *sep++ = 0;
 
-#define PARSE_CHANNEL(str, var, inout)                                         \
-        if (!(var = av_get_channel_layout(str))) {                             \
-            av_log(ctx, AV_LOG_ERROR, "Invalid " inout " channel: %s.\n", str);\
-            return AVERROR(EINVAL);                                            \
-        }                                                                      \
-        if (av_get_channel_layout_nb_channels(var) != 1) {                     \
-            av_log(ctx, AV_LOG_ERROR, "Channel map describes more than one "   \
-                   inout " channel.\n");                                       \
-            return AVERROR(EINVAL);                                            \
-        }
-
         /* parse output channel */
-        PARSE_CHANNEL(sep, out_channel, "output");
-        if (!(out_channel & s->channel_layout)) {
-            av_log(ctx, AV_LOG_ERROR, "Output channel '%s' is not present in "
-                   "requested channel layout.\n", sep);
+        out_ch_idx = av_channel_layout_index_from_string(&s->ch_layout, sep);
+        if (out_ch_idx < 0) {
+            av_log(ctx, AV_LOG_ERROR, "Invalid output channel: %s.\n", sep);
             return AVERROR(EINVAL);
         }
 
-        out_ch_idx = av_get_channel_layout_channel_index(s->channel_layout,
-                                                         out_channel);
-        if (s->channels[out_ch_idx].input >= 0) {
+        map = &s->channels[out_ch_idx];
+
+        if (map->input >= 0) {
             av_log(ctx, AV_LOG_ERROR, "Multiple maps for output channel "
                    "'%s'.\n", sep);
             return AVERROR(EINVAL);
@@ -142,19 +131,21 @@ static int parse_maps(AVFilterContext *ctx)
         if (*cur)
             cur++;
 
-        in_ch_idx = strtol(cur, &p, 0);
+        map->input          = input_idx;
+        map->in_channel     = AV_CHAN_NONE;
+        map->in_channel_idx = strtol(cur, &p, 0);
         if (p == cur) {
-            /* channel specifier is not a number,
-             * try to parse as channel name */
-            PARSE_CHANNEL(cur, in_channel, "input");
+            /* channel specifier is not a number, handle as channel name */
+            map->in_channel = av_channel_from_string(cur);
+            if (map->in_channel < 0) {
+                av_log(ctx, AV_LOG_ERROR, "Invalid input channel: %s.\n", cur);
+                return AVERROR(EINVAL);
+            }
+        } else if (map->in_channel_idx < 0) {
+            av_log(ctx, AV_LOG_ERROR, "Invalid input channel index: %d\n", map->in_channel_idx);
+            return AVERROR(EINVAL);
         }
 
-        s->channels[out_ch_idx].input      = input_idx;
-        if (in_channel)
-            s->channels[out_ch_idx].in_channel = in_channel;
-        else
-            s->channels[out_ch_idx].in_channel_idx = in_ch_idx;
-
         cur = next;
     }
     return 0;
@@ -165,22 +156,37 @@ static av_cold int join_init(AVFilterContext *ctx)
     JoinContext *s = ctx->priv;
     int ret, i;
 
-    if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) {
-        av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
+    ret = av_channel_layout_from_string(&s->ch_layout, s->channel_layout_str);
+    if (ret < 0) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+        uint64_t mask;
+FF_DISABLE_DEPRECATION_WARNINGS
+        mask = av_get_channel_layout(s->channel_layout_str);
+        if (!mask) {
+#endif
+            av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
+                   s->channel_layout_str);
+            return AVERROR(EINVAL);
+#if FF_API_OLD_CHANNEL_LAYOUT
+        }
+FF_ENABLE_DEPRECATION_WARNINGS
+        av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
                s->channel_layout_str);
-        return AVERROR(EINVAL);
+        av_channel_layout_from_mask(&s->ch_layout, mask);
+#endif
     }
 
-    s->nb_channels  = av_get_channel_layout_nb_channels(s->channel_layout);
-    s->channels     = av_calloc(s->nb_channels, sizeof(*s->channels));
-    s->buffers      = av_calloc(s->nb_channels, sizeof(*s->buffers));
+    s->channels     = av_calloc(s->ch_layout.nb_channels, sizeof(*s->channels));
+    s->buffers      = av_calloc(s->ch_layout.nb_channels, sizeof(*s->buffers));
     s->input_frames = av_calloc(s->inputs, sizeof(*s->input_frames));
     if (!s->channels || !s->buffers|| !s->input_frames)
         return AVERROR(ENOMEM);
 
-    for (i = 0; i < s->nb_channels; i++) {
-        s->channels[i].out_channel = av_channel_layout_extract_channel(s->channel_layout, i);
-        s->channels[i].input       = -1;
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
+        s->channels[i].out_channel    = av_channel_layout_channel_from_index(&s->ch_layout, i);
+        s->channels[i].input          = -1;
+        s->channels[i].in_channel_idx = -1;
+        s->channels[i].in_channel     = AV_CHAN_NONE;
     }
 
     if ((ret = parse_maps(ctx)) < 0)
@@ -221,7 +227,7 @@ static int join_query_formats(AVFilterContext *ctx)
     AVFilterChannelLayouts *layouts = NULL;
     int i, ret;
 
-    if ((ret = ff_add_channel_layout(&layouts, s->channel_layout)) < 0 ||
+    if ((ret = ff_add_channel_layout(&layouts, &s->ch_layout)) < 0 ||
         (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0)
         return ret;
 
@@ -238,38 +244,55 @@ static int join_query_formats(AVFilterContext *ctx)
     return 0;
 }
 
+typedef struct ChannelList {
+    enum AVChannel *ch;
+    int          nb_ch;
+} ChannelList;
+
+static enum AVChannel channel_list_pop(ChannelList *chl, int idx)
+{
+    enum AVChannel ret = chl->ch[idx];
+    memcpy(chl->ch + idx, chl->ch + idx + 1,
+           (chl->nb_ch - idx - 1) * sizeof(*chl->ch));
+    chl->nb_ch--;
+    return ret;
+}
+
+/*
+ * If ch is present in chl, remove it from the list and return it.
+ * Otherwise return AV_CHAN_NONE.
+ */
+static enum AVChannel channel_list_pop_ch(ChannelList *chl, enum AVChannel ch)
+{
+    for (int i = 0; i < chl->nb_ch; i++)
+        if (chl->ch[i] == ch)
+            return channel_list_pop(chl, i);
+    return AV_CHAN_NONE;
+}
+
 static void guess_map_matching(AVFilterContext *ctx, ChannelMap *ch,
-                               uint64_t *inputs)
+                               ChannelList *inputs)
 {
     int i;
 
     for (i = 0; i < ctx->nb_inputs; i++) {
-        AVFilterLink *link = ctx->inputs[i];
-
-        if (ch->out_channel & link->channel_layout &&
-            !(ch->out_channel & inputs[i])) {
+        if (channel_list_pop_ch(&inputs[i], ch->out_channel) != AV_CHAN_NONE) {
             ch->input      = i;
             ch->in_channel = ch->out_channel;
-            inputs[i]     |= ch->out_channel;
             return;
         }
     }
 }
 
 static void guess_map_any(AVFilterContext *ctx, ChannelMap *ch,
-                          uint64_t *inputs)
+                          ChannelList *inputs)
 {
     int i;
 
     for (i = 0; i < ctx->nb_inputs; i++) {
-        AVFilterLink *link = ctx->inputs[i];
-
-        if ((inputs[i] & link->channel_layout) != link->channel_layout) {
-            uint64_t unused = link->channel_layout & ~inputs[i];
-
+        if (inputs[i].nb_ch) {
             ch->input      = i;
-            ch->in_channel = av_channel_layout_extract_channel(unused, 0);
-            inputs[i]     |= ch->in_channel;
+            ch->in_channel = channel_list_pop(&inputs[i], 0);
             return;
         }
     }
@@ -279,81 +302,136 @@ static int join_config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
     JoinContext       *s = ctx->priv;
-    uint64_t *inputs;   // nth element tracks which channels are used from nth input
+    // unused channels from each input
+    ChannelList *inputs_unused;
+    char inbuf[64], outbuf[64];
     int i, ret = 0;
 
-    /* initialize inputs to user-specified mappings */
-    if (!(inputs = av_calloc(ctx->nb_inputs, sizeof(*inputs))))
+    /* initialize unused channel list for each input */
+    inputs_unused = av_calloc(ctx->nb_inputs, sizeof(*inputs_unused));
+    if (!inputs_unused)
         return AVERROR(ENOMEM);
-    for (i = 0; i < s->nb_channels; i++) {
+    for (i = 0; i < ctx->nb_inputs; i++) {
+        AVFilterLink *inlink = ctx->inputs[i];
+        AVChannelLayout *chl = &inlink->ch_layout;
+        ChannelList      *iu = &inputs_unused[i];
+
+        iu->nb_ch = chl->nb_channels;
+        iu->ch    = av_malloc_array(iu->nb_ch, sizeof(*iu->ch));
+        if (!iu->ch) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+
+        for (int ch_idx = 0; ch_idx < iu->nb_ch; ch_idx++) {
+            iu->ch[ch_idx] = av_channel_layout_channel_from_index(chl, ch_idx);
+            if (iu->ch[ch_idx] < 0) {
+                /* no channel ordering information in this input,
+                 * so don't auto-map from it */
+                iu->nb_ch = 0;
+                break;
+            }
+        }
+    }
+
+    /* process user-specified maps */
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
         ChannelMap *ch = &s->channels[i];
         AVFilterLink *inlink;
+        AVChannelLayout *ichl;
+        ChannelList     *iu;
 
         if (ch->input < 0)
             continue;
 
         inlink = ctx->inputs[ch->input];
+        ichl   = &inlink->ch_layout;
+        iu     = &inputs_unused[ch->input];
+
+        /* get the index for the channels defined by name */
+        if (ch->in_channel != AV_CHAN_NONE) {
+            ch->in_channel_idx = av_channel_layout_index_from_channel(ichl, ch->in_channel);
+            if (ch->in_channel_idx < 0) {
+                av_channel_name(inbuf, sizeof(inbuf), ch->in_channel);
+                av_log(ctx, AV_LOG_ERROR, "Requested channel %s is not present in "
+                       "input stream #%d.\n", inbuf,
+                       ch->input);
+                ret = AVERROR(EINVAL);
+                goto fail;
+            }
+        }
 
-        if (!ch->in_channel)
-            ch->in_channel = av_channel_layout_extract_channel(inlink->channel_layout,
-                                                               ch->in_channel_idx);
-
-        if (!(ch->in_channel & inlink->channel_layout)) {
-            av_log(ctx, AV_LOG_ERROR, "Requested channel %s is not present in "
-                   "input stream #%d.\n", av_get_channel_name(ch->in_channel),
-                   ch->input);
+        /* make sure channels specified by index actually exist */
+        if (ch->in_channel_idx >= ichl->nb_channels) {
+            av_log(ctx, AV_LOG_ERROR, "Requested channel with index %d is not "
+                   "present in input stream #%d.\n", ch->in_channel_idx, ch->input);
             ret = AVERROR(EINVAL);
             goto fail;
         }
 
-        inputs[ch->input] |= ch->in_channel;
+        channel_list_pop_ch(iu, av_channel_layout_channel_from_index(ichl, ch->in_channel_idx));
     }
 
     /* guess channel maps when not explicitly defined */
     /* first try unused matching channels */
-    for (i = 0; i < s->nb_channels; i++) {
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
         ChannelMap *ch = &s->channels[i];
 
         if (ch->input < 0)
-            guess_map_matching(ctx, ch, inputs);
+            guess_map_matching(ctx, ch, inputs_unused);
     }
 
     /* if the above failed, try to find _any_ unused input channel */
-    for (i = 0; i < s->nb_channels; i++) {
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
         ChannelMap *ch = &s->channels[i];
 
         if (ch->input < 0)
-            guess_map_any(ctx, ch, inputs);
+            guess_map_any(ctx, ch, inputs_unused);
 
         if (ch->input < 0) {
+            av_channel_name(outbuf, sizeof(outbuf), ch->out_channel);
             av_log(ctx, AV_LOG_ERROR, "Could not find input channel for "
                    "output channel '%s'.\n",
-                   av_get_channel_name(ch->out_channel));
+                   outbuf);
+            ret = AVERROR(EINVAL);
             goto fail;
         }
 
-        ch->in_channel_idx = av_get_channel_layout_channel_index(ctx->inputs[ch->input]->channel_layout,
-                                                                 ch->in_channel);
+        if (ch->in_channel != AV_CHAN_NONE) {
+            ch->in_channel_idx = av_channel_layout_index_from_channel(
+                &ctx->inputs[ch->input]->ch_layout, ch->in_channel);
+        }
+
+        av_assert0(ch->in_channel_idx >= 0);
     }
 
     /* print mappings */
     av_log(ctx, AV_LOG_VERBOSE, "mappings: ");
-    for (i = 0; i < s->nb_channels; i++) {
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
         ChannelMap *ch = &s->channels[i];
-        av_log(ctx, AV_LOG_VERBOSE, "%d.%s => %s ", ch->input,
-               av_get_channel_name(ch->in_channel),
-               av_get_channel_name(ch->out_channel));
+        AVFilterLink  *inlink = ctx->inputs[ch->input];
+        AVChannelLayout *ichl = &inlink->ch_layout;
+        enum AVChannel  in_ch = av_channel_layout_channel_from_index(
+                                    ichl, ch->in_channel_idx);
+
+        av_channel_name(inbuf, sizeof(inbuf), in_ch);
+        av_channel_name(outbuf, sizeof(outbuf), ch->out_channel);
+        av_log(ctx, AV_LOG_VERBOSE, "%d.%s(%d) => %s(%d) ", ch->input,
+               inbuf, ch->in_channel_idx,
+               outbuf, i);
     }
     av_log(ctx, AV_LOG_VERBOSE, "\n");
 
     for (i = 0; i < ctx->nb_inputs; i++) {
-        if (!inputs[i])
+        if (inputs_unused[i].nb_ch == ctx->inputs[i]->ch_layout.nb_channels)
             av_log(ctx, AV_LOG_WARNING, "No channels are used from input "
                    "stream %d.\n", i);
     }
 
 fail:
-    av_freep(&inputs);
+    for (i = 0; i < ctx->nb_inputs; i++)
+        av_freep(&inputs_unused[i].ch);
+    av_freep(&inputs_unused);
     return ret;
 }
 
@@ -382,8 +460,8 @@ static int try_push_frame(AVFilterContext *ctx)
     frame = av_frame_alloc();
     if (!frame)
         return AVERROR(ENOMEM);
-    if (s->nb_channels > FF_ARRAY_ELEMS(frame->data)) {
-        frame->extended_data = av_calloc(s->nb_channels,
+    if (s->ch_layout.nb_channels > FF_ARRAY_ELEMS(frame->data)) {
+        frame->extended_data = av_calloc(s->ch_layout.nb_channels,
                                           sizeof(*frame->extended_data));
         if (!frame->extended_data) {
             ret = AVERROR(ENOMEM);
@@ -392,7 +470,7 @@ static int try_push_frame(AVFilterContext *ctx)
     }
 
     /* copy the data pointers */
-    for (i = 0; i < s->nb_channels; i++) {
+    for (i = 0; i < s->ch_layout.nb_channels; i++) {
         ChannelMap *ch = &s->channels[i];
         AVFrame *cur   = s->input_frames[ch->input];
         AVBufferRef *buf;
@@ -442,15 +520,21 @@ static int try_push_frame(AVFilterContext *ctx)
     }
 
     frame->nb_samples     = nb_samples;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     frame->channel_layout = outlink->channel_layout;
-    frame->channels       = outlink->channels;
+    frame->channels       = outlink->ch_layout.nb_channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((ret = av_channel_layout_copy(&frame->ch_layout, &outlink->ch_layout)) < 0)
+        return ret;
     frame->sample_rate    = outlink->sample_rate;
     frame->format         = outlink->format;
     frame->pts            = s->input_frames[0]->pts;
     frame->linesize[0]    = linesize;
     if (frame->data != frame->extended_data) {
         memcpy(frame->data, frame->extended_data, sizeof(*frame->data) *
-               FFMIN(FF_ARRAY_ELEMS(frame->data), s->nb_channels));
+               FFMIN(FF_ARRAY_ELEMS(frame->data), s->ch_layout.nb_channels));
     }
 
     s->eof_pts = frame->pts + av_rescale_q(frame->nb_samples,
diff --git a/libavfilter/af_ladspa.c b/libavfilter/af_ladspa.c
index ff16388a56..46f85943e0 100644
--- a/libavfilter/af_ladspa.c
+++ b/libavfilter/af_ladspa.c
@@ -366,8 +366,14 @@ static int config_output(AVFilterLink *outlink)
         outlink->format      = inlink->format;
         outlink->sample_rate = inlink->sample_rate;
         if (s->nb_inputs == s->nb_outputs) {
+            if ((ret = av_channel_layout_copy(&outlink->ch_layout, &inlink->ch_layout)) < 0)
+                return ret;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             outlink->channel_layout = inlink->channel_layout;
-            outlink->channels = inlink->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+            outlink->ch_layout.nb_channels = inlink->ch_layout.nb_channels;
         }
 
         ret = 0;
@@ -681,7 +687,7 @@ static int query_formats(AVFilterContext *ctx)
             return ret;
     } else if (s->nb_inputs == 2 && s->nb_outputs == 2) {
         layouts = NULL;
-        ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO);
+        ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
         if (ret < 0)
             return ret;
         ret = ff_set_common_channel_layouts(ctx, layouts);
@@ -692,10 +698,10 @@ static int query_formats(AVFilterContext *ctx)
 
         if (s->nb_inputs >= 1) {
             AVFilterLink *inlink = ctx->inputs[0];
-            uint64_t inlayout = FF_COUNT2LAYOUT(s->nb_inputs);
+            AVChannelLayout inlayout = FF_COUNT2LAYOUT(s->nb_inputs);
 
             layouts = NULL;
-            ret = ff_add_channel_layout(&layouts, inlayout);
+            ret = ff_add_channel_layout(&layouts, &inlayout);
             if (ret < 0)
                 return ret;
             ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts);
@@ -710,10 +716,10 @@ static int query_formats(AVFilterContext *ctx)
         }
 
         if (s->nb_outputs >= 1) {
-            uint64_t outlayout = FF_COUNT2LAYOUT(s->nb_outputs);
+            AVChannelLayout outlayout = FF_COUNT2LAYOUT(s->nb_outputs);
 
             layouts = NULL;
-            ret = ff_add_channel_layout(&layouts, outlayout);
+            ret = ff_add_channel_layout(&layouts, &outlayout);
             if (ret < 0)
                 return ret;
             ret = ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts);
diff --git a/libavfilter/af_loudnorm.c b/libavfilter/af_loudnorm.c
index dbe7fba986..ac3cb2021d 100644
--- a/libavfilter/af_loudnorm.c
+++ b/libavfilter/af_loudnorm.c
@@ -446,7 +446,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         double offset, offset_tp, true_peak;
 
         ff_ebur128_loudness_global(s->r128_in, &global);
-        for (c = 0; c < inlink->channels; c++) {
+        for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
             double tmp;
             ff_ebur128_sample_peak(s->r128_in, c, &tmp);
             if (c == 0 || tmp > true_peak)
@@ -462,11 +462,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     switch (s->frame_type) {
     case FIRST_FRAME:
         for (n = 0; n < in->nb_samples; n++) {
-            for (c = 0; c < inlink->channels; c++) {
+            for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
                 buf[s->buf_index + c] = src[c];
             }
-            src += inlink->channels;
-            s->buf_index += inlink->channels;
+            src += inlink->ch_layout.nb_channels;
+            s->buf_index += inlink->ch_layout.nb_channels;
         }
 
         ff_ebur128_loudness_shortterm(s->r128_in, &shortterm);
@@ -486,19 +486,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         s->buf_index =
         s->limiter_buf_index = 0;
 
-        for (n = 0; n < (s->limiter_buf_size / inlink->channels); n++) {
-            for (c = 0; c < inlink->channels; c++) {
+        for (n = 0; n < (s->limiter_buf_size / inlink->ch_layout.nb_channels); n++) {
+            for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
                 limiter_buf[s->limiter_buf_index + c] = buf[s->buf_index + c] * s->delta[s->index] * s->offset;
             }
-            s->limiter_buf_index += inlink->channels;
+            s->limiter_buf_index += inlink->ch_layout.nb_channels;
             if (s->limiter_buf_index >= s->limiter_buf_size)
                 s->limiter_buf_index -= s->limiter_buf_size;
 
-            s->buf_index += inlink->channels;
+            s->buf_index += inlink->ch_layout.nb_channels;
         }
 
         subframe_length = frame_size(inlink->sample_rate, 100);
-        true_peak_limiter(s, dst, subframe_length, inlink->channels);
+        true_peak_limiter(s, dst, subframe_length, inlink->ch_layout.nb_channels);
         ff_ebur128_add_frames_double(s->r128_out, dst, subframe_length);
 
         s->pts +=
@@ -514,29 +514,29 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         gain_next = gaussian_filter(s, s->index + 11 < 30 ? s->index + 11 : s->index + 11 - 30);
 
         for (n = 0; n < in->nb_samples; n++) {
-            for (c = 0; c < inlink->channels; c++) {
+            for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
                 buf[s->prev_buf_index + c] = src[c];
                 limiter_buf[s->limiter_buf_index + c] = buf[s->buf_index + c] * (gain + (((double) n / in->nb_samples) * (gain_next - gain))) * s->offset;
             }
-            src += inlink->channels;
+            src += inlink->ch_layout.nb_channels;
 
-            s->limiter_buf_index += inlink->channels;
+            s->limiter_buf_index += inlink->ch_layout.nb_channels;
             if (s->limiter_buf_index >= s->limiter_buf_size)
                 s->limiter_buf_index -= s->limiter_buf_size;
 
-            s->prev_buf_index += inlink->channels;
+            s->prev_buf_index += inlink->ch_layout.nb_channels;
             if (s->prev_buf_index >= s->buf_size)
                 s->prev_buf_index -= s->buf_size;
 
-            s->buf_index += inlink->channels;
+            s->buf_index += inlink->ch_layout.nb_channels;
             if (s->buf_index >= s->buf_size)
                 s->buf_index -= s->buf_size;
         }
 
-        subframe_length = (frame_size(inlink->sample_rate, 100) - in->nb_samples) * inlink->channels;
+        subframe_length = (frame_size(inlink->sample_rate, 100) - in->nb_samples) * inlink->ch_layout.nb_channels;
         s->limiter_buf_index = s->limiter_buf_index + subframe_length < s->limiter_buf_size ? s->limiter_buf_index + subframe_length : s->limiter_buf_index + subframe_length - s->limiter_buf_size;
 
-        true_peak_limiter(s, dst, in->nb_samples, inlink->channels);
+        true_peak_limiter(s, dst, in->nb_samples, inlink->ch_layout.nb_channels);
         ff_ebur128_add_frames_double(s->r128_out, dst, in->nb_samples);
 
         ff_ebur128_loudness_range(s->r128_in, &lra);
@@ -576,39 +576,39 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         s->limiter_buf_index = 0;
         src_index = 0;
 
-        for (n = 0; n < s->limiter_buf_size / inlink->channels; n++) {
-            for (c = 0; c < inlink->channels; c++) {
+        for (n = 0; n < s->limiter_buf_size / inlink->ch_layout.nb_channels; n++) {
+            for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
                 s->limiter_buf[s->limiter_buf_index + c] = src[src_index + c] * gain * s->offset;
             }
-            src_index += inlink->channels;
+            src_index += inlink->ch_layout.nb_channels;
 
-            s->limiter_buf_index += inlink->channels;
+            s->limiter_buf_index += inlink->ch_layout.nb_channels;
             if (s->limiter_buf_index >= s->limiter_buf_size)
                 s->limiter_buf_index -= s->limiter_buf_size;
         }
 
         subframe_length = frame_size(inlink->sample_rate, 100);
         for (i = 0; i < in->nb_samples / subframe_length; i++) {
-            true_peak_limiter(s, dst, subframe_length, inlink->channels);
+            true_peak_limiter(s, dst, subframe_length, inlink->ch_layout.nb_channels);
 
             for (n = 0; n < subframe_length; n++) {
-                for (c = 0; c < inlink->channels; c++) {
-                    if (src_index < (in->nb_samples * inlink->channels)) {
+                for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
+                    if (src_index < (in->nb_samples * inlink->ch_layout.nb_channels)) {
                         limiter_buf[s->limiter_buf_index + c] = src[src_index + c] * gain * s->offset;
                     } else {
                         limiter_buf[s->limiter_buf_index + c] = 0.;
                     }
                 }
 
-                if (src_index < (in->nb_samples * inlink->channels))
-                    src_index += inlink->channels;
+                if (src_index < (in->nb_samples * inlink->ch_layout.nb_channels))
+                    src_index += inlink->ch_layout.nb_channels;
 
-                s->limiter_buf_index += inlink->channels;
+                s->limiter_buf_index += inlink->ch_layout.nb_channels;
                 if (s->limiter_buf_index >= s->limiter_buf_size)
                     s->limiter_buf_index -= s->limiter_buf_size;
             }
 
-            dst += (subframe_length * inlink->channels);
+            dst += (subframe_length * inlink->ch_layout.nb_channels);
         }
 
         dst = (double *)out->data[0];
@@ -617,11 +617,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     case LINEAR_MODE:
         for (n = 0; n < in->nb_samples; n++) {
-            for (c = 0; c < inlink->channels; c++) {
+            for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
                 dst[c] = src[c] * s->offset;
             }
-            src += inlink->channels;
-            dst += inlink->channels;
+            src += inlink->ch_layout.nb_channels;
+            dst += inlink->ch_layout.nb_channels;
         }
 
         dst = (double *)out->data[0];
@@ -650,7 +650,7 @@ static int request_frame(AVFilterLink *outlink)
         int nb_samples, n, c, offset;
         AVFrame *frame;
 
-        nb_samples  = (s->buf_size / inlink->channels) - s->prev_nb_samples;
+        nb_samples  = (s->buf_size / inlink->ch_layout.nb_channels) - s->prev_nb_samples;
         nb_samples -= (frame_size(inlink->sample_rate, 100) - s->prev_nb_samples);
 
         frame = ff_get_audio_buffer(outlink, nb_samples);
@@ -661,16 +661,16 @@ static int request_frame(AVFilterLink *outlink)
         buf = s->buf;
         src = (double *)frame->data[0];
 
-        offset  = ((s->limiter_buf_size / inlink->channels) - s->prev_nb_samples) * inlink->channels;
-        offset -= (frame_size(inlink->sample_rate, 100) - s->prev_nb_samples) * inlink->channels;
+        offset  = ((s->limiter_buf_size / inlink->ch_layout.nb_channels) - s->prev_nb_samples) * inlink->ch_layout.nb_channels;
+        offset -= (frame_size(inlink->sample_rate, 100) - s->prev_nb_samples) * inlink->ch_layout.nb_channels;
         s->buf_index = s->buf_index - offset < 0 ? s->buf_index - offset + s->buf_size : s->buf_index - offset;
 
         for (n = 0; n < nb_samples; n++) {
-            for (c = 0; c < inlink->channels; c++) {
+            for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
                 src[c] = buf[s->buf_index + c];
             }
-            src += inlink->channels;
-            s->buf_index += inlink->channels;
+            src += inlink->ch_layout.nb_channels;
+            s->buf_index += inlink->ch_layout.nb_channels;
             if (s->buf_index >= s->buf_size)
                 s->buf_index -= s->buf_size;
         }
@@ -720,30 +720,30 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     LoudNormContext *s = ctx->priv;
 
-    s->r128_in = ff_ebur128_init(inlink->channels, inlink->sample_rate, 0, FF_EBUR128_MODE_I | FF_EBUR128_MODE_S | FF_EBUR128_MODE_LRA | FF_EBUR128_MODE_SAMPLE_PEAK);
+    s->r128_in = ff_ebur128_init(inlink->ch_layout.nb_channels, inlink->sample_rate, 0, FF_EBUR128_MODE_I | FF_EBUR128_MODE_S | FF_EBUR128_MODE_LRA | FF_EBUR128_MODE_SAMPLE_PEAK);
     if (!s->r128_in)
         return AVERROR(ENOMEM);
 
-    s->r128_out = ff_ebur128_init(inlink->channels, inlink->sample_rate, 0, FF_EBUR128_MODE_I | FF_EBUR128_MODE_S | FF_EBUR128_MODE_LRA | FF_EBUR128_MODE_SAMPLE_PEAK);
+    s->r128_out = ff_ebur128_init(inlink->ch_layout.nb_channels, inlink->sample_rate, 0, FF_EBUR128_MODE_I | FF_EBUR128_MODE_S | FF_EBUR128_MODE_LRA | FF_EBUR128_MODE_SAMPLE_PEAK);
     if (!s->r128_out)
         return AVERROR(ENOMEM);
 
-    if (inlink->channels == 1 && s->dual_mono) {
+    if (inlink->ch_layout.nb_channels == 1 && s->dual_mono) {
         ff_ebur128_set_channel(s->r128_in,  0, FF_EBUR128_DUAL_MONO);
         ff_ebur128_set_channel(s->r128_out, 0, FF_EBUR128_DUAL_MONO);
     }
 
-    s->buf_size = frame_size(inlink->sample_rate, 3000) * inlink->channels;
+    s->buf_size = frame_size(inlink->sample_rate, 3000) * inlink->ch_layout.nb_channels;
     s->buf = av_malloc_array(s->buf_size, sizeof(*s->buf));
     if (!s->buf)
         return AVERROR(ENOMEM);
 
-    s->limiter_buf_size = frame_size(inlink->sample_rate, 210) * inlink->channels;
+    s->limiter_buf_size = frame_size(inlink->sample_rate, 210) * inlink->ch_layout.nb_channels;
     s->limiter_buf = av_malloc_array(s->buf_size, sizeof(*s->limiter_buf));
     if (!s->limiter_buf)
         return AVERROR(ENOMEM);
 
-    s->prev_smp = av_malloc_array(inlink->channels, sizeof(*s->prev_smp));
+    s->prev_smp = av_malloc_array(inlink->ch_layout.nb_channels, sizeof(*s->prev_smp));
     if (!s->prev_smp)
         return AVERROR(ENOMEM);
 
@@ -758,7 +758,7 @@ static int config_input(AVFilterLink *inlink)
     s->buf_index =
     s->prev_buf_index =
     s->limiter_buf_index = 0;
-    s->channels = inlink->channels;
+    s->channels = inlink->ch_layout.nb_channels;
     s->index = 1;
     s->limiter_state = OUT;
     s->offset = pow(10., s->offset / 20.);
diff --git a/libavfilter/af_lv2.c b/libavfilter/af_lv2.c
index 0f0c797989..4d96b380ff 100644
--- a/libavfilter/af_lv2.c
+++ b/libavfilter/af_lv2.c
@@ -288,8 +288,15 @@ static int config_output(AVFilterLink *outlink)
         outlink->format      = inlink->format;
         outlink->sample_rate = sample_rate = inlink->sample_rate;
         if (s->nb_inputs == s->nb_outputs) {
+            int ret;
+            if ((ret = av_channel_layout_copy(&outlink->ch_layout, &inlink->ch_layout)) < 0)
+                return ret;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             outlink->channel_layout = inlink->channel_layout;
-            outlink->channels = inlink->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+            outlink->ch_layout.nb_channels = inlink->ch_layout.nb_channels;
         }
 
     } else {
@@ -496,7 +503,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if (s->nb_inputs == 2 && s->nb_outputs == 2) {
         layouts = NULL;
-        ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO);
+        ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
         if (ret < 0)
             return ret;
         ret = ff_set_common_channel_layouts(ctx, layouts);
@@ -505,10 +512,10 @@ static int query_formats(AVFilterContext *ctx)
     } else {
         if (s->nb_inputs >= 1) {
             AVFilterLink *inlink = ctx->inputs[0];
-            uint64_t inlayout = FF_COUNT2LAYOUT(s->nb_inputs);
+            AVChannelLayout inlayout = FF_COUNT2LAYOUT(s->nb_inputs);
 
             layouts = NULL;
-            ret = ff_add_channel_layout(&layouts, inlayout);
+            ret = ff_add_channel_layout(&layouts, &inlayout);
             if (ret < 0)
                 return ret;
             ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts);
@@ -523,10 +530,10 @@ static int query_formats(AVFilterContext *ctx)
         }
 
         if (s->nb_outputs >= 1) {
-            uint64_t outlayout = FF_COUNT2LAYOUT(s->nb_outputs);
+            AVChannelLayout outlayout = FF_COUNT2LAYOUT(s->nb_outputs);
 
             layouts = NULL;
-            ret = ff_add_channel_layout(&layouts, outlayout);
+            ret = ff_add_channel_layout(&layouts, &outlayout);
             if (ret < 0)
                 return ret;
             ret = ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts);
diff --git a/libavfilter/af_mcompand.c b/libavfilter/af_mcompand.c
index 90cfda38c9..1267cd9f34 100644
--- a/libavfilter/af_mcompand.c
+++ b/libavfilter/af_mcompand.c
@@ -302,7 +302,7 @@ static int crossover_setup(AVFilterLink *outlink, Crossover *p, double frequency
     square_quadratic(x + 3, p->coefs + 5);
     square_quadratic(x + 6, p->coefs + 10);
 
-    p->previous = av_calloc(outlink->channels, sizeof(*p->previous));
+    p->previous = av_calloc(outlink->ch_layout.nb_channels, sizeof(*p->previous));
     if (!p->previous)
         return AVERROR(ENOMEM);
 
@@ -350,13 +350,13 @@ static int config_output(AVFilterLink *outlink)
             return AVERROR(EINVAL);
         }
 
-        s->bands[i].attack_rate = av_calloc(outlink->channels, sizeof(double));
-        s->bands[i].decay_rate = av_calloc(outlink->channels, sizeof(double));
-        s->bands[i].volume = av_calloc(outlink->channels, sizeof(double));
+        s->bands[i].attack_rate = av_calloc(outlink->ch_layout.nb_channels, sizeof(double));
+        s->bands[i].decay_rate = av_calloc(outlink->ch_layout.nb_channels, sizeof(double));
+        s->bands[i].volume = av_calloc(outlink->ch_layout.nb_channels, sizeof(double));
         if (!s->bands[i].attack_rate || !s->bands[i].decay_rate || !s->bands[i].volume)
             return AVERROR(ENOMEM);
 
-        for (k = 0; k < FFMIN(nb_attacks / 2, outlink->channels); k++) {
+        for (k = 0; k < FFMIN(nb_attacks / 2, outlink->ch_layout.nb_channels); k++) {
             char *tstr3 = av_strtok(p3, ",", &saveptr3);
 
             p3 = NULL;
@@ -377,7 +377,7 @@ static int config_output(AVFilterLink *outlink)
             }
         }
 
-        for (ch = k; ch < outlink->channels; ch++) {
+        for (ch = k; ch < outlink->ch_layout.nb_channels; ch++) {
             s->bands[i].attack_rate[ch] = s->bands[i].attack_rate[k - 1];
             s->bands[i].decay_rate[ch]  = s->bands[i].decay_rate[k - 1];
         }
@@ -440,7 +440,7 @@ static int config_output(AVFilterLink *outlink)
                 sscanf(tstr2, "%lf", &initial_volume);
                 initial_volume = pow(10.0, initial_volume / 20);
 
-                for (k = 0; k < outlink->channels; k++) {
+                for (k = 0; k < outlink->ch_layout.nb_channels; k++) {
                     s->bands[i].volume[k] = initial_volume;
                 }
 
@@ -574,7 +574,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         s->band_samples = in->nb_samples;
     }
 
-    for (ch = 0; ch < outlink->channels; ch++) {
+    for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {
         double *a, *dst = (double *)out->extended_data[ch];
 
         for (band = 0, abuf = in, bbuf = s->band_buf2, cbuf = s->band_buf1; band < s->nb_bands; band++) {
diff --git a/libavfilter/af_pan.c b/libavfilter/af_pan.c
index a8a18960c4..067f646805 100644
--- a/libavfilter/af_pan.c
+++ b/libavfilter/af_pan.c
@@ -42,7 +42,7 @@
 typedef struct PanContext {
     const AVClass *class;
     char *args;
-    int64_t out_channel_layout;
+    AVChannelLayout out_channel_layout;
     double gain[MAX_CHANNELS][MAX_CHANNELS];
     int64_t need_renorm;
     int need_renumber;
@@ -65,23 +65,15 @@ static void skip_spaces(char **arg)
 static int parse_channel_name(char **arg, int *rchannel, int *rnamed)
 {
     char buf[8];
-    int len, i, channel_id = 0;
-    int64_t layout, layout0;
+    int len, channel_id = 0;
 
     skip_spaces(arg);
     /* try to parse a channel name, e.g. "FL" */
     if (sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
-        layout0 = layout = av_get_channel_layout(buf);
-        /* channel_id <- first set bit in layout */
-        for (i = 32; i > 0; i >>= 1) {
-            if (layout >= (int64_t)1 << i) {
-                channel_id += i;
-                layout >>= i;
-            }
-        }
-        /* reject layouts that are not a single channel */
-        if (channel_id >= MAX_CHANNELS || layout0 != (int64_t)1 << channel_id)
-            return AVERROR(EINVAL);
+        channel_id = av_channel_from_string(buf);
+        if (channel_id < 0)
+            return channel_id;
+
         *rchannel = channel_id;
         *rnamed = 1;
         *arg += len;
@@ -137,17 +129,12 @@ static av_cold int init(AVFilterContext *ctx)
             goto fail;
         }
         if (named) {
-            if (!((pan->out_channel_layout >> out_ch_id) & 1)) {
+            if ((out_ch_id = av_channel_layout_index_from_channel(&pan->out_channel_layout, out_ch_id)) < 0) {
                 av_log(ctx, AV_LOG_ERROR,
                        "Channel \"%.8s\" does not exist in the chosen layout\n", arg0);
                 ret = AVERROR(EINVAL);
                 goto fail;
             }
-            /* get the channel number in the output channel layout:
-             * out_channel_layout & ((1 << out_ch_id) - 1) are all the
-             * channels that come before out_ch_id,
-             * so their count is the index of out_ch_id */
-            out_ch_id = av_get_channel_layout_nb_channels(pan->out_channel_layout & (((int64_t)1 << out_ch_id) - 1));
         }
         if (out_ch_id < 0 || out_ch_id >= pan->nb_output_channels) {
             av_log(ctx, AV_LOG_ERROR,
@@ -269,9 +256,7 @@ static int query_formats(AVFilterContext *ctx)
 
     // outlink supports only requested output channel layout
     layouts = NULL;
-    if ((ret = ff_add_channel_layout(&layouts,
-                          pan->out_channel_layout ? pan->out_channel_layout :
-                          FF_COUNT2LAYOUT(pan->nb_output_channels))) < 0)
+    if ((ret = ff_add_channel_layout(&layouts, &pan->out_channel_layout)) < 0)
         return ret;
     return ff_channel_layouts_ref(layouts, &outlink->incfg.channel_layouts);
 }
@@ -281,13 +266,13 @@ static int config_props(AVFilterLink *link)
     AVFilterContext *ctx = link->dst;
     PanContext *pan = ctx->priv;
     char buf[1024], *cur;
-    int i, j, k, r;
+    int i, j, k, r, ret;
     double t;
 
     if (pan->need_renumber) {
         // input channels were given by their name: renumber them
         for (i = j = 0; i < MAX_CHANNELS; i++) {
-            if ((link->channel_layout >> i) & 1) {
+            if (av_channel_layout_index_from_channel(&link->ch_layout, i) >= 0) {
                 for (k = 0; k < pan->nb_output_channels; k++)
                     pan->gain[k][j] = pan->gain[k][i];
                 j++;
@@ -297,7 +282,7 @@ static int config_props(AVFilterLink *link)
 
     // sanity check; can't be done in query_formats since the inlink
     // channel layout is unknown at that time
-    if (link->channels > MAX_CHANNELS ||
+    if (link->ch_layout.nb_channels > MAX_CHANNELS ||
         pan->nb_output_channels > MAX_CHANNELS) {
         av_log(ctx, AV_LOG_ERROR,
                "af_pan supports a maximum of %d channels. "
@@ -306,20 +291,12 @@ static int config_props(AVFilterLink *link)
     }
 
     // init libswresample context
-    pan->swr = swr_alloc_set_opts(pan->swr,
-                                  pan->out_channel_layout, link->format, link->sample_rate,
-                                  link->channel_layout,    link->format, link->sample_rate,
-                                  0, ctx);
-    if (!pan->swr)
+    ret = swr_alloc_set_opts2(&pan->swr,
+                              &pan->out_channel_layout, link->format, link->sample_rate,
+                              &link->ch_layout, link->format, link->sample_rate,
+                              0, ctx);
+    if (ret < 0)
         return AVERROR(ENOMEM);
-    if (!link->channel_layout) {
-        if (av_opt_set_int(pan->swr, "ich", link->channels, 0) < 0)
-            return AVERROR(EINVAL);
-    }
-    if (!pan->out_channel_layout) {
-        if (av_opt_set_int(pan->swr, "och", pan->nb_output_channels, 0) < 0)
-            return AVERROR(EINVAL);
-    }
 
     // gains are pure, init the channel mapping
     if (pan->pure_gains) {
@@ -327,7 +304,7 @@ static int config_props(AVFilterLink *link)
         // get channel map from the pure gains
         for (i = 0; i < pan->nb_output_channels; i++) {
             int ch_id = -1;
-            for (j = 0; j < link->channels; j++) {
+            for (j = 0; j < link->ch_layout.nb_channels; j++) {
                 if (pan->gain[i][j]) {
                     ch_id = j;
                     break;
@@ -336,7 +313,6 @@ static int config_props(AVFilterLink *link)
             pan->channel_map[i] = ch_id;
         }
 
-        av_opt_set_int(pan->swr, "icl", pan->out_channel_layout, 0);
         av_opt_set_int(pan->swr, "uch", pan->nb_output_channels, 0);
         swr_set_channel_mapping(pan->swr, pan->channel_map);
     } else {
@@ -345,7 +321,7 @@ static int config_props(AVFilterLink *link)
             if (!((pan->need_renorm >> i) & 1))
                 continue;
             t = 0;
-            for (j = 0; j < link->channels; j++)
+            for (j = 0; j < link->ch_layout.nb_channels; j++)
                 t += fabs(pan->gain[i][j]);
             if (t > -1E-5 && t < 1E-5) {
                 // t is almost 0 but not exactly, this is probably a mistake
@@ -354,11 +330,9 @@ static int config_props(AVFilterLink *link)
                            "Degenerate coefficients while renormalizing\n");
                 continue;
             }
-            for (j = 0; j < link->channels; j++)
+            for (j = 0; j < link->ch_layout.nb_channels; j++)
                 pan->gain[i][j] /= t;
         }
-        av_opt_set_int(pan->swr, "icl", link->channel_layout, 0);
-        av_opt_set_int(pan->swr, "ocl", pan->out_channel_layout, 0);
         swr_set_matrix(pan->swr, pan->gain[0], pan->gain[1] - pan->gain[0]);
     }
 
@@ -369,7 +343,7 @@ static int config_props(AVFilterLink *link)
     // summary
     for (i = 0; i < pan->nb_output_channels; i++) {
         cur = buf;
-        for (j = 0; j < link->channels; j++) {
+        for (j = 0; j < link->ch_layout.nb_channels; j++) {
             r = snprintf(cur, buf + sizeof(buf) - cur, "%s%.3g i%d",
                          j ? " + " : "", pan->gain[i][j], j);
             cur += FFMIN(buf + sizeof(buf) - cur, r);
@@ -405,8 +379,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
     swr_convert(pan->swr, outsamples->extended_data, n,
                 (void *)insamples->extended_data, n);
     av_frame_copy_props(outsamples, insamples);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     outsamples->channel_layout = outlink->channel_layout;
-    outsamples->channels = outlink->channels;
+    outsamples->channels = outlink->ch_layout.nb_channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if ((ret = av_channel_layout_copy(&outsamples->ch_layout, &outlink->ch_layout)) < 0)
+        return ret;
 
     ret = ff_filter_frame(outlink, outsamples);
     av_frame_free(&insamples);
diff --git a/libavfilter/af_replaygain.c b/libavfilter/af_replaygain.c
index e9bfc5676c..53852ac8bc 100644
--- a/libavfilter/af_replaygain.c
+++ b/libavfilter/af_replaygain.c
@@ -327,7 +327,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_FLT  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_rubberband.c b/libavfilter/af_rubberband.c
index 4a42aa8a1f..34a1605667 100644
--- a/libavfilter/af_rubberband.c
+++ b/libavfilter/af_rubberband.c
@@ -135,7 +135,7 @@ static int config_input(AVFilterLink *inlink)
 
     if (s->rbs)
         rubberband_delete(s->rbs);
-    s->rbs = rubberband_new(inlink->sample_rate, inlink->channels, opts, 1. / s->tempo, s->pitch);
+    s->rbs = rubberband_new(inlink->sample_rate, inlink->ch_layout.nb_channels, opts, 1. / s->tempo, s->pitch);
     if (!s->rbs)
         return AVERROR(ENOMEM);
 
diff --git a/libavfilter/af_sidechaincompress.c b/libavfilter/af_sidechaincompress.c
index c0ce82066b..90d2a2c726 100644
--- a/libavfilter/af_sidechaincompress.c
+++ b/libavfilter/af_sidechaincompress.c
@@ -177,13 +177,13 @@ static void compressor(SidechainCompressContext *s,
         abs_sample = fabs(scsrc[0] * level_sc);
 
         if (s->link == 1) {
-            for (c = 1; c < sclink->channels; c++)
+            for (c = 1; c < sclink->ch_layout.nb_channels; c++)
                 abs_sample = FFMAX(fabs(scsrc[c] * level_sc), abs_sample);
         } else {
-            for (c = 1; c < sclink->channels; c++)
+            for (c = 1; c < sclink->ch_layout.nb_channels; c++)
                 abs_sample += fabs(scsrc[c] * level_sc);
 
-            abs_sample /= sclink->channels;
+            abs_sample /= sclink->ch_layout.nb_channels;
         }
 
         if (s->detection)
@@ -206,12 +206,12 @@ static void compressor(SidechainCompressContext *s,
                                s->compressed_knee_stop,
                                s->detection, s->mode);
 
-        for (c = 0; c < inlink->channels; c++)
+        for (c = 0; c < inlink->ch_layout.nb_channels; c++)
             dst[c] = src[c] * level_in * (gain * makeup * mix + (1. - mix));
 
-        src += inlink->channels;
-        dst += inlink->channels;
-        scsrc += sclink->channels;
+        src += inlink->ch_layout.nb_channels;
+        dst += inlink->ch_layout.nb_channels;
+        scsrc += sclink->ch_layout.nb_channels;
     }
 }
 
@@ -325,8 +325,8 @@ static int config_output(AVFilterLink *outlink)
 
     outlink->time_base   = ctx->inputs[0]->time_base;
 
-    s->fifo[0] = av_audio_fifo_alloc(ctx->inputs[0]->format, ctx->inputs[0]->channels, 1024);
-    s->fifo[1] = av_audio_fifo_alloc(ctx->inputs[1]->format, ctx->inputs[1]->channels, 1024);
+    s->fifo[0] = av_audio_fifo_alloc(ctx->inputs[0]->format, ctx->inputs[0]->ch_layout.nb_channels, 1024);
+    s->fifo[1] = av_audio_fifo_alloc(ctx->inputs[1]->format, ctx->inputs[1]->ch_layout.nb_channels, 1024);
     if (!s->fifo[0] || !s->fifo[1])
         return AVERROR(ENOMEM);
 
diff --git a/libavfilter/af_silencedetect.c b/libavfilter/af_silencedetect.c
index 0ba76469de..6518283d9f 100644
--- a/libavfilter/af_silencedetect.c
+++ b/libavfilter/af_silencedetect.c
@@ -136,12 +136,12 @@ static void silencedetect_##name(SilenceDetectContext *s, AVFrame *insamples,
                                  int nb_samples, int64_t nb_samples_notify,      \
                                  AVRational time_base)                           \
 {                                                                                \
-    const int channels = insamples->channels;                                    \
+    const int channels = insamples->ch_layout.nb_channels;                       \
     const type noise = s->noise;                                                 \
                                                                                  \
     nb_samples /= channels;                                                      \
     for (int i = 0; i < nb_samples; i++) {                                       \
-        for (int ch = 0; ch < insamples->channels; ch++) {                       \
+        for (int ch = 0; ch < insamples->ch_layout.nb_channels; ch++) {          \
             const type *p = (const type *)insamples->extended_data[ch];          \
             update(s, insamples, p[i] < noise && p[i] > -noise,                  \
                    channels * i + ch,                                            \
@@ -166,7 +166,7 @@ static int config_input(AVFilterLink *inlink)
     SilenceDetectContext *s = ctx->priv;
     int c;
 
-    s->channels = inlink->channels;
+    s->channels = inlink->ch_layout.nb_channels;
     s->duration = av_rescale(s->duration, inlink->sample_rate, AV_TIME_BASE);
     s->independent_channels = s->mono ? s->channels : 1;
     s->nb_null_samples = av_calloc(s->independent_channels,
@@ -210,7 +210,7 @@ static int config_input(AVFilterLink *inlink)
 static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
 {
     SilenceDetectContext *s         = inlink->dst->priv;
-    const int nb_channels           = inlink->channels;
+    const int nb_channels           = inlink->ch_layout.nb_channels;
     const int srate                 = inlink->sample_rate;
     const int nb_samples            = insamples->nb_samples     * nb_channels;
     const int64_t nb_samples_notify = s->duration * (s->mono ? 1 : nb_channels);
diff --git a/libavfilter/af_silenceremove.c b/libavfilter/af_silenceremove.c
index a02e1de783..a6db9be9d5 100644
--- a/libavfilter/af_silenceremove.c
+++ b/libavfilter/af_silenceremove.c
@@ -136,10 +136,10 @@ static void copy_double(SilenceRemoveContext *s, AVFrame *out, AVFrame *in,
                         int ch, int out_offset, int in_offset)
 {
     const double *srcp = (const double *)in->data[0];
-    const double src = srcp[in->channels * in_offset + ch];
+    const double src = srcp[in->ch_layout.nb_channels * in_offset + ch];
     double *dstp = (double *)out->data[0];
 
-    dstp[out->channels * out_offset + ch] = src;
+    dstp[out->ch_layout.nb_channels * out_offset + ch] = src;
 }
 
 static void copy_doublep(SilenceRemoveContext *s, AVFrame *out, AVFrame *in,
@@ -156,10 +156,10 @@ static void copy_float(SilenceRemoveContext *s, AVFrame *out, AVFrame *in,
                        int ch, int out_offset, int in_offset)
 {
     const float *srcp = (const float *)in->data[0];
-    const float src = srcp[in->channels * in_offset + ch];
+    const float src = srcp[in->ch_layout.nb_channels * in_offset + ch];
     float *dstp = (float *)out->data[0];
 
-    dstp[out->channels * out_offset + ch] = src;
+    dstp[out->ch_layout.nb_channels * out_offset + ch] = src;
 }
 
 static void copy_floatp(SilenceRemoveContext *s, AVFrame *out, AVFrame *in,
@@ -176,8 +176,8 @@ static double compute_peak_double(SilenceRemoveContext *s, AVFrame *frame, int c
 {
     const double *samples = (const double *)frame->data[0];
     const double *wsamples = (const double *)s->window->data[0];
-    double sample = samples[frame->channels * offset + ch];
-    double wsample = wsamples[frame->channels * s->window_offset + ch];
+    double sample = samples[frame->ch_layout.nb_channels * offset + ch];
+    double wsample = wsamples[frame->ch_layout.nb_channels * s->window_offset + ch];
     double new_sum;
 
     new_sum  = s->sum;
@@ -192,8 +192,8 @@ static void update_peak_double(SilenceRemoveContext *s, AVFrame *frame, int ch,
 {
     const double *samples = (const double *)frame->data[0];
     double *wsamples = (double *)s->window->data[0];
-    double sample = samples[frame->channels * offset + ch];
-    double *wsample = &wsamples[frame->channels * s->window_offset + ch];
+    double sample = samples[frame->ch_layout.nb_channels * offset + ch];
+    double *wsample = &wsamples[frame->ch_layout.nb_channels * s->window_offset + ch];
 
     s->sum -= *wsample;
     s->sum  = fmax(s->sum, 0.);
@@ -205,8 +205,8 @@ static double compute_peak_float(SilenceRemoveContext *s, AVFrame *frame, int ch
 {
     const float *samples = (const float *)frame->data[0];
     const float *wsamples = (const float *)s->window->data[0];
-    float sample = samples[frame->channels * offset + ch];
-    float wsample = wsamples[frame->channels * s->window_offset + ch];
+    float sample = samples[frame->ch_layout.nb_channels * offset + ch];
+    float wsample = wsamples[frame->ch_layout.nb_channels * s->window_offset + ch];
     float new_sum;
 
     new_sum  = s->sum;
@@ -221,8 +221,8 @@ static void update_peak_float(SilenceRemoveContext *s, AVFrame *frame, int ch, i
 {
     const float *samples = (const float *)frame->data[0];
     float *wsamples = (float *)s->window->data[0];
-    float sample = samples[frame->channels * offset + ch];
-    float *wsample = &wsamples[frame->channels * s->window_offset + ch];
+    float sample = samples[frame->ch_layout.nb_channels * offset + ch];
+    float *wsample = &wsamples[frame->ch_layout.nb_channels * s->window_offset + ch];
 
     s->sum -= *wsample;
     s->sum  = fmaxf(s->sum, 0.f);
@@ -234,8 +234,8 @@ static double compute_rms_double(SilenceRemoveContext *s, AVFrame *frame, int ch
 {
     const double *samples = (const double *)frame->data[0];
     const double *wsamples = (const double *)s->window->data[0];
-    double sample = samples[frame->channels * offset + ch];
-    double wsample = wsamples[frame->channels * s->window_offset + ch];
+    double sample = samples[frame->ch_layout.nb_channels * offset + ch];
+    double wsample = wsamples[frame->ch_layout.nb_channels * s->window_offset + ch];
     double new_sum;
 
     new_sum  = s->sum;
@@ -251,8 +251,8 @@ static void update_rms_double(SilenceRemoveContext *s, AVFrame *frame, int ch, i
 {
     const double *samples = (const double *)frame->data[0];
     double *wsamples = (double *)s->window->data[0];
-    double sample = samples[frame->channels * offset + ch];
-    double *wsample = &wsamples[frame->channels * s->window_offset + ch];
+    double sample = samples[frame->ch_layout.nb_channels * offset + ch];
+    double *wsample = &wsamples[frame->ch_layout.nb_channels * s->window_offset + ch];
 
     s->sum -= *wsample;
     s->sum  = fmax(s->sum, 0.);
@@ -264,8 +264,8 @@ static double compute_rms_float(SilenceRemoveContext *s, AVFrame *frame, int ch,
 {
     const float *samples = (const float *)frame->data[0];
     const float *wsamples = (const float *)s->window->data[0];
-    float sample = samples[frame->channels * offset + ch];
-    float wsample = wsamples[frame->channels * s->window_offset + ch];
+    float sample = samples[frame->ch_layout.nb_channels * offset + ch];
+    float wsample = wsamples[frame->ch_layout.nb_channels * s->window_offset + ch];
     float new_sum;
 
     new_sum  = s->sum;
@@ -280,9 +280,9 @@ static double compute_rms_float(SilenceRemoveContext *s, AVFrame *frame, int ch,
 static void update_rms_float(SilenceRemoveContext *s, AVFrame *frame, int ch, int offset)
 {
     const float *samples = (const float *)frame->data[0];
-    float sample = samples[frame->channels * offset + ch];
+    float sample = samples[frame->ch_layout.nb_channels * offset + ch];
     float *wsamples = (float *)s->window->data[0];
-    float *wsample = &wsamples[frame->channels * s->window_offset + ch];
+    float *wsample = &wsamples[frame->ch_layout.nb_channels * s->window_offset + ch];
 
     s->sum -= *wsample;
     s->sum  = fmaxf(s->sum, 0.f);
@@ -423,7 +423,7 @@ static av_cold int init(AVFilterContext *ctx)
 static void clear_window(SilenceRemoveContext *s)
 {
     av_samples_set_silence(s->window->extended_data, 0, s->window_duration,
-                           s->window->channels, s->window->format);
+                           s->window->ch_layout.nb_channels, s->window->format);
 
     s->window_offset = 0;
     s->sum = 0;
@@ -543,7 +543,7 @@ static int config_input(AVFilterLink *inlink)
         return AVERROR_BUG;
     }
 
-    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, 1024);
+    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->ch_layout.nb_channels, 1024);
     if (!s->fifo)
         return AVERROR(ENOMEM);
 
@@ -576,14 +576,14 @@ static void flush(SilenceRemoveContext *s,
         av_samples_copy(silence->extended_data, s->stop_silence_hold->extended_data, 0,
                         s->stop_silence_offset,
                         s->stop_silence_end - s->stop_silence_offset,
-                        outlink->channels, outlink->format);
+                        outlink->ch_layout.nb_channels, outlink->format);
     }
 
     if (s->stop_silence_offset > 0) {
         av_samples_copy(silence->extended_data, s->stop_silence_hold->extended_data,
                         s->stop_silence_end - s->stop_silence_offset,
                         0, s->stop_silence_offset,
-                        outlink->channels, outlink->format);
+                        outlink->ch_layout.nb_channels, outlink->format);
     }
 
     s->stop_silence_offset = 0;
@@ -617,18 +617,18 @@ silence_trim:
         for (i = 0; i < nbs; i++) {
             if (s->start_mode == T_ANY) {
                 threshold = 0;
-                for (j = 0; j < outlink->channels; j++) {
+                for (j = 0; j < outlink->ch_layout.nb_channels; j++) {
                     threshold |= s->compute(s, in, j, nb_samples_read) > s->start_threshold;
                 }
             } else {
                 threshold = 1;
-                for (j = 0; j < outlink->channels; j++) {
+                for (j = 0; j < outlink->ch_layout.nb_channels; j++) {
                     threshold &= s->compute(s, in, j, nb_samples_read) > s->start_threshold;
                 }
             }
 
             if (threshold) {
-                for (j = 0; j < outlink->channels; j++) {
+                for (j = 0; j < outlink->ch_layout.nb_channels; j++) {
                     s->update(s, in, j, nb_samples_read);
                     s->copy(s, s->start_holdoff, in, j, s->start_holdoff_end, nb_samples_read);
                 }
@@ -656,7 +656,7 @@ silence_trim:
                 s->start_holdoff_end = 0;
                 s->one_period++;
 
-                for (j = 0; j < outlink->channels; j++) {
+                for (j = 0; j < outlink->ch_layout.nb_channels; j++) {
                     s->update(s, in, j, nb_samples_read);
                     if (s->start_silence)
                         s->copy(s, s->start_silence_hold, in, j, s->start_silence_offset, nb_samples_read);
@@ -694,21 +694,21 @@ silence_trim_flush:
                 av_samples_copy(out->extended_data, s->start_silence_hold->extended_data, 0,
                                 s->start_silence_offset,
                                 s->start_silence_end - s->start_silence_offset,
-                                outlink->channels, outlink->format);
+                                outlink->ch_layout.nb_channels, outlink->format);
             }
 
             if (s->start_silence_offset > 0) {
                 av_samples_copy(out->extended_data, s->start_silence_hold->extended_data,
                                 s->start_silence_end - s->start_silence_offset,
                                 0, s->start_silence_offset,
-                                outlink->channels, outlink->format);
+                                outlink->ch_layout.nb_channels, outlink->format);
             }
         }
 
         av_samples_copy(out->extended_data, s->start_holdoff->extended_data,
                         s->start_silence_end,
                         s->start_holdoff_offset, nbs,
-                        outlink->channels, outlink->format);
+                        outlink->ch_layout.nb_channels, outlink->format);
 
         s->start_holdoff_offset += nbs;
 
@@ -741,12 +741,12 @@ silence_copy:
             for (i = 0; i < nbs; i++) {
                 if (s->stop_mode == T_ANY) {
                     threshold = 0;
-                    for (j = 0; j < outlink->channels; j++) {
+                    for (j = 0; j < outlink->ch_layout.nb_channels; j++) {
                         threshold |= s->compute(s, in, j, nb_samples_read) > s->stop_threshold;
                     }
                 } else {
                     threshold = 1;
-                    for (j = 0; j < outlink->channels; j++) {
+                    for (j = 0; j < outlink->ch_layout.nb_channels; j++) {
                         threshold &= s->compute(s, in, j, nb_samples_read) > s->stop_threshold;
                     }
                 }
@@ -757,7 +757,7 @@ silence_copy:
                     s->one_period++;
                     goto silence_copy_flush;
                 } else if (threshold) {
-                    for (j = 0; j < outlink->channels; j++) {
+                    for (j = 0; j < outlink->ch_layout.nb_channels; j++) {
                         s->update(s, in, j, nb_samples_read);
                         s->copy(s, out, in, j, nb_samples_written, nb_samples_read);
                     }
@@ -769,7 +769,7 @@ silence_copy:
                     nb_samples_written++;
                     s->one_period++;
                 } else if (!threshold) {
-                    for (j = 0; j < outlink->channels; j++) {
+                    for (j = 0; j < outlink->ch_layout.nb_channels; j++) {
                         s->update(s, in, j, nb_samples_read);
                         if (s->stop_silence)
                             s->copy(s, s->stop_silence_hold, in, j, s->stop_silence_offset, nb_samples_read);
@@ -827,7 +827,7 @@ silence_copy:
             av_samples_copy(out->extended_data, in->extended_data,
                             nb_samples_written,
                             nb_samples_read, nbs,
-                            outlink->channels, outlink->format);
+                            outlink->ch_layout.nb_channels, outlink->format);
 
             av_audio_fifo_write(s->fifo, (void **)out->extended_data, out->nb_samples);
             av_frame_free(&out);
@@ -848,7 +848,7 @@ silence_copy_flush:
 
         av_samples_copy(out->extended_data, s->stop_holdoff->extended_data, 0,
                         s->stop_holdoff_offset, nbs,
-                        outlink->channels, outlink->format);
+                        outlink->ch_layout.nb_channels, outlink->format);
 
         s->stop_holdoff_offset += nbs;
 
@@ -909,7 +909,7 @@ static int request_frame(AVFilterLink *outlink)
 
             av_samples_copy(frame->extended_data, s->stop_holdoff->extended_data, 0,
                             s->stop_holdoff_offset, nbs,
-                            outlink->channels, outlink->format);
+                            outlink->ch_layout.nb_channels, outlink->format);
 
             frame->pts = s->next_pts;
             s->next_pts += av_rescale_q(frame->nb_samples,
diff --git a/libavfilter/af_sofalizer.c b/libavfilter/af_sofalizer.c
index 20b717bdf8..246ddeffb9 100644
--- a/libavfilter/af_sofalizer.c
+++ b/libavfilter/af_sofalizer.c
@@ -187,25 +187,15 @@ static int preload_sofa(AVFilterContext *ctx, char *filename, int *samplingrate)
 
 static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel)
 {
-    int len, i, channel_id = 0;
-    int64_t layout, layout0;
+    int len, channel_id = 0;
     char buf[8] = {0};
 
     /* try to parse a channel name, e.g. "FL" */
     if (av_sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
-        layout0 = layout = av_get_channel_layout(buf);
-        /* channel_id <- first set bit in layout */
-        for (i = 32; i > 0; i >>= 1) {
-            if (layout >= 1LL << i) {
-                channel_id += i;
-                layout >>= i;
-            }
-        }
-        /* reject layouts that are not a single channel */
-        if (channel_id >= 64 || layout0 != 1LL << channel_id) {
-            av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf);
-            return AVERROR(EINVAL);
-        }
+        channel_id = av_channel_from_string(buf);
+        if (channel_id < 0)
+            return channel_id;
+
         *rchannel = channel_id;
         *arg += len;
         return 0;
@@ -221,7 +211,7 @@ static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel)
     return AVERROR(EINVAL);
 }
 
-static void parse_speaker_pos(AVFilterContext *ctx, int64_t in_channel_layout)
+static void parse_speaker_pos(AVFilterContext *ctx)
 {
     SOFAlizerContext *s = ctx->priv;
     char *arg, *tokenizer, *p, *args = av_strdup(s->speakers_pos);
@@ -256,10 +246,10 @@ static int get_speaker_pos(AVFilterContext *ctx,
                            float *speaker_azim, float *speaker_elev)
 {
     struct SOFAlizerContext *s = ctx->priv;
-    uint64_t channels_layout = ctx->inputs[0]->channel_layout;
+    AVChannelLayout *channel_layout = &ctx->inputs[0]->ch_layout;
     float azim[64] = { 0 };
     float elev[64] = { 0 };
-    int m, ch, n_conv = ctx->inputs[0]->channels; /* get no. input channels */
+    int m, ch, n_conv = ctx->inputs[0]->ch_layout.nb_channels; /* get no. input channels */
 
     if (n_conv < 0 || n_conv > 64)
         return AVERROR(EINVAL);
@@ -267,45 +257,45 @@ static int get_speaker_pos(AVFilterContext *ctx,
     s->lfe_channel = -1;
 
     if (s->speakers_pos)
-        parse_speaker_pos(ctx, channels_layout);
+        parse_speaker_pos(ctx);
 
     /* set speaker positions according to input channel configuration: */
     for (m = 0, ch = 0; ch < n_conv && m < 64; m++) {
-        uint64_t mask = channels_layout & (1ULL << m);
-
-        switch (mask) {
-        case AV_CH_FRONT_LEFT:            azim[ch] =  30;      break;
-        case AV_CH_FRONT_RIGHT:           azim[ch] = 330;      break;
-        case AV_CH_FRONT_CENTER:          azim[ch] =   0;      break;
-        case AV_CH_LOW_FREQUENCY:
-        case AV_CH_LOW_FREQUENCY_2:       s->lfe_channel = ch; break;
-        case AV_CH_BACK_LEFT:             azim[ch] = 150;      break;
-        case AV_CH_BACK_RIGHT:            azim[ch] = 210;      break;
-        case AV_CH_BACK_CENTER:           azim[ch] = 180;      break;
-        case AV_CH_SIDE_LEFT:             azim[ch] =  90;      break;
-        case AV_CH_SIDE_RIGHT:            azim[ch] = 270;      break;
-        case AV_CH_FRONT_LEFT_OF_CENTER:  azim[ch] =  15;      break;
-        case AV_CH_FRONT_RIGHT_OF_CENTER: azim[ch] = 345;      break;
-        case AV_CH_TOP_CENTER:            azim[ch] =   0;
+        int chan = av_channel_layout_channel_from_index(channel_layout, m);
+
+        switch (chan) {
+        case AV_CHAN_FRONT_LEFT:          azim[ch] =  30;      break;
+        case AV_CHAN_FRONT_RIGHT:         azim[ch] = 330;      break;
+        case AV_CHAN_FRONT_CENTER:        azim[ch] =   0;      break;
+        case AV_CHAN_LOW_FREQUENCY:
+        case AV_CHAN_LOW_FREQUENCY_2:     s->lfe_channel = ch; break;
+        case AV_CHAN_BACK_LEFT:           azim[ch] = 150;      break;
+        case AV_CHAN_BACK_RIGHT:          azim[ch] = 210;      break;
+        case AV_CHAN_BACK_CENTER:         azim[ch] = 180;      break;
+        case AV_CHAN_SIDE_LEFT:           azim[ch] =  90;      break;
+        case AV_CHAN_SIDE_RIGHT:          azim[ch] = 270;      break;
+        case AV_CHAN_FRONT_LEFT_OF_CENTER:  azim[ch] =  15;    break;
+        case AV_CHAN_FRONT_RIGHT_OF_CENTER: azim[ch] = 345;    break;
+        case AV_CHAN_TOP_CENTER:          azim[ch] =   0;
                                           elev[ch] =  90;      break;
-        case AV_CH_TOP_FRONT_LEFT:        azim[ch] =  30;
+        case AV_CHAN_TOP_FRONT_LEFT:      azim[ch] =  30;
                                           elev[ch] =  45;      break;
-        case AV_CH_TOP_FRONT_CENTER:      azim[ch] =   0;
+        case AV_CHAN_TOP_FRONT_CENTER:    azim[ch] =   0;
                                           elev[ch] =  45;      break;
-        case AV_CH_TOP_FRONT_RIGHT:       azim[ch] = 330;
+        case AV_CHAN_TOP_FRONT_RIGHT:     azim[ch] = 330;
                                           elev[ch] =  45;      break;
-        case AV_CH_TOP_BACK_LEFT:         azim[ch] = 150;
+        case AV_CHAN_TOP_BACK_LEFT:       azim[ch] = 150;
                                           elev[ch] =  45;      break;
-        case AV_CH_TOP_BACK_RIGHT:        azim[ch] = 210;
+        case AV_CHAN_TOP_BACK_RIGHT:      azim[ch] = 210;
                                           elev[ch] =  45;      break;
-        case AV_CH_TOP_BACK_CENTER:       azim[ch] = 180;
+        case AV_CHAN_TOP_BACK_CENTER:     azim[ch] = 180;
                                           elev[ch] =  45;      break;
-        case AV_CH_WIDE_LEFT:             azim[ch] =  90;      break;
-        case AV_CH_WIDE_RIGHT:            azim[ch] = 270;      break;
-        case AV_CH_SURROUND_DIRECT_LEFT:  azim[ch] =  90;      break;
-        case AV_CH_SURROUND_DIRECT_RIGHT: azim[ch] = 270;      break;
-        case AV_CH_STEREO_LEFT:           azim[ch] =  90;      break;
-        case AV_CH_STEREO_RIGHT:          azim[ch] = 270;      break;
+        case AV_CHAN_WIDE_LEFT:           azim[ch] =  90;      break;
+        case AV_CHAN_WIDE_RIGHT:          azim[ch] = 270;      break;
+        case AV_CHAN_SURROUND_DIRECT_LEFT:  azim[ch] =  90;    break;
+        case AV_CHAN_SURROUND_DIRECT_RIGHT: azim[ch] = 270;    break;
+        case AV_CHAN_STEREO_LEFT:         azim[ch] =  90;      break;
+        case AV_CHAN_STEREO_RIGHT:        azim[ch] = 270;      break;
         case 0:                                                break;
         default:
             return AVERROR(EINVAL);
@@ -316,7 +306,7 @@ static int get_speaker_pos(AVFilterContext *ctx,
             elev[ch] = s->vspkrpos[m].elev;
         }
 
-        if (mask)
+        if (chan)
             ch++;
     }
 
@@ -668,7 +658,7 @@ static int query_formats(AVFilterContext *ctx)
         return ret;
 
     layouts = NULL;
-    ret = ff_add_channel_layout(&layouts, AV_CH_LAYOUT_STEREO);
+    ret = ff_add_channel_layout(&layouts, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
     if (ret)
         return ret;
 
@@ -733,7 +723,7 @@ static int load_data(AVFilterContext *ctx, int azim, int elev, float radius, int
     int n_fft;
     float delay_l; /* broadband delay for each IR */
     float delay_r;
-    int nb_input_channels = ctx->inputs[0]->channels; /* no. input channels */
+    int nb_input_channels = ctx->inputs[0]->ch_layout.nb_channels; /* no. input channels */
     float gain_lin = expf((s->gain - 3 * nb_input_channels) / 20 * M_LN10); /* gain - 3dB/channel */
     AVComplexFloat *data_hrtf_l = NULL;
     AVComplexFloat *data_hrtf_r = NULL;
@@ -1016,16 +1006,16 @@ static int config_input(AVFilterLink *inlink)
         s->nb_samples = s->framesize;
 
     /* gain -3 dB per channel */
-    s->gain_lfe = expf((s->gain - 3 * inlink->channels + s->lfe_gain) / 20 * M_LN10);
+    s->gain_lfe = expf((s->gain - 3 * inlink->ch_layout.nb_channels + s->lfe_gain) / 20 * M_LN10);
 
-    s->n_conv = inlink->channels;
+    s->n_conv = inlink->ch_layout.nb_channels;
 
     /* load IRs to data_ir[0] and data_ir[1] for required directions */
     if ((ret = load_data(ctx, s->rotation, s->elevation, s->radius, inlink->sample_rate)) < 0)
         return ret;
 
     av_log(ctx, AV_LOG_DEBUG, "Samplerate: %d Channels to convolute: %d, Length of ringbuffer: %d x %d\n",
-        inlink->sample_rate, s->n_conv, inlink->channels, s->buffer_length);
+        inlink->sample_rate, s->n_conv, inlink->ch_layout.nb_channels, s->buffer_length);
 
     return 0;
 }
diff --git a/libavfilter/af_speechnorm.c b/libavfilter/af_speechnorm.c
index 212a926f36..a40abc025d 100644
--- a/libavfilter/af_speechnorm.c
+++ b/libavfilter/af_speechnorm.c
@@ -68,7 +68,7 @@ typedef struct SpeechNormalizerContext {
     double threshold_value;
     double raise_amount;
     double fall_amount;
-    uint64_t channels;
+    AVChannelLayout ch_layout;
     int invert;
     int link;
 
@@ -103,8 +103,8 @@ static const AVOption speechnorm_options[] = {
     { "r",     "set the expansion raising amount", OFFSET(raise_amount), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0.0, 1.0, FLAGS },
     { "fall", "set the compression raising amount", OFFSET(fall_amount), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0.0, 1.0, FLAGS },
     { "f",    "set the compression raising amount", OFFSET(fall_amount), AV_OPT_TYPE_DOUBLE, {.dbl=0.001}, 0.0, 1.0, FLAGS },
-    { "channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS },
-    { "h",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS },
+    { "channels", "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS },
+    { "h",        "set channels to filter", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="0xFFFFFFFF"}, INT64_MIN, INT64_MAX, FLAGS },
     { "invert", "set inverted filtering", OFFSET(invert), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
     { "i",      "set inverted filtering", OFFSET(invert), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
     { "link", "set linked channels filtering", OFFSET(link), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
@@ -142,7 +142,7 @@ static int available_samples(AVFilterContext *ctx)
     int min_pi_nb_samples;
 
     min_pi_nb_samples = get_pi_samples(s->cc[0].pi, s->cc[0].pi_start, s->cc[0].pi_end, s->cc[0].pi_size);
-    for (int ch = 1; ch < inlink->channels && min_pi_nb_samples > 0; ch++) {
+    for (int ch = 1; ch < inlink->ch_layout.nb_channels && min_pi_nb_samples > 0; ch++) {
         ChannelContext *cc = &s->cc[ch];
 
         min_pi_nb_samples = FFMIN(min_pi_nb_samples, get_pi_samples(cc->pi, cc->pi_start, cc->pi_end, cc->pi_size));
@@ -283,11 +283,12 @@ static void filter_channels_## name (AVFilterContext *ctx,
     SpeechNormalizerContext *s = ctx->priv;                                     \
     AVFilterLink *inlink = ctx->inputs[0];                                      \
                                                                                 \
-    for (int ch = 0; ch < inlink->channels; ch++) {                             \
+    for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {                             \
         ChannelContext *cc = &s->cc[ch];                                        \
         const ptype *src = (const ptype *)in->extended_data[ch];                \
         ptype *dst = (ptype *)out->extended_data[ch];                           \
-        const int bypass = !(av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels); \
+        const int bypass = !(av_channel_layout_channel_from_index(&inlink->ch_layout, ch) >= 0 && \
+                             av_channel_layout_channel_from_index(&s->ch_layout, ch) >= 0); \
         int n = 0;                                                              \
                                                                                 \
         while (n < nb_samples) {                                                \
@@ -333,10 +334,11 @@ static void filter_link_channels_## name (AVFilterContext *ctx,
         int max_size = 1;                                                       \
         ptype gain = s->max_expansion;                                          \
                                                                                 \
-        for (int ch = 0; ch < inlink->channels; ch++) {                         \
+        for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {                         \
             ChannelContext *cc = &s->cc[ch];                                    \
                                                                                 \
-            cc->bypass = !(av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels); \
+            cc->bypass = !(av_channel_layout_channel_from_index(&inlink->ch_layout, ch) >= 0 && \
+                             av_channel_layout_channel_from_index(&s->ch_layout, ch) >= 0); \
                                                                                 \
             next_pi(ctx, cc, cc->bypass);                                       \
             min_size = FFMIN(min_size, cc->pi_size);                            \
@@ -344,7 +346,7 @@ static void filter_link_channels_## name (AVFilterContext *ctx,
         }                                                                       \
                                                                                 \
         av_assert0(min_size > 0);                                               \
-        for (int ch = 0; ch < inlink->channels; ch++) {                         \
+        for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {                         \
             ChannelContext *cc = &s->cc[ch];                                    \
                                                                                 \
             if (cc->bypass)                                                     \
@@ -352,7 +354,7 @@ static void filter_link_channels_## name (AVFilterContext *ctx,
             gain = FFMIN(gain, min_gain(ctx, cc, max_size));                    \
         }                                                                       \
                                                                                 \
-        for (int ch = 0; ch < inlink->channels; ch++) {                         \
+        for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {                         \
             ChannelContext *cc = &s->cc[ch];                                    \
             const ptype *src = (const ptype *)in->extended_data[ch];            \
             ptype *dst = (ptype *)out->extended_data[ch];                       \
@@ -428,7 +430,7 @@ static int filter_frame(AVFilterContext *ctx)
 
         ff_bufqueue_add(ctx, &s->queue, in);
 
-        for (int ch = 0; ch < inlink->channels; ch++) {
+        for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
             ChannelContext *cc = &s->cc[ch];
 
             s->analyze_channel(ctx, cc, in->extended_data[ch], in->nb_samples);
@@ -486,11 +488,11 @@ static int config_input(AVFilterLink *inlink)
     s->max_period = inlink->sample_rate / 10;
 
     s->prev_gain = 1.;
-    s->cc = av_calloc(inlink->channels, sizeof(*s->cc));
+    s->cc = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->cc));
     if (!s->cc)
         return AVERROR(ENOMEM);
 
-    for (int ch = 0; ch < inlink->channels; ch++) {
+    for (int ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         ChannelContext *cc = &s->cc[ch];
 
         cc->state = -1;
diff --git a/libavfilter/af_stereotools.c b/libavfilter/af_stereotools.c
index 27ec4a2e4a..eedc7c68bd 100644
--- a/libavfilter/af_stereotools.c
+++ b/libavfilter/af_stereotools.c
@@ -107,7 +107,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_DBL  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_stereowiden.c b/libavfilter/af_stereowiden.c
index 7cce1a8f28..a91ea03957 100644
--- a/libavfilter/af_stereowiden.c
+++ b/libavfilter/af_stereowiden.c
@@ -60,7 +60,7 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_FLT  )) < 0 ||
         (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
-        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
+        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx     , layout             )) < 0)
         return ret;
 
diff --git a/libavfilter/af_superequalizer.c b/libavfilter/af_superequalizer.c
index aa73e92039..6df8d36d0f 100644
--- a/libavfilter/af_superequalizer.c
+++ b/libavfilter/af_superequalizer.c
@@ -199,7 +199,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         return AVERROR(ENOMEM);
     }
 
-    for (ch = 0; ch < in->channels; ch++) {
+    for (ch = 0; ch < in->ch_layout.nb_channels; ch++) {
         ptr = (float *)out->extended_data[ch];
         dst = (float *)s->out->extended_data[ch];
         src = (float *)in->extended_data[ch];
diff --git a/libavfilter/af_surround.c b/libavfilter/af_surround.c
index ccd85148e9..71d713e4ed 100644
--- a/libavfilter/af_surround.c
+++ b/libavfilter/af_surround.c
@@ -92,8 +92,8 @@ typedef struct AudioSurroundContext {
     float lowcut;
     float highcut;
 
-    uint64_t out_channel_layout;
-    uint64_t in_channel_layout;
+    AVChannelLayout out_channel_layout;
+    AVChannelLayout in_channel_layout;
     int nb_in_channels;
     int nb_out_channels;
 
@@ -171,7 +171,7 @@ static int query_formats(AVFilterContext *ctx)
         return ret;
 
     layouts = NULL;
-    ret = ff_add_channel_layout(&layouts, s->out_channel_layout);
+    ret = ff_add_channel_layout(&layouts, &s->out_channel_layout);
     if (ret)
         return ret;
 
@@ -180,7 +180,7 @@ static int query_formats(AVFilterContext *ctx)
         return ret;
 
     layouts = NULL;
-    ret = ff_add_channel_layout(&layouts, s->in_channel_layout);
+    ret = ff_add_channel_layout(&layouts, &s->in_channel_layout);
     if (ret)
         return ret;
 
@@ -197,12 +197,12 @@ static int config_input(AVFilterLink *inlink)
     AudioSurroundContext *s = ctx->priv;
     int ch;
 
-    s->rdft = av_calloc(inlink->channels, sizeof(*s->rdft));
+    s->rdft = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->rdft));
     if (!s->rdft)
         return AVERROR(ENOMEM);
-    s->nb_in_channels = inlink->channels;
+    s->nb_in_channels = inlink->ch_layout.nb_channels;
 
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         s->rdft[ch]  = av_rdft_init(ff_log2(s->buf_size), DFT_R2C);
         if (!s->rdft[ch])
             return AVERROR(ENOMEM);
@@ -212,31 +212,31 @@ static int config_input(AVFilterLink *inlink)
         return AVERROR(ENOMEM);
     for (ch = 0;  ch < s->nb_in_channels; ch++)
         s->input_levels[ch] = s->level_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_CENTER);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_CENTER);
     if (ch >= 0)
         s->input_levels[ch] *= s->fc_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_LEFT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_LEFT);
     if (ch >= 0)
         s->input_levels[ch] *= s->fl_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_RIGHT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_RIGHT);
     if (ch >= 0)
         s->input_levels[ch] *= s->fr_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_LEFT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_LEFT);
     if (ch >= 0)
         s->input_levels[ch] *= s->sl_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_RIGHT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_RIGHT);
     if (ch >= 0)
         s->input_levels[ch] *= s->sr_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_LEFT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_LEFT);
     if (ch >= 0)
         s->input_levels[ch] *= s->bl_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_RIGHT);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_RIGHT);
     if (ch >= 0)
         s->input_levels[ch] *= s->br_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_CENTER);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_CENTER);
     if (ch >= 0)
         s->input_levels[ch] *= s->bc_in;
-    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_LOW_FREQUENCY);
+    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_LOW_FREQUENCY);
     if (ch >= 0)
         s->input_levels[ch] *= s->lfe_in;
 
@@ -244,7 +244,7 @@ static int config_input(AVFilterLink *inlink)
     if (!s->input)
         return AVERROR(ENOMEM);
 
-    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->buf_size);
+    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->ch_layout.nb_channels, s->buf_size);
     if (!s->fifo)
         return AVERROR(ENOMEM);
 
@@ -260,12 +260,12 @@ static int config_output(AVFilterLink *outlink)
     AudioSurroundContext *s = ctx->priv;
     int ch;
 
-    s->irdft = av_calloc(outlink->channels, sizeof(*s->irdft));
+    s->irdft = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->irdft));
     if (!s->irdft)
         return AVERROR(ENOMEM);
-    s->nb_out_channels = outlink->channels;
+    s->nb_out_channels = outlink->ch_layout.nb_channels;
 
-    for (ch = 0; ch < outlink->channels; ch++) {
+    for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {
         s->irdft[ch] = av_rdft_init(ff_log2(s->buf_size), IDFT_C2R);
         if (!s->irdft[ch])
             return AVERROR(ENOMEM);
@@ -275,31 +275,31 @@ static int config_output(AVFilterLink *outlink)
         return AVERROR(ENOMEM);
     for (ch = 0;  ch < s->nb_out_channels; ch++)
         s->output_levels[ch] = s->level_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_CENTER);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_CENTER);
     if (ch >= 0)
         s->output_levels[ch] *= s->fc_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_LEFT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_LEFT);
     if (ch >= 0)
         s->output_levels[ch] *= s->fl_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_RIGHT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_RIGHT);
     if (ch >= 0)
         s->output_levels[ch] *= s->fr_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_SIDE_LEFT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_SIDE_LEFT);
     if (ch >= 0)
         s->output_levels[ch] *= s->sl_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_SIDE_RIGHT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_SIDE_RIGHT);
     if (ch >= 0)
         s->output_levels[ch] *= s->sr_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_LEFT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_LEFT);
     if (ch >= 0)
         s->output_levels[ch] *= s->bl_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_RIGHT);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_RIGHT);
     if (ch >= 0)
         s->output_levels[ch] *= s->br_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_CENTER);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_CENTER);
     if (ch >= 0)
         s->output_levels[ch] *= s->bc_out;
-    ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_LOW_FREQUENCY);
+    ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_LOW_FREQUENCY);
     if (ch >= 0)
         s->output_levels[ch] *= s->lfe_out;
 
@@ -1373,15 +1373,16 @@ static av_cold int init(AVFilterContext *ctx)
 {
     AudioSurroundContext *s = ctx->priv;
     float overlap;
-    int i;
+    int64_t in_channel_layout, out_channel_layout;
+    int i, ret;
 
-    if (!(s->out_channel_layout = av_get_channel_layout(s->out_channel_layout_str))) {
+    if ((ret = av_channel_layout_from_string(&s->out_channel_layout, s->out_channel_layout_str)) < 0) {
         av_log(ctx, AV_LOG_ERROR, "Error parsing output channel layout '%s'.\n",
                s->out_channel_layout_str);
-        return AVERROR(EINVAL);
+        return ret;
     }
 
-    if (!(s->in_channel_layout = av_get_channel_layout(s->in_channel_layout_str))) {
+    if ((ret = av_channel_layout_from_string(&s->in_channel_layout, s->in_channel_layout_str)) < 0) {
         av_log(ctx, AV_LOG_ERROR, "Error parsing input channel layout '%s'.\n",
                s->in_channel_layout_str);
         return AVERROR(EINVAL);
@@ -1393,10 +1394,15 @@ static av_cold int init(AVFilterContext *ctx)
         return AVERROR(EINVAL);
     }
 
-    switch (s->in_channel_layout) {
+    in_channel_layout  = s->in_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                         s->in_channel_layout.u.mask : 0;
+    out_channel_layout = s->out_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                         s->out_channel_layout.u.mask : 0;
+
+    switch (in_channel_layout) {
     case AV_CH_LAYOUT_STEREO:
         s->filter = filter_stereo;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_MONO:
             s->upmix_stereo = upmix_1_0;
             break;
@@ -1442,7 +1448,7 @@ static av_cold int init(AVFilterContext *ctx)
         break;
     case AV_CH_LAYOUT_2POINT1:
         s->filter = filter_2_1;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_5POINT1_BACK:
             s->upmix_2_1 = upmix_5_1_back_2_1;
             break;
@@ -1452,7 +1458,7 @@ static av_cold int init(AVFilterContext *ctx)
         break;
     case AV_CH_LAYOUT_SURROUND:
         s->filter = filter_surround;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_3POINT1:
             s->upmix_3_0 = upmix_3_1_surround;
             break;
@@ -1465,7 +1471,7 @@ static av_cold int init(AVFilterContext *ctx)
         break;
     case AV_CH_LAYOUT_5POINT0:
         s->filter = filter_5_0_side;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_7POINT1:
             s->upmix_5_0 = upmix_7_1_5_0_side;
             break;
@@ -1475,7 +1481,7 @@ static av_cold int init(AVFilterContext *ctx)
         break;
     case AV_CH_LAYOUT_5POINT1:
         s->filter = filter_5_1_side;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_7POINT1:
             s->upmix_5_1 = upmix_7_1_5_1;
             break;
@@ -1485,7 +1491,7 @@ static av_cold int init(AVFilterContext *ctx)
         break;
     case AV_CH_LAYOUT_5POINT1_BACK:
         s->filter = filter_5_1_back;
-        switch (s->out_channel_layout) {
+        switch (out_channel_layout) {
         case AV_CH_LAYOUT_7POINT1:
             s->upmix_5_1 = upmix_7_1_5_1;
             break;
@@ -1586,7 +1592,7 @@ static int filter_frame(AVFilterLink *inlink)
     if (ret < 0)
         return ret;
 
-    ff_filter_execute(ctx, fft_channel, NULL, NULL, inlink->channels);
+    ff_filter_execute(ctx, fft_channel, NULL, NULL, inlink->ch_layout.nb_channels);
 
     s->filter(ctx);
 
@@ -1594,7 +1600,7 @@ static int filter_frame(AVFilterLink *inlink)
     if (!out)
         return AVERROR(ENOMEM);
 
-    ff_filter_execute(ctx, ifft_channel, out, NULL, outlink->channels);
+    ff_filter_execute(ctx, ifft_channel, out, NULL, outlink->ch_layout.nb_channels);
 
     out->pts = s->pts;
     if (s->pts != AV_NOPTS_VALUE)
diff --git a/libavfilter/af_tremolo.c b/libavfilter/af_tremolo.c
index b34a7b79f7..400549a58c 100644
--- a/libavfilter/af_tremolo.c
+++ b/libavfilter/af_tremolo.c
@@ -49,7 +49,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     AVFilterLink *outlink = ctx->outputs[0];
     TremoloContext *s = ctx->priv;
     const double *src = (const double *)in->data[0];
-    const int channels = inlink->channels;
+    const int channels = inlink->ch_layout.nb_channels;
     const int nb_samples = in->nb_samples;
     AVFrame *out;
     double *dst;
diff --git a/libavfilter/af_vibrato.c b/libavfilter/af_vibrato.c
index 2cf1364273..900f63e397 100644
--- a/libavfilter/af_vibrato.c
+++ b/libavfilter/af_vibrato.c
@@ -80,7 +80,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         if (s->wave_table_index >= s->wave_table_size)
             s->wave_table_index -= s->wave_table_size;
 
-        for (c = 0; c < inlink->channels; c++) {
+        for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
             int samp1_index, samp2_index;
             double *buf;
             double this_samp;
@@ -128,10 +128,10 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     VibratoContext *s = ctx->priv;
 
-    s->buf = av_calloc(inlink->channels, sizeof(*s->buf));
+    s->buf = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->buf));
     if (!s->buf)
         return AVERROR(ENOMEM);
-    s->channels = inlink->channels;
+    s->channels = inlink->ch_layout.nb_channels;
     s->buf_size = lrint(inlink->sample_rate * 0.005 + 0.5);
     for (c = 0; c < s->channels; c++) {
         s->buf[c] = av_malloc_array(s->buf_size, sizeof(*s->buf[c]));
diff --git a/libavfilter/af_volume.c b/libavfilter/af_volume.c
index 76ccddc316..4c9b96f17e 100644
--- a/libavfilter/af_volume.c
+++ b/libavfilter/af_volume.c
@@ -281,7 +281,7 @@ static int config_output(AVFilterLink *outlink)
     AVFilterLink *inlink = ctx->inputs[0];
 
     vol->sample_fmt = inlink->format;
-    vol->channels   = inlink->channels;
+    vol->channels   = inlink->ch_layout.nb_channels;
     vol->planes     = av_sample_fmt_is_planar(inlink->format) ? vol->channels : 1;
 
     vol->var_values[VAR_N] =
@@ -294,7 +294,7 @@ static int config_output(AVFilterLink *outlink)
     vol->var_values[VAR_T] =
     vol->var_values[VAR_VOLUME] = NAN;
 
-    vol->var_values[VAR_NB_CHANNELS] = inlink->channels;
+    vol->var_values[VAR_NB_CHANNELS] = inlink->ch_layout.nb_channels;
     vol->var_values[VAR_TB]          = av_q2d(inlink->time_base);
     vol->var_values[VAR_SAMPLE_RATE] = inlink->sample_rate;
 
diff --git a/libavfilter/af_volumedetect.c b/libavfilter/af_volumedetect.c
index 486fccc4e9..ebfad6914f 100644
--- a/libavfilter/af_volumedetect.c
+++ b/libavfilter/af_volumedetect.c
@@ -38,7 +38,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *samples)
     AVFilterContext *ctx = inlink->dst;
     VolDetectContext *vd = ctx->priv;
     int nb_samples  = samples->nb_samples;
-    int nb_channels = samples->channels;
+    int nb_channels = samples->ch_layout.nb_channels;
     int nb_planes   = nb_channels;
     int plane, i;
     int16_t *pcm;
diff --git a/libavfilter/asrc_afirsrc.c b/libavfilter/asrc_afirsrc.c
index 3612610e75..b3651d3862 100644
--- a/libavfilter/asrc_afirsrc.c
+++ b/libavfilter/asrc_afirsrc.c
@@ -109,7 +109,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 static av_cold int query_formats(AVFilterContext *ctx)
 {
     AudioFIRSourceContext *s = ctx->priv;
-    static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 };
+    static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } };
     int sample_rates[] = { s->sample_rate, -1 };
     static const enum AVSampleFormat sample_fmts[] = {
         AV_SAMPLE_FMT_FLT,
diff --git a/libavfilter/asrc_anoisesrc.c b/libavfilter/asrc_anoisesrc.c
index 8c834492fe..8e90a420ea 100644
--- a/libavfilter/asrc_anoisesrc.c
+++ b/libavfilter/asrc_anoisesrc.c
@@ -84,7 +84,7 @@ AVFILTER_DEFINE_CLASS(anoisesrc);
 static av_cold int query_formats(AVFilterContext *ctx)
 {
     ANoiseSrcContext *s = ctx->priv;
-    static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 };
+    static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } };
     int sample_rates[] = { s->sample_rate, -1 };
     static const enum AVSampleFormat sample_fmts[] = {
         AV_SAMPLE_FMT_DBL,
diff --git a/libavfilter/asrc_anullsrc.c b/libavfilter/asrc_anullsrc.c
index 7ee2fa5a5d..17cbc5fb6c 100644
--- a/libavfilter/asrc_anullsrc.c
+++ b/libavfilter/asrc_anullsrc.c
@@ -37,8 +37,7 @@
 
 typedef struct ANullContext {
     const AVClass *class;
-    char   *channel_layout_str;
-    uint64_t channel_layout;
+    AVChannelLayout ch_layout;
     char   *sample_rate_str;
     int     sample_rate;
     int64_t duration;
@@ -50,8 +49,8 @@ typedef struct ANullContext {
 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
 static const AVOption anullsrc_options[]= {
-    { "channel_layout", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS },
-    { "cl",             "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS },
+    { "channel_layout", "set channel_layout", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "stereo"}, 0, 0, FLAGS },
+    { "cl",             "set channel_layout", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "stereo"}, 0, 0, FLAGS },
     { "sample_rate",    "set sample rate",    OFFSET(sample_rate_str)   , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS },
     { "r",              "set sample rate",    OFFSET(sample_rate_str)   , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS },
     { "nb_samples",     "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 1, UINT16_MAX, FLAGS },
@@ -72,17 +71,13 @@ static av_cold int init(AVFilterContext *ctx)
                                      null->sample_rate_str, ctx)) < 0)
         return ret;
 
-    if ((ret = ff_parse_channel_layout(&null->channel_layout, NULL,
-                                        null->channel_layout_str, ctx)) < 0)
-        return ret;
-
     return 0;
 }
 
 static int query_formats(AVFilterContext *ctx)
 {
     ANullContext *null = ctx->priv;
-    int64_t chlayouts[] = { null->channel_layout, -1 };
+    const AVChannelLayout chlayouts[] = { null->ch_layout, { 0 } };
     int sample_rates[] = { null->sample_rate, -1 };
     int ret;
 
diff --git a/libavfilter/asrc_flite.c b/libavfilter/asrc_flite.c
index 17e7a5b9bc..5fab8086ba 100644
--- a/libavfilter/asrc_flite.c
+++ b/libavfilter/asrc_flite.c
@@ -225,11 +225,13 @@ static int query_formats(AVFilterContext *ctx)
     int ret;
 
     AVFilterChannelLayouts *chlayouts = NULL;
-    int64_t chlayout = av_get_default_channel_layout(flite->wave->num_channels);
     AVFilterFormats *sample_formats = NULL;
     AVFilterFormats *sample_rates = NULL;
+    AVChannelLayout chlayout = { 0 };
 
-    if ((ret = ff_add_channel_layout         (&chlayouts     , chlayout                )) < 0 ||
+    av_channel_layout_default(&chlayout, flite->wave->num_channels);
+
+    if ((ret = ff_add_channel_layout         (&chlayouts     , &chlayout               )) < 0 ||
         (ret = ff_set_common_channel_layouts (ctx            , chlayouts               )) < 0 ||
         (ret = ff_add_format                 (&sample_formats, AV_SAMPLE_FMT_S16       )) < 0 ||
         (ret = ff_set_common_formats         (ctx            , sample_formats          )) < 0 ||
diff --git a/libavfilter/asrc_hilbert.c b/libavfilter/asrc_hilbert.c
index 82996c7362..6469ea2cda 100644
--- a/libavfilter/asrc_hilbert.c
+++ b/libavfilter/asrc_hilbert.c
@@ -77,7 +77,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 static av_cold int query_formats(AVFilterContext *ctx)
 {
     HilbertContext *s = ctx->priv;
-    static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 };
+    static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } };
     int sample_rates[] = { s->sample_rate, -1 };
     static const enum AVSampleFormat sample_fmts[] = {
         AV_SAMPLE_FMT_FLT,
diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c
index aaa81291a8..e4ae61c406 100644
--- a/libavfilter/asrc_sinc.c
+++ b/libavfilter/asrc_sinc.c
@@ -76,7 +76,7 @@ static int activate(AVFilterContext *ctx)
 static int query_formats(AVFilterContext *ctx)
 {
     SincContext *s = ctx->priv;
-    static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 };
+    static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } };
     int sample_rates[] = { s->sample_rate, -1 };
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLT,
                                                        AV_SAMPLE_FMT_NONE };
diff --git a/libavfilter/asrc_sine.c b/libavfilter/asrc_sine.c
index c8995ae2c9..780070e205 100644
--- a/libavfilter/asrc_sine.c
+++ b/libavfilter/asrc_sine.c
@@ -180,7 +180,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 static av_cold int query_formats(AVFilterContext *ctx)
 {
     SineContext *sine = ctx->priv;
-    static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 };
+    static const AVChannelLayout chlayouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, { 0 } };
     int sample_rates[] = { sine->sample_rate, -1 };
     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16,
                                                        AV_SAMPLE_FMT_NONE };
diff --git a/libavfilter/audio.c b/libavfilter/audio.c
index cebc9709dd..0567c3c361 100644
--- a/libavfilter/audio.c
+++ b/libavfilter/audio.c
@@ -39,10 +39,14 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
 AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
 {
     AVFrame *frame = NULL;
-    int channels = link->channels;
+    int channels = link->ch_layout.nb_channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     int channel_layout_nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
 
     av_assert0(channels == channel_layout_nb_channels || !channel_layout_nb_channels);
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     if (!link->frame_pool) {
         link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
@@ -77,7 +81,17 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
         return NULL;
 
     frame->nb_samples = nb_samples;
-    frame->channel_layout = link->channel_layout;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    frame->channel_layout = link->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                            link->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if (link->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC &&
+        av_channel_layout_copy(&frame->ch_layout, &link->ch_layout) < 0) {
+        av_frame_free(&frame);
+        return NULL;
+    }
     frame->sample_rate = link->sample_rate;
 
     av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format);
diff --git a/libavfilter/avf_abitscope.c b/libavfilter/avf_abitscope.c
index f74a6eacb0..73a8290c9e 100644
--- a/libavfilter/avf_abitscope.c
+++ b/libavfilter/avf_abitscope.c
@@ -96,7 +96,7 @@ static int config_input(AVFilterLink *inlink)
     char *colors, *saveptr = NULL;
 
     s->nb_samples = FFMAX(1, av_rescale(inlink->sample_rate, s->frame_rate.den, s->frame_rate.num));
-    s->nb_channels = inlink->channels;
+    s->nb_channels = inlink->ch_layout.nb_channels;
     s->depth = inlink->format == AV_SAMPLE_FMT_S16P ? 16 : 32;
 
     s->fg = av_malloc_array(s->nb_channels, 4 * sizeof(*s->fg));
@@ -168,9 +168,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
 
     switch (insamples->format) {
     case AV_SAMPLE_FMT_S16P:
-        for (ch = 0; ch < inlink->channels; ch++) {
+        for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
             uint16_t *in = (uint16_t *)insamples->extended_data[ch];
-            int w = outpicref->width / inlink->channels;
+            int w = outpicref->width / inlink->ch_layout.nb_channels;
             int h = outpicref->height / 16;
             uint32_t color = AV_RN32(&s->fg[4 * ch]);
 
@@ -191,9 +191,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
         }
         break;
     case AV_SAMPLE_FMT_S32P:
-        for (ch = 0; ch < inlink->channels; ch++) {
+        for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
             uint32_t *in = (uint32_t *)insamples->extended_data[ch];
-            int w = outpicref->width / inlink->channels;
+            int w = outpicref->width / inlink->ch_layout.nb_channels;
             int h = outpicref->height / 32;
             uint32_t color = AV_RN32(&s->fg[4 * ch]);
 
diff --git a/libavfilter/avf_ahistogram.c b/libavfilter/avf_ahistogram.c
index 258b062873..98606b1149 100644
--- a/libavfilter/avf_ahistogram.c
+++ b/libavfilter/avf_ahistogram.c
@@ -121,7 +121,7 @@ static int config_input(AVFilterLink *inlink)
     AudioHistogramContext *s = ctx->priv;
 
     s->nb_samples = FFMAX(1, av_rescale(inlink->sample_rate, s->frame_rate.den, s->frame_rate.num));
-    s->dchannels = s->dmode == SINGLE ? 1 : inlink->channels;
+    s->dchannels = s->dmode == SINGLE ? 1 : inlink->ch_layout.nb_channels;
     s->shistogram = av_calloc(s->w, s->dchannels * sizeof(*s->shistogram));
     if (!s->shistogram)
         return AVERROR(ENOMEM);
@@ -201,7 +201,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 
     switch (s->ascale) {
     case ALINEAR:
-        for (c = 0; c < inlink->channels; c++) {
+        for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
             const float *src = (const float *)in->extended_data[c];
             uint64_t *achistogram = &s->achistogram[(s->dmode == SINGLE ? 0: c) * w];
 
@@ -224,7 +224,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
         }
         break;
     case ALOG:
-        for (c = 0; c < inlink->channels; c++) {
+        for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
             const float *src = (const float *)in->extended_data[c];
             uint64_t *achistogram = &s->achistogram[(s->dmode == SINGLE ? 0: c) * w];
 
diff --git a/libavfilter/avf_aphasemeter.c b/libavfilter/avf_aphasemeter.c
index d9302cf867..eae584d17f 100644
--- a/libavfilter/avf_aphasemeter.c
+++ b/libavfilter/avf_aphasemeter.c
@@ -101,7 +101,7 @@ static int query_formats(AVFilterContext *ctx)
     formats = ff_make_format_list(sample_fmts);
     if ((ret = ff_formats_ref         (formats, &inlink->outcfg.formats        )) < 0 ||
         (ret = ff_formats_ref         (formats, &outlink->incfg.formats        )) < 0 ||
-        (ret = ff_add_channel_layout  (&layout, AV_CH_LAYOUT_STEREO         )) < 0 ||
+        (ret = ff_add_channel_layout  (&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO )) < 0 ||
         (ret = ff_channel_layouts_ref (layout , &inlink->outcfg.channel_layouts)) < 0 ||
         (ret = ff_channel_layouts_ref (layout , &outlink->incfg.channel_layouts)) < 0)
         return ret;
diff --git a/libavfilter/avf_avectorscope.c b/libavfilter/avf_avectorscope.c
index ba392153f3..c1deaa1ea0 100644
--- a/libavfilter/avf_avectorscope.c
+++ b/libavfilter/avf_avectorscope.c
@@ -207,7 +207,7 @@ static int query_formats(AVFilterContext *ctx)
 
     formats = ff_make_format_list(sample_fmts);
     if ((ret = ff_formats_ref         (formats, &inlink->outcfg.formats        )) < 0 ||
-        (ret = ff_add_channel_layout  (&layout, AV_CH_LAYOUT_STEREO         )) < 0 ||
+        (ret = ff_add_channel_layout  (&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_channel_layouts_ref (layout , &inlink->outcfg.channel_layouts)) < 0)
         return ret;
 
diff --git a/libavfilter/avf_concat.c b/libavfilter/avf_concat.c
index 84c2a52094..c85c17b51f 100644
--- a/libavfilter/avf_concat.c
+++ b/libavfilter/avf_concat.c
@@ -263,7 +263,7 @@ static int send_silence(AVFilterContext *ctx, unsigned in_no, unsigned out_no,
         if (!buf)
             return AVERROR(ENOMEM);
         av_samples_set_silence(buf->extended_data, 0, frame_nb_samples,
-                               outlink->channels, outlink->format);
+                               outlink->ch_layout.nb_channels, outlink->format);
         buf->pts = base_pts + av_rescale_q(sent, rate_tb, outlink->time_base);
         ret = ff_filter_frame(outlink, buf);
         if (ret < 0)
diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c
index 6f63574a8f..057a957a2a 100644
--- a/libavfilter/avf_showcqt.c
+++ b/libavfilter/avf_showcqt.c
@@ -1325,7 +1325,8 @@ static int query_formats(AVFilterContext *ctx)
         AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
         AV_PIX_FMT_YUV444P, AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
     };
-    static const int64_t channel_layouts[] = { AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_STEREO_DOWNMIX, -1 };
+    static const AVChannelLayout channel_layouts[] = { (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO,
+                                                       (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX, { 0 } };
     int ret;
 
     /* set input audio formats */
diff --git a/libavfilter/avf_showfreqs.c b/libavfilter/avf_showfreqs.c
index 08dbce53c8..c72a464884 100644
--- a/libavfilter/avf_showfreqs.c
+++ b/libavfilter/avf_showfreqs.c
@@ -177,7 +177,7 @@ static int config_output(AVFilterLink *outlink)
     av_freep(&s->fft_input);
     av_freep(&s->fft_data);
     av_freep(&s->avg_data);
-    s->nb_channels = inlink->channels;
+    s->nb_channels = inlink->ch_layout.nb_channels;
 
     s->fft_input = av_calloc(s->nb_channels, sizeof(*s->fft_input));
     if (!s->fft_input)
@@ -219,7 +219,7 @@ static int config_output(AVFilterLink *outlink)
     outlink->w = s->w;
     outlink->h = s->h;
 
-    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->win_size);
+    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->ch_layout.nb_channels, s->win_size);
     if (!s->fifo)
         return AVERROR(ENOMEM);
     return 0;
diff --git a/libavfilter/avf_showspatial.c b/libavfilter/avf_showspatial.c
index 64e5204837..7807628540 100644
--- a/libavfilter/avf_showspatial.c
+++ b/libavfilter/avf_showspatial.c
@@ -94,7 +94,7 @@ static int query_formats(AVFilterContext *ctx)
 
     formats = ff_make_format_list(sample_fmts);
     if ((ret = ff_formats_ref         (formats, &inlink->outcfg.formats        )) < 0 ||
-        (ret = ff_add_channel_layout  (&layout, AV_CH_LAYOUT_STEREO         )) < 0 ||
+        (ret = ff_add_channel_layout  (&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) < 0 ||
         (ret = ff_channel_layouts_ref (layout , &inlink->outcfg.channel_layouts)) < 0)
         return ret;
 
@@ -190,7 +190,7 @@ static int config_output(AVFilterLink *outlink)
     outlink->time_base = av_inv_q(outlink->frame_rate);
 
     av_audio_fifo_free(s->fifo);
-    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->win_size);
+    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->ch_layout.nb_channels, s->win_size);
     if (!s->fifo)
         return AVERROR(ENOMEM);
     return 0;
diff --git a/libavfilter/avf_showspectrum.c b/libavfilter/avf_showspectrum.c
index 74d2dd758c..3defc9d05c 100644
--- a/libavfilter/avf_showspectrum.c
+++ b/libavfilter/avf_showspectrum.c
@@ -738,8 +738,7 @@ static int draw_legend(AVFilterContext *ctx, int samples)
     uint8_t *dst;
     char chlayout_str[128];
 
-    av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), inlink->channels,
-                                 inlink->channel_layout);
+    av_channel_layout_describe(&inlink->ch_layout, chlayout_str, sizeof(chlayout_str));
 
     text = av_asprintf("%d Hz | %s", inlink->sample_rate, chlayout_str);
     if (!text)
@@ -1041,8 +1040,8 @@ static int config_output(AVFilterLink *outlink)
         outlink->h += s->start_y * 2;
     }
 
-    h = (s->mode == COMBINED || s->orientation == HORIZONTAL) ? s->h : s->h / inlink->channels;
-    w = (s->mode == COMBINED || s->orientation == VERTICAL)   ? s->w : s->w / inlink->channels;
+    h = (s->mode == COMBINED || s->orientation == HORIZONTAL) ? s->h : s->h / inlink->ch_layout.nb_channels;
+    w = (s->mode == COMBINED || s->orientation == VERTICAL)   ? s->w : s->w / inlink->ch_layout.nb_channels;
     s->channel_height = h;
     s->channel_width  = w;
 
@@ -1058,14 +1057,14 @@ static int config_output(AVFilterLink *outlink)
     s->buf_size = FFALIGN(s->win_size << (!!s->stop), av_cpu_max_align());
 
     if (!s->fft) {
-        s->fft = av_calloc(inlink->channels, sizeof(*s->fft));
+        s->fft = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->fft));
         if (!s->fft)
             return AVERROR(ENOMEM);
     }
 
     if (s->stop) {
         if (!s->ifft) {
-            s->ifft = av_calloc(inlink->channels, sizeof(*s->ifft));
+            s->ifft = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->ifft));
             if (!s->ifft)
                 return AVERROR(ENOMEM);
         }
@@ -1091,7 +1090,7 @@ static int config_output(AVFilterLink *outlink)
         }
         av_freep(&s->fft_data);
 
-        s->nb_display_channels = inlink->channels;
+        s->nb_display_channels = inlink->ch_layout.nb_channels;
         for (i = 0; i < s->nb_display_channels; i++) {
             float scale;
 
@@ -1240,7 +1239,7 @@ static int config_output(AVFilterLink *outlink)
            s->w, s->h, s->win_size);
 
     av_audio_fifo_free(s->fifo);
-    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->win_size);
+    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->ch_layout.nb_channels, s->win_size);
     if (!s->fifo)
         return AVERROR(ENOMEM);
     return 0;
diff --git a/libavfilter/avf_showvolume.c b/libavfilter/avf_showvolume.c
index 401b65ca69..1c072a16a6 100644
--- a/libavfilter/avf_showvolume.c
+++ b/libavfilter/avf_showvolume.c
@@ -166,15 +166,15 @@ static int config_input(AVFilterLink *inlink)
     ShowVolumeContext *s = ctx->priv;
 
     s->nb_samples = FFMAX(1, av_rescale(inlink->sample_rate, s->frame_rate.den, s->frame_rate.num));
-    s->values = av_calloc(inlink->channels * VAR_VARS_NB, sizeof(double));
+    s->values = av_calloc(inlink->ch_layout.nb_channels * VAR_VARS_NB, sizeof(double));
     if (!s->values)
         return AVERROR(ENOMEM);
 
-    s->color_lut = av_calloc(s->w, sizeof(*s->color_lut) * inlink->channels);
+    s->color_lut = av_calloc(s->w, sizeof(*s->color_lut) * inlink->ch_layout.nb_channels);
     if (!s->color_lut)
         return AVERROR(ENOMEM);
 
-    s->max = av_calloc(inlink->channels, sizeof(*s->max));
+    s->max = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->max));
     if (!s->max)
         return AVERROR(ENOMEM);
 
@@ -188,8 +188,8 @@ static int config_input(AVFilterLink *inlink)
 
     if (s->draw_persistent_duration > 0.) {
         s->persistent_max_frames = (int) FFMAX(av_q2d(s->frame_rate) * s->draw_persistent_duration, 1.);
-        s->max_persistent = av_calloc(inlink->channels * s->persistent_max_frames, sizeof(*s->max_persistent));
-        s->nb_frames_max_display = av_calloc(inlink->channels * s->persistent_max_frames, sizeof(*s->nb_frames_max_display));
+        s->max_persistent = av_calloc(inlink->ch_layout.nb_channels * s->persistent_max_frames, sizeof(*s->max_persistent));
+        s->nb_frames_max_display = av_calloc(inlink->ch_layout.nb_channels * s->persistent_max_frames, sizeof(*s->nb_frames_max_display));
     }
     return 0;
 }
@@ -202,16 +202,16 @@ static int config_output(AVFilterLink *outlink)
 
     if (s->orientation) {
         outlink->h = s->w;
-        outlink->w = s->h * inlink->channels + (inlink->channels - 1) * s->b;
+        outlink->w = s->h * inlink->ch_layout.nb_channels + (inlink->ch_layout.nb_channels - 1) * s->b;
     } else {
         outlink->w = s->w;
-        outlink->h = s->h * inlink->channels + (inlink->channels - 1) * s->b;
+        outlink->h = s->h * inlink->ch_layout.nb_channels + (inlink->ch_layout.nb_channels - 1) * s->b;
     }
 
     outlink->sample_aspect_ratio = (AVRational){1,1};
     outlink->frame_rate = s->frame_rate;
 
-    for (ch = 0; ch < inlink->channels; ch++) {
+    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
         int i;
 
         for (i = 0; i < s->w; i++) {
@@ -322,6 +322,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
     ShowVolumeContext *s = ctx->priv;
     const int step = s->step;
     int c, j, k, max_draw;
+    char channel_name[64];
     AVFrame *out;
 
     if (!s->out || s->out->width  != outlink->w ||
@@ -353,7 +354,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
     }
 
     if (s->orientation) { /* vertical */
-        for (c = 0; c < inlink->channels; c++) {
+        for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
             float *src = (float *)insamples->extended_data[c];
             uint32_t *lut = s->color_lut + s->w * c;
             float max;
@@ -375,8 +376,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
             }
 
             if (s->h >= 8 && s->draw_text) {
-                const char *channel_name = av_get_channel_name(av_channel_layout_extract_channel(insamples->channel_layout, c));
-                if (!channel_name)
+                int ret = av_channel_name(channel_name, sizeof(channel_name), av_channel_layout_channel_from_index(&insamples->ch_layout, c));
+                if (ret < 0)
                     continue;
                 drawtext(s->out, c * (s->h + s->b) + (s->h - 10) / 2, outlink->h - 35, channel_name, 1);
             }
@@ -388,7 +389,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
             }
         }
     } else { /* horizontal */
-        for (c = 0; c < inlink->channels; c++) {
+        for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
             float *src = (float *)insamples->extended_data[c];
             uint32_t *lut = s->color_lut + s->w * c;
             float max;
@@ -411,8 +412,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
             }
 
             if (s->h >= 8 && s->draw_text) {
-                const char *channel_name = av_get_channel_name(av_channel_layout_extract_channel(insamples->channel_layout, c));
-                if (!channel_name)
+                int ret = av_channel_name(channel_name, sizeof(channel_name), av_channel_layout_channel_from_index(&insamples->ch_layout, c));
+                if (ret < 0)
                     continue;
                 drawtext(s->out, 2, c * (s->h + s->b) + (s->h - 8) / 2, channel_name, 0);
             }
@@ -432,7 +433,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
     av_frame_make_writable(out);
 
     /* draw volume level */
-    for (c = 0; c < inlink->channels && s->h >= 8 && s->draw_volume; c++) {
+    for (c = 0; c < inlink->ch_layout.nb_channels && s->h >= 8 && s->draw_volume; c++) {
         char buf[16];
 
         if (s->orientation) { /* vertical */
diff --git a/libavfilter/avf_showwaves.c b/libavfilter/avf_showwaves.c
index 853f6bbdcb..4aa415b115 100644
--- a/libavfilter/avf_showwaves.c
+++ b/libavfilter/avf_showwaves.c
@@ -415,7 +415,7 @@ static int config_output(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     AVFilterLink *inlink = ctx->inputs[0];
     ShowWavesContext *showwaves = ctx->priv;
-    int nb_channels = inlink->channels;
+    int nb_channels = inlink->ch_layout.nb_channels;
     char *colors, *saveptr = NULL;
     uint8_t x;
     int ch;
@@ -551,7 +551,7 @@ inline static int push_frame(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     AVFilterLink *inlink = ctx->inputs[0];
     ShowWavesContext *showwaves = outlink->src->priv;
-    int nb_channels = inlink->channels;
+    int nb_channels = inlink->ch_layout.nb_channels;
     int ret, i;
 
     ret = ff_filter_frame(outlink, showwaves->outpicref);
@@ -572,7 +572,7 @@ static int push_single_pic(AVFilterLink *outlink)
     int64_t last_column_samples = column_max_samples + remaining_samples;
     AVFrame *out = showwaves->outpicref;
     struct frame_node *node;
-    const int nb_channels = inlink->channels;
+    const int nb_channels = inlink->ch_layout.nb_channels;
     const int ch_height = showwaves->split_channels ? outlink->h / nb_channels : outlink->h;
     const int linesize = out->linesize[0];
     const int pixstep = showwaves->pixstep;
@@ -661,7 +661,7 @@ static int alloc_out_frame(ShowWavesContext *showwaves, const int16_t *p,
             return AVERROR(ENOMEM);
         out->width  = outlink->w;
         out->height = outlink->h;
-        out->pts = in->pts + av_rescale_q((p - (int16_t *)in->data[0]) / inlink->channels,
+        out->pts = in->pts + av_rescale_q((p - (int16_t *)in->data[0]) / inlink->ch_layout.nb_channels,
                                           av_make_q(1, inlink->sample_rate),
                                           outlink->time_base);
         for (j = 0; j < outlink->h; j++)
@@ -692,7 +692,7 @@ static int showwaves_filter_frame(AVFilterLink *inlink, AVFrame *insamples)
     const int nb_samples = insamples->nb_samples;
     AVFrame *outpicref = showwaves->outpicref;
     int16_t *p = (int16_t *)insamples->data[0];
-    int nb_channels = inlink->channels;
+    int nb_channels = inlink->ch_layout.nb_channels;
     int i, j, ret = 0;
     const int pixstep = showwaves->pixstep;
     const int n = showwaves->n;
@@ -820,7 +820,7 @@ static int showwavespic_config_input(AVFilterLink *inlink)
     ShowWavesContext *showwaves = ctx->priv;
 
     if (showwaves->single_pic) {
-        showwaves->sum = av_calloc(inlink->channels, sizeof(*showwaves->sum));
+        showwaves->sum = av_calloc(inlink->ch_layout.nb_channels, sizeof(*showwaves->sum));
         if (!showwaves->sum)
             return AVERROR(ENOMEM);
     }
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 7362bcdab5..acb2d7db51 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -204,6 +204,7 @@ void avfilter_link_free(AVFilterLink **link)
 
     ff_framequeue_free(&(*link)->fifo);
     ff_frame_pool_uninit((FFFramePool**)&(*link)->frame_pool);
+    av_channel_layout_uninit(&(*link)->ch_layout);
 
     av_freep(link);
 }
@@ -405,7 +406,7 @@ void ff_tlog_link(void *ctx, AVFilterLink *link, int end)
                 end ? "\n" : "");
     } else {
         char buf[128];
-        av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
+        av_channel_layout_describe(&link->ch_layout, buf, sizeof(buf));
 
         ff_tlog(ctx,
                 "link[%p r:%d cl:%s fmt:%s %s->%s]%s",
@@ -1036,11 +1037,21 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
             av_log(link->dst, AV_LOG_ERROR, "Format change is not supported\n");
             goto error;
         }
-        if (frame->channels != link->channels) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        if (frame->channels != link->ch_layout.nb_channels) {
             av_log(link->dst, AV_LOG_ERROR, "Channel count change is not supported\n");
             goto error;
         }
-        if (frame->channel_layout != link->channel_layout) {
+        if (frame->channel_layout && frame->channel_layout != link->channel_layout) {
+            av_log(link->dst, AV_LOG_ERROR, "Channel layout change is not supported\n");
+            goto error;
+        }
+FF_ENABLE_DEPRECATION_WARNINGS
+        if (av_channel_layout_check(&frame->ch_layout) && av_channel_layout_compare(&frame->ch_layout, &link->ch_layout)) {
+#else
+        if (av_channel_layout_compare(&frame->ch_layout, &link->ch_layout)) {
+#endif
             av_log(link->dst, AV_LOG_ERROR, "Channel layout change is not supported\n");
             goto error;
         }
@@ -1117,7 +1128,7 @@ static int take_samples(AVFilterLink *link, unsigned min, unsigned max,
     for (i = 0; i < nb_frames; i++) {
         frame = ff_framequeue_take(&link->fifo);
         av_samples_copy(buf->extended_data, frame->extended_data, p, 0,
-                        frame->nb_samples, link->channels, link->format);
+                        frame->nb_samples, link->ch_layout.nb_channels, link->format);
         p += frame->nb_samples;
         av_frame_free(&frame);
     }
@@ -1125,7 +1136,7 @@ static int take_samples(AVFilterLink *link, unsigned min, unsigned max,
         unsigned n = nb_samples - p;
         frame = ff_framequeue_peek(&link->fifo, 0);
         av_samples_copy(buf->extended_data, frame->extended_data, p, 0, n,
-                        link->channels, link->format);
+                        link->ch_layout.nb_channels, link->format);
         ff_framequeue_skip_samples(&link->fifo, n, link->time_base);
     }
 
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index b105dc3159..fcde7ab7af 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -543,7 +543,14 @@ struct AVFilterLink {
     int h;                      ///< agreed upon image height
     AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
     /* These 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
+    /**
+     * channel layout of current buffer (see libavutil/channel_layout.h)
+     * @deprecated use ch_layout
+     */
+    attribute_deprecated
+    uint64_t channel_layout;
+#endif
     int sample_rate;            ///< samples per second
 
     int format;                 ///< agreed upon media format
@@ -557,6 +564,8 @@ struct AVFilterLink {
      */
     AVRational time_base;
 
+    AVChannelLayout ch_layout;  ///< channel layout of current buffer (see libavutil/channel_layout.h)
+
     /*****************************************************************
      * All fields below this line are not part of the public API. They
      * may not be used outside of libavfilter and can be changed and
@@ -632,11 +641,6 @@ struct AVFilterLink {
      */
     int max_samples;
 
-    /**
-     * Number of channels.
-     */
-    int channels;
-
     /**
      * Number of past frames sent through the link.
      */
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index b8b432e98b..1d4343d961 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -639,6 +639,8 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref)
     link->format = link->incfg.formats->formats[0];
 
     if (link->type == AVMEDIA_TYPE_AUDIO) {
+        int ret;
+
         if (!link->incfg.samplerates->nb_formats) {
             av_log(link->src, AV_LOG_ERROR, "Cannot select sample rate for"
                    " the link between filters %s and %s.\n", link->src->name,
@@ -659,11 +661,15 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref)
             return AVERROR(EINVAL);
         }
         link->incfg.channel_layouts->nb_channel_layouts = 1;
-        link->channel_layout = link->incfg.channel_layouts->channel_layouts[0];
-        if ((link->channels = FF_LAYOUT2COUNT(link->channel_layout)))
-            link->channel_layout = 0;
-        else
-            link->channels = av_get_channel_layout_nb_channels(link->channel_layout);
+        ret = av_channel_layout_copy(&link->ch_layout, &link->incfg.channel_layouts->channel_layouts[0]);
+        if (ret < 0)
+            return ret;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        link->channel_layout = link->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                               link->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     }
 
     ff_formats_unref(&link->incfg.formats);
@@ -725,12 +731,12 @@ static int reduce_formats_on_filter(AVFilterContext *filter)
     /* reduce channel layouts */
     for (i = 0; i < filter->nb_inputs; i++) {
         AVFilterLink *inlink = filter->inputs[i];
-        uint64_t fmt;
+        AVChannelLayout fmt = { 0 };
 
         if (!inlink->outcfg.channel_layouts ||
             inlink->outcfg.channel_layouts->nb_channel_layouts != 1)
             continue;
-        fmt = inlink->outcfg.channel_layouts->channel_layouts[0];
+        av_channel_layout_copy(&fmt, &inlink->outcfg.channel_layouts->channel_layouts[0]);
 
         for (j = 0; j < filter->nb_outputs; j++) {
             AVFilterLink *outlink = filter->outputs[j];
@@ -741,23 +747,24 @@ static int reduce_formats_on_filter(AVFilterContext *filter)
                 continue;
 
             if (fmts->all_layouts &&
-                (!FF_LAYOUT2COUNT(fmt) || fmts->all_counts)) {
+                (KNOWN(&fmt) || fmts->all_counts)) {
                 /* Turn the infinite list into a singleton */
                 fmts->all_layouts = fmts->all_counts  = 0;
-                if (ff_add_channel_layout(&outlink->incfg.channel_layouts, fmt) < 0)
+                if (ff_add_channel_layout(&outlink->incfg.channel_layouts, &fmt) < 0)
                     ret = 1;
                 break;
             }
 
             for (k = 0; k < outlink->incfg.channel_layouts->nb_channel_layouts; k++) {
-                if (fmts->channel_layouts[k] == fmt) {
-                    fmts->channel_layouts[0]  = fmt;
+                if (!av_channel_layout_compare(&fmts->channel_layouts[k], &fmt)) {
+                    av_channel_layout_copy(&fmts->channel_layouts[0], &fmt);
                     fmts->nb_channel_layouts = 1;
                     ret = 1;
                     break;
                 }
             }
         }
+        av_channel_layout_uninit(&fmt);
     }
 
     return ret;
@@ -887,26 +894,31 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter)
             continue;
 
         for (j = 0; j < outlink->incfg.channel_layouts->nb_channel_layouts; j++) {
-            uint64_t  in_chlayout = link->outcfg.channel_layouts->channel_layouts[0];
-            uint64_t out_chlayout = outlink->incfg.channel_layouts->channel_layouts[j];
-            int  in_channels      = av_get_channel_layout_nb_channels(in_chlayout);
-            int out_channels      = av_get_channel_layout_nb_channels(out_chlayout);
-            int count_diff        = out_channels - in_channels;
+            AVChannelLayout in_chlayout = { 0 }, out_chlayout = { 0 };
+            int  in_channels;
+            int out_channels;
+            int count_diff;
             int matched_channels, extra_channels;
             int score = 100000;
 
-            if (FF_LAYOUT2COUNT(in_chlayout) || FF_LAYOUT2COUNT(out_chlayout)) {
+            av_channel_layout_copy(&in_chlayout, &link->outcfg.channel_layouts->channel_layouts[0]);
+            av_channel_layout_copy(&out_chlayout, &outlink->incfg.channel_layouts->channel_layouts[j]);
+            in_channels            = in_chlayout.nb_channels;
+            out_channels           = out_chlayout.nb_channels;
+            count_diff             = out_channels - in_channels;
+            if (!KNOWN(&in_chlayout) || !KNOWN(&out_chlayout)) {
                 /* Compute score in case the input or output layout encodes
                    a channel count; in this case the score is not altered by
                    the computation afterwards, as in_chlayout and
                    out_chlayout have both been set to 0 */
-                if (FF_LAYOUT2COUNT(in_chlayout))
-                    in_channels = FF_LAYOUT2COUNT(in_chlayout);
-                if (FF_LAYOUT2COUNT(out_chlayout))
-                    out_channels = FF_LAYOUT2COUNT(out_chlayout);
+                if (!KNOWN(&in_chlayout))
+                    in_channels = FF_LAYOUT2COUNT(&in_chlayout);
+                if (!KNOWN(&out_chlayout))
+                    out_channels = FF_LAYOUT2COUNT(&out_chlayout);
                 score -= 10000 + FFABS(out_channels - in_channels) +
                          (in_channels > out_channels ? 10000 : 0);
-                in_chlayout = out_chlayout = 0;
+                av_channel_layout_uninit(&in_chlayout);
+                av_channel_layout_uninit(&out_chlayout);
                 /* Let the remaining computation run, even if the score
                    value is not altered */
             }
@@ -915,27 +927,27 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter)
             for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) {
                 uint64_t cmp0 = ch_subst[k][0];
                 uint64_t cmp1 = ch_subst[k][1];
-                if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) &&
-                    (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) {
-                    in_chlayout  &= ~cmp0;
-                    out_chlayout &= ~cmp1;
+                if ( av_channel_layout_subset(& in_chlayout, cmp0) &&
+                    !av_channel_layout_subset(&out_chlayout, cmp0) &&
+                     av_channel_layout_subset(&out_chlayout, cmp1) &&
+                    !av_channel_layout_subset(& in_chlayout, cmp1)) {
+                    av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(& in_chlayout, ~cmp0));
+                    av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~cmp1));
                     /* add score for channel match, minus a deduction for
                        having to do the substitution */
-                    score += 10 * av_get_channel_layout_nb_channels(cmp1) - 2;
+                    score += 10 * av_popcount64(cmp1) - 2;
                 }
             }
 
             /* no penalty for LFE channel mismatch */
-            if ( (in_chlayout & AV_CH_LOW_FREQUENCY) &&
-                (out_chlayout & AV_CH_LOW_FREQUENCY))
+            if (av_channel_layout_channel_from_index(&in_chlayout,  AV_CHAN_LOW_FREQUENCY) >= 0 &&
+                av_channel_layout_channel_from_index(&out_chlayout, AV_CHAN_LOW_FREQUENCY) >= 0)
                 score += 10;
-            in_chlayout  &= ~AV_CH_LOW_FREQUENCY;
-            out_chlayout &= ~AV_CH_LOW_FREQUENCY;
+            av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(&in_chlayout, ~AV_CH_LOW_FREQUENCY));
+            av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~AV_CH_LOW_FREQUENCY));
 
-            matched_channels = av_get_channel_layout_nb_channels(in_chlayout &
-                                                                 out_chlayout);
-            extra_channels   = av_get_channel_layout_nb_channels(out_chlayout &
-                                                                 (~in_chlayout));
+            matched_channels = av_popcount64(in_chlayout.u.mask & out_chlayout.u.mask);
+            extra_channels   = av_popcount64(out_chlayout.u.mask & (~in_chlayout.u.mask));
             score += 10 * matched_channels - 5 * extra_channels;
 
             if (score > best_score ||
@@ -946,7 +958,7 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter)
             }
         }
         av_assert0(best_idx >= 0);
-        FFSWAP(uint64_t, outlink->incfg.channel_layouts->channel_layouts[0],
+        FFSWAP(AVChannelLayout, outlink->incfg.channel_layouts->channel_layouts[0],
                outlink->incfg.channel_layouts->channel_layouts[best_idx]);
     }
 
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index c0215669e7..c96ac1e626 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -74,7 +74,7 @@ static void cleanup_redundant_layouts(AVFilterContext *ctx)
         if (buf->channel_counts[i] < 64)
             counts |= (uint64_t)1 << buf->channel_counts[i];
     for (i = lc = 0; i < nb_layouts; i++) {
-        n = av_get_channel_layout_nb_channels(buf->channel_layouts[i]);
+        n = av_popcount64(buf->channel_layouts[i]);
         if (n < 64 && (counts & ((uint64_t)1 << n)))
             av_log(ctx, AV_LOG_WARNING,
                    "Removing channel layout 0x%"PRIx64", redundant with %d channels\n",
@@ -217,12 +217,34 @@ MAKE_AVFILTERLINK_ACCESSOR(int              , w                  )
 MAKE_AVFILTERLINK_ACCESSOR(int              , h                  )
 MAKE_AVFILTERLINK_ACCESSOR(AVRational       , sample_aspect_ratio)
 
-MAKE_AVFILTERLINK_ACCESSOR(int              , channels           )
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
 MAKE_AVFILTERLINK_ACCESSOR(uint64_t         , channel_layout     )
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 MAKE_AVFILTERLINK_ACCESSOR(int              , sample_rate        )
 
 MAKE_AVFILTERLINK_ACCESSOR(AVBufferRef *    , hw_frames_ctx      )
 
+int av_buffersink_get_channels(const AVFilterContext *ctx)
+{
+    av_assert0(ctx->filter->activate == activate);
+    return ctx->inputs[0]->ch_layout.nb_channels;
+}
+
+int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out)
+{
+    AVChannelLayout ch_layout = { 0 };
+    int ret;
+
+    av_assert0(ctx->filter->activate == activate);
+    ret = av_channel_layout_copy(&ch_layout, &ctx->inputs[0]->ch_layout);
+    if (ret < 0)
+        return ret;
+    *out = ch_layout;
+    return 0;
+}
+
 #define CHECK_LIST_SIZE(field) \
         if (buf->field ## _size % sizeof(*buf->field)) { \
             av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
@@ -256,6 +278,7 @@ static int asink_query_formats(AVFilterContext *ctx)
 {
     BufferSinkContext *buf = ctx->priv;
     AVFilterFormats *formats = NULL;
+    AVChannelLayout layout = { 0 };
     AVFilterChannelLayouts *layouts = NULL;
     unsigned i;
     int ret;
@@ -277,11 +300,14 @@ static int asink_query_formats(AVFilterContext *ctx)
         buf->all_channel_counts) {
         cleanup_redundant_layouts(ctx);
         for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++)
-            if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0)
+            if ((ret = av_channel_layout_from_mask(&layout, buf->channel_layouts[i])) < 0 ||
+                (ret = ff_add_channel_layout(&layouts, &layout) < 0))
                 return ret;
-        for (i = 0; i < NB_ITEMS(buf->channel_counts); i++)
-            if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0)
+        for (i = 0; i < NB_ITEMS(buf->channel_counts); i++) {
+            layout = FF_COUNT2LAYOUT(buf->channel_counts[i]);
+            if ((ret = ff_add_channel_layout(&layouts, &layout)) < 0)
                 return ret;
+        }
         if (buf->all_channel_counts) {
             if (layouts)
                 av_log(ctx, AV_LOG_WARNING,
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index 69ed0f29a8..ae90ae87fa 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -46,7 +46,7 @@
  * - av_buffersink_get_h(),
  * - av_buffersink_get_sample_aspect_ratio(),
  * - av_buffersink_get_channels(),
- * - av_buffersink_get_channel_layout(),
+ * - av_buffersink_get_ch_layout(),
  * - av_buffersink_get_sample_rate().
  *
  * The format can be constrained by setting options, using av_opt_set() and
@@ -156,7 +156,12 @@ int              av_buffersink_get_h                   (const AVFilterContext *c
 AVRational       av_buffersink_get_sample_aspect_ratio (const AVFilterContext *ctx);
 
 int              av_buffersink_get_channels            (const AVFilterContext *ctx);
+#if FF_API_OLD_CHANNEL_LAYOUT
+attribute_deprecated
 uint64_t         av_buffersink_get_channel_layout      (const AVFilterContext *ctx);
+#endif
+int              av_buffersink_get_ch_layout           (const AVFilterContext *ctx,
+                                                        AVChannelLayout *ch_layout);
 int              av_buffersink_get_sample_rate         (const AVFilterContext *ctx);
 
 AVBufferRef *    av_buffersink_get_hw_frames_ctx       (const AVFilterContext *ctx);
diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index b0611872f1..a2a08a7d89 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -60,8 +60,8 @@ typedef struct BufferSourceContext {
     int sample_rate;
     enum AVSampleFormat sample_fmt;
     int channels;
-    uint64_t channel_layout;
     char    *channel_layout_str;
+    AVChannelLayout ch_layout;
 
     int eof;
 } BufferSourceContext;
@@ -73,12 +73,12 @@ typedef struct BufferSourceContext {
         av_log(s, AV_LOG_WARNING, "Changing video frame properties on the fly is not supported by all filters.\n");\
     }
 
-#define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, ch_layout, ch_count, format, pts)\
+#define CHECK_AUDIO_PARAM_CHANGE(s, c, srate, layout, format, pts)\
     if (c->sample_fmt != format || c->sample_rate != srate ||\
-        c->channel_layout != ch_layout || c->channels != ch_count) {\
+        av_channel_layout_compare(&c->ch_layout, &layout) || c->channels != layout.nb_channels) {\
         av_log(s, AV_LOG_INFO, "filter context - fmt: %s r: %d layout: %"PRIX64" ch: %d, incoming frame - fmt: %s r: %d layout: %"PRIX64" ch: %d pts_time: %s\n",\
-               av_get_sample_fmt_name(c->sample_fmt), c->sample_rate, c->channel_layout, c->channels,\
-               av_get_sample_fmt_name(format), srate, ch_layout, ch_count, av_ts2timestr(pts, &s->outputs[0]->time_base));\
+               av_get_sample_fmt_name(c->sample_fmt), c->sample_rate, c->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? c->ch_layout.u.mask : 0, c->channels,\
+               av_get_sample_fmt_name(format), srate, layout.order == AV_CHANNEL_ORDER_NATIVE ? layout.u.mask : 0, layout.nb_channels, av_ts2timestr(pts, &s->outputs[0]->time_base));\
         av_log(s, AV_LOG_ERROR, "Changing audio frame properties on the fly is not supported.\n");\
         return AVERROR(EINVAL);\
     }
@@ -127,8 +127,20 @@ int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *par
         }
         if (param->sample_rate > 0)
             s->sample_rate = param->sample_rate;
-        if (param->channel_layout)
-            s->channel_layout = param->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 (param->channel_layout && (param->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
+                                      param->ch_layout.u.mask != param->channel_layout)) {
+            av_channel_layout_from_mask(&s->ch_layout, param->channel_layout);
+FF_ENABLE_DEPRECATION_WARNINGS
+        } else
+#endif
+        if (param->ch_layout.nb_channels) {
+            int ret = av_channel_layout_copy(&s->ch_layout, &param->ch_layout);
+            if (ret < 0)
+                return ret;
+        }
         break;
     default:
         return AVERROR_BUG;
@@ -168,11 +180,15 @@ int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFra
     AVFrame *copy;
     int refcounted, ret;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
     if (frame && frame->channel_layout &&
         av_get_channel_layout_nb_channels(frame->channel_layout) != frame->channels) {
         av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
         return AVERROR(EINVAL);
     }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
     s->nb_failed_requests = 0;
 
@@ -192,10 +208,20 @@ int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFra
             break;
         case AVMEDIA_TYPE_AUDIO:
             /* For layouts unknown on input but known on link after negotiation. */
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             if (!frame->channel_layout)
-                frame->channel_layout = s->channel_layout;
-            CHECK_AUDIO_PARAM_CHANGE(ctx, s, frame->sample_rate, frame->channel_layout,
-                                     frame->channels, frame->format, frame->pts);
+                frame->channel_layout = s->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                        s->ch_layout.u.mask : 0;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+            if (frame->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
+                ret = av_channel_layout_copy(&frame->ch_layout, &s->ch_layout);
+                if (ret < 0)
+                    return ret;
+            }
+            CHECK_AUDIO_PARAM_CHANGE(ctx, s, frame->sample_rate, frame->ch_layout,
+                                     frame->format, frame->pts);
             break;
         default:
             return AVERROR(EINVAL);
@@ -301,6 +327,7 @@ AVFILTER_DEFINE_CLASS(abuffer);
 static av_cold int init_audio(AVFilterContext *ctx)
 {
     BufferSourceContext *s = ctx->priv;
+    char buf[128];
     int ret = 0;
 
     if (s->sample_fmt == AV_SAMPLE_FMT_NONE) {
@@ -308,24 +335,39 @@ static av_cold int init_audio(AVFilterContext *ctx)
         return AVERROR(EINVAL);
     }
 
-    if (s->channel_layout_str || s->channel_layout) {
+    if (s->channel_layout_str || s->ch_layout.nb_channels) {
         int n;
 
-        if (!s->channel_layout) {
-            s->channel_layout = av_get_channel_layout(s->channel_layout_str);
-            if (!s->channel_layout) {
-                av_log(ctx, AV_LOG_ERROR, "Invalid channel layout %s.\n",
+        if (!s->ch_layout.nb_channels) {
+            ret = av_channel_layout_from_string(&s->ch_layout, s->channel_layout_str);
+            if (ret < 0) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+                uint64_t mask;
+FF_DISABLE_DEPRECATION_WARNINGS
+                mask = av_get_channel_layout(s->channel_layout_str);
+                if (!mask) {
+#endif
+                    av_log(ctx, AV_LOG_ERROR, "Invalid channel layout %s.\n",
+                           s->channel_layout_str);
+                    return AVERROR(EINVAL);
+#if FF_API_OLD_CHANNEL_LAYOUT
+                }
+FF_ENABLE_DEPRECATION_WARNINGS
+                av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
                        s->channel_layout_str);
-                return AVERROR(EINVAL);
+                av_channel_layout_from_mask(&s->ch_layout, mask);
+#endif
             }
         }
-        n = av_get_channel_layout_nb_channels(s->channel_layout);
+
+        n = s->ch_layout.nb_channels;
+        av_channel_layout_describe(&s->ch_layout, buf, sizeof(buf));
         if (s->channels) {
             if (n != s->channels) {
                 av_log(ctx, AV_LOG_ERROR,
                        "Mismatching channel count %d and layout '%s' "
                        "(%d channels)\n",
-                       s->channels, s->channel_layout_str, n);
+                       s->channels, buf, n);
                 return AVERROR(EINVAL);
             }
         }
@@ -334,6 +376,9 @@ static av_cold int init_audio(AVFilterContext *ctx)
         av_log(ctx, AV_LOG_ERROR, "Neither number of channels nor "
                                   "channel layout specified\n");
         return AVERROR(EINVAL);
+    } else {
+        s->ch_layout = FF_COUNT2LAYOUT(s->channels);
+        av_channel_layout_describe(&s->ch_layout, buf, sizeof(buf));
     }
 
     if (!s->time_base.num)
@@ -342,7 +387,7 @@ static av_cold int init_audio(AVFilterContext *ctx)
     av_log(ctx, AV_LOG_VERBOSE,
            "tb:%d/%d samplefmt:%s samplerate:%d chlayout:%s\n",
            s->time_base.num, s->time_base.den, av_get_sample_fmt_name(s->sample_fmt),
-           s->sample_rate, s->channel_layout_str);
+           s->sample_rate, buf);
 
     return ret;
 }
@@ -374,9 +419,7 @@ static int query_formats(AVFilterContext *ctx)
             (ret = ff_set_common_samplerates (ctx         , samplerates   )) < 0)
             return ret;
 
-        if ((ret = ff_add_channel_layout(&channel_layouts,
-                              c->channel_layout ? c->channel_layout :
-                              FF_COUNT2LAYOUT(c->channels))) < 0)
+        if ((ret = ff_add_channel_layout(&channel_layouts, &c->ch_layout)) < 0)
             return ret;
         if ((ret = ff_set_common_channel_layouts(ctx, channel_layouts)) < 0)
             return ret;
@@ -405,8 +448,11 @@ static int config_props(AVFilterLink *link)
         }
         break;
     case AVMEDIA_TYPE_AUDIO:
-        if (!c->channel_layout)
-            c->channel_layout = link->channel_layout;
+        if (!c->ch_layout.nb_channels) {
+            int ret = av_channel_layout_copy(&c->ch_layout, &link->ch_layout);
+            if (ret < 0)
+                return ret;
+        }
         break;
     default:
         return AVERROR(EINVAL);
diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h
index 08fbd18a47..3b248b37cd 100644
--- a/libavfilter/buffersrc.h
+++ b/libavfilter/buffersrc.h
@@ -110,10 +110,19 @@ typedef struct AVBufferSrcParameters {
      */
     int sample_rate;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
     /**
      * Audio only, the audio channel layout
+     * @deprecated use ch_layout
      */
+    attribute_deprecated
     uint64_t channel_layout;
+#endif
+
+    /**
+     * Audio only, the audio channel layout
+     */
+    AVChannelLayout ch_layout;
 } AVBufferSrcParameters;
 
 /**
diff --git a/libavfilter/f_ebur128.c b/libavfilter/f_ebur128.c
index 88d6a1fe46..2a6edba3d8 100644
--- a/libavfilter/f_ebur128.c
+++ b/libavfilter/f_ebur128.c
@@ -422,7 +422,7 @@ static int config_audio_output(AVFilterLink *outlink)
     int i;
     AVFilterContext *ctx = outlink->src;
     EBUR128Context *ebur128 = ctx->priv;
-    const int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout);
+    const int nb_channels = outlink->ch_layout.nb_channels;
 
 #define BACK_MASK (AV_CH_BACK_LEFT    |AV_CH_BACK_CENTER    |AV_CH_BACK_RIGHT| \
                    AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_BACK_RIGHT| \
@@ -439,8 +439,8 @@ static int config_audio_output(AVFilterLink *outlink)
 
     for (i = 0; i < nb_channels; i++) {
         /* channel weighting */
-        const uint64_t chl = av_channel_layout_extract_channel(outlink->channel_layout, i);
-        if (chl & (AV_CH_LOW_FREQUENCY|AV_CH_LOW_FREQUENCY_2)) {
+        const int chl = av_channel_layout_channel_from_index(&outlink->ch_layout, i);
+        if (chl == AV_CHAN_LOW_FREQUENCY || chl == AV_CHAN_LOW_FREQUENCY_2) {
             ebur128->ch_weighting[i] = 0;
         } else if (chl & BACK_MASK) {
             ebur128->ch_weighting[i] = 1.41;
@@ -472,11 +472,11 @@ static int config_audio_output(AVFilterLink *outlink)
             !ebur128->true_peaks_per_frame || !ebur128->swr_ctx)
             return AVERROR(ENOMEM);
 
-        av_opt_set_int(ebur128->swr_ctx, "in_channel_layout",    outlink->channel_layout, 0);
+        av_opt_set_chlayout(ebur128->swr_ctx, "in_ch_layout",   &outlink->ch_layout, 0);
         av_opt_set_int(ebur128->swr_ctx, "in_sample_rate",       outlink->sample_rate, 0);
         av_opt_set_sample_fmt(ebur128->swr_ctx, "in_sample_fmt", outlink->format, 0);
 
-        av_opt_set_int(ebur128->swr_ctx, "out_channel_layout",    outlink->channel_layout, 0);
+        av_opt_set_chlayout(ebur128->swr_ctx, "out_ch_layout",   &outlink->ch_layout, 0);
         av_opt_set_int(ebur128->swr_ctx, "out_sample_rate",       192000, 0);
         av_opt_set_sample_fmt(ebur128->swr_ctx, "out_sample_fmt", outlink->format, 0);
 
diff --git a/libavfilter/f_graphmonitor.c b/libavfilter/f_graphmonitor.c
index 51d0a568e3..f20825a488 100644
--- a/libavfilter/f_graphmonitor.c
+++ b/libavfilter/f_graphmonitor.c
@@ -196,7 +196,7 @@ static void draw_items(AVFilterContext *ctx, AVFrame *out,
         if (l->type == AVMEDIA_TYPE_VIDEO) {
             snprintf(buffer, sizeof(buffer)-1, " | size: %dx%d", l->w, l->h);
         } else if (l->type == AVMEDIA_TYPE_AUDIO) {
-            snprintf(buffer, sizeof(buffer)-1, " | channels: %d", l->channels);
+            snprintf(buffer, sizeof(buffer)-1, " | channels: %d", l->ch_layout.nb_channels);
         }
         drawtext(out, xpos, ypos, buffer, s->white);
         xpos += strlen(buffer) * 8;
diff --git a/libavfilter/f_loop.c b/libavfilter/f_loop.c
index f8ae4a6a3a..c619ba85b3 100644
--- a/libavfilter/f_loop.c
+++ b/libavfilter/f_loop.c
@@ -70,8 +70,8 @@ static int aconfig_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     LoopContext *s  = ctx->priv;
 
-    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, 8192);
-    s->left = av_audio_fifo_alloc(inlink->format, inlink->channels, 8192);
+    s->fifo = av_audio_fifo_alloc(inlink->format, inlink->ch_layout.nb_channels, 8192);
+    s->left = av_audio_fifo_alloc(inlink->format, inlink->ch_layout.nb_channels, 8192);
     if (!s->fifo || !s->left)
         return AVERROR(ENOMEM);
 
diff --git a/libavfilter/f_reverse.c b/libavfilter/f_reverse.c
index f7a7e716fa..2776c83b8d 100644
--- a/libavfilter/f_reverse.c
+++ b/libavfilter/f_reverse.c
@@ -148,7 +148,7 @@ const AVFilter ff_vf_reverse = {
 
 static void reverse_samples_planar(AVFrame *out)
 {
-    for (int p = 0; p < out->channels; p++) {
+    for (int p = 0; p < out->ch_layout.nb_channels; p++) {
         switch (out->format) {
         case AV_SAMPLE_FMT_U8P: {
             uint8_t *dst = (uint8_t *)out->extended_data[p];
@@ -192,7 +192,7 @@ static void reverse_samples_planar(AVFrame *out)
 
 static void reverse_samples_packed(AVFrame *out)
 {
-    const int channels = out->channels;
+    const int channels = out->ch_layout.nb_channels;
 
     switch (out->format) {
     case AV_SAMPLE_FMT_U8: {
diff --git a/libavfilter/f_streamselect.c b/libavfilter/f_streamselect.c
index 3708d2b256..1328a842f9 100644
--- a/libavfilter/f_streamselect.c
+++ b/libavfilter/f_streamselect.c
@@ -118,8 +118,12 @@ static int config_output(AVFilterLink *outlink)
         break;
     case AVMEDIA_TYPE_AUDIO:
         outlink->sample_rate    = inlink->sample_rate;
-        outlink->channels       = inlink->channels;
+        outlink->ch_layout.nb_channels       = inlink->ch_layout.nb_channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
         outlink->channel_layout = inlink->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
         break;
     }
 
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index ba62f73248..5f3e204418 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -28,8 +28,6 @@
 #include "internal.h"
 #include "formats.h"
 
-#define KNOWN(l) (!FF_LAYOUT2COUNT(l)) /* for readability */
-
 /**
  * Add all refs from a to ret and destroy a.
  */
@@ -215,7 +213,7 @@ static int merge_channel_layouts(void *va, void *vb)
 {
     AVFilterChannelLayouts *a = va;
     AVFilterChannelLayouts *b = vb;
-    uint64_t *channel_layouts;
+    AVChannelLayout *channel_layouts;
     unsigned a_all = a->all_layouts + a->all_counts;
     unsigned b_all = b->all_layouts + b->all_counts;
     int ret_max, ret_nb = 0, i, j, round;
@@ -233,8 +231,8 @@ static int merge_channel_layouts(void *va, void *vb)
         if (a_all == 1 && !b_all) {
             /* keep only known layouts in b; works also for b_all = 1 */
             for (i = j = 0; i < b->nb_channel_layouts; i++)
-                if (KNOWN(b->channel_layouts[i]))
-                    b->channel_layouts[j++] = b->channel_layouts[i];
+                if (KNOWN(&b->channel_layouts[i]) && i != j++)
+                    av_channel_layout_copy(&b->channel_layouts[j], &b->channel_layouts[i]);
             /* Not optimal: the unknown layouts of b may become known after
                another merge. */
             if (!j)
@@ -246,17 +244,18 @@ static int merge_channel_layouts(void *va, void *vb)
     }
 
     ret_max = a->nb_channel_layouts + b->nb_channel_layouts;
-    if (!(channel_layouts = av_malloc_array(ret_max, sizeof(*channel_layouts))))
+    if (!(channel_layouts = av_mallocz_array(ret_max, sizeof(*channel_layouts))))
         return AVERROR(ENOMEM);
 
     /* a[known] intersect b[known] */
     for (i = 0; i < a->nb_channel_layouts; i++) {
-        if (!KNOWN(a->channel_layouts[i]))
+        if (!KNOWN(&a->channel_layouts[i]))
             continue;
         for (j = 0; j < b->nb_channel_layouts; j++) {
-            if (a->channel_layouts[i] == b->channel_layouts[j]) {
-                channel_layouts[ret_nb++] = a->channel_layouts[i];
-                a->channel_layouts[i] = b->channel_layouts[j] = 0;
+            if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
+                av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
+                av_channel_layout_uninit(&a->channel_layouts[i]);
+                av_channel_layout_uninit(&b->channel_layouts[j]);
                 break;
             }
         }
@@ -265,24 +264,24 @@ static int merge_channel_layouts(void *va, void *vb)
        2nd round: a[generic] intersect b[known] */
     for (round = 0; round < 2; round++) {
         for (i = 0; i < a->nb_channel_layouts; i++) {
-            uint64_t fmt = a->channel_layouts[i], bfmt;
-            if (!fmt || !KNOWN(fmt))
+            AVChannelLayout *fmt = &a->channel_layouts[i], bfmt = { 0 };
+            if (!av_channel_layout_check(fmt) || !KNOWN(fmt))
                 continue;
-            bfmt = FF_COUNT2LAYOUT(av_get_channel_layout_nb_channels(fmt));
+            bfmt = FF_COUNT2LAYOUT(fmt->nb_channels);
             for (j = 0; j < b->nb_channel_layouts; j++)
-                if (b->channel_layouts[j] == bfmt)
-                    channel_layouts[ret_nb++] = a->channel_layouts[i];
+                if (!av_channel_layout_compare(&b->channel_layouts[j], &bfmt))
+                    av_channel_layout_copy(&channel_layouts[ret_nb++], fmt);
         }
         /* 1st round: swap to prepare 2nd round; 2nd round: put it back */
         FFSWAP(AVFilterChannelLayouts *, a, b);
     }
     /* a[generic] intersect b[generic] */
     for (i = 0; i < a->nb_channel_layouts; i++) {
-        if (KNOWN(a->channel_layouts[i]))
+        if (KNOWN(&a->channel_layouts[i]))
             continue;
         for (j = 0; j < b->nb_channel_layouts; j++)
-            if (a->channel_layouts[i] == b->channel_layouts[j])
-                channel_layouts[ret_nb++] = a->channel_layouts[i];
+            if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j]))
+                av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
     }
 
     if (!ret_nb) {
@@ -388,15 +387,40 @@ AVFilterFormats *ff_make_format_list(const int *fmts)
     return formats;
 }
 
-AVFilterChannelLayouts *ff_make_format64_list(const int64_t *fmts)
+AVFilterChannelLayouts *ff_make_format64_list(const AVChannelLayout *fmts)
 {
-    MAKE_FORMAT_LIST(AVFilterChannelLayouts,
-                     channel_layouts, nb_channel_layouts);
-    if (count)
-        memcpy(formats->channel_layouts, fmts,
-               sizeof(*formats->channel_layouts) * count);
+    AVFilterChannelLayouts *ch_layouts;
+    int count = 0;
+    if (fmts)
+        for (count = 0; fmts[count].nb_channels; count++)
+            ;
+    ch_layouts = av_mallocz(sizeof(*ch_layouts));
+    if (!ch_layouts)
+        return NULL;
+    ch_layouts->nb_channel_layouts = count;
+    if (count) {
+        ch_layouts->channel_layouts =
+            av_mallocz_array(count, sizeof(*ch_layouts->channel_layouts));
+        if (!ch_layouts->channel_layouts) {
+            av_freep(&ch_layouts);
+            return NULL;
+        }
+        for (int i = 0; i < count; i++) {
+            int ret = av_channel_layout_copy(&ch_layouts->channel_layouts[i], &fmts[i]);
+            if (ret < 0)
+                goto fail;
+        }
+    }
 
-    return formats;
+    return ch_layouts;
+
+fail:
+    for (int i = 0; i < count; i++)
+        av_channel_layout_uninit(&ch_layouts->channel_layouts[i]);
+    av_free(ch_layouts->channel_layouts);
+    av_freep(&ch_layouts);
+
+    return NULL;
 }
 
 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)        \
@@ -415,6 +439,11 @@ do {                                                        \
     }                                                       \
                                                             \
     (*f)->list = fmts;                                      \
+    ASSIGN_FMT(f, fmt, list, nb);                           \
+} while (0)
+
+#define ASSIGN_FMT(f, fmt, list, nb)                        \
+do {                                                        \
     (*f)->list[(*f)->nb++] = fmt;                           \
 } while (0)
 
@@ -424,10 +453,21 @@ int ff_add_format(AVFilterFormats **avff, int64_t fmt)
     return 0;
 }
 
-int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
+#undef ASSIGN_FMT
+#define ASSIGN_FMT(f, fmt, list, nb)                              \
+do {                                                              \
+    int ret;                                                      \
+    memset((*f)->list + (*f)->nb, 0, sizeof(*(*f)->list));        \
+    ret = av_channel_layout_copy(&(*f)->list[(*f)->nb], fmt);     \
+    if (ret < 0)                                                  \
+        return ret;                                               \
+    (*f)->nb++;                                                   \
+} while (0)
+
+int ff_add_channel_layout(AVFilterChannelLayouts **l, AVChannelLayout *channel_layout)
 {
     av_assert1(!(*l && (*l)->all_layouts));
-    ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, uint64_t, channel_layouts, nb_channel_layouts);
+    ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, AVChannelLayout, channel_layouts, nb_channel_layouts);
     return 0;
 }
 
@@ -583,6 +623,7 @@ do {                                                               \
         --(*ref)->refcount;                                        \
     }                                                              \
     if (!(*ref)->refcount) {                                       \
+        FREE_LIST(ref, list);                                      \
         av_free((*ref)->list);                                     \
         av_free((*ref)->refs);                                     \
         av_free(*ref);                                             \
@@ -590,11 +631,19 @@ do {                                                               \
     *ref = NULL;                                                   \
 } while (0)
 
+#define FREE_LIST(ref, list) do { } while(0)
 void ff_formats_unref(AVFilterFormats **ref)
 {
     FORMATS_UNREF(ref, formats);
 }
 
+#undef FREE_LIST
+#define FREE_LIST(ref, list)                                       \
+    do {                                                           \
+        for (int i = 0; i < (*ref)->nb_channel_layouts; i++)       \
+            av_channel_layout_uninit(&(*ref)->list[i]);            \
+    } while(0)
+
 void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
 {
     FORMATS_UNREF(ref, channel_layouts);
@@ -664,7 +713,7 @@ int ff_set_common_channel_layouts(AVFilterContext *ctx,
 }
 
 int ff_set_common_channel_layouts_from_list(AVFilterContext *ctx,
-                                            const int64_t *fmts)
+                                            const AVChannelLayout *fmts)
 {
     return ff_set_common_channel_layouts(ctx, ff_make_format64_list(fmts));
 }
@@ -787,23 +836,41 @@ int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
     return 0;
 }
 
-int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
+int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
                             void *log_ctx)
 {
-    int64_t chlayout;
-    int nb_channels;
-
-    if (av_get_extended_channel_layout(arg, &chlayout, &nb_channels) < 0) {
-        av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
-        return AVERROR(EINVAL);
+    AVChannelLayout chlayout = { 0 };
+    int res;
+
+    res = av_channel_layout_from_string(&chlayout, arg);
+    if (res < 0) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+        int64_t mask;
+        int nb_channels;
+FF_DISABLE_DEPRECATION_WARNINGS
+        if (av_get_extended_channel_layout(arg, &mask, &nb_channels) < 0) {
+#endif
+            av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
+            return AVERROR(EINVAL);
+#if FF_API_OLD_CHANNEL_LAYOUT
+        }
+FF_ENABLE_DEPRECATION_WARNINGS
+        av_log(log_ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
+               arg);
+        if (mask)
+            av_channel_layout_from_mask(&chlayout, mask);
+        else
+            chlayout = (AVChannelLayout) { .order = AV_CHANNEL_ORDER_UNSPEC, .nb_channels = nb_channels };
+#endif
     }
-    if (!chlayout && !nret) {
+
+    if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) {
         av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg);
         return AVERROR(EINVAL);
     }
     *ret = chlayout;
     if (nret)
-        *nret = nb_channels;
+        *nret = chlayout.nb_channels;
 
     return 0;
 }
@@ -846,11 +913,11 @@ int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
     return check_list(log, "sample rate", fmts);
 }
 
-static int layouts_compatible(uint64_t a, uint64_t b)
+static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b)
 {
-    return a == b ||
-           (KNOWN(a) && !KNOWN(b) && av_get_channel_layout_nb_channels(a) == FF_LAYOUT2COUNT(b)) ||
-           (KNOWN(b) && !KNOWN(a) && av_get_channel_layout_nb_channels(b) == FF_LAYOUT2COUNT(a));
+    return !av_channel_layout_compare(a, b) ||
+           (KNOWN(a) && !KNOWN(b) && a->nb_channels == b->nb_channels) ||
+           (KNOWN(b) && !KNOWN(a) && b->nb_channels == a->nb_channels);
 }
 
 int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts)
@@ -869,7 +936,7 @@ int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fm
     }
     for (i = 0; i < fmts->nb_channel_layouts; i++) {
         for (j = i + 1; j < fmts->nb_channel_layouts; j++) {
-            if (layouts_compatible(fmts->channel_layouts[i], fmts->channel_layouts[j])) {
+            if (layouts_compatible(&fmts->channel_layouts[i], &fmts->channel_layouts[j])) {
                 av_log(log, AV_LOG_ERROR, "Duplicated or redundant channel layout\n");
                 return AVERROR(EINVAL);
             }
diff --git a/libavfilter/formats.h b/libavfilter/formats.h
index a884d15213..e55180f45c 100644
--- a/libavfilter/formats.h
+++ b/libavfilter/formats.h
@@ -83,7 +83,7 @@ struct AVFilterFormats {
  *   (e.g. AV_CH_LAYOUT_STEREO and FF_COUNT2LAYOUT(2).
  */
 struct AVFilterChannelLayouts {
-    uint64_t *channel_layouts;  ///< list of channel layouts
+    AVChannelLayout *channel_layouts; ///< list of channel layouts
     int    nb_channel_layouts;  ///< number of channel layouts
     char all_layouts;           ///< accept any known channel layout
     char all_counts;            ///< accept any channel layout or count
@@ -99,14 +99,16 @@ struct AVFilterChannelLayouts {
  * The result is only valid inside AVFilterChannelLayouts and immediately
  * related functions.
  */
-#define FF_COUNT2LAYOUT(c) (0x8000000000000000ULL | (c))
+#define FF_COUNT2LAYOUT(c) ((AVChannelLayout) { .order = AV_CHANNEL_ORDER_UNSPEC, .nb_channels = c })
 
 /**
  * Decode a channel count encoded as a channel layout.
  * Return 0 if the channel layout was a real one.
  */
-#define FF_LAYOUT2COUNT(l) (((l) & 0x8000000000000000ULL) ? \
-                           (int)((l) & 0x7FFFFFFF) : 0)
+#define FF_LAYOUT2COUNT(l) (((l)->order == AV_CHANNEL_ORDER_UNSPEC) ? \
+                            (l)->nb_channels : 0)
+
+#define KNOWN(l) (!FF_LAYOUT2COUNT(l)) /* for readability */
 
 /**
  * Construct an empty AVFilterChannelLayouts/AVFilterFormats struct --
@@ -126,7 +128,7 @@ av_warn_unused_result
 AVFilterChannelLayouts *ff_all_channel_counts(void);
 
 av_warn_unused_result
-AVFilterChannelLayouts *ff_make_format64_list(const int64_t *fmts);
+AVFilterChannelLayouts *ff_make_format64_list(const AVChannelLayout *fmts);
 
 /**
  * Helpers for query_formats() which set all free audio links to the same list
@@ -141,7 +143,7 @@ int ff_set_common_channel_layouts(AVFilterContext *ctx,
  */
 av_warn_unused_result
 int ff_set_common_channel_layouts_from_list(AVFilterContext *ctx,
-                                            const int64_t *fmts);
+                                            const AVChannelLayout *fmts);
 /**
  * Equivalent to ff_set_common_channel_layouts(ctx, ff_all_channel_counts())
  */
@@ -178,7 +180,7 @@ av_warn_unused_result
 int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts);
 
 av_warn_unused_result
-int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout);
+int ff_add_channel_layout(AVFilterChannelLayouts **l, AVChannelLayout *channel_layout);
 
 /**
  * Add *ref as a new reference to f.
diff --git a/libavfilter/framepool.c b/libavfilter/framepool.c
index 7c63807df3..0ef41b9404 100644
--- a/libavfilter/framepool.c
+++ b/libavfilter/framepool.c
@@ -238,7 +238,12 @@ AVFrame *ff_frame_pool_get(FFFramePool *pool)
         break;
     case AVMEDIA_TYPE_AUDIO:
         frame->nb_samples = pool->nb_samples;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
         frame->channels = pool->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+        frame->ch_layout.nb_channels = pool->channels;
         frame->format = pool->format;
         frame->linesize[0] = pool->linesize[0];
 
diff --git a/libavfilter/framequeue.c b/libavfilter/framequeue.c
index fed1118975..383c195b85 100644
--- a/libavfilter/framequeue.c
+++ b/libavfilter/framequeue.c
@@ -134,10 +134,10 @@ void ff_framequeue_skip_samples(FFFrameQueue *fq, size_t samples, AVRational tim
     b = bucket(fq, 0);
     av_assert1(samples < b->frame->nb_samples);
     planar = av_sample_fmt_is_planar(b->frame->format);
-    planes = planar ? b->frame->channels : 1;
+    planes = planar ? b->frame->ch_layout.nb_channels : 1;
     bytes = samples * av_get_bytes_per_sample(b->frame->format);
     if (!planar)
-        bytes *= b->frame->channels;
+        bytes *= b->frame->ch_layout.nb_channels;
     if (b->frame->pts != AV_NOPTS_VALUE)
         b->frame->pts += av_rescale_q(samples, av_make_q(1, b->frame->sample_rate), time_base);
     b->frame->nb_samples -= samples;
diff --git a/libavfilter/graphdump.c b/libavfilter/graphdump.c
index cf8914b558..80f7bf6c98 100644
--- a/libavfilter/graphdump.c
+++ b/libavfilter/graphdump.c
@@ -30,6 +30,7 @@
 static int print_link_prop(AVBPrint *buf, AVFilterLink *link)
 {
     const char *format;
+    char layout[128];
     AVBPrint dummy_buffer;
 
     if (!buf) {
@@ -49,7 +50,8 @@ static int print_link_prop(AVBPrint *buf, AVFilterLink *link)
             format = av_x_if_null(av_get_sample_fmt_name(link->format), "?");
             av_bprintf(buf, "[%dHz %s:",
                        (int)link->sample_rate, format);
-            av_bprint_channel_layout(buf, link->channels, link->channel_layout);
+            av_channel_layout_describe(&link->ch_layout, layout, sizeof(layout));
+            av_bprintf(buf, "%s", layout);
             av_bprint_chars(buf, ']', 1);
             break;
 
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 1099b82b4b..3eecaca3fb 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -237,7 +237,7 @@ int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx);
  * @return >= 0 in case of success, a negative AVERROR code on error
  */
 av_warn_unused_result
-int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
+int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
                             void *log_ctx);
 
 void ff_update_link_current_pts(AVFilterLink *link, int64_t pts);
diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index b89a680883..3ebd279df7 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -189,23 +189,24 @@ static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
 {
     AVCodecParameters *dec_par = st->st->codecpar;
     char buf[256];
-    int64_t chl = av_get_default_channel_layout(dec_par->channels);
+    AVChannelLayout chl = { 0 };
 
-    if (!chl) {
+    av_channel_layout_default(&chl, dec_par->ch_layout.nb_channels);
+
+    if (!KNOWN(&chl)) {
         av_log(log_ctx, AV_LOG_ERROR,
                "Channel layout is not set in stream %d, and could not "
                "be guessed from the number of channels (%d)\n",
-               st_index, dec_par->channels);
+               st_index, dec_par->ch_layout.nb_channels);
         return AVERROR(EINVAL);
     }
 
-    av_get_channel_layout_string(buf, sizeof(buf), dec_par->channels, chl);
+    av_channel_layout_describe(&chl, buf, sizeof(buf));
     av_log(log_ctx, AV_LOG_WARNING,
            "Channel layout is not set in output stream %d, "
            "guessed channel layout is '%s'\n",
            st_index, buf);
-    dec_par->channel_layout = chl;
-    return 0;
+    return av_channel_layout_copy(&dec_par->ch_layout, &chl);
 }
 
 static av_cold int movie_common_init(AVFilterContext *ctx)
@@ -315,7 +316,7 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
         if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0)
             return ret;
         if ( movie->st[i].st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
-            !movie->st[i].st->codecpar->channel_layout) {
+            !KNOWN(&movie->st[i].st->codecpar->ch_layout)) {
             ret = guess_channel_layout(&movie->st[i], i, ctx);
             if (ret < 0)
                 return ret;
@@ -351,7 +352,7 @@ static int movie_query_formats(AVFilterContext *ctx)
 {
     MovieContext *movie = ctx->priv;
     int list[] = { 0, -1 };
-    int64_t list64[] = { 0, -1 };
+    AVChannelLayout list64[] = { { 0 }, { 0 } };
     int i, ret;
 
     for (i = 0; i < ctx->nb_outputs; i++) {
@@ -372,7 +373,7 @@ static int movie_query_formats(AVFilterContext *ctx)
             list[0] = c->sample_rate;
             if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->incfg.samplerates)) < 0)
                 return ret;
-            list64[0] = c->channel_layout;
+            list64[0] = c->ch_layout;
             if ((ret = ff_channel_layouts_ref(ff_make_format64_list(list64),
                                    &outlink->incfg.channel_layouts)) < 0)
                 return ret;
diff --git a/libavfilter/tests/filtfmts.c b/libavfilter/tests/filtfmts.c
index d793480344..909c1e8dc9 100644
--- a/libavfilter/tests/filtfmts.c
+++ b/libavfilter/tests/filtfmts.c
@@ -59,8 +59,7 @@ static void print_formats_internal(AVFilterLink **links, const AVFilterPad *pads
 
             for (unsigned j = 0; layouts && j < layouts->nb_channel_layouts; j++) {
                 char buf[256];
-                av_get_channel_layout_string(buf, sizeof(buf), -1,
-                                             layouts->channel_layouts[j]);
+                av_channel_layout_describe(&layouts->channel_layouts[j], buf, sizeof(buf));
                 printf("%s[%u] %s: chlayout:%s\n",
                        inout_string, i, pad_name, buf);
             }
diff --git a/libavfilter/tests/formats.c b/libavfilter/tests/formats.c
index c1e30e73ee..a02f2b49b5 100644
--- a/libavfilter/tests/formats.c
+++ b/libavfilter/tests/formats.c
@@ -129,12 +129,12 @@ int main(void)
     }
 
     for ( i = 0; i<FF_ARRAY_ELEMS(teststrings); i++) {
-        int64_t layout = -1;
+        AVChannelLayout layout = { 0 };
         int count = -1;
         int ret;
         ret = ff_parse_channel_layout(&layout, &count, teststrings[i], NULL);
 
-        printf ("%d = ff_parse_channel_layout(%016"PRIX64", %2d, %s);\n", ret ? -1 : 0, layout, count, teststrings[i]);
+        printf ("%d = ff_parse_channel_layout(%016"PRIX64", %2d, %s);\n", ret ? -1 : 0, layout.order == AV_CHANNEL_ORDER_NATIVE ? layout.u.mask : 0, count, teststrings[i]);
     }
 
     return 0;
diff --git a/libavfilter/trim.c b/libavfilter/trim.c
index e627903c64..59adc54a92 100644
--- a/libavfilter/trim.c
+++ b/libavfilter/trim.c
@@ -309,7 +309,7 @@ static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame)
 
         av_frame_copy_props(out, frame);
         av_samples_copy(out->extended_data, frame->extended_data, 0, start_sample,
-                        out->nb_samples, inlink->channels,
+                        out->nb_samples, inlink->ch_layout.nb_channels,
                         frame->format);
         if (out->pts != AV_NOPTS_VALUE)
             out->pts += av_rescale_q(start_sample, (AVRational){ 1, out->sample_rate },
diff --git a/libavfilter/vaf_spectrumsynth.c b/libavfilter/vaf_spectrumsynth.c
index 674e9953b2..e0baf855a8 100644
--- a/libavfilter/vaf_spectrumsynth.c
+++ b/libavfilter/vaf_spectrumsynth.c
@@ -112,7 +112,7 @@ static int query_formats(AVFilterContext *ctx)
 
     formats = ff_make_format_list(sample_fmts);
     if ((ret = ff_formats_ref         (formats, &outlink->incfg.formats        )) < 0 ||
-        (ret = ff_add_channel_layout  (&layout, FF_COUNT2LAYOUT(s->channels))) < 0 ||
+        (ret = ff_add_channel_layout  (&layout, &FF_COUNT2LAYOUT(s->channels))) < 0 ||
         (ret = ff_channel_layouts_ref (layout , &outlink->incfg.channel_layouts)) < 0)
         return ret;
 
diff --git a/tests/ref/fate/filter-formats b/tests/ref/fate/filter-formats
index 17ff5b222f..c179b38ff0 100644
--- a/tests/ref/fate/filter-formats
+++ b/tests/ref/fate/filter-formats
@@ -66,20 +66,20 @@ quad(side)
 7 channels (FL+FR+BC+SL+SR+DL+DR)
 8 channels (FL+FR+LFE+BC+SL+SR+DL+DR)
 8 channels (FL+FR+FC+BC+SL+SR+DL+DR)
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, blah);
-0 = ff_parse_channel_layout(0000000000000001,  1, 1);
-0 = ff_parse_channel_layout(0000000000000002,  1, 2);
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, -1);
-0 = ff_parse_channel_layout(000000000000003C,  4, 60);
-0 = ff_parse_channel_layout(0000000000000041,  2, 65);
+-1 = ff_parse_channel_layout(0000000000000000, -1, blah);
+0 = ff_parse_channel_layout(0000000000000000,  1, 1);
+0 = ff_parse_channel_layout(0000000000000000,  2, 2);
+-1 = ff_parse_channel_layout(0000000000000000, -1, -1);
+0 = ff_parse_channel_layout(0000000000000000, 60, 60);
+0 = ff_parse_channel_layout(0000000000000000, 65, 65);
 0 = ff_parse_channel_layout(0000000000000004,  1, 1c);
 0 = ff_parse_channel_layout(0000000000000003,  2, 2c);
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, -1c);
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 60c);
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 65c);
+-1 = ff_parse_channel_layout(0000000000000000, -1, -1c);
+0 = ff_parse_channel_layout(0000000000000000, 60, 60c);
+0 = ff_parse_channel_layout(0000000000000000, 65, 65c);
 0 = ff_parse_channel_layout(0000000000000000,  2, 2C);
 0 = ff_parse_channel_layout(0000000000000000, 60, 60C);
--1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 65C);
+0 = ff_parse_channel_layout(0000000000000000, 65, 65C);
 0 = ff_parse_channel_layout(000000000000003F,  6, 5.1);
 0 = ff_parse_channel_layout(0000000000000003,  2, stereo);
 0 = ff_parse_channel_layout(0000000000000001,  1, 1+1+1+1);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 276/281] avdevice/lavfi: remove call to deprecated function av_buffersink_get_channel_layout()
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (276 preceding siblings ...)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 275/281] avfilter: " James Almer
@ 2022-01-13  2:09 ` James Almer
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API James Almer
                   ` (4 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavdevice/lavfi.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index fdb93b835f..db5d0b94de 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -333,11 +333,9 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx)
             par->sample_aspect_ratio = av_buffersink_get_sample_aspect_ratio(sink);
         } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
             par->sample_rate = av_buffersink_get_sample_rate(sink);
-            ret = av_channel_layout_from_mask(&par->ch_layout, av_buffersink_get_channel_layout(sink));
-            if (ret < 0) {
-                par->ch_layout.nb_channels = av_buffersink_get_channels(sink);
-                par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
-            }
+            ret = av_buffersink_get_ch_layout(sink, &par->ch_layout);
+            if (ret < 0)
+                goto end;
             par->format      = av_buffersink_get_format(sink);
             par->codec_id    = av_get_pcm_codec(par->format, -1);
             if (par->codec_id == AV_CODEC_ID_NONE)
@@ -441,7 +439,7 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
                                 frame->format, frame->width, frame->height, 1);
     } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
         size = frame->nb_samples * av_get_bytes_per_sample(frame->format) *
-                                   frame->channels;
+                                   frame->ch_layout.nb_channels;
         if ((ret = av_new_packet(pkt, size)) < 0)
             goto fail;
         memcpy(pkt->data, frame->data[0], size);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (277 preceding siblings ...)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 276/281] avdevice/lavfi: remove call to deprecated function av_buffersink_get_channel_layout() James Almer
@ 2022-01-13  2:09 ` James Almer
  2022-01-13 18:29   ` Michael Niedermayer
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 278/281] ffprobe: " James Almer
                   ` (3 subsequent siblings)
  282 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 fftools/cmdutils.c            | 42 +++++++++++++++---------
 fftools/cmdutils.h            |  8 -----
 fftools/ffmpeg.c              | 47 ++++++++++++++++----------
 fftools/ffmpeg.h              |  7 ++--
 fftools/ffmpeg_filter.c       | 52 ++++++++++++++++++++++-------
 fftools/ffmpeg_opt.c          | 62 ++++++++++++++++++++++++++++++-----
 tests/fate/aac.mak            |  2 +-
 tests/fate/lavf-container.mak |  2 +-
 8 files changed, 155 insertions(+), 67 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 4b50e15eef..55cdbfb7a7 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -1470,8 +1470,19 @@ static void print_codec(const AVCodec *c)
                           GET_SAMPLE_RATE_NAME);
     PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
                           AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
-    PRINT_CODEC_SUPPORTED(c, channel_layouts, uint64_t, "channel layouts",
-                          0, GET_CH_LAYOUT_DESC);
+
+    if (c->ch_layouts) {
+        const AVChannelLayout *p = c->ch_layouts;
+
+        printf("    Supported channel layouts:");
+        while (p->nb_channels) {
+            char name[128];
+            av_channel_layout_describe(p, name, sizeof(name));
+            printf(" %s", name);
+            p++;
+        }
+        printf("\n");
+    }
 
     if (c->priv_class) {
         show_help_children(c->priv_class,
@@ -1784,29 +1795,30 @@ int show_pix_fmts(void *optctx, const char *opt, const char *arg)
 
 int show_layouts(void *optctx, const char *opt, const char *arg)
 {
+    const AVChannelLayout *ch_layout;
+    void *iter = NULL;
+    char buf[128], buf2[128];
     int i = 0;
-    uint64_t layout, j;
-    const char *name, *descr;
 
     printf("Individual channels:\n"
            "NAME           DESCRIPTION\n");
     for (i = 0; i < 63; i++) {
-        name = av_get_channel_name((uint64_t)1 << i);
-        if (!name)
+        av_channel_name(buf, sizeof(buf), i);
+        if (!strcmp(buf, "?"))
             continue;
-        descr = av_get_channel_description((uint64_t)1 << i);
-        printf("%-14s %s\n", name, descr);
+        av_channel_description(buf2, sizeof(buf2), i);
+        printf("%-14s %s\n", buf, buf2);
     }
     printf("\nStandard channel layouts:\n"
            "NAME           DECOMPOSITION\n");
-    for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) {
-        if (name) {
-            printf("%-14s ", name);
-            for (j = 1; j; j <<= 1)
-                if ((layout & j))
-                    printf("%s%s", (layout & (j - 1)) ? "+" : "", av_get_channel_name(j));
+    while (ch_layout = av_channel_layout_standard(&iter)) {
+            av_channel_layout_describe(ch_layout, buf, sizeof(buf));
+            av_channel_name(buf2, sizeof(buf2), i);
+            printf("%-14s ", buf);
+            for (i = 0; i < 63; i++)
+                if (av_channel_layout_index_from_channel(ch_layout, i) >= 0)
+                    printf("%s%s", i ? "+" : "", buf2);
             printf("\n");
-        }
     }
     return 0;
 }
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 50eed9b13a..274d2e5b14 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -663,14 +663,6 @@ void *allocate_array_elem(void *array, size_t elem_size, int *nb_elems);
     char name[16];\
     snprintf(name, sizeof(name), "%d", rate);
 
-#define GET_CH_LAYOUT_NAME(ch_layout)\
-    char name[16];\
-    snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
-
-#define GET_CH_LAYOUT_DESC(ch_layout)\
-    char name[128];\
-    av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
-
 double get_rotation(int32_t *displaymatrix);
 
 #endif /* FFTOOLS_CMDUTILS_H */
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5d134b025f..22d6309f2a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -555,6 +555,7 @@ static void ffmpeg_cleanup(int ret)
 
             avfilter_inout_free(&ofilter->out_tmp);
             av_freep(&ofilter->name);
+            av_channel_layout_uninit(&ofilter->ch_layout);
             av_freep(&fg->outputs[j]);
         }
         av_freep(&fg->outputs);
@@ -1537,7 +1538,7 @@ static int reap_filters(int flush)
                 break;
             case AVMEDIA_TYPE_AUDIO:
                 if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) &&
-                    enc->channels != filtered_frame->channels) {
+                    enc->ch_layout.nb_channels != filtered_frame->ch_layout.nb_channels) {
                     av_log(NULL, AV_LOG_ERROR,
                            "Audio filter graph output is not normalized and encoder does not support parameter changes\n");
                     break;
@@ -1883,17 +1884,22 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
         print_final_stats(total_size);
 }
 
-static void ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par)
+static int ifilter_parameters_from_codecpar(InputFilter *ifilter, AVCodecParameters *par)
 {
+    int ret;
+
     // We never got any input. Set a fake format, which will
     // come from libavformat.
     ifilter->format                 = par->format;
     ifilter->sample_rate            = par->sample_rate;
-    ifilter->channels               = par->channels;
-    ifilter->channel_layout         = par->channel_layout;
     ifilter->width                  = par->width;
     ifilter->height                 = par->height;
     ifilter->sample_aspect_ratio    = par->sample_aspect_ratio;
+    ret = av_channel_layout_copy(&ifilter->ch_layout, &par->ch_layout);
+    if (ret < 0)
+        return ret;
+
+    return 0;
 }
 
 static void flush_encoders(void)
@@ -1921,8 +1927,11 @@ static void flush_encoders(void)
                 int x;
                 for (x = 0; x < fg->nb_inputs; x++) {
                     InputFilter *ifilter = fg->inputs[x];
-                    if (ifilter->format < 0)
-                        ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar);
+                    if (ifilter->format < 0 &&
+                        ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar) < 0) {
+                        av_log(NULL, AV_LOG_ERROR, "Error copying paramerets from input stream\n");
+                        exit_program(1);
+                    }
                 }
 
                 if (!ifilter_has_all_input_formats(fg))
@@ -2098,16 +2107,15 @@ int guess_input_channel_layout(InputStream *ist)
 {
     AVCodecContext *dec = ist->dec_ctx;
 
-    if (!dec->channel_layout) {
+    if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
         char layout_name[256];
 
-        if (dec->channels > ist->guess_layout_max)
+        if (dec->ch_layout.nb_channels > ist->guess_layout_max)
             return 0;
-        dec->channel_layout = av_get_default_channel_layout(dec->channels);
-        if (!dec->channel_layout)
+        av_channel_layout_default(&dec->ch_layout, dec->ch_layout.nb_channels);
+        if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
             return 0;
-        av_get_channel_layout_string(layout_name, sizeof(layout_name),
-                                     dec->channels, dec->channel_layout);
+        av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name));
         av_log(NULL, AV_LOG_WARNING, "Guessed Channel Layout for Input Stream "
                "#%d.%d : %s\n", ist->file_index, ist->st->index, layout_name);
     }
@@ -2160,8 +2168,7 @@ static int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_ref
     switch (ifilter->ist->st->codecpar->codec_type) {
     case AVMEDIA_TYPE_AUDIO:
         need_reinit |= ifilter->sample_rate    != frame->sample_rate ||
-                       ifilter->channels       != frame->channels ||
-                       ifilter->channel_layout != frame->channel_layout;
+                       av_channel_layout_compare(&ifilter->ch_layout, &frame->ch_layout);
         break;
     case AVMEDIA_TYPE_VIDEO:
         need_reinit |= ifilter->width  != frame->width ||
@@ -2241,8 +2248,11 @@ static int ifilter_send_eof(InputFilter *ifilter, int64_t pts)
             return ret;
     } else {
         // the filtergraph was never configured
-        if (ifilter->format < 0)
-            ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar);
+        if (ifilter->format < 0) {
+            ret = ifilter_parameters_from_codecpar(ifilter, ifilter->ist->st->codecpar);
+            if (ret < 0)
+                return ret;
+        }
         if (ifilter->format < 0 && (ifilter->type == AVMEDIA_TYPE_AUDIO || ifilter->type == AVMEDIA_TYPE_VIDEO)) {
             av_log(NULL, AV_LOG_ERROR, "Cannot determine format of input stream %d:%d after EOF\n", ifilter->ist->file_index, ifilter->ist->st->index);
             return AVERROR_INVALIDDATA;
@@ -3316,8 +3326,9 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame)
     case AVMEDIA_TYPE_AUDIO:
         enc_ctx->sample_fmt     = av_buffersink_get_format(ost->filter->filter);
         enc_ctx->sample_rate    = av_buffersink_get_sample_rate(ost->filter->filter);
-        enc_ctx->channel_layout = av_buffersink_get_channel_layout(ost->filter->filter);
-        enc_ctx->channels       = av_buffersink_get_channels(ost->filter->filter);
+        ret = av_buffersink_get_ch_layout(ost->filter->filter, &enc_ctx->ch_layout);
+        if (ret < 0)
+            return ret;
 
         if (ost->bits_per_raw_sample)
             enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 9b200b806a..75f6f9ef72 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -250,8 +250,7 @@ typedef struct InputFilter {
     AVRational sample_aspect_ratio;
 
     int sample_rate;
-    int channels;
-    uint64_t channel_layout;
+    AVChannelLayout ch_layout;
 
     AVBufferRef *hw_frames_ctx;
     int32_t *displaymatrix;
@@ -274,12 +273,12 @@ typedef struct OutputFilter {
     AVRational frame_rate;
     int format;
     int sample_rate;
-    uint64_t channel_layout;
+    AVChannelLayout ch_layout;
 
     // those are only set if no format is specified and the encoder gives us multiple options
     // They point directly to the relevant lists of the encoder.
     const int *formats;
-    const uint64_t *channel_layouts;
+    const AVChannelLayout *ch_layouts;
     const int *sample_rates;
 } OutputFilter;
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 1f6cba2c04..b096196135 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -153,8 +153,29 @@ DEF_CHOOSE_FORMAT(sample_fmts, enum AVSampleFormat, format, formats,
 DEF_CHOOSE_FORMAT(sample_rates, int, sample_rate, sample_rates, 0,
                   "%d", )
 
-DEF_CHOOSE_FORMAT(channel_layouts, uint64_t, channel_layout, channel_layouts, 0,
-                  "0x%"PRIx64, )
+static void choose_channel_layouts(OutputFilter *ofilter, AVBPrint *bprint)
+{
+    AVBPrint bp;
+
+    av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
+    if (av_channel_layout_check(&ofilter->ch_layout)) {
+        av_channel_layout_describe_bprint(&ofilter->ch_layout, &bp);
+        av_bprintf(bprint, "channel_layouts=%s", bp.str);
+    } else if (ofilter->ch_layouts) {
+        const AVChannelLayout *p;
+
+        av_bprintf(bprint, "channel_layouts=");
+        for (p = ofilter->ch_layouts; p->nb_channels; p++) {
+            av_channel_layout_describe_bprint(p, &bp);
+            av_bprintf(bprint, "%s|", bp.str);
+        }
+        if (bprint->len > 0)
+            bprint->str[--bprint->len] = '\0';
+    } else
+        return;
+    av_bprint_finalize(&bp, NULL);
+    av_bprint_chars(bprint, ':', 1);
+}
 
 int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
 {
@@ -541,9 +562,11 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
 } while (0)
     av_bprint_init(&args, 0, AV_BPRINT_SIZE_UNLIMITED);
     if (ost->audio_channels_mapped) {
+        AVChannelLayout mapped_layout = { 0 };
         int i;
-        av_bprintf(&args, "0x%"PRIx64,
-                   av_get_default_channel_layout(ost->audio_channels_mapped));
+        av_channel_layout_default(&mapped_layout, ost->audio_channels_mapped);
+        av_bprintf(&args, "0x%"PRIx64, mapped_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                       mapped_layout.u.mask : 0);
         for (i = 0; i < ost->audio_channels_mapped; i++)
             if (ost->audio_channels_map[i] != -1)
                 av_bprintf(&args, "|c%d=c%d", i, ost->audio_channels_map[i]);
@@ -552,8 +575,8 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter,
         av_bprint_clear(&args);
     }
 
-    if (codec->channels && !codec->channel_layout)
-        codec->channel_layout = av_get_default_channel_layout(codec->channels);
+    if (codec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
+        av_channel_layout_default(&codec->ch_layout, codec->ch_layout.nb_channels);
 
     choose_sample_fmts(ofilter,     &args);
     choose_sample_rates(ofilter,    &args);
@@ -832,11 +855,11 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter,
              1, ifilter->sample_rate,
              ifilter->sample_rate,
              av_get_sample_fmt_name(ifilter->format));
-    if (ifilter->channel_layout)
+    if (av_channel_layout_check(&ifilter->ch_layout) && ifilter->ch_layout.order == AV_CHANNEL_ORDER_NATIVE)
         av_bprintf(&args, ":channel_layout=0x%"PRIx64,
-                   ifilter->channel_layout);
+                   ifilter->ch_layout.u.mask);
     else
-        av_bprintf(&args, ":channels=%d", ifilter->channels);
+        av_bprintf(&args, ":channels=%d", ifilter->ch_layout.nb_channels);
     snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index,
              ist->file_index, ist->st->index);
 
@@ -1084,7 +1107,10 @@ int configure_filtergraph(FilterGraph *fg)
         ofilter->height = av_buffersink_get_h(sink);
 
         ofilter->sample_rate    = av_buffersink_get_sample_rate(sink);
-        ofilter->channel_layout = av_buffersink_get_channel_layout(sink);
+        av_channel_layout_uninit(&ofilter->ch_layout);
+        ret = av_buffersink_get_ch_layout(sink, &ofilter->ch_layout);
+        if (ret < 0)
+            goto fail;
     }
 
     fg->reconfiguration = 1;
@@ -1148,6 +1174,7 @@ fail:
 int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
 {
     AVFrameSideData *sd;
+    int ret;
 
     av_buffer_unref(&ifilter->hw_frames_ctx);
 
@@ -1158,8 +1185,9 @@ int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame)
     ifilter->sample_aspect_ratio = frame->sample_aspect_ratio;
 
     ifilter->sample_rate         = frame->sample_rate;
-    ifilter->channels            = frame->channels;
-    ifilter->channel_layout      = frame->channel_layout;
+    ret = av_channel_layout_copy(&ifilter->ch_layout, &frame->ch_layout);
+    if (ret < 0)
+        return ret;
 
     av_freep(&ifilter->displaymatrix);
     sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX);
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 9c820ab73f..0eb2c779f2 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -507,7 +507,7 @@ static int opt_map_channel(void *optctx, const char *opt, const char *arg)
     /* allow trailing ? to map_channel */
     if (allow_unused = strchr(mapchan, '?'))
         *allow_unused = 0;
-    if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->channels ||
+    if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->ch_layout.nb_channels ||
         input_streams[input_files[m->file_idx]->ist_index + m->stream_idx]->user_set_discard == AVDISCARD_ALL) {
         if (allow_unused) {
             av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
@@ -1954,9 +1954,14 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in
     MATCH_PER_STREAM_OPT(filters,        str, ost->filters,        oc, st);
 
     if (!ost->stream_copy) {
+        int channels = 0;
         char *sample_fmt = NULL;
 
-        MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
+        MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st);
+        if (channels) {
+            audio_enc->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+            audio_enc->ch_layout.nb_channels = channels;
+        }
 
         MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
         if (sample_fmt &&
@@ -2378,7 +2383,7 @@ static int open_output_file(OptionsContext *o, const char *filename)
                 for (i = 0; i < ifile->nb_streams; i++) {
                     int score;
                     ist = input_streams[ifile->ist_index + i];
-                    score = ist->st->codecpar->channels
+                    score = ist->st->codecpar->ch_layout.nb_channels
                             + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
                             + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
                     if (ist->user_set_discard == AVDISCARD_ALL)
@@ -2651,10 +2656,10 @@ loop_end:
                 } else {
                     f->sample_rates = ost->enc->supported_samplerates;
                 }
-                if (ost->enc_ctx->channels) {
-                    f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels);
-                } else {
-                    f->channel_layouts = ost->enc->channel_layouts;
+                if (ost->enc_ctx->ch_layout.nb_channels) {
+                    av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
+                } else if (ost->enc->ch_layouts) {
+                    f->ch_layouts = ost->enc->ch_layouts;
                 }
                 break;
             }
@@ -3237,6 +3242,41 @@ static int opt_timecode(void *optctx, const char *opt, const char *arg)
     return ret;
 }
 
+static int opt_ch_layout(void *optctx, const char *opt, const char *arg)
+{
+    OptionsContext *o = optctx;
+    char layout_str[32];
+    char *stream_str;
+    char *ac_str;
+    int ret, ac_str_size;
+    AVChannelLayout layout = { 0 };
+
+    ret = av_channel_layout_from_string(&layout, arg);
+    if (ret < 0) {
+        av_log(NULL, AV_LOG_ERROR, "Unknown channel layout: %s\n", arg);
+        return AVERROR(EINVAL);
+    }
+    ret = opt_default_new(o, opt, arg);
+    if (ret < 0)
+        return ret;
+
+    /* set 'ac' option based on channel layout */
+    snprintf(layout_str, sizeof(layout_str), "%d", layout.nb_channels);
+    stream_str = strchr(opt, ':');
+    ac_str_size = 3 + (stream_str ? strlen(stream_str) : 0);
+    ac_str = av_mallocz(ac_str_size);
+    if (!ac_str)
+        return AVERROR(ENOMEM);
+    av_strlcpy(ac_str, "ac", 3);
+    if (stream_str)
+        av_strlcat(ac_str, stream_str, ac_str_size);
+    ret = parse_option(o, ac_str, layout_str, options);
+    av_free(ac_str);
+
+    return ret;
+}
+
+#if FF_API_OLD_CHANNEL_LAYOUT
 static int opt_channel_layout(void *optctx, const char *opt, const char *arg)
 {
     OptionsContext *o = optctx;
@@ -3272,6 +3312,7 @@ static int opt_channel_layout(void *optctx, const char *opt, const char *arg)
 
     return ret;
 }
+#endif
 
 static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
 {
@@ -3818,9 +3859,14 @@ const OptionDef options[] = {
     { "sample_fmt",     OPT_AUDIO | HAS_ARG  | OPT_EXPERT | OPT_SPEC |
                         OPT_STRING | OPT_INPUT | OPT_OUTPUT,                       { .off = OFFSET(sample_fmts) },
         "set sample format", "format" },
+    { "ch_layout",      OPT_AUDIO | HAS_ARG  | OPT_EXPERT | OPT_PERFILE |
+                        OPT_INPUT | OPT_OUTPUT,                                    { .func_arg = opt_ch_layout },
+        "set channel layout", "layout" },
+#if FF_API_OLD_CHANNEL_LAYOUT
     { "channel_layout", OPT_AUDIO | HAS_ARG  | OPT_EXPERT | OPT_PERFILE |
                         OPT_INPUT | OPT_OUTPUT,                                    { .func_arg = opt_channel_layout },
-        "set channel layout", "layout" },
+        "deprecated, use -ch_layout", "layout" },
+#endif
     { "af",             OPT_AUDIO | HAS_ARG  | OPT_PERFILE | OPT_OUTPUT,           { .func_arg = opt_audio_filters },
         "set audio filters", "filter_graph" },
     { "guess_layout_max", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(guess_layout_max) },
diff --git a/tests/fate/aac.mak b/tests/fate/aac.mak
index 1743428f54..d8750b093a 100644
--- a/tests/fate/aac.mak
+++ b/tests/fate/aac.mak
@@ -237,7 +237,7 @@ fate-aac-latm_000000001180bc60: CMD = pcm -i $(TARGET_SAMPLES)/aac/latm_00000000
 fate-aac-latm_000000001180bc60: REF = $(SAMPLES)/aac/latm_000000001180bc60.s16
 
 FATE_AAC_LATM += fate-aac-latm_stereo_to_51
-fate-aac-latm_stereo_to_51: CMD = pcm -i $(TARGET_SAMPLES)/aac/latm_stereo_to_51.ts -channel_layout 5.1
+fate-aac-latm_stereo_to_51: CMD = pcm -i $(TARGET_SAMPLES)/aac/latm_stereo_to_51.ts -ch_layout 5.1
 fate-aac-latm_stereo_to_51: REF = $(SAMPLES)/aac/latm_stereo_to_51_ref.s16
 
 fate-aac-autobsf-adtstoasc: CMD = transcode "aac" $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts \
diff --git a/tests/fate/lavf-container.mak b/tests/fate/lavf-container.mak
index 9e0eed4851..446a0cfbe2 100644
--- a/tests/fate/lavf-container.mak
+++ b/tests/fate/lavf-container.mak
@@ -26,7 +26,7 @@ $(FATE_LAVF_CONTAINER): $(AREF) $(VREF)
 
 fate-lavf-asf: CMD = lavf_container "" "-c:a mp2 -ar 44100" "-r 25"
 fate-lavf-avi fate-lavf-nut: CMD = lavf_container "" "-c:a mp2 -ar 44100 -threads 1"
-fate-lavf-dv:  CMD = lavf_container "-ar 48000 -channel_layout stereo" "-r 25 -s pal"
+fate-lavf-dv:  CMD = lavf_container "-ar 48000 -ch_layout stereo" "-r 25 -s pal"
 fate-lavf-dv_pal:  CMD = lavf_container_timecode_nodrop "-ar 48000 -r 25 -s pal -ac 2 -f dv"
 fate-lavf-dv_ntsc:  CMD = lavf_container_timecode_drop "-ar 48000 -pix_fmt yuv411p -s ntsc -ac 2 -f dv"
 fate-lavf-flv fate-lavf-swf: CMD = lavf_container "" "-an"
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 278/281] ffprobe: convert to new channel layout-API
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (278 preceding siblings ...)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API James Almer
@ 2022-01-13  2:09 ` James Almer
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 279/281] channel_layout: add support for Ambisonic James Almer
                   ` (2 subsequent siblings)
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

Signed-off-by: James Almer <jamrial@gmail.com>
---
 fftools/ffprobe.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 20582ca7ac..aff9b880cc 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -2462,12 +2462,10 @@ static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream,
         if (s) print_str    ("sample_fmt", s);
         else   print_str_opt("sample_fmt", "unknown");
         print_int("nb_samples",         frame->nb_samples);
-        print_int("channels", frame->channels);
-        if (frame->channel_layout) {
-            av_bprint_clear(&pbuf);
-            av_bprint_channel_layout(&pbuf, frame->channels,
-                                     frame->channel_layout);
-            print_str    ("channel_layout", pbuf.str);
+        print_int("channels", frame->ch_layout.nb_channels);
+        if (frame->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
+            av_channel_layout_describe(&frame->ch_layout, val_str, sizeof(val_str));
+            print_str    ("channel_layout", val_str);
         } else
             print_str_opt("channel_layout", "unknown");
         break;
@@ -2873,12 +2871,11 @@ static int show_stream(WriterContext *w, AVFormatContext *fmt_ctx, int stream_id
         if (s) print_str    ("sample_fmt", s);
         else   print_str_opt("sample_fmt", "unknown");
         print_val("sample_rate",     par->sample_rate, unit_hertz_str);
-        print_int("channels",        par->channels);
+        print_int("channels",        par->ch_layout.nb_channels);
 
-        if (par->channel_layout) {
-            av_bprint_clear(&pbuf);
-            av_bprint_channel_layout(&pbuf, par->channels, par->channel_layout);
-            print_str    ("channel_layout", pbuf.str);
+        if (par->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
+            av_channel_layout_describe(&par->ch_layout, val_str, sizeof(val_str));
+            print_str    ("channel_layout", val_str);
         } else {
             print_str_opt("channel_layout", "unknown");
         }
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 279/281] channel_layout: add support for Ambisonic
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (279 preceding siblings ...)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 278/281] ffprobe: " James Almer
@ 2022-01-13  2:09 ` James Almer
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 280/281] opus: export mapping family 2 (Ambisonic) as Ambisonic layout James Almer
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 281/281] mov: Implement spatial audio support James Almer
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/channel_layout.c       | 166 ++++++++++++++++++++++++++++++-
 libavutil/channel_layout.h       |  52 +++++++++-
 libavutil/tests/channel_layout.c |  20 ++++
 tests/ref/fate/channel_layout    |  13 +++
 4 files changed, 247 insertions(+), 4 deletions(-)

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index 68b40cc37c..3863e50e91 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -31,6 +31,9 @@
 #include "bprint.h"
 #include "common.h"
 
+#define CHAN_IS_AMBI(x) ((x) >= AV_CHAN_AMBISONIC_BASE &&\
+                         (x) <= AV_CHAN_AMBISONIC_END)
+
 struct channel_name {
     const char *name;
     const char *description;
@@ -81,7 +84,10 @@ void av_channel_name_bprint(AVBPrint *bp, enum AVChannel channel_id)
 {
     av_bprint_clear(bp);
 
-    if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names))
+    if (channel_id >= AV_CHAN_AMBISONIC_BASE &&
+        channel_id <= AV_CHAN_AMBISONIC_END)
+        av_bprintf(bp, "AMBI%d", channel_id - AV_CHAN_AMBISONIC_BASE);
+    else if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names))
         av_bprintf(bp, "%s", channel_names[channel_id].name);
     else
         av_bprintf(bp, "USR%d", channel_id);
@@ -104,7 +110,10 @@ void av_channel_description_bprint(AVBPrint *bp, enum AVChannel channel_id)
 {
     av_bprint_clear(bp);
 
-    if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names))
+    if (channel_id >= AV_CHAN_AMBISONIC_BASE &&
+        channel_id <= AV_CHAN_AMBISONIC_END)
+        av_bprintf(bp, "ambisonic ACN %d", channel_id - AV_CHAN_AMBISONIC_BASE);
+    else if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names))
         av_bprintf(bp, "%s", channel_names[channel_id].description);
     else
         av_bprintf(bp, "user %d", channel_id);
@@ -128,6 +137,14 @@ enum AVChannel av_channel_from_string(const char *str)
     int i;
     char *endptr = (char *)str;
     enum AVChannel id = AV_CHAN_NONE;
+
+    if (!strncmp(str, "AMBI", 4)) {
+        i = strtol(str + 4, NULL, 0);
+        if (i < 0 || i > AV_CHAN_AMBISONIC_END - AV_CHAN_AMBISONIC_BASE)
+            return AV_CHAN_NONE;
+        return AV_CHAN_AMBISONIC_BASE + i;
+    }
+
     for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) {
         if (channel_names[i].name && !strcmp(str, channel_names[i].name))
             return i;
@@ -395,6 +412,60 @@ int av_channel_layout_from_string(AVChannelLayout *channel_layout,
         }
     }
 
+    /* ambisonic */
+    if (!strncmp(str, "ambisonic ", 10)) {
+        const char *p = str + 10;
+        char *endptr;
+        AVChannelLayout extra = {0};
+        int order;
+
+        order = strtol(p, &endptr, 0);
+        if (order < 0 || order + 1  > INT_MAX / (order + 1) ||
+            (*endptr && *endptr != '+'))
+            return AVERROR(EINVAL);
+
+        channel_layout->order       = AV_CHANNEL_ORDER_AMBISONIC;
+        channel_layout->nb_channels = (order + 1) * (order + 1);
+
+        if (*endptr) {
+            int ret = av_channel_layout_from_string(&extra, endptr + 1);
+            if (ret < 0)
+                return ret;
+            if (extra.nb_channels >= INT_MAX - channel_layout->nb_channels) {
+                av_channel_layout_uninit(&extra);
+                return AVERROR(EINVAL);
+            }
+
+            if (extra.order == AV_CHANNEL_ORDER_NATIVE) {
+                channel_layout->u.mask = extra.u.mask;
+            } else {
+                channel_layout->order = AV_CHANNEL_ORDER_CUSTOM;
+                channel_layout->u.map =
+                    av_calloc(channel_layout->nb_channels + extra.nb_channels,
+                              sizeof(*channel_layout->u.map));
+                if (!channel_layout->u.map) {
+                    av_channel_layout_uninit(&extra);
+                    return AVERROR(ENOMEM);
+                }
+
+                for (i = 0; i < channel_layout->nb_channels; i++)
+                    channel_layout->u.map[i].id = AV_CHAN_AMBISONIC_BASE + i;
+                for (i = 0; i < extra.nb_channels; i++) {
+                    enum AVChannel ch = av_channel_layout_channel_from_index(&extra, i);
+                    if (CHAN_IS_AMBI(ch)) {
+                        av_channel_layout_uninit(&extra);
+                        return AVERROR(EINVAL);
+                    }
+                    channel_layout->u.map[channel_layout->nb_channels + i].id = ch;
+                }
+            }
+            channel_layout->nb_channels += extra.nb_channels;
+            av_channel_layout_uninit(&extra);
+        }
+
+        return 0;
+    }
+
     /* channel names */
     while (*dup) {
         char *chname = av_get_token(&dup, "+");
@@ -526,6 +597,77 @@ int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
     return 0;
 }
 
+/**
+ * If the custom layout is n-th order standard-order ambisonic, with optional
+ * extra non-diegetic channels at the end, write its string description in bp.
+ * Return a negative error code on error.
+ */
+static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout)
+{
+    int i, highest_ambi, order;
+
+    highest_ambi = -1;
+    if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC)
+        highest_ambi = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask) - 1;
+    else {
+        const AVChannelCustom *map = channel_layout->u.map;
+        for (i = 0; i < channel_layout->nb_channels; i++) {
+            int is_ambi = CHAN_IS_AMBI(map[i].id);
+
+            /* ambisonic following non-ambisonic */
+            if (i > 0 && is_ambi && !CHAN_IS_AMBI(map[i - 1].id))
+                return 0;
+
+            /* non-default ordering */
+            if (is_ambi && map[i].id - AV_CHAN_AMBISONIC_BASE != i)
+                return 0;
+
+            if (CHAN_IS_AMBI(map[i].id))
+                highest_ambi = i;
+        }
+    }
+    /* no ambisonic channels*/
+    if (highest_ambi < 0)
+        return 0;
+
+    order = floor(sqrt(highest_ambi));
+    /* incomplete order - some harmonics are missing */
+    if ((order + 1) * (order + 1) != highest_ambi + 1)
+        return 0;
+
+    av_bprintf(bp, "ambisonic %d", order);
+
+    /* extra channels present */
+    if (highest_ambi < channel_layout->nb_channels - 1) {
+        AVChannelLayout extra = { 0 };
+        char buf[128];
+
+        if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) {
+            extra.order       = AV_CHANNEL_ORDER_NATIVE;
+            extra.nb_channels = av_popcount64(channel_layout->u.mask);
+            extra.u.mask      = channel_layout->u.mask;
+        } else {
+            const AVChannelCustom *map = channel_layout->u.map;
+
+            extra.order       = AV_CHANNEL_ORDER_CUSTOM;
+            extra.nb_channels = channel_layout->nb_channels - highest_ambi - 1;
+            extra.u.map       = av_calloc(extra.nb_channels, sizeof(*extra.u.map));
+            if (!extra.u.map)
+                return AVERROR(ENOMEM);
+
+            memcpy(extra.u.map, &map[highest_ambi + 1],
+                   sizeof(*extra.u.map) * extra.nb_channels);
+        }
+
+        av_channel_layout_describe(&extra, buf, sizeof(buf));
+        av_channel_layout_uninit(&extra);
+
+        av_bprintf(bp, "+%s", buf);
+    }
+
+    return 0;
+}
+
 int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout,
                                       AVBPrint *bp)
 {
@@ -542,6 +684,11 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout,
             }
         // fall-through
     case AV_CHANNEL_ORDER_CUSTOM:
+        if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) {
+            int res = try_describe_ambisonic(bp, channel_layout);
+            if (res < 0 || bp->len)
+                return res;
+        }
         for (i = 0; i < channel_layout->nb_channels; i++) {
             const char *ch_name = NULL;
             enum AVChannel ch = AV_CHAN_NONE;
@@ -567,6 +714,8 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout,
     case AV_CHANNEL_ORDER_UNSPEC:
         av_bprintf(bp, "%d channels", channel_layout->nb_channels);
         return 0;
+    case AV_CHANNEL_ORDER_AMBISONIC:
+        return try_describe_ambisonic(bp, channel_layout);
     default:
         return AVERROR(EINVAL);
     }
@@ -601,6 +750,8 @@ av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout,
     switch (channel_layout->order) {
     case AV_CHANNEL_ORDER_CUSTOM:
         return channel_layout->u.map[idx].id;
+    case AV_CHANNEL_ORDER_AMBISONIC:
+        return AV_CHAN_AMBISONIC_BASE + idx;
     case AV_CHANNEL_ORDER_NATIVE:
         for (i = 0; i < 64; i++) {
             if ((1ULL << i) & channel_layout->u.mask && !idx--)
@@ -651,6 +802,11 @@ int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout,
             if (channel_layout->u.map[i].id == channel)
                 return i;
         return AVERROR(EINVAL);
+    case AV_CHANNEL_ORDER_AMBISONIC:
+        if (!CHAN_IS_AMBI(channel) ||
+            channel - AV_CHAN_AMBISONIC_BASE >= channel_layout->nb_channels)
+            return AVERROR(EINVAL);
+        return channel - AV_CHAN_AMBISONIC_BASE;
     case AV_CHANNEL_ORDER_NATIVE: {
         uint64_t mask = channel_layout->u.mask;
         if (!(mask & (1ULL << channel)))
@@ -701,6 +857,9 @@ int av_channel_layout_check(const AVChannelLayout *channel_layout)
                 return 0;
         }
         return 1;
+    case AV_CHANNEL_ORDER_AMBISONIC:
+        /* If non-diegetic channels are present, ensure they are taken into account */
+        return av_popcount64(channel_layout->u.mask) < channel_layout->nb_channels;
     case AV_CHANNEL_ORDER_UNSPEC:
         return 1;
     default:
@@ -725,7 +884,8 @@ int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout
         return 0;
 
     /* can compare masks directly */
-    if (chl->order != AV_CHANNEL_ORDER_CUSTOM &&
+    if ((chl->order == AV_CHANNEL_ORDER_NATIVE ||
+         chl->order == AV_CHANNEL_ORDER_AMBISONIC) &&
         chl->order == chl1->order)
         return chl->u.mask != chl1->u.mask;
 
diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h
index 6356a9a38a..b7e709a022 100644
--- a/libavutil/channel_layout.h
+++ b/libavutil/channel_layout.h
@@ -79,6 +79,23 @@ enum AVChannel {
 
     /** Channel contains data, but its position is unknown. */
     AV_CHAN_UNKWNOWN = 128,
+
+    /**
+     * Range of channels between AV_CHAN_AMBISONIC_BASE and
+     * AV_CHAN_AMBISONIC_END represent Ambisonic components using the ACN system.
+     *
+     * Given a channel id <i> between AV_CHAN_AMBISONIC_BASE and
+     * AV_CHAN_AMBISONIC_END (inclusive), the ACN index of the channel <n> is
+     * <n> = <i> - AV_CHAN_AMBISONIC_BASE.
+     *
+     * @note these values are only used for AV_CHANNEL_ORDER_CUSTOM channel
+     * orderings, the AV_CHANNEL_ORDER_AMBISONIC ordering orders the channels
+     * implicitly by their position in the stream.
+     */
+    AV_CHAN_AMBISONIC_BASE = 0x400,
+    // leave space for 1024 ids, which correspond to maximum order-32 harmonics,
+    // which should be enough for the foreseeable use cases
+    AV_CHAN_AMBISONIC_END  = 0x7ff,
 };
 
 enum AVChannelOrder {
@@ -100,6 +117,29 @@ enum AVChannelOrder {
      * channels at arbitrary positions.
      */
     AV_CHANNEL_ORDER_CUSTOM,
+    /**
+     * The audio is represented as the decomposition of the sound field into
+     * spherical harmonics. Each channel corresponds to a single expansion
+     * component. Channels are ordered according to ACN (Ambisonic Channel
+     * Number).
+     *
+     * The channel with the index n in the stream contains the spherical
+     * harmonic of degree l and order m given by
+     * @code{.unparsed}
+     *   l   = floor(sqrt(n)),
+     *   m   = n - l * (l + 1).
+     * @endcode
+     *
+     * Conversely given a spherical harmonic of degree l and order m, the
+     * corresponding channel index n is given by
+     * @code{.unparsed}
+     *   n = l * (l + 1) + m.
+     * @endcode
+     *
+     * Normalization is assumed to be SN3D (Schmidt Semi-Normalization)
+     * as defined in AmbiX format $ 2.1.
+     */
+    AV_CHANNEL_ORDER_AMBISONIC,
 };
 
 
@@ -266,7 +306,8 @@ typedef struct AVChannelLayout {
      */
     union {
         /**
-         * This member must be used for AV_CHANNEL_ORDER_NATIVE.
+         * This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used
+         * for AV_CHANNEL_ORDER_AMBISONIC to signal non-diegetic channels.
          * It is a bitmask, where the position of each set bit means that the
          * AVChannel with the corresponding value is present.
          *
@@ -288,6 +329,11 @@ typedef struct AVChannelLayout {
          * I.e. when map[i].id is equal to AV_CHAN_FOO, then AV_CH_FOO is the
          * i-th channel in the audio data.
          *
+         * When map[i].id is in the range between AV_CHAN_AMBISONIC_BASE and
+         * AV_CHAN_AMBISONIC_END (inclusive), the channel contains an ambisonic
+         * component with ACN index (as defined above)
+         * n = map[i].id - AV_CHAN_AMBISONIC_BASE.
+         *
          * map[i].name may be filled with a 0-terminated string, in which case
          * it will be used for the purpose of identifying the channel with the
          * convenience functions below. Otherise it must be zeroed.
@@ -359,6 +405,8 @@ typedef struct AVChannelLayout {
     { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 2,  .u = { .mask = AV_CH_LAYOUT_STEREO_DOWNMIX }}
 #define AV_CHANNEL_LAYOUT_22POINT2 \
     { .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = 24, .u = { .mask = AV_CH_LAYOUT_22POINT2 }}
+#define AV_CHANNEL_LAYOUT_AMBISONIC_FIRST_ORDER \
+    { .order = AV_CHANNEL_ORDER_AMBISONIC, .nb_channels = 4, .u = { .mask = 0 }}
 
 struct AVBPrint;
 
@@ -554,6 +602,8 @@ int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask);
  *  - a hexadecimal value of a channel layout (eg. "0x4")
  *  - the number of channels with default layout (eg. "5c")
  *  - the number of unordered channels (eg. "4", "4C", or "4 channels")
+ *  - the ambisonic order followed by optional non-diegetic channels (eg.
+ *    "ambisonic 2+stereo")
  *
  * @param channel_layout input channel layout
  * @param str string describing the channel layout
diff --git a/libavutil/tests/channel_layout.c b/libavutil/tests/channel_layout.c
index 7e6be0be17..b3318aed27 100644
--- a/libavutil/tests/channel_layout.c
+++ b/libavutil/tests/channel_layout.c
@@ -66,6 +66,10 @@ int main(void)
     printf("With AV_CHAN_FRONT_RIGHT: %26s\n", bp.str);
     av_channel_name_bprint(&bp, 63);
     printf("With 63: %43s\n", bp.str);
+    av_channel_name_bprint(&bp, AV_CHAN_AMBISONIC_BASE);
+    printf("With AV_CHAN_AMBISONIC_BASE: %23s\n", bp.str);
+    av_channel_name_bprint(&bp, AV_CHAN_AMBISONIC_END);
+    printf("With AV_CHAN_AMBISONIC_END: %24s\n", bp.str);
 
     printf("Testing av_channel_description\n");
     av_channel_description_bprint(&bp, AV_CHAN_FRONT_LEFT);
@@ -74,11 +78,17 @@ int main(void)
     printf("With AV_CHAN_FRONT_RIGHT: %26s\n", bp.str);
     av_channel_description_bprint(&bp, 63);
     printf("With 63: %43s\n", bp.str);
+    av_channel_description_bprint(&bp, AV_CHAN_AMBISONIC_BASE);
+    printf("With AV_CHAN_AMBISONIC_BASE: %23s\n", bp.str);
+    av_channel_description_bprint(&bp, AV_CHAN_AMBISONIC_END);
+    printf("With AV_CHAN_AMBISONIC_END: %24s\n", bp.str);
 
     printf("\nTesting av_channel_from_string\n");
     printf("With \"FL\": %41d\n", av_channel_from_string("FL"));
     printf("With \"FR\": %41d\n", av_channel_from_string("FR"));
     printf("With \"USR63\": %38d\n", av_channel_from_string("USR63"));
+    printf("With \"AMBI0\": %38d\n", av_channel_from_string("AMBI0"));
+    printf("With \"AMBI1023\": %35d\n", av_channel_from_string("AMBI1023"));
 
     printf("\n==Native layouts==\n");
 
@@ -177,6 +187,8 @@ int main(void)
     printf("\nTesting av_channel_layout_from_string\n");
     CHANNEL_LAYOUT_FROM_STRING(custom, "FL+FR+FC+BL+BR+LFE");
     printf("With \"FL+FR+FC+BL+BR+LFE\": %25s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(custom, "ambisonic 1+FR+FL");
+    printf("With \"ambisonic 1+FR+FL\": %26s\n", bp.str);
     CHANNEL_LAYOUT_FROM_STRING(custom, "FR+FL+USR63");
     printf("With \"FR+FL+USR63\" layout: %25s\n", bp.str);
 
@@ -225,6 +237,14 @@ int main(void)
     CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(custom, 3);
     printf("On \"FR+FL+USR63\" layout with 3: %20d\n", ret);
 
+    printf("\n==Ambisonic layouts==\n");
+
+    printf("\nTesting av_channel_layout_from_string\n");
+    CHANNEL_LAYOUT_FROM_STRING(custom, "ambisonic 1");
+    printf("With \"ambisonic 1\": %32s\n", bp.str);
+    CHANNEL_LAYOUT_FROM_STRING(custom, "ambisonic 2+stereo");
+    printf("With \"ambisonic 2+stereo\": %25s\n", bp.str);
+
     av_channel_layout_uninit(&surround);
     av_channel_layout_uninit(&custom);
     av_bprint_finalize(&bp, NULL);
diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout
index bac00086d6..4614934028 100644
--- a/tests/ref/fate/channel_layout
+++ b/tests/ref/fate/channel_layout
@@ -2,15 +2,21 @@ Testing av_channel_name
 With AV_CHAN_FRONT_LEFT:                          FL
 With AV_CHAN_FRONT_RIGHT:                         FR
 With 63:                                       USR63
+With AV_CHAN_AMBISONIC_BASE:                   AMBI0
+With AV_CHAN_AMBISONIC_END:                 AMBI1023
 Testing av_channel_description
 With AV_CHAN_FRONT_LEFT:                  front left
 With AV_CHAN_FRONT_RIGHT:                front right
 With 63:                                     user 63
+With AV_CHAN_AMBISONIC_BASE:         ambisonic ACN 0
+With AV_CHAN_AMBISONIC_END:       ambisonic ACN 1023
 
 Testing av_channel_from_string
 With "FL":                                         0
 With "FR":                                         1
 With "USR63":                                     63
+With "AMBI0":                                   1024
+With "AMBI1023":                                2047
 
 ==Native layouts==
 
@@ -69,6 +75,7 @@ On 5.1(side) layout with "BC":                    -1
 
 Testing av_channel_layout_from_string
 With "FL+FR+FC+BL+BR+LFE":        FL+FR+FC+BL+BR+LFE
+With "ambisonic 1+FR+FL":          ambisonic 1+FR+FL
 With "FR+FL+USR63" layout:               FR+FL+USR63
 
 Testing av_channel_layout_index_from_string
@@ -96,3 +103,9 @@ On "FR+FL+USR63" layout with 0:                    1
 On "FR+FL+USR63" layout with 1:                    0
 On "FR+FL+USR63" layout with 2:                   63
 On "FR+FL+USR63" layout with 3:                   -1
+
+==Ambisonic layouts==
+
+Testing av_channel_layout_from_string
+With "ambisonic 1":                      ambisonic 1
+With "ambisonic 2+stereo":        ambisonic 2+stereo
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 280/281] opus: export mapping family 2 (Ambisonic) as Ambisonic layout
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (280 preceding siblings ...)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 279/281] channel_layout: add support for Ambisonic James Almer
@ 2022-01-13  2:09 ` James Almer
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 281/281] mov: Implement spatial audio support James Almer
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/opus.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/libavcodec/opus.c b/libavcodec/opus.c
index c18ff47f71..474ae427aa 100644
--- a/libavcodec/opus.c
+++ b/libavcodec/opus.c
@@ -398,8 +398,22 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
                 ret = AVERROR_INVALIDDATA;
                 goto fail;
             }
-            layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+
             layout.nb_channels = channels;
+            if (channels == (ambisonic_order + 1) * (ambisonic_order + 1)) {
+                layout.order = AV_CHANNEL_ORDER_AMBISONIC;
+            } else {
+                layout.order = AV_CHANNEL_ORDER_CUSTOM;
+                layout.u.map = av_mallocz_array(channels, sizeof(*layout.u.map));
+                if (!layout.u.map) {
+                    ret = AVERROR(ENOMEM);
+                    goto fail;
+                }
+                for (i = 0; i < channels - 2; i++)
+                    layout.u.map[i].id = AV_CHAN_AMBISONIC_BASE + i;
+                layout.u.map[channels - 2].id = AV_CHAN_FRONT_LEFT;
+                layout.u.map[channels - 1].id = AV_CHAN_FRONT_RIGHT;
+            }
         } else {
             layout.order       = AV_CHANNEL_ORDER_UNSPEC;
             layout.nb_channels = channels;
@@ -450,8 +464,10 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
         }
     }
 
-    av_channel_layout_uninit(&avctx->ch_layout);
-    avctx->ch_layout = layout;
+    ret = av_channel_layout_copy(&avctx->ch_layout, &layout);
+    if (ret < 0)
+        goto fail;
+
     s->nb_streams         = streams;
     s->nb_stereo_streams  = stereo_streams;
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* [FFmpeg-devel] [PATCH 281/281] mov: Implement spatial audio support
  2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
                   ` (281 preceding siblings ...)
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 280/281] opus: export mapping family 2 (Ambisonic) as Ambisonic layout James Almer
@ 2022-01-13  2:09 ` James Almer
  282 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-13  2:09 UTC (permalink / raw)
  To: ffmpeg-devel

From: Vittorio Giovara <vittorio.giovara@gmail.com>

As defined by Google's Spatial Audio RFC.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mov.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index e307df8e3c..d6d287262d 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7193,6 +7193,100 @@ cleanup:
     return ret;
 }
 
+static int mov_read_SA3D(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    AVStream *st;
+    int i, version, type;
+    int ambisonic_order, channel_order, normalization, channel_count;
+
+    if (c->fc->nb_streams < 1)
+        return 0;
+
+    st = c->fc->streams[c->fc->nb_streams - 1];
+
+    if (atom.size < 16) {
+        av_log(c->fc, AV_LOG_ERROR, "SA3D audio box too small\n");
+        return AVERROR_INVALIDDATA;
+    }
+
+    version = avio_r8(pb);
+    if (version) {
+        av_log(c->fc, AV_LOG_WARNING, "Unsupported SA3D box version %d\n", version);
+        return 0;
+    }
+
+    type = avio_r8(pb);
+    if (type) {
+        av_log(c->fc, AV_LOG_WARNING,
+               "Unsupported ambisonic type %d\n", type);
+        return 0;
+    }
+
+    ambisonic_order = avio_rb32(pb);
+
+    channel_order = avio_r8(pb);
+    if (channel_order) {
+        av_log(c->fc, AV_LOG_WARNING,
+               "Unsupported channel_order %d\n", channel_order);
+        return 0;
+    }
+
+    normalization = avio_r8(pb);
+    if (normalization) {
+        av_log(c->fc, AV_LOG_WARNING,
+               "Unsupported normalization %d\n", normalization);
+        return 0;
+    }
+
+    channel_count = avio_rb32(pb);
+    if (channel_count != (ambisonic_order + 1) * (ambisonic_order + 1)) {
+        av_log(c->fc, AV_LOG_ERROR,
+               "Invalid number of channels (%d / %d)\n",
+               channel_count, ambisonic_order);
+        return 0;
+    }
+
+    for (i = 0; i < channel_count; i++) {
+        if (i != avio_rb32(pb)) {
+            av_log(c->fc, AV_LOG_WARNING,
+                   "Ambisonic channel reordering is not supported\n");
+            return 0;
+        }
+    }
+
+    av_channel_layout_uninit(&st->codecpar->ch_layout);
+    st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_AMBISONIC;
+    st->codecpar->ch_layout.nb_channels = channel_count;
+
+    return 0;
+}
+
+static int mov_read_SAND(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    AVStream *st;
+    int version;
+
+    if (c->fc->nb_streams < 1)
+        return 0;
+
+    st = c->fc->streams[c->fc->nb_streams - 1];
+
+    if (atom.size < 5) {
+        av_log(c->fc, AV_LOG_ERROR, "Empty SAND audio box\n");
+        return AVERROR_INVALIDDATA;
+    }
+
+    version = avio_r8(pb);
+    if (version) {
+        av_log(c->fc, AV_LOG_WARNING, "Unsupported SAND box version %d\n", version);
+        return 0;
+    }
+
+    st->disposition |= AV_DISPOSITION_NON_DIEGETIC;
+
+    return 0;
+}
+
 static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('A','C','L','R'), mov_read_aclr },
 { MKTAG('A','P','R','G'), mov_read_avid },
@@ -7292,6 +7386,8 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('d','v','v','C'), mov_read_dvcc_dvvc },
 { MKTAG('d','v','w','C'), mov_read_dvcc_dvvc },
 { MKTAG('k','i','n','d'), mov_read_kind },
+{ MKTAG('S','A','3','D'), mov_read_SA3D }, /* ambisonic audio box */
+{ MKTAG('S','A','N','D'), mov_read_SAND }, /* non diegetic audio box */
 { 0, NULL }
 };
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 001/281] Add a new " James Almer
@ 2022-01-13 14:08   ` Lynne
  2022-01-16 11:27   ` Nicolas George
  1 sibling, 0 replies; 337+ messages in thread
From: Lynne @ 2022-01-13 14:08 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

13 Jan 2022, 02:49 by jamrial@gmail.com:

> From: Anton Khirnov <anton@khirnov.net>
>
> The new API is more extensible and allows for custom layouts.
> More accurate information is exported, eg for decoders that do not
> set a channel layout, lavc will not make one up for them.
>
> Deprecate the old API working with just uint64_t bitmasks.
>
> Expanded and completed by Vittorio Giovara <vittorio.giovara@gmail.com>
> and James Almer <jamrial@gmail.com>.
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavutil/channel_layout.c | 629 ++++++++++++++++++++++++++++++++-----
>  libavutil/channel_layout.h | 542 ++++++++++++++++++++++++++++++--
>  libavutil/version.h        |   1 +
>  3 files changed, 1069 insertions(+), 103 deletions(-)
>

API looks good to me now.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API James Almer
@ 2022-01-13 18:29   ` Michael Niedermayer
  2022-01-13 18:40     ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: Michael Niedermayer @ 2022-01-13 18:29 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 11012 bytes --]

On Wed, Jan 12, 2022 at 11:09:09PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  fftools/cmdutils.c            | 42 +++++++++++++++---------
>  fftools/cmdutils.h            |  8 -----
>  fftools/ffmpeg.c              | 47 ++++++++++++++++----------
>  fftools/ffmpeg.h              |  7 ++--
>  fftools/ffmpeg_filter.c       | 52 ++++++++++++++++++++++-------
>  fftools/ffmpeg_opt.c          | 62 ++++++++++++++++++++++++++++++-----
>  tests/fate/aac.mak            |  2 +-
>  tests/fate/lavf-container.mak |  2 +-
>  8 files changed, 155 insertions(+), 67 deletions(-)

This or a prior patch introduces crashes (it bisected to this but this is my
2nd testcase the first did not reproduce reliably at all)

Thread 1 "ffmpeg_g" received signal SIGSEGV, Segmentation fault.
0x00005555566ed811 in av_vlog (avcl=0x5555577400c0, level=24, fmt=0x5555568249e8 "%d frames left in the queue on closing\n", vl=0x7fffffffda50) at libavutil/log.c:428
428	    if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
(gdb) bt
#0  0x00005555566ed811 in av_vlog (avcl=0x5555577400c0, level=24, fmt=0x5555568249e8 "%d frames left in the queue on closing\n", vl=0x7fffffffda50) at libavutil/log.c:428
#1  0x00005555566ed6bd in av_log (avcl=0x5555577400c0, level=24, fmt=0x5555568249e8 "%d frames left in the queue on closing\n") at libavutil/log.c:411
#2  0x0000555555c320b9 in ff_af_queue_close (afq=0x5555576c47c8) at libavcodec/audio_frame_queue.c:39
#3  0x0000555555e84c06 in mp3lame_encode_close (avctx=0x5555576bf180) at libavcodec/libmp3lame.c:86
#4  0x0000555555c373f7 in avcodec_close (avctx=0x5555576bf180) at libavcodec/avcodec.c:489
#5  0x0000555555f7feab in avcodec_free_context (pavctx=0x5555576a8858) at libavcodec/options.c:163
#6  0x000055555569cfe3 in ffmpeg_cleanup (ret=1) at fftools/ffmpeg.c:608
#7  0x0000555555694817 in exit_program (ret=1) at fftools/cmdutils.c:131
#8  0x000055555569ef1f in do_audio_out (of=0x5555576ae2c0, ost=0x5555576a8800, frame=0x5555576bf580) at fftools/ffmpeg.c:1056
#9  0x00005555556a117a in reap_filters (flush=0) at fftools/ffmpeg.c:1546
#10 0x00005555556ad8e5 in transcode_step () at fftools/ffmpeg.c:4643
#11 0x00005555556ad9e7 in transcode () at fftools/ffmpeg.c:4687
#12 0x00005555556ae45c in main (argc=12, argv=0x7fffffffe1c8) at fftools/ffmpeg.c:4903
(gdb) print avc->version
Cannot access memory at address 0xc1528eb7c0ea0157

make -j32 && gdb --args ./ffmpeg_g -ss 8 -i NeroRecodeSample.mp4 -bitexact -t 3 -filter_complex '[0:2]scale=720:576[v];[v][0:5]overlay' -y file-whitesubs.avi

it appears this file is at:
https://samples.ffmpeg.org/MPEG-4/NeroRecodeSample-MP4/


Press [q] to stop, [?] for help
[aac @ 0x16fb3540] This stream seems to incorrectly report its last channel as SCE[1], mapping to LFE[0]
[aac @ 0x16fb3540] env_facs_q 253 is invalid
==21617==    at 0x12A09F8: VALGRIND_PRINTF_BACKTRACE (valgrind.h:6303)
==21617==    by 0x12A15B6: av_log_default_callback (log.c:397)
==21617==    by 0x12A185D: av_vlog (log.c:432)
==21617==    by 0x12A16BC: av_log (log.c:411)
==21617==    by 0xEED8B6: read_sbr_envelope (aacsbr_template.c:865)
==21617==    by 0xEEE22F: read_sbr_single_channel_element (aacsbr_template.c:983)
==21617==    by 0xEEE762: read_sbr_data (aacsbr_template.c:1055)
==21617==    by 0xEEEAFD: ff_decode_sbr_extension (aacsbr_template.c:1144)
==21617==    by 0xECD082: decode_extension_payload (aacdec_template.c:2582)
==21617==    by 0xED029B: aac_decode_frame_int (aacdec_template.c:3372)
==21617==    by 0xED0842: aac_decode_frame (aacdec_template.c:3500)
==21617==    by 0x8ABF66: decode_simple_internal (decode.c:329)
==21617==    by 0x8ACB62: decode_simple_receive_frame (decode.c:528)
==21617==    by 0x8ACC5C: decode_receive_frame_internal (decode.c:548)
==21617==    by 0x8ACF38: avcodec_send_packet (decode.c:615)
==21617==    by 0x258160: decode (ffmpeg.c:2276)
==21617==    by 0x258354: decode_audio (ffmpeg.c:2319)
==21617==    by 0x259949: process_input_packet (ffmpeg.c:2638)
==21617==    by 0x26138A: process_input (ffmpeg.c:4493)
==21617==    by 0x26187E: transcode_step (ffmpeg.c:4633)
[aac @ 0x16fb3540] env_facs_q 252 is invalid
==21617==    at 0x12A09F8: VALGRIND_PRINTF_BACKTRACE (valgrind.h:6303)
==21617==    by 0x12A15B6: av_log_default_callback (log.c:397)
==21617==    by 0x12A185D: av_vlog (log.c:432)
==21617==    by 0x12A16BC: av_log (log.c:411)
==21617==    by 0xEED8B6: read_sbr_envelope (aacsbr_template.c:865)
==21617==    by 0xEEE5AC: read_sbr_channel_pair_element (aacsbr_template.c:1028)
==21617==    by 0xEEE7A7: read_sbr_data (aacsbr_template.c:1060)
==21617==    by 0xEEEAFD: ff_decode_sbr_extension (aacsbr_template.c:1144)
==21617==    by 0xECD082: decode_extension_payload (aacdec_template.c:2582)
==21617==    by 0xED029B: aac_decode_frame_int (aacdec_template.c:3372)
==21617==    by 0xED0842: aac_decode_frame (aacdec_template.c:3500)
==21617==    by 0x8ABF66: decode_simple_internal (decode.c:329)
==21617==    by 0x8ACB62: decode_simple_receive_frame (decode.c:528)
==21617==    by 0x8ACC5C: decode_receive_frame_internal (decode.c:548)
==21617==    by 0x8ACF38: avcodec_send_packet (decode.c:615)
==21617==    by 0x258160: decode (ffmpeg.c:2276)
==21617==    by 0x258354: decode_audio (ffmpeg.c:2319)
==21617==    by 0x259949: process_input_packet (ffmpeg.c:2638)
==21617==    by 0x26138A: process_input (ffmpeg.c:4493)
==21617==    by 0x26187E: transcode_step (ffmpeg.c:4633)
[aac @ 0x16fb3540] noise_facs_q 255 is invalid
==21617==    at 0x12A09F8: VALGRIND_PRINTF_BACKTRACE (valgrind.h:6303)
==21617==    by 0x12A15B6: av_log_default_callback (log.c:397)
==21617==    by 0x12A185D: av_vlog (log.c:432)
==21617==    by 0x12A16BC: av_log (log.c:411)
==21617==    by 0xEEDE4D: read_sbr_noise (aacsbr_template.c:923)
==21617==    by 0xEEE615: read_sbr_channel_pair_element (aacsbr_template.c:1032)
==21617==    by 0xEEE7A7: read_sbr_data (aacsbr_template.c:1060)
==21617==    by 0xEEEAFD: ff_decode_sbr_extension (aacsbr_template.c:1144)
==21617==    by 0xECD082: decode_extension_payload (aacdec_template.c:2582)
==21617==    by 0xED029B: aac_decode_frame_int (aacdec_template.c:3372)
==21617==    by 0xED0842: aac_decode_frame (aacdec_template.c:3500)
==21617==    by 0x8ABF66: decode_simple_internal (decode.c:329)
==21617==    by 0x8ACB62: decode_simple_receive_frame (decode.c:528)
==21617==    by 0x8ACC5C: decode_receive_frame_internal (decode.c:548)
==21617==    by 0x8ACF38: avcodec_send_packet (decode.c:615)
==21617==    by 0x258160: decode (ffmpeg.c:2276)
==21617==    by 0x258354: decode_audio (ffmpeg.c:2319)
==21617==    by 0x259949: process_input_packet (ffmpeg.c:2638)
==21617==    by 0x26138A: process_input (ffmpeg.c:4493)
==21617==    by 0x26187E: transcode_step (ffmpeg.c:4633)
Audio encoding failed
==21617==    at 0x12A09F8: VALGRIND_PRINTF_BACKTRACE (valgrind.h:6303)
==21617==    by 0x12A15B6: av_log_default_callback (log.c:397)
==21617==    by 0x12A185D: av_vlog (log.c:432)
==21617==    by 0x12A16BC: av_log (log.c:411)
==21617==    by 0x252F14: do_audio_out (ffmpeg.c:1055)
==21617==    by 0x255179: reap_filters (ffmpeg.c:1546)
==21617==    by 0x2618E4: transcode_step (ffmpeg.c:4643)
==21617==    by 0x2619E6: transcode (ffmpeg.c:4687)
==21617==    by 0x26245B: main (ffmpeg.c:4903)
==21617== Invalid read of size 4
==21617==    at 0x12A1811: av_vlog (log.c:428)
==21617==    by 0x12A16BC: av_log (log.c:411)
==21617==    by 0x7E60B8: ff_af_queue_close (audio_frame_queue.c:39)
==21617==    by 0xA38C05: mp3lame_encode_close (libmp3lame.c:86)
==21617==    by 0x7EB3F6: avcodec_close (avcodec.c:489)
==21617==    by 0xB33EAA: avcodec_free_context (options.c:163)
==21617==    by 0x250FE2: ffmpeg_cleanup (ffmpeg.c:608)
==21617==    by 0x248816: exit_program (cmdutils.c:131)
==21617==    by 0x252F1E: do_audio_out (ffmpeg.c:1056)
==21617==    by 0x255179: reap_filters (ffmpeg.c:1546)
==21617==    by 0x2618E4: transcode_step (ffmpeg.c:4643)
==21617==    by 0x2619E6: transcode (ffmpeg.c:4687)
==21617==    by 0x26245B: main (ffmpeg.c:4903)
==21617==  Address 0xc1528eb7c0ea0157 is not stack'd, malloc'd or (recently) free'd
==21617== 
==21617== 
==21617== Process terminating with default action of signal 11 (SIGSEGV)
==21617==  General Protection Fault
==21617==    at 0x12A1811: av_vlog (log.c:428)
==21617==    by 0x12A16BC: av_log (log.c:411)
==21617==    by 0x7E60B8: ff_af_queue_close (audio_frame_queue.c:39)
==21617==    by 0xA38C05: mp3lame_encode_close (libmp3lame.c:86)
==21617==    by 0x7EB3F6: avcodec_close (avcodec.c:489)
==21617==    by 0xB33EAA: avcodec_free_context (options.c:163)
==21617==    by 0x250FE2: ffmpeg_cleanup (ffmpeg.c:608)
==21617==    by 0x248816: exit_program (cmdutils.c:131)
==21617==    by 0x252F1E: do_audio_out (ffmpeg.c:1056)
==21617==    by 0x255179: reap_filters (ffmpeg.c:1546)
==21617==    by 0x2618E4: transcode_step (ffmpeg.c:4643)
==21617==    by 0x2619E6: transcode (ffmpeg.c:4687)
==21617==    by 0x26245B: main (ffmpeg.c:4903)
==21617== 
==21617== HEAP SUMMARY:
==21617==     in use at exit: 3,463,746 bytes in 473 blocks
==21617==   total heap usage: 1,923 allocs, 1,450 frees, 9,590,510 bytes allocated
==21617== 
==21617== 5,888 bytes in 16 blocks are possibly lost in loss record 159 of 180
==21617==    at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==21617==    by 0x4013646: allocate_dtv (dl-tls.c:286)
==21617==    by 0x4013646: _dl_allocate_tls (dl-tls.c:530)
==21617==    by 0xCB4F227: allocate_stack (allocatestack.c:627)
==21617==    by 0xCB4F227: pthread_create@@GLIBC_2.2.5 (pthread_create.c:644)
==21617==    by 0xB6C3FB: init_thread (pthread_frame.c:842)
==21617==    by 0xB6C625: ff_frame_thread_init (pthread_frame.c:898)
==21617==    by 0xB69E97: ff_thread_init (pthread.c:81)
==21617==    by 0x7EAC52: avcodec_open2 (avcodec.c:330)
==21617==    by 0x25AA65: init_input_stream (ffmpeg.c:2922)
==21617==    by 0x25D48C: transcode_init (ffmpeg.c:3634)
==21617==    by 0x261924: transcode (ffmpeg.c:4658)
==21617==    by 0x26245B: main (ffmpeg.c:4903)
==21617== 
==21617== LEAK SUMMARY:
==21617==    definitely lost: 0 bytes in 0 blocks
==21617==    indirectly lost: 0 bytes in 0 blocks
==21617==      possibly lost: 5,888 bytes in 16 blocks
==21617==    still reachable: 3,457,858 bytes in 457 blocks
==21617==         suppressed: 0 bytes in 0 blocks
==21617== Reachable blocks (those to which a pointer was found) are not shown.
==21617== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==21617== 
==21617== For counts of detected and suppressed errors, rerun with: -v
==21617== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)


thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API
  2022-01-13 18:29   ` Michael Niedermayer
@ 2022-01-13 18:40     ` James Almer
  2022-01-13 19:44       ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13 18:40 UTC (permalink / raw)
  To: ffmpeg-devel

On 1/13/2022 3:29 PM, Michael Niedermayer wrote:
> On Wed, Jan 12, 2022 at 11:09:09PM -0300, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   fftools/cmdutils.c            | 42 +++++++++++++++---------
>>   fftools/cmdutils.h            |  8 -----
>>   fftools/ffmpeg.c              | 47 ++++++++++++++++----------
>>   fftools/ffmpeg.h              |  7 ++--
>>   fftools/ffmpeg_filter.c       | 52 ++++++++++++++++++++++-------
>>   fftools/ffmpeg_opt.c          | 62 ++++++++++++++++++++++++++++++-----
>>   tests/fate/aac.mak            |  2 +-
>>   tests/fate/lavf-container.mak |  2 +-
>>   8 files changed, 155 insertions(+), 67 deletions(-)
> 
> This or a prior patch introduces crashes (it bisected to this but this is my
> 2nd testcase the first did not reproduce reliably at all)
> 
> Thread 1 "ffmpeg_g" received signal SIGSEGV, Segmentation fault.
> 0x00005555566ed811 in av_vlog (avcl=0x5555577400c0, level=24, fmt=0x5555568249e8 "%d frames left in the queue on closing\n", vl=0x7fffffffda50) at libavutil/log.c:428

av_vlog() is where it crashes?

> 428	    if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
> (gdb) bt
> #0  0x00005555566ed811 in av_vlog (avcl=0x5555577400c0, level=24, fmt=0x5555568249e8 "%d frames left in the queue on closing\n", vl=0x7fffffffda50) at libavutil/log.c:428
> #1  0x00005555566ed6bd in av_log (avcl=0x5555577400c0, level=24, fmt=0x5555568249e8 "%d frames left in the queue on closing\n") at libavutil/log.c:411
> #2  0x0000555555c320b9 in ff_af_queue_close (afq=0x5555576c47c8) at libavcodec/audio_frame_queue.c:39
> #3  0x0000555555e84c06 in mp3lame_encode_close (avctx=0x5555576bf180) at libavcodec/libmp3lame.c:86
> #4  0x0000555555c373f7 in avcodec_close (avctx=0x5555576bf180) at libavcodec/avcodec.c:489
> #5  0x0000555555f7feab in avcodec_free_context (pavctx=0x5555576a8858) at libavcodec/options.c:163
> #6  0x000055555569cfe3 in ffmpeg_cleanup (ret=1) at fftools/ffmpeg.c:608
> #7  0x0000555555694817 in exit_program (ret=1) at fftools/cmdutils.c:131
> #8  0x000055555569ef1f in do_audio_out (of=0x5555576ae2c0, ost=0x5555576a8800, frame=0x5555576bf580) at fftools/ffmpeg.c:1056
> #9  0x00005555556a117a in reap_filters (flush=0) at fftools/ffmpeg.c:1546
> #10 0x00005555556ad8e5 in transcode_step () at fftools/ffmpeg.c:4643
> #11 0x00005555556ad9e7 in transcode () at fftools/ffmpeg.c:4687
> #12 0x00005555556ae45c in main (argc=12, argv=0x7fffffffe1c8) at fftools/ffmpeg.c:4903
> (gdb) print avc->version
> Cannot access memory at address 0xc1528eb7c0ea0157
> 
> make -j32 && gdb --args ./ffmpeg_g -ss 8 -i NeroRecodeSample.mp4 -bitexact -t 3 -filter_complex '[0:2]scale=720:576[v];[v][0:5]overlay' -y file-whitesubs.avi
> 
> it appears this file is at:
> https://samples.ffmpeg.org/MPEG-4/NeroRecodeSample-MP4/

I can't reproduce this on mingw64.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API
  2022-01-13 18:40     ` James Almer
@ 2022-01-13 19:44       ` James Almer
  2022-01-15 13:47         ` Michael Niedermayer
  0 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-13 19:44 UTC (permalink / raw)
  To: ffmpeg-devel



On 1/13/2022 3:40 PM, James Almer wrote:
> On 1/13/2022 3:29 PM, Michael Niedermayer wrote:
>> On Wed, Jan 12, 2022 at 11:09:09PM -0300, James Almer wrote:
>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>> ---
>>>   fftools/cmdutils.c            | 42 +++++++++++++++---------
>>>   fftools/cmdutils.h            |  8 -----
>>>   fftools/ffmpeg.c              | 47 ++++++++++++++++----------
>>>   fftools/ffmpeg.h              |  7 ++--
>>>   fftools/ffmpeg_filter.c       | 52 ++++++++++++++++++++++-------
>>>   fftools/ffmpeg_opt.c          | 62 ++++++++++++++++++++++++++++++-----
>>>   tests/fate/aac.mak            |  2 +-
>>>   tests/fate/lavf-container.mak |  2 +-
>>>   8 files changed, 155 insertions(+), 67 deletions(-)
>>
>> This or a prior patch introduces crashes (it bisected to this but this 
>> is my
>> 2nd testcase the first did not reproduce reliably at all)
>>
>> Thread 1 "ffmpeg_g" received signal SIGSEGV, Segmentation fault.
>> 0x00005555566ed811 in av_vlog (avcl=0x5555577400c0, level=24, 
>> fmt=0x5555568249e8 "%d frames left in the queue on closing\n", 
>> vl=0x7fffffffda50) at libavutil/log.c:428
> 
> av_vlog() is where it crashes?
> 
>> 428        if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
>> (gdb) bt
>> #0  0x00005555566ed811 in av_vlog (avcl=0x5555577400c0, level=24, 
>> fmt=0x5555568249e8 "%d frames left in the queue on closing\n", 
>> vl=0x7fffffffda50) at libavutil/log.c:428
>> #1  0x00005555566ed6bd in av_log (avcl=0x5555577400c0, level=24, 
>> fmt=0x5555568249e8 "%d frames left in the queue on closing\n") at 
>> libavutil/log.c:411
>> #2  0x0000555555c320b9 in ff_af_queue_close (afq=0x5555576c47c8) at 
>> libavcodec/audio_frame_queue.c:39
>> #3  0x0000555555e84c06 in mp3lame_encode_close (avctx=0x5555576bf180) 
>> at libavcodec/libmp3lame.c:86
>> #4  0x0000555555c373f7 in avcodec_close (avctx=0x5555576bf180) at 
>> libavcodec/avcodec.c:489
>> #5  0x0000555555f7feab in avcodec_free_context (pavctx=0x5555576a8858) 
>> at libavcodec/options.c:163
>> #6  0x000055555569cfe3 in ffmpeg_cleanup (ret=1) at fftools/ffmpeg.c:608
>> #7  0x0000555555694817 in exit_program (ret=1) at fftools/cmdutils.c:131
>> #8  0x000055555569ef1f in do_audio_out (of=0x5555576ae2c0, 
>> ost=0x5555576a8800, frame=0x5555576bf580) at fftools/ffmpeg.c:1056
>> #9  0x00005555556a117a in reap_filters (flush=0) at fftools/ffmpeg.c:1546
>> #10 0x00005555556ad8e5 in transcode_step () at fftools/ffmpeg.c:4643
>> #11 0x00005555556ad9e7 in transcode () at fftools/ffmpeg.c:4687
>> #12 0x00005555556ae45c in main (argc=12, argv=0x7fffffffe1c8) at 
>> fftools/ffmpeg.c:4903
>> (gdb) print avc->version
>> Cannot access memory at address 0xc1528eb7c0ea0157
>>
>> make -j32 && gdb --args ./ffmpeg_g -ss 8 -i NeroRecodeSample.mp4 
>> -bitexact -t 3 -filter_complex '[0:2]scale=720:576[v];[v][0:5]overlay' 
>> -y file-whitesubs.avi
>>
>> it appears this file is at:
>> https://samples.ffmpeg.org/MPEG-4/NeroRecodeSample-MP4/
> 
> I can't reproduce this on mingw64.

Does the following fix it for you?

> diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
> index 36ae57eb83..728005b840 100644
> --- a/libavcodec/libmp3lame.c
> +++ b/libavcodec/libmp3lame.c
> @@ -344,9 +344,15 @@ const AVCodec ff_libmp3lame_encoder = {
>                                                               AV_SAMPLE_FMT_S16P,
>                                                               AV_SAMPLE_FMT_NONE },
>      .supported_samplerates = libmp3lame_sample_rates,
> +#if FF_API_OLD_CHANNEL_LAYOUT
>      .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
>                                                    AV_CH_LAYOUT_STEREO,
>                                                    0 },
> +#endif
> +    .ch_layouts            = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_MONO,
> +                                                         AV_CHANNEL_LAYOUT_STEREO,
> +                                                         { 0 },
> +    },
>      .priv_class            = &libmp3lame_class,
>      .defaults              = libmp3lame_defaults,
>      .wrapper_name          = "libmp3lame",
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API
  2022-01-13 19:44       ` James Almer
@ 2022-01-15 13:47         ` Michael Niedermayer
  2022-01-15 16:04           ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: Michael Niedermayer @ 2022-01-15 13:47 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 4723 bytes --]

On Thu, Jan 13, 2022 at 04:44:55PM -0300, James Almer wrote:
> 
> 
> On 1/13/2022 3:40 PM, James Almer wrote:
> > On 1/13/2022 3:29 PM, Michael Niedermayer wrote:
> > > On Wed, Jan 12, 2022 at 11:09:09PM -0300, James Almer wrote:
> > > > Signed-off-by: James Almer <jamrial@gmail.com>
> > > > ---
> > > >   fftools/cmdutils.c            | 42 +++++++++++++++---------
> > > >   fftools/cmdutils.h            |  8 -----
> > > >   fftools/ffmpeg.c              | 47 ++++++++++++++++----------
> > > >   fftools/ffmpeg.h              |  7 ++--
> > > >   fftools/ffmpeg_filter.c       | 52 ++++++++++++++++++++++-------
> > > >   fftools/ffmpeg_opt.c          | 62 ++++++++++++++++++++++++++++++-----
> > > >   tests/fate/aac.mak            |  2 +-
> > > >   tests/fate/lavf-container.mak |  2 +-
> > > >   8 files changed, 155 insertions(+), 67 deletions(-)
> > > 
> > > This or a prior patch introduces crashes (it bisected to this but
> > > this is my
> > > 2nd testcase the first did not reproduce reliably at all)
> > > 
> > > Thread 1 "ffmpeg_g" received signal SIGSEGV, Segmentation fault.
> > > 0x00005555566ed811 in av_vlog (avcl=0x5555577400c0, level=24,
> > > fmt=0x5555568249e8 "%d frames left in the queue on closing\n",
> > > vl=0x7fffffffda50) at libavutil/log.c:428
> > 
> > av_vlog() is where it crashes?
> > 
> > > 428        if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
> > > (gdb) bt
> > > #0  0x00005555566ed811 in av_vlog (avcl=0x5555577400c0, level=24,
> > > fmt=0x5555568249e8 "%d frames left in the queue on closing\n",
> > > vl=0x7fffffffda50) at libavutil/log.c:428
> > > #1  0x00005555566ed6bd in av_log (avcl=0x5555577400c0, level=24,
> > > fmt=0x5555568249e8 "%d frames left in the queue on closing\n") at
> > > libavutil/log.c:411
> > > #2  0x0000555555c320b9 in ff_af_queue_close (afq=0x5555576c47c8) at
> > > libavcodec/audio_frame_queue.c:39
> > > #3  0x0000555555e84c06 in mp3lame_encode_close
> > > (avctx=0x5555576bf180) at libavcodec/libmp3lame.c:86
> > > #4  0x0000555555c373f7 in avcodec_close (avctx=0x5555576bf180) at
> > > libavcodec/avcodec.c:489
> > > #5  0x0000555555f7feab in avcodec_free_context
> > > (pavctx=0x5555576a8858) at libavcodec/options.c:163
> > > #6  0x000055555569cfe3 in ffmpeg_cleanup (ret=1) at fftools/ffmpeg.c:608
> > > #7  0x0000555555694817 in exit_program (ret=1) at fftools/cmdutils.c:131
> > > #8  0x000055555569ef1f in do_audio_out (of=0x5555576ae2c0,
> > > ost=0x5555576a8800, frame=0x5555576bf580) at fftools/ffmpeg.c:1056
> > > #9  0x00005555556a117a in reap_filters (flush=0) at fftools/ffmpeg.c:1546
> > > #10 0x00005555556ad8e5 in transcode_step () at fftools/ffmpeg.c:4643
> > > #11 0x00005555556ad9e7 in transcode () at fftools/ffmpeg.c:4687
> > > #12 0x00005555556ae45c in main (argc=12, argv=0x7fffffffe1c8) at
> > > fftools/ffmpeg.c:4903
> > > (gdb) print avc->version
> > > Cannot access memory at address 0xc1528eb7c0ea0157
> > > 
> > > make -j32 && gdb --args ./ffmpeg_g -ss 8 -i NeroRecodeSample.mp4
> > > -bitexact -t 3 -filter_complex
> > > '[0:2]scale=720:576[v];[v][0:5]overlay' -y file-whitesubs.avi
> > > 
> > > it appears this file is at:
> > > https://samples.ffmpeg.org/MPEG-4/NeroRecodeSample-MP4/
> > 
> > I can't reproduce this on mingw64.
> 
> Does the following fix it for you?

jamrial/channel_layout4 seems not to crash anymore
but the output from
libswresample/tests/swresample

changes substantially with that branch merged
here a hunk showing that:

--- /tmp/old    2022-01-15 14:38:42.370067768 +0100
+++ /tmp/new    2022-01-15 14:37:58.265740924 +0100
@@ -3,14 +3,14 @@
 [e:0.037321 c:0.988153 max:0.208739] len:  968
 [e:0.037581 c:0.988035 max:0.208739] len:  968
 [e:0.040051 c:0.986398 max:0.208739] len:  968
-[e:0.042843 c:0.984417 max:0.215337] len:  968
-[e:0.038669 c:0.987065 max:0.208739] len:  968
+[e:0.238849 c:-nan max:0.990217] len:  968
+[e:0.236179 c:-nan max:0.990217] len:  968
 [e:0.000987 c:0.999985 max:0.003293] len:   16 F:  1
 [e:0.000131 c:0.999999 max:0.000438] len:   16 F:  1
 [e:0.000999 c:0.999985 max:0.003333] len:   16 F:  1
 [e:0.000084 c:1.000000 max:0.000280] len:   16 F:  1
-[e:0.000996 c:0.999985 max:0.003322] len:   16 F:  1
-[e:0.000027 c:1.000000 max:0.000089] len:   16 F:  1
+[e:0.181271 c:-nan max:0.297598] len:   16 F:  1
+[e:0.080519 c:-nan max:0.227637] len:   16 F:  1
 
 TEST: 3.0->7.1(wide-side), rate:16000->48000, fmt:dbl->dbl
 [e:0.039816 c:0.986742 max:0.283776] len:  968


 
[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API
  2022-01-15 13:47         ` Michael Niedermayer
@ 2022-01-15 16:04           ` James Almer
  0 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-15 16:04 UTC (permalink / raw)
  To: ffmpeg-devel



On 1/15/2022 10:47 AM, Michael Niedermayer wrote:
> On Thu, Jan 13, 2022 at 04:44:55PM -0300, James Almer wrote:
>>
>>
>> On 1/13/2022 3:40 PM, James Almer wrote:
>>> On 1/13/2022 3:29 PM, Michael Niedermayer wrote:
>>>> On Wed, Jan 12, 2022 at 11:09:09PM -0300, James Almer wrote:
>>>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>>>> ---
>>>>>    fftools/cmdutils.c            | 42 +++++++++++++++---------
>>>>>    fftools/cmdutils.h            |  8 -----
>>>>>    fftools/ffmpeg.c              | 47 ++++++++++++++++----------
>>>>>    fftools/ffmpeg.h              |  7 ++--
>>>>>    fftools/ffmpeg_filter.c       | 52 ++++++++++++++++++++++-------
>>>>>    fftools/ffmpeg_opt.c          | 62 ++++++++++++++++++++++++++++++-----
>>>>>    tests/fate/aac.mak            |  2 +-
>>>>>    tests/fate/lavf-container.mak |  2 +-
>>>>>    8 files changed, 155 insertions(+), 67 deletions(-)
>>>>
>>>> This or a prior patch introduces crashes (it bisected to this but
>>>> this is my
>>>> 2nd testcase the first did not reproduce reliably at all)
>>>>
>>>> Thread 1 "ffmpeg_g" received signal SIGSEGV, Segmentation fault.
>>>> 0x00005555566ed811 in av_vlog (avcl=0x5555577400c0, level=24,
>>>> fmt=0x5555568249e8 "%d frames left in the queue on closing\n",
>>>> vl=0x7fffffffda50) at libavutil/log.c:428
>>>
>>> av_vlog() is where it crashes?
>>>
>>>> 428        if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
>>>> (gdb) bt
>>>> #0  0x00005555566ed811 in av_vlog (avcl=0x5555577400c0, level=24,
>>>> fmt=0x5555568249e8 "%d frames left in the queue on closing\n",
>>>> vl=0x7fffffffda50) at libavutil/log.c:428
>>>> #1  0x00005555566ed6bd in av_log (avcl=0x5555577400c0, level=24,
>>>> fmt=0x5555568249e8 "%d frames left in the queue on closing\n") at
>>>> libavutil/log.c:411
>>>> #2  0x0000555555c320b9 in ff_af_queue_close (afq=0x5555576c47c8) at
>>>> libavcodec/audio_frame_queue.c:39
>>>> #3  0x0000555555e84c06 in mp3lame_encode_close
>>>> (avctx=0x5555576bf180) at libavcodec/libmp3lame.c:86
>>>> #4  0x0000555555c373f7 in avcodec_close (avctx=0x5555576bf180) at
>>>> libavcodec/avcodec.c:489
>>>> #5  0x0000555555f7feab in avcodec_free_context
>>>> (pavctx=0x5555576a8858) at libavcodec/options.c:163
>>>> #6  0x000055555569cfe3 in ffmpeg_cleanup (ret=1) at fftools/ffmpeg.c:608
>>>> #7  0x0000555555694817 in exit_program (ret=1) at fftools/cmdutils.c:131
>>>> #8  0x000055555569ef1f in do_audio_out (of=0x5555576ae2c0,
>>>> ost=0x5555576a8800, frame=0x5555576bf580) at fftools/ffmpeg.c:1056
>>>> #9  0x00005555556a117a in reap_filters (flush=0) at fftools/ffmpeg.c:1546
>>>> #10 0x00005555556ad8e5 in transcode_step () at fftools/ffmpeg.c:4643
>>>> #11 0x00005555556ad9e7 in transcode () at fftools/ffmpeg.c:4687
>>>> #12 0x00005555556ae45c in main (argc=12, argv=0x7fffffffe1c8) at
>>>> fftools/ffmpeg.c:4903
>>>> (gdb) print avc->version
>>>> Cannot access memory at address 0xc1528eb7c0ea0157
>>>>
>>>> make -j32 && gdb --args ./ffmpeg_g -ss 8 -i NeroRecodeSample.mp4
>>>> -bitexact -t 3 -filter_complex
>>>> '[0:2]scale=720:576[v];[v][0:5]overlay' -y file-whitesubs.avi
>>>>
>>>> it appears this file is at:
>>>> https://samples.ffmpeg.org/MPEG-4/NeroRecodeSample-MP4/
>>>
>>> I can't reproduce this on mingw64.
>>
>> Does the following fix it for you?
> 
> jamrial/channel_layout4 seems not to crash anymore
> but the output from
> libswresample/tests/swresample
> 
> changes substantially with that branch merged
> here a hunk showing that:
> 
> --- /tmp/old    2022-01-15 14:38:42.370067768 +0100
> +++ /tmp/new    2022-01-15 14:37:58.265740924 +0100
> @@ -3,14 +3,14 @@
>   [e:0.037321 c:0.988153 max:0.208739] len:  968
>   [e:0.037581 c:0.988035 max:0.208739] len:  968
>   [e:0.040051 c:0.986398 max:0.208739] len:  968
> -[e:0.042843 c:0.984417 max:0.215337] len:  968
> -[e:0.038669 c:0.987065 max:0.208739] len:  968
> +[e:0.238849 c:-nan max:0.990217] len:  968
> +[e:0.236179 c:-nan max:0.990217] len:  968
>   [e:0.000987 c:0.999985 max:0.003293] len:   16 F:  1
>   [e:0.000131 c:0.999999 max:0.000438] len:   16 F:  1
>   [e:0.000999 c:0.999985 max:0.003333] len:   16 F:  1
>   [e:0.000084 c:1.000000 max:0.000280] len:   16 F:  1
> -[e:0.000996 c:0.999985 max:0.003322] len:   16 F:  1
> -[e:0.000027 c:1.000000 max:0.000089] len:   16 F:  1
> +[e:0.181271 c:-nan max:0.297598] len:   16 F:  1
> +[e:0.080519 c:-nan max:0.227637] len:   16 F:  1
>   
>   TEST: 3.0->7.1(wide-side), rate:16000->48000, fmt:dbl->dbl
>   [e:0.039816 c:0.986742 max:0.283776] len:  968

Should be fixed in the branch.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 001/281] Add a new " James Almer
  2022-01-13 14:08   ` Lynne
@ 2022-01-16 11:27   ` Nicolas George
  2022-01-16 22:54     ` Marton Balint
  2022-01-17 13:32     ` James Almer
  1 sibling, 2 replies; 337+ messages in thread
From: Nicolas George @ 2022-01-16 11:27 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 3855 bytes --]

James Almer (12022-01-12):
> From: Anton Khirnov <anton@khirnov.net>
> 
> The new API is more extensible and allows for custom layouts.
> More accurate information is exported, eg for decoders that do not
> set a channel layout, lavc will not make one up for them.
> 
> Deprecate the old API working with just uint64_t bitmasks.
> 
> Expanded and completed by Vittorio Giovara <vittorio.giovara@gmail.com>
> and James Almer <jamrial@gmail.com>.
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavutil/channel_layout.c | 629 ++++++++++++++++++++++++++++++++-----
>  libavutil/channel_layout.h | 542 ++++++++++++++++++++++++++++++--
>  libavutil/version.h        |   1 +
>  3 files changed, 1069 insertions(+), 103 deletions(-)

Thank you. I have no fundamental objection to the design of the API as
it is, but the user interface and documentation is still missing, that
needs to be addressed before the patch goes in.

(But IIRC, Marton had other requirements, so let us wait for him to
weigh in.)

> +/**
> + * Initialize a channel layout from a given string description.
> + * The input string can be represented by:
> + *  - the formal channel layout name (returned by av_channel_layout_describe())
> + *  - single or multiple channel names (returned by av_channel_name()
> + *    or concatenated with "+")
> + *  - a hexadecimal value of a channel layout (eg. "0x4")
> + *  - the number of channels with default layout (eg. "5c")
> + *  - the number of unordered channels (eg. "4", "4C", or "4 channels")
> + *
> + * @param channel_layout input channel layout
> + * @param str string describing the channel layout
> + * @return 0 channel layout was detected, AVERROR_INVALIDATATA otherwise
> + */
> +int av_channel_layout_from_string(AVChannelLayout *channel_layout,
> +                                  const char *str);

The documentation for the syntax needs to be in the user documentation,
with examples, not just in the API documentation.

> +/**
> + * This is the inverse function of @ref av_channel_name().
> + *
> + * @return the channel with the given name
> + *         AV_CHAN_NONE when name does not identify a known channel
> + */
> +enum AVChannel av_channel_from_string(const char *name);

> +/**
> + * Get a channel described by the given string.
> + *
> + * This function accepts channel names in the same format as
> + * @ref av_channel_from_string().
> + *
> + * @param channel_layout input channel layout
> + * @return a channel described by the given string, or a negative AVERROR value.
> + */
> +int av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout,
> +                                          const char *name);

This looks to be the preferred function for when the user will specify a
channel in a layout.

First, this fact should be stated clearly in the introduction of the
documentation. Otherwise, people will likely use other functions,
probably av_channel_layout_channel_from_index().

Second, the "name" argument cannot be just a name argument: the user
must be able to say "the third FC channel" or "the FC channel with name
'piano'". And probably both at once.

idx = av_channel_layout_channel_from_string(layout, "FC");
idx = av_channel_layout_channel_from_string(layout, "FC#2");
idx = av_channel_layout_channel_from_string(layout, "FC[piano]");
idx = av_channel_layout_channel_from_string(layout, "FC[piano]#2");

(I think it would be acceptable to limit the name, for example "names
with non-alphanumeric ASCII characters are not supported.)

And this need to go in the user documentation.

I am not sure if we also need a function to extract "all the FL channels
with name 'piano'".

Regards,

-- 
  Nicolas George

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-16 11:27   ` Nicolas George
@ 2022-01-16 22:54     ` Marton Balint
  2022-01-17 13:22       ` James Almer
  2022-01-17 13:53       ` Nicolas George
  2022-01-17 13:32     ` James Almer
  1 sibling, 2 replies; 337+ messages in thread
From: Marton Balint @ 2022-01-16 22:54 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On Sun, 16 Jan 2022, Nicolas George wrote:

> James Almer (12022-01-12):
>> From: Anton Khirnov <anton@khirnov.net>
>>
>> The new API is more extensible and allows for custom layouts.
>> More accurate information is exported, eg for decoders that do not
>> set a channel layout, lavc will not make one up for them.
>>
>> Deprecate the old API working with just uint64_t bitmasks.
>>
>> Expanded and completed by Vittorio Giovara <vittorio.giovara@gmail.com>
>> and James Almer <jamrial@gmail.com>.
>> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavutil/channel_layout.c | 629 ++++++++++++++++++++++++++++++++-----
>>  libavutil/channel_layout.h | 542 ++++++++++++++++++++++++++++++--
>>  libavutil/version.h        |   1 +
>>  3 files changed, 1069 insertions(+), 103 deletions(-)
>
> Thank you. I have no fundamental objection to the design of the API as
> it is, but the user interface and documentation is still missing, that
> needs to be addressed before the patch goes in.
>
> (But IIRC, Marton had other requirements, so let us wait for him to
> weigh in.)

My extensible metadata idea was not popular, so I am willing to let it go.

>
>> +/**
>> + * Initialize a channel layout from a given string description.
>> + * The input string can be represented by:
>> + *  - the formal channel layout name (returned by av_channel_layout_describe())
>> + *  - single or multiple channel names (returned by av_channel_name()
>> + *    or concatenated with "+")
>> + *  - a hexadecimal value of a channel layout (eg. "0x4")
>> + *  - the number of channels with default layout (eg. "5c")
>> + *  - the number of unordered channels (eg. "4", "4C", or "4 channels")
>> + *
>> + * @param channel_layout input channel layout
>> + * @param str string describing the channel layout
>> + * @return 0 channel layout was detected, AVERROR_INVALIDATATA otherwise
>> + */
>> +int av_channel_layout_from_string(AVChannelLayout *channel_layout,
>> +                                  const char *str);
>
> The documentation for the syntax needs to be in the user documentation,
> with examples, not just in the API documentation.
>
>> +/**
>> + * This is the inverse function of @ref av_channel_name().
>> + *
>> + * @return the channel with the given name
>> + *         AV_CHAN_NONE when name does not identify a known channel
>> + */
>> +enum AVChannel av_channel_from_string(const char *name);
>
>> +/**
>> + * Get a channel described by the given string.
>> + *
>> + * This function accepts channel names in the same format as
>> + * @ref av_channel_from_string().
>> + *
>> + * @param channel_layout input channel layout
>> + * @return a channel described by the given string, or a negative AVERROR value.
>> + */
>> +int av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout,
>> +                                          const char *name);
>
> This looks to be the preferred function for when the user will specify a
> channel in a layout.
>
> First, this fact should be stated clearly in the introduction of the
> documentation. Otherwise, people will likely use other functions,
> probably av_channel_layout_channel_from_index().
>
> Second, the "name" argument cannot be just a name argument: the user
> must be able to say "the third FC channel" or "the FC channel with name
> 'piano'". And probably both at once.
>
> idx = av_channel_layout_channel_from_string(layout, "FC");
> idx = av_channel_layout_channel_from_string(layout, "FC#2");
> idx = av_channel_layout_channel_from_string(layout, "FC[piano]");
> idx = av_channel_layout_channel_from_string(layout, "FC[piano]#2");
>
> (I think it would be acceptable to limit the name, for example "names
> with non-alphanumeric ASCII characters are not supported.)
>
> And this need to go in the user documentation.
>
> I am not sure if we also need a function to extract "all the FL channels
> with name 'piano'".

Before discussing channel selection syntax, can we discuss serialization?

Should the serializaton and unserialization functions store/parse both 
the channel label and the channel designation? As far as I see right now 
it is kind of inconsistent: av_channel_layout_describe_print() prints the 
label (if exists), not the designation, but av_channel_layout_from_string() 
expects the designations only, never the custom label.

There is still confusion what custom channel labels should be used for. Is 
it only used for string labels for user channel designations or is it used 
by the end user to tag its channels unrelated to their designation? 
"Piano" example suggest the latter, but API is designed for the former...

Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-16 22:54     ` Marton Balint
@ 2022-01-17 13:22       ` James Almer
  2022-01-17 20:18         ` Marton Balint
  2022-01-17 13:53       ` Nicolas George
  1 sibling, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-17 13:22 UTC (permalink / raw)
  To: ffmpeg-devel



On 1/16/2022 7:54 PM, Marton Balint wrote:
> 
> 
> On Sun, 16 Jan 2022, Nicolas George wrote:
> 
>> James Almer (12022-01-12):
>>> From: Anton Khirnov <anton@khirnov.net>
>>>
>>> The new API is more extensible and allows for custom layouts.
>>> More accurate information is exported, eg for decoders that do not
>>> set a channel layout, lavc will not make one up for them.
>>>
>>> Deprecate the old API working with just uint64_t bitmasks.
>>>
>>> Expanded and completed by Vittorio Giovara <vittorio.giovara@gmail.com>
>>> and James Almer <jamrial@gmail.com>.
>>> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>> ---
>>>  libavutil/channel_layout.c | 629 ++++++++++++++++++++++++++++++++-----
>>>  libavutil/channel_layout.h | 542 ++++++++++++++++++++++++++++++--
>>>  libavutil/version.h        |   1 +
>>>  3 files changed, 1069 insertions(+), 103 deletions(-)
>>
>> Thank you. I have no fundamental objection to the design of the API as
>> it is, but the user interface and documentation is still missing, that
>> needs to be addressed before the patch goes in.
>>
>> (But IIRC, Marton had other requirements, so let us wait for him to
>> weigh in.)
> 
> My extensible metadata idea was not popular, so I am willing to let it go.
> 
>>
>>> +/**
>>> + * Initialize a channel layout from a given string description.
>>> + * The input string can be represented by:
>>> + *  - the formal channel layout name (returned by 
>>> av_channel_layout_describe())
>>> + *  - single or multiple channel names (returned by av_channel_name()
>>> + *    or concatenated with "+")
>>> + *  - a hexadecimal value of a channel layout (eg. "0x4")
>>> + *  - the number of channels with default layout (eg. "5c")
>>> + *  - the number of unordered channels (eg. "4", "4C", or "4 channels")
>>> + *
>>> + * @param channel_layout input channel layout
>>> + * @param str string describing the channel layout
>>> + * @return 0 channel layout was detected, AVERROR_INVALIDATATA 
>>> otherwise
>>> + */
>>> +int av_channel_layout_from_string(AVChannelLayout *channel_layout,
>>> +                                  const char *str);
>>
>> The documentation for the syntax needs to be in the user documentation,
>> with examples, not just in the API documentation.
>>
>>> +/**
>>> + * This is the inverse function of @ref av_channel_name().
>>> + *
>>> + * @return the channel with the given name
>>> + *         AV_CHAN_NONE when name does not identify a known channel
>>> + */
>>> +enum AVChannel av_channel_from_string(const char *name);
>>
>>> +/**
>>> + * Get a channel described by the given string.
>>> + *
>>> + * This function accepts channel names in the same format as
>>> + * @ref av_channel_from_string().
>>> + *
>>> + * @param channel_layout input channel layout
>>> + * @return a channel described by the given string, or a negative 
>>> AVERROR value.
>>> + */
>>> +int av_channel_layout_channel_from_string(const AVChannelLayout 
>>> *channel_layout,
>>> +                                          const char *name);
>>
>> This looks to be the preferred function for when the user will specify a
>> channel in a layout.
>>
>> First, this fact should be stated clearly in the introduction of the
>> documentation. Otherwise, people will likely use other functions,
>> probably av_channel_layout_channel_from_index().
>>
>> Second, the "name" argument cannot be just a name argument: the user
>> must be able to say "the third FC channel" or "the FC channel with name
>> 'piano'". And probably both at once.
>>
>> idx = av_channel_layout_channel_from_string(layout, "FC");
>> idx = av_channel_layout_channel_from_string(layout, "FC#2");
>> idx = av_channel_layout_channel_from_string(layout, "FC[piano]");
>> idx = av_channel_layout_channel_from_string(layout, "FC[piano]#2");
>>
>> (I think it would be acceptable to limit the name, for example "names
>> with non-alphanumeric ASCII characters are not supported.)
>>
>> And this need to go in the user documentation.
>>
>> I am not sure if we also need a function to extract "all the FL channels
>> with name 'piano'".
> 
> Before discussing channel selection syntax, can we discuss serialization?
> 
> Should the serializaton and unserialization functions store/parse both 
> the channel label and the channel designation? As far as I see right now 
> it is kind of inconsistent: av_channel_layout_describe_print() prints 
> the label (if exists), not the designation, but 
> av_channel_layout_from_string() expects the designations only, never the 
> custom label.

You're still thinking there's a distinction, when i already told you 
that there is none. I added the name field because people wanted to give 
non standard channel names, and maybe also change the standard ones too. 
It's not a label to go alongside a designation, it's *a* name.
There are about 20 channels that have a standard name from waveformat 
and extensions, while the rest lack one. You can obviously have a non 
standard speaker setup with 50 channels, and all those extra speakers 
can surely have a name based on their position (Say, RTFC, to refer to 
"right of top front center"), so the field lets you give it to them if 
that's convenient for you and you want a pretty print output of the 
layout without seeing things like USR49. That's it.

Yes, av_channel_layout_from_string() will not be able to parse the 
output of av_channel_layout_from_describe() if you gave channels a 
custom name, since they are specifically from that other layout. There's 
no way around that, as we can't make describe() output some string that 
from_string() can interpret for those because then describe() will be 
useless for printing the layout for human readability purposes.
It is in fact a good reason to either remove the name field or stop 
making these helpers look at it, since describe() is meant to create 
strings from_string() can parse.

I personally would do just that and keep the opaque fields alone. 
Otherwise I'll make the helpers stop looking at it, since after your 
request, non standard channels can be addressed as USR#, so you can 
create layout from strings with them just fine.
The opaque field is more than enough to give channels custom names and 
even implement all kinds of crazy unconventional inter-filter usage 
within libavfilter like Nicolas wants to without overdesigning the 
helpers for virtually unused scenarios outside of our own libraries.

> 
> There is still confusion what custom channel labels should be used for. 
> Is it only used for string labels for user channel designations or is it 
> used by the end user to tag its channels unrelated to their designation? 
> "Piano" example suggest the latter, but API is designed for the former...

It's what i said above. The piano stuff is Nicolas personal usecase for 
libavfilter internal behavior that's beyond the scope of these helpers.

> 
> Regards,
> Marton
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-16 11:27   ` Nicolas George
  2022-01-16 22:54     ` Marton Balint
@ 2022-01-17 13:32     ` James Almer
  2022-01-17 13:51       ` Nicolas George
  1 sibling, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-17 13:32 UTC (permalink / raw)
  To: ffmpeg-devel



On 1/16/2022 8:27 AM, Nicolas George wrote:
> James Almer (12022-01-12):
>> From: Anton Khirnov <anton@khirnov.net>
>>
>> The new API is more extensible and allows for custom layouts.
>> More accurate information is exported, eg for decoders that do not
>> set a channel layout, lavc will not make one up for them.
>>
>> Deprecate the old API working with just uint64_t bitmasks.
>>
>> Expanded and completed by Vittorio Giovara <vittorio.giovara@gmail.com>
>> and James Almer <jamrial@gmail.com>.
>> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavutil/channel_layout.c | 629 ++++++++++++++++++++++++++++++++-----
>>   libavutil/channel_layout.h | 542 ++++++++++++++++++++++++++++++--
>>   libavutil/version.h        |   1 +
>>   3 files changed, 1069 insertions(+), 103 deletions(-)
> 
> Thank you. I have no fundamental objection to the design of the API as
> it is, but the user interface and documentation is still missing, that
> needs to be addressed before the patch goes in.
> 
> (But IIRC, Marton had other requirements, so let us wait for him to
> weigh in.)
> 
>> +/**
>> + * Initialize a channel layout from a given string description.
>> + * The input string can be represented by:
>> + *  - the formal channel layout name (returned by av_channel_layout_describe())
>> + *  - single or multiple channel names (returned by av_channel_name()
>> + *    or concatenated with "+")
>> + *  - a hexadecimal value of a channel layout (eg. "0x4")
>> + *  - the number of channels with default layout (eg. "5c")
>> + *  - the number of unordered channels (eg. "4", "4C", or "4 channels")
>> + *
>> + * @param channel_layout input channel layout
>> + * @param str string describing the channel layout
>> + * @return 0 channel layout was detected, AVERROR_INVALIDATATA otherwise
>> + */
>> +int av_channel_layout_from_string(AVChannelLayout *channel_layout,
>> +                                  const char *str);
> 
> The documentation for the syntax needs to be in the user documentation,
> with examples, not just in the API documentation.

I'll look into it.

> 
>> +/**
>> + * This is the inverse function of @ref av_channel_name().
>> + *
>> + * @return the channel with the given name
>> + *         AV_CHAN_NONE when name does not identify a known channel
>> + */
>> +enum AVChannel av_channel_from_string(const char *name);
> 
>> +/**
>> + * Get a channel described by the given string.
>> + *
>> + * This function accepts channel names in the same format as
>> + * @ref av_channel_from_string().
>> + *
>> + * @param channel_layout input channel layout
>> + * @return a channel described by the given string, or a negative AVERROR value.
>> + */
>> +int av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout,
>> +                                          const char *name);
> 
> This looks to be the preferred function for when the user will specify a
> channel in a layout.
> 
> First, this fact should be stated clearly in the introduction of the
> documentation. Otherwise, people will likely use other functions,
> probably av_channel_layout_channel_from_index().

And they can if they want to. It has a very specific purpose and it 
fulfills it.

> 
> Second, the "name" argument cannot be just a name argument: the user
> must be able to say "the third FC channel" or "the FC channel with name
> 'piano'". And probably both at once.
> 
> idx = av_channel_layout_channel_from_string(layout, "FC");
> idx = av_channel_layout_channel_from_string(layout, "FC#2");
> idx = av_channel_layout_channel_from_string(layout, "FC[piano]");
> idx = av_channel_layout_channel_from_string(layout, "FC[piano]#2");

Please, stop asking for this. It's an incredibly niche usecase you want 
for libavfilter, so you can and should implement it there. The API is 
there and you can use it, you don't need to overdesign these general 
purpose helpers to create these bizarre scenarios just to remove one or 
two filters from your chain.

You have the opaque field in both the layout and each channel. You can 
store a pointer there to anything you want at any point in your chain, 
like an internal and refcounted lavfi struct that stores all this 
information filters in the chain can parse and use.

This is a layout of speaker positions. If you want metadata, use metadata.

> 
> (I think it would be acceptable to limit the name, for example "names
> with non-alphanumeric ASCII characters are not supported.)
> 
> And this need to go in the user documentation.
> 
> I am not sure if we also need a function to extract "all the FL channels
> with name 'piano'".
> 
> Regards,
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 13:32     ` James Almer
@ 2022-01-17 13:51       ` Nicolas George
  2022-01-17 14:12         ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: Nicolas George @ 2022-01-17 13:51 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 964 bytes --]

James Almer (12022-01-17):
> And they can if they want to. It has a very specific purpose and it fulfills
> it.

Just be clearer in the documentation.

> Please, stop asking for this. It's an incredibly niche usecase you want for
> libavfilter, so you can and should implement it there. The API is there and
> you can use it, you don't need to overdesign these general purpose helpers
> to create these bizarre scenarios just to remove one or two filters from
> your chain.

I will not stop asking for this, it is not specific to libavfilter: with
a quick search, I spot -map_channel that requires exactly the same
feature.

There may be filters that require an option to distinguish one channel
in particular; even if there are no now, there may be in the future. Can
you guarantee it does not and will not happen?

This use case happens at several places, therefore the parsing belongs
in a common API.

Regards,

-- 
  Nicolas George

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-16 22:54     ` Marton Balint
  2022-01-17 13:22       ` James Almer
@ 2022-01-17 13:53       ` Nicolas George
  2022-01-17 13:54         ` James Almer
  1 sibling, 1 reply; 337+ messages in thread
From: Nicolas George @ 2022-01-17 13:53 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 611 bytes --]

Marton Balint (12022-01-16):
> Should the serializaton and unserialization functions store/parse both the
> channel label and the channel designation? As far as I see right now it is
> kind of inconsistent: av_channel_layout_describe_print() prints the label
> (if exists), not the designation, but av_channel_layout_from_string()
> expects the designations only, never the custom label.

Oh, excellent point. av_channel_layout_from_string() should be able to
parse the output of av_channel_layout_describe_bprint() in all cases.
And it should be covered by FATE.

Regards,

-- 
  Nicolas George

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 13:53       ` Nicolas George
@ 2022-01-17 13:54         ` James Almer
  2022-01-17 13:56           ` Nicolas George
  0 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-17 13:54 UTC (permalink / raw)
  To: ffmpeg-devel



On 1/17/2022 10:53 AM, Nicolas George wrote:
> Marton Balint (12022-01-16):
>> Should the serializaton and unserialization functions store/parse both the
>> channel label and the channel designation? As far as I see right now it is
>> kind of inconsistent: av_channel_layout_describe_print() prints the label
>> (if exists), not the designation, but av_channel_layout_from_string()
>> expects the designations only, never the custom label.
> 
> Oh, excellent point. av_channel_layout_from_string() should be able to
> parse the output of av_channel_layout_describe_bprint() in all cases.
> And it should be covered by FATE.

Yes, which is why I'll make describe() stop looking at the name field.

> 
> Regards,
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 13:54         ` James Almer
@ 2022-01-17 13:56           ` Nicolas George
  2022-01-17 14:02             ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: Nicolas George @ 2022-01-17 13:56 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 144 bytes --]

James Almer (12022-01-17):
> Yes, which is why I'll make describe() stop looking at the name field.

Unacceptable.

-- 
  Nicolas George

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 13:56           ` Nicolas George
@ 2022-01-17 14:02             ` James Almer
  2022-01-17 16:50               ` Nicolas George
  0 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-17 14:02 UTC (permalink / raw)
  To: ffmpeg-devel



On 1/17/2022 10:56 AM, Nicolas George wrote:
> James Almer (12022-01-17):
>> Yes, which is why I'll make describe() stop looking at the name field.
> 
> Unacceptable.

Either that, or the field is removed. The opaque field is more than 
enough for your usecase. lavfi can and should use it to do everything 
you need.
Alternative, you can, at any time, extend this API yourself to cover all 
kinds of crazy musical instrumental scenarios. Create a new layout order 
and go nuts. But I'm not going to overdesign this API or its helpers 
just because you want less code in lavfi.

There are real world files and real world scenarios waiting for this API 
to land, unlike front center pianos and clarinets wishing they could 
skip one entry in your -filter_complex line, so it's not an excuse to 
delay it any longer.

> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 13:51       ` Nicolas George
@ 2022-01-17 14:12         ` James Almer
  2022-01-17 16:48           ` Nicolas George
  0 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-17 14:12 UTC (permalink / raw)
  To: ffmpeg-devel



On 1/17/2022 10:51 AM, Nicolas George wrote:
> James Almer (12022-01-17):
>> And they can if they want to. It has a very specific purpose and it fulfills
>> it.
> 
> Just be clearer in the documentation.
> 
>> Please, stop asking for this. It's an incredibly niche usecase you want for
>> libavfilter, so you can and should implement it there. The API is there and
>> you can use it, you don't need to overdesign these general purpose helpers
>> to create these bizarre scenarios just to remove one or two filters from
>> your chain.
> 
> I will not stop asking for this, it is not specific to libavfilter: with
> a quick search, I spot -map_channel that requires exactly the same
> feature.

-map_channel works perfectly with the current bitmask API, and the new one.

> 
> There may be filters that require an option to distinguish one channel
> in particular; even if there are no now, there may be in the future. Can
> you guarantee it does not and will not happen?

Look at their IDs? Look at their names? Give them names if you need to?
And again, you keep talking about filtering scenarios. Lavfi can and 
should handle all this on its own internally, just like it was designed 
to, and not pollute an API meant to define the position a channel is 
supposed to be.

> 
> This use case happens at several places, therefore the parsing belongs
> in a common API.
> 
> Regards,
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 14:12         ` James Almer
@ 2022-01-17 16:48           ` Nicolas George
  2022-01-17 16:50             ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: Nicolas George @ 2022-01-17 16:48 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 218 bytes --]

James Almer (12022-01-17):
> -map_channel works perfectly with the current bitmask API, and the new one.

Not if there are several times the same channel with different labels.
It should.

-- 
  Nicolas George

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 14:02             ` James Almer
@ 2022-01-17 16:50               ` Nicolas George
  2022-01-17 16:52                 ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: Nicolas George @ 2022-01-17 16:50 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 329 bytes --]

James Almer (12022-01-17):
> Either that, or the field is removed.

Are we discussing together to design the best API possible or are you a
dictator making threats?

The label field stays, and the parse and stringify functions must be
reciprocal of each other. The API is unacceptable otherwise.

-- 
  Nicolas George

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 16:48           ` Nicolas George
@ 2022-01-17 16:50             ` James Almer
  0 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-17 16:50 UTC (permalink / raw)
  To: ffmpeg-devel



On 1/17/2022 1:48 PM, Nicolas George wrote:
> James Almer (12022-01-17):
>> -map_channel works perfectly with the current bitmask API, and the new one.
> 
> Not if there are several times the same channel with different labels.
> It should.

Patches are always welcome for new or updated functionality.

> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 16:50               ` Nicolas George
@ 2022-01-17 16:52                 ` James Almer
  2022-01-17 16:54                   ` Nicolas George
  0 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-17 16:52 UTC (permalink / raw)
  To: ffmpeg-devel



On 1/17/2022 1:50 PM, Nicolas George wrote:
> James Almer (12022-01-17):
>> Either that, or the field is removed.
> 
> Are we discussing together to design the best API possible or are you a
> dictator making threats?

Like you said below, the functions must be reciprocal, so they can't 
take that field into account. Removing the field is not necessary, but 
is another option.

> 
> The label field stays, and the parse and stringify functions must be
> reciprocal of each other. The API is unacceptable otherwise.
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 16:52                 ` James Almer
@ 2022-01-17 16:54                   ` Nicolas George
  2022-01-17 16:57                     ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: Nicolas George @ 2022-01-17 16:54 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 256 bytes --]

James Almer (12022-01-17):
> Like you said below, the functions must be reciprocal, so they can't take
> that field into account.

A serializaion function is supposed to serialize the whole structure. I
will not accept less.

-- 
  Nicolas George

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 16:54                   ` Nicolas George
@ 2022-01-17 16:57                     ` James Almer
  2022-01-17 17:55                       ` Nicolas George
  0 siblings, 1 reply; 337+ messages in thread
From: James Almer @ 2022-01-17 16:57 UTC (permalink / raw)
  To: ffmpeg-devel



On 1/17/2022 1:54 PM, Nicolas George wrote:
> James Almer (12022-01-17):
>> Like you said below, the functions must be reciprocal, so they can't take
>> that field into account.
> 
> A serializaion function is supposed to serialize the whole structure. I
> will not accept less.

It will print the whole structure, what makes you think it wont? It 
doesn't need custom names to be set to do that.

> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 16:57                     ` James Almer
@ 2022-01-17 17:55                       ` Nicolas George
  0 siblings, 0 replies; 337+ messages in thread
From: Nicolas George @ 2022-01-17 17:55 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 355 bytes --]

James Almer (12022-01-17):
> It will print the whole structure, what makes you think it wont? It doesn't
> need custom names to be set to do that.

If it prints the whole structure, including the names, and if the
parsing function parses the whole result, including the names, it is
good. Anything else... needs more work.

-- 
  Nicolas George

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 13:22       ` James Almer
@ 2022-01-17 20:18         ` Marton Balint
  2022-01-17 20:27           ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: Marton Balint @ 2022-01-17 20:18 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On Mon, 17 Jan 2022, James Almer wrote:

>
>
> You're still thinking there's a distinction, when i already told you that 
> there is none. I added the name field because people wanted to give non 
> standard channel names, and maybe also change the standard ones too. It's not 
> a label to go alongside a designation, it's *a* name.
> There are about 20 channels that have a standard name from waveformat and 
> extensions, while the rest lack one. You can obviously have a non standard 
> speaker setup with 50 channels, and all those extra speakers can surely have 
> a name based on their position (Say, RTFC, to refer to "right of top front 
> center"), so the field lets you give it to them if that's convenient for you 
> and you want a pretty print output of the layout without seeing things like 
> USR49. That's it.

OK, but shouldn't the user be able to specify if it means a builtin name 
or a custom name when specifying a channel name?

That is why I suggested some additinal syntax for custom names 
in av_channel_layout_index_from_string() and 
av_channel_layout_channel_from_string(). Like "FL" is a builtin name, 
"@name" is a custom name.

>
> Yes, av_channel_layout_from_string() will not be able to parse the output of 
> av_channel_layout_from_describe() if you gave channels a custom name, since 
> they are specifically from that other layout. There's no way around that, as 
> we can't make describe() output some string that from_string() can interpret 
> for those because then describe() will be useless for printing the layout for 
> human readability purposes.
> It is in fact a good reason to either remove the name field or stop making 
> these helpers look at it, since describe() is meant to create strings 
> from_string() can parse.
>
> I personally would do just that and keep the opaque fields alone. Otherwise 
> I'll make the helpers stop looking at it, since after your request, non 
> standard channels can be addressed as USR#, so you can create layout from 
> strings with them just fine.

Removing the custom names is fine with me. Maybe it's a compromise nobody 
is particularly happy about.

Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 001/281] Add a new channel layout API
  2022-01-17 20:18         ` Marton Balint
@ 2022-01-17 20:27           ` James Almer
  0 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-17 20:27 UTC (permalink / raw)
  To: ffmpeg-devel



On 1/17/2022 5:18 PM, Marton Balint wrote:
> 
> 
> On Mon, 17 Jan 2022, James Almer wrote:
> 
>>
>>
>> You're still thinking there's a distinction, when i already told you 
>> that there is none. I added the name field because people wanted to 
>> give non standard channel names, and maybe also change the standard 
>> ones too. It's not a label to go alongside a designation, it's *a* name.
>> There are about 20 channels that have a standard name from waveformat 
>> and extensions, while the rest lack one. You can obviously have a non 
>> standard speaker setup with 50 channels, and all those extra speakers 
>> can surely have a name based on their position (Say, RTFC, to refer to 
>> "right of top front center"), so the field lets you give it to them if 
>> that's convenient for you and you want a pretty print output of the 
>> layout without seeing things like USR49. That's it.
> 
> OK, but shouldn't the user be able to specify if it means a builtin name 
> or a custom name when specifying a channel name?
> 
> That is why I suggested some additinal syntax for custom names in 
> av_channel_layout_index_from_string() and 
> av_channel_layout_channel_from_string(). Like "FL" is a builtin name, 
> "@name" is a custom name.
> 
>>
>> Yes, av_channel_layout_from_string() will not be able to parse the 
>> output of av_channel_layout_from_describe() if you gave channels a 
>> custom name, since they are specifically from that other layout. 
>> There's no way around that, as we can't make describe() output some 
>> string that from_string() can interpret for those because then 
>> describe() will be useless for printing the layout for human 
>> readability purposes.
>> It is in fact a good reason to either remove the name field or stop 
>> making these helpers look at it, since describe() is meant to create 
>> strings from_string() can parse.
>>
>> I personally would do just that and keep the opaque fields alone. 
>> Otherwise I'll make the helpers stop looking at it, since after your 
>> request, non standard channels can be addressed as USR#, so you can 
>> create layout from strings with them just fine.
> 
> Removing the custom names is fine with me. Maybe it's a compromise 
> nobody is particularly happy about.

I will not remove it. It has its uses even if helpers don't make 
extended use of it at first.

Advanced syntax can be implemented later. See my comments in v4.

> 
> Regards,
> Marton
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 274/281] swresample: convert to new channel layout API
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 274/281] swresample: convert to new channel layout API James Almer
@ 2022-01-19 17:20   ` Andreas Rheinhardt
  2022-01-19 17:29     ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: Andreas Rheinhardt @ 2022-01-19 17:20 UTC (permalink / raw)
  To: ffmpeg-devel

James Almer:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libswresample/options.c             |  33 +++-
>  libswresample/rematrix.c            | 237 ++++++++++++++++++----------
>  libswresample/rematrix_template.c   |   7 +-
>  libswresample/swresample.c          | 152 +++++++++++++++---
>  libswresample/swresample.h          |  63 ++++++++

This header still contains many references to swr_alloc_set_opts().

>  libswresample/swresample_frame.c    |  65 +++++++-
>  libswresample/swresample_internal.h |  10 +-
>  7 files changed, 445 insertions(+), 122 deletions(-)
> 
> diff --git a/libswresample/options.c b/libswresample/options.c
> index 6911709157..ffa27c590d 100644
> --- a/libswresample/options.c
> +++ b/libswresample/options.c
> @@ -34,12 +34,19 @@
>  
>  #define OFFSET(x) offsetof(SwrContext,x)
>  #define PARAM AV_OPT_FLAG_AUDIO_PARAM
> +#define DEPREC AV_OPT_FLAG_DEPRECATED
>  
>  static const AVOption options[]={
> -{"ich"                  , "set input channel count"     , OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
> -{"in_channel_count"     , "set input channel count"     , OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
> -{"och"                  , "set output channel count"    , OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
> -{"out_channel_count"    , "set output channel count"    , OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
> +#if FF_API_OLD_CHANNEL_LAYOUT
> +{"ich"                  , "set input channel count (Deprecated, use ichl)",
> +                                                          OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
> +{"in_channel_count"     , "set input channel count (Deprecated, use in_chlayout)",
> +                                                          OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
> +{"och"                  , "set output channel count (Deprecated, use ochl)",
> +                                                          OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
> +{"out_channel_count"    , "set output channel count (Deprecated, use out_chlayout)",
> +                                                          OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
> +#endif
>  {"uch"                  , "set used channel count"      , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
>  {"used_channel_count"   , "set used channel count"      , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
>  {"isr"                  , "set input sample rate"       , OFFSET( in_sample_rate), AV_OPT_TYPE_INT  , {.i64=0                     }, 0      , INT_MAX   , PARAM},
> @@ -52,10 +59,20 @@ static const AVOption options[]={
>  {"out_sample_fmt"       , "set output sample format"    , OFFSET(out_sample_fmt ), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1   , INT_MAX, PARAM},
>  {"tsf"                  , "set internal sample format"  , OFFSET(user_int_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1   , INT_MAX, PARAM},
>  {"internal_sample_fmt"  , "set internal sample format"  , OFFSET(user_int_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1   , INT_MAX, PARAM},
> -{"icl"                  , "set input channel layout"    , OFFSET(user_in_ch_layout ), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
> -{"in_channel_layout"    , "set input channel layout"    , OFFSET(user_in_ch_layout ), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
> -{"ocl"                  , "set output channel layout"   , OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
> -{"out_channel_layout"   , "set output channel layout"   , OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
> +#if FF_API_OLD_CHANNEL_LAYOUT
> +{"icl"                  , "set input channel layout (Deprecated, use ichl)",
> +                                                          OFFSET(user_in_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0          }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
> +{"in_channel_layout"    , "set input channel layout (Deprecated, use in_chlayout)",
> +                                                          OFFSET(user_in_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0          }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
> +{"ocl"                  , "set output channel layout (Deprecated, use ochl)",
> +                                                          OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0         }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
> +{"out_channel_layout"   , "set output channel layout (Deprecated, use out_chlayout)",
> +                                                          OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0         }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
> +#endif
> +{"ichl"                 , "set input channel layout"    , OFFSET(user_in_chlayout ), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
> +{"in_chlayout"          , "set input channel layout"    , OFFSET(user_in_chlayout ), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
> +{"ochl"                 , "set output channel layout"   , OFFSET(user_out_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
> +{"out_chlayout"         , "set output channel layout"   , OFFSET(user_out_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
>  {"clev"                 , "set center mix level"        , OFFSET(clev           ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB                }, -32    , 32        , PARAM},
>  {"center_mix_level"     , "set center mix level"        , OFFSET(clev           ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB                }, -32    , 32        , PARAM},
>  {"slev"                 , "set surround mix level"      , OFFSET(slev           ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB                }, -32    , 32        , PARAM},
> diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
> index 94b3de88f6..35086c218d 100644
> --- a/libswresample/rematrix.c
> +++ b/libswresample/rematrix.c
> @@ -64,15 +64,37 @@
>  int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
>  {
>      int nb_in, nb_out, in, out;
> +    int user_in_chlayout_nb_channels, user_out_chlayout_nb_channels;
>  
>      if (!s || s->in_convert) // s needs to be allocated but not initialized
>          return AVERROR(EINVAL);
>      memset(s->matrix, 0, sizeof(s->matrix));
>      memset(s->matrix_flt, 0, sizeof(s->matrix_flt));
> -    nb_in = (s->user_in_ch_count > 0) ? s->user_in_ch_count :
> -        av_get_channel_layout_nb_channels(s->user_in_ch_layout);
> -    nb_out = (s->user_out_ch_count > 0) ? s->user_out_ch_count :
> -        av_get_channel_layout_nb_channels(s->user_out_ch_layout);
> +
> +#if FF_API_OLD_CHANNEL_LAYOUT
> +FF_DISABLE_DEPRECATION_WARNINGS
> +    user_in_chlayout_nb_channels = av_get_channel_layout_nb_channels(s->user_in_ch_layout);
> +FF_ENABLE_DEPRECATION_WARNINGS
> +    if (!user_in_chlayout_nb_channels)
> +#endif
> +    user_in_chlayout_nb_channels = s->user_in_chlayout.nb_channels;
> +    nb_in =
> +#if FF_API_OLD_CHANNEL_LAYOUT
> +            (s->user_in_ch_count > 0) ? s->user_in_ch_count :
> +#endif
> +            user_in_chlayout_nb_channels;
> +#if FF_API_OLD_CHANNEL_LAYOUT
> +FF_DISABLE_DEPRECATION_WARNINGS
> +    user_out_chlayout_nb_channels = av_get_channel_layout_nb_channels(s->user_out_ch_layout);
> +FF_ENABLE_DEPRECATION_WARNINGS
> +    if (!user_out_chlayout_nb_channels)
> +#endif
> +    user_out_chlayout_nb_channels = s->user_out_chlayout.nb_channels;
> +    nb_out =
> +#if FF_API_OLD_CHANNEL_LAYOUT
> +             (s->user_out_ch_count > 0) ? s->user_out_ch_count :
> +#endif
> +             user_out_chlayout_nb_channels;
>      for (out = 0; out < nb_out; out++) {
>          for (in = 0; in < nb_in; in++)
>              s->matrix_flt[out][in] = s->matrix[out][in] = matrix[in];
> @@ -88,95 +110,141 @@ static int even(int64_t layout){
>      return 0;
>  }
>  
> -static int64_t clean_layout(void *s, int64_t layout){
> -    if(layout && layout != AV_CH_FRONT_CENTER && !(layout&(layout-1))) {
> +static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void *s)
> +{
> +    int ret = 0;
> +
> +    if(av_channel_layout_index_from_channel(in, AV_CH_FRONT_CENTER) < 0 && in->nb_channels == 1) {
>          char buf[128];
> -        av_get_channel_layout_string(buf, sizeof(buf), -1, layout);
> +        av_channel_layout_describe(in, buf, sizeof(buf));
>          av_log(s, AV_LOG_VERBOSE, "Treating %s as mono\n", buf);
> -        return AV_CH_FRONT_CENTER;
> -    }
> +        *out = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
> +    } else
> +        ret = av_channel_layout_copy(out, in);
>  
> -    return layout;
> +    return ret;
>  }
>  
> -static int sane_layout(int64_t layout){
> -    if(!(layout & AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker
> +static int sane_layout(AVChannelLayout *ch_layout) {
> +    if (ch_layout->order != AV_CHANNEL_ORDER_NATIVE)
> +        return 0;
> +    if(!av_channel_layout_subset(ch_layout, AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker
>          return 0;
> -    if(!even(layout & (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT))) // no asymetric front
> +    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)))) // no asymetric front
>          return 0;
> -    if(!even(layout & (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)))   // no asymetric side
> +    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT))))   // no asymetric side
>          return 0;
> -    if(!even(layout & (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)))
> +    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT))))
>          return 0;
> -    if(!even(layout & (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)))
> +    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER))))
>          return 0;
> -    if(av_get_channel_layout_nb_channels(layout) >= SWR_CH_MAX)
> +    if(ch_layout->nb_channels >= SWR_CH_MAX)
>          return 0;
>  
>      return 1;
>  }
>  
> +#if FF_API_OLD_CHANNEL_LAYOUT
>  av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout_param,
>                               double center_mix_level, double surround_mix_level,
>                               double lfe_mix_level, double maxval,
>                               double rematrix_volume, double *matrix_param,
>                               int stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
>  {
> -    int i, j, out_i;
> +    AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
> +    int ret;
> +
> +    ret  = av_channel_layout_from_mask(&in_ch_layout, in_ch_layout_param);
> +    ret |= av_channel_layout_from_mask(&out_ch_layout, out_ch_layout_param);
> +    if (ret < 0)
> +        return ret;
> +
> +    return swr_build_matrix2(&in_ch_layout, &out_ch_layout, center_mix_level, surround_mix_level,
> +                             lfe_mix_level, maxval, rematrix_volume, matrix_param,
> +                             stride, matrix_encoding, log_context);
> +}
> +#endif
> +
> +av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
> +                              double center_mix_level, double surround_mix_level,
> +                              double lfe_mix_level, double maxval,
> +                              double rematrix_volume, double *matrix_param,
> +                              ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
> +{
> +    int i, j, out_i, ret;
> +    AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
>      double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}};
> -    int64_t unaccounted, in_ch_layout, out_ch_layout;
> +    int64_t unaccounted;
>      double maxcoef=0;
>      char buf[128];
>  
> -     in_ch_layout = clean_layout(log_context,  in_ch_layout_param);
> -    out_ch_layout = clean_layout(log_context, out_ch_layout_param);
> -
> -    if(   out_ch_layout == AV_CH_LAYOUT_STEREO_DOWNMIX
> -       && (in_ch_layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == 0
> -    )
> -        out_ch_layout = AV_CH_LAYOUT_STEREO;
> +    ret  = clean_layout(&in_ch_layout, in_layout, log_context);
> +    ret |= clean_layout(&out_ch_layout, out_layout, log_context);
> +    if (ret < 0)
> +        goto fail;
>  
> -    if(    in_ch_layout == AV_CH_LAYOUT_STEREO_DOWNMIX
> -       && (out_ch_layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == 0
> -    )
> -        in_ch_layout = AV_CH_LAYOUT_STEREO;
> -
> -    if (in_ch_layout == AV_CH_LAYOUT_22POINT2 &&
> -        out_ch_layout != AV_CH_LAYOUT_22POINT2) {
> -        in_ch_layout = (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER);
> -        av_get_channel_layout_string(buf, sizeof(buf), -1, in_ch_layout);
> +    if(   !av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
> +       && !av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
> +    ) {
> +        av_channel_layout_uninit(&out_ch_layout);
> +        out_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
> +    }
> +    if(   !av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
> +       && !av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
> +    ) {
> +        av_channel_layout_uninit(&in_ch_layout);
> +        in_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
> +    }
> +    if (!av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2) &&
> +        av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2)) {
> +        av_channel_layout_from_mask(&in_ch_layout, (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER));
> +        av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
>          av_log(log_context, AV_LOG_WARNING,
>                 "Full-on remixing from 22.2 has not yet been implemented! "
>                 "Processing the input as '%s'\n",
>                 buf);
>      }
>  
> -    if(!sane_layout(in_ch_layout)){
> -        av_get_channel_layout_string(buf, sizeof(buf), -1, in_ch_layout_param);
> +    if(!av_channel_layout_check(&in_ch_layout)) {
> +        av_log(log_context, AV_LOG_ERROR, "Input channel layout is invalid\n");
> +        ret = AVERROR(EINVAL);
> +        goto fail;
> +    }
> +    if(!sane_layout(&in_ch_layout)) {
> +        av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
>          av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
> -        return AVERROR(EINVAL);
> +        ret = AVERROR(EINVAL);
> +        goto fail;
>      }
>  
> -    if(!sane_layout(out_ch_layout)){
> -        av_get_channel_layout_string(buf, sizeof(buf), -1, out_ch_layout_param);
> +    if(!av_channel_layout_check(&out_ch_layout)) {
> +        av_log(log_context, AV_LOG_ERROR, "Output channel layout is invalid\n");
> +        ret = AVERROR(EINVAL);
> +        goto fail;
> +    }
> +    if(!sane_layout(&out_ch_layout)) {
> +        av_channel_layout_describe(&out_ch_layout, buf, sizeof(buf));
>          av_log(log_context, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
> -        return AVERROR(EINVAL);
> +        ret = AVERROR(EINVAL);
> +        goto fail;
>      }
>  
>      for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){
> -        if(in_ch_layout & out_ch_layout & (1ULL<<i))
> +        int idx;
> +        if(   (idx = av_channel_layout_index_from_channel(&in_ch_layout, i)) >= 0
> +           && av_channel_layout_index_from_channel(&out_ch_layout, i) == idx)
>              matrix[i][i]= 1.0;
>      }
>  
> -    unaccounted= in_ch_layout & ~out_ch_layout;
> +    unaccounted =  in_ch_layout.u.mask & ~out_ch_layout.u.mask;

Weird whitespace.

>  
>  //FIXME implement dolby surround
>  //FIXME implement full ac3
>  
>  
>      if(unaccounted & AV_CH_FRONT_CENTER){
> -        if((out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
> -            if(in_ch_layout & AV_CH_LAYOUT_STEREO) {
> +        if(av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
> +            if(av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO)) {

Missing whitespace. Applies to the whole patch.

>                  matrix[ FRONT_LEFT][FRONT_CENTER]+= center_mix_level;
>                  matrix[FRONT_RIGHT][FRONT_CENTER]+= center_mix_level;
>              } else {
> @@ -187,23 +255,23 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>              av_assert0(0);
>      }
>      if(unaccounted & AV_CH_LAYOUT_STEREO){
> -        if(out_ch_layout & AV_CH_FRONT_CENTER){
> +        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
>              matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
>              matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
> -            if(in_ch_layout & AV_CH_FRONT_CENTER)
> +            if(av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_FRONT_CENTER) >= 0)
>                  matrix[FRONT_CENTER][ FRONT_CENTER] = center_mix_level*sqrt(2);
>          }else
>              av_assert0(0);
>      }
>  
>      if(unaccounted & AV_CH_BACK_CENTER){
> -        if(out_ch_layout & AV_CH_BACK_LEFT){
> +        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0){
>              matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
>              matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
> -        }else if(out_ch_layout & AV_CH_SIDE_LEFT){
> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){
>              matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;
>              matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;
> -        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
>              if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
>                  matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
>                  if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
> @@ -217,24 +285,24 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>                  matrix[ FRONT_LEFT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
>                  matrix[FRONT_RIGHT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
>              }
> -        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
>              matrix[ FRONT_CENTER][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
>          }else
>              av_assert0(0);
>      }
>      if(unaccounted & AV_CH_BACK_LEFT){
> -        if(out_ch_layout & AV_CH_BACK_CENTER){
> +        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0){
>              matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
>              matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
> -        }else if(out_ch_layout & AV_CH_SIDE_LEFT){
> -            if(in_ch_layout & AV_CH_SIDE_LEFT){
> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){
> +            if(av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){
>                  matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
>                  matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
>              }else{
>              matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
>              matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
>              }
> -        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
>              if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
>                  matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * M_SQRT1_2;
>                  matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;
> @@ -249,7 +317,7 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>                  matrix[ FRONT_LEFT][ BACK_LEFT] += surround_mix_level;
>                  matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level;
>              }
> -        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
>              matrix[ FRONT_CENTER][BACK_LEFT ]+= surround_mix_level*M_SQRT1_2;
>              matrix[ FRONT_CENTER][BACK_RIGHT]+= surround_mix_level*M_SQRT1_2;
>          }else
> @@ -257,20 +325,20 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>      }
>  
>      if(unaccounted & AV_CH_SIDE_LEFT){
> -        if(out_ch_layout & AV_CH_BACK_LEFT){
> +        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0){
>              /* if back channels do not exist in the input, just copy side
>                 channels to back channels, otherwise mix side into back */
> -            if (in_ch_layout & AV_CH_BACK_LEFT) {
> +            if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
>                  matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;
>                  matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;
>              } else {
>                  matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
>                  matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
>              }
> -        }else if(out_ch_layout & AV_CH_BACK_CENTER){
> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0){
>              matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;
>              matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;
> -        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
>              if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
>                  matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * M_SQRT1_2;
>                  matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;
> @@ -285,7 +353,7 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>                  matrix[ FRONT_LEFT][ SIDE_LEFT] += surround_mix_level;
>                  matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level;
>              }
> -        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
>              matrix[ FRONT_CENTER][SIDE_LEFT ]+= surround_mix_level * M_SQRT1_2;
>              matrix[ FRONT_CENTER][SIDE_RIGHT]+= surround_mix_level * M_SQRT1_2;
>          }else
> @@ -293,10 +361,10 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>      }
>  
>      if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
> -        if(out_ch_layout & AV_CH_FRONT_LEFT){
> +        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
>              matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
>              matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
> -        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
>              matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
>              matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
>          }else
> @@ -304,9 +372,9 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>      }
>      /* mix LFE into front left/right or center */
>      if (unaccounted & AV_CH_LOW_FREQUENCY) {
> -        if (out_ch_layout & AV_CH_FRONT_CENTER) {
> +        if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
>              matrix[FRONT_CENTER][LOW_FREQUENCY] += lfe_mix_level;
> -        } else if (out_ch_layout & AV_CH_FRONT_LEFT) {
> +        } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
>              matrix[FRONT_LEFT ][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
>              matrix[FRONT_RIGHT][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
>          } else
> @@ -316,15 +384,19 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>      for(out_i=i=0; i<64; i++){
>          double sum=0;
>          int in_i=0;
> -        if((out_ch_layout & (1ULL<<i)) == 0)
> +        if(av_channel_layout_index_from_channel(&out_ch_layout, i) < 0)
>              continue;
>          for(j=0; j<64; j++){
> -            if((in_ch_layout & (1ULL<<j)) == 0)
> +            if(av_channel_layout_index_from_channel(&in_ch_layout, j) < 0)
>                 continue;
>              if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0]))
>                  matrix_param[stride*out_i + in_i] = matrix[i][j];
> -            else
> -                matrix_param[stride*out_i + in_i] = i == j && (in_ch_layout & out_ch_layout & (1ULL<<i));
> +            else {
> +                int idx;
> +                matrix_param[stride*out_i + in_i] = i == j &&
> +                (   (idx = av_channel_layout_index_from_channel(&in_ch_layout, i)) >= 0
> +                 && av_channel_layout_index_from_channel(&out_ch_layout, i) == idx);
> +            }
>              sum += fabs(matrix_param[stride*out_i + in_i]);
>              in_i++;
>          }
> @@ -350,17 +422,22 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>      }
>  
>      av_log(log_context, AV_LOG_DEBUG, "Matrix coefficients:\n");
> -    for(i=0; i<av_get_channel_layout_nb_channels(out_ch_layout); i++){
> -        const char *c =
> -            av_get_channel_name(av_channel_layout_extract_channel(out_ch_layout, i));
> -        av_log(log_context, AV_LOG_DEBUG, "%s: ", c ? c : "?");
> -        for(j=0; j<av_get_channel_layout_nb_channels(in_ch_layout); j++){
> -            c = av_get_channel_name(av_channel_layout_extract_channel(in_ch_layout, j));
> -            av_log(log_context, AV_LOG_DEBUG, "%s:%f ", c ? c : "?", matrix_param[stride*i + j]);
> +    for(i = 0; i < out_ch_layout.nb_channels; i++){
> +        av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&out_ch_layout, i));
> +        av_log(log_context, AV_LOG_DEBUG, "%s: ", buf);
> +        for(j = 0; j < in_ch_layout.nb_channels; j++){
> +            av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&in_ch_layout, j));
> +            av_log(log_context, AV_LOG_DEBUG, "%s:%f ", buf, matrix_param[stride*i + j]);
>          }
>          av_log(log_context, AV_LOG_DEBUG, "\n");
>      }
> -    return 0;
> +
> +    ret = 0;
> +fail:
> +    av_channel_layout_uninit(&in_ch_layout);
> +    av_channel_layout_uninit(&out_ch_layout);
> +
> +    return ret;
>  }
>  
>  av_cold static int auto_matrix(SwrContext *s)
> @@ -377,7 +454,7 @@ av_cold static int auto_matrix(SwrContext *s)
>          maxval = INT_MAX;
>  
>      memset(s->matrix, 0, sizeof(s->matrix));
> -    ret = swr_build_matrix(s->in_ch_layout, s->out_ch_layout,
> +    ret = swr_build_matrix2(&s->in_ch_layout, &s->out_ch_layout,
>                             s->clev, s->slev, s->lfe_mix_level,
>                             maxval, s->rematrix_volume, (double*)s->matrix,
>                             s->matrix[1] - s->matrix[0], s->matrix_encoding, s);
> @@ -519,8 +596,8 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
>          off = len1 * out->bps;
>      }
>  
> -    av_assert0(!s->out_ch_layout || out->ch_count == av_get_channel_layout_nb_channels(s->out_ch_layout));
> -    av_assert0(!s-> in_ch_layout || in ->ch_count == av_get_channel_layout_nb_channels(s-> in_ch_layout));
> +    av_assert0(s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || out->ch_count == s->out_ch_layout.nb_channels);
> +    av_assert0(s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || in ->ch_count == s->in_ch_layout.nb_channels);
>  
>      for(out_i=0; out_i<out->ch_count; out_i++){
>          switch(s->matrix_ch[out_i][0]){
> diff --git a/libswresample/rematrix_template.c b/libswresample/rematrix_template.c
> index add65e3155..f5a508361c 100644
> --- a/libswresample/rematrix_template.c
> +++ b/libswresample/rematrix_template.c
> @@ -88,13 +88,16 @@ static void RENAME(mix8to2)(SAMPLE **out, const SAMPLE **in, COEFF *coeffp, inte
>  }
>  
>  static RENAME(mix_any_func_type) *RENAME(get_mix_any_func)(SwrContext *s){
> -    if(   s->out_ch_layout == AV_CH_LAYOUT_STEREO && (s->in_ch_layout == AV_CH_LAYOUT_5POINT1 || s->in_ch_layout == AV_CH_LAYOUT_5POINT1_BACK)
> +    if(   !av_channel_layout_compare(&s->out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)
> +       && (   !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1)
> +           || !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK))
>         && s->matrix[0][2] == s->matrix[1][2] && s->matrix[0][3] == s->matrix[1][3]
>         && !s->matrix[0][1] && !s->matrix[0][5] && !s->matrix[1][0] && !s->matrix[1][4]
>      )
>          return RENAME(mix6to2);
>  
> -    if(   s->out_ch_layout == AV_CH_LAYOUT_STEREO && s->in_ch_layout == AV_CH_LAYOUT_7POINT1
> +    if(   !av_channel_layout_compare(&s->out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)
> +       && !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1)
>         && s->matrix[0][2] == s->matrix[1][2] && s->matrix[0][3] == s->matrix[1][3]
>         && !s->matrix[0][1] && !s->matrix[0][5] && !s->matrix[1][0] && !s->matrix[1][4]
>         && !s->matrix[0][7] && !s->matrix[1][6]
> diff --git a/libswresample/swresample.c b/libswresample/swresample.c
> index 16734c9df9..f8fbd9134b 100644
> --- a/libswresample/swresample.c
> +++ b/libswresample/swresample.c
> @@ -56,6 +56,8 @@ int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map){
>      return 0;
>  }
>  
> +#if FF_API_OLD_CHANNEL_LAYOUT
> +FF_DISABLE_DEPRECATION_WARNINGS
>  struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
>                                        int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
>                                        int64_t  in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
> @@ -97,6 +99,58 @@ fail:
>      swr_free(&s);
>      return NULL;
>  }
> +FF_ENABLE_DEPRECATION_WARNINGS
> +#endif
> +
> +int swr_alloc_set_opts2(struct SwrContext **ps,
> +                        AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
> +                        AVChannelLayout *in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
> +                        int log_offset, void *log_ctx) {
> +    struct SwrContext *s = *ps;
> +    int ret;
> +
> +    if (!s) s = swr_alloc();
> +    if (!s) return AVERROR(ENOMEM);
> +
> +    s->log_level_offset= log_offset;
> +    s->log_ctx= log_ctx;

This has been copied from swr_alloc_set_opts without fixing whitespace
issues.

> +
> +    if ((ret = av_opt_set_chlayout(s, "ochl", out_ch_layout, 0)) < 0)
> +        goto fail;
> +
> +    if ((ret = av_opt_set_int(s, "osf", out_sample_fmt, 0)) < 0)
> +        goto fail;
> +
> +    if ((ret = av_opt_set_int(s, "osr", out_sample_rate, 0)) < 0)
> +        goto fail;
> +
> +    if ((ret = av_opt_set_chlayout(s, "ichl", in_ch_layout, 0)) < 0)
> +        goto fail;
> +
> +    if ((ret = av_opt_set_int(s, "isf", in_sample_fmt, 0)) < 0)
> +        goto fail;
> +
> +    if ((ret = av_opt_set_int(s, "isr", in_sample_rate, 0)) < 0)
> +        goto fail;
> +
> +    av_opt_set_int(s, "uch", 0, 0);
> +
> +#if FF_API_OLD_CHANNEL_LAYOUT
> +    // Clear old API values so they don't take precedence in swr_init()
> +    av_opt_set_int(s, "icl", 0, 0);
> +    av_opt_set_int(s, "ocl", 0, 0);
> +    av_opt_set_int(s, "ich", 0, 0);
> +    av_opt_set_int(s, "och", 0, 0);
> +#endif
> +
> +    *ps = s;
> +
> +    return 0;
> +fail:
> +    av_log(s, AV_LOG_ERROR, "Failed to set option\n");
> +    swr_free(ps);

In case s has been allocated by this function, it leaks. *ps = s needs
to be moved directly after allocation.

And why don't you implement the old API in terms of the new API?

> +    return ret;
> +}
>  
>  static void set_audiodata_fmt(AudioData *a, enum AVSampleFormat fmt){
>      a->fmt   = fmt;
> @@ -125,6 +179,8 @@ static void clear_context(SwrContext *s){
>      free_temp(&s->drop_temp);
>      free_temp(&s->dither.noise);
>      free_temp(&s->dither.temp);
> +    av_channel_layout_uninit(&s->in_ch_layout);
> +    av_channel_layout_uninit(&s->out_ch_layout);
>      swri_audio_convert_free(&s-> in_convert);
>      swri_audio_convert_free(&s->out_convert);
>      swri_audio_convert_free(&s->full_convert);
> @@ -138,6 +194,9 @@ av_cold void swr_free(SwrContext **ss){
>      SwrContext *s= *ss;
>      if(s){
>          clear_context(s);
> +        av_channel_layout_uninit(&s->user_in_chlayout);
> +        av_channel_layout_uninit(&s->user_out_chlayout);
> +
>          if (s->resampler)
>              s->resampler->free(&s->resample);
>      }
> @@ -172,25 +231,66 @@ av_cold int swr_init(struct SwrContext *s){
>          av_log(s, AV_LOG_ERROR, "Requested output sample rate %d is invalid\n", s->out_sample_rate);
>          return AVERROR(EINVAL);
>      }
> +    s->used_ch_count = s->user_used_ch_count;
> +#if FF_API_OLD_CHANNEL_LAYOUT
>      s->out.ch_count  = s-> user_out_ch_count;
>      s-> in.ch_count  = s->  user_in_ch_count;
> -    s->used_ch_count = s->user_used_ch_count;
>  
> -    s-> in_ch_layout = s-> user_in_ch_layout;
> -    s->out_ch_layout = s->user_out_ch_layout;
> +    // if the old/new fields are set inconsistently, prefer the old ones
> +    if ((s->user_in_ch_count && s->user_in_ch_count != s->user_in_chlayout.nb_channels) ||
> +        (s->user_in_ch_layout && (s->user_in_chlayout.order != AV_CHANNEL_ORDER_NATIVE ||
> +                                  s->user_in_chlayout.u.mask != s->user_in_ch_layout))) {
> +        av_channel_layout_uninit(&s->in_ch_layout);
> +        if (s->user_in_ch_layout)
> +            av_channel_layout_from_mask(&s->in_ch_layout, s->user_in_ch_layout);
> +        else {
> +            s->in_ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
> +            s->in_ch_layout.nb_channels = s->user_in_ch_count;
> +        }
> +    } else
> +        av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout);
> +
> +    if ((s->user_out_ch_count && s->user_out_ch_count != s->user_out_chlayout.nb_channels) ||
> +        (s->user_out_ch_layout && (s->user_out_chlayout.order != AV_CHANNEL_ORDER_NATIVE ||
> +                                   s->user_out_chlayout.u.mask != s->user_out_ch_layout))) {
> +        av_channel_layout_uninit(&s->out_ch_layout);
> +        if (s->user_out_ch_layout)
> +            av_channel_layout_from_mask(&s->out_ch_layout, s->user_out_ch_layout);
> +        else {
> +            s->out_ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
> +            s->out_ch_layout.nb_channels = s->user_out_ch_count;
> +        }
> +    } else
> +        av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout);
> +
> +    if (!s->out.ch_count && !s->user_out_ch_layout)
> +        s->out.ch_count  = s->out_ch_layout.nb_channels;
> +    if (!s-> in.ch_count && !s-> user_in_ch_layout)
> +        s-> in.ch_count  = s->in_ch_layout.nb_channels;
> +#else
> +    s->out.ch_count  = s-> user_out_chlayout.nb_channels;
> +    s-> in.ch_count  = s->  user_in_chlayout.nb_channels;
> +
> +    ret  = av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout);
> +    ret |= av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout);
> +    if (ret < 0)
> +        return ret;
> +#endif
>  
>      s->int_sample_fmt= s->user_int_sample_fmt;
>  
>      s->dither.method = s->user_dither_method;
>  
> -    if(av_get_channel_layout_nb_channels(s-> in_ch_layout) > SWR_CH_MAX) {
> -        av_log(s, AV_LOG_WARNING, "Input channel layout 0x%"PRIx64" is invalid or unsupported.\n", s-> in_ch_layout);
> -        s->in_ch_layout = 0;
> +    if (!av_channel_layout_check(&s->in_ch_layout) || s->in_ch_layout.nb_channels > SWR_CH_MAX) {
> +        av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1));
> +        av_log(s, AV_LOG_WARNING, "Input channel layout \"%s\" is invalid or unsupported.\n", l1);
> +        av_channel_layout_uninit(&s->in_ch_layout);
>      }
>  
> -    if(av_get_channel_layout_nb_channels(s->out_ch_layout) > SWR_CH_MAX) {
> -        av_log(s, AV_LOG_WARNING, "Output channel layout 0x%"PRIx64" is invalid or unsupported.\n", s->out_ch_layout);
> -        s->out_ch_layout = 0;
> +    if (!av_channel_layout_check(&s->out_ch_layout) || s->out_ch_layout.nb_channels > SWR_CH_MAX) {
> +        av_channel_layout_describe(&s->out_ch_layout, l2, sizeof(l2));
> +        av_log(s, AV_LOG_WARNING, "Output channel layout \"%s\" is invalid or unsupported.\n", l2);
> +        av_channel_layout_uninit(&s->out_ch_layout);
>      }
>  
>      switch(s->engine){
> @@ -206,17 +306,18 @@ av_cold int swr_init(struct SwrContext *s){
>      if(!s->used_ch_count)
>          s->used_ch_count= s->in.ch_count;
>  
> -    if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){
> +    if(s->used_ch_count && s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_ch_count != s->in_ch_layout.nb_channels){
>          av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
> -        s-> in_ch_layout= 0;
> +        av_channel_layout_uninit(&s->in_ch_layout);
>      }
>  
> -    if(!s-> in_ch_layout)
> -        s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count);
> -    if(!s->out_ch_layout)
> -        s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count);
> +    if(!s->in_ch_layout.nb_channels || s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
> +        av_channel_layout_default(&s->in_ch_layout, s->used_ch_count);
> +    if(!s->out_ch_layout.nb_channels || s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
> +        av_channel_layout_default(&s->out_ch_layout, s->out.ch_count);
>  
> -    s->rematrix= s->out_ch_layout  !=s->in_ch_layout || s->rematrix_volume!=1.0 ||
> +    s->rematrix= av_channel_layout_compare(&s->out_ch_layout, &s->in_ch_layout) ||
> +                 s->rematrix_volume!=1.0 ||
>                   s->rematrix_custom;
>  
>      if(s->int_sample_fmt == AV_SAMPLE_FMT_NONE){
> @@ -291,33 +392,36 @@ av_cold int swr_init(struct SwrContext *s){
>  
>  #define RSC 1 //FIXME finetune
>      if(!s-> in.ch_count)
> -        s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout);
> +        s-> in.ch_count = s->in_ch_layout.nb_channels;
>      if(!s->used_ch_count)
>          s->used_ch_count= s->in.ch_count;
>      if(!s->out.ch_count)
> -        s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout);
> +        s->out.ch_count = s->out_ch_layout.nb_channels;
>  
>      if(!s-> in.ch_count){
> -        av_assert0(!s->in_ch_layout);
> +        av_assert0(s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC);
>          av_log(s, AV_LOG_ERROR, "Input channel count and layout are unset\n");
>          ret = AVERROR(EINVAL);
>          goto fail;
>      }
>  
> -    av_get_channel_layout_string(l1, sizeof(l1), s-> in.ch_count, s-> in_ch_layout);
> -    av_get_channel_layout_string(l2, sizeof(l2), s->out.ch_count, s->out_ch_layout);
> -    if (s->out_ch_layout && s->out.ch_count != av_get_channel_layout_nb_channels(s->out_ch_layout)) {
> +#if FF_API_OLD_CHANNEL_LAYOUT
> +    av_channel_layout_describe(&s->out_ch_layout, l1, sizeof(l1));
> +    if (s->out_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->out.ch_count != s->out_ch_layout.nb_channels) {
>          av_log(s, AV_LOG_ERROR, "Output channel layout %s mismatches specified channel count %d\n", l2, s->out.ch_count);
>          ret = AVERROR(EINVAL);
>          goto fail;
>      }
> -    if (s->in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s->in_ch_layout)) {
> +#endif
> +    av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1));
> +    if (s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_ch_count != s->in_ch_layout.nb_channels) {
>          av_log(s, AV_LOG_ERROR, "Input channel layout %s mismatches specified channel count %d\n", l1, s->used_ch_count);
>          ret = AVERROR(EINVAL);
>          goto fail;
>      }
>  
> -    if ((!s->out_ch_layout || !s->in_ch_layout) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) {
> +    if ((   s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC
> +         || s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) {
>          av_log(s, AV_LOG_ERROR, "Rematrix is needed between %s and %s "
>                 "but there is not enough information to do it\n", l1, l2);
>          ret = AVERROR(EINVAL);
> diff --git a/libswresample/swresample.h b/libswresample/swresample.h
> index c7b84fbcac..c6ff2345e9 100644
> --- a/libswresample/swresample.h
> +++ b/libswresample/swresample.h
> @@ -227,6 +227,7 @@ int swr_init(struct SwrContext *s);
>   */
>  int swr_is_initialized(struct SwrContext *s);
>  
> +#if FF_API_OLD_CHANNEL_LAYOUT
>  /**
>   * Allocate SwrContext if needed and set/reset common parameters.
>   *
> @@ -246,12 +247,40 @@ int swr_is_initialized(struct SwrContext *s);
>   *
>   * @see swr_init(), swr_free()
>   * @return NULL on error, allocated context otherwise
> + * @deprecated use @ref swr_alloc_set_opts2()
>   */
> +attribute_deprecated
>  struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
>                                        int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
>                                        int64_t  in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
>                                        int log_offset, void *log_ctx);
> +#endif
>  
> +/**
> + * Allocate SwrContext if needed and set/reset common parameters.
> + *
> + * This function does not require s to be allocated with swr_alloc(). On the
> + * other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters
> + * on the allocated context.
> + *
> + * @param ps              Pointer to an existing Swr context if available, or to NULL if not.
> + *                        On success, *ps will be set the allocated context.

This does not sound like proper English to me.
Moreover, it does not document that an already allocated context will be
freed here on error.

> + * @param out_ch_layout   output channel layout (AV_CH_LAYOUT_*)
> + * @param out_sample_fmt  output sample format (AV_SAMPLE_FMT_*).
> + * @param out_sample_rate output sample rate (frequency in Hz)
> + * @param in_ch_layout    input channel layout (AV_CH_LAYOUT_*)
> + * @param in_sample_fmt   input sample format (AV_SAMPLE_FMT_*).
> + * @param in_sample_rate  input sample rate (frequency in Hz)
> + * @param log_offset      logging level offset
> + * @param log_ctx         parent logging context, can be NULL
> + *
> + * @see swr_init(), swr_free()
> + * @return 0 on success, a negative AVERROR code on error.
> + */
> +int swr_alloc_set_opts2(struct SwrContext **ps,
> +                        AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
> +                        AVChannelLayout *in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
> +                        int log_offset, void *log_ctx);
>  /**
>   * @}
>   *
> @@ -362,6 +391,7 @@ int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensatio
>   */
>  int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
>  
> +#if FF_API_OLD_CHANNEL_LAYOUT
>  /**
>   * Generate a channel mixing matrix.
>   *
> @@ -384,13 +414,46 @@ int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
>   * @param matrix_encoding     matrixed stereo downmix mode (e.g. dplii)
>   * @param log_ctx             parent logging context, can be NULL
>   * @return                    0 on success, negative AVERROR code on failure
> + * @deprecated                use @ref swr_build_matrix2()
>   */
> +attribute_deprecated
>  int swr_build_matrix(uint64_t in_layout, uint64_t out_layout,
>                       double center_mix_level, double surround_mix_level,
>                       double lfe_mix_level, double rematrix_maxval,
>                       double rematrix_volume, double *matrix,
>                       int stride, enum AVMatrixEncoding matrix_encoding,
>                       void *log_ctx);
> +#endif
> +
> +/**
> + * Generate a channel mixing matrix.
> + *
> + * This function is the one used internally by libswresample for building the
> + * default mixing matrix. It is made public just as a utility function for
> + * building custom matrices.
> + *
> + * @param in_layout           input channel layout
> + * @param out_layout          output channel layout
> + * @param center_mix_level    mix level for the center channel
> + * @param surround_mix_level  mix level for the surround channel(s)
> + * @param lfe_mix_level       mix level for the low-frequency effects channel
> + * @param rematrix_maxval     if 1.0, coefficients will be normalized to prevent
> + *                            overflow. if INT_MAX, coefficients will not be
> + *                            normalized.
> + * @param[out] matrix         mixing coefficients; matrix[i + stride * o] is
> + *                            the weight of input channel i in output channel o.

The parameter below is named matrix_param.

> + * @param stride              distance between adjacent input channels in the
> + *                            matrix array
> + * @param matrix_encoding     matrixed stereo downmix mode (e.g. dplii)
> + * @param log_ctx             parent logging context, can be NULL
> + * @return                    0 on success, negative AVERROR code on failure
> + */
> +int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
> +                      double center_mix_level, double surround_mix_level,
> +                      double lfe_mix_level, double maxval,
> +                      double rematrix_volume, double *matrix_param,
> +                      ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding,
> +                      void *log_context);
>  
>  /**
>   * Set a customized remix matrix.
> diff --git a/libswresample/swresample_frame.c b/libswresample/swresample_frame.c
> index d95c1cc537..747cf119a9 100644
> --- a/libswresample/swresample_frame.c
> +++ b/libswresample/swresample_frame.c
> @@ -29,7 +29,19 @@ int swr_config_frame(SwrContext *s, const AVFrame *out, const AVFrame *in)
>      swr_close(s);
>  
>      if (in) {
> -        if (av_opt_set_int(s, "icl", in->channel_layout, 0) < 0)
> +        AVChannelLayout in_ch_layout = { 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(&in_ch_layout, in->channel_layout);
> +FF_ENABLE_DEPRECATION_WARNINGS
> +        } else
> +#endif
> +        if (av_channel_layout_copy(&in_ch_layout, &in->ch_layout) < 0)
> +            goto fail;
> +        if (av_opt_set_chlayout(s, "ichl", &in_ch_layout, 0) < 0)
>              goto fail;
>          if (av_opt_set_int(s, "isf", in->format, 0) < 0)
>              goto fail;
> @@ -38,7 +50,19 @@ int swr_config_frame(SwrContext *s, const AVFrame *out, const AVFrame *in)
>      }
>  
>      if (out) {
> -        if (av_opt_set_int(s, "ocl", out->channel_layout, 0) < 0)
> +        AVChannelLayout out_ch_layout = { 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_from_mask(&out_ch_layout, out->channel_layout);
> +FF_ENABLE_DEPRECATION_WARNINGS
> +        } else
> +#endif
> +        if (av_channel_layout_copy(&out_ch_layout, &out->ch_layout) < 0)
> +            goto fail;
> +        if (av_opt_set_chlayout(s, "ochl", &out_ch_layout, 0) < 0)
>              goto fail;
>          if (av_opt_set_int(s, "osf", out->format,  0) < 0)
>              goto fail;
> @@ -58,7 +82,19 @@ static int config_changed(SwrContext *s,
>      int ret = 0;
>  
>      if (in) {
> -        if (s->in_ch_layout   != in->channel_layout ||
> +        AVChannelLayout in_ch_layout = { 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(&in_ch_layout, in->channel_layout);
> +FF_ENABLE_DEPRECATION_WARNINGS
> +        } else
> +#endif
> +        if ((ret = av_channel_layout_copy(&in_ch_layout, &in->ch_layout)) < 0)
> +            return ret;
> +        if (av_channel_layout_compare(&s->in_ch_layout, &in_ch_layout) ||
>              s->in_sample_rate != in->sample_rate ||
>              s->in_sample_fmt  != in->format) {
>              ret |= AVERROR_INPUT_CHANGED;
> @@ -66,7 +102,19 @@ static int config_changed(SwrContext *s,
>      }
>  
>      if (out) {
> -        if (s->out_ch_layout   != out->channel_layout ||
> +        AVChannelLayout out_ch_layout = { 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_from_mask(&out_ch_layout, out->channel_layout);
> +FF_ENABLE_DEPRECATION_WARNINGS
> +        } else
> +#endif
> +        if ((ret = av_channel_layout_copy(&out_ch_layout, &out->ch_layout)) < 0)
> +            return ret;
> +        if (av_channel_layout_compare(&s->out_ch_layout, &out_ch_layout) ||
>              s->out_sample_rate != out->sample_rate ||
>              s->out_sample_fmt  != out->format) {
>              ret |= AVERROR_OUTPUT_CHANGED;
> @@ -116,7 +164,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;
>      }
>  }
> diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
> index f2ea5a226d..262a0e2b8c 100644
> --- a/libswresample/swresample_internal.h
> +++ b/libswresample/swresample_internal.h
> @@ -99,8 +99,8 @@ struct SwrContext {
>      enum AVSampleFormat  in_sample_fmt;             ///< input sample format
>      enum AVSampleFormat int_sample_fmt;             ///< internal sample format (AV_SAMPLE_FMT_FLTP or AV_SAMPLE_FMT_S16P)
>      enum AVSampleFormat out_sample_fmt;             ///< output sample format
> -    int64_t  in_ch_layout;                          ///< input channel layout
> -    int64_t out_ch_layout;                          ///< output channel layout
> +    AVChannelLayout  in_ch_layout;                  ///< input channel layout
> +    AVChannelLayout out_ch_layout;                  ///< output channel layout
>      int      in_sample_rate;                        ///< input sample rate
>      int     out_sample_rate;                        ///< output sample rate
>      int flags;                                      ///< miscellaneous flags such as SWR_FLAG_RESAMPLE
> @@ -114,11 +114,15 @@ struct SwrContext {
>      int used_ch_count;                              ///< number of used input channels (mapped channel count if channel_map, otherwise in.ch_count)
>      int engine;
>  
> +    int user_used_ch_count;                         ///< User set used channel count
> +#if FF_API_OLD_CHANNEL_LAYOUT
>      int user_in_ch_count;                           ///< User set input channel count
>      int user_out_ch_count;                          ///< User set output channel count
> -    int user_used_ch_count;                         ///< User set used channel count
>      int64_t user_in_ch_layout;                      ///< User set input channel layout
>      int64_t user_out_ch_layout;                     ///< User set output channel layout
> +#endif
> +    AVChannelLayout user_in_chlayout;               ///< User set input channel layout
> +    AVChannelLayout user_out_chlayout;              ///< User set output channel layout
>      enum AVSampleFormat user_int_sample_fmt;        ///< User set internal sample format
>      int user_dither_method;                         ///< User set dither method
>  
> 

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 274/281] swresample: convert to new channel layout API
  2022-01-19 17:20   ` Andreas Rheinhardt
@ 2022-01-19 17:29     ` James Almer
  0 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-19 17:29 UTC (permalink / raw)
  To: ffmpeg-devel

On 1/19/2022 2:20 PM, Andreas Rheinhardt wrote:
> James Almer:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libswresample/options.c             |  33 +++-
>>   libswresample/rematrix.c            | 237 ++++++++++++++++++----------
>>   libswresample/rematrix_template.c   |   7 +-
>>   libswresample/swresample.c          | 152 +++++++++++++++---
>>   libswresample/swresample.h          |  63 ++++++++
> 
> This header still contains many references to swr_alloc_set_opts().

Will change.

> 
>>   libswresample/swresample_frame.c    |  65 +++++++-
>>   libswresample/swresample_internal.h |  10 +-
>>   7 files changed, 445 insertions(+), 122 deletions(-)
>>
>> diff --git a/libswresample/options.c b/libswresample/options.c
>> index 6911709157..ffa27c590d 100644
>> --- a/libswresample/options.c
>> +++ b/libswresample/options.c
>> @@ -34,12 +34,19 @@
>>   
>>   #define OFFSET(x) offsetof(SwrContext,x)
>>   #define PARAM AV_OPT_FLAG_AUDIO_PARAM
>> +#define DEPREC AV_OPT_FLAG_DEPRECATED
>>   
>>   static const AVOption options[]={
>> -{"ich"                  , "set input channel count"     , OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
>> -{"in_channel_count"     , "set input channel count"     , OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
>> -{"och"                  , "set output channel count"    , OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
>> -{"out_channel_count"    , "set output channel count"    , OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>> +{"ich"                  , "set input channel count (Deprecated, use ichl)",
>> +                                                          OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
>> +{"in_channel_count"     , "set input channel count (Deprecated, use in_chlayout)",
>> +                                                          OFFSET(user_in_ch_count  ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
>> +{"och"                  , "set output channel count (Deprecated, use ochl)",
>> +                                                          OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
>> +{"out_channel_count"    , "set output channel count (Deprecated, use out_chlayout)",
>> +                                                          OFFSET(user_out_ch_count ), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM|DEPREC},
>> +#endif
>>   {"uch"                  , "set used channel count"      , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
>>   {"used_channel_count"   , "set used channel count"      , OFFSET(user_used_ch_count), AV_OPT_TYPE_INT, {.i64=0                    }, 0      , SWR_CH_MAX, PARAM},
>>   {"isr"                  , "set input sample rate"       , OFFSET( in_sample_rate), AV_OPT_TYPE_INT  , {.i64=0                     }, 0      , INT_MAX   , PARAM},
>> @@ -52,10 +59,20 @@ static const AVOption options[]={
>>   {"out_sample_fmt"       , "set output sample format"    , OFFSET(out_sample_fmt ), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1   , INT_MAX, PARAM},
>>   {"tsf"                  , "set internal sample format"  , OFFSET(user_int_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1   , INT_MAX, PARAM},
>>   {"internal_sample_fmt"  , "set internal sample format"  , OFFSET(user_int_sample_fmt), AV_OPT_TYPE_SAMPLE_FMT , {.i64=AV_SAMPLE_FMT_NONE}, -1   , INT_MAX, PARAM},
>> -{"icl"                  , "set input channel layout"    , OFFSET(user_in_ch_layout ), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
>> -{"in_channel_layout"    , "set input channel layout"    , OFFSET(user_in_ch_layout ), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
>> -{"ocl"                  , "set output channel layout"   , OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
>> -{"out_channel_layout"   , "set output channel layout"   , OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0           }, INT64_MIN, INT64_MAX , PARAM, "channel_layout"},
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>> +{"icl"                  , "set input channel layout (Deprecated, use ichl)",
>> +                                                          OFFSET(user_in_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0          }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
>> +{"in_channel_layout"    , "set input channel layout (Deprecated, use in_chlayout)",
>> +                                                          OFFSET(user_in_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0          }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
>> +{"ocl"                  , "set output channel layout (Deprecated, use ochl)",
>> +                                                          OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0         }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
>> +{"out_channel_layout"   , "set output channel layout (Deprecated, use out_chlayout)",
>> +                                                          OFFSET(user_out_ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=0         }, INT64_MIN, INT64_MAX, PARAM|DEPREC, "channel_layout"},
>> +#endif
>> +{"ichl"                 , "set input channel layout"    , OFFSET(user_in_chlayout ), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
>> +{"in_chlayout"          , "set input channel layout"    , OFFSET(user_in_chlayout ), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
>> +{"ochl"                 , "set output channel layout"   , OFFSET(user_out_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
>> +{"out_chlayout"         , "set output channel layout"   , OFFSET(user_out_chlayout), AV_OPT_TYPE_CHLAYOUT, {.str=NULL             }, 0, 0 , PARAM, "chlayout"},
>>   {"clev"                 , "set center mix level"        , OFFSET(clev           ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB                }, -32    , 32        , PARAM},
>>   {"center_mix_level"     , "set center mix level"        , OFFSET(clev           ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB                }, -32    , 32        , PARAM},
>>   {"slev"                 , "set surround mix level"      , OFFSET(slev           ), AV_OPT_TYPE_FLOAT, {.dbl=C_30DB                }, -32    , 32        , PARAM},
>> diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
>> index 94b3de88f6..35086c218d 100644
>> --- a/libswresample/rematrix.c
>> +++ b/libswresample/rematrix.c
>> @@ -64,15 +64,37 @@
>>   int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
>>   {
>>       int nb_in, nb_out, in, out;
>> +    int user_in_chlayout_nb_channels, user_out_chlayout_nb_channels;
>>   
>>       if (!s || s->in_convert) // s needs to be allocated but not initialized
>>           return AVERROR(EINVAL);
>>       memset(s->matrix, 0, sizeof(s->matrix));
>>       memset(s->matrix_flt, 0, sizeof(s->matrix_flt));
>> -    nb_in = (s->user_in_ch_count > 0) ? s->user_in_ch_count :
>> -        av_get_channel_layout_nb_channels(s->user_in_ch_layout);
>> -    nb_out = (s->user_out_ch_count > 0) ? s->user_out_ch_count :
>> -        av_get_channel_layout_nb_channels(s->user_out_ch_layout);
>> +
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>> +FF_DISABLE_DEPRECATION_WARNINGS
>> +    user_in_chlayout_nb_channels = av_get_channel_layout_nb_channels(s->user_in_ch_layout);
>> +FF_ENABLE_DEPRECATION_WARNINGS
>> +    if (!user_in_chlayout_nb_channels)
>> +#endif
>> +    user_in_chlayout_nb_channels = s->user_in_chlayout.nb_channels;
>> +    nb_in =
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>> +            (s->user_in_ch_count > 0) ? s->user_in_ch_count :
>> +#endif
>> +            user_in_chlayout_nb_channels;
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>> +FF_DISABLE_DEPRECATION_WARNINGS
>> +    user_out_chlayout_nb_channels = av_get_channel_layout_nb_channels(s->user_out_ch_layout);
>> +FF_ENABLE_DEPRECATION_WARNINGS
>> +    if (!user_out_chlayout_nb_channels)
>> +#endif
>> +    user_out_chlayout_nb_channels = s->user_out_chlayout.nb_channels;
>> +    nb_out =
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>> +             (s->user_out_ch_count > 0) ? s->user_out_ch_count :
>> +#endif
>> +             user_out_chlayout_nb_channels;
>>       for (out = 0; out < nb_out; out++) {
>>           for (in = 0; in < nb_in; in++)
>>               s->matrix_flt[out][in] = s->matrix[out][in] = matrix[in];
>> @@ -88,95 +110,141 @@ static int even(int64_t layout){
>>       return 0;
>>   }
>>   
>> -static int64_t clean_layout(void *s, int64_t layout){
>> -    if(layout && layout != AV_CH_FRONT_CENTER && !(layout&(layout-1))) {
>> +static int clean_layout(AVChannelLayout *out, const AVChannelLayout *in, void *s)
>> +{
>> +    int ret = 0;
>> +
>> +    if(av_channel_layout_index_from_channel(in, AV_CH_FRONT_CENTER) < 0 && in->nb_channels == 1) {
>>           char buf[128];
>> -        av_get_channel_layout_string(buf, sizeof(buf), -1, layout);
>> +        av_channel_layout_describe(in, buf, sizeof(buf));
>>           av_log(s, AV_LOG_VERBOSE, "Treating %s as mono\n", buf);
>> -        return AV_CH_FRONT_CENTER;
>> -    }
>> +        *out = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
>> +    } else
>> +        ret = av_channel_layout_copy(out, in);
>>   
>> -    return layout;
>> +    return ret;
>>   }
>>   
>> -static int sane_layout(int64_t layout){
>> -    if(!(layout & AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker
>> +static int sane_layout(AVChannelLayout *ch_layout) {
>> +    if (ch_layout->order != AV_CHANNEL_ORDER_NATIVE)
>> +        return 0;
>> +    if(!av_channel_layout_subset(ch_layout, AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker
>>           return 0;
>> -    if(!even(layout & (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT))) // no asymetric front
>> +    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)))) // no asymetric front
>>           return 0;
>> -    if(!even(layout & (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)))   // no asymetric side
>> +    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT))))   // no asymetric side
>>           return 0;
>> -    if(!even(layout & (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)))
>> +    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT))))
>>           return 0;
>> -    if(!even(layout & (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)))
>> +    if(!even(av_channel_layout_subset(ch_layout, (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER))))
>>           return 0;
>> -    if(av_get_channel_layout_nb_channels(layout) >= SWR_CH_MAX)
>> +    if(ch_layout->nb_channels >= SWR_CH_MAX)
>>           return 0;
>>   
>>       return 1;
>>   }
>>   
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>>   av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout_param,
>>                                double center_mix_level, double surround_mix_level,
>>                                double lfe_mix_level, double maxval,
>>                                double rematrix_volume, double *matrix_param,
>>                                int stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
>>   {
>> -    int i, j, out_i;
>> +    AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
>> +    int ret;
>> +
>> +    ret  = av_channel_layout_from_mask(&in_ch_layout, in_ch_layout_param);
>> +    ret |= av_channel_layout_from_mask(&out_ch_layout, out_ch_layout_param);
>> +    if (ret < 0)
>> +        return ret;
>> +
>> +    return swr_build_matrix2(&in_ch_layout, &out_ch_layout, center_mix_level, surround_mix_level,
>> +                             lfe_mix_level, maxval, rematrix_volume, matrix_param,
>> +                             stride, matrix_encoding, log_context);
>> +}
>> +#endif
>> +
>> +av_cold int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
>> +                              double center_mix_level, double surround_mix_level,
>> +                              double lfe_mix_level, double maxval,
>> +                              double rematrix_volume, double *matrix_param,
>> +                              ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding, void *log_context)
>> +{
>> +    int i, j, out_i, ret;
>> +    AVChannelLayout in_ch_layout = { 0 }, out_ch_layout = { 0 };
>>       double matrix[NUM_NAMED_CHANNELS][NUM_NAMED_CHANNELS]={{0}};
>> -    int64_t unaccounted, in_ch_layout, out_ch_layout;
>> +    int64_t unaccounted;
>>       double maxcoef=0;
>>       char buf[128];
>>   
>> -     in_ch_layout = clean_layout(log_context,  in_ch_layout_param);
>> -    out_ch_layout = clean_layout(log_context, out_ch_layout_param);
>> -
>> -    if(   out_ch_layout == AV_CH_LAYOUT_STEREO_DOWNMIX
>> -       && (in_ch_layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == 0
>> -    )
>> -        out_ch_layout = AV_CH_LAYOUT_STEREO;
>> +    ret  = clean_layout(&in_ch_layout, in_layout, log_context);
>> +    ret |= clean_layout(&out_ch_layout, out_layout, log_context);
>> +    if (ret < 0)
>> +        goto fail;
>>   
>> -    if(    in_ch_layout == AV_CH_LAYOUT_STEREO_DOWNMIX
>> -       && (out_ch_layout & AV_CH_LAYOUT_STEREO_DOWNMIX) == 0
>> -    )
>> -        in_ch_layout = AV_CH_LAYOUT_STEREO;
>> -
>> -    if (in_ch_layout == AV_CH_LAYOUT_22POINT2 &&
>> -        out_ch_layout != AV_CH_LAYOUT_22POINT2) {
>> -        in_ch_layout = (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER);
>> -        av_get_channel_layout_string(buf, sizeof(buf), -1, in_ch_layout);
>> +    if(   !av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
>> +       && !av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
>> +    ) {
>> +        av_channel_layout_uninit(&out_ch_layout);
>> +        out_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
>> +    }
>> +    if(   !av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)
>> +       && !av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO_DOWNMIX)
>> +    ) {
>> +        av_channel_layout_uninit(&in_ch_layout);
>> +        in_ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
>> +    }
>> +    if (!av_channel_layout_compare(&in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2) &&
>> +        av_channel_layout_compare(&out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2)) {
>> +        av_channel_layout_from_mask(&in_ch_layout, (AV_CH_LAYOUT_7POINT1_WIDE_BACK|AV_CH_BACK_CENTER));
>> +        av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
>>           av_log(log_context, AV_LOG_WARNING,
>>                  "Full-on remixing from 22.2 has not yet been implemented! "
>>                  "Processing the input as '%s'\n",
>>                  buf);
>>       }
>>   
>> -    if(!sane_layout(in_ch_layout)){
>> -        av_get_channel_layout_string(buf, sizeof(buf), -1, in_ch_layout_param);
>> +    if(!av_channel_layout_check(&in_ch_layout)) {
>> +        av_log(log_context, AV_LOG_ERROR, "Input channel layout is invalid\n");
>> +        ret = AVERROR(EINVAL);
>> +        goto fail;
>> +    }
>> +    if(!sane_layout(&in_ch_layout)) {
>> +        av_channel_layout_describe(&in_ch_layout, buf, sizeof(buf));
>>           av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s' is not supported\n", buf);
>> -        return AVERROR(EINVAL);
>> +        ret = AVERROR(EINVAL);
>> +        goto fail;
>>       }
>>   
>> -    if(!sane_layout(out_ch_layout)){
>> -        av_get_channel_layout_string(buf, sizeof(buf), -1, out_ch_layout_param);
>> +    if(!av_channel_layout_check(&out_ch_layout)) {
>> +        av_log(log_context, AV_LOG_ERROR, "Output channel layout is invalid\n");
>> +        ret = AVERROR(EINVAL);
>> +        goto fail;
>> +    }
>> +    if(!sane_layout(&out_ch_layout)) {
>> +        av_channel_layout_describe(&out_ch_layout, buf, sizeof(buf));
>>           av_log(log_context, AV_LOG_ERROR, "Output channel layout '%s' is not supported\n", buf);
>> -        return AVERROR(EINVAL);
>> +        ret = AVERROR(EINVAL);
>> +        goto fail;
>>       }
>>   
>>       for(i=0; i<FF_ARRAY_ELEMS(matrix); i++){
>> -        if(in_ch_layout & out_ch_layout & (1ULL<<i))
>> +        int idx;
>> +        if(   (idx = av_channel_layout_index_from_channel(&in_ch_layout, i)) >= 0
>> +           && av_channel_layout_index_from_channel(&out_ch_layout, i) == idx)
>>               matrix[i][i]= 1.0;
>>       }
>>   
>> -    unaccounted= in_ch_layout & ~out_ch_layout;
>> +    unaccounted =  in_ch_layout.u.mask & ~out_ch_layout.u.mask;
> 
> Weird whitespace.
> 
>>   
>>   //FIXME implement dolby surround
>>   //FIXME implement full ac3
>>   
>>   
>>       if(unaccounted & AV_CH_FRONT_CENTER){
>> -        if((out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
>> -            if(in_ch_layout & AV_CH_LAYOUT_STEREO) {
>> +        if(av_channel_layout_subset(&out_ch_layout, AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){
>> +            if(av_channel_layout_subset(&in_ch_layout, AV_CH_LAYOUT_STEREO)) {
> 
> Missing whitespace. Applies to the whole patch.

More like the entire file. But ok, will fix the whitespace on the lines 
i change.

> 
>>                   matrix[ FRONT_LEFT][FRONT_CENTER]+= center_mix_level;
>>                   matrix[FRONT_RIGHT][FRONT_CENTER]+= center_mix_level;
>>               } else {
>> @@ -187,23 +255,23 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>>               av_assert0(0);
>>       }
>>       if(unaccounted & AV_CH_LAYOUT_STEREO){
>> -        if(out_ch_layout & AV_CH_FRONT_CENTER){
>> +        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
>>               matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2;
>>               matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2;
>> -            if(in_ch_layout & AV_CH_FRONT_CENTER)
>> +            if(av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_FRONT_CENTER) >= 0)
>>                   matrix[FRONT_CENTER][ FRONT_CENTER] = center_mix_level*sqrt(2);
>>           }else
>>               av_assert0(0);
>>       }
>>   
>>       if(unaccounted & AV_CH_BACK_CENTER){
>> -        if(out_ch_layout & AV_CH_BACK_LEFT){
>> +        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0){
>>               matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2;
>>               matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2;
>> -        }else if(out_ch_layout & AV_CH_SIDE_LEFT){
>> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){
>>               matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2;
>>               matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2;
>> -        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
>> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
>>               if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY ||
>>                   matrix_encoding == AV_MATRIX_ENCODING_DPLII) {
>>                   if (unaccounted & (AV_CH_BACK_LEFT | AV_CH_SIDE_LEFT)) {
>> @@ -217,24 +285,24 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>>                   matrix[ FRONT_LEFT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
>>                   matrix[FRONT_RIGHT][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
>>               }
>> -        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
>> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
>>               matrix[ FRONT_CENTER][BACK_CENTER]+= surround_mix_level * M_SQRT1_2;
>>           }else
>>               av_assert0(0);
>>       }
>>       if(unaccounted & AV_CH_BACK_LEFT){
>> -        if(out_ch_layout & AV_CH_BACK_CENTER){
>> +        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0){
>>               matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2;
>>               matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2;
>> -        }else if(out_ch_layout & AV_CH_SIDE_LEFT){
>> -            if(in_ch_layout & AV_CH_SIDE_LEFT){
>> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){
>> +            if(av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_SIDE_LEFT) >= 0){
>>                   matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2;
>>                   matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2;
>>               }else{
>>               matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0;
>>               matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0;
>>               }
>> -        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
>> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
>>               if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
>>                   matrix[FRONT_LEFT ][BACK_LEFT ] -= surround_mix_level * M_SQRT1_2;
>>                   matrix[FRONT_LEFT ][BACK_RIGHT] -= surround_mix_level * M_SQRT1_2;
>> @@ -249,7 +317,7 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>>                   matrix[ FRONT_LEFT][ BACK_LEFT] += surround_mix_level;
>>                   matrix[FRONT_RIGHT][BACK_RIGHT] += surround_mix_level;
>>               }
>> -        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
>> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
>>               matrix[ FRONT_CENTER][BACK_LEFT ]+= surround_mix_level*M_SQRT1_2;
>>               matrix[ FRONT_CENTER][BACK_RIGHT]+= surround_mix_level*M_SQRT1_2;
>>           }else
>> @@ -257,20 +325,20 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>>       }
>>   
>>       if(unaccounted & AV_CH_SIDE_LEFT){
>> -        if(out_ch_layout & AV_CH_BACK_LEFT){
>> +        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_LEFT) >= 0){
>>               /* if back channels do not exist in the input, just copy side
>>                  channels to back channels, otherwise mix side into back */
>> -            if (in_ch_layout & AV_CH_BACK_LEFT) {
>> +            if (av_channel_layout_index_from_channel(&in_ch_layout, AV_CHAN_BACK_LEFT) >= 0) {
>>                   matrix[BACK_LEFT ][SIDE_LEFT ] += M_SQRT1_2;
>>                   matrix[BACK_RIGHT][SIDE_RIGHT] += M_SQRT1_2;
>>               } else {
>>                   matrix[BACK_LEFT ][SIDE_LEFT ] += 1.0;
>>                   matrix[BACK_RIGHT][SIDE_RIGHT] += 1.0;
>>               }
>> -        }else if(out_ch_layout & AV_CH_BACK_CENTER){
>> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_BACK_CENTER) >= 0){
>>               matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2;
>>               matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2;
>> -        }else if(out_ch_layout & AV_CH_FRONT_LEFT){
>> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
>>               if (matrix_encoding == AV_MATRIX_ENCODING_DOLBY) {
>>                   matrix[FRONT_LEFT ][SIDE_LEFT ] -= surround_mix_level * M_SQRT1_2;
>>                   matrix[FRONT_LEFT ][SIDE_RIGHT] -= surround_mix_level * M_SQRT1_2;
>> @@ -285,7 +353,7 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>>                   matrix[ FRONT_LEFT][ SIDE_LEFT] += surround_mix_level;
>>                   matrix[FRONT_RIGHT][SIDE_RIGHT] += surround_mix_level;
>>               }
>> -        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
>> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
>>               matrix[ FRONT_CENTER][SIDE_LEFT ]+= surround_mix_level * M_SQRT1_2;
>>               matrix[ FRONT_CENTER][SIDE_RIGHT]+= surround_mix_level * M_SQRT1_2;
>>           }else
>> @@ -293,10 +361,10 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>>       }
>>   
>>       if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){
>> -        if(out_ch_layout & AV_CH_FRONT_LEFT){
>> +        if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0){
>>               matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0;
>>               matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0;
>> -        }else if(out_ch_layout & AV_CH_FRONT_CENTER){
>> +        }else if(av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0){
>>               matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2;
>>               matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2;
>>           }else
>> @@ -304,9 +372,9 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>>       }
>>       /* mix LFE into front left/right or center */
>>       if (unaccounted & AV_CH_LOW_FREQUENCY) {
>> -        if (out_ch_layout & AV_CH_FRONT_CENTER) {
>> +        if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_CENTER) >= 0) {
>>               matrix[FRONT_CENTER][LOW_FREQUENCY] += lfe_mix_level;
>> -        } else if (out_ch_layout & AV_CH_FRONT_LEFT) {
>> +        } else if (av_channel_layout_index_from_channel(&out_ch_layout, AV_CHAN_FRONT_LEFT) >= 0) {
>>               matrix[FRONT_LEFT ][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
>>               matrix[FRONT_RIGHT][LOW_FREQUENCY] += lfe_mix_level * M_SQRT1_2;
>>           } else
>> @@ -316,15 +384,19 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>>       for(out_i=i=0; i<64; i++){
>>           double sum=0;
>>           int in_i=0;
>> -        if((out_ch_layout & (1ULL<<i)) == 0)
>> +        if(av_channel_layout_index_from_channel(&out_ch_layout, i) < 0)
>>               continue;
>>           for(j=0; j<64; j++){
>> -            if((in_ch_layout & (1ULL<<j)) == 0)
>> +            if(av_channel_layout_index_from_channel(&in_ch_layout, j) < 0)
>>                  continue;
>>               if (i < FF_ARRAY_ELEMS(matrix) && j < FF_ARRAY_ELEMS(matrix[0]))
>>                   matrix_param[stride*out_i + in_i] = matrix[i][j];
>> -            else
>> -                matrix_param[stride*out_i + in_i] = i == j && (in_ch_layout & out_ch_layout & (1ULL<<i));
>> +            else {
>> +                int idx;
>> +                matrix_param[stride*out_i + in_i] = i == j &&
>> +                (   (idx = av_channel_layout_index_from_channel(&in_ch_layout, i)) >= 0
>> +                 && av_channel_layout_index_from_channel(&out_ch_layout, i) == idx);
>> +            }
>>               sum += fabs(matrix_param[stride*out_i + in_i]);
>>               in_i++;
>>           }
>> @@ -350,17 +422,22 @@ av_cold int swr_build_matrix(uint64_t in_ch_layout_param, uint64_t out_ch_layout
>>       }
>>   
>>       av_log(log_context, AV_LOG_DEBUG, "Matrix coefficients:\n");
>> -    for(i=0; i<av_get_channel_layout_nb_channels(out_ch_layout); i++){
>> -        const char *c =
>> -            av_get_channel_name(av_channel_layout_extract_channel(out_ch_layout, i));
>> -        av_log(log_context, AV_LOG_DEBUG, "%s: ", c ? c : "?");
>> -        for(j=0; j<av_get_channel_layout_nb_channels(in_ch_layout); j++){
>> -            c = av_get_channel_name(av_channel_layout_extract_channel(in_ch_layout, j));
>> -            av_log(log_context, AV_LOG_DEBUG, "%s:%f ", c ? c : "?", matrix_param[stride*i + j]);
>> +    for(i = 0; i < out_ch_layout.nb_channels; i++){
>> +        av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&out_ch_layout, i));
>> +        av_log(log_context, AV_LOG_DEBUG, "%s: ", buf);
>> +        for(j = 0; j < in_ch_layout.nb_channels; j++){
>> +            av_channel_name(buf, sizeof(buf), av_channel_layout_channel_from_index(&in_ch_layout, j));
>> +            av_log(log_context, AV_LOG_DEBUG, "%s:%f ", buf, matrix_param[stride*i + j]);
>>           }
>>           av_log(log_context, AV_LOG_DEBUG, "\n");
>>       }
>> -    return 0;
>> +
>> +    ret = 0;
>> +fail:
>> +    av_channel_layout_uninit(&in_ch_layout);
>> +    av_channel_layout_uninit(&out_ch_layout);
>> +
>> +    return ret;
>>   }
>>   
>>   av_cold static int auto_matrix(SwrContext *s)
>> @@ -377,7 +454,7 @@ av_cold static int auto_matrix(SwrContext *s)
>>           maxval = INT_MAX;
>>   
>>       memset(s->matrix, 0, sizeof(s->matrix));
>> -    ret = swr_build_matrix(s->in_ch_layout, s->out_ch_layout,
>> +    ret = swr_build_matrix2(&s->in_ch_layout, &s->out_ch_layout,
>>                              s->clev, s->slev, s->lfe_mix_level,
>>                              maxval, s->rematrix_volume, (double*)s->matrix,
>>                              s->matrix[1] - s->matrix[0], s->matrix_encoding, s);
>> @@ -519,8 +596,8 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
>>           off = len1 * out->bps;
>>       }
>>   
>> -    av_assert0(!s->out_ch_layout || out->ch_count == av_get_channel_layout_nb_channels(s->out_ch_layout));
>> -    av_assert0(!s-> in_ch_layout || in ->ch_count == av_get_channel_layout_nb_channels(s-> in_ch_layout));
>> +    av_assert0(s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || out->ch_count == s->out_ch_layout.nb_channels);
>> +    av_assert0(s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC || in ->ch_count == s->in_ch_layout.nb_channels);
>>   
>>       for(out_i=0; out_i<out->ch_count; out_i++){
>>           switch(s->matrix_ch[out_i][0]){
>> diff --git a/libswresample/rematrix_template.c b/libswresample/rematrix_template.c
>> index add65e3155..f5a508361c 100644
>> --- a/libswresample/rematrix_template.c
>> +++ b/libswresample/rematrix_template.c
>> @@ -88,13 +88,16 @@ static void RENAME(mix8to2)(SAMPLE **out, const SAMPLE **in, COEFF *coeffp, inte
>>   }
>>   
>>   static RENAME(mix_any_func_type) *RENAME(get_mix_any_func)(SwrContext *s){
>> -    if(   s->out_ch_layout == AV_CH_LAYOUT_STEREO && (s->in_ch_layout == AV_CH_LAYOUT_5POINT1 || s->in_ch_layout == AV_CH_LAYOUT_5POINT1_BACK)
>> +    if(   !av_channel_layout_compare(&s->out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)
>> +       && (   !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1)
>> +           || !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK))
>>          && s->matrix[0][2] == s->matrix[1][2] && s->matrix[0][3] == s->matrix[1][3]
>>          && !s->matrix[0][1] && !s->matrix[0][5] && !s->matrix[1][0] && !s->matrix[1][4]
>>       )
>>           return RENAME(mix6to2);
>>   
>> -    if(   s->out_ch_layout == AV_CH_LAYOUT_STEREO && s->in_ch_layout == AV_CH_LAYOUT_7POINT1
>> +    if(   !av_channel_layout_compare(&s->out_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)
>> +       && !av_channel_layout_compare(&s->in_ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1)
>>          && s->matrix[0][2] == s->matrix[1][2] && s->matrix[0][3] == s->matrix[1][3]
>>          && !s->matrix[0][1] && !s->matrix[0][5] && !s->matrix[1][0] && !s->matrix[1][4]
>>          && !s->matrix[0][7] && !s->matrix[1][6]
>> diff --git a/libswresample/swresample.c b/libswresample/swresample.c
>> index 16734c9df9..f8fbd9134b 100644
>> --- a/libswresample/swresample.c
>> +++ b/libswresample/swresample.c
>> @@ -56,6 +56,8 @@ int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map){
>>       return 0;
>>   }
>>   
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>> +FF_DISABLE_DEPRECATION_WARNINGS
>>   struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
>>                                         int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
>>                                         int64_t  in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
>> @@ -97,6 +99,58 @@ fail:
>>       swr_free(&s);
>>       return NULL;
>>   }
>> +FF_ENABLE_DEPRECATION_WARNINGS
>> +#endif
>> +
>> +int swr_alloc_set_opts2(struct SwrContext **ps,
>> +                        AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
>> +                        AVChannelLayout *in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
>> +                        int log_offset, void *log_ctx) {
>> +    struct SwrContext *s = *ps;
>> +    int ret;
>> +
>> +    if (!s) s = swr_alloc();
>> +    if (!s) return AVERROR(ENOMEM);
>> +
>> +    s->log_level_offset= log_offset;
>> +    s->log_ctx= log_ctx;
> 
> This has been copied from swr_alloc_set_opts without fixing whitespace
> issues.
> 
>> +
>> +    if ((ret = av_opt_set_chlayout(s, "ochl", out_ch_layout, 0)) < 0)
>> +        goto fail;
>> +
>> +    if ((ret = av_opt_set_int(s, "osf", out_sample_fmt, 0)) < 0)
>> +        goto fail;
>> +
>> +    if ((ret = av_opt_set_int(s, "osr", out_sample_rate, 0)) < 0)
>> +        goto fail;
>> +
>> +    if ((ret = av_opt_set_chlayout(s, "ichl", in_ch_layout, 0)) < 0)
>> +        goto fail;
>> +
>> +    if ((ret = av_opt_set_int(s, "isf", in_sample_fmt, 0)) < 0)
>> +        goto fail;
>> +
>> +    if ((ret = av_opt_set_int(s, "isr", in_sample_rate, 0)) < 0)
>> +        goto fail;
>> +
>> +    av_opt_set_int(s, "uch", 0, 0);
>> +
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>> +    // Clear old API values so they don't take precedence in swr_init()
>> +    av_opt_set_int(s, "icl", 0, 0);
>> +    av_opt_set_int(s, "ocl", 0, 0);
>> +    av_opt_set_int(s, "ich", 0, 0);
>> +    av_opt_set_int(s, "och", 0, 0);
>> +#endif
>> +
>> +    *ps = s;
>> +
>> +    return 0;
>> +fail:
>> +    av_log(s, AV_LOG_ERROR, "Failed to set option\n");
>> +    swr_free(ps);
> 
> In case s has been allocated by this function, it leaks. *ps = s needs
> to be moved directly after allocation.

Nice catch. Will fix.

> 
> And why don't you implement the old API in terms of the new API?

I'm not sure I understand what you mean.

> 
>> +    return ret;
>> +}
>>   
>>   static void set_audiodata_fmt(AudioData *a, enum AVSampleFormat fmt){
>>       a->fmt   = fmt;
>> @@ -125,6 +179,8 @@ static void clear_context(SwrContext *s){
>>       free_temp(&s->drop_temp);
>>       free_temp(&s->dither.noise);
>>       free_temp(&s->dither.temp);
>> +    av_channel_layout_uninit(&s->in_ch_layout);
>> +    av_channel_layout_uninit(&s->out_ch_layout);
>>       swri_audio_convert_free(&s-> in_convert);
>>       swri_audio_convert_free(&s->out_convert);
>>       swri_audio_convert_free(&s->full_convert);
>> @@ -138,6 +194,9 @@ av_cold void swr_free(SwrContext **ss){
>>       SwrContext *s= *ss;
>>       if(s){
>>           clear_context(s);
>> +        av_channel_layout_uninit(&s->user_in_chlayout);
>> +        av_channel_layout_uninit(&s->user_out_chlayout);
>> +
>>           if (s->resampler)
>>               s->resampler->free(&s->resample);
>>       }
>> @@ -172,25 +231,66 @@ av_cold int swr_init(struct SwrContext *s){
>>           av_log(s, AV_LOG_ERROR, "Requested output sample rate %d is invalid\n", s->out_sample_rate);
>>           return AVERROR(EINVAL);
>>       }
>> +    s->used_ch_count = s->user_used_ch_count;
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>>       s->out.ch_count  = s-> user_out_ch_count;
>>       s-> in.ch_count  = s->  user_in_ch_count;
>> -    s->used_ch_count = s->user_used_ch_count;
>>   
>> -    s-> in_ch_layout = s-> user_in_ch_layout;
>> -    s->out_ch_layout = s->user_out_ch_layout;
>> +    // if the old/new fields are set inconsistently, prefer the old ones
>> +    if ((s->user_in_ch_count && s->user_in_ch_count != s->user_in_chlayout.nb_channels) ||
>> +        (s->user_in_ch_layout && (s->user_in_chlayout.order != AV_CHANNEL_ORDER_NATIVE ||
>> +                                  s->user_in_chlayout.u.mask != s->user_in_ch_layout))) {
>> +        av_channel_layout_uninit(&s->in_ch_layout);
>> +        if (s->user_in_ch_layout)
>> +            av_channel_layout_from_mask(&s->in_ch_layout, s->user_in_ch_layout);
>> +        else {
>> +            s->in_ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
>> +            s->in_ch_layout.nb_channels = s->user_in_ch_count;
>> +        }
>> +    } else
>> +        av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout);
>> +
>> +    if ((s->user_out_ch_count && s->user_out_ch_count != s->user_out_chlayout.nb_channels) ||
>> +        (s->user_out_ch_layout && (s->user_out_chlayout.order != AV_CHANNEL_ORDER_NATIVE ||
>> +                                   s->user_out_chlayout.u.mask != s->user_out_ch_layout))) {
>> +        av_channel_layout_uninit(&s->out_ch_layout);
>> +        if (s->user_out_ch_layout)
>> +            av_channel_layout_from_mask(&s->out_ch_layout, s->user_out_ch_layout);
>> +        else {
>> +            s->out_ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
>> +            s->out_ch_layout.nb_channels = s->user_out_ch_count;
>> +        }
>> +    } else
>> +        av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout);
>> +
>> +    if (!s->out.ch_count && !s->user_out_ch_layout)
>> +        s->out.ch_count  = s->out_ch_layout.nb_channels;
>> +    if (!s-> in.ch_count && !s-> user_in_ch_layout)
>> +        s-> in.ch_count  = s->in_ch_layout.nb_channels;
>> +#else
>> +    s->out.ch_count  = s-> user_out_chlayout.nb_channels;
>> +    s-> in.ch_count  = s->  user_in_chlayout.nb_channels;
>> +
>> +    ret  = av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout);
>> +    ret |= av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout);
>> +    if (ret < 0)
>> +        return ret;
>> +#endif
>>   
>>       s->int_sample_fmt= s->user_int_sample_fmt;
>>   
>>       s->dither.method = s->user_dither_method;
>>   
>> -    if(av_get_channel_layout_nb_channels(s-> in_ch_layout) > SWR_CH_MAX) {
>> -        av_log(s, AV_LOG_WARNING, "Input channel layout 0x%"PRIx64" is invalid or unsupported.\n", s-> in_ch_layout);
>> -        s->in_ch_layout = 0;
>> +    if (!av_channel_layout_check(&s->in_ch_layout) || s->in_ch_layout.nb_channels > SWR_CH_MAX) {
>> +        av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1));
>> +        av_log(s, AV_LOG_WARNING, "Input channel layout \"%s\" is invalid or unsupported.\n", l1);
>> +        av_channel_layout_uninit(&s->in_ch_layout);
>>       }
>>   
>> -    if(av_get_channel_layout_nb_channels(s->out_ch_layout) > SWR_CH_MAX) {
>> -        av_log(s, AV_LOG_WARNING, "Output channel layout 0x%"PRIx64" is invalid or unsupported.\n", s->out_ch_layout);
>> -        s->out_ch_layout = 0;
>> +    if (!av_channel_layout_check(&s->out_ch_layout) || s->out_ch_layout.nb_channels > SWR_CH_MAX) {
>> +        av_channel_layout_describe(&s->out_ch_layout, l2, sizeof(l2));
>> +        av_log(s, AV_LOG_WARNING, "Output channel layout \"%s\" is invalid or unsupported.\n", l2);
>> +        av_channel_layout_uninit(&s->out_ch_layout);
>>       }
>>   
>>       switch(s->engine){
>> @@ -206,17 +306,18 @@ av_cold int swr_init(struct SwrContext *s){
>>       if(!s->used_ch_count)
>>           s->used_ch_count= s->in.ch_count;
>>   
>> -    if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){
>> +    if(s->used_ch_count && s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_ch_count != s->in_ch_layout.nb_channels){
>>           av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
>> -        s-> in_ch_layout= 0;
>> +        av_channel_layout_uninit(&s->in_ch_layout);
>>       }
>>   
>> -    if(!s-> in_ch_layout)
>> -        s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count);
>> -    if(!s->out_ch_layout)
>> -        s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count);
>> +    if(!s->in_ch_layout.nb_channels || s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
>> +        av_channel_layout_default(&s->in_ch_layout, s->used_ch_count);
>> +    if(!s->out_ch_layout.nb_channels || s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
>> +        av_channel_layout_default(&s->out_ch_layout, s->out.ch_count);
>>   
>> -    s->rematrix= s->out_ch_layout  !=s->in_ch_layout || s->rematrix_volume!=1.0 ||
>> +    s->rematrix= av_channel_layout_compare(&s->out_ch_layout, &s->in_ch_layout) ||
>> +                 s->rematrix_volume!=1.0 ||
>>                    s->rematrix_custom;
>>   
>>       if(s->int_sample_fmt == AV_SAMPLE_FMT_NONE){
>> @@ -291,33 +392,36 @@ av_cold int swr_init(struct SwrContext *s){
>>   
>>   #define RSC 1 //FIXME finetune
>>       if(!s-> in.ch_count)
>> -        s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout);
>> +        s-> in.ch_count = s->in_ch_layout.nb_channels;
>>       if(!s->used_ch_count)
>>           s->used_ch_count= s->in.ch_count;
>>       if(!s->out.ch_count)
>> -        s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout);
>> +        s->out.ch_count = s->out_ch_layout.nb_channels;
>>   
>>       if(!s-> in.ch_count){
>> -        av_assert0(!s->in_ch_layout);
>> +        av_assert0(s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC);
>>           av_log(s, AV_LOG_ERROR, "Input channel count and layout are unset\n");
>>           ret = AVERROR(EINVAL);
>>           goto fail;
>>       }
>>   
>> -    av_get_channel_layout_string(l1, sizeof(l1), s-> in.ch_count, s-> in_ch_layout);
>> -    av_get_channel_layout_string(l2, sizeof(l2), s->out.ch_count, s->out_ch_layout);
>> -    if (s->out_ch_layout && s->out.ch_count != av_get_channel_layout_nb_channels(s->out_ch_layout)) {
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>> +    av_channel_layout_describe(&s->out_ch_layout, l1, sizeof(l1));
>> +    if (s->out_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->out.ch_count != s->out_ch_layout.nb_channels) {
>>           av_log(s, AV_LOG_ERROR, "Output channel layout %s mismatches specified channel count %d\n", l2, s->out.ch_count);
>>           ret = AVERROR(EINVAL);
>>           goto fail;
>>       }
>> -    if (s->in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s->in_ch_layout)) {
>> +#endif
>> +    av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1));
>> +    if (s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_ch_count != s->in_ch_layout.nb_channels) {
>>           av_log(s, AV_LOG_ERROR, "Input channel layout %s mismatches specified channel count %d\n", l1, s->used_ch_count);
>>           ret = AVERROR(EINVAL);
>>           goto fail;
>>       }
>>   
>> -    if ((!s->out_ch_layout || !s->in_ch_layout) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) {
>> +    if ((   s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC
>> +         || s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) {
>>           av_log(s, AV_LOG_ERROR, "Rematrix is needed between %s and %s "
>>                  "but there is not enough information to do it\n", l1, l2);
>>           ret = AVERROR(EINVAL);
>> diff --git a/libswresample/swresample.h b/libswresample/swresample.h
>> index c7b84fbcac..c6ff2345e9 100644
>> --- a/libswresample/swresample.h
>> +++ b/libswresample/swresample.h
>> @@ -227,6 +227,7 @@ int swr_init(struct SwrContext *s);
>>    */
>>   int swr_is_initialized(struct SwrContext *s);
>>   
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>>   /**
>>    * Allocate SwrContext if needed and set/reset common parameters.
>>    *
>> @@ -246,12 +247,40 @@ int swr_is_initialized(struct SwrContext *s);
>>    *
>>    * @see swr_init(), swr_free()
>>    * @return NULL on error, allocated context otherwise
>> + * @deprecated use @ref swr_alloc_set_opts2()
>>    */
>> +attribute_deprecated
>>   struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
>>                                         int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
>>                                         int64_t  in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
>>                                         int log_offset, void *log_ctx);
>> +#endif
>>   
>> +/**
>> + * Allocate SwrContext if needed and set/reset common parameters.
>> + *
>> + * This function does not require s to be allocated with swr_alloc(). On the
>> + * other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters
>> + * on the allocated context.
>> + *
>> + * @param ps              Pointer to an existing Swr context if available, or to NULL if not.
>> + *                        On success, *ps will be set the allocated context.
> 
> This does not sound like proper English to me.

Just a missing "to". Will add.

> Moreover, it does not document that an already allocated context will be
> freed here on error.

Will mention it.

> 
>> + * @param out_ch_layout   output channel layout (AV_CH_LAYOUT_*)
>> + * @param out_sample_fmt  output sample format (AV_SAMPLE_FMT_*).
>> + * @param out_sample_rate output sample rate (frequency in Hz)
>> + * @param in_ch_layout    input channel layout (AV_CH_LAYOUT_*)
>> + * @param in_sample_fmt   input sample format (AV_SAMPLE_FMT_*).
>> + * @param in_sample_rate  input sample rate (frequency in Hz)
>> + * @param log_offset      logging level offset
>> + * @param log_ctx         parent logging context, can be NULL
>> + *
>> + * @see swr_init(), swr_free()
>> + * @return 0 on success, a negative AVERROR code on error.
>> + */
>> +int swr_alloc_set_opts2(struct SwrContext **ps,
>> +                        AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
>> +                        AVChannelLayout *in_ch_layout, enum AVSampleFormat  in_sample_fmt, int  in_sample_rate,
>> +                        int log_offset, void *log_ctx);
>>   /**
>>    * @}
>>    *
>> @@ -362,6 +391,7 @@ int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensatio
>>    */
>>   int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
>>   
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>>   /**
>>    * Generate a channel mixing matrix.
>>    *
>> @@ -384,13 +414,46 @@ int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
>>    * @param matrix_encoding     matrixed stereo downmix mode (e.g. dplii)
>>    * @param log_ctx             parent logging context, can be NULL
>>    * @return                    0 on success, negative AVERROR code on failure
>> + * @deprecated                use @ref swr_build_matrix2()
>>    */
>> +attribute_deprecated
>>   int swr_build_matrix(uint64_t in_layout, uint64_t out_layout,
>>                        double center_mix_level, double surround_mix_level,
>>                        double lfe_mix_level, double rematrix_maxval,
>>                        double rematrix_volume, double *matrix,
>>                        int stride, enum AVMatrixEncoding matrix_encoding,
>>                        void *log_ctx);
>> +#endif
>> +
>> +/**
>> + * Generate a channel mixing matrix.
>> + *
>> + * This function is the one used internally by libswresample for building the
>> + * default mixing matrix. It is made public just as a utility function for
>> + * building custom matrices.
>> + *
>> + * @param in_layout           input channel layout
>> + * @param out_layout          output channel layout
>> + * @param center_mix_level    mix level for the center channel
>> + * @param surround_mix_level  mix level for the surround channel(s)
>> + * @param lfe_mix_level       mix level for the low-frequency effects channel
>> + * @param rematrix_maxval     if 1.0, coefficients will be normalized to prevent
>> + *                            overflow. if INT_MAX, coefficients will not be
>> + *                            normalized.
>> + * @param[out] matrix         mixing coefficients; matrix[i + stride * o] is
>> + *                            the weight of input channel i in output channel o.
> 
> The parameter below is named matrix_param.

Will fix.

> 
>> + * @param stride              distance between adjacent input channels in the
>> + *                            matrix array
>> + * @param matrix_encoding     matrixed stereo downmix mode (e.g. dplii)
>> + * @param log_ctx             parent logging context, can be NULL
>> + * @return                    0 on success, negative AVERROR code on failure
>> + */
>> +int swr_build_matrix2(const AVChannelLayout *in_layout, const AVChannelLayout *out_layout,
>> +                      double center_mix_level, double surround_mix_level,
>> +                      double lfe_mix_level, double maxval,
>> +                      double rematrix_volume, double *matrix_param,
>> +                      ptrdiff_t stride, enum AVMatrixEncoding matrix_encoding,
>> +                      void *log_context);
>>   
>>   /**
>>    * Set a customized remix matrix.
>> diff --git a/libswresample/swresample_frame.c b/libswresample/swresample_frame.c
>> index d95c1cc537..747cf119a9 100644
>> --- a/libswresample/swresample_frame.c
>> +++ b/libswresample/swresample_frame.c
>> @@ -29,7 +29,19 @@ int swr_config_frame(SwrContext *s, const AVFrame *out, const AVFrame *in)
>>       swr_close(s);
>>   
>>       if (in) {
>> -        if (av_opt_set_int(s, "icl", in->channel_layout, 0) < 0)
>> +        AVChannelLayout in_ch_layout = { 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(&in_ch_layout, in->channel_layout);
>> +FF_ENABLE_DEPRECATION_WARNINGS
>> +        } else
>> +#endif
>> +        if (av_channel_layout_copy(&in_ch_layout, &in->ch_layout) < 0)
>> +            goto fail;
>> +        if (av_opt_set_chlayout(s, "ichl", &in_ch_layout, 0) < 0)
>>               goto fail;
>>           if (av_opt_set_int(s, "isf", in->format, 0) < 0)
>>               goto fail;
>> @@ -38,7 +50,19 @@ int swr_config_frame(SwrContext *s, const AVFrame *out, const AVFrame *in)
>>       }
>>   
>>       if (out) {
>> -        if (av_opt_set_int(s, "ocl", out->channel_layout, 0) < 0)
>> +        AVChannelLayout out_ch_layout = { 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_from_mask(&out_ch_layout, out->channel_layout);
>> +FF_ENABLE_DEPRECATION_WARNINGS
>> +        } else
>> +#endif
>> +        if (av_channel_layout_copy(&out_ch_layout, &out->ch_layout) < 0)
>> +            goto fail;
>> +        if (av_opt_set_chlayout(s, "ochl", &out_ch_layout, 0) < 0)
>>               goto fail;
>>           if (av_opt_set_int(s, "osf", out->format,  0) < 0)
>>               goto fail;
>> @@ -58,7 +82,19 @@ static int config_changed(SwrContext *s,
>>       int ret = 0;
>>   
>>       if (in) {
>> -        if (s->in_ch_layout   != in->channel_layout ||
>> +        AVChannelLayout in_ch_layout = { 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(&in_ch_layout, in->channel_layout);
>> +FF_ENABLE_DEPRECATION_WARNINGS
>> +        } else
>> +#endif
>> +        if ((ret = av_channel_layout_copy(&in_ch_layout, &in->ch_layout)) < 0)
>> +            return ret;
>> +        if (av_channel_layout_compare(&s->in_ch_layout, &in_ch_layout) ||
>>               s->in_sample_rate != in->sample_rate ||
>>               s->in_sample_fmt  != in->format) {
>>               ret |= AVERROR_INPUT_CHANGED;
>> @@ -66,7 +102,19 @@ static int config_changed(SwrContext *s,
>>       }
>>   
>>       if (out) {
>> -        if (s->out_ch_layout   != out->channel_layout ||
>> +        AVChannelLayout out_ch_layout = { 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_from_mask(&out_ch_layout, out->channel_layout);
>> +FF_ENABLE_DEPRECATION_WARNINGS
>> +        } else
>> +#endif
>> +        if ((ret = av_channel_layout_copy(&out_ch_layout, &out->ch_layout)) < 0)
>> +            return ret;
>> +        if (av_channel_layout_compare(&s->out_ch_layout, &out_ch_layout) ||
>>               s->out_sample_rate != out->sample_rate ||
>>               s->out_sample_fmt  != out->format) {
>>               ret |= AVERROR_OUTPUT_CHANGED;
>> @@ -116,7 +164,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;
>>       }
>>   }
>> diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
>> index f2ea5a226d..262a0e2b8c 100644
>> --- a/libswresample/swresample_internal.h
>> +++ b/libswresample/swresample_internal.h
>> @@ -99,8 +99,8 @@ struct SwrContext {
>>       enum AVSampleFormat  in_sample_fmt;             ///< input sample format
>>       enum AVSampleFormat int_sample_fmt;             ///< internal sample format (AV_SAMPLE_FMT_FLTP or AV_SAMPLE_FMT_S16P)
>>       enum AVSampleFormat out_sample_fmt;             ///< output sample format
>> -    int64_t  in_ch_layout;                          ///< input channel layout
>> -    int64_t out_ch_layout;                          ///< output channel layout
>> +    AVChannelLayout  in_ch_layout;                  ///< input channel layout
>> +    AVChannelLayout out_ch_layout;                  ///< output channel layout
>>       int      in_sample_rate;                        ///< input sample rate
>>       int     out_sample_rate;                        ///< output sample rate
>>       int flags;                                      ///< miscellaneous flags such as SWR_FLAG_RESAMPLE
>> @@ -114,11 +114,15 @@ struct SwrContext {
>>       int used_ch_count;                              ///< number of used input channels (mapped channel count if channel_map, otherwise in.ch_count)
>>       int engine;
>>   
>> +    int user_used_ch_count;                         ///< User set used channel count
>> +#if FF_API_OLD_CHANNEL_LAYOUT
>>       int user_in_ch_count;                           ///< User set input channel count
>>       int user_out_ch_count;                          ///< User set output channel count
>> -    int user_used_ch_count;                         ///< User set used channel count
>>       int64_t user_in_ch_layout;                      ///< User set input channel layout
>>       int64_t user_out_ch_layout;                     ///< User set output channel layout
>> +#endif
>> +    AVChannelLayout user_in_chlayout;               ///< User set input channel layout
>> +    AVChannelLayout user_out_chlayout;              ///< User set output channel layout
>>       enum AVSampleFormat user_int_sample_fmt;        ///< User set internal sample format
>>       int user_dither_method;                         ///< User set dither method
>>   
>>
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 109/281] mxf: convert to new channel layout API
  2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 109/281] mxf: " James Almer
@ 2022-01-19 19:06   ` Tomas Härdin
  0 siblings, 0 replies; 337+ messages in thread
From: Tomas Härdin @ 2022-01-19 19:06 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

ons 2022-01-12 klockan 22:56 -0300 skrev James Almer:
> From: Vittorio Giovara <vittorio.giovara@gmail.com>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: Anton Khirnov <anton@khirnov.net>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/mxfdec.c | 34 +++++++++++++++++++++-------------
>  libavformat/mxfenc.c | 20 +++++++++++---------
>  2 files changed, 32 insertions(+), 22 deletions(-)

Looks OK with the reservation that I haven't looked at the new API

/Tomas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 091/281] matroska: convert to new channel layout API
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 091/281] matroska: " James Almer
@ 2022-01-21 19:52   ` Andreas Rheinhardt
  2022-01-21 20:20     ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: Andreas Rheinhardt @ 2022-01-21 19:52 UTC (permalink / raw)
  To: ffmpeg-devel

James Almer:
> From: Vittorio Giovara <vittorio.giovara@gmail.com>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: Anton Khirnov <anton@khirnov.net>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/matroskadec.c |  8 ++++++--
>  libavformat/matroskaenc.c | 10 +++++-----
>  2 files changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 78e5a4a203..62a36cbb8c 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -2083,7 +2083,7 @@ static int matroska_parse_flac(AVFormatContext *s,
>                      av_log(s, AV_LOG_WARNING,
>                             "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n");
>                  } else
> -                    st->codecpar->channel_layout = mask;
> +                    av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
>              }
>              av_dict_free(&dict);
>          }
> @@ -2911,7 +2911,11 @@ static int matroska_parse_tracks(AVFormatContext *s)
>              st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
>              st->codecpar->codec_tag   = fourcc;
>              st->codecpar->sample_rate = track->audio.out_samplerate;
> -            st->codecpar->channels    = track->audio.channels;
> +            // channel layout may be already set by codec private checks above
> +            if (st->codecpar->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
> +                !st->codecpar->ch_layout.u.mask)
> +                st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
> +            st->codecpar->ch_layout.nb_channels = track->audio.channels;
>              if (!st->codecpar->bits_per_coded_sample)
>                  st->codecpar->bits_per_coded_sample = track->audio.bitdepth;
>              if (st->codecpar->codec_id == AV_CODEC_ID_MP3 ||
> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> index 152312102a..5278166e8c 100644
> --- a/libavformat/matroskaenc.c
> +++ b/libavformat/matroskaenc.c
> @@ -657,9 +657,9 @@ static int put_wv_codecpriv(AVIOContext *pb, const AVCodecParameters *par)
>  static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb,
>                                const AVCodecParameters *par)
>  {
> -    int write_comment = (par->channel_layout &&
> -                         !(par->channel_layout & ~0x3ffffULL) &&
> -                         !ff_flac_is_native_layout(par->channel_layout));
> +    int write_comment = (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE && par->ch_layout.u.mask &&
> +                         !av_channel_layout_subset(&par->ch_layout, ~0x3ffffULL) &&

Why are you using this function although you already know that it is a
native layout, so that the typical & works fine?

> +                         !ff_flac_is_native_layout(par->ch_layout.u.mask));
>      int ret = ff_flac_write_header(pb, par->extradata, par->extradata_size,
>                                     !write_comment);
>  
> @@ -673,7 +673,7 @@ static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb,
>          uint8_t buf[32];
>          int64_t len;
>  
> -        snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout);
> +        snprintf(buf, sizeof(buf), "0x%"PRIx64, par->ch_layout.u.mask);
>          av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
>  
>          len = ff_vorbiscomment_length(dict, vendor, NULL, 0);
> @@ -1396,7 +1396,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
>              put_ebml_string(pb, MATROSKA_ID_CODECID, "A_MS/ACM");
>  
>          subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 6 + 4 * 9);
> -        put_ebml_uint  (pb, MATROSKA_ID_AUDIOCHANNELS    , par->channels);
> +        put_ebml_uint(pb, MATROSKA_ID_AUDIOCHANNELS, par->ch_layout.nb_channels);
>  
>          track->sample_rate_offset = avio_tell(pb);
>          put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate);
> 

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 091/281] matroska: convert to new channel layout API
  2022-01-21 19:52   ` Andreas Rheinhardt
@ 2022-01-21 20:20     ` James Almer
  0 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-01-21 20:20 UTC (permalink / raw)
  To: ffmpeg-devel

On 1/21/2022 4:52 PM, Andreas Rheinhardt wrote:
> James Almer:
>> From: Vittorio Giovara <vittorio.giovara@gmail.com>
>>
>> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
>> Signed-off-by: Anton Khirnov <anton@khirnov.net>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavformat/matroskadec.c |  8 ++++++--
>>   libavformat/matroskaenc.c | 10 +++++-----
>>   2 files changed, 11 insertions(+), 7 deletions(-)
>>
>> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
>> index 78e5a4a203..62a36cbb8c 100644
>> --- a/libavformat/matroskadec.c
>> +++ b/libavformat/matroskadec.c
>> @@ -2083,7 +2083,7 @@ static int matroska_parse_flac(AVFormatContext *s,
>>                       av_log(s, AV_LOG_WARNING,
>>                              "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n");
>>                   } else
>> -                    st->codecpar->channel_layout = mask;
>> +                    av_channel_layout_from_mask(&st->codecpar->ch_layout, mask);
>>               }
>>               av_dict_free(&dict);
>>           }
>> @@ -2911,7 +2911,11 @@ static int matroska_parse_tracks(AVFormatContext *s)
>>               st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
>>               st->codecpar->codec_tag   = fourcc;
>>               st->codecpar->sample_rate = track->audio.out_samplerate;
>> -            st->codecpar->channels    = track->audio.channels;
>> +            // channel layout may be already set by codec private checks above
>> +            if (st->codecpar->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
>> +                !st->codecpar->ch_layout.u.mask)
>> +                st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
>> +            st->codecpar->ch_layout.nb_channels = track->audio.channels;
>>               if (!st->codecpar->bits_per_coded_sample)
>>                   st->codecpar->bits_per_coded_sample = track->audio.bitdepth;
>>               if (st->codecpar->codec_id == AV_CODEC_ID_MP3 ||
>> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
>> index 152312102a..5278166e8c 100644
>> --- a/libavformat/matroskaenc.c
>> +++ b/libavformat/matroskaenc.c
>> @@ -657,9 +657,9 @@ static int put_wv_codecpriv(AVIOContext *pb, const AVCodecParameters *par)
>>   static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb,
>>                                 const AVCodecParameters *par)
>>   {
>> -    int write_comment = (par->channel_layout &&
>> -                         !(par->channel_layout & ~0x3ffffULL) &&
>> -                         !ff_flac_is_native_layout(par->channel_layout));
>> +    int write_comment = (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE && par->ch_layout.u.mask &&
>> +                         !av_channel_layout_subset(&par->ch_layout, ~0x3ffffULL) &&
> 
> Why are you using this function although you already know that it is a
> native layout, so that the typical & works fine?

I think Vittorio originally wrote it as

int write_comment = (!av_channel_layout_subset(&par->ch_layout, 
~0x3ffffULL) && !ff_flac_is_native_layout(par->ch_layout.u.mask));

Which could potentially access the union's mask field on a layout other 
than native if av_channel_layout_subset() succeeded, so i added that 
check. But you're right it makes calling subset() superfluous, so will 
change it.

> 
>> +                         !ff_flac_is_native_layout(par->ch_layout.u.mask));
>>       int ret = ff_flac_write_header(pb, par->extradata, par->extradata_size,
>>                                      !write_comment);
>>   
>> @@ -673,7 +673,7 @@ static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb,
>>           uint8_t buf[32];
>>           int64_t len;
>>   
>> -        snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout);
>> +        snprintf(buf, sizeof(buf), "0x%"PRIx64, par->ch_layout.u.mask);
>>           av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
>>   
>>           len = ff_vorbiscomment_length(dict, vendor, NULL, 0);
>> @@ -1396,7 +1396,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
>>               put_ebml_string(pb, MATROSKA_ID_CODECID, "A_MS/ACM");
>>   
>>           subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 6 + 4 * 9);
>> -        put_ebml_uint  (pb, MATROSKA_ID_AUDIOCHANNELS    , par->channels);
>> +        put_ebml_uint(pb, MATROSKA_ID_AUDIOCHANNELS, par->ch_layout.nb_channels);
>>   
>>           track->sample_rate_offset = avio_tell(pb);
>>           put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate);
>>
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 027/281] apc: convert to new channel layout API
  2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 027/281] apc: " James Almer
@ 2022-01-26 13:41   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-01-26 13:41 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 02:49:49)
> From: Vittorio Giovara <vittorio.giovara@gmail.com>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/apc.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/libavformat/apc.c b/libavformat/apc.c
> index 56151bb59a..192e115278 100644
> --- a/libavformat/apc.c
> +++ b/libavformat/apc.c
> @@ -38,6 +38,7 @@ static int apc_read_header(AVFormatContext *s)
>      AVIOContext *pb = s->pb;
>      AVStream *st;
>      int ret;
> +    int channels;
>  
>      avio_rl32(pb); /* CRYO */
>      avio_rl32(pb); /* _APC */
> @@ -57,16 +58,11 @@ static int apc_read_header(AVFormatContext *s)
>      if ((ret = ff_get_extradata(s, st->codecpar, pb, 2 * 4)) < 0)
>          return ret;
>  
> -    if (avio_rl32(pb)) {
> -        st->codecpar->channels       = 2;
> -        st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
> -    } else {
> -        st->codecpar->channels       = 1;
> -        st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
> -    }
> +    channels = avio_rl32(pb) + 1;

This changes behavior in case the value read is > 1. No idea if that
ever happens, but still better make it !!avio_rl32.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 043/281] cdxl: convert to new channel layout API
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 043/281] cdxl: " James Almer
@ 2022-01-26 13:53   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-01-26 13:53 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 02:50:05)
> From: Vittorio Giovara <vittorio.giovara@gmail.com>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/cdxl.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/cdxl.c b/libavformat/cdxl.c
> index c42e0d3545..76dc1d18c9 100644
> --- a/libavformat/cdxl.c
> +++ b/libavformat/cdxl.c
> @@ -171,6 +171,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
>  
>      if (cdxl->read_chunk && audio_size) {
>          if (cdxl->audio_stream_index == -1) {
> +            int channels = !!(cdxl->header[1] & 0x10) + 1;

redundant after cba716f55e79ebb2db9627c6e3e11d6fc77ae737

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 045/281] dash: convert to new channel layout API
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 045/281] dash: " James Almer
@ 2022-01-26 13:56   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-01-26 13:56 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 02:50:07)
> From: Vittorio Giovara <vittorio.giovara@gmail.com>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/dashenc.c | 2 +-
>  libavformat/dauddec.c | 3 +--
>  libavformat/daudenc.c | 2 +-

The latter two don't have anything to do with dash

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 059/281] flic: convert to new channel layout API
  2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 059/281] flic: " James Almer
@ 2022-01-27  7:46   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-01-27  7:46 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 02:50:21)
> From: Vittorio Giovara <vittorio.giovara@gmail.com>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/flic.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/flic.c b/libavformat/flic.c
> index 44ed696421..496402aa94 100644
> --- a/libavformat/flic.c
> +++ b/libavformat/flic.c
> @@ -157,10 +157,10 @@ static int flic_read_header(AVFormatContext *s)
>          ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8;
>          ast->codecpar->codec_tag = 0;
>          ast->codecpar->sample_rate = FLIC_TFTD_SAMPLE_RATE;
> -        ast->codecpar->channels = 1;
> +        ast->codecpar->format   = AV_SAMPLE_FMT_U8;

This is unrelated.

Setting the format was removed in ffmpeg (but not in libav) in
7b007a7c1fad57e9ed4b685c1d3b4222f02d9720, with the comment
"It is supposed to be set from lavc only."
At the time it was still done on the AVStream-embedded codec context, so
it might have been true, but today there is no issue with setting the
AVCodecParameters format from the demuxer, several other demuxers do so.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 090/281] lxfdec: convert to new channel layout API
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 090/281] lxfdec: " James Almer
@ 2022-01-27 15:19   ` Tomas Härdin
  0 siblings, 0 replies; 337+ messages in thread
From: Tomas Härdin @ 2022-01-27 15:19 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

ons 2022-01-12 klockan 22:55 -0300 skrev James Almer:
> From: Vittorio Giovara <vittorio.giovara@gmail.com>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/lxfdec.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/lxfdec.c b/libavformat/lxfdec.c
> index 7889abb2c9..9e0d265f6a 100644
> --- a/libavformat/lxfdec.c
> +++ b/libavformat/lxfdec.c
> @@ -281,7 +281,8 @@ static int lxf_read_header(AVFormatContext *s)
>  
>          st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
>          st->codecpar->sample_rate = LXF_SAMPLERATE;
> -        st->codecpar->channels    = lxf->channels;
> +        st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
> +        st->codecpar->ch_layout.nb_channels = lxf->channels;
>  
>          avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
>      }

Looks OK

/Tomas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 096/281] mov: convert to new channel layout API
  2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 096/281] mov: " James Almer
@ 2022-01-28 10:08   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-01-28 10:08 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 02:55:49)
> diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c
> index 349634094c..5894bb8ce2 100644
> --- a/libavformat/mov_chan.c
> +++ b/libavformat/mov_chan.c
> @@ -499,7 +499,7 @@ static uint32_t mov_get_channel_label(uint32_t label)
>  }
>  
>  uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id,
> -                                       uint64_t channel_layout,
> +                                       AVChannelLayout *ch_layout,

const?

>                                         uint32_t *bitmap)
>  {
>      int i, j;
> @@ -519,7 +519,7 @@ uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id,
>          const struct MovChannelLayoutMap *layout_map;
>  
>          /* get the layout map based on the channel count */
> -        channels = av_get_channel_layout_nb_channels(channel_layout);
> +        channels = ch_layout->nb_channels;
>          if (channels > 9)
>              channels = 0;
>          layout_map = mov_ch_layout_map[channels];
> @@ -530,7 +530,8 @@ uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id,
>                  continue;
>              for (j = 0; layout_map[j].tag != 0; j++) {
>                  if (layout_map[j].tag    == layouts[i] &&
> -                    layout_map[j].layout == channel_layout)
> +                    (ch_layout->order == AV_CHANNEL_ORDER_NATIVE &&
> +                     layout_map[j].layout == ch_layout->u.mask))
>                      break;
>              }
>              if (layout_map[j].tag)
> @@ -540,9 +541,9 @@ uint32_t ff_mov_get_channel_layout_tag(enum AVCodecID codec_id,
>      }
>  
>      /* if no tag was found, use channel bitmap as a backup if possible */
> -    if (tag == 0 && channel_layout > 0 && channel_layout < 0x40000) {
> +    if (tag == 0 && av_channel_layout_check(ch_layout) && ch_layout->u.mask < 0x40000) {

This should check the order is native.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 135/281] rtp: convert to new channel layout API
  2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 135/281] rtp: " James Almer
@ 2022-01-28 14:15   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-01-28 14:15 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 02:57:52)
> diff --git a/libavformat/rtpdec_amr.c b/libavformat/rtpdec_amr.c
> index 988b7bddfd..20b435039c 100644
> --- a/libavformat/rtpdec_amr.c
> +++ b/libavformat/rtpdec_amr.c
> @@ -64,11 +64,10 @@ static int amr_handle_packet(AVFormatContext *ctx, PayloadContext *data,
>          return AVERROR_INVALIDDATA;
>      }
>  
> -    if (st->codecpar->channels != 1) {
> +    if (st->codecpar->ch_layout.nb_channels != 1) {
>          av_log(ctx, AV_LOG_ERROR, "Only mono AMR is supported\n");
>          return AVERROR_INVALIDDATA;
>      }
> -    st->codecpar->channel_layout = AV_CH_LAYOUT_MONO;

Looks wrong.


-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 186/281] alac: convert to new channel layout API
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 186/281] alac: " James Almer
@ 2022-02-09  9:40   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-02-09  9:40 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 03:02:19)
> diff --git a/libavcodec/alac_data.h b/libavcodec/alac_data.h
> index 650d6dcd15..a68a5f2648 100644
> --- a/libavcodec/alac_data.h
> +++ b/libavcodec/alac_data.h
> @@ -23,6 +23,8 @@
>  
>  #include <stdint.h>
>  
> +#include "libavutil/channel_layout.h"
> +
>  enum AlacRawDataBlockType {
>      /* At the moment, only SCE, CPE, LFE, and END are recognized. */
>      TYPE_SCE,
> @@ -39,7 +41,11 @@ enum AlacRawDataBlockType {
>  
>  extern const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNELS];
>  
> +extern const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1];
> +
> +#if FF_API_OLD_CHANNEL_LAYOUT
>  extern const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1];
> +#endif

Kill this

> @@ -616,6 +617,21 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
>      return 0;
>  }
>  
> +#if FF_API_OLD_CHANNEL_LAYOUT
> +const uint64_t alac_channel_layouts[ALAC_MAX_CHANNELS + 1] = {

static 

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 275/281] avfilter: convert to new channel layout API
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 275/281] avfilter: " James Almer
@ 2022-02-14 15:49   ` Anton Khirnov
  2022-02-15 11:50   ` Anton Khirnov
  2022-02-16 18:15   ` Anton Khirnov
  2 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-02-14 15:49 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 03:09:07)
> diff --git a/libavfilter/af_apulsator.c b/libavfilter/af_apulsator.c
> index c2a8de0e0b..c3ca752035 100644
> --- a/libavfilter/af_apulsator.c
> +++ b/libavfilter/af_apulsator.c
> @@ -192,7 +192,7 @@ static int query_formats(AVFilterContext *ctx)
>  
>      if ((ret = ff_add_format                 (&formats, AV_SAMPLE_FMT_DBL  )) < 0 ||
>          (ret = ff_set_common_formats         (ctx     , formats            )) < 0 ||
> -        (ret = ff_add_channel_layout         (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
> +        (ret = ff_add_channel_layout         (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) < 0 ||

completion fail?

> diff --git a/libavfilter/af_sofalizer.c b/libavfilter/af_sofalizer.c
> index 20b717bdf8..246ddeffb9 100644
> --- a/libavfilter/af_sofalizer.c
> +++ b/libavfilter/af_sofalizer.c
> @@ -187,25 +187,15 @@ static int preload_sofa(AVFilterContext *ctx, char *filename, int *samplingrate)
>  
>  static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel)
>  {
> -    int len, i, channel_id = 0;
> -    int64_t layout, layout0;
> +    int len, channel_id = 0;
>      char buf[8] = {0};
>  
>      /* try to parse a channel name, e.g. "FL" */
>      if (av_sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
> -        layout0 = layout = av_get_channel_layout(buf);
> -        /* channel_id <- first set bit in layout */
> -        for (i = 32; i > 0; i >>= 1) {
> -            if (layout >= 1LL << i) {
> -                channel_id += i;
> -                layout >>= i;
> -            }
> -        }
> -        /* reject layouts that are not a single channel */
> -        if (channel_id >= 64 || layout0 != 1LL << channel_id) {

You should keep the range check, because the id gets used as index into
vspkrpos[64].


> -            av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf);
> -            return AVERROR(EINVAL);
> -        }
> +        channel_id = av_channel_from_string(buf);
> +        if (channel_id < 0)
> +            return channel_id;
> +
>          *rchannel = channel_id;
>          *arg += len;
>          return 0;
> @@ -221,7 +211,7 @@ static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel)
>      return AVERROR(EINVAL);
>  }
>  
> -static void parse_speaker_pos(AVFilterContext *ctx, int64_t in_channel_layout)
> +static void parse_speaker_pos(AVFilterContext *ctx)
>  {
>      SOFAlizerContext *s = ctx->priv;
>      char *arg, *tokenizer, *p, *args = av_strdup(s->speakers_pos);
> @@ -256,10 +246,10 @@ static int get_speaker_pos(AVFilterContext *ctx,
>                             float *speaker_azim, float *speaker_elev)
>  {
>      struct SOFAlizerContext *s = ctx->priv;
> -    uint64_t channels_layout = ctx->inputs[0]->channel_layout;
> +    AVChannelLayout *channel_layout = &ctx->inputs[0]->ch_layout;
>      float azim[64] = { 0 };
>      float elev[64] = { 0 };
> -    int m, ch, n_conv = ctx->inputs[0]->channels; /* get no. input channels */
> +    int m, ch, n_conv = ctx->inputs[0]->ch_layout.nb_channels; /* get no. input channels */
>  
>      if (n_conv < 0 || n_conv > 64)
>          return AVERROR(EINVAL);
> @@ -267,45 +257,45 @@ static int get_speaker_pos(AVFilterContext *ctx,
>      s->lfe_channel = -1;
>  
>      if (s->speakers_pos)
> -        parse_speaker_pos(ctx, channels_layout);
> +        parse_speaker_pos(ctx);
>  
>      /* set speaker positions according to input channel configuration: */
>      for (m = 0, ch = 0; ch < n_conv && m < 64; m++) {
> -        uint64_t mask = channels_layout & (1ULL << m);
> -
> -        switch (mask) {
> -        case AV_CH_FRONT_LEFT:            azim[ch] =  30;      break;
> -        case AV_CH_FRONT_RIGHT:           azim[ch] = 330;      break;
> -        case AV_CH_FRONT_CENTER:          azim[ch] =   0;      break;
> -        case AV_CH_LOW_FREQUENCY:
> -        case AV_CH_LOW_FREQUENCY_2:       s->lfe_channel = ch; break;
> -        case AV_CH_BACK_LEFT:             azim[ch] = 150;      break;
> -        case AV_CH_BACK_RIGHT:            azim[ch] = 210;      break;
> -        case AV_CH_BACK_CENTER:           azim[ch] = 180;      break;
> -        case AV_CH_SIDE_LEFT:             azim[ch] =  90;      break;
> -        case AV_CH_SIDE_RIGHT:            azim[ch] = 270;      break;
> -        case AV_CH_FRONT_LEFT_OF_CENTER:  azim[ch] =  15;      break;
> -        case AV_CH_FRONT_RIGHT_OF_CENTER: azim[ch] = 345;      break;
> -        case AV_CH_TOP_CENTER:            azim[ch] =   0;
> +        int chan = av_channel_layout_channel_from_index(channel_layout, m);
> +
> +        switch (chan) {
> +        case AV_CHAN_FRONT_LEFT:          azim[ch] =  30;      break;
> +        case AV_CHAN_FRONT_RIGHT:         azim[ch] = 330;      break;
> +        case AV_CHAN_FRONT_CENTER:        azim[ch] =   0;      break;
> +        case AV_CHAN_LOW_FREQUENCY:
> +        case AV_CHAN_LOW_FREQUENCY_2:     s->lfe_channel = ch; break;
> +        case AV_CHAN_BACK_LEFT:           azim[ch] = 150;      break;
> +        case AV_CHAN_BACK_RIGHT:          azim[ch] = 210;      break;
> +        case AV_CHAN_BACK_CENTER:         azim[ch] = 180;      break;
> +        case AV_CHAN_SIDE_LEFT:           azim[ch] =  90;      break;
> +        case AV_CHAN_SIDE_RIGHT:          azim[ch] = 270;      break;
> +        case AV_CHAN_FRONT_LEFT_OF_CENTER:  azim[ch] =  15;    break;
> +        case AV_CHAN_FRONT_RIGHT_OF_CENTER: azim[ch] = 345;    break;
> +        case AV_CHAN_TOP_CENTER:          azim[ch] =   0;
>                                            elev[ch] =  90;      break;
> -        case AV_CH_TOP_FRONT_LEFT:        azim[ch] =  30;
> +        case AV_CHAN_TOP_FRONT_LEFT:      azim[ch] =  30;
>                                            elev[ch] =  45;      break;
> -        case AV_CH_TOP_FRONT_CENTER:      azim[ch] =   0;
> +        case AV_CHAN_TOP_FRONT_CENTER:    azim[ch] =   0;
>                                            elev[ch] =  45;      break;
> -        case AV_CH_TOP_FRONT_RIGHT:       azim[ch] = 330;
> +        case AV_CHAN_TOP_FRONT_RIGHT:     azim[ch] = 330;
>                                            elev[ch] =  45;      break;
> -        case AV_CH_TOP_BACK_LEFT:         azim[ch] = 150;
> +        case AV_CHAN_TOP_BACK_LEFT:       azim[ch] = 150;
>                                            elev[ch] =  45;      break;
> -        case AV_CH_TOP_BACK_RIGHT:        azim[ch] = 210;
> +        case AV_CHAN_TOP_BACK_RIGHT:      azim[ch] = 210;
>                                            elev[ch] =  45;      break;
> -        case AV_CH_TOP_BACK_CENTER:       azim[ch] = 180;
> +        case AV_CHAN_TOP_BACK_CENTER:     azim[ch] = 180;
>                                            elev[ch] =  45;      break;
> -        case AV_CH_WIDE_LEFT:             azim[ch] =  90;      break;
> -        case AV_CH_WIDE_RIGHT:            azim[ch] = 270;      break;
> -        case AV_CH_SURROUND_DIRECT_LEFT:  azim[ch] =  90;      break;
> -        case AV_CH_SURROUND_DIRECT_RIGHT: azim[ch] = 270;      break;
> -        case AV_CH_STEREO_LEFT:           azim[ch] =  90;      break;
> -        case AV_CH_STEREO_RIGHT:          azim[ch] = 270;      break;
> +        case AV_CHAN_WIDE_LEFT:           azim[ch] =  90;      break;
> +        case AV_CHAN_WIDE_RIGHT:          azim[ch] = 270;      break;
> +        case AV_CHAN_SURROUND_DIRECT_LEFT:  azim[ch] =  90;    break;
> +        case AV_CHAN_SURROUND_DIRECT_RIGHT: azim[ch] = 270;    break;
> +        case AV_CHAN_STEREO_LEFT:         azim[ch] =  90;      break;
> +        case AV_CHAN_STEREO_RIGHT:        azim[ch] = 270;      break;
>          case 0:                                                break;

case 0 makes no sense now

>          default:
>              return AVERROR(EINVAL);
> @@ -316,7 +306,7 @@ static int get_speaker_pos(AVFilterContext *ctx,
>              elev[ch] = s->vspkrpos[m].elev;
>          }
>  
> -        if (mask)
> +        if (chan)

and this check should be removed I think

> diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
> index 69ed0f29a8..ae90ae87fa 100644
> --- a/libavfilter/buffersink.h
> +++ b/libavfilter/buffersink.h
> @@ -46,7 +46,7 @@
>   * - av_buffersink_get_h(),
>   * - av_buffersink_get_sample_aspect_ratio(),
>   * - av_buffersink_get_channels(),
> - * - av_buffersink_get_channel_layout(),
> + * - av_buffersink_get_ch_layout(),

should mention that the layout should be uninited by the caller

> diff --git a/libavfilter/f_ebur128.c b/libavfilter/f_ebur128.c
> index 88d6a1fe46..2a6edba3d8 100644
> --- a/libavfilter/f_ebur128.c
> +++ b/libavfilter/f_ebur128.c
> @@ -422,7 +422,7 @@ static int config_audio_output(AVFilterLink *outlink)
>      int i;
>      AVFilterContext *ctx = outlink->src;
>      EBUR128Context *ebur128 = ctx->priv;
> -    const int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout);
> +    const int nb_channels = outlink->ch_layout.nb_channels;
>  
>  #define BACK_MASK (AV_CH_BACK_LEFT    |AV_CH_BACK_CENTER    |AV_CH_BACK_RIGHT| \
>                     AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_BACK_RIGHT| \
> @@ -439,8 +439,8 @@ static int config_audio_output(AVFilterLink *outlink)
>  
>      for (i = 0; i < nb_channels; i++) {
>          /* channel weighting */
> -        const uint64_t chl = av_channel_layout_extract_channel(outlink->channel_layout, i);
> -        if (chl & (AV_CH_LOW_FREQUENCY|AV_CH_LOW_FREQUENCY_2)) {
> +        const int chl = av_channel_layout_channel_from_index(&outlink->ch_layout, i);

enum AVChannel?

> +        if (chl == AV_CHAN_LOW_FREQUENCY || chl == AV_CHAN_LOW_FREQUENCY_2) {
>              ebur128->ch_weighting[i] = 0;
>          } else if (chl & BACK_MASK) {

This looks broken.

> diff --git a/libavfilter/formats.h b/libavfilter/formats.h
> index a884d15213..e55180f45c 100644
> --- a/libavfilter/formats.h
> +++ b/libavfilter/formats.h
> @@ -83,7 +83,7 @@ struct AVFilterFormats {
>   *   (e.g. AV_CH_LAYOUT_STEREO and FF_COUNT2LAYOUT(2).
>   */
>  struct AVFilterChannelLayouts {
> -    uint64_t *channel_layouts;  ///< list of channel layouts
> +    AVChannelLayout *channel_layouts; ///< list of channel layouts
>      int    nb_channel_layouts;  ///< number of channel layouts
>      char all_layouts;           ///< accept any known channel layout
>      char all_counts;            ///< accept any channel layout or count
> @@ -99,14 +99,16 @@ struct AVFilterChannelLayouts {
>   * The result is only valid inside AVFilterChannelLayouts and immediately
>   * related functions.
>   */
> -#define FF_COUNT2LAYOUT(c) (0x8000000000000000ULL | (c))
> +#define FF_COUNT2LAYOUT(c) ((AVChannelLayout) { .order = AV_CHANNEL_ORDER_UNSPEC, .nb_channels = c })
>  
>  /**
>   * Decode a channel count encoded as a channel layout.
>   * Return 0 if the channel layout was a real one.
>   */
> -#define FF_LAYOUT2COUNT(l) (((l) & 0x8000000000000000ULL) ? \
> -                           (int)((l) & 0x7FFFFFFF) : 0)
> +#define FF_LAYOUT2COUNT(l) (((l)->order == AV_CHANNEL_ORDER_UNSPEC) ? \
> +                            (l)->nb_channels : 0)
> +
> +#define KNOWN(l) (!FF_LAYOUT2COUNT(l)) /* for readability */
>  
>  /**
>   * Construct an empty AVFilterChannelLayouts/AVFilterFormats struct --
> @@ -126,7 +128,7 @@ av_warn_unused_result
>  AVFilterChannelLayouts *ff_all_channel_counts(void);
>  
>  av_warn_unused_result
> -AVFilterChannelLayouts *ff_make_format64_list(const int64_t *fmts);
> +AVFilterChannelLayouts *ff_make_format64_list(const AVChannelLayout *fmts);

The function name no longer makes sense

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 275/281] avfilter: convert to new channel layout API
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 275/281] avfilter: " James Almer
  2022-02-14 15:49   ` Anton Khirnov
@ 2022-02-15 11:50   ` Anton Khirnov
  2022-02-15 12:27     ` James Almer
  2022-02-15 18:52     ` James Almer
  2022-02-16 18:15   ` Anton Khirnov
  2 siblings, 2 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-02-15 11:50 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 03:09:07)
> diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c
> index ed3c75311a..96704e041c 100644
> --- a/libavfilter/af_aformat.c
> +++ b/libavfilter/af_aformat.c
> @@ -104,9 +104,36 @@ static av_cold int init(AVFilterContext *ctx)
>                    ff_add_format, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format");
>      PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format,
>                    get_sample_rate, 0, "sample rate");
> -    PARSE_FORMATS(s->channel_layouts_str, uint64_t, s->channel_layouts,
> -                  ff_add_channel_layout, av_get_channel_layout, 0,
> -                  "channel layout");
> +    {
> +        AVChannelLayout fmt = { 0 };
> +        const char *cur = s->channel_layouts_str;
> +        int ret;
> +
> +        if (s->channel_layouts_str && strchr(s->channel_layouts_str, ',')) {
> +            av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use '|' to "
> +                   "separate channel layout.\n");

It might be unclear to the user what "this syntax" refers to, maybe make
it "Using ',' to separate channel layouts is deprecated"

> diff --git a/libavfilter/af_biquads.c b/libavfilter/af_biquads.c
> index ee42b2a034..2a0747a037 100644
> --- a/libavfilter/af_biquads.c
> +++ b/libavfilter/af_biquads.c
> @@ -125,7 +125,7 @@ typedef struct BiquadsContext {
>      double frequency;
>      double width;
>      double mix;
> -    uint64_t channels;
> +    AVChannelLayout ch_layout;
>      int normalize;
>      int order;
>  
> @@ -716,11 +716,11 @@ static int config_filter(AVFilterLink *outlink, int reset)
>          s->b2 *= factor;
>      }
>  
> -    s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
> +    s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->ch_layout.nb_channels);
>      if (!s->cache)
>          return AVERROR(ENOMEM);
>      if (reset)
> -        memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
> +        memset(s->cache, 0, sizeof(ChanCache) * inlink->ch_layout.nb_channels);
>  
>      switch (s->transform_type) {
>      case DI:
> @@ -838,12 +838,14 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_job
>      AVFrame *buf = td->in;
>      AVFrame *out_buf = td->out;
>      BiquadsContext *s = ctx->priv;
> -    const int start = (buf->channels * jobnr) / nb_jobs;
> -    const int end = (buf->channels * (jobnr+1)) / nb_jobs;
> +    const int start = (buf->ch_layout.nb_channels * jobnr) / nb_jobs;
> +    const int end = (buf->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
>      int ch;
>  
>      for (ch = start; ch < end; ch++) {
> -        if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
> +        if (!(av_channel_layout_channel_from_index(&inlink->ch_layout, ch) >= 0 &&
> +              av_channel_layout_channel_from_index(&s->ch_layout, ch) >= 0)) {

This doesn't look right. The original code tests whether the channel
with index ch in inlink->channel_layout is present in s->channels.

The new code tests whether the channel with index ch exists in both
inlink->ch_layout and s->ch_layout (the test is also broken, because it
should compare against AV_CHAN_NONE).

Same applies to af_speechnorm

> diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
> index b2030dbbbb..2fe36368c1 100644
> --- a/libavfilter/af_headphone.c
> +++ b/libavfilter/af_headphone.c
> @@ -85,13 +85,13 @@ typedef struct HeadphoneContext {
>      uint64_t mapping[64];
>  } HeadphoneContext;
>  
> -static int parse_channel_name(const char *arg, uint64_t *rchannel)
> +static int parse_channel_name(const char *arg, int *rchannel)

enum AVChannel everywhere?

>  {
> -    uint64_t layout = av_get_channel_layout(arg);
> +    int channel = av_channel_from_string(arg);
>  
> -    if (av_get_channel_layout_nb_channels(layout) != 1)
> +    if (channel < 0)
>          return AVERROR(EINVAL);
> -    *rchannel = layout;
> +    *rchannel = channel;
>      return 0;
>  }
>  
> @@ -103,14 +103,14 @@ static void parse_map(AVFilterContext *ctx)
>  
>      p = s->map;
>      while ((arg = av_strtok(p, "|", &tokenizer))) {
> -        uint64_t out_channel;
> +        int out_channel;
>  
>          p = NULL;
>          if (parse_channel_name(arg, &out_channel)) {
>              av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", arg);
>              continue;
>          }
> -        if (used_channels & out_channel) {
> +        if (used_channels & (1ULL << out_channel)) {

should check that out_channel < 64

> diff --git a/libavfilter/af_surround.c b/libavfilter/af_surround.c
> index ccd85148e9..71d713e4ed 100644
> --- a/libavfilter/af_surround.c
> +++ b/libavfilter/af_surround.c
> @@ -92,8 +92,8 @@ typedef struct AudioSurroundContext {
>      float lowcut;
>      float highcut;
>  
> -    uint64_t out_channel_layout;
> -    uint64_t in_channel_layout;
> +    AVChannelLayout out_channel_layout;
> +    AVChannelLayout in_channel_layout;
>      int nb_in_channels;
>      int nb_out_channels;
>  
> @@ -171,7 +171,7 @@ static int query_formats(AVFilterContext *ctx)
>          return ret;
>  
>      layouts = NULL;
> -    ret = ff_add_channel_layout(&layouts, s->out_channel_layout);
> +    ret = ff_add_channel_layout(&layouts, &s->out_channel_layout);
>      if (ret)
>          return ret;
>  
> @@ -180,7 +180,7 @@ static int query_formats(AVFilterContext *ctx)
>          return ret;
>  
>      layouts = NULL;
> -    ret = ff_add_channel_layout(&layouts, s->in_channel_layout);
> +    ret = ff_add_channel_layout(&layouts, &s->in_channel_layout);
>      if (ret)
>          return ret;
>  
> @@ -197,12 +197,12 @@ static int config_input(AVFilterLink *inlink)
>      AudioSurroundContext *s = ctx->priv;
>      int ch;
>  
> -    s->rdft = av_calloc(inlink->channels, sizeof(*s->rdft));
> +    s->rdft = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->rdft));
>      if (!s->rdft)
>          return AVERROR(ENOMEM);
> -    s->nb_in_channels = inlink->channels;
> +    s->nb_in_channels = inlink->ch_layout.nb_channels;
>  
> -    for (ch = 0; ch < inlink->channels; ch++) {
> +    for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
>          s->rdft[ch]  = av_rdft_init(ff_log2(s->buf_size), DFT_R2C);
>          if (!s->rdft[ch])
>              return AVERROR(ENOMEM);
> @@ -212,31 +212,31 @@ static int config_input(AVFilterLink *inlink)
>          return AVERROR(ENOMEM);
>      for (ch = 0;  ch < s->nb_in_channels; ch++)
>          s->input_levels[ch] = s->level_in;
> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_CENTER);
> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_CENTER);
>      if (ch >= 0)
>          s->input_levels[ch] *= s->fc_in;
> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_LEFT);
> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_LEFT);
>      if (ch >= 0)
>          s->input_levels[ch] *= s->fl_in;
> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_RIGHT);
> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_RIGHT);
>      if (ch >= 0)
>          s->input_levels[ch] *= s->fr_in;
> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_LEFT);
> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_LEFT);
>      if (ch >= 0)
>          s->input_levels[ch] *= s->sl_in;
> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_RIGHT);
> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_RIGHT);
>      if (ch >= 0)
>          s->input_levels[ch] *= s->sr_in;
> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_LEFT);
> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_LEFT);
>      if (ch >= 0)
>          s->input_levels[ch] *= s->bl_in;
> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_RIGHT);
> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_RIGHT);
>      if (ch >= 0)
>          s->input_levels[ch] *= s->br_in;
> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_CENTER);
> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_CENTER);
>      if (ch >= 0)
>          s->input_levels[ch] *= s->bc_in;
> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_LOW_FREQUENCY);
> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_LOW_FREQUENCY);
>      if (ch >= 0)

Make all those compare to AV_CHAN_NONE

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 275/281] avfilter: convert to new channel layout API
  2022-02-15 11:50   ` Anton Khirnov
@ 2022-02-15 12:27     ` James Almer
  2022-02-15 12:34       ` Anton Khirnov
  2022-02-15 18:52     ` James Almer
  1 sibling, 1 reply; 337+ messages in thread
From: James Almer @ 2022-02-15 12:27 UTC (permalink / raw)
  To: ffmpeg-devel

On 2/15/2022 8:50 AM, Anton Khirnov wrote:
> Quoting James Almer (2022-01-13 03:09:07)
>> @@ -212,31 +212,31 @@ static int config_input(AVFilterLink *inlink)
>>           return AVERROR(ENOMEM);
>>       for (ch = 0;  ch < s->nb_in_channels; ch++)
>>           s->input_levels[ch] = s->level_in;
>> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_CENTER);
>> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_CENTER);
>>       if (ch >= 0)
>>           s->input_levels[ch] *= s->fc_in;
>> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_LEFT);
>> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_LEFT);
>>       if (ch >= 0)
>>           s->input_levels[ch] *= s->fl_in;
>> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_RIGHT);
>> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_RIGHT);
>>       if (ch >= 0)
>>           s->input_levels[ch] *= s->fr_in;
>> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_LEFT);
>> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_LEFT);
>>       if (ch >= 0)
>>           s->input_levels[ch] *= s->sl_in;
>> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_RIGHT);
>> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_RIGHT);
>>       if (ch >= 0)
>>           s->input_levels[ch] *= s->sr_in;
>> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_LEFT);
>> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_LEFT);
>>       if (ch >= 0)
>>           s->input_levels[ch] *= s->bl_in;
>> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_RIGHT);
>> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_RIGHT);
>>       if (ch >= 0)
>>           s->input_levels[ch] *= s->br_in;
>> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_CENTER);
>> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_CENTER);
>>       if (ch >= 0)
>>           s->input_levels[ch] *= s->bc_in;
>> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_LOW_FREQUENCY);
>> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_LOW_FREQUENCY);
>>       if (ch >= 0)
> 
> Make all those compare to AV_CHAN_NONE

ch is an index, so either >= 0, or EINVAL.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 275/281] avfilter: convert to new channel layout API
  2022-02-15 12:27     ` James Almer
@ 2022-02-15 12:34       ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-02-15 12:34 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-02-15 13:27:37)
> On 2/15/2022 8:50 AM, Anton Khirnov wrote:
> > Quoting James Almer (2022-01-13 03:09:07)
> >> @@ -212,31 +212,31 @@ static int config_input(AVFilterLink *inlink)
> >>           return AVERROR(ENOMEM);
> >>       for (ch = 0;  ch < s->nb_in_channels; ch++)
> >>           s->input_levels[ch] = s->level_in;
> >> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_CENTER);
> >> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_CENTER);
> >>       if (ch >= 0)
> >>           s->input_levels[ch] *= s->fc_in;
> >> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_LEFT);
> >> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_LEFT);
> >>       if (ch >= 0)
> >>           s->input_levels[ch] *= s->fl_in;
> >> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_RIGHT);
> >> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_RIGHT);
> >>       if (ch >= 0)
> >>           s->input_levels[ch] *= s->fr_in;
> >> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_LEFT);
> >> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_LEFT);
> >>       if (ch >= 0)
> >>           s->input_levels[ch] *= s->sl_in;
> >> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_RIGHT);
> >> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_RIGHT);
> >>       if (ch >= 0)
> >>           s->input_levels[ch] *= s->sr_in;
> >> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_LEFT);
> >> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_LEFT);
> >>       if (ch >= 0)
> >>           s->input_levels[ch] *= s->bl_in;
> >> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_RIGHT);
> >> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_RIGHT);
> >>       if (ch >= 0)
> >>           s->input_levels[ch] *= s->br_in;
> >> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_CENTER);
> >> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_CENTER);
> >>       if (ch >= 0)
> >>           s->input_levels[ch] *= s->bc_in;
> >> -    ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_LOW_FREQUENCY);
> >> +    ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_LOW_FREQUENCY);
> >>       if (ch >= 0)
> > 
> > Make all those compare to AV_CHAN_NONE
> 
> ch is an index, so either >= 0, or EINVAL.

right, nevermind then

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 275/281] avfilter: convert to new channel layout API
  2022-02-15 11:50   ` Anton Khirnov
  2022-02-15 12:27     ` James Almer
@ 2022-02-15 18:52     ` James Almer
  1 sibling, 0 replies; 337+ messages in thread
From: James Almer @ 2022-02-15 18:52 UTC (permalink / raw)
  To: ffmpeg-devel



On 2/15/2022 8:50 AM, Anton Khirnov wrote:
> Quoting James Almer (2022-01-13 03:09:07)
>> diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c
>> index ed3c75311a..96704e041c 100644
>> --- a/libavfilter/af_aformat.c
>> +++ b/libavfilter/af_aformat.c
>> @@ -104,9 +104,36 @@ static av_cold int init(AVFilterContext *ctx)
>>                     ff_add_format, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format");
>>       PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format,
>>                     get_sample_rate, 0, "sample rate");
>> -    PARSE_FORMATS(s->channel_layouts_str, uint64_t, s->channel_layouts,
>> -                  ff_add_channel_layout, av_get_channel_layout, 0,
>> -                  "channel layout");
>> +    {
>> +        AVChannelLayout fmt = { 0 };
>> +        const char *cur = s->channel_layouts_str;
>> +        int ret;
>> +
>> +        if (s->channel_layouts_str && strchr(s->channel_layouts_str, ',')) {
>> +            av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use '|' to "
>> +                   "separate channel layout.\n");
> It might be unclear to the user what "this syntax" refers to, maybe make
> it "Using ',' to separate channel layouts is deprecated"

This is copy-paste from the PARSE_FORMATS() macro. I'd rather leave 
changing it to a separate commit, and do it for sample rate and sample 
format too.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 275/281] avfilter: convert to new channel layout API
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 275/281] avfilter: " James Almer
  2022-02-14 15:49   ` Anton Khirnov
  2022-02-15 11:50   ` Anton Khirnov
@ 2022-02-16 18:15   ` Anton Khirnov
  2022-02-18 13:07     ` James Almer
  2 siblings, 1 reply; 337+ messages in thread
From: Anton Khirnov @ 2022-02-16 18:15 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 03:09:07)
> diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c
> index 1a2519dd32..31453823c5 100644
> --- a/libavfilter/af_channelsplit.c
> +++ b/libavfilter/af_channelsplit.c
> @@ -36,7 +36,7 @@
>  typedef struct ChannelSplitContext {
>      const AVClass *class;
>  
> -    uint64_t channel_layout;
> +    AVChannelLayout channel_layout;
>      char    *channel_layout_str;
>      char    *channels_str;
>  
> @@ -57,11 +57,11 @@ AVFILTER_DEFINE_CLASS(channelsplit);
>  static av_cold int init(AVFilterContext *ctx)
>  {
>      ChannelSplitContext *s = ctx->priv;
> -    uint64_t channel_layout;
> +    AVChannelLayout channel_layout = { 0 };
>      int nb_channels;
>      int all = 0, ret = 0, i;
>  
> -    if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) {
> +    if ((ret = av_channel_layout_from_string(&s->channel_layout, s->channel_layout_str)) < 0) {
>          av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
>                 s->channel_layout_str);
>          ret = AVERROR(EINVAL);
> @@ -70,27 +70,32 @@ static av_cold int init(AVFilterContext *ctx)
>  
>  
>      if (!strcmp(s->channels_str, "all")) {
> -        nb_channels = av_get_channel_layout_nb_channels(s->channel_layout);
> +        nb_channels = s->channel_layout.nb_channels;
>          channel_layout = s->channel_layout;
>          all = 1;
>      } else {
> -        if ((ret = av_get_extended_channel_layout(s->channels_str, &channel_layout, &nb_channels)) < 0)
> +        if ((ret = av_channel_layout_from_string(&channel_layout, s->channels_str)) < 0)
>              return ret;
>      }
>  
>      for (i = 0; i < nb_channels; i++) {
> -        uint64_t channel = av_channel_layout_extract_channel(channel_layout, i);
> -        AVFilterPad pad  = { 0 };
> +        int channel = av_channel_layout_channel_from_index(&channel_layout, i);
> +        char buf[64];
> +        AVFilterPad pad = { .flags = AVFILTERPAD_FLAG_FREE_NAME };
>  
> +        av_channel_name(buf, sizeof(buf), channel);
>          pad.type = AVMEDIA_TYPE_AUDIO;
> -        pad.name = av_get_channel_name(channel);
> +        pad.name = av_strdup(buf);
> +        if (!pad.name)
> +            return AVERROR(ENOMEM);
>  
>          if (all) {
>              s->map[i] = i;

Should either make map dynamically allocated or check that there are
fewer than 64 channels in the layout.

>          } else {
> -            if ((ret = av_get_channel_layout_channel_index(s->channel_layout, channel)) < 0) {
> +            if ((ret = av_channel_layout_index_from_channel(&s->channel_layout, channel)) < 0) {
>                  av_log(ctx, AV_LOG_ERROR, "Channel name '%s' not present in channel layout '%s'.\n",
> -                       av_get_channel_name(channel), s->channel_layout_str);
> +                       pad.name, s->channel_layout_str);
> +                av_freep(&pad.name);
>                  return ret;
>              }
>  
> @@ -115,15 +120,18 @@ static int query_formats(AVFilterContext *ctx)
>          (ret = ff_set_common_all_samplerates(ctx)) < 0)
>          return ret;
>  
> -    if ((ret = ff_add_channel_layout(&in_layouts, s->channel_layout)) < 0 ||
> +    if ((ret = ff_add_channel_layout(&in_layouts, &s->channel_layout)) < 0 ||
>          (ret = ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->outcfg.channel_layouts)) < 0)
>          return ret;
>  
>      for (i = 0; i < ctx->nb_outputs; i++) {
> +        AVChannelLayout channel_layout = { 0 };
>          AVFilterChannelLayouts *out_layouts = NULL;
> -        uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, s->map[i]);
> +        int channel = av_channel_layout_channel_from_index(&s->channel_layout, s->map[i]);
>  
> -        if ((ret = ff_add_channel_layout(&out_layouts, channel)) < 0 ||
> +        if ((channel < 0) ||
> +            (ret = av_channel_layout_from_mask(&channel_layout, 1ULL << channel)) < 0 ||
> +            (ret = ff_add_channel_layout(&out_layouts, &channel_layout)) < 0 ||
>              (ret = ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->incfg.channel_layouts)) < 0)
>              return ret;
>      }
> @@ -139,6 +147,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
>  
>      for (i = 0; i < ctx->nb_outputs; i++) {
>          AVFrame *buf_out = av_frame_clone(buf);
> +        int channel = av_channel_layout_channel_from_index(&buf->ch_layout, s->map[i]);
>  
>          if (!buf_out) {
>              ret = AVERROR(ENOMEM);
> @@ -146,9 +155,16 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
>          }
>  
>          buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[s->map[i]];
> +        ret = av_channel_layout_from_mask(&buf_out->ch_layout, 1ULL << channel);

potential invalid shift?

> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 7362bcdab5..acb2d7db51 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -204,6 +204,7 @@ void avfilter_link_free(AVFilterLink **link)
>  
>      ff_framequeue_free(&(*link)->fifo);
>      ff_frame_pool_uninit((FFFramePool**)&(*link)->frame_pool);
> +    av_channel_layout_uninit(&(*link)->ch_layout);
>  
>      av_freep(link);
>  }
> @@ -405,7 +406,7 @@ void ff_tlog_link(void *ctx, AVFilterLink *link, int end)
>                  end ? "\n" : "");
>      } else {
>          char buf[128];
> -        av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
> +        av_channel_layout_describe(&link->ch_layout, buf, sizeof(buf));
>  
>          ff_tlog(ctx,
>                  "link[%p r:%d cl:%s fmt:%s %s->%s]%s",
> @@ -1036,11 +1037,21 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
>              av_log(link->dst, AV_LOG_ERROR, "Format change is not supported\n");
>              goto error;
>          }
> -        if (frame->channels != link->channels) {
> +#if FF_API_OLD_CHANNEL_LAYOUT
> +FF_DISABLE_DEPRECATION_WARNINGS
> +        if (frame->channels != link->ch_layout.nb_channels) {
>              av_log(link->dst, AV_LOG_ERROR, "Channel count change is not supported\n");
>              goto error;
>          }
> -        if (frame->channel_layout != link->channel_layout) {
> +        if (frame->channel_layout && frame->channel_layout != link->channel_layout) {
> +            av_log(link->dst, AV_LOG_ERROR, "Channel layout change is not supported\n");
> +            goto error;
> +        }
> +FF_ENABLE_DEPRECATION_WARNINGS
> +        if (av_channel_layout_check(&frame->ch_layout) && av_channel_layout_compare(&frame->ch_layout, &link->ch_layout)) {
> +#else
> +        if (av_channel_layout_compare(&frame->ch_layout, &link->ch_layout)) {
> +#endif

Is all this still needed? Presumably after this patch all sources make
sure the old and new fields are in sync, so we could just assert here,
or not check at all.

> diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
> index b89a680883..3ebd279df7 100644
> --- a/libavfilter/src_movie.c
> +++ b/libavfilter/src_movie.c
> @@ -189,23 +189,24 @@ static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
>  {
>      AVCodecParameters *dec_par = st->st->codecpar;
>      char buf[256];
> -    int64_t chl = av_get_default_channel_layout(dec_par->channels);
> +    AVChannelLayout chl = { 0 };
>  
> -    if (!chl) {
> +    av_channel_layout_default(&chl, dec_par->ch_layout.nb_channels);
> +
> +    if (!KNOWN(&chl)) {
>          av_log(log_ctx, AV_LOG_ERROR,
>                 "Channel layout is not set in stream %d, and could not "
>                 "be guessed from the number of channels (%d)\n",
> -               st_index, dec_par->channels);
> +               st_index, dec_par->ch_layout.nb_channels);
>          return AVERROR(EINVAL);

Should this still be an error? Unspec layouts should now be properly
supported by (almost?) everything.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 275/281] avfilter: convert to new channel layout API
  2022-02-16 18:15   ` Anton Khirnov
@ 2022-02-18 13:07     ` James Almer
  0 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-02-18 13:07 UTC (permalink / raw)
  To: ffmpeg-devel



On 2/16/2022 3:15 PM, Anton Khirnov wrote:
>> diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
>> index b89a680883..3ebd279df7 100644
>> --- a/libavfilter/src_movie.c
>> +++ b/libavfilter/src_movie.c
>> @@ -189,23 +189,24 @@ static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
>>   {
>>       AVCodecParameters *dec_par = st->st->codecpar;
>>       char buf[256];
>> -    int64_t chl = av_get_default_channel_layout(dec_par->channels);
>> +    AVChannelLayout chl = { 0 };
>>   
>> -    if (!chl) {
>> +    av_channel_layout_default(&chl, dec_par->ch_layout.nb_channels);
>> +
>> +    if (!KNOWN(&chl)) {
>>           av_log(log_ctx, AV_LOG_ERROR,
>>                  "Channel layout is not set in stream %d, and could not "
>>                  "be guessed from the number of channels (%d)\n",
>> -               st_index, dec_par->channels);
>> +               st_index, dec_par->ch_layout.nb_channels);
>>           return AVERROR(EINVAL);
> Should this still be an error? Unspec layouts should now be properly
> supported by (almost?) everything.

Probably, but making it no longer abort if a native channel layout can't 
be guessed is a behavior change that I'd rather leave for a different 
patch, if you don't mind.

> 
> -- Anton Khirnov _______________________________________________ 
> ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org 
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit 
> link above, or email ffmpeg-devel-request@ffmpeg.org with subject 
> "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 195/281] audiotoolbox: convert to new channel layout API
  2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 195/281] audiotoolbox: " James Almer
@ 2022-02-21 14:22   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-02-21 14:22 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 03:02:28)
> From: Anton Khirnov <anton@khirnov.net>
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/audiotoolboxdec.c | 27 +++++-----
>  libavcodec/audiotoolboxenc.c | 95 ++++++++++++++++--------------------
>  2 files changed, 57 insertions(+), 65 deletions(-)
> 
> diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c
> index 9939fef218..8edf9bd463 100644
> --- a/libavcodec/audiotoolboxdec.c
> +++ b/libavcodec/audiotoolboxdec.c
> @@ -166,8 +166,8 @@ static int ffat_update_ctx(AVCodecContext *avctx)
>                                     &size, &format)) {
>          if (format.mSampleRate)
>              avctx->sample_rate = format.mSampleRate;
> -        avctx->channels = format.mChannelsPerFrame;
> -        avctx->channel_layout = av_get_default_channel_layout(avctx->channels);
> +        av_channel_layout_uninit(&avctx->ch_layout);
> +        av_get_default_channel_layout(&avctx->ch_layout, format.mChannelsPerFrame);

Looks wrong

> @@ -364,11 +365,11 @@ static av_cold int ffat_create_decoder(AVCodecContext *avctx,
>  #endif
>      } else {
>          in_format.mSampleRate = avctx->sample_rate ? avctx->sample_rate : 44100;
> -        in_format.mChannelsPerFrame = avctx->channels ? avctx->channels : 1;
> +        in_format.mChannelsPerFrame = avctx->ch_layout.nb_channels ? avctx->ch_layout.nb_channels : 1;
>      }
>  
>      avctx->sample_rate = out_format.mSampleRate = in_format.mSampleRate;
> -    avctx->channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;
> +    avctx->ch_layout.nb_channels = out_format.mChannelsPerFrame = in_format.mChannelsPerFrame;

Should probably uninit+set order.

> diff --git a/libavcodec/audiotoolboxenc.c b/libavcodec/audiotoolboxenc.c
> index 9245aa9dc4..aeda1c36fd 100644
> --- a/libavcodec/audiotoolboxenc.c
> +++ b/libavcodec/audiotoolboxenc.c
> @@ -278,10 +272,7 @@ static av_cold int ffat_init_encoder(AVCodecContext *avctx)
>          return AVERROR_UNKNOWN;
>      }
>  
> -    if (!avctx->channel_layout)
> -        avctx->channel_layout = av_get_default_channel_layout(avctx->channels);

I suspect this will break unspec channel layouts that previously worked.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 211/281] flac: convert to new channel layout API
  2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 211/281] flac: " James Almer
@ 2022-02-23 10:24   ` Anton Khirnov
  2022-02-23 11:51     ` James Almer
  0 siblings, 1 reply; 337+ messages in thread
From: Anton Khirnov @ 2022-02-23 10:24 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 03:04:50)
> From: Anton Khirnov <anton@khirnov.net>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: Anton Khirnov <anton@khirnov.net>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/flac.c        | 39 +++++++++++++++++++++------------------
>  libavcodec/flac.h        |  2 +-
>  libavcodec/flac_parser.c |  7 ++-----
>  libavcodec/flacdec.c     |  9 ++++-----
>  libavcodec/flacenc.c     | 26 +++++++++++++-------------
>  5 files changed, 41 insertions(+), 42 deletions(-)
> 
> diff --git a/libavcodec/flac.c b/libavcodec/flac.c
> index 7b075d4bd3..51014faea1 100644
> --- a/libavcodec/flac.c
> +++ b/libavcodec/flac.c
> @@ -29,15 +29,15 @@
>  
>  static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 };
>  
> -static const uint64_t flac_channel_layouts[8] = {
> -    AV_CH_LAYOUT_MONO,
> -    AV_CH_LAYOUT_STEREO,
> -    AV_CH_LAYOUT_SURROUND,
> -    AV_CH_LAYOUT_QUAD,
> -    AV_CH_LAYOUT_5POINT0,
> -    AV_CH_LAYOUT_5POINT1,
> -    AV_CH_LAYOUT_6POINT1,
> -    AV_CH_LAYOUT_7POINT1
> +static const AVChannelLayout flac_channel_layouts[8] = {
> +    AV_CHANNEL_LAYOUT_MONO,
> +    AV_CHANNEL_LAYOUT_STEREO,
> +    AV_CHANNEL_LAYOUT_SURROUND,
> +    AV_CHANNEL_LAYOUT_QUAD,
> +    AV_CHANNEL_LAYOUT_5POINT0,
> +    AV_CHANNEL_LAYOUT_5POINT1,
> +    AV_CHANNEL_LAYOUT_6POINT1,
> +    AV_CHANNEL_LAYOUT_7POINT1
>  };
>  
>  static int64_t get_utf8(GetBitContext *gb)
> @@ -193,12 +193,19 @@ int ff_flac_is_extradata_valid(AVCodecContext *avctx,
>      return 1;
>  }
>  
> -void ff_flac_set_channel_layout(AVCodecContext *avctx)
> +void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels)
>  {
> -    if (avctx->channels <= FF_ARRAY_ELEMS(flac_channel_layouts))
> -        avctx->channel_layout = flac_channel_layouts[avctx->channels - 1];
> +    if (channels == avctx->ch_layout.nb_channels &&
> +        avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
> +        avctx->ch_layout.u.mask)

Not sure why I wrote this check like this originally, now it seems
better to check for order != UNSPEC, so that a user-supplied custom
layout is preserved.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 211/281] flac: convert to new channel layout API
  2022-02-23 10:24   ` Anton Khirnov
@ 2022-02-23 11:51     ` James Almer
  0 siblings, 0 replies; 337+ messages in thread
From: James Almer @ 2022-02-23 11:51 UTC (permalink / raw)
  To: ffmpeg-devel



On 2/23/2022 7:24 AM, Anton Khirnov wrote:
> Quoting James Almer (2022-01-13 03:04:50)
>> From: Anton Khirnov <anton@khirnov.net>
>>
>> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
>> Signed-off-by: Anton Khirnov <anton@khirnov.net>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavcodec/flac.c        | 39 +++++++++++++++++++++------------------
>>   libavcodec/flac.h        |  2 +-
>>   libavcodec/flac_parser.c |  7 ++-----
>>   libavcodec/flacdec.c     |  9 ++++-----
>>   libavcodec/flacenc.c     | 26 +++++++++++++-------------
>>   5 files changed, 41 insertions(+), 42 deletions(-)
>>
>> diff --git a/libavcodec/flac.c b/libavcodec/flac.c
>> index 7b075d4bd3..51014faea1 100644
>> --- a/libavcodec/flac.c
>> +++ b/libavcodec/flac.c
>> @@ -29,15 +29,15 @@
>>   
>>   static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 };
>>   
>> -static const uint64_t flac_channel_layouts[8] = {
>> -    AV_CH_LAYOUT_MONO,
>> -    AV_CH_LAYOUT_STEREO,
>> -    AV_CH_LAYOUT_SURROUND,
>> -    AV_CH_LAYOUT_QUAD,
>> -    AV_CH_LAYOUT_5POINT0,
>> -    AV_CH_LAYOUT_5POINT1,
>> -    AV_CH_LAYOUT_6POINT1,
>> -    AV_CH_LAYOUT_7POINT1
>> +static const AVChannelLayout flac_channel_layouts[8] = {
>> +    AV_CHANNEL_LAYOUT_MONO,
>> +    AV_CHANNEL_LAYOUT_STEREO,
>> +    AV_CHANNEL_LAYOUT_SURROUND,
>> +    AV_CHANNEL_LAYOUT_QUAD,
>> +    AV_CHANNEL_LAYOUT_5POINT0,
>> +    AV_CHANNEL_LAYOUT_5POINT1,
>> +    AV_CHANNEL_LAYOUT_6POINT1,
>> +    AV_CHANNEL_LAYOUT_7POINT1
>>   };
>>   
>>   static int64_t get_utf8(GetBitContext *gb)
>> @@ -193,12 +193,19 @@ int ff_flac_is_extradata_valid(AVCodecContext *avctx,
>>       return 1;
>>   }
>>   
>> -void ff_flac_set_channel_layout(AVCodecContext *avctx)
>> +void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels)
>>   {
>> -    if (avctx->channels <= FF_ARRAY_ELEMS(flac_channel_layouts))
>> -        avctx->channel_layout = flac_channel_layouts[avctx->channels - 1];
>> +    if (channels == avctx->ch_layout.nb_channels &&
>> +        avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
>> +        avctx->ch_layout.u.mask)
> 
> Not sure why I wrote this check like this originally, now it seems
> better to check for order != UNSPEC, so that a user-supplied custom
> layout is preserved.

You didn't write that, i did it to prevent the failure of 
fate-matroska-flac-extradata-update (a very recent test). Changing it to 
!= UNSPEC also works, so I'll do that.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 224/281] libfdk-aac: convert to new channel layout API
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 224/281] libfdk-aac: " James Almer
@ 2022-02-25 11:18   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-02-25 11:18 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 03:05:03)
> diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
> index 7ee2f13ac7..d43f45d9ee 100644
> --- a/libavcodec/libfdk-aacenc.c
> +++ b/libavcodec/libfdk-aacenc.c
> @@ -128,7 +128,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
>      int aot = FF_PROFILE_AAC_LOW + 1;
>      int sce = 0, cpe = 0;
>  
> -    if ((err = aacEncOpen(&s->handle, 0, avctx->channels)) != AACENC_OK) {
> +    if ((err = aacEncOpen(&s->handle, 0, avctx->ch_layout.nb_channels)) != AACENC_OK) {
>          av_log(avctx, AV_LOG_ERROR, "Unable to open the encoder: %s\n",
>                 aac_get_error(err));
>          goto error;
> @@ -159,7 +159,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
>          goto error;
>      }
>  
> -    switch (avctx->channels) {
> +    switch (avctx->ch_layout.nb_channels) {
>      case 1: mode = MODE_1;       sce = 1; cpe = 0; break;
>      case 2:
>  #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
> @@ -193,7 +193,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
>      case 8:
>          sce = 2;
>          cpe = 3;
> -        if (avctx->channel_layout == AV_CH_LAYOUT_7POINT1) {
> +        if (avctx->ch_layout.u.mask == AV_CH_LAYOUT_7POINT1) {

Either check for order == NATIVE or use channel_layout_compare.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 226/281] libgsm: convert to new channel layout API
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 226/281] libgsm: " James Almer
@ 2022-02-25 11:20   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-02-25 11:20 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 03:05:05)
> From: Anton Khirnov <anton@khirnov.net>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: Anton Khirnov <anton@khirnov.net>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/libgsmdec.c | 4 ++--
>  libavcodec/libgsmenc.c | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/libgsmdec.c b/libavcodec/libgsmdec.c
> index ae4a952d99..aa028bc262 100644
> --- a/libavcodec/libgsmdec.c
> +++ b/libavcodec/libgsmdec.c
> @@ -48,8 +48,8 @@ typedef struct LibGSMDecodeContext {
>  static av_cold int libgsm_decode_init(AVCodecContext *avctx) {
>      LibGSMDecodeContext *s = avctx->priv_data;
>  
> -    avctx->channels       = 1;
> -    avctx->channel_layout = AV_CH_LAYOUT_MONO;
> +    av_channel_layout_uninit(&avctx->ch_layout);
> +    avctx->ch_layout      = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
>      if (!avctx->sample_rate)
>          avctx->sample_rate = 8000;
>      avctx->sample_fmt     = AV_SAMPLE_FMT_S16;
> diff --git a/libavcodec/libgsmenc.c b/libavcodec/libgsmenc.c
> index a2f6c1c62e..f73f254d50 100644
> --- a/libavcodec/libgsmenc.c
> +++ b/libavcodec/libgsmenc.c
> @@ -49,9 +49,9 @@ static av_cold int libgsm_encode_close(AVCodecContext *avctx) {
>  }
>  
>  static av_cold int libgsm_encode_init(AVCodecContext *avctx) {
> -    if (avctx->channels > 1) {
> +    if (avctx->ch_layout.nb_channels > 1) {
>          av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n",
> -               avctx->channels);
> +               avctx->ch_layout.nb_channels);
>          return -1;

This could be dropped completely, since the codec sets ch_layouts.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 229/281] libopus: convert to new channel layout API
  2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 229/281] libopus: " James Almer
@ 2022-02-25 11:46   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-02-25 11:46 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 03:05:08)
> From: Anton Khirnov <anton@khirnov.net>
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/libopusdec.c  | 39 +++++++++++++-----------
>  libavcodec/libopusenc.c  | 65 ++++++++++++++++++++++------------------
>  libavcodec/vorbis.h      |  3 ++
>  libavcodec/vorbis_data.c | 18 +++++++++++
>  4 files changed, 79 insertions(+), 46 deletions(-)
> 
> diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c
> index 86ef715205..abffd5f463 100644
> --- a/libavcodec/libopusdec.c
> +++ b/libavcodec/libopusdec.c
> @@ -50,55 +50,60 @@ struct libopus_context {
>  static av_cold int libopus_decode_init(AVCodecContext *avc)
>  {
>      struct libopus_context *opus = avc->priv_data;
> -    int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
> +    int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled, channels;
>      uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
>  
> -    avc->channels = avc->extradata_size >= 10 ? avc->extradata[9] : (avc->channels == 1) ? 1 : 2;
> -    if (avc->channels <= 0) {
> +    channels = avc->extradata_size >= 10 ? avc->extradata[9] : (channels == 1) ? 1 : 2;
                                                                   ^^^^^^^^
uninitialized read
this is meant to use the user-provided value

> diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
> index 45b23fcbb5..401a2c17c8 100644
> --- a/libavcodec/libopusenc.c
> +++ b/libavcodec/libopusenc.c
> @@ -91,7 +91,7 @@ static void libopus_write_header(AVCodecContext *avctx, int stream_count,
>                                   const uint8_t *channel_mapping)
>  {
>      uint8_t *p   = avctx->extradata;
> -    int channels = avctx->channels;
> +    int channels = avctx->ch_layout.nb_channels;
>  
>      bytestream_put_buffer(&p, "OpusHead", 8);
>      bytestream_put_byte(&p, 1); /* Version */
> @@ -180,9 +180,9 @@ static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc,
>  
>  static int libopus_check_max_channels(AVCodecContext *avctx,
>                                        int max_channels) {
> -    if (avctx->channels > max_channels) {
> +    if (avctx->ch_layout.nb_channels > max_channels) {
>          av_log(avctx, AV_LOG_ERROR, "Opus mapping family undefined for %d channels.\n",
> -               avctx->channels);
> +               avctx->ch_layout.nb_channels);
>          return AVERROR(EINVAL);
>      }
>  
> @@ -190,21 +190,26 @@ static int libopus_check_max_channels(AVCodecContext *avctx,
>  }
>  
>  static int libopus_check_vorbis_layout(AVCodecContext *avctx, int mapping_family) {
> -    av_assert2(avctx->channels < FF_ARRAY_ELEMS(ff_vorbis_channel_layouts));
> +    av_assert2(avctx->ch_layout.nb_channels < FF_ARRAY_ELEMS(ff_vorbis_ch_layouts));
>  
> -    if (!avctx->channel_layout) {
> +    if (avctx->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
>          av_log(avctx, AV_LOG_WARNING,
>                 "No channel layout specified. Opus encoder will use Vorbis "
> -               "channel layout for %d channels.\n", avctx->channels);
> -    } else if (avctx->channel_layout != ff_vorbis_channel_layouts[avctx->channels - 1]) {
> -        char name[32];
> -        av_get_channel_layout_string(name, sizeof(name), avctx->channels,
> -                                     avctx->channel_layout);
> -        av_log(avctx, AV_LOG_ERROR,
> -               "Invalid channel layout %s for specified mapping family %d.\n",
> -               name, mapping_family);
> +               "channel layout for %d channels.\n", avctx->ch_layout.nb_channels);
> +    } else {
> +        AVChannelLayout chl;
> +        av_channel_layout_copy(&chl, &ff_vorbis_ch_layouts[avctx->ch_layout.nb_channels - 1]);

chl is garbage, while av_channel_layout_copy() uninits it

is the copy even necessary? Why not pass ff_vorbis_ch_layouts to compare
directly?

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 270/281] wma: convert to new channel layout API
  2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 270/281] wma: " James Almer
@ 2022-03-07 10:26   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-03-07 10:26 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 03:09:02)
> From: Anton Khirnov <anton@khirnov.net>
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/wma.c            | 11 ++++++-----
>  libavcodec/wmadec.c         | 29 +++++++++++++++--------------
>  libavcodec/wmaenc.c         | 27 ++++++++++++++-------------
>  libavcodec/wmalosslessdec.c | 13 +++++++------
>  libavcodec/wmaprodec.c      | 30 ++++++++++++++++++++----------
>  libavcodec/wmavoice.c       |  4 ++--
>  6 files changed, 64 insertions(+), 50 deletions(-)
> 
> diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
> index ba7bddc51c..5c1d38eca5 100644
> --- a/libavcodec/wmaprodec.c
> +++ b/libavcodec/wmaprodec.c
> @@ -384,7 +384,7 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu
>          s->decode_flags    = 0x10d6;
>          s->bits_per_sample = 16;
>          channel_mask       = 0; //AV_RL32(edata_ptr+2); /* not always in expected order */
> -        if ((num_stream+1) * XMA_MAX_CHANNELS_STREAM > avctx->channels) /* stream config is 2ch + 2ch + ... + 1/2ch */
> +        if ((num_stream+1) * XMA_MAX_CHANNELS_STREAM > avctx->ch_layout.nb_channels) /* stream config is 2ch + 2ch + ... + 1/2ch */
>              s->nb_channels = 1;
>          else
>              s->nb_channels = 2;
> @@ -402,7 +402,7 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu
>          s->decode_flags    = AV_RL16(edata_ptr+14);
>          channel_mask       = AV_RL32(edata_ptr+2);
>          s->bits_per_sample = AV_RL16(edata_ptr);
> -        s->nb_channels     = avctx->channels;
> +        s->nb_channels     = avctx->ch_layout.nb_channels;
>  
>          if (s->bits_per_sample > 32 || s->bits_per_sample < 1) {
>              avpriv_request_sample(avctx, "bits per sample is %d", s->bits_per_sample);
> @@ -474,7 +474,7 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu
>          av_log(avctx, AV_LOG_ERROR, "invalid number of channels per XMA stream %d\n",
>                 s->nb_channels);
>          return AVERROR_INVALIDDATA;
> -    } else if (s->nb_channels > WMAPRO_MAX_CHANNELS || s->nb_channels > avctx->channels) {
> +    } else if (s->nb_channels > WMAPRO_MAX_CHANNELS || s->nb_channels > avctx->ch_layout.nb_channels) {
>          avpriv_request_sample(avctx,
>                                "More than %d channels", WMAPRO_MAX_CHANNELS);
>          return AVERROR_PATCHWELCOME;
> @@ -575,8 +575,13 @@ static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int nu
>      if (avctx->debug & FF_DEBUG_BITSTREAM)
>          dump_context(s);
>  
> -    if (avctx->codec_id == AV_CODEC_ID_WMAPRO)
> -        avctx->channel_layout = channel_mask;
> +    if (avctx->codec_id == AV_CODEC_ID_WMAPRO) {
> +        if (channel_mask) {
> +            av_channel_layout_uninit(&avctx->ch_layout);
> +            av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
> +        } else
> +            avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
> +    }
>  
>      ff_thread_once(&init_static_once, decode_init_static);
>  
> @@ -1775,7 +1780,7 @@ static int decode_packet(AVCodecContext *avctx, WMAProDecodeCtx *s,
>          AVFrame *frame = data;
>  
>          if (s->trim_start < frame->nb_samples) {
> -            for (int ch = 0; ch < frame->channels; ch++)
> +            for (int ch = 0; ch < frame->ch_layout.nb_channels; ch++)
>                  frame->extended_data[ch] += s->trim_start * 4;
>  
>              frame->nb_samples -= s->trim_start;
> @@ -1952,13 +1957,18 @@ static av_cold int xma_decode_init(AVCodecContext *avctx)
>      XMADecodeCtx *s = avctx->priv_data;
>      int i, ret, start_channels = 0;
>  
> -    if (avctx->channels <= 0 || avctx->extradata_size == 0)
> +    if (avctx->ch_layout.nb_channels <= 0 || avctx->extradata_size == 0)
>          return AVERROR_INVALIDDATA;
>  
>      /* get stream config */
>      if (avctx->codec_id == AV_CODEC_ID_XMA2 && avctx->extradata_size == 34) { /* XMA2WAVEFORMATEX */
> +        unsigned int channel_mask = AV_RL32(avctx->extradata + 2);
> +        if (channel_mask) {
> +            av_channel_layout_uninit(&avctx->ch_layout);
> +            av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
> +        } else
> +            avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;

This function doesn't seem to validate that the channel_mask is
consistent with s->nb_channels - should probably be done

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

* Re: [FFmpeg-devel] [PATCH 269/281] wavpack: convert to new channel layout API
  2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 269/281] wavpack: " James Almer
@ 2022-03-07 10:42   ` Anton Khirnov
  0 siblings, 0 replies; 337+ messages in thread
From: Anton Khirnov @ 2022-03-07 10:42 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting James Almer (2022-01-13 03:07:13)
> From: Anton Khirnov <anton@khirnov.net>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/wavpack.c    | 51 ++++++++++++++++++-----------------------
>  libavcodec/wavpackenc.c | 29 ++++++++++++-----------
>  2 files changed, 37 insertions(+), 43 deletions(-)
> 
> diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
> index 6b2ec19bf1..e0350ce732 100644
> --- a/libavcodec/wavpack.c
> +++ b/libavcodec/wavpack.c
> @@ -1512,36 +1509,32 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
>          new_samplerate *= rate_x;
>  
>          if (multiblock) {
> -            if (chan)
> -                new_channels = chan;
> -            if (chmask)
> -                new_chmask = chmask;
> +            if (chmask) {
> +                av_channel_layout_from_mask(&new_ch_layout, chmask);
> +                if (chan && new_ch_layout.nb_channels != chan) {
> +                    av_log(avctx, AV_LOG_ERROR, "Channel mask does not match the channel count\n");
> +                    return AVERROR_INVALIDDATA;
> +                }
> +            } else
> +                av_channel_layout_copy(&new_ch_layout, &avctx->ch_layout);

user-supplied layout can be custom, so you should probably check this
and the second copy below


-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 337+ messages in thread

end of thread, other threads:[~2022-03-07 10:42 UTC | newest]

Thread overview: 337+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-13  1:49 [FFmpeg-devel] [PATCH 000/281 v3] New channel layout API James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 001/281] Add a new " James Almer
2022-01-13 14:08   ` Lynne
2022-01-16 11:27   ` Nicolas George
2022-01-16 22:54     ` Marton Balint
2022-01-17 13:22       ` James Almer
2022-01-17 20:18         ` Marton Balint
2022-01-17 20:27           ` James Almer
2022-01-17 13:53       ` Nicolas George
2022-01-17 13:54         ` James Almer
2022-01-17 13:56           ` Nicolas George
2022-01-17 14:02             ` James Almer
2022-01-17 16:50               ` Nicolas George
2022-01-17 16:52                 ` James Almer
2022-01-17 16:54                   ` Nicolas George
2022-01-17 16:57                     ` James Almer
2022-01-17 17:55                       ` Nicolas George
2022-01-17 13:32     ` James Almer
2022-01-17 13:51       ` Nicolas George
2022-01-17 14:12         ` James Almer
2022-01-17 16:48           ` Nicolas George
2022-01-17 16:50             ` James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 002/281] fate: add a channel_layout API test James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 003/281] lavu: support AVChannelLayout AVOptions James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 004/281] lavc: deprecate channel count/layout changing side data James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 005/281] avframe: switch to the new channel layout API James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 006/281] avcodecpar: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 007/281] lavf: add a temporary compat layer for the channel layout API change James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 008/281] lavf: convert the generic layer to the new channel layout James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 009/281] 3dostr: convert to new channel layout API James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 010/281] 4xm: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 011/281] aa: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 012/281] aax: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 013/281] ace: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 014/281] acm: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 015/281] act: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 016/281] adp: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 017/281] ads: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 018/281] adxdec: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 019/281] aea: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 020/281] afc: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 021/281] aiff: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 022/281] aixdec: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 023/281] alsa: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 024/281] alp: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 025/281] amr: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 026/281] amv: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 027/281] apc: " James Almer
2022-01-26 13:41   ` Anton Khirnov
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 028/281] ape: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 029/281] apm: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 030/281] aptxdec: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 031/281] argo: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 032/281] ast: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 033/281] au: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 034/281] avr: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 035/281] bethsoftvid: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 036/281] bfi: " James Almer
2022-01-13  1:49 ` [FFmpeg-devel] [PATCH 037/281] bink: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 038/281] bit: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 039/281] bmv: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 040/281] boa: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 041/281] brstm: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 042/281] caf: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 043/281] cdxl: " James Almer
2022-01-26 13:53   ` Anton Khirnov
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 044/281] codec2: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 045/281] dash: " James Almer
2022-01-26 13:56   ` Anton Khirnov
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 046/281] dcstr: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 047/281] derf: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 048/281] dhav: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 049/281] dtshddec: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 050/281] dsicin: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 051/281] dshow: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 052/281] dss: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 053/281] dsfdec: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 054/281] dv: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 055/281] eac: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 056/281] electronicarts: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 057/281] epafdec: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 058/281] flac: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 059/281] flic: " James Almer
2022-01-27  7:46   ` Anton Khirnov
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 060/281] flv: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 061/281] framehash: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 062/281] fsb: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 063/281] fwse: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 064/281] g722: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 065/281] g723_1: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 066/281] g726: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 067/281] g729: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 068/281] gdv: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 069/281] genh: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 070/281] gsm: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 071/281] gxf: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 072/281] hca: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 073/281] hcom: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 074/281] hls_sample_encryption: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 075/281] idcin: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 076/281] idroq: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 077/281] iff: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 078/281] ifv: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 079/281] ilbc: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 080/281] imx: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 081/281] ircam: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 082/281] ipmovie: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 083/281] iss: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 084/281] jack: port " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 085/281] jvdec: convert " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 086/281] kvag: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 087/281] avdevice/lavfi: " James Almer
2022-01-13  1:50 ` [FFmpeg-devel] [PATCH 088/281] libcdio: port " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 089/281] lvf: convert " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 090/281] lxfdec: " James Almer
2022-01-27 15:19   ` Tomas Härdin
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 091/281] matroska: " James Almer
2022-01-21 19:52   ` Andreas Rheinhardt
2022-01-21 20:20     ` James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 092/281] mca: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 093/281] mm: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 094/281] mmf: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 095/281] moflex: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 096/281] mov: " James Almer
2022-01-28 10:08   ` Anton Khirnov
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 097/281] movenc-test: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 098/281] mp3: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 099/281] mpc: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 100/281] mpc8: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 101/281] mpeg: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 102/281] mpegenc: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 103/281] mpegtsenc: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 104/281] msf: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 105/281] mtaf: " James Almer
2022-01-13  1:55 ` [FFmpeg-devel] [PATCH 106/281] musx: " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 107/281] mvdec: " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 108/281] mvi: " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 109/281] mxf: " James Almer
2022-01-19 19:06   ` Tomas Härdin
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 110/281] mxg: " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 111/281] nistspheredec: " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 112/281] nspdec: " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 113/281] nsvdec: " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 114/281] nutdec: " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 115/281] nuv: " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 116/281] ogg: " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 117/281] oma: " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 118/281] oss: port " James Almer
2022-01-13  1:56 ` [FFmpeg-devel] [PATCH 119/281] paf: convert " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 089/281] lvf: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 120/281] pcm: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 121/281] pmp: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 122/281] pp_bnk: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 123/281] psxstr: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 124/281] pvf: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 125/281] qcp: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 126/281] r3d: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 127/281] rawenc: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 128/281] redspark: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 129/281] riff: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 130/281] rl2: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 131/281] rm: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 132/281] rpl: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 133/281] rsd: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 134/281] rso: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 135/281] rtp: " James Almer
2022-01-28 14:15   ` Anton Khirnov
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 136/281] sbg: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 137/281] scd: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 138/281] sdp: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 139/281] sdr2: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 140/281] sds: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 141/281] sdx: " James Almer
2022-01-13  1:57 ` [FFmpeg-devel] [PATCH 142/281] segafilm: " James Almer
2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 143/281] sga: " James Almer
2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 144/281] sierravmd: " James Almer
2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 145/281] siff: " James Almer
2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 146/281] smacker: " James Almer
2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 147/281] smjpegenc: " James Almer
2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 148/281] smoothstreaming: " James Almer
2022-01-13  1:58 ` [FFmpeg-devel] [PATCH 149/281] smush: " James Almer
2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 089/281] lvf: " James Almer
2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 150/281] sol: " James Almer
2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 151/281] sox: " James Almer
2022-01-13  1:59 ` [FFmpeg-devel] [PATCH 152/281] svag: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 153/281] svs: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 154/281] swf: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 155/281] tak: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 156/281] thp: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 157/281] tiertexseq: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 158/281] tmv: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 159/281] tta: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 160/281] uncodedframecrcenc: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 161/281] vag: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 162/281] vividas: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 163/281] vivo: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 164/281] voc: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 165/281] vpk: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 166/281] vqf: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 167/281] wav: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 168/281] wc3movie: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 169/281] westwood: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 170/281] wtv: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 171/281] wv: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 172/281] xa: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 173/281] xmv: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 174/281] xwma: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 175/281] yop: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 176/281] wsd: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 177/281] wve: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 178/281] xvag: " James Almer
2022-01-13  2:00 ` [FFmpeg-devel] [PATCH 179/281] lavf: drop the channel layout compat layer for old-style (de)muxers James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 180/281] lavc: switch to the new channel layout API James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 181/281] 8svx: convert to " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 182/281] aac: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 183/281] ac3: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 184/281] adpcm: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 185/281] adx: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 186/281] alac: " James Almer
2022-02-09  9:40   ` Anton Khirnov
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 187/281] als: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 188/281] amr: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 189/281] aptx: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 190/281] atrac1: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 191/281] atrac3: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 192/281] atrac3plus: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 193/281] atrac9: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 194/281] apedec: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 195/281] audiotoolbox: " James Almer
2022-02-21 14:22   ` Anton Khirnov
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 196/281] binkaudio: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 197/281] bmvaudio: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 198/281] cng: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 199/281] cook: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 200/281] dca: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 201/281] dolby_e: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 202/281] dpcm: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 203/281] dsd: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 204/281] dsicinav: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 205/281] dss_sp: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 206/281] dst: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 207/281] dvaudio: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 208/281] evrc: " James Almer
2022-01-13  2:02 ` [FFmpeg-devel] [PATCH 209/281] fastaudio: " James Almer
2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 210/281] ffwavesynth: " James Almer
2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 211/281] flac: " James Almer
2022-02-23 10:24   ` Anton Khirnov
2022-02-23 11:51     ` James Almer
2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 212/281] g722: " James Almer
2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 213/281] g723_1: " James Almer
2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 214/281] g726: " James Almer
2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 215/281] g729: " James Almer
2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 216/281] gsmdec: " James Almer
2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 217/281] hca: " James Almer
2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 218/281] hcom: " James Almer
2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 219/281] ilbc: " James Almer
2022-01-13  2:04 ` [FFmpeg-devel] [PATCH 220/281] imc: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 221/281] interplayacm: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 222/281] libcelt: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 223/281] libcodec2: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 224/281] libfdk-aac: " James Almer
2022-02-25 11:18   ` Anton Khirnov
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 225/281] libilbc: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 226/281] libgsm: " James Almer
2022-02-25 11:20   ` Anton Khirnov
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 227/281] libmp3lame: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 228/281] libopencore-amr: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 229/281] libopus: " James Almer
2022-02-25 11:46   ` Anton Khirnov
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 230/281] libshine: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 231/281] libspeexdec: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 232/281] libtwolame: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 233/281] libvo-amrwbenc: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 234/281] libvorbis: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 235/281] mace: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 236/281] metasound: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 237/281] mf: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 238/281] mlp: " James Almer
2022-01-13  2:05 ` [FFmpeg-devel] [PATCH 239/281] mpc7: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 240/281] mpc8: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 241/281] mpegaudio: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 242/281] nellymoser: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 243/281] on2avc: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 244/281] opus: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 245/281] pafaudio: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 246/281] pcm: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 247/281] qcelpdec: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 248/281] qdmc: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 249/281] qdm2: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 250/281] ra144: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 251/281] ra288: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 252/281] ralf: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 253/281] roqaudioenc: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 254/281] s302m: " James Almer
2022-01-13  2:06 ` [FFmpeg-devel] [PATCH 255/281] sbc: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 256/281] shorten: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 257/281] sipr: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 258/281] siren: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 259/281] smacker: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 260/281] sonic: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 261/281] speex: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 262/281] tak: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 263/281] truespeech: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 264/281] tta: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 265/281] twinvq: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 266/281] vima: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 267/281] vmdaudio: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 268/281] vorbis: " James Almer
2022-01-13  2:07 ` [FFmpeg-devel] [PATCH 269/281] wavpack: " James Almer
2022-03-07 10:42   ` Anton Khirnov
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 270/281] wma: " James Almer
2022-03-07 10:26   ` Anton Khirnov
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 271/281] ws-snd1: " James Almer
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 272/281] lavc: drop temporary compat wrappers for channel layout API change James Almer
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 273/281] lavf: Add non diegetic stream disposition flag James Almer
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 274/281] swresample: convert to new channel layout API James Almer
2022-01-19 17:20   ` Andreas Rheinhardt
2022-01-19 17:29     ` James Almer
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 275/281] avfilter: " James Almer
2022-02-14 15:49   ` Anton Khirnov
2022-02-15 11:50   ` Anton Khirnov
2022-02-15 12:27     ` James Almer
2022-02-15 12:34       ` Anton Khirnov
2022-02-15 18:52     ` James Almer
2022-02-16 18:15   ` Anton Khirnov
2022-02-18 13:07     ` James Almer
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 276/281] avdevice/lavfi: remove call to deprecated function av_buffersink_get_channel_layout() James Almer
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 277/281] ffmpeg: convert to new channel layout-API James Almer
2022-01-13 18:29   ` Michael Niedermayer
2022-01-13 18:40     ` James Almer
2022-01-13 19:44       ` James Almer
2022-01-15 13:47         ` Michael Niedermayer
2022-01-15 16:04           ` James Almer
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 278/281] ffprobe: " James Almer
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 279/281] channel_layout: add support for Ambisonic James Almer
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 280/281] opus: export mapping family 2 (Ambisonic) as Ambisonic layout James Almer
2022-01-13  2:09 ` [FFmpeg-devel] [PATCH 281/281] mov: Implement spatial audio support James Almer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git