Ignore:
Timestamp:
Apr 1, 2019, 1:30:06 AM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
7a02ce9
Parents:
5f57ea9 (diff), f55630c (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 feature/pitchshift

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_avcodec.c

    r5f57ea9 r439ba7b  
    3131#endif
    3232#include <libavutil/opt.h>
    33 #include <stdlib.h>
    3433
    3534// determine whether we use libavformat from ffmpeg or from libav
     
    6160#include "fvec.h"
    6261#include "fmat.h"
     62#include "ioutils.h"
    6363#include "source_avcodec.h"
    6464
     
    120120    uint_t samplerate, uint_t hop_size) {
    121121  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;
     122  AVFormatContext *avFormatCtx = NULL;
     123  AVCodecContext *avCodecCtx = NULL;
     124  AVFrame *avFrame = NULL;
    125125  sint_t selected_stream = -1;
    126126#if FF_API_LAVF_AVCTX
     
    464464      (const uint8_t **)avFrame->data, in_samples);
    465465#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    466   if (out_samples <= 0) {
    467     AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n",
    468         s->path);
     466  if (out_samples < 0) {
     467    AUBIO_WRN("source_avcodec: error while resampling %s (%d)\n",
     468        s->path, out_samples);
    469469    goto beach;
    470470  }
     
    473473
    474474beach:
    475   s->avFormatCtx = avFormatCtx;
    476   s->avCodecCtx = avCodecCtx;
    477   s->avFrame = avFrame;
    478 #if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
    479   s->avr = avr;
    480 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    481   s->output = output;
    482 
    483475  av_packet_unref(&avPacket);
    484476}
     
    489481  uint_t end = 0;
    490482  uint_t total_wrote = 0;
    491   while (total_wrote < s->hop_size) {
    492     end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     483  uint_t length = aubio_source_validate_input_length("source_avcodec", s->path,
     484      s->hop_size, read_data->length);
     485  if (!s->avr || !s->avFormatCtx || !s->avCodecCtx) {
     486    AUBIO_ERR("source_avcodec: could not read from %s (file was closed)\n",
     487        s->path);
     488    *read= 0;
     489    return;
     490  }
     491  while (total_wrote < length) {
     492    end = MIN(s->read_samples - s->read_index, length - total_wrote);
    493493    for (i = 0; i < end; i++) {
    494494      read_data->data[i + total_wrote] = 0.;
     
    500500    }
    501501    total_wrote += end;
    502     if (total_wrote < s->hop_size) {
     502    if (total_wrote < length) {
    503503      uint_t avcodec_read = 0;
    504504      aubio_source_avcodec_readframe(s, &avcodec_read);
     
    512512    }
    513513  }
    514   if (total_wrote < s->hop_size) {
    515     for (i = total_wrote; i < s->hop_size; i++) {
    516       read_data->data[i] = 0.;
    517     }
    518   }
     514
     515  aubio_source_pad_output(read_data, total_wrote);
     516
    519517  *read = total_wrote;
    520518}
     
    525523  uint_t end = 0;
    526524  uint_t total_wrote = 0;
    527   while (total_wrote < s->hop_size) {
    528     end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    529     for (j = 0; j < read_data->height; j++) {
     525  uint_t length = aubio_source_validate_input_length("source_avcodec", s->path,
     526      s->hop_size, read_data->length);
     527  uint_t channels = aubio_source_validate_input_channels("source_avcodec",
     528      s->path, s->input_channels, read_data->height);
     529  if (!s->avr || !s->avFormatCtx || !s->avCodecCtx) {
     530    AUBIO_ERR("source_avcodec: could not read from %s (file was closed)\n",
     531        s->path);
     532    *read= 0;
     533    return;
     534  }
     535  while (total_wrote < length) {
     536    end = MIN(s->read_samples - s->read_index, length - total_wrote);
     537    for (j = 0; j < channels; j++) {
    530538      for (i = 0; i < end; i++) {
    531539        read_data->data[j][i + total_wrote] =
     
    534542    }
    535543    total_wrote += end;
    536     if (total_wrote < s->hop_size) {
     544    if (total_wrote < length) {
    537545      uint_t avcodec_read = 0;
    538546      aubio_source_avcodec_readframe(s, &avcodec_read);
     
    546554    }
    547555  }
    548   if (total_wrote < s->hop_size) {
    549     for (j = 0; j < read_data->height; j++) {
    550       for (i = total_wrote; i < s->hop_size; i++) {
    551         read_data->data[j][i] = 0.;
    552       }
    553     }
    554   }
     556
     557  aubio_source_pad_multi_output(read_data, s->input_channels, total_wrote);
     558
    555559  *read = total_wrote;
    556560}
     
    616620#ifdef HAVE_AVRESAMPLE
    617621    avresample_close( s->avr );
     622    av_free ( s->avr );
    618623#elif defined(HAVE_SWRESAMPLE)
    619624    swr_close ( s->avr );
    620 #endif
    621     av_free ( s->avr );
     625    swr_free ( &s->avr );
     626#endif
    622627  }
    623628  s->avr = NULL;
Note: See TracChangeset for help on using the changeset viewer.