Commit 4dec101a authored by wm4's avatar wm4 Committed by Diego Biurrun

dxva: preparations for new hwaccel API

The actual hwaccel code will need to access an internal context instead
of avctx->hwaccel_context, so add a new DXVA_CONTEXT() macro, that will
dispatch between the "old" external and the new internal context.

Also, the new API requires a new D3D11 pixfmt, so all places which check
for the pixfmt need to be adjusted. Introduce a ff_dxva2_is_d3d11()
function, which does the check.
Signed-off-by: 's avatarDiego Biurrun <diego@biurrun.de>
parent bd747b92
...@@ -71,7 +71,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, ...@@ -71,7 +71,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx,
HRESULT hr; HRESULT hr;
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) if (ff_dxva2_is_d3d11(avctx))
hr = ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, hr = ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context,
D3D11VA_CONTEXT(ctx)->decoder, D3D11VA_CONTEXT(ctx)->decoder,
type, type,
...@@ -91,7 +91,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, ...@@ -91,7 +91,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx,
memcpy(dxva_data, data, size); memcpy(dxva_data, data, size);
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = dsc; D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = dsc;
memset(dsc11, 0, sizeof(*dsc11)); memset(dsc11, 0, sizeof(*dsc11));
dsc11->BufferType = type; dsc11->BufferType = type;
...@@ -116,7 +116,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, ...@@ -116,7 +116,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx,
} }
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) if (ff_dxva2_is_d3d11(avctx))
hr = ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type); hr = ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type);
#endif #endif
#if CONFIG_DXVA2 #if CONFIG_DXVA2
...@@ -139,7 +139,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -139,7 +139,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
DECODER_BUFFER_DESC *bs, DECODER_BUFFER_DESC *bs,
DECODER_BUFFER_DESC *slice)) DECODER_BUFFER_DESC *slice))
{ {
AVDXVAContext *ctx = avctx->hwaccel_context; AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
unsigned buffer_count = 0; unsigned buffer_count = 0;
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
D3D11_VIDEO_DECODER_BUFFER_DESC buffer11[4]; D3D11_VIDEO_DECODER_BUFFER_DESC buffer11[4];
...@@ -154,7 +154,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -154,7 +154,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
do { do {
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
WaitForSingleObjectEx(D3D11VA_CONTEXT(ctx)->context_mutex, INFINITE, FALSE); WaitForSingleObjectEx(D3D11VA_CONTEXT(ctx)->context_mutex, INFINITE, FALSE);
hr = ID3D11VideoContext_DecoderBeginFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, hr = ID3D11VideoContext_DecoderBeginFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder,
...@@ -171,7 +171,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -171,7 +171,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
if (hr != E_PENDING || ++runs > 50) if (hr != E_PENDING || ++runs > 50)
break; break;
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) if (ff_dxva2_is_d3d11(avctx))
if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex); ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);
#endif #endif
...@@ -181,7 +181,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -181,7 +181,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
if (FAILED(hr)) { if (FAILED(hr)) {
av_log(avctx, AV_LOG_ERROR, "Failed to begin frame: 0x%x\n", hr); av_log(avctx, AV_LOG_ERROR, "Failed to begin frame: 0x%x\n", hr);
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) if (ff_dxva2_is_d3d11(avctx))
if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex); ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);
#endif #endif
...@@ -189,7 +189,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -189,7 +189,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
} }
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
buffer = &buffer11[buffer_count]; buffer = &buffer11[buffer_count];
type = D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS; type = D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS;
} }
...@@ -212,7 +212,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -212,7 +212,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
if (qm_size > 0) { if (qm_size > 0) {
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
buffer = &buffer11[buffer_count]; buffer = &buffer11[buffer_count];
type = D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX; type = D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX;
} }
...@@ -235,7 +235,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -235,7 +235,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
} }
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
buffer = &buffer11[buffer_count + 0]; buffer = &buffer11[buffer_count + 0];
buffer_slice = &buffer11[buffer_count + 1]; buffer_slice = &buffer11[buffer_count + 1];
} }
...@@ -262,7 +262,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -262,7 +262,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
assert(buffer_count == 1 + (qm_size > 0) + 2); assert(buffer_count == 1 + (qm_size > 0) + 2);
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) if (ff_dxva2_is_d3d11(avctx))
hr = ID3D11VideoContext_SubmitDecoderBuffers(D3D11VA_CONTEXT(ctx)->video_context, hr = ID3D11VideoContext_SubmitDecoderBuffers(D3D11VA_CONTEXT(ctx)->video_context,
D3D11VA_CONTEXT(ctx)->decoder, D3D11VA_CONTEXT(ctx)->decoder,
buffer_count, buffer11); buffer_count, buffer11);
...@@ -284,7 +284,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -284,7 +284,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
end: end:
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
hr = ID3D11VideoContext_DecoderEndFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder); hr = ID3D11VideoContext_DecoderEndFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder);
if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex); ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);
...@@ -301,3 +301,11 @@ end: ...@@ -301,3 +301,11 @@ end:
return result; return result;
} }
int ff_dxva2_is_d3d11(const AVCodecContext *avctx)
{
if (CONFIG_D3D11VA)
return avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD;
else
return 0;
}
...@@ -220,7 +220,7 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, ...@@ -220,7 +220,7 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice,
{ {
const H264Context *h = avctx->priv_data; const H264Context *h = avctx->priv_data;
H264SliceContext *sl = &h->slice_ctx[0]; H264SliceContext *sl = &h->slice_ctx[0];
AVDXVAContext *ctx = avctx->hwaccel_context; AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
unsigned list; unsigned list;
memset(slice, 0, sizeof(*slice)); memset(slice, 0, sizeof(*slice));
...@@ -302,7 +302,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -302,7 +302,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
{ {
const H264Context *h = avctx->priv_data; const H264Context *h = avctx->priv_data;
const unsigned mb_count = h->mb_width * h->mb_height; const unsigned mb_count = h->mb_width * h->mb_height;
AVDXVAContext *ctx = avctx->hwaccel_context; AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
const H264Picture *current_picture = h->cur_pic_ptr; const H264Picture *current_picture = h->cur_pic_ptr;
struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private; struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
DXVA_Slice_H264_Short *slice = NULL; DXVA_Slice_H264_Short *slice = NULL;
...@@ -317,7 +317,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -317,7 +317,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
/* Create an annex B bitstream buffer with only slice NAL and finalize slice */ /* Create an annex B bitstream buffer with only slice NAL and finalize slice */
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM; type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context,
D3D11VA_CONTEXT(ctx)->decoder, D3D11VA_CONTEXT(ctx)->decoder,
...@@ -388,7 +388,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -388,7 +388,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
slice->SliceBytesInBuffer += padding; slice->SliceBytesInBuffer += padding;
} }
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) if (ff_dxva2_is_d3d11(avctx))
if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type))) if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type)))
return -1; return -1;
#endif #endif
...@@ -401,7 +401,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -401,7 +401,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
return -1; return -1;
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs; D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
memset(dsc11, 0, sizeof(*dsc11)); memset(dsc11, 0, sizeof(*dsc11));
dsc11->BufferType = type; dsc11->BufferType = type;
...@@ -442,7 +442,7 @@ static int dxva2_h264_start_frame(AVCodecContext *avctx, ...@@ -442,7 +442,7 @@ static int dxva2_h264_start_frame(AVCodecContext *avctx,
av_unused uint32_t size) av_unused uint32_t size)
{ {
const H264Context *h = avctx->priv_data; const H264Context *h = avctx->priv_data;
AVDXVAContext *ctx = avctx->hwaccel_context; AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
struct dxva2_picture_context *ctx_pic = h->cur_pic_ptr->hwaccel_picture_private; struct dxva2_picture_context *ctx_pic = h->cur_pic_ptr->hwaccel_picture_private;
if (!DXVA_CONTEXT_VALID(avctx, ctx)) if (!DXVA_CONTEXT_VALID(avctx, ctx))
...@@ -467,7 +467,7 @@ static int dxva2_h264_decode_slice(AVCodecContext *avctx, ...@@ -467,7 +467,7 @@ static int dxva2_h264_decode_slice(AVCodecContext *avctx,
{ {
const H264Context *h = avctx->priv_data; const H264Context *h = avctx->priv_data;
const H264SliceContext *sl = &h->slice_ctx[0]; const H264SliceContext *sl = &h->slice_ctx[0];
AVDXVAContext *ctx = avctx->hwaccel_context; AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
const H264Picture *current_picture = h->cur_pic_ptr; const H264Picture *current_picture = h->cur_pic_ptr;
struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private; struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
unsigned position; unsigned position;
......
...@@ -243,7 +243,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -243,7 +243,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
DECODER_BUFFER_DESC *sc) DECODER_BUFFER_DESC *sc)
{ {
const HEVCContext *h = avctx->priv_data; const HEVCContext *h = avctx->priv_data;
AVDXVAContext *ctx = avctx->hwaccel_context; AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
const HEVCFrame *current_picture = h->ref; const HEVCFrame *current_picture = h->ref;
struct hevc_dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private; struct hevc_dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
DXVA_Slice_HEVC_Short *slice = NULL; DXVA_Slice_HEVC_Short *slice = NULL;
...@@ -258,7 +258,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -258,7 +258,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
/* Create an annex B bitstream buffer with only slice NAL and finalize slice */ /* Create an annex B bitstream buffer with only slice NAL and finalize slice */
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM; type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context,
D3D11VA_CONTEXT(ctx)->decoder, D3D11VA_CONTEXT(ctx)->decoder,
...@@ -312,7 +312,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -312,7 +312,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
slice->SliceBytesInBuffer += padding; slice->SliceBytesInBuffer += padding;
} }
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) if (ff_dxva2_is_d3d11(avctx))
if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type))) if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type)))
return -1; return -1;
#endif #endif
...@@ -325,7 +325,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -325,7 +325,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
return -1; return -1;
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs; D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
memset(dsc11, 0, sizeof(*dsc11)); memset(dsc11, 0, sizeof(*dsc11));
dsc11->BufferType = type; dsc11->BufferType = type;
...@@ -362,7 +362,7 @@ static int dxva2_hevc_start_frame(AVCodecContext *avctx, ...@@ -362,7 +362,7 @@ static int dxva2_hevc_start_frame(AVCodecContext *avctx,
av_unused uint32_t size) av_unused uint32_t size)
{ {
const HEVCContext *h = avctx->priv_data; const HEVCContext *h = avctx->priv_data;
AVDXVAContext *ctx = avctx->hwaccel_context; AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
struct hevc_dxva2_picture_context *ctx_pic = h->ref->hwaccel_picture_private; struct hevc_dxva2_picture_context *ctx_pic = h->ref->hwaccel_picture_private;
if (!DXVA_CONTEXT_VALID(avctx, ctx)) if (!DXVA_CONTEXT_VALID(avctx, ctx))
......
...@@ -59,21 +59,23 @@ typedef union { ...@@ -59,21 +59,23 @@ typedef union {
#endif #endif
} AVDXVAContext; } AVDXVAContext;
#define DXVA_CONTEXT(avctx) ((AVDXVAContext *)(avctx)->hwaccel_context)
#define D3D11VA_CONTEXT(ctx) (&ctx->d3d11va) #define D3D11VA_CONTEXT(ctx) (&ctx->d3d11va)
#define DXVA2_CONTEXT(ctx) (&ctx->dxva2) #define DXVA2_CONTEXT(ctx) (&ctx->dxva2)
#if CONFIG_D3D11VA && CONFIG_DXVA2 #if CONFIG_D3D11VA && CONFIG_DXVA2
#define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.workaround : ctx->dxva2.workaround) #define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.workaround : ctx->dxva2.workaround)
#define DXVA_CONTEXT_COUNT(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.surface_count : ctx->dxva2.surface_count) #define DXVA_CONTEXT_COUNT(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.surface_count : ctx->dxva2.surface_count)
#define DXVA_CONTEXT_DECODER(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.decoder : ctx->dxva2.decoder) #define DXVA_CONTEXT_DECODER(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.decoder : ctx->dxva2.decoder)
#define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*(avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? &ctx->d3d11va.report_id : &ctx->dxva2.report_id)) #define DXVA_CONTEXT_REPORT_ID(avctx, ctx) (*(ff_dxva2_is_d3d11(avctx) ? &ctx->d3d11va.report_id : &ctx->dxva2.report_id))
#define DXVA_CONTEXT_CFG(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg : ctx->dxva2.cfg) #define DXVA_CONTEXT_CFG(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg : ctx->dxva2.cfg)
#define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg->ConfigBitstreamRaw : ctx->dxva2.cfg->ConfigBitstreamRaw) #define DXVA_CONTEXT_CFG_BITSTREAM(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigBitstreamRaw : ctx->dxva2.cfg->ConfigBitstreamRaw)
#define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg->ConfigIntraResidUnsigned : ctx->dxva2.cfg->ConfigIntraResidUnsigned) #define DXVA_CONTEXT_CFG_INTRARESID(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigIntraResidUnsigned : ctx->dxva2.cfg->ConfigIntraResidUnsigned)
#define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg->ConfigResidDiffAccelerator : ctx->dxva2.cfg->ConfigResidDiffAccelerator) #define DXVA_CONTEXT_CFG_RESIDACCEL(avctx, ctx) (ff_dxva2_is_d3d11(avctx) ? ctx->d3d11va.cfg->ConfigResidDiffAccelerator : ctx->dxva2.cfg->ConfigResidDiffAccelerator)
#define DXVA_CONTEXT_VALID(avctx, ctx) (DXVA_CONTEXT_DECODER(avctx, ctx) && \ #define DXVA_CONTEXT_VALID(avctx, ctx) (DXVA_CONTEXT_DECODER(avctx, ctx) && \
DXVA_CONTEXT_CFG(avctx, ctx) && \ DXVA_CONTEXT_CFG(avctx, ctx) && \
(avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD || ctx->dxva2.surface_count)) (ff_dxva2_is_d3d11(avctx) || ctx->dxva2.surface_count))
#elif CONFIG_DXVA2 #elif CONFIG_DXVA2
#define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (ctx->dxva2.workaround) #define DXVA_CONTEXT_WORKAROUND(avctx, ctx) (ctx->dxva2.workaround)
#define DXVA_CONTEXT_COUNT(avctx, ctx) (ctx->dxva2.surface_count) #define DXVA_CONTEXT_COUNT(avctx, ctx) (ctx->dxva2.surface_count)
...@@ -113,4 +115,6 @@ int ff_dxva2_common_end_frame(AVCodecContext *, AVFrame *, ...@@ -113,4 +115,6 @@ int ff_dxva2_common_end_frame(AVCodecContext *, AVFrame *,
DECODER_BUFFER_DESC *bs, DECODER_BUFFER_DESC *bs,
DECODER_BUFFER_DESC *slice)); DECODER_BUFFER_DESC *slice));
int ff_dxva2_is_d3d11(const AVCodecContext *avctx);
#endif /* AVCODEC_DXVA2_INTERNAL_H */ #endif /* AVCODEC_DXVA2_INTERNAL_H */
...@@ -156,7 +156,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -156,7 +156,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
DECODER_BUFFER_DESC *sc) DECODER_BUFFER_DESC *sc)
{ {
const struct MpegEncContext *s = avctx->priv_data; const struct MpegEncContext *s = avctx->priv_data;
AVDXVAContext *ctx = avctx->hwaccel_context; AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
struct dxva2_picture_context *ctx_pic = struct dxva2_picture_context *ctx_pic =
s->current_picture_ptr->hwaccel_picture_private; s->current_picture_ptr->hwaccel_picture_private;
const int is_field = s->picture_structure != PICT_FRAME; const int is_field = s->picture_structure != PICT_FRAME;
...@@ -168,7 +168,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -168,7 +168,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
unsigned type; unsigned type;
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM; type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context,
D3D11VA_CONTEXT(ctx)->decoder, D3D11VA_CONTEXT(ctx)->decoder,
...@@ -212,7 +212,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -212,7 +212,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
current += size; current += size;
} }
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) if (ff_dxva2_is_d3d11(avctx))
if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type))) if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type)))
return -1; return -1;
#endif #endif
...@@ -225,7 +225,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -225,7 +225,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
return -1; return -1;
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs; D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
memset(dsc11, 0, sizeof(*dsc11)); memset(dsc11, 0, sizeof(*dsc11));
dsc11->BufferType = type; dsc11->BufferType = type;
...@@ -259,7 +259,7 @@ static int dxva2_mpeg2_start_frame(AVCodecContext *avctx, ...@@ -259,7 +259,7 @@ static int dxva2_mpeg2_start_frame(AVCodecContext *avctx,
av_unused uint32_t size) av_unused uint32_t size)
{ {
const struct MpegEncContext *s = avctx->priv_data; const struct MpegEncContext *s = avctx->priv_data;
AVDXVAContext *ctx = avctx->hwaccel_context; AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
struct dxva2_picture_context *ctx_pic = struct dxva2_picture_context *ctx_pic =
s->current_picture_ptr->hwaccel_picture_private; s->current_picture_ptr->hwaccel_picture_private;
......
...@@ -165,7 +165,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -165,7 +165,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
DECODER_BUFFER_DESC *sc) DECODER_BUFFER_DESC *sc)
{ {
const VC1Context *v = avctx->priv_data; const VC1Context *v = avctx->priv_data;
AVDXVAContext *ctx = avctx->hwaccel_context; AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
const MpegEncContext *s = &v->s; const MpegEncContext *s = &v->s;
struct dxva2_picture_context *ctx_pic = s->current_picture_ptr->hwaccel_picture_private; struct dxva2_picture_context *ctx_pic = s->current_picture_ptr->hwaccel_picture_private;
...@@ -184,7 +184,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -184,7 +184,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
unsigned type; unsigned type;
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM; type = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, if (FAILED(ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context,
D3D11VA_CONTEXT(ctx)->decoder, D3D11VA_CONTEXT(ctx)->decoder,
...@@ -215,7 +215,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -215,7 +215,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
slice->dwSliceBitsInBuffer = 8 * data_size; slice->dwSliceBitsInBuffer = 8 * data_size;
} }
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) if (ff_dxva2_is_d3d11(avctx))
if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type))) if (FAILED(ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type)))
return -1; return -1;
#endif #endif
...@@ -228,7 +228,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, ...@@ -228,7 +228,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx,
return result; return result;
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { if (ff_dxva2_is_d3d11(avctx)) {
D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs; D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = bs;
memset(dsc11, 0, sizeof(*dsc11)); memset(dsc11, 0, sizeof(*dsc11));
dsc11->BufferType = type; dsc11->BufferType = type;
...@@ -261,7 +261,7 @@ static int dxva2_vc1_start_frame(AVCodecContext *avctx, ...@@ -261,7 +261,7 @@ static int dxva2_vc1_start_frame(AVCodecContext *avctx,
av_unused uint32_t size) av_unused uint32_t size)
{ {
const VC1Context *v = avctx->priv_data; const VC1Context *v = avctx->priv_data;
AVDXVAContext *ctx = avctx->hwaccel_context; AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->hwaccel_picture_private; struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->hwaccel_picture_private;
if (!DXVA_CONTEXT_VALID(avctx, ctx)) if (!DXVA_CONTEXT_VALID(avctx, ctx))
......
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