23#include "config_components.h"
32#define MAX_SLICES 1024
34 DXVA_PictureParameters
pp;
45 DXVA_PictureParameters *pp)
51 memset(pp, 0,
sizeof(*pp));
52 pp->wDeblockedPictureIndex = 0;
56 pp->wForwardRefPictureIndex = 0xffff;
60 pp->wBackwardRefPictureIndex = 0xffff;
62 pp->wPicWidthInMBminus1 =
s->mb_width - 1;
63 pp->wPicHeightInMBminus1 = (
s->mb_height >> is_field) - 1;
64 pp->bMacroblockWidthMinus1 = 15;
65 pp->bMacroblockHeightMinus1 = 15;
66 pp->bBlockWidthMinus1 = 7;
67 pp->bBlockHeightMinus1 = 7;
69 pp->bPicStructure =
s->picture_structure;
70 pp->bSecondField = is_field && !
s->first_field;
73 pp->bBidirectionalAveragingMode = 0;
74 pp->bMVprecisionAndChromaRelation= 0;
75 pp->bChromaFormat =
s->chroma_format;
76 pp->bPicScanFixed = 1;
77 pp->bPicScanMethod =
s->alternate_scan ? 1 : 0;
78 pp->bPicReadbackRequests = 0;
80 pp->bPicSpatialResid8 = 0;
81 pp->bPicOverflowBlocks = 0;
82 pp->bPicExtrapolation = 0;
83 pp->bPicDeblocked = 0;
84 pp->bPicDeblockConfined = 0;
85 pp->bPic4MVallowed = 0;
89 pp->bReservedBits = 0;
90 pp->wBitstreamFcodes = (
s->mpeg_f_code[0][0] << 12) |
91 (
s->mpeg_f_code[0][1] << 8) |
92 (
s->mpeg_f_code[1][0] << 4) |
93 (
s->mpeg_f_code[1][1] );
94 pp->wBitstreamPCEelements = (
s->intra_dc_precision << 14) |
95 (
s->picture_structure << 12) |
96 (
s->top_field_first << 11) |
97 (
s->frame_pred_frame_dct << 10) |
98 (
s->concealment_motion_vectors << 9) |
99 (
s->q_scale_type << 8) |
100 (
s->intra_vlc_format << 7) |
101 (
s->alternate_scan << 6) |
102 (
s->repeat_first_field << 5) |
103 (
s->chroma_420_type << 4) |
104 (
s->progressive_frame << 3);
105 pp->bBitstreamConcealmentNeed = 0;
106 pp->bBitstreamConcealmentMethod = 0;
111 DXVA_QmatrixData *qm)
115 for (
i = 0;
i < 4;
i++)
116 qm->bNewQmatrix[
i] = 1;
117 for (
i = 0;
i < 64;
i++) {
119 qm->Qmatrix[0][
i] =
s->intra_matrix[n];
120 qm->Qmatrix[1][
i] =
s->inter_matrix[n];
121 qm->Qmatrix[2][
i] =
s->chroma_intra_matrix[n];
122 qm->Qmatrix[3][
i] =
s->chroma_inter_matrix[n];
127 DXVA_SliceInfo *slice,
135 memset(slice, 0,
sizeof(*slice));
136 slice->wHorizontalPosition =
s->mb_x;
137 slice->wVerticalPosition =
s->mb_y >> is_field;
138 slice->dwSliceBitsInBuffer = 8 *
size;
139 slice->dwSliceDataLocation = position;
140 slice->bStartCodeBitOffset = 0;
141 slice->bReservedBits = 0;
143 slice->wNumberMBsInSlice = (
s->mb_y >> is_field) *
s->mb_width +
s->mb_x;
144 slice->wBadSliceChopping = 0;
148 slice->wQuantizerScaleCode =
get_bits(&gb, 5);
160 s->cur_pic.ptr->hwaccel_picture_private;
161 const int is_field =
s->picture_structure !=
PICT_FRAME;
162 const unsigned mb_count =
s->mb_width * (
s->mb_height >> is_field);
163 void *dxva_data_ptr =
NULL;
164 uint8_t *dxva_data, *
current, *end;
171 type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
175 &dxva_size, &dxva_data_ptr)))
181 type = DXVA2_BitStreamDateBufferType;
184 &dxva_data_ptr, &dxva_size)))
192 dxva_data = dxva_data_ptr;
194 end = dxva_data + dxva_size;
198 unsigned position =
slice->dwSliceDataLocation;
199 unsigned size =
slice->dwSliceBitsInBuffer / 8;
207 slice->wNumberMBsInSlice =
208 slice[1].wNumberMBsInSlice -
slice[0].wNumberMBsInSlice;
210 slice->wNumberMBsInSlice =
211 mb_count -
slice[0].wNumberMBsInSlice;
231 D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
232 memset(dsc11, 0,
sizeof(*dsc11));
233 dsc11->BufferType =
type;
234 dsc11->DataSize =
current - dxva_data;
235 dsc11->NumMBsInBuffer = mb_count;
237 type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
242 DXVA2_DecodeBufferDesc *dsc2 = bs;
243 memset(dsc2, 0,
sizeof(*dsc2));
244 dsc2->CompressedBufferType =
type;
245 dsc2->DataSize =
current - dxva_data;
246 dsc2->NumMBsInBuffer = mb_count;
248 type = DXVA2_SliceControlBufferType;
267 s->cur_pic.ptr->hwaccel_picture_private;
287 s->cur_pic.ptr->hwaccel_picture_private;
309 s->cur_pic.ptr->hwaccel_picture_private;
315 &ctx_pic->
pp,
sizeof(ctx_pic->
pp),
316 &ctx_pic->
qm,
sizeof(ctx_pic->
qm),
323#if CONFIG_MPEG2_DXVA2_HWACCEL
325 .p.name =
"mpeg2_dxva2",
340#if CONFIG_MPEG2_D3D11VA_HWACCEL
342 .p.name =
"mpeg2_d3d11va",
357#if CONFIG_MPEG2_D3D11VA2_HWACCEL
359 .p.name =
"mpeg2_d3d11va2",
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define i(width, name, range_min, range_max)
int ff_dxva2_is_d3d11(const AVCodecContext *avctx)
unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx, AVDXVAContext *ctx, const AVFrame *frame, int curr)
int ff_dxva2_decode_init(AVCodecContext *avctx)
int ff_dxva2_commit_buffer(AVCodecContext *avctx, AVDXVAContext *ctx, DECODER_BUFFER_DESC *dsc, unsigned type, const void *data, unsigned size, unsigned mb_count)
int ff_dxva2_decode_uninit(AVCodecContext *avctx)
int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, const void *pp, unsigned pp_size, const void *qm, unsigned qm_size, int(*commit_bs_si)(AVCodecContext *, DECODER_BUFFER_DESC *bs, DECODER_BUFFER_DESC *slice))
int ff_dxva2_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, DECODER_BUFFER_DESC *bs, DECODER_BUFFER_DESC *sc)
#define DXVA_CONTEXT(avctx)
#define DXVA2_CONTEXT(ctx)
#define D3D11VA_CONTEXT(ctx)
#define DXVA_CONTEXT_VALID(avctx, ctx)
void ff_dxva2_mpeg2_fill_quantization_matrices(AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_QmatrixData *qm)
static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, DECODER_BUFFER_DESC *bs, DECODER_BUFFER_DESC *sc)
static int dxva2_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
void ff_dxva2_mpeg2_fill_picture_parameters(AVCodecContext *avctx, AVDXVAContext *ctx, DXVA_PictureParameters *pp)
static int dxva2_mpeg2_start_frame(AVCodecContext *avctx, av_unused const AVBufferRef *buffer_ref, av_unused const uint8_t *buffer, av_unused uint32_t size)
void ff_dxva2_mpeg2_fill_slice(AVCodecContext *avctx, DXVA_SliceInfo *slice, unsigned position, const uint8_t *buffer, unsigned size)
static int dxva2_mpeg2_end_frame(AVCodecContext *avctx)
static struct @111144215057303131116103221376075045141373005341 current
static int skip_1stop_8data_bits(GetBitContext *gb)
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
const struct FFHWAccel ff_mpeg2_d3d11va_hwaccel
const struct FFHWAccel ff_mpeg2_dxva2_hwaccel
const struct FFHWAccel ff_mpeg2_d3d11va2_hwaccel
static const chunk_decoder decoder[8]
const uint8_t ff_zigzag_direct[64]
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
mpegvideo decoder header.
@ AV_PIX_FMT_DXVA2_VLD
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer.
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
@ AV_PIX_FMT_D3D11VA_VLD
HW decoding through Direct3D11 via old API, Picture.data[3] contains a ID3D11VideoDecoderOutputView p...
A reference to a data buffer.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
struct AVCodecContext * avctx
DXVA_SliceInfo slice[MAX_SLICES]
const uint8_t * bitstream
#define avpriv_request_sample(...)
static AVFormatContext * ctx