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 9/9] avformat/evc: move NALU length and type parsing functions to a header
Date: Tue, 20 Jun 2023 11:40:42 -0300
Message-ID: <20230620144042.9629-9-jamrial@gmail.com> (raw)
In-Reply-To: <20230620144042.9629-1-jamrial@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/evc.c    |  5 ++---
 libavformat/evc.h    | 30 ++++++++++++++++++++++++++++++
 libavformat/evcdec.c | 44 ++++----------------------------------------
 3 files changed, 36 insertions(+), 43 deletions(-)

diff --git a/libavformat/evc.c b/libavformat/evc.c
index 421ff84cb7..f6e53aa6cf 100644
--- a/libavformat/evc.c
+++ b/libavformat/evc.c
@@ -23,7 +23,6 @@
 #include "libavcodec/get_bits.h"
 #include "libavcodec/golomb.h"
 #include "libavcodec/evc.h"
-#include "libavcodec/evc_parse.h"
 #include "avformat.h"
 #include "avio.h"
 #include "evc.h"
@@ -361,7 +360,7 @@ int ff_isom_write_evcc(AVIOContext *pb, const uint8_t *data,
     evcc_init(&evcc);
 
     while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) {
-        nalu_size = evc_read_nal_unit_length(data, EVC_NALU_LENGTH_PREFIX_SIZE, pb);
+        nalu_size = evc_read_nal_unit_length(data, EVC_NALU_LENGTH_PREFIX_SIZE);
         if (nalu_size == 0) break;
 
         data += EVC_NALU_LENGTH_PREFIX_SIZE;
@@ -369,7 +368,7 @@ int ff_isom_write_evcc(AVIOContext *pb, const uint8_t *data,
 
         if (bytes_to_read < nalu_size) break;
 
-        nalu_type = evc_get_nalu_type(data, bytes_to_read, pb);
+        nalu_type = evc_get_nalu_type(data, bytes_to_read);
         if (nalu_type < EVC_NOIDR_NUT || nalu_type > EVC_UNSPEC_NUT62) {
             ret = AVERROR_INVALIDDATA;
             goto end;
diff --git a/libavformat/evc.h b/libavformat/evc.h
index db56275fd8..46b27f7df7 100644
--- a/libavformat/evc.h
+++ b/libavformat/evc.h
@@ -24,9 +24,39 @@
 
 #include <stdint.h>
 #include "libavutil/rational.h"
+#include "libavcodec/evc.h"
 #include "avio.h"
 
+static inline int evc_get_nalu_type(const uint8_t *bits, int bits_size)
+{
+    int unit_type_plus1 = 0;
 
+    if (bits_size >= EVC_NALU_HEADER_SIZE) {
+        unsigned char *p = (unsigned char *)bits;
+        // forbidden_zero_bit
+        if ((p[0] & 0x80) != 0)   // Cannot get bitstream information. Malformed bitstream.
+            return -1;
+
+        // nal_unit_type
+        unit_type_plus1 = (p[0] >> 1) & 0x3F;
+    }
+
+    return unit_type_plus1 - 1;
+}
+
+static inline uint32_t evc_read_nal_unit_length(const uint8_t *bits, int bits_size)
+{
+    uint32_t nalu_len = 0;
+
+    if (bits_size >= EVC_NALU_LENGTH_PREFIX_SIZE) {
+        unsigned char *p = (unsigned char *)bits;
+
+        for (int i = 0; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++)
+            nalu_len = (nalu_len << 8) | p[i];
+    }
+
+    return nalu_len;
+}
 
 /**
  * Writes EVC sample metadata to the provided AVIOContext.
diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index ef743028ae..73aab6c52f 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -31,6 +31,7 @@
 #include "rawdec.h"
 #include "avformat.h"
 #include "avio_internal.h"
+#include "evc.h"
 #include "internal.h"
 
 
@@ -59,43 +60,6 @@ static const AVClass evc_demuxer_class = {
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
-static int get_nalu_type(const uint8_t *bits, int bits_size)
-{
-    int unit_type_plus1 = 0;
-
-    if (bits_size >= EVC_NALU_HEADER_SIZE) {
-        unsigned char *p = (unsigned char *)bits;
-        // forbidden_zero_bit
-        if ((p[0] & 0x80) != 0)   // Cannot get bitstream information. Malformed bitstream.
-            return -1;
-
-        // nal_unit_type
-        unit_type_plus1 = (p[0] >> 1) & 0x3F;
-    }
-
-    return unit_type_plus1 - 1;
-}
-
-static uint32_t read_nal_unit_length(const uint8_t *bits, int bits_size)
-{
-    uint32_t nalu_len = 0;
-
-    if (bits_size >= EVC_NALU_LENGTH_PREFIX_SIZE) {
-
-        int t = 0;
-        unsigned char *p = (unsigned char *)bits;
-
-        for (int i = 0; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++)
-            t = (t << 8) | p[i];
-
-        nalu_len = t;
-        if (nalu_len == 0)   // Invalid bitstream size
-            return 0;
-    }
-
-    return nalu_len;
-}
-
 static int annexb_probe(const AVProbeData *p)
 {
     int nalu_type;
@@ -106,7 +70,7 @@ static int annexb_probe(const AVProbeData *p)
 
     while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) {
 
-        nalu_size = read_nal_unit_length(bits, EVC_NALU_LENGTH_PREFIX_SIZE);
+        nalu_size = evc_read_nal_unit_length(bits, EVC_NALU_LENGTH_PREFIX_SIZE);
         if (nalu_size == 0) break;
 
         bits += EVC_NALU_LENGTH_PREFIX_SIZE;
@@ -114,7 +78,7 @@ static int annexb_probe(const AVProbeData *p)
 
         if(bytes_to_read < nalu_size) break;
 
-        nalu_type = get_nalu_type(bits, bytes_to_read);
+        nalu_type = evc_get_nalu_type(bits, bytes_to_read);
 
         if (nalu_type == EVC_SPS_NUT)
             got_sps++;
@@ -199,7 +163,7 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
         if (ret < 0)
             return ret;
 
-        nalu_size = read_nal_unit_length((const uint8_t *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE);
+        nalu_size = evc_read_nal_unit_length((const uint8_t *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE);
         if (!nalu_size || nalu_size > INT_MAX)
             return AVERROR_INVALIDDATA;
 
-- 
2.41.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".

  parent reply	other threads:[~2023-06-20 14:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-20 14:40 [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 2/9] avformat/evcdec: remove unnecessary av_packet_unref() calls James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 3/9] avformat/evcdec: flush the bsf on EOF James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 4/9] avformat/evcdec: use an unsigned type for nalu_size James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 5/9] avcodec/evc_ps: pass a GetBitContext to the SPS and PPS parsing functions James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 6/9] avcodec/evc_parse: pass a GetBitContext to the slice header parsing function James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 7/9] avcodec/evc_frame_merge: use a GetBitContext to parse entire NALUs James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 8/9] avcodec/evc_parser: " James Almer
2023-06-20 14:40 ` James Almer [this message]
2023-06-21 16:31 ` [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback James Almer

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=20230620144042.9629-9-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