You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avcodec/h264: use avpriv_find_start_code() in h264_split()
This also allows replacing several literal numbers by named constants And it should be faster, the function is not speed relevant though as it is generally only called a few times at the streams start. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
committed by
Michael Niedermayer
parent
7d60baa8d9
commit
2a72b1664d
@@ -526,34 +526,37 @@ static int h264_parse(AVCodecParserContext *s,
|
|||||||
static int h264_split(AVCodecContext *avctx,
|
static int h264_split(AVCodecContext *avctx,
|
||||||
const uint8_t *buf, int buf_size)
|
const uint8_t *buf, int buf_size)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
uint32_t state = -1;
|
uint32_t state = -1;
|
||||||
int has_sps = 0;
|
int has_sps = 0;
|
||||||
int has_pps = 0;
|
int has_pps = 0;
|
||||||
|
const uint8_t *ptr = buf, *end = buf + buf_size;
|
||||||
|
int nalu_type;
|
||||||
|
|
||||||
for (i = 0; i <= buf_size; i++) {
|
while (ptr < end) {
|
||||||
if ((state & 0xFFFFFF1F) == 0x107)
|
ptr = avpriv_find_start_code(ptr, end, &state);
|
||||||
|
if ((state & 0xFFFFFF00) != 0x100)
|
||||||
|
break;
|
||||||
|
nalu_type = state & 0x1F;
|
||||||
|
if (nalu_type == NAL_SPS) {
|
||||||
has_sps = 1;
|
has_sps = 1;
|
||||||
if ((state & 0xFFFFFF1F) == 0x108)
|
} else if (nalu_type == NAL_PPS)
|
||||||
has_pps = 1;
|
has_pps = 1;
|
||||||
/* if ((state&0xFFFFFF1F) == 0x101 ||
|
/* else if (nalu_type == 0x01 ||
|
||||||
* (state&0xFFFFFF1F) == 0x102 ||
|
* nalu_type == 0x02 ||
|
||||||
* (state&0xFFFFFF1F) == 0x105) {
|
* nalu_type == 0x05) {
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
if ((state & 0xFFFFFF00) == 0x100 && ((state & 0xFFFFFF1F) != 0x106 || has_pps) &&
|
else if ((nalu_type != NAL_SEI || has_pps) &&
|
||||||
(state & 0xFFFFFF1F) != 0x107 && (state & 0xFFFFFF1F) != 0x108 &&
|
nalu_type != NAL_AUD && nalu_type != NAL_SPS_EXT &&
|
||||||
(state & 0xFFFFFF1F) != 0x109 && (state & 0xFFFFFF1F) != 0x10d &&
|
nalu_type != 0x0f) {
|
||||||
(state & 0xFFFFFF1F) != 0x10f) {
|
|
||||||
if (has_sps) {
|
if (has_sps) {
|
||||||
while (i > 4 && buf[i - 5] == 0)
|
while (ptr - 4 > buf && ptr[-5] == 0)
|
||||||
i--;
|
ptr--;
|
||||||
return i - 4;
|
return ptr - 4 - buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i < buf_size)
|
|
||||||
state = (state << 8) | buf[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user