[FFmpeg-devel] [PATCH 4/8] avcodec: Constify some AVPackets

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Thu Mar 4 17:42:29 EET 2021


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
Of all the decoders using the simple decode API (i.e. with .decode set)
only imm5 seems to modify its input packet (which is fine given that it
is not the user-supplied reference); libfdk_aac's API is not
const-correct, so as-is it is not compatible with constifiying the AVPacket
in the .decode function, yet this is easily fixable.

 libavcodec/aacdec_template.c |  3 ++-
 libavcodec/audiotoolboxdec.c |  3 ++-
 libavcodec/bitpacked.c       |  6 +++---
 libavcodec/dsddec.c          |  4 ++--
 libavcodec/flashsv.c         |  2 +-
 libavcodec/movtextdec.c      | 10 +++++-----
 libavcodec/pgxdec.c          |  6 +++---
 libavcodec/pixlet.c          |  2 +-
 libavcodec/pngdec.c          |  2 +-
 libavcodec/rasc.c            | 14 +++++++-------
 libavcodec/tiff.c            |  3 ++-
 libavcodec/vp8.c             |  2 +-
 12 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index aa89f7cbb8..7b78566993 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -3216,7 +3216,8 @@ static int aac_decode_er_frame(AVCodecContext *avctx, void *data,
 }
 
 static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
-                                int *got_frame_ptr, GetBitContext *gb, AVPacket *avpkt)
+                                int *got_frame_ptr, GetBitContext *gb,
+                                const AVPacket *avpkt)
 {
     AACContext *ac = avctx->priv_data;
     ChannelElement *che = NULL, *che_prev = NULL;
diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c
index 1f3f7f5ac5..8f9a8d5c27 100644
--- a/libavcodec/audiotoolboxdec.c
+++ b/libavcodec/audiotoolboxdec.c
@@ -296,7 +296,8 @@ static int ffat_set_extradata(AVCodecContext *avctx)
     return 0;
 }
 
-static av_cold int ffat_create_decoder(AVCodecContext *avctx, AVPacket *pkt)
+static av_cold int ffat_create_decoder(AVCodecContext *avctx,
+                                       const AVPacket *pkt)
 {
     ATDecodeContext *at = avctx->priv_data;
     OSStatus status;
diff --git a/libavcodec/bitpacked.c b/libavcodec/bitpacked.c
index 952ba73a32..23e82c69b5 100644
--- a/libavcodec/bitpacked.c
+++ b/libavcodec/bitpacked.c
@@ -33,12 +33,12 @@
 
 struct BitpackedContext {
     int (*decode)(AVCodecContext *avctx, AVFrame *frame,
-                  AVPacket *pkt);
+                  const AVPacket *pkt);
 };
 
 /* For this format, it's a simple passthrough */
 static int bitpacked_decode_uyvy422(AVCodecContext *avctx, AVFrame *frame,
-                                    AVPacket *avpkt)
+                                    const AVPacket *avpkt)
 {
     int ret;
 
@@ -56,7 +56,7 @@ static int bitpacked_decode_uyvy422(AVCodecContext *avctx, AVFrame *frame,
 }
 
 static int bitpacked_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame,
-                                      AVPacket *avpkt)
+                                      const AVPacket *avpkt)
 {
     uint64_t frame_size = (uint64_t)avctx->width * (uint64_t)avctx->height * 20;
     uint64_t packet_size = (uint64_t)avpkt->size * 8;
diff --git a/libavcodec/dsddec.c b/libavcodec/dsddec.c
index 9814c9eb82..21d1d9f5de 100644
--- a/libavcodec/dsddec.c
+++ b/libavcodec/dsddec.c
@@ -66,7 +66,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
 typedef struct ThreadData {
     AVFrame *frame;
-    AVPacket *avpkt;
+    const AVPacket *avpkt;
 } ThreadData;
 
 static int dsd_channel(AVCodecContext *avctx, void *tdata, int j, int threadnr)
@@ -75,7 +75,7 @@ static int dsd_channel(AVCodecContext *avctx, void *tdata, int j, int threadnr)
     DSDContext *s = avctx->priv_data;
     ThreadData *td = tdata;
     AVFrame *frame = td->frame;
-    AVPacket *avpkt = td->avpkt;
+    const AVPacket *avpkt = td->avpkt;
     int src_next, src_stride;
     float *dst = ((float **)frame->extended_data)[j];
 
diff --git a/libavcodec/flashsv.c b/libavcodec/flashsv.c
index f55cb0feeb..9481f80f0b 100644
--- a/libavcodec/flashsv.c
+++ b/libavcodec/flashsv.c
@@ -179,7 +179,7 @@ static int flashsv2_prime(FlashSVContext *s, uint8_t *src, int size)
     return 0;
 }
 
