diff mbox series

[FFmpeg-devel,3/3] avformat/evc: Don't cast const away, avoid loop

Message ID GV1P250MB07372FE0CA7FD69EEA802C9D8F2CA@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit e52676e20b387dae8e338bbf191729ce029fab7e
Headers show
Series [FFmpeg-devel,1/3] avformat/evcdec: Avoid nonsense casts | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt July 6, 2023, 9:08 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/evc.h | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/evc.h b/libavformat/evc.h
index 46b27f7df7..f30831257d 100644
--- a/libavformat/evc.h
+++ b/libavformat/evc.h
@@ -23,16 +23,17 @@ 
 #define AVFORMAT_EVC_H
 
 #include <stdint.h>
+
+#include "libavutil/intreadwrite.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)
+static inline int evc_get_nalu_type(const uint8_t *p, 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;
@@ -46,16 +47,10 @@  static inline int evc_get_nalu_type(const uint8_t *bits, int bits_size)
 
 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];
-    }
+    if (bits_size >= EVC_NALU_LENGTH_PREFIX_SIZE)
+        return AV_RB32(bits);
 
-    return nalu_len;
+    return 0;
 }
 
 /**