Skip to content

Commit

Permalink
utilities refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jdibenes committed Nov 14, 2022
1 parent 2e5352e commit 27fb95c
Show file tree
Hide file tree
Showing 33 changed files with 148 additions and 133 deletions.
1 change: 0 additions & 1 deletion hl2ss/hl2ss/custom_hook_callback.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#include <new>
#include "custom_hook_callback.h"
#include "utilities.h"

//-----------------------------------------------------------------------------
// HookSinkCallback Methods
Expand Down
9 changes: 6 additions & 3 deletions hl2ss/hl2ss/custom_media_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <mferror.h>
#include "custom_media_sink.h"
#include "custom_stream_sink.h"
#include "utilities.h"
#include "lock.h"

//-----------------------------------------------------------------------------
// CustomMediaSink Methods
Expand Down Expand Up @@ -185,7 +185,7 @@ HRESULT CustomMediaSink::SetPresentationClock(IMFPresentationClock* pPresentatio
CriticalSection cs(&m_critSec);
if (m_isShutdown) { return MF_E_SHUTDOWN; }
HRESULT hr;
if (m_pClock) { hr = m_pClock->RemoveClockStateSink(this); if (FAILED(hr)) { return hr; } SafeRelease(&m_pClock); }
if (m_pClock) { hr = m_pClock->RemoveClockStateSink(this); if (FAILED(hr)) { return hr; } /*SafeRelease(&m_pClock);*/ m_pClock->Release(); m_pClock = NULL; }
if (pPresentationClock) { hr = pPresentationClock->AddClockStateSink(this); if (FAILED(hr)) { return hr; } pPresentationClock->AddRef(); }
m_pClock = pPresentationClock;
return S_OK;
Expand All @@ -208,9 +208,12 @@ HRESULT CustomMediaSink::Shutdown()
CriticalSection cs(&m_critSec);
if (m_isShutdown) { return MF_E_SHUTDOWN; }
for (auto stream : m_streams) { stream->Shutdown(); } // TODO: Error Handling
SafeRelease(&m_pClock);
//SafeRelease(&m_pClock);
CleanupStreams();
m_isShutdown = true;
if (!m_pClock) { return S_OK; }
m_pClock->Release();
m_pClock = NULL;
return S_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion hl2ss/hl2ss/custom_media_type_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <new>
#include <mferror.h>
#include "custom_media_type_handler.h"
#include "utilities.h"
#include "lock.h"

//-----------------------------------------------------------------------------
// CustomMediaTypeHandler Methods
Expand Down
22 changes: 15 additions & 7 deletions hl2ss/hl2ss/custom_stream_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <mferror.h>
#include "custom_stream_sink.h"
#include "custom_media_type_handler.h"
#include "utilities.h"
#include "lock.h"

//-----------------------------------------------------------------------------
// CustomStreamSink Methods
Expand All @@ -18,7 +18,8 @@ HRESULT CustomStreamSink::CreateInstance(CustomStreamSink** ppStream, IMFMediaSi
if (!pStream) { return E_OUTOFMEMORY; }
HRESULT hr = pStream->Initialize(dwStreamSinkIdentifier, pMediaType, pHook);
if (SUCCEEDED(hr)) { (*ppStream = pStream)->AddRef(); }
SafeRelease(&pStream);
//SafeRelease(&pStream);
pStream->Release();
return hr;
}

Expand Down Expand Up @@ -53,10 +54,14 @@ CustomStreamSink::~CustomStreamSink()
{
//assert(!m_RefCount)
DeleteCriticalSection(&m_critSec);
SafeRelease(&m_pSink);
SafeRelease(&m_pEventQueue);
SafeRelease(&m_pHandler);
SafeRelease(&m_pHook);
//SafeRelease(&m_pSink);
if (m_pSink) { m_pSink->Release(); }
//SafeRelease(&m_pEventQueue);
if (m_pEventQueue) { m_pEventQueue->Release(); }
//SafeRelease(&m_pHandler);
if (m_pHandler) { m_pHandler->Release(); }
//SafeRelease(&m_pHook);
if (m_pHook) { m_pHook->Release(); }
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -215,7 +220,10 @@ void CustomStreamSink::Shutdown()
void CustomStreamSink::Detach()
{
CriticalSection cs(&m_critSec);
SafeRelease(&m_pSink);
//SafeRelease(&m_pSink);
if (!m_pSink) { return; }
m_pSink->Release();
m_pSink = NULL;
}

// OK
Expand Down
9 changes: 9 additions & 0 deletions hl2ss/hl2ss/display7s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Functions
//-----------------------------------------------------------------------------

// OK
static void DrawGlyphUnit(int x, int y, int glyph_unit_width, int glyph_unit_height, int image_width, int image_height, u32 color, u32* buffer)
{
for (int v = 0; v < glyph_unit_height; ++v)
Expand All @@ -21,16 +22,19 @@ static void DrawGlyphUnit(int x, int y, int glyph_unit_width, int glyph_unit_hei
}
}

// OK
static void DrawGlyphH(int x, int y, int glyph_width, int glyph_unit_width, int glyph_unit_height, int image_width, int image_height, u32 color, u32 *buffer)
{
for (int u = glyph_unit_width; u < (glyph_width - glyph_unit_width); u += glyph_unit_width) { DrawGlyphUnit(x + u, y, glyph_unit_width, glyph_unit_height, image_width, image_height, color, buffer); }
}

// OK
static void DrawGlyphV(int x, int y, int glyph_height, int glyph_unit_width, int glyph_unit_height, int image_width, int image_height, u32 color, u32* buffer)
{
for (int v = glyph_unit_height; v < (glyph_height - glyph_unit_height); v += glyph_unit_height) { DrawGlyphUnit(x, y + v, glyph_unit_width, glyph_unit_height, image_width, image_height, color, buffer); }
}

// OK
static void DrawGlyphTile(int segments, int x, int y, int glyph_width, int glyph_height, int glyph_unit_width, int glyph_unit_height, int image_width, int image_height, u32 color, u32* buffer)
{
if (segments & 1) { DrawGlyphH(x, y, glyph_width, glyph_unit_width, glyph_unit_height, image_width, image_height, color, buffer); }
Expand All @@ -39,12 +43,14 @@ static void DrawGlyphTile(int segments, int x, int y, int glyph_width, int glyph
if (segments & 8) { DrawGlyphV(x, y, glyph_height, glyph_unit_width, glyph_unit_height, image_width, image_height, color, buffer); }
}

// OK
static void DrawGlyph(int segments, int x, int y, int glyph_width, int glyph_height, int glyph_unit_width, int glyph_unit_height, int image_width, int image_height, u32 color, u32* buffer)
{
DrawGlyphTile(segments, x, y, glyph_width, glyph_height, glyph_unit_width, glyph_unit_height, image_width, image_height, color, buffer);
DrawGlyphTile(segments >> 4, x, y + glyph_height - glyph_unit_width, glyph_width, glyph_height, glyph_unit_width, glyph_unit_height, image_width, image_height, color, buffer);
}

// OK
static int DigitToSegments(char number)
{
switch (number)
Expand All @@ -63,6 +69,7 @@ static int DigitToSegments(char number)
}
}

// OK
static int DigitToSegments(wchar_t number)
{
switch (number)
Expand All @@ -81,12 +88,14 @@ static int DigitToSegments(wchar_t number)
}
}

// OK
void DrawDigits(wchar_t const* str, int x, int y, int glyph_width, int glyph_kerning, int glyph_height, int glyph_unit_width, int glyph_unit_height, int image_width, int image_height, u32 color, u32* buffer)
{
int offset = glyph_width + glyph_kerning;
for (int i = 0; i < wcslen(str); ++i) { DrawGlyph(DigitToSegments(str[i]), x + (i * offset), y, glyph_width, glyph_height, glyph_unit_width, glyph_unit_height, image_width, image_height, color, buffer); }
}

// OK
void DrawDigits(char const* str, int x, int y, int glyph_width, int glyph_kerning, int glyph_height, int glyph_unit_width, int glyph_unit_height, int image_width, int image_height, u32 color, u32* buffer)
{
int offset = glyph_width + glyph_kerning;
Expand Down
6 changes: 4 additions & 2 deletions hl2ss/hl2ss/hl2ss.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
<ClInclude Include="holographic_space.h" />
<ClInclude Include="ipc_sc.h" />
<ClInclude Include="locator.h" />
<ClInclude Include="log.h" />
<ClInclude Include="neon.h" />
<ClInclude Include="nfo.h" />
<ClInclude Include="personal_video.h" />
Expand All @@ -182,7 +183,7 @@
<ClInclude Include="stream_si.h" />
<ClInclude Include="timestamps.h" />
<ClInclude Include="types.h" />
<ClInclude Include="utilities.h" />
<ClInclude Include="lock.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Cannon\AnimatedVector.cpp" />
Expand All @@ -202,6 +203,7 @@
<ClCompile Include="display7s.cpp" />
<ClCompile Include="holographic_space.cpp" />
<ClCompile Include="ipc_sc.cpp" />
<ClCompile Include="log.cpp" />
<ClCompile Include="neon.cpp" />
<ClCompile Include="nfo.cpp" />
<ClCompile Include="research_mode.cpp" />
Expand All @@ -220,7 +222,7 @@
<ClCompile Include="stream_rm_zab.cpp" />
<ClCompile Include="stream_rm_vlc.cpp" />
<ClCompile Include="timestamps.cpp" />
<ClCompile Include="utilities.cpp" />
<ClCompile Include="lock.cpp" />
<ClCompile Include="stream_rm.cpp" />
<ClCompile Include="server.cpp" />
</ItemGroup>
Expand Down
10 changes: 8 additions & 2 deletions hl2ss/hl2ss/hl2ss.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<ClCompile Include="stream_si.cpp">
<Filter>Source Files\streams</Filter>
</ClCompile>
<ClCompile Include="utilities.cpp">
<ClCompile Include="lock.cpp">
<Filter>Source Files\utilities</Filter>
</ClCompile>
<ClCompile Include="holographic_space.cpp">
Expand Down Expand Up @@ -109,6 +109,9 @@
<ClCompile Include="display7s.cpp">
<Filter>Source Files\utilities</Filter>
</ClCompile>
<ClCompile Include="log.cpp">
<Filter>Source Files\utilities</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="Assets\Wide310x150Logo.scale-200.png">
Expand Down Expand Up @@ -300,7 +303,7 @@
<ClInclude Include="custom_media_buffers.h">
<Filter>Header Files\sink</Filter>
</ClInclude>
<ClInclude Include="utilities.h">
<ClInclude Include="lock.h">
<Filter>Header Files\utilities</Filter>
</ClInclude>
<ClInclude Include="holographic_space.h">
Expand Down Expand Up @@ -330,6 +333,9 @@
<ClInclude Include="display7s.h">
<Filter>Header Files\utilities</Filter>
</ClInclude>
<ClInclude Include="log.h">
<Filter>Header Files\utilities</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
Expand Down
22 changes: 14 additions & 8 deletions hl2ss/hl2ss/holographic_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "Cannon/DrawCall.h"
#include "nfo.h"
#include "display7s.h"
#include "utilities.h"
#include "types.h"

#include <windows.graphics.directx.direct3d11.interop.h>
Expand Down Expand Up @@ -45,18 +44,24 @@ void HolographicSpace_EnableMarker(bool state)
// OK
static void HolographicSpace_CreateHUDTextures()
{
int const iptext_x = 0;
int const iptext_y = 0;
int const iptext_side = 20;
int const iptext_size = 4;
u32 const iptext_color = 0x6F6F6F6F;

int const line_thickness = 16;
UINT32 const line_color = 0xFFFFFFFF;
u32 const line_color = 0xFFFFFFFF;

int const buffer_width = 1440;
int const buffer_width = 1440;
int const buffer_height = 936;
int const buffer_bpt = sizeof(UINT32);
int const buffer_size = buffer_width * buffer_height * buffer_bpt;
int const y0 = buffer_height - line_thickness;

int const buffer_bpt = sizeof(UINT32);
int const buffer_size = buffer_width * buffer_height * buffer_bpt;

D3D11_TEXTURE2D_DESC dtd;
D3D11_SUBRESOURCE_DATA dsd[2];
BYTE* data; // delete[]
int y0;

dtd.Width = buffer_width;
dtd.Height = buffer_height;
Expand All @@ -83,10 +88,11 @@ static void HolographicSpace_CreateHUDTextures()

std::vector<wchar_t> ipaddress;
GetLocalIPv4Address(ipaddress);
DrawDigits(ipaddress.data(), 128, 0, 20, 6, 24, 4, 4, buffer_width, buffer_height, 0x3F3F3F3F, (u32*)data);
DrawDigits(ipaddress.data(), iptext_x, iptext_y, iptext_side, iptext_size, iptext_side, iptext_size, iptext_size, buffer_width, buffer_height, iptext_color, (u32*)data);

g_device->CreateTexture2D(&dtd, dsd, &g_texture_empty);

y0 = buffer_height - line_thickness;
for (int y = y0 - line_thickness; y < (y0 + line_thickness); ++y) { for (int x = 0; x < buffer_width; ++x) { ((UINT32*)data)[y * buffer_width + x] = line_color; } }

g_device->CreateTexture2D(&dtd, dsd, &g_texture_marker);
Expand Down
2 changes: 1 addition & 1 deletion hl2ss/hl2ss/ipc_rc.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include "server.h"
#include "ports.h"
#include "utilities.h"
#include "log.h"
#include "holographic_space.h"
#include "personal_video.h"
#include "timestamps.h"
Expand Down
1 change: 0 additions & 1 deletion hl2ss/hl2ss/locator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#include "utilities.h"
#include "types.h"

#include <winrt/Windows.Foundation.h>
Expand Down
20 changes: 20 additions & 0 deletions hl2ss/hl2ss/lock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#include <Windows.h>
#include "lock.h"

//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------

// OK
CriticalSection::CriticalSection(CRITICAL_SECTION* pcs)
{
m_pcs = pcs;
if (m_pcs) { EnterCriticalSection(m_pcs); }
}

// OK
CriticalSection::~CriticalSection()
{
if (m_pcs) { LeaveCriticalSection(m_pcs); }
}
14 changes: 14 additions & 0 deletions hl2ss/hl2ss/lock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#pragma once

#include <Windows.h>

class CriticalSection
{
private:
CRITICAL_SECTION* m_pcs;

public:
CriticalSection(CRITICAL_SECTION* pcs);
~CriticalSection();
};
23 changes: 4 additions & 19 deletions hl2ss/hl2ss/utilities.cpp → hl2ss/hl2ss/log.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

#include "utilities.h"
#include <Windows.h>
#include <stdio.h>
#include <malloc.h>

//-----------------------------------------------------------------------------
// Logging
// Functions
//-----------------------------------------------------------------------------

// OK
Expand Down Expand Up @@ -40,20 +42,3 @@ void ShowMessage(const wchar_t* format, ...)
OutputDebugStringW(text);
free(text);
}

//-----------------------------------------------------------------------------
// Critical Section
//-----------------------------------------------------------------------------

// OK
CriticalSection::CriticalSection(void* pcs)
{
m_pcs = pcs;
if (m_pcs) { EnterCriticalSection(static_cast<CRITICAL_SECTION*>(m_pcs)); }
}

// OK
CriticalSection::~CriticalSection()
{
if (m_pcs) { LeaveCriticalSection(static_cast<CRITICAL_SECTION*>(m_pcs)); }
}
5 changes: 5 additions & 0 deletions hl2ss/hl2ss/log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#pragma once

void ShowMessage(const char* format, ...);
void ShowMessage(const wchar_t* format, ...);
1 change: 0 additions & 1 deletion hl2ss/hl2ss/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <mfapi.h>
#include "research_mode.h"
#include "server.h"
#include "utilities.h"
#include "ipc_rc.h"
#include "stream_pv.h"
#include "stream_rm.h"
Expand Down
1 change: 0 additions & 1 deletion hl2ss/hl2ss/microphone_capture.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#include <mfapi.h>
#include "microphone_capture.h"
#include "utilities.h"
#include "timestamps.h"
#include "types.h"

Expand Down
Loading

0 comments on commit 27fb95c

Please sign in to comment.