-static int flashsv_decode_block(AVCodecContext *avctx, AVPacket *avpkt,
+static int flashsv_decode_block(AVCodecContext *avctx, const AVPacket *avpkt,
                                 GetBitContext *gb, int block_size,
                                 int width, int height, int x_pos, int y_pos,
                                 int blk_idx)
diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index ad790bf44c..7adc16d262 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -117,7 +117,7 @@ typedef struct {
 typedef struct {
     uint32_t type;
     size_t base_size;
-    int (*decode)(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt);
+    int (*decode)(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt);
 } Box;
 
 static void mov_text_cleanup(MovTextContext *m)
@@ -240,14 +240,14 @@ static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
     return 0;
 }
 
-static int decode_twrp(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
+static int decode_twrp(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
 {
     m->box_flags |= TWRP_BOX;
     m->w.wrap_flag = bytestream_get_byte(&tsmb);
     return 0;
 }
 
-static int decode_hlit(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
+static int decode_hlit(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
 {
     m->box_flags |= HLIT_BOX;
     m->h.hlit_start = bytestream_get_be16(&tsmb);
@@ -255,14 +255,14 @@ static int decode_hlit(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
     return 0;
 }
 
-static int decode_hclr(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
+static int decode_hclr(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
 {
     m->box_flags |= HCLR_BOX;
     bytestream_get_buffer(&tsmb, m->c.hlit_color, 4);
     return 0;
 }
 
-static int decode_styl(const uint8_t *tsmb, MovTextContext *m, AVPacket *avpkt)
+static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
 {
     int i;
     int style_entries = bytestream_get_be16(&tsmb);
diff --git a/libavcodec/pgxdec.c b/libavcodec/pgxdec.c
index 5c735894ab..65b2929283 100644
--- a/libavcodec/pgxdec.c
+++ b/libavcodec/pgxdec.c
@@ -95,7 +95,7 @@ error:
 }
 
 #define WRITE_FRAME(D, PIXEL, suffix)                                                       \
-    static inline void write_frame_ ##D(AVPacket *avpkt, AVFrame *frame, GetByteContext *g, \
+    static inline void write_frame_ ##D(AVFrame *frame, GetByteContext *g, \
                                         int width, int height, int sign, int depth)         \
     {                                                                                       \
         int i, j;                                                                           \
@@ -151,9 +151,9 @@ static int pgx_decode_frame(AVCodecContext *avctx, void *data,
     p->key_frame = 1;
     avctx->bits_per_raw_sample = depth;
     if (bpp == 8)
-        write_frame_8(avpkt, p, &g, width, height, sign, depth);
+        write_frame_8(p, &g, width, height, sign, depth);
     else if (bpp == 16)
-        write_frame_16(avpkt, p, &g, width, height, sign, depth);
+        write_frame_16(p, &g, width, height, sign, depth);
     *got_frame = 1;
     return 0;
 }
diff --git a/libavcodec/pixlet.c b/libavcodec/pixlet.c
index 42acd683fa..ad9d830af7 100644
--- a/libavcodec/pixlet.c
+++ b/libavcodec/pixlet.c
@@ -525,7 +525,7 @@ static void postprocess_chroma(AVFrame *frame, int w, int h, int depth)
 }
 
 static int decode_plane(AVCodecContext *avctx, int plane,
-                        AVPacket *avpkt, AVFrame *frame)
+                        const AVPacket *avpkt, AVFrame *frame)
 {
     PixletContext *ctx = avctx->priv_data;
     ptrdiff_t stride   = frame->linesize[plane] / 2;
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index cece08ebca..a5a71ef161 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1179,7 +1179,7 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s,
 }
 
 static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
-                               AVFrame *p, AVPacket *avpkt)
+                               AVFrame *p, const AVPacket *avpkt)
 {
     const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE);
     AVDictionary **metadatap = NULL;
diff --git a/libavcodec/rasc.c b/libavcodec/rasc.c
index 706940bf5f..207d50c452 100644
--- a/libavcodec/rasc.c
+++ b/libavcodec/rasc.c
@@ -112,7 +112,7 @@ static int init_frames(AVCodecContext *avctx)
 }
 
 static int decode_fint(AVCodecContext *avctx,
-                       AVPacket *avpkt, unsigned size)
+                       const AVPacket *avpkt, unsigned size)
 {
     RASCContext *s = avctx->priv_data;
     GetByteContext *gb = &s->gb;
@@ -171,7 +171,7 @@ static int decode_fint(AVCodecContext *avctx,
     return 0;
 }
 
-static int decode_zlib(AVCodecContext *avctx, AVPacket *avpkt,
+static int decode_zlib(AVCodecContext *avctx, const AVPacket *avpkt,
                        unsigned size, unsigned uncompressed_size)
 {
     RASCContext *s = avctx->priv_data;
@@ -205,7 +205,7 @@ static int decode_zlib(AVCodecContext *avctx, AVPacket *avpkt,
 }
 
 static int decode_move(AVCodecContext *avctx,
-                       AVPacket *avpkt, unsigned size)
+                       const AVPacket *avpkt, unsigned size)
 {
     RASCContext *s = avctx->priv_data;
     GetByteContext *gb = &s->gb;
@@ -329,7 +329,7 @@ static int decode_move(AVCodecContext *avctx,
     len--;
 
 static int decode_dlta(AVCodecContext *avctx,
-                       AVPacket *avpkt, unsigned size)
+                       const AVPacket *avpkt, unsigned size)
 {
     RASCContext *s = avctx->priv_data;
     GetByteContext *gb = &s->gb;
@@ -471,7 +471,7 @@ static int decode_dlta(AVCodecContext *avctx,
 }
 
 static int decode_kfrm(AVCodecContext *avctx,
-                       AVPacket *avpkt, unsigned size)
+                       const AVPacket *avpkt, unsigned size)
 {
     RASCContext *s = avctx->priv_data;
     GetByteContext *gb = &s->gb;
@@ -534,7 +534,7 @@ static int decode_kfrm(AVCodecContext *avctx,
 }
 
 static int decode_mous(AVCodecContext *avctx,
-                       AVPacket *avpkt, unsigned size)
+                       const AVPacket *avpkt, unsigned size)
 {
     RASCContext *s = avctx->priv_data;
     GetByteContext *gb = &s->gb;
@@ -574,7 +574,7 @@ static int decode_mous(AVCodecContext *avctx,
 }
 
 static int decode_mpos(AVCodecContext *avctx,
-                       AVPacket *avpkt, unsigned size)
+                       const AVPacket *avpkt, unsigned size)
 {
     RASCContext *s = avctx->priv_data;
     GetByteContext *gb = &s->gb;
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index d1e908fd43..9cd2876851 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -964,7 +964,8 @@ static int dng_decode_jpeg(AVCodecContext *avctx, AVFrame *frame,
     return 0;
 }
 
-static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame, AVPacket *avpkt)
+static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame,
+                            const AVPacket *avpkt)
 {
     TiffContext *s = avctx->priv_data;
     int tile_idx;
diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index 89c48e6cb1..d16e7b6aa3 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -2622,7 +2622,7 @@ static int vp8_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata,
 
 static av_always_inline
 int vp78_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
-                      AVPacket *avpkt, int is_vp7)
+                      const AVPacket *avpkt, int is_vp7)
 {
     VP8Context *s = avctx->priv_data;
     int ret, i, referenced, num_jobs;
-- 
2.27.0



More information about the ffmpeg-devel mailing list