]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/h264dec.h
Add ClearVideo decoder
[ffmpeg] / libavcodec / h264dec.h
index 300077d7f22cfbe696b0e90e4d94767ef03bc310..fc7beeb9944e80775ab9f719b2c11ba0625ccd13 100644 (file)
@@ -35,6 +35,7 @@
 #include "cabac.h"
 #include "error_resilience.h"
 #include "h264_parse.h"
+#include "h264_ps.h"
 #include "h264_sei.h"
 #include "h2645_parse.h"
 #include "h264chroma.h"
@@ -50,9 +51,6 @@
 
 #define H264_MAX_PICTURE_COUNT 32
 
-#define MAX_SPS_COUNT          32
-#define MAX_PPS_COUNT         256
-
 #define MAX_MMCO_COUNT         66
 
 #define MAX_DELAYED_PIC_COUNT  16
 #define CHROMA422(h) (h->ps.sps->chroma_format_idc == 2)
 #define CHROMA444(h) (h->ps.sps->chroma_format_idc == 3)
 
-#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)
 
-#define QP_MAX_NUM (51 + 2 * 6)           // The maximum supported qp
-
-/* 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,
-};
-
-/**
- * Sequence parameter set
- */
-typedef struct SPS {
-    unsigned int sps_id;
-    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 log2_max_poc_lsb;              ///< log2_max_pic_order_cnt_lsb_minus4
-    int delta_pic_order_always_zero_flag;
-    int offset_for_non_ref_pic;
-    int offset_for_top_to_bottom_field;
-    int poc_cycle_length;              ///< num_ref_frames_in_pic_order_cnt_cycle
-    int ref_frame_count;               ///< num_ref_frames
-    int gaps_in_frame_num_allowed_flag;
-    int mb_width;                      ///< pic_width_in_mbs_minus1 + 1
-    int mb_height;                     ///< pic_height_in_map_units_minus1 + 1
-    int frame_mbs_only_flag;
-    int mb_aff;                        ///< mb_adaptive_frame_field_flag
-    int direct_8x8_inference_flag;
-    int crop;                          ///< frame_cropping_flag
-
-    /* those 4 are already in luma samples */
-    unsigned int crop_left;            ///< frame_cropping_rect_left_offset
-    unsigned int crop_right;           ///< frame_cropping_rect_right_offset
-    unsigned int crop_top;             ///< frame_cropping_rect_top_offset
-    unsigned int crop_bottom;          ///< frame_cropping_rect_bottom_offset
-    int vui_parameters_present_flag;
-    AVRational sar;
-    int video_signal_type_present_flag;
-    int full_range;
-    int colour_description_present_flag;
-    enum AVColorPrimaries color_primaries;
-    enum AVColorTransferCharacteristic color_trc;
-    enum AVColorSpace colorspace;
-    int timing_info_present_flag;
-    uint32_t num_units_in_tick;
-    uint32_t time_scale;
-    int fixed_frame_rate_flag;
-    short offset_for_ref_frame[256]; // FIXME dyn aloc?
-    int bitstream_restriction_flag;
-    int num_reorder_frames;
-    int scaling_matrix_present;
-    uint8_t scaling_matrix4[6][16];
-    uint8_t scaling_matrix8[6][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
-    int constraint_set_flags;             ///< constraint_set[0-3]_flag
-} SPS;
-
-/**
- * Picture parameter set
- */
-typedef struct PPS {
-    unsigned int sps_id;
-    int cabac;                  ///< entropy_coding_mode_flag
-    int pic_order_present;      ///< pic_order_present_flag
-    int slice_group_count;      ///< num_slice_groups_minus1 + 1
-    int mb_slice_group_map_type;
-    unsigned int ref_count[2];  ///< num_ref_idx_l0/1_active_minus1 + 1
-    int weighted_pred;          ///< weighted_pred_flag
-    int weighted_bipred_idc;
-    int init_qp;                ///< pic_init_qp_minus26 + 26
-    int init_qs;                ///< pic_init_qs_minus26 + 26
-    int chroma_qp_index_offset[2];
-    int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag
-    int constrained_intra_pred;     ///< constrained_intra_pred_flag
-    int redundant_pic_cnt_present;  ///< redundant_pic_cnt_present_flag
-    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
-    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.
  */
@@ -471,6 +345,7 @@ typedef struct H264Context {
 
     H264SliceContext *slice_ctx;
     int            nb_slice_ctx;
+    int            nb_slice_ctx_queued;
 
     H2645Packet pkt;
 
@@ -492,6 +367,16 @@ typedef struct H264Context {
      */
     int postpone_filter;
 
+    /*
+     * Set to 1 when the current picture is IDR, 0 otherwise.
+     */
+    int picture_idr;
+
+    int crop_left;
+    int crop_right;
+    int crop_top;
+    int crop_bottom;
+
     int8_t(*intra4x4_pred_mode);
     H264PredContext hpc;
 
@@ -570,7 +455,6 @@ typedef struct H264Context {
     H264Picture *long_ref[32];
     H264Picture *delayed_pic[MAX_DELAYED_PIC_COUNT + 2]; // FIXME size?
     int last_pocs[MAX_DELAYED_PIC_COUNT];
-    H264Picture *next_output_pic;
     int next_outputed_poc;
 
     /**
@@ -630,6 +514,18 @@ typedef struct H264Context {
      * slices) anymore */
     int setup_finished;
 
+    /* This is set to 1 if h264_field_start() has been called successfully,
+     * so all per-field state is properly initialized and we can decode
+     * the slice data */
+    int field_started;
+
+    /* original AVCodecContext dimensions, used to handle container
+     * cropping */
+    int width_from_caller;
+    int height_from_caller;
+
+    AVFrame *output_frame;
+
     int enable_er;
 
     H264SEIContext sei;
@@ -643,18 +539,6 @@ typedef struct H264Context {
 
 extern const uint16_t ff_h264_mb_sizes[4];
 
-/**
- * Decode SPS
- */
-int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
-                                     H264ParamSets *ps);
-
-/**
- * Decode PPS
- */
-int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
-                                         H264ParamSets *ps, int bit_length);
-
 /**
  * Reconstruct bitstream slice_type.
  */
@@ -666,7 +550,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_decode_ref_pic_list_reordering(H264SliceContext *sl, void *logctx);
 int ff_h264_build_ref_list(const H264Context *h, H264SliceContext *sl);
 void ff_h264_remove_all_refs(H264Context *h);
 
@@ -675,11 +559,10 @@ void ff_h264_remove_all_refs(H264Context *h);
  */
 int ff_h264_execute_ref_pic_marking(H264Context *h);
 
-int ff_h264_decode_ref_pic_marking(const H264Context *h, H264SliceContext *sl,
-                                   GetBitContext *gb);
+int ff_h264_decode_ref_pic_marking(H264SliceContext *sl, GetBitContext *gb,
+                                   const H2645NAL *nal, void *logctx);
 
 void ff_h264_hl_decode_mb(const H264Context *h, H264SliceContext *sl);
-int ff_h264_decode_init(AVCodecContext *avctx);
 void ff_h264_decode_init_vlc(void);
 
 /**
@@ -925,9 +808,14 @@ 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_h264_decode_slice_header(H264Context *h, H264SliceContext *sl,
-                                const H2645NAL *nal);
-int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count);
+/**
+ * Submit a slice for decoding.
+ *
+ * Parse the slice header, starting a new field/frame if necessary. If any
+ * slices are queued for the previous field, they are decoded.
+ */
+int ff_h264_queue_decode_slice(H264Context *h, const H2645NAL *nal);
+int ff_h264_execute_decode_slices(H264Context *h);
 int ff_h264_update_thread_context(AVCodecContext *dst,
                                   const AVCodecContext *src);