Skip to content

Commit

Permalink
Revert not needed changes in video-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
TheElixZammuto committed Feb 4, 2024
1 parent b2df8b5 commit 5047e7b
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 184 deletions.
33 changes: 33 additions & 0 deletions Common/DeviceResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ void DX::DeviceResources::CreateWindowSizeDependentResources()
m_d3dRenderTargetView = nullptr;
m_d2dContext->SetTarget(nullptr);
m_d2dTargetBitmap = nullptr;
m_d3dDepthStencilView = nullptr;
m_d3dContext->Flush1(D3D11_CONTEXT_TYPE_ALL, nullptr);

UpdateRenderTargetSize();
Expand Down Expand Up @@ -395,6 +396,34 @@ void DX::DeviceResources::CreateWindowSizeDependentResources()
)
);

// Create a depth stencil view for use with 3D rendering if needed.
CD3D11_TEXTURE2D_DESC1 depthStencilDesc(
DXGI_FORMAT_D24_UNORM_S8_UINT,
lround(m_d3dRenderTargetSize.Width),
lround(m_d3dRenderTargetSize.Height),
1, // This depth stencil view has only one texture.
1, // Use a single mipmap level.
D3D11_BIND_DEPTH_STENCIL
);

ComPtr<ID3D11Texture2D1> depthStencil;
DX::ThrowIfFailed(
m_d3dDevice->CreateTexture2D1(
&depthStencilDesc,
nullptr,
&depthStencil
)
);

CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D);
DX::ThrowIfFailed(
m_d3dDevice->CreateDepthStencilView(
depthStencil.Get(),
&depthStencilViewDesc,
&m_d3dDepthStencilView
)
);

