Unified · Split
| @@ -82,7 +82,11 @@ struct _aubio_source_avcodec_t { · 81 unmodified lines | |||
| 82 | AVFormatContext *avFormatCtx; | 82 | AVFormatContext *avFormatCtx; |
| 83 | AVCodecContext *avCodecCtx; | 83 | AVCodecContext *avCodecCtx; |
| 84 | AVFrame *avFrame; | 84 | AVFrame *avFrame; |
| 85 | #if FF_API_INIT_PACKET | ||
| 86 | AVPacket *avPacket; | ||
| 87 | #else | ||
| 85 | AVPacket avPacket; | 88 | AVPacket avPacket; |
| 89 | #endif | ||
| 86 | #ifdef HAVE_AVRESAMPLE | 90 | #ifdef HAVE_AVRESAMPLE |
| 87 | AVAudioResampleContext *avr; | 91 | AVAudioResampleContext *avr; |
| 88 | #elif defined(HAVE_SWRESAMPLE) | 92 | #elif defined(HAVE_SWRESAMPLE) |
| @@ -122,10 +126,14 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, · 33 unmodified lines | |||
| 122 | AVFormatContext *avFormatCtx = NULL; | 126 | AVFormatContext *avFormatCtx = NULL; |
| 123 | AVCodecContext *avCodecCtx = NULL; | 127 | AVCodecContext *avCodecCtx = NULL; |
| 124 | AVFrame *avFrame = NULL; | 128 | AVFrame *avFrame = NULL; |
| 129 | #if FF_API_INIT_PACKET | ||
| 130 | AVPacket *avPacket = NULL; | ||
| 131 | #endif | ||
| 125 | sint_t selected_stream = -1; | 132 | sint_t selected_stream = -1; |
| 126 | #if FF_API_LAVF_AVCTX | 133 | #if FF_API_LAVF_AVCTX |
| 127 | AVCodecParameters *codecpar; | 134 | AVCodecParameters *codecpar; |
| 128 | #endif | 135 | #endif |
| 136 | |||
| 129 | AVCodec *codec; | 137 | AVCodec *codec; |
| 130 | uint_t i; | 138 | uint_t i; |
| 131 | int err; | 139 | int err; |
| @@ -277,8 +285,17 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, · 145 unmodified lines | |||
| 277 | avFrame = av_frame_alloc(); | 285 | avFrame = av_frame_alloc(); |
| 278 | if (!avFrame) { | 286 | if (!avFrame) { |
| 279 | AUBIO_ERR("source_avcodec: Could not allocate frame for (%s)\n", s->path); | 287 | AUBIO_ERR("source_avcodec: Could not allocate frame for (%s)\n", s->path); |
| 288 | goto beach; | ||
| 280 | } | 289 | } |
| 281 | 290 | ||
| 291 | #if FF_API_INIT_PACKET | ||
| 292 | avPacket = av_packet_alloc(); | ||
| 293 | if (!avPacket) { | ||
| 294 | AUBIO_ERR("source_avcodec: Could not allocate packet for (%s)\n", s->path); | ||
| 295 | goto beach; | ||
| 296 | } | ||
| 297 | #endif | ||
| 298 | |||
| 282 | /* allocate output for avr */ | 299 | /* allocate output for avr */ |
| 283 | s->output = (smpl_t *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE | 300 | s->output = (smpl_t *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE |
| 284 | * sizeof(smpl_t)); | 301 | * sizeof(smpl_t)); |
| @@ -289,6 +306,9 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, · 4 unmodified lines | |||
| 289 | s->avFormatCtx = avFormatCtx; | 306 | s->avFormatCtx = avFormatCtx; |
| 290 | s->avCodecCtx = avCodecCtx; | 307 | s->avCodecCtx = avCodecCtx; |
| 291 | s->avFrame = avFrame; | 308 | s->avFrame = avFrame; |
| 309 | #if FF_API_INIT_PACKET | ||
| 310 | s->avPacket = avPacket; | ||
| 311 | #endif | ||
| 292 | 312 | ||
| 293 | aubio_source_avcodec_reset_resampler(s); | 313 | aubio_source_avcodec_reset_resampler(s); |
| 294 | 314 | ||
| @@ -354,7 +374,11 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, · 59 unmodified lines | |||
| 354 | AVFormatContext *avFormatCtx = s->avFormatCtx; | 374 | AVFormatContext *avFormatCtx = s->avFormatCtx; |
| 355 | AVCodecContext *avCodecCtx = s->avCodecCtx; | 375 | AVCodecContext *avCodecCtx = s->avCodecCtx; |
| 356 | AVFrame *avFrame = s->avFrame; | 376 | AVFrame *avFrame = s->avFrame; |
| 357 | AVPacket avPacket = s->avPacket; | 377 | #if FF_API_INIT_PACKET |
| 378 | AVPacket *avPacket = s->avPacket; | ||
| 379 | #else | ||
| 380 | AVPacket *avPacket = &s->avPacket; | ||
| 381 | #endif | ||
| 358 | #ifdef HAVE_AVRESAMPLE | 382 | #ifdef HAVE_AVRESAMPLE |
| 359 | AVAudioResampleContext *avr = s->avr; | 383 | AVAudioResampleContext *avr = s->avr; |
| 360 | #elif defined(HAVE_SWRESAMPLE) | 384 | #elif defined(HAVE_SWRESAMPLE) |
| @@ -378,12 +402,14 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, · 17 unmodified lines | |||
| 378 | #else | 402 | #else |
| 379 | int ret = 0; | 403 | int ret = 0; |
| 380 | #endif | 404 | #endif |
| 381 | av_init_packet (&avPacket); | 405 | #ifndef FF_API_INIT_PACKET |
| 406 | av_init_packet (avPacket); | ||
| 407 | #endif | ||
| 382 | *read_samples = 0; | 408 | *read_samples = 0; |
| 383 | 409 | ||
| 384 | do | 410 | do |
| 385 | { | 411 | { |
| 386 | int err = av_read_frame (avFormatCtx, &avPacket); | 412 | int err = av_read_frame (avFormatCtx, avPacket); |
| 387 | if (err == AVERROR_EOF) { | 413 | if (err == AVERROR_EOF) { |
| 388 | s->eof = 1; | 414 | s->eof = 1; |
| 389 | goto beach; | 415 | goto beach; |
| @@ -396,10 +422,10 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, · 6 unmodified lines | |||
| 396 | s->eof = 1; | 422 | s->eof = 1; |
| 397 | goto beach; | 423 | goto beach; |
| 398 | } | 424 | } |
| 399 | } while (avPacket.stream_index != s->selected_stream); | 425 | } while (avPacket->stream_index != s->selected_stream); |
| 400 | 426 | ||
| 401 | #if FF_API_LAVF_AVCTX | 427 | #if FF_API_LAVF_AVCTX |
| 402 | ret = avcodec_send_packet(avCodecCtx, &avPacket); | 428 | ret = avcodec_send_packet(avCodecCtx, avPacket); |
| 403 | if (ret < 0 && ret != AVERROR_EOF) { | 429 | if (ret < 0 && ret != AVERROR_EOF) { |
| 404 | AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path); | 430 | AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path); |
| 405 | goto beach; | 431 | goto beach; |
| @@ -422,7 +448,7 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, · 16 unmodified lines | |||
| 422 | } | 448 | } |
| 423 | } | 449 | } |
| 424 | #else | 450 | #else |
| 425 | len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket); | 451 | len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, avPacket); |
| 426 | 452 | ||
| 427 | if (len < 0) { | 453 | if (len < 0) { |
| 428 | AUBIO_ERR("source_avcodec: error while decoding %s\n", s->path); | 454 | AUBIO_ERR("source_avcodec: error while decoding %s\n", s->path); |
| @@ -472,7 +498,7 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, · 43 unmodified lines | |||
| 472 | *read_samples = out_samples; | 498 | *read_samples = out_samples; |
| 473 | 499 | ||
| 474 | beach: | 500 | beach: |
| 475 | av_packet_unref(&avPacket); | 501 | av_packet_unref(avPacket); |
| 476 | } | 502 | } |
| 477 | 503 | ||
| 478 | void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, | 504 | void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, |
| @@ -638,7 +664,13 @@ uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) { · 159 unmodified lines | |||
| 638 | avformat_close_input(&s->avFormatCtx); | 664 | avformat_close_input(&s->avFormatCtx); |
| 639 | s->avFormatCtx = NULL; | 665 | s->avFormatCtx = NULL; |
| 640 | } | 666 | } |
| 667 | #if FF_API_INIT_PACKET | ||
| 668 | if (s->avPacket) { | ||
| 669 | av_packet_unref(s->avPacket); | ||
| 670 | } | ||
| 671 | #else | ||
| 641 | av_packet_unref(&s->avPacket); | 672 | av_packet_unref(&s->avPacket); |
| 673 | #endif | ||
| 642 | return AUBIO_OK; | 674 | return AUBIO_OK; |
| 643 | } | 675 | } |
| 644 | 676 | ||
| @@ -653,6 +685,12 @@ void del_aubio_source_avcodec(aubio_source_avcodec_t * s){ · 8 unmodified lines | |||
| 653 | av_frame_free( &(s->avFrame) ); | 685 | av_frame_free( &(s->avFrame) ); |
| 654 | } | 686 | } |
| 655 | s->avFrame = NULL; | 687 | s->avFrame = NULL; |
| 688 | #if FF_API_INIT_PACKET | ||
| 689 | if (s->avPacket != NULL) { | ||
| 690 | av_packet_free( &(s->avPacket) ); | ||
| 691 | } | ||
| 692 | s->avPacket = NULL; | ||
| 693 | #endif | ||
| 656 | if (s->path) { | 694 | if (s->path) { |
| 657 | AUBIO_FREE(s->path); | 695 | AUBIO_FREE(s->path); |
| 658 | } | 696 | } |