From 3a05ca7b5e31f7c6e0b61dac03f76c3ee36ecab5 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Thu, 29 Apr 2021 16:52:28 +0200 Subject: [PATCH] Fix FFmpeg deprecation warnings. --- MP42/MP42BitmapSubConverter.m | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/MP42/MP42BitmapSubConverter.m b/MP42/MP42BitmapSubConverter.m index d483cea..f6fdcc7 100644 --- a/MP42/MP42BitmapSubConverter.m +++ b/MP42/MP42BitmapSubConverter.m @@ -36,6 +36,7 @@ MP42_OBJC_DIRECT_MEMBERS CIContext *_imgContext; AVCodec *avCodec; AVCodecContext *avContext; + AVPacket *pkt; MP42Fifo *_inputSamplesBuffer; MP42Fifo *_outputSamplesBuffer; @@ -141,12 +142,11 @@ MP42_OBJC_DIRECT_MEMBERS memcpy(codecData, sampleBuffer->data, sampleBuffer->size); } - AVPacket pkt; AVSubtitle subtitle; - av_init_packet(&pkt); - pkt.data = codecData; - pkt.size = bufferSize; - ret = avcodec_decode_subtitle2(avContext, &subtitle, &got_sub, &pkt); + pkt->data = codecData; + pkt->size = bufferSize; + ret = avcodec_decode_subtitle2(avContext, &subtitle, &got_sub, pkt); + av_packet_unref(pkt); if (ret < 0 || !got_sub) { NSLog(@"Error decoding DVD subtitle %d / %ld", ret, (long)bufferSize); @@ -262,7 +262,6 @@ MP42_OBJC_DIRECT_MEMBERS } avsubtitle_free(&subtitle); - av_packet_unref(&pkt); } } dispatch_semaphore_signal(_done); @@ -282,14 +281,13 @@ MP42_OBJC_DIRECT_MEMBERS break; } - AVPacket pkt; AVSubtitle subtitle; - av_init_packet(&pkt); - pkt.data = sampleBuffer->data; - pkt.size = sampleBuffer->size; + pkt->data = sampleBuffer->data; + pkt->size = sampleBuffer->size; int ret, got_sub; - ret = avcodec_decode_subtitle2(avContext, &subtitle, &got_sub, &pkt); + ret = avcodec_decode_subtitle2(avContext, &subtitle, &got_sub, pkt); + av_packet_unref(pkt); if (ret < 0 || !got_sub || !subtitle.num_rects) { MP42SampleBuffer *subSample = copyEmptySubtitleSample(sampleBuffer->trackId, sampleBuffer->duration, NO); @@ -381,7 +379,6 @@ MP42_OBJC_DIRECT_MEMBERS [_outputSamplesBuffer enqueue:subSample]; avsubtitle_free(&subtitle); - av_packet_unref(&pkt); } } dispatch_semaphore_signal(_done); @@ -402,6 +399,7 @@ MP42_OBJC_DIRECT_MEMBERS if (avCodec) { avContext = avcodec_alloc_context3(NULL); + pkt = av_packet_alloc(); if (avcodec_open2(avContext, avCodec, NULL)) { NSLog(@"Error opening subtitle decoder"); @@ -461,6 +459,9 @@ MP42_OBJC_DIRECT_MEMBERS avcodec_close(avContext); av_freep(&avContext); } + if (pkt) { + av_packet_free(&pkt); + } if (codecData) { av_freep(&codecData); }