Ignore:
Timestamp:
Dec 27, 2023, 6:39:35 PM (11 months ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
master
Children:
53bc55c
Parents:
128acfd
Message:

[source_avcodec] add support for AVChannelLayout (ffmpeg 5.1)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_avcodec.c

    r128acfd r0b947f9  
    264264  /* get input specs */
    265265  s->input_samplerate = avCodecCtx->sample_rate;
     266#ifdef AVUTIL_CHANNEL_LAYOUT_H
     267  s->input_channels   = avCodecCtx->ch_layout.nb_channels;
     268#else
    266269  s->input_channels   = avCodecCtx->channels;
     270#endif
    267271  //AUBIO_DBG("input_samplerate: %d\n", s->input_samplerate);
    268272  //AUBIO_DBG("input_channels: %d\n", s->input_channels);
     
    330334    int err;
    331335    SwrContext *avr = swr_alloc();
     336#ifdef AVUTIL_CHANNEL_LAYOUT_H
     337    AVChannelLayout input_layout;
     338    AVChannelLayout output_layout;
     339    av_channel_layout_default(&input_layout, s->input_channels);
     340    av_channel_layout_default(&output_layout, s->input_channels);
     341
     342    av_opt_set_chlayout(avr, "in_channel_layout",  &input_layout,        0);
     343    av_opt_set_chlayout(avr, "out_channel_layout", &output_layout,       0);
     344#else
    332345    int64_t input_layout = av_get_default_channel_layout(s->input_channels);
    333346    int64_t output_layout = av_get_default_channel_layout(s->input_channels);
     
    335348    av_opt_set_int(avr, "in_channel_layout",  input_layout,              0);
    336349    av_opt_set_int(avr, "out_channel_layout", output_layout,             0);
     350#endif
    337351    av_opt_set_int(avr, "in_sample_rate",     s->input_samplerate,       0);
    338352    av_opt_set_int(avr, "out_sample_rate",    s->samplerate,             0);
     
    371385  int got_frame = 0;
    372386  int in_samples = avFrame->nb_samples;
     387#ifdef AVUTIL_CHANNEL_LAYOUT_H
     388  int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->ch_layout.nb_channels;
     389#else
    373390  int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
     391#endif
    374392  int out_samples = 0;
    375393  smpl_t *output = s->output;
     
    439457
    440458#if LIBAVUTIL_VERSION_MAJOR > 52
    441   if (avFrame->channels != (sint_t)s->input_channels) {
     459#ifdef AVUTIL_CHANNEL_LAYOUT_H
     460  int frame_channels = avFrame->ch_layout.nb_channels;
     461#else
     462  int frame_channels = avFrame->channels;
     463#endif
     464  if (frame_channels != (sint_t)s->input_channels) {
    442465    AUBIO_WRN ("source_avcodec: trying to read from %d channel(s),"
    443466        "but configured for %d; is '%s' corrupt?\n",
    444         avFrame->channels, s->input_channels, s->path);
     467        frame_channels, s->input_channels, s->path);
    445468    goto beach;
    446469  }
     
    450473
    451474  in_samples = avFrame->nb_samples;
    452   max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
     475  max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
     476  if (frame_channels > 0) max_out_samples /= frame_channels;
    453477  out_samples = swr_convert( avr,
    454478      (uint8_t **)&output, max_out_samples,
Note: See TracChangeset for help on using the changeset viewer.