diff options
author | Hendrik Leppkes <h.leppkes@gmail.com> | 2016-05-17 14:21:12 +0200 |
---|---|---|
committer | Hendrik Leppkes <h.leppkes@gmail.com> | 2016-05-17 14:21:12 +0200 |
commit | 15ad0232107496c3b12d8aaedfc3398b8cda9ee7 (patch) | |
tree | 42a4576116d4e96448468acc18386efe004a2128 /libavcodec/h264_parser.c | |
parent | a9bb4cf87d1eb68f9ed2dc971e3400b95c1a6a78 (diff) | |
parent | 8d0cc8ca97678f4ca87948ebabcbaab5a4f4c1f6 (diff) | |
download | ffmpeg-15ad0232107496c3b12d8aaedfc3398b8cda9ee7.tar.gz |
Merge commit '8d0cc8ca97678f4ca87948ebabcbaab5a4f4c1f6'
* commit '8d0cc8ca97678f4ca87948ebabcbaab5a4f4c1f6':
h264_parser: switch to h2645_parse for NAL unescaping
Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
Diffstat (limited to 'libavcodec/h264_parser.c')
-rw-r--r-- | libavcodec/h264_parser.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index c86f0324f8..6cf4a236a0 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -227,13 +227,14 @@ static inline int parse_nal_units(AVCodecParserContext *s, H264ParseContext *p = s->priv_data; H264Context *h = &p->h; H264SliceContext *sl = &h->slice_ctx[0]; + H2645NAL nal = { NULL }; int buf_index, next_avc; unsigned int pps_id; unsigned int slice_type; int state = -1, got_reset = 0; - const uint8_t *ptr; int q264 = buf_size >=4 && !memcmp("Q264", buf, 4); int field_poc[2]; + int ret; /* set some sane default values */ s->pict_type = AV_PICTURE_TYPE_I; @@ -250,7 +251,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, buf_index = 0; next_avc = h->is_avc ? 0 : buf_size; for (;;) { - int src_length, dst_length, consumed, nalsize = 0; + int src_length, consumed, nalsize = 0; if (buf_index >= next_avc) { nalsize = get_avc_nalsize(h, buf, buf_size, &buf_index); @@ -283,14 +284,23 @@ static inline int parse_nal_units(AVCodecParserContext *s, } break; } - ptr = ff_h264_decode_nal(h, sl, buf + buf_index, &dst_length, - &consumed, src_length); - if (!ptr || dst_length < 0) + consumed = ff_h2645_extract_rbsp(buf + buf_index, src_length, &nal); + if (consumed < 0) break; buf_index += consumed; - init_get_bits(&h->gb, ptr, 8 * dst_length); + ret = init_get_bits8(&nal.gb, nal.data, nal.size); + 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, 0); @@ -310,7 +320,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_long(&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]; @@ -322,18 +332,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); @@ -414,7 +424,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. */ @@ -492,13 +502,18 @@ 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 */ } } - if (q264) + if (q264) { + av_freep(&nal.rbsp_buffer); return 0; + } /* didn't find a picture! */ av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size); +fail: + av_freep(&nal.rbsp_buffer); return -1; } |