diff mbox series

[FFmpeg-devel,02/50] avcodec/cri: use av_packet_alloc() to allocate packets

Message ID 20210204191005.48190-3-jamrial@gmail.com
State New
Headers show
Series deprecate av_init_packet() and sizeof(AVPacket) as part of the ABI | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer Feb. 4, 2021, 7:09 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/cri.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/cri.c b/libavcodec/cri.c
index efbccf4fee..8aadab7703 100644
--- a/libavcodec/cri.c
+++ b/libavcodec/cri.c
@@ -37,6 +37,7 @@ 
 
 typedef struct CRIContext {
     AVCodecContext *jpeg_avctx;   // wrapper context for MJPEG
+    AVPacket *jpkt;               // encoded JPEG tile
     AVFrame *jpgframe;            // decoded JPEG tile
 
     GetByteContext gb;
@@ -56,6 +57,10 @@  static av_cold int cri_decode_init(AVCodecContext *avctx)
     if (!s->jpgframe)
         return AVERROR(ENOMEM);
 
+    s->jpkt = av_packet_alloc();
+    if (!s->jpkt)
+        return AVERROR(ENOMEM);
+
     codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG);
     if (!codec)
         return AVERROR_BUG;
@@ -342,13 +347,11 @@  skip:
         unsigned offset = 0;
 
         for (int tile = 0; tile < 4; tile++) {
-            AVPacket jpkt;
-
-            av_init_packet(&jpkt);
-            jpkt.data = (uint8_t *)s->data + offset;
-            jpkt.size = s->tile_size[tile];
+            av_packet_unref(s->jpkt);
+            s->jpkt->data = (uint8_t *)s->data + offset;
+            s->jpkt->size = s->tile_size[tile];
 
-            ret = avcodec_send_packet(s->jpeg_avctx, &jpkt);
+            ret = avcodec_send_packet(s->jpeg_avctx, s->jpkt);
             if (ret < 0) {
                 av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
                 return ret;
@@ -412,6 +415,7 @@  static av_cold int cri_decode_close(AVCodecContext *avctx)
     CRIContext *s = avctx->priv_data;
 
     av_frame_free(&s->jpgframe);
+    av_packet_free(&s->jpkt);
     avcodec_free_context(&s->jpeg_avctx);
 
     return 0;