Unified · Split
| @@ -82,7 +82,11 @@ struct _aubio_source_avcodec_t { · 81 unmodified lines | ||
| 82 | 82 | AVFormatContext *avFormatCtx; |
| 83 | 83 | AVCodecContext *avCodecCtx; |
| 84 | 84 | AVFrame *avFrame; |
| 85 | +#if FF_API_INIT_PACKET | |
| 86 | + AVPacket *avPacket; | |
| 87 | +#else | |
| 85 | 88 | AVPacket avPacket; |
| 89 | +#endif | |
| 86 | 90 | #ifdef HAVE_AVRESAMPLE |
| 87 | 91 | AVAudioResampleContext *avr; |
| 88 | 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 | 126 | AVFormatContext *avFormatCtx = NULL; |
| 123 | 127 | AVCodecContext *avCodecCtx = NULL; |
| 124 | 128 | AVFrame *avFrame = NULL; |
| 129 | +#if FF_API_INIT_PACKET | |
| 130 | + AVPacket *avPacket = NULL; | |
| 131 | +#endif | |
| 125 | 132 | sint_t selected_stream = -1; |
| 126 | 133 | #if FF_API_LAVF_AVCTX |
| 127 | 134 | AVCodecParameters *codecpar; |
| 128 | 135 | #endif |
| 136 | + | |
| 129 | 137 | AVCodec *codec; |
| 130 | 138 | uint_t i; |
| 131 | 139 | int err; |
| @@ -277,8 +285,17 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, · 145 unmodified lines | ||
| 277 | 285 | avFrame = av_frame_alloc(); |
| 278 | 286 | if (!avFrame) { |
| 279 | 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 | 299 | /* allocate output for avr */ |
| 283 | 300 | s->output = (smpl_t *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE |
| 284 | 301 | * sizeof(smpl_t)); |
| @@ -289,6 +306,9 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, · 4 unmodified lines | ||
| 289 | 306 | s->avFormatCtx = avFormatCtx; |
| 290 | 307 | s->avCodecCtx = avCodecCtx; |
| 291 | 308 | s->avFrame = avFrame; |
| 309 | +#if FF_API_INIT_PACKET | |
| 310 | + s->avPacket = avPacket; | |
| 311 | +#endif | |
| 292 | 312 | |
| 293 | 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 | 374 | AVFormatContext *avFormatCtx = s->avFormatCtx; |
| 355 | 375 | AVCodecContext *avCodecCtx = s->avCodecCtx; |
| 356 | 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 | 382 | #ifdef HAVE_AVRESAMPLE |
| 359 | 383 | AVAudioResampleContext *avr = s->avr; |
| 360 | 384 | #elif defined(HAVE_SWRESAMPLE) |
| @@ -378,12 +402,14 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, · 17 unmodified lines | ||
| 378 | 402 | #else |
| 379 | 403 | int ret = 0; |
| 380 | 404 | #endif |
| 381 | − av_init_packet (&avPacket); | |
| 405 | +#ifndef FF_API_INIT_PACKET | |
| 406 | + av_init_packet (avPacket); | |
| 407 | +#endif | |
| 382 | 408 | *read_samples = 0; |
| 383 | 409 | |
| 384 | 410 | do |
| 385 | 411 | { |
| 386 | − int err = av_read_frame (avFormatCtx, &avPacket); | |
| 412 | + int err = av_read_frame (avFormatCtx, avPacket); | |
| 387 | 413 | if (err == AVERROR_EOF) { |
| 388 | 414 | s->eof = 1; |
| 389 | 415 | goto beach; |
| @@ -396,10 +422,10 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, · 6 unmodified lines | ||
| 396 | 422 | s->eof = 1; |
| 397 | 423 | goto beach; |
| 398 | 424 | } |
| 399 | − } while (avPacket.stream_index != s->selected_stream); | |
| 425 | + } while (avPacket->stream_index != s->selected_stream); | |
| 400 | 426 | |
| 401 | 427 | #if FF_API_LAVF_AVCTX |
| 402 | − ret = avcodec_send_packet(avCodecCtx, &avPacket); | |
| 428 | + ret = avcodec_send_packet(avCodecCtx, avPacket); | |
| 403 | 429 | if (ret < 0 && ret != AVERROR_EOF) { |
| 404 | 430 | AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path); |
| 405 | 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 | 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 | 453 | if (len < 0) { |
| 428 | 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 | 498 | *read_samples = out_samples; |
| 473 | 499 | |
| 474 | 500 | beach: |
| 475 | − av_packet_unref(&avPacket); | |
| 501 | + av_packet_unref(avPacket); | |
| 476 | 502 | } |
| 477 | 503 | |
| 478 | 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 | 664 | avformat_close_input(&s->avFormatCtx); |
| 639 | 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 | 672 | av_packet_unref(&s->avPacket); |
| 673 | +#endif | |
| 642 | 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 | 685 | av_frame_free( &(s->avFrame) ); |
| 654 | 686 | } |
| 655 | 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 | 694 | if (s->path) { |
| 657 | 695 | AUBIO_FREE(s->path); |
| 658 | 696 | } |