From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 5/5] avcodec/mjpegbdec: Don't use GetBit-API for byte-aligned reads
Date: Thu, 14 Apr 2022 17:57:40 +0200
Message-ID: <AS8PR01MB79447404943B21E726217FEE8FEF9@AS8PR01MB7944.eurprd01.prod.exchangelabs.com> (raw)
In-Reply-To: <AS8PR01MB7944E105BE990A5D01EF89208FEF9@AS8PR01MB7944.eurprd01.prod.exchangelabs.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mjpegbdec.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/libavcodec/mjpegbdec.c b/libavcodec/mjpegbdec.c
index 46b9eb377e..50fff2562b 100644
--- a/libavcodec/mjpegbdec.c
+++ b/libavcodec/mjpegbdec.c
@@ -27,12 +27,15 @@
#include <inttypes.h>
#include "avcodec.h"
+#include "bytestream.h"
#include "codec_internal.h"
#include "mjpeg.h"
#include "mjpegdec.h"
-static uint32_t read_offs(AVCodecContext *avctx, GetBitContext *gb, uint32_t size, const char *err_msg){
- uint32_t offs= get_bits_long(gb, 32);
+static uint32_t read_offs(AVCodecContext *avctx, GetByteContext *gb,
+ uint32_t size, const char *err_msg)
+{
+ uint32_t offs = bytestream2_get_be32u(gb);
if(offs >= size){
av_log(avctx, AV_LOG_WARNING, err_msg, offs, size);
return 0;
@@ -47,7 +50,7 @@ static int mjpegb_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
int buf_size = avpkt->size;
MJpegDecodeContext *s = avctx->priv_data;
const uint8_t *buf_end, *buf_ptr;
- GetBitContext hgb; /* for the header */
+ GetByteContext hgb; /* for the header */
uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs;
uint32_t field_size, sod_offs;
int ret;
@@ -64,21 +67,22 @@ read_header:
s->restart_count = 0;
s->mjpb_skiptosod = 0;
- if (buf_end - buf_ptr >= 1 << 28)
+ if (buf_end - buf_ptr >= 1 << 28 ||
+ buf_end - buf_ptr < 40 /* header size */)
return AVERROR_INVALIDDATA;
- init_get_bits(&hgb, buf_ptr, /*buf_size*/(buf_end - buf_ptr)*8);
+ bytestream2_init(&hgb, buf_ptr, buf_end - buf_ptr);
- skip_bits(&hgb, 32); /* reserved zeros */
+ bytestream2_skipu(&hgb, 4); /* reserved zeros */
- if (get_bits_long(&hgb, 32) != MKBETAG('m','j','p','g')) {
+ if (bytestream2_get_be32u(&hgb) != MKBETAG('m','j','p','g')) {
av_log(avctx, AV_LOG_WARNING, "not mjpeg-b (bad fourcc)\n");
return AVERROR_INVALIDDATA;
}
- field_size = get_bits_long(&hgb, 32); /* field size */
+ field_size = bytestream2_get_be32u(&hgb); /* field size */
av_log(avctx, AV_LOG_DEBUG, "field size: 0x%"PRIx32"\n", field_size);
- skip_bits(&hgb, 32); /* padded field size */
+ bytestream2_skipu(&hgb, 4); /* padded field size */
second_field_offs = read_offs(avctx, &hgb, buf_end - buf_ptr, "second_field_offs is %d and size is %d\n");
av_log(avctx, AV_LOG_DEBUG, "second field offs: 0x%"PRIx32"\n",
second_field_offs);
--
2.32.0
_______________________________________________
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".
next prev parent reply other threads:[~2022-04-14 15:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-14 15:56 [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Always reset got_picture at the beginnig of decoding Andreas Rheinhardt
2022-04-14 15:57 ` [FFmpeg-devel] [PATCH 2/5] avcodec/mjpegdec: Don't create unnecessary AVFrame reference Andreas Rheinhardt
2022-04-14 16:39 ` James Almer
2022-04-14 16:43 ` Andreas Rheinhardt
2022-04-14 16:46 ` James Almer
2022-04-14 16:51 ` Andreas Rheinhardt
2022-04-14 15:57 ` [FFmpeg-devel] [PATCH 3/5] avcodec/mjpegdec: Avoid copying data when flipping image Andreas Rheinhardt
2022-04-17 12:57 ` Michael Niedermayer
2022-04-14 15:57 ` [FFmpeg-devel] [PATCH 4/5] avcodec/mjpegbdec: Don't create unnecessary AVFrame reference Andreas Rheinhardt
2022-04-14 15:57 ` Andreas Rheinhardt [this message]
2022-04-15 22:15 ` [FFmpeg-devel] [PATCH 1/5] avcodec/mjpegdec: Always reset got_picture at the beginnig of decoding Michael Niedermayer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AS8PR01MB79447404943B21E726217FEE8FEF9@AS8PR01MB7944.eurprd01.prod.exchangelabs.com \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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