29 #define MAX_SLICES 1024
31 DXVA_PictureParameters
pp;
43 DXVA_PictureParameters *pp)
45 const Picture *current_picture =
s->current_picture_ptr;
48 memset(pp, 0,
sizeof(*pp));
50 pp->wDeblockedPictureIndex = 0;
54 pp->wForwardRefPictureIndex = 0xffff;
58 pp->wBackwardRefPictureIndex = 0xffff;
59 pp->wPicWidthInMBminus1 =
s->mb_width - 1;
60 pp->wPicHeightInMBminus1 = (
s->mb_height >> is_field) - 1;
61 pp->bMacroblockWidthMinus1 = 15;
62 pp->bMacroblockHeightMinus1 = 15;
63 pp->bBlockWidthMinus1 = 7;
64 pp->bBlockHeightMinus1 = 7;
66 pp->bPicStructure =
s->picture_structure;
67 pp->bSecondField = is_field && !
s->first_field;
70 pp->bBidirectionalAveragingMode = 0;
71 pp->bMVprecisionAndChromaRelation= 0;
72 pp->bChromaFormat =
s->chroma_format;
73 pp->bPicScanFixed = 1;
74 pp->bPicScanMethod =
s->alternate_scan ? 1 : 0;
75 pp->bPicReadbackRequests = 0;
77 pp->bPicSpatialResid8 = 0;
78 pp->bPicOverflowBlocks = 0;
79 pp->bPicExtrapolation = 0;
80 pp->bPicDeblocked = 0;
81 pp->bPicDeblockConfined = 0;
82 pp->bPic4MVallowed = 0;
86 pp->bReservedBits = 0;
87 pp->wBitstreamFcodes = (
s->mpeg_f_code[0][0] << 12) |
88 (
s->mpeg_f_code[0][1] << 8) |
89 (
s->mpeg_f_code[1][0] << 4) |
90 (
s->mpeg_f_code[1][1] );
91 pp->wBitstreamPCEelements = (
s->intra_dc_precision << 14) |
92 (
s->picture_structure << 12) |
93 (
s->top_field_first << 11) |
94 (
s->frame_pred_frame_dct << 10) |
95 (
s->concealment_motion_vectors << 9) |
96 (
s->q_scale_type << 8) |
97 (
s->intra_vlc_format << 7) |
98 (
s->alternate_scan << 6) |
99 (
s->repeat_first_field << 5) |
100 (
s->chroma_420_type << 4) |
101 (
s->progressive_frame << 3);
102 pp->bBitstreamConcealmentNeed = 0;
103 pp->bBitstreamConcealmentMethod = 0;
109 DXVA_QmatrixData *qm)
112 for (
i = 0;
i < 4;
i++)
113 qm->bNewQmatrix[
i] = 1;
114 for (
i = 0;
i < 64;
i++) {
116 qm->Qmatrix[0][
i] =
s->intra_matrix[n];
117 qm->Qmatrix[1][
i] =
s->inter_matrix[n];
118 qm->Qmatrix[2][
i] =
s->chroma_intra_matrix[n];
119 qm->Qmatrix[3][
i] =
s->chroma_inter_matrix[n];
125 DXVA_SliceInfo *slice,
132 memset(slice, 0,
sizeof(*slice));
133 slice->wHorizontalPosition =
s->mb_x;
134 slice->wVerticalPosition =
s->mb_y >> is_field;
135 slice->dwSliceBitsInBuffer = 8 *
size;
136 slice->dwSliceDataLocation = position;
137 slice->bStartCodeBitOffset = 0;
138 slice->bReservedBits = 0;
140 slice->wNumberMBsInSlice = (
s->mb_y >> is_field) *
s->mb_width +
s->mb_x;
141 slice->wBadSliceChopping = 0;
145 slice->wQuantizerScaleCode =
get_bits(&gb, 5);
157 s->current_picture_ptr->hwaccel_picture_private;
158 const int is_field =
s->picture_structure !=
PICT_FRAME;
159 const unsigned mb_count =
s->mb_width * (
s->mb_height >> is_field);
161 uint8_t *dxva_data, *current, *end;
168 type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
172 &dxva_size, &dxva_data_ptr)))
178 type = DXVA2_BitStreamDateBufferType;
181 &dxva_data_ptr, &dxva_size)))
186 dxva_data = dxva_data_ptr;
188 end = dxva_data + dxva_size;
192 unsigned position =
slice->dwSliceDataLocation;
193 unsigned size =
slice->dwSliceBitsInBuffer / 8;
194 if (
size > end - current) {
198 slice->dwSliceDataLocation = current - dxva_data;
201 slice->wNumberMBsInSlice =
202 slice[1].wNumberMBsInSlice -
slice[0].wNumberMBsInSlice;
204 slice->wNumberMBsInSlice =
205 mb_count -
slice[0].wNumberMBsInSlice;
225 D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
226 memset(dsc11, 0,
sizeof(*dsc11));
227 dsc11->BufferType =
type;
228 dsc11->DataSize = current - dxva_data;
229 dsc11->NumMBsInBuffer = mb_count;
231 type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
236 DXVA2_DecodeBufferDesc *dsc2 = bs;
237 memset(dsc2, 0,
sizeof(*dsc2));
238 dsc2->CompressedBufferType =
type;
239 dsc2->DataSize = current - dxva_data;
240 dsc2->NumMBsInBuffer = mb_count;
242 type = DXVA2_SliceControlBufferType;
260 s->current_picture_ptr->hwaccel_picture_private;
262 if (!DXVA_CONTEXT_VALID(avctx,
ctx))
280 s->current_picture_ptr->hwaccel_picture_private;
302 s->current_picture_ptr->hwaccel_picture_private;
308 &ctx_pic->
pp,
sizeof(ctx_pic->
pp),
309 &ctx_pic->
qm,
sizeof(ctx_pic->
qm),
316 #if CONFIG_MPEG2_DXVA2_HWACCEL
318 .
name =
"mpeg2_dxva2",
333 #if CONFIG_MPEG2_D3D11VA_HWACCEL
335 .
name =
"mpeg2_d3d11va",
350 #if CONFIG_MPEG2_D3D11VA2_HWACCEL
352 .
name =
"mpeg2_d3d11va2",
int ff_dxva2_is_d3d11(const AVCodecContext *avctx)
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)
unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx, const AVDXVAContext *ctx, const AVFrame *frame)
#define DXVA_CONTEXT(avctx)
#define DXVA2_CONTEXT(ctx)
#define D3D11VA_CONTEXT(ctx)
static void fill_slice(AVCodecContext *avctx, const struct MpegEncContext *s, DXVA_SliceInfo *slice, unsigned position, const uint8_t *buffer, unsigned size)
static void fill_picture_parameters(AVCodecContext *avctx, AVDXVAContext *ctx, const struct MpegEncContext *s, DXVA_PictureParameters *pp)
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)
static int dxva2_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
static void fill_quantization_matrices(AVCodecContext *avctx, AVDXVAContext *ctx, const struct MpegEncContext *s, DXVA_QmatrixData *qm)
static int dxva2_mpeg2_end_frame(AVCodecContext *avctx)
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 AVHWAccel ff_mpeg2_dxva2_hwaccel
const AVHWAccel ff_mpeg2_d3d11va2_hwaccel
const AVHWAccel ff_mpeg2_d3d11va_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)
@ 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...
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
const char * name
Name of the hardware accelerated codec.
struct AVCodecContext * avctx
DXVA_SliceInfo slice[MAX_SLICES]
DXVA_PictureParameters pp
const uint8_t * bitstream
#define avpriv_request_sample(...)