aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/h264.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2016-03-21 16:14:31 +0100
committerAnton Khirnov <anton@khirnov.net>2016-04-24 10:06:24 +0200
commitc8dcff0cdb17d0aa03ac729eba12d1a20f1f59c8 (patch)
treeb86b624464e77fe4d82a4ccef0b5fec64ff639c7 /libavcodec/h264.c
parent113aeee6aed35cb786a9f6d69b0cb210f498b9da (diff)
downloadffmpeg-c8dcff0cdb17d0aa03ac729eba12d1a20f1f59c8.tar.gz
h264: factor out calculating the POC count into a separate file
This will allow decoupling the parser from the decoder.
Diffstat (limited to 'libavcodec/h264.c')
-rw-r--r--libavcodec/h264.c93
1 files changed, 7 insertions, 86 deletions
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 81c1e81832..e415103a0f 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -399,7 +399,7 @@ static int h264_init_context(AVCodecContext *avctx, H264Context *h)
h->slice_context_count = 1;
h->workaround_bugs = avctx->workaround_bugs;
h->flags = avctx->flags;
- h->prev_poc_msb = 1 << 16;
+ h->poc.prev_poc_msb = 1 << 16;
h->x264_build = -1;
h->recovery_frame = -1;
h->frame_recovered = 0;
@@ -813,10 +813,10 @@ static void decode_postinit(H264Context *h, int setup_finished)
static void idr(H264Context *h)
{
ff_h264_remove_all_refs(h);
- h->prev_frame_num =
- h->prev_frame_num_offset =
- h->prev_poc_msb =
- h->prev_poc_lsb = 0;
+ h->poc.prev_frame_num =
+ h->poc.prev_frame_num_offset =
+ h->poc.prev_poc_msb =
+ h->poc.prev_poc_lsb = 0;
}
/* forget old pics after a seek */
@@ -857,85 +857,6 @@ static void flush_dpb(AVCodecContext *avctx)
h->context_initialized = 0;
}
-int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc)
-{
- const SPS *sps = h->ps.sps;
- const int max_frame_num = 1 << sps->log2_max_frame_num;
- int field_poc[2];
-
- h->frame_num_offset = h->prev_frame_num_offset;
- if (h->frame_num < h->prev_frame_num)
- h->frame_num_offset += max_frame_num;
-
- if (sps->poc_type == 0) {
- const int max_poc_lsb = 1 << sps->log2_max_poc_lsb;
-
- if (h->poc_lsb < h->prev_poc_lsb &&
- h->prev_poc_lsb - h->poc_lsb >= max_poc_lsb / 2)
- h->poc_msb = h->prev_poc_msb + max_poc_lsb;
- else if (h->poc_lsb > h->prev_poc_lsb &&
- h->prev_poc_lsb - h->poc_lsb < -max_poc_lsb / 2)
- h->poc_msb = h->prev_poc_msb - max_poc_lsb;
- else
- h->poc_msb = h->prev_poc_msb;
- field_poc[0] =
- field_poc[1] = h->poc_msb + h->poc_lsb;
- if (h->picture_structure == PICT_FRAME)
- field_poc[1] += h->delta_poc_bottom;
- } else if (sps->poc_type == 1) {
- int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
- int i;
-
- if (sps->poc_cycle_length != 0)
- abs_frame_num = h->frame_num_offset + h->frame_num;
- else
- abs_frame_num = 0;
-
- if (h->nal_ref_idc == 0 && abs_frame_num > 0)
- abs_frame_num--;
-
- expected_delta_per_poc_cycle = 0;
- for (i = 0; i < sps->poc_cycle_length; i++)
- // FIXME integrate during sps parse
- expected_delta_per_poc_cycle += sps->offset_for_ref_frame[i];
-
- if (abs_frame_num > 0) {
- int poc_cycle_cnt = (abs_frame_num - 1) / sps->poc_cycle_length;
- int frame_num_in_poc_cycle = (abs_frame_num - 1) % sps->poc_cycle_length;
-
- expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
- for (i = 0; i <= frame_num_in_poc_cycle; i++)
- expectedpoc = expectedpoc + sps->offset_for_ref_frame[i];
- } else
- expectedpoc = 0;
-
- if (h->nal_ref_idc == 0)
- expectedpoc = expectedpoc + sps->offset_for_non_ref_pic;
-
- field_poc[0] = expectedpoc + h->delta_poc[0];
- field_poc[1] = field_poc[0] + sps->offset_for_top_to_bottom_field;
-
- if (h->picture_structure == PICT_FRAME)
- field_poc[1] += h->delta_poc[1];
- } else {
- int poc = 2 * (h->frame_num_offset + h->frame_num);
-
- if (!h->nal_ref_idc)
- poc--;
-
- field_poc[0] = poc;
- field_poc[1] = poc;
- }
-
- if (h->picture_structure != PICT_BOTTOM_FIELD)
- pic_field_poc[0] = field_poc[0];
- if (h->picture_structure != PICT_TOP_FIELD)
- pic_field_poc[1] = field_poc[1];
- *pic_poc = FFMIN(pic_field_poc[0], pic_field_poc[1]);
-
- return 0;
-}
-
/**
* Compute profile from profile_idc and constraint_set?_flags.
*
@@ -1064,14 +985,14 @@ again:
break;
if (h->sei_recovery_frame_cnt >= 0 && h->recovery_frame < 0) {
- h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) &
+ h->recovery_frame = (h->poc.frame_num + h->sei_recovery_frame_cnt) &
((1 << h->ps.sps->log2_max_frame_num) - 1);
}
h->cur_pic_ptr->f->key_frame |=
(nal->type == NAL_IDR_SLICE) || (h->sei_recovery_frame_cnt >= 0);
- if (nal->type == NAL_IDR_SLICE || h->recovery_frame == h->frame_num) {
+ if (nal->type == NAL_IDR_SLICE || h->recovery_frame == h->poc.frame_num) {
h->recovery_frame = -1;
h->cur_pic_ptr->recovered = 1;
}