aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/sp5xdec.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-12-07 17:36:22 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-12-10 21:15:27 +0100
commit05086a6c936c360a43db38b11b5074fb0cb65211 (patch)
treefc29e69890474c1eae3034ea6800cd95bc639ba4 /libavcodec/sp5xdec.c
parentec2d582cb02dc3b838b2ff9efe48a5fa2ee288dd (diff)
downloadffmpeg-05086a6c936c360a43db38b11b5074fb0cb65211.tar.gz
avcodec/mjpegdec: Only use receive_frame for SMVJPEG
Only one codec using mjpegdec.c actually creates multiple frames from a single packet, namely SMVJPEG. The other can use the ordinary decode callback just fine. This e.g. has the advantage of confining the special SP5X/AMV code to sp5xdec.c. This reverts most of commit e9a2a8777317d91af658f774c68442ac4aa726ec; of course it is not a simple revert: Way too much has changed; furthermore, outright reverting the sp5xdec.c changes would readd a stack packet to sp5x_decode_frame() which is not desired. In order to avoid this without modifying the given AVPacket, a variant of ff_mjpeg_decode_frame() with explicit buf and size parameters has been added. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/sp5xdec.c')
-rw-r--r--libavcodec/sp5xdec.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/libavcodec/sp5xdec.c b/libavcodec/sp5xdec.c
index 394448c5a9..dfed725500 100644
--- a/libavcodec/sp5xdec.c
+++ b/libavcodec/sp5xdec.c
@@ -32,21 +32,23 @@
#include "mjpegdec.h"
#include "sp5x.h"
-int ff_sp5x_process_packet(AVCodecContext *avctx, AVPacket *avpkt)
+
+static int sp5x_decode_frame(AVCodecContext *avctx,
+ AVFrame *frame, int *got_frame,
+ AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
- AVBufferRef *buf_recoded;
uint8_t *recoded;
int i = 0, j = 0;
+ int ret;
if (!avctx->width || !avctx->height)
return -1;
- buf_recoded = av_buffer_allocz(buf_size + 1024);
- if (!buf_recoded)
+ recoded = av_mallocz(buf_size + 1024);
+ if (!recoded)
return -1;
- recoded = buf_recoded->data;
/* SOI */
recoded[j++] = 0xFF;
@@ -83,12 +85,12 @@ int ff_sp5x_process_packet(AVCodecContext *avctx, AVPacket *avpkt)
recoded[j++] = 0xFF;
recoded[j++] = 0xD9;
- av_buffer_unref(&avpkt->buf);
- avpkt->buf = buf_recoded;
- avpkt->data = recoded;
- avpkt->size = j;
+ ret = ff_mjpeg_decode_frame_from_buf(avctx, frame, got_frame,
+ avpkt, recoded, j);
+
+ av_free(recoded);
- return 0;
+ return ret < 0 ? ret : avpkt->size;
}
#if CONFIG_SP5X_DECODER
@@ -100,11 +102,10 @@ const FFCodec ff_sp5x_decoder = {
.priv_data_size = sizeof(MJpegDecodeContext),
.init = ff_mjpeg_decode_init,
.close = ff_mjpeg_decode_end,
- FF_CODEC_RECEIVE_FRAME_CB(ff_mjpeg_receive_frame),
+ FF_CODEC_DECODE_CB(sp5x_decode_frame),
.p.capabilities = AV_CODEC_CAP_DR1,
.p.max_lowres = 3,
- .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
- FF_CODEC_CAP_SETS_PKT_DTS,
+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
};
#endif
#if CONFIG_AMV_DECODER
@@ -116,10 +117,9 @@ const FFCodec ff_amv_decoder = {
.priv_data_size = sizeof(MJpegDecodeContext),
.init = ff_mjpeg_decode_init,
.close = ff_mjpeg_decode_end,
- FF_CODEC_RECEIVE_FRAME_CB(ff_mjpeg_receive_frame),
+ FF_CODEC_DECODE_CB(sp5x_decode_frame),
.p.max_lowres = 3,
.p.capabilities = AV_CODEC_CAP_DR1,
- .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
- FF_CODEC_CAP_SETS_PKT_DTS,
+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
};
#endif