diff options
author | Clément Bœsch <u@pkh.me> | 2016-06-12 16:06:58 +0200 |
---|---|---|
committer | Clément Bœsch <u@pkh.me> | 2016-06-12 19:01:43 +0200 |
commit | bd3fd467febe92300e0ebf8ff13c193f9236479a (patch) | |
tree | e2a4382598405ce35492ec3c69e007e36f9b5e6c /libavcodec/h264_parse.c | |
parent | 65d5f32fd7d234a9b08e3743593de0a72af7c03c (diff) | |
parent | c8dcff0cdb17d0aa03ac729eba12d1a20f1f59c8 (diff) | |
download | ffmpeg-bd3fd467febe92300e0ebf8ff13c193f9236479a.tar.gz |
Merge commit 'c8dcff0cdb17d0aa03ac729eba12d1a20f1f59c8'
* commit 'c8dcff0cdb17d0aa03ac729eba12d1a20f1f59c8':
h264: factor out calculating the POC count into a separate file
Merged-by: Clément Bœsch <u@pkh.me>
Diffstat (limited to 'libavcodec/h264_parse.c')
-rw-r--r-- | libavcodec/h264_parse.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c index 4f125b56a1..d99d4ae5d8 100644 --- a/libavcodec/h264_parse.c +++ b/libavcodec/h264_parse.c @@ -239,3 +239,83 @@ fail: ref_count[1] = 0; return AVERROR_INVALIDDATA; } + +int ff_h264_init_poc(int pic_field_poc[2], int *pic_poc, + const SPS *sps, H264POCContext *pc, + int picture_structure, int nal_ref_idc) +{ + const int max_frame_num = 1 << sps->log2_max_frame_num; + int field_poc[2]; + + pc->frame_num_offset = pc->prev_frame_num_offset; + if (pc->frame_num < pc->prev_frame_num) + pc->frame_num_offset += max_frame_num; + + if (sps->poc_type == 0) { + const int max_poc_lsb = 1 << sps->log2_max_poc_lsb; + + if (pc->poc_lsb < pc->prev_poc_lsb && + pc->prev_poc_lsb - pc->poc_lsb >= max_poc_lsb / 2) + pc->poc_msb = pc->prev_poc_msb + max_poc_lsb; + else if (pc->poc_lsb > pc->prev_poc_lsb && + pc->prev_poc_lsb - pc->poc_lsb < -max_poc_lsb / 2) + pc->poc_msb = pc->prev_poc_msb - max_poc_lsb; + else + pc->poc_msb = pc->prev_poc_msb; + field_poc[0] = + field_poc[1] = pc->poc_msb + pc->poc_lsb; + if (picture_structure == PICT_FRAME) + field_poc[1] += pc->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 = pc->frame_num_offset + pc->frame_num; + else + abs_frame_num = 0; + + if (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 (nal_ref_idc == 0) + expectedpoc = expectedpoc + sps->offset_for_non_ref_pic; + + field_poc[0] = expectedpoc + pc->delta_poc[0]; + field_poc[1] = field_poc[0] + sps->offset_for_top_to_bottom_field; + + if (picture_structure == PICT_FRAME) + field_poc[1] += pc->delta_poc[1]; + } else { + int poc = 2 * (pc->frame_num_offset + pc->frame_num); + + if (!nal_ref_idc) + poc--; + + field_poc[0] = poc; + field_poc[1] = poc; + } + + if (picture_structure != PICT_BOTTOM_FIELD) + pic_field_poc[0] = field_poc[0]; + if (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; +} |