ffmpeg | branch: master | James Almer <jamr...@gmail.com> | Mon Aug 1 15:11:05 2016 -0300| [f41048f6ec5671c2e09ae317cecc1e98ecc3c2ce] | committer: James Almer
Merge commit '5c2fb561d94fc51d76ab21d6f7cc5b6cc3aa599c' * commit '5c2fb561d94fc51d76ab21d6f7cc5b6cc3aa599c': h264: add H264_ prefix to the NAL unit types Conflicts: libavcodec/h264_parse.c libavcodec/h264_parser.c libavcodec/h264_slice.c libavcodec/h264dec.c Merged-by: James Almer <jamr...@gmail.com> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f41048f6ec5671c2e09ae317cecc1e98ecc3c2ce --- libavcodec/h264.h | 28 +++++++++++------------ libavcodec/h264_parse.c | 4 ++-- libavcodec/h264_parser.c | 36 +++++++++++++++--------------- libavcodec/h264_refs.c | 2 +- libavcodec/h264_slice.c | 12 +++++----- libavcodec/h264dec.c | 50 +++++++++++++++++++++--------------------- libavcodec/omx.c | 2 +- libavcodec/vaapi_encode_h264.c | 10 ++++----- libavformat/mxfenc.c | 4 ++-- 9 files changed, 74 insertions(+), 74 deletions(-) diff --git a/libavcodec/h264.h b/libavcodec/h264.h index bcdd4f6..86df5eb 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -28,20 +28,20 @@ /* NAL unit types */ enum { - NAL_SLICE = 1, - NAL_DPA = 2, - NAL_DPB = 3, - NAL_DPC = 4, - NAL_IDR_SLICE = 5, - NAL_SEI = 6, - NAL_SPS = 7, - NAL_PPS = 8, - NAL_AUD = 9, - NAL_END_SEQUENCE = 10, - NAL_END_STREAM = 11, - NAL_FILLER_DATA = 12, - NAL_SPS_EXT = 13, - NAL_AUXILIARY_SLICE = 19, + H264_NAL_SLICE = 1, + H264_NAL_DPA = 2, + H264_NAL_DPB = 3, + H264_NAL_DPC = 4, + H264_NAL_IDR_SLICE = 5, + H264_NAL_SEI = 6, + H264_NAL_SPS = 7, + H264_NAL_PPS = 8, + H264_NAL_AUD = 9, + H264_NAL_END_SEQUENCE = 10, + H264_NAL_END_STREAM = 11, + H264_NAL_FILLER_DATA = 12, + H264_NAL_SPS_EXT = 13, + H264_NAL_AUXILIARY_SLICE = 19, }; #endif /* AVCODEC_H264_H */ diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c index da67149..1d4b1e4 100644 --- a/libavcodec/h264_parse.c +++ b/libavcodec/h264_parse.c @@ -346,12 +346,12 @@ static int decode_extradata_ps(const uint8_t *data, int size, H264ParamSets *ps, for (i = 0; i < pkt.nb_nals; i++) { H2645NAL *nal = &pkt.nals[i]; switch (nal->type) { - case NAL_SPS: + case H264_NAL_SPS: ret = ff_h264_decode_seq_parameter_set(&nal->gb, logctx, ps, 0); if (ret < 0) goto fail; break; - case NAL_PPS: + case H264_NAL_PPS: ret = ff_h264_decode_picture_parameter_set(&nal->gb, logctx, ps, nal->size_bits); if (ret < 0) diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 20efdaa..0352b21 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -106,14 +106,14 @@ static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf, state >>= 1; // 2->1, 1->0, 0->0 } else if (state <= 5) { int nalu_type = buf[i] & 0x1F; - if (nalu_type == NAL_SEI || nalu_type == NAL_SPS || - nalu_type == NAL_PPS || nalu_type == NAL_AUD) { + if (nalu_type == H264_NAL_SEI || nalu_type == H264_NAL_SPS || + nalu_type == H264_NAL_PPS || nalu_type == H264_NAL_AUD) { if (pc->frame_start_found) { i++; goto found; } - } else if (nalu_type == NAL_SLICE || nalu_type == NAL_DPA || - nalu_type == NAL_IDR_SLICE) { + } else if (nalu_type == H264_NAL_SLICE || nalu_type == H264_NAL_DPA || + nalu_type == H264_NAL_IDR_SLICE) { state += 8; continue; } @@ -303,10 +303,10 @@ static inline int parse_nal_units(AVCodecParserContext *s, state = buf[buf_index]; switch (state & 0x1f) { - case NAL_SLICE: - case NAL_IDR_SLICE: + case H264_NAL_SLICE: + case H264_NAL_IDR_SLICE: // Do not walk the whole buffer just to decode slice header - if ((state & 0x1f) == NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) { + if ((state & 0x1f) == H264_NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) { /* IDR or disposable slice * No need to decode many bytes because MMCOs shall not be present. */ if (src_length > 60) @@ -332,17 +332,17 @@ static inline int parse_nal_units(AVCodecParserContext *s, nal.type = get_bits(&nal.gb, 5); switch (nal.type) { - case NAL_SPS: + case H264_NAL_SPS: ff_h264_decode_seq_parameter_set(&nal.gb, avctx, &p->ps, 0); break; - case NAL_PPS: + case H264_NAL_PPS: ff_h264_decode_picture_parameter_set(&nal.gb, avctx, &p->ps, nal.size_bits); break; - case NAL_SEI: + case H264_NAL_SEI: ff_h264_sei_decode(&p->sei, &nal.gb, &p->ps, avctx); break; - case NAL_IDR_SLICE: + case H264_NAL_IDR_SLICE: s->key_frame = 1; p->poc.prev_frame_num = 0; @@ -350,7 +350,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, p->poc.prev_poc_msb = p->poc.prev_poc_lsb = 0; /* fall through */ - case NAL_SLICE: + case H264_NAL_SLICE: get_ue_golomb_long(&nal.gb); // skip first_mb_in_slice slice_type = get_ue_golomb_31(&nal.gb); s->pict_type = ff_h264_golomb_to_pict_type[slice_type % 5]; @@ -440,7 +440,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, } } - if (nal.type == NAL_IDR_SLICE) + if (nal.type == H264_NAL_IDR_SLICE) get_ue_golomb_long(&nal.gb); /* idr_pic_id */ if (sps->poc_type == 0) { p->poc.poc_lsb = get_bits(&nal.gb, sps->log2_max_poc_lsb); @@ -469,7 +469,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, * FIXME: MMCO_RESET could appear in non-first slice. * Maybe, we should parse all undisposable non-IDR slice of this * picture until encountering MMCO_RESET in a slice of it. */ - if (nal.ref_idc && nal.type != NAL_IDR_SLICE) { + if (nal.ref_idc && nal.type != H264_NAL_IDR_SLICE) { got_reset = scan_mmco_reset(s, &nal.gb, avctx); if (got_reset < 0) goto fail; @@ -637,17 +637,17 @@ static int h264_split(AVCodecContext *avctx, if ((state & 0xFFFFFF00) != 0x100) break; nalu_type = state & 0x1F; - if (nalu_type == NAL_SPS) { + if (nalu_type == H264_NAL_SPS) { has_sps = 1; - } else if (nalu_type == NAL_PPS) + } else if (nalu_type == H264_NAL_PPS) has_pps = 1; /* else if (nalu_type == 0x01 || * nalu_type == 0x02 || * nalu_type == 0x05) { * } */ - else if ((nalu_type != NAL_SEI || has_pps) && - nalu_type != NAL_AUD && nalu_type != NAL_SPS_EXT && + else if ((nalu_type != H264_NAL_SEI || has_pps) && + nalu_type != H264_NAL_AUD && nalu_type != H264_NAL_SPS_EXT && nalu_type != 0x0f) { if (has_sps) { while (ptr - 4 > buf && ptr[-5] == 0) diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c index e66f69a..e760df1 100644 --- a/libavcodec/h264_refs.c +++ b/libavcodec/h264_refs.c @@ -828,7 +828,7 @@ int ff_h264_decode_ref_pic_marking(const H264Context *h, H264SliceContext *sl, MMCO *mmco = sl->mmco; int nb_mmco = 0; - if (h->nal_unit_type == NAL_IDR_SLICE) { // FIXME fields + if (h->nal_unit_type == H264_NAL_IDR_SLICE) { // FIXME fields skip_bits1(gb); // broken_link if (get_bits1(gb)) { mmco[0].opcode = MMCO_LONG; diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 9495b6e..fcc8443 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1542,7 +1542,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl, sl->slice_type = slice_type; sl->slice_type_nos = slice_type & 3; - if (nal->type == NAL_IDR_SLICE && + if (nal->type == H264_NAL_IDR_SLICE && sl->slice_type_nos != AV_PICTURE_TYPE_I) { av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n"); return AVERROR_INVALIDDATA; @@ -1605,7 +1605,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl, sl->max_pic_num = 1 << (sps->log2_max_frame_num + 1); } - if (nal->type == NAL_IDR_SLICE) + if (nal->type == H264_NAL_IDR_SLICE) get_ue_golomb_long(&sl->gb); /* idr_pic_id */ if (sps->poc_type == 0) { @@ -1758,7 +1758,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, h->current_slice = 0; if (ret < 0) return ret; - } else if (h->cur_pic_ptr && !FIELD_PICTURE(h) && !h->first_field && h->nal_unit_type == NAL_IDR_SLICE) { + } else if (h->cur_pic_ptr && !FIELD_PICTURE(h) && !h->first_field && h->nal_unit_type == H264_NAL_IDR_SLICE) { av_log(h, AV_LOG_WARNING, "Broken frame packetizing\n"); ret = ff_h264_field_end(h, h->slice_ctx, 1); h->current_slice = 0; @@ -1788,7 +1788,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, (h->avctx->skip_frame >= AVDISCARD_NONREF && !h->nal_ref_idc) || (h->avctx->skip_frame >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) || (h->avctx->skip_frame >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) || - (h->avctx->skip_frame >= AVDISCARD_NONKEY && h->nal_unit_type != NAL_IDR_SLICE && h->sei.recovery_point.recovery_frame_cnt < 0) || + (h->avctx->skip_frame >= AVDISCARD_NONKEY && h->nal_unit_type != H264_NAL_IDR_SLICE && h->sei.recovery_point.recovery_frame_cnt < 0) || h->avctx->skip_frame >= AVDISCARD_ALL) { return SLICE_SKIPED; } @@ -1861,7 +1861,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, if (h->avctx->skip_loop_filter >= AVDISCARD_ALL || (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY && - h->nal_unit_type != NAL_IDR_SLICE) || + h->nal_unit_type != H264_NAL_IDR_SLICE) || (h->avctx->skip_loop_filter >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) || (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR && @@ -1938,7 +1938,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, sl->mb_y * h->mb_width + sl->mb_x, av_get_picture_type_char(sl->slice_type), sl->slice_type_fixed ? " fix" : "", - nal->type == NAL_IDR_SLICE ? " IDR" : "", + nal->type == H264_NAL_IDR_SLICE ? " IDR" : "", h->poc.frame_num, h->cur_pic_ptr->field_poc[0], h->cur_pic_ptr->field_poc[1], diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 91bc38d..d944a8c 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -674,13 +674,13 @@ static int get_last_needed_nal(H264Context *h) * which splits NALs strangely if so, when frame threading we * can't start the next thread until we've read all of them */ switch (nal->type) { - case NAL_SPS: - case NAL_PPS: + case H264_NAL_SPS: + case H264_NAL_PPS: nals_needed = i; break; - case NAL_DPA: - case NAL_IDR_SLICE: - case NAL_SLICE: + case H264_NAL_DPA: + case H264_NAL_IDR_SLICE: + case H264_NAL_SLICE: ret = init_get_bits8(&gb, nal->data + 1, (nal->size - 1)); if (ret < 0) return ret; @@ -768,7 +768,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size) int err; if (avctx->skip_frame >= AVDISCARD_NONREF && - nal->ref_idc == 0 && nal->type != NAL_SEI) + nal->ref_idc == 0 && nal->type != H264_NAL_SEI) continue; again: @@ -778,14 +778,14 @@ again: err = 0; switch (nal->type) { - case NAL_IDR_SLICE: + case H264_NAL_IDR_SLICE: if ((nal->data[1] & 0xFC) == 0x98) { av_log(h->avctx, AV_LOG_ERROR, "Invalid inter IDR frame\n"); h->next_outputed_poc = INT_MIN; ret = -1; goto end; } - if (nal->type != NAL_IDR_SLICE) { + if (nal->type != H264_NAL_IDR_SLICE) { av_log(h->avctx, AV_LOG_ERROR, "Invalid mix of idr and non-idr slices\n"); ret = -1; @@ -801,7 +801,7 @@ again: } idr_cleared = 1; h->has_recovery_point = 1; - case NAL_SLICE: + case H264_NAL_SLICE: sl->gb = nal->gb; if ((err = ff_h264_decode_slice_header(h, sl, nal))) @@ -822,16 +822,16 @@ again: } } - h->cur_pic_ptr->f->key_frame |= (nal->type == NAL_IDR_SLICE); + h->cur_pic_ptr->f->key_frame |= (nal->type == H264_NAL_IDR_SLICE); - if (nal->type == NAL_IDR_SLICE || + if (nal->type == H264_NAL_IDR_SLICE || (h->recovery_frame == h->poc.frame_num && nal->ref_idc)) { h->recovery_frame = -1; h->cur_pic_ptr->recovered = 1; } // If we have an IDR, all frames after it in decoded order are // "recovered". - if (nal->type == NAL_IDR_SLICE) + if (nal->type == H264_NAL_IDR_SLICE) h->frame_recovered |= FRAME_RECOVERED_IDR; #if 1 h->cur_pic_ptr->recovered |= h->frame_recovered; @@ -874,12 +874,12 @@ again: context_count++; } break; - case NAL_DPA: - case NAL_DPB: - case NAL_DPC: + case H264_NAL_DPA: + case H264_NAL_DPB: + case H264_NAL_DPC: avpriv_request_sample(avctx, "data partitioning"); break; - case NAL_SEI: + case H264_NAL_SEI: ret = ff_h264_sei_decode(&h->sei, &nal->gb, &h->ps, avctx); h->has_recovery_point = h->has_recovery_point || h->sei.recovery_point.recovery_frame_cnt != -1; if (avctx->debug & FF_DEBUG_GREEN_MD) @@ -892,7 +892,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) goto end; break; - case NAL_SPS: { + case H264_NAL_SPS: { GetBitContext tmp_gb = nal->gb; if (ff_h264_decode_seq_parameter_set(&tmp_gb, avctx, &h->ps, 0) >= 0) break; @@ -904,18 +904,18 @@ FF_ENABLE_DEPRECATION_WARNINGS ff_h264_decode_seq_parameter_set(&nal->gb, avctx, &h->ps, 1); break; } - case NAL_PPS: + case H264_NAL_PPS: ret = ff_h264_decode_picture_parameter_set(&nal->gb, avctx, &h->ps, nal->size_bits); if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) goto end; break; - case NAL_AUD: - case NAL_END_SEQUENCE: - case NAL_END_STREAM: - case NAL_FILLER_DATA: - case NAL_SPS_EXT: - case NAL_AUXILIARY_SLICE: + case H264_NAL_AUD: + case H264_NAL_END_SEQUENCE: + case H264_NAL_END_STREAM: + case H264_NAL_FILLER_DATA: + case H264_NAL_SPS_EXT: + case H264_NAL_AUXILIARY_SLICE: break; default: av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n", @@ -1157,7 +1157,7 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data, if (buf_index < 0) return AVERROR_INVALIDDATA; - if (!h->cur_pic_ptr && h->nal_unit_type == NAL_END_SEQUENCE) { + if (!h->cur_pic_ptr && h->nal_unit_type == H264_NAL_END_SEQUENCE) { av_assert0(buf_index <= buf_size); goto out; } diff --git a/libavcodec/omx.c b/libavcodec/omx.c index 1b2ae0d..c1b6fb9 100644 --- a/libavcodec/omx.c +++ b/libavcodec/omx.c @@ -703,7 +703,7 @@ static av_cold int omx_encode_init(AVCodecContext *avctx) nals[avctx->extradata[i + 4] & 0x1f]++; } } - if (nals[NAL_SPS] && nals[NAL_PPS]) + if (nals[H264_NAL_SPS] && nals[H264_NAL_PPS]) break; } else { if (avctx->extradata_size > 0) diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index d576ede..979cf37 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -283,7 +283,7 @@ static void vaapi_encode_h264_write_sps(PutBitContext *pbc, VAAPIEncodeH264MiscSequenceParams *mseq = &priv->misc_sequence_params; int i; - vaapi_encode_h264_write_nal_header(pbc, NAL_SPS, 3); + vaapi_encode_h264_write_nal_header(pbc, H264_NAL_SPS, 3); u(8, mseq_var(profile_idc)); u(1, mseq_var(constraint_set0_flag)); @@ -368,7 +368,7 @@ static void vaapi_encode_h264_write_pps(PutBitContext *pbc, VAAPIEncodeH264Context *priv = ctx->priv_data; VAAPIEncodeH264MiscSequenceParams *mseq = &priv->misc_sequence_params; - vaapi_encode_h264_write_nal_header(pbc, NAL_PPS, 3); + vaapi_encode_h264_write_nal_header(pbc, H264_NAL_PPS, 3); ue(vpic_var(pic_parameter_set_id)); ue(vpic_var(seq_parameter_set_id)); @@ -642,7 +642,7 @@ static void vaapi_encode_h264_write_sei(PutBitContext *pbc, VAAPIEncodeContext *ctx, VAAPIEncodePicture *pic) = NULL; - vaapi_encode_h264_write_nal_header(pbc, NAL_SEI, 0); + vaapi_encode_h264_write_nal_header(pbc, H264_NAL_SEI, 0); for (payload_type = 0; payload_type < 64; payload_type++) { switch (payload_type) { @@ -1010,9 +1010,9 @@ static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx, mslice = &pslice->misc_slice_params; if (pic->type == PICTURE_TYPE_IDR) - mslice->nal_unit_type = NAL_IDR_SLICE; + mslice->nal_unit_type = H264_NAL_IDR_SLICE; else - mslice->nal_unit_type = NAL_SLICE; + mslice->nal_unit_type = H264_NAL_SLICE; switch (pic->type) { case PICTURE_TYPE_IDR: diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 80318b8..ffd0bf2 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -1860,11 +1860,11 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, break; --buf; switch (state & 0x1f) { - case NAL_SPS: + case H264_NAL_SPS: st->codecpar->profile = buf[1]; e->flags |= 0x40; break; - case NAL_PPS: + case H264_NAL_PPS: if (e->flags & 0x40) { // sequence header present e->flags |= 0x80; // random access extra_size = 0; ====================================================================== diff --cc libavcodec/h264_parse.c index da67149,d694558..1d4b1e4 --- a/libavcodec/h264_parse.c +++ b/libavcodec/h264_parse.c @@@ -346,8 -330,8 +346,8 @@@ static int decode_extradata_ps(const ui for (i = 0; i < pkt.nb_nals; i++) { H2645NAL *nal = &pkt.nals[i]; switch (nal->type) { - case NAL_SPS: + case H264_NAL_SPS: - ret = ff_h264_decode_seq_parameter_set(&nal->gb, logctx, ps); + ret = ff_h264_decode_seq_parameter_set(&nal->gb, logctx, ps, 0); if (ret < 0) goto fail; break; diff --cc libavcodec/h264_parser.c index 20efdaa,b4da123..0352b21 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@@ -112,29 -89,20 +112,29 @@@ static int h264_find_frame_end(H264Pars i++; goto found; } - } else if (nalu_type == NAL_SLICE || nalu_type == NAL_DPA || - nalu_type == NAL_IDR_SLICE) { + } else if (nalu_type == H264_NAL_SLICE || nalu_type == H264_NAL_DPA || + nalu_type == H264_NAL_IDR_SLICE) { + state += 8; + continue; + } + state = 7; + } else { + p->parse_history[p->parse_history_count++] = buf[i]; + if (p->parse_history_count > 5) { + unsigned int mb, last_mb = p->parse_last_mb; + GetBitContext gb; + + init_get_bits(&gb, p->parse_history, 8*p->parse_history_count); + p->parse_history_count = 0; + mb= get_ue_golomb_long(&gb); + p->parse_last_mb = mb; if (pc->frame_start_found) { - state += 8; - continue; + if (mb <= last_mb) + goto found; } else pc->frame_start_found = 1; + state = 7; } - state = 7; - } else { - // first_mb_in_slice is 0, probably the first nal of a new slice - if (buf[i] & 0x80) - goto found; - state = 7; } } pc->state = state; @@@ -281,32 -225,19 +281,32 @@@ static inline int parse_nal_units(AVCod if (!buf_size) return 0; + buf_index = 0; + next_avc = p->is_avc ? 0 : buf_size; for (;;) { const SPS *sps; - int src_length, consumed; - buf = avpriv_find_start_code(buf, buf_end, &state); - if (buf >= buf_end) - break; - --buf; - src_length = buf_end - buf; + int src_length, consumed, nalsize = 0; + + if (buf_index >= next_avc) { + nalsize = get_avc_nalsize(p, buf, buf_size, &buf_index, avctx); + if (nalsize < 0) + break; + next_avc = buf_index + nalsize; + } else { + buf_index = find_start_code(buf, buf_size, buf_index, next_avc); + if (buf_index >= buf_size) + break; + if (buf_index >= next_avc) + continue; + } + src_length = next_avc - buf_index; + + state = buf[buf_index]; switch (state & 0x1f) { - case NAL_SLICE: - case NAL_IDR_SLICE: + case H264_NAL_SLICE: + case H264_NAL_IDR_SLICE: // Do not walk the whole buffer just to decode slice header - if ((state & 0x1f) == NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) { + if ((state & 0x1f) == H264_NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) { /* IDR or disposable slice * No need to decode many bytes because MMCOs shall not be present. */ if (src_length > 60) @@@ -332,10 -262,10 +332,10 @@@ nal.type = get_bits(&nal.gb, 5); switch (nal.type) { - case NAL_SPS: + case H264_NAL_SPS: - ff_h264_decode_seq_parameter_set(&nal.gb, avctx, &p->ps); + ff_h264_decode_seq_parameter_set(&nal.gb, avctx, &p->ps, 0); break; - case NAL_PPS: + case H264_NAL_PPS: ff_h264_decode_picture_parameter_set(&nal.gb, avctx, &p->ps, nal.size_bits); break; @@@ -350,8 -280,8 +350,8 @@@ p->poc.prev_poc_msb = p->poc.prev_poc_lsb = 0; /* fall through */ - case NAL_SLICE: + case H264_NAL_SLICE: - get_ue_golomb(&nal.gb); // skip first_mb_in_slice + get_ue_golomb_long(&nal.gb); // skip first_mb_in_slice slice_type = get_ue_golomb_31(&nal.gb); s->pict_type = ff_h264_golomb_to_pict_type[slice_type % 5]; if (p->sei.recovery_point.recovery_frame_cnt >= 0) { @@@ -440,8 -353,8 +440,8 @@@ } } - if (nal.type == NAL_IDR_SLICE) + if (nal.type == H264_NAL_IDR_SLICE) - get_ue_golomb(&nal.gb); /* idr_pic_id */ + get_ue_golomb_long(&nal.gb); /* idr_pic_id */ if (sps->poc_type == 0) { p->poc.poc_lsb = get_bits(&nal.gb, sps->log2_max_poc_lsb); @@@ -626,37 -534,31 +626,37 @@@ static int h264_parse(AVCodecParserCont static int h264_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size) { - int i; uint32_t state = -1; int has_sps = 0; + int has_pps = 0; + const uint8_t *ptr = buf, *end = buf + buf_size; + int nalu_type; - for (i = 0; i <= buf_size; i++) { - if ((state & 0xFFFFFF1F) == 0x107) + while (ptr < end) { + ptr = avpriv_find_start_code(ptr, end, &state); + if ((state & 0xFFFFFF00) != 0x100) + break; + nalu_type = state & 0x1F; - if (nalu_type == NAL_SPS) { ++ if (nalu_type == H264_NAL_SPS) { has_sps = 1; - } else if (nalu_type == NAL_PPS) - /* if((state&0xFFFFFF1F) == 0x101 || - * (state&0xFFFFFF1F) == 0x102 || - * (state&0xFFFFFF1F) == 0x105) { ++ } else if (nalu_type == H264_NAL_PPS) + has_pps = 1; + /* else if (nalu_type == 0x01 || + * nalu_type == 0x02 || + * nalu_type == 0x05) { * } */ - else if ((nalu_type != NAL_SEI || has_pps) && - nalu_type != NAL_AUD && nalu_type != NAL_SPS_EXT && - if ((state & 0xFFFFFF00) == 0x100 && (state & 0xFFFFFF1F) != 0x106 && - (state & 0xFFFFFF1F) != 0x107 && (state & 0xFFFFFF1F) != 0x108 && - (state & 0xFFFFFF1F) != 0x109 && (state & 0xFFFFFF1F) != 0x10d && - (state & 0xFFFFFF1F) != 0x10f) { ++ else if ((nalu_type != H264_NAL_SEI || has_pps) && ++ nalu_type != H264_NAL_AUD && nalu_type != H264_NAL_SPS_EXT && + nalu_type != 0x0f) { if (has_sps) { - while (i > 4 && buf[i - 5] == 0) - i--; - return i - 4; + while (ptr - 4 > buf && ptr[-5] == 0) + ptr--; + return ptr - 4 - buf; } } - if (i < buf_size) - state = (state << 8) | buf[i]; } + return 0; } diff --cc libavcodec/h264_slice.c index 9495b6e,376be27..fcc8443 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@@ -1605,8 -1427,8 +1605,8 @@@ static int h264_slice_header_parse(cons sl->max_pic_num = 1 << (sps->log2_max_frame_num + 1); } - if (nal->type == NAL_IDR_SLICE) + if (nal->type == H264_NAL_IDR_SLICE) - get_ue_golomb(&sl->gb); /* idr_pic_id */ + get_ue_golomb_long(&sl->gb); /* idr_pic_id */ if (sps->poc_type == 0) { sl->poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb); @@@ -1735,62 -1556,26 +1735,62 @@@ int ff_h264_decode_slice_header(H264Con if (ret < 0) return ret; - if (!h->setup_finished) { - if (sl->first_mb_addr == 0) { // FIXME better field boundary detection - if (h->current_slice && h->cur_pic_ptr && FIELD_PICTURE(h)) { - ff_h264_field_end(h, sl, 1); - } + if (sl->first_mb_addr == 0 || !h->current_slice) { + if (h->setup_finished) { + av_log(h->avctx, AV_LOG_ERROR, "Too many fields\n"); + return AVERROR_INVALIDDATA; + } + } - h->current_slice = 0; - if (!h->first_field) { - if (h->cur_pic_ptr && !h->droppable) { - ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, - h->picture_structure == PICT_BOTTOM_FIELD); + if (sl->first_mb_addr == 0) { // FIXME better field boundary detection + if (h->current_slice) { + if (h->max_contexts > 1) { + if (!h->single_decode_warning) { + av_log(h->avctx, AV_LOG_WARNING, "Cannot decode multiple access units as slice threads\n"); + h->single_decode_warning = 1; } + h->max_contexts = 1; + return SLICE_SINGLETHREAD; + } + + if (h->cur_pic_ptr && FIELD_PICTURE(h) && h->first_field) { + ret = ff_h264_field_end(h, h->slice_ctx, 1); + h->current_slice = 0; + if (ret < 0) + return ret; - } else if (h->cur_pic_ptr && !FIELD_PICTURE(h) && !h->first_field && h->nal_unit_type == NAL_IDR_SLICE) { ++ } else if (h->cur_pic_ptr && !FIELD_PICTURE(h) && !h->first_field && h->nal_unit_type == H264_NAL_IDR_SLICE) { + av_log(h, AV_LOG_WARNING, "Broken frame packetizing\n"); + ret = ff_h264_field_end(h, h->slice_ctx, 1); + h->current_slice = 0; + ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0); + ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1); h->cur_pic_ptr = NULL; + if (ret < 0) + return ret; + } else + return AVERROR_INVALIDDATA; + } + + if (!h->first_field) { + if (h->cur_pic_ptr && !h->droppable) { + ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, + h->picture_structure == PICT_BOTTOM_FIELD); } + h->cur_pic_ptr = NULL; } + } - if (h->current_slice == 0) { - ret = h264_field_start(h, sl, nal); - if (ret < 0) - return ret; + if (!h->current_slice) + av_assert0(sl == h->slice_ctx); + + if (h->current_slice == 0 && !h->first_field) { + if ( + (h->avctx->skip_frame >= AVDISCARD_NONREF && !h->nal_ref_idc) || + (h->avctx->skip_frame >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) || + (h->avctx->skip_frame >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) || - (h->avctx->skip_frame >= AVDISCARD_NONKEY && h->nal_unit_type != NAL_IDR_SLICE && h->sei.recovery_point.recovery_frame_cnt < 0) || ++ (h->avctx->skip_frame >= AVDISCARD_NONKEY && h->nal_unit_type != H264_NAL_IDR_SLICE && h->sei.recovery_point.recovery_frame_cnt < 0) || + h->avctx->skip_frame >= AVDISCARD_ALL) { + return SLICE_SKIPED; } } @@@ -1861,8 -1631,6 +1861,8 @@@ if (h->avctx->skip_loop_filter >= AVDISCARD_ALL || (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY && - h->nal_unit_type != NAL_IDR_SLICE) || ++ h->nal_unit_type != H264_NAL_IDR_SLICE) || + (h->avctx->skip_loop_filter >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) || (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) || diff --cc libavcodec/h264dec.c index 91bc38d,52cb9ae..d944a8c --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@@ -674,22 -639,16 +674,22 @@@ static int get_last_needed_nal(H264Cont * which splits NALs strangely if so, when frame threading we * can't start the next thread until we've read all of them */ switch (nal->type) { - case NAL_SPS: - case NAL_PPS: + case H264_NAL_SPS: + case H264_NAL_PPS: nals_needed = i; break; - case NAL_DPA: - case NAL_IDR_SLICE: - case NAL_SLICE: + case H264_NAL_DPA: + case H264_NAL_IDR_SLICE: + case H264_NAL_SLICE: - init_get_bits(&gb, nal->data + 1, (nal->size - 1) * 8); - if (!get_ue_golomb(&gb)) + ret = init_get_bits8(&gb, nal->data + 1, (nal->size - 1)); + if (ret < 0) + return ret; + if (!get_ue_golomb_long(&gb) || // first_mb_in_slice + !first_slice || + first_slice != nal->type) nals_needed = i; + if (!first_slice) + first_slice = nal->type; } } @@@ -768,76 -686,46 +768,76 @@@ static int decode_nal_units(H264Contex int err; if (avctx->skip_frame >= AVDISCARD_NONREF && - nal->ref_idc == 0 && nal->type != NAL_SEI) + nal->ref_idc == 0 && nal->type != H264_NAL_SEI) continue; +again: // FIXME these should stop being context-global variables h->nal_ref_idc = nal->ref_idc; h->nal_unit_type = nal->type; err = 0; switch (nal->type) { - case NAL_IDR_SLICE: + case H264_NAL_IDR_SLICE: + if ((nal->data[1] & 0xFC) == 0x98) { + av_log(h->avctx, AV_LOG_ERROR, "Invalid inter IDR frame\n"); + h->next_outputed_poc = INT_MIN; + ret = -1; + goto end; + } - if (nal->type != NAL_IDR_SLICE) { + if (nal->type != H264_NAL_IDR_SLICE) { av_log(h->avctx, AV_LOG_ERROR, "Invalid mix of idr and non-idr slices\n"); ret = -1; goto end; } - idr(h); // FIXME ensure we don't lose some frames if there is reordering + if(!idr_cleared) { + if (h->current_slice && (avctx->active_thread_type & FF_THREAD_SLICE)) { + av_log(h, AV_LOG_ERROR, "invalid mixed IDR / non IDR frames cannot be decoded in slice multithreading mode\n"); + ret = AVERROR_INVALIDDATA; + goto end; + } + idr(h); // FIXME ensure we don't lose some frames if there is reordering + } + idr_cleared = 1; + h->has_recovery_point = 1; - case NAL_SLICE: + case H264_NAL_SLICE: sl->gb = nal->gb; if ((err = ff_h264_decode_slice_header(h, sl, nal))) break; - if (h->sei.recovery_point.recovery_frame_cnt >= 0 && h->recovery_frame < 0) { - h->recovery_frame = (h->poc.frame_num + h->sei.recovery_point.recovery_frame_cnt) & - ((1 << h->ps.sps->log2_max_frame_num) - 1); + if (h->sei.recovery_point.recovery_frame_cnt >= 0) { + const int sei_recovery_frame_cnt = h->sei.recovery_point.recovery_frame_cnt; + + if (h->poc.frame_num != sei_recovery_frame_cnt || sl->slice_type_nos != AV_PICTURE_TYPE_I) + h->valid_recovery_point = 1; + + if ( h->recovery_frame < 0 + || av_mod_uintp2(h->recovery_frame - h->poc.frame_num, h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) { + h->recovery_frame = av_mod_uintp2(h->poc.frame_num + sei_recovery_frame_cnt, h->ps.sps->log2_max_frame_num); + + if (!h->valid_recovery_point) + h->recovery_frame = h->poc.frame_num; + } } - h->cur_pic_ptr->f->key_frame |= (nal->type == NAL_IDR_SLICE); - h->cur_pic_ptr->f->key_frame |= - (nal->type == H264_NAL_IDR_SLICE) || (h->sei.recovery_point.recovery_frame_cnt >= 0); ++ h->cur_pic_ptr->f->key_frame |= (nal->type == H264_NAL_IDR_SLICE); - if (nal->type == NAL_IDR_SLICE || - if (nal->type == H264_NAL_IDR_SLICE || h->recovery_frame == h->poc.frame_num) { ++ if (nal->type == H264_NAL_IDR_SLICE || + (h->recovery_frame == h->poc.frame_num && nal->ref_idc)) { h->recovery_frame = -1; h->cur_pic_ptr->recovered = 1; } // If we have an IDR, all frames after it in decoded order are // "recovered". - if (nal->type == NAL_IDR_SLICE) + if (nal->type == H264_NAL_IDR_SLICE) h->frame_recovered |= FRAME_RECOVERED_IDR; +#if 1 + h->cur_pic_ptr->recovered |= h->frame_recovered; +#else h->cur_pic_ptr->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_IDR); +#endif if (h->current_slice == 1) { if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) @@@ -874,37 -751,24 +874,37 @@@ context_count++; } break; - case NAL_DPA: - case NAL_DPB: - case NAL_DPC: + case H264_NAL_DPA: + case H264_NAL_DPB: + case H264_NAL_DPC: avpriv_request_sample(avctx, "data partitioning"); - ret = AVERROR(ENOSYS); - goto end; break; - case NAL_SEI: + case H264_NAL_SEI: ret = ff_h264_sei_decode(&h->sei, &nal->gb, &h->ps, avctx); + h->has_recovery_point = h->has_recovery_point || h->sei.recovery_point.recovery_frame_cnt != -1; + if (avctx->debug & FF_DEBUG_GREEN_MD) + debug_green_metadata(&h->sei.green_metadata, h->avctx); +#if FF_API_AFD +FF_DISABLE_DEPRECATION_WARNINGS + h->avctx->dtg_active_format = h->sei.afd.active_format_description; +FF_ENABLE_DEPRECATION_WARNINGS +#endif /* FF_API_AFD */ if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) goto end; break; - case NAL_SPS: { - case H264_NAL_SPS: - ret = ff_h264_decode_seq_parameter_set(&nal->gb, avctx, &h->ps); - if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) - goto end; ++ case H264_NAL_SPS: { + GetBitContext tmp_gb = nal->gb; + if (ff_h264_decode_seq_parameter_set(&tmp_gb, avctx, &h->ps, 0) >= 0) + break; + av_log(h->avctx, AV_LOG_DEBUG, + "SPS decoding failure, trying again with the complete NAL\n"); + init_get_bits8(&tmp_gb, nal->raw_data + 1, nal->raw_size - 1); + if (ff_h264_decode_seq_parameter_set(&tmp_gb, avctx, &h->ps, 0) >= 0) + break; + ff_h264_decode_seq_parameter_set(&nal->gb, avctx, &h->ps, 1); break; + } - case NAL_PPS: + case H264_NAL_PPS: ret = ff_h264_decode_picture_parameter_set(&nal->gb, avctx, &h->ps, nal->size_bits); if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) @@@ -1157,8 -912,8 +1157,8 @@@ static int h264_decode_frame(AVCodecCon if (buf_index < 0) return AVERROR_INVALIDDATA; - if (!h->cur_pic_ptr && h->nal_unit_type == NAL_END_SEQUENCE) { + if (!h->cur_pic_ptr && h->nal_unit_type == H264_NAL_END_SEQUENCE) { - buf_size = 0; + av_assert0(buf_index <= buf_size); goto out; } diff --cc libavformat/mxfenc.c index 80318b8,1431fc6..ffd0bf2 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@@ -1656,255 -1280,6 +1656,255 @@@ static int mxf_write_partition(AVFormat return 0; } +static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, +AVPacket *pkt) +{ + MXFContext *mxf = s->priv_data; + MXFStreamContext *sc = st->priv_data; + int i, cid; + uint8_t* header_cid; + int frame_size = 0; + + if (mxf->header_written) + return 1; + + if (pkt->size < 43) + return -1; + + header_cid = pkt->data + 0x28; + cid = header_cid[0] << 24 | header_cid[1] << 16 | header_cid[2] << 8 | header_cid[3]; + + if ((frame_size = avpriv_dnxhd_get_frame_size(cid)) < 0) + return -1; + if ((sc->interlaced = avpriv_dnxhd_get_interlaced(cid)) < 0) + return AVERROR_INVALIDDATA; + + switch (cid) { + case 1235: + sc->index = 24; + sc->component_depth = 10; + break; + case 1237: + sc->index = 25; + break; + case 1238: + sc->index = 26; + break; + case 1241: + sc->index = 27; + sc->component_depth = 10; + break; + case 1242: + sc->index = 28; + break; + case 1243: + sc->index = 29; + break; + case 1250: + sc->index = 30; + sc->component_depth = 10; + break; + case 1251: + sc->index = 31; + break; + case 1252: + sc->index = 32; + break; + case 1253: + sc->index = 33; + break; + default: + return -1; + } + + sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul; + sc->aspect_ratio = (AVRational){ 16, 9 }; + + if(s->oformat == &ff_mxf_opatom_muxer){ + mxf->edit_unit_byte_count = frame_size; + return 1; + } + + mxf->edit_unit_byte_count = KAG_SIZE; + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + MXFStreamContext *sc = st->priv_data; + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + mxf->edit_unit_byte_count += 16 + 4 + sc->aic.samples[0]*sc->aic.sample_size; + mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + mxf->edit_unit_byte_count += 16 + 4 + frame_size; + mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); + } + } + + return 1; +} + +static int mxf_parse_dv_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) +{ + MXFContext *mxf = s->priv_data; + MXFStreamContext *sc = st->priv_data; + uint8_t *vs_pack, *vsc_pack; + int i, ul_index, frame_size, stype, pal; + + if (mxf->header_written) + return 1; + + // Check for minimal frame size + if (pkt->size < 120000) + return -1; + + vs_pack = pkt->data + 80*5 + 48; + vsc_pack = pkt->data + 80*5 + 53; + stype = vs_pack[3] & 0x1f; + pal = (vs_pack[3] >> 5) & 0x1; + + if ((vs_pack[2] & 0x07) == 0x02) + sc->aspect_ratio = (AVRational){ 16, 9 }; + else + sc->aspect_ratio = (AVRational){ 4, 3 }; + + sc->interlaced = (vsc_pack[3] >> 4) & 0x01; + // TODO: fix dv encoder to set proper FF/FS value in VSC pack + // and set field dominance accordingly + // av_log(s, AV_LOG_DEBUG, "DV vsc pack ff/ss = %x\n", vsc_pack[2] >> 6); + + switch (stype) { + case 0x18: // DV100 720p + ul_index = 6 + pal; + frame_size = pal ? 288000 : 240000; + if (sc->interlaced) { + av_log(s, AV_LOG_ERROR, "source marked as interlaced but codec profile is progressive\n"); + sc->interlaced = 0; + } + break; + case 0x14: // DV100 1080i + ul_index = 4 + pal; + frame_size = pal ? 576000 : 480000; + break; + case 0x04: // DV50 + ul_index = 2 + pal; + frame_size = pal ? 288000 : 240000; + break; + default: // DV25 + ul_index = 0 + pal; + frame_size = pal ? 144000 : 120000; + } + + sc->index = ul_index + 16; + sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul; + + if(s->oformat == &ff_mxf_opatom_muxer) { + mxf->edit_unit_byte_count = frame_size; + return 1; + } + + mxf->edit_unit_byte_count = KAG_SIZE; + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + MXFStreamContext *sc = st->priv_data; + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + mxf->edit_unit_byte_count += 16 + 4 + sc->aic.samples[0]*sc->aic.sample_size; + mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + mxf->edit_unit_byte_count += 16 + 4 + frame_size; + mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); + } + } + + return 1; +} + +static const struct { + UID uid; + int frame_size; + int profile; + uint8_t interlaced; +} mxf_h264_codec_uls[] = { + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x20,0x01 }, 0, 110, 0 }, // AVC High 10 Intra + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x01 }, 232960, 0, 1 }, // AVC Intra 50 1080i60 + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x02 }, 281088, 0, 1 }, // AVC Intra 50 1080i50 + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x03 }, 232960, 0, 0 }, // AVC Intra 50 1080p30 + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x04 }, 281088, 0, 0 }, // AVC Intra 50 1080p25 + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x08 }, 116736, 0, 0 }, // AVC Intra 50 720p60 + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x21,0x09 }, 140800, 0, 0 }, // AVC Intra 50 720p50 + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x30,0x01 }, 0, 122, 0 }, // AVC High 422 Intra + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x01 }, 472576, 0, 1 }, // AVC Intra 100 1080i60 + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x02 }, 568832, 0, 1 }, // AVC Intra 100 1080i50 + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x03 }, 472576, 0, 0 }, // AVC Intra 100 1080p30 + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x04 }, 568832, 0, 0 }, // AVC Intra 100 1080p25 + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x08 }, 236544, 0, 0 }, // AVC Intra 100 720p60 + {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x32,0x31,0x09 }, 284672, 0, 0 }, // AVC Intra 100 720p50 +}; + +static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, + AVPacket *pkt, MXFIndexEntry *e) +{ + MXFContext *mxf = s->priv_data; + MXFStreamContext *sc = st->priv_data; + static const int mxf_h264_num_codec_uls = sizeof(mxf_h264_codec_uls) / sizeof(mxf_h264_codec_uls[0]); + const uint8_t *buf = pkt->data; + const uint8_t *buf_end = pkt->data + pkt->size; + uint32_t state = -1; + int extra_size = 512; // support AVC Intra files without SPS/PPS header + int i, frame_size; + uint8_t uid_found; + + if (pkt->size > extra_size) + buf_end -= pkt->size - extra_size; // no need to parse beyond SPS/PPS header + + for (;;) { + buf = avpriv_find_start_code(buf, buf_end, &state); + if (buf >= buf_end) + break; + --buf; + switch (state & 0x1f) { - case NAL_SPS: ++ case H264_NAL_SPS: + st->codecpar->profile = buf[1]; + e->flags |= 0x40; + break; - case NAL_PPS: ++ case H264_NAL_PPS: + if (e->flags & 0x40) { // sequence header present + e->flags |= 0x80; // random access + extra_size = 0; + buf = buf_end; + } + break; + default: + break; + } + } + + if (mxf->header_written) + return 1; + + sc->aspect_ratio = (AVRational){ 16, 9 }; // 16:9 is mandatory for broadcast HD + sc->component_depth = 10; // AVC Intra is always 10 Bit + sc->interlaced = st->codecpar->field_order != AV_FIELD_PROGRESSIVE ? 1 : 0; + if (sc->interlaced) + sc->field_dominance = 1; // top field first is mandatory for AVC Intra + + uid_found = 0; + frame_size = pkt->size + extra_size; + for (i = 0; i < mxf_h264_num_codec_uls; i++) { + if (frame_size == mxf_h264_codec_uls[i].frame_size && sc->interlaced == mxf_h264_codec_uls[i].interlaced) { + sc->codec_ul = &mxf_h264_codec_uls[i].uid; + return 1; + } else if (st->codecpar->profile == mxf_h264_codec_uls[i].profile) { + sc->codec_ul = &mxf_h264_codec_uls[i].uid; + uid_found = 1; + } + } + + if (!uid_found) { + av_log(s, AV_LOG_ERROR, "AVC Intra 50/100 supported only\n"); + return 0; + } + + return 1; +} + static const UID mxf_mpeg2_codec_uls[] = { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x10,0x00 }, // MP-ML I-Frame { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, // MP-ML Long GOP _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog