diff options
Diffstat (limited to 'libavcodec/h264.h')
-rw-r--r-- | libavcodec/h264.h | 147 |
1 files changed, 121 insertions, 26 deletions
diff --git a/libavcodec/h264.h b/libavcodec/h264.h index cd4bf87..b94f06b 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -2,20 +2,20 @@ * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -36,6 +36,7 @@ #include "h264dsp.h" #include "h264pred.h" #include "h264qpel.h" +#include "internal.h" // for avpriv_find_start_code() #include "me_cmp.h" #include "mpegutils.h" #include "parser.h" @@ -43,8 +44,8 @@ #include "rectangle.h" #include "videodsp.h" -#define H264_MAX_PICTURE_COUNT 32 -#define H264_MAX_THREADS 16 +#define H264_MAX_PICTURE_COUNT 36 +#define H264_MAX_THREADS 32 #define MAX_SPS_COUNT 32 #define MAX_PPS_COUNT 256 @@ -53,6 +54,8 @@ #define MAX_DELAYED_PIC_COUNT 16 +#define MAX_MBPAIR_SIZE (256*1024) // a tighter bound could be calculated if someone cares about a few bytes + /* Compiling in interlaced support reduces the speed * of progressive decoding by about 2%. */ #define ALLOW_INTERLACE @@ -66,10 +69,10 @@ #define MAX_SLICES 16 #ifdef ALLOW_INTERLACE -#define MB_MBAFF(h) h->mb_mbaff -#define MB_FIELD(h) h->mb_field_decoding_flag -#define FRAME_MBAFF(h) h->mb_aff_frame -#define FIELD_PICTURE(h) (h->picture_structure != PICT_FRAME) +#define MB_MBAFF(h) (h)->mb_mbaff +#define MB_FIELD(h) (h)->mb_field_decoding_flag +#define FRAME_MBAFF(h) (h)->mb_aff_frame +#define FIELD_PICTURE(h) ((h)->picture_structure != PICT_FRAME) #define LEFT_MBS 2 #define LTOP 0 #define LBOT 1 @@ -89,11 +92,12 @@ #define FIELD_OR_MBAFF_PICTURE(h) (FRAME_MBAFF(h) || FIELD_PICTURE(h)) #ifndef CABAC -#define CABAC(h) h->pps.cabac +#define CABAC(h) (h)->pps.cabac #endif -#define CHROMA422(h) (h->sps.chroma_format_idc == 2) -#define CHROMA444(h) (h->sps.chroma_format_idc == 3) +#define CHROMA(h) ((h)->sps.chroma_format_idc) +#define CHROMA422(h) ((h)->sps.chroma_format_idc == 2) +#define CHROMA444(h) ((h)->sps.chroma_format_idc == 3) #define EXTENDED_SAR 255 @@ -102,7 +106,7 @@ #define IS_REF0(a) ((a) & MB_TYPE_REF0) #define IS_8x8DCT(a) ((a) & MB_TYPE_8x8DCT) -#define QP_MAX_NUM (51 + 2 * 6) // The maximum supported qp +#define QP_MAX_NUM (51 + 6*6) // The maximum supported qp /* NAL unit types */ enum { @@ -129,6 +133,7 @@ enum { typedef enum { SEI_TYPE_BUFFERING_PERIOD = 0, ///< buffering period (H.264, D.1.1) SEI_TYPE_PIC_TIMING = 1, ///< picture timing + SEI_TYPE_USER_DATA_ITU_T_T35 = 4, ///< user data registered by ITU-T Recommendation T.35 SEI_TYPE_USER_DATA_UNREGISTERED = 5, ///< unregistered user data SEI_TYPE_RECOVERY_POINT = 6, ///< recovery point (frame # to decoder sync) SEI_TYPE_FRAME_PACKING = 45, ///< frame packing arrangement @@ -151,6 +156,19 @@ typedef enum { } SEI_PicStructType; /** + * frame_packing_arrangement types + */ +typedef enum { + SEI_FPA_TYPE_CHECKERBOARD = 0, + SEI_FPA_TYPE_INTERLEAVE_COLUMN = 1, + SEI_FPA_TYPE_INTERLEAVE_ROW = 2, + SEI_FPA_TYPE_SIDE_BY_SIDE = 3, + SEI_FPA_TYPE_TOP_BOTTOM = 4, + SEI_FPA_TYPE_INTERLEAVE_TEMPORAL = 5, + SEI_FPA_TYPE_2D = 6, +} SEI_FpaType; + +/** * Sequence parameter set */ typedef struct SPS { @@ -234,11 +252,23 @@ typedef struct PPS { int transform_8x8_mode; ///< transform_8x8_mode_flag uint8_t scaling_matrix4[6][16]; uint8_t scaling_matrix8[6][64]; - uint8_t chroma_qp_table[2][64]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table + uint8_t chroma_qp_table[2][QP_MAX_NUM+1]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table int chroma_qp_diff; } PPS; /** + * Frame Packing Arrangement Type + */ +typedef struct FPA { + int frame_packing_arrangement_id; + int frame_packing_arrangement_cancel_flag; ///< is previous arrangement canceled, -1 if never received + SEI_FpaType frame_packing_arrangement_type; + int frame_packing_arrangement_repetition_period; + int content_interpretation_type; + int quincunx_sampling_flag; +} FPA; + +/** * Memory management control operation opcode. */ typedef enum MMCOOpcode { @@ -262,6 +292,7 @@ typedef struct MMCO { typedef struct H264Picture { struct AVFrame f; + uint8_t avframe_padding[1024]; // hack to allow linking to a avutil with larger AVFrame ThreadFrame tf; AVBufferRef *qscale_table_buf; @@ -287,7 +318,7 @@ typedef struct H264Picture { int pic_id; /**< pic_num (short -> no wrap version of pic_num, pic_num & max_pic_num; long -> long_pic_num) */ int long_ref; ///< 1->long term reference 0->short term reference - int ref_poc[2][2][32]; ///< POCs of the frames used as reference (FIXME need per slice) + int ref_poc[2][2][32]; ///< POCs of the frames/fields used as reference (FIXME need per slice) int ref_count[2][2]; ///< number of entries in ref_poc (FIXME need per slice) int mbaff; ///< 1 -> MBAFF frame 0-> not MBAFF int field_picture; ///< whether or not picture was encoded in separate fields @@ -295,6 +326,12 @@ typedef struct H264Picture { int needs_realloc; ///< picture needs to be reallocated (eg due to a frame size change) int reference; int recovered; ///< picture at IDR or recovery point + recovery count + int invalid_gap; + int sei_recovery_frame_cnt; + + int crop; + int crop_left; + int crop_top; } H264Picture; /** @@ -398,9 +435,12 @@ typedef struct H264Context { ptrdiff_t mb_linesize; ///< may be equal to s->linesize or s->linesize * 2, for mbaff ptrdiff_t mb_uvlinesize; + unsigned current_sps_id; ///< id of the current SPS SPS sps; ///< current sps PPS pps; ///< current pps + int au_pps_id; ///< pps_id of current access unit + uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16]; // FIXME should these be moved down? uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64]; uint32_t(*dequant4_coeff[6])[16]; @@ -457,7 +497,7 @@ typedef struct H264Context { GetBitContext *inter_gb_ptr; const uint8_t *intra_pcm_ptr; - DECLARE_ALIGNED(16, int16_t, mb)[16 * 48 * 2]; ///< as a dct coeffecient is int32_t in high depth, we need to reserve twice the space. + DECLARE_ALIGNED(16, int16_t, mb)[16 * 48 * 2]; ///< as a dct coefficient is int32_t in high depth, we need to reserve twice the space. DECLARE_ALIGNED(16, int16_t, mb_luma_dc)[3][16 * 2]; int16_t mb_padding[256 * 2]; ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too large or ensure that there is some unused stuff after mb @@ -486,12 +526,12 @@ typedef struct H264Context { uint8_t field_scan[16]; uint8_t field_scan8x8[64]; uint8_t field_scan8x8_cavlc[64]; - const uint8_t *zigzag_scan_q0; - const uint8_t *zigzag_scan8x8_q0; - const uint8_t *zigzag_scan8x8_cavlc_q0; - const uint8_t *field_scan_q0; - const uint8_t *field_scan8x8_q0; - const uint8_t *field_scan8x8_cavlc_q0; + uint8_t zigzag_scan_q0[16]; + uint8_t zigzag_scan8x8_q0[64]; + uint8_t zigzag_scan8x8_cavlc_q0[64]; + uint8_t field_scan_q0[16]; + uint8_t field_scan8x8_q0[64]; + uint8_t field_scan8x8_cavlc_q0[64]; int x264_build; @@ -588,7 +628,7 @@ typedef struct H264Context { struct H264Context *thread_context[H264_MAX_THREADS]; /** - * current slice number, used to initalize slice_num of each thread/context + * current slice number, used to initialize slice_num of each thread/context */ int current_slice; @@ -611,6 +651,7 @@ typedef struct H264Context { enum AVPictureType pict_type; int last_slice_type; + unsigned int last_ref_count[2]; /** @} */ /** @@ -668,6 +709,13 @@ typedef struct H264Context { int sei_recovery_frame_cnt; /** + * Are the SEI recovery points looking valid. + */ + int valid_recovery_point; + + FPA sei_fpa; + + /** * recovery_frame is the frame_num at which the next frame should * be fully constructed. * @@ -688,6 +736,8 @@ typedef struct H264Context { int frame_recovered; ///< Initial frame has been completely recovered + int has_recovery_point; + int luma_weight_flag[2]; ///< 7.4.3.2 luma_weight_lX_flag int chroma_weight_flag[2]; ///< 7.4.3.2 chroma_weight_lX_flag @@ -697,6 +747,12 @@ typedef struct H264Context { int cur_chroma_format_idc; uint8_t *bipred_scratchpad; + + int16_t slice_row[MAX_SLICES]; ///< to detect when MAX_SLICES is too low + + uint8_t parse_history[6]; + int parse_history_count; + int parse_last_mb; uint8_t *edge_emu_buffer; int16_t *dc_val_base; @@ -710,7 +766,7 @@ typedef struct H264Context { qpel_mc_func (*qpel_avg)[16]; } H264Context; -extern const uint8_t ff_h264_chroma_qp[3][QP_MAX_NUM + 1]; ///< One chroma qp table for each supported bit depth (8, 9, 10). +extern const uint8_t ff_h264_chroma_qp[7][QP_MAX_NUM + 1]; ///< One chroma qp table for each possible bit depth (8-14). extern const uint16_t ff_h264_mb_sizes[4]; /** @@ -793,7 +849,7 @@ int ff_h264_check_intra4x4_pred_mode(H264Context *h); int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma); void ff_h264_hl_decode_mb(H264Context *h); -int ff_h264_decode_extradata(H264Context *h); +int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size); int ff_h264_decode_init(AVCodecContext *avctx); void ff_h264_decode_init_vlc(void); @@ -831,6 +887,12 @@ void ff_h264_filter_mb(H264Context *h, int mb_x, int mb_y, */ void ff_h264_reset_sei(H264Context *h); +/** + * Get stereo_mode string from the h264 frame_packing_arrangement + * @param h H.264 context. + */ +const char* ff_h264_sei_stereo_mode(H264Context *h); + /* * o-o o-o * / / / @@ -1031,6 +1093,34 @@ static av_always_inline int get_dct8x8_allowed(H264Context *h) 0x0001000100010001ULL)); } +static inline int find_start_code(const uint8_t *buf, int buf_size, + int buf_index, int next_avc) +{ + uint32_t state = -1; + + buf_index = avpriv_find_start_code(buf + buf_index, buf + next_avc + 1, &state) - buf - 1; + + return FFMIN(buf_index, buf_size); +} + +static inline int get_avc_nalsize(H264Context *h, const uint8_t *buf, + int buf_size, int *buf_index) +{ + int i, nalsize = 0; + + if (*buf_index >= buf_size - h->nal_length_size) + return -1; + + for (i = 0; i < h->nal_length_size; i++) + nalsize = ((unsigned)nalsize << 8) | buf[(*buf_index)++]; + if (nalsize <= 0 || nalsize > buf_size - *buf_index) { + av_log(h->avctx, AV_LOG_ERROR, + "AVC: nal size %d\n", nalsize); + return -1; + } + return nalsize; +} + int ff_h264_field_end(H264Context *h, int in_setup); int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src); @@ -1045,6 +1135,9 @@ int ff_pred_weight_table(H264Context *h); int ff_set_ref_count(H264Context *h); int ff_h264_decode_slice_header(H264Context *h, H264Context *h0); +#define SLICE_SINGLETHREAD 1 +#define SLICE_SKIPED 2 + int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count); int ff_h264_update_thread_context(AVCodecContext *dst, const AVCodecContext *src); @@ -1053,4 +1146,6 @@ void ff_h264_flush_change(H264Context *h); void ff_h264_free_tables(H264Context *h, int free_rbsp); +void ff_h264_set_erpic(ERPicture *dst, H264Picture *src); + #endif /* AVCODEC_H264_H */ |