From 3f1a7ceb2c604deff10f475f4b1941458d09d1e7 Mon Sep 17 00:00:00 2001 From: Yusuke Nakamura Date: Wed, 15 May 2013 07:37:36 +0900 Subject: [PATCH 1/2] h264_parser: Set field_order and picture_structure. Signed-off-by: Anton Khirnov --- libavcodec/h264.c | 12 ++++----- libavcodec/h264.h | 1 + libavcodec/h264_parser.c | 57 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/libavcodec/h264.c b/libavcodec/h264.c index 38e471d998..c53ea13c42 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -2642,11 +2642,10 @@ static void flush_dpb(AVCodecContext *avctx) h->parse_context.last_index = 0; } -static int init_poc(H264Context *h) +int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc) { const int max_frame_num = 1 << h->sps.log2_max_frame_num; int field_poc[2]; - Picture *cur = h->cur_pic_ptr; h->frame_num_offset = h->prev_frame_num_offset; if (h->frame_num < h->prev_frame_num) @@ -2711,10 +2710,11 @@ static int init_poc(H264Context *h) } if (h->picture_structure != PICT_BOTTOM_FIELD) - h->cur_pic_ptr->field_poc[0] = field_poc[0]; + pic_field_poc[0] = field_poc[0]; if (h->picture_structure != PICT_TOP_FIELD) - h->cur_pic_ptr->field_poc[1] = field_poc[1]; - cur->poc = FFMIN(cur->field_poc[0], cur->field_poc[1]); + pic_field_poc[1] = field_poc[1]; + if (pic_poc) + *pic_poc = FFMIN(pic_field_poc[0], pic_field_poc[1]); return 0; } @@ -3516,7 +3516,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0) h->delta_poc[1] = get_se_golomb(&h->gb); } - init_poc(h); + ff_init_poc(h, h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc); if (h->pps.redundant_pic_cnt_present) h->redundant_pic_count = get_ue_golomb(&h->gb); diff --git a/libavcodec/h264.h b/libavcodec/h264.h index 484c9d3cfc..3ef8420ef6 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -949,5 +949,6 @@ static av_always_inline int get_dct8x8_allowed(H264Context *h) } void ff_h264_draw_horiz_band(H264Context *h, int y, int height); +int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc); #endif /* AVCODEC_H264_H */ diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index e5d2c03f8a..1f79f1ba2f 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -116,10 +116,12 @@ static inline int parse_nal_units(AVCodecParserContext *s, unsigned int slice_type; int state = -1; const uint8_t *ptr; + int field_poc[2]; /* set some sane default values */ s->pict_type = AV_PICTURE_TYPE_I; s->key_frame = 0; + s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN; h->avctx= avctx; h->sei_recovery_frame_cnt = -1; @@ -162,6 +164,11 @@ static inline int parse_nal_units(AVCodecParserContext *s, break; 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; /* fall through */ case NAL_SLICE: get_ue_golomb(&h->gb); // skip first_mb_in_slice @@ -201,6 +208,24 @@ static inline int parse_nal_units(AVCodecParserContext *s, } } + if (h->nal_unit_type == NAL_IDR_SLICE) + get_ue_golomb(&h->gb); /* idr_pic_id */ + if (h->sps.poc_type == 0) { + h->poc_lsb = get_bits(&h->gb, h->sps.log2_max_poc_lsb); + + if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME) + h->delta_poc_bottom = get_se_golomb(&h->gb); + } + + if (h->sps.poc_type == 1 && !h->sps.delta_pic_order_always_zero_flag) { + h->delta_poc[0] = get_se_golomb(&h->gb); + + if (h->pps.pic_order_present == 1 && h->picture_structure == PICT_FRAME) + h->delta_poc[1] = get_se_golomb(&h->gb); + } + + ff_init_poc(h, field_poc, NULL); + if(h->sps.pic_struct_present_flag) { switch (h->sei_pic_struct) { case SEI_PIC_STRUCT_TOP_FIELD: @@ -230,6 +255,38 @@ static inline int parse_nal_units(AVCodecParserContext *s, s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0; } + if (h->picture_structure == PICT_FRAME) { + s->picture_structure = AV_PICTURE_STRUCTURE_FRAME; + if (h->sps.pic_struct_present_flag) { + switch (h->sei_pic_struct) { + case SEI_PIC_STRUCT_TOP_BOTTOM: + case SEI_PIC_STRUCT_TOP_BOTTOM_TOP: + s->field_order = AV_FIELD_TT; + break; + case SEI_PIC_STRUCT_BOTTOM_TOP: + case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM: + s->field_order = AV_FIELD_BB; + break; + default: + s->field_order = AV_FIELD_PROGRESSIVE; + break; + } + } else { + if (field_poc[0] < field_poc[1]) + s->field_order = AV_FIELD_TT; + else if (field_poc[0] > field_poc[1]) + s->field_order = AV_FIELD_BB; + else + s->field_order = AV_FIELD_PROGRESSIVE; + } + } else { + if (h->picture_structure == PICT_TOP_FIELD) + s->picture_structure = AV_PICTURE_STRUCTURE_TOP_FIELD; + else + s->picture_structure = AV_PICTURE_STRUCTURE_BOTTOM_FIELD; + s->field_order = AV_FIELD_UNKNOWN; + } + return 0; /* no need to evaluate the rest */ } buf += consumed; From e9e5a1bdc769a7225ab0d4f8b33bcacc6496bd68 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Fri, 3 May 2013 10:13:00 +0200 Subject: [PATCH 2/2] Monkey's Audio old versions FATE tests --- tests/Makefile | 1 + tests/fate/lossless-audio.mak | 3 --- tests/fate/monkeysaudio.mak | 20 +++++++++++++++++++ ...monkeysaudio => lossless-monkeysaudio-399} | 0 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/fate/monkeysaudio.mak rename tests/ref/fate/{lossless-monkeysaudio => lossless-monkeysaudio-399} (100%) diff --git a/tests/Makefile b/tests/Makefile index 939490b349..1b3f319405 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -76,6 +76,7 @@ include $(SRC_PATH)/tests/fate/libavutil.mak include $(SRC_PATH)/tests/fate/lossless-audio.mak include $(SRC_PATH)/tests/fate/lossless-video.mak include $(SRC_PATH)/tests/fate/microsoft.mak +include $(SRC_PATH)/tests/fate/monkeysaudio.mak include $(SRC_PATH)/tests/fate/mp3.mak include $(SRC_PATH)/tests/fate/mpc.mak include $(SRC_PATH)/tests/fate/pcm.mak diff --git a/tests/fate/lossless-audio.mak b/tests/fate/lossless-audio.mak index 0794241c46..e8f01e1f34 100644 --- a/tests/fate/lossless-audio.mak +++ b/tests/fate/lossless-audio.mak @@ -4,9 +4,6 @@ fate-lossless-alac: CMD = md5 -i $(SAMPLES)/lossless-audio/inside.m4a -f s16le FATE_SAMPLES_AVCONV-$(call DEMDEC, MLP, MLP) += fate-lossless-meridianaudio fate-lossless-meridianaudio: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.mlp -f s16le -FATE_SAMPLES_AVCONV-$(call DEMDEC, APE, APE) += fate-lossless-monkeysaudio -fate-lossless-monkeysaudio: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.ape -f s16le - FATE_SAMPLES_AVCONV-$(call DEMDEC, RM, RALF) += fate-ralf fate-ralf: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.rmvb -vn -f s16le diff --git a/tests/fate/monkeysaudio.mak b/tests/fate/monkeysaudio.mak new file mode 100644 index 0000000000..70fca49b91 --- /dev/null +++ b/tests/fate/monkeysaudio.mak @@ -0,0 +1,20 @@ +APE_VERSIONS = 380 388 389b1 391b1 392b2 394b1 + +define FATE_APE_SUITE +FATE_APE += fate-lossless-monkeysaudio-$(1)-normal +fate-lossless-monkeysaudio-$(1)-normal: CMD = crc -i $(SAMPLES)/lossless-audio/luckynight-mac$(1)-c2000.ape -af atrim=end_sample=73728 +fate-lossless-monkeysaudio-$(1)-normal: REF = CRC=0x5d08c17e +fate-lossless-monkeysaudio-$(1)-normal: CMP = oneline +FATE_APE += fate-lossless-monkeysaudio-$(1)-extrahigh +fate-lossless-monkeysaudio-$(1)-extrahigh: CMD = crc -i $(SAMPLES)/lossless-audio/luckynight-mac$(1)-c4000.ape -af atrim=end_sample=73728 +fate-lossless-monkeysaudio-$(1)-extrahigh: REF = CRC=0x5d08c17e +fate-lossless-monkeysaudio-$(1)-extrahigh: CMP = oneline +endef + +$(foreach N,$(APE_VERSIONS),$(eval $(call FATE_APE_SUITE,$(N)))) + +FATE_APE += fate-lossless-monkeysaudio-399 +fate-lossless-monkeysaudio-399: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.ape -f s16le + +FATE_SAMPLES_AVCONV-$(call DEMDEC, APE, APE) += $(FATE_APE) +fate-lossless-monkeysaudio: $(FATE_APE) diff --git a/tests/ref/fate/lossless-monkeysaudio b/tests/ref/fate/lossless-monkeysaudio-399 similarity index 100% rename from tests/ref/fate/lossless-monkeysaudio rename to tests/ref/fate/lossless-monkeysaudio-399