Changeset 7a02ce9 for src/io/source_avcodec.c
- Timestamp:
- Apr 1, 2019, 1:30:22 AM (5 years ago)
- Branches:
- feature/cnn, feature/crepe, feature/timestretch, fix/ffmpeg5, master
- Children:
- 65f7886
- Parents:
- 1301f66 (diff), 439ba7b (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_avcodec.c
r1301f66 r7a02ce9 31 31 #endif 32 32 #include <libavutil/opt.h> 33 #include <stdlib.h>34 33 35 34 // determine whether we use libavformat from ffmpeg or from libav … … 61 60 #include "fvec.h" 62 61 #include "fmat.h" 62 #include "ioutils.h" 63 63 #include "source_avcodec.h" 64 64 … … 120 120 uint_t samplerate, uint_t hop_size) { 121 121 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; 125 125 sint_t selected_stream = -1; 126 126 #if FF_API_LAVF_AVCTX … … 464 464 (const uint8_t **)avFrame->data, in_samples); 465 465 #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); 469 469 goto beach; 470 470 } … … 473 473 474 474 beach: 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 483 475 av_packet_unref(&avPacket); 484 476 } … … 489 481 uint_t end = 0; 490 482 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); 493 493 for (i = 0; i < end; i++) { 494 494 read_data->data[i + total_wrote] = 0.; … … 500 500 } 501 501 total_wrote += end; 502 if (total_wrote < s->hop_size) {502 if (total_wrote < length) { 503 503 uint_t avcodec_read = 0; 504 504 aubio_source_avcodec_readframe(s, &avcodec_read); … … 512 512 } 513 513 } 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 519 517 *read = total_wrote; 520 518 } … … 525 523 uint_t end = 0; 526 524 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++) { 530 538 for (i = 0; i < end; i++) { 531 539 read_data->data[j][i + total_wrote] = … … 534 542 } 535 543 total_wrote += end; 536 if (total_wrote < s->hop_size) {544 if (total_wrote < length) { 537 545 uint_t avcodec_read = 0; 538 546 aubio_source_avcodec_readframe(s, &avcodec_read); … … 546 554 } 547 555 } 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 555 559 *read = total_wrote; 556 560 } … … 616 620 #ifdef HAVE_AVRESAMPLE 617 621 avresample_close( s->avr ); 622 av_free ( s->avr ); 618 623 #elif defined(HAVE_SWRESAMPLE) 619 624 swr_close ( s->avr ); 620 #endif 621 av_free ( s->avr ); 625 swr_free ( &s->avr ); 626 #endif 622 627 } 623 628 s->avr = NULL;
Note: See TracChangeset
for help on using the changeset viewer.