// Set the 3D rendering viewport to target the entire window.
m_screenViewport = CD3D11_VIEWPORT(
0.0f,
Expand Down Expand Up @@ -613,6 +642,10 @@ void DX::DeviceResources::Present()
// Discard the contents of the render target.
// This is a valid operation only when the existing contents will be entirely
// overwritten. If dirty or scroll rects are used, this call should be modified.
m_d3dContext->DiscardView1(m_d3dRenderTargetView.Get(), nullptr, 0);

// Discard the contents of the depth stencil.
m_d3dContext->DiscardView1(m_d3dDepthStencilView.Get(), nullptr, 0);

// If the device was removed either by a disconnection or a driver upgrade, we
// must recreate all device resources.
Expand Down
2 changes: 2 additions & 0 deletions Common/DeviceResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace DX
IDXGISwapChain4* GetSwapChain() const { return m_swapChain.Get(); }
D3D_FEATURE_LEVEL GetDeviceFeatureLevel() const { return m_d3dFeatureLevel; }
ID3D11RenderTargetView1* GetBackBufferRenderTargetView() const { return m_d3dRenderTargetView.Get(); }
ID3D11DepthStencilView* GetDepthStencilView() const { return m_d3dDepthStencilView.Get(); }
D3D11_VIEWPORT GetScreenViewport() const { return m_screenViewport; }
DirectX::XMFLOAT4X4 GetOrientationTransform3D() const { return m_orientationTransform3D; }

Expand All @@ -66,6 +67,7 @@ namespace DX

// Direct3D rendering objects. Required for 3D.
Microsoft::WRL::ComPtr<ID3D11RenderTargetView1> m_d3dRenderTargetView;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_d3dDepthStencilView;
D3D11_VIEWPORT m_screenViewport;

// Direct2D drawing components.
Expand Down
65 changes: 15 additions & 50 deletions Streaming/FFmpegDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,6 @@ namespace moonlight_xbox_dx {
// to override the default get_format() which will try
// to gracefully fall back to software decode and break us.
if (*p == AV_PIX_FMT_D3D11) {
auto hw_frames_ctx = av_hwframe_ctx_alloc(context->hw_device_ctx);
if (!hw_frames_ctx) {
return AV_PIX_FMT_NONE;
}

AVHWFramesContext* framesContext = (AVHWFramesContext*)hw_frames_ctx->data;

// We require NV12 or P010 textures for our shader
framesContext->format = AV_PIX_FMT_D3D11;
framesContext->sw_format = (d->videoFormat & VIDEO_FORMAT_MASK_10BIT) ? AV_PIX_FMT_P010 : AV_PIX_FMT_NV12;

framesContext->width = FFALIGN(d->width, 16);
framesContext->height = FFALIGN(d->height, 16);

// We can have up to 16 reference frames plus a working surface
framesContext->initial_pool_size = 16;

AVD3D11VAFramesContext* d3d11vaFramesContext = (AVD3D11VAFramesContext*)framesContext->hwctx;

d3d11vaFramesContext->texture = NULL;
d3d11vaFramesContext->BindFlags = D3D11_BIND_DECODER;

int err = av_hwframe_ctx_init(hw_frames_ctx);
if (err < 0) {
return AV_PIX_FMT_NONE;
}
context->hw_frames_ctx = av_buffer_ref(hw_frames_ctx);
return *p;
}
}
Expand Down Expand Up @@ -144,11 +117,8 @@ namespace moonlight_xbox_dx {
decoder_ctx->sw_pix_fmt = (videoFormat & VIDEO_FORMAT_MASK_10BIT) ? AV_PIX_FMT_P010 : AV_PIX_FMT_NV12;
decoder_ctx->width = width;
decoder_ctx->height = height;
//decoder_ctx->get_format = ffGetFormat;
decoder_ctx->flags |= AV_CODEC_FLAG_LOW_DELAY;
decoder_ctx->flags |= AV_CODEC_FLAG_OUTPUT_CORRUPT;
decoder_ctx->flags2 |= AV_CODEC_FLAG2_SHOW_ALL;
decoder_ctx->err_recognition = AV_EF_EXPLODE;
decoder_ctx->get_format = ffGetFormat;

int err = avcodec_open2(decoder_ctx, decoder, NULL);
if (err < 0) {
char msg[2048];
Expand Down Expand Up @@ -227,7 +197,15 @@ namespace moonlight_xbox_dx {
LiCompleteVideoFrame(frameHandle, DR_NEED_IDR);
return false;
}
int err = Decode(decodeUnit);
PLENTRY entry = decodeUnit->bufferList;
uint32_t length = 0;
while (entry != NULL) {
memcpy(ffmpeg_buffer + length, entry->data, entry->length);
length += entry->length;
entry = entry->next;
}
int err;
err = Decode(ffmpeg_buffer, length);
if (err < 0) {
LiCompleteVideoFrame(frameHandle, DR_NEED_IDR);
return false;
Expand All @@ -236,24 +214,11 @@ namespace moonlight_xbox_dx {
return true;
}

int FFMpegDecoder::Decode(PDECODE_UNIT decodeUnit) {
PLENTRY entry = decodeUnit->bufferList;
uint32_t length = 0;
while (entry != NULL) {
memcpy(ffmpeg_buffer + length, entry->data, entry->length);
length += entry->length;
entry = entry->next;
}
int FFMpegDecoder::Decode(unsigned char* indata, int inlen) {
int err;

pkt.data = ffmpeg_buffer;
pkt.size = length;
if (decodeUnit->frameType == FRAME_TYPE_IDR) {
pkt.flags = AV_PKT_FLAG_KEY;
}
else {
pkt.flags = 0;
}
pkt.data = indata;
pkt.size = inlen;
int ts = GetTickCount64();
err = avcodec_send_packet(decoder_ctx, &pkt);
if (err < 0) {
Expand Down Expand Up @@ -330,7 +295,7 @@ namespace moonlight_xbox_dx {
decoder_callbacks_sdl.stop = stopCallback;
decoder_callbacks_sdl.cleanup = cleanupCallback;
decoder_callbacks_sdl.submitDecodeUnit = NULL;
decoder_callbacks_sdl.capabilities = CAPABILITY_PULL_RENDERER | CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC | CAPABILITY_REFERENCE_FRAME_INVALIDATION_HEVC;
decoder_callbacks_sdl.capabilities = CAPABILITY_PULL_RENDERER;
return decoder_callbacks_sdl;
}

Expand Down
3 changes: 1 addition & 2 deletions Streaming/FFmpegDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace moonlight_xbox_dx
int videoFormat,width,height;

private:
int Decode(PDECODE_UNIT decodeUnit);
int Decode(unsigned char* indata, int inlen);
AVPacket pkt;
const AVCodec* decoder;
AVCodecContext* decoder_ctx;
Expand All @@ -45,6 +45,5 @@ namespace moonlight_xbox_dx
AVFrame** ready_frames;
int next_frame, current_frame;
std::shared_ptr<DX::DeviceResources> resources;
FILE* recordFile;
};
}
Loading

0 comments on commit 5047e7b

Please sign in to comment.