Ignore:
Timestamp:
Dec 26, 2021, 7:52:16 AM (3 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, fix/ffmpeg5, master
Children:
d8e78e6
Parents:
ea7f48e
Message:

[source_avcodec] avoid deprecation warning with latest avcodec api (58.134.100)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_avcodec.c

    rea7f48e rcdfe9ce  
    8383  AVCodecContext *avCodecCtx;
    8484  AVFrame *avFrame;
     85#if FF_API_INIT_PACKET
     86  AVPacket *avPacket;
     87#else
    8588  AVPacket avPacket;
     89#endif
    8690#ifdef HAVE_AVRESAMPLE
    8791  AVAudioResampleContext *avr;
     
    123127  AVCodecContext *avCodecCtx = NULL;
    124128  AVFrame *avFrame = NULL;
     129#if FF_API_INIT_PACKET
     130  AVPacket *avPacket = NULL;
     131#endif
    125132  sint_t selected_stream = -1;
    126133#if FF_API_LAVF_AVCTX
    127134  AVCodecParameters *codecpar;
    128135#endif
     136
    129137  AVCodec *codec;
    130138  uint_t i;
     
    278286  if (!avFrame) {
    279287    AUBIO_ERR("source_avcodec: Could not allocate frame for (%s)\n", s->path);
    280   }
     288    goto beach;
     289  }
     290
     291#if FF_API_INIT_PACKET
     292  avPacket = av_packet_alloc();
     293  if (!avPacket) {
     294    AUBIO_ERR("source_avcodec: Could not allocate packet for (%s)\n", s->path);
     295    goto beach;
     296  }
     297#endif
    281298
    282299  /* allocate output for avr */
     
    290307  s->avCodecCtx = avCodecCtx;
    291308  s->avFrame = avFrame;
     309#if FF_API_INIT_PACKET
     310  s->avPacket = avPacket;
     311#endif
    292312
    293313  aubio_source_avcodec_reset_resampler(s);
     
    355375  AVCodecContext *avCodecCtx = s->avCodecCtx;
    356376  AVFrame *avFrame = s->avFrame;
    357   AVPacket avPacket = s->avPacket;
     377#if FF_API_INIT_PACKET
     378  AVPacket *avPacket = s->avPacket;
     379#else
     380  AVPacket *avPacket = &s->avPacket;
     381#endif
    358382#ifdef HAVE_AVRESAMPLE
    359383  AVAudioResampleContext *avr = s->avr;
     
    379403  int ret = 0;
    380404#endif
    381   av_init_packet (&avPacket);
     405#ifndef FF_API_INIT_PACKET
     406  av_init_packet (avPacket);
     407#endif
    382408  *read_samples = 0;
    383409
    384410  do
    385411  {
    386     int err = av_read_frame (avFormatCtx, &avPacket);
     412    int err = av_read_frame (avFormatCtx, avPacket);
    387413    if (err == AVERROR_EOF) {
    388414      s->eof = 1;
     
    397423      goto beach;
    398424    }
    399   } while (avPacket.stream_index != s->selected_stream);
     425  } while (avPacket->stream_index != s->selected_stream);
    400426
    401427#if FF_API_LAVF_AVCTX
    402   ret = avcodec_send_packet(avCodecCtx, &avPacket);
     428  ret = avcodec_send_packet(avCodecCtx, avPacket);
    403429  if (ret < 0 && ret != AVERROR_EOF) {
    404430    AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path);
     
    423449  }
    424450#else
    425   len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket);
     451  len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, avPacket);
    426452
    427453  if (len < 0) {
     
    473499
    474500beach:
    475   av_packet_unref(&avPacket);
     501  av_packet_unref(avPacket);
    476502}
    477503
     
    639665    s->avFormatCtx = NULL;
    640666  }
     667#if FF_API_INIT_PACKET
     668  if (s->avPacket) {
     669    av_packet_unref(s->avPacket);
     670  }
     671#else
    641672  av_packet_unref(&s->avPacket);
     673#endif
    642674  return AUBIO_OK;
    643675}
     
    654686  }
    655687  s->avFrame = NULL;
     688#if FF_API_INIT_PACKET
     689  if (s->avPacket != NULL) {
     690    av_packet_free( &(s->avPacket) );
     691  }
     692  s->avPacket = NULL;
     693#endif
    656694  if (s->path) {
    657695    AUBIO_FREE(s->path);
Note: See TracChangeset for help on using the changeset viewer.