Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
PHZ76 committed Jul 18, 2021
1 parent 19e4e9c commit 8ef2525
Show file tree
Hide file tree
Showing 25 changed files with 2,945 additions and 2,447 deletions.
3 changes: 2 additions & 1 deletion src/ffmpeg-d3d11va/d3d11va_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 113,14 @@ bool AVDecoder::Init(AVStream* stream, void* d3d11_device)
d3d11_device_context->device->AddRef();
av_hwdevice_ctx_init(device_buffer_);

//codec_context_->hw_device_ctx = av_buffer_ref(device_buffer_);
codec_context_->hw_device_ctx = av_buffer_ref(device_buffer_);
codec_context_->opaque = device_buffer_;
}
else {
av_hwdevice_ctx_create(&device_buffer_, hw_type, NULL, NULL, 0);
}

codec_context_->hw_device_ctx = av_buffer_ref(device_buffer_);
codec_context_->get_format = get_d3d11va_hw_format;
codec_context_->thread_count = 1;
codec_context_->pkt_timebase = stream->time_base;
Expand Down
1 change: 1 addition & 0 deletions src/ffmpeg-dxva2/dxva2_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 217,7 @@ bool AVDecoder::Init(AVStream* stream, void* d3d9_device)
av_hwdevice_ctx_create(&device_buffer_, hw_type, NULL, NULL, 0);
}

codec_context_->hw_device_ctx = av_buffer_ref(device_buffer_);
codec_context_->get_format = get_dxva2_hw_format;
codec_context_->thread_count = 1;
codec_context_->pkt_timebase = stream->time_base;
Expand Down
14 changes: 4 additions & 10 deletions src/video-renderer/d3d11_render_texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 370,18 @@ void D3D11RenderTexture::Cleanup()
DX_SAFE_RELEASE(vertex_layout_);
DX_SAFE_RELEASE(vertex_constants_);
DX_SAFE_RELEASE(vertex_shader_);
DX_SAFE_RELEASE(vertex_buffer_);
DX_SAFE_RELEASE(pixel_shader_);

DX_SAFE_RELEASE(texture_);
DX_SAFE_RELEASE(render_target_view_);
DX_SAFE_RELEASE(texture_view_);

DX_SAFE_RELEASE(chrominance_view_);
DX_SAFE_RELEASE(luminance_view_);

DX_SAFE_RELEASE(d3d11_device_);
DX_SAFE_RELEASE(d3d11_context_);
DX_SAFE_RELEASE(swap_chain_);
}

void D3D11RenderTexture::Begin()
Expand All @@ -404,13 406,7 @@ void D3D11RenderTexture::Begin()
d3d11_context_->RSSetViewports(1, &viewport);

D3D11_MAPPED_SUBRESOURCE mapped_resource;
HRESULT hr = d3d11_context_->Map(
(ID3D11Resource*)vertex_buffer_,
0,
D3D11_MAP_WRITE_DISCARD,
0,
&mapped_resource
);
HRESULT hr = d3d11_context_->Map(vertex_buffer_, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource);
if (FAILED(hr)) {
LOG("ID3D11DeviceContext::Map() failed, %x \n", hr);
return ;
Expand Down Expand Up @@ -509,6 505,4 @@ void D3D11RenderTexture::End()
d3d11_context_->OMSetRenderTargets(1, &cache_render_target_view_, cache_depth_stencil_view_);
DX_SAFE_RELEASE(cache_render_target_view_);
DX_SAFE_RELEASE(cache_depth_stencil_view_);


}
21 changes: 18 additions & 3 deletions src/video-renderer/d3d11_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 32,8 @@ D3D11Renderer::~D3D11Renderer()

