Changeset 245deea


Ignore:
Timestamp:
Dec 27, 2023, 6:09:23 PM (11 months ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
master
Children:
885e316
Parents:
df2de24
Message:

[source_avcodec] drop support for libavresample

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_avcodec.c

    rdf2de24 r245deea  
    2525#include <libavcodec/avcodec.h>
    2626#include <libavformat/avformat.h>
    27 #if defined(HAVE_SWRESAMPLE)
    2827#include <libswresample/swresample.h>
    29 #elif defined(HAVE_AVRESAMPLE)
    30 #include <libavresample/avresample.h>
    31 #endif
    3228#include <libavutil/opt.h>
    3329
     
    9288  AVPacket avPacket;
    9389#endif
    94 #ifdef HAVE_AVRESAMPLE
    95   AVAudioResampleContext *avr;
    96 #elif defined(HAVE_SWRESAMPLE)
    9790  SwrContext *avr;
    98 #endif
    9991  smpl_t *output;
    10092  uint_t read_samples;
     
    337329  if ( s->avr == NULL ) {
    338330    int err;
     331    SwrContext *avr = swr_alloc();
    339332    int64_t input_layout = av_get_default_channel_layout(s->input_channels);
    340333    int64_t output_layout = av_get_default_channel_layout(s->input_channels);
    341 #ifdef HAVE_AVRESAMPLE
    342     AVAudioResampleContext *avr = avresample_alloc_context();
    343 #elif defined(HAVE_SWRESAMPLE)
    344     SwrContext *avr = swr_alloc();
    345 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    346334
    347335    av_opt_set_int(avr, "in_channel_layout",  input_layout,              0);
     
    357345    // TODO: use planar?
    358346    //av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_FLTP,      0);
    359 #ifdef HAVE_AVRESAMPLE
    360     if ( ( err = avresample_open(avr) ) < 0)
    361 #elif defined(HAVE_SWRESAMPLE)
    362347    if ( ( err = swr_init(avr) ) < 0)
    363 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    364348    {
    365349      char errorstr[256];
     
    384368  AVPacket *avPacket = &s->avPacket;
    385369#endif
    386 #ifdef HAVE_AVRESAMPLE
    387   AVAudioResampleContext *avr = s->avr;
    388 #elif defined(HAVE_SWRESAMPLE)
    389370  SwrContext *avr = s->avr;
    390 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    391371  int got_frame = 0;
    392 #ifdef HAVE_AVRESAMPLE
    393   int in_linesize = 0;
    394   int in_samples = avFrame->nb_samples;
    395   int out_linesize = 0;
    396   int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
    397   int out_samples = 0;
    398 #elif defined(HAVE_SWRESAMPLE)
    399372  int in_samples = avFrame->nb_samples;
    400373  int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
    401374  int out_samples = 0;
    402 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    403375  smpl_t *output = s->output;
    404376#ifndef FF_API_LAVF_AVCTX
     
    477449#endif
    478450
    479 #ifdef HAVE_AVRESAMPLE
    480   in_linesize = 0;
    481   av_samples_get_buffer_size(&in_linesize, avCodecCtx->channels,
    482       avFrame->nb_samples, avCodecCtx->sample_fmt, 1);
    483   in_samples = avFrame->nb_samples;
    484   out_linesize = 0;
    485   max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
    486   out_samples = avresample_convert ( avr,
    487         (uint8_t **)&output, out_linesize, max_out_samples,
    488         (uint8_t **)avFrame->data, in_linesize, in_samples);
    489 #elif defined(HAVE_SWRESAMPLE)
    490451  in_samples = avFrame->nb_samples;
    491452  max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
     
    493454      (uint8_t **)&output, max_out_samples,
    494455      (const uint8_t **)avFrame->data, in_samples);
    495 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    496456  if (out_samples < 0) {
    497457    AUBIO_WRN("source_avcodec: error while resampling %s (%d)\n",
     
    627587  s->read_index = 0;
    628588  s->read_samples = 0;
    629 #ifdef HAVE_AVRESAMPLE
    630   // reset the AVAudioResampleContext
    631   avresample_close(s->avr);
    632   avresample_open(s->avr);
    633 #elif defined(HAVE_SWRESAMPLE)
    634589  swr_close(s->avr);
    635590  swr_init(s->avr);
    636 #endif
    637591  return ret;
    638592}
     
    648602uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
    649603  if (s->avr != NULL) {
    650 #ifdef HAVE_AVRESAMPLE
    651     avresample_close( s->avr );
    652     av_free ( s->avr );
    653 #elif defined(HAVE_SWRESAMPLE)
    654604    swr_close ( s->avr );
    655605    swr_free ( &s->avr );
    656 #endif
    657606  }
    658607  s->avr = NULL;
Note: See TracChangeset for help on using the changeset viewer.