diff options
Diffstat (limited to 'libavcodec/h264dec.h')
-rw-r--r-- | libavcodec/h264dec.h | 117 |
1 files changed, 91 insertions, 26 deletions
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index fbe68c1dc3..a73a9dd0b9 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.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 */ @@ -49,12 +49,14 @@ #include "rectangle.h" #include "videodsp.h" -#define H264_MAX_PICTURE_COUNT 32 +#define H264_MAX_PICTURE_COUNT 36 #define MAX_MMCO_COUNT 66 #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 @@ -68,17 +70,17 @@ #define MAX_SLICES 32 #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(sl) (sl)->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 #define LEFT(i) (i) #else #define MB_MBAFF(h) 0 -#define MB_FIELD(h) 0 +#define MB_FIELD(sl) 0 #define FRAME_MBAFF(h) 0 #define FIELD_PICTURE(h) 0 #undef IS_INTERLACED @@ -91,11 +93,12 @@ #define FIELD_OR_MBAFF_PICTURE(h) (FRAME_MBAFF(h) || FIELD_PICTURE(h)) #ifndef CABAC -#define CABAC(h) h->ps.pps->cabac +#define CABAC(h) (h)->ps.pps->cabac #endif -#define CHROMA422(h) (h->ps.sps->chroma_format_idc == 2) -#define CHROMA444(h) (h->ps.sps->chroma_format_idc == 3) +#define CHROMA(h) ((h)->ps.sps->chroma_format_idc) +#define CHROMA422(h) ((h)->ps.sps->chroma_format_idc == 2) +#define CHROMA444(h) ((h)->ps.sps->chroma_format_idc == 3) #define MB_TYPE_REF0 MB_TYPE_ACPRED // dirty but it fits in 16 bit #define MB_TYPE_8x8DCT 0x01000000 @@ -151,13 +154,19 @@ 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 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; typedef struct H264Ref { @@ -268,7 +277,7 @@ typedef struct H264SliceContext { * according to picture reordering in slice header */ struct { uint8_t op; - uint8_t val; + uint32_t val; } ref_modifications[2][32]; int nb_ref_modifications[2]; @@ -342,6 +351,7 @@ typedef struct H264Context { H264Picture DPB[H264_MAX_PICTURE_COUNT]; H264Picture *cur_pic_ptr; H264Picture cur_pic; + H264Picture last_pic_for_ec; H264SliceContext *slice_ctx; int nb_slice_ctx; @@ -354,6 +364,14 @@ typedef struct H264Context { int width, height; int chroma_x_shift, chroma_y_shift; + /** + * Backup frame properties: needed, because they can be different + * between returned frame and last decoded frame. + **/ + int backup_width; + int backup_height; + enum AVPixelFormat backup_pix_fmt; + int droppable; int coded_picture_number; @@ -407,12 +425,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 mb_y; int mb_height, mb_width; @@ -440,6 +458,7 @@ typedef struct H264Context { H264POCContext poc; + H264Ref default_ref[2]; H264Picture *short_ref[32]; H264Picture *long_ref[32]; H264Picture *delayed_pic[MAX_DELAYED_PIC_COUNT + 2]; // FIXME size? @@ -467,6 +486,20 @@ typedef struct H264Context { */ int current_slice; + /** + * Max number of threads / contexts. + * This is equal to AVCodecContext.thread_count unless + * multithreaded decoding is impossible, in which case it is + * reduced to 1. + */ + int max_contexts; + + /** + * 1 if the single thread fallback warning has already been + * displayed, 0 otherwise. + */ + int single_decode_warning; + /** @} */ /** @@ -478,6 +511,11 @@ typedef struct H264Context { int prev_interlaced_frame; /** + * Are the SEI recovery points looking valid. + */ + int valid_recovery_point; + + /** * recovery_frame is the frame_num at which the next frame should * be fully constructed. * @@ -498,12 +536,20 @@ typedef struct H264Context { int frame_recovered; ///< Initial frame has been completely recovered + int has_recovery_point; + + int missing_fields; + /* for frame threading, this is set to 1 * after finish_setup() has been called, so we cannot modify * some context properties (which are supposed to stay constant between * slices) anymore */ int setup_finished; + int cur_chroma_format_idc; + int cur_bit_depth_luma; + int16_t slice_row[MAX_SLICES]; ///< to detect when MAX_SLICES is too low + int enable_er; H264SEIContext sei; @@ -518,6 +564,12 @@ typedef struct H264Context { extern const uint16_t ff_h264_mb_sizes[4]; /** + * Uninit H264 param sets structure. + */ + +void ff_h264_ps_uninit(H264ParamSets *ps); + +/** * Reconstruct bitstream slice_type. */ int ff_h264_get_slice_type(const H264SliceContext *sl); @@ -529,7 +581,7 @@ int ff_h264_get_slice_type(const H264SliceContext *sl); int ff_h264_alloc_tables(H264Context *h); int ff_h264_decode_ref_pic_list_reordering(const H264Context *h, H264SliceContext *sl); -int ff_h264_build_ref_list(const H264Context *h, H264SliceContext *sl); +int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl); void ff_h264_remove_all_refs(H264Context *h); /** @@ -558,8 +610,6 @@ int ff_h264_decode_mb_cabac(const H264Context *h, H264SliceContext *sl); void ff_h264_init_cabac_states(const H264Context *h, H264SliceContext *sl); -void ff_h264_init_dequant_tables(H264Context *h); - void ff_h264_direct_dist_scale_factor(const H264Context *const h, H264SliceContext *sl); void ff_h264_direct_ref_list_init(const H264Context *const h, H264SliceContext *sl); void ff_h264_pred_direct_motion(const H264Context *const h, H264SliceContext *sl, @@ -622,7 +672,7 @@ static const uint8_t scan8[16 * 3 + 3] = { 0 + 0 * 8, 0 + 5 * 8, 0 + 10 * 8 }; -static av_always_inline uint32_t pack16to32(int a, int b) +static av_always_inline uint32_t pack16to32(unsigned a, unsigned b) { #if HAVE_BIGENDIAN return (b & 0xFFFF) + (a << 16); @@ -631,7 +681,7 @@ static av_always_inline uint32_t pack16to32(int a, int b) #endif } -static av_always_inline uint16_t pack8to16(int a, int b) +static av_always_inline uint16_t pack8to16(unsigned a, unsigned b) { #if HAVE_BIGENDIAN return (b & 0xFF) + (a << 8); @@ -778,6 +828,16 @@ static av_always_inline int get_dct8x8_allowed(const H264Context *h, H264SliceCo 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); +} + int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup); int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src); @@ -789,6 +849,9 @@ void ff_h264_draw_horiz_band(const H264Context *h, H264SliceContext *sl, int y, int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, const H2645NAL *nal); +#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); @@ -797,4 +860,6 @@ void ff_h264_flush_change(H264Context *h); void ff_h264_free_tables(H264Context *h); +void ff_h264_set_erpic(ERPicture *dst, H264Picture *src); + #endif /* AVCODEC_H264DEC_H */ |