#ifndef AVCODEC_H264_H
#define AVCODEC_H264_H
+#include "libavutil/buffer.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/thread.h"
#include "cabac.h"
#include "error_resilience.h"
#include "get_bits.h"
#include "h264_parse.h"
+#include "h264_sei.h"
#include "h2645_parse.h"
#include "h264chroma.h"
#include "h264dsp.h"
#define FIELD_OR_MBAFF_PICTURE(h) (FRAME_MBAFF(h) || FIELD_PICTURE(h))
#ifndef CABAC
-#define CABAC(h) h->pps.cabac
+#define CABAC(h) h->ps.pps->cabac
#endif
-#define CHROMA422(h) (h->sps.chroma_format_idc == 2)
-#define CHROMA444(h) (h->sps.chroma_format_idc == 3)
+#define CHROMA422(h) (h->ps.sps->chroma_format_idc == 2)
+#define CHROMA444(h) (h->ps.sps->chroma_format_idc == 3)
#define EXTENDED_SAR 255
NAL_FF_IGNORE = 0xff0f001,
};
-/**
- * SEI message types
- */
-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_REGISTERED = 4, ///< registered user data as specified by Rec. ITU-T 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
- SEI_TYPE_DISPLAY_ORIENTATION = 47, ///< display orientation
-} SEI_Type;
-
-/**
- * pic_struct in picture timing SEI message
- */
-typedef enum {
- SEI_PIC_STRUCT_FRAME = 0, ///< 0: %frame
- SEI_PIC_STRUCT_TOP_FIELD = 1, ///< 1: top field
- SEI_PIC_STRUCT_BOTTOM_FIELD = 2, ///< 2: bottom field
- SEI_PIC_STRUCT_TOP_BOTTOM = 3, ///< 3: top field, bottom field, in that order
- SEI_PIC_STRUCT_BOTTOM_TOP = 4, ///< 4: bottom field, top field, in that order
- SEI_PIC_STRUCT_TOP_BOTTOM_TOP = 5, ///< 5: top field, bottom field, top field repeated, in that order
- SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM = 6, ///< 6: bottom field, top field, bottom field repeated, in that order
- SEI_PIC_STRUCT_FRAME_DOUBLING = 7, ///< 7: %frame doubling
- SEI_PIC_STRUCT_FRAME_TRIPLING = 8 ///< 8: %frame tripling
-} SEI_PicStructType;
-
/**
* Sequence parameter set
*/
int bit_depth_chroma; ///< bit_depth_chroma_minus8 + 8
int residual_color_transform_flag; ///< residual_colour_transform_flag
int constraint_set_flags; ///< constraint_set[0-3]_flag
- int new; ///< flag to keep track if the decoder context needs re-init due to changed SPS
} SPS;
/**
uint8_t scaling_matrix8[6][64];
uint8_t chroma_qp_table[2][64]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table
int chroma_qp_diff;
+
+ uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16];
+ uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64];
+ uint32_t(*dequant4_coeff[6])[16];
+ uint32_t(*dequant8_coeff[6])[64];
} PPS;
+typedef struct H264ParamSets {
+ AVBufferRef *sps_list[MAX_SPS_COUNT];
+ AVBufferRef *pps_list[MAX_PPS_COUNT];
+
+ /* currently active parameters sets */
+ const PPS *pps;
+ // FIXME this should properly be const
+ SPS *sps;
+} H264ParamSets;
+
/**
* Memory management control operation opcode.
*/
uint32_t *mb2br_xy;
int b_stride; // FIXME use s->b4_stride
- SPS sps; ///< current sps
- PPS pps; ///< current pps
-
- 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];
- uint32_t(*dequant8_coeff[6])[64];
-
uint16_t *slice_table; ///< slice_table_base + 2*mb_stride + 1
// interlacing specific flags
const uint8_t *field_scan8x8_q0;
const uint8_t *field_scan8x8_cavlc_q0;
- int x264_build;
-
int mb_y;
int mb_height, mb_width;
int mb_stride;
int bit_depth_luma; ///< luma bit depth from sps to detect changes
int chroma_format_idc; ///< chroma format from sps to detect changes
- SPS *sps_buffers[MAX_SPS_COUNT];
- PPS *pps_buffers[MAX_PPS_COUNT];
-
- int dequant_coeff_pps; ///< reinit tables when pps changes
+ H264ParamSets ps;
uint16_t *slice_table_base;
- // POC stuff
- int poc_lsb;
- int poc_msb;
- int delta_poc_bottom;
- int delta_poc[2];
- int frame_num;
- int prev_poc_msb; ///< poc_msb of the last reference pic for POC type 0
- int prev_poc_lsb; ///< poc_lsb of the last reference pic for POC type 0
- int frame_num_offset; ///< for POC type 2
- int prev_frame_num_offset; ///< for POC type 2
- int prev_frame_num; ///< frame_num of the last pic for POC type 1/2
+ H264POCContext poc;
/**
* frame_num for frames or 2 * frame_num + 1 for field pics.
/** @} */
- /**
- * pic_struct in picture timing SEI message
- */
- SEI_PicStructType sei_pic_struct;
-
/**
* Complement sei_pic_struct
* SEI_PIC_STRUCT_TOP_BOTTOM and SEI_PIC_STRUCT_BOTTOM_TOP indicate interlaced frames.
*/
int prev_interlaced_frame;
- /**
- * frame_packing_arrangment SEI message
- */
- int sei_frame_packing_present;
- int frame_packing_arrangement_type;
- int content_interpretation_type;
- int quincunx_subsampling;
-
- /**
- * display orientation SEI message
- */
- int sei_display_orientation_present;
- int sei_anticlockwise_rotation;
- int sei_hflip, sei_vflip;
-
- /**
- * User data registered by Rec. ITU-T T.35 SEI
- */
- int sei_reguserdata_afd_present;
- uint8_t active_format_description;
- int a53_caption_size;
- uint8_t *a53_caption;
-
- /**
- * Bit set of clock types for fields/frames in picture timing SEI message.
- * For each found ct_type, appropriate bit is set (e.g., bit 1 for
- * interlaced).
- */
- int sei_ct_type;
-
- /**
- * dpb_output_delay in picture timing SEI message, see H.264 C.2.2
- */
- int sei_dpb_output_delay;
-
- /**
- * cpb_removal_delay in picture timing SEI message, see H.264 C.1.2
- */
- int sei_cpb_removal_delay;
-
- /**
- * recovery_frame_cnt from SEI message
- *
- * Set to -1 if no recovery point SEI message found or to number of frames
- * before playback synchronizes. Frames having recovery point are key
- * frames.
- */
- int sei_recovery_frame_cnt;
-
/**
* recovery_frame is the frame_num at which the next frame should
* be fully constructed.
* slices) anymore */
int setup_finished;
- // Timestamp stuff
- int sei_buffering_period_present; ///< Buffering period SEI flag
- int initial_cpb_removal_delay[32]; ///< Initial timestamps for CPBs
-
int enable_er;
+ H264SEIContext sei;
+
AVBufferPool *qscale_table_pool;
AVBufferPool *mb_type_pool;
AVBufferPool *motion_val_pool;
extern const uint16_t ff_h264_mb_sizes[4];
-/**
- * Decode SEI
- */
-int ff_h264_decode_sei(H264Context *h);
-
/**
* Decode SPS
*/
-int ff_h264_decode_seq_parameter_set(H264Context *h);
-
-/**
- * compute profile from sps
- */
-int ff_h264_get_profile(SPS *sps);
+int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
+ H264ParamSets *ps);
/**
* Decode PPS
*/
-int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length);
-
-/**
- * Decode a network abstraction layer unit.
- * @param consumed is the number of bytes used as input
- * @param length is the length of the array
- * @param dst_length is the number of decoded bytes FIXME here
- * or a decode rbsp tailing?
- * @return decoded bytes, might be src+1 if no escapes
- */
-const uint8_t *ff_h264_decode_nal(H264Context *h, H264SliceContext *sl, const uint8_t *src,
- int *dst_length, int *consumed, int length);
+int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
+ H264ParamSets *ps, int bit_length);
/**
* Free any data that may have been allocated in the H264 context
*/
int ff_h264_alloc_tables(H264Context *h);
-int ff_h264_decode_ref_pic_list_reordering(H264Context *h, H264SliceContext *sl);
-void ff_h264_fill_mbaff_ref_list(H264Context *h, H264SliceContext *sl);
+int ff_h264_decode_ref_pic_list_reordering(const H264Context *h, H264SliceContext *sl);
+void ff_h264_fill_mbaff_ref_list(H264SliceContext *sl);
void ff_h264_remove_all_refs(H264Context *h);
/**
int ff_generate_sliding_window_mmcos(H264Context *h, int first_slice);
void ff_h264_hl_decode_mb(const H264Context *h, H264SliceContext *sl);
-int ff_h264_decode_extradata(H264Context *h);
int ff_h264_decode_init(AVCodecContext *avctx);
void ff_h264_decode_init_vlc(void);
uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,
unsigned int linesize, unsigned int uvlinesize);
-/**
- * Reset SEI values at the beginning of the frame.
- *
- * @param h H.264 context.
- */
-void ff_h264_reset_sei(H264Context *h);
-
/*
* o-o o-o
* / / /
*/
static av_always_inline int get_chroma_qp(const H264Context *h, int t, int qscale)
{
- return h->pps.chroma_qp_table[t][qscale];
+ return h->ps.pps->chroma_qp_table[t][qscale];
}
/**
static av_always_inline int get_dct8x8_allowed(const H264Context *h, H264SliceContext *sl)
{
- if (h->sps.direct_8x8_inference_flag)
+ if (h->ps.sps->direct_8x8_inference_flag)
return !(AV_RN64A(sl->sub_mb_type) &
((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8) *
0x0001000100010001ULL));
int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl);
void ff_h264_draw_horiz_band(const H264Context *h, H264SliceContext *sl, int y, int height);
-int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc);
-int ff_set_ref_count(H264Context *h, H264SliceContext *sl);
int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl);
int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count);