diff mbox series

[FFmpeg-devel,4/7] avcodec/iff: Pass extradata and extradata_size explicitly

Message ID DB6PR0101MB2214A80E8C79210447BAAECD8F869@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com
State Accepted
Commit 8612b26202caddf47c9c277b75e88ac27b2fbda8
Headers show
Series [FFmpeg-devel,1/7] avcodec/iff: Split extract_header into extradata and packet part | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt July 12, 2022, 10:27 a.m. UTC
This might be useful in case this decoder were changed to support
new extradata passed via side-data.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/iff.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/iff.c b/libavcodec/iff.c
index 13912e9133..453e910982 100644
--- a/libavcodec/iff.c
+++ b/libavcodec/iff.c
@@ -201,20 +201,20 @@  static int cmap_read_palette(AVCodecContext *avctx, uint32_t *pal)
  * @param avctx the AVCodecContext where to extract extra context to
  * @return >= 0 in case of success, a negative error code otherwise
  */
-static int extract_header(AVCodecContext *const avctx)
+static int extract_header(AVCodecContext *const avctx,
+                          const uint8_t *const extradata, int extradata_size)
 {
     IffContext *s = avctx->priv_data;
-    const uint8_t *buf;
+    const uint8_t *buf = extradata;
     unsigned buf_size = 0;
     int i, palette_size;
 
-    if (avctx->extradata_size < 2) {
+    if (extradata_size < 2) {
         av_log(avctx, AV_LOG_ERROR, "not enough extradata\n");
         return AVERROR_INVALIDDATA;
     }
-    palette_size = avctx->extradata_size - AV_RB16(avctx->extradata);
+    palette_size = extradata_size - AV_RB16(extradata);
 
-        buf = avctx->extradata;
         buf_size = bytestream_get_be16(&buf);
         if (buf_size <= 1 || palette_size < 0) {
             av_log(avctx, AV_LOG_ERROR,
@@ -274,7 +274,7 @@  static int extract_header(AVCodecContext *const avctx)
         if (s->ham) {
             int i, count = FFMIN(palette_size / 3, 1 << s->ham);
             int ham_count;
-            const uint8_t *const palette = avctx->extradata + AV_RB16(avctx->extradata);
+            const uint8_t *const palette = extradata + AV_RB16(extradata);
             int extra_space = 1;
 
             if (avctx->codec_tag == MKTAG('P', 'B', 'M', ' ') && s->ham == 4)
@@ -389,7 +389,8 @@  static av_cold int decode_init(AVCodecContext *avctx)
             return AVERROR(ENOMEM);
     }
 
-    if ((err = extract_header(avctx)) < 0)
+    err = extract_header(avctx, avctx->extradata, avctx->extradata_size);
+    if (err < 0)
         return err;
 
     return 0;