Changeset de9178e
- Timestamp:
- Oct 26, 2018, 5:47:27 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
- Children:
- cc3f129
- Parents:
- fb1c5e2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_avcodec.c
rfb1c5e2 rde9178e 35 35 // determine whether we use libavformat from ffmpeg or from libav 36 36 #define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99 ) 37 // max_analyze_duration2 was used from ffmpeg libavformat 55.43.100 through57.2.10037 // max_analyze_duration2 was used from ffmpeg libavformat 55.43.100 -> 57.2.100 38 38 #define FFMPEG_LIBAVFORMAT_MAX_DUR2 FFMPEG_LIBAVFORMAT && ( \ 39 39 (LIBAVFORMAT_VERSION_MAJOR == 55 && LIBAVFORMAT_VERSION_MINOR >= 43) \ … … 93 93 }; 94 94 95 // hack to create or re-create the context the first time _do or _do_multi is called 96 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, uint_t multi); 97 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples); 95 // create or re-create the context when _do or _do_multi is called 96 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, 97 uint_t multi); 98 // actually read a frame 99 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, 100 uint_t * read_samples); 98 101 99 102 uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s); … … 112 115 113 116 114 aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t samplerate, uint_t hop_size) { 117 aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, 118 uint_t samplerate, uint_t hop_size) { 115 119 aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t); 116 120 AVFormatContext *avFormatCtx = s->avFormatCtx; … … 129 133 } 130 134 if ((sint_t)samplerate < 0) { 131 AUBIO_ERR("source_avcodec: Can not open %s with samplerate %d\n", path, samplerate); 135 AUBIO_ERR("source_avcodec: Can not open %s with samplerate %d\n", 136 path, samplerate); 132 137 goto beach; 133 138 } 134 139 if ((sint_t)hop_size <= 0) { 135 AUBIO_ERR("source_avcodec: Can not open %s with hop_size %d\n", path, hop_size); 140 AUBIO_ERR("source_avcodec: Can not open %s with hop_size %d\n", 141 path, hop_size); 136 142 goto beach; 137 143 } … … 173 179 char errorstr[256]; 174 180 av_strerror (err, errorstr, sizeof(errorstr)); 175 AUBIO_ERR("source_avcodec: Could not find stream information " "for %s (%s)\n", s->path,176 errorstr);181 AUBIO_ERR("source_avcodec: Could not find stream information " 182 "for %s (%s)\n", s->path, errorstr); 177 183 goto beach; 178 184 } … … 214 220 avCodecCtx = avcodec_alloc_context3(codec); 215 221 if (!avCodecCtx) { 216 AUBIO_ERR("source_avcodec: Failed to allocate the %s codec context for path %s\n", 217 av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path); 222 AUBIO_ERR("source_avcodec: Failed to allocate the %s codec context " 223 "for path %s\n", av_get_media_type_string(AVMEDIA_TYPE_AUDIO), 224 s->path); 218 225 goto beach; 219 226 } … … 230 237 /* Copy codec parameters from input stream to output codec context */ 231 238 if ((err = avcodec_parameters_to_context(avCodecCtx, codecpar)) < 0) { 232 AUBIO_ERR("source_avcodec: Failed to copy %s codec parameters to decoder context for %s\n", 233 av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path); 239 AUBIO_ERR("source_avcodec: Failed to copy %s codec parameters to " 240 "decoder context for %s\n", 241 av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path); 234 242 goto beach; 235 243 } … … 239 247 char errorstr[256]; 240 248 av_strerror (err, errorstr, sizeof(errorstr)); 241 AUBIO_ERR("source_avcodec: Could not load codec for %s (%s)\n", s->path, errorstr); 249 AUBIO_ERR("source_avcodec: Could not load codec for %s (%s)\n", s->path, 250 errorstr); 242 251 goto beach; 243 252 } … … 266 275 267 276 /* allocate output for avr */ 268 s->output = (smpl_t *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE * sizeof(smpl_t)); 277 s->output = (smpl_t *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE 278 * sizeof(smpl_t)); 269 279 270 280 s->read_samples = 0; … … 294 304 } 295 305 296 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, uint_t multi) { 306 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, 307 uint_t multi) 308 { 297 309 // create or reset resampler to/from mono/multi-channel 298 310 if ( (multi != s->multi) || (s->avr == NULL) ) { … … 309 321 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 310 322 311 av_opt_set_int(avr, "in_channel_layout", input_layout, 0);312 av_opt_set_int(avr, "out_channel_layout", output_layout, 0);313 av_opt_set_int(avr, "in_sample_rate", s->input_samplerate, 0);314 av_opt_set_int(avr, "out_sample_rate", s->samplerate, 0);323 av_opt_set_int(avr, "in_channel_layout", input_layout, 0); 324 av_opt_set_int(avr, "out_channel_layout", output_layout, 0); 325 av_opt_set_int(avr, "in_sample_rate", s->input_samplerate, 0); 326 av_opt_set_int(avr, "out_sample_rate", s->samplerate, 0); 315 327 av_opt_set_int(avr, "in_sample_fmt", s->avCodecCtx->sample_fmt, 0); 316 328 #if HAVE_AUBIO_DOUBLE 317 av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_DBL, 0);318 #else 319 av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0);329 av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_DBL, 0); 330 #else 331 av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0); 320 332 #endif 321 333 // TODO: use planar? … … 329 341 char errorstr[256]; 330 342 av_strerror (err, errorstr, sizeof(errorstr)); 331 AUBIO_ERR("source_avcodec: Could not open resampling context for %s (%s)\n",332 s->path, errorstr);343 AUBIO_ERR("source_avcodec: Could not open resampling context" 344 " for %s (%s)\n", s->path, errorstr); 333 345 return; 334 346 } … … 347 359 } 348 360 349 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples) { 361 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, 362 uint_t * read_samples) 363 { 350 364 AVFormatContext *avFormatCtx = s->avFormatCtx; 351 365 AVCodecContext *avCodecCtx = s->avCodecCtx; … … 388 402 char errorstr[256]; 389 403 av_strerror (err, errorstr, sizeof(errorstr)); 390 AUBIO_ERR("source_avcodec: could not read frame in %s (%s)\n", s->path, errorstr); 404 AUBIO_ERR("source_avcodec: could not read frame in %s (%s)\n", 405 s->path, errorstr); 391 406 s->eof = 1; 392 407 goto beach; … … 406 421 if (ret < 0) { 407 422 if (ret == AVERROR(EAGAIN)) { 408 //AUBIO_WRN("source_avcodec: output is not available right now - user must try to send new input\n"); 423 //AUBIO_WRN("source_avcodec: output is not available right now - " 424 // "user must try to send new input\n"); 409 425 goto beach; 410 426 } else if (ret == AVERROR_EOF) { 411 AUBIO_WRN("source_avcodec: the decoder has been fully flushed, and there will be no more output frames\n"); 427 AUBIO_WRN("source_avcodec: the decoder has been fully flushed, " 428 "and there will be no more output frames\n"); 412 429 } else { 413 430 AUBIO_ERR("source_avcodec: decoding errors on %s\n", s->path); … … 424 441 #endif 425 442 if (got_frame == 0) { 426 AUBIO_WRN("source_avcodec: did not get a frame when reading %s\n", s->path); 443 AUBIO_WRN("source_avcodec: did not get a frame when reading %s\n", 444 s->path); 427 445 goto beach; 428 446 } … … 431 449 if (avFrame->channels != (sint_t)s->input_channels) { 432 450 AUBIO_WRN ("source_avcodec: trying to read from %d channel(s)," 433 "but configured for %d; is '%s' corrupt?\n", avFrame->channels,434 s->input_channels, s->path);451 "but configured for %d; is '%s' corrupt?\n", 452 avFrame->channels, s->input_channels, s->path); 435 453 goto beach; 436 454 } … … 455 473 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */ 456 474 if (out_samples <= 0) { 457 AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n", s->path); 475 AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n", 476 s->path); 458 477 goto beach; 459 478 } … … 473 492 } 474 493 475 void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, uint_t * read){ 494 void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, 495 uint_t * read) { 476 496 uint_t i; 477 497 uint_t end = 0; … … 505 525 } 506 526 507 void aubio_source_avcodec_do_multi(aubio_source_avcodec_t * s, fmat_t * read_data, uint_t * read){ 527 void aubio_source_avcodec_do_multi(aubio_source_avcodec_t * s, 528 fmat_t * read_data, uint_t * read) { 508 529 uint_t i,j; 509 530 uint_t end = 0; … … 551 572 552 573 uint_t aubio_source_avcodec_seek (aubio_source_avcodec_t * s, uint_t pos) { 553 int64_t resampled_pos = (uint_t)ROUND(pos * (s->input_samplerate * 1. / s->samplerate)); 574 int64_t resampled_pos = 575 (uint_t)ROUND(pos * (s->input_samplerate * 1. / s->samplerate)); 554 576 int64_t min_ts = MAX(resampled_pos - 2000, 0); 555 577 int64_t max_ts = MIN(resampled_pos + 2000, INT64_MAX); … … 559 581 ret = AUBIO_OK; 560 582 } else { 561 AUBIO_ERR("source_avcodec: failed seeking in %s (file not opened?)", s->path); 583 AUBIO_ERR("source_avcodec: failed seeking in %s (file not opened?)", 584 s->path); 562 585 return ret; 563 586 } … … 570 593 min_ts, resampled_pos, max_ts, seek_flags); 571 594 if (ret < 0) { 572 AUBIO_ERR("source_avcodec: failed seeking to %d in file %s", pos, s->path); 595 AUBIO_ERR("source_avcodec: failed seeking to %d in file %s", 596 pos, s->path); 573 597 } 574 598 // reset read status
Note: See TracChangeset
for help on using the changeset viewer.