summaryrefslogtreecommitdiff
path: root/libavcodec/h264.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-10-16 12:51:26 +0200
committerMichael Niedermayer <michaelni@gmx.at>2013-10-16 12:51:26 +0200
commitf7f74a37b82d7905e49aeb8beed02a9966f15ef6 (patch)
tree8dcf232b8665fd2dc9d9f8e99d83eb6bcf6ebe5b /libavcodec/h264.c
parent91248f081f343cde894a9c60624b6f4dc4581c94 (diff)
parent4baba6c813b7a1f27370e20fb1a87b05fcb39208 (diff)
Merge commit '4baba6c813b7a1f27370e20fb1a87b05fcb39208'
* commit '4baba6c813b7a1f27370e20fb1a87b05fcb39208': h264_parser: Fix POC parsing for the case where MMCO_RESET is present. Conflicts: libavcodec/h264.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/h264.c')
-rw-r--r--libavcodec/h264.c87
1 files changed, 50 insertions, 37 deletions
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index ccad9b9ff3..6d7ac58b75 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -2602,7 +2602,7 @@ void ff_h264_hl_decode_mb(H264Context *h)
hl_decode_mb_simple_8(h);
}
-static int pred_weight_table(H264Context *h)
+int ff_pred_weight_table(H264Context *h)
{
int list, i;
int luma_def, chroma_def;
@@ -3310,6 +3310,49 @@ static int h264_slice_header_init(H264Context *h, int reinit)
return 0;
}
+int ff_set_ref_count(H264Context *h)
+{
+ int num_ref_idx_active_override_flag;
+
+ // set defaults, might be overridden a few lines later
+ h->ref_count[0] = h->pps.ref_count[0];
+ h->ref_count[1] = h->pps.ref_count[1];
+
+ if (h->slice_type_nos != AV_PICTURE_TYPE_I) {
+ unsigned max[2];
+ max[0] = max[1] = h->picture_structure == PICT_FRAME ? 15 : 31;
+
+ if (h->slice_type_nos == AV_PICTURE_TYPE_B)
+ h->direct_spatial_mv_pred = get_bits1(&h->gb);
+ num_ref_idx_active_override_flag = get_bits1(&h->gb);
+
+ if (num_ref_idx_active_override_flag) {
+ h->ref_count[0] = get_ue_golomb(&h->gb) + 1;
+ if (h->slice_type_nos == AV_PICTURE_TYPE_B) {
+ h->ref_count[1] = get_ue_golomb(&h->gb) + 1;
+ } else
+ // full range is spec-ok in this case, even for frames
+ h->ref_count[1] = 1;
+ }
+
+ if (h->ref_count[0]-1 > max[0] || h->ref_count[1]-1 > max[1]){
+ av_log(h->avctx, AV_LOG_ERROR, "reference overflow %u > %u or %u > %u\n", h->ref_count[0]-1, max[0], h->ref_count[1]-1, max[1]);
+ h->ref_count[0] = h->ref_count[1] = 0;
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (h->slice_type_nos == AV_PICTURE_TYPE_B)
+ h->list_count = 2;
+ else
+ h->list_count = 1;
+ } else {
+ h->list_count = 0;
+ h->ref_count[0] = h->ref_count[1] = 0;
+ }
+
+ return 0;
+}
+
/**
* Decode a slice header.
* This will also call ff_MPV_common_init() and frame_start() as needed.
@@ -3324,7 +3367,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0)
{
unsigned int first_mb_in_slice;
unsigned int pps_id;
- int num_ref_idx_active_override_flag, ret;
+ int ret;
unsigned int slice_type, tmp, i, j;
int last_pic_structure, last_pic_droppable;
int must_reinit;
@@ -3777,45 +3820,15 @@ static int decode_slice_header(H264Context *h, H264Context *h0)
if (h->pps.redundant_pic_cnt_present)
h->redundant_pic_count = get_ue_golomb(&h->gb);
- // set defaults, might be overridden a few lines later
- h->ref_count[0] = h->pps.ref_count[0];
- h->ref_count[1] = h->pps.ref_count[1];
-
- if (h->slice_type_nos != AV_PICTURE_TYPE_I) {
- unsigned max[2];
- max[0] = max[1] = h->picture_structure == PICT_FRAME ? 15 : 31;
-
- if (h->slice_type_nos == AV_PICTURE_TYPE_B)
- h->direct_spatial_mv_pred = get_bits1(&h->gb);
- num_ref_idx_active_override_flag = get_bits1(&h->gb);
-
- if (num_ref_idx_active_override_flag) {
- h->ref_count[0] = get_ue_golomb(&h->gb) + 1;
- if (h->slice_type_nos == AV_PICTURE_TYPE_B) {
- h->ref_count[1] = get_ue_golomb(&h->gb) + 1;
- } else
- // full range is spec-ok in this case, even for frames
- h->ref_count[1] = 1;
- }
-
- if (h->ref_count[0]-1 > max[0] || h->ref_count[1]-1 > max[1]){
- av_log(h->avctx, AV_LOG_ERROR, "reference overflow %u > %u or %u > %u\n", h->ref_count[0]-1, max[0], h->ref_count[1]-1, max[1]);
- h->ref_count[0] = h->ref_count[1] = 0;
- return AVERROR_INVALIDDATA;
- }
+ ret = ff_set_ref_count(h);
+ if (ret < 0)
+ return ret;
- if (h->slice_type_nos == AV_PICTURE_TYPE_B)
- h->list_count = 2;
- else
- h->list_count = 1;
- } else {
- h->list_count = 0;
- h->ref_count[0] = h->ref_count[1] = 0;
- }
if (slice_type != AV_PICTURE_TYPE_I &&
(h0->current_slice == 0 ||
slice_type != h0->last_slice_type ||
memcmp(h0->last_ref_count, h0->ref_count, sizeof(h0->ref_count)))) {
+
ff_h264_fill_default_ref_list(h);
}
@@ -3830,7 +3843,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0)
if ((h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P) ||
(h->pps.weighted_bipred_idc == 1 &&
h->slice_type_nos == AV_PICTURE_TYPE_B))
- pred_weight_table(h);
+ ff_pred_weight_table(h);
else if (h->pps.weighted_bipred_idc == 2 &&
h->slice_type_nos == AV_PICTURE_TYPE_B) {
implicit_weight_table(h, -1);