Changeset 2b3c438


Ignore:
Timestamp:
Nov 30, 2016, 5:11:11 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, sampler, yinfft+
Children:
e0ad269
Parents:
877b3b8
Message:

src/io/source_avcodec.c: avoid deprecation warnings with ffmpeg 3.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_avcodec.c

    r877b3b8 r2b3c438  
    151151  sint_t selected_stream = -1;
    152152  for (i = 0; i < avFormatCtx->nb_streams; i++) {
     153#if FF_API_LAVF_AVCTX
     154    if (avFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
     155#else
    153156    if (avFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
     157#endif
    154158      if (selected_stream == -1) {
    155159        selected_stream = i;
     
    168172
    169173  AVCodecContext *avCodecCtx = s->avCodecCtx;
     174#if FF_API_LAVF_AVCTX
     175  AVCodecParameters *codecpar = avFormatCtx->streams[selected_stream]->codecpar;
     176  if (codecpar == NULL) {
     177    AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path);
     178    goto beach;
     179  }
     180  AVCodec *codec = avcodec_find_decoder(codecpar->codec_id);
     181
     182  /* Allocate a codec context for the decoder */
     183  avCodecCtx = avcodec_alloc_context3(codec);
     184  if (!avCodecCtx) {
     185    AUBIO_ERR("source_avcodec: Failed to allocate the %s codec context for path %s\n",
     186        av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path);
     187    goto beach;
     188  }
     189#else
    170190  avCodecCtx = avFormatCtx->streams[selected_stream]->codec;
    171191  AVCodec *codec = avcodec_find_decoder(avCodecCtx->codec_id);
     192#endif
    172193  if (codec == NULL) {
    173194    AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path);
    174195    goto beach;
    175196  }
     197
     198#if FF_API_LAVF_AVCTX
     199  /* Copy codec parameters from input stream to output codec context */
     200  if ((err = avcodec_parameters_to_context(avCodecCtx, codecpar)) < 0) {
     201    AUBIO_ERR("source_avcodec: Failed to copy %s codec parameters to decoder context for %s\n",
     202       av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path);
     203    goto beach;
     204  }
     205#endif
    176206
    177207  if ( ( err = avcodec_open2(avCodecCtx, codec, NULL) ) < 0) {
     
    298328
    299329  int got_frame = 0;
     330#if FF_API_LAVF_AVCTX
     331  int ret = avcodec_send_packet(avCodecCtx, &avPacket);
     332  if (ret < 0 && ret != AVERROR_EOF) {
     333    AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path);
     334    goto beach;
     335  }
     336  ret = avcodec_receive_frame(avCodecCtx, avFrame);
     337  if (ret >= 0) {
     338    got_frame = 1;
     339  }
     340  if (ret < 0) {
     341    if (ret == AVERROR(EAGAIN)) {
     342      AUBIO_WRN("source_avcodec: output is not available right now - user must try to send new input\n");
     343    } else if (ret == AVERROR_EOF) {
     344      AUBIO_WRN("source_avcodec: the decoder has been fully flushed, and there will be no more output frames\n");
     345    } else {
     346      AUBIO_ERR("source_avcodec: decoding errors on %s\n", s->path);
     347      goto beach;
     348    }
     349  }
     350#else
    300351  int len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket);
    301352
     
    304355    goto beach;
    305356  }
     357#endif
    306358  if (got_frame == 0) {
    307359    //AUBIO_ERR("Could not get frame for (%s)\n", s->path);
Note: See TracChangeset for help on using the changeset viewer.