h264: factor out calculating the POC count into a separate file

This will allow decoupling the parser from the decoder.
This commit is contained in:
Anton Khirnov
2016-03-21 16:14:31 +01:00
parent 113aeee6ae
commit c8dcff0cdb
11 changed files with 162 additions and 152 deletions

View File

@@ -47,6 +47,7 @@ typedef struct H264ParseContext {
ParseContext pc;
H264ParamSets ps;
H264DSPContext h264dsp;
H264POCContext poc;
int got_first;
} H264ParseContext;
@@ -274,10 +275,10 @@ static inline int parse_nal_units(AVCodecParserContext *s,
case NAL_IDR_SLICE:
s->key_frame = 1;
h->prev_frame_num = 0;
h->prev_frame_num_offset = 0;
h->prev_poc_msb =
h->prev_poc_lsb = 0;
p->poc.prev_frame_num = 0;
p->poc.prev_frame_num_offset = 0;
p->poc.prev_poc_msb =
p->poc.prev_poc_lsb = 0;
/* fall through */
case NAL_SLICE:
get_ue_golomb(&nal.gb); // skip first_mb_in_slice
@@ -310,7 +311,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
h->ps.pps = p->ps.pps;
sps = p->ps.sps;
h->frame_num = get_bits(&nal.gb, sps->log2_max_frame_num);
p->poc.frame_num = get_bits(&nal.gb, sps->log2_max_frame_num);
s->coded_width = 16 * sps->mb_width;
s->coded_height = 16 * sps->mb_height;
@@ -357,26 +358,27 @@ static inline int parse_nal_units(AVCodecParserContext *s,
if (h->nal_unit_type == NAL_IDR_SLICE)
get_ue_golomb(&nal.gb); /* idr_pic_id */
if (sps->poc_type == 0) {
h->poc_lsb = get_bits(&nal.gb, sps->log2_max_poc_lsb);
p->poc.poc_lsb = get_bits(&nal.gb, sps->log2_max_poc_lsb);
if (p->ps.pps->pic_order_present == 1 &&
h->picture_structure == PICT_FRAME)
h->delta_poc_bottom = get_se_golomb(&nal.gb);
p->poc.delta_poc_bottom = get_se_golomb(&nal.gb);
}
if (sps->poc_type == 1 &&
!sps->delta_pic_order_always_zero_flag) {
h->delta_poc[0] = get_se_golomb(&nal.gb);
p->poc.delta_poc[0] = get_se_golomb(&nal.gb);
if (p->ps.pps->pic_order_present == 1 &&
h->picture_structure == PICT_FRAME)
h->delta_poc[1] = get_se_golomb(&nal.gb);
p->poc.delta_poc[1] = get_se_golomb(&nal.gb);
}
/* Decode POC of this picture.
* The prev_ values needed for decoding POC of the next picture are not set here. */
field_poc[0] = field_poc[1] = INT_MAX;
ff_init_poc(h, field_poc, &s->output_picture_number);
ff_h264_init_poc(field_poc, &s->output_picture_number, sps,
&p->poc, h->picture_structure, nal.ref_idc);
/* Continue parsing to check if MMCO_RESET is present.
* FIXME: MMCO_RESET could appear in non-first slice.
@@ -389,15 +391,15 @@ static inline int parse_nal_units(AVCodecParserContext *s,
}
/* Set up the prev_ values for decoding POC of the next picture. */
h->prev_frame_num = got_reset ? 0 : h->frame_num;
h->prev_frame_num_offset = got_reset ? 0 : h->frame_num_offset;
p->poc.prev_frame_num = got_reset ? 0 : p->poc.frame_num;
p->poc.prev_frame_num_offset = got_reset ? 0 : p->poc.frame_num_offset;
if (h->nal_ref_idc != 0) {
if (!got_reset) {
h->prev_poc_msb = h->poc_msb;
h->prev_poc_lsb = h->poc_lsb;
p->poc.prev_poc_msb = p->poc.poc_msb;
p->poc.prev_poc_lsb = p->poc.poc_lsb;
} else {
h->prev_poc_msb = 0;
h->prev_poc_lsb =
p->poc.prev_poc_msb = 0;
p->poc.prev_poc_lsb =
h->picture_structure == PICT_BOTTOM_FIELD ? 0 : field_poc[0];
}
}