History

[source_avcodec] avoid deprecation warning with latest avcodec api (58.134.100)

Paul Brossier committed 4 years ago

Commit cdfe9ce1 parent ea7f48e1 file · +45 −7Browse files

Unified · Split

src/io/source_avcodec.c+45−7
@@ -82,7 +82,11 @@ struct _aubio_source_avcodec_t { · 81 unmodified lines
8282 AVFormatContext *avFormatCtx;
8383 AVCodecContext *avCodecCtx;
8484 AVFrame *avFrame;
85+#if FF_API_INIT_PACKET
86+ AVPacket *avPacket;
87+#else
8588 AVPacket avPacket;
89+#endif
8690 #ifdef HAVE_AVRESAMPLE
8791 AVAudioResampleContext *avr;
8892 #elif defined(HAVE_SWRESAMPLE)
@@ -122,10 +126,14 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, · 33 unmodified lines
122126 AVFormatContext *avFormatCtx = NULL;
123127 AVCodecContext *avCodecCtx = NULL;
124128 AVFrame *avFrame = NULL;
129+#if FF_API_INIT_PACKET
130+ AVPacket *avPacket = NULL;
131+#endif
125132 sint_t selected_stream = -1;
126133 #if FF_API_LAVF_AVCTX
127134 AVCodecParameters *codecpar;
128135 #endif
136+
129137 AVCodec *codec;
130138 uint_t i;
131139 int err;
@@ -277,8 +285,17 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, · 145 unmodified lines
277285 avFrame = av_frame_alloc();
278286 if (!avFrame) {
279287 AUBIO_ERR("source_avcodec: Could not allocate frame for (%s)\n", s->path);
288+ goto beach;
280289 }
281290
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+
282299 /* allocate output for avr */
283300 s->output = (smpl_t *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE
284301 * sizeof(smpl_t));
@@ -289,6 +306,9 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, · 4 unmodified lines
289306 s->avFormatCtx = avFormatCtx;
290307 s->avCodecCtx = avCodecCtx;
291308 s->avFrame = avFrame;
309+#if FF_API_INIT_PACKET
310+ s->avPacket = avPacket;
311+#endif
292312
293313 aubio_source_avcodec_reset_resampler(s);
294314
@@ -354,7 +374,11 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, · 59 unmodified lines
354374 AVFormatContext *avFormatCtx = s->avFormatCtx;
355375 AVCodecContext *avCodecCtx = s->avCodecCtx;
356376 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
358382 #ifdef HAVE_AVRESAMPLE
359383 AVAudioResampleContext *avr = s->avr;
360384 #elif defined(HAVE_SWRESAMPLE)
@@ -378,12 +402,14 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, · 17 unmodified lines
378402 #else
379403 int ret = 0;
380404 #endif
381− av_init_packet (&avPacket);
405+#ifndef FF_API_INIT_PACKET
406+ av_init_packet (avPacket);
407+#endif
382408 *read_samples = 0;
383409
384410 do
385411 {
386− int err = av_read_frame (avFormatCtx, &avPacket);
412+ int err = av_read_frame (avFormatCtx, avPacket);
387413 if (err == AVERROR_EOF) {
388414 s->eof = 1;
389415 goto beach;
@@ -396,10 +422,10 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, · 6 unmodified lines
396422 s->eof = 1;
397423 goto beach;
398424 }
399− } while (avPacket.stream_index != s->selected_stream);
425+ } while (avPacket->stream_index != s->selected_stream);
400426
401427 #if FF_API_LAVF_AVCTX
402− ret = avcodec_send_packet(avCodecCtx, &avPacket);
428+ ret = avcodec_send_packet(avCodecCtx, avPacket);
403429 if (ret < 0 && ret != AVERROR_EOF) {
404430 AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path);
405431 goto beach;
@@ -422,7 +448,7 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, · 16 unmodified lines
422448 }
423449 }
424450 #else
425− len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket);
451+ len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, avPacket);
426452
427453 if (len < 0) {
428454 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
472498 *read_samples = out_samples;
473499
474500 beach:
475− av_packet_unref(&avPacket);
501+ av_packet_unref(avPacket);
476502 }
477503
478504 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
638664 avformat_close_input(&s->avFormatCtx);
639665 s->avFormatCtx = NULL;
640666 }
667+#if FF_API_INIT_PACKET
668+ if (s->avPacket) {
669+ av_packet_unref(s->avPacket);
670+ }
671+#else
641672 av_packet_unref(&s->avPacket);
673+#endif
642674 return AUBIO_OK;
643675 }
644676
@@ -653,6 +685,12 @@ void del_aubio_source_avcodec(aubio_source_avcodec_t * s){ · 8 unmodified lines
653685 av_frame_free( &(s->avFrame) );
654686 }
655687 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
656694 if (s->path) {
657695 AUBIO_FREE(s->path);
658696 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t