Ignore:
Timestamp:
Apr 11, 2017, 1:49:44 AM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
sampler
Children:
04d0c89
Parents:
fbafd2c (diff), b762f8d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into sampler

Fixed conflicts:

python/lib/gen_external.py
src/io/source_avcodec.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_avcodec.c

    rfbafd2c rb201912  
    4343
    4444// backward compatibility with libavcodec55
     45#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,0,0)
     46#define HAVE_AUBIO_LIBAVCODEC_DEPRECATED 1
     47#endif
     48
    4549#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
    46 #warning "libavcodec55 is deprecated"
    47 #define HAVE_AUBIO_LIBAVCODEC_DEPRECATED 1
     50#warning "libavcodec < 56 is deprecated"
    4851#define av_frame_alloc  avcodec_alloc_frame
    4952#define av_frame_free avcodec_free_frame
     
    117120aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t samplerate, uint_t hop_size) {
    118121  aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t);
     122  AVFormatContext *avFormatCtx = s->avFormatCtx;
     123  AVCodecContext *avCodecCtx = s->avCodecCtx;
     124  AVFrame *avFrame = s->avFrame;
     125  AVDictionary *streamopts = 0;
     126  sint_t selected_stream = -1;
     127#if FF_API_LAVF_AVCTX
     128  AVCodecParameters *codecpar;
     129#endif
     130  AVCodec *codec;
     131  uint_t i;
    119132  int err;
    120133  if (path == NULL) {
     
    150163
    151164  // try opening the file and get some info about it
    152   AVFormatContext *avFormatCtx = s->avFormatCtx;
    153   AVDictionary *streamopts = 0;
    154165  if (s->has_network_url) {
    155166    if (av_dict_set(&streamopts, "timeout", "1000000", 0)) { // in microseconds
     
    187198
    188199  // look for the first audio stream
    189   uint_t i;
    190   sint_t selected_stream = -1;
    191200  for (i = 0; i < avFormatCtx->nb_streams; i++) {
    192201#if FF_API_LAVF_AVCTX
     
    210219  s->selected_stream = selected_stream;
    211220
    212   AVCodecContext *avCodecCtx = s->avCodecCtx;
    213221#if FF_API_LAVF_AVCTX
    214   AVCodecParameters *codecpar = avFormatCtx->streams[selected_stream]->codecpar;
     222  codecpar = avFormatCtx->streams[selected_stream]->codecpar;
    215223  if (codecpar == NULL) {
    216224    AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path);
    217225    goto beach;
    218226  }
    219   AVCodec *codec = avcodec_find_decoder(codecpar->codec_id);
     227  codec = avcodec_find_decoder(codecpar->codec_id);
    220228
    221229  /* Allocate a codec context for the decoder */
     
    228236#else
    229237  avCodecCtx = avFormatCtx->streams[selected_stream]->codec;
    230   AVCodec *codec = avcodec_find_decoder(avCodecCtx->codec_id);
     238  codec = avcodec_find_decoder(avCodecCtx->codec_id);
    231239#endif
    232240  if (codec == NULL) {
     
    272280  }
    273281
    274   AVFrame *avFrame = s->avFrame;
    275282  avFrame = av_frame_alloc();
    276283  if (!avFrame) {
     
    313320  // create or reset resampler to/from mono/multi-channel
    314321  if ( (multi != s->multi) || (s->avr == NULL) ) {
     322    int err;
    315323    int64_t input_layout = av_get_default_channel_layout(s->input_channels);
    316324    uint_t output_channels = multi ? s->input_channels : 1;
     
    336344    // TODO: use planar?
    337345    //av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_FLTP,      0);
    338     int err;
    339346#ifdef HAVE_AVRESAMPLE
    340347    if ( ( err = avresample_open(avr) ) < 0) {
     
    368375  AVFrame *avFrame = s->avFrame;
    369376  AVPacket avPacket = s->avPacket;
    370   av_init_packet (&avPacket);
    371377#ifdef HAVE_AVRESAMPLE
    372378  AVAudioResampleContext *avr = s->avr;
     
    374380  SwrContext *avr = s->avr;
    375381#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
     382  int got_frame = 0;
     383  int ret = 0;
     384#ifdef HAVE_AVRESAMPLE
     385  int in_linesize = 0;
     386  int in_samples = avFrame->nb_samples;
     387  int out_linesize = 0;
     388  int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
     389  int out_samples = 0;
     390#elif defined(HAVE_SWRESAMPLE)
     391  int in_samples = avFrame->nb_samples;
     392  int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
     393  int out_samples = 0;
     394#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    376395  smpl_t *output = s->output;
     396#ifndef FF_API_LAVF_AVCTX
     397  int len = 0;
     398#endif
     399  av_init_packet (&avPacket);
    377400  *read_samples = 0;
    378401
     
    393416  } while (avPacket.stream_index != s->selected_stream);
    394417
    395   int got_frame = 0;
    396418#if FF_API_LAVF_AVCTX
    397   int ret = avcodec_send_packet(avCodecCtx, &avPacket);
     419  ret = avcodec_send_packet(avCodecCtx, &avPacket);
    398420  if (ret < 0 && ret != AVERROR_EOF) {
    399421    AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path);
     
    416438  }
    417439#else
    418   int len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket);
     440  len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket);
    419441
    420442  if (len < 0) {
     
    429451
    430452#ifdef HAVE_AVRESAMPLE
    431   int in_linesize = 0;
     453  in_linesize = 0;
    432454  av_samples_get_buffer_size(&in_linesize, avCodecCtx->channels,
    433455      avFrame->nb_samples, avCodecCtx->sample_fmt, 1);
    434   int in_samples = avFrame->nb_samples;
    435   int out_linesize = 0;
    436   int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
    437   int out_samples = avresample_convert ( avr,
     456  in_samples = avFrame->nb_samples;
     457  out_linesize = 0;
     458  max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
     459  out_samples = avresample_convert ( avr,
    438460        (uint8_t **)&output, out_linesize, max_out_samples,
    439461        (uint8_t **)avFrame->data, in_linesize, in_samples);
    440462#elif defined(HAVE_SWRESAMPLE)
    441   int in_samples = avFrame->nb_samples;
    442   int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
    443   int out_samples = swr_convert( avr,
     463  in_samples = avFrame->nb_samples;
     464  max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
     465  out_samples = swr_convert( avr,
    444466      (uint8_t **)&output, max_out_samples,
    445467      (const uint8_t **)avFrame->data, in_samples);
     
    606628  if (s->avFormatCtx != NULL) {
    607629    avformat_close_input(&s->avFormatCtx);
    608 #ifndef HAVE_AUBIO_LIBAVCODEC_DEPRECATED // avoid crash on old libavcodec54
    609     avformat_free_context(s->avFormatCtx);
    610 #endif
    611630    s->avFormatCtx = NULL;
    612631  }
Note: See TracChangeset for help on using the changeset viewer.