Changeset 7760b40 for src/io


Ignore:
Timestamp:
Dec 6, 2013, 12:43:55 AM (11 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, pitchshift, sampler, timestretch, yinfft+
Children:
eadd8d5
Parents:
f3b93c6
Message:

src/io/source_avcodec.c: only read packets from selected stream, get correct out_samples from avresample_convert

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_avcodec.c

    rf3b93c6 r7760b40  
    5858  uint_t read_samples;
    5959  uint_t read_index;
     60  sint_t selected_stream;
    6061};
    6162
     
    124125    goto beach;
    125126  }
    126   //AUBIO_DBG("Taking stream %d in file %s\n", selected_stream, s->path);
     127  AUBIO_DBG("Taking stream %d in file %s\n", selected_stream, s->path);
     128  s->selected_stream = selected_stream;
    127129
    128130  AVCodecContext *avCodecCtx = s->avCodecCtx;
     
    216218  int16_t *output = s->output;
    217219
    218   int err = av_read_frame (avFormatCtx, &avPacket);
    219   if (err != 0) {
    220     //AUBIO_ERR("Could not read frame for (%s)\n", s->path);
    221     *read_samples = 0;
    222     return;
    223   }
     220  do
     221  {
     222    int err = av_read_frame (avFormatCtx, &avPacket);
     223    if (err != 0) {
     224      uint8_t errorstr_len = 128;
     225      char errorstr[errorstr_len];
     226      if (av_strerror (err, errorstr, errorstr_len) == 0) {
     227        AUBIO_ERR("Could not read frame in %s (%s)\n", s->path, errorstr);
     228      } else {
     229        AUBIO_ERR("Could not read frame in %s (unknown error)\n", s->path);
     230      }
     231      *read_samples = 0;
     232      return;
     233    }
     234  } while (avPacket.stream_index != s->selected_stream);
    224235
    225236  int got_frame = 0;
     
    244255  int out_plane_size = 0; //sizeof(float); //in_samples * sizeof(float);
    245256  int max_out_samples = AUBIO_AVCODEC_MIN_BUFFER_SIZE;
    246   if (avresample_convert ( avr,
     257  uint_t out_samples = avresample_convert ( avr,
    247258        (uint8_t **)&output, out_plane_size, max_out_samples,
    248         (uint8_t **)avFrame->data, in_plane_size, in_samples) < 0) {
     259        (uint8_t **)avFrame->data, in_plane_size, in_samples);
     260  if (out_samples < 0) {
    249261      AUBIO_ERR("Could not convert frame  (%s)\n", s->path);
     262      *read_samples = 0;
    250263  }
    251264  //AUBIO_ERR("Got in_plane_size %d frame for (%s)\n", in_plane_size, s->path);
     
    254267  //    max_out_samples, AUBIO_AVCODEC_MIN_BUFFER_SIZE);
    255268
    256   uint_t out_samples = avresample_available(avr) + (avresample_get_delay(avr)
    257         + in_samples) * s->samplerate / s->input_samplerate;
    258269  //AUBIO_WRN("Converted %d to %d samples\n", in_samples, out_samples);
    259270  //for (i = 0; i < out_samples; i ++) {
Note: See TracChangeset for help on using the changeset viewer.