bool D3D11Renderer::Init(HWND hwnd)
{
std::lock_guard<std::mutex> locker(mutex_);

wnd_ = hwnd;

if (!InitDevice()) {
Expand All @@ -50,6 52,8 @@ bool D3D11Renderer::Init(HWND hwnd)

void D3D11Renderer::Destroy()
{
std::lock_guard<std::mutex> locker(mutex_);

for (int i = 0; i < PIXEL_PLANE_MAX; i ) {
input_texture_[i].reset();
}
Expand All @@ -76,6 80,8 @@ void D3D11Renderer::Destroy()

bool D3D11Renderer::Resize()
{
std::lock_guard<std::mutex> locker(mutex_);

if (!swap_chain_) {
return false;
}
Expand All @@ -85,6 91,13 @@ bool D3D11Renderer::Resize()
return false;
}

UINT width = static_cast<UINT>(rect.right - rect.left);
UINT height = static_cast<UINT>(rect.bottom - rect.top);

if (width == 0 && height == 0) {
return false;
}

d3d11_context_->OMSetRenderTargets(0, NULL, NULL);

DX_SAFE_RELEASE(sharpen_constants_);
Expand All @@ -105,8 118,8 @@ bool D3D11Renderer::Resize()

HRESULT hr = swap_chain_->ResizeBuffers(
0,
static_cast<UINT>(rect.right - rect.left),
static_cast<UINT>(rect.bottom - rect.top),
width,
height,
DXGI_FORMAT_UNKNOWN,
0
);
Expand All @@ -127,6 140,8 @@ bool D3D11Renderer::Resize()

void D3D11Renderer::Render(PixelFrame* frame)
{
std::lock_guard<std::mutex> locker(mutex_);

if (!d3d11_device_) {
return;
}
Expand Down Expand Up @@ -352,7 367,7 @@ bool D3D11Renderer::CreateRenderer()
return false;
}

sampler_desc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;// D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;// D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
hr = d3d11_device_->CreateSamplerState(&sampler_desc, &linear_sampler_);
if (FAILED(hr)) {
LOG("ID3D11Device::CreateSamplerState(LINEAR) failed, %x ", hr);
Expand Down
7 changes: 5 additions & 2 deletions src/video-renderer/d3d11_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,7 @@

#include "renderer.h"
#include "d3d11_render_texture.h"
#include <mutex>

namespace xop {

Expand Down Expand Up @@ -37,9 38,11 @@ class D3D11Renderer : public Renderer
void UpdateI420(PixelFrame* frame);
void UpdateNV12(PixelFrame* frame);

std::mutex mutex_;

HWND wnd_ = NULL;
D3D_DRIVER_TYPE driver_type_;
D3D_FEATURE_LEVEL feature_level_;
D3D_DRIVER_TYPE driver_type_ = D3D_DRIVER_TYPE_UNKNOWN;
D3D_FEATURE_LEVEL feature_level_ = D3D_FEATURE_LEVEL_11_0;

ID3D11Device* d3d11_device_ = NULL;
IDXGISwapChain* swap_chain_ = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/video-renderer/d3d9_render_texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 205,7 @@ void D3D9RenderTexture::Begin()
d3dmatrix.m[3][0] = -1.0f;
d3dmatrix.m[3][1] = 1.0f;
d3dmatrix.m[3][3] = 1.0f;

//D3DXMatrixOrthoOffCenterLH(&projection, 0.0f, frame->width, frame->height, 0.0f, 0.0f, 1.0f);
d3d9_device_->SetTransform(D3DTS_PROJECTION, &d3dmatrix);

Expand Down
24 changes: 20 additions & 4 deletions src/video-renderer/d3d9_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 65,8 @@ void D3D9Renderer::Destroy()

bool D3D9Renderer::Resize()
{
std::lock_guard<std::mutex> locker(mutex_);

if (!d3d9_device_) {
return false;
}
Expand All @@ -74,6 76,13 @@ bool D3D9Renderer::Resize()
return false;
}

UINT width = static_cast<UINT>(client_rect.right - client_rect.left);
UINT height = static_cast<UINT>(client_rect.bottom - client_rect.top);

if (width == 0 && height == 0) {
return false;
}

for (int i = 0; i < PIXEL_PLANE_MAX; i ) {
input_texture_[i].reset();
}
Expand All @@ -86,8 95,8 @@ bool D3D9Renderer::Resize()
output_texture_ = NULL;
pixel_format_ = PIXEL_FORMAT_UNKNOW;

present_params_.BackBufferWidth = static_cast<UINT>(client_rect.right - client_rect.left);
present_params_.BackBufferHeight = static_cast<UINT>(client_rect.bottom - client_rect.top);
present_params_.BackBufferWidth = width;
present_params_.BackBufferHeight = height;

HRESULT hr = d3d9_device_->Reset(&present_params_);
if (FAILED(hr)) {
Expand All @@ -104,6 113,8 @@ bool D3D9Renderer::Resize()

void D3D9Renderer::Render(PixelFrame* frame)
{
std::lock_guard<std::mutex> locker(mutex_);

if (!d3d9_device_) {
return;
}
Expand All @@ -122,6 133,11 @@ void D3D9Renderer::Render(PixelFrame* frame)
End();
}

IDirect3DDevice9* D3D9Renderer::GetDevice()
{
return d3d9_device_;
}

void D3D9Renderer::SetSharpen(float unsharp)
{
unsharp_ = unsharp;
Expand Down Expand Up @@ -403,7 419,7 @@ void D3D9Renderer::End()
return ;
}

d3d9_device_->StretchRect(output_texture_->GetSurface(), NULL, back_buffer_, NULL, D3DTEXF_LINEAR);
d3d9_device_->StretchRect(output_texture_->GetSurface(), NULL, back_buffer_, NULL, D3DTEXF_NONE);
DX_SAFE_RELEASE(back_buffer_);
output_texture_ = NULL;
}
Expand Down Expand Up @@ -624,6 640,6 @@ void D3D9Renderer::UpdateNV12(PixelFrame* frame)

// NV12 To ARGB
output_texture_ = input_texture_[PIXEL_PLANE_ARGB].get();
d3d9_device_->StretchRect(surface, NULL, output_texture_->GetSurface(), NULL, D3DTEXF_NONE);
d3d9_device_->StretchRect(surface, NULL, output_texture_->GetSurface(), NULL, D3DTEXF_LINEAR);
}
}
6 changes: 6 additions & 0 deletions src/video-renderer/d3d9_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,8 @@
#include "renderer.h"
#include "d3d9_render_texture.h"

#include <mutex>

namespace xop {

class D3D9Renderer : public Renderer
Expand All @@ -18,6 20,8 @@ class D3D9Renderer : public Renderer

virtual void Render(PixelFrame* frame);

virtual IDirect3DDevice9* GetDevice();

// sharpness: 0.0 to 10.0
virtual void SetSharpen(float unsharp);

Expand All @@ -36,6 40,8 @@ class D3D9Renderer : public Renderer
void UpdateI420(PixelFrame* frame);
void UpdateNV12(PixelFrame* frame);

std::mutex mutex_;

HWND hwnd_ = NULL;

D3DCAPS9 d3d9_caps_;
Expand Down
4 changes: 2 additions & 2 deletions src/video-renderer/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 5,5 @@
#define LOG(format, ...) \
{ \
fprintf(stderr, "[%s:%d] " format " \n", \
__FUNCTION__ , __LINE__, ##__VA_ARGS__); \
}
__FUNCTION__ , __LINE__, ##__VA_ARGS__); \
}
6 changes: 3 additions & 3 deletions src/video-renderer/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 12,7 @@ enum PixelFormat
PIXEL_FORMAT_I420,
PIXEL_FORMAT_NV12,
PIXEL_FORMAT_I444,
PIXEL_FORMAT_MAX
PIXEL_FORMAT_MAX,
};

enum PixelShader
Expand All @@ -24,7 24,7 @@ enum PixelShader
PIXEL_SHADER_NV12_BT601,
PIXEL_SHADER_NV12_BT709,
PIXEL_SHADER_SHARPEN,
PIXEL_SHADER_MAX
PIXEL_SHADER_MAX,
};

enum PixelPlane
Expand All @@ -36,7 36,7 @@ enum PixelPlane
PIXEL_PLANE_U,
PIXEL_PLANE_V,
PIXEL_PLANE_UV,
PIXEL_PLANE_MAX
PIXEL_PLANE_MAX,
};

struct PixelFrame
Expand Down
Loading

0 comments on commit 8ef2525

Please sign in to comment.