* [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG @ 2022-12-07 19:00 Andreas Rheinhardt 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 2/5] avcodec/mjpegdec: Move special SMVJPEG-code to SMVJPEG-only function Andreas Rheinhardt ` (5 more replies) 0 siblings, 6 replies; 7+ messages in thread From: Andreas Rheinhardt @ 2022-12-07 19:00 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Andreas Rheinhardt AVID content is not supposed to be SMVJPEG; given that both these codecs involve manipulating image dimensions and cropping dimensions, it makes sense to restrict the AVID codepaths to non-SMVJPEG codecs in order not to have to think about what if SMVJPEG happens to have a codec tag indicating AVID. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/mjpegdec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 9b7465abe7..28e2839072 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -452,7 +452,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) if (ret < 0) return ret; - if ((s->avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || + if (s->avctx->codec_id != AV_CODEC_ID_SMVJPEG && + (s->avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || s->avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) && s->orig_height < height) s->avctx->height = AV_CEIL_RSHIFT(s->orig_height, s->avctx->lowres); @@ -2927,7 +2928,8 @@ the_end: return ret; } } - if ((avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || + if (avctx->codec_id != AV_CODEC_ID_SMVJPEG && + (avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) && avctx->coded_height > s->orig_height) { frame->height = AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres); -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH 2/5] avcodec/mjpegdec: Move special SMVJPEG-code to SMVJPEG-only function 2022-12-07 19:00 [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG Andreas Rheinhardt @ 2022-12-07 19:02 ` Andreas Rheinhardt 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 3/5] avcodec/mjpegdec: Avoid checks whose results are known at compile-time Andreas Rheinhardt ` (4 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: Andreas Rheinhardt @ 2022-12-07 19:02 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Andreas Rheinhardt This automatically avoids runtime checks for whether the decoder is SMVJPEG. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/mjpegdec.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 28e2839072..b88d2ab889 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -2422,9 +2422,6 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) s->force_pal8 = 0; - if (avctx->codec_id == AV_CODEC_ID_SMVJPEG && s->smv_next_frame > 0) - return smv_process_frame(avctx, frame); - av_dict_free(&s->exif_metadata); av_freep(&s->stereo3d); s->adobe_transform = -1; @@ -2921,13 +2918,6 @@ the_end: av_dict_copy(&frame->metadata, s->exif_metadata, 0); av_dict_free(&s->exif_metadata); - if (avctx->codec_id == AV_CODEC_ID_SMVJPEG) { - ret = smv_process_frame(avctx, frame); - if (ret < 0) { - av_frame_unref(frame); - return ret; - } - } if (avctx->codec_id != AV_CODEC_ID_SMVJPEG && (avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) && @@ -3060,6 +3050,21 @@ const FFCodec ff_thp_decoder = { #endif #if CONFIG_SMVJPEG_DECODER +static int smvjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) +{ + MJpegDecodeContext *s = avctx->priv_data; + int ret; + + if (s->smv_next_frame > 0) + return smv_process_frame(avctx, frame); + + ret = ff_mjpeg_receive_frame(avctx, frame); + if (ret < 0) + return ret; + + return smv_process_frame(avctx, frame); +} + const FFCodec ff_smvjpeg_decoder = { .p.name = "smvjpeg", CODEC_LONG_NAME("SMV JPEG"), @@ -3068,7 +3073,7 @@ const FFCodec ff_smvjpeg_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_RECEIVE_FRAME_CB(smvjpeg_receive_frame), .flush = decode_flush, .p.capabilities = AV_CODEC_CAP_DR1, .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH 3/5] avcodec/mjpegdec: Avoid checks whose results are known at compile-time 2022-12-07 19:00 [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG Andreas Rheinhardt 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 2/5] avcodec/mjpegdec: Move special SMVJPEG-code to SMVJPEG-only function Andreas Rheinhardt @ 2022-12-07 19:02 ` Andreas Rheinhardt 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 4/5] avcodec/mjpegdec: Only use receive_frame for SMVJPEG Andreas Rheinhardt ` (3 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: Andreas Rheinhardt @ 2022-12-07 19:02 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Andreas Rheinhardt Namely the result of the check for smv_next_frame > 0 in smv_process_frame(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/mjpegdec.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index b88d2ab889..2abc42a082 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -2349,24 +2349,9 @@ static void reset_icc_profile(MJpegDecodeContext *s) // SMV JPEG just stacks several output frames into one JPEG picture // we handle that by setting up the cropping parameters appropriately -static int smv_process_frame(AVCodecContext *avctx, AVFrame *frame) +static void smv_process_frame(AVCodecContext *avctx, AVFrame *frame) { MJpegDecodeContext *s = avctx->priv_data; - int ret; - - if (s->smv_next_frame > 0) { - av_assert0(s->smv_frame->buf[0]); - av_frame_unref(frame); - ret = av_frame_ref(frame, s->smv_frame); - if (ret < 0) - return ret; - } else { - av_assert0(frame->buf[0]); - av_frame_unref(s->smv_frame); - ret = av_frame_ref(s->smv_frame, frame); - if (ret < 0) - return ret; - } av_assert0((s->smv_next_frame + 1) * avctx->height <= avctx->coded_height); @@ -2379,8 +2364,6 @@ static int smv_process_frame(AVCodecContext *avctx, AVFrame *frame) if (s->smv_next_frame == 0) av_frame_unref(s->smv_frame); - - return 0; } static int mjpeg_get_packet(AVCodecContext *avctx) @@ -3055,14 +3038,28 @@ static int smvjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) MJpegDecodeContext *s = avctx->priv_data; int ret; - if (s->smv_next_frame > 0) - return smv_process_frame(avctx, frame); + if (s->smv_next_frame > 0) { + av_assert0(s->smv_frame->buf[0]); + ret = av_frame_ref(frame, s->smv_frame); + if (ret < 0) + return ret; + + smv_process_frame(avctx, frame); + return 0; + } ret = ff_mjpeg_receive_frame(avctx, frame); if (ret < 0) return ret; - return smv_process_frame(avctx, frame); + av_assert0(frame->buf[0]); + av_frame_unref(s->smv_frame); + ret = av_frame_ref(s->smv_frame, frame); + if (ret < 0) + return ret; + + smv_process_frame(avctx, frame); + return 0; } const FFCodec ff_smvjpeg_decoder = { -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH 4/5] avcodec/mjpegdec: Only use receive_frame for SMVJPEG 2022-12-07 19:00 [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG Andreas Rheinhardt 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 2/5] avcodec/mjpegdec: Move special SMVJPEG-code to SMVJPEG-only function Andreas Rheinhardt 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 3/5] avcodec/mjpegdec: Avoid checks whose results are known at compile-time Andreas Rheinhardt @ 2022-12-07 19:02 ` Andreas Rheinhardt 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 5/5] avcodec/mjpegdec: Move smv_process_frame() to other SMV stuff Andreas Rheinhardt ` (2 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: Andreas Rheinhardt @ 2022-12-07 19:02 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Andreas Rheinhardt 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> --- Weird that these receive_frame decoders have FF_CODEC_CAP_SETS_PKT_DTS set, despite this flag only being used for decode_frame decoders. libavcodec/jpeglsdec.c | 5 ++- libavcodec/mjpegdec.c | 80 ++++++++++++++++++------------------------ libavcodec/mjpegdec.h | 11 +++--- libavcodec/sp5xdec.c | 32 ++++++++--------- 4 files changed, 59 insertions(+), 69 deletions(-) diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c index 2e6d018ea6..ec163b8964 100644 --- a/libavcodec/jpeglsdec.c +++ b/libavcodec/jpeglsdec.c @@ -558,8 +558,7 @@ const FFCodec ff_jpegls_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(ff_mjpeg_decode_frame), .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, }; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 2abc42a082..aa1a6b5208 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -131,8 +131,6 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) s->picture_ptr = s->picture; } - s->pkt = avctx->internal->in_pkt; - s->avctx = avctx; ff_blockdsp_init(&s->bdsp); ff_hpeldsp_init(&s->hdsp, avctx->flags); @@ -2366,31 +2364,9 @@ static void smv_process_frame(AVCodecContext *avctx, AVFrame *frame) av_frame_unref(s->smv_frame); } -static int mjpeg_get_packet(AVCodecContext *avctx) -{ - MJpegDecodeContext *s = avctx->priv_data; - int ret; - - av_packet_unref(s->pkt); - ret = ff_decode_get_packet(avctx, s->pkt); - if (ret < 0) - return ret; - -#if CONFIG_SP5X_DECODER || CONFIG_AMV_DECODER - if (avctx->codec_id == AV_CODEC_ID_SP5X || - avctx->codec_id == AV_CODEC_ID_AMV) { - ret = ff_sp5x_process_packet(avctx, s->pkt); - if (ret < 0) - return ret; - } -#endif - - s->buf_size = s->pkt->size; - - return 0; -} - -int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) +int ff_mjpeg_decode_frame_from_buf(AVCodecContext *avctx, AVFrame *frame, + int *got_frame, const AVPacket *avpkt, + const uint8_t *buf, const int buf_size) { MJpegDecodeContext *s = avctx->priv_data; const uint8_t *buf_end, *buf_ptr; @@ -2405,6 +2381,8 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) s->force_pal8 = 0; + s->buf_size = buf_size; + av_dict_free(&s->exif_metadata); av_freep(&s->stereo3d); s->adobe_transform = -1; @@ -2412,12 +2390,9 @@ int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) if (s->iccnum != 0) reset_icc_profile(s); - ret = mjpeg_get_packet(avctx); - if (ret < 0) - return ret; redo_for_pal8: - buf_ptr = s->pkt->data; - buf_end = s->pkt->data + s->pkt->size; + buf_ptr = buf; + buf_end = buf + buf_size; while (buf_ptr < buf_end) { /* find start next marker */ start_code = ff_mjpeg_find_marker(s, &buf_ptr, buf_end, @@ -2429,7 +2404,7 @@ redo_for_pal8: } else if (unescaped_buf_size > INT_MAX / 8) { av_log(avctx, AV_LOG_ERROR, "MJPEG packet 0x%x too big (%d/%d), corrupt data?\n", - start_code, unescaped_buf_size, s->pkt->size); + start_code, unescaped_buf_size, buf_size); return AVERROR_INVALIDDATA; } av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%"PTRDIFF_SPECIFIER"\n", @@ -2568,7 +2543,6 @@ eoi_parser: } if (avctx->skip_frame == AVDISCARD_ALL) { s->got_picture = 0; - ret = AVERROR(EAGAIN); goto the_end_no_picture; } if (s->avctx->hwaccel) { @@ -2580,10 +2554,9 @@ eoi_parser: } if ((ret = av_frame_ref(frame, s->picture_ptr)) < 0) return ret; + *got_frame = 1; s->got_picture = 0; - frame->pkt_dts = s->pkt->dts; - if (!s->lossless && avctx->debug & FF_DEBUG_QP) { int qp = FFMAX3(s->qscale[0], s->qscale[1], @@ -2909,15 +2882,20 @@ the_end: frame->crop_top = frame->height - avctx->height; } - ret = 0; - the_end_no_picture: av_log(avctx, AV_LOG_DEBUG, "decode frame unused %"PTRDIFF_SPECIFIER" bytes\n", buf_end - buf_ptr); + return buf_ptr - buf; +} - return ret; +int ff_mjpeg_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, + AVPacket *avpkt) +{ + return ff_mjpeg_decode_frame_from_buf(avctx, frame, got_frame, + avpkt, avpkt->data, avpkt->size); } + /* mxpeg may call the following function (with a blank MJpegDecodeContext) * even without having called ff_mjpeg_decode_init(). */ av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx) @@ -2993,7 +2971,7 @@ const FFCodec ff_mjpeg_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(ff_mjpeg_decode_frame), .flush = decode_flush, .p.capabilities = AV_CODEC_CAP_DR1, .p.max_lowres = 3, @@ -3001,7 +2979,6 @@ const FFCodec ff_mjpeg_decoder = { .p.profiles = NULL_IF_CONFIG_SMALL(ff_mjpeg_profiles), .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | - FF_CODEC_CAP_SETS_PKT_DTS | FF_CODEC_CAP_ICC_PROFILES, .hw_configs = (const AVCodecHWConfigInternal *const []) { #if CONFIG_MJPEG_NVDEC_HWACCEL @@ -3023,12 +3000,11 @@ const FFCodec ff_thp_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(ff_mjpeg_decode_frame), .flush = decode_flush, .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 @@ -3036,6 +3012,9 @@ const FFCodec ff_thp_decoder = { static int smvjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) { MJpegDecodeContext *s = avctx->priv_data; + AVPacket *const pkt = avctx->internal->in_pkt; + int64_t pkt_dts; + int got_frame = 0; int ret; if (s->smv_next_frame > 0) { @@ -3048,10 +3027,21 @@ static int smvjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) return 0; } - ret = ff_mjpeg_receive_frame(avctx, frame); + ret = ff_decode_get_packet(avctx, pkt); + if (ret < 0) + return ret; + + ret = ff_mjpeg_decode_frame(avctx, frame, &got_frame, pkt); + pkt_dts = pkt->dts; + av_packet_unref(pkt); if (ret < 0) return ret; + if (!got_frame) + return AVERROR(EAGAIN); + + frame->pkt_dts = pkt_dts; + av_assert0(frame->buf[0]); av_frame_unref(s->smv_frame); ret = av_frame_ref(s->smv_frame, frame); diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index 2cb218902c..13c524d597 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -57,8 +57,6 @@ typedef struct MJpegDecodeContext { GetBitContext gb; int buf_size; - AVPacket *pkt; - int start_code; /* current start code */ int buffer_size; uint8_t *buffer; @@ -173,7 +171,12 @@ int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, int is_ac, void *logctx); int ff_mjpeg_decode_init(AVCodecContext *avctx); int ff_mjpeg_decode_end(AVCodecContext *avctx); -int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame); +int ff_mjpeg_decode_frame(AVCodecContext *avctx, + AVFrame *frame, int *got_frame, + AVPacket *avpkt); +int ff_mjpeg_decode_frame_from_buf(AVCodecContext *avctx, + AVFrame *frame, int *got_frame, + const AVPacket *avpkt, const uint8_t *buf, int buf_size); int ff_mjpeg_decode_dqt(MJpegDecodeContext *s); int ff_mjpeg_decode_dht(MJpegDecodeContext *s); int ff_mjpeg_decode_sof(MJpegDecodeContext *s); @@ -184,6 +187,4 @@ int ff_mjpeg_find_marker(MJpegDecodeContext *s, const uint8_t **buf_ptr, const uint8_t *buf_end, const uint8_t **unescaped_buf_ptr, int *unescaped_buf_size); -int ff_sp5x_process_packet(AVCodecContext *avctx, AVPacket *avpkt); - #endif /* AVCODEC_MJPEGDEC_H */ 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 -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH 5/5] avcodec/mjpegdec: Move smv_process_frame() to other SMV stuff 2022-12-07 19:00 [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG Andreas Rheinhardt ` (2 preceding siblings ...) 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 4/5] avcodec/mjpegdec: Only use receive_frame for SMVJPEG Andreas Rheinhardt @ 2022-12-07 19:02 ` Andreas Rheinhardt 2022-12-10 10:51 ` [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG Andreas Rheinhardt 2022-12-10 11:02 ` Paul B Mahol 5 siblings, 0 replies; 7+ messages in thread From: Andreas Rheinhardt @ 2022-12-07 19:02 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Andreas Rheinhardt Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/mjpegdec.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index aa1a6b5208..ea6f724049 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -2345,25 +2345,6 @@ static void reset_icc_profile(MJpegDecodeContext *s) s->iccnum = 0; } -// SMV JPEG just stacks several output frames into one JPEG picture -// we handle that by setting up the cropping parameters appropriately -static void smv_process_frame(AVCodecContext *avctx, AVFrame *frame) -{ - MJpegDecodeContext *s = avctx->priv_data; - - av_assert0((s->smv_next_frame + 1) * avctx->height <= avctx->coded_height); - - frame->width = avctx->coded_width; - frame->height = avctx->coded_height; - frame->crop_top = FFMIN(s->smv_next_frame * avctx->height, frame->height); - frame->crop_bottom = frame->height - (s->smv_next_frame + 1) * avctx->height; - - s->smv_next_frame = (s->smv_next_frame + 1) % s->smv_frames_per_jpeg; - - if (s->smv_next_frame == 0) - av_frame_unref(s->smv_frame); -} - int ff_mjpeg_decode_frame_from_buf(AVCodecContext *avctx, AVFrame *frame, int *got_frame, const AVPacket *avpkt, const uint8_t *buf, const int buf_size) @@ -3009,6 +2990,25 @@ const FFCodec ff_thp_decoder = { #endif #if CONFIG_SMVJPEG_DECODER +// SMV JPEG just stacks several output frames into one JPEG picture +// we handle that by setting up the cropping parameters appropriately +static void smv_process_frame(AVCodecContext *avctx, AVFrame *frame) +{ + MJpegDecodeContext *s = avctx->priv_data; + + av_assert0((s->smv_next_frame + 1) * avctx->height <= avctx->coded_height); + + frame->width = avctx->coded_width; + frame->height = avctx->coded_height; + frame->crop_top = FFMIN(s->smv_next_frame * avctx->height, frame->height); + frame->crop_bottom = frame->height - (s->smv_next_frame + 1) * avctx->height; + + s->smv_next_frame = (s->smv_next_frame + 1) % s->smv_frames_per_jpeg; + + if (s->smv_next_frame == 0) + av_frame_unref(s->smv_frame); +} + static int smvjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame) { MJpegDecodeContext *s = avctx->priv_data; -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG 2022-12-07 19:00 [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG Andreas Rheinhardt ` (3 preceding siblings ...) 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 5/5] avcodec/mjpegdec: Move smv_process_frame() to other SMV stuff Andreas Rheinhardt @ 2022-12-10 10:51 ` Andreas Rheinhardt 2022-12-10 11:02 ` Paul B Mahol 5 siblings, 0 replies; 7+ messages in thread From: Andreas Rheinhardt @ 2022-12-10 10:51 UTC (permalink / raw) To: ffmpeg-devel Andreas Rheinhardt: > AVID content is not supposed to be SMVJPEG; given that > both these codecs involve manipulating image dimensions > and cropping dimensions, it makes sense to restrict > the AVID codepaths to non-SMVJPEG codecs in order not > to have to think about what if SMVJPEG happens to > have a codec tag indicating AVID. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> > --- > libavcodec/mjpegdec.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c > index 9b7465abe7..28e2839072 100644 > --- a/libavcodec/mjpegdec.c > +++ b/libavcodec/mjpegdec.c > @@ -452,7 +452,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) > if (ret < 0) > return ret; > > - if ((s->avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || > + if (s->avctx->codec_id != AV_CODEC_ID_SMVJPEG && > + (s->avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || > s->avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) && > s->orig_height < height) > s->avctx->height = AV_CEIL_RSHIFT(s->orig_height, s->avctx->lowres); > @@ -2927,7 +2928,8 @@ the_end: > return ret; > } > } > - if ((avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || > + if (avctx->codec_id != AV_CODEC_ID_SMVJPEG && > + (avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || > avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) && > avctx->coded_height > s->orig_height) { > frame->height = AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres); Will apply this patchset tonight unless there are objections. - Andreas _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG 2022-12-07 19:00 [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG Andreas Rheinhardt ` (4 preceding siblings ...) 2022-12-10 10:51 ` [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG Andreas Rheinhardt @ 2022-12-10 11:02 ` Paul B Mahol 5 siblings, 0 replies; 7+ messages in thread From: Paul B Mahol @ 2022-12-10 11:02 UTC (permalink / raw) To: FFmpeg development discussions and patches; +Cc: Andreas Rheinhardt On 12/7/22, Andreas Rheinhardt <andreas.rheinhardt@outlook.com> wrote: > AVID content is not supposed to be SMVJPEG; given that > both these codecs involve manipulating image dimensions > and cropping dimensions, it makes sense to restrict > the AVID codepaths to non-SMVJPEG codecs in order not > to have to think about what if SMVJPEG happens to > have a codec tag indicating AVID. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> > --- > libavcodec/mjpegdec.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c > index 9b7465abe7..28e2839072 100644 > --- a/libavcodec/mjpegdec.c > +++ b/libavcodec/mjpegdec.c > @@ -452,7 +452,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) > if (ret < 0) > return ret; > > - if ((s->avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || > + if (s->avctx->codec_id != AV_CODEC_ID_SMVJPEG && > + (s->avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || > s->avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) && > s->orig_height < height) > s->avctx->height = AV_CEIL_RSHIFT(s->orig_height, > s->avctx->lowres); > @@ -2927,7 +2928,8 @@ the_end: > return ret; > } > } > - if ((avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || > + if (avctx->codec_id != AV_CODEC_ID_SMVJPEG && > + (avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') || > avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) && > avctx->coded_height > s->orig_height) { > frame->height = AV_CEIL_RSHIFT(avctx->coded_height, > avctx->lowres); > -- > 2.34.1 > LGTM > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-12-10 11:02 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-12-07 19:00 [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG Andreas Rheinhardt 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 2/5] avcodec/mjpegdec: Move special SMVJPEG-code to SMVJPEG-only function Andreas Rheinhardt 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 3/5] avcodec/mjpegdec: Avoid checks whose results are known at compile-time Andreas Rheinhardt 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 4/5] avcodec/mjpegdec: Only use receive_frame for SMVJPEG Andreas Rheinhardt 2022-12-07 19:02 ` [FFmpeg-devel] [PATCH 5/5] avcodec/mjpegdec: Move smv_process_frame() to other SMV stuff Andreas Rheinhardt 2022-12-10 10:51 ` [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG Andreas Rheinhardt 2022-12-10 11:02 ` Paul B Mahol
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git