* 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
*/
#include "libavutil/intreadwrite.h"
#include "cabac.h"
+#include "get_bits.h"
#include "mpegvideo.h"
#include "h264chroma.h"
#include "h264dsp.h"
#include "h264qpel.h"
#include "rectangle.h"
-#define interlaced_dct interlaced_dct_is_a_bad_name
-#define mb_intra mb_intra_is_not_initialized_see_mb_type
-
#define MAX_SPS_COUNT 32
#define MAX_PPS_COUNT 256
#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
#define MB_MBAFF h->mb_mbaff
#define MB_FIELD h->mb_field_decoding_flag
#define FRAME_MBAFF h->mb_aff_frame
-#define FIELD_PICTURE (s->picture_structure != PICT_FRAME)
+#define FIELD_PICTURE (h->picture_structure != PICT_FRAME)
#define LEFT_MBS 2
#define LTOP 0
#define LBOT 1
#define CABAC h->pps.cabac
#endif
+#define CHROMA (h->sps.chroma_format_idc)
#define CHROMA422 (h->sps.chroma_format_idc == 2)
#define CHROMA444 (h->sps.chroma_format_idc == 3)
#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
/* NAL unit types */
enum {
typedef enum {
SEI_BUFFERING_PERIOD = 0, ///< buffering period (H.264, D.1.1)
SEI_TYPE_PIC_TIMING = 1, ///< picture timing
+ SEI_TYPE_USER_DATA_ITU_T_T35 = 4, ///< user data registered by ITU-T Recommendation T.35
SEI_TYPE_USER_DATA_UNREGISTERED = 5, ///< unregistered user data
SEI_TYPE_RECOVERY_POINT = 6 ///< recovery point (frame # to decoder sync)
} SEI_Type;
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;
} PPS;
* H264Context
*/
typedef struct H264Context {
- MpegEncContext s;
+ AVCodecContext *avctx;
+ DSPContext dsp;
+ VideoDSPContext vdsp;
H264DSPContext h264dsp;
H264ChromaContext h264chroma;
H264QpelContext h264qpel;
+ MotionEstContext me;
+ ParseContext parse_context;
+ GetBitContext gb;
+ ERContext er;
+
+ Picture *DPB;
+ Picture *cur_pic_ptr;
+ Picture cur_pic;
+ int picture_count;
+ int picture_range_start, picture_range_end;
+
int pixel_shift; ///< 0 for 8-bit H264, 1 for high-bit-depth H264
int chroma_qp[2]; // QPc
int qp_thresh; ///< QP threshold to skip loopfilter
+ int width, height;
+ int linesize, uvlinesize;
+ int chroma_x_shift, chroma_y_shift;
+
+ int qscale;
+ int droppable;
+ int data_partitioning;
+ int coded_picture_number;
+ int low_delay;
+
+ int context_initialized;
+ int flags;
+ int workaround_bugs;
+
int prev_mb_skipped;
int next_mb_skipped;
int mb_aff_frame;
int mb_field_decoding_flag;
int mb_mbaff; ///< mb_aff_frame && mb_field_decoding_flag
+ int picture_structure;
+ int first_field;
DECLARE_ALIGNED(8, uint16_t, sub_mb_type)[4];
GetBitContext *intra_gb_ptr;
GetBitContext *inter_gb_ptr;
+ const uint8_t *intra_pcm_ptr;
DECLARE_ALIGNED(16, int16_t, mb)[16 * 48 * 2]; ///< as a dct coeffecient is int32_t in high depth, we need to reserve twice the space.
DECLARE_ALIGNED(16, int16_t, mb_luma_dc)[3][16 * 2];
int16_t mb_padding[256 * 2]; ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too large or ensure that there is some unused stuff after mb
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 x264_build;
+ int mb_x, mb_y;
+ int resync_mb_x;
+ int resync_mb_y;
+ int mb_skip_run;
+ int mb_height, mb_width;
+ int mb_stride;
+ int mb_num;
int mb_xy;
int is_complex;
int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4)
int got_first; ///< this flag is != 0 if we've parsed a frame
- int context_reinitialized;
+ 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];
struct H264Context *thread_context[MAX_THREADS];
/**
- * current slice number, used to initalize slice_num of each thread/context
+ * current slice number, used to initialize slice_num of each thread/context
*/
int current_slice;
*/
int max_contexts;
+ int slice_context_count;
+
/**
* 1 if the single thread fallback warning has already been
* displayed, 0 otherwise.
*/
int single_decode_warning;
+ enum AVPictureType pict_type;
+
int last_slice_type;
/** @} */
* frames.
*/
int sei_recovery_frame_cnt;
+ /**
+ * recovery_frame is the frame_num at which the next frame should
+ * be fully constructed.
+ *
+ * Set to -1 when not expecting a recovery point.
+ */
+ int recovery_frame;
+
+ /**
+ * Are the SEI recovery points looking valid.
+ */
+ int valid_recovery_point;
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
int cur_chroma_format_idc;
uint8_t *bipred_scratchpad;
+
+ int16_t slice_row[MAX_SLICES]; ///< to detect when MAX_SLICES is too low
+
+ int sync; ///< did we had a keyframe or recovery point
+
+ uint8_t parse_history[4];
+ int parse_history_count;
+ int parse_last_mb;
+ uint8_t *edge_emu_buffer;
+ int16_t *dc_val_base;
} H264Context;
-extern const uint8_t ff_h264_chroma_qp[3][QP_MAX_NUM + 1]; ///< One chroma qp table for each supported bit depth (8, 9, 10).
+extern const uint8_t ff_h264_chroma_qp[7][QP_MAX_NUM + 1]; ///< One chroma qp table for each possible bit depth (8-14).
extern const uint16_t ff_h264_mb_sizes[4];
/**
void ff_h264_hl_decode_mb(H264Context *h);
int ff_h264_frame_start(H264Context *h);
-int ff_h264_decode_extradata(H264Context *h);
+int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size);
av_cold int ff_h264_decode_init(AVCodecContext *avctx);
av_cold void ff_h264_decode_init_vlc(void);
const int top = h->intra4x4_pred_mode_cache[index8 - 8];
const int min = FFMIN(left, top);
- tprintf(h->s.avctx, "mode:%d %d min:%d\n", left, top, min);
+ tprintf(h->avctx, "mode:%d %d min:%d\n", left, top, min);
if (min < 0)
return DC_PRED;
AV_COPY32(&nnz[32], &nnz_cache[4 + 8 * 11]);
AV_COPY32(&nnz[36], &nnz_cache[4 + 8 * 12]);
- if (!h->s.chroma_y_shift) {
+ if (!h->chroma_y_shift) {
AV_COPY32(&nnz[24], &nnz_cache[4 + 8 * 8]);
AV_COPY32(&nnz[28], &nnz_cache[4 + 8 * 9]);
AV_COPY32(&nnz[40], &nnz_cache[4 + 8 * 13]);
}
static av_always_inline void write_back_motion_list(H264Context *h,
- MpegEncContext *const s,
int b_stride,
int b_xy, int b8_xy,
int mb_type, int list)
{
- int16_t(*mv_dst)[2] = &s->current_picture.f.motion_val[list][b_xy];
+ int16_t(*mv_dst)[2] = &h->cur_pic.f.motion_val[list][b_xy];
int16_t(*mv_src)[2] = &h->mv_cache[list][scan8[0]];
AV_COPY128(mv_dst + 0 * b_stride, mv_src + 8 * 0);
AV_COPY128(mv_dst + 1 * b_stride, mv_src + 8 * 1);
}
{
- int8_t *ref_index = &s->current_picture.f.ref_index[list][b8_xy];
+ int8_t *ref_index = &h->cur_pic.f.ref_index[list][b8_xy];
int8_t *ref_cache = h->ref_cache[list];
ref_index[0 + 0 * 2] = ref_cache[scan8[0]];
ref_index[1 + 0 * 2] = ref_cache[scan8[4]];
static av_always_inline void write_back_motion(H264Context *h, int mb_type)
{
- MpegEncContext *const s = &h->s;
const int b_stride = h->b_stride;
- const int b_xy = 4 * s->mb_x + 4 * s->mb_y * h->b_stride; // try mb2b(8)_xy
+ const int b_xy = 4 * h->mb_x + 4 * h->mb_y * h->b_stride; // try mb2b(8)_xy
const int b8_xy = 4 * h->mb_xy;
if (USES_LIST(mb_type, 0)) {
- write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 0);
+ write_back_motion_list(h, b_stride, b_xy, b8_xy, mb_type, 0);
} else {
- fill_rectangle(&s->current_picture.f.ref_index[0][b8_xy],
+ fill_rectangle(&h->cur_pic.f.ref_index[0][b8_xy],
2, 2, 2, (uint8_t)LIST_NOT_USED, 1);
}
if (USES_LIST(mb_type, 1))
- write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 1);
+ write_back_motion_list(h, b_stride, b_xy, b8_xy, mb_type, 1);
if (h->slice_type_nos == AV_PICTURE_TYPE_B && CABAC) {
if (IS_8X8(mb_type)) {
0x0001000100010001ULL));
}
+void ff_h264_draw_horiz_band(H264Context *h, int y, int height);
+
#endif /* AVCODEC_H264_H */