Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] avformat/oggparseflac: use the GetByteContext API
Date: Tue, 30 May 2023 19:50:43 -0300
Message-ID: <20230530225043.1928-1-jamrial@gmail.com> (raw)

All but one read are byte aligned, so there's no point in using the
GetBitContext API.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/oggparseflac.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c
index 557440d94b..f25ed9cc15 100644
--- a/libavformat/oggparseflac.c
+++ b/libavformat/oggparseflac.c
@@ -20,7 +20,7 @@
 
 #include <stdlib.h>
 #include "libavcodec/avcodec.h"
-#include "libavcodec/get_bits.h"
+#include "libavcodec/bytestream.h"
 #include "libavcodec/flac.h"
 #include "avformat.h"
 #include "internal.h"
@@ -34,31 +34,28 @@ flac_header (AVFormatContext * s, int idx)
     struct ogg *ogg = s->priv_data;
     struct ogg_stream *os = ogg->streams + idx;
     AVStream *st = s->streams[idx];
-    GetBitContext gb;
+    GetByteContext gb;
     int mdt, ret;
 
     if (os->buf[os->pstart] == 0xff)
         return 0;
 
-    ret = init_get_bits8(&gb, os->buf + os->pstart, os->psize);
-    if (ret < 0)
-        return ret;
-
-    skip_bits1(&gb); /* metadata_last */
-    mdt = get_bits(&gb, 7);
+    bytestream2_init(&gb, os->buf + os->pstart, os->psize);
+    mdt = bytestream2_get_byte(&gb) & 0x7F;
 
     if (mdt == OGG_FLAC_METADATA_TYPE_STREAMINFO) {
-        uint8_t *streaminfo_start = os->buf + os->pstart + 5 + 4 + 4 + 4;
         uint32_t samplerate;
 
-        skip_bits_long(&gb, 4*8); /* "FLAC" */
-        if(get_bits(&gb, 8) != 1) /* unsupported major version */
+        if (bytestream2_get_bytes_left(&gb) < 4 + 4 + 4 + 4 + FLAC_STREAMINFO_SIZE)
+            return AVERROR_INVALIDDATA;
+        bytestream2_skipu(&gb, 4); /* "FLAC" */
+        if (bytestream2_get_byteu(&gb) != 1) /* unsupported major version */
             return -1;
-        skip_bits(&gb, 8 + 16);   /* minor version + header count */
-        skip_bits_long(&gb, 4*8); /* "fLaC" */
+        bytestream2_skipu(&gb, 1 + 2); /* minor version + header count */
+        bytestream2_skipu(&gb, 4); /* "fLaC" */
 
         /* METADATA_BLOCK_HEADER */
-        if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE)
+        if (bytestream2_get_be32u(&gb) != FLAC_STREAMINFO_SIZE)
             return -1;
 
         st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -67,7 +64,7 @@ flac_header (AVFormatContext * s, int idx)
 
         if ((ret = ff_alloc_extradata(st->codecpar, FLAC_STREAMINFO_SIZE)) < 0)
             return ret;
-        memcpy(st->codecpar->extradata, streaminfo_start, st->codecpar->extradata_size);
+        bytestream2_get_bufferu(&gb, st->codecpar->extradata, FLAC_STREAMINFO_SIZE);
 
         samplerate = AV_RB24(st->codecpar->extradata + 10) >> 4;
         if (!samplerate)
-- 
2.40.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".

                 reply	other threads:[~2023-05-30 22:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230530225043.1928-1-jamrial@gmail.com \
    --to=jamrial@gmail.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