h264: refactor NAL decode loop
Write out the NAL decoding loops in full so that they are easier to parse for a preprocessor without it having to be aware of macros or other such things in C code. This also makes the code more readable. Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
This commit is contained in:
parent
08cd95e8a3
commit
58db34aa1e
@ -175,42 +175,50 @@ const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src,
|
|||||||
src++;
|
src++;
|
||||||
length--;
|
length--;
|
||||||
|
|
||||||
|
#define STARTCODE_TEST \
|
||||||
|
if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
|
||||||
|
if (src[i + 2] != 3) { \
|
||||||
|
/* startcode, so we must be past the end */ \
|
||||||
|
length = i; \
|
||||||
|
} \
|
||||||
|
break; \
|
||||||
|
}
|
||||||
#if HAVE_FAST_UNALIGNED
|
#if HAVE_FAST_UNALIGNED
|
||||||
|
#define FIND_FIRST_ZERO \
|
||||||
|
if (i > 0 && !src[i]) \
|
||||||
|
i--; \
|
||||||
|
while (src[i]) \
|
||||||
|
i++
|
||||||
#if HAVE_FAST_64BIT
|
#if HAVE_FAST_64BIT
|
||||||
#define RS 7
|
|
||||||
for (i = 0; i + 1 < length; i += 9) {
|
for (i = 0; i + 1 < length; i += 9) {
|
||||||
if (!((~AV_RN64A(src + i) &
|
if (!((~AV_RN64A(src + i) &
|
||||||
(AV_RN64A(src + i) - 0x0100010001000101ULL)) &
|
(AV_RN64A(src + i) - 0x0100010001000101ULL)) &
|
||||||
0x8000800080008080ULL))
|
0x8000800080008080ULL))
|
||||||
|
continue;
|
||||||
|
FIND_FIRST_ZERO;
|
||||||
|
STARTCODE_TEST;
|
||||||
|
i -= 7;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#define RS 3
|
|
||||||
for (i = 0; i + 1 < length; i += 5) {
|
for (i = 0; i + 1 < length; i += 5) {
|
||||||
if (!((~AV_RN32A(src + i) &
|
if (!((~AV_RN32A(src + i) &
|
||||||
(AV_RN32A(src + i) - 0x01000101U)) &
|
(AV_RN32A(src + i) - 0x01000101U)) &
|
||||||
0x80008080U))
|
0x80008080U))
|
||||||
#endif
|
|
||||||
continue;
|
continue;
|
||||||
if (i > 0 && !src[i])
|
FIND_FIRST_ZERO;
|
||||||
i--;
|
STARTCODE_TEST;
|
||||||
while (src[i])
|
i -= 3;
|
||||||
i++;
|
}
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#define RS 0
|
|
||||||
for (i = 0; i + 1 < length; i += 2) {
|
for (i = 0; i + 1 < length; i += 2) {
|
||||||
if (src[i])
|
if (src[i])
|
||||||
continue;
|
continue;
|
||||||
if (i > 0 && src[i - 1] == 0)
|
if (i > 0 && src[i - 1] == 0)
|
||||||
i--;
|
i--;
|
||||||
#endif
|
STARTCODE_TEST;
|
||||||
if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) {
|
|
||||||
if (src[i + 2] != 3) {
|
|
||||||
/* startcode, so we must be past the end */
|
|
||||||
length = i;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i -= RS;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (i >= length - 1) { // no escaped 0
|
if (i >= length - 1) { // no escaped 0
|
||||||
*dst_length = length;
|
*dst_length = length;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user