*/
/**
- * @file h264.h
+ * @file libavcodec/h264.h
* H.264 / AVC / MPEG4 part10 codec.
* @author Michael Niedermayer <michaelni@gmx.at>
*/
-#ifndef FFMPEG_H264_H
-#define FFMPEG_H264_H
+#ifndef AVCODEC_H264_H
+#define AVCODEC_H264_H
#include "dsputil.h"
#include "cabac.h"
#define MAX_MMCO_COUNT 66
+#define MAX_DELAYED_PIC_COUNT 16
+
/* Compiling in interlaced support reduces the speed
* of progressive decoding by about 2%. */
#define ALLOW_INTERLACE
+#define ALLOW_NOCHROMA
+
+/**
+ * The maximum number of slices supported by the decoder.
+ * must be a power of 2
+ */
+#define MAX_SLICES 16
+
#ifdef ALLOW_INTERLACE
#define MB_MBAFF h->mb_mbaff
#define MB_FIELD h->mb_field_decoding_flag
#endif
#define FIELD_OR_MBAFF_PICTURE (FRAME_MBAFF || FIELD_PICTURE)
+#ifdef ALLOW_NOCHROMA
+#define CHROMA h->sps.chroma_format_idc
+#else
+#define CHROMA 1
+#endif
+
+#define EXTENDED_SAR 255
+
+#define MB_TYPE_REF0 MB_TYPE_ACPRED //dirty but it fits in 16 bit
+#define MB_TYPE_8x8DCT 0x01000000
+#define IS_REF0(a) ((a) & MB_TYPE_REF0)
+#define IS_8x8DCT(a) ((a) & MB_TYPE_8x8DCT)
+
+/* NAL unit types */
+enum {
+ NAL_SLICE=1,
+ NAL_DPA,
+ NAL_DPB,
+ NAL_DPC,
+ NAL_IDR_SLICE,
+ NAL_SEI,
+ NAL_SPS,
+ NAL_PPS,
+ NAL_AUD,
+ NAL_END_SEQUENCE,
+ NAL_END_STREAM,
+ NAL_FILLER_DATA,
+ NAL_SPS_EXT,
+ NAL_AUXILIARY_SLICE=19
+};
+
+/**
+ * SEI message types
+ */
+typedef enum {
+ SEI_BUFFERING_PERIOD = 0, ///< buffering period (H.264, D.1.1)
+ SEI_TYPE_PIC_TIMING = 1, ///< picture timing
+ SEI_TYPE_USER_DATA_UNREGISTERED = 5, ///< unregistered user data
+ SEI_TYPE_RECOVERY_POINT = 6 ///< recovery point (frame # to decoder sync)
+} 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 profile_idc;
int level_idc;
+ int chroma_format_idc;
int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag
int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4
int poc_type; ///< pic_order_cnt_type
int scaling_matrix_present;
uint8_t scaling_matrix4[6][16];
uint8_t scaling_matrix8[2][64];
+ int nal_hrd_parameters_present_flag;
+ int vcl_hrd_parameters_present_flag;
+ int pic_struct_present_flag;
+ int time_offset_length;
+ int cpb_cnt; ///< See H.264 E.1.2
+ int initial_cpb_removal_delay_length; ///< initial_cpb_removal_delay_length_minus1 +1
+ int cpb_removal_delay_length; ///< cpb_removal_delay_length_minus1 + 1
+ int dpb_output_delay_length; ///< dpb_output_delay_length_minus1 + 1
+ int bit_depth_luma; ///< bit_depth_luma_minus8 + 8
+ int bit_depth_chroma; ///< bit_depth_chroma_minus8 + 8
+ int residual_color_transform_flag; ///< residual_colour_transform_flag
}SPS;
/**
int transform_8x8_mode; ///< transform_8x8_mode_flag
uint8_t scaling_matrix4[6][16];
uint8_t scaling_matrix8[2][64];
- uint8_t chroma_qp_table[2][256]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table
+ uint8_t chroma_qp_table[2][64]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table
int chroma_qp_diff;
}PPS;
int dequant_coeff_pps; ///< reinit tables when pps changes
int slice_num;
- uint8_t *slice_table_base;
- uint8_t *slice_table; ///< slice_table_base + 2*mb_stride + 1
+ uint16_t *slice_table_base;
+ uint16_t *slice_table; ///< slice_table_base + 2*mb_stride + 1
int slice_type;
+ int slice_type_nos; ///< S free slice type (SI/SP are remapped to I/P)
int slice_type_fixed;
//interlacing specific flags
int mb_field_decoding_flag;
int mb_mbaff; ///< mb_aff_frame && mb_field_decoding_flag
- unsigned int sub_mb_type[4];
+ DECLARE_ALIGNED_8(uint16_t, sub_mb_type[4]);
//POC stuff
int poc_lsb;
int direct_spatial_mv_pred;
int dist_scale_factor[16];
- int dist_scale_factor_field[32];
- int map_col_to_list0[2][16];
- int map_col_to_list0_field[2][32];
+ int dist_scale_factor_field[2][32];
+ int map_col_to_list0[2][16+32];
+ int map_col_to_list0_field[2][2][16+32];
/**
* num_ref_idx_l0/1_active_minus1 + 1
Picture ref_list[2][48]; /**< 0..15: frame refs, 16..47: mbaff field refs.
Reordered version of default_ref_list
according to picture reordering in slice header */
- Picture *delayed_pic[18]; //FIXME size?
- Picture *delayed_output_pic;
+ int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1
+ Picture *delayed_pic[MAX_DELAYED_PIC_COUNT+2]; //FIXME size?
+ int outputed_poc;
/**
* memory management control operations buffer.
int last_slice_type;
/** @} */
+ int mb_xy;
+
+ uint32_t svq3_watermark_key;
+
+ /**
+ * 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.
+ * However, soft telecined frames may have these values.
+ * This is used in an attempt to flag soft telecine progressive.
+ */
+ int prev_interlaced_frame;
+
+ /**
+ * 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;
+
+ int is_complex;
+
+ 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
+
+ // Timestamp stuff
+ int sei_buffering_period_present; ///< Buffering period SEI flag
+ int initial_cpb_removal_delay[32]; ///< Initial timestamps for CPBs
}H264Context;
-#endif /* FFMPEG_H264_H */
+/**
+ * Decode SEI
+ */
+int ff_h264_decode_sei(H264Context *h);
+
+/**
+ * Decode SPS
+ */
+int ff_h264_decode_seq_parameter_set(H264Context *h);
+
+/**
+ * Decode PPS
+ */
+int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length);
+
+/**
+ * Decodes 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?
+ * @returns decoded bytes, might be src+1 if no escapes
+ */
+const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length);
+
+/**
+ * identifies the exact end of the bitstream
+ * @return the length of the trailing, or 0 if damaged
+ */
+int ff_h264_decode_rbsp_trailing(H264Context *h, const uint8_t *src);
+
+/**
+ * frees any data that may have been allocated in the H264 context like SPS, PPS etc.
+ */
+av_cold void ff_h264_free_context(H264Context *h);
+
+#endif /* AVCODEC_H264_H */