Skip to content

Commit

Permalink
win: Update windows dxva/d3d drivers for driver rewrite.
Browse files Browse the repository at this point in the history
Bring Mark Kendall's 2020 video driver rewrite to the windows drivers.
This is not complete, but there are far fewer errors than before.

These changes are all in conditionally compiled code, and therefore
should not affect any non-windows build.  Windows builds do not
currently build this driver either, and are also unaffected.
  • Loading branch information
linuxdude42 committed Nov 24, 2023
2 parents d8c7856 + 0a9923f commit b3bf95d
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 314 deletions.
48 changes: 13 additions & 35 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ static float get_aspect(AVCParser &p)


int get_avf_buffer(struct AVCodecContext *c, AVFrame *pic, int flags);
#ifdef USING_DXVA2
int get_avf_buffer_dxva2(struct AVCodecContext *c, AVFrame *pic, int flags);
#endif

// currently unused
//static int determinable_frame_size(struct AVCodecContext *avctx)
Expand Down Expand Up @@ -1368,33 +1365,6 @@ float AvFormatDecoder::GetVideoFrameRate(AVStream *Stream, AVCodecContext *Conte
return static_cast<float>(detected);
}

#ifdef USING_DXVA2
// Declared separately to allow attribute
static enum AVPixelFormat get_format_dxva2(struct AVCodecContext *,
const enum AVPixelFormat *);

enum AVPixelFormat get_format_dxva2(struct AVCodecContext *avctx,
const enum AVPixelFormat *valid_fmts)
{
AvFormatDecoder *nd = (AvFormatDecoder *)(avctx->opaque);
if (nd && nd->GetPlayer())
{
static uint8_t *dummy[1] = { nullptr };
avctx->hwaccel_context =
(dxva_context*)nd->GetPlayer()->GetDecoderContext(nullptr, dummy[0]);
}

while (*valid_fmts != AV_PIX_FMT_NONE) {
if (avctx->hwaccel_context and (*valid_fmts == AV_PIX_FMT_DXVA2_VLD))
return AV_PIX_FMT_DXVA2_VLD;
if (not avctx->hwaccel_context and (*valid_fmts == AV_PIX_FMT_YUV420P))
return AV_PIX_FMT_YUV420P;
valid_fmts++;
}
return AV_PIX_FMT_NONE;
}
#endif

