summaryrefslogtreecommitdiff
path: root/libavcodec/h264_parse.c
diff options
context:
space:
mode:
authorDerek Buitenhuis <derek.buitenhuis@gmail.com>2016-05-17 15:16:38 +0100
committerDerek Buitenhuis <derek.buitenhuis@gmail.com>2016-05-17 15:16:38 +0100
commit278dcec28db8f309cf202b002966f06b9d275248 (patch)
tree6858d93582c3bb46ce358961165ae4628b312bf6 /libavcodec/h264_parse.c
parent6b295bccbbf7e19d92fe7850de42885b40fe9f07 (diff)
parenta6e27f7add2698fdd89911632b570c3d0c3f2aaa (diff)
downloadffmpeg-278dcec28db8f309cf202b002966f06b9d275248.tar.gz
Merge commit 'a6e27f7add2698fdd89911632b570c3d0c3f2aaa'
* commit 'a6e27f7add2698fdd89911632b570c3d0c3f2aaa': h264: factor out parsing the reference count into a separate file Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavcodec/h264_parse.c')
-rw-r--r--libavcodec/h264_parse.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index e6cc28e42e..5153ddc586 100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@ -186,3 +186,51 @@ int ff_h264_check_intra_pred_mode(void *logctx, int top_samples_available,
return mode;
}
+
+int ff_h264_parse_ref_count(int *plist_count, int ref_count[2],
+ GetBitContext *gb, const PPS *pps,
+ int slice_type_nos, int picture_structure, void *logctx)
+{
+ int list_count;
+ int num_ref_idx_active_override_flag;
+
+ // set defaults, might be overridden a few lines later
+ ref_count[0] = pps->ref_count[0];
+ ref_count[1] = pps->ref_count[1];
+
+ if (slice_type_nos != AV_PICTURE_TYPE_I) {
+ unsigned max[2];
+ max[0] = max[1] = picture_structure == PICT_FRAME ? 15 : 31;
+
+ num_ref_idx_active_override_flag = get_bits1(gb);
+
+ if (num_ref_idx_active_override_flag) {
+ ref_count[0] = get_ue_golomb(gb) + 1;
+ if (slice_type_nos == AV_PICTURE_TYPE_B) {
+ ref_count[1] = get_ue_golomb(gb) + 1;
+ } else
+ // full range is spec-ok in this case, even for frames
+ ref_count[1] = 1;
+ }
+
+ if (ref_count[0] - 1 > max[0] || ref_count[1] - 1 > max[1]) {
+ av_log(logctx, AV_LOG_ERROR, "reference overflow %u > %u or %u > %u\n",
+ ref_count[0] - 1, max[0], ref_count[1] - 1, max[1]);
+ ref_count[0] = ref_count[1] = 0;
+ *plist_count = 0;
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (slice_type_nos == AV_PICTURE_TYPE_B)
+ list_count = 2;
+ else
+ list_count = 1;
+ } else {
+ list_count = 0;
+ ref_count[0] = ref_count[1] = 0;
+ }
+
+ *plist_count = list_count;
+
+ return 0;
+}