Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware encoding and Latency minimization via FFMPEG #54

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions code/common/src/PVRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ void pvrdebug(string msg)
GetLocalTime(&t);
ofstream of(std::wstring(_GetExePath() + logFileDebug).c_str(), ios_base::app);
auto ms = system_clock::now().time_since_epoch() / 1ms;

//std::replace(msg.begin(), msg.end(), '\n', ' ');
std::replace(msg.begin(), msg.end(), '\r', ' ');

string elapsed = (ms - pvrdebug_oldMs < 1000 ? to_string(ms - pvrdebug_oldMs) : "max");
of << t.wMinute << ":" << setfill('0') << setw(2) << t.wSecond << " " << setfill('0') << setw(3) << elapsed << " " << msg << endl;

Expand Down
4 changes: 2 additions & 2 deletions code/common/src/PVRGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ void pvrInfo(T i) {
void pvrdebugClear();

// PVR_DB only to Debug Log file, PVR_DB_I both to Log file and Info file
#if defined _DEBUG
#if defined PVR_DEBUG
#define PVR_DB(msg) pvrdebug(msg)
#else
#define PVR_DB(msg)
#endif

#if defined _DEBUG
#if defined PVR_DEBUG
#define PVR_DB_I(msg) {pvrdebug(msg);pvrInfo(msg);}
#else
#define PVR_DB_I(msg) pvrInfo(msg);
Expand Down
5 changes: 5 additions & 0 deletions code/windows/PhoneVR/AMP Crashes WorkArround.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
in Debug Build,

Replace _DEBUG preProcessor with NDEBUG & PVR_DEBUG

Code Generation RuntimeLibrary -> MultiThreaded DLL (/MD) (initially was /MDd)
6 changes: 4 additions & 2 deletions code/windows/PhoneVR/PhoneVR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.9
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PhoneVR", "PhoneVR\PhoneVR.vcxproj", "{EECAFA17-E17D-4D6A-898F-DA593C98D0E2}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "driver_PVRServer", "PhoneVR\PhoneVR.vcxproj", "{EECAFA17-E17D-4D6A-898F-DA593C98D0E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -14,7 +14,6 @@ Global
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EECAFA17-E17D-4D6A-898F-DA593C98D0E2}.Debug|x64.ActiveCfg = Debug|x64
{EECAFA17-E17D-4D6A-898F-DA593C98D0E2}.Debug|x64.Build.0 = Debug|x64
{EECAFA17-E17D-4D6A-898F-DA593C98D0E2}.Debug|x86.ActiveCfg = Debug|Win32
{EECAFA17-E17D-4D6A-898F-DA593C98D0E2}.Debug|x86.Build.0 = Debug|Win32
{EECAFA17-E17D-4D6A-898F-DA593C98D0E2}.Release|x64.ActiveCfg = Release|x64
Expand All @@ -25,4 +24,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {019DA038-36FE-4F25-AAF0-53EFA125B5D8}
EndGlobalSection
EndGlobal
37 changes: 2 additions & 35 deletions code/windows/PhoneVR/PhoneVR/PVRGraphics.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
#include "PVRGraphics.h"

#include <d3d11.h>

#include <amp_graphics.h>
#include "PVRGlobals.h"
#include <optional>


#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3dcompiler.lib")


using namespace std;
using namespace this_thread;
using namespace concurrency;
using namespace concurrency::direct3d;
using namespace concurrency::graphics;
using namespace concurrency::graphics::direct3d;

namespace {
ID3D11Device *dxDev;
ID3D11DeviceContext *dxDevCtx;
Expand All @@ -38,21 +19,6 @@ namespace {
thread *gThr;
}

#define RELEASE(obj) if(obj) { obj->Release(); obj = nullptr; }
#define OK_OR_EXEC(call, func) if(FAILED(call)) func()
#define OK_OR_DEBUG(call) { HRESULT hr = call; OK_OR_EXEC(hr, [hr] { PVR_DB_I("######### DirectX Error: #########"); debugHr(hr); }); }
#define QUERY(from, to) OK_OR_DEBUG(from->QueryInterface(__uuidof(to), reinterpret_cast<void**>(&to)))
//#define PARENT(child, parent) OK_OR_DEBUG(child->GetParent(__uuidof(parent), reinterpret_cast<void**>(&parent)))
//#define OK_OR_REINIT(call) OK_OR_EXEC(call, [] { PVRReleaseDX(); PVRInitDX(outID); })

// RGB to YUV constants
#define wr 0.299f
#define wb 0.114f
#define wg 0.587f // 1.0 - wr - wb;
#define ku 0.492f //0.436 / (1.0 - wb);
#define kv 0.877f //0.615 / (1.0 - wr);


void PVRInitDX() {
auto fl = D3D_FEATURE_LEVEL_11_0;
OK_OR_DEBUG(D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, &fl, 1, D3D11_SDK_VERSION, &dxDev, nullptr, &dxDevCtx));
Expand All @@ -72,7 +38,8 @@ void PVRUpdTexHdl(uint64_t texHdl, int whichBuf) {

void PVRStartGraphics(vector<vector<uint8_t *>> vvbuf, uint32_t inpWidth, uint32_t inpHeight) {
gRunning = true;
gThr = new thread([=] {
gThr = new std::thread([=] {

vector<vector<array_view<uint, 2>>> yuvBufViews; // output

for (auto vbuf : vvbuf) // divide width by 4: store 4 bytes in an uint
Expand Down
32 changes: 32 additions & 0 deletions code/windows/PhoneVR/PhoneVR/PVRGraphics.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
#pragma once
#include <vector>
#include <d3d11.h>

#include <amp_graphics.h>
#include "PVRGlobals.h"
#include <optional>


#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3dcompiler.lib")


using namespace std;
using namespace this_thread;
using namespace concurrency;
using namespace concurrency::direct3d;
using namespace concurrency::graphics;
using namespace concurrency::graphics::direct3d;

#define RELEASE(obj) if(obj) { obj->Release(); obj = nullptr; }
#define OK_OR_EXEC(call, func) if(FAILED(call)) func()
#define OK_OR_DEBUG(call) { HRESULT hr = call; OK_OR_EXEC(hr, [hr] { PVR_DB_I("######### DirectX Error: #########"); debugHr(hr); }); }
#define QUERY(from, to) OK_OR_DEBUG(from->QueryInterface(__uuidof(to), reinterpret_cast<void**>(&to)))
//#define PARENT(child, parent) OK_OR_DEBUG(child->GetParent(__uuidof(parent), reinterpret_cast<void**>(&parent)))
//#define OK_OR_REINIT(call) OK_OR_EXEC(call, [] { PVRReleaseDX(); PVRInitDX(outID); })

// RGB to YUV constants
#define wr 0.299f
#define wb 0.114f
#define wg 0.587f // 1.0 - wr - wb;
#define ku 0.492f //0.436 / (1.0 - wb);
#define kv 0.877f //0.615 / (1.0 - wr);

void PVRInitDX();
void PVRUpdTexHdl(uint64_t texHdl, int whichBuffer);
Expand Down
Loading