int AvFormatDecoder::GetMaxReferenceFrames(AVCodecContext *Context)
{
switch (Context->codec_id)
Expand Down Expand Up @@ -2766,22 +2736,30 @@ int get_avf_buffer(struct AVCodecContext *c, AVFrame *pic, int flags)
int get_avf_buffer_dxva2(struct AVCodecContext *c, AVFrame *pic, int /*flags*/)
{
AvFormatDecoder *nd = (AvFormatDecoder *)(c->opaque);
VideoFrame *frame = nd->GetPlayer()->GetNextVideoFrame();
MythVideoFrame *frame = nd->GetPlayer()->GetNextVideoFrame();

for (int i = 0; i < 4; i++)
{
pic->data[i] = nullptr;
pic->linesize[i] = 0;
}
pic->opaque = frame;
frame->pix_fmt = c->pix_fmt;
frame->m_pixFmt = c->pix_fmt;
pic->reordered_opaque = c->reordered_opaque;
pic->data[0] = (uint8_t*)frame->buf;
pic->data[3] = (uint8_t*)frame->buf;
pic->data[0] = (uint8_t*)frame->m_buffer;
pic->data[3] = (uint8_t*)frame->m_buffer;

// Set release method
AVBufferRef *buffer =
av_buffer_create((uint8_t*)frame, 0, release_avf_buffer, nd, 0);
av_buffer_create((uint8_t*)frame, 0,
[](void* Opaque, uint8_t* Data)
{
AvFormatDecoder *avfd = static_cast<AvFormatDecoder*>(Opaque);
MythVideoFrame *vf = reinterpret_cast<MythVideoFrame*>(Data);
if (avfd && avfd->GetPlayer())
avfd->GetPlayer()->DeLimboFrame(vf);
}
, nd, 0);
pic->buf[0] = buffer;

return 0;
Expand Down
5 changes: 4 additions & 1 deletion mythtv/libs/libmythtv/decoders/mythcodeccontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
#ifdef USING_EGL
#include "mythdrmprimecontext.h"
#endif
#ifdef USING_DXVA2
#include "videoout_d3d.h"
#endif
#include "mythcodeccontext.h"

extern "C" {
Expand Down Expand Up @@ -267,7 +270,7 @@ MythCodecID MythCodecContext::FindDecoder(const QString &Decoder,
return result;
#endif
#ifdef USING_DXVA2
result = VideoOutputD3D::GetBestSupportedCodec(width, height, Decoder, streamtype, false);
result = VideoOutputD3D::GetSupportedCodec(Context, Codec, Decoder, streamtype);
if (codec_is_dxva2(result))
return result;
#endif
Expand Down
6 changes: 5 additions & 1 deletion mythtv/libs/libmythtv/dxva2decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

#include "libmythbase/mythlogging.h"
#include "initguid.h"
#include "mythrender_d3d9.h"
#include "libmythui/mythrender_d3d9.h"
#include "dxva2decoder.h"

#ifndef __MINGW32__
static const GUID IID_IDirectXVideoDecoderService =
{
0xfc51a551, 0xd5e7, 0x11d9, {0xaf,0x55,0x00,0x05,0x4e,0x43,0xff,0x02}
};
#endif

static inline QString toString(const GUID& guid)
{
Expand All @@ -30,6 +32,7 @@ static inline QString toString(const GUID& guid)
#define LOC QString("DXVA2: ")
#define ERR QString("DXVA2 Error: ")

#ifndef __MINGW32__
DEFINE_GUID(DXVA2_ModeH264_A, 0x1b81be64, 0xa0c7, 0x11d3, 0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
DEFINE_GUID(DXVA2_ModeH264_B, 0x1b81be65, 0xa0c7, 0x11d3, 0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
DEFINE_GUID(DXVA2_ModeH264_C, 0x1b81be66, 0xa0c7, 0x11d3, 0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
Expand All @@ -52,6 +55,7 @@ DEFINE_GUID(DXVA2_ModeVC1_D, 0x1b81beA3, 0xa0c7, 0x11d3, 0xb9,0x84,0x00,0
DEFINE_GUID(DXVA2_ModeMPEG2_MoComp, 0xe6a9f44b, 0x61b0, 0x4563, 0x9e,0xa4,0x63,0xd2,0xa3,0xc6,0xfe,0x66);
DEFINE_GUID(DXVA2_ModeMPEG2_IDCT, 0xbf22ad00, 0x03ea, 0x4690, 0x80,0x77,0x47,0x33,0x46,0x20,0x9b,0x7e);
DEFINE_GUID(DXVA2_ModeMPEG2_VLD, 0xee27417f, 0x5e28, 0x4e65, 0xbe,0xea,0x1d,0x26,0xb5,0x08,0xad,0xc9);
#endif

#define DXVA2_ModeWMV8_PostProc DXVA2_ModeWMV8_A
#define DXVA2_ModeWMV8_MoComp DXVA2_ModeWMV8_B
Expand Down
12 changes: 10 additions & 2 deletions mythtv/libs/libmythtv/mythvideooutgpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "mythvideogpu.h"
#include "mythvideooutgpu.h"

#ifdef _WIN32
#include "libmythui/mythpainter_d3d9.h"
#include "videoout_d3d.h"
#endif
#ifdef USING_OPENGL
#include "libmythui/opengl/mythpainteropengl.h"
#include "opengl/mythvideooutopengl.h"
Expand Down Expand Up @@ -55,7 +59,9 @@ MythVideoOutputGPU *MythVideoOutputGPU::Create(MythMainWindow* MainWindow, MythR
QStringList renderers;

#ifdef _WIN32
// if (render->Type() == kRenderDirect3D9)
// auto * d3drender = dynamic_cast<MythRenderD3D9*>(Render);
// auto * d3dpainter = dynamic_cast<MythD3D9Painter*>(Painter);
// if (Render->Type() == kRenderDirect3D9)
// renderers += VideoOutputD3D::GetAllowedRenderers(CodecID, VideoDispDim);
#endif

Expand Down Expand Up @@ -134,7 +140,9 @@ MythVideoOutputGPU *MythVideoOutputGPU::Create(MythMainWindow* MainWindow, MythR

#ifdef _WIN32
// if (renderer == "direct3d")
// video = new VideoOutputD3D();
// video = new VideoOutputD3D(MainWindow, d3drender,
// d3dpainter, Display,
// videoprofile, renderer);
#endif
#ifdef USING_OPENGL
// cppcheck-suppress knownConditionTrueFalse
Expand Down
Loading

0 comments on commit b3bf95d

Please sign in to comment.