src/io/source_avcodec.c: keep a reference to packet to remove it when closing file
authorPaul Brossier <piem@piem.org>
Wed, 30 Nov 2016 16:18:14 +0000 (17:18 +0100)
committerPaul Brossier <piem@piem.org>
Wed, 30 Nov 2016 16:18:14 +0000 (17:18 +0100)
src/io/source_avcodec.c

index 00bf3da..9df4e6d 100644 (file)
@@ -59,6 +59,7 @@ struct _aubio_source_avcodec_t {
   AVFormatContext *avFormatCtx;
   AVCodecContext *avCodecCtx;
   AVFrame *avFrame;
+  AVPacket avPacket;
   AVAudioResampleContext *avr;
   smpl_t *output;
   uint_t read_samples;
@@ -305,7 +306,7 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_sam
   AVFormatContext *avFormatCtx = s->avFormatCtx;
   AVCodecContext *avCodecCtx = s->avCodecCtx;
   AVFrame *avFrame = s->avFrame;
-  AVPacket avPacket;
+  AVPacket avPacket = s->avPacket;
   av_init_packet (&avPacket);
   AVAudioResampleContext *avr = s->avr;
   smpl_t *output = s->output;
@@ -506,6 +507,11 @@ uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
     avformat_free_context(s->avFormatCtx);
     s->avFormatCtx = NULL;
   }
+#if FF_API_LAVF_AVCTX
+  av_packet_unref(&s->avPacket);
+#else
+  av_free_packet(&s->avPacket);
+#endif
   return AUBIO_OK;
 }