27 #define MAX_SLICES 1024
29 DXVA_PictureParameters
pp;
41 DXVA_PictureParameters *pp)
46 memset(pp, 0,
sizeof(*pp));
48 pp->wDeblockedPictureIndex = 0;
52 pp->wForwardRefPictureIndex = 0xffff;
56 pp->wBackwardRefPictureIndex = 0xffff;
57 pp->wPicWidthInMBminus1 = s->
mb_width - 1;
58 pp->wPicHeightInMBminus1 = (s->
mb_height >> is_field) - 1;
59 pp->bMacroblockWidthMinus1 = 15;
60 pp->bMacroblockHeightMinus1 = 15;
61 pp->bBlockWidthMinus1 = 7;
62 pp->bBlockHeightMinus1 = 7;
68 pp->bBidirectionalAveragingMode = 0;
69 pp->bMVprecisionAndChromaRelation= 0;
71 pp->bPicScanFixed = 1;
73 pp->bPicReadbackRequests = 0;
75 pp->bPicSpatialResid8 = 0;
76 pp->bPicOverflowBlocks = 0;
77 pp->bPicExtrapolation = 0;
78 pp->bPicDeblocked = 0;
79 pp->bPicDeblockConfined = 0;
80 pp->bPic4MVallowed = 0;
84 pp->bReservedBits = 0;
85 pp->wBitstreamFcodes = (s->
mpeg_f_code[0][0] << 12) |
100 pp->bBitstreamConcealmentNeed = 0;
101 pp->bBitstreamConcealmentMethod = 0;
107 DXVA_QmatrixData *qm)
110 for (i = 0; i < 4; i++)
111 qm->bNewQmatrix[i] = 1;
112 for (i = 0; i < 64; i++) {
123 DXVA_SliceInfo *slice,
130 memset(slice, 0,
sizeof(*slice));
131 slice->wHorizontalPosition = s->
mb_x;
132 slice->wVerticalPosition = s->
mb_y >> is_field;
133 slice->dwSliceBitsInBuffer = 8 *
size;
134 slice->dwSliceDataLocation = position;
135 slice->bStartCodeBitOffset = 0;
136 slice->bReservedBits = 0;
139 slice->wBadSliceChopping = 0;
143 slice->wQuantizerScaleCode =
get_bits(&gb, 5);
166 type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
167 if (
FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context,
170 &dxva_size, &dxva_data_ptr)))
176 type = DXVA2_BitStreamDateBufferType;
177 if (
FAILED(IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(ctx)->
decoder,
179 &dxva_data_ptr, &dxva_size)))
184 dxva_data = dxva_data_ptr;
186 end = dxva_data + dxva_size;
190 unsigned position = slice->dwSliceDataLocation;
191 unsigned size = slice->dwSliceBitsInBuffer / 8;
192 if (size > end - current) {
196 slice->dwSliceDataLocation = current - dxva_data;
199 slice->wNumberMBsInSlice =
200 slice[1].wNumberMBsInSlice - slice[0].wNumberMBsInSlice;
202 slice->wNumberMBsInSlice =
203 mb_count - slice[0].wNumberMBsInSlice;
205 memcpy(current, &ctx_pic->
bitstream[position], size);
210 if (
FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->
decoder, type)))
215 if (
FAILED(IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(ctx)->
decoder, type)))
223 D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
224 memset(dsc11, 0,
sizeof(*dsc11));
225 dsc11->BufferType =
type;
226 dsc11->DataSize = current - dxva_data;
227 dsc11->NumMBsInBuffer = mb_count;
229 type = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
234 DXVA2_DecodeBufferDesc *dsc2 = bs;
235 memset(dsc2, 0,
sizeof(*dsc2));
236 dsc2->CompressedBufferType =
type;
237 dsc2->DataSize = current - dxva_data;
238 dsc2->NumMBsInBuffer = mb_count;
240 type = DXVA2_SliceControlBufferType;
260 if (DXVA_CONTEXT_DECODER(avctx, ctx) ==
NULL ||
261 DXVA_CONTEXT_CFG(avctx, ctx) ==
NULL ||
262 DXVA_CONTEXT_COUNT(avctx, ctx) <= 0)
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",
329 #if CONFIG_MPEG2_D3D11VA_HWACCEL
331 .
name =
"mpeg2_d3d11va",
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
uint16_t chroma_intra_matrix[64]
uint16_t chroma_inter_matrix[64]
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int dxva2_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
DXVA_PictureParameters pp
static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, DECODER_BUFFER_DESC *bs, DECODER_BUFFER_DESC *sc)
DXVA_SliceInfo slice[MAX_SLICES]
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
void * hwaccel_context
Hardware accelerator context.
static av_cold int end(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))
static int get_bits_count(const GetBitContext *s)
static int dxva2_mpeg2_end_frame(AVCodecContext *avctx)
int mb_height
number of MBs horizontally & vertically
static void fill_picture_parameters(AVCodecContext *avctx, AVDXVAContext *ctx, const struct MpegEncContext *s, DXVA_PictureParameters *pp)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int dxva2_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
const char * name
Name of the hardware accelerated codec.
static const chunk_decoder decoder[8]
Picture * current_picture_ptr
pointer to the current picture
void * hwaccel_picture_private
hardware accelerator private data
uint8_t idct_permutation[64]
IDCT input permutation.
static void fill_quantization_matrices(AVCodecContext *avctx, AVDXVAContext *ctx, const struct MpegEncContext *s, DXVA_QmatrixData *qm)
static void fill_slice(AVCodecContext *avctx, const struct MpegEncContext *s, DXVA_SliceInfo *slice, unsigned position, const uint8_t *buffer, unsigned size)
preferred ID for MPEG-1/2 video decoding
int first_field
is 1 for the first field of a field picture 0 otherwise
uint16_t inter_matrix[64]
int concealment_motion_vectors
unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx, const AVDXVAContext *ctx, const AVFrame *frame)
main external API structure.
int ff_dxva2_commit_buffer(AVCodecContext *avctx, AVDXVAContext *ctx, DECODER_BUFFER_DESC *dsc, unsigned type, const void *data, unsigned size, unsigned mb_count)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
const uint8_t ff_zigzag_direct[64]
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
const uint8_t * bitstream
Picture last_picture
copy of the previous picture structure.
Picture next_picture
copy of the next picture structure.
uint16_t intra_matrix[64]
matrix transmitted in the bitstream
static int skip_1stop_8data_bits(GetBitContext *gb)
HW decoding through Direct3D11, Picture.data[3] contains a ID3D11VideoDecoderOutputView pointer...