summaryrefslogtreecommitdiff
path: root/libavcodec/h264_parser.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2016-03-21 15:38:31 +0100
committerAnton Khirnov <anton@khirnov.net>2016-04-24 10:06:23 +0200
commit8d0cc8ca97678f4ca87948ebabcbaab5a4f4c1f6 (patch)
tree0a3ba3db5a734025e0b718b4457be3ee10d4ae07 /libavcodec/h264_parser.c
parentf3ed484953b81856e40239d2410058a96188b2be (diff)
h264_parser: switch to h2645_parse for NAL unescaping
Remove now unused ff_h264_decode_nal().
Diffstat (limited to 'libavcodec/h264_parser.c')
-rw-r--r--libavcodec/h264_parser.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index b5ccce3425..bcbaf1a2ce 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -195,11 +195,14 @@ static inline int parse_nal_units(AVCodecParserContext *s,
H264Context *h = &p->h;
H264SliceContext *sl = &h->slice_ctx[0];
const uint8_t *buf_end = buf + buf_size;
+
+ H2645NAL nal = { NULL };
+
unsigned int pps_id;
unsigned int slice_type;
int state = -1, got_reset = 0;
- const uint8_t *ptr;
int field_poc[2];
+ int ret;
/* set some sane default values */
s->pict_type = AV_PICTURE_TYPE_I;
@@ -213,7 +216,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
return 0;
for (;;) {
- int src_length, dst_length, consumed;
+ int src_length, consumed;
buf = avpriv_find_start_code(buf, buf_end, &state);
if (buf >= buf_end)
break;
@@ -235,11 +238,22 @@ static inline int parse_nal_units(AVCodecParserContext *s,
}
break;
}
- ptr = ff_h264_decode_nal(h, sl, buf, &dst_length, &consumed, src_length);
- if (!ptr || dst_length < 0)
+
+ consumed = ff_h2645_extract_rbsp(buf, src_length, &nal);
+ if (consumed < 0)
break;
- init_get_bits(&h->gb, ptr, 8 * dst_length);
+ ret = init_get_bits(&nal.gb, nal.data, nal.size * 8);
+ if (ret < 0)
+ goto fail;
+ get_bits1(&nal.gb);
+ nal.ref_idc = get_bits(&nal.gb, 2);
+ nal.type = get_bits(&nal.gb, 5);
+
+ h->gb = nal.gb;
+ h->nal_ref_idc = nal.ref_idc;
+ h->nal_unit_type = nal.type;
+
switch (h->nal_unit_type) {
case NAL_SPS:
ff_h264_decode_seq_parameter_set(h);
@@ -259,7 +273,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
h->prev_poc_lsb = 0;
/* fall through */
case NAL_SLICE:
- init_get_bits(&sl->gb, ptr, 8 * dst_length);
+ sl->gb = nal.gb;
get_ue_golomb(&sl->gb); // skip first_mb_in_slice
slice_type = get_ue_golomb_31(&sl->gb);
s->pict_type = ff_h264_golomb_to_pict_type[slice_type % 5];
@@ -271,18 +285,18 @@ static inline int parse_nal_units(AVCodecParserContext *s,
if (pps_id >= MAX_PPS_COUNT) {
av_log(h->avctx, AV_LOG_ERROR,
"pps_id %u out of range\n", pps_id);
- return -1;
+ goto fail;
}
if (!h->pps_buffers[pps_id]) {
av_log(h->avctx, AV_LOG_ERROR,
"non-existing PPS %u referenced\n", pps_id);
- return -1;
+ goto fail;
}
h->pps = *h->pps_buffers[pps_id];
if (!h->sps_buffers[h->pps.sps_id]) {
av_log(h->avctx, AV_LOG_ERROR,
"non-existing SPS %u referenced\n", h->pps.sps_id);
- return -1;
+ goto fail;
}
h->sps = *h->sps_buffers[h->pps.sps_id];
h->frame_num = get_bits(&sl->gb, h->sps.log2_max_frame_num);
@@ -360,7 +374,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
if (h->nal_ref_idc && h->nal_unit_type != NAL_IDR_SLICE) {
got_reset = scan_mmco_reset(s);
if (got_reset < 0)
- return got_reset;
+ goto fail;
}
/* Set up the prev_ values for decoding POC of the next picture. */
@@ -438,12 +452,15 @@ static inline int parse_nal_units(AVCodecParserContext *s,
s->field_order = AV_FIELD_UNKNOWN;
}
+ av_freep(&nal.rbsp_buffer);
return 0; /* no need to evaluate the rest */
}
buf += consumed;
}
/* didn't find a picture! */
av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit\n");
+fail:
+ av_freep(&nal.rbsp_buffer);
return -1;
}