summaryrefslogtreecommitdiff
path: root/libavcodec/h264dec.h
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/h264dec.h')
-rw-r--r--libavcodec/h264dec.h132
1 files changed, 101 insertions, 31 deletions
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index e79257ea36..c74b9fad6c 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
*/
@@ -48,7 +48,7 @@
#include "rectangle.h"
#include "videodsp.h"
-#define H264_MAX_PICTURE_COUNT 32
+#define H264_MAX_PICTURE_COUNT 36
#define MAX_SPS_COUNT 32
#define MAX_PPS_COUNT 256
@@ -57,6 +57,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
@@ -70,17 +72,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
@@ -93,11 +95,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 EXTENDED_SAR 255
@@ -106,7 +109,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
/**
* Sequence parameter set
@@ -168,6 +171,8 @@ typedef struct SPS {
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
+ uint8_t data[4096];
+ size_t data_size;
} SPS;
/**
@@ -191,8 +196,10 @@ 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;
+ uint8_t data[4096];
+ size_t data_size;
uint32_t dequant4_buffer[6][QP_MAX_NUM + 1][16];
uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64];
@@ -204,10 +211,11 @@ typedef struct H264ParamSets {
AVBufferRef *sps_list[MAX_SPS_COUNT];
AVBufferRef *pps_list[MAX_PPS_COUNT];
+ AVBufferRef *pps_ref;
+ AVBufferRef *sps_ref;
/* currently active parameters sets */
const PPS *pps;
- // FIXME this should properly be const
- SPS *sps;
+ const SPS *sps;
} H264ParamSets;
/**
@@ -259,13 +267,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 {
@@ -376,7 +390,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];
@@ -450,6 +464,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;
@@ -462,6 +477,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;
@@ -515,12 +538,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;
@@ -548,6 +571,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?
@@ -575,6 +599,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;
+
/** @} */
/**
@@ -586,6 +624,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.
*
@@ -606,12 +649,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;
@@ -626,10 +677,16 @@ typedef struct H264Context {
extern const uint16_t ff_h264_mb_sizes[4];
/**
+ * Uninit H264 param sets structure.
+ */
+
+void ff_h264_ps_uninit(H264ParamSets *ps);
+
+/**
* Decode SPS
*/
int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
- H264ParamSets *ps);
+ H264ParamSets *ps, int ignore_truncation);
/**
* Decode PPS
@@ -649,7 +706,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);
/**
@@ -678,8 +735,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,
@@ -742,7 +797,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);
@@ -751,7 +806,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);
@@ -898,6 +953,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);
@@ -909,6 +974,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);
@@ -917,4 +985,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 */