[FFmpeg-devel] [PATCH 12/17] avformat/evcdec: deduplicate nalu length and type parsing functions
James Almer
jamrial at gmail.com
Mon Jun 19 02:43:27 EEST 2023
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavformat/evcdec.c | 46 ++++----------------------------------------
1 file changed, 4 insertions(+), 42 deletions(-)
diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index 807406885a..0f17edd371 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -20,10 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "libavcodec/get_bits.h"
-#include "libavcodec/golomb.h"
#include "libavcodec/internal.h"
#include "libavcodec/evc.h"
+#include "libavcodec/evc_parse.h"
#include "libavcodec/bsf.h"
#include "libavutil/opt.h"
@@ -66,43 +65,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 parse_nal_units(const AVProbeData *p, EVCParserContext *ev)
{
int nalu_type;
@@ -112,7 +74,7 @@ static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev)
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, NULL);
if (nalu_size == 0) break;
bits += EVC_NALU_LENGTH_PREFIX_SIZE;
@@ -120,7 +82,7 @@ static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev)
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, NULL);
if (nalu_type == EVC_SPS_NUT)
ev->got_sps++;
@@ -218,7 +180,7 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
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, s);
if(nalu_size <= 0) {
av_packet_unref(pkt);
return -1;
--
2.41.0
More information about the ffmpeg-devel
mailing list