Commit 2c541554 authored by Anton Khirnov's avatar Anton Khirnov

h264: deMpegEncContextize

Most of the changes are just trivial are just trivial replacements of
fields from MpegEncContext with equivalent fields in H264Context.
Everything in h264* other than h264.c are those trivial changes.

The nontrivial parts are:
1) extracting a simplified version of the frame management code from
   mpegvideo.c. We don't need last/next_picture anymore, since h264 uses
   its own more complex system already and those were set only to appease
   the mpegvideo parts.
2) some tables that need to be allocated/freed in appropriate places.
3) hwaccels -- mostly trivial replacements.
   for dxva, the draw_horiz_band() call is moved from
   ff_dxva2_common_end_frame() to per-codec end_frame() callbacks,
   because it's now different for h264 and MpegEncContext-based
   decoders.
4) svq3 -- it does not use h264 complex reference system, so I just
   added some very simplistic frame management instead and dropped the
   use of ff_h264_frame_start(). Because of this I also had to move some
   initialization code to svq3.

Additional fixes for chroma format and bit depth changes by
Janne Grunau <janne-libav@jannau.net>
Signed-off-by: 's avatarAnton Khirnov <anton@khirnov.net>
parent 1d0feb5d
......@@ -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 Libav) */
(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 Libav */
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 = {
......
......@@ -47,7 +47,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 = {
......
......@@ -254,14 +254,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
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -30,6 +30,7 @@
#include "libavutil/intreadwrite.h"
#include "cabac.h"
#include "get_bits.h"
#include "mpegvideo.h"
#include "h264chroma.h"
#include "h264dsp.h"
......@@ -60,7 +61,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
......@@ -250,15 +251,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;
......@@ -348,6 +376,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];
......@@ -424,6 +454,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;
......@@ -448,7 +485,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];
......@@ -521,12 +559,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;
/** @} */
......@@ -578,6 +620,8 @@ typedef struct H264Context {
int cur_chroma_format_idc;
uint8_t *bipred_scratchpad;
uint8_t *edge_emu_buffer;
int16_t *dc_val_base;
} H264Context;
extern const uint8_t ff_h264_chroma_qp[3][QP_MAX_NUM + 1]; ///< One chroma qp table for each supported bit depth (8, 9, 10).
......@@ -786,7 +830,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;
......@@ -820,7 +864,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]);
......@@ -829,12 +873,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);
......@@ -855,7 +898,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]];
......@@ -866,19 +909,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)) {
......@@ -902,4 +944,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 */
This diff is collapsed.
This diff is collapsed.
......@@ -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
......
......@@ -244,8 +244,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 = !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY));
int chroma = !(CONFIG_GRAY && (h->flags&CODEC_FLAG_GRAY));
int chroma444 = CHROMA444;
int chroma422 = CHROMA422;
......@@ -257,10 +256,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 );
......@@ -465,7 +464,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;
......@@ -493,16 +491,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]);
......@@ -517,12 +515,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);
......@@ -540,7 +538,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 {
......@@ -582,10 +580,10 @@ 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 ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
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 ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
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) {
......@@ -665,8 +663,8 @@ 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 ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
qp = h->cur_pic.f.qscale_table[mb_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);
if( dir == 0 ) {
filter_mb_edgev( &img_y[4*edge << h->pixel_shift], linesize, bS, qp, a, b, h, 0 );
if (chroma) {
......@@ -703,13 +701,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 = !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY));
int 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;
......@@ -761,9 +758,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;
......@@ -776,8 +773,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 );
......
This diff is collapsed.
......@@ -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];
assert(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);
......
This diff is collapsed.
......@@ -36,7 +36,7 @@ static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_si
{
int i;
uint32_t state;
ParseContext *pc = &(h->s.parse_context);
ParseContext *pc = &h->parse_context;
// mb_addr= pc->mb_addr - 1;
state= pc->state;
if(state>13)
......@@ -119,7 +119,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;
......@@ -147,13 +147,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);
......@@ -162,40 +162,40 @@ static inline int parse_nal_units(AVCodecParserContext *s,
s->key_frame = 1;
/* fall through */
case NAL_SLICE:
get_ue_golomb(&h->s.gb); // skip first_mb_in_slice
slice_type = get_ue_golomb_31(&h->s.gb);
get_ue_golomb(&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;
}
}
......@@ -221,11 +221,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 */
......@@ -233,7 +233,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
buf += consumed;
}
/* didn't find a picture! */
av_log(h->s.avctx, AV_LOG_ERROR, "missing picture in access unit\n");
av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit\n");
return -1;
}
......@@ -243,20 +243,20 @@ 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 the decoder.
// otherwise opening the parser, creating extradata,
// and then closing and opening again
// will cause has_b_frames to be always set.
// NB: estimate_timings_from_pts behaves exactly like this.
if (!avctx->has_b_frames)
h->s.low_delay = 1;
h->low_delay = 1;
ff_h264_decode_extradata(h);
}
}
......@@ -326,7 +326,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);
......@@ -336,7 +336,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;
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -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(&s->gb, h->sps.cpb_removal_delay_length);
h->sei_dpb_output_delay = get_bits(&s->gb, h->sps.dpb_output_delay_length);
h->sei_cpb_removal_delay = get_bits(&h->gb, h->sps.cpb_removal_delay_length);
h->sei_dpb_output_delay = get_bits(&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_unregistered_user_data(H264Context *h, int size){
MpegEncContext * const s = &h->s;
uint8_t user_data[16+256];
int e, build, i;
......@@ -104,7 +102,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;
......@@ -112,33 +110,30 @@ static int decode_unregistered_user_data(H264Context *h, int size){
if(e==1 && build>0)
h->x264_build= build;
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];
......@@ -146,14 +141,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(&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(&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(&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(&h->gb, sps->initial_cpb_removal_delay_length);
skip_bits(&h->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset
}
}
......@@ -162,20 +157,18 @@ 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{
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{
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);
switch(type){
case SEI_TYPE_PIC_TIMING: // Picture timing SEI
......@@ -195,11 +188,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;
......
......@@ -399,8 +399,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,
const int chroma_format_idc)
{
// MpegEncContext * const s = &h->s;
#undef FUNC
#undef FUNCC
#define FUNC(a, depth) a ## _ ## depth
......
......@@ -141,7 +141,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)
} Picture;
......
This diff is collapsed.
......@@ -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;
......@@ -289,10 +288,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. */
......@@ -301,7 +314,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);
......@@ -310,14 +322,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,
};
......@@ -241,7 +241,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,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment