* qatar/master: h264: deMpegEncContextize Conflicts: libavcodec/dxva2_h264.c libavcodec/h264.c libavcodec/h264.h libavcodec/h264_cabac.c libavcodec/h264_cavlc.c libavcodec/h264_loopfilter.c libavcodec/h264_mb_template.c libavcodec/h264_parser.c libavcodec/h264_ps.c libavcodec/h264_refs.c libavcodec/h264_sei.c libavcodec/svq3.c Merged-by: Michael Niedermayer <michaelni@gmx.at>tags/n1.2
@@ -932,8 +932,8 @@ static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *a | |||
} else { | |||
av_log(avctx, AV_LOG_VERBOSE, | |||
"CrystalHD: parser picture type %d\n", | |||
h->s.picture_structure); | |||
pic_type = h->s.picture_structure; | |||
h->picture_structure); | |||
pic_type = h->picture_structure; | |||
} | |||
} else { | |||
av_log(avctx, AV_LOG_WARNING, | |||
@@ -76,7 +76,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, | |||
return result; | |||
} | |||
int ff_dxva2_common_end_frame(AVCodecContext *avctx, MpegEncContext *s, | |||
int ff_dxva2_common_end_frame(AVCodecContext *avctx, Picture *pic, | |||
const void *pp, unsigned pp_size, | |||
const void *qm, unsigned qm_size, | |||
int (*commit_bs_si)(AVCodecContext *, | |||
@@ -90,7 +90,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, MpegEncContext *s, | |||
int result; | |||
if (FAILED(IDirectXVideoDecoder_BeginFrame(ctx->decoder, | |||
ff_dxva2_get_surface(s->current_picture_ptr), | |||
ff_dxva2_get_surface(pic), | |||
NULL))) { | |||
av_log(avctx, AV_LOG_ERROR, "Failed to begin frame\n"); | |||
return -1; | |||
@@ -146,7 +146,5 @@ end: | |||
result = -1; | |||
} | |||
if (!result) | |||
ff_mpeg_draw_horiz_band(s, 0, s->avctx->height); | |||
return result; | |||
} |
@@ -44,15 +44,14 @@ static void fill_picture_entry(DXVA_PicEntry_H264 *pic, | |||
static void fill_picture_parameters(struct dxva_context *ctx, const H264Context *h, | |||
DXVA_PicParams_H264 *pp) | |||
{ | |||
const MpegEncContext *s = &h->s; | |||
const Picture *current_picture = s->current_picture_ptr; | |||
const Picture *current_picture = h->cur_pic_ptr; | |||
int i, j; | |||
memset(pp, 0, sizeof(*pp)); | |||
/* Configure current picture */ | |||
fill_picture_entry(&pp->CurrPic, | |||
ff_dxva2_get_surface_index(ctx, current_picture), | |||
s->picture_structure == PICT_BOTTOM_FIELD); | |||
h->picture_structure == PICT_BOTTOM_FIELD); | |||
/* Configure the set of references */ | |||
pp->UsedForReferenceFlags = 0; | |||
pp->NonExistingFrameFlags = 0; | |||
@@ -88,13 +87,13 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context | |||
} | |||
} | |||
pp->wFrameWidthInMbsMinus1 = s->mb_width - 1; | |||
pp->wFrameHeightInMbsMinus1 = s->mb_height - 1; | |||
pp->wFrameWidthInMbsMinus1 = h->mb_width - 1; | |||
pp->wFrameHeightInMbsMinus1 = h->mb_height - 1; | |||
pp->num_ref_frames = h->sps.ref_frame_count; | |||
pp->wBitFields = ((s->picture_structure != PICT_FRAME) << 0) | | |||
pp->wBitFields = ((h->picture_structure != PICT_FRAME) << 0) | | |||
((h->sps.mb_aff && | |||
(s->picture_structure == PICT_FRAME)) << 1) | | |||
(h->picture_structure == PICT_FRAME)) << 1) | | |||
(h->sps.residual_color_transform_flag << 2) | | |||
/* sp_for_switch_flag (not implemented by FFmpeg) */ | |||
(0 << 3) | | |||
@@ -120,11 +119,11 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context | |||
pp->Reserved16Bits = 3; /* FIXME is there a way to detect the right mode ? */ | |||
pp->StatusReportFeedbackNumber = 1 + ctx->report_id++; | |||
pp->CurrFieldOrderCnt[0] = 0; | |||
if ((s->picture_structure & PICT_TOP_FIELD) && | |||
if ((h->picture_structure & PICT_TOP_FIELD) && | |||
current_picture->field_poc[0] != INT_MAX) | |||
pp->CurrFieldOrderCnt[0] = current_picture->field_poc[0]; | |||
pp->CurrFieldOrderCnt[1] = 0; | |||
if ((s->picture_structure & PICT_BOTTOM_FIELD) && | |||
if ((h->picture_structure & PICT_BOTTOM_FIELD) && | |||
current_picture->field_poc[1] != INT_MAX) | |||
pp->CurrFieldOrderCnt[1] = current_picture->field_poc[1]; | |||
pp->pic_init_qs_minus26 = h->pps.init_qs - 26; | |||
@@ -200,7 +199,6 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, | |||
{ | |||
const H264Context *h = avctx->priv_data; | |||
struct dxva_context *ctx = avctx->hwaccel_context; | |||
const MpegEncContext *s = &h->s; | |||
unsigned list; | |||
memset(slice, 0, sizeof(*slice)); | |||
@@ -208,9 +206,9 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, | |||
slice->SliceBytesInBuffer = size; | |||
slice->wBadSliceChopping = 0; | |||
slice->first_mb_in_slice = (s->mb_y >> FIELD_OR_MBAFF_PICTURE) * s->mb_width + s->mb_x; | |||
slice->first_mb_in_slice = (h->mb_y >> FIELD_OR_MBAFF_PICTURE) * h->mb_width + h->mb_x; | |||
slice->NumMbsForSlice = 0; /* XXX it is set once we have all slices */ | |||
slice->BitOffsetToSliceData = get_bits_count(&s->gb); | |||
slice->BitOffsetToSliceData = get_bits_count(&h->gb); | |||
slice->slice_type = ff_h264_get_slice_type(h); | |||
if (h->slice_type_fixed) | |||
slice->slice_type += 5; | |||
@@ -260,7 +258,7 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, | |||
} | |||
} | |||
slice->slice_qs_delta = 0; /* XXX not implemented by FFmpeg */ | |||
slice->slice_qp_delta = s->qscale - h->pps.init_qp; | |||
slice->slice_qp_delta = h->qscale - h->pps.init_qp; | |||
slice->redundant_pic_cnt = h->redundant_pic_count; | |||
if (h->slice_type == AV_PICTURE_TYPE_B) | |||
slice->direct_spatial_mv_pred_flag = h->direct_spatial_mv_pred; | |||
@@ -277,10 +275,9 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, | |||
DXVA2_DecodeBufferDesc *sc) | |||
{ | |||
const H264Context *h = avctx->priv_data; | |||
const MpegEncContext *s = &h->s; | |||
const unsigned mb_count = s->mb_width * s->mb_height; | |||
const unsigned mb_count = h->mb_width * h->mb_height; | |||
struct dxva_context *ctx = avctx->hwaccel_context; | |||
const Picture *current_picture = h->s.current_picture_ptr; | |||
const Picture *current_picture = h->cur_pic_ptr; | |||
struct dxva2_picture_context *ctx_pic = current_picture->f.hwaccel_picture_private; | |||
DXVA_Slice_H264_Short *slice = NULL; | |||
uint8_t *dxva_data, *current, *end; | |||
@@ -376,7 +373,7 @@ static int start_frame(AVCodecContext *avctx, | |||
{ | |||
const H264Context *h = avctx->priv_data; | |||
struct dxva_context *ctx = avctx->hwaccel_context; | |||
struct dxva2_picture_context *ctx_pic = h->s.current_picture_ptr->f.hwaccel_picture_private; | |||
struct dxva2_picture_context *ctx_pic = h->cur_pic_ptr->f.hwaccel_picture_private; | |||
if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0) | |||
return -1; | |||
@@ -399,7 +396,7 @@ static int decode_slice(AVCodecContext *avctx, | |||
{ | |||
const H264Context *h = avctx->priv_data; | |||
struct dxva_context *ctx = avctx->hwaccel_context; | |||
const Picture *current_picture = h->s.current_picture_ptr; | |||
const Picture *current_picture = h->cur_pic_ptr; | |||
struct dxva2_picture_context *ctx_pic = current_picture->f.hwaccel_picture_private; | |||
unsigned position; | |||
@@ -427,16 +424,19 @@ static int decode_slice(AVCodecContext *avctx, | |||
static int end_frame(AVCodecContext *avctx) | |||
{ | |||
H264Context *h = avctx->priv_data; | |||
MpegEncContext *s = &h->s; | |||
struct dxva2_picture_context *ctx_pic = | |||
h->s.current_picture_ptr->f.hwaccel_picture_private; | |||
h->cur_pic_ptr->f.hwaccel_picture_private; | |||
int ret; | |||
if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0) | |||
return -1; | |||
return ff_dxva2_common_end_frame(avctx, s, | |||
&ctx_pic->pp, sizeof(ctx_pic->pp), | |||
&ctx_pic->qm, sizeof(ctx_pic->qm), | |||
commit_bitstream_and_slice_buffer); | |||
ret = ff_dxva2_common_end_frame(avctx, h->cur_pic_ptr, | |||
&ctx_pic->pp, sizeof(ctx_pic->pp), | |||
&ctx_pic->qm, sizeof(ctx_pic->qm), | |||
commit_bitstream_and_slice_buffer); | |||
if (!ret) | |||
ff_h264_draw_horiz_band(h, 0, h->avctx->height); | |||
return ret; | |||
} | |||
AVHWAccel ff_h264_dxva2_hwaccel = { | |||
@@ -54,7 +54,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *, struct dxva_context *, | |||
unsigned mb_count); | |||
int ff_dxva2_common_end_frame(AVCodecContext *, MpegEncContext *, | |||
int ff_dxva2_common_end_frame(AVCodecContext *, Picture *, | |||
const void *pp, unsigned pp_size, | |||
const void *qm, unsigned qm_size, | |||
int (*commit_bs_si)(AVCodecContext *, | |||
@@ -251,13 +251,17 @@ static int end_frame(AVCodecContext *avctx) | |||
struct MpegEncContext *s = avctx->priv_data; | |||
struct dxva2_picture_context *ctx_pic = | |||
s->current_picture_ptr->f.hwaccel_picture_private; | |||
int ret; | |||
if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0) | |||
return -1; | |||
return ff_dxva2_common_end_frame(avctx, s, | |||
&ctx_pic->pp, sizeof(ctx_pic->pp), | |||
&ctx_pic->qm, sizeof(ctx_pic->qm), | |||
commit_bitstream_and_slice_buffer); | |||
ret = ff_dxva2_common_end_frame(avctx, s->current_picture_ptr, | |||
&ctx_pic->pp, sizeof(ctx_pic->pp), | |||
&ctx_pic->qm, sizeof(ctx_pic->qm), | |||
commit_bitstream_and_slice_buffer); | |||
if (!ret) | |||
ff_mpeg_draw_horiz_band(s, 0, avctx->height); | |||
return ret; | |||
} | |||
AVHWAccel ff_mpeg2_dxva2_hwaccel = { | |||
@@ -257,14 +257,18 @@ static int end_frame(AVCodecContext *avctx) | |||
{ | |||
VC1Context *v = avctx->priv_data; | |||
struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->f.hwaccel_picture_private; | |||
int ret; | |||
if (ctx_pic->bitstream_size <= 0) | |||
return -1; | |||
return ff_dxva2_common_end_frame(avctx, &v->s, | |||
&ctx_pic->pp, sizeof(ctx_pic->pp), | |||
NULL, 0, | |||
commit_bitstream_and_slice_buffer); | |||
ret = ff_dxva2_common_end_frame(avctx, v->s.current_picture_ptr, | |||
&ctx_pic->pp, sizeof(ctx_pic->pp), | |||
NULL, 0, | |||
commit_bitstream_and_slice_buffer); | |||
if (!ret) | |||
ff_mpeg_draw_horiz_band(&v->s, 0, avctx->height); | |||
return ret; | |||
} | |||
#if CONFIG_WMV3_DXVA2_HWACCEL | |||
@@ -30,6 +30,7 @@ | |||
#include "libavutil/intreadwrite.h" | |||
#include "cabac.h" | |||
#include "get_bits.h" | |||
#include "mpegvideo.h" | |||
#include "h264chroma.h" | |||
#include "h264dsp.h" | |||
@@ -62,7 +63,7 @@ | |||
#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 | |||
@@ -254,15 +255,42 @@ typedef struct MMCO { | |||
* 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; | |||
@@ -352,6 +380,8 @@ typedef struct H264Context { | |||
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]; | |||
@@ -428,6 +458,13 @@ typedef struct H264Context { | |||
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; | |||
@@ -452,7 +489,8 @@ typedef struct H264Context { | |||
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]; | |||
@@ -525,12 +563,16 @@ typedef struct H264Context { | |||
*/ | |||
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; | |||
/** @} */ | |||
@@ -602,6 +644,8 @@ typedef struct H264Context { | |||
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[7][QP_MAX_NUM + 1]; ///< One chroma qp table for each possible bit depth (8-14). | |||
@@ -810,7 +854,7 @@ static av_always_inline int pred_intra_mode(H264Context *h, int n) | |||
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; | |||
@@ -844,7 +888,7 @@ static av_always_inline void write_back_non_zero_count(H264Context *h) | |||
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]); | |||
@@ -853,12 +897,11 @@ static av_always_inline void write_back_non_zero_count(H264Context *h) | |||
} | |||
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); | |||
@@ -879,7 +922,7 @@ static av_always_inline void write_back_motion_list(H264Context *h, | |||
} | |||
{ | |||
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]]; | |||
@@ -890,19 +933,18 @@ static av_always_inline void write_back_motion_list(H264Context *h, | |||
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)) { | |||
@@ -926,4 +968,6 @@ static av_always_inline int get_dct8x8_allowed(H264Context *h) | |||
0x0001000100010001ULL)); | |||
} | |||
void ff_h264_draw_horiz_band(H264Context *h, int y, int height); | |||
#endif /* AVCODEC_H264_H */ |
@@ -1259,10 +1259,9 @@ static const int8_t cabac_context_init_PB[3][1024][2] = | |||
}; | |||
void ff_h264_init_cabac_states(H264Context *h) { | |||
MpegEncContext * const s = &h->s; | |||
int i; | |||
const int8_t (*tab)[2]; | |||
const int slice_qp = av_clip(s->qscale - 6*(h->sps.bit_depth_luma-8), 0, 51); | |||
const int slice_qp = av_clip(h->qscale - 6*(h->sps.bit_depth_luma-8), 0, 51); | |||
if( h->slice_type_nos == AV_PICTURE_TYPE_I ) tab = cabac_context_init_I; | |||
else tab = cabac_context_init_PB[h->cabac_init_idc]; | |||
@@ -1280,13 +1279,12 @@ void ff_h264_init_cabac_states(H264Context *h) { | |||
} | |||
static int decode_cabac_field_decoding_flag(H264Context *h) { | |||
MpegEncContext * const s = &h->s; | |||
const long mbb_xy = h->mb_xy - 2L*s->mb_stride; | |||
const long mbb_xy = h->mb_xy - 2L*h->mb_stride; | |||
unsigned long ctx = 0; | |||
ctx += h->mb_field_decoding_flag & !!s->mb_x; //for FMO:(s->current_picture.f.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num); | |||
ctx += (s->current_picture.f.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num); | |||
ctx += h->mb_field_decoding_flag & !!h->mb_x; //for FMO:(s->current_picture.f.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num); | |||
ctx += (h->cur_pic.f.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num); | |||
return get_cabac_noinline( &h->cabac, &(h->cabac_state+70)[ctx] ); | |||
} | |||
@@ -1322,34 +1320,33 @@ static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_sl | |||
} | |||
static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) { | |||
MpegEncContext * const s = &h->s; | |||
int mba_xy, mbb_xy; | |||
int ctx = 0; | |||
if(FRAME_MBAFF){ //FIXME merge with the stuff in fill_caches? | |||
int mb_xy = mb_x + (mb_y&~1)*s->mb_stride; | |||
int mb_xy = mb_x + (mb_y&~1)*h->mb_stride; | |||
mba_xy = mb_xy - 1; | |||
if( (mb_y&1) | |||
&& h->slice_table[mba_xy] == h->slice_num | |||
&& MB_FIELD == !!IS_INTERLACED( s->current_picture.f.mb_type[mba_xy] ) ) | |||
mba_xy += s->mb_stride; | |||
&& MB_FIELD == !!IS_INTERLACED( h->cur_pic.f.mb_type[mba_xy] ) ) | |||
mba_xy += h->mb_stride; | |||
if( MB_FIELD ){ | |||
mbb_xy = mb_xy - s->mb_stride; | |||
mbb_xy = mb_xy - h->mb_stride; | |||
if( !(mb_y&1) | |||
&& h->slice_table[mbb_xy] == h->slice_num | |||
&& IS_INTERLACED( s->current_picture.f.mb_type[mbb_xy] ) ) | |||
mbb_xy -= s->mb_stride; | |||
&& IS_INTERLACED( h->cur_pic.f.mb_type[mbb_xy] ) ) | |||
mbb_xy -= h->mb_stride; | |||
}else | |||
mbb_xy = mb_x + (mb_y-1)*s->mb_stride; | |||
mbb_xy = mb_x + (mb_y-1)*h->mb_stride; | |||
}else{ | |||
int mb_xy = h->mb_xy; | |||
mba_xy = mb_xy - 1; | |||
mbb_xy = mb_xy - (s->mb_stride << FIELD_PICTURE); | |||
mbb_xy = mb_xy - (h->mb_stride << FIELD_PICTURE); | |||
} | |||
if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mba_xy] )) | |||
if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP(h->cur_pic.f.mb_type[mba_xy] )) | |||
ctx++; | |||
if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mbb_xy] )) | |||
if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP(h->cur_pic.f.mb_type[mbb_xy] )) | |||
ctx++; | |||
if( h->slice_type_nos == AV_PICTURE_TYPE_B ) | |||
@@ -1506,7 +1503,7 @@ static int decode_cabac_mb_mvd( H264Context *h, int ctxbase, int amvd, int *mvda | |||
mvd += 1 << k; | |||
k++; | |||
if(k>24){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_mvd\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_mvd\n"); | |||
return INT_MIN; | |||
} | |||
} | |||
@@ -1831,8 +1828,7 @@ static av_always_inline void decode_cabac_luma_residual( H264Context *h, const u | |||
static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}}; | |||
const uint32_t *qmul; | |||
int i8x8, i4x4; | |||
MpegEncContext * const s = &h->s; | |||
int qscale = p == 0 ? s->qscale : h->chroma_qp[p-1]; | |||
int qscale = p == 0 ? h->qscale : h->chroma_qp[p-1]; | |||
if( IS_INTRA16x16( mb_type ) ) { | |||
AV_ZERO128(h->mb_luma_dc[p]+0); | |||
AV_ZERO128(h->mb_luma_dc[p]+8); | |||
@@ -1878,7 +1874,6 @@ static av_always_inline void decode_cabac_luma_residual( H264Context *h, const u | |||
* @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed | |||
*/ | |||
int ff_h264_decode_mb_cabac(H264Context *h) { | |||
MpegEncContext * const s = &h->s; | |||
int mb_xy; | |||
int mb_type, partition_count, cbp = 0; | |||
int dct8x8_allowed= h->pps.transform_8x8_mode; | |||
@@ -1886,21 +1881,21 @@ int ff_h264_decode_mb_cabac(H264Context *h) { | |||
const int pixel_shift = h->pixel_shift; | |||
unsigned local_ref_count[2]; | |||
mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; | |||
mb_xy = h->mb_xy = h->mb_x + h->mb_y*h->mb_stride; | |||
tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); | |||
tprintf(h->avctx, "pic:%d mb:%d/%d\n", h->frame_num, h->mb_x, h->mb_y); | |||
if( h->slice_type_nos != AV_PICTURE_TYPE_I ) { | |||
int skip; | |||
/* a skipped mb needs the aff flag from the following mb */ | |||
if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped ) | |||
if( FRAME_MBAFF && (h->mb_y&1)==1 && h->prev_mb_skipped ) | |||
skip = h->next_mb_skipped; | |||
else | |||
skip = decode_cabac_mb_skip( h, s->mb_x, s->mb_y ); | |||
skip = decode_cabac_mb_skip( h, h->mb_x, h->mb_y ); | |||
/* read skip flags */ | |||
if( skip ) { | |||
if( FRAME_MBAFF && (s->mb_y&1)==0 ){ | |||
s->current_picture.f.mb_type[mb_xy] = MB_TYPE_SKIP; | |||
h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 ); | |||
if( FRAME_MBAFF && (h->mb_y&1)==0 ){ | |||
h->cur_pic.f.mb_type[mb_xy] = MB_TYPE_SKIP; | |||
h->next_mb_skipped = decode_cabac_mb_skip( h, h->mb_x, h->mb_y+1 ); | |||
if(!h->next_mb_skipped) | |||
h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h); | |||
} | |||
@@ -1916,7 +1911,7 @@ int ff_h264_decode_mb_cabac(H264Context *h) { | |||
} | |||
} | |||
if(FRAME_MBAFF){ | |||
if( (s->mb_y&1) == 0 ) | |||
if( (h->mb_y&1) == 0 ) | |||
h->mb_mbaff = | |||
h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h); | |||
} | |||
@@ -2017,10 +2012,10 @@ decode_intra_mb: | |||
h->cbp_table[mb_xy] = 0xf7ef; | |||
h->chroma_pred_mode_table[mb_xy] = 0; | |||
// In deblocking, the quantizer is 0 | |||
s->current_picture.f.qscale_table[mb_xy] = 0; | |||
h->cur_pic.f.qscale_table[mb_xy] = 0; | |||
// All coeffs are present | |||
memset(h->non_zero_count[mb_xy], 16, 48); | |||
s->current_picture.f.mb_type[mb_xy] = mb_type; | |||
h->cur_pic.f.mb_type[mb_xy] = mb_type; | |||
h->last_qscale_diff = 0; | |||
return 0; | |||
} | |||
@@ -2045,7 +2040,7 @@ decode_intra_mb: | |||
int pred = pred_intra_mode( h, i ); | |||
h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred ); | |||
av_dlog(s->avctx, "i4x4 pred=%d mode=%d\n", pred, | |||
av_dlog(h->avctx, "i4x4 pred=%d mode=%d\n", pred, | |||
h->intra4x4_pred_mode_cache[scan8[i]]); | |||
} | |||
} | |||
@@ -2099,7 +2094,7 @@ decode_intra_mb: | |||
if (local_ref_count[list] > 1) { | |||
ref[list][i] = decode_cabac_mb_ref( h, list, 4*i ); | |||
if (ref[list][i] >= (unsigned)local_ref_count[list]) { | |||
av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref[list][i], local_ref_count[list]); | |||
av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref[list][i], local_ref_count[list]); | |||
return -1; | |||
} | |||
}else | |||
@@ -2134,7 +2129,7 @@ decode_intra_mb: | |||
uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ]; | |||
pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); | |||
DECODE_CABAC_MB_MVD( h, list, index) | |||
tprintf(s->avctx, "final mv:%d %d\n", mx, my); | |||
tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
if(IS_SUB_8X8(sub_mb_type)){ | |||
mv_cache[ 1 ][0]= | |||
@@ -2185,7 +2180,7 @@ decode_intra_mb: | |||
if (local_ref_count[list] > 1) { | |||
ref= decode_cabac_mb_ref(h, list, 0); | |||
if (ref >= (unsigned)local_ref_count[list]) { | |||
av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); | |||
av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); | |||
return -1; | |||
} | |||
}else | |||
@@ -2198,7 +2193,7 @@ decode_intra_mb: | |||
int mx,my,mpx,mpy; | |||
pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); | |||
DECODE_CABAC_MB_MVD( h, list, 0) | |||
tprintf(s->avctx, "final mv:%d %d\n", mx, my); | |||
tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2); | |||
fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); | |||
@@ -2213,7 +2208,7 @@ decode_intra_mb: | |||
if (local_ref_count[list] > 1) { | |||
ref= decode_cabac_mb_ref( h, list, 8*i ); | |||
if (ref >= (unsigned)local_ref_count[list]) { | |||
av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); | |||
av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); | |||
return -1; | |||
} | |||
}else | |||
@@ -2229,7 +2224,7 @@ decode_intra_mb: | |||
int mx,my,mpx,mpy; | |||
pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); | |||
DECODE_CABAC_MB_MVD( h, list, 8*i) | |||
tprintf(s->avctx, "final mv:%d %d\n", mx, my); | |||
tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2); | |||
fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); | |||
@@ -2248,7 +2243,7 @@ decode_intra_mb: | |||
if (local_ref_count[list] > 1) { | |||
ref= decode_cabac_mb_ref( h, list, 4*i ); | |||
if (ref >= (unsigned)local_ref_count[list]) { | |||
av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); | |||
av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, local_ref_count[list]); | |||
return -1; | |||
} | |||
}else | |||
@@ -2265,7 +2260,7 @@ decode_intra_mb: | |||
pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); | |||
DECODE_CABAC_MB_MVD( h, list, 4*i) | |||
tprintf(s->avctx, "final mv:%d %d\n", mx, my); | |||
tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2); | |||
fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); | |||
}else{ | |||
@@ -2288,7 +2283,7 @@ decode_intra_mb: | |||
cbp |= decode_cabac_mb_cbp_chroma( h ) << 4; | |||
} else { | |||
if (!decode_chroma && cbp>15) { | |||
av_log(s->avctx, AV_LOG_ERROR, "gray chroma\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "gray chroma\n"); | |||
return AVERROR_INVALIDDATA; | |||
} | |||
} | |||
@@ -2321,18 +2316,18 @@ decode_intra_mb: | |||
AV_WN32A(&nnz_cache[4+8*10], top_empty); | |||
} | |||
} | |||
s->current_picture.f.mb_type[mb_xy] = mb_type; | |||
h->cur_pic.f.mb_type[mb_xy] = mb_type; | |||
if( cbp || IS_INTRA16x16( mb_type ) ) { | |||
const uint8_t *scan, *scan8x8; | |||
const uint32_t *qmul; | |||
if(IS_INTERLACED(mb_type)){ | |||
scan8x8= s->qscale ? h->field_scan8x8 : h->field_scan8x8_q0; | |||
scan= s->qscale ? h->field_scan : h->field_scan_q0; | |||
scan8x8= h->qscale ? h->field_scan8x8 : h->field_scan8x8_q0; | |||
scan= h->qscale ? h->field_scan : h->field_scan_q0; | |||
}else{ | |||
scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0; | |||
scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0; | |||
scan8x8= h->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0; | |||
scan= h->qscale ? h->zigzag_scan : h->zigzag_scan_q0; | |||
} | |||
// decode_cabac_mb_dqp | |||
@@ -2345,7 +2340,7 @@ decode_intra_mb: | |||
ctx= 3; | |||
val++; | |||
if(val > 2*max_qp){ //prevent infinite loop | |||
av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", s->mb_x, s->mb_y); | |||
av_log(h->avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", h->mb_x, h->mb_y); | |||
return -1; | |||
} | |||
} | |||
@@ -2355,13 +2350,13 @@ decode_intra_mb: | |||
else | |||
val= -((val + 1)>>1); | |||
h->last_qscale_diff = val; | |||
s->qscale += val; | |||
if(((unsigned)s->qscale) > max_qp){ | |||
if(s->qscale<0) s->qscale+= max_qp+1; | |||
else s->qscale-= max_qp+1; | |||
h->qscale += val; | |||
if(((unsigned)h->qscale) > max_qp){ | |||
if(h->qscale<0) h->qscale+= max_qp+1; | |||
else h->qscale-= max_qp+1; | |||
} | |||
h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); | |||
h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); | |||
h->chroma_qp[0] = get_chroma_qp(h, 0, h->qscale); | |||
h->chroma_qp[1] = get_chroma_qp(h, 1, h->qscale); | |||
}else | |||
h->last_qscale_diff=0; | |||
@@ -2423,7 +2418,7 @@ decode_intra_mb: | |||
h->last_qscale_diff = 0; | |||
} | |||
s->current_picture.f.qscale_table[mb_xy] = s->qscale; | |||
h->cur_pic.f.qscale_table[mb_xy] = h->qscale; | |||
write_back_non_zero_count(h); | |||
return 0; | |||
@@ -292,7 +292,7 @@ static inline int pred_non_zero_count(H264Context *h, int n){ | |||
if(i<64) i= (i+1)>>1; | |||
tprintf(h->s.avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); | |||
tprintf(h->avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); | |||
return i&31; | |||
} | |||
@@ -443,7 +443,6 @@ static inline int get_level_prefix(GetBitContext *gb){ | |||
* @return <0 if an error occurred | |||
*/ | |||
static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff){ | |||
MpegEncContext * const s = &h->s; | |||
static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3}; | |||
int level[16]; | |||
int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before; | |||
@@ -474,12 +473,12 @@ static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, in | |||
if(total_coeff==0) | |||
return 0; | |||
if(total_coeff > (unsigned)max_coeff) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", s->mb_x, s->mb_y, total_coeff); | |||
av_log(h->avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", h->mb_x, h->mb_y, total_coeff); | |||
return -1; | |||
} | |||
trailing_ones= coeff_token&3; | |||
tprintf(h->s.avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff); | |||
tprintf(h->avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff); | |||
av_assert2(total_coeff<=16); | |||
i = show_bits(gb, 3); | |||
@@ -515,7 +514,7 @@ static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, in | |||
level_code= 30; | |||
if(prefix>=16){ | |||
if(prefix > 25+3){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "Invalid level prefix\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "Invalid level prefix\n"); | |||
return -1; | |||
} | |||
level_code += (1<<(prefix-3))-4096; | |||
@@ -618,7 +617,7 @@ static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, in | |||
} | |||
if(zeros_left<0){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y); | |||
av_log(h->avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", h->mb_x, h->mb_y); | |||
return -1; | |||
} | |||
@@ -627,8 +626,7 @@ static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, in | |||
static av_always_inline int decode_luma_residual(H264Context *h, GetBitContext *gb, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p){ | |||
int i4x4, i8x8; | |||
MpegEncContext * const s = &h->s; | |||
int qscale = p == 0 ? s->qscale : h->chroma_qp[p-1]; | |||
int qscale = p == 0 ? h->qscale : h->chroma_qp[p-1]; | |||
if(IS_INTRA16x16(mb_type)){ | |||
AV_ZERO128(h->mb_luma_dc[p]+0); | |||
AV_ZERO128(h->mb_luma_dc[p]+8); | |||
@@ -693,7 +691,6 @@ static av_always_inline int decode_luma_residual(H264Context *h, GetBitContext * | |||
} | |||
int ff_h264_decode_mb_cavlc(H264Context *h){ | |||
MpegEncContext * const s = &h->s; | |||
int mb_xy; | |||
int partition_count; | |||
unsigned int mb_type, cbp; | |||
@@ -702,32 +699,32 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ | |||
const int pixel_shift = h->pixel_shift; | |||
unsigned local_ref_count[2]; | |||
mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; | |||
mb_xy = h->mb_xy = h->mb_x + h->mb_y*h->mb_stride; | |||
tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); | |||
tprintf(h->avctx, "pic:%d mb:%d/%d\n", h->frame_num, h->mb_x, h->mb_y); | |||
cbp = 0; /* avoid warning. FIXME: find a solution without slowing | |||
down the code */ | |||
if(h->slice_type_nos != AV_PICTURE_TYPE_I){ | |||
if(s->mb_skip_run==-1) | |||
s->mb_skip_run= get_ue_golomb(&s->gb); | |||
if(h->mb_skip_run==-1) | |||
h->mb_skip_run= get_ue_golomb(&h->gb); | |||
if (s->mb_skip_run--) { | |||
if(FRAME_MBAFF && (s->mb_y&1) == 0){ | |||
if(s->mb_skip_run==0) | |||
h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb); | |||
if (h->mb_skip_run--) { | |||
if(FRAME_MBAFF && (h->mb_y&1) == 0){ | |||
if(h->mb_skip_run==0) | |||
h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&h->gb); | |||
} | |||
decode_mb_skip(h); | |||
return 0; | |||
} | |||
} | |||
if(FRAME_MBAFF){ | |||
if( (s->mb_y&1) == 0 ) | |||
h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb); | |||
if( (h->mb_y&1) == 0 ) | |||
h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&h->gb); | |||
} | |||
h->prev_mb_skipped= 0; | |||
mb_type= get_ue_golomb(&s->gb); | |||
mb_type= get_ue_golomb(&h->gb); | |||
if(h->slice_type_nos == AV_PICTURE_TYPE_B){ | |||
if(mb_type < 23){ | |||
partition_count= b_mb_type_info[mb_type].partition_count; | |||
@@ -750,7 +747,7 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ | |||
mb_type--; | |||
decode_intra_mb: | |||
if(mb_type > 25){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(h->slice_type), s->mb_x, s->mb_y); | |||
av_log(h->avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(h->slice_type), h->mb_x, h->mb_y); | |||
return -1; | |||
} | |||
partition_count=0; | |||
@@ -770,19 +767,19 @@ decode_intra_mb: | |||
h->sps.bit_depth_luma >> 3; | |||
// We assume these blocks are very rare so we do not optimize it. | |||
align_get_bits(&s->gb); | |||
align_get_bits(&h->gb); | |||
// The pixels are stored in the same order as levels in h->mb array. | |||
for(x=0; x < mb_size; x++){ | |||
((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8); | |||
((uint8_t*)h->mb)[x]= get_bits(&h->gb, 8); | |||
} | |||
// In deblocking, the quantizer is 0 | |||
s->current_picture.f.qscale_table[mb_xy] = 0; | |||
h->cur_pic.f.qscale_table[mb_xy] = 0; | |||
// All coeffs are present | |||
memset(h->non_zero_count[mb_xy], 16, 48); | |||
s->current_picture.f.mb_type[mb_xy] = mb_type; | |||
h->cur_pic.f.mb_type[mb_xy] = mb_type; | |||
return 0; | |||
} | |||
@@ -799,7 +796,7 @@ decode_intra_mb: | |||
if(IS_INTRA4x4(mb_type)){ | |||
int i; | |||
int di = 1; | |||
if(dct8x8_allowed && get_bits1(&s->gb)){ | |||
if(dct8x8_allowed && get_bits1(&h->gb)){ | |||
mb_type |= MB_TYPE_8x8DCT; | |||
di = 4; | |||
} | |||
@@ -808,8 +805,8 @@ decode_intra_mb: | |||
for(i=0; i<16; i+=di){ | |||
int mode= pred_intra_mode(h, i); | |||
if(!get_bits1(&s->gb)){ | |||
const int rem_mode= get_bits(&s->gb, 3); | |||
if(!get_bits1(&h->gb)){ | |||
const int rem_mode= get_bits(&h->gb, 3); | |||
mode = rem_mode + (rem_mode >= mode); | |||
} | |||
@@ -827,7 +824,7 @@ decode_intra_mb: | |||
return -1; | |||
} | |||
if(decode_chroma){ | |||
pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb), 1); | |||
pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&h->gb), 1); | |||
if(pred_mode < 0) | |||
return -1; | |||
h->chroma_pred_mode= pred_mode; | |||
@@ -839,9 +836,9 @@ decode_intra_mb: | |||
if(h->slice_type_nos == AV_PICTURE_TYPE_B){ | |||
for(i=0; i<4; i++){ | |||
h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); | |||
h->sub_mb_type[i]= get_ue_golomb_31(&h->gb); | |||
if(h->sub_mb_type[i] >=13){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); | |||
av_log(h->avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], h->mb_x, h->mb_y); | |||
return -1; | |||
} | |||
sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | |||
@@ -857,9 +854,9 @@ decode_intra_mb: | |||
}else{ | |||
av_assert2(h->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ? | |||
for(i=0; i<4; i++){ | |||
h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); | |||
h->sub_mb_type[i]= get_ue_golomb_31(&h->gb); | |||
if(h->sub_mb_type[i] >=4){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); | |||
av_log(h->avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], h->mb_x, h->mb_y); | |||
return -1; | |||
} | |||
sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; | |||
@@ -876,11 +873,11 @@ decode_intra_mb: | |||
if(ref_count == 1){ | |||
tmp= 0; | |||
}else if(ref_count == 2){ | |||
tmp= get_bits1(&s->gb)^1; | |||
tmp= get_bits1(&h->gb)^1; | |||
}else{ | |||
tmp= get_ue_golomb_31(&s->gb); | |||
tmp= get_ue_golomb_31(&h->gb); | |||
if(tmp>=ref_count){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp); | |||
av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp); | |||
return -1; | |||
} | |||
} | |||
@@ -912,9 +909,9 @@ decode_intra_mb: | |||
const int index= 4*i + block_width*j; | |||
int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; | |||
pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); | |||
mx += get_se_golomb(&s->gb); | |||
my += get_se_golomb(&s->gb); | |||
tprintf(s->avctx, "final mv:%d %d\n", mx, my); | |||
mx += get_se_golomb(&h->gb); | |||
my += get_se_golomb(&h->gb); | |||
tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
if(IS_SUB_8X8(sub_mb_type)){ | |||
mv_cache[ 1 ][0]= | |||
@@ -951,11 +948,11 @@ decode_intra_mb: | |||
if(local_ref_count[list]==1){ | |||
val= 0; | |||
}else if(local_ref_count[list]==2){ | |||
val= get_bits1(&s->gb)^1; | |||
val= get_bits1(&h->gb)^1; | |||
}else{ | |||
val= get_ue_golomb_31(&s->gb); | |||
val= get_ue_golomb_31(&h->gb); | |||
if(val >= local_ref_count[list]){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); | |||
av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); | |||
return -1; | |||
} | |||
} | |||
@@ -965,9 +962,9 @@ decode_intra_mb: | |||
for(list=0; list<h->list_count; list++){ | |||
if(IS_DIR(mb_type, 0, list)){ | |||
pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); | |||
mx += get_se_golomb(&s->gb); | |||
my += get_se_golomb(&s->gb); | |||
tprintf(s->avctx, "final mv:%d %d\n", mx, my); | |||
mx += get_se_golomb(&h->gb); | |||
my += get_se_golomb(&h->gb); | |||
tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); | |||
} | |||
@@ -981,11 +978,11 @@ decode_intra_mb: | |||
if(local_ref_count[list] == 1){ | |||
val= 0; | |||
}else if(local_ref_count[list] == 2){ | |||
val= get_bits1(&s->gb)^1; | |||
val= get_bits1(&h->gb)^1; | |||
}else{ | |||
val= get_ue_golomb_31(&s->gb); | |||
val= get_ue_golomb_31(&h->gb); | |||
if(val >= local_ref_count[list]){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); | |||
av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); | |||
return -1; | |||
} | |||
} | |||
@@ -999,9 +996,9 @@ decode_intra_mb: | |||
unsigned int val; | |||
if(IS_DIR(mb_type, i, list)){ | |||
pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); | |||
mx += get_se_golomb(&s->gb); | |||
my += get_se_golomb(&s->gb); | |||
tprintf(s->avctx, "final mv:%d %d\n", mx, my); | |||
mx += get_se_golomb(&h->gb); | |||
my += get_se_golomb(&h->gb); | |||
tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
val= pack16to32(mx,my); | |||
}else | |||
@@ -1018,11 +1015,11 @@ decode_intra_mb: | |||
if(local_ref_count[list]==1){ | |||
val= 0; | |||
}else if(local_ref_count[list]==2){ | |||
val= get_bits1(&s->gb)^1; | |||
val= get_bits1(&h->gb)^1; | |||
}else{ | |||
val= get_ue_golomb_31(&s->gb); | |||
val= get_ue_golomb_31(&h->gb); | |||
if(val >= local_ref_count[list]){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); | |||
av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); | |||
return -1; | |||
} | |||
} | |||
@@ -1036,9 +1033,9 @@ decode_intra_mb: | |||
unsigned int val; | |||
if(IS_DIR(mb_type, i, list)){ | |||
pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); | |||
mx += get_se_golomb(&s->gb); | |||
my += get_se_golomb(&s->gb); | |||
tprintf(s->avctx, "final mv:%d %d\n", mx, my); | |||
mx += get_se_golomb(&h->gb); | |||
my += get_se_golomb(&h->gb); | |||
tprintf(h->avctx, "final mv:%d %d\n", mx, my); | |||
val= pack16to32(mx,my); | |||
}else | |||
@@ -1053,18 +1050,18 @@ decode_intra_mb: | |||
write_back_motion(h, mb_type); | |||
if(!IS_INTRA16x16(mb_type)){ | |||
cbp= get_ue_golomb(&s->gb); | |||
cbp= get_ue_golomb(&h->gb); | |||
if(decode_chroma){ | |||
if(cbp > 47){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); | |||
av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, h->mb_x, h->mb_y); | |||
return -1; | |||
} | |||
if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp]; | |||
else cbp= golomb_to_inter_cbp [cbp]; | |||
}else{ | |||
if(cbp > 15){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); | |||
av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, h->mb_x, h->mb_y); | |||
return -1; | |||
} | |||
if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp]; | |||
@@ -1072,17 +1069,17 @@ decode_intra_mb: | |||
} | |||
} else { | |||
if (!decode_chroma && cbp>15) { | |||
av_log(s->avctx, AV_LOG_ERROR, "gray chroma\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "gray chroma\n"); | |||
return AVERROR_INVALIDDATA; | |||
} | |||
} | |||
if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){ | |||
mb_type |= MB_TYPE_8x8DCT*get_bits1(&s->gb); | |||
mb_type |= MB_TYPE_8x8DCT*get_bits1(&h->gb); | |||
} | |||
h->cbp= | |||
h->cbp_table[mb_xy]= cbp; | |||
s->current_picture.f.mb_type[mb_xy] = mb_type; | |||
h->cur_pic.f.mb_type[mb_xy] = mb_type; | |||
if(cbp || IS_INTRA16x16(mb_type)){ | |||
int i4x4, i8x8, chroma_idx; | |||
@@ -1093,28 +1090,28 @@ decode_intra_mb: | |||
const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8); | |||
if(IS_INTERLACED(mb_type)){ | |||
scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0; | |||
scan= s->qscale ? h->field_scan : h->field_scan_q0; | |||
scan8x8= h->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0; | |||
scan= h->qscale ? h->field_scan : h->field_scan_q0; | |||
}else{ | |||
scan8x8= s->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0; | |||
scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0; | |||
scan8x8= h->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0; | |||
scan= h->qscale ? h->zigzag_scan : h->zigzag_scan_q0; | |||
} | |||
dquant= get_se_golomb(&s->gb); | |||
dquant= get_se_golomb(&h->gb); | |||
s->qscale += dquant; | |||
h->qscale += dquant; | |||
if(((unsigned)s->qscale) > max_qp){ | |||
if(s->qscale<0) s->qscale+= max_qp+1; | |||
else s->qscale-= max_qp+1; | |||
if(((unsigned)s->qscale) > max_qp){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y); | |||
if(((unsigned)h->qscale) > max_qp){ | |||
if(h->qscale<0) h->qscale+= max_qp+1; | |||
else h->qscale-= max_qp+1; | |||
if(((unsigned)h->qscale) > max_qp){ | |||
av_log(h->avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, h->mb_x, h->mb_y); | |||
return -1; | |||
} | |||
} | |||
h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale); | |||
h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale); | |||
h->chroma_qp[0]= get_chroma_qp(h, 0, h->qscale); | |||
h->chroma_qp[1]= get_chroma_qp(h, 1, h->qscale); | |||
if( (ret = decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ){ | |||
return -1; | |||
@@ -1163,7 +1160,7 @@ decode_intra_mb: | |||
fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); | |||
fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); | |||
} | |||
s->current_picture.f.qscale_table[mb_xy] = s->qscale; | |||
h->cur_pic.f.qscale_table[mb_xy] = h->qscale; | |||
write_back_non_zero_count(h); | |||
return 0; | |||
@@ -50,14 +50,13 @@ static int get_scale_factor(H264Context * const h, int poc, int poc1, int i){ | |||
} | |||
void ff_h264_direct_dist_scale_factor(H264Context * const h){ | |||
MpegEncContext * const s = &h->s; | |||
const int poc = h->s.current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ]; | |||
const int poc = h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD]; | |||
const int poc1 = h->ref_list[1][0].poc; | |||
int i, field; | |||
if (FRAME_MBAFF) | |||
for (field = 0; field < 2; field++){ | |||
const int poc = h->s.current_picture_ptr->field_poc[field]; | |||
const int poc = h->cur_pic_ptr->field_poc[field]; | |||
const int poc1 = h->ref_list[1][0].field_poc[field]; | |||
for (i = 0; i < 2 * h->ref_count[0]; i++) | |||
h->dist_scale_factor_field[field][i^field] = | |||
@@ -70,12 +69,11 @@ void ff_h264_direct_dist_scale_factor(H264Context * const h){ | |||
} | |||
static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){ | |||
MpegEncContext * const s = &h->s; | |||
Picture * const ref1 = &h->ref_list[1][0]; | |||
int j, old_ref, rfield; | |||
int start= mbafi ? 16 : 0; | |||
int end = mbafi ? 16+2*h->ref_count[0] : h->ref_count[0]; | |||
int interl= mbafi || s->picture_structure != PICT_FRAME; | |||
int interl= mbafi || h->picture_structure != PICT_FRAME; | |||
/* bogus; fills in for missing frames */ | |||
memset(map[list], 0, sizeof(map[list])); | |||
@@ -104,11 +102,10 @@ static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, | |||
} | |||
void ff_h264_direct_ref_list_init(H264Context * const h){ | |||
MpegEncContext * const s = &h->s; | |||
Picture * const ref1 = &h->ref_list[1][0]; | |||
Picture * const cur = s->current_picture_ptr; | |||
Picture * const cur = h->cur_pic_ptr; | |||
int list, j, field; | |||
int sidx= (s->picture_structure&1)^1; | |||
int sidx= (h->picture_structure&1)^1; | |||
int ref1sidx = (ref1->f.reference&1)^1; | |||
for(list=0; list<2; list++){ | |||
@@ -117,7 +114,7 @@ void ff_h264_direct_ref_list_init(H264Context * const h){ | |||
cur->ref_poc[sidx][list][j] = 4 * h->ref_list[list][j].frame_num + (h->ref_list[list][j].f.reference & 3); | |||
} | |||
if(s->picture_structure == PICT_FRAME){ | |||
if(h->picture_structure == PICT_FRAME){ | |||
memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0])); | |||
memcpy(cur->ref_poc [1], cur->ref_poc [0], sizeof(cur->ref_poc [0])); | |||
} | |||
@@ -125,12 +122,12 @@ void ff_h264_direct_ref_list_init(H264Context * const h){ | |||
cur->mbaff= FRAME_MBAFF; | |||
h->col_fieldoff= 0; | |||
if(s->picture_structure == PICT_FRAME){ | |||
int cur_poc = s->current_picture_ptr->poc; | |||
if(h->picture_structure == PICT_FRAME){ | |||
int cur_poc = h->cur_pic_ptr->poc; | |||
int *col_poc = h->ref_list[1]->field_poc; | |||
h->col_parity= (FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc)); | |||
ref1sidx=sidx= h->col_parity; | |||
} else if (!(s->picture_structure & h->ref_list[1][0].f.reference) && !h->ref_list[1][0].mbaff) { // FL -> FL & differ parity | |||
} else if (!(h->picture_structure & h->ref_list[1][0].f.reference) && !h->ref_list[1][0].mbaff) { // FL -> FL & differ parity | |||
h->col_fieldoff = 2 * h->ref_list[1][0].f.reference - 3; | |||
} | |||
@@ -149,9 +146,9 @@ static void await_reference_mb_row(H264Context * const h, Picture *ref, int mb_y | |||
{ | |||
int ref_field = ref->f.reference - 1; | |||
int ref_field_picture = ref->field_picture; | |||
int ref_height = 16*h->s.mb_height >> ref_field_picture; | |||
int ref_height = 16*h->mb_height >> ref_field_picture; | |||
if(!HAVE_THREADS || !(h->s.avctx->active_thread_type&FF_THREAD_FRAME)) | |||
if(!HAVE_THREADS || !(h->avctx->active_thread_type&FF_THREAD_FRAME)) | |||
return; | |||
//FIXME it can be safe to access mb stuff | |||
@@ -163,10 +160,9 @@ static void await_reference_mb_row(H264Context * const h, Picture *ref, int mb_y | |||
} | |||
static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ | |||
MpegEncContext * const s = &h->s; | |||
int b8_stride = 2; | |||
int b4_stride = h->b_stride; | |||
int mb_xy = h->mb_xy, mb_y = s->mb_y; | |||
int mb_xy = h->mb_xy, mb_y = h->mb_y; | |||
int mb_type_col[2]; | |||
const int16_t (*l1mv0)[2], (*l1mv1)[2]; | |||
const int8_t *l1ref0, *l1ref1; | |||
@@ -179,7 +175,7 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ | |||
assert(h->ref_list[1][0].f.reference & 3); | |||
await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type)); | |||
await_reference_mb_row(h, &h->ref_list[1][0], h->mb_y + !!IS_INTERLACED(*mb_type)); | |||
#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM) | |||
@@ -241,21 +237,21 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ | |||
if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL | |||
if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL | |||
mb_y = (s->mb_y&~1) + h->col_parity; | |||
mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride; | |||
mb_y = (h->mb_y&~1) + h->col_parity; | |||
mb_xy= h->mb_x + ((h->mb_y&~1) + h->col_parity)*h->mb_stride; | |||
b8_stride = 0; | |||
}else{ | |||
mb_y += h->col_fieldoff; | |||
mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity | |||
mb_xy += h->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity | |||
} | |||
goto single_col; | |||
}else{ // AFL/AFR/FR/FL -> AFR/FR | |||
if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR | |||
mb_y = s->mb_y&~1; | |||
mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride; | |||
mb_y = h->mb_y&~1; | |||
mb_xy= h->mb_x + (h->mb_y&~1)*h->mb_stride; | |||
mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy]; | |||
mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride]; | |||
b8_stride = 2+4*s->mb_stride; | |||
mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + h->mb_stride]; | |||
b8_stride = 2+4*h->mb_stride; | |||
b4_stride *= 6; | |||
if (IS_INTERLACED(mb_type_col[0]) != IS_INTERLACED(mb_type_col[1])) { | |||
mb_type_col[0] &= ~MB_TYPE_INTERLACED; | |||
@@ -298,7 +294,7 @@ single_col: | |||
l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy]; | |||
l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy]; | |||
if(!b8_stride){ | |||
if(s->mb_y&1){ | |||
if(h->mb_y&1){ | |||
l1ref0 += 2; | |||
l1ref1 += 2; | |||
l1mv0 += 2*b4_stride; | |||
@@ -414,10 +410,9 @@ single_col: | |||
} | |||
static void pred_temp_direct_motion(H264Context * const h, int *mb_type){ | |||
MpegEncContext * const s = &h->s; | |||
int b8_stride = 2; | |||
int b4_stride = h->b_stride; | |||
int mb_xy = h->mb_xy, mb_y = s->mb_y; | |||
int mb_xy = h->mb_xy, mb_y = h->mb_y; | |||
int mb_type_col[2]; | |||
const int16_t (*l1mv0)[2], (*l1mv1)[2]; | |||
const int8_t *l1ref0, *l1ref1; | |||
@@ -427,25 +422,25 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){ | |||
assert(h->ref_list[1][0].f.reference & 3); | |||
await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type)); | |||
await_reference_mb_row(h, &h->ref_list[1][0], h->mb_y + !!IS_INTERLACED(*mb_type)); | |||
if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL | |||
if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL | |||
mb_y = (s->mb_y&~1) + h->col_parity; | |||
mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride; | |||
mb_y = (h->mb_y&~1) + h->col_parity; | |||
mb_xy= h->mb_x + ((h->mb_y&~1) + h->col_parity)*h->mb_stride; | |||
b8_stride = 0; | |||
}else{ | |||
mb_y += h->col_fieldoff; | |||
mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity | |||
mb_xy += h->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity | |||
} | |||
goto single_col; | |||
}else{ // AFL/AFR/FR/FL -> AFR/FR | |||
if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR | |||
mb_y = s->mb_y&~1; | |||
mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride; | |||
mb_y = h->mb_y&~1; | |||
mb_xy= h->mb_x + (h->mb_y&~1)*h->mb_stride; | |||
mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy]; | |||
mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride]; | |||
b8_stride = 2+4*s->mb_stride; | |||
mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + h->mb_stride]; | |||
b8_stride = 2+4*h->mb_stride; | |||
b4_stride *= 6; | |||
if (IS_INTERLACED(mb_type_col[0]) != IS_INTERLACED(mb_type_col[1])) { | |||
mb_type_col[0] &= ~MB_TYPE_INTERLACED; | |||
@@ -489,7 +484,7 @@ single_col: | |||
l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy]; | |||
l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy]; | |||
if(!b8_stride){ | |||
if(s->mb_y&1){ | |||
if(h->mb_y&1){ | |||
l1ref0 += 2; | |||
l1ref1 += 2; | |||
l1mv0 += 2*b4_stride; | |||
@@ -503,9 +498,9 @@ single_col: | |||
int ref_offset; | |||
if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){ | |||
map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0]; | |||
map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1]; | |||
dist_scale_factor =h->dist_scale_factor_field[s->mb_y&1]; | |||
map_col_to_list0[0] = h->map_col_to_list0_field[h->mb_y&1][0]; | |||
map_col_to_list0[1] = h->map_col_to_list0_field[h->mb_y&1][1]; | |||
dist_scale_factor =h->dist_scale_factor_field[h->mb_y&1]; | |||
} | |||
ref_offset = (h->ref_list[1][0].mbaff<<4) & (mb_type_col[0]>>3); //if(h->ref_list[1][0].mbaff && IS_INTERLACED(mb_type_col[0])) ref_offset=16 else 0 | |||
@@ -241,8 +241,7 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, | |||
unsigned int uvlinesize, | |||
int pixel_shift) | |||
{ | |||
MpegEncContext * const s = &h->s; | |||
int chroma = CHROMA && !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY)); | |||
int chroma = CHROMA && !(CONFIG_GRAY && (h->flags&CODEC_FLAG_GRAY)); | |||
int chroma444 = CHROMA444; | |||
int chroma422 = CHROMA422; | |||
@@ -254,10 +253,10 @@ static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, | |||
int a = h->slice_alpha_c0_offset - qp_bd_offset; | |||
int b = h->slice_beta_offset - qp_bd_offset; | |||
int mb_type = s->current_picture.f.mb_type[mb_xy]; | |||
int qp = s->current_picture.f.qscale_table[mb_xy]; | |||
int qp0 = s->current_picture.f.qscale_table[mb_xy - 1]; | |||
int qp1 = s->current_picture.f.qscale_table[h->top_mb_xy]; | |||
int mb_type = h->cur_pic.f.mb_type[mb_xy]; | |||
int qp = h->cur_pic.f.qscale_table[mb_xy]; | |||
int qp0 = h->cur_pic.f.qscale_table[mb_xy - 1]; | |||
int qp1 = h->cur_pic.f.qscale_table[h->top_mb_xy]; | |||
int qpc = get_chroma_qp( h, 0, qp ); | |||
int qpc0 = get_chroma_qp( h, 0, qp0 ); | |||
int qpc1 = get_chroma_qp( h, 0, qp1 ); | |||
@@ -462,7 +461,6 @@ static int check_mv(H264Context *h, long b_idx, long bn_idx, int mvy_limit){ | |||
} | |||
static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize, int mb_xy, int mb_type, int mvy_limit, int first_vertical_edge_done, int a, int b, int chroma, int dir) { | |||
MpegEncContext * const s = &h->s; | |||
int edge; | |||
int chroma_qp_avg[2]; | |||
int chroma444 = CHROMA444; | |||
@@ -490,16 +488,16 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u | |||
// | |||
unsigned int tmp_linesize = 2 * linesize; | |||
unsigned int tmp_uvlinesize = 2 * uvlinesize; | |||
int mbn_xy = mb_xy - 2 * s->mb_stride; | |||
int mbn_xy = mb_xy - 2 * h->mb_stride; | |||
int j; | |||
for(j=0; j<2; j++, mbn_xy += s->mb_stride){ | |||
for(j=0; j<2; j++, mbn_xy += h->mb_stride){ | |||
DECLARE_ALIGNED(8, int16_t, bS)[4]; | |||
int qp; | |||
if (IS_INTRA(mb_type | s->current_picture.f.mb_type[mbn_xy])) { | |||
if (IS_INTRA(mb_type | h->cur_pic.f.mb_type[mbn_xy])) { | |||
AV_WN64A(bS, 0x0003000300030003ULL); | |||
} else { | |||
if (!CABAC && IS_8x8DCT(s->current_picture.f.mb_type[mbn_xy])) { | |||
if (!CABAC && IS_8x8DCT(h->cur_pic.f.mb_type[mbn_xy])) { | |||
bS[0]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+0]); | |||
bS[1]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+1]); | |||
bS[2]= 1+((h->cbp_table[mbn_xy] & 0x8000)||h->non_zero_count_cache[scan8[0]+2]); | |||
@@ -514,12 +512,12 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u | |||
} | |||
// Do not use s->qscale as luma quantizer because it has not the same | |||
// value in IPCM macroblocks. | |||
qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbn_xy] + 1) >> 1; | |||
tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); | |||
{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } | |||
qp = (h->cur_pic.f.qscale_table[mb_xy] + h->cur_pic.f.qscale_table[mbn_xy] + 1) >> 1; | |||
tprintf(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); | |||
{ int i; for (i = 0; i < 4; i++) tprintf(h->avctx, " bS[%d]:%d", i, bS[i]); tprintf(h->avctx, "\n"); } | |||
filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, a, b, h, 0 ); | |||
chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1; | |||
chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1; | |||
chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, h->cur_pic.f.qscale_table[mbn_xy]) + 1) >> 1; | |||
chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, h->cur_pic.f.qscale_table[mbn_xy]) + 1) >> 1; | |||
if (chroma) { | |||
if (chroma444) { | |||
filter_mb_edgeh (&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0); | |||
@@ -537,7 +535,7 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u | |||
if( IS_INTRA(mb_type|mbm_type)) { | |||
AV_WN64A(bS, 0x0003000300030003ULL); | |||
if ( (!IS_INTERLACED(mb_type|mbm_type)) | |||
|| ((FRAME_MBAFF || (s->picture_structure != PICT_FRAME)) && (dir == 0)) | |||
|| ((FRAME_MBAFF || (h->picture_structure != PICT_FRAME)) && (dir == 0)) | |||
) | |||
AV_WN64A(bS, 0x0004000400040004ULL); | |||
} else { | |||
@@ -579,12 +577,12 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u | |||
// Do not use s->qscale as luma quantizer because it has not the same | |||
// value in IPCM macroblocks. | |||
if(bS[0]+bS[1]+bS[2]+bS[3]){ | |||
qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbm_xy] + 1) >> 1; | |||
//tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]); | |||
tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); | |||
//{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } | |||
chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1; | |||
chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1; | |||
qp = (h->cur_pic.f.qscale_table[mb_xy] + h->cur_pic.f.qscale_table[mbm_xy] + 1) >> 1; | |||
//tprintf(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], h->cur_pic.qscale_table[mbn_xy]); | |||
tprintf(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); | |||
//{ int i; for (i = 0; i < 4; i++) tprintf(h->avctx, " bS[%d]:%d", i, bS[i]); tprintf(h->avctx, "\n"); } | |||
chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, h->cur_pic.f.qscale_table[mbm_xy]) + 1) >> 1; | |||
chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, h->cur_pic.f.qscale_table[mbm_xy]) + 1) >> 1; | |||
if( dir == 0 ) { | |||
filter_mb_edgev( &img_y[0], linesize, bS, qp, a, b, h, 1 ); | |||
if (chroma) { | |||
@@ -664,10 +662,10 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u | |||
/* Filter edge */ | |||
// Do not use s->qscale as luma quantizer because it has not the same | |||
// value in IPCM macroblocks. | |||
qp = s->current_picture.f.qscale_table[mb_xy]; | |||
//tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]); | |||
tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); | |||
//{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } | |||
qp = h->cur_pic.f.qscale_table[mb_xy]; | |||
//tprintf(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], h->cur_pic.qscale_table[mbn_xy]); | |||
tprintf(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); | |||
//{ int i; for (i = 0; i < 4; i++) tprintf(h->avctx, " bS[%d]:%d", i, bS[i]); tprintf(h->avctx, "\n"); } | |||
if( dir == 0 ) { | |||
filter_mb_edgev( &img_y[4*edge << h->pixel_shift], linesize, bS, qp, a, b, h, 0 ); | |||
if (chroma) { | |||
@@ -704,13 +702,12 @@ static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, u | |||
} | |||
void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) { | |||
MpegEncContext * const s = &h->s; | |||
const int mb_xy= mb_x + mb_y*s->mb_stride; | |||
const int mb_type = s->current_picture.f.mb_type[mb_xy]; | |||
const int mb_xy= mb_x + mb_y*h->mb_stride; | |||
const int mb_type = h->cur_pic.f.mb_type[mb_xy]; | |||
const int mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4; | |||
int first_vertical_edge_done = 0; | |||
av_unused int dir; | |||
int chroma = CHROMA && !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY)); | |||
int chroma = CHROMA && !(CONFIG_GRAY && (h->flags&CODEC_FLAG_GRAY)); | |||
int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); | |||
int a = h->slice_alpha_c0_offset - qp_bd_offset; | |||
int b = h->slice_beta_offset - qp_bd_offset; | |||
@@ -762,9 +759,9 @@ void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint | |||
} | |||
} | |||
mb_qp = s->current_picture.f.qscale_table[mb_xy]; | |||
mbn0_qp = s->current_picture.f.qscale_table[h->left_mb_xy[0]]; | |||
mbn1_qp = s->current_picture.f.qscale_table[h->left_mb_xy[1]]; | |||
mb_qp = h->cur_pic.f.qscale_table[mb_xy]; | |||
mbn0_qp = h->cur_pic.f.qscale_table[h->left_mb_xy[0]]; | |||
mbn1_qp = h->cur_pic.f.qscale_table[h->left_mb_xy[1]]; | |||
qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1; | |||
bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) + | |||
get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1; | |||
@@ -777,8 +774,8 @@ void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint | |||
get_chroma_qp( h, 1, mbn1_qp ) + 1 ) >> 1; | |||
/* Filter edge */ | |||
tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize); | |||
{ int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } | |||
tprintf(h->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize); | |||
{ int i; for (i = 0; i < 8; i++) tprintf(h->avctx, " bS[%d]:%d", i, bS[i]); tprintf(h->avctx, "\n"); } | |||
if(MB_FIELD){ | |||
filter_mb_mbaff_edgev ( h, img_y , linesize, bS , 1, qp [0], a, b, 1 ); | |||
filter_mb_mbaff_edgev ( h, img_y + 8* linesize, linesize, bS+4, 1, qp [1], a, b, 1 ); | |||
@@ -40,39 +40,38 @@ | |||
static av_noinline void FUNC(hl_decode_mb)(H264Context *h) | |||
{ | |||
MpegEncContext *const s = &h->s; | |||
const int mb_x = s->mb_x; | |||
const int mb_y = s->mb_y; | |||
const int mb_x = h->mb_x; | |||
const int mb_y = h->mb_y; | |||
const int mb_xy = h->mb_xy; | |||
const int mb_type = s->current_picture.f.mb_type[mb_xy]; | |||
const int mb_type = h->cur_pic.f.mb_type[mb_xy]; | |||
uint8_t *dest_y, *dest_cb, *dest_cr; | |||
int linesize, uvlinesize /*dct_offset*/; | |||
int i, j; | |||
int *block_offset = &h->block_offset[0]; | |||
const int transform_bypass = !SIMPLE && (s->qscale == 0 && h->sps.transform_bypass); | |||
const int transform_bypass = !SIMPLE && (h->qscale == 0 && h->sps.transform_bypass); | |||
/* is_h264 should always be true if SVQ3 is disabled. */ | |||
const int is_h264 = !CONFIG_SVQ3_DECODER || SIMPLE || s->codec_id == AV_CODEC_ID_H264; | |||
const int is_h264 = !CONFIG_SVQ3_DECODER || SIMPLE || h->avctx->codec_id == AV_CODEC_ID_H264; | |||
void (*idct_add)(uint8_t *dst, int16_t *block, int stride); | |||
const int block_h = 16 >> s->chroma_y_shift; | |||
const int block_h = 16 >> h->chroma_y_shift; | |||
const int chroma422 = CHROMA422; | |||
dest_y = s->current_picture.f.data[0] + ((mb_x << PIXEL_SHIFT) + mb_y * s->linesize) * 16; | |||
dest_cb = s->current_picture.f.data[1] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * s->uvlinesize * block_h; | |||
dest_cr = s->current_picture.f.data[2] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * s->uvlinesize * block_h; | |||
dest_y = h->cur_pic.f.data[0] + ((mb_x << PIXEL_SHIFT) + mb_y * h->linesize) * 16; | |||
dest_cb = h->cur_pic.f.data[1] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * h->uvlinesize * block_h; | |||
dest_cr = h->cur_pic.f.data[2] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * h->uvlinesize * block_h; | |||
s->vdsp.prefetch(dest_y + (s->mb_x & 3) * 4 * s->linesize + (64 << PIXEL_SHIFT), s->linesize, 4); | |||
s->vdsp.prefetch(dest_cb + (s->mb_x & 7) * s->uvlinesize + (64 << PIXEL_SHIFT), dest_cr - dest_cb, 2); | |||
h->vdsp.prefetch(dest_y + (h->mb_x & 3) * 4 * h->linesize + (64 << PIXEL_SHIFT), h->linesize, 4); | |||
h->vdsp.prefetch(dest_cb + (h->mb_x & 7) * h->uvlinesize + (64 << PIXEL_SHIFT), dest_cr - dest_cb, 2); | |||
h->list_counts[mb_xy] = h->list_count; | |||
if (!SIMPLE && MB_FIELD) { | |||
linesize = h->mb_linesize = s->linesize * 2; | |||
uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2; | |||
linesize = h->mb_linesize = h->linesize * 2; | |||
uvlinesize = h->mb_uvlinesize = h->uvlinesize * 2; | |||
block_offset = &h->block_offset[48]; | |||
if (mb_y & 1) { // FIXME move out of this function? | |||
dest_y -= s->linesize * 15; | |||
dest_cb -= s->uvlinesize * (block_h - 1); | |||
dest_cr -= s->uvlinesize * (block_h - 1); | |||
dest_y -= h->linesize * 15; | |||
dest_cb -= h->uvlinesize * (block_h - 1); | |||
dest_cr -= h->uvlinesize * (block_h - 1); | |||
} | |||
if (FRAME_MBAFF) { | |||
int list; | |||
@@ -81,20 +80,20 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) | |||
continue; | |||
if (IS_16X16(mb_type)) { | |||
int8_t *ref = &h->ref_cache[list][scan8[0]]; | |||
fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (s->mb_y & 1), 1); | |||
fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (h->mb_y & 1), 1); | |||
} else { | |||
for (i = 0; i < 16; i += 4) { | |||
int ref = h->ref_cache[list][scan8[i]]; | |||
if (ref >= 0) | |||
fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, | |||
8, (16 + ref) ^ (s->mb_y & 1), 1); | |||
8, (16 + ref) ^ (h->mb_y & 1), 1); | |||
} | |||
} | |||
} | |||
} | |||
} else { | |||
linesize = h->mb_linesize = s->linesize; | |||
uvlinesize = h->mb_uvlinesize = s->uvlinesize; | |||
linesize = h->mb_linesize = h->linesize; | |||
uvlinesize = h->mb_uvlinesize = h->uvlinesize; | |||
// dct_offset = s->linesize * 16; | |||
} | |||
@@ -111,7 +110,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) | |||
for (j = 0; j < 16; j++) | |||
tmp_y[j] = get_bits(&gb, bit_depth); | |||
} | |||
if (SIMPLE || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { | |||
if (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) { | |||
if (!h->sps.chroma_format_idc) { | |||
for (i = 0; i < block_h; i++) { | |||
uint16_t *tmp_cb = (uint16_t *)(dest_cb + i * uvlinesize); | |||
@@ -136,7 +135,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) | |||
} else { | |||
for (i = 0; i < 16; i++) | |||
memcpy(dest_y + i * linesize, (uint8_t *)h->mb + i * 16, 16); | |||
if (SIMPLE || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { | |||
if (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) { | |||
if (!h->sps.chroma_format_idc) { | |||
for (i = 0; i < 8; i++) { | |||
memset(dest_cb + i*uvlinesize, 1 << (bit_depth - 1), 8); | |||
@@ -158,7 +157,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) | |||
xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, | |||
uvlinesize, 1, 0, SIMPLE, PIXEL_SHIFT); | |||
if (SIMPLE || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { | |||
if (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) { | |||
h->hpc.pred8x8[h->chroma_pred_mode](dest_cb, uvlinesize); | |||
h->hpc.pred8x8[h->chroma_pred_mode](dest_cr, uvlinesize); | |||
} | |||
@@ -173,14 +172,14 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) | |||
} else if (is_h264) { | |||
if (chroma422) { | |||
FUNC(hl_motion_422)(h, dest_y, dest_cb, dest_cr, | |||
s->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab, | |||
s->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab, | |||
h->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab, | |||
h->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab, | |||
h->h264dsp.weight_h264_pixels_tab, | |||
h->h264dsp.biweight_h264_pixels_tab); | |||
} else { | |||
FUNC(hl_motion_420)(h, dest_y, dest_cb, dest_cr, | |||
s->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab, | |||
s->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab, | |||
h->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab, | |||
h->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab, | |||
h->h264dsp.weight_h264_pixels_tab, | |||
h->h264dsp.biweight_h264_pixels_tab); | |||
} | |||
@@ -189,7 +188,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) | |||
hl_decode_mb_idct_luma(h, mb_type, is_h264, SIMPLE, transform_bypass, | |||
PIXEL_SHIFT, block_offset, linesize, dest_y, 0); | |||
if ((SIMPLE || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) && | |||
if ((SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) && | |||
(h->cbp & 0x30)) { | |||
uint8_t *dest[2] = { dest_cb, dest_cr }; | |||
if (transform_bypass) { | |||
@@ -253,7 +252,7 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) | |||
uint8_t *const ptr = dest[j - 1] + block_offset[i]; | |||
ff_svq3_add_idct_c(ptr, h->mb + i * 16, | |||
uvlinesize, | |||
ff_h264_chroma_qp[0][s->qscale + 12] - 12, 2); | |||
ff_h264_chroma_qp[0][h->qscale + 12] - 12, 2); | |||
} | |||
} | |||
} | |||
@@ -261,8 +260,8 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) | |||
} | |||
} | |||
if (h->cbp || IS_INTRA(mb_type)) { | |||
s->dsp.clear_blocks(h->mb); | |||
s->dsp.clear_blocks(h->mb + (24 * 16 << PIXEL_SHIFT)); | |||
h->dsp.clear_blocks(h->mb); | |||
h->dsp.clear_blocks(h->mb + (24 * 16 << PIXEL_SHIFT)); | |||
} | |||
} | |||
@@ -274,33 +273,32 @@ static av_noinline void FUNC(hl_decode_mb)(H264Context *h) | |||
static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h) | |||
{ | |||
MpegEncContext *const s = &h->s; | |||
const int mb_x = s->mb_x; | |||
const int mb_y = s->mb_y; | |||
const int mb_x = h->mb_x; | |||
const int mb_y = h->mb_y; | |||
const int mb_xy = h->mb_xy; | |||
const int mb_type = s->current_picture.f.mb_type[mb_xy]; | |||
const int mb_type = h->cur_pic.f.mb_type[mb_xy]; | |||
uint8_t *dest[3]; | |||
int linesize; | |||
int i, j, p; | |||
int *block_offset = &h->block_offset[0]; | |||
const int transform_bypass = !SIMPLE && (s->qscale == 0 && h->sps.transform_bypass); | |||
const int plane_count = (SIMPLE || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) ? 3 : 1; | |||
const int transform_bypass = !SIMPLE && (h->qscale == 0 && h->sps.transform_bypass); | |||
const int plane_count = (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) ? 3 : 1; | |||
for (p = 0; p < plane_count; p++) { | |||
dest[p] = s->current_picture.f.data[p] + | |||
((mb_x << PIXEL_SHIFT) + mb_y * s->linesize) * 16; | |||
s->vdsp.prefetch(dest[p] + (s->mb_x & 3) * 4 * s->linesize + (64 << PIXEL_SHIFT), | |||
s->linesize, 4); | |||
dest[p] = h->cur_pic.f.data[p] + | |||
((mb_x << PIXEL_SHIFT) + mb_y * h->linesize) * 16; | |||
h->vdsp.prefetch(dest[p] + (h->mb_x & 3) * 4 * h->linesize + (64 << PIXEL_SHIFT), | |||
h->linesize, 4); | |||
} | |||
h->list_counts[mb_xy] = h->list_count; | |||
if (!SIMPLE && MB_FIELD) { | |||
linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize * 2; | |||
linesize = h->mb_linesize = h->mb_uvlinesize = h->linesize * 2; | |||
block_offset = &h->block_offset[48]; | |||
if (mb_y & 1) // FIXME move out of this function? | |||
for (p = 0; p < 3; p++) | |||
dest[p] -= s->linesize * 15; | |||
dest[p] -= h->linesize * 15; | |||
if (FRAME_MBAFF) { | |||
int list; | |||
for (list = 0; list < h->list_count; list++) { | |||
@@ -308,19 +306,19 @@ static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h) | |||
continue; | |||
if (IS_16X16(mb_type)) { | |||
int8_t *ref = &h->ref_cache[list][scan8[0]]; | |||
fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (s->mb_y & 1), 1); | |||
fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (h->mb_y & 1), 1); | |||
} else { | |||
for (i = 0; i < 16; i += 4) { | |||
int ref = h->ref_cache[list][scan8[i]]; | |||
if (ref >= 0) | |||
fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, | |||
8, (16 + ref) ^ (s->mb_y & 1), 1); | |||
8, (16 + ref) ^ (h->mb_y & 1), 1); | |||
} | |||
} | |||
} | |||
} | |||
} else { | |||
linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize; | |||
linesize = h->mb_linesize = h->mb_uvlinesize = h->linesize; | |||
} | |||
if (!SIMPLE && IS_INTRA_PCM(mb_type)) { | |||
@@ -357,8 +355,8 @@ static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h) | |||
linesize, 0, 1, SIMPLE, PIXEL_SHIFT); | |||
} else { | |||
FUNC(hl_motion_444)(h, dest[0], dest[1], dest[2], | |||
s->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab, | |||
s->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab, | |||
h->me.qpel_put, h->h264chroma.put_h264_chroma_pixels_tab, | |||
h->me.qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab, | |||
h->h264dsp.weight_h264_pixels_tab, | |||
h->h264dsp.biweight_h264_pixels_tab); | |||
} | |||
@@ -369,8 +367,8 @@ static av_noinline void FUNC(hl_decode_mb_444)(H264Context *h) | |||
dest[p], p); | |||
} | |||
if (h->cbp || IS_INTRA(mb_type)) { | |||
s->dsp.clear_blocks(h->mb); | |||
s->dsp.clear_blocks(h->mb + (24 * 16 << PIXEL_SHIFT)); | |||
h->dsp.clear_blocks(h->mb); | |||
h->dsp.clear_blocks(h->mb + (24 * 16 << PIXEL_SHIFT)); | |||
} | |||
} | |||
@@ -46,7 +46,7 @@ static void mc_part(H264Context *h, int n, int square, | |||
int list0, int list1) | |||
{ | |||
if ((h->use_weight == 2 && list0 && list1 && | |||
(h->implicit_weight[h->ref_cache[0][scan8[n]]][h->ref_cache[1][scan8[n]]][h->s.mb_y & 1] != 32)) || | |||
(h->implicit_weight[h->ref_cache[0][scan8[n]]][h->ref_cache[1][scan8[n]]][h->mb_y & 1] != 32)) || | |||
h->use_weight == 1) | |||
mc_part_weighted(h, n, square, height, delta, dest_y, dest_cb, dest_cr, | |||
x_offset, y_offset, qpix_put, chroma_put, | |||
@@ -67,13 +67,12 @@ static void MCFUNC(hl_motion)(H264Context *h, uint8_t *dest_y, | |||
h264_weight_func *weight_op, | |||
h264_biweight_func *weight_avg) | |||
{ | |||
MpegEncContext *const s = &h->s; | |||
const int mb_xy = h->mb_xy; | |||
const int mb_type = s->current_picture.f.mb_type[mb_xy]; | |||
const int mb_type = h->cur_pic.f.mb_type[mb_xy]; | |||
av_assert2(IS_INTER(mb_type)); | |||
if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) | |||
if (HAVE_THREADS && (h->avctx->active_thread_type & FF_THREAD_FRAME)) | |||
await_references(h); | |||
prefetch_motion(h, 0, PIXEL_SHIFT, CHROMA_IDC); | |||
@@ -38,32 +38,31 @@ static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, | |||
int i, int list, int part_width) | |||
{ | |||
const int topright_ref = h->ref_cache[list][i - 8 + part_width]; | |||
MpegEncContext *s = &h->s; | |||
/* there is no consistent mapping of mvs to neighboring locations that will | |||
* make mbaff happy, so we can't move all this logic to fill_caches */ | |||
if (FRAME_MBAFF) { | |||
#define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4) \ | |||
const int xy = XY, y4 = Y4; \ | |||
const int mb_type = mb_types[xy + (y4 >> 2) * s->mb_stride]; \ | |||
const int mb_type = mb_types[xy + (y4 >> 2) * h->mb_stride]; \ | |||
if (!USES_LIST(mb_type, list)) \ | |||
return LIST_NOT_USED; \ | |||
mv = s->current_picture_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \ | |||
mv = h->cur_pic_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \ | |||
h->mv_cache[list][scan8[0] - 2][0] = mv[0]; \ | |||
h->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP; \ | |||
return s->current_picture_ptr->f.ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP; | |||
return h->cur_pic_ptr->f.ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP; | |||
if (topright_ref == PART_NOT_AVAILABLE | |||
&& i >= scan8[0] + 8 && (i & 7) == 4 | |||
&& h->ref_cache[list][scan8[0] - 1] != PART_NOT_AVAILABLE) { | |||
const uint32_t *mb_types = s->current_picture_ptr->f.mb_type; | |||
const uint32_t *mb_types = h->cur_pic_ptr->f.mb_type; | |||
const int16_t *mv; | |||
AV_ZERO32(h->mv_cache[list][scan8[0] - 2]); | |||
*C = h->mv_cache[list][scan8[0] - 2]; | |||
if (!MB_FIELD && IS_INTERLACED(h->left_type[0])) { | |||
SET_DIAG_MV(* 2, >> 1, h->left_mb_xy[0] + s->mb_stride, | |||
(s->mb_y & 1) * 2 + (i >> 5)); | |||
SET_DIAG_MV(* 2, >> 1, h->left_mb_xy[0] + h->mb_stride, | |||
(h->mb_y & 1) * 2 + (i >> 5)); | |||
} | |||
if (MB_FIELD && !IS_INTERLACED(h->left_type[0])) { | |||
// left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK. | |||
@@ -77,7 +76,7 @@ static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, | |||
*C = h->mv_cache[list][i - 8 + part_width]; | |||
return topright_ref; | |||
} else { | |||
tprintf(s->avctx, "topright MV not available\n"); | |||
tprintf(h->avctx, "topright MV not available\n"); | |||
*C = h->mv_cache[list][i - 8 - 1]; | |||
return h->ref_cache[list][i - 8 - 1]; | |||
@@ -115,7 +114,7 @@ static av_always_inline void pred_motion(H264Context *const h, int n, | |||
diagonal_ref = fetch_diagonal_mv(h, &C, index8, list, part_width); | |||
match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref); | |||
tprintf(h->s.avctx, "pred_motion match_count=%d\n", match_count); | |||
tprintf(h->avctx, "pred_motion match_count=%d\n", match_count); | |||
if (match_count > 1) { //most common | |||
*mx = mid_pred(A[0], B[0], C[0]); | |||
*my = mid_pred(A[1], B[1], C[1]); | |||
@@ -142,10 +141,10 @@ static av_always_inline void pred_motion(H264Context *const h, int n, | |||
} | |||
} | |||
tprintf(h->s.avctx, | |||
tprintf(h->avctx, | |||
"pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", | |||
top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, | |||
A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list); | |||
A[0], A[1], ref, *mx, *my, h->mb_x, h->mb_y, n, list); | |||
} | |||
/** | |||
@@ -162,8 +161,8 @@ static av_always_inline void pred_16x8_motion(H264Context *const h, | |||
const int top_ref = h->ref_cache[list][scan8[0] - 8]; | |||
const int16_t *const B = h->mv_cache[list][scan8[0] - 8]; | |||
tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", | |||
top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list); | |||
tprintf(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", | |||
top_ref, B[0], B[1], h->mb_x, h->mb_y, n, list); | |||
if (top_ref == ref) { | |||
*mx = B[0]; | |||
@@ -174,8 +173,8 @@ static av_always_inline void pred_16x8_motion(H264Context *const h, | |||
const int left_ref = h->ref_cache[list][scan8[8] - 1]; | |||
const int16_t *const A = h->mv_cache[list][scan8[8] - 1]; | |||
tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", | |||
left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); | |||
tprintf(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", | |||
left_ref, A[0], A[1], h->mb_x, h->mb_y, n, list); | |||
if (left_ref == ref) { | |||
*mx = A[0]; | |||
@@ -202,8 +201,8 @@ static av_always_inline void pred_8x16_motion(H264Context *const h, | |||
const int left_ref = h->ref_cache[list][scan8[0] - 1]; | |||
const int16_t *const A = h->mv_cache[list][scan8[0] - 1]; | |||
tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", | |||
left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); | |||
tprintf(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", | |||
left_ref, A[0], A[1], h->mb_x, h->mb_y, n, list); | |||
if (left_ref == ref) { | |||
*mx = A[0]; | |||
@@ -216,8 +215,8 @@ static av_always_inline void pred_8x16_motion(H264Context *const h, | |||
diagonal_ref = fetch_diagonal_mv(h, &C, scan8[4], list, 2); | |||
tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", | |||
diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list); | |||
tprintf(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", | |||
diagonal_ref, C[0], C[1], h->mb_x, h->mb_y, n, list); | |||
if (diagonal_ref == ref) { | |||
*mx = C[0]; | |||
@@ -253,9 +252,8 @@ static av_always_inline void pred_pskip_motion(H264Context *const h) | |||
{ | |||
DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = { 0 }; | |||
DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2]; | |||
MpegEncContext *const s = &h->s; | |||
int8_t *ref = s->current_picture.f.ref_index[0]; | |||
int16_t(*mv)[2] = s->current_picture.f.motion_val[0]; | |||
int8_t *ref = h->cur_pic.f.ref_index[0]; | |||
int16_t(*mv)[2] = h->cur_pic.f.motion_val[0]; | |||
int top_ref, left_ref, diagonal_ref, match_count, mx, my; | |||
const int16_t *A, *B, *C; | |||
int b_stride = h->b_stride; | |||
@@ -293,8 +291,8 @@ static av_always_inline void pred_pskip_motion(H264Context *const h) | |||
goto zeromv; | |||
} | |||
tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", | |||
top_ref, left_ref, h->s.mb_x, h->s.mb_y); | |||
tprintf(h->avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", | |||
top_ref, left_ref, h->mb_x, h->mb_y); | |||
if (USES_LIST(h->topright_type, 0)) { | |||
diagonal_ref = ref[4 * h->topright_mb_xy + 2]; | |||
@@ -320,7 +318,7 @@ static av_always_inline void pred_pskip_motion(H264Context *const h) | |||
} | |||
match_count = !diagonal_ref + !top_ref + !left_ref; | |||
tprintf(h->s.avctx, "pred_pskip_motion match_count=%d\n", match_count); | |||
tprintf(h->avctx, "pred_pskip_motion match_count=%d\n", match_count); | |||
if (match_count > 1) { | |||
mx = mid_pred(A[0], B[0], C[0]); | |||
my = mid_pred(A[1], B[1], C[1]); | |||
@@ -350,7 +348,6 @@ zeromv: | |||
static void fill_decode_neighbors(H264Context *h, int mb_type) | |||
{ | |||
MpegEncContext *const s = &h->s; | |||
const int mb_xy = h->mb_xy; | |||
int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; | |||
static const uint8_t left_block_options[4][32] = { | |||
@@ -362,7 +359,7 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) | |||
h->topleft_partition = -1; | |||
top_xy = mb_xy - (s->mb_stride << MB_FIELD); | |||
top_xy = mb_xy - (h->mb_stride << MB_FIELD); | |||
/* Wow, what a mess, why didn't they simplify the interlacing & intra | |||
* stuff, I can't imagine that these complex rules are worth it. */ | |||
@@ -372,16 +369,16 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) | |||
left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1; | |||
h->left_block = left_block_options[0]; | |||
if (FRAME_MBAFF) { | |||
const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]); | |||
const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.f.mb_type[mb_xy - 1]); | |||
const int curr_mb_field_flag = IS_INTERLACED(mb_type); | |||
if (s->mb_y & 1) { | |||
if (h->mb_y & 1) { | |||
if (left_mb_field_flag != curr_mb_field_flag) { | |||
left_xy[LBOT] = left_xy[LTOP] = mb_xy - s->mb_stride - 1; | |||
left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1; | |||
if (curr_mb_field_flag) { | |||
left_xy[LBOT] += s->mb_stride; | |||
left_xy[LBOT] += h->mb_stride; | |||
h->left_block = left_block_options[3]; | |||
} else { | |||
topleft_xy += s->mb_stride; | |||
topleft_xy += h->mb_stride; | |||
/* take top left mv from the middle of the mb, as opposed | |||
* to all other modes which use the bottom right partition */ | |||
h->topleft_partition = 0; | |||
@@ -390,13 +387,13 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) | |||
} | |||
} else { | |||
if (curr_mb_field_flag) { | |||
topleft_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy - 1] >> 7) & 1) - 1); | |||
topright_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy + 1] >> 7) & 1) - 1); | |||
top_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy] >> 7) & 1) - 1); | |||
topleft_xy += h->mb_stride & (((h->cur_pic.f.mb_type[top_xy - 1] >> 7) & 1) - 1); | |||
topright_xy += h->mb_stride & (((h->cur_pic.f.mb_type[top_xy + 1] >> 7) & 1) - 1); | |||
top_xy += h->mb_stride & (((h->cur_pic.f.mb_type[top_xy] >> 7) & 1) - 1); | |||
} | |||
if (left_mb_field_flag != curr_mb_field_flag) { | |||
if (curr_mb_field_flag) { | |||
left_xy[LBOT] += s->mb_stride; | |||
left_xy[LBOT] += h->mb_stride; | |||
h->left_block = left_block_options[3]; | |||
} else { | |||
h->left_block = left_block_options[2]; | |||
@@ -412,11 +409,11 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) | |||
h->left_mb_xy[LBOT] = left_xy[LBOT]; | |||
//FIXME do we need all in the context? | |||
h->topleft_type = s->current_picture.f.mb_type[topleft_xy]; | |||
h->top_type = s->current_picture.f.mb_type[top_xy]; | |||
h->topright_type = s->current_picture.f.mb_type[topright_xy]; | |||
h->left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]]; | |||
h->left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]]; | |||
h->topleft_type = h->cur_pic.f.mb_type[topleft_xy]; | |||
h->top_type = h->cur_pic.f.mb_type[top_xy]; | |||
h->topright_type = h->cur_pic.f.mb_type[topright_xy]; | |||
h->left_type[LTOP] = h->cur_pic.f.mb_type[left_xy[LTOP]]; | |||
h->left_type[LBOT] = h->cur_pic.f.mb_type[left_xy[LBOT]]; | |||
if (FMO) { | |||
if (h->slice_table[topleft_xy] != h->slice_num) | |||
@@ -440,7 +437,6 @@ static void fill_decode_neighbors(H264Context *h, int mb_type) | |||
static void fill_decode_caches(H264Context *h, int mb_type) | |||
{ | |||
MpegEncContext *const s = &h->s; | |||
int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; | |||
int topleft_type, top_type, topright_type, left_type[LEFT_MBS]; | |||
const uint8_t *left_block = h->left_block; | |||
@@ -483,7 +479,7 @@ static void fill_decode_caches(H264Context *h, int mb_type) | |||
h->left_samples_available &= 0xFF5F; | |||
} | |||
} else { | |||
int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride]; | |||
int left_typei = h->cur_pic.f.mb_type[left_xy[LTOP] + h->mb_stride]; | |||
av_assert2(left_xy[LTOP] == left_xy[LBOT]); | |||
if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) { | |||
@@ -540,7 +536,7 @@ static void fill_decode_caches(H264Context *h, int mb_type) | |||
if (top_type) { | |||
nnz = h->non_zero_count[top_xy]; | |||
AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]); | |||
if (!s->chroma_y_shift) { | |||
if (!h->chroma_y_shift) { | |||
AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]); | |||
AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]); | |||
} else { | |||
@@ -605,9 +601,9 @@ static void fill_decode_caches(H264Context *h, int mb_type) | |||
int b_stride = h->b_stride; | |||
for (list = 0; list < h->list_count; list++) { | |||
int8_t *ref_cache = &h->ref_cache[list][scan8[0]]; | |||
int8_t *ref = s->current_picture.f.ref_index[list]; | |||
int8_t *ref = h->cur_pic.f.ref_index[list]; | |||
int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]]; | |||
int16_t(*mv)[2] = s->current_picture.f.motion_val[list]; | |||
int16_t(*mv)[2] = h->cur_pic.f.motion_val[list]; | |||
if (!USES_LIST(mb_type, list)) | |||
continue; | |||
av_assert2(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); | |||
@@ -799,7 +795,6 @@ static void fill_decode_caches(H264Context *h, int mb_type) | |||
*/ | |||
static void av_unused decode_mb_skip(H264Context *h) | |||
{ | |||
MpegEncContext *const s = &h->s; | |||
const int mb_xy = h->mb_xy; | |||
int mb_type = 0; | |||
@@ -825,10 +820,10 @@ static void av_unused decode_mb_skip(H264Context *h) | |||
} | |||
write_back_motion(h, mb_type); | |||
s->current_picture.f.mb_type[mb_xy] = mb_type; | |||
s->current_picture.f.qscale_table[mb_xy] = s->qscale; | |||
h->slice_table[mb_xy] = h->slice_num; | |||
h->prev_mb_skipped = 1; | |||
h->cur_pic.f.mb_type[mb_xy] = mb_type; | |||
h->cur_pic.f.qscale_table[mb_xy] = h->qscale; | |||
h->slice_table[mb_xy] = h->slice_num; | |||
h->prev_mb_skipped = 1; | |||
} | |||
#endif /* AVCODEC_H264_MVPRED_H */ |
@@ -36,7 +36,7 @@ static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_si | |||
{ | |||
int i, j; | |||
uint32_t state; | |||
ParseContext *pc = &(h->s.parse_context); | |||
ParseContext *pc = &h->parse_context; | |||
int next_avc= h->is_avc ? 0 : buf_size; | |||
// mb_addr= pc->mb_addr - 1; | |||
@@ -45,7 +45,7 @@ static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_si | |||
state= 7; | |||
if(h->is_avc && !h->nal_length_size) | |||
av_log(h->s.avctx, AV_LOG_ERROR, "AVC-parser: nal length size invalid\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "AVC-parser: nal length size invalid\n"); | |||
for(i=0; i<buf_size; i++){ | |||
if(i >= next_avc) { | |||
@@ -54,7 +54,7 @@ static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_si | |||
for(j = 0; j < h->nal_length_size; j++) | |||
nalsize = (nalsize << 8) | buf[i++]; | |||
if(nalsize <= 0 || nalsize > buf_size - i){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "AVC-parser: nal size %d remaining %d\n", nalsize, buf_size - i); | |||
av_log(h->avctx, AV_LOG_ERROR, "AVC-parser: nal size %d remaining %d\n", nalsize, buf_size - i); | |||
return buf_size; | |||
} | |||
next_avc= i + nalsize; | |||
@@ -153,7 +153,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, | |||
s->pict_type = AV_PICTURE_TYPE_I; | |||
s->key_frame = 0; | |||
h->s.avctx= avctx; | |||
h->avctx= avctx; | |||
h->sei_recovery_frame_cnt = -1; | |||
h->sei_dpb_output_delay = 0; | |||
h->sei_cpb_removal_delay = -1; | |||
@@ -171,7 +171,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, | |||
for (i = 0; i < h->nal_length_size; i++) | |||
nalsize = (nalsize << 8) | *buf++; | |||
if (nalsize <= 0 || nalsize > buf_end - buf) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize); | |||
av_log(h->avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize); | |||
break; | |||
} | |||
src_length = nalsize; | |||
@@ -194,13 +194,13 @@ static inline int parse_nal_units(AVCodecParserContext *s, | |||
if (ptr==NULL || dst_length < 0) | |||
break; | |||
init_get_bits(&h->s.gb, ptr, 8*dst_length); | |||
init_get_bits(&h->gb, ptr, 8*dst_length); | |||
switch(h->nal_unit_type) { | |||
case NAL_SPS: | |||
ff_h264_decode_seq_parameter_set(h); | |||
break; | |||
case NAL_PPS: | |||
ff_h264_decode_picture_parameter_set(h, h->s.gb.size_in_bits); | |||
ff_h264_decode_picture_parameter_set(h, h->gb.size_in_bits); | |||
break; | |||
case NAL_SEI: | |||
ff_h264_decode_sei(h); | |||
@@ -209,40 +209,40 @@ static inline int parse_nal_units(AVCodecParserContext *s, | |||
s->key_frame = 1; | |||
/* fall through */ | |||
case NAL_SLICE: | |||
get_ue_golomb_long(&h->s.gb); // skip first_mb_in_slice | |||
slice_type = get_ue_golomb_31(&h->s.gb); | |||
get_ue_golomb_long(&h->gb); // skip first_mb_in_slice | |||
slice_type = get_ue_golomb_31(&h->gb); | |||
s->pict_type = golomb_to_pict_type[slice_type % 5]; | |||
if (h->sei_recovery_frame_cnt >= 0) { | |||
/* key frame, since recovery_frame_cnt is set */ | |||
s->key_frame = 1; | |||
} | |||
pps_id= get_ue_golomb(&h->s.gb); | |||
pps_id= get_ue_golomb(&h->gb); | |||
if(pps_id>=MAX_PPS_COUNT) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "pps_id out of range\n"); | |||
return -1; | |||
} | |||
if(!h->pps_buffers[pps_id]) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS referenced\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "non-existing PPS referenced\n"); | |||
return -1; | |||
} | |||
h->pps= *h->pps_buffers[pps_id]; | |||
if(!h->sps_buffers[h->pps.sps_id]) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS referenced\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "non-existing SPS referenced\n"); | |||
return -1; | |||
} | |||
h->sps = *h->sps_buffers[h->pps.sps_id]; | |||
h->frame_num = get_bits(&h->s.gb, h->sps.log2_max_frame_num); | |||
h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num); | |||
avctx->profile = ff_h264_get_profile(&h->sps); | |||
avctx->level = h->sps.level_idc; | |||
if(h->sps.frame_mbs_only_flag){ | |||
h->s.picture_structure= PICT_FRAME; | |||
h->picture_structure= PICT_FRAME; | |||
}else{ | |||
if(get_bits1(&h->s.gb)) { //field_pic_flag | |||
h->s.picture_structure= PICT_TOP_FIELD + get_bits1(&h->s.gb); //bottom_field_flag | |||
if(get_bits1(&h->gb)) { //field_pic_flag | |||
h->picture_structure= PICT_TOP_FIELD + get_bits1(&h->gb); //bottom_field_flag | |||
} else { | |||
h->s.picture_structure= PICT_FRAME; | |||
h->picture_structure= PICT_FRAME; | |||
} | |||
} | |||
@@ -268,11 +268,11 @@ static inline int parse_nal_units(AVCodecParserContext *s, | |||
s->repeat_pict = 5; | |||
break; | |||
default: | |||
s->repeat_pict = h->s.picture_structure == PICT_FRAME ? 1 : 0; | |||
s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0; | |||
break; | |||
} | |||
} else { | |||
s->repeat_pict = h->s.picture_structure == PICT_FRAME ? 1 : 0; | |||
s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0; | |||
} | |||
return 0; /* no need to evaluate the rest */ | |||
@@ -282,7 +282,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, | |||
if (q264) | |||
return 0; | |||
/* didn't find a picture! */ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size); | |||
av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size); | |||
return -1; | |||
} | |||
@@ -292,19 +292,19 @@ static int h264_parse(AVCodecParserContext *s, | |||
const uint8_t *buf, int buf_size) | |||
{ | |||
H264Context *h = s->priv_data; | |||
ParseContext *pc = &h->s.parse_context; | |||
ParseContext *pc = &h->parse_context; | |||
int next; | |||
if (!h->got_first) { | |||
h->got_first = 1; | |||
if (avctx->extradata_size) { | |||
h->s.avctx = avctx; | |||
h->avctx = avctx; | |||
// must be done like in decoder, otherwise opening the parser, | |||
// letting it create extradata and then closing and opening again | |||
// will cause has_b_frames to be always set. | |||
// Note that estimate_timings_from_pts does exactly this. | |||
if (!avctx->has_b_frames) | |||
h->s.low_delay = 1; | |||
h->low_delay = 1; | |||
ff_h264_decode_extradata(h, avctx->extradata, avctx->extradata_size); | |||
} | |||
} | |||
@@ -374,7 +374,7 @@ static int h264_split(AVCodecContext *avctx, | |||
static void close(AVCodecParserContext *s) | |||
{ | |||
H264Context *h = s->priv_data; | |||
ParseContext *pc = &h->s.parse_context; | |||
ParseContext *pc = &h->parse_context; | |||
av_free(pc->buffer); | |||
ff_h264_free_context(h); | |||
@@ -384,7 +384,7 @@ static int init(AVCodecParserContext *s) | |||
{ | |||
H264Context *h = s->priv_data; | |||
h->thread_context[0] = h; | |||
h->s.slice_context_count = 1; | |||
h->slice_context_count = 1; | |||
return 0; | |||
} | |||
@@ -151,46 +151,44 @@ static const uint8_t default_scaling8[2][64]={ | |||
}}; | |||
static inline int decode_hrd_parameters(H264Context *h, SPS *sps){ | |||
MpegEncContext * const s = &h->s; | |||
int cpb_count, i; | |||
cpb_count = get_ue_golomb_31(&s->gb) + 1; | |||
cpb_count = get_ue_golomb_31(&h->gb) + 1; | |||
if(cpb_count > 32U){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count); | |||
av_log(h->avctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count); | |||
return -1; | |||
} | |||
get_bits(&s->gb, 4); /* bit_rate_scale */ | |||
get_bits(&s->gb, 4); /* cpb_size_scale */ | |||
get_bits(&h->gb, 4); /* bit_rate_scale */ | |||
get_bits(&h->gb, 4); /* cpb_size_scale */ | |||
for(i=0; i<cpb_count; i++){ | |||
get_ue_golomb_long(&s->gb); /* bit_rate_value_minus1 */ | |||
get_ue_golomb_long(&s->gb); /* cpb_size_value_minus1 */ | |||
get_bits1(&s->gb); /* cbr_flag */ | |||
get_ue_golomb_long(&h->gb); /* bit_rate_value_minus1 */ | |||
get_ue_golomb_long(&h->gb); /* cpb_size_value_minus1 */ | |||
get_bits1(&h->gb); /* cbr_flag */ | |||
} | |||
sps->initial_cpb_removal_delay_length = get_bits(&s->gb, 5) + 1; | |||
sps->cpb_removal_delay_length = get_bits(&s->gb, 5) + 1; | |||
sps->dpb_output_delay_length = get_bits(&s->gb, 5) + 1; | |||
sps->time_offset_length = get_bits(&s->gb, 5); | |||
sps->initial_cpb_removal_delay_length = get_bits(&h->gb, 5) + 1; | |||
sps->cpb_removal_delay_length = get_bits(&h->gb, 5) + 1; | |||
sps->dpb_output_delay_length = get_bits(&h->gb, 5) + 1; | |||
sps->time_offset_length = get_bits(&h->gb, 5); | |||
sps->cpb_cnt = cpb_count; | |||
return 0; | |||
} | |||
static inline int decode_vui_parameters(H264Context *h, SPS *sps){ | |||
MpegEncContext * const s = &h->s; | |||
int aspect_ratio_info_present_flag; | |||
unsigned int aspect_ratio_idc; | |||
aspect_ratio_info_present_flag= get_bits1(&s->gb); | |||
aspect_ratio_info_present_flag= get_bits1(&h->gb); | |||
if( aspect_ratio_info_present_flag ) { | |||
aspect_ratio_idc= get_bits(&s->gb, 8); | |||
aspect_ratio_idc= get_bits(&h->gb, 8); | |||
if( aspect_ratio_idc == EXTENDED_SAR ) { | |||
sps->sar.num= get_bits(&s->gb, 16); | |||
sps->sar.den= get_bits(&s->gb, 16); | |||
sps->sar.num= get_bits(&h->gb, 16); | |||
sps->sar.den= get_bits(&h->gb, 16); | |||
}else if(aspect_ratio_idc < FF_ARRAY_ELEMS(pixel_aspect)){ | |||
sps->sar= pixel_aspect[aspect_ratio_idc]; | |||
}else{ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "illegal aspect ratio\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "illegal aspect ratio\n"); | |||
return -1; | |||
} | |||
}else{ | |||
@@ -199,20 +197,20 @@ static inline int decode_vui_parameters(H264Context *h, SPS *sps){ | |||
} | |||
// s->avctx->aspect_ratio= sar_width*s->width / (float)(s->height*sar_height); | |||
if(get_bits1(&s->gb)){ /* overscan_info_present_flag */ | |||
get_bits1(&s->gb); /* overscan_appropriate_flag */ | |||
if(get_bits1(&h->gb)){ /* overscan_info_present_flag */ | |||
get_bits1(&h->gb); /* overscan_appropriate_flag */ | |||
} | |||
sps->video_signal_type_present_flag = get_bits1(&s->gb); | |||
sps->video_signal_type_present_flag = get_bits1(&h->gb); | |||
if(sps->video_signal_type_present_flag){ | |||
get_bits(&s->gb, 3); /* video_format */ | |||
sps->full_range = get_bits1(&s->gb); /* video_full_range_flag */ | |||
get_bits(&h->gb, 3); /* video_format */ | |||
sps->full_range = get_bits1(&h->gb); /* video_full_range_flag */ | |||
sps->colour_description_present_flag = get_bits1(&s->gb); | |||
sps->colour_description_present_flag = get_bits1(&h->gb); | |||
if(sps->colour_description_present_flag){ | |||
sps->color_primaries = get_bits(&s->gb, 8); /* colour_primaries */ | |||
sps->color_trc = get_bits(&s->gb, 8); /* transfer_characteristics */ | |||
sps->colorspace = get_bits(&s->gb, 8); /* matrix_coefficients */ | |||
sps->color_primaries = get_bits(&h->gb, 8); /* colour_primaries */ | |||
sps->color_trc = get_bits(&h->gb, 8); /* transfer_characteristics */ | |||
sps->colorspace = get_bits(&h->gb, 8); /* matrix_coefficients */ | |||
if (sps->color_primaries >= AVCOL_PRI_NB) | |||
sps->color_primaries = AVCOL_PRI_UNSPECIFIED; | |||
if (sps->color_trc >= AVCOL_TRC_NB) | |||
@@ -222,58 +220,58 @@ static inline int decode_vui_parameters(H264Context *h, SPS *sps){ | |||
} | |||
} | |||
if(get_bits1(&s->gb)){ /* chroma_location_info_present_flag */ | |||
s->avctx->chroma_sample_location = get_ue_golomb(&s->gb)+1; /* chroma_sample_location_type_top_field */ | |||
get_ue_golomb(&s->gb); /* chroma_sample_location_type_bottom_field */ | |||
if(get_bits1(&h->gb)){ /* chroma_location_info_present_flag */ | |||
h->avctx->chroma_sample_location = get_ue_golomb(&h->gb)+1; /* chroma_sample_location_type_top_field */ | |||
get_ue_golomb(&h->gb); /* chroma_sample_location_type_bottom_field */ | |||
} | |||
sps->timing_info_present_flag = get_bits1(&s->gb); | |||
sps->timing_info_present_flag = get_bits1(&h->gb); | |||
if(sps->timing_info_present_flag){ | |||
sps->num_units_in_tick = get_bits_long(&s->gb, 32); | |||
sps->time_scale = get_bits_long(&s->gb, 32); | |||
sps->num_units_in_tick = get_bits_long(&h->gb, 32); | |||
sps->time_scale = get_bits_long(&h->gb, 32); | |||
if(!sps->num_units_in_tick || !sps->time_scale){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "time_scale/num_units_in_tick invalid or unsupported (%d/%d)\n", sps->time_scale, sps->num_units_in_tick); | |||
av_log(h->avctx, AV_LOG_ERROR, "time_scale/num_units_in_tick invalid or unsupported (%d/%d)\n", sps->time_scale, sps->num_units_in_tick); | |||
return -1; | |||
} | |||
sps->fixed_frame_rate_flag = get_bits1(&s->gb); | |||
sps->fixed_frame_rate_flag = get_bits1(&h->gb); | |||
} | |||
sps->nal_hrd_parameters_present_flag = get_bits1(&s->gb); | |||
sps->nal_hrd_parameters_present_flag = get_bits1(&h->gb); | |||
if(sps->nal_hrd_parameters_present_flag) | |||
if(decode_hrd_parameters(h, sps) < 0) | |||
return -1; | |||
sps->vcl_hrd_parameters_present_flag = get_bits1(&s->gb); | |||
sps->vcl_hrd_parameters_present_flag = get_bits1(&h->gb); | |||
if(sps->vcl_hrd_parameters_present_flag) | |||
if(decode_hrd_parameters(h, sps) < 0) | |||
return -1; | |||
if(sps->nal_hrd_parameters_present_flag || sps->vcl_hrd_parameters_present_flag) | |||
get_bits1(&s->gb); /* low_delay_hrd_flag */ | |||
sps->pic_struct_present_flag = get_bits1(&s->gb); | |||
if(!get_bits_left(&s->gb)) | |||
get_bits1(&h->gb); /* low_delay_hrd_flag */ | |||
sps->pic_struct_present_flag = get_bits1(&h->gb); | |||
if(!get_bits_left(&h->gb)) | |||
return 0; | |||
sps->bitstream_restriction_flag = get_bits1(&s->gb); | |||
sps->bitstream_restriction_flag = get_bits1(&h->gb); | |||
if(sps->bitstream_restriction_flag){ | |||
get_bits1(&s->gb); /* motion_vectors_over_pic_boundaries_flag */ | |||
get_ue_golomb(&s->gb); /* max_bytes_per_pic_denom */ | |||
get_ue_golomb(&s->gb); /* max_bits_per_mb_denom */ | |||
get_ue_golomb(&s->gb); /* log2_max_mv_length_horizontal */ | |||
get_ue_golomb(&s->gb); /* log2_max_mv_length_vertical */ | |||
sps->num_reorder_frames= get_ue_golomb(&s->gb); | |||
get_ue_golomb(&s->gb); /*max_dec_frame_buffering*/ | |||
if (get_bits_left(&s->gb) < 0) { | |||
get_bits1(&h->gb); /* motion_vectors_over_pic_boundaries_flag */ | |||
get_ue_golomb(&h->gb); /* max_bytes_per_pic_denom */ | |||
get_ue_golomb(&h->gb); /* max_bits_per_mb_denom */ | |||
get_ue_golomb(&h->gb); /* log2_max_mv_length_horizontal */ | |||
get_ue_golomb(&h->gb); /* log2_max_mv_length_vertical */ | |||
sps->num_reorder_frames= get_ue_golomb(&h->gb); | |||
get_ue_golomb(&h->gb); /*max_dec_frame_buffering*/ | |||
if (get_bits_left(&h->gb) < 0) { | |||
sps->num_reorder_frames=0; | |||
sps->bitstream_restriction_flag= 0; | |||
} | |||
if(sps->num_reorder_frames > 16U /*max_dec_frame_buffering || max_dec_frame_buffering > 16*/){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "illegal num_reorder_frames %d\n", sps->num_reorder_frames); | |||
av_log(h->avctx, AV_LOG_ERROR, "illegal num_reorder_frames %d\n", sps->num_reorder_frames); | |||
return -1; | |||
} | |||
} | |||
if (get_bits_left(&s->gb) < 0) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "Overread VUI by %d bits\n", -get_bits_left(&s->gb)); | |||
if (get_bits_left(&h->gb) < 0) { | |||
av_log(h->avctx, AV_LOG_ERROR, "Overread VUI by %d bits\n", -get_bits_left(&h->gb)); | |||
return AVERROR_INVALIDDATA; | |||
} | |||
@@ -282,15 +280,14 @@ static inline int decode_vui_parameters(H264Context *h, SPS *sps){ | |||
static void decode_scaling_list(H264Context *h, uint8_t *factors, int size, | |||
const uint8_t *jvt_list, const uint8_t *fallback_list){ | |||
MpegEncContext * const s = &h->s; | |||
int i, last = 8, next = 8; | |||
const uint8_t *scan = size == 16 ? zigzag_scan : ff_zigzag_direct; | |||
if(!get_bits1(&s->gb)) /* matrix not written, we use the predicted one */ | |||
if(!get_bits1(&h->gb)) /* matrix not written, we use the predicted one */ | |||
memcpy(factors, fallback_list, size*sizeof(uint8_t)); | |||
else | |||
for(i=0;i<size;i++){ | |||
if(next) | |||
next = (last + get_se_golomb(&s->gb)) & 0xff; | |||
next = (last + get_se_golomb(&h->gb)) & 0xff; | |||
if(!i && !next){ /* matrix not written, we use the preset one */ | |||
memcpy(factors, jvt_list, size*sizeof(uint8_t)); | |||
break; | |||
@@ -301,7 +298,6 @@ static void decode_scaling_list(H264Context *h, uint8_t *factors, int size, | |||
static void decode_scaling_matrices(H264Context *h, SPS *sps, PPS *pps, int is_sps, | |||
uint8_t (*scaling_matrix4)[16], uint8_t (*scaling_matrix8)[64]){ | |||
MpegEncContext * const s = &h->s; | |||
int fallback_sps = !is_sps && sps->scaling_matrix_present; | |||
const uint8_t *fallback[4] = { | |||
fallback_sps ? sps->scaling_matrix4[0] : default_scaling4[0], | |||
@@ -309,7 +305,7 @@ static void decode_scaling_matrices(H264Context *h, SPS *sps, PPS *pps, int is_s | |||
fallback_sps ? sps->scaling_matrix8[0] : default_scaling8[0], | |||
fallback_sps ? sps->scaling_matrix8[3] : default_scaling8[1] | |||
}; | |||
if(get_bits1(&s->gb)){ | |||
if(get_bits1(&h->gb)){ | |||
sps->scaling_matrix_present |= is_sps; | |||
decode_scaling_list(h,scaling_matrix4[0],16,default_scaling4[0],fallback[0]); // Intra, Y | |||
decode_scaling_list(h,scaling_matrix4[1],16,default_scaling4[0],scaling_matrix4[0]); // Intra, Cr | |||
@@ -331,25 +327,24 @@ static void decode_scaling_matrices(H264Context *h, SPS *sps, PPS *pps, int is_s | |||
} | |||
int ff_h264_decode_seq_parameter_set(H264Context *h){ | |||
MpegEncContext * const s = &h->s; | |||
int profile_idc, level_idc, constraint_set_flags = 0; | |||
unsigned int sps_id; | |||
int i, log2_max_frame_num_minus4; | |||
SPS *sps; | |||
profile_idc= get_bits(&s->gb, 8); | |||
constraint_set_flags |= get_bits1(&s->gb) << 0; //constraint_set0_flag | |||
constraint_set_flags |= get_bits1(&s->gb) << 1; //constraint_set1_flag | |||
constraint_set_flags |= get_bits1(&s->gb) << 2; //constraint_set2_flag | |||
constraint_set_flags |= get_bits1(&s->gb) << 3; //constraint_set3_flag | |||
constraint_set_flags |= get_bits1(&s->gb) << 4; //constraint_set4_flag | |||
constraint_set_flags |= get_bits1(&s->gb) << 5; //constraint_set5_flag | |||
get_bits(&s->gb, 2); // reserved | |||
level_idc= get_bits(&s->gb, 8); | |||
sps_id= get_ue_golomb_31(&s->gb); | |||
profile_idc= get_bits(&h->gb, 8); | |||
constraint_set_flags |= get_bits1(&h->gb) << 0; //constraint_set0_flag | |||
constraint_set_flags |= get_bits1(&h->gb) << 1; //constraint_set1_flag | |||
constraint_set_flags |= get_bits1(&h->gb) << 2; //constraint_set2_flag | |||
constraint_set_flags |= get_bits1(&h->gb) << 3; //constraint_set3_flag | |||
constraint_set_flags |= get_bits1(&h->gb) << 4; //constraint_set4_flag | |||
constraint_set_flags |= get_bits1(&h->gb) << 5; //constraint_set5_flag | |||
get_bits(&h->gb, 2); // reserved | |||
level_idc= get_bits(&h->gb, 8); | |||
sps_id= get_ue_golomb_31(&h->gb); | |||
if(sps_id >= MAX_SPS_COUNT) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "sps_id (%d) out of range\n", sps_id); | |||
av_log(h->avctx, AV_LOG_ERROR, "sps_id (%d) out of range\n", sps_id); | |||
return -1; | |||
} | |||
sps= av_mallocz(sizeof(SPS)); | |||
@@ -372,25 +367,25 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){ | |||
sps->profile_idc == 44 || sps->profile_idc == 83 || | |||
sps->profile_idc == 86 || sps->profile_idc == 118 || | |||
sps->profile_idc == 128 || sps->profile_idc == 144) { | |||
sps->chroma_format_idc= get_ue_golomb_31(&s->gb); | |||
sps->chroma_format_idc= get_ue_golomb_31(&h->gb); | |||
if (sps->chroma_format_idc > 3U) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "chroma_format_idc %d is illegal\n", sps->chroma_format_idc); | |||
av_log(h->avctx, AV_LOG_ERROR, "chroma_format_idc %d is illegal\n", sps->chroma_format_idc); | |||
goto fail; | |||
} else if(sps->chroma_format_idc == 3) { | |||
sps->residual_color_transform_flag = get_bits1(&s->gb); | |||
sps->residual_color_transform_flag = get_bits1(&h->gb); | |||
if(sps->residual_color_transform_flag) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "separate color planes are not supported\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "separate color planes are not supported\n"); | |||
goto fail; | |||
} | |||
} | |||
sps->bit_depth_luma = get_ue_golomb(&s->gb) + 8; | |||
sps->bit_depth_chroma = get_ue_golomb(&s->gb) + 8; | |||
sps->bit_depth_luma = get_ue_golomb(&h->gb) + 8; | |||
sps->bit_depth_chroma = get_ue_golomb(&h->gb) + 8; | |||
if (sps->bit_depth_luma > 14U || sps->bit_depth_chroma > 14U) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "illegal bit depth value (%d, %d)\n", | |||
av_log(h->avctx, AV_LOG_ERROR, "illegal bit depth value (%d, %d)\n", | |||
sps->bit_depth_luma, sps->bit_depth_chroma); | |||
goto fail; | |||
} | |||
sps->transform_bypass = get_bits1(&s->gb); | |||
sps->transform_bypass = get_bits1(&h->gb); | |||
decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8); | |||
}else{ | |||
sps->chroma_format_idc= 1; | |||
@@ -398,81 +393,81 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){ | |||
sps->bit_depth_chroma = 8; | |||
} | |||
log2_max_frame_num_minus4 = get_ue_golomb(&s->gb); | |||
log2_max_frame_num_minus4 = get_ue_golomb(&h->gb); | |||
if (log2_max_frame_num_minus4 < MIN_LOG2_MAX_FRAME_NUM - 4 || | |||
log2_max_frame_num_minus4 > MAX_LOG2_MAX_FRAME_NUM - 4) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, | |||
av_log(h->avctx, AV_LOG_ERROR, | |||
"log2_max_frame_num_minus4 out of range (0-12): %d\n", | |||
log2_max_frame_num_minus4); | |||
goto fail; | |||
} | |||
sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4; | |||
sps->poc_type= get_ue_golomb_31(&s->gb); | |||
sps->poc_type= get_ue_golomb_31(&h->gb); | |||
if(sps->poc_type == 0){ //FIXME #define | |||
unsigned t = get_ue_golomb(&s->gb); | |||
unsigned t = get_ue_golomb(&h->gb); | |||
if(t>12){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "log2_max_poc_lsb (%d) is out of range\n", t); | |||
av_log(h->avctx, AV_LOG_ERROR, "log2_max_poc_lsb (%d) is out of range\n", t); | |||
goto fail; | |||
} | |||
sps->log2_max_poc_lsb= t + 4; | |||
} else if(sps->poc_type == 1){//FIXME #define | |||
sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb); | |||
sps->offset_for_non_ref_pic= get_se_golomb(&s->gb); | |||
sps->offset_for_top_to_bottom_field= get_se_golomb(&s->gb); | |||
sps->poc_cycle_length = get_ue_golomb(&s->gb); | |||
sps->delta_pic_order_always_zero_flag= get_bits1(&h->gb); | |||
sps->offset_for_non_ref_pic= get_se_golomb(&h->gb); | |||
sps->offset_for_top_to_bottom_field= get_se_golomb(&h->gb); | |||
sps->poc_cycle_length = get_ue_golomb(&h->gb); | |||
if((unsigned)sps->poc_cycle_length >= FF_ARRAY_ELEMS(sps->offset_for_ref_frame)){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\n", sps->poc_cycle_length); | |||
av_log(h->avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\n", sps->poc_cycle_length); | |||
goto fail; | |||
} | |||
for(i=0; i<sps->poc_cycle_length; i++) | |||
sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb); | |||
sps->offset_for_ref_frame[i]= get_se_golomb(&h->gb); | |||
}else if(sps->poc_type != 2){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); | |||
av_log(h->avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); | |||
goto fail; | |||
} | |||
sps->ref_frame_count= get_ue_golomb_31(&s->gb); | |||
if (h->s.avctx->codec_tag == MKTAG('S', 'M', 'V', '2')) | |||
sps->ref_frame_count= get_ue_golomb_31(&h->gb); | |||
if (h->avctx->codec_tag == MKTAG('S', 'M', 'V', '2')) | |||
sps->ref_frame_count= FFMAX(2, sps->ref_frame_count); | |||
if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count > 16U){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "too many reference frames\n"); | |||
goto fail; | |||
} | |||
sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb); | |||
sps->mb_width = get_ue_golomb(&s->gb) + 1; | |||
sps->mb_height= get_ue_golomb(&s->gb) + 1; | |||
sps->gaps_in_frame_num_allowed_flag= get_bits1(&h->gb); | |||
sps->mb_width = get_ue_golomb(&h->gb) + 1; | |||
sps->mb_height= get_ue_golomb(&h->gb) + 1; | |||
if((unsigned)sps->mb_width >= INT_MAX/16 || (unsigned)sps->mb_height >= INT_MAX/16 || | |||
av_image_check_size(16*sps->mb_width, 16*sps->mb_height, 0, h->s.avctx)){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "mb_width/height overflow\n"); | |||
av_image_check_size(16*sps->mb_width, 16*sps->mb_height, 0, h->avctx)){ | |||
av_log(h->avctx, AV_LOG_ERROR, "mb_width/height overflow\n"); | |||
goto fail; | |||
} | |||
sps->frame_mbs_only_flag= get_bits1(&s->gb); | |||
sps->frame_mbs_only_flag= get_bits1(&h->gb); | |||
if(!sps->frame_mbs_only_flag) | |||
sps->mb_aff= get_bits1(&s->gb); | |||
sps->mb_aff= get_bits1(&h->gb); | |||
else | |||
sps->mb_aff= 0; | |||
sps->direct_8x8_inference_flag= get_bits1(&s->gb); | |||
sps->direct_8x8_inference_flag= get_bits1(&h->gb); | |||
#ifndef ALLOW_INTERLACE | |||
if(sps->mb_aff) | |||
av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF support not included; enable it at compile-time.\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "MBAFF support not included; enable it at compile-time.\n"); | |||
#endif | |||
sps->crop= get_bits1(&s->gb); | |||
sps->crop= get_bits1(&h->gb); | |||
if(sps->crop){ | |||
int crop_vertical_limit = sps->chroma_format_idc & 2 ? 16 : 8; | |||
int crop_horizontal_limit = sps->chroma_format_idc == 3 ? 16 : 8; | |||
sps->crop_left = get_ue_golomb(&s->gb); | |||
sps->crop_right = get_ue_golomb(&s->gb); | |||
sps->crop_top = get_ue_golomb(&s->gb); | |||
sps->crop_bottom= get_ue_golomb(&s->gb); | |||
if (h->s.avctx->flags2 & CODEC_FLAG2_IGNORE_CROP) { | |||
av_log(h->s.avctx, AV_LOG_DEBUG, | |||
sps->crop_left = get_ue_golomb(&h->gb); | |||
sps->crop_right = get_ue_golomb(&h->gb); | |||
sps->crop_top = get_ue_golomb(&h->gb); | |||
sps->crop_bottom= get_ue_golomb(&h->gb); | |||
if (h->avctx->flags2 & CODEC_FLAG2_IGNORE_CROP) { | |||
av_log(h->avctx, AV_LOG_DEBUG, | |||
"discarding sps cropping, " | |||
"original values are l:%u r:%u t:%u b:%u\n", | |||
sps->crop_left, | |||
@@ -486,10 +481,10 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){ | |||
sps->crop_bottom = 0; | |||
} | |||
if(sps->crop_left || sps->crop_top){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ... (left: %d, top: %d)\n", sps->crop_left, sps->crop_top); | |||
av_log(h->avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ... (left: %d, top: %d)\n", sps->crop_left, sps->crop_top); | |||
} | |||
if(sps->crop_right >= crop_horizontal_limit || sps->crop_bottom >= crop_vertical_limit){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not supported, cropping disabled (right: %d, bottom: %d)\n", sps->crop_right, sps->crop_bottom); | |||
av_log(h->avctx, AV_LOG_ERROR, "brainfart cropping not supported, cropping disabled (right: %d, bottom: %d)\n", sps->crop_right, sps->crop_bottom); | |||
/* It is very unlikely that partial cropping will make anybody happy. | |||
* Not cropping at all fixes for example playback of Sisvel 3D streams | |||
* in applications supporting Sisvel 3D. */ | |||
@@ -505,7 +500,7 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){ | |||
sps->crop_bottom= 0; | |||
} | |||
sps->vui_parameters_present_flag= get_bits1(&s->gb); | |||
sps->vui_parameters_present_flag= get_bits1(&h->gb); | |||
if( sps->vui_parameters_present_flag ) | |||
if (decode_vui_parameters(h, sps) < 0) | |||
goto fail; | |||
@@ -513,9 +508,9 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){ | |||
if(!sps->sar.den) | |||
sps->sar.den= 1; | |||
if(s->avctx->debug&FF_DEBUG_PICT_INFO){ | |||
if(h->avctx->debug&FF_DEBUG_PICT_INFO){ | |||
static const char csp[4][5] = { "Gray", "420", "422", "444" }; | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d b%d reo:%d\n", | |||
av_log(h->avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d b%d reo:%d\n", | |||
sps_id, sps->profile_idc, sps->level_idc, | |||
sps->poc_type, | |||
sps->ref_frame_count, | |||
@@ -561,7 +556,7 @@ static int more_rbsp_data_in_pps(H264Context *h, PPS *pps) | |||
if ((profile_idc == 66 || profile_idc == 77 || | |||
profile_idc == 88) && (sps->constraint_set_flags & 7)) { | |||
av_log(h->s.avctx, AV_LOG_VERBOSE, | |||
av_log(h->avctx, AV_LOG_VERBOSE, | |||
"Current profile doesn't provide more RBSP data in PPS, skipping\n"); | |||
return 0; | |||
} | |||
@@ -570,38 +565,37 @@ static int more_rbsp_data_in_pps(H264Context *h, PPS *pps) | |||
} | |||
int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){ | |||
MpegEncContext * const s = &h->s; | |||
unsigned int pps_id= get_ue_golomb(&s->gb); | |||
unsigned int pps_id= get_ue_golomb(&h->gb); | |||
PPS *pps; | |||
const int qp_bd_offset = 6*(h->sps.bit_depth_luma-8); | |||
int bits_left; | |||
if(pps_id >= MAX_PPS_COUNT) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id); | |||
av_log(h->avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id); | |||
return -1; | |||
} else if (h->sps.bit_depth_luma > 14) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "Invalid luma bit depth=%d\n", h->sps.bit_depth_luma); | |||
av_log(h->avctx, AV_LOG_ERROR, "Invalid luma bit depth=%d\n", h->sps.bit_depth_luma); | |||
return AVERROR_INVALIDDATA; | |||
} else if (h->sps.bit_depth_luma == 11 || h->sps.bit_depth_luma == 13) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "Unimplemented luma bit depth=%d\n", h->sps.bit_depth_luma); | |||
av_log(h->avctx, AV_LOG_ERROR, "Unimplemented luma bit depth=%d\n", h->sps.bit_depth_luma); | |||
return AVERROR_PATCHWELCOME; | |||
} | |||
pps= av_mallocz(sizeof(PPS)); | |||
if(pps == NULL) | |||
return -1; | |||
pps->sps_id= get_ue_golomb_31(&s->gb); | |||
pps->sps_id= get_ue_golomb_31(&h->gb); | |||
if((unsigned)pps->sps_id>=MAX_SPS_COUNT || h->sps_buffers[pps->sps_id] == NULL){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "sps_id out of range\n"); | |||
goto fail; | |||
} | |||
pps->cabac= get_bits1(&s->gb); | |||
pps->pic_order_present= get_bits1(&s->gb); | |||
pps->slice_group_count= get_ue_golomb(&s->gb) + 1; | |||
pps->cabac= get_bits1(&h->gb); | |||
pps->pic_order_present= get_bits1(&h->gb); | |||
pps->slice_group_count= get_ue_golomb(&h->gb) + 1; | |||
if(pps->slice_group_count > 1 ){ | |||
pps->mb_slice_group_map_type= get_ue_golomb(&s->gb); | |||
av_log(h->s.avctx, AV_LOG_ERROR, "FMO not supported\n"); | |||
pps->mb_slice_group_map_type= get_ue_golomb(&h->gb); | |||
av_log(h->avctx, AV_LOG_ERROR, "FMO not supported\n"); | |||
switch(pps->mb_slice_group_map_type){ | |||
case 0: | |||
#if 0 | |||
@@ -636,32 +630,32 @@ int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){ | |||
break; | |||
} | |||
} | |||
pps->ref_count[0]= get_ue_golomb(&s->gb) + 1; | |||
pps->ref_count[1]= get_ue_golomb(&s->gb) + 1; | |||
pps->ref_count[0]= get_ue_golomb(&h->gb) + 1; | |||
pps->ref_count[1]= get_ue_golomb(&h->gb) + 1; | |||
if(pps->ref_count[0]-1 > 32-1 || pps->ref_count[1]-1 > 32-1){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); | |||
goto fail; | |||
} | |||
pps->weighted_pred= get_bits1(&s->gb); | |||
pps->weighted_bipred_idc= get_bits(&s->gb, 2); | |||
pps->init_qp= get_se_golomb(&s->gb) + 26 + qp_bd_offset; | |||
pps->init_qs= get_se_golomb(&s->gb) + 26 + qp_bd_offset; | |||
pps->chroma_qp_index_offset[0]= get_se_golomb(&s->gb); | |||
pps->deblocking_filter_parameters_present= get_bits1(&s->gb); | |||
pps->constrained_intra_pred= get_bits1(&s->gb); | |||
pps->redundant_pic_cnt_present = get_bits1(&s->gb); | |||
pps->weighted_pred= get_bits1(&h->gb); | |||
pps->weighted_bipred_idc= get_bits(&h->gb, 2); | |||
pps->init_qp= get_se_golomb(&h->gb) + 26 + qp_bd_offset; | |||
pps->init_qs= get_se_golomb(&h->gb) + 26 + qp_bd_offset; | |||
pps->chroma_qp_index_offset[0]= get_se_golomb(&h->gb); | |||
pps->deblocking_filter_parameters_present= get_bits1(&h->gb); | |||
pps->constrained_intra_pred= get_bits1(&h->gb); | |||
pps->redundant_pic_cnt_present = get_bits1(&h->gb); | |||
pps->transform_8x8_mode= 0; | |||
h->dequant_coeff_pps= -1; //contents of sps/pps can change even if id doesn't, so reinit | |||
memcpy(pps->scaling_matrix4, h->sps_buffers[pps->sps_id]->scaling_matrix4, sizeof(pps->scaling_matrix4)); | |||
memcpy(pps->scaling_matrix8, h->sps_buffers[pps->sps_id]->scaling_matrix8, sizeof(pps->scaling_matrix8)); | |||
bits_left = bit_length - get_bits_count(&s->gb); | |||
bits_left = bit_length - get_bits_count(&h->gb); | |||
if(bits_left > 0 && more_rbsp_data_in_pps(h, pps)){ | |||
pps->transform_8x8_mode= get_bits1(&s->gb); | |||
pps->transform_8x8_mode= get_bits1(&h->gb); | |||
decode_scaling_matrices(h, h->sps_buffers[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8); | |||
pps->chroma_qp_index_offset[1]= get_se_golomb(&s->gb); //second_chroma_qp_index_offset | |||
pps->chroma_qp_index_offset[1]= get_se_golomb(&h->gb); //second_chroma_qp_index_offset | |||
} else { | |||
pps->chroma_qp_index_offset[1]= pps->chroma_qp_index_offset[0]; | |||
} | |||
@@ -671,8 +665,8 @@ int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){ | |||
if(pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1]) | |||
pps->chroma_qp_diff= 1; | |||
if(s->avctx->debug&FF_DEBUG_PICT_INFO){ | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d/%d %s %s %s %s\n", | |||
if(h->avctx->debug&FF_DEBUG_PICT_INFO){ | |||
av_log(h->avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d/%d %s %s %s %s\n", | |||
pps_id, pps->sps_id, | |||
pps->cabac ? "CABAC" : "CAVLC", | |||
pps->slice_group_count, | |||
@@ -107,7 +107,6 @@ static int add_sorted(Picture **sorted, Picture **src, int len, int limit, int d | |||
} | |||
int ff_h264_fill_default_ref_list(H264Context *h){ | |||
MpegEncContext * const s = &h->s; | |||
int i, len; | |||
if(h->slice_type_nos==AV_PICTURE_TYPE_B){ | |||
@@ -116,16 +115,16 @@ int ff_h264_fill_default_ref_list(H264Context *h){ | |||
int lens[2]; | |||
if(FIELD_PICTURE) | |||
cur_poc= s->current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ]; | |||
cur_poc= h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD]; | |||
else | |||
cur_poc= s->current_picture_ptr->poc; | |||
cur_poc= h->cur_pic_ptr->poc; | |||
for(list= 0; list<2; list++){ | |||
len= add_sorted(sorted , h->short_ref, h->short_ref_count, cur_poc, 1^list); | |||
len+=add_sorted(sorted+len, h->short_ref, h->short_ref_count, cur_poc, 0^list); | |||
av_assert0(len<=32); | |||
len= build_def_list(h->default_ref_list[list] , sorted , len, 0, s->picture_structure); | |||
len+=build_def_list(h->default_ref_list[list]+len, h->long_ref, 16 , 1, s->picture_structure); | |||
len= build_def_list(h->default_ref_list[list] , sorted , len, 0, h->picture_structure); | |||
len+=build_def_list(h->default_ref_list[list]+len, h->long_ref, 16 , 1, h->picture_structure); | |||
av_assert0(len<=32); | |||
if(len < h->ref_count[list]) | |||
@@ -139,19 +138,19 @@ int ff_h264_fill_default_ref_list(H264Context *h){ | |||
FFSWAP(Picture, h->default_ref_list[1][0], h->default_ref_list[1][1]); | |||
} | |||
}else{ | |||
len = build_def_list(h->default_ref_list[0] , h->short_ref, h->short_ref_count, 0, s->picture_structure); | |||
len+= build_def_list(h->default_ref_list[0]+len, h-> long_ref, 16 , 1, s->picture_structure); | |||
len = build_def_list(h->default_ref_list[0] , h->short_ref, h->short_ref_count, 0, h->picture_structure); | |||
len+= build_def_list(h->default_ref_list[0]+len, h-> long_ref, 16 , 1, h->picture_structure); | |||
av_assert0(len<=32); | |||
if(len < h->ref_count[0]) | |||
memset(&h->default_ref_list[0][len], 0, sizeof(Picture)*(h->ref_count[0] - len)); | |||
} | |||
#ifdef TRACE | |||
for (i=0; i<h->ref_count[0]; i++) { | |||
tprintf(h->s.avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].f.data[0]); | |||
tprintf(h->avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].f.data[0]); | |||
} | |||
if(h->slice_type_nos==AV_PICTURE_TYPE_B){ | |||
for (i=0; i<h->ref_count[1]; i++) { | |||
tprintf(h->s.avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].f.data[0]); | |||
tprintf(h->avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].f.data[0]); | |||
} | |||
} | |||
#endif | |||
@@ -172,9 +171,7 @@ static void print_long_term(H264Context *h); | |||
* described by pic_num | |||
*/ | |||
static int pic_num_extract(H264Context *h, int pic_num, int *structure){ | |||
MpegEncContext * const s = &h->s; | |||
*structure = s->picture_structure; | |||
*structure = h->picture_structure; | |||
if(FIELD_PICTURE){ | |||
if (!(pic_num & 1)) | |||
/* opposite field */ | |||
@@ -186,7 +183,6 @@ static int pic_num_extract(H264Context *h, int pic_num, int *structure){ | |||
} | |||
int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ | |||
MpegEncContext * const s = &h->s; | |||
int list, index, pic_structure; | |||
print_short_term(h); | |||
@@ -195,11 +191,11 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ | |||
for(list=0; list<h->list_count; list++){ | |||
memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); | |||
if(get_bits1(&s->gb)){ | |||
if(get_bits1(&h->gb)){ | |||
int pred= h->curr_pic_num; | |||
for(index=0; ; index++){ | |||
unsigned int reordering_of_pic_nums_idc= get_ue_golomb_31(&s->gb); | |||
unsigned int reordering_of_pic_nums_idc= get_ue_golomb_31(&h->gb); | |||
unsigned int pic_id; | |||
int i; | |||
Picture *ref = NULL; | |||
@@ -208,17 +204,17 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ | |||
break; | |||
if(index >= h->ref_count[list]){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "reference count overflow\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "reference count overflow\n"); | |||
return -1; | |||
} | |||
if(reordering_of_pic_nums_idc<3){ | |||
if(reordering_of_pic_nums_idc<2){ | |||
const unsigned int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1; | |||
const unsigned int abs_diff_pic_num= get_ue_golomb(&h->gb) + 1; | |||
int frame_num; | |||
if(abs_diff_pic_num > h->max_pic_num){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); | |||
return -1; | |||
} | |||
@@ -242,12 +238,12 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ | |||
ref->pic_id= pred; | |||
}else{ | |||
int long_idx; | |||
pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx | |||
pic_id= get_ue_golomb(&h->gb); //long_term_pic_idx | |||
long_idx= pic_num_extract(h, pic_id, &pic_structure); | |||
if(long_idx>31){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n"); | |||
return -1; | |||
} | |||
ref = h->long_ref[long_idx]; | |||
@@ -262,7 +258,7 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ | |||
} | |||
if (i < 0) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); | |||
memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME | |||
} else { | |||
for(i=index; i+1<h->ref_count[list]; i++){ | |||
@@ -278,7 +274,7 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ | |||
} | |||
} | |||
}else{ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); | |||
return -1; | |||
} | |||
} | |||
@@ -288,7 +284,7 @@ int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ | |||
for(index= 0; index < h->ref_count[list]; index++){ | |||
if (!h->ref_list[list][index].f.data[0]) { | |||
int i; | |||
av_log(h->s.avctx, AV_LOG_ERROR, "Missing reference picture, default is %d\n", h->default_ref_list[list][0].poc); | |||
av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture, default is %d\n", h->default_ref_list[list][0].poc); | |||
for (i=0; i<FF_ARRAY_ELEMS(h->last_pocs); i++) | |||
h->last_pocs[i] = INT_MIN; | |||
if (h->default_ref_list[list][0].f.data[0]) | |||
@@ -363,13 +359,12 @@ static inline int unreference_pic(H264Context *h, Picture *pic, int refmask){ | |||
* frame number is found | |||
*/ | |||
static Picture * find_short(H264Context *h, int frame_num, int *idx){ | |||
MpegEncContext * const s = &h->s; | |||
int i; | |||
for(i=0; i<h->short_ref_count; i++){ | |||
Picture *pic= h->short_ref[i]; | |||
if(s->avctx->debug&FF_DEBUG_MMCO) | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); | |||
if(h->avctx->debug&FF_DEBUG_MMCO) | |||
av_log(h->avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); | |||
if(pic->frame_num == frame_num) { | |||
*idx = i; | |||
return pic; | |||
@@ -396,12 +391,11 @@ static void remove_short_at_index(H264Context *h, int i){ | |||
* @return the removed picture or NULL if an error occurs | |||
*/ | |||
static Picture * remove_short(H264Context *h, int frame_num, int ref_mask){ | |||
MpegEncContext * const s = &h->s; | |||
Picture *pic; | |||
int i; | |||
if(s->avctx->debug&FF_DEBUG_MMCO) | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); | |||
if(h->avctx->debug&FF_DEBUG_MMCO) | |||
av_log(h->avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); | |||
pic = find_short(h, frame_num, &i); | |||
if (pic){ | |||
@@ -456,11 +450,11 @@ void ff_h264_remove_all_refs(H264Context *h){ | |||
*/ | |||
static void print_short_term(H264Context *h) { | |||
uint32_t i; | |||
if(h->s.avctx->debug&FF_DEBUG_MMCO) { | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "short term list:\n"); | |||
if(h->avctx->debug&FF_DEBUG_MMCO) { | |||
av_log(h->avctx, AV_LOG_DEBUG, "short term list:\n"); | |||
for(i=0; i<h->short_ref_count; i++){ | |||
Picture *pic= h->short_ref[i]; | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", | |||
av_log(h->avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", | |||
i, pic->frame_num, pic->poc, pic->f.data[0]); | |||
} | |||
} | |||
@@ -471,12 +465,12 @@ static void print_short_term(H264Context *h) { | |||
*/ | |||
static void print_long_term(H264Context *h) { | |||
uint32_t i; | |||
if(h->s.avctx->debug&FF_DEBUG_MMCO) { | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "long term list:\n"); | |||
if(h->avctx->debug&FF_DEBUG_MMCO) { | |||
av_log(h->avctx, AV_LOG_DEBUG, "long term list:\n"); | |||
for(i = 0; i < 16; i++){ | |||
Picture *pic= h->long_ref[i]; | |||
if (pic) { | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", | |||
av_log(h->avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", | |||
i, pic->frame_num, pic->poc, pic->f.data[0]); | |||
} | |||
} | |||
@@ -500,14 +494,12 @@ static int check_opcodes(MMCO *mmco1, MMCO *mmco2, int n_mmcos) | |||
int ff_generate_sliding_window_mmcos(H264Context *h, int first_slice) | |||
{ | |||
MpegEncContext * const s = &h->s; | |||
MMCO mmco_temp[MAX_MMCO_COUNT], *mmco = first_slice ? h->mmco : mmco_temp; | |||
int mmco_index = 0, i; | |||
if (h->short_ref_count && | |||
h->long_ref_count + h->short_ref_count >= h->sps.ref_frame_count && | |||
!(FIELD_PICTURE && !s->first_field && | |||
s->current_picture_ptr->f.reference)) { | |||
!(FIELD_PICTURE && !h->first_field && h->cur_pic_ptr->f.reference)) { | |||
mmco[0].opcode = MMCO_SHORT2UNUSED; | |||
mmco[0].short_pic_num = h->short_ref[h->short_ref_count - 1]->frame_num; | |||
mmco_index = 1; | |||
@@ -524,7 +516,7 @@ int ff_generate_sliding_window_mmcos(H264Context *h, int first_slice) | |||
} else if (!first_slice && mmco_index >= 0 && | |||
(mmco_index != h->mmco_index || | |||
(i = check_opcodes(h->mmco, mmco_temp, mmco_index)))) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, | |||
av_log(h->avctx, AV_LOG_ERROR, | |||
"Inconsistent MMCO state between slices [%d, %d]\n", | |||
mmco_index, h->mmco_index); | |||
return AVERROR_INVALIDDATA; | |||
@@ -533,18 +525,17 @@ int ff_generate_sliding_window_mmcos(H264Context *h, int first_slice) | |||
} | |||
int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |||
MpegEncContext * const s = &h->s; | |||
int i, av_uninit(j); | |||
int current_ref_assigned=0, err=0; | |||
Picture *av_uninit(pic); | |||
if((s->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0) | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "no mmco here\n"); | |||
if((h->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0) | |||
av_log(h->avctx, AV_LOG_DEBUG, "no mmco here\n"); | |||
for(i=0; i<mmco_count; i++){ | |||
int av_uninit(structure), av_uninit(frame_num); | |||
if(s->avctx->debug&FF_DEBUG_MMCO) | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_pic_num, h->mmco[i].long_arg); | |||
if(h->avctx->debug&FF_DEBUG_MMCO) | |||
av_log(h->avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_pic_num, h->mmco[i].long_arg); | |||
if( mmco[i].opcode == MMCO_SHORT2UNUSED | |||
|| mmco[i].opcode == MMCO_SHORT2LONG){ | |||
@@ -553,7 +544,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |||
if(!pic){ | |||
if(mmco[i].opcode != MMCO_SHORT2LONG || !h->long_ref[mmco[i].long_arg] | |||
|| h->long_ref[mmco[i].long_arg]->frame_num != frame_num) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "mmco: unref short failure\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "mmco: unref short failure\n"); | |||
err = AVERROR_INVALIDDATA; | |||
} | |||
continue; | |||
@@ -562,8 +553,8 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |||
switch(mmco[i].opcode){ | |||
case MMCO_SHORT2UNUSED: | |||
if(s->avctx->debug&FF_DEBUG_MMCO) | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n", h->mmco[i].short_pic_num, h->short_ref_count); | |||
if(h->avctx->debug&FF_DEBUG_MMCO) | |||
av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n", h->mmco[i].short_pic_num, h->short_ref_count); | |||
remove_short(h, frame_num, structure ^ PICT_FRAME); | |||
break; | |||
case MMCO_SHORT2LONG: | |||
@@ -582,8 +573,8 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |||
pic = h->long_ref[j]; | |||
if (pic) { | |||
remove_long(h, j, structure ^ PICT_FRAME); | |||
} else if(s->avctx->debug&FF_DEBUG_MMCO) | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref long failure\n"); | |||
} else if(h->avctx->debug&FF_DEBUG_MMCO) | |||
av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref long failure\n"); | |||
break; | |||
case MMCO_LONG: | |||
// Comment below left from previous code as it is an interresting note. | |||
@@ -594,15 +585,15 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |||
* and mark this field valid. | |||
*/ | |||
if (h->long_ref[mmco[i].long_arg] != s->current_picture_ptr) { | |||
if (h->long_ref[mmco[i].long_arg] != h->cur_pic_ptr) { | |||
remove_long(h, mmco[i].long_arg, 0); | |||
h->long_ref[ mmco[i].long_arg ]= s->current_picture_ptr; | |||
h->long_ref[ mmco[i].long_arg ]= h->cur_pic_ptr; | |||
h->long_ref[ mmco[i].long_arg ]->long_ref=1; | |||
h->long_ref_count++; | |||
} | |||
s->current_picture_ptr->f.reference |= s->picture_structure; | |||
h->cur_pic_ptr->f.reference |= h->picture_structure; | |||
current_ref_assigned=1; | |||
break; | |||
case MMCO_SET_MAX_LONG: | |||
@@ -620,9 +611,9 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |||
remove_long(h, j, 0); | |||
} | |||
h->frame_num= | |||
s->current_picture_ptr->frame_num= 0; | |||
h->cur_pic_ptr->frame_num= 0; | |||
h->mmco_reset = 1; | |||
s->current_picture_ptr->mmco_reset=1; | |||
h->cur_pic_ptr->mmco_reset=1; | |||
for (j = 0; j < MAX_DELAYED_PIC_COUNT; j++) | |||
h->last_pocs[j] = INT_MIN; | |||
break; | |||
@@ -637,28 +628,28 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |||
* in long_ref; trying to put it on the short list here is an | |||
* error in the encoded bit stream (ref: 7.4.3.3, NOTE 2 and 3). | |||
*/ | |||
if (h->short_ref_count && h->short_ref[0] == s->current_picture_ptr) { | |||
if (h->short_ref_count && h->short_ref[0] == h->cur_pic_ptr) { | |||
/* Just mark the second field valid */ | |||
s->current_picture_ptr->f.reference = PICT_FRAME; | |||
} else if (s->current_picture_ptr->long_ref) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term reference " | |||
"assignment for second field " | |||
"in complementary field pair " | |||
"(first field is long term)\n"); | |||
h->cur_pic_ptr->f.reference = PICT_FRAME; | |||
} else if (h->cur_pic_ptr->long_ref) { | |||
av_log(h->avctx, AV_LOG_ERROR, "illegal short term reference " | |||
"assignment for second field " | |||
"in complementary field pair " | |||
"(first field is long term)\n"); | |||
err = AVERROR_INVALIDDATA; | |||
} else { | |||
pic= remove_short(h, s->current_picture_ptr->frame_num, 0); | |||
pic= remove_short(h, h->cur_pic_ptr->frame_num, 0); | |||
if(pic){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); | |||
av_log(h->avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); | |||
err = AVERROR_INVALIDDATA; | |||
} | |||
if(h->short_ref_count) | |||
memmove(&h->short_ref[1], &h->short_ref[0], h->short_ref_count*sizeof(Picture*)); | |||
h->short_ref[0]= s->current_picture_ptr; | |||
h->short_ref[0]= h->cur_pic_ptr; | |||
h->short_ref_count++; | |||
s->current_picture_ptr->f.reference |= s->picture_structure; | |||
h->cur_pic_ptr->f.reference |= h->picture_structure; | |||
} | |||
} | |||
@@ -668,7 +659,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |||
* stream. Need to discard one frame. Prevents overrun of the | |||
* short_ref and long_ref buffers. | |||
*/ | |||
av_log(h->s.avctx, AV_LOG_ERROR, | |||
av_log(h->avctx, AV_LOG_ERROR, | |||
"number of reference frames (%d+%d) exceeds max (%d; probably " | |||
"corrupt input), discarding one\n", | |||
h->long_ref_count, h->short_ref_count, h->sps.ref_frame_count); | |||
@@ -690,25 +681,24 @@ int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ | |||
print_short_term(h); | |||
print_long_term(h); | |||
if(err >= 0 && h->long_ref_count==0 && h->short_ref_count<=2 && h->pps.ref_count[0]<=1 + (s->picture_structure != PICT_FRAME) && s->current_picture_ptr->f.pict_type == AV_PICTURE_TYPE_I){ | |||
s->current_picture_ptr->sync |= 1; | |||
if(!h->s.avctx->has_b_frames) | |||
if(err >= 0 && h->long_ref_count==0 && h->short_ref_count<=2 && h->pps.ref_count[0]<=1 + (h->picture_structure != PICT_FRAME) && h->cur_pic_ptr->f.pict_type == AV_PICTURE_TYPE_I){ | |||
h->cur_pic_ptr->sync |= 1; | |||
if(!h->avctx->has_b_frames) | |||
h->sync = 2; | |||
} | |||
return (h->s.avctx->err_recognition & AV_EF_EXPLODE) ? err : 0; | |||
return (h->avctx->err_recognition & AV_EF_EXPLODE) ? err : 0; | |||
} | |||
int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, | |||
int first_slice) | |||
{ | |||
MpegEncContext * const s = &h->s; | |||
int i, ret; | |||
MMCO mmco_temp[MAX_MMCO_COUNT], *mmco = first_slice ? h->mmco : mmco_temp; | |||
int mmco_index = 0; | |||
if (h->nal_unit_type == NAL_IDR_SLICE){ // FIXME fields | |||
s->broken_link = get_bits1(gb) - 1; | |||
skip_bits1(gb); // broken_link | |||
if (get_bits1(gb)){ | |||
mmco[0].opcode = MMCO_LONG; | |||
mmco[0].long_arg = 0; | |||
@@ -741,7 +731,7 @@ int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, | |||
(long_arg >= 16 && !(opcode == MMCO_SET_MAX_LONG && | |||
long_arg == 16) && | |||
!(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, | |||
av_log(h->avctx, AV_LOG_ERROR, | |||
"illegal long ref in memory management control " | |||
"operation %d\n", opcode); | |||
return -1; | |||
@@ -750,7 +740,7 @@ int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, | |||
} | |||
if (opcode > (unsigned) MMCO_LONG){ | |||
av_log(h->s.avctx, AV_LOG_ERROR, | |||
av_log(h->avctx, AV_LOG_ERROR, | |||
"illegal memory management control operation %d\n", | |||
opcode); | |||
return -1; | |||
@@ -762,7 +752,7 @@ int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, | |||
} else { | |||
if (first_slice) { | |||
ret = ff_generate_sliding_window_mmcos(h, first_slice); | |||
if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE) | |||
if (ret < 0 && h->avctx->err_recognition & AV_EF_EXPLODE) | |||
return ret; | |||
} | |||
mmco_index = -1; | |||
@@ -774,7 +764,7 @@ int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb, | |||
} else if (!first_slice && mmco_index >= 0 && | |||
(mmco_index != h->mmco_index || | |||
(i = check_opcodes(h->mmco, mmco_temp, mmco_index)))) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, | |||
av_log(h->avctx, AV_LOG_ERROR, | |||
"Inconsistent MMCO state between slices [%d, %d]\n", | |||
mmco_index, h->mmco_index); | |||
return AVERROR_INVALIDDATA; | |||
@@ -45,14 +45,13 @@ void ff_h264_reset_sei(H264Context *h) { | |||
} | |||
static int decode_picture_timing(H264Context *h){ | |||
MpegEncContext * const s = &h->s; | |||
if(h->sps.nal_hrd_parameters_present_flag || h->sps.vcl_hrd_parameters_present_flag){ | |||
h->sei_cpb_removal_delay = get_bits_long(&s->gb, h->sps.cpb_removal_delay_length); | |||
h->sei_dpb_output_delay = get_bits_long(&s->gb, h->sps.dpb_output_delay_length); | |||
h->sei_cpb_removal_delay = get_bits_long(&h->gb, h->sps.cpb_removal_delay_length); | |||
h->sei_dpb_output_delay = get_bits_long(&h->gb, h->sps.dpb_output_delay_length); | |||
} | |||
if(h->sps.pic_struct_present_flag){ | |||
unsigned int i, num_clock_ts; | |||
h->sei_pic_struct = get_bits(&s->gb, 4); | |||
h->sei_pic_struct = get_bits(&h->gb, 4); | |||
h->sei_ct_type = 0; | |||
if (h->sei_pic_struct > SEI_PIC_STRUCT_FRAME_TRIPLING) | |||
@@ -61,42 +60,41 @@ static int decode_picture_timing(H264Context *h){ | |||
num_clock_ts = sei_num_clock_ts_table[h->sei_pic_struct]; | |||
for (i = 0 ; i < num_clock_ts ; i++){ | |||
if(get_bits(&s->gb, 1)){ /* clock_timestamp_flag */ | |||
if(get_bits(&h->gb, 1)){ /* clock_timestamp_flag */ | |||
unsigned int full_timestamp_flag; | |||
h->sei_ct_type |= 1<<get_bits(&s->gb, 2); | |||
skip_bits(&s->gb, 1); /* nuit_field_based_flag */ | |||
skip_bits(&s->gb, 5); /* counting_type */ | |||
full_timestamp_flag = get_bits(&s->gb, 1); | |||
skip_bits(&s->gb, 1); /* discontinuity_flag */ | |||
skip_bits(&s->gb, 1); /* cnt_dropped_flag */ | |||
skip_bits(&s->gb, 8); /* n_frames */ | |||
h->sei_ct_type |= 1<<get_bits(&h->gb, 2); | |||
skip_bits(&h->gb, 1); /* nuit_field_based_flag */ | |||
skip_bits(&h->gb, 5); /* counting_type */ | |||
full_timestamp_flag = get_bits(&h->gb, 1); | |||
skip_bits(&h->gb, 1); /* discontinuity_flag */ | |||
skip_bits(&h->gb, 1); /* cnt_dropped_flag */ | |||
skip_bits(&h->gb, 8); /* n_frames */ | |||
if(full_timestamp_flag){ | |||
skip_bits(&s->gb, 6); /* seconds_value 0..59 */ | |||
skip_bits(&s->gb, 6); /* minutes_value 0..59 */ | |||
skip_bits(&s->gb, 5); /* hours_value 0..23 */ | |||
skip_bits(&h->gb, 6); /* seconds_value 0..59 */ | |||
skip_bits(&h->gb, 6); /* minutes_value 0..59 */ | |||
skip_bits(&h->gb, 5); /* hours_value 0..23 */ | |||
}else{ | |||
if(get_bits(&s->gb, 1)){ /* seconds_flag */ | |||
skip_bits(&s->gb, 6); /* seconds_value range 0..59 */ | |||
if(get_bits(&s->gb, 1)){ /* minutes_flag */ | |||
skip_bits(&s->gb, 6); /* minutes_value 0..59 */ | |||
if(get_bits(&s->gb, 1)) /* hours_flag */ | |||
skip_bits(&s->gb, 5); /* hours_value 0..23 */ | |||
if(get_bits(&h->gb, 1)){ /* seconds_flag */ | |||
skip_bits(&h->gb, 6); /* seconds_value range 0..59 */ | |||
if(get_bits(&h->gb, 1)){ /* minutes_flag */ | |||
skip_bits(&h->gb, 6); /* minutes_value 0..59 */ | |||
if(get_bits(&h->gb, 1)) /* hours_flag */ | |||
skip_bits(&h->gb, 5); /* hours_value 0..23 */ | |||
} | |||
} | |||
} | |||
if(h->sps.time_offset_length > 0) | |||
skip_bits(&s->gb, h->sps.time_offset_length); /* time_offset */ | |||
skip_bits(&h->gb, h->sps.time_offset_length); /* time_offset */ | |||
} | |||
} | |||
if(s->avctx->debug & FF_DEBUG_PICT_INFO) | |||
av_log(s->avctx, AV_LOG_DEBUG, "ct_type:%X pic_struct:%d\n", h->sei_ct_type, h->sei_pic_struct); | |||
if(h->avctx->debug & FF_DEBUG_PICT_INFO) | |||
av_log(h->avctx, AV_LOG_DEBUG, "ct_type:%X pic_struct:%d\n", h->sei_ct_type, h->sei_pic_struct); | |||
} | |||
return 0; | |||
} | |||
static int decode_user_data_itu_t_t35(H264Context *h, int size) { | |||
MpegEncContext * const s = &h->s; | |||
uint32_t user_identifier; | |||
int dtg_active_format; | |||
@@ -104,28 +102,28 @@ static int decode_user_data_itu_t_t35(H264Context *h, int size) { | |||
return -1; | |||
size -= 7; | |||
skip_bits(&s->gb, 8); // country_code | |||
skip_bits(&s->gb, 16); // provider_code | |||
user_identifier = get_bits_long(&s->gb, 32); | |||
skip_bits(&h->gb, 8); // country_code | |||
skip_bits(&h->gb, 16); // provider_code | |||
user_identifier = get_bits_long(&h->gb, 32); | |||
switch (user_identifier) { | |||
case 0x44544731: // "DTG1" - AFD_data | |||
if (size < 1) | |||
return -1; | |||
skip_bits(&s->gb, 1); | |||
if (get_bits(&s->gb, 1)) { | |||
skip_bits(&s->gb, 6); | |||
skip_bits(&h->gb, 1); | |||
if (get_bits(&h->gb, 1)) { | |||
skip_bits(&h->gb, 6); | |||
if (size < 2) | |||
return -1; | |||
skip_bits(&s->gb, 4); | |||
dtg_active_format = get_bits(&s->gb, 4); | |||
s->avctx->dtg_active_format = dtg_active_format; | |||
skip_bits(&h->gb, 4); | |||
dtg_active_format = get_bits(&h->gb, 4); | |||
h->avctx->dtg_active_format = dtg_active_format; | |||
} else { | |||
skip_bits(&s->gb, 6); | |||
skip_bits(&h->gb, 6); | |||
} | |||
break; | |||
default: | |||
skip_bits(&s->gb, size * 8); | |||
skip_bits(&h->gb, size * 8); | |||
break; | |||
} | |||
@@ -133,7 +131,6 @@ static int decode_user_data_itu_t_t35(H264Context *h, int size) { | |||
} | |||
static int decode_unregistered_user_data(H264Context *h, int size){ | |||
MpegEncContext * const s = &h->s; | |||
uint8_t user_data[16+256]; | |||
int e, build, i; | |||
@@ -141,7 +138,7 @@ static int decode_unregistered_user_data(H264Context *h, int size){ | |||
return -1; | |||
for(i=0; i<sizeof(user_data)-1 && i<size; i++){ | |||
user_data[i]= get_bits(&s->gb, 8); | |||
user_data[i]= get_bits(&h->gb, 8); | |||
} | |||
user_data[i]= 0; | |||
@@ -151,33 +148,30 @@ static int decode_unregistered_user_data(H264Context *h, int size){ | |||
if(e==1 && build==1 && !strncmp(user_data+16, "x264 - core 0000", 16)) | |||
h->x264_build = 67; | |||
if(s->avctx->debug & FF_DEBUG_BUGS) | |||
av_log(s->avctx, AV_LOG_DEBUG, "user data:\"%s\"\n", user_data+16); | |||
if(h->avctx->debug & FF_DEBUG_BUGS) | |||
av_log(h->avctx, AV_LOG_DEBUG, "user data:\"%s\"\n", user_data+16); | |||
for(; i<size; i++) | |||
skip_bits(&s->gb, 8); | |||
skip_bits(&h->gb, 8); | |||
return 0; | |||
} | |||
static int decode_recovery_point(H264Context *h){ | |||
MpegEncContext * const s = &h->s; | |||
h->sei_recovery_frame_cnt = get_ue_golomb(&s->gb); | |||
skip_bits(&s->gb, 4); /* 1b exact_match_flag, 1b broken_link_flag, 2b changing_slice_group_idc */ | |||
h->sei_recovery_frame_cnt = get_ue_golomb(&h->gb); | |||
skip_bits(&h->gb, 4); /* 1b exact_match_flag, 1b broken_link_flag, 2b changing_slice_group_idc */ | |||
return 0; | |||
} | |||
static int decode_buffering_period(H264Context *h){ | |||
MpegEncContext * const s = &h->s; | |||
unsigned int sps_id; | |||
int sched_sel_idx; | |||
SPS *sps; | |||
sps_id = get_ue_golomb_31(&s->gb); | |||
sps_id = get_ue_golomb_31(&h->gb); | |||
if(sps_id > 31 || !h->sps_buffers[sps_id]) { | |||
av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %d referenced in buffering period\n", sps_id); | |||
av_log(h->avctx, AV_LOG_ERROR, "non-existing SPS %d referenced in buffering period\n", sps_id); | |||
return -1; | |||
} | |||
sps = h->sps_buffers[sps_id]; | |||
@@ -185,14 +179,14 @@ static int decode_buffering_period(H264Context *h){ | |||
// NOTE: This is really so duplicated in the standard... See H.264, D.1.1 | |||
if (sps->nal_hrd_parameters_present_flag) { | |||
for (sched_sel_idx = 0; sched_sel_idx < sps->cpb_cnt; sched_sel_idx++) { | |||
h->initial_cpb_removal_delay[sched_sel_idx] = get_bits_long(&s->gb, sps->initial_cpb_removal_delay_length); | |||
skip_bits(&s->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset | |||
h->initial_cpb_removal_delay[sched_sel_idx] = get_bits_long(&h->gb, sps->initial_cpb_removal_delay_length); | |||
skip_bits(&h->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset | |||
} | |||
} | |||
if (sps->vcl_hrd_parameters_present_flag) { | |||
for (sched_sel_idx = 0; sched_sel_idx < sps->cpb_cnt; sched_sel_idx++) { | |||
h->initial_cpb_removal_delay[sched_sel_idx] = get_bits_long(&s->gb, sps->initial_cpb_removal_delay_length); | |||
skip_bits(&s->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset | |||
h->initial_cpb_removal_delay[sched_sel_idx] = get_bits_long(&h->gb, sps->initial_cpb_removal_delay_length); | |||
skip_bits(&h->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset | |||
} | |||
} | |||
@@ -201,27 +195,25 @@ static int decode_buffering_period(H264Context *h){ | |||
} | |||
int ff_h264_decode_sei(H264Context *h){ | |||
MpegEncContext * const s = &h->s; | |||
while (get_bits_left(&s->gb) > 16) { | |||
while (get_bits_left(&h->gb) > 16) { | |||
int size, type; | |||
type=0; | |||
do{ | |||
if (get_bits_left(&s->gb) < 8) | |||
if (get_bits_left(&h->gb) < 8) | |||
return -1; | |||
type+= show_bits(&s->gb, 8); | |||
}while(get_bits(&s->gb, 8) == 255); | |||
type+= show_bits(&h->gb, 8); | |||
}while(get_bits(&h->gb, 8) == 255); | |||
size=0; | |||
do{ | |||
if (get_bits_left(&s->gb) < 8) | |||
if (get_bits_left(&h->gb) < 8) | |||
return -1; | |||
size+= show_bits(&s->gb, 8); | |||
}while(get_bits(&s->gb, 8) == 255); | |||
size+= show_bits(&h->gb, 8); | |||
}while(get_bits(&h->gb, 8) == 255); | |||
if(s->avctx->debug&FF_DEBUG_STARTCODE) | |||
av_log(h->s.avctx, AV_LOG_DEBUG, "SEI %d len:%d\n", type, size); | |||
if(h->avctx->debug&FF_DEBUG_STARTCODE) | |||
av_log(h->avctx, AV_LOG_DEBUG, "SEI %d len:%d\n", type, size); | |||
switch(type){ | |||
case SEI_TYPE_PIC_TIMING: // Picture timing SEI | |||
@@ -245,11 +237,11 @@ int ff_h264_decode_sei(H264Context *h){ | |||
return -1; | |||
break; | |||
default: | |||
skip_bits(&s->gb, 8*size); | |||
skip_bits(&h->gb, 8*size); | |||
} | |||
//FIXME check bits here | |||
align_get_bits(&s->gb); | |||
align_get_bits(&h->gb); | |||
} | |||
return 0; | |||
@@ -410,8 +410,6 @@ static void pred8x8_tm_vp8_c(uint8_t *src, ptrdiff_t stride) | |||
void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, | |||
int chroma_format_idc) | |||
{ | |||
// MpegEncContext * const s = &h->s; | |||
#undef FUNC | |||
#undef FUNCC | |||
#define FUNC(a, depth) a ## _ ## depth | |||
@@ -143,7 +143,7 @@ typedef struct Picture{ | |||
uint16_t *mc_mb_var; ///< Table for motion compensated MB variances | |||
uint8_t *mb_mean; ///< Table for MB luminance | |||
int b_frame_score; /* */ | |||
struct MpegEncContext *owner2; ///< pointer to the MpegEncContext that allocated this picture | |||
void *owner2; ///< pointer to the context that allocated this picture | |||
int needs_realloc; ///< Picture needs to be reallocated (eg due to a frame size change) | |||
int period_since_free; ///< "cycles" since this Picture has been freed | |||
} Picture; | |||
@@ -21,6 +21,7 @@ | |||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||
*/ | |||
#include "h264.h" | |||
#include "vaapi_internal.h" | |||
/** | |||
@@ -40,7 +41,7 @@ static void destroy_buffers(VADisplay display, VABufferID *buffers, unsigned int | |||
} | |||
} | |||
static int render_picture(struct vaapi_context *vactx, VASurfaceID surface) | |||
int ff_vaapi_render_picture(struct vaapi_context *vactx, VASurfaceID surface) | |||
{ | |||
VABufferID va_buffers[3]; | |||
unsigned int n_va_buffers = 0; | |||
@@ -77,7 +78,7 @@ static int render_picture(struct vaapi_context *vactx, VASurfaceID surface) | |||
return 0; | |||
} | |||
static int commit_slices(struct vaapi_context *vactx) | |||
int ff_vaapi_commit_slices(struct vaapi_context *vactx) | |||
{ | |||
VABufferID *slice_buf_ids; | |||
VABufferID slice_param_buf_id, slice_data_buf_id; | |||
@@ -152,7 +153,7 @@ VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, co | |||
if (!vactx->slice_data) | |||
vactx->slice_data = buffer; | |||
if (vactx->slice_data + vactx->slice_data_size != buffer) { | |||
if (commit_slices(vactx) < 0) | |||
if (ff_vaapi_commit_slices(vactx) < 0) | |||
return NULL; | |||
vactx->slice_data = buffer; | |||
} | |||
@@ -175,23 +176,12 @@ VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, co | |||
return slice_param; | |||
} | |||
int ff_vaapi_common_end_frame(MpegEncContext *s) | |||
void ff_vaapi_common_end_frame(AVCodecContext *avctx) | |||
{ | |||
struct vaapi_context * const vactx = s->avctx->hwaccel_context; | |||
int ret = -1; | |||
struct vaapi_context * const vactx = avctx->hwaccel_context; | |||
av_dlog(s->avctx, "ff_vaapi_common_end_frame()\n"); | |||
av_dlog(avctx, "ff_vaapi_common_end_frame()\n"); | |||
if (commit_slices(vactx) < 0) | |||
goto done; | |||
if (vactx->n_slice_buf_ids > 0) { | |||
if (render_picture(vactx, ff_vaapi_get_surface_id(s->current_picture_ptr)) < 0) | |||
goto done; | |||
ff_mpeg_draw_horiz_band(s, 0, s->avctx->height); | |||
} | |||
ret = 0; | |||
done: | |||
destroy_buffers(vactx->display, &vactx->pic_param_buf_id, 1); | |||
destroy_buffers(vactx->display, &vactx->iq_matrix_buf_id, 1); | |||
destroy_buffers(vactx->display, &vactx->bitplane_buf_id, 1); | |||
@@ -202,6 +192,27 @@ done: | |||
vactx->slice_buf_ids_alloc = 0; | |||
vactx->slice_count = 0; | |||
vactx->slice_params_alloc = 0; | |||
} | |||
int ff_vaapi_mpeg_end_frame(AVCodecContext *avctx) | |||
{ | |||
struct vaapi_context * const vactx = avctx->hwaccel_context; | |||
MpegEncContext *s = avctx->priv_data; | |||
int ret; | |||
ret = ff_vaapi_commit_slices(vactx); | |||
if (ret < 0) | |||
goto finish; | |||
ret = ff_vaapi_render_picture(vactx, | |||
ff_vaapi_get_surface_id(s->current_picture_ptr)); | |||
if (ret < 0) | |||
goto finish; | |||
ff_mpeg_draw_horiz_band(s, 0, s->avctx->height); | |||
finish: | |||
ff_vaapi_common_end_frame(avctx->priv_data); | |||
return ret; | |||
} | |||
@@ -224,7 +224,6 @@ static int start_frame(AVCodecContext *avctx, | |||
av_unused uint32_t size) | |||
{ | |||
H264Context * const h = avctx->priv_data; | |||
MpegEncContext * const s = &h->s; | |||
struct vaapi_context * const vactx = avctx->hwaccel_context; | |||
VAPictureParameterBufferH264 *pic_param; | |||
VAIQMatrixBufferH264 *iq_matrix; | |||
@@ -237,11 +236,11 @@ static int start_frame(AVCodecContext *avctx, | |||
pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferH264)); | |||
if (!pic_param) | |||
return -1; | |||
fill_vaapi_pic(&pic_param->CurrPic, s->current_picture_ptr, s->picture_structure); | |||
fill_vaapi_pic(&pic_param->CurrPic, h->cur_pic_ptr, h->picture_structure); | |||
if (fill_vaapi_ReferenceFrames(pic_param, h) < 0) | |||
return -1; | |||
pic_param->picture_width_in_mbs_minus1 = s->mb_width - 1; | |||
pic_param->picture_height_in_mbs_minus1 = s->mb_height - 1; | |||
pic_param->picture_width_in_mbs_minus1 = h->mb_width - 1; | |||
pic_param->picture_height_in_mbs_minus1 = h->mb_height - 1; | |||
pic_param->bit_depth_luma_minus8 = h->sps.bit_depth_luma - 8; | |||
pic_param->bit_depth_chroma_minus8 = h->sps.bit_depth_chroma - 8; | |||
pic_param->num_ref_frames = h->sps.ref_frame_count; | |||
@@ -269,7 +268,7 @@ static int start_frame(AVCodecContext *avctx, | |||
pic_param->pic_fields.bits.weighted_pred_flag = h->pps.weighted_pred; | |||
pic_param->pic_fields.bits.weighted_bipred_idc = h->pps.weighted_bipred_idc; | |||
pic_param->pic_fields.bits.transform_8x8_mode_flag = h->pps.transform_8x8_mode; | |||
pic_param->pic_fields.bits.field_pic_flag = s->picture_structure != PICT_FRAME; | |||
pic_param->pic_fields.bits.field_pic_flag = h->picture_structure != PICT_FRAME; | |||
pic_param->pic_fields.bits.constrained_intra_pred_flag = h->pps.constrained_intra_pred; | |||
pic_param->pic_fields.bits.pic_order_present_flag = h->pps.pic_order_present; | |||
pic_param->pic_fields.bits.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present; | |||
@@ -290,10 +289,24 @@ static int start_frame(AVCodecContext *avctx, | |||
/** End a hardware decoding based frame. */ | |||
static int end_frame(AVCodecContext *avctx) | |||
{ | |||
struct vaapi_context * const vactx = avctx->hwaccel_context; | |||
H264Context * const h = avctx->priv_data; | |||
int ret; | |||
av_dlog(avctx, "end_frame()\n"); | |||
return ff_vaapi_common_end_frame(&h->s); | |||
ret = ff_vaapi_commit_slices(vactx); | |||
if (ret < 0) | |||
goto finish; | |||
ret = ff_vaapi_render_picture(vactx, ff_vaapi_get_surface_id(h->cur_pic_ptr)); | |||
if (ret < 0) | |||
goto finish; | |||
ff_h264_draw_horiz_band(h, 0, h->avctx->height); | |||
finish: | |||
ff_vaapi_common_end_frame(avctx); | |||
return ret; | |||
} | |||
/** Decode the given H.264 slice with VA API. */ | |||
@@ -302,7 +315,6 @@ static int decode_slice(AVCodecContext *avctx, | |||
uint32_t size) | |||
{ | |||
H264Context * const h = avctx->priv_data; | |||
MpegEncContext * const s = &h->s; | |||
VASliceParameterBufferH264 *slice_param; | |||
av_dlog(avctx, "decode_slice(): buffer %p, size %d\n", buffer, size); | |||
@@ -311,14 +323,14 @@ static int decode_slice(AVCodecContext *avctx, | |||
slice_param = (VASliceParameterBufferH264 *)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size); | |||
if (!slice_param) | |||
return -1; | |||
slice_param->slice_data_bit_offset = get_bits_count(&h->s.gb) + 8; /* bit buffer started beyond nal_unit_type */ | |||
slice_param->first_mb_in_slice = (s->mb_y >> FIELD_OR_MBAFF_PICTURE) * s->mb_width + s->mb_x; | |||
slice_param->slice_data_bit_offset = get_bits_count(&h->gb) + 8; /* bit buffer started beyond nal_unit_type */ | |||
slice_param->first_mb_in_slice = (h->mb_y >> FIELD_OR_MBAFF_PICTURE) * h->mb_width + h->mb_x; | |||
slice_param->slice_type = ff_h264_get_slice_type(h); | |||
slice_param->direct_spatial_mv_pred_flag = h->slice_type == AV_PICTURE_TYPE_B ? h->direct_spatial_mv_pred : 0; | |||
slice_param->num_ref_idx_l0_active_minus1 = h->list_count > 0 ? h->ref_count[0] - 1 : 0; | |||
slice_param->num_ref_idx_l1_active_minus1 = h->list_count > 1 ? h->ref_count[1] - 1 : 0; | |||
slice_param->cabac_init_idc = h->cabac_init_idc; | |||
slice_param->slice_qp_delta = s->qscale - h->pps.init_qp; | |||
slice_param->slice_qp_delta = h->qscale - h->pps.init_qp; | |||
slice_param->disable_deblocking_filter_idc = h->deblocking_filter < 2 ? !h->deblocking_filter : h->deblocking_filter; | |||
slice_param->slice_alpha_c0_offset_div2 = h->slice_alpha_c0_offset / 2 - 26; | |||
slice_param->slice_beta_offset_div2 = h->slice_beta_offset / 2 - 26; | |||
@@ -42,7 +42,7 @@ static inline VASurfaceID ff_vaapi_get_surface_id(Picture *pic) | |||
} | |||
/** Common AVHWAccel.end_frame() implementation */ | |||
int ff_vaapi_common_end_frame(MpegEncContext *s); | |||
void ff_vaapi_common_end_frame(AVCodecContext *avctx); | |||
/** Allocate a new picture parameter buffer */ | |||
void *ff_vaapi_alloc_pic_param(struct vaapi_context *vactx, unsigned int size); | |||
@@ -63,6 +63,10 @@ uint8_t *ff_vaapi_alloc_bitplane(struct vaapi_context *vactx, uint32_t size); | |||
*/ | |||
VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, const uint8_t *buffer, uint32_t size); | |||
int ff_vaapi_mpeg_end_frame(AVCodecContext *avctx); | |||
int ff_vaapi_commit_slices(struct vaapi_context *vactx); | |||
int ff_vaapi_render_picture(struct vaapi_context *vactx, VASurfaceID surface); | |||
/* @} */ | |||
#endif /* AVCODEC_VAAPI_INTERNAL_H */ |
@@ -99,11 +99,6 @@ static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_ | |||
return 0; | |||
} | |||
static int vaapi_mpeg2_end_frame(AVCodecContext *avctx) | |||
{ | |||
return ff_vaapi_common_end_frame(avctx->priv_data); | |||
} | |||
static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) | |||
{ | |||
MpegEncContext * const s = avctx->priv_data; | |||
@@ -144,6 +139,6 @@ AVHWAccel ff_mpeg2_vaapi_hwaccel = { | |||
.id = AV_CODEC_ID_MPEG2VIDEO, | |||
.pix_fmt = AV_PIX_FMT_VAAPI_VLD, | |||
.start_frame = vaapi_mpeg2_start_frame, | |||
.end_frame = vaapi_mpeg2_end_frame, | |||
.end_frame = ff_vaapi_mpeg_end_frame, | |||
.decode_slice = vaapi_mpeg2_decode_slice, | |||
}; |
@@ -115,11 +115,6 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_ | |||
return 0; | |||
} | |||
static int vaapi_mpeg4_end_frame(AVCodecContext *avctx) | |||
{ | |||
return ff_vaapi_common_end_frame(avctx->priv_data); | |||
} | |||
static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) | |||
{ | |||
MpegEncContext * const s = avctx->priv_data; | |||
@@ -156,7 +151,7 @@ AVHWAccel ff_mpeg4_vaapi_hwaccel = { | |||
.id = AV_CODEC_ID_MPEG4, | |||
.pix_fmt = AV_PIX_FMT_VAAPI_VLD, | |||
.start_frame = vaapi_mpeg4_start_frame, | |||
.end_frame = vaapi_mpeg4_end_frame, | |||
.end_frame = ff_vaapi_mpeg_end_frame, | |||
.decode_slice = vaapi_mpeg4_decode_slice, | |||
}; | |||
#endif | |||
@@ -168,7 +163,7 @@ AVHWAccel ff_h263_vaapi_hwaccel = { | |||
.id = AV_CODEC_ID_H263, | |||
.pix_fmt = AV_PIX_FMT_VAAPI_VLD, | |||
.start_frame = vaapi_mpeg4_start_frame, | |||
.end_frame = vaapi_mpeg4_end_frame, | |||
.end_frame = ff_vaapi_mpeg_end_frame, | |||
.decode_slice = vaapi_mpeg4_decode_slice, | |||
}; | |||
#endif |
@@ -310,13 +310,6 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t | |||
return 0; | |||
} | |||
static int vaapi_vc1_end_frame(AVCodecContext *avctx) | |||
{ | |||
VC1Context * const v = avctx->priv_data; | |||
return ff_vaapi_common_end_frame(&v->s); | |||
} | |||
static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) | |||
{ | |||
VC1Context * const v = avctx->priv_data; | |||
@@ -347,7 +340,7 @@ AVHWAccel ff_wmv3_vaapi_hwaccel = { | |||
.id = AV_CODEC_ID_WMV3, | |||
.pix_fmt = AV_PIX_FMT_VAAPI_VLD, | |||
.start_frame = vaapi_vc1_start_frame, | |||
.end_frame = vaapi_vc1_end_frame, | |||
.end_frame = ff_vaapi_mpeg_end_frame, | |||
.decode_slice = vaapi_vc1_decode_slice, | |||
}; | |||
#endif | |||
@@ -358,6 +351,6 @@ AVHWAccel ff_vc1_vaapi_hwaccel = { | |||
.id = AV_CODEC_ID_VC1, | |||
.pix_fmt = AV_PIX_FMT_VAAPI_VLD, | |||
.start_frame = vaapi_vc1_start_frame, | |||
.end_frame = vaapi_vc1_end_frame, | |||
.end_frame = ff_vaapi_mpeg_end_frame, | |||
.decode_slice = vaapi_vc1_decode_slice, | |||
}; |
@@ -243,7 +243,7 @@ static int end_frame(AVCodecContext *avctx) | |||
{ | |||
H264Context *h = avctx->priv_data; | |||
struct vda_context *vda_ctx = avctx->hwaccel_context; | |||
AVFrame *frame = &h->s.current_picture_ptr->f; | |||
AVFrame *frame = &h->cur_pic_ptr->f; | |||
int status; | |||
if (!vda_ctx->decoder || !vda_ctx->priv_bitstream) | |||
@@ -48,20 +48,18 @@ int ff_vdpau_common_start_frame(AVCodecContext *avctx, | |||
return 0; | |||
} | |||
int ff_vdpau_common_end_frame(AVCodecContext *avctx) | |||
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx) | |||
{ | |||
MpegEncContext * const s = avctx->priv_data; | |||
AVVDPAUContext *hwctx = avctx->hwaccel_context; | |||
MpegEncContext *s = avctx->priv_data; | |||
VdpVideoSurface surf = ff_vdpau_get_surface_id(s->current_picture_ptr); | |||
if (hwctx->bitstream_buffers_used) { | |||
VdpVideoSurface surf = ff_vdpau_get_surface_id(s->current_picture_ptr); | |||
hwctx->render(hwctx->decoder, surf, (void *)&hwctx->info, | |||
hwctx->bitstream_buffers_used, hwctx->bitstream_buffers); | |||
hwctx->render(hwctx->decoder, surf, (void *)&hwctx->info, | |||
hwctx->bitstream_buffers_used, hwctx->bitstream_buffers); | |||
ff_mpeg_draw_horiz_band(s, 0, s->avctx->height); | |||
hwctx->bitstream_buffers_used = 0; | |||
ff_mpeg_draw_horiz_band(s, 0, s->avctx->height); | |||
hwctx->bitstream_buffers_used = 0; | |||
} | |||
return 0; | |||
} | |||
@@ -87,15 +85,14 @@ int ff_vdpau_add_buffer(AVCodecContext *avctx, | |||
/* Obsolete non-hwaccel VDPAU support below... */ | |||
void ff_vdpau_h264_set_reference_frames(MpegEncContext *s) | |||
void ff_vdpau_h264_set_reference_frames(H264Context *h) | |||
{ | |||
H264Context *h = s->avctx->priv_data; | |||
struct vdpau_render_state *render, *render_ref; | |||
VdpReferenceFrameH264 *rf, *rf2; | |||
Picture *pic; | |||
int i, list, pic_frame_idx; | |||
render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0]; | |||
render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0]; | |||
assert(render); | |||
rf = &render->info.h264.referenceFrames[0]; | |||
@@ -156,12 +153,9 @@ void ff_vdpau_h264_set_reference_frames(MpegEncContext *s) | |||
} | |||
} | |||
void ff_vdpau_add_data_chunk(MpegEncContext *s, | |||
const uint8_t *buf, int buf_size) | |||
void ff_vdpau_add_data_chunk(uint8_t *data, const uint8_t *buf, int buf_size) | |||
{ | |||
struct vdpau_render_state *render; | |||
render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0]; | |||
struct vdpau_render_state *render = (struct vdpau_render_state*)data; | |||
assert(render); | |||
render->bitstream_buffers= av_fast_realloc( | |||
@@ -176,17 +170,16 @@ void ff_vdpau_add_data_chunk(MpegEncContext *s, | |||
render->bitstream_buffers_used++; | |||
} | |||
void ff_vdpau_h264_picture_start(MpegEncContext *s) | |||
void ff_vdpau_h264_picture_start(H264Context *h) | |||
{ | |||
H264Context *h = s->avctx->priv_data; | |||
struct vdpau_render_state *render; | |||
int i; | |||
render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0]; | |||
render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0]; | |||
assert(render); | |||
for (i = 0; i < 2; ++i) { | |||
int foc = s->current_picture_ptr->field_poc[i]; | |||
int foc = h->cur_pic_ptr->field_poc[i]; | |||
if (foc == INT_MAX) | |||
foc = 0; | |||
render->info.h264.field_order_cnt[i] = foc; | |||
@@ -195,21 +188,20 @@ void ff_vdpau_h264_picture_start(MpegEncContext *s) | |||
render->info.h264.frame_num = h->frame_num; | |||
} | |||
void ff_vdpau_h264_picture_complete(MpegEncContext *s) | |||
void ff_vdpau_h264_picture_complete(H264Context *h) | |||
{ | |||
H264Context *h = s->avctx->priv_data; | |||
struct vdpau_render_state *render; | |||
render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0]; | |||
render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0]; | |||
assert(render); | |||
render->info.h264.slice_count = h->slice_num; | |||
if (render->info.h264.slice_count < 1) | |||
return; | |||
render->info.h264.is_reference = (s->current_picture_ptr->f.reference & 3) ? VDP_TRUE : VDP_FALSE; | |||
render->info.h264.field_pic_flag = s->picture_structure != PICT_FRAME; | |||
render->info.h264.bottom_field_flag = s->picture_structure == PICT_BOTTOM_FIELD; | |||
render->info.h264.is_reference = (h->cur_pic_ptr->f.reference & 3) ? VDP_TRUE : VDP_FALSE; | |||
render->info.h264.field_pic_flag = h->picture_structure != PICT_FRAME; | |||
render->info.h264.bottom_field_flag = h->picture_structure == PICT_BOTTOM_FIELD; | |||
render->info.h264.num_ref_frames = h->sps.ref_frame_count; | |||
render->info.h264.mb_adaptive_frame_field_flag = h->sps.mb_aff && !render->info.h264.field_pic_flag; | |||
render->info.h264.constrained_intra_pred_flag = h->pps.constrained_intra_pred; | |||
@@ -235,7 +227,7 @@ void ff_vdpau_h264_picture_complete(MpegEncContext *s) | |||
memcpy(render->info.h264.scaling_lists_8x8[0], h->pps.scaling_matrix8[0], sizeof(render->info.h264.scaling_lists_8x8[0])); | |||
memcpy(render->info.h264.scaling_lists_8x8[1], h->pps.scaling_matrix8[3], sizeof(render->info.h264.scaling_lists_8x8[0])); | |||
ff_mpeg_draw_horiz_band(s, 0, s->avctx->height); | |||
ff_h264_draw_horiz_band(h, 0, h->avctx->height); | |||
render->bitstream_buffers_used = 0; | |||
} | |||
@@ -287,7 +279,7 @@ void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf, | |||
render->info.mpeg.forward_reference = last->surface; | |||
} | |||
ff_vdpau_add_data_chunk(s, buf, buf_size); | |||
ff_vdpau_add_data_chunk(s->current_picture_ptr->f.data[0], buf, buf_size); | |||
render->info.mpeg.slice_count = slice_count; | |||
@@ -357,7 +349,7 @@ void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf, | |||
render->info.vc1.forward_reference = last->surface; | |||
} | |||
ff_vdpau_add_data_chunk(s, buf, buf_size); | |||
ff_vdpau_add_data_chunk(s->current_picture_ptr->f.data[0], buf, buf_size); | |||
render->info.vc1.slice_count = 1; | |||
@@ -413,7 +405,7 @@ void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf, | |||
render->info.mpeg4.forward_reference = last->surface; | |||
} | |||
ff_vdpau_add_data_chunk(s, buf, buf_size); | |||
ff_vdpau_add_data_chunk(s->current_picture_ptr->f.data[0], buf, buf_size); | |||
ff_mpeg_draw_horiz_band(s, 0, s->avctx->height); | |||
render->bitstream_buffers_used = 0; | |||
@@ -119,9 +119,8 @@ static int vdpau_h264_start_frame(AVCodecContext *avctx, | |||
{ | |||
H264Context * const h = avctx->priv_data; | |||
AVVDPAUContext *hwctx = avctx->hwaccel_context; | |||
MpegEncContext * const s = &h->s; | |||
VdpPictureInfoH264 *info = &hwctx->info.h264; | |||
Picture *pic = s->current_picture_ptr; | |||
Picture *pic = h->cur_pic_ptr; | |||
/* init VdpPictureInfoH264 */ | |||
info->slice_count = 0; | |||
@@ -129,8 +128,8 @@ static int vdpau_h264_start_frame(AVCodecContext *avctx, | |||
info->field_order_cnt[1] = h264_foc(pic->field_poc[1]); | |||
info->is_reference = h->nal_ref_idc != 0; | |||
info->frame_num = h->frame_num; | |||
info->field_pic_flag = s->picture_structure != PICT_FRAME; | |||
info->bottom_field_flag = s->picture_structure == PICT_BOTTOM_FIELD; | |||
info->field_pic_flag = h->picture_structure != PICT_FRAME; | |||
info->bottom_field_flag = h->picture_structure == PICT_BOTTOM_FIELD; | |||
info->num_ref_frames = h->sps.ref_frame_count; | |||
info->mb_adaptive_frame_field_flag = h->sps.mb_aff && !info->field_pic_flag; | |||
info->constrained_intra_pred_flag = h->pps.constrained_intra_pred; | |||
@@ -185,12 +184,27 @@ static int vdpau_h264_decode_slice(AVCodecContext *avctx, | |||
return 0; | |||
} | |||
static int vdpau_h264_end_frame(AVCodecContext *avctx) | |||
{ | |||
AVVDPAUContext *hwctx = avctx->hwaccel_context; | |||
H264Context *h = avctx->priv_data; | |||
VdpVideoSurface surf = ff_vdpau_get_surface_id(h->cur_pic_ptr); | |||
hwctx->render(hwctx->decoder, surf, (void *)&hwctx->info, | |||
hwctx->bitstream_buffers_used, hwctx->bitstream_buffers); | |||
ff_h264_draw_horiz_band(h, 0, h->avctx->height); | |||
hwctx->bitstream_buffers_used = 0; | |||
return 0; | |||
} | |||
AVHWAccel ff_h264_vdpau_hwaccel = { | |||
.name = "h264_vdpau", | |||
.type = AVMEDIA_TYPE_VIDEO, | |||
.id = AV_CODEC_ID_H264, | |||
.pix_fmt = AV_PIX_FMT_VDPAU, | |||
.start_frame = vdpau_h264_start_frame, | |||
.end_frame = ff_vdpau_common_end_frame, | |||
.end_frame = vdpau_h264_end_frame, | |||
.decode_slice = vdpau_h264_decode_slice, | |||
}; |
@@ -25,6 +25,7 @@ | |||
#define AVCODEC_VDPAU_INTERNAL_H | |||
#include <stdint.h> | |||
#include "h264.h" | |||
#include "mpegvideo.h" | |||
/** Extract VdpVideoSurface from a Picture */ | |||
@@ -35,20 +36,20 @@ static inline uintptr_t ff_vdpau_get_surface_id(Picture *pic) | |||
int ff_vdpau_common_start_frame(AVCodecContext *avctx, | |||
const uint8_t *buffer, uint32_t size); | |||
int ff_vdpau_common_end_frame(AVCodecContext *avctx); | |||
int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx); | |||
int ff_vdpau_add_buffer(AVCodecContext *avctx, | |||
const uint8_t *buf, uint32_t buf_size); | |||
void ff_vdpau_add_data_chunk(MpegEncContext *s, const uint8_t *buf, | |||
void ff_vdpau_add_data_chunk(uint8_t *data, const uint8_t *buf, | |||
int buf_size); | |||
void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf, | |||
int buf_size, int slice_count); | |||
void ff_vdpau_h264_picture_start(MpegEncContext *s); | |||
void ff_vdpau_h264_set_reference_frames(MpegEncContext *s); | |||
void ff_vdpau_h264_picture_complete(MpegEncContext *s); | |||
void ff_vdpau_h264_picture_start(H264Context *h); | |||
void ff_vdpau_h264_set_reference_frames(H264Context *h); | |||
void ff_vdpau_h264_picture_complete(H264Context *h); | |||
void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf, | |||
int buf_size); | |||
@@ -98,7 +98,7 @@ AVHWAccel ff_mpeg1_vdpau_hwaccel = { | |||
.id = AV_CODEC_ID_MPEG1VIDEO, | |||
.pix_fmt = AV_PIX_FMT_VDPAU, | |||
.start_frame = vdpau_mpeg_start_frame, | |||
.end_frame = ff_vdpau_common_end_frame, | |||
.end_frame = ff_vdpau_mpeg_end_frame, | |||
.decode_slice = vdpau_mpeg_decode_slice, | |||
}; | |||
#endif | |||
@@ -110,7 +110,7 @@ AVHWAccel ff_mpeg2_vdpau_hwaccel = { | |||
.id = AV_CODEC_ID_MPEG2VIDEO, | |||
.pix_fmt = AV_PIX_FMT_VDPAU, | |||
.start_frame = vdpau_mpeg_start_frame, | |||
.end_frame = ff_vdpau_common_end_frame, | |||
.end_frame = ff_vdpau_mpeg_end_frame, | |||
.decode_slice = vdpau_mpeg_decode_slice, | |||
}; | |||
#endif |
@@ -92,7 +92,7 @@ AVHWAccel ff_h263_vdpau_hwaccel = { | |||
.id = AV_CODEC_ID_H263, | |||
.pix_fmt = AV_PIX_FMT_VDPAU, | |||
.start_frame = vdpau_mpeg4_start_frame, | |||
.end_frame = ff_vdpau_common_end_frame, | |||
.end_frame = ff_vdpau_mpeg_end_frame, | |||
.decode_slice = vdpau_mpeg4_decode_slice, | |||
}; | |||
#endif | |||
@@ -104,7 +104,7 @@ AVHWAccel ff_mpeg4_vdpau_hwaccel = { | |||
.id = AV_CODEC_ID_MPEG4, | |||
.pix_fmt = AV_PIX_FMT_VDPAU, | |||
.start_frame = vdpau_mpeg4_start_frame, | |||
.end_frame = ff_vdpau_common_end_frame, | |||
.end_frame = ff_vdpau_mpeg_end_frame, | |||
.decode_slice = vdpau_mpeg4_decode_slice, | |||
}; | |||
#endif |
@@ -112,7 +112,7 @@ AVHWAccel ff_wmv3_vdpau_hwaccel = { | |||
.id = AV_CODEC_ID_WMV3, | |||
.pix_fmt = AV_PIX_FMT_VDPAU, | |||
.start_frame = vdpau_vc1_start_frame, | |||
.end_frame = ff_vdpau_common_end_frame, | |||
.end_frame = ff_vdpau_mpeg_end_frame, | |||
.decode_slice = vdpau_vc1_decode_slice, | |||
}; | |||
#endif | |||
@@ -123,6 +123,6 @@ AVHWAccel ff_vc1_vdpau_hwaccel = { | |||
.id = AV_CODEC_ID_VC1, | |||
.pix_fmt = AV_PIX_FMT_VDPAU, | |||
.start_frame = vdpau_vc1_start_frame, | |||
.end_frame = ff_vdpau_common_end_frame, | |||
.end_frame = ff_vdpau_mpeg_end_frame, | |||
.decode_slice = vdpau_vc1_decode_slice, | |||
}; |