Changeset 245deea
- Timestamp:
- Dec 27, 2023, 6:09:23 PM (12 months ago)
- Branches:
- master
- Children:
- 885e316
- Parents:
- df2de24
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_avcodec.c
rdf2de24 r245deea 25 25 #include <libavcodec/avcodec.h> 26 26 #include <libavformat/avformat.h> 27 #if defined(HAVE_SWRESAMPLE)28 27 #include <libswresample/swresample.h> 29 #elif defined(HAVE_AVRESAMPLE)30 #include <libavresample/avresample.h>31 #endif32 28 #include <libavutil/opt.h> 33 29 … … 92 88 AVPacket avPacket; 93 89 #endif 94 #ifdef HAVE_AVRESAMPLE95 AVAudioResampleContext *avr;96 #elif defined(HAVE_SWRESAMPLE)97 90 SwrContext *avr; 98 #endif99 91 smpl_t *output; 100 92 uint_t read_samples; … … 337 329 if ( s->avr == NULL ) { 338 330 int err; 331 SwrContext *avr = swr_alloc(); 339 332 int64_t input_layout = av_get_default_channel_layout(s->input_channels); 340 333 int64_t output_layout = av_get_default_channel_layout(s->input_channels); 341 #ifdef HAVE_AVRESAMPLE342 AVAudioResampleContext *avr = avresample_alloc_context();343 #elif defined(HAVE_SWRESAMPLE)344 SwrContext *avr = swr_alloc();345 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */346 334 347 335 av_opt_set_int(avr, "in_channel_layout", input_layout, 0); … … 357 345 // TODO: use planar? 358 346 //av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_FLTP, 0); 359 #ifdef HAVE_AVRESAMPLE360 if ( ( err = avresample_open(avr) ) < 0)361 #elif defined(HAVE_SWRESAMPLE)362 347 if ( ( err = swr_init(avr) ) < 0) 363 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */364 348 { 365 349 char errorstr[256]; … … 384 368 AVPacket *avPacket = &s->avPacket; 385 369 #endif 386 #ifdef HAVE_AVRESAMPLE387 AVAudioResampleContext *avr = s->avr;388 #elif defined(HAVE_SWRESAMPLE)389 370 SwrContext *avr = s->avr; 390 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */391 371 int got_frame = 0; 392 #ifdef HAVE_AVRESAMPLE393 int in_linesize = 0;394 int in_samples = avFrame->nb_samples;395 int out_linesize = 0;396 int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;397 int out_samples = 0;398 #elif defined(HAVE_SWRESAMPLE)399 372 int in_samples = avFrame->nb_samples; 400 373 int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels; 401 374 int out_samples = 0; 402 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */403 375 smpl_t *output = s->output; 404 376 #ifndef FF_API_LAVF_AVCTX … … 477 449 #endif 478 450 479 #ifdef HAVE_AVRESAMPLE480 in_linesize = 0;481 av_samples_get_buffer_size(&in_linesize, avCodecCtx->channels,482 avFrame->nb_samples, avCodecCtx->sample_fmt, 1);483 in_samples = avFrame->nb_samples;484 out_linesize = 0;485 max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;486 out_samples = avresample_convert ( avr,487 (uint8_t **)&output, out_linesize, max_out_samples,488 (uint8_t **)avFrame->data, in_linesize, in_samples);489 #elif defined(HAVE_SWRESAMPLE)490 451 in_samples = avFrame->nb_samples; 491 452 max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels; … … 493 454 (uint8_t **)&output, max_out_samples, 494 455 (const uint8_t **)avFrame->data, in_samples); 495 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */496 456 if (out_samples < 0) { 497 457 AUBIO_WRN("source_avcodec: error while resampling %s (%d)\n", … … 627 587 s->read_index = 0; 628 588 s->read_samples = 0; 629 #ifdef HAVE_AVRESAMPLE630 // reset the AVAudioResampleContext631 avresample_close(s->avr);632 avresample_open(s->avr);633 #elif defined(HAVE_SWRESAMPLE)634 589 swr_close(s->avr); 635 590 swr_init(s->avr); 636 #endif637 591 return ret; 638 592 } … … 648 602 uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) { 649 603 if (s->avr != NULL) { 650 #ifdef HAVE_AVRESAMPLE651 avresample_close( s->avr );652 av_free ( s->avr );653 #elif defined(HAVE_SWRESAMPLE)654 604 swr_close ( s->avr ); 655 605 swr_free ( &s->avr ); 656 #endif657 606 } 658 607 s->avr = NULL;
Note: See TracChangeset
for help on using the changeset viewer.