mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-07-02 16:39:14 +02:00
Compare commits
18 Commits
stable
...
workspaces
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6a81a4235 | ||
|
|
f94c439a8d | ||
|
|
a6f4357c94 | ||
|
|
6961fc66d0 | ||
|
|
8cd88f9817 | ||
|
|
57bdc9da6e | ||
|
|
81ee6b6efd | ||
|
|
ed1570a0e3 | ||
|
|
b364da81e8 | ||
|
|
8c9bd8ba64 | ||
|
|
aaee51b90e | ||
|
|
ff3c1f9252 | ||
|
|
99ee955dfb | ||
|
|
4d01062f76 | ||
|
|
d7d1e543ae | ||
|
|
272b725ff0 | ||
|
|
7884f4217a | ||
|
|
92014c81b9 |
3
.github/actions/spell-check/allow/code.txt
vendored
3
.github/actions/spell-check/allow/code.txt
vendored
@@ -432,3 +432,6 @@ SHELLEXPERIENCEHOST
|
||||
SHELLHOST
|
||||
STARTMENUEXPERIENCEHOST
|
||||
WIDGETBOARD
|
||||
|
||||
# URIs
|
||||
actioncenter
|
||||
|
||||
212
.github/actions/spell-check/allow/zoomit.txt
vendored
212
.github/actions/spell-check/allow/zoomit.txt
vendored
@@ -1,23 +1,51 @@
|
||||
accelscroll
|
||||
acq
|
||||
ADDTO
|
||||
ADDTOOL
|
||||
adr
|
||||
Adr
|
||||
ALWAYSTIP
|
||||
APPLYTOSUBMENUS
|
||||
ARCHMASK
|
||||
archs
|
||||
AUDCLNT
|
||||
autocorr
|
||||
avx
|
||||
axisdefer
|
||||
axisflip
|
||||
axisstart
|
||||
backlight
|
||||
BEOS
|
||||
bfi
|
||||
BFIN
|
||||
bfly
|
||||
BGRX
|
||||
bitmaps
|
||||
bitrev
|
||||
blits
|
||||
Borgerding
|
||||
Borland
|
||||
breakc
|
||||
BREAKSCR
|
||||
BUFFERFLAGS
|
||||
bugzilla
|
||||
Cands
|
||||
capturepath
|
||||
cbs
|
||||
centiseconds
|
||||
cexp
|
||||
cfx
|
||||
cfy
|
||||
cgem
|
||||
cifx
|
||||
cify
|
||||
CLASSW
|
||||
coeffs
|
||||
colblocks
|
||||
constantbuffer
|
||||
coprime
|
||||
cpuid
|
||||
cpx
|
||||
CREATEDIBSECTION
|
||||
CREATESTRUCTW
|
||||
crossfades
|
||||
@@ -28,109 +56,216 @@ CTLCOLORDLG
|
||||
CTLCOLOREDIT
|
||||
CTLCOLORLISTBOX
|
||||
CTrim
|
||||
CVTEPI
|
||||
DBuffer
|
||||
dcl
|
||||
dct
|
||||
ddx
|
||||
ddy
|
||||
Deinterleave
|
||||
denoise
|
||||
denoised
|
||||
DEVSOURCE
|
||||
DFCS
|
||||
DIVSCALAR
|
||||
DJGPP
|
||||
dlg
|
||||
dlu
|
||||
dnn
|
||||
DONTCARE
|
||||
downsample
|
||||
DRAWITEM
|
||||
DRAWITEMSTRUCT
|
||||
droppedband
|
||||
Droppedband
|
||||
DSPs
|
||||
dsum
|
||||
dupburst
|
||||
dupsegments
|
||||
DWLP
|
||||
eband
|
||||
ebx
|
||||
ECX
|
||||
EDITCONTROL
|
||||
EDSP
|
||||
emmintrin
|
||||
EMX
|
||||
ENABLEHOOK
|
||||
endloop
|
||||
ENDOFSTREAM
|
||||
ener
|
||||
enh
|
||||
ettings
|
||||
expectedlock
|
||||
expf
|
||||
fabs
|
||||
fabsf
|
||||
facbuf
|
||||
fastscroll
|
||||
FDE
|
||||
ffast
|
||||
FIXDIV
|
||||
floorf
|
||||
fmadd
|
||||
fout
|
||||
fstride
|
||||
fxc
|
||||
GETCHANNELRECT
|
||||
GETCHECK
|
||||
GETCOUNT
|
||||
GETDISPINFO
|
||||
GETSCREENSAVEACTIVE
|
||||
GETSCREENSAVETIMEOUT
|
||||
GETTHUMBRECT
|
||||
GIFs
|
||||
glu
|
||||
groupshared
|
||||
gru
|
||||
hcfdark
|
||||
hcfwhitespace
|
||||
hlsl
|
||||
Hsieh
|
||||
hstride
|
||||
HTBOTTOMRIGHT
|
||||
HTHEME
|
||||
htol
|
||||
ICONINFORMATION
|
||||
ICONWARNING
|
||||
idct
|
||||
IDIn
|
||||
IDISHWND
|
||||
ifft
|
||||
igc
|
||||
ilog
|
||||
imad
|
||||
imax
|
||||
imin
|
||||
immintrin
|
||||
Inj
|
||||
interp
|
||||
inttypes
|
||||
ishl
|
||||
itof
|
||||
jumprecover
|
||||
kfft
|
||||
kheight
|
||||
kissfft
|
||||
KSDATAFORMAT
|
||||
ksize
|
||||
ktime
|
||||
lastg
|
||||
latestcapture
|
||||
ldx
|
||||
LEFTNOWORDWRAP
|
||||
legitjumps
|
||||
lenmem
|
||||
letterbox
|
||||
lld
|
||||
lldx
|
||||
llu
|
||||
llums
|
||||
logfont
|
||||
lookback
|
||||
lpc
|
||||
lpcnet
|
||||
LPNMHDR
|
||||
LPNMTTDISPINFO
|
||||
lround
|
||||
lte
|
||||
luma
|
||||
Luma
|
||||
maj
|
||||
manualdrop
|
||||
maskcache
|
||||
maxabs
|
||||
maxcorr
|
||||
MAXFACTORS
|
||||
maxperiod
|
||||
maxstep
|
||||
memalign
|
||||
memid
|
||||
memneeded
|
||||
MENUINFO
|
||||
MFSTARTUP
|
||||
mfxhw
|
||||
mic
|
||||
middledrop
|
||||
minperiod
|
||||
MIPSr
|
||||
MJPEG
|
||||
MMRESULT
|
||||
momentumreversal
|
||||
movc
|
||||
mrate
|
||||
mrt
|
||||
MULBYSCALAR
|
||||
MULC
|
||||
MWERKS
|
||||
mycfg
|
||||
narrowstrip
|
||||
nbak
|
||||
nbytes
|
||||
ncapture
|
||||
nchw
|
||||
ncm
|
||||
nduplicates
|
||||
nfft
|
||||
NHWC
|
||||
niterations
|
||||
nmonitor
|
||||
nnet
|
||||
NONCLIENTMETRICS
|
||||
NONOTIFY
|
||||
nonvle
|
||||
normf
|
||||
nredraw
|
||||
nstop
|
||||
nsubpixel
|
||||
ntorn
|
||||
numthreads
|
||||
nvw
|
||||
Octasic
|
||||
osc
|
||||
OSCE
|
||||
ovflw
|
||||
OWNERDRAW
|
||||
PBGRA
|
||||
periodictrap
|
||||
pillarbox
|
||||
pfdc
|
||||
pillarbox
|
||||
playhead
|
||||
pnmh
|
||||
pointerreuse
|
||||
PPW
|
||||
prereq
|
||||
PSHR
|
||||
pstdint
|
||||
PSWA
|
||||
pwfx
|
||||
QCONST
|
||||
qpc
|
||||
Qpc
|
||||
quantums
|
||||
qweight
|
||||
RCSEGMODEL
|
||||
RCZOOMITSCR
|
||||
readback
|
||||
READERF
|
||||
realcapture
|
||||
REFKNOWNFOLDERID
|
||||
relu
|
||||
reposted
|
||||
RETURNCMD
|
||||
rnn
|
||||
rnnoise
|
||||
rotateleft
|
||||
rsqrt
|
||||
rtcd
|
||||
RTEXT
|
||||
RTH
|
||||
rtvs
|
||||
SCALEIN
|
||||
SCALEOUT
|
||||
SCREENSAVE
|
||||
SCRNSAVE
|
||||
SCRNSAVECONFIGURE
|
||||
@@ -138,43 +273,80 @@ scrnsavw
|
||||
Scrnsavw
|
||||
scrollramp
|
||||
SCROLLSIZEGRIP
|
||||
selfie
|
||||
selftest
|
||||
SETBARCOLOR
|
||||
SETBKCOLOR
|
||||
SETDEFID
|
||||
SETRECT
|
||||
SETSCREENSAVETIMEOUT
|
||||
SETTIPSIDE
|
||||
sgem
|
||||
sgemv
|
||||
sgv
|
||||
SHAREMODE
|
||||
SHAREVIOLATION
|
||||
shortlist
|
||||
simde
|
||||
siv
|
||||
slowthenfast
|
||||
smallstart
|
||||
SNIPOCR
|
||||
softmax
|
||||
sqrtf
|
||||
SROUND
|
||||
srvs
|
||||
ssi
|
||||
startuprecovery
|
||||
stdint
|
||||
stf
|
||||
stopafter
|
||||
STREAMFLAGS
|
||||
SUBFROM
|
||||
subias
|
||||
submix
|
||||
sxx
|
||||
sxy
|
||||
symbian
|
||||
synthesising
|
||||
syy
|
||||
tallportal
|
||||
TBTS
|
||||
tci
|
||||
tcsicmp
|
||||
TEXTCALLBACK
|
||||
TEXTMETRIC
|
||||
tgsm
|
||||
THIRDPARTY
|
||||
tinystep
|
||||
tme
|
||||
toolbars
|
||||
TOOLINFO
|
||||
TRACKMOUSEEVENT
|
||||
TRIANGLELIST
|
||||
TTM
|
||||
TTN
|
||||
TWID
|
||||
UADD
|
||||
uav
|
||||
uavs
|
||||
uge
|
||||
Unadvise
|
||||
upscaled
|
||||
upscales
|
||||
USUB
|
||||
utof
|
||||
vad
|
||||
vaddq
|
||||
vaddvq
|
||||
valgrind
|
||||
Valin
|
||||
vandq
|
||||
vblank
|
||||
vcgeq
|
||||
vdup
|
||||
vectorizer
|
||||
VERTID
|
||||
VIDCAP
|
||||
vld
|
||||
vle
|
||||
@@ -184,6 +356,7 @@ vminq
|
||||
vmlal
|
||||
vmull
|
||||
vqaddq
|
||||
VSHR
|
||||
vshrn
|
||||
vsntprintf
|
||||
vsnwprintf
|
||||
@@ -194,7 +367,9 @@ WAVEFORMATEXTENSIBLE
|
||||
webcam
|
||||
Webcam
|
||||
webcams
|
||||
Wextra
|
||||
wfopen
|
||||
WGC
|
||||
wideportal
|
||||
wil
|
||||
WMU
|
||||
@@ -202,11 +377,46 @@ wrapjump
|
||||
wtol
|
||||
WTSSESSION
|
||||
WTSUn
|
||||
wxyz
|
||||
xchg
|
||||
xcorr
|
||||
XEnd
|
||||
Xfl
|
||||
Xiang
|
||||
Xiph
|
||||
xmmintrin
|
||||
xptr
|
||||
xshift
|
||||
XStart
|
||||
XStep
|
||||
xxxy
|
||||
xxyx
|
||||
xxyz
|
||||
xyw
|
||||
xywx
|
||||
xyxx
|
||||
xyxz
|
||||
xyzw
|
||||
xyzx
|
||||
xzwx
|
||||
xzxx
|
||||
Yfl
|
||||
YInternal
|
||||
yshift
|
||||
YUV
|
||||
yyyx
|
||||
yyzw
|
||||
yzw
|
||||
yzwy
|
||||
yzyy
|
||||
Zhou
|
||||
Zhu
|
||||
ZMBS
|
||||
zncc
|
||||
Zncc
|
||||
ZNCC
|
||||
zrh
|
||||
zwzz
|
||||
zyzw
|
||||
zzwz
|
||||
zzzw
|
||||
|
||||
4
.github/actions/spell-check/excludes.txt
vendored
4
.github/actions/spell-check/excludes.txt
vendored
@@ -112,8 +112,6 @@
|
||||
^src/modules/cmdpal/Microsoft\.CmdPal\.UI/Settings/InternalPage\.SampleData\.cs$
|
||||
^src/modules/cmdpal/Tests/Microsoft\.CmdPal\.Common\.UnitTests/.*\.TestData\.cs$
|
||||
^src/modules/cmdpal/Tests/Microsoft\.CmdPal\.Common\.UnitTests/Text/.*\.cs$
|
||||
^src/modules/cmdpal/Tests/Microsoft\.CommandPalette\.Extensions\.Toolkit\.UnitTests/FuzzyMatcherComparisonTests.cs$
|
||||
^src/modules/cmdpal/Tests/Microsoft\.CommandPalette\.Extensions\.Toolkit\.UnitTests/FuzzyMatcherDiacriticsTests.cs$
|
||||
^src/modules/colorPicker/ColorPickerUI/Shaders/GridShader\.cso$
|
||||
^src/modules/launcher/Plugins/Microsoft\.PowerToys\.Run\.Plugin\.TimeDate/Properties/
|
||||
^src/modules/MouseUtils/MouseJumpUI/MainForm\.resx$
|
||||
@@ -137,6 +135,8 @@
|
||||
^src/modules/previewpane/SvgPreviewHandler/SvgHTMLPreviewGenerator\.cs$
|
||||
^src/modules/previewpane/UnitTests-MarkdownPreviewHandler/HelperFiles/MarkdownWithHTMLImageTag\.txt$
|
||||
^src/modules/registrypreview/RegistryPreviewUILib/Controls/HexBox/.*$
|
||||
^src/modules/ZoomIt/ZoomIt/rnnoise/
|
||||
^src/modules/ZoomIt/ZoomIt/selfie_segmentation\.onnx$
|
||||
^src/modules/ZoomIt/ZoomIt/ZoomIt\.idc$
|
||||
^src/Monaco/
|
||||
^tools/project_template/ModuleTemplate/resource\.h$
|
||||
|
||||
7
.github/actions/spell-check/expect.txt
vendored
7
.github/actions/spell-check/expect.txt
vendored
@@ -113,7 +113,6 @@ azman
|
||||
azureaiinference
|
||||
azureinference
|
||||
azureopenai
|
||||
Backlight
|
||||
backticks
|
||||
Badflags
|
||||
Badmode
|
||||
@@ -472,7 +471,6 @@ DWMWINDOWATTRIBUTE
|
||||
DWMWINDOWMAXIMIZEDCHANGE
|
||||
DWORDLONG
|
||||
dworigin
|
||||
DWRITE
|
||||
dxgi
|
||||
Dxva
|
||||
eab
|
||||
@@ -998,7 +996,6 @@ luid
|
||||
lusrmgr
|
||||
LVDS
|
||||
LWA
|
||||
LWIN
|
||||
LZero
|
||||
MAGTRANSFORM
|
||||
makeappx
|
||||
@@ -1208,7 +1205,6 @@ nonclient
|
||||
NONCLIENTMETRICSW
|
||||
NONELEVATED
|
||||
nonspace
|
||||
nonstd
|
||||
NOOWNERZORDER
|
||||
NOPARENTNOTIFY
|
||||
NOPREFIX
|
||||
@@ -1422,7 +1418,6 @@ Prefixer
|
||||
Premul
|
||||
prependpath
|
||||
prepopulate
|
||||
Prereq
|
||||
prevhost
|
||||
previewer
|
||||
PREVIEWHANDLERFRAMEINFO
|
||||
@@ -2000,7 +1995,6 @@ valuegenerator
|
||||
VARTYPE
|
||||
vbcscompiler
|
||||
vcamp
|
||||
VCENTER
|
||||
vcgtq
|
||||
VCINSTALLDIR
|
||||
vcp
|
||||
@@ -2038,7 +2032,6 @@ vorrq
|
||||
VOS
|
||||
vpaddlq
|
||||
vqsubq
|
||||
VREDRAW
|
||||
vreinterpretq
|
||||
VSC
|
||||
VSCBD
|
||||
|
||||
6
.github/actions/spell-check/patterns.txt
vendored
6
.github/actions/spell-check/patterns.txt
vendored
@@ -312,3 +312,9 @@ ms-windows-store://\S+
|
||||
|
||||
# ANSI color codes
|
||||
(?:\\(?:u00|x)1[Bb]|\\03[1-7]|\x1b|\\u\{1[Bb]\})\[\d+(?:;\d+)*m
|
||||
|
||||
# Special licenses text from RNNoise (BSD-style disclaimer: ``AS IS'')
|
||||
``AS IS''
|
||||
|
||||
# Old school moniker for macOS from RNNoise
|
||||
MacOS
|
||||
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -19,6 +19,9 @@
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
!**/rnnoise/
|
||||
!**/rnnoise/x86/
|
||||
!**/rnnoise/x86/**
|
||||
ARM64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
@@ -375,3 +378,6 @@ installer/*/*.wxs.bk
|
||||
vcpkg_installed/
|
||||
|
||||
deps/vcpkg/
|
||||
|
||||
# Superpowers-generated docs (specs, design, plans) — local-only, not committed
|
||||
docs/superpowers/
|
||||
|
||||
@@ -234,8 +234,8 @@
|
||||
"PowerToys.WorkspacesWindowArranger.exe",
|
||||
"PowerToys.WorkspacesEditor.exe",
|
||||
"PowerToys.WorkspacesEditor.dll",
|
||||
"PowerToys.WorkspacesLauncherUI.exe",
|
||||
"PowerToys.WorkspacesLauncherUI.dll",
|
||||
"WinUI3Apps\\PowerToys.WorkspacesLauncherUI.exe",
|
||||
"WinUI3Apps\\PowerToys.WorkspacesLauncherUI.dll",
|
||||
"PowerToys.WorkspacesModuleInterface.dll",
|
||||
"PowerToys.WorkspacesCsharpLibrary.dll",
|
||||
|
||||
|
||||
@@ -78,10 +78,10 @@
|
||||
<PackageVersion Include="Microsoft.Windows.CsWinRT" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.Windows.ImplementationLibrary" Version="1.0.250325.1"/>
|
||||
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.6901" />
|
||||
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="2.0.1" />
|
||||
<PackageVersion Include="Microsoft.WindowsAppSDK.Foundation" Version="2.0.20" />
|
||||
<PackageVersion Include="Microsoft.WindowsAppSDK.AI" Version="2.0.185" />
|
||||
<PackageVersion Include="Microsoft.WindowsAppSDK.Runtime" Version="2.0.1" />
|
||||
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.WindowsAppSDK.Foundation" Version="2.1.0" />
|
||||
<PackageVersion Include="Microsoft.WindowsAppSDK.AI" Version="2.2.3" />
|
||||
<PackageVersion Include="Microsoft.WindowsAppSDK.Runtime" Version="2.2.0" />
|
||||
<PackageVersion Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
|
||||
<PackageVersion Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
|
||||
<PackageVersion Include="ModernWpfUI" Version="0.9.4" />
|
||||
|
||||
@@ -1020,7 +1020,7 @@
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
<Project Path="src/modules/Workspaces/WorkspacesLauncher/WorkspacesLauncher.vcxproj" Id="2cac093e-5fcf-4102-9c2c-ac7dd5d9eb96" />
|
||||
<Project Path="src/modules/Workspaces/WorkspacesLauncherUI/WorkspacesLauncherUI.csproj">
|
||||
<Project Path="src/modules/Workspaces/WorkspacesLauncherUI.WinUI/WorkspacesLauncherUI.WinUI.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
@@ -1103,6 +1103,14 @@
|
||||
<File Path="src/Solution.props" />
|
||||
<File Path="src/Version.props" />
|
||||
</Folder>
|
||||
<Folder Name="/src/" />
|
||||
<Folder Name="/src/modules/" />
|
||||
<Folder Name="/src/modules/Workspaces/">
|
||||
<Project Path="src/modules/Workspaces/WorkspacesLauncherUI.UnitTests/WorkspacesLauncherUI.UnitTests.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
</Folder>
|
||||
<Project Path="src/ActionRunner/ActionRunner.vcxproj" Id="d29ddd63-e2cf-4657-9fd5-2aede4257e5d">
|
||||
<BuildDependency Project="src/common/updating/updating.vcxproj" />
|
||||
</Project>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 258 KiB After Width: | Height: | Size: 134 KiB |
@@ -79,4 +79,4 @@ Below are community created plugins that target a website or software. They are
|
||||
| [Linear](https://github.com/vednig/powertoys-linear) | [vednig](https://github.com/vednig) | Create Linear Issues directly from Powertoys Run |
|
||||
| [PerplexitySearchShortcut](https://github.com/0x6f677548/PowerToys-Run-PerplexitySearchShortcut) | [0x6f677548](https://github.com/0x6f677548) | Search Perplexity |
|
||||
| [SpeedTest](https://github.com/ruslanlap/PowerToysRun-SpeedTest) | [ruslanlap](https://github.com/ruslanlap) | One-command internet speed tests with real-time results, modern UI, and shareable links. |
|
||||
| [DiskAnalyzer](https://github.com/thetsaw/PowerToys.Plugin) | [thetsaw](https://github.com/thetsaw) | Scan folders, find the largest files, and view drive space usage with visual progress bars. |
|
||||
| [DiskAnalyzer](https://github.com/valley-soft/powertoys-diskanalyzer) | [ValleySoft](https://github.com/valley-soft) | Scan folders, find the largest files, and view drive space usage. |
|
||||
|
||||
@@ -73,7 +73,8 @@
|
||||
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<AdditionalOptions>%(AdditionalOptions) /bigobj</AdditionalOptions>
|
||||
<PreprocessorDefinitions>_WINRT_DLL;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<!-- TODO: _SILENCE_EXPERIMENTAL_COROUTINE_DEPRECATION_WARNINGS: suppress VS 2026 STL hard error for <experimental/coroutine> until the code is ported to <coroutine> -->
|
||||
<PreprocessorDefinitions>_WINRT_DLL;WINRT_LEAN_AND_MEAN;_SILENCE_EXPERIMENTAL_COROUTINE_DEPRECATION_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>../../..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
||||
</ClCompile>
|
||||
|
||||
@@ -46,7 +46,7 @@ void LauncherUIHelper::LaunchUI()
|
||||
GetModuleFileName(NULL, buffer, MAX_PATH);
|
||||
std::wstring path = std::filesystem::path(buffer).parent_path();
|
||||
|
||||
auto res = AppLauncher::LaunchApp(path + L"\\PowerToys.WorkspacesLauncherUI.exe", L"", false);
|
||||
auto res = AppLauncher::LaunchApp(path + L"\\WinUI3Apps\\PowerToys.WorkspacesLauncherUI.exe", L"", false);
|
||||
if (res.isOk())
|
||||
{
|
||||
auto value = res.value();
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using WorkspacesLauncherUI.Data;
|
||||
|
||||
namespace WorkspacesLauncherUI.UnitTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for ApplicationWrapper struct field mapping.
|
||||
/// All fields must be accessible and hold correct values after deserialization.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class ApplicationDataModelTests
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_ApplicationName_StoresDisplayName()
|
||||
{
|
||||
var app = new ApplicationWrapper { Application = "Visual Studio Code" };
|
||||
Assert.AreEqual("Visual Studio Code", app.Application);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_ExecutablePath_StoresFullPathWithSpaces()
|
||||
{
|
||||
var app = new ApplicationWrapper { ApplicationPath = @"C:\Users\test\AppData\Local\Programs\Microsoft VS Code\Code.exe" };
|
||||
Assert.AreEqual(@"C:\Users\test\AppData\Local\Programs\Microsoft VS Code\Code.exe", app.ApplicationPath);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_WindowTitle_StoresActiveWindowTitle()
|
||||
{
|
||||
var app = new ApplicationWrapper { Title = "MyProject - Visual Studio Code" };
|
||||
Assert.AreEqual("MyProject - Visual Studio Code", app.Title);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_PackageFullName_StoresUwpPackageIdentifier()
|
||||
{
|
||||
var app = new ApplicationWrapper { PackageFullName = "Microsoft.WindowsTerminal_1.21.0.0_x64__8wekyb3d8bbwe" };
|
||||
Assert.AreEqual("Microsoft.WindowsTerminal_1.21.0.0_x64__8wekyb3d8bbwe", app.PackageFullName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_AppUserModelId_StoresAumidForPackagedApps()
|
||||
{
|
||||
var app = new ApplicationWrapper { AppUserModelId = "Microsoft.WindowsTerminal_8wekyb3d8bbwe!App" };
|
||||
Assert.AreEqual("Microsoft.WindowsTerminal_8wekyb3d8bbwe!App", app.AppUserModelId);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_PwaAppId_StoresChromeOrEdgePwaIdentifier()
|
||||
{
|
||||
var app = new ApplicationWrapper { PwaAppId = "fmgjjmmmlfnkbppncijlocphclkkleod" };
|
||||
Assert.AreEqual("fmgjjmmmlfnkbppncijlocphclkkleod", app.PwaAppId);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_CliArguments_StoresLaunchArgumentsExactly()
|
||||
{
|
||||
var app = new ApplicationWrapper { CommandLineArguments = "--reuse-window --goto file.ts:42" };
|
||||
Assert.AreEqual("--reuse-window --goto file.ts:42", app.CommandLineArguments);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_IsElevated_StoresAdminRunningState()
|
||||
{
|
||||
var app = new ApplicationWrapper { IsElevated = true };
|
||||
Assert.IsTrue(app.IsElevated);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_CanLaunchElevated_StoresElevationCapability()
|
||||
{
|
||||
var app = new ApplicationWrapper { CanLaunchElevated = true };
|
||||
Assert.IsTrue(app.CanLaunchElevated);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_Minimized_StoresMinimizedWindowState()
|
||||
{
|
||||
var app = new ApplicationWrapper { Minimized = true };
|
||||
Assert.IsTrue(app.Minimized);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_Maximized_StoresMaximizedWindowState()
|
||||
{
|
||||
var app = new ApplicationWrapper { Maximized = true };
|
||||
Assert.IsTrue(app.Maximized);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_MonitorIndex_StoresTargetDisplayNumber()
|
||||
{
|
||||
var app = new ApplicationWrapper { Monitor = 2 };
|
||||
Assert.AreEqual(2, app.Monitor);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppField_WindowPosition_StoresRectangleCoordinates()
|
||||
{
|
||||
var pos = new PositionWrapper { X = 100, Y = 200, Width = 800, Height = 600 };
|
||||
var app = new ApplicationWrapper { Position = pos };
|
||||
|
||||
Assert.AreEqual(100, app.Position.X);
|
||||
Assert.AreEqual(200, app.Position.Y);
|
||||
Assert.AreEqual(800, app.Position.Width);
|
||||
Assert.AreEqual(600, app.Position.Height);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppDefaults_StringFields_AreNullBeforeDeserialization()
|
||||
{
|
||||
ApplicationWrapper app = default;
|
||||
|
||||
Assert.IsNull(app.Application);
|
||||
Assert.IsNull(app.ApplicationPath);
|
||||
Assert.IsNull(app.Title);
|
||||
Assert.IsNull(app.PackageFullName);
|
||||
Assert.IsNull(app.AppUserModelId);
|
||||
Assert.IsNull(app.PwaAppId);
|
||||
Assert.IsNull(app.CommandLineArguments);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppDefaults_BooleanFields_AreFalseBeforeDeserialization()
|
||||
{
|
||||
ApplicationWrapper app = default;
|
||||
|
||||
Assert.IsFalse(app.IsElevated);
|
||||
Assert.IsFalse(app.CanLaunchElevated);
|
||||
Assert.IsFalse(app.Minimized);
|
||||
Assert.IsFalse(app.Maximized);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppDefaults_MonitorIndex_IsZeroPrimaryMonitor()
|
||||
{
|
||||
ApplicationWrapper app = default;
|
||||
Assert.AreEqual(0, app.Monitor);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppConfig_AdminAppOnSecondMonitor_AllFieldsPopulated()
|
||||
{
|
||||
var app = new ApplicationWrapper
|
||||
{
|
||||
Application = "Registry Editor",
|
||||
ApplicationPath = @"C:\Windows\regedit.exe",
|
||||
Title = "Registry Editor",
|
||||
PackageFullName = string.Empty,
|
||||
AppUserModelId = string.Empty,
|
||||
PwaAppId = string.Empty,
|
||||
CommandLineArguments = string.Empty,
|
||||
IsElevated = true,
|
||||
CanLaunchElevated = true,
|
||||
Minimized = false,
|
||||
Maximized = false,
|
||||
Position = new PositionWrapper { X = 1920, Y = 0, Width = 1024, Height = 768 },
|
||||
Monitor = 1,
|
||||
};
|
||||
|
||||
Assert.IsTrue(app.IsElevated);
|
||||
Assert.AreEqual(1, app.Monitor);
|
||||
Assert.AreEqual(1920, app.Position.X);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppConfig_MinimizedOnThirdMonitor_StateAndMonitorCorrect()
|
||||
{
|
||||
var app = new ApplicationWrapper
|
||||
{
|
||||
Application = "Notepad",
|
||||
ApplicationPath = @"C:\Windows\System32\notepad.exe",
|
||||
Minimized = true,
|
||||
Maximized = false,
|
||||
Position = new PositionWrapper { X = 3840, Y = 0, Width = 800, Height = 600 },
|
||||
Monitor = 2,
|
||||
};
|
||||
|
||||
Assert.IsTrue(app.Minimized);
|
||||
Assert.IsFalse(app.Maximized);
|
||||
Assert.AreEqual(2, app.Monitor);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppConfig_PathWithParenthesesAndSpaces_PreservedExactly()
|
||||
{
|
||||
string complexPath = @"C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE";
|
||||
var app = new ApplicationWrapper { ApplicationPath = complexPath };
|
||||
Assert.AreEqual(complexPath, app.ApplicationPath);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void AppConfig_ExplicitEmptyStrings_AreEmptyNotNull()
|
||||
{
|
||||
var app = new ApplicationWrapper
|
||||
{
|
||||
Application = string.Empty,
|
||||
ApplicationPath = string.Empty,
|
||||
Title = string.Empty,
|
||||
PackageFullName = string.Empty,
|
||||
AppUserModelId = string.Empty,
|
||||
PwaAppId = string.Empty,
|
||||
CommandLineArguments = string.Empty,
|
||||
};
|
||||
|
||||
Assert.AreEqual(string.Empty, app.Application);
|
||||
Assert.AreEqual(string.Empty, app.ApplicationPath);
|
||||
Assert.AreEqual(string.Empty, app.PackageFullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using WorkspacesLauncherUI.Utils;
|
||||
|
||||
namespace WorkspacesLauncherUI.UnitTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for DashCaseNamingPolicy and StringUtils.
|
||||
/// These utilities control JSON property name mapping for IPC messages.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class IpcJsonPropertyNamingTests
|
||||
{
|
||||
private readonly DashCaseNamingPolicy _policy = DashCaseNamingPolicy.Instance;
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_ApplicationPath_MapsTo_application_path()
|
||||
{
|
||||
Assert.AreEqual("application-path", _policy.ConvertName("ApplicationPath"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_Application_MapsTo_application()
|
||||
{
|
||||
Assert.AreEqual("application", _policy.ConvertName("Application"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_AppUserModelId_MapsTo_app_user_model_id()
|
||||
{
|
||||
Assert.AreEqual("app-user-model-id", _policy.ConvertName("AppUserModelId"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_LowercaseInput_RemainsUnchanged()
|
||||
{
|
||||
Assert.AreEqual("title", _policy.ConvertName("title"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_SingleUppercaseChar_PreservedAsIs()
|
||||
{
|
||||
Assert.AreEqual("X", _policy.ConvertName("X"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_SingleLowercaseChar_PreservedAsIs()
|
||||
{
|
||||
Assert.AreEqual("x", _policy.ConvertName("x"));
|
||||
}
|
||||
|
||||
// Exact IPC property names that must match the C++ side
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_PackageFullName_MatchesCppIpcKey()
|
||||
{
|
||||
Assert.AreEqual("package-full-name", _policy.ConvertName("PackageFullName"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_AppUserModelId_MatchesCppIpcKey()
|
||||
{
|
||||
Assert.AreEqual("app-user-model-id", _policy.ConvertName("AppUserModelId"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_PwaAppId_MatchesCppIpcKey()
|
||||
{
|
||||
Assert.AreEqual("pwa-app-id", _policy.ConvertName("PwaAppId"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_CommandLineArguments_MatchesCppIpcKey()
|
||||
{
|
||||
Assert.AreEqual("command-line-arguments", _policy.ConvertName("CommandLineArguments"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_IsElevated_MatchesCppIpcKey()
|
||||
{
|
||||
Assert.AreEqual("is-elevated", _policy.ConvertName("IsElevated"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_CanLaunchElevated_MatchesCppIpcKey()
|
||||
{
|
||||
Assert.AreEqual("can-launch-elevated", _policy.ConvertName("CanLaunchElevated"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_ApplicationPath_MatchesCppIpcKey()
|
||||
{
|
||||
Assert.AreEqual("application-path", _policy.ConvertName("ApplicationPath"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void NamingPolicy_Singleton_ReturnsSameInstanceEveryTime()
|
||||
{
|
||||
var instance1 = DashCaseNamingPolicy.Instance;
|
||||
var instance2 = DashCaseNamingPolicy.Instance;
|
||||
Assert.AreSame(instance1, instance2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void StringConversion_TwoUppercaseLetters_InsertsDashBetween()
|
||||
{
|
||||
Assert.AreEqual("a-b", "AB".UpperCamelCaseToDashCase());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void StringConversion_AllLowercase_NoTransformation()
|
||||
{
|
||||
Assert.AreEqual("alllowercase", "alllowercase".UpperCamelCaseToDashCase());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Serialization")]
|
||||
public void StringConversion_NumbersInMiddle_PreservedWithDashBeforeNextUpper()
|
||||
{
|
||||
Assert.AreEqual("version2-test", "Version2Test".UpperCamelCaseToDashCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,539 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using WorkspacesLauncherUI.Data;
|
||||
|
||||
namespace WorkspacesLauncherUI.UnitTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for JSON deserialization of IPC messages received from the C++ launcher engine.
|
||||
/// These messages drive the entire Launcher UI state and must remain stable
|
||||
/// across any future UI or data layer changes.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class IpcMessageDeserializationTests
|
||||
{
|
||||
private const string FullIpcMessage = @"{
|
||||
""processId"": 12345,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": [
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""Visual Studio Code"",
|
||||
""application-path"": ""C:\\Users\\test\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"",
|
||||
""title"": ""MyProject - Visual Studio Code"",
|
||||
""package-full-name"": """",
|
||||
""app-user-model-id"": """",
|
||||
""pwa-app-id"": """",
|
||||
""command-line-arguments"": ""--reuse-window"",
|
||||
""is-elevated"": false,
|
||||
""can-launch-elevated"": true,
|
||||
""minimized"": false,
|
||||
""maximized"": true,
|
||||
""position"": { ""X"": 0, ""Y"": 0, ""width"": 1920, ""height"": 1080 },
|
||||
""monitor"": 0
|
||||
},
|
||||
""state"": 2
|
||||
},
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""Windows Terminal"",
|
||||
""application-path"": ""C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_1.0.0.0_x64__8wekyb3d8bbwe\\wt.exe"",
|
||||
""title"": ""PowerShell"",
|
||||
""package-full-name"": ""Microsoft.WindowsTerminal_1.0.0.0_x64__8wekyb3d8bbwe"",
|
||||
""app-user-model-id"": ""Microsoft.WindowsTerminal_8wekyb3d8bbwe!App"",
|
||||
""pwa-app-id"": """",
|
||||
""command-line-arguments"": """",
|
||||
""is-elevated"": false,
|
||||
""can-launch-elevated"": false,
|
||||
""minimized"": false,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": 960, ""Y"": 0, ""width"": 960, ""height"": 540 },
|
||||
""monitor"": 0
|
||||
},
|
||||
""state"": 0
|
||||
},
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""Notepad"",
|
||||
""application-path"": ""C:\\Windows\\System32\\notepad.exe"",
|
||||
""title"": ""Untitled - Notepad"",
|
||||
""package-full-name"": """",
|
||||
""app-user-model-id"": """",
|
||||
""pwa-app-id"": """",
|
||||
""command-line-arguments"": """",
|
||||
""is-elevated"": false,
|
||||
""can-launch-elevated"": true,
|
||||
""minimized"": true,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": 100, ""Y"": 100, ""width"": 800, ""height"": 600 },
|
||||
""monitor"": 1
|
||||
},
|
||||
""state"": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_WithMultipleApps_ExtractsLauncherProcessId()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(FullIpcMessage);
|
||||
Assert.AreEqual(12345, result.LauncherProcessID);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_WithThreeApps_DeserializesAllAppEntries()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(FullIpcMessage);
|
||||
Assert.AreEqual(3, result.AppLaunchInfos.AppLaunchInfoList.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_Win32Application_DeserializesAllApplicationFields()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(FullIpcMessage);
|
||||
var vscode = result.AppLaunchInfos.AppLaunchInfoList[0];
|
||||
|
||||
Assert.AreEqual("Visual Studio Code", vscode.Application.Application);
|
||||
Assert.AreEqual(@"C:\Users\test\AppData\Local\Programs\Microsoft VS Code\Code.exe", vscode.Application.ApplicationPath);
|
||||
Assert.AreEqual("MyProject - Visual Studio Code", vscode.Application.Title);
|
||||
Assert.AreEqual(string.Empty, vscode.Application.PackageFullName);
|
||||
Assert.AreEqual(string.Empty, vscode.Application.AppUserModelId);
|
||||
Assert.AreEqual(string.Empty, vscode.Application.PwaAppId);
|
||||
Assert.AreEqual("--reuse-window", vscode.Application.CommandLineArguments);
|
||||
Assert.IsFalse(vscode.Application.IsElevated);
|
||||
Assert.IsTrue(vscode.Application.CanLaunchElevated);
|
||||
Assert.IsFalse(vscode.Application.Minimized);
|
||||
Assert.IsTrue(vscode.Application.Maximized);
|
||||
Assert.AreEqual(0, vscode.Application.Monitor);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_Win32Application_DeserializesWindowPosition()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(FullIpcMessage);
|
||||
var pos = result.AppLaunchInfos.AppLaunchInfoList[0].Application.Position;
|
||||
|
||||
Assert.AreEqual(0, pos.X);
|
||||
Assert.AreEqual(0, pos.Y);
|
||||
Assert.AreEqual(1920, pos.Width);
|
||||
Assert.AreEqual(1080, pos.Height);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_PackagedUwpApp_DeserializesPackageIdentifiers()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(FullIpcMessage);
|
||||
var terminal = result.AppLaunchInfos.AppLaunchInfoList[1];
|
||||
|
||||
Assert.AreEqual("Windows Terminal", terminal.Application.Application);
|
||||
Assert.AreEqual("Microsoft.WindowsTerminal_1.0.0.0_x64__8wekyb3d8bbwe", terminal.Application.PackageFullName);
|
||||
Assert.AreEqual("Microsoft.WindowsTerminal_8wekyb3d8bbwe!App", terminal.Application.AppUserModelId);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_StateValueTwo_MapsToLaunchedAndMovedEnum()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(FullIpcMessage);
|
||||
Assert.AreEqual(LaunchingState.LaunchedAndMoved, result.AppLaunchInfos.AppLaunchInfoList[0].State);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_StateValueZero_MapsToWaitingEnum()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(FullIpcMessage);
|
||||
Assert.AreEqual(LaunchingState.Waiting, result.AppLaunchInfos.AppLaunchInfoList[1].State);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_StateValueThree_MapsToFailedEnum()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(FullIpcMessage);
|
||||
Assert.AreEqual(LaunchingState.Failed, result.AppLaunchInfos.AppLaunchInfoList[2].State);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_MinimizedWindow_DeserializesWindowStateFlags()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(FullIpcMessage);
|
||||
var notepad = result.AppLaunchInfos.AppLaunchInfoList[2];
|
||||
|
||||
Assert.IsTrue(notepad.Application.Minimized);
|
||||
Assert.IsFalse(notepad.Application.Maximized);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_SecondaryMonitor_DeserializesMonitorIndex()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(FullIpcMessage);
|
||||
Assert.AreEqual(1, result.AppLaunchInfos.AppLaunchInfoList[2].Application.Monitor);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_ProgressiveWebApp_DeserializesPwaIdentifier()
|
||||
{
|
||||
string pwaMessage = @"{
|
||||
""processId"": 100,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": [
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""Gmail"",
|
||||
""application-path"": ""C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"",
|
||||
""title"": ""Gmail"",
|
||||
""package-full-name"": """",
|
||||
""app-user-model-id"": """",
|
||||
""pwa-app-id"": ""fmgjjmmmlfnkbppncijlocphclkkleod"",
|
||||
""command-line-arguments"": """",
|
||||
""is-elevated"": false,
|
||||
""can-launch-elevated"": false,
|
||||
""minimized"": false,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": 0, ""Y"": 0, ""width"": 800, ""height"": 600 },
|
||||
""monitor"": 0
|
||||
},
|
||||
""state"": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(pwaMessage);
|
||||
var gmail = result.AppLaunchInfos.AppLaunchInfoList[0];
|
||||
|
||||
Assert.AreEqual("fmgjjmmmlfnkbppncijlocphclkkleod", gmail.Application.PwaAppId);
|
||||
Assert.AreEqual(LaunchingState.Launched, gmail.State);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_ElevatedProcess_DeserializesAdminFlags()
|
||||
{
|
||||
string elevatedMessage = @"{
|
||||
""processId"": 200,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": [
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""Registry Editor"",
|
||||
""application-path"": ""C:\\Windows\\regedit.exe"",
|
||||
""title"": ""Registry Editor"",
|
||||
""package-full-name"": """",
|
||||
""app-user-model-id"": """",
|
||||
""pwa-app-id"": """",
|
||||
""command-line-arguments"": """",
|
||||
""is-elevated"": true,
|
||||
""can-launch-elevated"": true,
|
||||
""minimized"": false,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": 100, ""Y"": 100, ""width"": 1024, ""height"": 768 },
|
||||
""monitor"": 0
|
||||
},
|
||||
""state"": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(elevatedMessage);
|
||||
var regedit = result.AppLaunchInfos.AppLaunchInfoList[0];
|
||||
|
||||
Assert.IsTrue(regedit.Application.IsElevated);
|
||||
Assert.IsTrue(regedit.Application.CanLaunchElevated);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_SingleAppWorkspace_DeserializesSuccessfully()
|
||||
{
|
||||
string singleAppMessage = @"{
|
||||
""processId"": 1,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": [
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""Notepad"",
|
||||
""application-path"": ""C:\\Windows\\System32\\notepad.exe"",
|
||||
""title"": """",
|
||||
""package-full-name"": """",
|
||||
""app-user-model-id"": """",
|
||||
""pwa-app-id"": """",
|
||||
""command-line-arguments"": """",
|
||||
""is-elevated"": false,
|
||||
""can-launch-elevated"": false,
|
||||
""minimized"": false,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": 0, ""Y"": 0, ""width"": 400, ""height"": 300 },
|
||||
""monitor"": 0
|
||||
},
|
||||
""state"": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(singleAppMessage);
|
||||
|
||||
Assert.AreEqual(1, result.AppLaunchInfos.AppLaunchInfoList.Count);
|
||||
Assert.AreEqual("Notepad", result.AppLaunchInfos.AppLaunchInfoList[0].Application.Application);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_ZeroApps_ReturnsEmptyListWithValidProcessId()
|
||||
{
|
||||
string emptyAppsMessage = @"{
|
||||
""processId"": 42,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": []
|
||||
}
|
||||
}";
|
||||
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(emptyAppsMessage);
|
||||
|
||||
Assert.AreEqual(42, result.LauncherProcessID);
|
||||
Assert.AreEqual(0, result.AppLaunchInfos.AppLaunchInfoList.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
[ExpectedException(typeof(JsonException))]
|
||||
public void IpcMessage_MalformedJson_ThrowsJsonException()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
parser.Deserialize("not valid json {{{");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
[ExpectedException(typeof(JsonException))]
|
||||
public void IpcMessage_EmptyPayload_ThrowsJsonException()
|
||||
{
|
||||
var parser = new AppLaunchData();
|
||||
parser.Deserialize(string.Empty);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_LeftOfPrimaryMonitor_DeserializesNegativeCoordinates()
|
||||
{
|
||||
string negativePositionMessage = @"{
|
||||
""processId"": 1,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": [
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""Notepad"",
|
||||
""application-path"": ""C:\\Windows\\System32\\notepad.exe"",
|
||||
""title"": """",
|
||||
""package-full-name"": """",
|
||||
""app-user-model-id"": """",
|
||||
""pwa-app-id"": """",
|
||||
""command-line-arguments"": """",
|
||||
""is-elevated"": false,
|
||||
""can-launch-elevated"": false,
|
||||
""minimized"": false,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": -1920, ""Y"": -200, ""width"": 800, ""height"": 600 },
|
||||
""monitor"": 1
|
||||
},
|
||||
""state"": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(negativePositionMessage);
|
||||
var pos = result.AppLaunchInfos.AppLaunchInfoList[0].Application.Position;
|
||||
|
||||
Assert.AreEqual(-1920, pos.X);
|
||||
Assert.AreEqual(-200, pos.Y);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_FourthMonitor_DeserializesHighMonitorIndex()
|
||||
{
|
||||
string multiMonitorMessage = @"{
|
||||
""processId"": 1,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": [
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""App"",
|
||||
""application-path"": ""C:\\app.exe"",
|
||||
""title"": """",
|
||||
""package-full-name"": """",
|
||||
""app-user-model-id"": """",
|
||||
""pwa-app-id"": """",
|
||||
""command-line-arguments"": """",
|
||||
""is-elevated"": false,
|
||||
""can-launch-elevated"": false,
|
||||
""minimized"": false,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": 3840, ""Y"": 0, ""width"": 1920, ""height"": 1080 },
|
||||
""monitor"": 3
|
||||
},
|
||||
""state"": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(multiMonitorMessage);
|
||||
Assert.AreEqual(3, result.AppLaunchInfos.AppLaunchInfoList[0].Application.Monitor);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_AllFiveStateValues_MapToCorrectEnumMembers()
|
||||
{
|
||||
for (int stateValue = 0; stateValue <= 4; stateValue++)
|
||||
{
|
||||
string template = @"{""processId"": 1,""apps"": {""appLaunchInfos"": [{""application"": {""application"": ""App"",""application-path"": ""C:\\app.exe"",""title"": """",""package-full-name"": """",""app-user-model-id"": """",""pwa-app-id"": """",""command-line-arguments"": """",""is-elevated"": false,""can-launch-elevated"": false,""minimized"": false,""maximized"": false,""position"": { ""X"": 0, ""Y"": 0, ""width"": 100, ""height"": 100 },""monitor"": 0},""state"": STATE_PLACEHOLDER}]}}";
|
||||
string message = template.Replace("STATE_PLACEHOLDER", stateValue.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(message);
|
||||
Assert.AreEqual((LaunchingState)stateValue, result.AppLaunchInfos.AppLaunchInfoList[0].State);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_CommandLineWithSpecialChars_PreservesArgumentsExactly()
|
||||
{
|
||||
string cliMessage = @"{
|
||||
""processId"": 1,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": [
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""VS Code"",
|
||||
""application-path"": ""C:\\Code.exe"",
|
||||
""title"": """",
|
||||
""package-full-name"": """",
|
||||
""app-user-model-id"": """",
|
||||
""pwa-app-id"": """",
|
||||
""command-line-arguments"": ""--new-window --goto C:\\project\\file.ts:42"",
|
||||
""is-elevated"": false,
|
||||
""can-launch-elevated"": false,
|
||||
""minimized"": false,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": 0, ""Y"": 0, ""width"": 100, ""height"": 100 },
|
||||
""monitor"": 0
|
||||
},
|
||||
""state"": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(cliMessage);
|
||||
Assert.AreEqual(@"--new-window --goto C:\project\file.ts:42", result.AppLaunchInfos.AppLaunchInfoList[0].Application.CommandLineArguments);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_JapaneseAppName_DeserializesUnicodeCorrectly()
|
||||
{
|
||||
string unicodeMessage = @"{
|
||||
""processId"": 1,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": [
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""\u30E1\u30E2\u5E33"",
|
||||
""application-path"": ""C:\\Windows\\System32\\notepad.exe"",
|
||||
""title"": ""\u7121\u984C - \u30E1\u30E2\u5E33"",
|
||||
""package-full-name"": """",
|
||||
""app-user-model-id"": """",
|
||||
""pwa-app-id"": """",
|
||||
""command-line-arguments"": """",
|
||||
""is-elevated"": false,
|
||||
""can-launch-elevated"": false,
|
||||
""minimized"": false,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": 0, ""Y"": 0, ""width"": 400, ""height"": 300 },
|
||||
""monitor"": 0
|
||||
},
|
||||
""state"": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(unicodeMessage);
|
||||
|
||||
Assert.AreEqual("\u30E1\u30E2\u5E33", result.AppLaunchInfos.AppLaunchInfoList[0].Application.Application);
|
||||
Assert.AreEqual("\u7121\u984C - \u30E1\u30E2\u5E33", result.AppLaunchInfos.AppLaunchInfoList[0].Application.Title);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Deserialization")]
|
||||
public void IpcMessage_TenAppWorkspace_DeserializesAllWithCorrectPositionsAndStates()
|
||||
{
|
||||
var appEntries = new StringBuilder();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
appEntries.Append(',');
|
||||
}
|
||||
|
||||
string entry = string.Create(CultureInfo.InvariantCulture, $@"{{""application"": {{""application"": ""App{i}"",""application-path"": ""C:\\app{i}.exe"",""title"": ""Window {i}"",""package-full-name"": """",""app-user-model-id"": """",""pwa-app-id"": """",""command-line-arguments"": """",""is-elevated"": false,""can-launch-elevated"": false,""minimized"": false,""maximized"": false,""position"": {{ ""X"": {i * 100}, ""Y"": 0, ""width"": 400, ""height"": 300 }},""monitor"": {i % 3}}},""state"": {i % 5}}}");
|
||||
appEntries.Append(entry);
|
||||
}
|
||||
|
||||
string manyAppsMessage = string.Create(CultureInfo.InvariantCulture, $@"{{""processId"": 9999,""apps"": {{""appLaunchInfos"": [{appEntries}]}}}}");
|
||||
|
||||
var parser = new AppLaunchData();
|
||||
var result = parser.Deserialize(manyAppsMessage);
|
||||
|
||||
Assert.AreEqual(10, result.AppLaunchInfos.AppLaunchInfoList.Count);
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Assert.AreEqual(string.Create(CultureInfo.InvariantCulture, $"App{i}"), result.AppLaunchInfos.AppLaunchInfoList[i].Application.Application);
|
||||
Assert.AreEqual(i * 100, result.AppLaunchInfos.AppLaunchInfoList[i].Application.Position.X);
|
||||
Assert.AreEqual(i % 3, result.AppLaunchInfos.AppLaunchInfoList[i].Application.Monitor);
|
||||
Assert.AreEqual((LaunchingState)(i % 5), result.AppLaunchInfos.AppLaunchInfoList[i].State);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using WorkspacesLauncherUI.Data;
|
||||
|
||||
namespace WorkspacesLauncherUI.UnitTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for the LaunchingState enum values and their integer mapping.
|
||||
/// The C++ launcher engine sends state as integer values over IPC.
|
||||
/// These integer values MUST remain stable across the migration.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class LaunchStateEnumContractTests
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void EnumContract_WaitingState_MapsToIntegerZero()
|
||||
{
|
||||
Assert.AreEqual(0, (int)LaunchingState.Waiting);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void EnumContract_LaunchedState_MapsToIntegerOne()
|
||||
{
|
||||
Assert.AreEqual(1, (int)LaunchingState.Launched);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void EnumContract_LaunchedAndMovedState_MapsToIntegerTwo()
|
||||
{
|
||||
Assert.AreEqual(2, (int)LaunchingState.LaunchedAndMoved);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void EnumContract_FailedState_MapsToIntegerThree()
|
||||
{
|
||||
Assert.AreEqual(3, (int)LaunchingState.Failed);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void EnumContract_CanceledState_MapsToIntegerFour()
|
||||
{
|
||||
Assert.AreEqual(4, (int)LaunchingState.Canceled);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void EnumContract_TotalMemberCount_IsExactlyFiveMatchingCppHeader()
|
||||
{
|
||||
var values = Enum.GetValues(typeof(LaunchingState));
|
||||
Assert.AreEqual(5, values.Length, "LaunchingState must have exactly 5 values to match C++ LaunchingStateEnum.h");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void EnumContract_IntToEnumCast_RoundTripsForAllValues()
|
||||
{
|
||||
for (int i = 0; i <= 4; i++)
|
||||
{
|
||||
var state = (LaunchingState)i;
|
||||
Assert.AreEqual(i, (int)state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using WorkspacesLauncherUI.Data;
|
||||
using WorkspacesLauncherUI.Models;
|
||||
|
||||
namespace WorkspacesLauncherUI.UnitTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for the AppLaunching model which drives UI display:
|
||||
/// loading indicator, state glyph, and state color.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class LaunchStatusDisplayLogicTests
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void LoadingSpinner_WhenStateIsWaiting_IsVisible()
|
||||
{
|
||||
var app = new AppLaunching { LaunchState = LaunchingState.Waiting };
|
||||
Assert.IsTrue(app.Loading);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void LoadingSpinner_WhenStateIsLaunched_RemainsVisibleUntilMoved()
|
||||
{
|
||||
var app = new AppLaunching { LaunchState = LaunchingState.Launched };
|
||||
Assert.IsTrue(app.Loading);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void LoadingSpinner_WhenStateIsLaunchedAndMoved_IsHidden()
|
||||
{
|
||||
var app = new AppLaunching { LaunchState = LaunchingState.LaunchedAndMoved };
|
||||
Assert.IsFalse(app.Loading);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void LoadingSpinner_WhenStateIsFailed_IsHidden()
|
||||
{
|
||||
var app = new AppLaunching { LaunchState = LaunchingState.Failed };
|
||||
Assert.IsFalse(app.Loading);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void LoadingSpinner_WhenStateIsCanceled_IsHidden()
|
||||
{
|
||||
var app = new AppLaunching { LaunchState = LaunchingState.Canceled };
|
||||
Assert.IsFalse(app.Loading);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void StatusIcon_WhenSuccessful_ShowsGreenCheckmarkGlyph()
|
||||
{
|
||||
var app = new AppLaunching { LaunchState = LaunchingState.LaunchedAndMoved };
|
||||
Assert.AreEqual("\U0000F78C", app.StateGlyph, "LaunchedAndMoved should show checkmark glyph");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void StatusIcon_WhenFailed_ShowsRedErrorGlyph()
|
||||
{
|
||||
var app = new AppLaunching { LaunchState = LaunchingState.Failed };
|
||||
Assert.AreEqual("\U0000EF2C", app.StateGlyph, "Failed should show error glyph");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void StatusIcon_WhenCanceled_ShowsRedErrorGlyph()
|
||||
{
|
||||
var app = new AppLaunching { LaunchState = LaunchingState.Canceled };
|
||||
Assert.AreEqual("\U0000EF2C", app.StateGlyph, "Canceled should fall through to default error glyph");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void StatusColor_WhenSuccessful_IsGreenRgb0_128_0()
|
||||
{
|
||||
var app = new AppLaunching { LaunchState = LaunchingState.LaunchedAndMoved };
|
||||
var color = app.StateColorValue;
|
||||
|
||||
Assert.AreNotEqual(default(Windows.UI.Color), color);
|
||||
Assert.AreEqual(0, color.R, "Green color R component");
|
||||
Assert.AreEqual(128, color.G, "Green color G component");
|
||||
Assert.AreEqual(0, color.B, "Green color B component");
|
||||
Assert.AreEqual(255, color.A, "Green color A component");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void StatusColor_WhenFailed_IsRedRgb254_0_0()
|
||||
{
|
||||
var app = new AppLaunching { LaunchState = LaunchingState.Failed };
|
||||
var color = app.StateColorValue;
|
||||
|
||||
Assert.AreNotEqual(default(Windows.UI.Color), color);
|
||||
Assert.AreEqual(254, color.R, "Red color R component");
|
||||
Assert.AreEqual(0, color.G, "Red color G component");
|
||||
Assert.AreEqual(0, color.B, "Red color B component");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void StatusColor_WhenCanceled_IsRedRgb254_0_0()
|
||||
{
|
||||
var app = new AppLaunching { LaunchState = LaunchingState.Canceled };
|
||||
var color = app.StateColorValue;
|
||||
|
||||
Assert.AreNotEqual(default(Windows.UI.Color), color);
|
||||
Assert.AreEqual(254, color.R, "Canceled should fall through to red");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void AppName_SetToString_ReturnsExactValue()
|
||||
{
|
||||
var app = new AppLaunching { Name = "Test Application" };
|
||||
Assert.AreEqual("Test Application", app.Name);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void AppName_SetToEmpty_ReturnsEmptyString()
|
||||
{
|
||||
var app = new AppLaunching { Name = string.Empty };
|
||||
Assert.AreEqual(string.Empty, app.Name);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void StateProgression_WaitingToSuccess_TransitionsSpinnerToGreenCheckmark()
|
||||
{
|
||||
var app = new AppLaunching { Name = "Test", LaunchState = LaunchingState.Waiting };
|
||||
Assert.IsTrue(app.Loading);
|
||||
|
||||
app.LaunchState = LaunchingState.Launched;
|
||||
Assert.IsTrue(app.Loading);
|
||||
|
||||
app.LaunchState = LaunchingState.LaunchedAndMoved;
|
||||
Assert.IsFalse(app.Loading);
|
||||
Assert.AreEqual("\U0000F78C", app.StateGlyph);
|
||||
var color = app.StateColorValue;
|
||||
Assert.AreEqual(0, color.R);
|
||||
Assert.AreEqual(128, color.G);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Model")]
|
||||
public void StateProgression_WaitingToFailed_TransitionsSpinnerToRedError()
|
||||
{
|
||||
var app = new AppLaunching { Name = "Test", LaunchState = LaunchingState.Waiting };
|
||||
Assert.IsTrue(app.Loading);
|
||||
|
||||
app.LaunchState = LaunchingState.Failed;
|
||||
Assert.IsFalse(app.Loading);
|
||||
Assert.AreEqual("\U0000EF2C", app.StateGlyph);
|
||||
var color = app.StateColorValue;
|
||||
Assert.AreEqual(254, color.R);
|
||||
Assert.AreEqual(0, color.G);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using WorkspacesLauncherUI.Data;
|
||||
using WorkspacesLauncherUI.Models;
|
||||
using WorkspacesLauncherUI.ViewModels;
|
||||
|
||||
namespace WorkspacesLauncherUI.UnitTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for MainViewModel IPC message handling and state management.
|
||||
/// MainViewModel is the core of the Launcher UI — it receives IPC messages
|
||||
/// from the C++ launcher engine and populates the AppsListed collection
|
||||
/// that the UI binds to.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class LauncherViewModelStateManagementTests
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_ValidPayload_PopulatesAppsListedCollection()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
string message = CreateIpcMessage(("App1", @"C:\app1.exe", LaunchingState.Waiting), ("App2", @"C:\app2.exe", LaunchingState.Launched));
|
||||
SimulateIpcMessage(message);
|
||||
|
||||
Assert.AreEqual(2, vm.AppsListed.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_ValidPayload_MapsAppNamesFromJson()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
string message = CreateIpcMessage(("Visual Studio Code", @"C:\Code.exe", LaunchingState.Waiting), ("Windows Terminal", @"C:\wt.exe", LaunchingState.Launched));
|
||||
SimulateIpcMessage(message);
|
||||
|
||||
Assert.AreEqual("Visual Studio Code", vm.AppsListed[0].Name);
|
||||
Assert.AreEqual("Windows Terminal", vm.AppsListed[1].Name);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_MixedStates_MapsEachAppToCorrectState()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
string message = CreateIpcMessage(
|
||||
("App1", @"C:\app1.exe", LaunchingState.Waiting),
|
||||
("App2", @"C:\app2.exe", LaunchingState.Launched),
|
||||
("App3", @"C:\app3.exe", LaunchingState.LaunchedAndMoved),
|
||||
("App4", @"C:\app4.exe", LaunchingState.Failed));
|
||||
SimulateIpcMessage(message);
|
||||
|
||||
Assert.AreEqual(LaunchingState.Waiting, vm.AppsListed[0].LaunchState);
|
||||
Assert.AreEqual(LaunchingState.Launched, vm.AppsListed[1].LaunchState);
|
||||
Assert.AreEqual(LaunchingState.LaunchedAndMoved, vm.AppsListed[2].LaunchState);
|
||||
Assert.AreEqual(LaunchingState.Failed, vm.AppsListed[3].LaunchState);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_ValidPayload_PreservesExecutablePaths()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
string message = CreateIpcMessage(("Notepad", @"C:\Windows\System32\notepad.exe", LaunchingState.Waiting));
|
||||
SimulateIpcMessage(message);
|
||||
|
||||
Assert.AreEqual(@"C:\Windows\System32\notepad.exe", vm.AppsListed[0].AppPath);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_PackagedApp_MapsPackageNameAndAumid()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
string message = @"{
|
||||
""processId"": 1,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": [
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""Terminal"",
|
||||
""application-path"": ""C:\\wt.exe"",
|
||||
""title"": """",
|
||||
""package-full-name"": ""Microsoft.WindowsTerminal_1.0_x64__8wekyb3d8bbwe"",
|
||||
""app-user-model-id"": ""Microsoft.WindowsTerminal_8wekyb3d8bbwe!App"",
|
||||
""pwa-app-id"": """",
|
||||
""command-line-arguments"": """",
|
||||
""is-elevated"": false,
|
||||
""can-launch-elevated"": false,
|
||||
""minimized"": false,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": 0, ""Y"": 0, ""width"": 100, ""height"": 100 },
|
||||
""monitor"": 0
|
||||
},
|
||||
""state"": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
SimulateIpcMessage(message);
|
||||
|
||||
Assert.AreEqual("Microsoft.WindowsTerminal_1.0_x64__8wekyb3d8bbwe", vm.AppsListed[0].PackagedName);
|
||||
Assert.AreEqual("Microsoft.WindowsTerminal_8wekyb3d8bbwe!App", vm.AppsListed[0].Aumid);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_PwaApp_MapsPwaAppIdentifier()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
string message = @"{
|
||||
""processId"": 1,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": [
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""Gmail"",
|
||||
""application-path"": ""C:\\chrome.exe"",
|
||||
""title"": """",
|
||||
""package-full-name"": """",
|
||||
""app-user-model-id"": """",
|
||||
""pwa-app-id"": ""abc123"",
|
||||
""command-line-arguments"": """",
|
||||
""is-elevated"": false,
|
||||
""can-launch-elevated"": false,
|
||||
""minimized"": false,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": 0, ""Y"": 0, ""width"": 100, ""height"": 100 },
|
||||
""monitor"": 0
|
||||
},
|
||||
""state"": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
SimulateIpcMessage(message);
|
||||
|
||||
Assert.AreEqual("abc123", vm.AppsListed[0].PwaAppId);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_AnyUpdate_RaisesPropertyChangedForDataBinding()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
bool propertyChangedFired = false;
|
||||
string changedPropertyName = null;
|
||||
|
||||
vm.PropertyChanged += (sender, args) =>
|
||||
{
|
||||
propertyChangedFired = true;
|
||||
changedPropertyName = args.PropertyName;
|
||||
};
|
||||
|
||||
string message = CreateIpcMessage(("App", @"C:\app.exe", LaunchingState.Waiting));
|
||||
SimulateIpcMessage(message);
|
||||
|
||||
Assert.IsTrue(propertyChangedFired, "PropertyChanged should fire when AppsListed is updated");
|
||||
Assert.AreEqual("AppsListed", changedPropertyName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_ProgressUpdates_ReplacesEntireCollectionEachTime()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
|
||||
string msg1 = CreateIpcMessage(("App1", @"C:\app1.exe", LaunchingState.Waiting), ("App2", @"C:\app2.exe", LaunchingState.Waiting));
|
||||
SimulateIpcMessage(msg1);
|
||||
Assert.AreEqual(2, vm.AppsListed.Count);
|
||||
Assert.AreEqual(LaunchingState.Waiting, vm.AppsListed[0].LaunchState);
|
||||
|
||||
string msg2 = CreateIpcMessage(("App1", @"C:\app1.exe", LaunchingState.Launched), ("App2", @"C:\app2.exe", LaunchingState.Waiting));
|
||||
SimulateIpcMessage(msg2);
|
||||
Assert.AreEqual(2, vm.AppsListed.Count);
|
||||
Assert.AreEqual(LaunchingState.Launched, vm.AppsListed[0].LaunchState);
|
||||
|
||||
string msg3 = CreateIpcMessage(("App1", @"C:\app1.exe", LaunchingState.LaunchedAndMoved), ("App2", @"C:\app2.exe", LaunchingState.LaunchedAndMoved));
|
||||
SimulateIpcMessage(msg3);
|
||||
Assert.AreEqual(LaunchingState.LaunchedAndMoved, vm.AppsListed[0].LaunchState);
|
||||
Assert.AreEqual(LaunchingState.LaunchedAndMoved, vm.AppsListed[1].LaunchState);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_SomeAppsFail_AllowsMixedSuccessAndFailure()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
string message = CreateIpcMessage(
|
||||
("App1", @"C:\app1.exe", LaunchingState.LaunchedAndMoved),
|
||||
("App2", @"C:\app2.exe", LaunchingState.Failed),
|
||||
("App3", @"C:\app3.exe", LaunchingState.LaunchedAndMoved));
|
||||
SimulateIpcMessage(message);
|
||||
|
||||
Assert.AreEqual(LaunchingState.LaunchedAndMoved, vm.AppsListed[0].LaunchState);
|
||||
Assert.AreEqual(LaunchingState.Failed, vm.AppsListed[1].LaunchState);
|
||||
Assert.AreEqual(LaunchingState.LaunchedAndMoved, vm.AppsListed[2].LaunchState);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_CanceledState_ReflectedInCollection()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
string message = CreateIpcMessage(("App1", @"C:\app1.exe", LaunchingState.LaunchedAndMoved), ("App2", @"C:\app2.exe", LaunchingState.Canceled));
|
||||
SimulateIpcMessage(message);
|
||||
|
||||
Assert.AreEqual(LaunchingState.Canceled, vm.AppsListed[1].LaunchState);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_EmptyAppList_SetsCollectionToEmpty()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
string message = @"{ ""processId"": 1, ""apps"": { ""appLaunchInfos"": [] } }";
|
||||
SimulateIpcMessage(message);
|
||||
|
||||
Assert.AreEqual(0, vm.AppsListed.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_CorruptedPayload_GracefullyIgnoredWithoutCrash()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
SimulateIpcMessage("this is not json");
|
||||
|
||||
Assert.AreEqual(0, vm.AppsListed.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_EmptyString_GracefullyIgnoredWithoutCrash()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
SimulateIpcMessage(string.Empty);
|
||||
Assert.AreEqual(0, vm.AppsListed.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void DisposeViewModel_SingleCall_CompletesWithoutException()
|
||||
{
|
||||
var vm = new MainViewModel();
|
||||
vm.Dispose();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void DisposeViewModel_MultipleCalls_RemainsIdempotent()
|
||||
{
|
||||
var vm = new MainViewModel();
|
||||
vm.Dispose();
|
||||
vm.Dispose();
|
||||
}
|
||||
|
||||
private static void SimulateIpcMessage(string message)
|
||||
{
|
||||
App.IPCMessageReceivedCallback?.Invoke(message);
|
||||
}
|
||||
|
||||
private static string CreateIpcMessage(params (string Name, string Path, LaunchingState State)[] apps)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(@"{ ""processId"": 1, ""apps"": { ""appLaunchInfos"": [");
|
||||
|
||||
for (int i = 0; i < apps.Length; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
sb.Append(',');
|
||||
}
|
||||
|
||||
var (name, path, state) = apps[i];
|
||||
string escapedPath = path.Replace(@"\", @"\\");
|
||||
string appJson = string.Create(CultureInfo.InvariantCulture, $@"{{""application"": {{""application"": ""{name}"",""application-path"": ""{escapedPath}"",""title"": """",""package-full-name"": """",""app-user-model-id"": """",""pwa-app-id"": """",""command-line-arguments"": """",""is-elevated"": false,""can-launch-elevated"": false,""minimized"": false,""maximized"": false,""position"": {{ ""X"": 0, ""Y"": 0, ""width"": 100, ""height"": 100 }},""monitor"": 0}},""state"": {(int)state}}}");
|
||||
sb.Append(appJson);
|
||||
}
|
||||
|
||||
sb.Append("]}}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
105
src/modules/Workspaces/WorkspacesLauncherUI.UnitTests/README.md
Normal file
105
src/modules/Workspaces/WorkspacesLauncherUI.UnitTests/README.md
Normal file
@@ -0,0 +1,105 @@
|
||||
# WorkspacesLauncherUI Unit Tests
|
||||
|
||||
Unit tests for the Workspaces Launcher UI (WinUI 3). These validate the data layer, ViewModel, and display logic that drives the workspace launch progress window.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Visual Studio 2022 17.4+ or Visual Studio 2026
|
||||
- .NET SDK (see `global.json` in repo root)
|
||||
- Submodules initialized: `git submodule update --init --recursive`
|
||||
|
||||
## Build
|
||||
|
||||
From this directory:
|
||||
|
||||
```powershell
|
||||
# Quick build (auto-detects platform)
|
||||
& "$env:RepoRoot\tools\build\build.cmd"
|
||||
|
||||
# Or with explicit options
|
||||
& "$env:RepoRoot\tools\build\build.cmd" -Platform arm64 -Configuration Debug
|
||||
```
|
||||
|
||||
If you get NuGet restore errors on first build:
|
||||
|
||||
```powershell
|
||||
& "$env:RepoRoot\tools\build\build-essentials.cmd"
|
||||
```
|
||||
|
||||
## Run Tests
|
||||
|
||||
### Option 1: dotnet test (recommended for CI)
|
||||
|
||||
```powershell
|
||||
dotnet test "<output-dir>\tests\WorkspacesLauncherUI.Tests\PowerToys.WorkspacesLauncherUI.Tests.dll" --verbosity normal
|
||||
```
|
||||
|
||||
The output directory depends on your platform/config. For arm64 Debug:
|
||||
|
||||
```powershell
|
||||
dotnet test "arm64\Debug\tests\WorkspacesLauncherUI.Tests\PowerToys.WorkspacesLauncherUI.Tests.dll" --verbosity normal
|
||||
```
|
||||
|
||||
### Option 2: Visual Studio Test Explorer
|
||||
|
||||
1. Open `PowerToys.slnx` in Visual Studio
|
||||
2. Build the `WorkspacesLauncherUI.UnitTests` project
|
||||
3. Open Test Explorer (`Ctrl+E, T`)
|
||||
4. Run all tests in `PowerToys.WorkspacesLauncherUI.Tests`
|
||||
|
||||
### Option 3: Filter by category
|
||||
|
||||
```powershell
|
||||
dotnet test <dll-path> --filter "TestCategory=Scenario"
|
||||
dotnet test <dll-path> --filter "TestCategory=Deserialization"
|
||||
dotnet test <dll-path> --filter "TestCategory=ViewModel"
|
||||
dotnet test <dll-path> --filter "TestCategory=Model"
|
||||
dotnet test <dll-path> --filter "TestCategory=Serialization"
|
||||
dotnet test <dll-path> --filter "TestCategory=DataModel"
|
||||
dotnet test <dll-path> --filter "TestCategory=Converter"
|
||||
```
|
||||
|
||||
### Generate TRX Report
|
||||
|
||||
```powershell
|
||||
dotnet test <dll-path> --logger "trx;LogFileName=TestResults.trx"
|
||||
```
|
||||
|
||||
Report saved to `TestResults/TestResults.trx`.
|
||||
|
||||
## Test Categories
|
||||
|
||||
| Category | File | What It Validates |
|
||||
|----------|------|-------------------|
|
||||
| `Deserialization` | `IpcMessageDeserializationTests.cs` | C++ launcher engine JSON → C# data models |
|
||||
| `ViewModel` | `LauncherViewModelStateManagementTests.cs` | IPC callback → ObservableCollection pipeline |
|
||||
| `Model` | `LaunchStatusDisplayLogicTests.cs` | Spinner/glyph/color for each launch state |
|
||||
| `Scenario` | `UserWorkflowIntegrationTests.cs` | Full user workflows (launch, cancel, fail) |
|
||||
| `Serialization` | `IpcJsonPropertyNamingTests.cs` | JSON key names match C++ IPC protocol |
|
||||
| `DataModel` | `WindowPositionDataTests.cs` | Window coordinates and equality |
|
||||
| `DataModel` | `ApplicationDataModelTests.cs` | All application fields |
|
||||
| `DataModel` | `LaunchStateEnumContractTests.cs` | Enum integers match `LaunchingStateEnum.h` |
|
||||
| `Converter` | `StatusIndicatorVisibilityTests.cs` | Loading → Visibility toggle |
|
||||
|
||||
## When to Run
|
||||
|
||||
- **After IPC contract changes**: Deserialization + Serialization categories
|
||||
- **After UI state changes**: Model + ViewModel categories
|
||||
- **After dependency updates**: All tests to verify no regressions
|
||||
|
||||
## Adding New Tests
|
||||
|
||||
Follow the naming convention: `{WhatIsUnderTest}_{GivenCondition}_{ExpectedBehavior}`
|
||||
|
||||
Example:
|
||||
```csharp
|
||||
[TestMethod]
|
||||
[TestCategory("ViewModel")]
|
||||
public void ReceiveIpcMessage_NewFieldAdded_DeserializesWithoutBreakingExistingFields()
|
||||
```
|
||||
|
||||
## Note on Color Assertions
|
||||
|
||||
Color tests use `AppLaunching.StateColorValue` (returns `Windows.UI.Color`) instead of
|
||||
`StateColor` (returns `SolidColorBrush`) because WinUI brush creation requires a UI thread.
|
||||
The `StateColorValue` property exposes the same ARGB values for headless test validation.
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using WorkspacesLauncherUI.Converters;
|
||||
|
||||
namespace WorkspacesLauncherUI.UnitTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for BooleanToInvertedVisibilityConverter.
|
||||
/// When Loading=true → spinner Visible, glyph Collapsed
|
||||
/// When Loading=false → spinner Collapsed, glyph Visible
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class StatusIndicatorVisibilityTests
|
||||
{
|
||||
private readonly BooleanToInvertedVisibilityConverter _converter = new();
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Converter")]
|
||||
public void Converter_WhenLoadingTrue_HidesStatusGlyph()
|
||||
{
|
||||
var result = _converter.Convert(true, typeof(Visibility), null, "en-US");
|
||||
Assert.AreEqual(Visibility.Collapsed, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Converter")]
|
||||
public void Converter_WhenLoadingFalse_ShowsStatusGlyph()
|
||||
{
|
||||
var result = _converter.Convert(false, typeof(Visibility), null, "en-US");
|
||||
Assert.AreEqual(Visibility.Visible, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Converter")]
|
||||
[ExpectedException(typeof(NotImplementedException))]
|
||||
public void Converter_ReverseConversion_IsNotSupported()
|
||||
{
|
||||
_converter.ConvertBack(Visibility.Visible, typeof(bool), null, "en-US");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Converter")]
|
||||
public void Converter_NullConverterParameter_StillFunctionsCorrectly()
|
||||
{
|
||||
var result = _converter.Convert(true, typeof(Visibility), null, null);
|
||||
Assert.AreEqual(Visibility.Collapsed, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Converter")]
|
||||
public void Converter_MultipleCultures_BehaviorIsCultureInvariant()
|
||||
{
|
||||
var result1 = _converter.Convert(true, typeof(Visibility), null, "en-US");
|
||||
var result2 = _converter.Convert(true, typeof(Visibility), null, "ja-JP");
|
||||
var result3 = _converter.Convert(true, typeof(Visibility), null, "de-DE");
|
||||
|
||||
Assert.AreEqual(Visibility.Collapsed, result1);
|
||||
Assert.AreEqual(Visibility.Collapsed, result2);
|
||||
Assert.AreEqual(Visibility.Collapsed, result3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using WorkspacesLauncherUI.Data;
|
||||
using WorkspacesLauncherUI.Models;
|
||||
using WorkspacesLauncherUI.ViewModels;
|
||||
|
||||
namespace WorkspacesLauncherUI.UnitTests
|
||||
{
|
||||
/// <summary>
|
||||
/// End-to-end scenario tests that simulate complete user workflows
|
||||
/// through the Launcher UI. These verify the full pipeline:
|
||||
/// IPC JSON message → Deserialization → ViewModel → Model properties.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class UserWorkflowIntegrationTests
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserLaunchesWorkspace_ThreeApps_AllProgressFromWaitingToSuccess()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
|
||||
SimulateIpcMessage(BuildMessage(
|
||||
1234,
|
||||
App("Visual Studio Code", @"C:\Code.exe", LaunchingState.Waiting),
|
||||
App("Windows Terminal", @"C:\wt.exe", LaunchingState.Waiting),
|
||||
App("Microsoft Edge", @"C:\edge.exe", LaunchingState.Waiting)));
|
||||
|
||||
Assert.AreEqual(3, vm.AppsListed.Count);
|
||||
Assert.IsTrue(vm.AppsListed.All(a => a.Loading), "All apps should show loading spinner initially");
|
||||
|
||||
SimulateIpcMessage(BuildMessage(
|
||||
1234,
|
||||
App("Visual Studio Code", @"C:\Code.exe", LaunchingState.Launched),
|
||||
App("Windows Terminal", @"C:\wt.exe", LaunchingState.Waiting),
|
||||
App("Microsoft Edge", @"C:\edge.exe", LaunchingState.Waiting)));
|
||||
|
||||
Assert.IsTrue(vm.AppsListed[0].Loading, "Launched but not yet moved — still loading");
|
||||
|
||||
SimulateIpcMessage(BuildMessage(
|
||||
1234,
|
||||
App("Visual Studio Code", @"C:\Code.exe", LaunchingState.LaunchedAndMoved),
|
||||
App("Windows Terminal", @"C:\wt.exe", LaunchingState.Launched),
|
||||
App("Microsoft Edge", @"C:\edge.exe", LaunchingState.Waiting)));
|
||||
|
||||
Assert.IsFalse(vm.AppsListed[0].Loading, "Moved app should stop loading");
|
||||
Assert.AreEqual("\U0000F78C", vm.AppsListed[0].StateGlyph, "Moved app should show checkmark");
|
||||
|
||||
SimulateIpcMessage(BuildMessage(
|
||||
1234,
|
||||
App("Visual Studio Code", @"C:\Code.exe", LaunchingState.LaunchedAndMoved),
|
||||
App("Windows Terminal", @"C:\wt.exe", LaunchingState.LaunchedAndMoved),
|
||||
App("Microsoft Edge", @"C:\edge.exe", LaunchingState.LaunchedAndMoved)));
|
||||
|
||||
Assert.IsTrue(vm.AppsListed.All(a => !a.Loading), "All apps should stop loading");
|
||||
Assert.IsTrue(vm.AppsListed.All(a => a.StateGlyph == "\U0000F78C"), "All apps should show checkmark");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserLaunchesWorkspace_OneAppMissing_FailedShowsRedOthersShowGreen()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
|
||||
SimulateIpcMessage(BuildMessage(
|
||||
1234,
|
||||
App("Notepad", @"C:\Windows\notepad.exe", LaunchingState.LaunchedAndMoved),
|
||||
App("Missing App", @"C:\nonexistent\app.exe", LaunchingState.Failed),
|
||||
App("Calculator", @"C:\Windows\calc.exe", LaunchingState.LaunchedAndMoved)));
|
||||
|
||||
Assert.IsFalse(vm.AppsListed[0].Loading);
|
||||
Assert.AreEqual("\U0000F78C", vm.AppsListed[0].StateGlyph);
|
||||
|
||||
Assert.IsFalse(vm.AppsListed[1].Loading);
|
||||
Assert.AreEqual("\U0000EF2C", vm.AppsListed[1].StateGlyph);
|
||||
var color = vm.AppsListed[1].StateColorValue;
|
||||
Assert.AreEqual(254, color.R);
|
||||
|
||||
Assert.AreEqual("\U0000F78C", vm.AppsListed[2].StateGlyph);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserCancelsLaunch_MidProgress_PartialAppsShowCanceledState()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
|
||||
SimulateIpcMessage(BuildMessage(
|
||||
5678,
|
||||
App("App1", @"C:\app1.exe", LaunchingState.LaunchedAndMoved),
|
||||
App("App2", @"C:\app2.exe", LaunchingState.Canceled),
|
||||
App("App3", @"C:\app3.exe", LaunchingState.Canceled)));
|
||||
|
||||
Assert.AreEqual(LaunchingState.LaunchedAndMoved, vm.AppsListed[0].LaunchState);
|
||||
Assert.AreEqual(LaunchingState.Canceled, vm.AppsListed[1].LaunchState);
|
||||
Assert.AreEqual(LaunchingState.Canceled, vm.AppsListed[2].LaunchState);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserLaunchesWorkspace_SingleApp_CompletesFullLifecycle()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
|
||||
SimulateIpcMessage(BuildMessage(
|
||||
100,
|
||||
App("Notepad", @"C:\Windows\System32\notepad.exe", LaunchingState.Waiting)));
|
||||
|
||||
Assert.AreEqual(1, vm.AppsListed.Count);
|
||||
Assert.AreEqual("Notepad", vm.AppsListed[0].Name);
|
||||
Assert.IsTrue(vm.AppsListed[0].Loading);
|
||||
|
||||
SimulateIpcMessage(BuildMessage(
|
||||
100,
|
||||
App("Notepad", @"C:\Windows\System32\notepad.exe", LaunchingState.LaunchedAndMoved)));
|
||||
|
||||
Assert.IsFalse(vm.AppsListed[0].Loading);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserLaunchesWorkspace_ChromeAndEdgePwa_PwaIdsPreserved()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
|
||||
SimulateIpcMessage(BuildMessageFull(
|
||||
300,
|
||||
AppFull("Gmail", @"C:\chrome.exe", string.Empty, string.Empty, "fmgjjmmmlfnkbppncijlocphclkkleod", LaunchingState.LaunchedAndMoved),
|
||||
AppFull("Teams", @"C:\edge.exe", string.Empty, string.Empty, "cifhbcnohmdccbgoicgdjpfamggdegmo", LaunchingState.Launched)));
|
||||
|
||||
Assert.AreEqual("fmgjjmmmlfnkbppncijlocphclkkleod", vm.AppsListed[0].PwaAppId);
|
||||
Assert.AreEqual("cifhbcnohmdccbgoicgdjpfamggdegmo", vm.AppsListed[1].PwaAppId);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserLaunchesWorkspace_AdminApp_ElevatedFlagPreservedInUi()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
|
||||
string message = @"{
|
||||
""processId"": 400,
|
||||
""apps"": {
|
||||
""appLaunchInfos"": [
|
||||
{
|
||||
""application"": {
|
||||
""application"": ""Command Prompt (Admin)"",
|
||||
""application-path"": ""C:\\Windows\\System32\\cmd.exe"",
|
||||
""title"": ""Administrator: Command Prompt"",
|
||||
""package-full-name"": """",
|
||||
""app-user-model-id"": """",
|
||||
""pwa-app-id"": """",
|
||||
""command-line-arguments"": """",
|
||||
""is-elevated"": true,
|
||||
""can-launch-elevated"": true,
|
||||
""minimized"": false,
|
||||
""maximized"": false,
|
||||
""position"": { ""X"": 0, ""Y"": 0, ""width"": 800, ""height"": 600 },
|
||||
""monitor"": 0
|
||||
},
|
||||
""state"": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
SimulateIpcMessage(message);
|
||||
Assert.AreEqual("Command Prompt (Admin)", vm.AppsListed[0].Name);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserLaunchesWorkspace_FifteenApps_AllAppsDisplayedWithLoadingState()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
var apps = new (string Name, string Path, LaunchingState State)[15];
|
||||
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
apps[i] = ($"App {i}", $@"C:\app{i}.exe", LaunchingState.Waiting);
|
||||
}
|
||||
|
||||
SimulateIpcMessage(BuildMessage(500, apps));
|
||||
|
||||
Assert.AreEqual(15, vm.AppsListed.Count);
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
Assert.AreEqual($"App {i}", vm.AppsListed[i].Name);
|
||||
Assert.IsTrue(vm.AppsListed[i].Loading);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserLaunchesWorkspace_AllAppsMissing_AllShowRedErrorState()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
|
||||
SimulateIpcMessage(BuildMessage(
|
||||
800,
|
||||
App("App1", @"C:\missing1.exe", LaunchingState.Failed),
|
||||
App("App2", @"C:\missing2.exe", LaunchingState.Failed)));
|
||||
|
||||
Assert.IsTrue(vm.AppsListed.All(a => !a.Loading), "Failed apps should not show loading");
|
||||
Assert.IsTrue(vm.AppsListed.All(a => a.StateGlyph == "\U0000EF2C"), "Failed apps should show error glyph");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserLaunchesWorkspace_UwpStoreApp_PackageFieldsMappedToUi()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
|
||||
SimulateIpcMessage(BuildMessageFull(
|
||||
900,
|
||||
AppFull(
|
||||
"Windows Settings",
|
||||
@"C:\Program Files\WindowsApps\windows.immersivecontrolpanel\SystemSettings.exe",
|
||||
"windows.immersivecontrolpanel_10.0.0.0_neutral_cw5n1h2txyewy",
|
||||
"windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel",
|
||||
string.Empty,
|
||||
LaunchingState.LaunchedAndMoved)));
|
||||
|
||||
Assert.AreEqual("Windows Settings", vm.AppsListed[0].Name);
|
||||
Assert.AreEqual("windows.immersivecontrolpanel_10.0.0.0_neutral_cw5n1h2txyewy", vm.AppsListed[0].PackagedName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserLaunchesWorkspace_RapidIpcUpdates_FinalStateIsDisplayed()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
|
||||
for (int i = 0; i <= 4; i++)
|
||||
{
|
||||
SimulateIpcMessage(BuildMessage(
|
||||
1000,
|
||||
App("App", @"C:\app.exe", (LaunchingState)Math.Min(i, 2))));
|
||||
}
|
||||
|
||||
Assert.AreEqual(1, vm.AppsListed.Count);
|
||||
Assert.AreEqual(LaunchingState.LaunchedAndMoved, vm.AppsListed[0].LaunchState);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserLaunchesWorkspace_Win32AndPackagedAndPwa_AllTypesCoexistInList()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
|
||||
SimulateIpcMessage(BuildMessageFull(
|
||||
1100,
|
||||
AppFull("Notepad", @"C:\Windows\notepad.exe", string.Empty, string.Empty, string.Empty, LaunchingState.LaunchedAndMoved),
|
||||
AppFull("Terminal", @"C:\wt.exe", "Microsoft.WindowsTerminal_1.0_x64__8wekyb3d8bbwe", "Microsoft.WindowsTerminal_8wekyb3d8bbwe!App", string.Empty, LaunchingState.LaunchedAndMoved),
|
||||
AppFull("Outlook", @"C:\edge.exe", string.Empty, string.Empty, "pwa_outlook_id", LaunchingState.Launched)));
|
||||
|
||||
Assert.AreEqual(3, vm.AppsListed.Count);
|
||||
Assert.AreEqual(string.Empty, vm.AppsListed[0].PwaAppId);
|
||||
Assert.AreEqual("Microsoft.WindowsTerminal_1.0_x64__8wekyb3d8bbwe", vm.AppsListed[1].PackagedName);
|
||||
Assert.AreEqual("pwa_outlook_id", vm.AppsListed[2].PwaAppId);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("Scenario")]
|
||||
public void UserLaunchesWorkspace_FiveUpdates_UiRefreshedOnEveryIpcMessage()
|
||||
{
|
||||
using var vm = new MainViewModel();
|
||||
int fireCount = 0;
|
||||
|
||||
vm.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == "AppsListed")
|
||||
{
|
||||
fireCount++;
|
||||
}
|
||||
};
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
SimulateIpcMessage(BuildMessage(
|
||||
1200,
|
||||
App("App", @"C:\app.exe", (LaunchingState)Math.Min(i, 2))));
|
||||
}
|
||||
|
||||
Assert.AreEqual(5, fireCount, "PropertyChanged should fire once per IPC message");
|
||||
}
|
||||
|
||||
private static (string Name, string Path, LaunchingState State) App(string name, string path, LaunchingState state)
|
||||
{
|
||||
return (name, path, state);
|
||||
}
|
||||
|
||||
private static (string Name, string Path, string PackageFullName, string Aumid, string PwaAppId, LaunchingState State) AppFull(
|
||||
string name, string path, string packageFullName, string aumid, string pwaAppId, LaunchingState state)
|
||||
{
|
||||
return (name, path, packageFullName, aumid, pwaAppId, state);
|
||||
}
|
||||
|
||||
private static void SimulateIpcMessage(string message)
|
||||
{
|
||||
WorkspacesLauncherUI.App.IPCMessageReceivedCallback?.Invoke(message);
|
||||
}
|
||||
|
||||
private static string BuildMessage(
|
||||
int processId,
|
||||
params (string Name, string Path, LaunchingState State)[] apps)
|
||||
{
|
||||
var fullApps = apps.Select(a => (a.Name, a.Path, string.Empty, string.Empty, string.Empty, a.State)).ToArray();
|
||||
return BuildMessageFull(processId, fullApps);
|
||||
}
|
||||
|
||||
private static string BuildMessageFull(
|
||||
int processId,
|
||||
params (string Name, string Path, string PackageFullName, string Aumid, string PwaAppId, LaunchingState State)[] apps)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(CultureInfo.InvariantCulture, $@"{{ ""processId"": {processId}, ""apps"": {{ ""appLaunchInfos"": [");
|
||||
|
||||
for (int i = 0; i < apps.Length; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
sb.Append(',');
|
||||
}
|
||||
|
||||
var (name, path, packageFullName, aumid, pwaAppId, state) = apps[i];
|
||||
string escapedPath = path.Replace(@"\", @"\\");
|
||||
string appJson = string.Create(CultureInfo.InvariantCulture, $@"{{""application"": {{""application"": ""{name}"",""application-path"": ""{escapedPath}"",""title"": """",""package-full-name"": ""{packageFullName}"",""app-user-model-id"": ""{aumid}"",""pwa-app-id"": ""{pwaAppId}"",""command-line-arguments"": """",""is-elevated"": false,""can-launch-elevated"": false,""minimized"": false,""maximized"": false,""position"": {{ ""X"": 0, ""Y"": 0, ""width"": 100, ""height"": 100 }},""monitor"": 0}},""state"": {(int)state}}}");
|
||||
sb.Append(appJson);
|
||||
}
|
||||
|
||||
sb.Append("]}}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using WorkspacesLauncherUI.Data;
|
||||
|
||||
namespace WorkspacesLauncherUI.UnitTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for PositionWrapper struct equality and operator behavior.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class WindowPositionDataTests
|
||||
{
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void PositionEquality_IdenticalCoordinates_ReturnsTrue()
|
||||
{
|
||||
var pos1 = new PositionWrapper { X = 100, Y = 200, Width = 800, Height = 600 };
|
||||
var pos2 = new PositionWrapper { X = 100, Y = 200, Width = 800, Height = 600 };
|
||||
Assert.IsTrue(pos1 == pos2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void PositionEquality_DifferentXCoordinate_ReturnsFalse()
|
||||
{
|
||||
var pos1 = new PositionWrapper { X = 100, Y = 200, Width = 800, Height = 600 };
|
||||
var pos2 = new PositionWrapper { X = 101, Y = 200, Width = 800, Height = 600 };
|
||||
Assert.IsFalse(pos1 == pos2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void PositionEquality_DifferentYCoordinate_ReturnsFalse()
|
||||
{
|
||||
var pos1 = new PositionWrapper { X = 100, Y = 200, Width = 800, Height = 600 };
|
||||
var pos2 = new PositionWrapper { X = 100, Y = 201, Width = 800, Height = 600 };
|
||||
Assert.IsFalse(pos1 == pos2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void PositionEquality_DifferentWidth_ReturnsFalse()
|
||||
{
|
||||
var pos1 = new PositionWrapper { X = 100, Y = 200, Width = 800, Height = 600 };
|
||||
var pos2 = new PositionWrapper { X = 100, Y = 200, Width = 801, Height = 600 };
|
||||
Assert.IsFalse(pos1 == pos2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void PositionEquality_DifferentHeight_ReturnsFalse()
|
||||
{
|
||||
var pos1 = new PositionWrapper { X = 100, Y = 200, Width = 800, Height = 600 };
|
||||
var pos2 = new PositionWrapper { X = 100, Y = 200, Width = 800, Height = 601 };
|
||||
Assert.IsFalse(pos1 == pos2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void PositionInequality_DifferentCoordinates_ReturnsTrue()
|
||||
{
|
||||
var pos1 = new PositionWrapper { X = 0, Y = 0, Width = 1920, Height = 1080 };
|
||||
var pos2 = new PositionWrapper { X = 960, Y = 0, Width = 960, Height = 1080 };
|
||||
Assert.IsTrue(pos1 != pos2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void PositionInequality_IdenticalCoordinates_ReturnsFalse()
|
||||
{
|
||||
var pos1 = new PositionWrapper { X = 0, Y = 0, Width = 1920, Height = 1080 };
|
||||
var pos2 = new PositionWrapper { X = 0, Y = 0, Width = 1920, Height = 1080 };
|
||||
Assert.IsFalse(pos1 != pos2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void PositionEquals_BoxedIdenticalValues_ReturnsTrue()
|
||||
{
|
||||
var pos1 = new PositionWrapper { X = 100, Y = 200, Width = 800, Height = 600 };
|
||||
object pos2 = new PositionWrapper { X = 100, Y = 200, Width = 800, Height = 600 };
|
||||
Assert.IsTrue(pos1.Equals(pos2));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void PositionEquals_NullComparison_ReturnsFalse()
|
||||
{
|
||||
var pos = new PositionWrapper { X = 0, Y = 0, Width = 100, Height = 100 };
|
||||
Assert.IsFalse(pos.Equals(null));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void PositionEquals_DifferentObjectType_ReturnsFalse()
|
||||
{
|
||||
var pos = new PositionWrapper { X = 0, Y = 0, Width = 100, Height = 100 };
|
||||
Assert.IsFalse(pos.Equals("not a position"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void WindowPosition_LeftOfPrimaryMonitor_StoresNegativeCoordinates()
|
||||
{
|
||||
var pos = new PositionWrapper { X = -1920, Y = -200, Width = 1920, Height = 1080 };
|
||||
Assert.AreEqual(-1920, pos.X);
|
||||
Assert.AreEqual(-200, pos.Y);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void WindowPosition_AllZeroValues_IsValidState()
|
||||
{
|
||||
var pos = new PositionWrapper { X = 0, Y = 0, Width = 0, Height = 0 };
|
||||
Assert.AreEqual(0, pos.X);
|
||||
Assert.AreEqual(0, pos.Y);
|
||||
Assert.AreEqual(0, pos.Width);
|
||||
Assert.AreEqual(0, pos.Height);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void WindowPosition_FourthMonitor4K_StoresLargeCoordinates()
|
||||
{
|
||||
var pos = new PositionWrapper { X = 11520, Y = 0, Width = 3840, Height = 2160 };
|
||||
Assert.AreEqual(11520, pos.X);
|
||||
Assert.AreEqual(3840, pos.Width);
|
||||
Assert.AreEqual(2160, pos.Height);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void WindowPosition_DefaultStruct_AllFieldsAreZero()
|
||||
{
|
||||
PositionWrapper pos = default;
|
||||
Assert.AreEqual(0, pos.X);
|
||||
Assert.AreEqual(0, pos.Y);
|
||||
Assert.AreEqual(0, pos.Width);
|
||||
Assert.AreEqual(0, pos.Height);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory("DataModel")]
|
||||
public void WindowPosition_TwoDefaultStructs_AreConsideredEqual()
|
||||
{
|
||||
PositionWrapper pos1 = default;
|
||||
PositionWrapper pos2 = default;
|
||||
Assert.IsTrue(pos1 == pos2);
|
||||
Assert.IsTrue(pos1.Equals(pos2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<!-- Look at Directory.Build.props in root for common stuff as well -->
|
||||
<Import Project="$(RepoRoot)src\Common.Dotnet.CsWinRT.props" />
|
||||
<Import Project="$(RepoRoot)src\Common.SelfContained.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<IsPackable>false</IsPackable>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\tests\WorkspacesLauncherUI.Tests\</OutputPath>
|
||||
<RootNamespace>WorkspacesLauncherUI.UnitTests</RootNamespace>
|
||||
<AssemblyName>PowerToys.WorkspacesLauncherUI.Tests</AssemblyName>
|
||||
<OutputType>Exe</OutputType>
|
||||
<UseWinUI>true</UseWinUI>
|
||||
<Platforms>x64;ARM64</Platforms>
|
||||
<WindowsPackageType>None</WindowsPackageType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
||||
<PackageReference Include="Moq" />
|
||||
<PackageReference Include="MSTest" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WorkspacesCsharpLibrary\WorkspacesCsharpLibrary.csproj" />
|
||||
<ProjectReference Include="..\WorkspacesLauncherUI.WinUI\WorkspacesLauncherUI.WinUI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace WorkspacesLauncherUI.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a boolean to inverted Visibility:
|
||||
/// true → Collapsed (hide the element)
|
||||
/// false → Visible (show the element)
|
||||
///
|
||||
/// Used to show the status glyph (checkmark/X) only when loading is complete.
|
||||
/// The spinner uses the standard BooleanToVisibility (true=Visible),
|
||||
/// and this converter shows the glyph when loading is false.
|
||||
/// </summary>
|
||||
public sealed partial class BooleanToInvertedVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, System.Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is bool boolValue && boolValue)
|
||||
{
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
return Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, System.Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace WorkspacesLauncherUI.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a boolean to Visibility:
|
||||
/// true → Visible
|
||||
/// false → Collapsed
|
||||
///
|
||||
/// Used to show the loading spinner while an app is still launching.
|
||||
/// </summary>
|
||||
public sealed partial class BooleanToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, System.Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is bool boolValue && boolValue)
|
||||
{
|
||||
return Visibility.Visible;
|
||||
}
|
||||
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, System.Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace WorkspacesLauncherUI.Helpers
|
||||
{
|
||||
internal static class IconHelper
|
||||
{
|
||||
public static BitmapImage TryGetExecutableIcon(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using Icon icon = Icon.ExtractAssociatedIcon(path);
|
||||
if (icon is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using Bitmap bitmap = icon.ToBitmap();
|
||||
using MemoryStream stream = new();
|
||||
bitmap.Save(stream, ImageFormat.Png);
|
||||
stream.Position = 0;
|
||||
|
||||
BitmapImage bitmapImage = new();
|
||||
bitmapImage.SetSource(stream.AsRandomAccessStream());
|
||||
return bitmapImage;
|
||||
}
|
||||
catch (Exception ex) when (ex is FileNotFoundException
|
||||
or UnauthorizedAccessException
|
||||
or Win32Exception
|
||||
or ArgumentException
|
||||
or IOException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using ManagedCommon;
|
||||
using Microsoft.Windows.ApplicationModel.Resources;
|
||||
|
||||
namespace WorkspacesLauncherUI
|
||||
{
|
||||
internal static class ResourceLoaderInstance
|
||||
{
|
||||
private static ResourceLoader _resourceLoader;
|
||||
|
||||
internal static ResourceLoader ResourceLoader
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_resourceLoader == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_resourceLoader = new ResourceLoader("PowerToys.WorkspacesLauncherUI.pri");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("Failed to load ResourceLoader: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return _resourceLoader;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
|
||||
using WorkspacesLauncherUI.Data;
|
||||
|
||||
namespace WorkspacesLauncherUI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Model representing an application's launch status in the Launcher UI.
|
||||
/// Drives the display of the spinner (Loading), checkmark/X glyph (StateGlyph),
|
||||
/// and color (StateColor) for each app row.
|
||||
/// </summary>
|
||||
public partial class AppLaunching : ObservableObject
|
||||
{
|
||||
public bool Loading => LaunchState == LaunchingState.Waiting || LaunchState == LaunchingState.Launched;
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string AppPath { get; set; }
|
||||
|
||||
public BitmapImage IconImage { get; set; }
|
||||
|
||||
public string PackagedName { get; set; }
|
||||
|
||||
public string Aumid { get; set; }
|
||||
|
||||
public string PwaAppId { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(Loading))]
|
||||
[NotifyPropertyChangedFor(nameof(StateGlyph))]
|
||||
[NotifyPropertyChangedFor(nameof(StateColor))]
|
||||
[NotifyPropertyChangedFor(nameof(StateColorValue))]
|
||||
private LaunchingState _launchState;
|
||||
|
||||
partial void OnLaunchStateChanged(LaunchingState value)
|
||||
{
|
||||
_stateColorBrush = null;
|
||||
}
|
||||
|
||||
public string StateGlyph
|
||||
{
|
||||
get => LaunchState switch
|
||||
{
|
||||
LaunchingState.LaunchedAndMoved => "\U0000F78C",
|
||||
LaunchingState.Failed => "\U0000EF2C",
|
||||
_ => "\U0000EF2C",
|
||||
};
|
||||
}
|
||||
|
||||
private SolidColorBrush _stateColorBrush;
|
||||
|
||||
public Brush StateColor
|
||||
{
|
||||
get => _stateColorBrush ??= new SolidColorBrush(StateColorValue);
|
||||
}
|
||||
|
||||
public Windows.UI.Color StateColorValue
|
||||
{
|
||||
get => LaunchState switch
|
||||
{
|
||||
LaunchingState.LaunchedAndMoved => Windows.UI.Color.FromArgb(255, 0, 128, 0),
|
||||
LaunchingState.Failed => Windows.UI.Color.FromArgb(255, 254, 0, 0),
|
||||
_ => Windows.UI.Color.FromArgb(255, 254, 0, 0),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
46
src/modules/Workspaces/WorkspacesLauncherUI.WinUI/Program.cs
Normal file
46
src/modules/Workspaces/WorkspacesLauncherUI.WinUI/Program.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
using ManagedCommon;
|
||||
using Microsoft.UI.Dispatching;
|
||||
|
||||
namespace WorkspacesLauncherUI
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Logger.InitializeLogger("\\Workspaces\\WorkspacesLauncherUI");
|
||||
|
||||
WinRT.ComWrappersSupport.InitializeComWrappers();
|
||||
|
||||
if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredWorkspacesEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
|
||||
{
|
||||
Logger.LogWarning("Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
|
||||
return;
|
||||
}
|
||||
|
||||
const string mutexName = "Local\\PowerToys_Workspaces_LauncherUI_InstanceMutex";
|
||||
bool createdNew;
|
||||
using var mutex = new Mutex(true, mutexName, out createdNew);
|
||||
|
||||
if (!createdNew)
|
||||
{
|
||||
Logger.LogWarning("Another instance of Workspaces Launcher UI is already running. Exiting this instance.");
|
||||
return;
|
||||
}
|
||||
|
||||
Microsoft.UI.Xaml.Application.Start((p) =>
|
||||
{
|
||||
var context = new DispatcherQueueSynchronizationContext(DispatcherQueue.GetForCurrentThread());
|
||||
SynchronizationContext.SetSynchronizationContext(context);
|
||||
_ = new App();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="CancelButton.Content" xml:space="preserve">
|
||||
<value>Cancel launch</value>
|
||||
</data>
|
||||
<data name="CancelButton.AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Cancel launch</value>
|
||||
</data>
|
||||
<data name="DismissButton.Content" xml:space="preserve">
|
||||
<value>Dismiss</value>
|
||||
</data>
|
||||
<data name="DismissButton.AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Dismiss</value>
|
||||
</data>
|
||||
<data name="LauncherWindowTitle" xml:space="preserve">
|
||||
<value>Your workspace is launching. Waiting on ...</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -5,35 +5,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
using ManagedCommon;
|
||||
using WorkspacesCsharpLibrary;
|
||||
using WorkspacesLauncherUI.Data;
|
||||
using WorkspacesLauncherUI.Helpers;
|
||||
using WorkspacesLauncherUI.Models;
|
||||
|
||||
namespace WorkspacesLauncherUI.ViewModels
|
||||
{
|
||||
public class MainViewModel : INotifyPropertyChanged, IDisposable
|
||||
public partial class MainViewModel : ObservableObject, IDisposable
|
||||
{
|
||||
public ObservableCollection<AppLaunching> AppsListed { get; set; } = new ObservableCollection<AppLaunching>();
|
||||
private readonly PwaHelper _pwaHelper;
|
||||
private bool _isDisposed;
|
||||
|
||||
private StatusWindow _snapshotWindow;
|
||||
private int launcherProcessID;
|
||||
private PwaHelper _pwaHelper;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void OnPropertyChanged(PropertyChangedEventArgs e)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, e);
|
||||
}
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<AppLaunching> _appsListed = new ObservableCollection<AppLaunching>();
|
||||
|
||||
public MainViewModel()
|
||||
{
|
||||
_pwaHelper = new PwaHelper();
|
||||
|
||||
// receive IPC Message
|
||||
App.IPCMessageReceivedCallback = (string msg) =>
|
||||
{
|
||||
try
|
||||
@@ -51,7 +46,6 @@ namespace WorkspacesLauncherUI.ViewModels
|
||||
|
||||
private void HandleAppLaunchingState(AppLaunchData.AppLaunchDataWrapper appLaunchData)
|
||||
{
|
||||
launcherProcessID = appLaunchData.LauncherProcessID;
|
||||
List<AppLaunching> appLaunchingList = new List<AppLaunching>();
|
||||
foreach (var app in appLaunchData.AppLaunchInfos.AppLaunchInfoList)
|
||||
{
|
||||
@@ -59,6 +53,7 @@ namespace WorkspacesLauncherUI.ViewModels
|
||||
{
|
||||
Name = app.Application.Application,
|
||||
AppPath = app.Application.ApplicationPath,
|
||||
IconImage = IconHelper.TryGetExecutableIcon(app.Application.ApplicationPath),
|
||||
PackagedName = app.Application.PackageFullName,
|
||||
Aumid = app.Application.AppUserModelId,
|
||||
PwaAppId = app.Application.PwaAppId,
|
||||
@@ -67,30 +62,28 @@ namespace WorkspacesLauncherUI.ViewModels
|
||||
}
|
||||
|
||||
AppsListed = new ObservableCollection<AppLaunching>(appLaunchingList);
|
||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(AppsListed)));
|
||||
}
|
||||
|
||||
private void SelfDestroy(object source, System.Timers.ElapsedEventArgs e)
|
||||
[RelayCommand]
|
||||
private void CancelLaunch()
|
||||
{
|
||||
_snapshotWindow.Dispatcher.Invoke(() =>
|
||||
{
|
||||
_snapshotWindow.Close();
|
||||
});
|
||||
App.SendIPCMessage("cancel");
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Dismiss()
|
||||
{
|
||||
// Window close is handled by the view
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_isDisposed)
|
||||
{
|
||||
_isDisposed = true;
|
||||
}
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
internal void SetSnapshotWindow(StatusWindow snapshotWindow)
|
||||
{
|
||||
_snapshotWindow = snapshotWindow;
|
||||
}
|
||||
|
||||
internal void CancelLaunch()
|
||||
{
|
||||
App.SendIPCMessage("cancel");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Application
|
||||
x:Class="WorkspacesLauncherUI.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:WorkspacesLauncherUI">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<FontFamily x:Key="SymbolThemeFontFamily">Segoe Fluent Icons, Segoe MDL2 Assets</FontFamily>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
@@ -0,0 +1,96 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
using ManagedCommon;
|
||||
using Microsoft.UI.Dispatching;
|
||||
using Microsoft.UI.Xaml;
|
||||
using PowerToys.Interop;
|
||||
|
||||
namespace WorkspacesLauncherUI
|
||||
{
|
||||
/// <summary>
|
||||
/// WinUI 3 Application class for the Workspaces Launcher UI.
|
||||
/// Manages the IPC pipe connection to the C++ launcher engine and hosts the status window.
|
||||
/// </summary>
|
||||
public partial class App : Application, IDisposable
|
||||
{
|
||||
private StatusWindow _mainWindow;
|
||||
private TwoWayPipeMessageIPCManaged _ipcManager;
|
||||
private bool _isDisposed;
|
||||
|
||||
public static Action<string> IPCMessageReceivedCallback { get; set; }
|
||||
|
||||
public static DispatcherQueue DispatcherQueue { get; private set; }
|
||||
|
||||
public App()
|
||||
{
|
||||
string languageTag = LanguageHelper.LoadLanguage();
|
||||
if (!string.IsNullOrEmpty(languageTag))
|
||||
{
|
||||
try
|
||||
{
|
||||
Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = languageTag;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("Failed to set language override: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
this.InitializeComponent();
|
||||
this.UnhandledException += OnUnhandledException;
|
||||
}
|
||||
|
||||
public static void SendIPCMessage(string message)
|
||||
{
|
||||
if ((Current as App)?._ipcManager != null)
|
||||
{
|
||||
(Current as App)._ipcManager.Send(message);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
DispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||
|
||||
_ipcManager = new TwoWayPipeMessageIPCManaged(
|
||||
"\\\\.\\pipe\\powertoys_workspaces_ui_",
|
||||
"\\\\.\\pipe\\powertoys_workspaces_launcher_ui_",
|
||||
(string message) =>
|
||||
{
|
||||
if (IPCMessageReceivedCallback != null && message.Length > 0)
|
||||
{
|
||||
DispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
IPCMessageReceivedCallback(message);
|
||||
});
|
||||
}
|
||||
});
|
||||
_ipcManager.Start();
|
||||
|
||||
_mainWindow = new StatusWindow();
|
||||
_mainWindow.Activate();
|
||||
}
|
||||
|
||||
private void OnUnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
|
||||
{
|
||||
Logger.LogError("Unhandled exception occurred", e.Exception);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_isDisposed)
|
||||
{
|
||||
_ipcManager?.End();
|
||||
_ipcManager?.Dispose();
|
||||
_isDisposed = true;
|
||||
}
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Window
|
||||
x:Class="WorkspacesLauncherUI.StatusWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:converters="clr-namespace:WorkspacesLauncherUI.Converters"
|
||||
xmlns:converters="using:WorkspacesLauncherUI.Converters"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:WorkspacesLauncherUI"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:props="clr-namespace:WorkspacesLauncherUI.Properties"
|
||||
Title="{x:Static props:Resources.LauncherWindowTitle}"
|
||||
Width="360"
|
||||
Height="340"
|
||||
BorderBrush="Red"
|
||||
BorderThickness="4"
|
||||
Closing="Window_Closing"
|
||||
ResizeMode="NoResize"
|
||||
Topmost="True"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
xmlns:models="using:WorkspacesLauncherUI.Models"
|
||||
Title="Workspaces"
|
||||
mc:Ignorable="d">
|
||||
<Window.Resources>
|
||||
<BooleanToVisibilityConverter x:Key="BoolToVis" />
|
||||
<converters:BooleanToInvertedVisibilityConverter x:Key="BooleanToInvertedVisibilityConverter" />
|
||||
</Window.Resources>
|
||||
|
||||
<Grid Margin="4" Background="Transparent">
|
||||
<Grid Margin="4">
|
||||
<Grid.Resources>
|
||||
<converters:BooleanToVisibilityConverter x:Key="BoolToVis" />
|
||||
<converters:BooleanToInvertedVisibilityConverter x:Key="BooleanToInvertedVisibilityConverter" />
|
||||
</Grid.Resources>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="1*" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ScrollViewer Grid.ColumnSpan="2">
|
||||
<StackPanel>
|
||||
<ItemsControl ItemsSource="{Binding AppsListed, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
|
||||
|
||||
<ScrollViewer
|
||||
Grid.ColumnSpan="2"
|
||||
AutomationProperties.Name="Application launch status list"
|
||||
TabIndex="0">
|
||||
<StackPanel AutomationProperties.AccessibilityView="Content" AutomationProperties.LiveSetting="Polite">
|
||||
<ItemsControl AutomationProperties.Name="Applications" ItemsSource="{Binding AppsListed, Mode=OneWay}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<DataTemplate x:DataType="models:AppLaunching">
|
||||
<Grid
|
||||
Margin="0,2"
|
||||
Padding="4"
|
||||
AutomationProperties.Name="{Binding Name, Mode=OneWay}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image
|
||||
Width="20"
|
||||
Height="20"
|
||||
Margin="10"
|
||||
Margin="4,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Source="{Binding IconBitmapImage}" />
|
||||
Source="{Binding IconImage}" />
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
Text="{Binding Name, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<ProgressBar
|
||||
AutomationProperties.AccessibilityView="Raw"
|
||||
Foreground="{ThemeResource TextFillColorPrimaryBrush}"
|
||||
Text="{Binding Name, Mode=OneWay}" />
|
||||
<ProgressRing
|
||||
Grid.Column="2"
|
||||
Width="20"
|
||||
Height="20"
|
||||
Margin="10"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
IsIndeterminate="True"
|
||||
Visibility="{Binding Loading, Mode=OneWay, Converter={StaticResource BoolToVis}, UpdateSourceTrigger=PropertyChanged}" />
|
||||
AutomationProperties.Name="Loading"
|
||||
IsActive="True"
|
||||
Visibility="{Binding Loading, Mode=OneWay, Converter={StaticResource BoolToVis}}" />
|
||||
<TextBlock
|
||||
Grid.Column="2"
|
||||
Width="20"
|
||||
@@ -70,34 +72,38 @@
|
||||
Margin="10"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="{DynamicResource SymbolThemeFontFamily}"
|
||||
AutomationProperties.AccessibilityView="Raw"
|
||||
FontFamily="{ThemeResource SymbolThemeFontFamily}"
|
||||
FontSize="20"
|
||||
Foreground="{Binding StateColor}"
|
||||
Text="{Binding StateGlyph}"
|
||||
Visibility="{Binding Loading, Mode=OneWay, Converter={StaticResource BooleanToInvertedVisibilityConverter}, UpdateSourceTrigger=PropertyChanged}" />
|
||||
Foreground="{Binding StateColor, Mode=OneWay}"
|
||||
Text="{Binding StateGlyph, Mode=OneWay}"
|
||||
Visibility="{Binding Loading, Mode=OneWay, Converter={StaticResource BooleanToInvertedVisibilityConverter}}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<Button
|
||||
x:Name="CancelButton"
|
||||
x:Uid="CancelButton"
|
||||
Grid.Row="1"
|
||||
Margin="4"
|
||||
HorizontalAlignment="Stretch"
|
||||
AutomationProperties.Name="{x:Static props:Resources.CancelLaunch}"
|
||||
Click="CancelButtonClicked"
|
||||
Content="{x:Static props:Resources.CancelLaunch}" />
|
||||
Command="{Binding CancelLaunchCommand}"
|
||||
Click="CancelButton_Click"
|
||||
TabIndex="1" />
|
||||
|
||||
<Button
|
||||
x:Name="DismissButton"
|
||||
x:Uid="DismissButton"
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="4"
|
||||
HorizontalAlignment="Stretch"
|
||||
AutomationProperties.Name="{x:Static props:Resources.Dismiss}"
|
||||
Click="DismissButtonClicked"
|
||||
Content="{x:Static props:Resources.Dismiss}"
|
||||
Style="{DynamicResource AccentButtonStyle}" />
|
||||
Click="DismissButton_Click"
|
||||
Style="{ThemeResource AccentButtonStyle}"
|
||||
TabIndex="2" />
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,89 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using ManagedCommon;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
using WorkspacesLauncherUI.ViewModels;
|
||||
|
||||
namespace WorkspacesLauncherUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Status window showing workspace launch progress.
|
||||
/// Displays a list of apps with their launch state (loading/success/failed).
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA1001:Types that own disposable fields should be disposable", Justification = "WinUI Window does not support IDisposable; ViewModel is disposed on window close.")]
|
||||
public sealed partial class StatusWindow : Window
|
||||
{
|
||||
public MainViewModel ViewModel { get; }
|
||||
|
||||
public StatusWindow()
|
||||
{
|
||||
ViewModel = new MainViewModel();
|
||||
this.InitializeComponent();
|
||||
|
||||
// WinUI Window is not a FrameworkElement, so set DataContext on the root content
|
||||
// for {Binding} expressions. DataTemplate x:Bind works independently via x:DataType.
|
||||
if (this.Content is FrameworkElement rootElement)
|
||||
{
|
||||
rootElement.DataContext = ViewModel;
|
||||
}
|
||||
|
||||
this.Closed += Window_Closed;
|
||||
|
||||
// Configure window size and behavior to match WPF original (360x340, non-resizable, topmost)
|
||||
var appWindow = this.AppWindow;
|
||||
appWindow.Resize(new Windows.Graphics.SizeInt32(360, 340));
|
||||
appWindow.SetIcon("Assets/Workspaces/Workspaces.ico");
|
||||
|
||||
// Set title from resources
|
||||
try
|
||||
{
|
||||
this.Title = ResourceLoaderInstance.ResourceLoader?.GetString("LauncherWindowTitle") ?? "Workspaces";
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Logger.LogError("Failed to load window title resource: " + ex.Message);
|
||||
this.Title = "Workspaces";
|
||||
}
|
||||
|
||||
if (appWindow.Presenter is OverlappedPresenter presenter)
|
||||
{
|
||||
presenter.IsResizable = false;
|
||||
presenter.IsAlwaysOnTop = true;
|
||||
}
|
||||
|
||||
// Center on screen
|
||||
CenterOnScreen(appWindow);
|
||||
}
|
||||
|
||||
private static void CenterOnScreen(AppWindow appWindow)
|
||||
{
|
||||
var displayArea = DisplayArea.GetFromWindowId(appWindow.Id, DisplayAreaFallback.Nearest);
|
||||
if (displayArea != null)
|
||||
{
|
||||
int centerX = (displayArea.WorkArea.Width - appWindow.Size.Width) / 2;
|
||||
int centerY = (displayArea.WorkArea.Height - appWindow.Size.Height) / 2;
|
||||
appWindow.Move(new Windows.Graphics.PointInt32(centerX, centerY));
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void DismissButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void Window_Closed(object sender, WindowEventArgs args)
|
||||
{
|
||||
ViewModel?.Dispose();
|
||||
(Application.Current as System.IDisposable)?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<!-- Look at Directory.Build.props in root for common stuff as well -->
|
||||
<Import Project="$(RepoRoot)src\Common.Dotnet.CsWinRT.props" />
|
||||
<Import Project="$(RepoRoot)src\Common.SelfContained.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>WorkspacesLauncherUI</RootNamespace>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<UseWinUI>true</UseWinUI>
|
||||
<Platforms>x64;ARM64</Platforms>
|
||||
<EnableMsixTooling>true</EnableMsixTooling>
|
||||
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
|
||||
<WindowsPackageType>None</WindowsPackageType>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
|
||||
<DefineConstants>DISABLE_XAML_GENERATED_MAIN,TRACE</DefineConstants>
|
||||
<OutputPath>$(RepoRoot)$(Platform)\$(Configuration)\WinUI3Apps</OutputPath>
|
||||
<AssemblyName>PowerToys.WorkspacesLauncherUI</AssemblyName>
|
||||
<ApplicationIcon>..\Assets\Workspaces\Workspaces.ico</ApplicationIcon>
|
||||
<ProjectPriFileName>PowerToys.WorkspacesLauncherUI.pri</ProjectPriFileName>
|
||||
<GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Page Remove="Views\App.xaml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="Views\App.xaml" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- See https://learn.microsoft.com/windows/apps/develop/platform/csharp-winrt/net-projection-from-cppwinrt-component for more info -->
|
||||
<PropertyGroup>
|
||||
<CsWinRTIncludes>PowerToys.GPOWrapper</CsWinRTIncludes>
|
||||
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
|
||||
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\Assets\**\*.*">
|
||||
<Link>Assets\Workspaces\%(Filename)%(Extension)</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\common\Common.UI\Common.UI.csproj" />
|
||||
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
|
||||
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
|
||||
<ProjectReference Include="..\..\..\common\interop\PowerToys.Interop.vcxproj" />
|
||||
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
|
||||
<ProjectReference Include="..\WorkspacesCsharpLibrary\WorkspacesCsharpLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
|
||||
<PackageReference Include="System.Drawing.Common" />
|
||||
<PackageReference Include="System.IO.Abstractions" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<assemblyIdentity version="1.0.0.0" name="PowerToys.WorkspacesLauncherUI.app"/>
|
||||
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- Windows 10 compatibility for unpackaged WinUI 3 apps -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||
</application>
|
||||
</compatibility>
|
||||
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
</assembly>
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
|
||||
</startup>
|
||||
<runtime>
|
||||
<AppContextSwitchOverrides value = "Switch.System.Windows.DoNotScaleForDpiChanges=false"/>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -1,57 +0,0 @@
|
||||
<Application
|
||||
x:Class="WorkspacesLauncherUI.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:WorkspacesLauncherUI"
|
||||
Exit="OnExit"
|
||||
Startup="OnStartup"
|
||||
ThemeMode="System">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<FontFamily x:Key="SymbolThemeFontFamily">Segoe Fluent Icons, Segoe MDL2 Assets</FontFamily>
|
||||
<Style x:Key="HeadingTextBlock" TargetType="TextBlock" />
|
||||
<Style
|
||||
x:Key="SubtleButtonStyle"
|
||||
BasedOn="{StaticResource {x:Type Button}}"
|
||||
TargetType="Button">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border
|
||||
x:Name="Border"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4"
|
||||
SnapsToDevicePixels="True">
|
||||
<ContentPresenter
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Focusable="False"
|
||||
RecognizesAccessKey="True"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="Border" Property="Background" Value="{DynamicResource SubtleFillColorSecondaryBrush}" />
|
||||
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource SubtleFillColorSecondaryBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter TargetName="Border" Property="Background" Value="{DynamicResource SubtleFillColorTertiaryBrush}" />
|
||||
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource SubtleFillColorTertiaryBrush}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextFillColorSecondaryBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextFillColorDisabledBrush}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
@@ -1,147 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
|
||||
using ManagedCommon;
|
||||
using PowerToys.Interop;
|
||||
using WorkspacesLauncherUI.ViewModels;
|
||||
|
||||
namespace WorkspacesLauncherUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application, IDisposable
|
||||
{
|
||||
private static Mutex _instanceMutex;
|
||||
|
||||
// Create an instance of the IPC wrapper.
|
||||
private static TwoWayPipeMessageIPCManaged ipcmanager;
|
||||
|
||||
private StatusWindow _mainWindow;
|
||||
|
||||
private MainViewModel _mainViewModel;
|
||||
|
||||
private bool _isDisposed;
|
||||
|
||||
public static Action<string> IPCMessageReceivedCallback { get; set; }
|
||||
|
||||
public App()
|
||||
{
|
||||
}
|
||||
|
||||
public static void SendIPCMessage(string message)
|
||||
{
|
||||
if (ipcmanager != null)
|
||||
{
|
||||
ipcmanager.Send(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStartup(object sender, StartupEventArgs e)
|
||||
{
|
||||
Logger.InitializeLogger("\\Workspaces\\WorkspacesLauncherUI");
|
||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
|
||||
var languageTag = LanguageHelper.LoadLanguage();
|
||||
|
||||
if (!string.IsNullOrEmpty(languageTag))
|
||||
{
|
||||
try
|
||||
{
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(languageTag);
|
||||
}
|
||||
catch (CultureNotFoundException ex)
|
||||
{
|
||||
Logger.LogError("CultureNotFoundException: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
const string appName = "Local\\PowerToys_Workspaces_LauncherUI_InstanceMutex";
|
||||
bool createdNew;
|
||||
_instanceMutex = new Mutex(true, appName, out createdNew);
|
||||
if (!createdNew)
|
||||
{
|
||||
Logger.LogWarning("Another instance of Workspaces Launcher UI is already running. Exiting this instance.");
|
||||
_instanceMutex = null;
|
||||
Shutdown(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PowerToys.GPOWrapperProjection.GPOWrapper.GetConfiguredWorkspacesEnabledValue() == PowerToys.GPOWrapperProjection.GpoRuleConfigured.Disabled)
|
||||
{
|
||||
Logger.LogWarning("Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
|
||||
Shutdown(0);
|
||||
return;
|
||||
}
|
||||
|
||||
ipcmanager = new TwoWayPipeMessageIPCManaged("\\\\.\\pipe\\powertoys_workspaces_ui_", "\\\\.\\pipe\\powertoys_workspaces_launcher_ui_", (string message) =>
|
||||
{
|
||||
if (IPCMessageReceivedCallback != null && message.Length > 0)
|
||||
{
|
||||
IPCMessageReceivedCallback(message);
|
||||
}
|
||||
});
|
||||
ipcmanager.Start();
|
||||
|
||||
if (_mainViewModel == null)
|
||||
{
|
||||
_mainViewModel = new MainViewModel();
|
||||
}
|
||||
|
||||
// normal start of editor
|
||||
if (_mainWindow == null)
|
||||
{
|
||||
_mainWindow = new StatusWindow(_mainViewModel);
|
||||
}
|
||||
|
||||
// reset main window owner to keep it on the top
|
||||
_mainWindow.ShowActivated = true;
|
||||
_mainWindow.Topmost = true;
|
||||
_mainWindow.Show();
|
||||
}
|
||||
|
||||
private void OnExit(object sender, ExitEventArgs e)
|
||||
{
|
||||
if (_instanceMutex != null)
|
||||
{
|
||||
_instanceMutex.ReleaseMutex();
|
||||
}
|
||||
|
||||
Dispose();
|
||||
}
|
||||
|
||||
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs args)
|
||||
{
|
||||
Logger.LogError("Unhandled exception occurred", args.ExceptionObject as Exception);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_isDisposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
ipcmanager?.End();
|
||||
ipcmanager?.Dispose();
|
||||
|
||||
_instanceMutex?.Dispose();
|
||||
}
|
||||
|
||||
_isDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WorkspacesLauncherUI.Converters
|
||||
{
|
||||
public class BooleanToInvertedVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if ((bool)value)
|
||||
{
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
return Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Windows.Automation.Peers;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace WorkspacesLauncherUI
|
||||
{
|
||||
public class HeadingTextBlock : TextBlock
|
||||
{
|
||||
protected override AutomationPeer OnCreateAutomationPeer()
|
||||
{
|
||||
return new HeadingTextBlockAutomationPeer(this);
|
||||
}
|
||||
|
||||
internal sealed class HeadingTextBlockAutomationPeer : TextBlockAutomationPeer
|
||||
{
|
||||
public HeadingTextBlockAutomationPeer(HeadingTextBlock owner)
|
||||
: base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
protected override AutomationControlType GetAutomationControlTypeCore()
|
||||
{
|
||||
return AutomationControlType.Header;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using ManagedCommon;
|
||||
using WorkspacesCsharpLibrary.Models;
|
||||
using WorkspacesLauncherUI.Data;
|
||||
|
||||
namespace WorkspacesLauncherUI.Models
|
||||
{
|
||||
public class AppLaunching : BaseApplication, IDisposable
|
||||
{
|
||||
public bool Loading => LaunchState == LaunchingState.Waiting || LaunchState == LaunchingState.Launched;
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public LaunchingState LaunchState { get; set; }
|
||||
|
||||
public string StateGlyph
|
||||
{
|
||||
get => LaunchState switch
|
||||
{
|
||||
LaunchingState.LaunchedAndMoved => "\U0000F78C",
|
||||
LaunchingState.Failed => "\U0000EF2C",
|
||||
_ => "\U0000EF2C",
|
||||
};
|
||||
}
|
||||
|
||||
public System.Windows.Media.Brush StateColor
|
||||
{
|
||||
get => LaunchState switch
|
||||
{
|
||||
LaunchingState.LaunchedAndMoved => new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 0, 128, 0)),
|
||||
LaunchingState.Failed => new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 254, 0, 0)),
|
||||
_ => new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 254, 0, 0)),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace WorkspacesLauncherUI.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
public class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WorkspacesLauncherUI.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Cancel launch.
|
||||
/// </summary>
|
||||
public static string CancelLaunch {
|
||||
get {
|
||||
return ResourceManager.GetString("CancelLaunch", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Dismiss.
|
||||
/// </summary>
|
||||
public static string Dismiss {
|
||||
get {
|
||||
return ResourceManager.GetString("Dismiss", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Your workspace is launching. Waiting on ....
|
||||
/// </summary>
|
||||
public static string LauncherWindowTitle {
|
||||
get {
|
||||
return ResourceManager.GetString("LauncherWindowTitle", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="CancelLaunch" xml:space="preserve">
|
||||
<value>Cancel launch</value>
|
||||
</data>
|
||||
<data name="Dismiss" xml:space="preserve">
|
||||
<value>Dismiss</value>
|
||||
</data>
|
||||
<data name="LauncherWindowTitle" xml:space="preserve">
|
||||
<value>Your workspace is launching. Waiting on ...</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -1,26 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace WorkspacesLauncherUI.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.1.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Windows;
|
||||
|
||||
using WorkspacesLauncherUI.ViewModels;
|
||||
|
||||
namespace WorkspacesLauncherUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for SnapshotWindow.xaml
|
||||
/// </summary>
|
||||
public partial class StatusWindow : Window
|
||||
{
|
||||
private MainViewModel _mainViewModel;
|
||||
|
||||
public StatusWindow(MainViewModel mainViewModel)
|
||||
{
|
||||
_mainViewModel = mainViewModel;
|
||||
_mainViewModel.SetSnapshotWindow(this);
|
||||
this.DataContext = _mainViewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void CancelButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_mainViewModel.CancelLaunch();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void DismissButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<!-- Look at Directory.Build.props in root for common stuff as well -->
|
||||
<Import Project="$(RepoRoot)src\Common.Dotnet.CsWinRT.props" />
|
||||
<Import Project="$(RepoRoot)src\Common.SelfContained.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyTitle>PowerToys.WorkspacesLauncherUI</AssemblyTitle>
|
||||
<AssemblyDescription>PowerToys Workspaces Launcher UI</AssemblyDescription>
|
||||
<Description>PowerToys Workspaces Launcher UI</Description>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
<GenerateSatelliteAssembliesForCore>true</GenerateSatelliteAssembliesForCore>
|
||||
<OutputPath>$(RepoRoot)$(Platform)\$(Configuration)</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{9C53CC25-0623-4569-95BC-B05410675EE3}</ProjectGuid>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>..\Assets\Workspaces\Workspaces.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<AssemblyName>PowerToys.WorkspacesLauncherUI</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\Assets\**\*.*">
|
||||
<Link>Assets\Workspaces\%(Filename)%(Extension)</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<COMReference Include="IWshRuntimeLibrary">
|
||||
<WrapperTool>tlbimp</WrapperTool>
|
||||
<VersionMinor>0</VersionMinor>
|
||||
<VersionMajor>1</VersionMajor>
|
||||
<Guid>f935dc20-1cf0-11d0-adb9-00c04fd58a0b</Guid>
|
||||
<Lcid>0</Lcid>
|
||||
<Isolated>false</Isolated>
|
||||
<EmbedInteropTypes>true</EmbedInteropTypes>
|
||||
</COMReference>
|
||||
<COMReference Include="Shell32">
|
||||
<WrapperTool>tlbimp</WrapperTool>
|
||||
<VersionMinor>0</VersionMinor>
|
||||
<VersionMajor>1</VersionMajor>
|
||||
<Guid>50a7e9b0-70ef-11d1-b75a-00a0c90564fe</Guid>
|
||||
<Lcid>0</Lcid>
|
||||
<Isolated>false</Isolated>
|
||||
<EmbedInteropTypes>true</EmbedInteropTypes>
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Include="app.manifest" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.IO.Abstractions" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\common\Common.UI\Common.UI.csproj" />
|
||||
<ProjectReference Include="..\..\..\common\GPOWrapperProjection\GPOWrapperProjection.csproj" />
|
||||
<ProjectReference Include="..\..\..\common\interop\PowerToys.Interop.vcxproj" />
|
||||
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||
<ProjectReference Include="..\..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
|
||||
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
|
||||
<ProjectReference Include="..\WorkspacesCsharpLibrary\WorkspacesCsharpLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Properties\Settings.Designer.cs">
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,74 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
||||
<security>
|
||||
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<!-- UAC Manifest Options
|
||||
If you want to change the Windows User Account Control level replace the
|
||||
requestedExecutionLevel node with one of the following.
|
||||
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
|
||||
|
||||
Specifying requestedExecutionLevel element will disable file and registry virtualization.
|
||||
Remove this element if your application requires this virtualization for backwards
|
||||
compatibility.
|
||||
-->
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- A list of the Windows versions that this application has been tested on
|
||||
and is designed to work with. Uncomment the appropriate elements
|
||||
and Windows will automatically select the most compatible environment. -->
|
||||
|
||||
<!-- Windows Vista -->
|
||||
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
|
||||
|
||||
<!-- Windows 7 -->
|
||||
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
|
||||
|
||||
<!-- Windows 8 -->
|
||||
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
|
||||
|
||||
<!-- Windows 8.1 -->
|
||||
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
|
||||
|
||||
<!-- Windows 10 -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||
|
||||
</application>
|
||||
</compatibility>
|
||||
|
||||
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
|
||||
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
|
||||
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
|
||||
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
|
||||
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
|
||||
<!--
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity
|
||||
type="win32"
|
||||
name="Microsoft.Windows.Common-Controls"
|
||||
version="6.0.0.0"
|
||||
processorArchitecture="*"
|
||||
publicKeyToken="6595b64144ccf1df"
|
||||
language="*"
|
||||
/>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
</assembly>
|
||||
@@ -34,15 +34,17 @@ namespace winrt
|
||||
using namespace Windows::Devices::Enumeration;
|
||||
}
|
||||
|
||||
AudioSampleGenerator::AudioSampleGenerator(bool captureMicrophone, bool captureSystemAudio, bool micMonoMix)
|
||||
AudioSampleGenerator::AudioSampleGenerator(bool captureMicrophone, bool captureSystemAudio, bool mixMicrophoneMono, bool useNoiseCancellation)
|
||||
: m_captureMicrophone(captureMicrophone)
|
||||
, m_captureSystemAudio(captureSystemAudio)
|
||||
, m_micMonoMix(micMonoMix)
|
||||
, m_mixMicrophoneMono(mixMicrophoneMono)
|
||||
, m_useNoiseCancellation(useNoiseCancellation)
|
||||
{
|
||||
OutputDebugStringA(("AudioSampleGenerator created, captureMicrophone=" +
|
||||
std::string(captureMicrophone ? "true" : "false") +
|
||||
", captureSystemAudio=" + std::string(captureSystemAudio ? "true" : "false") +
|
||||
", micMonoMix=" + std::string(micMonoMix ? "true" : "false") + "\n").c_str());
|
||||
", mixMicrophoneMono=" + std::string(mixMicrophoneMono ? "true" : "false") +
|
||||
", useNoiseCancellation=" + std::string(useNoiseCancellation ? "true" : "false") + "\n").c_str());
|
||||
m_audioEvent.create(wil::EventOptions::ManualReset);
|
||||
m_endEvent.create(wil::EventOptions::ManualReset);
|
||||
m_startEvent.create(wil::EventOptions::ManualReset);
|
||||
@@ -158,8 +160,24 @@ winrt::IAsyncAction AudioSampleGenerator::InitializeAsync()
|
||||
throw winrt::hresult_error(E_FAIL, L"Failed to initialize loopback audio capture!");
|
||||
}
|
||||
|
||||
// Initialize noise suppressor for microphone audio if enabled
|
||||
if (m_useNoiseCancellation && m_captureMicrophone)
|
||||
{
|
||||
m_noiseSuppressor = std::make_unique<NoiseSuppressor>();
|
||||
OutputDebugStringA("Noise cancellation enabled for microphone\n");
|
||||
}
|
||||
|
||||
m_audioGraph.QuantumStarted({ this, &AudioSampleGenerator::OnAudioQuantumStarted });
|
||||
|
||||
// Start the AudioGraph now so the microphone device begins warming up
|
||||
// during the remaining recording initialization (transcoder setup, etc.).
|
||||
// OnAudioQuantumStarted returns early while m_started is false, so audio
|
||||
// samples are discarded until Start() is called. The side-effect of
|
||||
// starting the graph early is that the system mic-active icon appears
|
||||
// sooner, which also triggers a desktop-content change that helps
|
||||
// unblock the WGC frame pool wait in OnMediaStreamSourceStarting.
|
||||
m_audioGraph.Start();
|
||||
|
||||
m_asyncInitialized.SetEvent();
|
||||
}
|
||||
}
|
||||
@@ -205,67 +223,65 @@ std::optional<winrt::MediaStreamSample> AudioSampleGenerator::TryGetNextSample()
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for audio samples to become available, retrying on spurious wakes
|
||||
// (e.g. when OnAudioQuantumStarted signals m_audioEvent but the quantum
|
||||
// produced an empty buffer so m_samples is still empty).
|
||||
for (;;)
|
||||
{
|
||||
auto lock = m_lock.lock_exclusive();
|
||||
if (m_samples.empty() && m_endEvent.is_signaled())
|
||||
{
|
||||
auto lock = m_lock.lock_exclusive();
|
||||
if (m_samples.empty() && m_endEvent.is_signaled())
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
else if (!m_samples.empty())
|
||||
{
|
||||
std::optional result(m_samples.front());
|
||||
m_samples.pop_front();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
m_audioEvent.ResetEvent();
|
||||
std::vector<HANDLE> events = { m_endEvent.get(), m_audioEvent.get() };
|
||||
auto waitResult = WaitForMultipleObjectsEx(static_cast<DWORD>(events.size()), events.data(), false, INFINITE, false);
|
||||
auto eventIndex = -1;
|
||||
switch (waitResult)
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
case WAIT_OBJECT_0 + 1:
|
||||
eventIndex = waitResult - WAIT_OBJECT_0;
|
||||
break;
|
||||
}
|
||||
WINRT_VERIFY(eventIndex >= 0);
|
||||
|
||||
auto signaledEvent = events[eventIndex];
|
||||
if (signaledEvent == m_endEvent.get())
|
||||
{
|
||||
// End was signaled, but check for any remaining samples before returning nullopt
|
||||
auto lock = m_lock.lock_exclusive();
|
||||
if (!m_samples.empty())
|
||||
{
|
||||
std::optional result(m_samples.front());
|
||||
m_samples.pop_front();
|
||||
return result;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
else if (!m_samples.empty())
|
||||
{
|
||||
std::optional result(m_samples.front());
|
||||
m_samples.pop_front();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
m_audioEvent.ResetEvent();
|
||||
std::vector<HANDLE> events = { m_endEvent.get(), m_audioEvent.get() };
|
||||
auto waitResult = WaitForMultipleObjectsEx(static_cast<DWORD>(events.size()), events.data(), false, INFINITE, false);
|
||||
auto eventIndex = -1;
|
||||
switch (waitResult)
|
||||
{
|
||||
case WAIT_OBJECT_0:
|
||||
case WAIT_OBJECT_0 + 1:
|
||||
eventIndex = waitResult - WAIT_OBJECT_0;
|
||||
break;
|
||||
}
|
||||
WINRT_VERIFY(eventIndex >= 0);
|
||||
|
||||
auto signaledEvent = events[eventIndex];
|
||||
if (signaledEvent == m_endEvent.get())
|
||||
{
|
||||
// End was signaled, but check for any remaining samples before returning nullopt
|
||||
auto lock = m_lock.lock_exclusive();
|
||||
if (!m_samples.empty())
|
||||
{
|
||||
std::optional result(m_samples.front());
|
||||
m_samples.pop_front();
|
||||
return result;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto lock = m_lock.lock_exclusive();
|
||||
if (m_samples.empty())
|
||||
{
|
||||
// Spurious wake or race - no samples available
|
||||
// If end is signaled, return nullopt
|
||||
return m_endEvent.is_signaled() ? std::nullopt : std::optional<winrt::MediaStreamSample>{};
|
||||
}
|
||||
std::optional result(m_samples.front());
|
||||
m_samples.pop_front();
|
||||
return result;
|
||||
// m_audioEvent was signaled — loop back to check m_samples again.
|
||||
// If the quantum produced an empty buffer, m_samples will still be
|
||||
// empty and we'll wait for the next quantum.
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSampleGenerator::Start()
|
||||
void AudioSampleGenerator::Start(int64_t videoStartTimestamp)
|
||||
{
|
||||
CheckInitialized();
|
||||
m_videoStartTimestamp = videoStartTimestamp;
|
||||
auto expected = false;
|
||||
if (m_started.compare_exchange_strong(expected, true))
|
||||
{
|
||||
OutputDebugStringW( L"[AudioGen] Start(): m_started set to true, setting m_startEvent\n" );
|
||||
m_endEvent.ResetEvent();
|
||||
m_startEvent.SetEvent();
|
||||
|
||||
@@ -284,7 +300,7 @@ void AudioSampleGenerator::Start()
|
||||
m_loopbackCapture->Start();
|
||||
}
|
||||
|
||||
m_audioGraph.Start();
|
||||
// AudioGraph was already started in InitializeAsync for mic warmup.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,12 +627,21 @@ void AudioSampleGenerator::CombineQueuedSamples()
|
||||
|
||||
void AudioSampleGenerator::OnAudioQuantumStarted(winrt::AudioGraph const& sender, winrt::IInspectable const& args)
|
||||
{
|
||||
// Don't process if we're not actively recording
|
||||
// Don't process if we're not actively recording, but DO drain the
|
||||
// output node so stale audio doesn't accumulate during mic warmup.
|
||||
// Without this, the first GetFrame() after m_started becomes true
|
||||
// would return several seconds of buffered audio, confusing the
|
||||
// transcoder's A/V interleaving.
|
||||
if (!m_started.load())
|
||||
{
|
||||
auto frame = m_audioOutputNode.GetFrame();
|
||||
(void)frame; // discard
|
||||
return;
|
||||
}
|
||||
|
||||
static int s_quantumCount = 0;
|
||||
s_quantumCount++;
|
||||
|
||||
{
|
||||
auto lock = m_lock.lock_exclusive();
|
||||
|
||||
@@ -628,6 +653,14 @@ void AudioSampleGenerator::OnAudioQuantumStarted(winrt::AudioGraph const& sender
|
||||
auto sampleBuffer = winrt::Buffer::CreateCopyFromMemoryBuffer(audioBuffer);
|
||||
sampleBuffer.Length(audioBuffer.Length());
|
||||
|
||||
if( s_quantumCount <= 5 )
|
||||
{
|
||||
wchar_t dbg[256];
|
||||
swprintf_s( dbg, L"[AudioGen] quantum #%d: audioBuffer.Length=%u sampleBuffer.Length=%u started=%d\n",
|
||||
s_quantumCount, audioBuffer.Length(), sampleBuffer.Length(), m_started.load() ? 1 : 0 );
|
||||
OutputDebugStringW( dbg );
|
||||
}
|
||||
|
||||
// Calculate expected samples per quantum (~10ms at graph sample rate)
|
||||
// AudioGraph uses 10ms quantums by default
|
||||
uint32_t expectedSamplesPerQuantum = (m_graphSampleRate / 100) * m_graphChannels;
|
||||
@@ -636,7 +669,7 @@ void AudioSampleGenerator::OnAudioQuantumStarted(winrt::AudioGraph const& sender
|
||||
// Apply mono mixing to microphone audio if enabled
|
||||
// This converts stereo mic input (with same signal on both channels) to true mono
|
||||
// by averaging the channels and writing the result to both channels
|
||||
if (m_micMonoMix && m_captureMicrophone && numMicSamples > 0 && m_graphChannels >= 2)
|
||||
if (m_mixMicrophoneMono && m_captureMicrophone && numMicSamples > 0 && m_graphChannels >= 2)
|
||||
{
|
||||
float* micData = reinterpret_cast<float*>(sampleBuffer.data());
|
||||
uint32_t numFrames = numMicSamples / m_graphChannels;
|
||||
@@ -656,6 +689,12 @@ void AudioSampleGenerator::OnAudioQuantumStarted(winrt::AudioGraph const& sender
|
||||
}
|
||||
}
|
||||
}
|
||||
// Apply noise suppression to microphone audio before mixing with loopback
|
||||
if (m_noiseSuppressor && m_captureMicrophone && numMicSamples > 0)
|
||||
{
|
||||
float* micData = reinterpret_cast<float*>(sampleBuffer.data());
|
||||
m_noiseSuppressor->Process(micData, numMicSamples, m_graphChannels);
|
||||
}
|
||||
|
||||
// Drain loopback samples regardless of whether we have mic audio
|
||||
if (m_loopbackCapture)
|
||||
@@ -733,13 +772,25 @@ void AudioSampleGenerator::OnAudioQuantumStarted(winrt::AudioGraph const& sender
|
||||
|
||||
if (sampleBuffer.Length() > 0)
|
||||
{
|
||||
auto sample = winrt::MediaStreamSample::CreateFromBuffer(sampleBuffer, timestamp.value());
|
||||
// Rebase audio timestamps to the video's SystemRelativeTime domain.
|
||||
// AudioGraph RelativeTime starts near 0 (or a few hundred ms after
|
||||
// warmup draining), while video uses absolute SRT (~hours since boot).
|
||||
// Without rebasing, the transcoder sees audio far behind video and
|
||||
// starves video while trying to fill the gap with audio.
|
||||
if (!m_hasTimestampOffset && timestamp.has_value())
|
||||
{
|
||||
m_timestampOffset = m_videoStartTimestamp - timestamp.value().count();
|
||||
m_hasTimestampOffset = true;
|
||||
}
|
||||
auto adjustedTs = winrt::TimeSpan{ timestamp.value().count() + m_timestampOffset };
|
||||
|
||||
auto sample = winrt::MediaStreamSample::CreateFromBuffer(sampleBuffer, adjustedTs);
|
||||
m_samples.push_back(sample);
|
||||
|
||||
const uint32_t sampleCount = sampleBuffer.Length() / sizeof(float);
|
||||
const uint32_t frames = (m_graphChannels > 0) ? (sampleCount / m_graphChannels) : 0;
|
||||
const int64_t durationTicks = (m_graphSampleRate > 0) ? (static_cast<int64_t>(frames) * 10000000LL / m_graphSampleRate) : 0;
|
||||
m_lastSampleTimestamp = timestamp.value();
|
||||
m_lastSampleTimestamp = adjustedTs;
|
||||
m_lastSampleDuration = winrt::TimeSpan{ durationTicks };
|
||||
m_hasLastSampleTimestamp = true;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "LoopbackCapture.h"
|
||||
#include "NoiseSuppressor.h"
|
||||
|
||||
#include <deque>
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
|
||||
class AudioSampleGenerator
|
||||
{
|
||||
public:
|
||||
AudioSampleGenerator(bool captureMicrophone = true, bool captureSystemAudio = true, bool micMonoMix = false);
|
||||
AudioSampleGenerator(bool captureMicrophone = true, bool captureSystemAudio = true, bool mixMicrophoneMono = false, bool useNoiseCancellation = false);
|
||||
~AudioSampleGenerator();
|
||||
|
||||
winrt::Windows::Foundation::IAsyncAction InitializeAsync();
|
||||
winrt::Windows::Media::MediaProperties::AudioEncodingProperties GetEncodingProperties();
|
||||
|
||||
std::optional<winrt::Windows::Media::Core::MediaStreamSample> TryGetNextSample();
|
||||
void Start();
|
||||
void Start(int64_t videoStartTimestamp = 0);
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
@@ -70,5 +75,14 @@ private:
|
||||
std::atomic<bool> m_started = false;
|
||||
bool m_captureMicrophone = true;
|
||||
bool m_captureSystemAudio = true;
|
||||
bool m_micMonoMix = false;
|
||||
};
|
||||
bool m_mixMicrophoneMono = false;
|
||||
bool m_useNoiseCancellation = false;
|
||||
std::unique_ptr<NoiseSuppressor> m_noiseSuppressor;
|
||||
|
||||
// Timestamp rebasing: audio RelativeTime → video SystemRelativeTime domain.
|
||||
// Without this, the transcoder sees audio timestamps (~350ms) far below video
|
||||
// timestamps (~111 billion ticks) and starves video while trying to fill the gap.
|
||||
int64_t m_videoStartTimestamp = 0;
|
||||
int64_t m_timestampOffset = 0;
|
||||
bool m_hasTimestampOffset = false;
|
||||
};
|
||||
|
||||
859
src/modules/ZoomIt/ZoomIt/BackgroundBlur.cpp
Normal file
859
src/modules/ZoomIt/ZoomIt/BackgroundBlur.cpp
Normal file
@@ -0,0 +1,859 @@
|
||||
//==============================================================================
|
||||
//
|
||||
// BackgroundBlur.cpp
|
||||
//
|
||||
// Windows ML-based person segmentation and background blur for the
|
||||
// webcam overlay. Uses the built-in Windows.AI.MachineLearning API
|
||||
// to load an ONNX segmentation model (e.g. MediaPipe SelfieSegmentation)
|
||||
// and produce a per-pixel person mask, then blurs or replaces the
|
||||
// background using an iterated box blur or a user-chosen image.
|
||||
//
|
||||
// Copyright (C) Mark Russinovich
|
||||
// Sysinternals - www.sysinternals.com
|
||||
//
|
||||
//==============================================================================
|
||||
#include "pch.h"
|
||||
#include "BackgroundBlur.h"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <wincodec.h>
|
||||
#include <wil/com.h>
|
||||
|
||||
namespace winml = winrt::Windows::AI::MachineLearning;
|
||||
namespace wf = winrt::Windows::Foundation::Collections;
|
||||
|
||||
// Defined in Zoomit.cpp; compiles to nothing in Release builds.
|
||||
void OutputDebug(const TCHAR* format, ...);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// BackgroundBlur::Initialize
|
||||
//
|
||||
// Loads the ONNX segmentation model via Windows ML and inspects its
|
||||
// input/output tensor shapes to auto-configure preprocessing.
|
||||
//----------------------------------------------------------------------------
|
||||
bool BackgroundBlur::Initialize( const wchar_t* modelPath )
|
||||
{
|
||||
try
|
||||
{
|
||||
// Load the model from file.
|
||||
m_model = winml::LearningModel::LoadFromFilePath( modelPath );
|
||||
|
||||
// Try GPU (DirectML) first for faster inference; fall back to CPU
|
||||
// if no suitable GPU is available.
|
||||
try
|
||||
{
|
||||
winml::LearningModelDevice gpuDevice( winml::LearningModelDeviceKind::DirectXHighPerformance );
|
||||
m_session = winml::LearningModelSession( m_model, gpuDevice );
|
||||
m_usingGpu = true;
|
||||
OutputDebug( L"[BackgroundBlur] Using DirectML (GPU) for inference\n" );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
winml::LearningModelDevice cpuDevice( winml::LearningModelDeviceKind::Cpu );
|
||||
m_session = winml::LearningModelSession( m_model, cpuDevice );
|
||||
m_usingGpu = false;
|
||||
OutputDebug( L"[BackgroundBlur] GPU unavailable, falling back to CPU\n" );
|
||||
}
|
||||
m_binding = winml::LearningModelBinding( m_session );
|
||||
|
||||
// Get input feature descriptor.
|
||||
auto inputFeatures = m_model.InputFeatures();
|
||||
if( inputFeatures.Size() == 0 )
|
||||
{
|
||||
OutputDebug( L"[BackgroundBlur] Model has no input features\n" );
|
||||
return false;
|
||||
}
|
||||
auto inputDesc = inputFeatures.GetAt( 0 );
|
||||
m_inputName = inputDesc.Name();
|
||||
|
||||
// Inspect input tensor shape.
|
||||
auto tensorDesc = inputDesc.as<winml::ITensorFeatureDescriptor>();
|
||||
auto shape = tensorDesc.Shape();
|
||||
if( shape.Size() == 4 )
|
||||
{
|
||||
if( shape.GetAt( 1 ) == 3 || shape.GetAt( 1 ) == 1 )
|
||||
{
|
||||
// NCHW layout.
|
||||
m_inputIsNchw = true;
|
||||
m_modelInputChannels = shape.GetAt( 1 );
|
||||
m_modelInputHeight = shape.GetAt( 2 ) > 0 ? shape.GetAt( 2 ) : 256;
|
||||
m_modelInputWidth = shape.GetAt( 3 ) > 0 ? shape.GetAt( 3 ) : 256;
|
||||
}
|
||||
else
|
||||
{
|
||||
// NHWC layout.
|
||||
m_inputIsNchw = false;
|
||||
m_modelInputHeight = shape.GetAt( 1 ) > 0 ? shape.GetAt( 1 ) : 256;
|
||||
m_modelInputWidth = shape.GetAt( 2 ) > 0 ? shape.GetAt( 2 ) : 256;
|
||||
m_modelInputChannels = shape.GetAt( 3 );
|
||||
}
|
||||
}
|
||||
|
||||
// Get output feature name.
|
||||
auto outputFeatures = m_model.OutputFeatures();
|
||||
if( outputFeatures.Size() == 0 )
|
||||
{
|
||||
OutputDebug( L"[BackgroundBlur] Model has no output features\n" );
|
||||
return false;
|
||||
}
|
||||
m_outputName = outputFeatures.GetAt( 0 ).Name();
|
||||
|
||||
OutputDebug( L"[BackgroundBlur] Model loaded: input=%s %lldx%lld (ch=%lld, %s)\n",
|
||||
m_inputName.c_str(), m_modelInputWidth, m_modelInputHeight,
|
||||
m_modelInputChannels, m_inputIsNchw ? L"NCHW" : L"NHWC" );
|
||||
|
||||
// Pre-allocate input tensor buffer.
|
||||
m_inputTensor.resize( static_cast<size_t>( m_modelInputChannels * m_modelInputHeight * m_modelInputWidth ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
catch( winrt::hresult_error const& ex )
|
||||
{
|
||||
OutputDebug( L"[BackgroundBlur] Initialize failed: %s (0x%08X)\n", ex.message().c_str(), ex.code().value );
|
||||
m_session = nullptr;
|
||||
m_model = nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// BackgroundBlur::RunSegmentation
|
||||
//
|
||||
// Resizes the BGRA frame to the model's expected input size, converts
|
||||
// to float RGB, runs inference via Windows ML, and produces a float mask
|
||||
// in m_mask where 1.0 = person, 0.0 = background.
|
||||
//----------------------------------------------------------------------------
|
||||
bool BackgroundBlur::RunSegmentation( const uint8_t* bgraPixels, uint32_t width, uint32_t height,
|
||||
bool modelResOnly )
|
||||
{
|
||||
const int64_t mW = m_modelInputWidth;
|
||||
const int64_t mH = m_modelInputHeight;
|
||||
const int64_t mC = m_modelInputChannels;
|
||||
|
||||
// Resize BGRA → model-sized float RGB using nearest-neighbor.
|
||||
for( int64_t y = 0; y < mH; y++ )
|
||||
{
|
||||
uint32_t srcY = static_cast<uint32_t>( y * height / mH );
|
||||
for( int64_t x = 0; x < mW; x++ )
|
||||
{
|
||||
uint32_t srcX = static_cast<uint32_t>( x * width / mW );
|
||||
const uint8_t* px = bgraPixels + ( static_cast<size_t>( srcY ) * width + srcX ) * 4;
|
||||
float b = px[0] / 255.0f;
|
||||
float g = px[1] / 255.0f;
|
||||
float r = px[2] / 255.0f;
|
||||
|
||||
if( m_inputIsNchw )
|
||||
{
|
||||
m_inputTensor[static_cast<size_t>(0ll * mH * mW + y * mW + x)] = r;
|
||||
if( mC > 1 ) m_inputTensor[static_cast<size_t>(1ll * mH * mW + y * mW + x)] = g;
|
||||
if( mC > 2 ) m_inputTensor[static_cast<size_t>(2ll * mH * mW + y * mW + x)] = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t idx = static_cast<size_t>( (y * mW + x) * mC );
|
||||
m_inputTensor[idx + 0] = r;
|
||||
if( mC > 1 ) m_inputTensor[idx + 1] = g;
|
||||
if( mC > 2 ) m_inputTensor[idx + 2] = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Create the input tensor shape.
|
||||
std::vector<int64_t> inputShape;
|
||||
if( m_inputIsNchw )
|
||||
inputShape = { 1, mC, mH, mW };
|
||||
else
|
||||
inputShape = { 1, mH, mW, mC };
|
||||
|
||||
// Create a TensorFloat from our data.
|
||||
auto inputTensor = winml::TensorFloat::CreateFromArray(
|
||||
inputShape, winrt::array_view<const float>( m_inputTensor.data(),
|
||||
m_inputTensor.data() + m_inputTensor.size() ) );
|
||||
|
||||
// Bind input and evaluate.
|
||||
m_binding.Clear();
|
||||
m_binding.Bind( m_inputName, inputTensor );
|
||||
|
||||
auto result = m_session.Evaluate( m_binding, L"" );
|
||||
|
||||
// Extract output tensor — bulk-copy to a raw float array so we
|
||||
// avoid per-element WinRT/COM dispatch in the hot loop.
|
||||
auto outputTensor = result.Outputs().Lookup( m_outputName ).as<winml::TensorFloat>();
|
||||
auto outputShape = outputTensor.Shape();
|
||||
auto outputView = outputTensor.GetAsVectorView();
|
||||
const uint32_t outputSize = outputView.Size();
|
||||
m_outputBuf.resize( outputSize );
|
||||
outputView.GetMany( 0, m_outputBuf );
|
||||
const float* outData = m_outputBuf.data();
|
||||
|
||||
// Determine output mask dimensions.
|
||||
int64_t outH = mH, outW = mW;
|
||||
int64_t numClasses = 1;
|
||||
if( outputShape.Size() == 4 )
|
||||
{
|
||||
if( outputShape.GetAt( 1 ) <= 2 && outputShape.GetAt( 2 ) > 2 )
|
||||
{
|
||||
// [1, classes, H, W]
|
||||
numClasses = outputShape.GetAt( 1 );
|
||||
outH = outputShape.GetAt( 2 );
|
||||
outW = outputShape.GetAt( 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// [1, H, W, classes]
|
||||
outH = outputShape.GetAt( 1 );
|
||||
outW = outputShape.GetAt( 2 );
|
||||
numClasses = outputShape.GetAt( 3 );
|
||||
}
|
||||
}
|
||||
else if( outputShape.Size() == 3 )
|
||||
{
|
||||
outH = outputShape.GetAt( 1 );
|
||||
outW = outputShape.GetAt( 2 );
|
||||
}
|
||||
|
||||
// Store actual output dimensions for GetModelMaskWidth/Height.
|
||||
m_modelOutputWidth = outW;
|
||||
m_modelOutputHeight = outH;
|
||||
|
||||
// Build model-resolution mask first, apply sigmoid sharpening
|
||||
// at model resolution (e.g. 256×256 = 65K pixels), then upscale
|
||||
// to frame resolution.
|
||||
const size_t modelPixels = static_cast<size_t>( outH * outW );
|
||||
m_erodeBuf.resize( modelPixels );
|
||||
|
||||
// Extract person scores at model resolution from the raw array.
|
||||
// Apply a hard threshold to produce a binary mask. This is much
|
||||
// faster than a sigmoid (no expf) and eliminates the partial-blur
|
||||
// halo that was bleeding onto body/head edges.
|
||||
for( int64_t y = 0; y < outH; y++ )
|
||||
{
|
||||
for( int64_t x = 0; x < outW; x++ )
|
||||
{
|
||||
float personScore;
|
||||
if( numClasses == 1 )
|
||||
{
|
||||
personScore = outData[y * outW + x];
|
||||
}
|
||||
else
|
||||
{
|
||||
float bg = outData[0 * outH * outW + y * outW + x];
|
||||
float fg = outData[1 * outH * outW + y * outW + x];
|
||||
personScore = ( fg > bg ) ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
m_erodeBuf[static_cast<size_t>( y * outW + x )] = ( personScore > 0.5f ) ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// ── GPU path: model-resolution post-processing only ────────
|
||||
// When modelResOnly is true, apply feathering and temporal
|
||||
// smoothing at model resolution (e.g. 256×256 = 65K pixels)
|
||||
// and return early. The GPU's hardware bilinear sampler will
|
||||
// handle upscaling to frame resolution for free.
|
||||
if( modelResOnly )
|
||||
{
|
||||
// Small box blur on m_erodeBuf for edge feathering.
|
||||
// Radius 1 at 256×256 provides similar smoothing to
|
||||
// radius 3 at 960×540 after bilinear upscale.
|
||||
const int modelBlurRadius = 1;
|
||||
const int modelDiam = modelBlurRadius * 2 + 1;
|
||||
m_maskBlurBuf.resize( modelPixels );
|
||||
|
||||
// Horizontal pass.
|
||||
for( int64_t y = 0; y < outH; y++ )
|
||||
{
|
||||
const float* srcRow = m_erodeBuf.data() + y * outW;
|
||||
float* dstRow = m_maskBlurBuf.data() + y * outW;
|
||||
float sum = 0.0f;
|
||||
for( int i = -modelBlurRadius; i <= modelBlurRadius; i++ )
|
||||
sum += srcRow[(std::max)( static_cast<int64_t>(0), (std::min)( outW - 1, static_cast<int64_t>( i ) ) )];
|
||||
for( int64_t x = 0; x < outW; x++ )
|
||||
{
|
||||
dstRow[x] = sum / modelDiam;
|
||||
int64_t remX = (std::max)( static_cast<int64_t>(0), x - modelBlurRadius );
|
||||
int64_t addX = (std::min)( outW - 1, x + modelBlurRadius + 1 );
|
||||
sum += srcRow[addX] - srcRow[remX];
|
||||
}
|
||||
}
|
||||
|
||||
// Vertical pass.
|
||||
for( int64_t x = 0; x < outW; x++ )
|
||||
{
|
||||
float sum = 0.0f;
|
||||
for( int i = -modelBlurRadius; i <= modelBlurRadius; i++ )
|
||||
{
|
||||
int64_t iy = (std::max)( static_cast<int64_t>(0), (std::min)( outH - 1, static_cast<int64_t>( i ) ) );
|
||||
sum += m_maskBlurBuf[static_cast<size_t>( iy * outW + x )];
|
||||
}
|
||||
for( int64_t y = 0; y < outH; y++ )
|
||||
{
|
||||
m_erodeBuf[static_cast<size_t>( y * outW + x )] = sum / modelDiam;
|
||||
int64_t remY = (std::max)( static_cast<int64_t>(0), y - modelBlurRadius );
|
||||
int64_t addY = (std::min)( outH - 1, y + modelBlurRadius + 1 );
|
||||
sum += m_maskBlurBuf[static_cast<size_t>( addY * outW + x )] -
|
||||
m_maskBlurBuf[static_cast<size_t>( remY * outW + x )];
|
||||
}
|
||||
}
|
||||
|
||||
// Temporal smoothing at model resolution.
|
||||
if( m_prevModelMask.size() == modelPixels )
|
||||
{
|
||||
constexpr float alpha = 0.6f;
|
||||
constexpr float beta = 0.4f;
|
||||
for( size_t i = 0; i < modelPixels; i++ )
|
||||
m_erodeBuf[i] = alpha * m_erodeBuf[i] + beta * m_prevModelMask[i];
|
||||
}
|
||||
m_prevModelMask = m_erodeBuf;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Upscale processed mask to frame dimensions via bilinear interpolation
|
||||
// to produce smooth edges instead of staircase artifacts.
|
||||
const size_t maskPixels = static_cast<size_t>( width ) * height;
|
||||
m_mask.resize( maskPixels );
|
||||
for( uint32_t y = 0; y < height; y++ )
|
||||
{
|
||||
float srcYf = ( y + 0.5f ) * outH / static_cast<float>( height ) - 0.5f;
|
||||
srcYf = (std::max)( 0.0f, (std::min)( srcYf, static_cast<float>( outH - 1 ) ) );
|
||||
int64_t y0 = static_cast<int64_t>( srcYf );
|
||||
int64_t y1 = (std::min)( y0 + 1, outH - 1 );
|
||||
float fy = srcYf - y0;
|
||||
|
||||
for( uint32_t x = 0; x < width; x++ )
|
||||
{
|
||||
float srcXf = ( x + 0.5f ) * outW / static_cast<float>( width ) - 0.5f;
|
||||
srcXf = (std::max)( 0.0f, (std::min)( srcXf, static_cast<float>( outW - 1 ) ) );
|
||||
int64_t x0 = static_cast<int64_t>( srcXf );
|
||||
int64_t x1 = (std::min)( x0 + 1, outW - 1 );
|
||||
float fx = srcXf - x0;
|
||||
|
||||
float v00 = m_erodeBuf[static_cast<size_t>(y0 * outW + x0)];
|
||||
float v01 = m_erodeBuf[static_cast<size_t>(y0 * outW + x1)];
|
||||
float v10 = m_erodeBuf[static_cast<size_t>(y1 * outW + x0)];
|
||||
float v11 = m_erodeBuf[static_cast<size_t>(y1 * outW + x1)];
|
||||
|
||||
m_mask[static_cast<size_t>( y ) * width + x] =
|
||||
v00 * ( 1.0f - fx ) * ( 1.0f - fy ) +
|
||||
v01 * fx * ( 1.0f - fy ) +
|
||||
v10 * ( 1.0f - fx ) * fy +
|
||||
v11 * fx * fy;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply a small box blur to the upscaled mask to feather edges.
|
||||
const int maskBlurRadius = 3;
|
||||
const int maskDiam = maskBlurRadius * 2 + 1;
|
||||
m_maskBlurBuf.resize( maskPixels );
|
||||
|
||||
// Horizontal pass.
|
||||
for( uint32_t y = 0; y < height; y++ )
|
||||
{
|
||||
const float* srcRow = m_mask.data() + static_cast<size_t>( y ) * width;
|
||||
float* dstRow = m_maskBlurBuf.data() + static_cast<size_t>( y ) * width;
|
||||
float sum = 0.0f;
|
||||
|
||||
for( int i = -maskBlurRadius; i <= maskBlurRadius; i++ )
|
||||
sum += srcRow[(std::max)( 0, (std::min)( static_cast<int>( width ) - 1, i ) )];
|
||||
|
||||
for( uint32_t x = 0; x < width; x++ )
|
||||
{
|
||||
dstRow[x] = sum / maskDiam;
|
||||
int remX = (std::max)( 0, static_cast<int>( x ) - maskBlurRadius );
|
||||
int addX = (std::min)( static_cast<int>( width ) - 1, static_cast<int>( x ) + maskBlurRadius + 1 );
|
||||
sum += srcRow[addX] - srcRow[remX];
|
||||
}
|
||||
}
|
||||
|
||||
// Vertical pass.
|
||||
for( uint32_t x = 0; x < width; x++ )
|
||||
{
|
||||
float sum = 0.0f;
|
||||
|
||||
for( int i = -maskBlurRadius; i <= maskBlurRadius; i++ )
|
||||
{
|
||||
int iy = (std::max)( 0, (std::min)( static_cast<int>( height ) - 1, i ) );
|
||||
sum += m_maskBlurBuf[static_cast<size_t>( iy ) * width + x];
|
||||
}
|
||||
|
||||
for( uint32_t y = 0; y < height; y++ )
|
||||
{
|
||||
m_mask[static_cast<size_t>( y ) * width + x] = sum / maskDiam;
|
||||
int remY = (std::max)( 0, static_cast<int>( y ) - maskBlurRadius );
|
||||
int addY = (std::min)( static_cast<int>( height ) - 1, static_cast<int>( y ) + maskBlurRadius + 1 );
|
||||
sum += m_maskBlurBuf[static_cast<size_t>( addY ) * width + x] -
|
||||
m_maskBlurBuf[static_cast<size_t>( remY ) * width + x];
|
||||
}
|
||||
}
|
||||
|
||||
// Temporal smoothing: blend the current mask with the previous
|
||||
// frame's mask to stabilize edges and reduce flicker. A weight
|
||||
// of 0.6 current + 0.4 previous keeps edges responsive while
|
||||
// dampening the frame-to-frame jitter around fine details like
|
||||
// ears, hair, and fingers.
|
||||
{
|
||||
const size_t maskPixelsInner = static_cast<size_t>( width ) * height;
|
||||
if( m_prevMask.size() == maskPixelsInner )
|
||||
{
|
||||
constexpr float alpha = 0.6f; // current frame weight
|
||||
constexpr float beta = 0.4f; // previous frame weight
|
||||
for( size_t i = 0; i < maskPixelsInner; i++ )
|
||||
{
|
||||
m_mask[i] = alpha * m_mask[i] + beta * m_prevMask[i];
|
||||
}
|
||||
}
|
||||
m_prevMask = m_mask;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch( winrt::hresult_error const& ex )
|
||||
{
|
||||
OutputDebug( L"[BackgroundBlur] Evaluate failed: %s (0x%08X)\n", ex.message().c_str(), ex.code().value );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// HorizontalBoxBlur / VerticalBoxBlur
|
||||
//
|
||||
// Separable box blur passes used to build an approximate Gaussian.
|
||||
//----------------------------------------------------------------------------
|
||||
static void HorizontalBoxBlur(
|
||||
const uint8_t* src, uint8_t* dst, uint32_t width, uint32_t height, int radius )
|
||||
{
|
||||
const int diameter = radius * 2 + 1;
|
||||
for( uint32_t y = 0; y < height; y++ )
|
||||
{
|
||||
int rSum = 0, gSum = 0, bSum = 0;
|
||||
const uint8_t* row = src + static_cast<size_t>( y ) * width * 4;
|
||||
|
||||
// Initialize window with clamped left edge.
|
||||
for( int i = -radius; i <= radius; i++ )
|
||||
{
|
||||
int ix = (std::max)( 0, (std::min)( static_cast<int>( width ) - 1, i ) );
|
||||
const uint8_t* px = row + ix * 4;
|
||||
bSum += px[0];
|
||||
gSum += px[1];
|
||||
rSum += px[2];
|
||||
}
|
||||
|
||||
uint8_t* dstRow = dst + static_cast<size_t>( y ) * width * 4;
|
||||
for( uint32_t x = 0; x < width; x++ )
|
||||
{
|
||||
dstRow[x * 4 + 0] = static_cast<uint8_t>( bSum / diameter );
|
||||
dstRow[x * 4 + 1] = static_cast<uint8_t>( gSum / diameter );
|
||||
dstRow[x * 4 + 2] = static_cast<uint8_t>( rSum / diameter );
|
||||
dstRow[x * 4 + 3] = 0xFF;
|
||||
|
||||
// Slide window: add right, remove left.
|
||||
int removeX = (std::max)( 0, static_cast<int>( x ) - radius );
|
||||
int addX = (std::min)( static_cast<int>( width ) - 1, static_cast<int>( x ) + radius + 1 );
|
||||
const uint8_t* remPx = row + removeX * 4;
|
||||
const uint8_t* addPx = row + addX * 4;
|
||||
bSum += addPx[0] - remPx[0];
|
||||
gSum += addPx[1] - remPx[1];
|
||||
rSum += addPx[2] - remPx[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void VerticalBoxBlur(
|
||||
const uint8_t* src, uint8_t* dst, uint32_t width, uint32_t height, int radius )
|
||||
{
|
||||
const int diameter = radius * 2 + 1;
|
||||
for( uint32_t x = 0; x < width; x++ )
|
||||
{
|
||||
int rSum = 0, gSum = 0, bSum = 0;
|
||||
|
||||
// Initialize window with clamped top edge.
|
||||
for( int i = -radius; i <= radius; i++ )
|
||||
{
|
||||
int iy = (std::max)( 0, (std::min)( static_cast<int>( height ) - 1, i ) );
|
||||
const uint8_t* px = src + ( static_cast<size_t>( iy ) * width + x ) * 4;
|
||||
bSum += px[0];
|
||||
gSum += px[1];
|
||||
rSum += px[2];
|
||||
}
|
||||
|
||||
for( uint32_t y = 0; y < height; y++ )
|
||||
{
|
||||
uint8_t* dstPx = dst + ( static_cast<size_t>( y ) * width + x ) * 4;
|
||||
dstPx[0] = static_cast<uint8_t>( bSum / diameter );
|
||||
dstPx[1] = static_cast<uint8_t>( gSum / diameter );
|
||||
dstPx[2] = static_cast<uint8_t>( rSum / diameter );
|
||||
dstPx[3] = 0xFF;
|
||||
|
||||
int removeY = (std::max)( 0, static_cast<int>( y ) - radius );
|
||||
int addY = (std::min)( static_cast<int>( height ) - 1, static_cast<int>( y ) + radius + 1 );
|
||||
const uint8_t* remPx = src + ( static_cast<size_t>( removeY ) * width + x ) * 4;
|
||||
const uint8_t* addPx = src + ( static_cast<size_t>( addY ) * width + x ) * 4;
|
||||
bSum += addPx[0] - remPx[0];
|
||||
gSum += addPx[1] - remPx[1];
|
||||
rSum += addPx[2] - remPx[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// BackgroundBlur::ApplyBlurWithMask
|
||||
//
|
||||
// Downscales the frame to a small working size, blurs there, then
|
||||
// performs a single full-resolution pass that blends the original
|
||||
// pixels with the upscaled blurred pixels according to the mask.
|
||||
//----------------------------------------------------------------------------
|
||||
void BackgroundBlur::ApplyBlurWithMask( uint8_t* bgraPixels, uint32_t width, uint32_t height, int blurRadius )
|
||||
{
|
||||
const size_t frameBytes = static_cast<size_t>( width ) * height * 4;
|
||||
m_blurredFrame.resize( frameBytes );
|
||||
m_tempFrame.resize( frameBytes );
|
||||
|
||||
// The input is already capped at 960×540 by WebcamCapture, so blur
|
||||
// directly — no need for a secondary downscale.
|
||||
int effectiveRadius = (std::max)( 3, blurRadius );
|
||||
|
||||
// 2 iterations of box blur → approximate Gaussian.
|
||||
HorizontalBoxBlur( bgraPixels, m_blurredFrame.data(), width, height, effectiveRadius );
|
||||
VerticalBoxBlur( m_blurredFrame.data(), m_tempFrame.data(), width, height, effectiveRadius );
|
||||
HorizontalBoxBlur( m_tempFrame.data(), m_blurredFrame.data(), width, height, effectiveRadius );
|
||||
VerticalBoxBlur( m_blurredFrame.data(), m_tempFrame.data(), width, height, effectiveRadius );
|
||||
|
||||
// Blend pass with alpha support for smooth mask edges.
|
||||
const uint8_t* blurData = m_tempFrame.data();
|
||||
for( uint32_t y = 0; y < height; y++ )
|
||||
{
|
||||
uint8_t* dstRow = bgraPixels + static_cast<size_t>( y ) * width * 4;
|
||||
const uint8_t* blurRow = blurData + static_cast<size_t>( y ) * width * 4;
|
||||
const float* maskRow = m_mask.data() + static_cast<size_t>( y ) * width;
|
||||
|
||||
for( uint32_t x = 0; x < width; x++ )
|
||||
{
|
||||
float maskVal = maskRow[x];
|
||||
|
||||
// Fast path: fully person → keep original pixel untouched.
|
||||
if( maskVal >= 1.0f )
|
||||
continue;
|
||||
|
||||
uint8_t* dp = dstRow + x * 4;
|
||||
const uint8_t* bp = blurRow + x * 4;
|
||||
|
||||
// Fast path: fully background → copy blurred pixel.
|
||||
if( maskVal <= 0.0f )
|
||||
{
|
||||
*reinterpret_cast<uint32_t*>( dp ) = *reinterpret_cast<const uint32_t*>( bp );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Edge pixel → alpha blend original and blurred.
|
||||
float inv = 1.0f - maskVal;
|
||||
dp[0] = static_cast<uint8_t>( dp[0] * maskVal + bp[0] * inv + 0.5f );
|
||||
dp[1] = static_cast<uint8_t>( dp[1] * maskVal + bp[1] * inv + 0.5f );
|
||||
dp[2] = static_cast<uint8_t>( dp[2] * maskVal + bp[2] * inv + 0.5f );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// BackgroundBlur::SetBackgroundImage
|
||||
//
|
||||
// Loads an image file via WIC and stores it as a BGRA pixel buffer.
|
||||
//----------------------------------------------------------------------------
|
||||
bool BackgroundBlur::SetBackgroundImage( const wchar_t* imagePath )
|
||||
{
|
||||
m_bgImage.clear();
|
||||
m_bgImageWidth = 0;
|
||||
m_bgImageHeight = 0;
|
||||
m_scaledBgImage.clear();
|
||||
m_scaledBgW = 0;
|
||||
m_scaledBgH = 0;
|
||||
|
||||
if( !imagePath || !*imagePath )
|
||||
return false;
|
||||
|
||||
auto factory = wil::CoCreateInstance<IWICImagingFactory>( CLSID_WICImagingFactory );
|
||||
if( !factory )
|
||||
return false;
|
||||
|
||||
wil::com_ptr<IWICBitmapDecoder> decoder;
|
||||
HRESULT hr = factory->CreateDecoderFromFilename(
|
||||
imagePath, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder );
|
||||
if( FAILED( hr ) )
|
||||
{
|
||||
OutputDebug( L"[BackgroundBlur] Failed to decode image: %s (hr=0x%08X)\n", imagePath, hr );
|
||||
return false;
|
||||
}
|
||||
|
||||
wil::com_ptr<IWICBitmapFrameDecode> frame;
|
||||
hr = decoder->GetFrame( 0, &frame );
|
||||
if( FAILED( hr ) )
|
||||
return false;
|
||||
|
||||
// Convert to BGRA 32bpp.
|
||||
wil::com_ptr<IWICFormatConverter> converter;
|
||||
hr = factory->CreateFormatConverter( &converter );
|
||||
if( FAILED( hr ) )
|
||||
return false;
|
||||
|
||||
hr = converter->Initialize(
|
||||
frame.get(), GUID_WICPixelFormat32bppBGRA,
|
||||
WICBitmapDitherTypeNone, nullptr, 0.0, WICBitmapPaletteTypeCustom );
|
||||
if( FAILED( hr ) )
|
||||
return false;
|
||||
|
||||
UINT w = 0, h = 0;
|
||||
converter->GetSize( &w, &h );
|
||||
if( w == 0 || h == 0 )
|
||||
return false;
|
||||
|
||||
m_bgImage.resize( static_cast<size_t>( w ) * h * 4 );
|
||||
hr = converter->CopyPixels( nullptr, w * 4, static_cast<UINT>( m_bgImage.size() ), m_bgImage.data() );
|
||||
if( FAILED( hr ) )
|
||||
{
|
||||
m_bgImage.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_bgImageWidth = w;
|
||||
m_bgImageHeight = h;
|
||||
|
||||
OutputDebug( L"[BackgroundBlur] Background image loaded: %ux%u from %s\n", w, h, imagePath );
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// BackgroundBlur::EnsureScaledBgImage
|
||||
//
|
||||
// Scales the loaded background image to the specified dimensions using
|
||||
// nearest-neighbor. The result is cached and only recomputed when the
|
||||
// target dimensions change. The image is center-cropped to preserve
|
||||
// aspect ratio (like "cover" scaling).
|
||||
//----------------------------------------------------------------------------
|
||||
void BackgroundBlur::EnsureScaledBgImage( uint32_t width, uint32_t height )
|
||||
{
|
||||
if( m_scaledBgW == width && m_scaledBgH == height && !m_scaledBgImage.empty() )
|
||||
return;
|
||||
|
||||
m_scaledBgImage.resize( static_cast<size_t>( width ) * height * 4 );
|
||||
m_scaledBgW = width;
|
||||
m_scaledBgH = height;
|
||||
|
||||
// Compute center-crop of the source image to match the target aspect ratio.
|
||||
double targetAspect = static_cast<double>( width ) / height;
|
||||
double srcAspect = static_cast<double>( m_bgImageWidth ) / m_bgImageHeight;
|
||||
|
||||
uint32_t cropW, cropH, cropX, cropY;
|
||||
if( srcAspect > targetAspect )
|
||||
{
|
||||
// Source is wider — crop horizontally.
|
||||
cropH = m_bgImageHeight;
|
||||
cropW = static_cast<uint32_t>( m_bgImageHeight * targetAspect + 0.5 );
|
||||
cropX = ( m_bgImageWidth - cropW ) / 2;
|
||||
cropY = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Source is taller — crop vertically.
|
||||
cropW = m_bgImageWidth;
|
||||
cropH = static_cast<uint32_t>( m_bgImageWidth / targetAspect + 0.5 );
|
||||
cropX = 0;
|
||||
cropY = ( m_bgImageHeight - cropH ) / 2;
|
||||
}
|
||||
|
||||
for( uint32_t y = 0; y < height; y++ )
|
||||
{
|
||||
uint32_t srcY = cropY + y * cropH / height;
|
||||
for( uint32_t x = 0; x < width; x++ )
|
||||
{
|
||||
uint32_t srcX = cropX + x * cropW / width;
|
||||
size_t srcIdx = ( static_cast<size_t>( srcY ) * m_bgImageWidth + srcX ) * 4;
|
||||
size_t dstIdx = ( static_cast<size_t>( y ) * width + x ) * 4;
|
||||
m_scaledBgImage[dstIdx + 0] = m_bgImage[srcIdx + 0];
|
||||
m_scaledBgImage[dstIdx + 1] = m_bgImage[srcIdx + 1];
|
||||
m_scaledBgImage[dstIdx + 2] = m_bgImage[srcIdx + 2];
|
||||
m_scaledBgImage[dstIdx + 3] = 0xFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// BackgroundBlur::ApplyImageWithMask
|
||||
//
|
||||
// Replaces background pixels with the loaded background image using the
|
||||
// segmentation mask. Person pixels are preserved, background pixels come
|
||||
// from the scaled image.
|
||||
//----------------------------------------------------------------------------
|
||||
void BackgroundBlur::ApplyImageWithMask( uint8_t* bgraPixels, uint32_t width, uint32_t height )
|
||||
{
|
||||
EnsureScaledBgImage( width, height );
|
||||
|
||||
const uint8_t* bgData = m_scaledBgImage.data();
|
||||
|
||||
for( uint32_t y = 0; y < height; y++ )
|
||||
{
|
||||
uint8_t* dstRow = bgraPixels + static_cast<size_t>( y ) * width * 4;
|
||||
const uint8_t* bgRow = bgData + static_cast<size_t>( y ) * width * 4;
|
||||
const float* maskRow = m_mask.data() + static_cast<size_t>( y ) * width;
|
||||
|
||||
for( uint32_t x = 0; x < width; x++ )
|
||||
{
|
||||
float maskVal = maskRow[x];
|
||||
|
||||
// Fully person → keep original pixel.
|
||||
if( maskVal >= 1.0f )
|
||||
continue;
|
||||
|
||||
uint8_t* dp = dstRow + x * 4;
|
||||
const uint8_t* bp = bgRow + x * 4;
|
||||
|
||||
// Fully background → copy background image pixel.
|
||||
if( maskVal <= 0.0f )
|
||||
{
|
||||
*reinterpret_cast<uint32_t*>( dp ) = *reinterpret_cast<const uint32_t*>( bp );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Edge pixel → alpha blend person and background image.
|
||||
float inv = 1.0f - maskVal;
|
||||
dp[0] = static_cast<uint8_t>( dp[0] * maskVal + bp[0] * inv + 0.5f );
|
||||
dp[1] = static_cast<uint8_t>( dp[1] * maskVal + bp[1] * inv + 0.5f );
|
||||
dp[2] = static_cast<uint8_t>( dp[2] * maskVal + bp[2] * inv + 0.5f );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// BackgroundBlur::ShouldRunInference
|
||||
//
|
||||
// Decides whether segmentation inference should run this frame.
|
||||
// Uses a combination of periodic fallback and motion detection:
|
||||
// motion is estimated by comparing luminance at a sparse grid of
|
||||
// sample points with the previous frame. When the scene changes
|
||||
// quickly (fast head movement), inference runs every frame.
|
||||
//----------------------------------------------------------------------------
|
||||
bool BackgroundBlur::ShouldRunInference( const uint8_t* bgraPixels, uint32_t width, uint32_t height )
|
||||
{
|
||||
// Always run if no cached mask or dimensions changed.
|
||||
if( !m_hasCachedMask || m_lastMaskWidth != width || m_lastMaskHeight != height )
|
||||
return true;
|
||||
|
||||
// Periodic fallback: run at least every N frames.
|
||||
const uint32_t pixels = width * height;
|
||||
const int inferenceInterval = ( pixels > 500000 ) ? 6 : 3;
|
||||
if( ( m_frameCounter % inferenceInterval ) == 0 )
|
||||
return true;
|
||||
|
||||
// Motion detection: sample luminance at a sparse grid and compare
|
||||
// with the previous frame.
|
||||
constexpr int gridSize = MOTION_GRID_SIZE;
|
||||
constexpr int numSamples = gridSize * gridSize;
|
||||
float curSamples[numSamples];
|
||||
|
||||
for( int gy = 0; gy < gridSize; gy++ )
|
||||
{
|
||||
uint32_t sy = ( gy * 2 + 1 ) * height / ( gridSize * 2 );
|
||||
for( int gx = 0; gx < gridSize; gx++ )
|
||||
{
|
||||
uint32_t sx = ( gx * 2 + 1 ) * width / ( gridSize * 2 );
|
||||
const uint8_t* px = bgraPixels + ( static_cast<size_t>( sy ) * width + sx ) * 4;
|
||||
curSamples[gy * gridSize + gx] = 0.299f * px[2] + 0.587f * px[1] + 0.114f * px[0];
|
||||
}
|
||||
}
|
||||
|
||||
float motionScore = 0.0f;
|
||||
if( m_hasPrevSamples )
|
||||
{
|
||||
for( int i = 0; i < numSamples; i++ )
|
||||
{
|
||||
float diff = curSamples[i] - m_prevSamples[i];
|
||||
motionScore += diff > 0.0f ? diff : -diff;
|
||||
}
|
||||
motionScore /= numSamples;
|
||||
}
|
||||
|
||||
memcpy( m_prevSamples, curSamples, sizeof( curSamples ) );
|
||||
m_hasPrevSamples = true;
|
||||
|
||||
// Average per-sample luminance change > 5/255 indicates significant motion.
|
||||
return motionScore > 5.0f;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// BackgroundBlur::ApplyImageReplacement
|
||||
//
|
||||
// Main entry point for background image replacement mode.
|
||||
//----------------------------------------------------------------------------
|
||||
bool BackgroundBlur::ApplyImageReplacement( uint8_t* bgraPixels, uint32_t width, uint32_t height )
|
||||
{
|
||||
if( !m_session || !bgraPixels || width == 0 || height == 0 )
|
||||
return false;
|
||||
|
||||
if( m_bgImage.empty() )
|
||||
return false;
|
||||
|
||||
if( ShouldRunInference( bgraPixels, width, height ) )
|
||||
{
|
||||
if( !RunSegmentation( bgraPixels, width, height ) )
|
||||
return false;
|
||||
m_lastMaskWidth = width;
|
||||
m_lastMaskHeight = height;
|
||||
m_hasCachedMask = true;
|
||||
}
|
||||
m_frameCounter++;
|
||||
|
||||
ApplyImageWithMask( bgraPixels, width, height );
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// BackgroundBlur::Apply
|
||||
//
|
||||
// Main entry point: runs segmentation and applies blur to the background.
|
||||
//----------------------------------------------------------------------------
|
||||
bool BackgroundBlur::Apply( uint8_t* bgraPixels, uint32_t width, uint32_t height, int blurRadius )
|
||||
{
|
||||
if( !m_session || !bgraPixels || width == 0 || height == 0 )
|
||||
return false;
|
||||
|
||||
if( ShouldRunInference( bgraPixels, width, height ) )
|
||||
{
|
||||
if( !RunSegmentation( bgraPixels, width, height ) )
|
||||
return false;
|
||||
m_lastMaskWidth = width;
|
||||
m_lastMaskHeight = height;
|
||||
m_hasCachedMask = true;
|
||||
}
|
||||
m_frameCounter++;
|
||||
|
||||
ApplyBlurWithMask( bgraPixels, width, height, blurRadius );
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// BackgroundBlur::RunSegmentationOnly
|
||||
//
|
||||
// Runs the segmentation model and produces the mask, but does NOT blur
|
||||
// or modify the pixel buffer. Used when the GPU compute shader will
|
||||
// perform the box blur instead of the CPU.
|
||||
//----------------------------------------------------------------------------
|
||||
bool BackgroundBlur::RunSegmentationOnly( const uint8_t* bgraPixels, uint32_t width, uint32_t height )
|
||||
{
|
||||
if( !m_session || !bgraPixels || width == 0 || height == 0 )
|
||||
return false;
|
||||
|
||||
if( ShouldRunInference( bgraPixels, width, height ) )
|
||||
{
|
||||
// Model-resolution only: skip CPU upscale+feather at frame
|
||||
// resolution — the GPU bilinear sampler handles that.
|
||||
if( !RunSegmentation( bgraPixels, width, height, /*modelResOnly=*/ true ) )
|
||||
return false;
|
||||
m_lastMaskWidth = width;
|
||||
m_lastMaskHeight = height;
|
||||
m_hasCachedMask = true;
|
||||
}
|
||||
m_frameCounter++;
|
||||
|
||||
return m_hasCachedMask;
|
||||
}
|
||||
160
src/modules/ZoomIt/ZoomIt/BackgroundBlur.h
Normal file
160
src/modules/ZoomIt/ZoomIt/BackgroundBlur.h
Normal file
@@ -0,0 +1,160 @@
|
||||
//==============================================================================
|
||||
//
|
||||
// BackgroundBlur.h
|
||||
//
|
||||
// Performs person segmentation using Windows ML (Windows.AI.MachineLearning)
|
||||
// and applies either a Gaussian blur or a custom background image to the
|
||||
// background of a BGRA webcam frame. The segmentation model runs on CPU
|
||||
// via the Windows ML default device, keeping the GPU free for recording.
|
||||
//
|
||||
// Copyright (C) Mark Russinovich
|
||||
// Sysinternals - www.sysinternals.com
|
||||
//
|
||||
//==============================================================================
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <winrt/Windows.AI.MachineLearning.h>
|
||||
|
||||
// Background processing mode for the webcam overlay.
|
||||
enum class WebcamBackgroundMode : uint32_t
|
||||
{
|
||||
None = 0, // No background processing
|
||||
Blur = 1, // Gaussian blur on the background
|
||||
Image = 2, // Replace background with a user-chosen image
|
||||
};
|
||||
|
||||
class BackgroundBlur
|
||||
{
|
||||
public:
|
||||
BackgroundBlur() = default;
|
||||
~BackgroundBlur() = default;
|
||||
|
||||
// Initialize the ONNX model. modelPath must point to a valid .onnx
|
||||
// segmentation model file. Returns true on success.
|
||||
bool Initialize( const wchar_t* modelPath );
|
||||
|
||||
// Load a background replacement image from the given file path.
|
||||
// The image is decoded via WIC and stored as a BGRA buffer.
|
||||
// Returns true on success.
|
||||
bool SetBackgroundImage( const wchar_t* imagePath );
|
||||
|
||||
// Returns true if a background image has been loaded.
|
||||
bool HasBackgroundImage() const { return !m_bgImage.empty(); }
|
||||
|
||||
// Apply background blur to a BGRA pixel buffer in-place.
|
||||
// width/height are the frame dimensions. blurRadius controls
|
||||
// the strength of the Gaussian blur (in pixels).
|
||||
// Returns true if segmentation + blur was applied successfully.
|
||||
bool Apply( uint8_t* bgraPixels, uint32_t width, uint32_t height, int blurRadius = 21 );
|
||||
|
||||
// Apply background image replacement to a BGRA pixel buffer in-place.
|
||||
// Uses the previously loaded background image (via SetBackgroundImage).
|
||||
// Returns true if segmentation + image replacement was applied.
|
||||
bool ApplyImageReplacement( uint8_t* bgraPixels, uint32_t width, uint32_t height );
|
||||
|
||||
// Returns true if the model has been loaded successfully.
|
||||
bool IsInitialized() const { return m_session != nullptr; }
|
||||
|
||||
// Access the segmentation mask after Apply()/ApplyImageReplacement().
|
||||
// The mask has one float [0..1] per pixel at the processing resolution
|
||||
// (1.0 = person / foreground, 0.0 = background).
|
||||
const std::vector<float>& GetMask() const { return m_mask; }
|
||||
uint32_t GetMaskWidth() const { return m_lastMaskWidth; }
|
||||
uint32_t GetMaskHeight() const { return m_lastMaskHeight; }
|
||||
bool HasCachedMask() const { return m_hasCachedMask; }
|
||||
|
||||
// Run segmentation only (no CPU blur or mask blend). Use this when
|
||||
// the blur will be performed on the GPU via a compute shader.
|
||||
// Populates the mask (GetMask) but does NOT touch bgraPixels.
|
||||
bool RunSegmentationOnly( const uint8_t* bgraPixels, uint32_t width, uint32_t height );
|
||||
|
||||
// Access the fully-blurred frame after Apply().
|
||||
// Contains all pixels blurred (before mask-based compositing).
|
||||
// Only valid after Apply() — NOT after ApplyImageReplacement().
|
||||
const std::vector<uint8_t>& GetBlurredFrame() const { return m_tempFrame; }
|
||||
|
||||
// Access the model-resolution mask before upscaling (e.g. 256×256).
|
||||
// Useful when the GPU handles upscaling via hardware bilinear filtering.
|
||||
const std::vector<float>& GetModelMask() const { return m_erodeBuf; }
|
||||
int64_t GetModelMaskWidth() const { return m_modelOutputWidth; }
|
||||
int64_t GetModelMaskHeight() const { return m_modelOutputHeight; }
|
||||
|
||||
private:
|
||||
// Run the segmentation model and produce a float mask [0..1] per pixel.
|
||||
// When modelResOnly is true, stops after model-resolution post-processing
|
||||
// (feathering + temporal smoothing at 256×256) and skips the CPU upscale
|
||||
// to frame resolution — the GPU bilinear sampler handles that instead.
|
||||
bool RunSegmentation( const uint8_t* bgraPixels, uint32_t width, uint32_t height,
|
||||
bool modelResOnly = false );
|
||||
|
||||
// Apply box blur (iterated for Gaussian approximation) to bgraPixels
|
||||
// only where the mask indicates background.
|
||||
void ApplyBlurWithMask( uint8_t* bgraPixels, uint32_t width, uint32_t height, int blurRadius );
|
||||
|
||||
// Replace background pixels with the loaded background image.
|
||||
void ApplyImageWithMask( uint8_t* bgraPixels, uint32_t width, uint32_t height );
|
||||
|
||||
// Scale the loaded background image to the given dimensions (cached).
|
||||
void EnsureScaledBgImage( uint32_t width, uint32_t height );
|
||||
|
||||
// Decide whether inference is needed this frame (periodic + motion-adaptive).
|
||||
bool ShouldRunInference( const uint8_t* bgraPixels, uint32_t width, uint32_t height );
|
||||
|
||||
// Windows ML objects.
|
||||
winrt::Windows::AI::MachineLearning::LearningModel m_model{ nullptr };
|
||||
winrt::Windows::AI::MachineLearning::LearningModelSession m_session{ nullptr };
|
||||
winrt::Windows::AI::MachineLearning::LearningModelBinding m_binding{ nullptr };
|
||||
winrt::hstring m_inputName;
|
||||
winrt::hstring m_outputName;
|
||||
|
||||
// Model metadata (detected from the loaded model).
|
||||
int64_t m_modelInputWidth = 256;
|
||||
int64_t m_modelInputHeight = 256;
|
||||
int64_t m_modelInputChannels = 3;
|
||||
bool m_inputIsNchw = true; // true = [1,C,H,W], false = [1,H,W,C]
|
||||
bool m_usingGpu = false; // true if DirectML session is active
|
||||
|
||||
// Actual model output dimensions (may differ from input dimensions).
|
||||
int64_t m_modelOutputWidth = 256;
|
||||
int64_t m_modelOutputHeight = 256;
|
||||
|
||||
// Reusable buffers to avoid per-frame allocations.
|
||||
std::vector<float> m_inputTensor; // RGB float [1,3,H,W] or [1,H,W,3]
|
||||
std::vector<float> m_outputBuf; // Raw copy of output tensor data
|
||||
std::vector<float> m_mask; // Segmentation mask [width*height]
|
||||
std::vector<float> m_erodeBuf; // Model-resolution mask buffer
|
||||
std::vector<float> m_maskBlurBuf; // Temp buffer for mask edge smoothing
|
||||
std::vector<uint8_t> m_blurredFrame; // Temporary blurred copy
|
||||
std::vector<uint8_t> m_tempFrame; // Second temp buffer for blur passes
|
||||
|
||||
// Background image (original resolution, BGRA).
|
||||
std::vector<uint8_t> m_bgImage;
|
||||
uint32_t m_bgImageWidth = 0;
|
||||
uint32_t m_bgImageHeight = 0;
|
||||
|
||||
// Scaled background image (cached at overlay dimensions).
|
||||
std::vector<uint8_t> m_scaledBgImage;
|
||||
uint32_t m_scaledBgW = 0;
|
||||
uint32_t m_scaledBgH = 0;
|
||||
|
||||
// Frame-skipping: reuse the segmentation mask for N frames.
|
||||
int m_frameCounter = 0;
|
||||
uint32_t m_lastMaskWidth = 0;
|
||||
uint32_t m_lastMaskHeight = 0;
|
||||
bool m_hasCachedMask = false;
|
||||
|
||||
// Motion detection: luminance samples from the previous frame.
|
||||
static constexpr int MOTION_GRID_SIZE = 8; // 8×8 = 64 sample points
|
||||
float m_prevSamples[MOTION_GRID_SIZE * MOTION_GRID_SIZE] = {};
|
||||
bool m_hasPrevSamples = false;
|
||||
|
||||
// Temporal smoothing: previous frame's mask blended with current
|
||||
// to stabilize edges and reduce flicker.
|
||||
std::vector<float> m_prevMask;
|
||||
|
||||
// Model-resolution previous mask for GPU path temporal smoothing.
|
||||
std::vector<float> m_prevModelMask;
|
||||
};
|
||||
606
src/modules/ZoomIt/ZoomIt/BoxBlurCS.h
Normal file
606
src/modules/ZoomIt/ZoomIt/BoxBlurCS.h
Normal file
@@ -0,0 +1,606 @@
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
|
||||
//
|
||||
//
|
||||
// Buffer Definitions:
|
||||
//
|
||||
// cbuffer BlurConstants
|
||||
// {
|
||||
//
|
||||
// uint Direction; // Offset: 0 Size: 4
|
||||
// int Radius; // Offset: 4 Size: 4
|
||||
// uint Width; // Offset: 8 Size: 4
|
||||
// uint Height; // Offset: 12 Size: 4
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// Resource Bindings:
|
||||
//
|
||||
// Name Type Format Dim HLSL Bind Count
|
||||
// ------------------------------ ---------- ------- ----------- -------------- ------
|
||||
// InputTex texture float4 2d t0 1
|
||||
// OutputTex UAV float4 2d u0 1
|
||||
// BlurConstants cbuffer NA NA cb0 1
|
||||
//
|
||||
//
|
||||
//
|
||||
// Input signature:
|
||||
//
|
||||
// Name Index Mask Register SysValue Format Used
|
||||
// -------------------- ----- ------ -------- -------- ------- ------
|
||||
// no Input
|
||||
//
|
||||
// Output signature:
|
||||
//
|
||||
// Name Index Mask Register SysValue Format Used
|
||||
// -------------------- ----- ------ -------- -------- ------- ------
|
||||
// no Output
|
||||
cs_5_0
|
||||
dcl_globalFlags refactoringAllowed
|
||||
dcl_constantbuffer CB0[1], immediateIndexed
|
||||
dcl_resource_texture2d (float,float,float,float) t0
|
||||
dcl_uav_typed_texture2d (float,float,float,float) u0
|
||||
dcl_input vThreadGroupID.xy
|
||||
dcl_input vThreadIDInGroup.x
|
||||
dcl_temps 4
|
||||
dcl_tgsm_structured g0, 16, 320
|
||||
dcl_thread_group 256, 1, 1
|
||||
imin r0.x, cb0[0].y, l(32)
|
||||
ishl r0.y, r0.x, l(1)
|
||||
iadd r0.z, r0.y, l(256)
|
||||
if_z cb0[0].x
|
||||
uge r0.w, vThreadGroupID.y, cb0[0].w
|
||||
if_nz r0.w
|
||||
ret
|
||||
endif
|
||||
ishl r0.w, vThreadGroupID.x, l(8)
|
||||
iadd r1.x, cb0[0].z, l(-1)
|
||||
mov r2.y, vThreadGroupID.y
|
||||
mov r2.zw, l(0,0,0,0)
|
||||
mov r1.y, vThreadIDInGroup.x
|
||||
loop
|
||||
ige r1.z, r1.y, r0.z
|
||||
breakc_nz r1.z
|
||||
iadd r1.z, r0.w, r1.y
|
||||
iadd r1.z, -r0.x, r1.z
|
||||
imax r1.z, r1.z, l(0)
|
||||
imin r2.x, r1.x, r1.z
|
||||
ld_indexable(texture2d)(float,float,float,float) r3.xyzw, r2.xyzw, t0.xyzw
|
||||
store_structured g0.xyzw, r1.y, l(0), r3.xyzw
|
||||
iadd r1.y, r1.y, l(256)
|
||||
endloop
|
||||
sync_g_t
|
||||
imad r1.x, vThreadGroupID.x, l(256), vThreadIDInGroup.x
|
||||
uge r0.w, r1.x, cb0[0].z
|
||||
if_nz r0.w
|
||||
ret
|
||||
endif
|
||||
mov r2.xyzw, l(0,0,0,0)
|
||||
mov r0.w, l(0)
|
||||
loop
|
||||
ilt r3.x, r0.y, r0.w
|
||||
breakc_nz r3.x
|
||||
iadd r3.x, r0.w, vThreadIDInGroup.x
|
||||
ld_structured r3.xyzw, r3.x, l(0), g0.xyzw
|
||||
add r2.xyzw, r2.xyzw, r3.xyzw
|
||||
iadd r0.w, r0.w, l(1)
|
||||
endloop
|
||||
bfi r0.w, l(31), l(1), r0.x, l(1)
|
||||
itof r0.w, r0.w
|
||||
div r2.xyzw, r2.xyzw, r0.wwww
|
||||
mov r1.yzw, vThreadGroupID.yyyy
|
||||
store_uav_typed u0.xyzw, r1.xyzw, r2.xyzw
|
||||
else
|
||||
uge r0.w, vThreadGroupID.y, cb0[0].z
|
||||
if_nz r0.w
|
||||
ret
|
||||
endif
|
||||
ishl r0.w, vThreadGroupID.x, l(8)
|
||||
iadd r1.x, cb0[0].w, l(-1)
|
||||
mov r2.x, vThreadGroupID.y
|
||||
mov r2.zw, l(0,0,0,0)
|
||||
mov r1.y, vThreadIDInGroup.x
|
||||
loop
|
||||
ige r1.z, r1.y, r0.z
|
||||
breakc_nz r1.z
|
||||
iadd r1.z, r0.w, r1.y
|
||||
iadd r1.z, -r0.x, r1.z
|
||||
imax r1.z, r1.z, l(0)
|
||||
imin r2.y, r1.x, r1.z
|
||||
ld_indexable(texture2d)(float,float,float,float) r3.xyzw, r2.xyzw, t0.xyzw
|
||||
store_structured g0.xyzw, r1.y, l(0), r3.xyzw
|
||||
iadd r1.y, r1.y, l(256)
|
||||
endloop
|
||||
sync_g_t
|
||||
imad r1.yzw, vThreadGroupID.xxxx, l(0, 256, 256, 256), vThreadIDInGroup.xxxx
|
||||
uge r0.z, r1.w, cb0[0].w
|
||||
if_nz r0.z
|
||||
ret
|
||||
endif
|
||||
mov r2.xyzw, l(0,0,0,0)
|
||||
mov r0.z, l(0)
|
||||
loop
|
||||
ilt r0.w, r0.y, r0.z
|
||||
breakc_nz r0.w
|
||||
iadd r0.w, r0.z, vThreadIDInGroup.x
|
||||
ld_structured r3.xyzw, r0.w, l(0), g0.xyzw
|
||||
add r2.xyzw, r2.xyzw, r3.xyzw
|
||||
iadd r0.z, r0.z, l(1)
|
||||
endloop
|
||||
bfi r0.x, l(31), l(1), r0.x, l(1)
|
||||
itof r0.x, r0.x
|
||||
div r0.xyzw, r2.xyzw, r0.xxxx
|
||||
mov r1.x, vThreadGroupID.y
|
||||
store_uav_typed u0.xyzw, r1.xyzw, r0.xyzw
|
||||
endif
|
||||
ret
|
||||
// Approximately 89 instruction slots used
|
||||
#endif
|
||||
|
||||
const BYTE g_BoxBlurCS[] =
|
||||
{
|
||||
68, 88, 66, 67, 109, 156,
|
||||
172, 79, 78, 198, 69, 61,
|
||||
87, 5, 27, 232, 85, 229,
|
||||
69, 181, 1, 0, 0, 0,
|
||||
212, 10, 0, 0, 5, 0,
|
||||
0, 0, 52, 0, 0, 0,
|
||||
80, 2, 0, 0, 96, 2,
|
||||
0, 0, 112, 2, 0, 0,
|
||||
56, 10, 0, 0, 82, 68,
|
||||
69, 70, 20, 2, 0, 0,
|
||||
1, 0, 0, 0, 192, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
60, 0, 0, 0, 0, 5,
|
||||
83, 67, 0, 1, 0, 0,
|
||||
233, 1, 0, 0, 82, 68,
|
||||
49, 49, 60, 0, 0, 0,
|
||||
24, 0, 0, 0, 32, 0,
|
||||
0, 0, 40, 0, 0, 0,
|
||||
36, 0, 0, 0, 12, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
156, 0, 0, 0, 2, 0,
|
||||
0, 0, 5, 0, 0, 0,
|
||||
4, 0, 0, 0, 255, 255,
|
||||
255, 255, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 13, 0,
|
||||
0, 0, 165, 0, 0, 0,
|
||||
4, 0, 0, 0, 5, 0,
|
||||
0, 0, 4, 0, 0, 0,
|
||||
255, 255, 255, 255, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
13, 0, 0, 0, 175, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
73, 110, 112, 117, 116, 84,
|
||||
101, 120, 0, 79, 117, 116,
|
||||
112, 117, 116, 84, 101, 120,
|
||||
0, 66, 108, 117, 114, 67,
|
||||
111, 110, 115, 116, 97, 110,
|
||||
116, 115, 0, 171, 171, 171,
|
||||
175, 0, 0, 0, 4, 0,
|
||||
0, 0, 216, 0, 0, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
120, 1, 0, 0, 0, 0,
|
||||
0, 0, 4, 0, 0, 0,
|
||||
2, 0, 0, 0, 136, 1,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
255, 255, 255, 255, 0, 0,
|
||||
0, 0, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 172, 1,
|
||||
0, 0, 4, 0, 0, 0,
|
||||
4, 0, 0, 0, 2, 0,
|
||||
0, 0, 184, 1, 0, 0,
|
||||
0, 0, 0, 0, 255, 255,
|
||||
255, 255, 0, 0, 0, 0,
|
||||
255, 255, 255, 255, 0, 0,
|
||||
0, 0, 220, 1, 0, 0,
|
||||
8, 0, 0, 0, 4, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
136, 1, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 255, 255,
|
||||
255, 255, 0, 0, 0, 0,
|
||||
226, 1, 0, 0, 12, 0,
|
||||
0, 0, 4, 0, 0, 0,
|
||||
2, 0, 0, 0, 136, 1,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
255, 255, 255, 255, 0, 0,
|
||||
0, 0, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 68, 105,
|
||||
114, 101, 99, 116, 105, 111,
|
||||
110, 0, 100, 119, 111, 114,
|
||||
100, 0, 0, 0, 19, 0,
|
||||
1, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 130, 1,
|
||||
0, 0, 82, 97, 100, 105,
|
||||
117, 115, 0, 105, 110, 116,
|
||||
0, 171, 0, 0, 2, 0,
|
||||
1, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 179, 1,
|
||||
0, 0, 87, 105, 100, 116,
|
||||
104, 0, 72, 101, 105, 103,
|
||||
104, 116, 0, 77, 105, 99,
|
||||
114, 111, 115, 111, 102, 116,
|
||||
32, 40, 82, 41, 32, 72,
|
||||
76, 83, 76, 32, 83, 104,
|
||||
97, 100, 101, 114, 32, 67,
|
||||
111, 109, 112, 105, 108, 101,
|
||||
114, 32, 49, 48, 46, 49,
|
||||
0, 171, 171, 171, 73, 83,
|
||||
71, 78, 8, 0, 0, 0,
|
||||
0, 0, 0, 0, 8, 0,
|
||||
0, 0, 79, 83, 71, 78,
|
||||
8, 0, 0, 0, 0, 0,
|
||||
0, 0, 8, 0, 0, 0,
|
||||
83, 72, 69, 88, 192, 7,
|
||||
0, 0, 80, 0, 5, 0,
|
||||
240, 1, 0, 0, 106, 8,
|
||||
0, 1, 89, 0, 0, 4,
|
||||
70, 142, 32, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
88, 24, 0, 4, 0, 112,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
85, 85, 0, 0, 156, 24,
|
||||
0, 4, 0, 224, 17, 0,
|
||||
0, 0, 0, 0, 85, 85,
|
||||
0, 0, 95, 0, 0, 2,
|
||||
50, 16, 2, 0, 95, 0,
|
||||
0, 2, 18, 32, 2, 0,
|
||||
104, 0, 0, 2, 4, 0,
|
||||
0, 0, 160, 0, 0, 5,
|
||||
0, 240, 17, 0, 0, 0,
|
||||
0, 0, 16, 0, 0, 0,
|
||||
64, 1, 0, 0, 155, 0,
|
||||
0, 4, 0, 1, 0, 0,
|
||||
1, 0, 0, 0, 1, 0,
|
||||
0, 0, 37, 0, 0, 8,
|
||||
18, 0, 16, 0, 0, 0,
|
||||
0, 0, 26, 128, 32, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 64, 0, 0,
|
||||
32, 0, 0, 0, 41, 0,
|
||||
0, 7, 34, 0, 16, 0,
|
||||
0, 0, 0, 0, 10, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
1, 64, 0, 0, 1, 0,
|
||||
0, 0, 30, 0, 0, 7,
|
||||
66, 0, 16, 0, 0, 0,
|
||||
0, 0, 26, 0, 16, 0,
|
||||
0, 0, 0, 0, 1, 64,
|
||||
0, 0, 0, 1, 0, 0,
|
||||
31, 0, 0, 4, 10, 128,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 80, 0,
|
||||
0, 7, 130, 0, 16, 0,
|
||||
0, 0, 0, 0, 26, 16,
|
||||
2, 0, 58, 128, 32, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 31, 0, 4, 3,
|
||||
58, 0, 16, 0, 0, 0,
|
||||
0, 0, 62, 0, 0, 1,
|
||||
21, 0, 0, 1, 41, 0,
|
||||
0, 6, 130, 0, 16, 0,
|
||||
0, 0, 0, 0, 10, 16,
|
||||
2, 0, 1, 64, 0, 0,
|
||||
8, 0, 0, 0, 30, 0,
|
||||
0, 8, 18, 0, 16, 0,
|
||||
1, 0, 0, 0, 42, 128,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 64,
|
||||
0, 0, 255, 255, 255, 255,
|
||||
54, 0, 0, 4, 34, 0,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
26, 16, 2, 0, 54, 0,
|
||||
0, 8, 194, 0, 16, 0,
|
||||
2, 0, 0, 0, 2, 64,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
54, 0, 0, 4, 34, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
10, 32, 2, 0, 48, 0,
|
||||
0, 1, 33, 0, 0, 7,
|
||||
66, 0, 16, 0, 1, 0,
|
||||
0, 0, 26, 0, 16, 0,
|
||||
1, 0, 0, 0, 42, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
3, 0, 4, 3, 42, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
30, 0, 0, 7, 66, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
58, 0, 16, 0, 0, 0,
|
||||
0, 0, 26, 0, 16, 0,
|
||||
1, 0, 0, 0, 30, 0,
|
||||
0, 8, 66, 0, 16, 0,
|
||||
1, 0, 0, 0, 10, 0,
|
||||
16, 128, 65, 0, 0, 0,
|
||||
0, 0, 0, 0, 42, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
36, 0, 0, 7, 66, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
42, 0, 16, 0, 1, 0,
|
||||
0, 0, 1, 64, 0, 0,
|
||||
0, 0, 0, 0, 37, 0,
|
||||
0, 7, 18, 0, 16, 0,
|
||||
2, 0, 0, 0, 10, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
42, 0, 16, 0, 1, 0,
|
||||
0, 0, 45, 0, 0, 137,
|
||||
194, 0, 0, 128, 67, 85,
|
||||
21, 0, 242, 0, 16, 0,
|
||||
3, 0, 0, 0, 70, 14,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
70, 126, 16, 0, 0, 0,
|
||||
0, 0, 168, 0, 0, 9,
|
||||
242, 240, 17, 0, 0, 0,
|
||||
0, 0, 26, 0, 16, 0,
|
||||
1, 0, 0, 0, 1, 64,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
70, 14, 16, 0, 3, 0,
|
||||
0, 0, 30, 0, 0, 7,
|
||||
34, 0, 16, 0, 1, 0,
|
||||
0, 0, 26, 0, 16, 0,
|
||||
1, 0, 0, 0, 1, 64,
|
||||
0, 0, 0, 1, 0, 0,
|
||||
22, 0, 0, 1, 190, 24,
|
||||
0, 1, 35, 0, 0, 7,
|
||||
18, 0, 16, 0, 1, 0,
|
||||
0, 0, 10, 16, 2, 0,
|
||||
1, 64, 0, 0, 0, 1,
|
||||
0, 0, 10, 32, 2, 0,
|
||||
80, 0, 0, 8, 130, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
10, 0, 16, 0, 1, 0,
|
||||
0, 0, 42, 128, 32, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 31, 0, 4, 3,
|
||||
58, 0, 16, 0, 0, 0,
|
||||
0, 0, 62, 0, 0, 1,
|
||||
21, 0, 0, 1, 54, 0,
|
||||
0, 8, 242, 0, 16, 0,
|
||||
2, 0, 0, 0, 2, 64,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
54, 0, 0, 5, 130, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
1, 64, 0, 0, 0, 0,
|
||||
0, 0, 48, 0, 0, 1,
|
||||
34, 0, 0, 7, 18, 0,
|
||||
16, 0, 3, 0, 0, 0,
|
||||
26, 0, 16, 0, 0, 0,
|
||||
0, 0, 58, 0, 16, 0,
|
||||
0, 0, 0, 0, 3, 0,
|
||||
4, 3, 10, 0, 16, 0,
|
||||
3, 0, 0, 0, 30, 0,
|
||||
0, 6, 18, 0, 16, 0,
|
||||
3, 0, 0, 0, 58, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
10, 32, 2, 0, 167, 0,
|
||||
0, 9, 242, 0, 16, 0,
|
||||
3, 0, 0, 0, 10, 0,
|
||||
16, 0, 3, 0, 0, 0,
|
||||
1, 64, 0, 0, 0, 0,
|
||||
0, 0, 70, 254, 17, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 7, 242, 0, 16, 0,
|
||||
2, 0, 0, 0, 70, 14,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
70, 14, 16, 0, 3, 0,
|
||||
0, 0, 30, 0, 0, 7,
|
||||
130, 0, 16, 0, 0, 0,
|
||||
0, 0, 58, 0, 16, 0,
|
||||
0, 0, 0, 0, 1, 64,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
22, 0, 0, 1, 140, 0,
|
||||
0, 11, 130, 0, 16, 0,
|
||||
0, 0, 0, 0, 1, 64,
|
||||
0, 0, 31, 0, 0, 0,
|
||||
1, 64, 0, 0, 1, 0,
|
||||
0, 0, 10, 0, 16, 0,
|
||||
0, 0, 0, 0, 1, 64,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
43, 0, 0, 5, 130, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
58, 0, 16, 0, 0, 0,
|
||||
0, 0, 14, 0, 0, 7,
|
||||
242, 0, 16, 0, 2, 0,
|
||||
0, 0, 70, 14, 16, 0,
|
||||
2, 0, 0, 0, 246, 15,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
54, 0, 0, 4, 226, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
86, 21, 2, 0, 164, 0,
|
||||
0, 7, 242, 224, 17, 0,
|
||||
0, 0, 0, 0, 70, 14,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
70, 14, 16, 0, 2, 0,
|
||||
0, 0, 18, 0, 0, 1,
|
||||
80, 0, 0, 7, 130, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
26, 16, 2, 0, 42, 128,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 31, 0,
|
||||
4, 3, 58, 0, 16, 0,
|
||||
0, 0, 0, 0, 62, 0,
|
||||
0, 1, 21, 0, 0, 1,
|
||||
41, 0, 0, 6, 130, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
10, 16, 2, 0, 1, 64,
|
||||
0, 0, 8, 0, 0, 0,
|
||||
30, 0, 0, 8, 18, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
58, 128, 32, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
1, 64, 0, 0, 255, 255,
|
||||
255, 255, 54, 0, 0, 4,
|
||||
18, 0, 16, 0, 2, 0,
|
||||
0, 0, 26, 16, 2, 0,
|
||||
54, 0, 0, 8, 194, 0,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
2, 64, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 54, 0, 0, 4,
|
||||
34, 0, 16, 0, 1, 0,
|
||||
0, 0, 10, 32, 2, 0,
|
||||
48, 0, 0, 1, 33, 0,
|
||||
0, 7, 66, 0, 16, 0,
|
||||
1, 0, 0, 0, 26, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
42, 0, 16, 0, 0, 0,
|
||||
0, 0, 3, 0, 4, 3,
|
||||
42, 0, 16, 0, 1, 0,
|
||||
0, 0, 30, 0, 0, 7,
|
||||
66, 0, 16, 0, 1, 0,
|
||||
0, 0, 58, 0, 16, 0,
|
||||
0, 0, 0, 0, 26, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
30, 0, 0, 8, 66, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
10, 0, 16, 128, 65, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
42, 0, 16, 0, 1, 0,
|
||||
0, 0, 36, 0, 0, 7,
|
||||
66, 0, 16, 0, 1, 0,
|
||||
0, 0, 42, 0, 16, 0,
|
||||
1, 0, 0, 0, 1, 64,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
37, 0, 0, 7, 34, 0,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
10, 0, 16, 0, 1, 0,
|
||||
0, 0, 42, 0, 16, 0,
|
||||
1, 0, 0, 0, 45, 0,
|
||||
0, 137, 194, 0, 0, 128,
|
||||
67, 85, 21, 0, 242, 0,
|
||||
16, 0, 3, 0, 0, 0,
|
||||
70, 14, 16, 0, 2, 0,
|
||||
0, 0, 70, 126, 16, 0,
|
||||
0, 0, 0, 0, 168, 0,
|
||||
0, 9, 242, 240, 17, 0,
|
||||
0, 0, 0, 0, 26, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
1, 64, 0, 0, 0, 0,
|
||||
0, 0, 70, 14, 16, 0,
|
||||
3, 0, 0, 0, 30, 0,
|
||||
0, 7, 34, 0, 16, 0,
|
||||
1, 0, 0, 0, 26, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
1, 64, 0, 0, 0, 1,
|
||||
0, 0, 22, 0, 0, 1,
|
||||
190, 24, 0, 1, 35, 0,
|
||||
0, 10, 226, 0, 16, 0,
|
||||
1, 0, 0, 0, 6, 16,
|
||||
2, 0, 2, 64, 0, 0,
|
||||
0, 0, 0, 0, 0, 1,
|
||||
0, 0, 0, 1, 0, 0,
|
||||
0, 1, 0, 0, 6, 32,
|
||||
2, 0, 80, 0, 0, 8,
|
||||
66, 0, 16, 0, 0, 0,
|
||||
0, 0, 58, 0, 16, 0,
|
||||
1, 0, 0, 0, 58, 128,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 31, 0,
|
||||
4, 3, 42, 0, 16, 0,
|
||||
0, 0, 0, 0, 62, 0,
|
||||
0, 1, 21, 0, 0, 1,
|
||||
54, 0, 0, 8, 242, 0,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
2, 64, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 54, 0, 0, 5,
|
||||
66, 0, 16, 0, 0, 0,
|
||||
0, 0, 1, 64, 0, 0,
|
||||
0, 0, 0, 0, 48, 0,
|
||||
0, 1, 34, 0, 0, 7,
|
||||
130, 0, 16, 0, 0, 0,
|
||||
0, 0, 26, 0, 16, 0,
|
||||
0, 0, 0, 0, 42, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
3, 0, 4, 3, 58, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
30, 0, 0, 6, 130, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
42, 0, 16, 0, 0, 0,
|
||||
0, 0, 10, 32, 2, 0,
|
||||
167, 0, 0, 9, 242, 0,
|
||||
16, 0, 3, 0, 0, 0,
|
||||
58, 0, 16, 0, 0, 0,
|
||||
0, 0, 1, 64, 0, 0,
|
||||
0, 0, 0, 0, 70, 254,
|
||||
17, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 7, 242, 0,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
70, 14, 16, 0, 2, 0,
|
||||
0, 0, 70, 14, 16, 0,
|
||||
3, 0, 0, 0, 30, 0,
|
||||
0, 7, 66, 0, 16, 0,
|
||||
0, 0, 0, 0, 42, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
1, 64, 0, 0, 1, 0,
|
||||
0, 0, 22, 0, 0, 1,
|
||||
140, 0, 0, 11, 18, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
1, 64, 0, 0, 31, 0,
|
||||
0, 0, 1, 64, 0, 0,
|
||||
1, 0, 0, 0, 10, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
1, 64, 0, 0, 1, 0,
|
||||
0, 0, 43, 0, 0, 5,
|
||||
18, 0, 16, 0, 0, 0,
|
||||
0, 0, 10, 0, 16, 0,
|
||||
0, 0, 0, 0, 14, 0,
|
||||
0, 7, 242, 0, 16, 0,
|
||||
0, 0, 0, 0, 70, 14,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
6, 0, 16, 0, 0, 0,
|
||||
0, 0, 54, 0, 0, 4,
|
||||
18, 0, 16, 0, 1, 0,
|
||||
0, 0, 26, 16, 2, 0,
|
||||
164, 0, 0, 7, 242, 224,
|
||||
17, 0, 0, 0, 0, 0,
|
||||
70, 14, 16, 0, 1, 0,
|
||||
0, 0, 70, 14, 16, 0,
|
||||
0, 0, 0, 0, 21, 0,
|
||||
0, 1, 62, 0, 0, 1,
|
||||
83, 84, 65, 84, 148, 0,
|
||||
0, 0, 89, 0, 0, 0,
|
||||
4, 0, 0, 0, 0, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
4, 0, 0, 0, 27, 0,
|
||||
0, 0, 4, 0, 0, 0,
|
||||
7, 0, 0, 0, 8, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
12, 0, 0, 0, 0, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
2, 0, 0, 0, 0, 0,
|
||||
0, 0, 2, 0, 0, 0
|
||||
};
|
||||
115
src/modules/ZoomIt/ZoomIt/BoxBlurCS.hlsl
Normal file
115
src/modules/ZoomIt/ZoomIt/BoxBlurCS.hlsl
Normal file
@@ -0,0 +1,115 @@
|
||||
//==============================================================================
|
||||
//
|
||||
// BoxBlurCS.hlsl
|
||||
//
|
||||
// D3D11 compute shader for separable box blur. Each dispatch performs
|
||||
// either a horizontal or a vertical pass controlled by the Direction
|
||||
// constant. Run four dispatches (H→V→H→V) to approximate a Gaussian.
|
||||
//
|
||||
// Uses group-shared memory so each texel is loaded once per thread
|
||||
// group, then reused across the sliding window.
|
||||
//
|
||||
// Entry point:
|
||||
// CSMain (cs_5_0)
|
||||
//
|
||||
// Recompile with:
|
||||
// fxc /T cs_5_0 /E CSMain /Fh BoxBlurCS.h /Vn g_BoxBlurCS BoxBlurCS.hlsl
|
||||
//
|
||||
// Copyright (C) Mark Russinovich
|
||||
// Sysinternals - www.sysinternals.com
|
||||
//
|
||||
//==============================================================================
|
||||
|
||||
// Input texture (read-only).
|
||||
Texture2D<float4> InputTex : register(t0);
|
||||
|
||||
// Output texture (write-only).
|
||||
RWTexture2D<float4> OutputTex : register(u0);
|
||||
|
||||
cbuffer BlurConstants : register(b0)
|
||||
{
|
||||
uint Direction; // 0 = horizontal, 1 = vertical
|
||||
int Radius; // Box blur radius in pixels
|
||||
uint Width; // Image width
|
||||
uint Height; // Image height
|
||||
};
|
||||
|
||||
// Thread group: 256 threads along the blur axis.
|
||||
#define GROUP_SIZE 256
|
||||
|
||||
// Max radius we support. Shared memory = (GROUP_SIZE + 2*MAX_RADIUS) * 4 floats * 4 bytes
|
||||
// = (256 + 64) * 16 = ~5 KB, well within the 32 KB limit.
|
||||
#define MAX_RADIUS 32
|
||||
|
||||
// Shared memory tile: enough for the group + apron on both sides.
|
||||
groupshared float4 tile[GROUP_SIZE + 2 * MAX_RADIUS];
|
||||
|
||||
[numthreads(GROUP_SIZE, 1, 1)]
|
||||
void CSMain( uint3 groupId : SV_GroupID,
|
||||
uint3 groupTid : SV_GroupThreadID,
|
||||
uint3 dispatchId : SV_DispatchThreadID )
|
||||
{
|
||||
int r = min( Radius, MAX_RADIUS );
|
||||
int tileSize = GROUP_SIZE + 2 * r;
|
||||
int tid = (int)groupTid.x;
|
||||
|
||||
if( Direction == 0 )
|
||||
{
|
||||
// ── Horizontal pass ────────────────────────────────────────
|
||||
int row = (int)groupId.y;
|
||||
if( (uint)row >= Height )
|
||||
return;
|
||||
|
||||
int groupStart = (int)groupId.x * GROUP_SIZE;
|
||||
|
||||
// Load tile: each thread loads its primary texel + apron.
|
||||
for( int i = tid; i < tileSize; i += GROUP_SIZE )
|
||||
{
|
||||
int srcX = clamp( groupStart + i - r, 0, (int)Width - 1 );
|
||||
tile[i] = InputTex[int2( srcX, row )];
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
int outX = groupStart + tid;
|
||||
if( (uint)outX >= Width )
|
||||
return;
|
||||
|
||||
// Sum the window from shared memory.
|
||||
float4 sum = (float4)0;
|
||||
int windowStart = tid; // tile index = tid + r - r
|
||||
for( int k = 0; k <= 2 * r; k++ )
|
||||
{
|
||||
sum += tile[windowStart + k];
|
||||
}
|
||||
OutputTex[int2( outX, row )] = sum / (float)( 2 * r + 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// ── Vertical pass ──────────────────────────────────────────
|
||||
int col = (int)groupId.y;
|
||||
if( (uint)col >= Width )
|
||||
return;
|
||||
|
||||
int groupStart = (int)groupId.x * GROUP_SIZE;
|
||||
|
||||
// Load tile.
|
||||
for( int i = tid; i < tileSize; i += GROUP_SIZE )
|
||||
{
|
||||
int srcY = clamp( groupStart + i - r, 0, (int)Height - 1 );
|
||||
tile[i] = InputTex[int2( col, srcY )];
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
int outY = groupStart + tid;
|
||||
if( (uint)outY >= Height )
|
||||
return;
|
||||
|
||||
float4 sum = (float4)0;
|
||||
int windowStart = tid;
|
||||
for( int k = 0; k <= 2 * r; k++ )
|
||||
{
|
||||
sum += tile[windowStart + k];
|
||||
}
|
||||
OutputTex[int2( col, outY )] = sum / (float)( 2 * r + 1 );
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,7 @@ std::optional<CaptureFrame> CaptureFrameWait::TryGetNextFrame()
|
||||
if (m_currentFrame != nullptr)
|
||||
{
|
||||
m_currentFrame.Close();
|
||||
m_currentFrame = nullptr; // Prevent double-Close on subsequent calls
|
||||
}
|
||||
m_nextFrameEvent.ResetEvent();
|
||||
|
||||
@@ -107,6 +108,33 @@ std::optional<CaptureFrame> CaptureFrameWait::TryGetNextFrame()
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
// CaptureFrameWait::PeekCurrentFrame
|
||||
//
|
||||
// Returns the frame that is currently held (if any) without closing
|
||||
// it and without waiting for a new one. This is useful during
|
||||
// recording startup: the constructor captured a frame when the
|
||||
// session began, and OnMediaStreamSourceStarting can use it
|
||||
// immediately instead of blocking until the next desktop change.
|
||||
// The frame remains alive in the pool until the next
|
||||
// TryGetNextFrame() call closes it.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
std::optional<CaptureFrame> CaptureFrameWait::PeekCurrentFrame() const
|
||||
{
|
||||
if (m_currentFrame != nullptr)
|
||||
{
|
||||
return std::optional<CaptureFrame>(
|
||||
{
|
||||
m_currentFrame.Surface(),
|
||||
m_currentFrame.ContentSize(),
|
||||
m_currentFrame.SystemRelativeTime(),
|
||||
});
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
// CaptureFrameWait::TryGetNextFrame (with timeout)
|
||||
@@ -121,6 +149,7 @@ std::optional<CaptureFrame> CaptureFrameWait::TryGetNextFrame( DWORD timeoutMs )
|
||||
if( m_currentFrame != nullptr )
|
||||
{
|
||||
m_currentFrame.Close();
|
||||
m_currentFrame = nullptr; // Prevent double-Close on subsequent calls
|
||||
}
|
||||
m_nextFrameEvent.ResetEvent();
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ public:
|
||||
|
||||
std::optional<CaptureFrame> TryGetNextFrame();
|
||||
std::optional<CaptureFrame> TryGetNextFrame( DWORD timeoutMs );
|
||||
std::optional<CaptureFrame> PeekCurrentFrame() const;
|
||||
void StopCapture();
|
||||
void EnableCursorCapture( bool enable = true )
|
||||
{
|
||||
|
||||
113
src/modules/ZoomIt/ZoomIt/NoiseSuppressor.cpp
Normal file
113
src/modules/ZoomIt/ZoomIt/NoiseSuppressor.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "pch.h"
|
||||
#include "NoiseSuppressor.h"
|
||||
|
||||
extern "C" {
|
||||
#include "rnnoise/rnnoise.h"
|
||||
}
|
||||
|
||||
// RNNoise processes 480 mono samples per frame (10ms at 48kHz)
|
||||
static constexpr uint32_t RNNOISE_FRAME_SIZE = 480;
|
||||
|
||||
// RNNoise expects samples in PCM16 range (-32768 to 32767), not normalized float [-1, 1]
|
||||
static constexpr float PCM16_SCALE = 32768.0f;
|
||||
static constexpr float PCM16_SCALE_INV = 1.0f / 32768.0f;
|
||||
|
||||
NoiseSuppressor::NoiseSuppressor()
|
||||
{
|
||||
}
|
||||
|
||||
NoiseSuppressor::~NoiseSuppressor()
|
||||
{
|
||||
for (auto& channel : m_channels)
|
||||
{
|
||||
if (channel.state)
|
||||
{
|
||||
rnnoise_destroy(channel.state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NoiseSuppressor::EnsureChannelCount(uint32_t channels)
|
||||
{
|
||||
if (m_channels.size() == channels)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Channel count changed (or first call): rebuild per-channel RNNoise state.
|
||||
for (auto& channel : m_channels)
|
||||
{
|
||||
if (channel.state)
|
||||
{
|
||||
rnnoise_destroy(channel.state);
|
||||
}
|
||||
}
|
||||
|
||||
m_channels.clear();
|
||||
m_channels.resize(channels);
|
||||
for (auto& channel : m_channels)
|
||||
{
|
||||
channel.state = rnnoise_create(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void NoiseSuppressor::Process(float* samples, uint32_t sampleCount, uint32_t channels)
|
||||
{
|
||||
if (sampleCount == 0 || channels == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EnsureChannelCount(channels);
|
||||
|
||||
uint32_t frameCount = sampleCount / channels;
|
||||
|
||||
// Denoise each channel independently so the original channel layout is
|
||||
// preserved (e.g. a mic wired only to the left channel stays on the left
|
||||
// and silent channels stay silent instead of being filled with the voice).
|
||||
for (uint32_t ch = 0; ch < channels; ch++)
|
||||
{
|
||||
ChannelState& channel = m_channels[ch];
|
||||
if (!channel.state)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t residualCount = static_cast<uint32_t>(channel.residual.size());
|
||||
uint32_t totalSamples = residualCount + frameCount;
|
||||
|
||||
channel.work.resize(totalSamples);
|
||||
|
||||
// Copy residual from previous call
|
||||
if (residualCount > 0)
|
||||
{
|
||||
memcpy(channel.work.data(), channel.residual.data(), residualCount * sizeof(float));
|
||||
}
|
||||
|
||||
// Deinterleave this channel and scale to PCM16 range for RNNoise
|
||||
for (uint32_t i = 0; i < frameCount; i++)
|
||||
{
|
||||
channel.work[residualCount + i] = samples[i * channels + ch] * PCM16_SCALE;
|
||||
}
|
||||
|
||||
// Process complete 480-sample frames through RNNoise
|
||||
uint32_t processedSamples = 0;
|
||||
while (processedSamples + RNNOISE_FRAME_SIZE <= totalSamples)
|
||||
{
|
||||
rnnoise_process_frame(channel.state, &channel.work[processedSamples], &channel.work[processedSamples]);
|
||||
processedSamples += RNNOISE_FRAME_SIZE;
|
||||
}
|
||||
|
||||
// Save unprocessed residual for next call
|
||||
channel.residual.assign(
|
||||
channel.work.begin() + processedSamples,
|
||||
channel.work.end());
|
||||
|
||||
// Write denoised samples back to the interleaved buffer, scaling back to
|
||||
// normalized float. Only this call's input region is written back.
|
||||
for (uint32_t i = 0; i < frameCount; i++)
|
||||
{
|
||||
samples[i * channels + ch] = channel.work[residualCount + i] * PCM16_SCALE_INV;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/modules/ZoomIt/ZoomIt/NoiseSuppressor.h
Normal file
37
src/modules/ZoomIt/ZoomIt/NoiseSuppressor.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
struct DenoiseState;
|
||||
|
||||
class NoiseSuppressor
|
||||
{
|
||||
public:
|
||||
NoiseSuppressor();
|
||||
~NoiseSuppressor();
|
||||
|
||||
NoiseSuppressor(const NoiseSuppressor&) = delete;
|
||||
NoiseSuppressor& operator=(const NoiseSuppressor&) = delete;
|
||||
|
||||
// Process interleaved multi-channel float samples in-place.
|
||||
// Each channel is denoised independently through its own RNNoise state in
|
||||
// 480-sample frames, preserving the original channel layout (e.g. a mic
|
||||
// wired only to the left channel stays on the left and is not duplicated
|
||||
// onto the right).
|
||||
void Process(float* samples, uint32_t sampleCount, uint32_t channels);
|
||||
|
||||
private:
|
||||
// Per-channel RNNoise state and buffers so each channel is denoised
|
||||
// independently and the channel layout is preserved.
|
||||
struct ChannelState
|
||||
{
|
||||
DenoiseState* state = nullptr;
|
||||
std::vector<float> work; // Working buffer for the current quantum
|
||||
std::vector<float> residual; // Leftover samples from previous quantum
|
||||
};
|
||||
|
||||
void EnsureChannelCount(uint32_t channels);
|
||||
|
||||
std::vector<ChannelState> m_channels;
|
||||
};
|
||||
@@ -32,6 +32,9 @@ extern DWORD g_WebcamPosition;
|
||||
extern DWORD g_WebcamSize;
|
||||
extern DWORD g_WebcamShape;
|
||||
extern TCHAR g_WebcamDeviceSymLink[MAX_PATH];
|
||||
extern DWORD g_WebcamBackgroundMode;
|
||||
extern TCHAR g_WebcamBackgroundImage[];
|
||||
extern DWORD g_WebcamBrightness;
|
||||
extern class ClassRegistry reg;
|
||||
extern REG_SETTING RegSettings[];
|
||||
extern HINSTANCE g_hInstance;
|
||||
@@ -106,6 +109,34 @@ static double RecDiagElapsedMs()
|
||||
return static_cast<double>( now.QuadPart - s_origin.QuadPart ) * 1000.0 / s_freq.QuadPart;
|
||||
}
|
||||
|
||||
static FILE* s_recDiagFile = nullptr;
|
||||
|
||||
static void RecDiagOpenFile()
|
||||
{
|
||||
if( !s_recDiagFile )
|
||||
{
|
||||
wchar_t path[MAX_PATH];
|
||||
if( ExpandEnvironmentStringsW( L"%TEMP%\\ZoomIt_RecDiag.log", path, MAX_PATH ) )
|
||||
{
|
||||
_wfopen_s( &s_recDiagFile, path, L"a" );
|
||||
if( s_recDiagFile )
|
||||
{
|
||||
fwprintf( s_recDiagFile, L"\n===== NEW SESSION =====\n" );
|
||||
fflush( s_recDiagFile );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void RecDiagCloseFile()
|
||||
{
|
||||
if( s_recDiagFile )
|
||||
{
|
||||
fclose( s_recDiagFile );
|
||||
s_recDiagFile = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void RecDiag( const wchar_t* fmt, ... )
|
||||
{
|
||||
wchar_t buf[512];
|
||||
@@ -123,8 +154,19 @@ static void RecDiag( const wchar_t* fmt, ... )
|
||||
_vsnwprintf_s( buf + offset, _countof( buf ) - offset, _TRUNCATE, fmt, va );
|
||||
va_end( va );
|
||||
OutputDebugStringW( buf );
|
||||
|
||||
RecDiagOpenFile();
|
||||
if( s_recDiagFile )
|
||||
{
|
||||
fwprintf( s_recDiagFile, L"%s", buf );
|
||||
fflush( s_recDiagFile );
|
||||
}
|
||||
}
|
||||
|
||||
static int s_diagVideoCount = 0;
|
||||
static int s_diagAudioCount = 0;
|
||||
static int64_t s_diagStartTs = 0; // SystemRelativeTime from OnStarting
|
||||
|
||||
static bool IsGifPath(const std::wstring& path)
|
||||
{
|
||||
try
|
||||
@@ -930,12 +972,20 @@ VideoRecordingSession::VideoRecordingSession(
|
||||
winrt::GraphicsCaptureItem const& item,
|
||||
RECT const cropRect,
|
||||
uint32_t frameRate,
|
||||
bool captureAudio,
|
||||
bool captureSystemAudio,
|
||||
bool micMonoMix,
|
||||
std::unique_ptr<AudioSampleGenerator> audioGenerator,
|
||||
winrt::IAsyncAction audioInitAction,
|
||||
winrt::Streams::IRandomAccessStream const& stream)
|
||||
{
|
||||
RecDiag( L"Constructor: entry\n" );
|
||||
|
||||
// Take ownership of pre-created audio generator. Its InitializeAsync
|
||||
// was started in StartRecordingAsync so it runs in parallel with all
|
||||
// the D3D, capture-item, and webcam setup below.
|
||||
m_audioGenerator = std::move( audioGenerator );
|
||||
m_audioInitAction = audioInitAction;
|
||||
RecDiag( L"Constructor: audio generator received (init %s)\n",
|
||||
m_audioInitAction ? L"pending" : L"none" );
|
||||
|
||||
m_device = device;
|
||||
m_d3dDevice = GetDXGIInterfaceFromObject<ID3D11Device>(m_device);
|
||||
m_d3dDevice->GetImmediateContext(m_d3dContext.put());
|
||||
@@ -1038,8 +1088,15 @@ VideoRecordingSession::VideoRecordingSession(
|
||||
probeCapture.Close();
|
||||
return true;
|
||||
}
|
||||
catch( winrt::hresult_error const& ex )
|
||||
{
|
||||
RecDiag( L"Constructor: webcam probe failed hr=0x%08X: %s\n",
|
||||
static_cast<unsigned>( ex.code() ), ex.message().c_str() );
|
||||
return false;
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
RecDiag( L"Constructor: webcam probe failed with unknown exception\n" );
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@@ -1067,7 +1124,10 @@ VideoRecordingSession::VideoRecordingSession(
|
||||
static_cast<WebcamCapture::Position>( g_WebcamPosition ),
|
||||
static_cast<WebcamCapture::Size>( g_WebcamSize ),
|
||||
webcamShape,
|
||||
isFullScreenRecording );
|
||||
isFullScreenRecording,
|
||||
static_cast<WebcamBackgroundMode>( g_WebcamBackgroundMode ),
|
||||
g_WebcamBackgroundImage,
|
||||
static_cast<int>( g_WebcamBrightness ) );
|
||||
m_webcamCapture->Start();
|
||||
RecDiag( L"Constructor: WebcamCapture::Start() returned\n" );
|
||||
}
|
||||
@@ -1089,12 +1149,12 @@ VideoRecordingSession::VideoRecordingSession(
|
||||
// Store frame interval for timeout-based frame production when webcam is active.
|
||||
m_frameIntervalTicks = ( frameRate > 0 ) ? ( 10'000'000LL / frameRate ) : 333'333LL;
|
||||
|
||||
if (captureAudio || captureSystemAudio)
|
||||
if (m_audioGenerator)
|
||||
{
|
||||
// Always set up audio profile for loopback capture (stereo AAC)
|
||||
auto audio = m_encodingProfile.Audio();
|
||||
audio = winrt::AudioEncodingProperties::CreateAac(48000, 2, 192000);
|
||||
m_encodingProfile.Audio(audio);
|
||||
auto audioProps = m_audioGenerator->GetEncodingProperties();
|
||||
m_encodingProfile.Audio(winrt::AudioEncodingProperties::CreateAac(
|
||||
audioProps.SampleRate(), audioProps.ChannelCount(), 192000));
|
||||
}
|
||||
|
||||
// Describe our input: uncompressed BGRA8 buffers
|
||||
@@ -1113,15 +1173,6 @@ VideoRecordingSession::VideoRecordingSession(
|
||||
DXGI_FORMAT_B8G8R8A8_UNORM,
|
||||
2);
|
||||
|
||||
if (captureAudio || captureSystemAudio)
|
||||
{
|
||||
m_audioGenerator = std::make_unique<AudioSampleGenerator>(captureAudio, captureSystemAudio, micMonoMix);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_audioGenerator = nullptr;
|
||||
}
|
||||
|
||||
// Wait for the webcam's first frame now that all other setup is done.
|
||||
// The camera was started early, so most of its ~850 ms sensor warmup has
|
||||
// overlapped with the encoding profile, swap chain, and audio generator
|
||||
@@ -1155,6 +1206,7 @@ VideoRecordingSession::VideoRecordingSession(
|
||||
VideoRecordingSession::~VideoRecordingSession()
|
||||
{
|
||||
Close();
|
||||
RecDiagCloseFile();
|
||||
}
|
||||
|
||||
|
||||
@@ -1173,8 +1225,13 @@ winrt::IAsyncAction VideoRecordingSession::StartAsync()
|
||||
// Create our MediaStreamSource
|
||||
if(m_audioGenerator) {
|
||||
|
||||
RecDiag( L"StartAsync: co_await InitializeAsync...\n" );
|
||||
co_await m_audioGenerator->InitializeAsync();
|
||||
RecDiag( L"StartAsync: co_await audio init...\n" );
|
||||
if (m_audioInitAction) {
|
||||
co_await m_audioInitAction; // started in constructor
|
||||
m_audioInitAction = nullptr;
|
||||
} else {
|
||||
co_await m_audioGenerator->InitializeAsync();
|
||||
}
|
||||
RecDiag( L"StartAsync: audio initialized\n" );
|
||||
m_streamSource = winrt::MediaStreamSource(m_videoDescriptor, winrt::AudioStreamDescriptor(m_audioGenerator->GetEncodingProperties()));
|
||||
}
|
||||
@@ -1236,6 +1293,9 @@ winrt::IAsyncAction VideoRecordingSession::StartAsync()
|
||||
//----------------------------------------------------------------------------
|
||||
void VideoRecordingSession::Close()
|
||||
{
|
||||
RecDiag( L"Close: totalVideoFrames=%d totalAudioSamples=%d\n",
|
||||
s_diagVideoCount, s_diagAudioCount );
|
||||
|
||||
// Stop webcam capture before closing the main session.
|
||||
if( m_webcamCapture )
|
||||
{
|
||||
@@ -1285,28 +1345,45 @@ void VideoRecordingSession::OnMediaStreamSourceStarting(
|
||||
winrt::MediaStreamSource const&,
|
||||
winrt::MediaStreamSourceStartingEventArgs const& args)
|
||||
{
|
||||
RecDiag( L"OnStarting: entry, calling TryGetNextFrame...\n" );
|
||||
auto frame = m_frameWait->TryGetNextFrame();
|
||||
// Close the stale frame captured in the constructor (~1-2 seconds
|
||||
// ago) and grab a FRESH frame via TryGetNextFrame. This gives us
|
||||
// both current visual content and a current SystemRelativeTime,
|
||||
// avoiding the frozen-first-frame artefact. WGC delivers a new
|
||||
// frame within one vblank (~16 ms) after the old frame is released
|
||||
// back to the pool, so a 200 ms timeout is very generous.
|
||||
RecDiag( L"OnStarting: calling TryGetNextFrame(200) for fresh frame...\n" );
|
||||
auto frame = m_frameWait->TryGetNextFrame( 200 );
|
||||
|
||||
int64_t startSRT = 0;
|
||||
|
||||
if (frame) {
|
||||
RecDiag( L"OnStarting: got frame, SystemRelativeTime=%lld (%.1fms)\n",
|
||||
frame->SystemRelativeTime.count(),
|
||||
frame->SystemRelativeTime.count() / 10000.0 );
|
||||
args.Request().SetActualStartPosition(frame->SystemRelativeTime);
|
||||
startSRT = frame->SystemRelativeTime.count();
|
||||
RecDiag( L"OnStarting: got fresh frame, SRT=%lld (%.1fms)\n",
|
||||
startSRT, startSRT / 10000.0 );
|
||||
|
||||
// Cache this frame so it can be served as the very first video
|
||||
// sample in OnMediaStreamSourceSampleRequested. Without this,
|
||||
// the frame is discarded and the first encoded sample comes from
|
||||
// the *next* capture, creating a visible timestamp gap.
|
||||
args.Request().SetActualStartPosition( frame->SystemRelativeTime );
|
||||
m_cachedStartingFrame = frame;
|
||||
|
||||
if (m_audioGenerator) {
|
||||
|
||||
RecDiag( L"OnStarting: calling AudioSampleGenerator::Start()\n" );
|
||||
m_audioGenerator->Start();
|
||||
RecDiag( L"OnStarting: audio started\n" );
|
||||
}
|
||||
m_adjustedStartSRT = startSRT;
|
||||
} else {
|
||||
RecDiag( L"OnStarting: TryGetNextFrame returned nullopt!\n" );
|
||||
// Timeout (very unlikely). Fall back to QPC-derived SRT.
|
||||
// Use double for the intermediate product to avoid int64
|
||||
// overflow (naive integer multiply overflows after ~25.6 h).
|
||||
RecDiag( L"OnStarting: TryGetNextFrame timed out, using QPC fallback\n" );
|
||||
LARGE_INTEGER qpcFreq, qpcNow;
|
||||
QueryPerformanceFrequency( &qpcFreq );
|
||||
QueryPerformanceCounter( &qpcNow );
|
||||
startSRT = static_cast<int64_t>(
|
||||
static_cast<double>( qpcNow.QuadPart ) * 10'000'000.0 / qpcFreq.QuadPart );
|
||||
args.Request().SetActualStartPosition( winrt::TimeSpan{ startSRT } );
|
||||
m_adjustedStartSRT = startSRT;
|
||||
}
|
||||
|
||||
// Start audio capture. Pass the video start SRT so audio
|
||||
// timestamps can be rebased to the same domain as video.
|
||||
if (m_audioGenerator) {
|
||||
RecDiag( L"OnStarting: calling AudioSampleGenerator::Start(videoStartSRT=%lld)\n", startSRT );
|
||||
m_audioGenerator->Start( startSRT );
|
||||
RecDiag( L"OnStarting: audio started\n" );
|
||||
}
|
||||
RecDiag( L"OnStarting: exit\n" );
|
||||
}
|
||||
@@ -1321,12 +1398,11 @@ std::shared_ptr<VideoRecordingSession> VideoRecordingSession::Create(
|
||||
winrt::GraphicsCaptureItem const& item,
|
||||
RECT const& crop,
|
||||
uint32_t frameRate,
|
||||
bool captureAudio,
|
||||
bool captureSystemAudio,
|
||||
bool micMonoMix,
|
||||
std::unique_ptr<AudioSampleGenerator> audioGenerator,
|
||||
winrt::IAsyncAction audioInitAction,
|
||||
winrt::Streams::IRandomAccessStream const& stream)
|
||||
{
|
||||
return std::shared_ptr<VideoRecordingSession>(new VideoRecordingSession(device, item, crop, frameRate, captureAudio, captureSystemAudio, micMonoMix, stream));
|
||||
return std::shared_ptr<VideoRecordingSession>(new VideoRecordingSession(device, item, crop, frameRate, std::move(audioGenerator), audioInitAction, stream));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -1338,10 +1414,6 @@ void VideoRecordingSession::OnMediaStreamSourceSampleRequested(
|
||||
winrt::MediaStreamSource const&,
|
||||
winrt::MediaStreamSourceSampleRequestedEventArgs const& args)
|
||||
{
|
||||
static int s_diagVideoCount = 0;
|
||||
static int s_diagAudioCount = 0;
|
||||
static int64_t s_diagStartTs = 0; // SystemRelativeTime from OnStarting
|
||||
|
||||
auto request = args.Request();
|
||||
auto streamDescriptor = request.StreamDescriptor();
|
||||
if (auto videoStreamDescriptor = streamDescriptor.try_as<winrt::VideoStreamDescriptor>())
|
||||
@@ -1412,7 +1484,16 @@ void VideoRecordingSession::OnMediaStreamSourceSampleRequested(
|
||||
else
|
||||
{
|
||||
// New desktop frame — crop and copy to back buffer.
|
||||
timeStamp = frame->SystemRelativeTime;
|
||||
// If this is the cached starting frame, use the adjusted
|
||||
// SRT (computed from QPC in OnStarting) instead of the
|
||||
// stale SRT from the constructor. The stale SRT is ~2-3s
|
||||
// behind, creating a massive timestamp gap between frame
|
||||
// #1 and #2 that causes the transcoder to starve video
|
||||
// while filling the gap with audio.
|
||||
if( cachedFrame.has_value() && m_adjustedStartSRT != 0 )
|
||||
timeStamp = winrt::TimeSpan{ m_adjustedStartSRT };
|
||||
else
|
||||
timeStamp = frame->SystemRelativeTime;
|
||||
auto contentSize = frame->ContentSize;
|
||||
auto frameTexture = GetDXGIInterfaceFromObject<ID3D11Texture2D>(frame->FrameTexture);
|
||||
D3D11_TEXTURE2D_DESC desc = {};
|
||||
@@ -1448,7 +1529,7 @@ void VideoRecordingSession::OnMediaStreamSourceSampleRequested(
|
||||
m_d3dContext->CopyResource( m_cachedDesktopTex.get(), backBuffer.get() );
|
||||
}
|
||||
|
||||
// Log first 10 video frames with timing.
|
||||
// Log first 50 video frames with timing.
|
||||
if( !m_hasVideoSample.load() )
|
||||
{
|
||||
s_diagVideoCount = 0;
|
||||
@@ -1462,13 +1543,14 @@ void VideoRecordingSession::OnMediaStreamSourceSampleRequested(
|
||||
m_hasQpcOrigin = true;
|
||||
}
|
||||
s_diagVideoCount++;
|
||||
if( s_diagVideoCount <= 10 )
|
||||
if( s_diagVideoCount <= 50 )
|
||||
{
|
||||
RecDiag( L"SampleReq VIDEO #%d: sysRelTime=%lld deltaFromStart=%.1fms repeat=%d\n",
|
||||
RecDiag( L"SampleReq VIDEO #%d: sysRelTime=%lld deltaFromStart=%.1fms repeat=%d cached=%d\n",
|
||||
s_diagVideoCount,
|
||||
timeStamp.count(),
|
||||
( timeStamp.count() - s_diagStartTs ) / 10000.0,
|
||||
isRepeatFrame ? 1 : 0 );
|
||||
isRepeatFrame ? 1 : 0,
|
||||
( s_diagVideoCount == 1 && cachedFrame.has_value() ) ? 1 : 0 );
|
||||
}
|
||||
|
||||
#if _DEBUG
|
||||
@@ -1492,6 +1574,11 @@ void VideoRecordingSession::OnMediaStreamSourceSampleRequested(
|
||||
// Composite webcam overlay onto the back buffer.
|
||||
if( m_webcamCapture )
|
||||
{
|
||||
if( s_diagVideoCount <= 3 )
|
||||
{
|
||||
RecDiag( L"SampleReq VIDEO #%d: compositing LIVE webcam frame\n",
|
||||
s_diagVideoCount );
|
||||
}
|
||||
m_webcamCapture->CompositeOnto( backBuffer.get() );
|
||||
}
|
||||
|
||||
@@ -1541,7 +1628,9 @@ void VideoRecordingSession::OnMediaStreamSourceSampleRequested(
|
||||
}
|
||||
catch (winrt::hresult_error const& error)
|
||||
{
|
||||
OutputDebugStringW(error.message().c_str());
|
||||
RecDiag( L"SampleReq VIDEO EXCEPTION on frame #%d: hr=0x%08X %s\n",
|
||||
s_diagVideoCount, static_cast<unsigned>(error.code()),
|
||||
error.message().c_str() );
|
||||
request.Sample(nullptr);
|
||||
CloseInternal();
|
||||
return;
|
||||
@@ -1551,26 +1640,53 @@ void VideoRecordingSession::OnMediaStreamSourceSampleRequested(
|
||||
{
|
||||
try
|
||||
{
|
||||
static int s_audioReqCount = 0;
|
||||
if( !m_hasVideoSample.load() )
|
||||
s_audioReqCount = 0;
|
||||
s_audioReqCount++;
|
||||
|
||||
if( s_audioReqCount <= 5 )
|
||||
{
|
||||
RecDiag( L"SampleReq AUDIO req #%d: calling TryGetNextSample (started=%d)...\n",
|
||||
s_audioReqCount, m_audioGenerator ? 1 : 0 );
|
||||
}
|
||||
|
||||
LARGE_INTEGER tBefore, tAfter, tFreq;
|
||||
QueryPerformanceFrequency( &tFreq );
|
||||
QueryPerformanceCounter( &tBefore );
|
||||
|
||||
if (auto sample = m_audioGenerator ? m_audioGenerator->TryGetNextSample() : std::optional<winrt::MediaStreamSample>{}; sample.has_value())
|
||||
{
|
||||
QueryPerformanceCounter( &tAfter );
|
||||
double waitMs = static_cast<double>( tAfter.QuadPart - tBefore.QuadPart ) * 1000.0 / tFreq.QuadPart;
|
||||
|
||||
s_diagAudioCount++;
|
||||
if( s_diagAudioCount <= 10 )
|
||||
if( s_diagAudioCount <= 50 )
|
||||
{
|
||||
RecDiag( L"SampleReq AUDIO #%d: timestamp=%lld (%.1fms)\n",
|
||||
s_diagAudioCount,
|
||||
sample.value().Timestamp().count(),
|
||||
sample.value().Timestamp().count() / 10000.0 );
|
||||
auto ts = sample.value().Timestamp().count();
|
||||
auto dur = sample.value().Duration().count();
|
||||
RecDiag( L"SampleReq AUDIO #%d (req %d): timestamp=%lld (%.1fms) duration=%lld (%.1fms) waitMs=%.1f\n",
|
||||
s_diagAudioCount, s_audioReqCount,
|
||||
ts, ts / 10000.0,
|
||||
dur, dur / 10000.0,
|
||||
waitMs );
|
||||
}
|
||||
request.Sample(sample.value());
|
||||
}
|
||||
else
|
||||
{
|
||||
QueryPerformanceCounter( &tAfter );
|
||||
double waitMs = static_cast<double>( tAfter.QuadPart - tBefore.QuadPart ) * 1000.0 / tFreq.QuadPart;
|
||||
RecDiag( L"SampleReq AUDIO req #%d: TryGetNextSample returned EMPTY after %.1fms → end-of-audio-stream\n",
|
||||
s_audioReqCount, waitMs );
|
||||
request.Sample(nullptr);
|
||||
}
|
||||
}
|
||||
catch (winrt::hresult_error const& error)
|
||||
{
|
||||
OutputDebugStringW(error.message().c_str());
|
||||
RecDiag( L"SampleReq AUDIO EXCEPTION on sample #%d: hr=0x%08X %s\n",
|
||||
s_diagAudioCount, static_cast<unsigned>(error.code()),
|
||||
error.message().c_str() );
|
||||
request.Sample(nullptr);
|
||||
CloseInternal();
|
||||
return;
|
||||
@@ -1659,7 +1775,7 @@ public:
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
IFACEMETHODIMP OnFolderChanging(IFileDialog*, IShellItem*) { return S_OK; }
|
||||
IFACEMETHODIMP OnSelectionChange(IFileDialog*) { return S_OK; }
|
||||
IFACEMETHODIMP OnShareViolation(IFileDialog*, IShellItem*, FDE_SHAREVIOLATION_RESPONSE*) { return S_OK; }
|
||||
@@ -2838,7 +2954,7 @@ static void HandlePlaybackCommand(int controlId, VideoRecordingSession::TrimDial
|
||||
case IDC_TRIM_REWIND:
|
||||
{
|
||||
StopPlayback(hDlg, pData, false);
|
||||
// Use 1 second step for timelines < 20 seconds, 2 seconds
|
||||
// Use 1 second step for timelines < 20 seconds, 2 seconds
|
||||
const int64_t duration = pData->trimEnd.count() - pData->trimStart.count();
|
||||
const int64_t stepTicks = (duration < 200'000'000) ? 10'000'000 : kJogStepTicks;
|
||||
const int64_t newTicks = (std::max)(pData->trimStart.count(), pData->currentPosition.count() - stepTicks);
|
||||
@@ -2854,7 +2970,7 @@ static void HandlePlaybackCommand(int controlId, VideoRecordingSession::TrimDial
|
||||
case IDC_TRIM_FORWARD:
|
||||
{
|
||||
StopPlayback(hDlg, pData, false);
|
||||
// Use 1 second step for timelines < 20 seconds, 2 seconds
|
||||
// Use 1 second step for timelines < 20 seconds, 2 seconds
|
||||
const int64_t duration = pData->trimEnd.count() - pData->trimStart.count();
|
||||
const int64_t stepTicks = (duration < 200'000'000) ? 10'000'000 : kJogStepTicks;
|
||||
const int64_t newTicks = (std::min)(pData->trimEnd.count(), pData->currentPosition.count() + stepTicks);
|
||||
@@ -5517,7 +5633,7 @@ INT_PTR CALLBACK VideoRecordingSession::TrimDialogProc(HWND hDlg, UINT message,
|
||||
const auto relativePos = winrt::TimeSpan{ (std::max)(pData->currentPosition.count() - pData->trimStart.count(), int64_t{ 0 }) };
|
||||
SetTimeText(hDlg, IDC_TRIM_POSITION_LABEL, relativePos, true);
|
||||
}
|
||||
|
||||
|
||||
if (elapsedMs >= frameDurationMs)
|
||||
{
|
||||
// Time to advance to next frame
|
||||
|
||||
@@ -27,9 +27,8 @@ public:
|
||||
winrt::GraphicsCaptureItem const& item,
|
||||
RECT const& cropRect,
|
||||
uint32_t frameRate,
|
||||
bool captureAudio,
|
||||
bool captureSystemAudio,
|
||||
bool micMonoMix,
|
||||
std::unique_ptr<AudioSampleGenerator> audioGenerator,
|
||||
winrt::Windows::Foundation::IAsyncAction audioInitAction,
|
||||
winrt::Streams::IRandomAccessStream const& stream);
|
||||
~VideoRecordingSession();
|
||||
|
||||
@@ -217,9 +216,8 @@ private:
|
||||
winrt::Capture::GraphicsCaptureItem const& item,
|
||||
RECT const cropRect,
|
||||
uint32_t frameRate,
|
||||
bool captureAudio,
|
||||
bool captureSystemAudio,
|
||||
bool micMonoMix,
|
||||
std::unique_ptr<AudioSampleGenerator> audioGenerator,
|
||||
winrt::Windows::Foundation::IAsyncAction audioInitAction,
|
||||
winrt::Streams::IRandomAccessStream const& stream);
|
||||
void CloseInternal();
|
||||
|
||||
@@ -279,5 +277,9 @@ private:
|
||||
LARGE_INTEGER m_qpcFreq{};
|
||||
LARGE_INTEGER m_qpcRecordingStart{}; // QPC at first sample
|
||||
int64_t m_startSystemRelativeTime = 0; // SystemRelativeTime of first frame
|
||||
int64_t m_adjustedStartSRT = 0; // QPC-based current SRT set in OnStarting
|
||||
bool m_hasQpcOrigin = false;
|
||||
|
||||
// Audio initialization started in the constructor, awaited in StartAsync.
|
||||
winrt::Windows::Foundation::IAsyncAction m_audioInitAction{ nullptr };
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,11 +18,37 @@
|
||||
#include <mfreadwrite.h>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include "BackgroundBlur.h"
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <winrt/base.h>
|
||||
|
||||
class BackgroundBlur;
|
||||
|
||||
// Must match CompositeConstants cbuffer layout in WebcamComposite.hlsl.
|
||||
struct GpuCompositeConstants
|
||||
{
|
||||
float CropOffsetX, CropOffsetY; // Camera crop UV offset
|
||||
float CropScaleX, CropScaleY; // Camera crop UV scale
|
||||
float Gamma; // Gamma correction exponent
|
||||
float CornerRadius; // Corner radius in output pixels
|
||||
float OutputW, OutputH; // Output dimensions
|
||||
UINT ShapeType; // 0=Square, 1=RoundedRect, 2=RoundedSquare, 3=Circle
|
||||
UINT HasMask; // 1 if mask texture valid
|
||||
float Pad[2];
|
||||
};
|
||||
|
||||
// Must match BlurConstants cbuffer layout in BoxBlurCS.hlsl.
|
||||
struct GpuBlurConstants
|
||||
{
|
||||
UINT Direction; // 0 = horizontal, 1 = vertical
|
||||
INT Radius; // Box blur radius in pixels
|
||||
UINT Width; // Image width
|
||||
UINT Height; // Image height
|
||||
};
|
||||
|
||||
class WebcamCapture
|
||||
{
|
||||
public:
|
||||
@@ -44,7 +70,10 @@ public:
|
||||
Position position,
|
||||
Size size,
|
||||
Shape shape,
|
||||
bool fullScreenRecording = false );
|
||||
bool fullScreenRecording = false,
|
||||
WebcamBackgroundMode backgroundMode = WebcamBackgroundMode::None,
|
||||
const wchar_t* backgroundImagePath = nullptr,
|
||||
int brightness = 50 );
|
||||
~WebcamCapture();
|
||||
|
||||
// Start/stop the capture thread.
|
||||
@@ -106,6 +135,19 @@ private:
|
||||
bool InitSourceReader();
|
||||
RECT ComputeDestRect() const;
|
||||
void ComputeOverlayDimensions();
|
||||
bool InitGpuComposite();
|
||||
bool GpuComposite( const UINT32* cameraPixels, UINT camW, UINT camH,
|
||||
const UINT32* blurPixels, UINT blurW, UINT blurH,
|
||||
const float* mask, UINT maskW, UINT maskH,
|
||||
UINT outW, UINT outH,
|
||||
UINT srcCropX, UINT srcCropY, UINT srcCropW, UINT srcCropH,
|
||||
float gamma, Shape shape, float cornerRadius,
|
||||
ID3D11ShaderResourceView* preBlurSRV = nullptr );
|
||||
|
||||
// GPU box blur: runs 4 compute-shader dispatches (H→V→H→V) on the
|
||||
// processing-resolution frame. The result stays GPU-resident in
|
||||
// m_blurPingPong[0] for direct use by GpuComposite.
|
||||
bool GpuBoxBlur( const UINT32* pixels, UINT width, UINT height, int radius );
|
||||
|
||||
winrt::com_ptr<ID3D11Device> m_d3dDevice;
|
||||
winrt::com_ptr<ID3D11DeviceContext> m_d3dContext;
|
||||
@@ -135,6 +177,7 @@ private:
|
||||
// Reusable frame buffer for the capture thread (avoids per-frame alloc).
|
||||
std::vector<BYTE> m_framePixels;
|
||||
std::vector<BYTE> m_scaledPixels;
|
||||
std::vector<BYTE> m_upscalePixels;
|
||||
|
||||
UINT m_overlayW = 0;
|
||||
UINT m_overlayH = 0;
|
||||
@@ -142,6 +185,11 @@ private:
|
||||
UINT m_camHeight = 0;
|
||||
RECT m_destRect = {};
|
||||
|
||||
// Brightness correction (user-controlled, fixed gamma LUT).
|
||||
int m_brightness = 50; // 0=dark, 50=neutral, 100=bright
|
||||
std::array<uint8_t, 256> m_gammaLUT = {}; // current LUT
|
||||
double m_lutGamma = 1.0; // gamma used for m_gammaLUT
|
||||
|
||||
// Output dimensions (recording output after crop+scale).
|
||||
UINT m_outputWidth = 0;
|
||||
UINT m_outputHeight = 0;
|
||||
@@ -163,8 +211,57 @@ private:
|
||||
std::condition_variable m_readyCV;
|
||||
bool m_firstFrameCaptured = false;
|
||||
|
||||
// Background processing.
|
||||
WebcamBackgroundMode m_backgroundMode = WebcamBackgroundMode::None;
|
||||
std::wstring m_backgroundImagePath;
|
||||
std::unique_ptr<BackgroundBlur> m_backgroundBlur;
|
||||
|
||||
// Debug counters for CompositeOnto logging.
|
||||
int m_compositeCount = 0;
|
||||
int m_lockFailCount = 0;
|
||||
int m_uploadCount = 0;
|
||||
|
||||
// ── GPU composite pipeline ──────────────────────────────
|
||||
// Separate D3D device for capture thread (avoids contention
|
||||
// with the recording session's device/context).
|
||||
winrt::com_ptr<ID3D11Device> m_gpuDevice;
|
||||
winrt::com_ptr<ID3D11DeviceContext> m_gpuContext;
|
||||
winrt::com_ptr<ID3D11VertexShader> m_compositeVS;
|
||||
winrt::com_ptr<ID3D11PixelShader> m_compositePS;
|
||||
winrt::com_ptr<ID3D11Buffer> m_compositeCB;
|
||||
winrt::com_ptr<ID3D11SamplerState> m_bilinearSampler;
|
||||
winrt::com_ptr<ID3D11RasterizerState> m_gpuRasterState;
|
||||
winrt::com_ptr<ID3D11BlendState> m_gpuBlendState;
|
||||
|
||||
// Input textures + SRVs (recreated when dimensions change).
|
||||
winrt::com_ptr<ID3D11Texture2D> m_gpuCameraTex;
|
||||
winrt::com_ptr<ID3D11ShaderResourceView> m_gpuCameraSRV;
|
||||
UINT m_gpuCameraW = 0, m_gpuCameraH = 0;
|
||||
|
||||
winrt::com_ptr<ID3D11Texture2D> m_gpuBlurTex;
|
||||
winrt::com_ptr<ID3D11ShaderResourceView> m_gpuBlurSRV;
|
||||
UINT m_gpuBlurW = 0, m_gpuBlurH = 0;
|
||||
|
||||
winrt::com_ptr<ID3D11Texture2D> m_gpuMaskTex;
|
||||
winrt::com_ptr<ID3D11ShaderResourceView> m_gpuMaskSRV;
|
||||
UINT m_gpuMaskW = 0, m_gpuMaskH = 0;
|
||||
|
||||
// Render target + staging for readback.
|
||||
winrt::com_ptr<ID3D11Texture2D> m_gpuRenderTarget;
|
||||
winrt::com_ptr<ID3D11RenderTargetView> m_gpuRTV;
|
||||
winrt::com_ptr<ID3D11Texture2D> m_gpuStaging;
|
||||
UINT m_gpuRTW = 0, m_gpuRTH = 0;
|
||||
|
||||
bool m_gpuCompositeReady = false;
|
||||
|
||||
// ── GPU box-blur compute pipeline ───────────────────────
|
||||
winrt::com_ptr<ID3D11ComputeShader> m_blurCS;
|
||||
winrt::com_ptr<ID3D11Buffer> m_blurCB;
|
||||
|
||||
// Ping-pong textures with SRV + UAV for blur passes.
|
||||
winrt::com_ptr<ID3D11Texture2D> m_blurPingPong[2];
|
||||
winrt::com_ptr<ID3D11ShaderResourceView> m_blurPingSRV[2];
|
||||
winrt::com_ptr<ID3D11UnorderedAccessView> m_blurPingUAV[2];
|
||||
UINT m_blurPPW = 0, m_blurPPH = 0;
|
||||
bool m_gpuBlurReady = false;
|
||||
};
|
||||
|
||||
143
src/modules/ZoomIt/ZoomIt/WebcamComposite.hlsl
Normal file
143
src/modules/ZoomIt/ZoomIt/WebcamComposite.hlsl
Normal file
@@ -0,0 +1,143 @@
|
||||
//==============================================================================
|
||||
//
|
||||
// WebcamComposite.hlsl
|
||||
//
|
||||
// GPU composite shader for webcam overlay.
|
||||
// Composites sharp foreground from full-resolution camera with
|
||||
// blurred background from processing-resolution blur buffer, using
|
||||
// a segmentation mask to blend between the two sources.
|
||||
//
|
||||
// The GPU's hardware texture sampler provides free bilinear filtering,
|
||||
// making this orders of magnitude faster than the equivalent CPU loop.
|
||||
//
|
||||
// Entry points:
|
||||
// VSMain (vs_5_0) — full-screen triangle, no vertex buffer needed
|
||||
// PSMain (ps_5_0) — composite camera + blur + mask + shape mask
|
||||
//
|
||||
// Recompile with:
|
||||
// fxc /T vs_5_0 /E VSMain /Fh WebcamCompositeVS.h /Vn g_WebcamCompositeVS WebcamComposite.hlsl
|
||||
// fxc /T ps_5_0 /E PSMain /Fh WebcamCompositePS.h /Vn g_WebcamCompositePS WebcamComposite.hlsl
|
||||
//
|
||||
// Copyright (C) Mark Russinovich
|
||||
// Sysinternals - www.sysinternals.com
|
||||
//
|
||||
//==============================================================================
|
||||
|
||||
// Camera frame at full resolution (e.g. 1920x1080), B8G8R8A8_UNORM.
|
||||
// Shader sees RGBA due to hardware swizzle.
|
||||
Texture2D CameraTex : register(t0);
|
||||
|
||||
// Blurred processing buffer at reduced resolution (e.g. 960x540), B8G8R8A8_UNORM.
|
||||
// Already gamma-corrected from CPU downsample.
|
||||
Texture2D BlurTex : register(t1);
|
||||
|
||||
// Segmentation mask from ONNX model, R32_FLOAT.
|
||||
// 1.0 = foreground (person), 0.0 = background.
|
||||
Texture2D MaskTex : register(t2);
|
||||
|
||||
// Bilinear sampler with clamp addressing — used for all textures.
|
||||
SamplerState BilinearSamp : register(s0);
|
||||
|
||||
cbuffer CompositeConstants : register(b0)
|
||||
{
|
||||
float2 CropOffset; // Camera crop UV offset (srcCropX/camW, srcCropY/camH)
|
||||
float2 CropScale; // Camera crop UV scale (srcCropW/camW, srcCropH/camH)
|
||||
float Gamma; // Gamma correction exponent (< 1 brightens)
|
||||
float CornerRadius; // Corner radius in output pixels
|
||||
float OutputW; // Output width in pixels
|
||||
float OutputH; // Output height in pixels
|
||||
uint ShapeType; // 0=Square, 1=RoundedRect, 2=RoundedSquare, 3=Circle
|
||||
uint HasMask; // 1 if segmentation mask is valid
|
||||
float2 Pad;
|
||||
};
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Position : SV_POSITION;
|
||||
float2 TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Vertex shader: full-screen triangle from SV_VertexID (no vertex buffer).
|
||||
// Draw(3, 0) to invoke. The triangle covers [-1,1] clip space.
|
||||
//----------------------------------------------------------------------------
|
||||
VSOutput VSMain( uint vertexId : SV_VertexID )
|
||||
{
|
||||
VSOutput output;
|
||||
output.TexCoord = float2( (vertexId << 1) & 2, vertexId & 2 );
|
||||
output.Position = float4( output.TexCoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0 );
|
||||
return output;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Pixel shader: composite camera foreground with blurred background.
|
||||
// - Shape masking (circle, rounded rect) produces alpha = 0 outside.
|
||||
// - Segmentation mask blends camera (foreground) with blur (background).
|
||||
// - Gamma correction applied to camera samples only (blur already corrected).
|
||||
// - Hardware bilinear filtering on all texture samples (free).
|
||||
//----------------------------------------------------------------------------
|
||||
float4 PSMain( VSOutput input ) : SV_TARGET
|
||||
{
|
||||
float2 uv = input.TexCoord;
|
||||
float px = uv.x * OutputW;
|
||||
float py = uv.y * OutputH;
|
||||
|
||||
// ── Shape mask ─────────────────────────────────────────────────────
|
||||
if( ShapeType == 3 ) // Circle
|
||||
{
|
||||
float halfW = OutputW * 0.5;
|
||||
float halfH = OutputH * 0.5;
|
||||
float radius = min( halfW, halfH );
|
||||
float dx = ( px - halfW ) / radius;
|
||||
float dy = ( py - halfH ) / radius;
|
||||
if( dx * dx + dy * dy > 1.0 )
|
||||
return float4( 0, 0, 0, 0 );
|
||||
}
|
||||
else if( ShapeType >= 1 ) // RoundedRect or RoundedSquare
|
||||
{
|
||||
float cx = 0, cy = 0;
|
||||
bool inCorner = false;
|
||||
|
||||
if( px < CornerRadius && py < CornerRadius )
|
||||
{ cx = CornerRadius; cy = CornerRadius; inCorner = true; }
|
||||
else if( px > OutputW - CornerRadius && py < CornerRadius )
|
||||
{ cx = OutputW - CornerRadius; cy = CornerRadius; inCorner = true; }
|
||||
else if( px < CornerRadius && py > OutputH - CornerRadius )
|
||||
{ cx = CornerRadius; cy = OutputH - CornerRadius; inCorner = true; }
|
||||
else if( px > OutputW - CornerRadius && py > OutputH - CornerRadius )
|
||||
{ cx = OutputW - CornerRadius; cy = OutputH - CornerRadius; inCorner = true; }
|
||||
|
||||
if( inCorner )
|
||||
{
|
||||
float ddx = px - cx;
|
||||
float ddy = py - cy;
|
||||
if( ddx * ddx + ddy * ddy > CornerRadius * CornerRadius )
|
||||
return float4( 0, 0, 0, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
// ── Composite ──────────────────────────────────────────────────────
|
||||
if( HasMask )
|
||||
{
|
||||
// Segmentation mask (bilinear-filtered for smooth edges).
|
||||
float mask = saturate( MaskTex.Sample( BilinearSamp, uv ).r );
|
||||
|
||||
// Camera: crop-to-fill UV mapping + gamma correction.
|
||||
float2 camUV = CropOffset + uv * CropScale;
|
||||
float4 cam = CameraTex.Sample( BilinearSamp, camUV );
|
||||
cam.rgb = pow( max( cam.rgb, 0.001 ), Gamma );
|
||||
|
||||
// Blur: already gamma-corrected from CPU downsample.
|
||||
float4 blur = BlurTex.Sample( BilinearSamp, uv );
|
||||
|
||||
// Blend: mask=1 → camera (foreground), mask=0 → blur (background).
|
||||
float3 result = lerp( blur.rgb, cam.rgb, mask );
|
||||
return float4( result, 1.0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// No segmentation mask — just display the processing buffer.
|
||||
float4 blur = BlurTex.Sample( BilinearSamp, uv );
|
||||
return float4( blur.rgb, 1.0 );
|
||||
}
|
||||
}
|
||||
616
src/modules/ZoomIt/ZoomIt/WebcamCompositePS.h
Normal file
616
src/modules/ZoomIt/ZoomIt/WebcamCompositePS.h
Normal file
@@ -0,0 +1,616 @@
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
|
||||
//
|
||||
//
|
||||
// Buffer Definitions:
|
||||
//
|
||||
// cbuffer CompositeConstants
|
||||
// {
|
||||
//
|
||||
// float2 CropOffset; // Offset: 0 Size: 8
|
||||
// float2 CropScale; // Offset: 8 Size: 8
|
||||
// float Gamma; // Offset: 16 Size: 4
|
||||
// float CornerRadius; // Offset: 20 Size: 4
|
||||
// float OutputW; // Offset: 24 Size: 4
|
||||
// float OutputH; // Offset: 28 Size: 4
|
||||
// uint ShapeType; // Offset: 32 Size: 4
|
||||
// uint HasMask; // Offset: 36 Size: 4
|
||||
// float2 Pad; // Offset: 40 Size: 8 [unused]
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// Resource Bindings:
|
||||
//
|
||||
// Name Type Format Dim HLSL Bind Count
|
||||
// ------------------------------ ---------- ------- ----------- -------------- ------
|
||||
// BilinearSamp sampler NA NA s0 1
|
||||
// CameraTex texture float4 2d t0 1
|
||||
// BlurTex texture float4 2d t1 1
|
||||
// MaskTex texture float4 2d t2 1
|
||||
// CompositeConstants cbuffer NA NA cb0 1
|
||||
//
|
||||
//
|
||||
//
|
||||
// Input signature:
|
||||
//
|
||||
// Name Index Mask Register SysValue Format Used
|
||||
// -------------------- ----- ------ -------- -------- ------- ------
|
||||
// SV_POSITION 0 xyzw 0 POS float
|
||||
// TEXCOORD 0 xy 1 NONE float xy
|
||||
//
|
||||
//
|
||||
// Output signature:
|
||||
//
|
||||
// Name Index Mask Register SysValue Format Used
|
||||
// -------------------- ----- ------ -------- -------- ------- ------
|
||||
// SV_TARGET 0 xyzw 0 TARGET float xyzw
|
||||
//
|
||||
ps_5_0
|
||||
dcl_globalFlags refactoringAllowed
|
||||
dcl_constantbuffer CB0[3], immediateIndexed
|
||||
dcl_sampler s0, mode_default
|
||||
dcl_resource_texture2d (float,float,float,float) t0
|
||||
dcl_resource_texture2d (float,float,float,float) t1
|
||||
dcl_resource_texture2d (float,float,float,float) t2
|
||||
dcl_input_ps linear v1.xy
|
||||
dcl_output o0.xyzw
|
||||
dcl_temps 4
|
||||
mul r0.xy, v1.xyxx, cb0[1].zwzz
|
||||
ieq r0.z, cb0[2].x, l(3)
|
||||
if_nz r0.z
|
||||
mul r0.zw, cb0[1].zzzw, l(0.000000, 0.000000, 0.500000, 0.500000)
|
||||
min r1.x, r0.w, r0.z
|
||||
mad r0.zw, v1.xxxy, cb0[1].zzzw, -r0.zzzw
|
||||
div r0.zw, r0.zzzw, r1.xxxx
|
||||
mul r0.zw, r0.zzzw, r0.zzzw
|
||||
add r0.z, r0.w, r0.z
|
||||
lt r0.z, l(1.000000), r0.z
|
||||
if_nz r0.z
|
||||
mov o0.xyzw, l(0,0,0,0)
|
||||
ret
|
||||
endif
|
||||
else
|
||||
uge r0.z, cb0[2].x, l(1)
|
||||
if_nz r0.z
|
||||
lt r0.zw, r0.yyyx, cb0[1].yyyy
|
||||
and r1.x, r0.z, r0.w
|
||||
add r2.xy, -cb0[1].yyyy, cb0[1].zwzz
|
||||
lt r0.xy, r2.xyxx, r0.xyxx
|
||||
and r0.zw, r0.zzzw, r0.xxxy
|
||||
and r3.z, r0.y, r0.x
|
||||
and r3.xy, r2.xyxx, r3.zzzz
|
||||
mov r2.z, cb0[1].y
|
||||
mov r2.w, l(-1)
|
||||
movc r0.xyw, r0.wwww, r2.zyzw, r3.xyxz
|
||||
movc r0.xyz, r0.zzzz, r2.xzwx, r0.xywx
|
||||
movc r0.xyz, r1.xxxx, r2.zzwz, r0.xyzx
|
||||
if_nz r0.z
|
||||
mad r0.xy, v1.xyxx, cb0[1].zwzz, -r0.xyxx
|
||||
mul r0.xy, r0.xyxx, r0.xyxx
|
||||
add r0.x, r0.y, r0.x
|
||||
mul r0.y, cb0[1].y, cb0[1].y
|
||||
lt r0.x, r0.y, r0.x
|
||||
if_nz r0.x
|
||||
mov o0.xyzw, l(0,0,0,0)
|
||||
ret
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
if_nz cb0[2].y
|
||||
sample_indexable(texture2d)(float,float,float,float) r0.x, v1.xyxx, t2.xyzw, s0
|
||||
mov_sat r0.x, r0.x
|
||||
mad r0.yz, v1.xxyx, cb0[0].zzwz, cb0[0].xxyx
|
||||
sample_indexable(texture2d)(float,float,float,float) r0.yzw, r0.yzyy, t0.wxyz, s0
|
||||
max r0.yzw, r0.yyzw, l(0.000000, 0.001000, 0.001000, 0.001000)
|
||||
log r0.yzw, r0.yyzw
|
||||
mul r0.yzw, r0.yyzw, cb0[1].xxxx
|
||||
exp r0.yzw, r0.yyzw
|
||||
sample_indexable(texture2d)(float,float,float,float) r1.xyz, v1.xyxx, t1.xyzw, s0
|
||||
add r0.yzw, r0.yyzw, -r1.xxyz
|
||||
mad o0.xyz, r0.xxxx, r0.yzwy, r1.xyzx
|
||||
mov o0.w, l(1.000000)
|
||||
ret
|
||||
else
|
||||
sample_indexable(texture2d)(float,float,float,float) r0.xyz, v1.xyxx, t1.xyzw, s0
|
||||
mov o0.xyz, r0.xyzx
|
||||
mov o0.w, l(1.000000)
|
||||
ret
|
||||
endif
|
||||
ret
|
||||
// Approximately 63 instruction slots used
|
||||
#endif
|
||||
|
||||
const BYTE g_WebcamCompositePS[] =
|
||||
{
|
||||
68, 88, 66, 67, 78, 221,
|
||||
134, 205, 221, 100, 55, 97,
|
||||
108, 36, 219, 137, 244, 189,
|
||||
76, 224, 1, 0, 0, 0,
|
||||
108, 11, 0, 0, 5, 0,
|
||||
0, 0, 52, 0, 0, 0,
|
||||
208, 3, 0, 0, 40, 4,
|
||||
0, 0, 92, 4, 0, 0,
|
||||
208, 10, 0, 0, 82, 68,
|
||||
69, 70, 148, 3, 0, 0,
|
||||
1, 0, 0, 0, 24, 1,
|
||||
0, 0, 5, 0, 0, 0,
|
||||
60, 0, 0, 0, 0, 5,
|
||||
255, 255, 0, 1, 0, 0,
|
||||
108, 3, 0, 0, 82, 68,
|
||||
49, 49, 60, 0, 0, 0,
|
||||
24, 0, 0, 0, 32, 0,
|
||||
0, 0, 40, 0, 0, 0,
|
||||
36, 0, 0, 0, 12, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
220, 0, 0, 0, 3, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 1, 0,
|
||||
0, 0, 233, 0, 0, 0,
|
||||
2, 0, 0, 0, 5, 0,
|
||||
0, 0, 4, 0, 0, 0,
|
||||
255, 255, 255, 255, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
13, 0, 0, 0, 243, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
5, 0, 0, 0, 4, 0,
|
||||
0, 0, 255, 255, 255, 255,
|
||||
1, 0, 0, 0, 1, 0,
|
||||
0, 0, 13, 0, 0, 0,
|
||||
251, 0, 0, 0, 2, 0,
|
||||
0, 0, 5, 0, 0, 0,
|
||||
4, 0, 0, 0, 255, 255,
|
||||
255, 255, 2, 0, 0, 0,
|
||||
1, 0, 0, 0, 13, 0,
|
||||
0, 0, 3, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
1, 0, 0, 0, 66, 105,
|
||||
108, 105, 110, 101, 97, 114,
|
||||
83, 97, 109, 112, 0, 67,
|
||||
97, 109, 101, 114, 97, 84,
|
||||
101, 120, 0, 66, 108, 117,
|
||||
114, 84, 101, 120, 0, 77,
|
||||
97, 115, 107, 84, 101, 120,
|
||||
0, 67, 111, 109, 112, 111,
|
||||
115, 105, 116, 101, 67, 111,
|
||||
110, 115, 116, 97, 110, 116,
|
||||
115, 0, 171, 171, 3, 1,
|
||||
0, 0, 9, 0, 0, 0,
|
||||
48, 1, 0, 0, 48, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 152, 2,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
8, 0, 0, 0, 2, 0,
|
||||
0, 0, 172, 2, 0, 0,
|
||||
0, 0, 0, 0, 255, 255,
|
||||
255, 255, 0, 0, 0, 0,
|
||||
255, 255, 255, 255, 0, 0,
|
||||
0, 0, 208, 2, 0, 0,
|
||||
8, 0, 0, 0, 8, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
172, 2, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 255, 255,
|
||||
255, 255, 0, 0, 0, 0,
|
||||
218, 2, 0, 0, 16, 0,
|
||||
0, 0, 4, 0, 0, 0,
|
||||
2, 0, 0, 0, 232, 2,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
255, 255, 255, 255, 0, 0,
|
||||
0, 0, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 12, 3,
|
||||
0, 0, 20, 0, 0, 0,
|
||||
4, 0, 0, 0, 2, 0,
|
||||
0, 0, 232, 2, 0, 0,
|
||||
0, 0, 0, 0, 255, 255,
|
||||
255, 255, 0, 0, 0, 0,
|
||||
255, 255, 255, 255, 0, 0,
|
||||
0, 0, 25, 3, 0, 0,
|
||||
24, 0, 0, 0, 4, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
232, 2, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 255, 255,
|
||||
255, 255, 0, 0, 0, 0,
|
||||
33, 3, 0, 0, 28, 0,
|
||||
0, 0, 4, 0, 0, 0,
|
||||
2, 0, 0, 0, 232, 2,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
255, 255, 255, 255, 0, 0,
|
||||
0, 0, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 41, 3,
|
||||
0, 0, 32, 0, 0, 0,
|
||||
4, 0, 0, 0, 2, 0,
|
||||
0, 0, 60, 3, 0, 0,
|
||||
0, 0, 0, 0, 255, 255,
|
||||
255, 255, 0, 0, 0, 0,
|
||||
255, 255, 255, 255, 0, 0,
|
||||
0, 0, 96, 3, 0, 0,
|
||||
36, 0, 0, 0, 4, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
60, 3, 0, 0, 0, 0,
|
||||
0, 0, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 255, 255,
|
||||
255, 255, 0, 0, 0, 0,
|
||||
104, 3, 0, 0, 40, 0,
|
||||
0, 0, 8, 0, 0, 0,
|
||||
0, 0, 0, 0, 172, 2,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
255, 255, 255, 255, 0, 0,
|
||||
0, 0, 255, 255, 255, 255,
|
||||
0, 0, 0, 0, 67, 114,
|
||||
111, 112, 79, 102, 102, 115,
|
||||
101, 116, 0, 102, 108, 111,
|
||||
97, 116, 50, 0, 171, 171,
|
||||
1, 0, 3, 0, 1, 0,
|
||||
2, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 163, 2, 0, 0,
|
||||
67, 114, 111, 112, 83, 99,
|
||||
97, 108, 101, 0, 71, 97,
|
||||
109, 109, 97, 0, 102, 108,
|
||||
111, 97, 116, 0, 171, 171,
|
||||
0, 0, 3, 0, 1, 0,
|
||||
1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 224, 2, 0, 0,
|
||||
67, 111, 114, 110, 101, 114,
|
||||
82, 97, 100, 105, 117, 115,
|
||||
0, 79, 117, 116, 112, 117,
|
||||
116, 87, 0, 79, 117, 116,
|
||||
112, 117, 116, 72, 0, 83,
|
||||
104, 97, 112, 101, 84, 121,
|
||||
112, 101, 0, 100, 119, 111,
|
||||
114, 100, 0, 171, 171, 171,
|
||||
0, 0, 19, 0, 1, 0,
|
||||
1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 51, 3, 0, 0,
|
||||
72, 97, 115, 77, 97, 115,
|
||||
107, 0, 80, 97, 100, 0,
|
||||
77, 105, 99, 114, 111, 115,
|
||||
111, 102, 116, 32, 40, 82,
|
||||
41, 32, 72, 76, 83, 76,
|
||||
32, 83, 104, 97, 100, 101,
|
||||
114, 32, 67, 111, 109, 112,
|
||||
105, 108, 101, 114, 32, 49,
|
||||
48, 46, 49, 0, 73, 83,
|
||||
71, 78, 80, 0, 0, 0,
|
||||
2, 0, 0, 0, 8, 0,
|
||||
0, 0, 56, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
0, 0, 0, 0, 15, 0,
|
||||
0, 0, 68, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
1, 0, 0, 0, 3, 3,
|
||||
0, 0, 83, 86, 95, 80,
|
||||
79, 83, 73, 84, 73, 79,
|
||||
78, 0, 84, 69, 88, 67,
|
||||
79, 79, 82, 68, 0, 171,
|
||||
171, 171, 79, 83, 71, 78,
|
||||
44, 0, 0, 0, 1, 0,
|
||||
0, 0, 8, 0, 0, 0,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
3, 0, 0, 0, 0, 0,
|
||||
0, 0, 15, 0, 0, 0,
|
||||
83, 86, 95, 84, 65, 82,
|
||||
71, 69, 84, 0, 171, 171,
|
||||
83, 72, 69, 88, 108, 6,
|
||||
0, 0, 80, 0, 0, 0,
|
||||
155, 1, 0, 0, 106, 8,
|
||||
0, 1, 89, 0, 0, 4,
|
||||
70, 142, 32, 0, 0, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
90, 0, 0, 3, 0, 96,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
88, 24, 0, 4, 0, 112,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
85, 85, 0, 0, 88, 24,
|
||||
0, 4, 0, 112, 16, 0,
|
||||
1, 0, 0, 0, 85, 85,
|
||||
0, 0, 88, 24, 0, 4,
|
||||
0, 112, 16, 0, 2, 0,
|
||||
0, 0, 85, 85, 0, 0,
|
||||
98, 16, 0, 3, 50, 16,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
101, 0, 0, 3, 242, 32,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
104, 0, 0, 2, 4, 0,
|
||||
0, 0, 56, 0, 0, 8,
|
||||
50, 0, 16, 0, 0, 0,
|
||||
0, 0, 70, 16, 16, 0,
|
||||
1, 0, 0, 0, 230, 138,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 32, 0,
|
||||
0, 8, 66, 0, 16, 0,
|
||||
0, 0, 0, 0, 10, 128,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
2, 0, 0, 0, 1, 64,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
31, 0, 4, 3, 42, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
56, 0, 0, 11, 194, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
166, 142, 32, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
2, 64, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 63, 0, 0,
|
||||
0, 63, 51, 0, 0, 7,
|
||||
18, 0, 16, 0, 1, 0,
|
||||
0, 0, 58, 0, 16, 0,
|
||||
0, 0, 0, 0, 42, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
50, 0, 0, 11, 194, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
6, 20, 16, 0, 1, 0,
|
||||
0, 0, 166, 142, 32, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 166, 14, 16, 128,
|
||||
65, 0, 0, 0, 0, 0,
|
||||
0, 0, 14, 0, 0, 7,
|
||||
194, 0, 16, 0, 0, 0,
|
||||
0, 0, 166, 14, 16, 0,
|
||||
0, 0, 0, 0, 6, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
56, 0, 0, 7, 194, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
166, 14, 16, 0, 0, 0,
|
||||
0, 0, 166, 14, 16, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 7, 66, 0, 16, 0,
|
||||
0, 0, 0, 0, 58, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
42, 0, 16, 0, 0, 0,
|
||||
0, 0, 49, 0, 0, 7,
|
||||
66, 0, 16, 0, 0, 0,
|
||||
0, 0, 1, 64, 0, 0,
|
||||
0, 0, 128, 63, 42, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
31, 0, 4, 3, 42, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
54, 0, 0, 8, 242, 32,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
2, 64, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 62, 0, 0, 1,
|
||||
21, 0, 0, 1, 18, 0,
|
||||
0, 1, 80, 0, 0, 8,
|
||||
66, 0, 16, 0, 0, 0,
|
||||
0, 0, 10, 128, 32, 0,
|
||||
0, 0, 0, 0, 2, 0,
|
||||
0, 0, 1, 64, 0, 0,
|
||||
1, 0, 0, 0, 31, 0,
|
||||
4, 3, 42, 0, 16, 0,
|
||||
0, 0, 0, 0, 49, 0,
|
||||
0, 8, 194, 0, 16, 0,
|
||||
0, 0, 0, 0, 86, 1,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
86, 133, 32, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
1, 0, 0, 7, 18, 0,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
42, 0, 16, 0, 0, 0,
|
||||
0, 0, 58, 0, 16, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 10, 50, 0, 16, 0,
|
||||
2, 0, 0, 0, 86, 133,
|
||||
32, 128, 65, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 230, 138, 32, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 49, 0, 0, 7,
|
||||
50, 0, 16, 0, 0, 0,
|
||||
0, 0, 70, 0, 16, 0,
|
||||
2, 0, 0, 0, 70, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 7, 194, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
166, 14, 16, 0, 0, 0,
|
||||
0, 0, 6, 4, 16, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 7, 66, 0, 16, 0,
|
||||
3, 0, 0, 0, 26, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
10, 0, 16, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 7,
|
||||
50, 0, 16, 0, 3, 0,
|
||||
0, 0, 70, 0, 16, 0,
|
||||
2, 0, 0, 0, 166, 10,
|
||||
16, 0, 3, 0, 0, 0,
|
||||
54, 0, 0, 6, 66, 0,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
26, 128, 32, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
54, 0, 0, 5, 130, 0,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
1, 64, 0, 0, 255, 255,
|
||||
255, 255, 55, 0, 0, 9,
|
||||
178, 0, 16, 0, 0, 0,
|
||||
0, 0, 246, 15, 16, 0,
|
||||
0, 0, 0, 0, 102, 14,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
70, 8, 16, 0, 3, 0,
|
||||
0, 0, 55, 0, 0, 9,
|
||||
114, 0, 16, 0, 0, 0,
|
||||
0, 0, 166, 10, 16, 0,
|
||||
0, 0, 0, 0, 134, 3,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
70, 3, 16, 0, 0, 0,
|
||||
0, 0, 55, 0, 0, 9,
|
||||
114, 0, 16, 0, 0, 0,
|
||||
0, 0, 6, 0, 16, 0,
|
||||
1, 0, 0, 0, 166, 11,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
70, 2, 16, 0, 0, 0,
|
||||
0, 0, 31, 0, 4, 3,
|
||||
42, 0, 16, 0, 0, 0,
|
||||
0, 0, 50, 0, 0, 11,
|
||||
50, 0, 16, 0, 0, 0,
|
||||
0, 0, 70, 16, 16, 0,
|
||||
1, 0, 0, 0, 230, 138,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 70, 0,
|
||||
16, 128, 65, 0, 0, 0,
|
||||
0, 0, 0, 0, 56, 0,
|
||||
0, 7, 50, 0, 16, 0,
|
||||
0, 0, 0, 0, 70, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
70, 0, 16, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 7,
|
||||
18, 0, 16, 0, 0, 0,
|
||||
0, 0, 26, 0, 16, 0,
|
||||
0, 0, 0, 0, 10, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
56, 0, 0, 9, 34, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
26, 128, 32, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
26, 128, 32, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
49, 0, 0, 7, 18, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
26, 0, 16, 0, 0, 0,
|
||||
0, 0, 10, 0, 16, 0,
|
||||
0, 0, 0, 0, 31, 0,
|
||||
4, 3, 10, 0, 16, 0,
|
||||
0, 0, 0, 0, 54, 0,
|
||||
0, 8, 242, 32, 16, 0,
|
||||
0, 0, 0, 0, 2, 64,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
62, 0, 0, 1, 21, 0,
|
||||
0, 1, 21, 0, 0, 1,
|
||||
21, 0, 0, 1, 21, 0,
|
||||
0, 1, 31, 0, 4, 4,
|
||||
26, 128, 32, 0, 0, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
69, 0, 0, 139, 194, 0,
|
||||
0, 128, 67, 85, 21, 0,
|
||||
18, 0, 16, 0, 0, 0,
|
||||
0, 0, 70, 16, 16, 0,
|
||||
1, 0, 0, 0, 70, 126,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
0, 96, 16, 0, 0, 0,
|
||||
0, 0, 54, 32, 0, 5,
|
||||
18, 0, 16, 0, 0, 0,
|
||||
0, 0, 10, 0, 16, 0,
|
||||
0, 0, 0, 0, 50, 0,
|
||||
0, 11, 98, 0, 16, 0,
|
||||
0, 0, 0, 0, 6, 17,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
166, 139, 32, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
6, 129, 32, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
69, 0, 0, 139, 194, 0,
|
||||
0, 128, 67, 85, 21, 0,
|
||||
226, 0, 16, 0, 0, 0,
|
||||
0, 0, 150, 5, 16, 0,
|
||||
0, 0, 0, 0, 54, 121,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
0, 96, 16, 0, 0, 0,
|
||||
0, 0, 52, 0, 0, 10,
|
||||
226, 0, 16, 0, 0, 0,
|
||||
0, 0, 86, 14, 16, 0,
|
||||
0, 0, 0, 0, 2, 64,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
111, 18, 131, 58, 111, 18,
|
||||
131, 58, 111, 18, 131, 58,
|
||||
47, 0, 0, 5, 226, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
86, 14, 16, 0, 0, 0,
|
||||
0, 0, 56, 0, 0, 8,
|
||||
226, 0, 16, 0, 0, 0,
|
||||
0, 0, 86, 14, 16, 0,
|
||||
0, 0, 0, 0, 6, 128,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 25, 0,
|
||||
0, 5, 226, 0, 16, 0,
|
||||
0, 0, 0, 0, 86, 14,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
69, 0, 0, 139, 194, 0,
|
||||
0, 128, 67, 85, 21, 0,
|
||||
114, 0, 16, 0, 1, 0,
|
||||
0, 0, 70, 16, 16, 0,
|
||||
1, 0, 0, 0, 70, 126,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
0, 96, 16, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 8,
|
||||
226, 0, 16, 0, 0, 0,
|
||||
0, 0, 86, 14, 16, 0,
|
||||
0, 0, 0, 0, 6, 9,
|
||||
16, 128, 65, 0, 0, 0,
|
||||
1, 0, 0, 0, 50, 0,
|
||||
0, 9, 114, 32, 16, 0,
|
||||
0, 0, 0, 0, 6, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
150, 7, 16, 0, 0, 0,
|
||||
0, 0, 70, 2, 16, 0,
|
||||
1, 0, 0, 0, 54, 0,
|
||||
0, 5, 130, 32, 16, 0,
|
||||
0, 0, 0, 0, 1, 64,
|
||||
0, 0, 0, 0, 128, 63,
|
||||
62, 0, 0, 1, 18, 0,
|
||||
0, 1, 69, 0, 0, 139,
|
||||
194, 0, 0, 128, 67, 85,
|
||||
21, 0, 114, 0, 16, 0,
|
||||
0, 0, 0, 0, 70, 16,
|
||||
16, 0, 1, 0, 0, 0,
|
||||
70, 126, 16, 0, 1, 0,
|
||||
0, 0, 0, 96, 16, 0,
|
||||
0, 0, 0, 0, 54, 0,
|
||||
0, 5, 114, 32, 16, 0,
|
||||
0, 0, 0, 0, 70, 2,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
54, 0, 0, 5, 130, 32,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
1, 64, 0, 0, 0, 0,
|
||||
128, 63, 62, 0, 0, 1,
|
||||
21, 0, 0, 1, 62, 0,
|
||||
0, 1, 83, 84, 65, 84,
|
||||
148, 0, 0, 0, 63, 0,
|
||||
0, 0, 4, 0, 0, 0,
|
||||
0, 0, 0, 0, 2, 0,
|
||||
0, 0, 23, 0, 0, 0,
|
||||
1, 0, 0, 0, 5, 0,
|
||||
0, 0, 7, 0, 0, 0,
|
||||
5, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
4, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 8, 0, 0, 0,
|
||||
3, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0
|
||||
};
|
||||
162
src/modules/ZoomIt/ZoomIt/WebcamCompositeVS.h
Normal file
162
src/modules/ZoomIt/ZoomIt/WebcamCompositeVS.h
Normal file
@@ -0,0 +1,162 @@
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
|
||||
//
|
||||
//
|
||||
//
|
||||
// Input signature:
|
||||
//
|
||||
// Name Index Mask Register SysValue Format Used
|
||||
// -------------------- ----- ------ -------- -------- ------- ------
|
||||
// SV_VertexID 0 x 0 VERTID uint x
|
||||
//
|
||||
//
|
||||
// Output signature:
|
||||
//
|
||||
// Name Index Mask Register SysValue Format Used
|
||||
// -------------------- ----- ------ -------- -------- ------- ------
|
||||
// SV_POSITION 0 xyzw 0 POS float xyzw
|
||||
// TEXCOORD 0 xy 1 NONE float xy
|
||||
//
|
||||
vs_5_0
|
||||
dcl_globalFlags refactoringAllowed
|
||||
dcl_input_sgv v0.x, vertex_id
|
||||
dcl_output_siv o0.xyzw, position
|
||||
dcl_output o1.xy
|
||||
dcl_temps 1
|
||||
bfi r0.x, l(1), l(1), v0.x, l(0)
|
||||
and r0.z, v0.x, l(2)
|
||||
utof r0.xy, r0.xzxx
|
||||
mad o0.xy, r0.xyxx, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000)
|
||||
mov o1.xy, r0.xyxx
|
||||
mov o0.zw, l(0,0,0,1.000000)
|
||||
ret
|
||||
// Approximately 7 instruction slots used
|
||||
#endif
|
||||
|
||||
const BYTE g_WebcamCompositeVS[] =
|
||||
{
|
||||
68, 88, 66, 67, 94, 195,
|
||||
253, 40, 165, 172, 45, 84,
|
||||
30, 136, 47, 40, 247, 112,
|
||||
58, 27, 1, 0, 0, 0,
|
||||
224, 2, 0, 0, 5, 0,
|
||||
0, 0, 52, 0, 0, 0,
|
||||
160, 0, 0, 0, 212, 0,
|
||||
0, 0, 44, 1, 0, 0,
|
||||
68, 2, 0, 0, 82, 68,
|
||||
69, 70, 100, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
60, 0, 0, 0, 0, 5,
|
||||
254, 255, 0, 1, 0, 0,
|
||||
60, 0, 0, 0, 82, 68,
|
||||
49, 49, 60, 0, 0, 0,
|
||||
24, 0, 0, 0, 32, 0,
|
||||
0, 0, 40, 0, 0, 0,
|
||||
36, 0, 0, 0, 12, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
77, 105, 99, 114, 111, 115,
|
||||
111, 102, 116, 32, 40, 82,
|
||||
41, 32, 72, 76, 83, 76,
|
||||
32, 83, 104, 97, 100, 101,
|
||||
114, 32, 67, 111, 109, 112,
|
||||
105, 108, 101, 114, 32, 49,
|
||||
48, 46, 49, 0, 73, 83,
|
||||
71, 78, 44, 0, 0, 0,
|
||||
1, 0, 0, 0, 8, 0,
|
||||
0, 0, 32, 0, 0, 0,
|
||||
0, 0, 0, 0, 6, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 1,
|
||||
0, 0, 83, 86, 95, 86,
|
||||
101, 114, 116, 101, 120, 73,
|
||||
68, 0, 79, 83, 71, 78,
|
||||
80, 0, 0, 0, 2, 0,
|
||||
0, 0, 8, 0, 0, 0,
|
||||
56, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
3, 0, 0, 0, 0, 0,
|
||||
0, 0, 15, 0, 0, 0,
|
||||
68, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
3, 0, 0, 0, 1, 0,
|
||||
0, 0, 3, 12, 0, 0,
|
||||
83, 86, 95, 80, 79, 83,
|
||||
73, 84, 73, 79, 78, 0,
|
||||
84, 69, 88, 67, 79, 79,
|
||||
82, 68, 0, 171, 171, 171,
|
||||
83, 72, 69, 88, 16, 1,
|
||||
0, 0, 80, 0, 1, 0,
|
||||
68, 0, 0, 0, 106, 8,
|
||||
0, 1, 96, 0, 0, 4,
|
||||
18, 16, 16, 0, 0, 0,
|
||||
0, 0, 6, 0, 0, 0,
|
||||
103, 0, 0, 4, 242, 32,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 101, 0,
|
||||
0, 3, 50, 32, 16, 0,
|
||||
1, 0, 0, 0, 104, 0,
|
||||
0, 2, 1, 0, 0, 0,
|
||||
140, 0, 0, 11, 18, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
1, 64, 0, 0, 1, 0,
|
||||
0, 0, 1, 64, 0, 0,
|
||||
1, 0, 0, 0, 10, 16,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
1, 64, 0, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 7,
|
||||
66, 0, 16, 0, 0, 0,
|
||||
0, 0, 10, 16, 16, 0,
|
||||
0, 0, 0, 0, 1, 64,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
86, 0, 0, 5, 50, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
134, 0, 16, 0, 0, 0,
|
||||
0, 0, 50, 0, 0, 15,
|
||||
50, 32, 16, 0, 0, 0,
|
||||
0, 0, 70, 0, 16, 0,
|
||||
0, 0, 0, 0, 2, 64,
|
||||
0, 0, 0, 0, 0, 64,
|
||||
0, 0, 0, 192, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
2, 64, 0, 0, 0, 0,
|
||||
128, 191, 0, 0, 128, 63,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 54, 0, 0, 5,
|
||||
50, 32, 16, 0, 1, 0,
|
||||
0, 0, 70, 0, 16, 0,
|
||||
0, 0, 0, 0, 54, 0,
|
||||
0, 8, 194, 32, 16, 0,
|
||||
0, 0, 0, 0, 2, 64,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 128, 63,
|
||||
62, 0, 0, 1, 83, 84,
|
||||
65, 84, 148, 0, 0, 0,
|
||||
7, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
3, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 2, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0
|
||||
};
|
||||
@@ -121,7 +121,7 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x0
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "OK",IDOK,184,308,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,241,308,50,14
|
||||
LTEXT "ZoomIt v12.0",IDC_VERSION,42,7,73,10
|
||||
LTEXT "ZoomIt v12.1",IDC_VERSION,42,7,73,10
|
||||
LTEXT "Copyright \251 2006-2026 Mark Russinovich",IDC_COPYRIGHT,42,17,251,8
|
||||
CONTROL "<a HREF=""https://www.sysinternals.com"">Sysinternals - www.sysinternals.com</a>",IDC_LINK,
|
||||
"SysLink",WS_TABSTOP,42,26,150,9
|
||||
@@ -267,33 +267,52 @@ RECORD DIALOGEX 0, 0, 263, 228
|
||||
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_SYSMENU
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
CONTROL "",IDC_RECORD_HOTKEY,"msctls_hotkey32",WS_BORDER | WS_TABSTOP,61,71,80,12
|
||||
LTEXT "Record Toggle:",IDC_STATIC,7,73,54,8
|
||||
CONTROL "",IDC_RECORD_HOTKEY,"msctls_hotkey32",WS_BORDER | WS_TABSTOP,65,59,80,12
|
||||
RTEXT "Record Toggle:",IDC_STATIC,7,62,54,8
|
||||
LTEXT "Record video of the unzoomed live screen or a static zoomed session by entering the recording hot key and finish the recording by entering it again. ",IDC_STATIC,7,7,248,22
|
||||
LTEXT "Scaling:",IDC_STATIC,30,90,26,8
|
||||
COMBOBOX IDC_RECORD_SCALING,61,89,26,30,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_OEMCONVERT | CBS_SORT | WS_VSCROLL | WS_TABSTOP
|
||||
CONTROL "16:9:",IDC_RECORD_ASPECT_RATIO,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,93,90,30,10
|
||||
LTEXT "Format:",IDC_STATIC,30,108,26,8
|
||||
COMBOBOX IDC_RECORD_FORMAT,61,106,60,30,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_OEMCONVERT | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Frame Rate:",IDC_STATIC,135,90,44,8,NOT WS_VISIBLE
|
||||
COMBOBOX IDC_RECORD_FRAME_RATE,182,89,42,30,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_OEMCONVERT | CBS_SORT | NOT WS_VISIBLE | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "To crop the portion of the screen that will be recorded, enter the hotkey with the Shift key in the opposite mode. ",IDC_STATIC,7,29,245,18
|
||||
LTEXT "To record a specific window, enter the hotkey with the Alt key in the opposite mode.",IDC_STATIC,7,48,251,19
|
||||
CONTROL "Capture &system audio",IDC_CAPTURE_SYSTEM_AUDIO,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,7,124,86,10
|
||||
CONTROL "&Capture audio input:",IDC_CAPTURE_AUDIO,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,125,124,83,10
|
||||
COMBOBOX IDC_MICROPHONE,81,137,128,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Microphone:",IDC_MICROPHONE_LABEL,34,139,47,8
|
||||
RTEXT "Scaling:",IDC_STATIC,36,79,26,8
|
||||
COMBOBOX IDC_RECORD_SCALING,65,78,26,30,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_OEMCONVERT | CBS_SORT | WS_VSCROLL | WS_TABSTOP
|
||||
CONTROL "16:9:",IDC_RECORD_ASPECT_RATIO,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,94,79,30,10
|
||||
RTEXT "Format:",IDC_STATIC,36,97,26,8
|
||||
COMBOBOX IDC_RECORD_FORMAT,65,96,60,30,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_OEMCONVERT | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Frame Rate:",IDC_STATIC,134,79,44,8,NOT WS_VISIBLE
|
||||
COMBOBOX IDC_RECORD_FRAME_RATE,177,78,42,30,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_OEMCONVERT | CBS_SORT | NOT WS_VISIBLE | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "To crop the portion of the screen that will be recorded, enter the hotkey with the Shift key in the opposite mode. ",IDC_STATIC,7,7,245,18
|
||||
LTEXT "To record a specific window, enter the hotkey with the Alt key in the opposite mode.",IDC_STATIC,7,38,251,19
|
||||
CONTROL "Capture &system audio:",IDC_CAPTURE_SYSTEM_AUDIO,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_RIGHT | WS_TABSTOP,7,115,90,10
|
||||
CONTROL "&Capture audio input:",IDC_CAPTURE_AUDIO,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_RIGHT | WS_TABSTOP,11,133,86,10
|
||||
CONTROL "Mono:",IDC_MIC_MONO_MIX,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_RIGHT | WS_TABSTOP,108,147,48,10
|
||||
COMBOBOX IDC_MICROPHONE,52,162,208,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Microphone:",IDC_MICROPHONE_LABEL,7,163,42,8
|
||||
CONTROL "&Noise cancellation:",IDC_NOISE_CANCELLATION,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_RIGHT | WS_TABSTOP,23,147,74,10
|
||||
CONTROL "Show &webcam overlay (Ctrl+C toggles)",IDC_WEBCAM_OVERLAY,
|
||||
"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,7,153,148,10
|
||||
LTEXT "Camera:",IDC_WEBCAM_DEVICE_LABEL,46,167,28,8
|
||||
COMBOBOX IDC_WEBCAM_DEVICE,82,165,127,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Position:",IDC_WEBCAM_POSITION_LABEL,33,185,32,8
|
||||
COMBOBOX IDC_WEBCAM_POSITION,64,183,55,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Size:",IDC_WEBCAM_SIZE_LABEL,137,185,20,8
|
||||
COMBOBOX IDC_WEBCAM_SIZE,159,183,50,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Shape:",IDC_WEBCAM_SHAPE_LABEL,33,201,24,8
|
||||
COMBOBOX IDC_WEBCAM_SHAPE,64,199,80,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
PUSHBUTTON "&Trim",IDC_TRIM_FILE,207,207,53,14
|
||||
"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,7,181,148,10
|
||||
PUSHBUTTON "Webcam S&ettings...",IDC_WEBCAM_SETTINGS,192,180,68,14
|
||||
PUSHBUTTON "&Trim",IDC_TRIM_FILE,207,209,53,14
|
||||
END
|
||||
|
||||
WEBCAM_SETTINGS DIALOGEX 0, 0, 220, 163
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Webcam Settings"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
LTEXT "Camera:",IDC_WEBCAM_DEVICE_LABEL,14,10,28,8
|
||||
COMBOBOX IDC_WEBCAM_DEVICE,50,8,158,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Position:",IDC_WEBCAM_POSITION_LABEL,14,28,32,8
|
||||
COMBOBOX IDC_WEBCAM_POSITION,50,26,65,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Size:",IDC_WEBCAM_SIZE_LABEL,125,28,20,8
|
||||
COMBOBOX IDC_WEBCAM_SIZE,148,26,60,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Shape:",IDC_WEBCAM_SHAPE_LABEL,14,46,24,8
|
||||
COMBOBOX IDC_WEBCAM_SHAPE,50,44,80,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Background:",IDC_WEBCAM_BG_LABEL,14,64,44,8
|
||||
COMBOBOX IDC_WEBCAM_BG_MODE,60,62,55,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
|
||||
EDITTEXT IDC_WEBCAM_BG_IMAGE,117,62,83,12,ES_AUTOHSCROLL | ES_READONLY
|
||||
PUSHBUTTON "...",IDC_WEBCAM_BG_BROWSE,202,62,14,12
|
||||
LTEXT "Brightness:",IDC_WEBCAM_BRIGHTNESS_LABEL,14,82,44,8
|
||||
CONTROL "",IDC_WEBCAM_BRIGHTNESS_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | TBS_NOTICKS | TBS_TOOLTIPS | WS_TABSTOP,60,80,148,15
|
||||
LTEXT "Uses MediaPipe SelfieSegmentation (Apache 2.0)",IDC_THIRDPARTY_NOTICES,14,102,200,8
|
||||
DEFPUSHBUTTON "OK",IDOK,108,142,50,14
|
||||
PUSHBUTTON "Cancel",IDCANCEL,162,142,50,14
|
||||
END
|
||||
|
||||
SNIP DIALOGEX 0, 0, 260, 80
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\..\common\version;$(MSBuildThisFileDirectory)PowerToys;$(InterPlatformDir)</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;windowscodecs.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<RandomizedBaseAddress>true</RandomizedBaseAddress>
|
||||
@@ -112,7 +112,7 @@
|
||||
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\..\common\version;$(MSBuildThisFileDirectory)PowerToys;$(MSBuildThisFileDirectory)..\ZoomItBreak\$(Platform)\$(Configuration)\</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;windowscodecs.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<RandomizedBaseAddress>true</RandomizedBaseAddress>
|
||||
@@ -135,7 +135,7 @@
|
||||
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\..\common\version;$(MSBuildThisFileDirectory)PowerToys;$(MSBuildThisFileDirectory)..\ZoomItBreak\$(Platform)\$(Configuration)\</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;windowscodecs.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<FixedBaseAddress>
|
||||
@@ -156,7 +156,7 @@
|
||||
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\..\common\version;$(MSBuildThisFileDirectory)PowerToys;$(InterPlatformDir)</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;windowscodecs.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<RandomizedBaseAddress>false</RandomizedBaseAddress>
|
||||
@@ -177,7 +177,7 @@
|
||||
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\..\common\version;$(MSBuildThisFileDirectory)PowerToys;$(MSBuildThisFileDirectory)..\ZoomItBreak\$(Platform)\$(Configuration)\</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;windowscodecs.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<UACUIAccess>true</UACUIAccess>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@@ -199,7 +199,7 @@
|
||||
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\..\common\version;$(MSBuildThisFileDirectory)PowerToys;$(MSBuildThisFileDirectory)..\ZoomItBreak\$(Platform)\$(Configuration)\</AdditionalIncludeDirectories>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>Shlwapi.lib;comctl32.lib;odbc32.lib;odbccp32.lib;version.lib;Winmm.lib;gdiplus.lib;Msimg32.lib;Wtsapi32.lib;windowscodecs.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<UACUIAccess>true</UACUIAccess>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@@ -257,6 +257,7 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GifRecordingSession.cpp" />
|
||||
<ClCompile Include="NoiseSuppressor.cpp" />
|
||||
<ClCompile Include="PanoramaCapture.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Use</PrecompiledHeader>
|
||||
@@ -266,6 +267,128 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Use</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="pch.cpp" />
|
||||
<ClCompile Include="rnnoise\celt_lpc.c">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">26451;4100;4091;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">26451;4100;4091;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">26451;4100;4091;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">26451;4100;4091;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">26451;4100;4091;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">26451;4100;4091;4245</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\denoise.c">
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">26451;4100;4091;4244;4245;4305</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">26451;4100;4091;4244;4245;4305</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">26451;4100;4091;4244;4245;4305</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">26451;4100;4091;4244;4245;4305</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">26451;4100;4091;4244;4245;4305</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">26451;4100;4091;4244;4245;4305</DisableSpecificWarnings>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\kiss_fft.c">
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\nnet.c">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\nnet_default.c">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\parse_lpcnet_weights.c">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\pitch.c">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">26451;4100;4091;4244;4245</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\rnn.c">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\rnnoise_data_little.c">
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">26451;4100;4091;4245;4305</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">26451;4100;4091;4245;4305</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">26451;4100;4091;4245;4305</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">26451;4100;4091;4245;4305</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">26451;4100;4091;4245;4305</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">26451;4100;4091;4245;4305</DisableSpecificWarnings>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\rnnoise_tables.c">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SelectRectangle.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Use</PrecompiledHeader>
|
||||
@@ -314,6 +437,14 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="BackgroundBlur.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="WebcamPreviewWindow.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
|
||||
@@ -338,16 +469,21 @@
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\common\sysinternals\Eula\Eula.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\ZoomItModuleInterface\Trace.h" />
|
||||
<ClInclude Include="GifRecordingSession.h" />
|
||||
<ClInclude Include="NoiseSuppressor.h" />
|
||||
<ClInclude Include="PanoramaCapture.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="Registry.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="rnnoise\nnet_arch.h" />
|
||||
<ClInclude Include="rnnoise\rnnoise.h" />
|
||||
<ClInclude Include="rnnoise\vec.h" />
|
||||
<ClInclude Include="SelectRectangle.h" />
|
||||
<ClInclude Include="Utility.h" />
|
||||
<ClInclude Include="DemoType.h" />
|
||||
<ClInclude Include="VersionHelper.h" />
|
||||
<ClInclude Include="VideoRecordingSession.h" />
|
||||
<ClInclude Include="WebcamCapture.h" />
|
||||
<ClInclude Include="BackgroundBlur.h" />
|
||||
<ClInclude Include="WebcamPreviewWindow.h" />
|
||||
<ClInclude Include="ZoomIt.h" />
|
||||
<ClInclude Include="ZoomItSettings.h" />
|
||||
|
||||
@@ -13,6 +13,12 @@
|
||||
<UniqueIdentifier>{e1fa606f-a2e6-40c8-8779-8ca1813d9f01}</UniqueIdentifier>
|
||||
<Extensions>ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\rnnoise">
|
||||
<UniqueIdentifier>{c1cc2820-c3a4-413d-b5d8-0d2034de2474}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\rnnoise">
|
||||
<UniqueIdentifier>{7795b908-e073-46ed-b209-c07ac0324adb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Zoomit.cpp">
|
||||
@@ -66,6 +72,48 @@
|
||||
<ClCompile Include="..\ZoomItBreak\BreakTimer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="BackgroundBlur.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="WebcamCapture.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="WebcamPreviewWindow.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\celt_lpc.c">
|
||||
<Filter>Source Files\rnnoise</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\denoise.c">
|
||||
<Filter>Source Files\rnnoise</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\kiss_fft.c">
|
||||
<Filter>Source Files\rnnoise</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\nnet.c">
|
||||
<Filter>Source Files\rnnoise</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\nnet_default.c">
|
||||
<Filter>Source Files\rnnoise</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\parse_lpcnet_weights.c">
|
||||
<Filter>Source Files\rnnoise</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\pitch.c">
|
||||
<Filter>Source Files\rnnoise</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\rnn.c">
|
||||
<Filter>Source Files\rnnoise</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\rnnoise_data_little.c">
|
||||
<Filter>Source Files\rnnoise</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="rnnoise\rnnoise_tables.c">
|
||||
<Filter>Source Files\rnnoise</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="NoiseSuppressor.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Registry.h">
|
||||
@@ -119,6 +167,27 @@
|
||||
<ClInclude Include="..\ZoomItBreak\BreakTimer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="BackgroundBlur.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="WebcamCapture.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="WebcamPreviewWindow.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="rnnoise\vec.h">
|
||||
<Filter>Header Files\rnnoise</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="rnnoise\nnet_arch.h">
|
||||
<Filter>Header Files\rnnoise</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="NoiseSuppressor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="rnnoise\rnnoise.h">
|
||||
<Filter>Header Files\rnnoise</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="appicon.ico">
|
||||
@@ -150,5 +219,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include="$(MSBuildThisFileDirectory)..\..\natvis\wil.natvis" />
|
||||
<Natvis Include="$(MSBuildThisFileDirectory)..\..\natvis\wil.natstepfilter" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -56,12 +56,16 @@ RecordingFormat g_RecordingFormat = RecordingFormat::MP4;
|
||||
BOOLEAN g_CaptureSystemAudio = TRUE;
|
||||
BOOLEAN g_CaptureAudio = FALSE;
|
||||
BOOLEAN g_MicMonoMix = FALSE;
|
||||
BOOLEAN g_NoiseCancellation = TRUE;
|
||||
TCHAR g_MicrophoneDeviceId[MAX_PATH] = {0};
|
||||
BOOLEAN g_WebcamOverlay = FALSE;
|
||||
DWORD g_WebcamPosition = 3; // 0=TL, 1=TR, 2=BL, 3=BR
|
||||
DWORD g_WebcamSize = 1; // 0=Small(15%), 1=Medium(25%), 2=Large(33%), 3=XLarge(50%)
|
||||
DWORD g_WebcamShape = 0; // 0=Square, 1=RoundedRect, 2=RoundedSquare, 3=Circle
|
||||
TCHAR g_WebcamDeviceSymLink[MAX_PATH] = {0};
|
||||
DWORD g_WebcamBackgroundMode = 0; // 0=None, 1=Blur, 2=Image
|
||||
TCHAR g_WebcamBackgroundImage[MAX_PATH] = {0};
|
||||
DWORD g_WebcamBrightness = 50; // 0=dark, 50=neutral, 100=bright
|
||||
BOOLEAN g_RecordAspectRatio = FALSE; // Lock region selection to 16:9
|
||||
TCHAR g_RecordingSaveLocationBuffer[MAX_PATH] = {0};
|
||||
TCHAR g_ScreenshotSaveLocationBuffer[MAX_PATH] = {0};
|
||||
@@ -116,11 +120,15 @@ REG_SETTING RegSettings[] = {
|
||||
{ L"CaptureSystemAudio", SETTING_TYPE_BOOLEAN, 0, &g_CaptureSystemAudio, static_cast<DOUBLE>(g_CaptureSystemAudio) },
|
||||
{ L"MicMonoMix", SETTING_TYPE_BOOLEAN, 0, &g_MicMonoMix, static_cast<DOUBLE>(g_MicMonoMix) },
|
||||
{ L"MicrophoneDeviceId", SETTING_TYPE_STRING, sizeof(g_MicrophoneDeviceId), g_MicrophoneDeviceId, static_cast<DOUBLE>(0) },
|
||||
{ L"NoiseCancellation", SETTING_TYPE_BOOLEAN, 0, &g_NoiseCancellation, static_cast<DOUBLE>(g_NoiseCancellation) },
|
||||
{ L"WebcamOverlay", SETTING_TYPE_BOOLEAN, 0, &g_WebcamOverlay, static_cast<DOUBLE>(g_WebcamOverlay) },
|
||||
{ L"WebcamPosition", SETTING_TYPE_DWORD, 0, &g_WebcamPosition, static_cast<DOUBLE>(g_WebcamPosition) },
|
||||
{ L"WebcamSize", SETTING_TYPE_DWORD, 0, &g_WebcamSize, static_cast<DOUBLE>(g_WebcamSize) },
|
||||
{ L"WebcamShape", SETTING_TYPE_DWORD, 0, &g_WebcamShape, static_cast<DOUBLE>(g_WebcamShape) },
|
||||
{ L"WebcamDeviceSymLink", SETTING_TYPE_STRING, sizeof(g_WebcamDeviceSymLink), g_WebcamDeviceSymLink, static_cast<DOUBLE>(0) },
|
||||
{ L"WebcamBackgroundMode", SETTING_TYPE_DWORD, 0, &g_WebcamBackgroundMode, static_cast<DOUBLE>(g_WebcamBackgroundMode) },
|
||||
{ L"WebcamBackgroundImage", SETTING_TYPE_STRING, sizeof(g_WebcamBackgroundImage), g_WebcamBackgroundImage, static_cast<DOUBLE>(0) },
|
||||
{ L"WebcamBrightness", SETTING_TYPE_DWORD, 0, &g_WebcamBrightness, static_cast<DOUBLE>(g_WebcamBrightness) },
|
||||
{ L"RecordAspectRatio", SETTING_TYPE_BOOLEAN, 0, &g_RecordAspectRatio, static_cast<DOUBLE>(g_RecordAspectRatio) },
|
||||
{ L"RecordingSaveLocation", SETTING_TYPE_STRING, sizeof(g_RecordingSaveLocationBuffer), g_RecordingSaveLocationBuffer, static_cast<DOUBLE>(0) },
|
||||
{ L"ScreenshotSaveLocation", SETTING_TYPE_STRING, sizeof(g_ScreenshotSaveLocationBuffer), g_ScreenshotSaveLocationBuffer, static_cast<DOUBLE>(0) },
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "PanoramaCapture.h"
|
||||
#include <wtsapi32.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __ZOOMIT_POWERTOYS__
|
||||
@@ -725,7 +724,7 @@ RunningOnWin64(
|
||||
// this executable.
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
BOOLEAN ExtractImageResource( PTCHAR ResourceName, PTCHAR TargetFile )
|
||||
BOOLEAN ExtractImageResource( PCTSTR ResourceName, PTCHAR TargetFile )
|
||||
{
|
||||
HRSRC hResource;
|
||||
HGLOBAL hImageResource;
|
||||
@@ -2835,6 +2834,323 @@ INT_PTR CALLBACK AdvancedBreakProc( HWND hDlg, UINT message, WPARAM wParam, LPAR
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
// WebcamSettingsProc
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
INT_PTR CALLBACK WebcamSettingsProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
|
||||
{
|
||||
static std::vector<std::pair<std::wstring, std::wstring>> webcams;
|
||||
static UINT currentDpi = DPI_BASELINE;
|
||||
static HWND s_hBrightnessTooltip = nullptr;
|
||||
|
||||
switch( message ) {
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
HICON hIcon = LoadIcon( g_hInstance, L"APPICON" );
|
||||
if( hIcon )
|
||||
{
|
||||
SendMessage( hDlg, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(hIcon) );
|
||||
SendMessage( hDlg, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(hIcon) );
|
||||
}
|
||||
|
||||
// Enumerate webcam devices
|
||||
webcams.clear();
|
||||
{
|
||||
MFStartup( MF_VERSION, MFSTARTUP_LITE );
|
||||
IMFAttributes* pAttributes = nullptr;
|
||||
if( SUCCEEDED( MFCreateAttributes( &pAttributes, 1 ) ) )
|
||||
{
|
||||
pAttributes->SetGUID( MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID );
|
||||
IMFActivate** ppDevices = nullptr;
|
||||
UINT32 count = 0;
|
||||
if( SUCCEEDED( MFEnumDeviceSources( pAttributes, &ppDevices, &count ) ) )
|
||||
{
|
||||
for( UINT32 i = 0; i < count; i++ )
|
||||
{
|
||||
LPWSTR symLink = nullptr, friendlyName = nullptr;
|
||||
UINT32 nameLen = 0;
|
||||
if( SUCCEEDED( ppDevices[i]->GetAllocatedString( MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &symLink, &nameLen ) ) &&
|
||||
SUCCEEDED( ppDevices[i]->GetAllocatedString( MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, &friendlyName, &nameLen ) ) )
|
||||
{
|
||||
webcams.emplace_back( symLink, friendlyName );
|
||||
}
|
||||
if( symLink ) CoTaskMemFree( symLink );
|
||||
if( friendlyName ) CoTaskMemFree( friendlyName );
|
||||
ppDevices[i]->Release();
|
||||
}
|
||||
CoTaskMemFree( ppDevices );
|
||||
}
|
||||
pAttributes->Release();
|
||||
}
|
||||
MFShutdown();
|
||||
}
|
||||
|
||||
// Populate camera combo
|
||||
SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_DEVICE ), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"Default") );
|
||||
{
|
||||
int selection = 0;
|
||||
for( size_t i = 0; i < webcams.size(); i++ )
|
||||
{
|
||||
SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_DEVICE ), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(webcams[i].second.c_str()) );
|
||||
if( selection == 0 && wcscmp( webcams[i].first.c_str(), g_WebcamDeviceSymLink ) == 0 )
|
||||
selection = static_cast<int>(i + 1);
|
||||
}
|
||||
SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_DEVICE ), CB_SETCURSEL, selection, 0 );
|
||||
}
|
||||
|
||||
// Populate position combo
|
||||
{
|
||||
const wchar_t* positions[] = { L"Top-left", L"Top-right", L"Bottom-left", L"Bottom-right" };
|
||||
for( int i = 0; i < 4; i++ )
|
||||
SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_POSITION ), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(positions[i]) );
|
||||
SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_POSITION ), CB_SETCURSEL, g_WebcamPosition, 0 );
|
||||
}
|
||||
|
||||
// Populate size combo
|
||||
{
|
||||
const wchar_t* sizes[] = { L"Small", L"Medium", L"Large", L"X-Large", L"Full screen" };
|
||||
for( int i = 0; i < 5; i++ )
|
||||
SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_SIZE ), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(sizes[i]) );
|
||||
SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_SIZE ), CB_SETCURSEL, g_WebcamSize, 0 );
|
||||
}
|
||||
|
||||
// Populate shape combo
|
||||
{
|
||||
const wchar_t* shapes[] = { L"Rectangle", L"Rounded Rectangle", L"Rounded Square", L"Circle" };
|
||||
for( int i = 0; i < 4; i++ )
|
||||
SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_SHAPE ), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(shapes[i]) );
|
||||
SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_SHAPE ), CB_SETCURSEL, g_WebcamShape, 0 );
|
||||
}
|
||||
|
||||
// Populate background mode combo
|
||||
{
|
||||
HWND hBgMode = GetDlgItem( hDlg, IDC_WEBCAM_BG_MODE );
|
||||
SendMessage( hBgMode, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"None") );
|
||||
SendMessage( hBgMode, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"Blur") );
|
||||
SendMessage( hBgMode, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"Image") );
|
||||
SendMessage( hBgMode, CB_SETCURSEL, g_WebcamBackgroundMode, 0 );
|
||||
SetDlgItemText( hDlg, IDC_WEBCAM_BG_IMAGE, g_WebcamBackgroundImage );
|
||||
}
|
||||
|
||||
// Initialize brightness slider
|
||||
{
|
||||
HWND hSlider = GetDlgItem( hDlg, IDC_WEBCAM_BRIGHTNESS_SLIDER );
|
||||
SendMessage( hSlider, TBM_SETRANGE, FALSE, MAKELONG( 0, 100 ) );
|
||||
SendMessage( hSlider, TBM_SETPOS, TRUE, g_WebcamBrightness );
|
||||
|
||||
// Place the built-in drag tooltip (TBS_TOOLTIPS) beneath the slider.
|
||||
SendMessage( hSlider, TBM_SETTIPSIDE, TBTS_BOTTOM, 0 );
|
||||
|
||||
// Hover tooltip that displays the current brightness when not dragging.
|
||||
// TTF_SUBCLASS lets the tooltip detect hover itself; LPSTR_TEXTCALLBACK
|
||||
// makes us supply the current value via TTN_GETDISPINFO.
|
||||
s_hBrightnessTooltip = CreateWindowEx(
|
||||
WS_EX_TOPMOST, TOOLTIPS_CLASS, nullptr,
|
||||
WS_POPUP | TTS_ALWAYSTIP | TTS_NOPREFIX,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
hDlg, nullptr, g_hInstance, nullptr );
|
||||
if( s_hBrightnessTooltip )
|
||||
{
|
||||
TOOLINFO ti = { sizeof(TOOLINFO) };
|
||||
ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
|
||||
ti.hwnd = hDlg;
|
||||
ti.uId = reinterpret_cast<UINT_PTR>(hSlider);
|
||||
ti.lpszText = LPSTR_TEXTCALLBACK;
|
||||
SendMessage( s_hBrightnessTooltip, TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&ti) );
|
||||
}
|
||||
}
|
||||
|
||||
// Set initial enabled state
|
||||
{
|
||||
bool isFullScreen = g_WebcamSize == 4;
|
||||
EnableWindow( GetDlgItem( hDlg, IDC_WEBCAM_SHAPE_LABEL ), !isFullScreen );
|
||||
EnableWindow( GetDlgItem( hDlg, IDC_WEBCAM_SHAPE ), !isFullScreen );
|
||||
bool isImageMode = g_WebcamBackgroundMode == 2;
|
||||
EnableWindow( GetDlgItem( hDlg, IDC_WEBCAM_BG_IMAGE ), isImageMode );
|
||||
EnableWindow( GetDlgItem( hDlg, IDC_WEBCAM_BG_BROWSE ), isImageMode );
|
||||
}
|
||||
|
||||
// DPI scaling
|
||||
currentDpi = GetDpiForWindowHelper( hDlg );
|
||||
if( currentDpi != DPI_BASELINE )
|
||||
ScaleDialogForDpi( hDlg, currentDpi, DPI_BASELINE );
|
||||
|
||||
ApplyDarkModeToDialog( hDlg );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_DPICHANGED:
|
||||
HandleDialogDpiChange( hDlg, wParam, lParam, currentDpi );
|
||||
return TRUE;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
if( IsDarkModeEnabled() )
|
||||
{
|
||||
HDC hdc = reinterpret_cast<HDC>(wParam);
|
||||
RECT rc;
|
||||
GetClientRect( hDlg, &rc );
|
||||
FillRect( hdc, &rc, GetDarkModeBrush() );
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CTLCOLORDLG:
|
||||
case WM_CTLCOLORSTATIC:
|
||||
case WM_CTLCOLORBTN:
|
||||
case WM_CTLCOLOREDIT:
|
||||
case WM_CTLCOLORLISTBOX:
|
||||
{
|
||||
HDC hdc = reinterpret_cast<HDC>(wParam);
|
||||
HWND hCtrl = reinterpret_cast<HWND>(lParam);
|
||||
HBRUSH hBrush = HandleDarkModeCtlColor( hdc, hCtrl, message );
|
||||
if( hBrush )
|
||||
return reinterpret_cast<INT_PTR>(hBrush);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_NOTIFY:
|
||||
{
|
||||
LPNMHDR pnmh = reinterpret_cast<LPNMHDR>(lParam);
|
||||
if( s_hBrightnessTooltip && pnmh->hwndFrom == s_hBrightnessTooltip )
|
||||
{
|
||||
if( pnmh->code == TTN_GETDISPINFO )
|
||||
{
|
||||
LPNMTTDISPINFO pdi = reinterpret_cast<LPNMTTDISPINFO>(lParam);
|
||||
static wchar_t buf[16];
|
||||
int pos = static_cast<int>(SendMessage(
|
||||
GetDlgItem( hDlg, IDC_WEBCAM_BRIGHTNESS_SLIDER ), TBM_GETPOS, 0, 0 ));
|
||||
_snwprintf_s( buf, _countof(buf), _TRUNCATE, L"%d", pos );
|
||||
pdi->lpszText = buf;
|
||||
return TRUE;
|
||||
}
|
||||
if( pnmh->code == TTN_SHOW )
|
||||
{
|
||||
// Reposition the tooltip directly beneath the slider, centered on the cursor.
|
||||
HWND hSlider = GetDlgItem( hDlg, IDC_WEBCAM_BRIGHTNESS_SLIDER );
|
||||
RECT rcSlider, rcTip;
|
||||
GetWindowRect( hSlider, &rcSlider );
|
||||
GetWindowRect( s_hBrightnessTooltip, &rcTip );
|
||||
POINT pt;
|
||||
GetCursorPos( &pt );
|
||||
int tipW = rcTip.right - rcTip.left;
|
||||
SetWindowPos( s_hBrightnessTooltip, HWND_TOPMOST,
|
||||
pt.x - tipW / 2, rcSlider.bottom + 4, 0, 0,
|
||||
SWP_NOSIZE | SWP_NOACTIVATE );
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_DESTROY:
|
||||
if( s_hBrightnessTooltip )
|
||||
{
|
||||
DestroyWindow( s_hBrightnessTooltip );
|
||||
s_hBrightnessTooltip = nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_COMMAND:
|
||||
// Handle size combo change — disable shape when Full screen
|
||||
if( HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_WEBCAM_SIZE )
|
||||
{
|
||||
bool isFullScreen = SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_SIZE ), CB_GETCURSEL, 0, 0 ) == 4;
|
||||
EnableWindow( GetDlgItem( hDlg, IDC_WEBCAM_SHAPE_LABEL ), !isFullScreen );
|
||||
EnableWindow( GetDlgItem( hDlg, IDC_WEBCAM_SHAPE ), !isFullScreen );
|
||||
}
|
||||
// Handle background mode combo change — show/hide browse controls
|
||||
if( HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_WEBCAM_BG_MODE )
|
||||
{
|
||||
bool isImageMode = SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_BG_MODE ), CB_GETCURSEL, 0, 0 ) == 2;
|
||||
EnableWindow( GetDlgItem( hDlg, IDC_WEBCAM_BG_IMAGE ), isImageMode );
|
||||
EnableWindow( GetDlgItem( hDlg, IDC_WEBCAM_BG_BROWSE ), isImageMode );
|
||||
}
|
||||
|
||||
switch( LOWORD(wParam) ) {
|
||||
case IDC_WEBCAM_BG_BROWSE:
|
||||
{
|
||||
auto openDialog = wil::CoCreateInstance<IFileOpenDialog>( CLSID_FileOpenDialog );
|
||||
|
||||
FILEOPENDIALOGOPTIONS options;
|
||||
if( SUCCEEDED( openDialog->GetOptions( &options ) ) )
|
||||
openDialog->SetOptions( options | FOS_FORCEFILESYSTEM );
|
||||
|
||||
COMDLG_FILTERSPEC fileTypes[] = {
|
||||
{ L"Bitmap Files (*.bmp;*.dib)", L"*.bmp;*.dib" },
|
||||
{ L"PNG (*.png)", L"*.png" },
|
||||
{ L"JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)", L"*.jpg;*.jpeg;*.jpe;*.jfif" },
|
||||
{ L"GIF (*.gif)", L"*.gif" },
|
||||
{ L"All Picture Files", L"*.bmp;*.dib;*.png;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif" },
|
||||
{ L"All Files", L"*.*" }
|
||||
};
|
||||
openDialog->SetFileTypes( _countof( fileTypes ), fileTypes );
|
||||
openDialog->SetFileTypeIndex( 5 );
|
||||
openDialog->SetTitle( L"ZoomIt: Specify Background Image..." );
|
||||
|
||||
TCHAR bgFilePath[MAX_PATH], bgInitDir[MAX_PATH];
|
||||
GetDlgItemText( hDlg, IDC_WEBCAM_BG_IMAGE, bgFilePath, _countof( bgFilePath ) );
|
||||
if( _tcsrchr( bgFilePath, '\\' ) )
|
||||
{
|
||||
_tcscpy( bgInitDir, bgFilePath );
|
||||
*( _tcsrchr( bgInitDir, '\\' ) + 1 ) = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_tcscpy( bgFilePath, L"%USERPROFILE%\\Pictures" );
|
||||
ExpandEnvironmentStrings( bgFilePath, bgInitDir, _countof( bgInitDir ) );
|
||||
}
|
||||
wil::com_ptr<IShellItem> folderItem;
|
||||
if( SUCCEEDED( SHCreateItemFromParsingName( bgInitDir, nullptr, IID_PPV_ARGS( &folderItem ) ) ) )
|
||||
openDialog->SetFolder( folderItem.get() );
|
||||
|
||||
OpenSaveDialogEvents* pEvents = new OpenSaveDialogEvents(false);
|
||||
DWORD dwCookie = 0;
|
||||
openDialog->Advise( pEvents, &dwCookie );
|
||||
|
||||
if( SUCCEEDED( openDialog->Show( hDlg ) ) )
|
||||
{
|
||||
wil::com_ptr<IShellItem> resultItem;
|
||||
if( SUCCEEDED( openDialog->GetResult( &resultItem ) ) )
|
||||
{
|
||||
wil::unique_cotaskmem_string pathStr;
|
||||
if( SUCCEEDED( resultItem->GetDisplayName( SIGDN_FILESYSPATH, &pathStr ) ) )
|
||||
SetDlgItemText( hDlg, IDC_WEBCAM_BG_IMAGE, pathStr.get() );
|
||||
}
|
||||
}
|
||||
|
||||
openDialog->Unadvise( dwCookie );
|
||||
pEvents->Release();
|
||||
break;
|
||||
}
|
||||
|
||||
case IDOK:
|
||||
g_WebcamPosition = static_cast<DWORD>(SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_POSITION ), CB_GETCURSEL, 0, 0 ));
|
||||
g_WebcamSize = static_cast<DWORD>(SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_SIZE ), CB_GETCURSEL, 0, 0 ));
|
||||
g_WebcamShape = static_cast<DWORD>(SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_SHAPE ), CB_GETCURSEL, 0, 0 ));
|
||||
g_WebcamBackgroundMode = static_cast<DWORD>(SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_BG_MODE ), CB_GETCURSEL, 0, 0 ));
|
||||
GetDlgItemText( hDlg, IDC_WEBCAM_BG_IMAGE, g_WebcamBackgroundImage, MAX_PATH );
|
||||
g_WebcamBrightness = static_cast<DWORD>(SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_BRIGHTNESS_SLIDER ), TBM_GETPOS, 0, 0 ));
|
||||
{
|
||||
int wcIndex = static_cast<int>(SendMessage( GetDlgItem( hDlg, IDC_WEBCAM_DEVICE ), CB_GETCURSEL, 0, 0 ));
|
||||
_tcscpy( g_WebcamDeviceSymLink, wcIndex == 0 ? L"" : webcams[static_cast<size_t>(wcIndex) - 1].first.c_str() );
|
||||
}
|
||||
reg.WriteRegSettings( RegSettings );
|
||||
EndDialog( hDlg, 0 );
|
||||
break;
|
||||
|
||||
case IDCANCEL:
|
||||
EndDialog( hDlg, 0 );
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
// OptionsTabProc
|
||||
@@ -2972,52 +3288,33 @@ INT_PTR CALLBACK OptionsTabProc( HWND hDlg, UINT message,
|
||||
// Enable/disable audio controls based on selection (GIF has no audio)
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_CAPTURE_SYSTEM_AUDIO), !isGifSelected);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_CAPTURE_AUDIO), !isGifSelected);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_NOISE_CANCELLATION), !isGifSelected);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_MIC_MONO_MIX), !isGifSelected);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_MICROPHONE_LABEL), !isGifSelected);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_MICROPHONE), !isGifSelected);
|
||||
|
||||
// Enable/disable webcam controls (webcam overlay is MP4-only).
|
||||
// Also keep everything disabled if no webcam is present.
|
||||
bool hasWebcam = SendMessage(GetDlgItem(hDlg, IDC_WEBCAM_DEVICE), CB_GETCOUNT, 0, 0) > 1;
|
||||
bool webcamEnabled = hasWebcam && !isGifSelected && IsDlgButtonChecked(hDlg, IDC_WEBCAM_OVERLAY) == BST_CHECKED;
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_OVERLAY), hasWebcam && !isGifSelected);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_DEVICE_LABEL), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_DEVICE), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_POSITION_LABEL), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_POSITION), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SIZE_LABEL), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SIZE), webcamEnabled);
|
||||
{
|
||||
bool isFullScreen = webcamEnabled && SendMessage(GetDlgItem(hDlg, IDC_WEBCAM_SIZE), CB_GETCURSEL, 0, 0) == 4;
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SHAPE_LABEL), webcamEnabled && !isFullScreen);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SHAPE), webcamEnabled && !isFullScreen);
|
||||
}
|
||||
// Enable/disable webcam overlay and settings button (webcam overlay is MP4-only).
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_OVERLAY), !isGifSelected);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SETTINGS), !isGifSelected && IsDlgButtonChecked(hDlg, IDC_WEBCAM_OVERLAY) == BST_CHECKED);
|
||||
}
|
||||
}
|
||||
if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_WEBCAM_OVERLAY) {
|
||||
bool isGif = (g_RecordingFormat == RecordingFormat::GIF);
|
||||
bool webcamEnabled = !isGif && IsDlgButtonChecked(hDlg, IDC_WEBCAM_OVERLAY) == BST_CHECKED;
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_DEVICE_LABEL), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_DEVICE), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_POSITION_LABEL), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_POSITION), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SIZE_LABEL), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SIZE), webcamEnabled);
|
||||
{
|
||||
bool isFullScreen = webcamEnabled && SendMessage(GetDlgItem(hDlg, IDC_WEBCAM_SIZE), CB_GETCURSEL, 0, 0) == 4;
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SHAPE_LABEL), webcamEnabled && !isFullScreen);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SHAPE), webcamEnabled && !isFullScreen);
|
||||
}
|
||||
bool webcamEnabled = IsDlgButtonChecked(hDlg, IDC_WEBCAM_OVERLAY) == BST_CHECKED;
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SETTINGS), webcamEnabled);
|
||||
}
|
||||
// Handle webcam size combo change — disable shape when Full screen selected
|
||||
if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_WEBCAM_SIZE) {
|
||||
bool isGif = (g_RecordingFormat == RecordingFormat::GIF);
|
||||
bool webcamEnabled = !isGif && IsDlgButtonChecked(hDlg, IDC_WEBCAM_OVERLAY) == BST_CHECKED;
|
||||
bool isFullScreen = SendMessage(GetDlgItem(hDlg, IDC_WEBCAM_SIZE), CB_GETCURSEL, 0, 0) == 4;
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SHAPE_LABEL), webcamEnabled && !isFullScreen);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_WEBCAM_SHAPE), webcamEnabled && !isFullScreen);
|
||||
if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_CAPTURE_AUDIO) {
|
||||
bool micEnabled = IsDlgButtonChecked(hDlg, IDC_CAPTURE_AUDIO) == BST_CHECKED;
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_NOISE_CANCELLATION), micEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_MIC_MONO_MIX), micEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_MICROPHONE_LABEL), micEnabled);
|
||||
EnableWindow(GetDlgItem(hDlg, IDC_MICROPHONE), micEnabled);
|
||||
|
||||
}
|
||||
|
||||
switch ( LOWORD( wParam )) {
|
||||
case IDC_WEBCAM_SETTINGS:
|
||||
DialogBox( g_hInstance, L"WEBCAM_SETTINGS", hDlg, WebcamSettingsProc );
|
||||
break;
|
||||
case IDC_ADVANCED_BREAK:
|
||||
DialogBox( g_hInstance, L"ADVANCED_BREAK", hDlg, AdvancedBreakProc );
|
||||
break;
|
||||
@@ -4577,7 +4874,6 @@ INT_PTR CALLBACK OptionsProc( HWND hDlg, UINT message,
|
||||
DWORD newDrawToggleKey, newDrawToggleMod, newBreakToggleMod, newDemoTypeToggleMod, newRecordToggleMod, newSnipToggleMod, newSnipPanoramaToggleMod, newSnipOcrToggleMod;
|
||||
DWORD newLiveZoomToggleKey, newLiveZoomToggleMod;
|
||||
static std::vector<std::pair<std::wstring, std::wstring>> microphones;
|
||||
static std::vector<std::pair<std::wstring, std::wstring>> webcams;
|
||||
|
||||
auto CleanupFonts = [&]()
|
||||
{
|
||||
@@ -4849,6 +5145,9 @@ INT_PTR CALLBACK OptionsProc( HWND hDlg, UINT message,
|
||||
CheckDlgButton( g_OptionsTabs[RECORD_PAGE].hPage, IDC_MIC_MONO_MIX,
|
||||
g_MicMonoMix ? BST_CHECKED: BST_UNCHECKED );
|
||||
|
||||
CheckDlgButton( g_OptionsTabs[RECORD_PAGE].hPage, IDC_NOISE_CANCELLATION,
|
||||
g_NoiseCancellation ? BST_CHECKED: BST_UNCHECKED );
|
||||
|
||||
CheckDlgButton( g_OptionsTabs[RECORD_PAGE].hPage, IDC_RECORD_ASPECT_RATIO,
|
||||
g_RecordAspectRatio ? BST_CHECKED: BST_UNCHECKED );
|
||||
|
||||
@@ -4924,101 +5223,19 @@ INT_PTR CALLBACK OptionsProc( HWND hDlg, UINT message,
|
||||
bool isGifSelected = (g_RecordingFormat == RecordingFormat::GIF);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_CAPTURE_SYSTEM_AUDIO), !isGifSelected);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_CAPTURE_AUDIO), !isGifSelected);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_MICROPHONE_LABEL), !isGifSelected);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_MICROPHONE), !isGifSelected);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_NOISE_CANCELLATION), !isGifSelected && g_CaptureAudio);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_MIC_MONO_MIX), !isGifSelected && g_CaptureAudio);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_MICROPHONE_LABEL), !isGifSelected && g_CaptureAudio);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_MICROPHONE), !isGifSelected && g_CaptureAudio);
|
||||
|
||||
// Webcam overlay controls
|
||||
CheckDlgButton( g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_OVERLAY,
|
||||
g_WebcamOverlay ? BST_CHECKED : BST_UNCHECKED );
|
||||
|
||||
// Enumerate webcam devices
|
||||
webcams.clear();
|
||||
// Set initial enabled state for webcam overlay and settings button
|
||||
{
|
||||
MFStartup( MF_VERSION, MFSTARTUP_LITE );
|
||||
IMFAttributes* pAttributes = nullptr;
|
||||
if( SUCCEEDED( MFCreateAttributes( &pAttributes, 1 ) ) )
|
||||
{
|
||||
pAttributes->SetGUID( MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID );
|
||||
IMFActivate** ppDevices = nullptr;
|
||||
UINT32 count = 0;
|
||||
if( SUCCEEDED( MFEnumDeviceSources( pAttributes, &ppDevices, &count ) ) )
|
||||
{
|
||||
for( UINT32 i = 0; i < count; i++ )
|
||||
{
|
||||
WCHAR* symLink = nullptr;
|
||||
UINT32 symLinkLen = 0;
|
||||
WCHAR* friendlyName = nullptr;
|
||||
UINT32 nameLen = 0;
|
||||
if( SUCCEEDED( ppDevices[i]->GetAllocatedString( MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &symLink, &symLinkLen ) ) &&
|
||||
SUCCEEDED( ppDevices[i]->GetAllocatedString( MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, &friendlyName, &nameLen ) ) )
|
||||
{
|
||||
webcams.emplace_back( symLink, friendlyName );
|
||||
}
|
||||
if( symLink ) CoTaskMemFree( symLink );
|
||||
if( friendlyName ) CoTaskMemFree( friendlyName );
|
||||
ppDevices[i]->Release();
|
||||
}
|
||||
CoTaskMemFree( ppDevices );
|
||||
}
|
||||
pAttributes->Release();
|
||||
}
|
||||
MFShutdown();
|
||||
}
|
||||
|
||||
// Add webcam devices to combo box
|
||||
SendMessage( GetDlgItem( g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_DEVICE ), static_cast<UINT>(CB_ADDSTRING), static_cast<WPARAM>(0), reinterpret_cast<LPARAM>(L"Default") );
|
||||
selection = 0;
|
||||
for( size_t i = 0; i < webcams.size(); i++ )
|
||||
{
|
||||
SendMessage( GetDlgItem( g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_DEVICE ), static_cast<UINT>(CB_ADDSTRING), static_cast<WPARAM>(0), reinterpret_cast<LPARAM>(webcams[i].second.c_str()) );
|
||||
if( selection == 0 && wcscmp( webcams[i].first.c_str(), g_WebcamDeviceSymLink ) == 0 )
|
||||
{
|
||||
selection = i + 1;
|
||||
}
|
||||
}
|
||||
SendMessage( GetDlgItem( g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_DEVICE ), CB_SETCURSEL, static_cast<WPARAM>(selection), static_cast<LPARAM>(0) );
|
||||
|
||||
// Webcam position combo
|
||||
{
|
||||
const wchar_t* positions[] = { L"Top left", L"Top right", L"Bottom left", L"Bottom right" };
|
||||
for( int i = 0; i < 4; i++ )
|
||||
SendMessage( GetDlgItem( g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_POSITION ), static_cast<UINT>(CB_ADDSTRING), static_cast<WPARAM>(0), reinterpret_cast<LPARAM>(positions[i]) );
|
||||
SendMessage( GetDlgItem( g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_POSITION ), CB_SETCURSEL, static_cast<WPARAM>(g_WebcamPosition), static_cast<LPARAM>(0) );
|
||||
}
|
||||
|
||||
// Webcam size combo
|
||||
{
|
||||
const wchar_t* sizes[] = { L"Small", L"Medium", L"Large", L"X-Large", L"Full screen" };
|
||||
for( int i = 0; i < 5; i++ )
|
||||
SendMessage( GetDlgItem( g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_SIZE ), static_cast<UINT>(CB_ADDSTRING), static_cast<WPARAM>(0), reinterpret_cast<LPARAM>(sizes[i]) );
|
||||
SendMessage( GetDlgItem( g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_SIZE ), CB_SETCURSEL, static_cast<WPARAM>(g_WebcamSize), static_cast<LPARAM>(0) );
|
||||
}
|
||||
|
||||
// Webcam shape combo
|
||||
{
|
||||
const wchar_t* shapes[] = { L"Rectangle", L"Rounded rectangle", L"Rounded square", L"Circle" };
|
||||
for( int i = 0; i < 4; i++ )
|
||||
SendMessage( GetDlgItem( g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_SHAPE ), static_cast<UINT>(CB_ADDSTRING), static_cast<WPARAM>(0), reinterpret_cast<LPARAM>(shapes[i]) );
|
||||
SendMessage( GetDlgItem( g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_SHAPE ), CB_SETCURSEL, static_cast<WPARAM>(g_WebcamShape), static_cast<LPARAM>(0) );
|
||||
}
|
||||
|
||||
// Set initial enabled state for webcam controls.
|
||||
// Disable everything if no webcam is detected on the system.
|
||||
{
|
||||
bool hasWebcam = !webcams.empty();
|
||||
bool webcamEnabled = hasWebcam && !isGifSelected && g_WebcamOverlay;
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_OVERLAY), hasWebcam && !isGifSelected);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_DEVICE_LABEL), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_DEVICE), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_POSITION_LABEL), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_POSITION), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_SIZE_LABEL), webcamEnabled);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_SIZE), webcamEnabled);
|
||||
{
|
||||
bool isFullScreen = webcamEnabled && g_WebcamSize == 4;
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_SHAPE_LABEL), webcamEnabled && !isFullScreen);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_SHAPE), webcamEnabled && !isFullScreen);
|
||||
}
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_OVERLAY), !isGifSelected);
|
||||
EnableWindow(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_SETTINGS), !isGifSelected && g_WebcamOverlay);
|
||||
}
|
||||
|
||||
if( GetFileAttributes( g_DemoTypeFile ) == -1 )
|
||||
@@ -5372,6 +5589,7 @@ INT_PTR CALLBACK OptionsProc( HWND hDlg, UINT message,
|
||||
g_CaptureSystemAudio = IsDlgButtonChecked(g_OptionsTabs[RECORD_PAGE].hPage, IDC_CAPTURE_SYSTEM_AUDIO) == BST_CHECKED;
|
||||
g_CaptureAudio = IsDlgButtonChecked(g_OptionsTabs[RECORD_PAGE].hPage, IDC_CAPTURE_AUDIO) == BST_CHECKED;
|
||||
g_MicMonoMix = IsDlgButtonChecked(g_OptionsTabs[RECORD_PAGE].hPage, IDC_MIC_MONO_MIX) == BST_CHECKED;
|
||||
g_NoiseCancellation = IsDlgButtonChecked(g_OptionsTabs[RECORD_PAGE].hPage, IDC_NOISE_CANCELLATION) == BST_CHECKED;
|
||||
g_RecordAspectRatio = IsDlgButtonChecked(g_OptionsTabs[RECORD_PAGE].hPage, IDC_RECORD_ASPECT_RATIO) == BST_CHECKED;
|
||||
GetDlgItemText( g_OptionsTabs[BREAK_PAGE].hPage, IDC_TIMER, text, 3 );
|
||||
text[2] = 0;
|
||||
@@ -5385,15 +5603,8 @@ INT_PTR CALLBACK OptionsProc( HWND hDlg, UINT message,
|
||||
int index = static_cast<int>(SendMessage( GetDlgItem( g_OptionsTabs[RECORD_PAGE].hPage, IDC_MICROPHONE ), static_cast<UINT>(CB_GETCURSEL), static_cast<WPARAM>(0), static_cast<LPARAM>(0) ));
|
||||
_tcscpy( g_MicrophoneDeviceId, index == 0 ? L"" : microphones[static_cast<size_t>(index) - 1].first.c_str() );
|
||||
|
||||
// Get the webcam settings
|
||||
// Get the webcam overlay setting (other webcam settings are saved in WebcamSettingsProc)
|
||||
g_WebcamOverlay = IsDlgButtonChecked(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_OVERLAY) == BST_CHECKED;
|
||||
g_WebcamPosition = static_cast<DWORD>(SendMessage(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_POSITION), CB_GETCURSEL, 0, 0));
|
||||
g_WebcamSize = static_cast<DWORD>(SendMessage(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_SIZE), CB_GETCURSEL, 0, 0));
|
||||
g_WebcamShape = static_cast<DWORD>(SendMessage(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_SHAPE), CB_GETCURSEL, 0, 0));
|
||||
{
|
||||
int wcIndex = static_cast<int>(SendMessage(GetDlgItem(g_OptionsTabs[RECORD_PAGE].hPage, IDC_WEBCAM_DEVICE), CB_GETCURSEL, 0, 0));
|
||||
_tcscpy( g_WebcamDeviceSymLink, wcIndex == 0 ? L"" : webcams[static_cast<size_t>(wcIndex) - 1].first.c_str() );
|
||||
}
|
||||
|
||||
if( newToggleKey && !RegisterHotKey( GetParent( hDlg ), ZOOM_HOTKEY, newToggleMod, newToggleKey & 0xFF )) {
|
||||
|
||||
@@ -6703,6 +6914,22 @@ winrt::fire_and_forget StartRecordingAsync( HWND hWnd, LPRECT rcCrop, HWND hWndR
|
||||
// Capture the UI thread context so we can resume on it for the save dialog
|
||||
winrt::apartment_context uiThread;
|
||||
|
||||
// Start audio initialization as early as possible. AudioGraph creation
|
||||
// and microphone device opening take ~1400 ms. By starting here, the
|
||||
// init runs in the background during D3D device creation, capture-item
|
||||
// creation, file I/O, and the entire VideoRecordingSession constructor
|
||||
// (webcam probe + warmup), giving it ~1400 ms of overlap — enough to
|
||||
// finish before StartAsync even needs the result.
|
||||
std::unique_ptr<AudioSampleGenerator> audioGenerator;
|
||||
winrt::Windows::Foundation::IAsyncAction audioInitAction{ nullptr };
|
||||
if ((g_RecordingFormat != RecordingFormat::GIF) && (g_CaptureAudio || g_CaptureSystemAudio))
|
||||
{
|
||||
audioGenerator = std::make_unique<AudioSampleGenerator>(
|
||||
g_CaptureAudio, g_CaptureSystemAudio, g_MicMonoMix, g_NoiseCancellation );
|
||||
audioInitAction = audioGenerator->InitializeAsync();
|
||||
_diagLog( L"audio InitializeAsync started (background)" );
|
||||
}
|
||||
|
||||
auto tempFolderPath = std::filesystem::temp_directory_path().wstring();
|
||||
auto tempFolder = co_await winrt::StorageFolder::GetFolderFromPathAsync( tempFolderPath );
|
||||
auto appFolder = co_await tempFolder.CreateFolderAsync( L"ZoomIt", winrt::CreationCollisionOption::OpenIfExists );
|
||||
@@ -6791,9 +7018,8 @@ winrt::fire_and_forget StartRecordingAsync( HWND hWnd, LPRECT rcCrop, HWND hWndR
|
||||
item,
|
||||
*rcCrop,
|
||||
g_RecordFrameRate,
|
||||
g_CaptureAudio,
|
||||
g_CaptureSystemAudio,
|
||||
g_MicMonoMix,
|
||||
std::move(audioGenerator),
|
||||
audioInitAction,
|
||||
stream );
|
||||
_diagLog( L"VideoRecordingSession::Create returned" );
|
||||
|
||||
|
||||
@@ -25,4 +25,7 @@ RCZOOMITSCR BINRES MOVEABLE PURE "ZoomItBreak64.scr"
|
||||
RCZOOMITSCR BINRES MOVEABLE PURE "ZoomItBreak64a.scr"
|
||||
#endif
|
||||
|
||||
// Embed the selfie segmentation ONNX model (platform-independent).
|
||||
RCSEGMODEL BINRES MOVEABLE PURE "selfie_segmentation.onnx"
|
||||
|
||||
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "ZoomIt.exe.manifest"
|
||||
|
||||
@@ -127,6 +127,16 @@
|
||||
#define IDC_WEBCAM_SHAPE_LABEL 1121
|
||||
#define IDC_TRIM_APPEND 1122
|
||||
#define IDC_RECORD_ASPECT_RATIO 1123
|
||||
#define IDC_WEBCAM_BACKGROUND_BLUR 1124
|
||||
#define IDC_WEBCAM_BG_LABEL 1125
|
||||
#define IDC_WEBCAM_BG_MODE 1126
|
||||
#define IDC_WEBCAM_BG_IMAGE 1127
|
||||
#define IDC_WEBCAM_BG_BROWSE 1128
|
||||
#define IDC_THIRDPARTY_NOTICES 1129
|
||||
#define IDC_WEBCAM_SETTINGS 1130
|
||||
#define IDC_WEBCAM_BRIGHTNESS_LABEL 1131
|
||||
#define IDC_WEBCAM_BRIGHTNESS_SLIDER 1132
|
||||
#define IDC_NOISE_CANCELLATION 1133
|
||||
#define IDC_SAVE 40002
|
||||
#define IDC_COPY 40004
|
||||
#define IDC_RECORD 40006
|
||||
@@ -142,7 +152,7 @@
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 120
|
||||
#define _APS_NEXT_COMMAND_VALUE 40015
|
||||
#define _APS_NEXT_CONTROL_VALUE 1124
|
||||
#define _APS_NEXT_CONTROL_VALUE 1134
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
|
||||
32
src/modules/ZoomIt/ZoomIt/rnnoise/COPYING
Normal file
32
src/modules/ZoomIt/ZoomIt/rnnoise/COPYING
Normal file
@@ -0,0 +1,32 @@
|
||||
Copyright (c) 2007-2017, 2024 Jean-Marc Valin
|
||||
Copyright (c) 2023 Amazon
|
||||
Copyright (c) 2017, Mozilla
|
||||
Copyright (c) 2005-2017, Xiph.Org Foundation
|
||||
Copyright (c) 2003-2004, Mark Borgerding
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of the Xiph.Org Foundation nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
182
src/modules/ZoomIt/ZoomIt/rnnoise/_kiss_fft_guts.h
Normal file
182
src/modules/ZoomIt/ZoomIt/rnnoise/_kiss_fft_guts.h
Normal file
@@ -0,0 +1,182 @@
|
||||
/*Copyright (c) 2003-2004, Mark Borgerding
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.*/
|
||||
|
||||
#ifndef KISS_FFT_GUTS_H
|
||||
#define KISS_FFT_GUTS_H
|
||||
|
||||
#define MIN(a,b) ((a)<(b) ? (a):(b))
|
||||
#define MAX(a,b) ((a)>(b) ? (a):(b))
|
||||
|
||||
/* kiss_fft.h
|
||||
defines kiss_fft_scalar as either short or a float type
|
||||
and defines
|
||||
typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */
|
||||
#include "kiss_fft.h"
|
||||
|
||||
/*
|
||||
Explanation of macros dealing with complex math:
|
||||
|
||||
C_MUL(m,a,b) : m = a*b
|
||||
C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise
|
||||
C_SUB( res, a,b) : res = a - b
|
||||
C_SUBFROM( res , a) : res -= a
|
||||
C_ADDTO( res , a) : res += a
|
||||
* */
|
||||
#ifdef FIXED_POINT
|
||||
#include "arch.h"
|
||||
|
||||
|
||||
#define SAMP_MAX 2147483647
|
||||
#define TWID_MAX 32767
|
||||
#define TRIG_UPSCALE 1
|
||||
|
||||
#define SAMP_MIN -SAMP_MAX
|
||||
|
||||
|
||||
# define S_MUL(a,b) MULT16_32_Q15(b, a)
|
||||
|
||||
# define C_MUL(m,a,b) \
|
||||
do{ (m).r = SUB32_ovflw(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \
|
||||
(m).i = ADD32_ovflw(S_MUL((a).r,(b).i) , S_MUL((a).i,(b).r)); }while(0)
|
||||
|
||||
# define C_MULC(m,a,b) \
|
||||
do{ (m).r = ADD32_ovflw(S_MUL((a).r,(b).r) , S_MUL((a).i,(b).i)); \
|
||||
(m).i = SUB32_ovflw(S_MUL((a).i,(b).r) , S_MUL((a).r,(b).i)); }while(0)
|
||||
|
||||
# define C_MULBYSCALAR( c, s ) \
|
||||
do{ (c).r = S_MUL( (c).r , s ) ;\
|
||||
(c).i = S_MUL( (c).i , s ) ; }while(0)
|
||||
|
||||
# define DIVSCALAR(x,k) \
|
||||
(x) = S_MUL( x, (TWID_MAX-((k)>>1))/(k)+1 )
|
||||
|
||||
# define C_FIXDIV(c,div) \
|
||||
do { DIVSCALAR( (c).r , div); \
|
||||
DIVSCALAR( (c).i , div); }while (0)
|
||||
|
||||
#define C_ADD( res, a,b)\
|
||||
do {(res).r=ADD32_ovflw((a).r,(b).r); (res).i=ADD32_ovflw((a).i,(b).i); \
|
||||
}while(0)
|
||||
#define C_SUB( res, a,b)\
|
||||
do {(res).r=SUB32_ovflw((a).r,(b).r); (res).i=SUB32_ovflw((a).i,(b).i); \
|
||||
}while(0)
|
||||
#define C_ADDTO( res , a)\
|
||||
do {(res).r = ADD32_ovflw((res).r, (a).r); (res).i = ADD32_ovflw((res).i,(a).i);\
|
||||
}while(0)
|
||||
|
||||
#define C_SUBFROM( res , a)\
|
||||
do {(res).r = ADD32_ovflw((res).r,(a).r); (res).i = SUB32_ovflw((res).i,(a).i); \
|
||||
}while(0)
|
||||
|
||||
#if defined(OPUS_ARM_INLINE_ASM)
|
||||
#include "arm/kiss_fft_armv4.h"
|
||||
#endif
|
||||
|
||||
#if defined(OPUS_ARM_INLINE_EDSP)
|
||||
#include "arm/kiss_fft_armv5e.h"
|
||||
#endif
|
||||
#if defined(MIPSr1_ASM)
|
||||
#include "mips/kiss_fft_mipsr1.h"
|
||||
#endif
|
||||
|
||||
#else /* not FIXED_POINT*/
|
||||
|
||||
# define S_MUL(a,b) ( (a)*(b) )
|
||||
#define C_MUL(m,a,b) \
|
||||
do{ (m).r = (a).r*(b).r - (a).i*(b).i;\
|
||||
(m).i = (a).r*(b).i + (a).i*(b).r; }while(0)
|
||||
#define C_MULC(m,a,b) \
|
||||
do{ (m).r = (a).r*(b).r + (a).i*(b).i;\
|
||||
(m).i = (a).i*(b).r - (a).r*(b).i; }while(0)
|
||||
|
||||
#define C_MUL4(m,a,b) C_MUL(m,a,b)
|
||||
|
||||
# define C_FIXDIV(c,div) /* NOOP */
|
||||
# define C_MULBYSCALAR( c, s ) \
|
||||
do{ (c).r *= (s);\
|
||||
(c).i *= (s); }while(0)
|
||||
#endif
|
||||
|
||||
#ifndef CHECK_OVERFLOW_OP
|
||||
# define CHECK_OVERFLOW_OP(a,op,b) /* noop */
|
||||
#endif
|
||||
|
||||
#ifndef C_ADD
|
||||
#define C_ADD( res, a,b)\
|
||||
do { \
|
||||
CHECK_OVERFLOW_OP((a).r,+,(b).r)\
|
||||
CHECK_OVERFLOW_OP((a).i,+,(b).i)\
|
||||
(res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \
|
||||
}while(0)
|
||||
#define C_SUB( res, a,b)\
|
||||
do { \
|
||||
CHECK_OVERFLOW_OP((a).r,-,(b).r)\
|
||||
CHECK_OVERFLOW_OP((a).i,-,(b).i)\
|
||||
(res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \
|
||||
}while(0)
|
||||
#define C_ADDTO( res , a)\
|
||||
do { \
|
||||
CHECK_OVERFLOW_OP((res).r,+,(a).r)\
|
||||
CHECK_OVERFLOW_OP((res).i,+,(a).i)\
|
||||
(res).r += (a).r; (res).i += (a).i;\
|
||||
}while(0)
|
||||
|
||||
#define C_SUBFROM( res , a)\
|
||||
do {\
|
||||
CHECK_OVERFLOW_OP((res).r,-,(a).r)\
|
||||
CHECK_OVERFLOW_OP((res).i,-,(a).i)\
|
||||
(res).r -= (a).r; (res).i -= (a).i; \
|
||||
}while(0)
|
||||
#endif /* C_ADD defined */
|
||||
|
||||
#ifdef FIXED_POINT
|
||||
/*# define KISS_FFT_COS(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * cos (phase))))
|
||||
# define KISS_FFT_SIN(phase) TRIG_UPSCALE*floor(MIN(32767,MAX(-32767,.5+32768 * sin (phase))))*/
|
||||
# define KISS_FFT_COS(phase) floor(.5+TWID_MAX*cos (phase))
|
||||
# define KISS_FFT_SIN(phase) floor(.5+TWID_MAX*sin (phase))
|
||||
# define HALF_OF(x) ((x)>>1)
|
||||
#elif defined(USE_SIMD)
|
||||
# define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) )
|
||||
# define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) )
|
||||
# define HALF_OF(x) ((x)*_mm_set1_ps(.5f))
|
||||
#else
|
||||
# define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase)
|
||||
# define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase)
|
||||
# define HALF_OF(x) ((x)*.5f)
|
||||
#endif
|
||||
|
||||
#define kf_cexp(x,phase) \
|
||||
do{ \
|
||||
(x)->r = KISS_FFT_COS(phase);\
|
||||
(x)->i = KISS_FFT_SIN(phase);\
|
||||
}while(0)
|
||||
|
||||
#define kf_cexp2(x,phase) \
|
||||
do{ \
|
||||
(x)->r = TRIG_UPSCALE*celt_cos_norm((phase));\
|
||||
(x)->i = TRIG_UPSCALE*celt_cos_norm((phase)-32768);\
|
||||
}while(0)
|
||||
|
||||
#endif /* KISS_FFT_GUTS_H */
|
||||
261
src/modules/ZoomIt/ZoomIt/rnnoise/arch.h
Normal file
261
src/modules/ZoomIt/ZoomIt/rnnoise/arch.h
Normal file
@@ -0,0 +1,261 @@
|
||||
/* Copyright (c) 2003-2008 Jean-Marc Valin
|
||||
Copyright (c) 2007-2008 CSIRO
|
||||
Copyright (c) 2007-2009 Xiph.Org Foundation
|
||||
Written by Jean-Marc Valin */
|
||||
/**
|
||||
@file arch.h
|
||||
@brief Various architecture definitions for CELT
|
||||
*/
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ARCH_H
|
||||
#define ARCH_H
|
||||
|
||||
#include "opus_types.h"
|
||||
#include "common.h"
|
||||
|
||||
# if !defined(__GNUC_PREREQ)
|
||||
# if defined(__GNUC__)&&defined(__GNUC_MINOR__)
|
||||
# define __GNUC_PREREQ(_maj,_min) \
|
||||
((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
|
||||
# else
|
||||
# define __GNUC_PREREQ(_maj,_min) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#define CELT_SIG_SCALE 32768.f
|
||||
|
||||
#define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__);
|
||||
#ifdef ENABLE_ASSERTIONS
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef __GNUC__
|
||||
__attribute__((noreturn))
|
||||
#endif
|
||||
static OPUS_INLINE void _celt_fatal(const char *str, const char *file, int line)
|
||||
{
|
||||
fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
|
||||
abort();
|
||||
}
|
||||
#define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}}
|
||||
#define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}}
|
||||
#else
|
||||
#define celt_assert(cond)
|
||||
#define celt_assert2(cond, message)
|
||||
#endif
|
||||
|
||||
#define IMUL32(a,b) ((a)*(b))
|
||||
|
||||
#define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 16-bit value. */
|
||||
#define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */
|
||||
#define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 32-bit value. */
|
||||
#define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */
|
||||
#define IMIN(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum int value. */
|
||||
#define IMAX(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum int value. */
|
||||
#define UADD32(a,b) ((a)+(b))
|
||||
#define USUB32(a,b) ((a)-(b))
|
||||
|
||||
/* Set this if opus_int64 is a native type of the CPU. */
|
||||
/* Assume that all LP64 architectures have fast 64-bit types; also x86_64
|
||||
(which can be ILP32 for x32) and Win64 (which is LLP64). */
|
||||
#if defined(__x86_64__) || defined(__LP64__) || defined(_WIN64)
|
||||
#define OPUS_FAST_INT64 1
|
||||
#else
|
||||
#define OPUS_FAST_INT64 0
|
||||
#endif
|
||||
|
||||
#define PRINT_MIPS(file)
|
||||
|
||||
#ifdef FIXED_POINT
|
||||
|
||||
typedef opus_int16 opus_val16;
|
||||
typedef opus_int32 opus_val32;
|
||||
typedef opus_int64 opus_val64;
|
||||
|
||||
typedef opus_val32 celt_sig;
|
||||
typedef opus_val16 celt_norm;
|
||||
typedef opus_val32 celt_ener;
|
||||
|
||||
#define Q15ONE 32767
|
||||
|
||||
#define SIG_SHIFT 12
|
||||
/* Safe saturation value for 32-bit signals. Should be less than
|
||||
2^31*(1-0.85) to avoid blowing up on DC at deemphasis.*/
|
||||
#define SIG_SAT (300000000)
|
||||
|
||||
#define NORM_SCALING 16384
|
||||
|
||||
#define DB_SHIFT 10
|
||||
|
||||
#define EPSILON 1
|
||||
#define VERY_SMALL 0
|
||||
#define VERY_LARGE16 ((opus_val16)32767)
|
||||
#define Q15_ONE ((opus_val16)32767)
|
||||
|
||||
#define SCALEIN(a) (a)
|
||||
#define SCALEOUT(a) (a)
|
||||
|
||||
#define ABS16(x) ((x) < 0 ? (-(x)) : (x))
|
||||
#define ABS32(x) ((x) < 0 ? (-(x)) : (x))
|
||||
|
||||
static OPUS_INLINE opus_int16 SAT16(opus_int32 x) {
|
||||
return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x;
|
||||
}
|
||||
|
||||
#ifdef FIXED_DEBUG
|
||||
#include "fixed_debug.h"
|
||||
#else
|
||||
|
||||
#include "fixed_generic.h"
|
||||
|
||||
#ifdef OPUS_ARM_PRESUME_AARCH64_NEON_INTR
|
||||
#include "arm/fixed_arm64.h"
|
||||
#elif OPUS_ARM_INLINE_EDSP
|
||||
#include "arm/fixed_armv5e.h"
|
||||
#elif defined (OPUS_ARM_INLINE_ASM)
|
||||
#include "arm/fixed_armv4.h"
|
||||
#elif defined (BFIN_ASM)
|
||||
#include "fixed_bfin.h"
|
||||
#elif defined (TI_C5X_ASM)
|
||||
#include "fixed_c5x.h"
|
||||
#elif defined (TI_C6X_ASM)
|
||||
#include "fixed_c6x.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#else /* FIXED_POINT */
|
||||
|
||||
typedef float opus_val16;
|
||||
typedef float opus_val32;
|
||||
typedef float opus_val64;
|
||||
|
||||
typedef float celt_sig;
|
||||
typedef float celt_norm;
|
||||
typedef float celt_ener;
|
||||
|
||||
#ifdef FLOAT_APPROX
|
||||
/* This code should reliably detect NaN/inf even when -ffast-math is used.
|
||||
Assumes IEEE 754 format. */
|
||||
static OPUS_INLINE int celt_isnan(float x)
|
||||
{
|
||||
union {float f; opus_uint32 i;} in;
|
||||
in.f = x;
|
||||
return ((in.i>>23)&0xFF)==0xFF && (in.i&0x007FFFFF)!=0;
|
||||
}
|
||||
#else
|
||||
#ifdef __FAST_MATH__
|
||||
#error Cannot build libopus with -ffast-math unless FLOAT_APPROX is defined. This could result in crashes on extreme (e.g. NaN) input
|
||||
#endif
|
||||
#define celt_isnan(x) ((x)!=(x))
|
||||
#endif
|
||||
|
||||
#define Q15ONE 1.0f
|
||||
|
||||
#define NORM_SCALING 1.f
|
||||
|
||||
#define EPSILON 1e-15f
|
||||
#define VERY_SMALL 1e-30f
|
||||
#define VERY_LARGE16 1e15f
|
||||
#define Q15_ONE ((opus_val16)1.f)
|
||||
|
||||
/* This appears to be the same speed as C99's fabsf() but it's more portable. */
|
||||
#define ABS16(x) ((float)fabs(x))
|
||||
#define ABS32(x) ((float)fabs(x))
|
||||
|
||||
#define QCONST16(x,bits) (x)
|
||||
#define QCONST32(x,bits) (x)
|
||||
|
||||
#define NEG16(x) (-(x))
|
||||
#define NEG32(x) (-(x))
|
||||
#define NEG32_ovflw(x) (-(x))
|
||||
#define EXTRACT16(x) (x)
|
||||
#define EXTEND32(x) (x)
|
||||
#define SHR16(a,shift) (a)
|
||||
#define SHL16(a,shift) (a)
|
||||
#define SHR32(a,shift) (a)
|
||||
#define SHL32(a,shift) (a)
|
||||
#define PSHR32(a,shift) (a)
|
||||
#define VSHR32(a,shift) (a)
|
||||
|
||||
#define PSHR(a,shift) (a)
|
||||
#define SHR(a,shift) (a)
|
||||
#define SHL(a,shift) (a)
|
||||
#define SATURATE(x,a) (x)
|
||||
#define SATURATE16(x) (x)
|
||||
|
||||
#define ROUND16(a,shift) (a)
|
||||
#define SROUND16(a,shift) (a)
|
||||
#define HALF16(x) (.5f*(x))
|
||||
#define HALF32(x) (.5f*(x))
|
||||
|
||||
#define ADD16(a,b) ((a)+(b))
|
||||
#define SUB16(a,b) ((a)-(b))
|
||||
#define ADD32(a,b) ((a)+(b))
|
||||
#define SUB32(a,b) ((a)-(b))
|
||||
#define ADD32_ovflw(a,b) ((a)+(b))
|
||||
#define SUB32_ovflw(a,b) ((a)-(b))
|
||||
#define MULT16_16_16(a,b) ((a)*(b))
|
||||
#define MULT16_16(a,b) ((opus_val32)(a)*(opus_val32)(b))
|
||||
#define MAC16_16(c,a,b) ((c)+(opus_val32)(a)*(opus_val32)(b))
|
||||
|
||||
#define MULT16_32_Q15(a,b) ((a)*(b))
|
||||
#define MULT16_32_Q16(a,b) ((a)*(b))
|
||||
|
||||
#define MULT32_32_Q31(a,b) ((a)*(b))
|
||||
|
||||
#define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
|
||||
#define MAC16_32_Q16(c,a,b) ((c)+(a)*(b))
|
||||
|
||||
#define MULT16_16_Q11_32(a,b) ((a)*(b))
|
||||
#define MULT16_16_Q11(a,b) ((a)*(b))
|
||||
#define MULT16_16_Q13(a,b) ((a)*(b))
|
||||
#define MULT16_16_Q14(a,b) ((a)*(b))
|
||||
#define MULT16_16_Q15(a,b) ((a)*(b))
|
||||
#define MULT16_16_P15(a,b) ((a)*(b))
|
||||
#define MULT16_16_P13(a,b) ((a)*(b))
|
||||
#define MULT16_16_P14(a,b) ((a)*(b))
|
||||
#define MULT16_32_P16(a,b) ((a)*(b))
|
||||
|
||||
#define DIV32_16(a,b) (((opus_val32)(a))/(opus_val16)(b))
|
||||
#define DIV32(a,b) (((opus_val32)(a))/(opus_val32)(b))
|
||||
|
||||
#define SCALEIN(a) ((a)*CELT_SIG_SCALE)
|
||||
#define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE))
|
||||
|
||||
#define SIG2WORD16(x) (x)
|
||||
|
||||
#endif /* !FIXED_POINT */
|
||||
|
||||
#ifndef GLOBAL_STACK_SIZE
|
||||
#ifdef FIXED_POINT
|
||||
#define GLOBAL_STACK_SIZE 120000
|
||||
#else
|
||||
#define GLOBAL_STACK_SIZE 120000
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* ARCH_H */
|
||||
174
src/modules/ZoomIt/ZoomIt/rnnoise/celt_lpc.c
Normal file
174
src/modules/ZoomIt/ZoomIt/rnnoise/celt_lpc.c
Normal file
@@ -0,0 +1,174 @@
|
||||
/* Copyright (c) 2009-2010 Xiph.Org Foundation
|
||||
Written by Jean-Marc Valin */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "celt_lpc.h"
|
||||
#include "arch.h"
|
||||
#include "common.h"
|
||||
#include "pitch.h"
|
||||
#include "denoise.h"
|
||||
|
||||
void rnn_lpc(
|
||||
opus_val16 *_lpc, /* out: [0...p-1] LPC coefficients */
|
||||
const opus_val32 *ac, /* in: [0...p] autocorrelation values */
|
||||
int p
|
||||
)
|
||||
{
|
||||
int i, j;
|
||||
opus_val32 r;
|
||||
opus_val32 error = ac[0];
|
||||
#ifdef FIXED_POINT
|
||||
opus_val32 lpc[LPC_ORDER];
|
||||
#else
|
||||
float *lpc = _lpc;
|
||||
#endif
|
||||
|
||||
RNN_CLEAR(lpc, p);
|
||||
if (ac[0] != 0)
|
||||
{
|
||||
for (i = 0; i < p; i++) {
|
||||
/* Sum up this iteration's reflection coefficient */
|
||||
opus_val32 rr = 0;
|
||||
for (j = 0; j < i; j++)
|
||||
rr += MULT32_32_Q31(lpc[j],ac[i - j]);
|
||||
rr += SHR32(ac[i + 1],3);
|
||||
r = -SHL32(rr,3)/error;
|
||||
/* Update LPC coefficients and total error */
|
||||
lpc[i] = SHR32(r,3);
|
||||
for (j = 0; j < (i+1)>>1; j++)
|
||||
{
|
||||
opus_val32 tmp1, tmp2;
|
||||
tmp1 = lpc[j];
|
||||
tmp2 = lpc[i-1-j];
|
||||
lpc[j] = tmp1 + MULT32_32_Q31(r,tmp2);
|
||||
lpc[i-1-j] = tmp2 + MULT32_32_Q31(r,tmp1);
|
||||
}
|
||||
|
||||
error = error - MULT32_32_Q31(MULT32_32_Q31(r,r),error);
|
||||
/* Bail out once we get 30 dB gain */
|
||||
#ifdef FIXED_POINT
|
||||
if (error<SHR32(ac[0],10))
|
||||
break;
|
||||
#else
|
||||
if (error<.001f*ac[0])
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef FIXED_POINT
|
||||
for (i=0;i<p;i++)
|
||||
_lpc[i] = ROUND16(lpc[i],16);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int rnn_autocorr(
|
||||
const opus_val16 *x, /* in: [0...n-1] samples x */
|
||||
opus_val32 *ac, /* out: [0...lag-1] ac values */
|
||||
const opus_val16 *window,
|
||||
int overlap,
|
||||
int lag,
|
||||
int n)
|
||||
{
|
||||
opus_val32 d;
|
||||
int i, k;
|
||||
int fastN=n-lag;
|
||||
int shift;
|
||||
const opus_val16 *xptr;
|
||||
opus_val16 xx[PITCH_BUF_SIZE/2];
|
||||
celt_assert(n>0);
|
||||
celt_assert(n<=PITCH_BUF_SIZE/2)
|
||||
celt_assert(overlap>=0);
|
||||
if (overlap == 0)
|
||||
{
|
||||
xptr = x;
|
||||
} else {
|
||||
for (i=0;i<n;i++)
|
||||
xx[i] = x[i];
|
||||
for (i=0;i<overlap;i++)
|
||||
{
|
||||
xx[i] = MULT16_16_Q15(x[i],window[i]);
|
||||
xx[n-i-1] = MULT16_16_Q15(x[n-i-1],window[i]);
|
||||
}
|
||||
xptr = xx;
|
||||
}
|
||||
shift=0;
|
||||
#ifdef FIXED_POINT
|
||||
{
|
||||
opus_val32 ac0;
|
||||
ac0 = 1+(n<<7);
|
||||
if (n&1) ac0 += SHR32(MULT16_16(xptr[0],xptr[0]),9);
|
||||
for(i=(n&1);i<n;i+=2)
|
||||
{
|
||||
ac0 += SHR32(MULT16_16(xptr[i],xptr[i]),9);
|
||||
ac0 += SHR32(MULT16_16(xptr[i+1],xptr[i+1]),9);
|
||||
}
|
||||
|
||||
shift = celt_ilog2(ac0)-30+10;
|
||||
shift = (shift)/2;
|
||||
if (shift>0)
|
||||
{
|
||||
for(i=0;i<n;i++)
|
||||
xx[i] = PSHR32(xptr[i], shift);
|
||||
xptr = xx;
|
||||
} else
|
||||
shift = 0;
|
||||
}
|
||||
#endif
|
||||
rnn_pitch_xcorr(xptr, xptr, ac, fastN, lag+1);
|
||||
for (k=0;k<=lag;k++)
|
||||
{
|
||||
for (i = k+fastN, d = 0; i < n; i++)
|
||||
d = MAC16_16(d, xptr[i], xptr[i-k]);
|
||||
ac[k] += d;
|
||||
}
|
||||
#ifdef FIXED_POINT
|
||||
shift = 2*shift;
|
||||
if (shift<=0)
|
||||
ac[0] += SHL32((opus_int32)1, -shift);
|
||||
if (ac[0] < 268435456)
|
||||
{
|
||||
int shift2 = 29 - EC_ILOG(ac[0]);
|
||||
for (i=0;i<=lag;i++)
|
||||
ac[i] = SHL32(ac[i], shift2);
|
||||
shift -= shift2;
|
||||
} else if (ac[0] >= 536870912)
|
||||
{
|
||||
int shift2=1;
|
||||
if (ac[0] >= 1073741824)
|
||||
shift2++;
|
||||
for (i=0;i<=lag;i++)
|
||||
ac[i] = SHR32(ac[i], shift2);
|
||||
shift += shift2;
|
||||
}
|
||||
#endif
|
||||
|
||||
return shift;
|
||||
}
|
||||
45
src/modules/ZoomIt/ZoomIt/rnnoise/celt_lpc.h
Normal file
45
src/modules/ZoomIt/ZoomIt/rnnoise/celt_lpc.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* Copyright (c) 2009-2010 Xiph.Org Foundation
|
||||
Written by Jean-Marc Valin */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef PLC_H
|
||||
#define PLC_H
|
||||
|
||||
#include "arch.h"
|
||||
#include "common.h"
|
||||
|
||||
#if defined(OPUS_X86_MAY_HAVE_SSE4_1)
|
||||
#include "x86/celt_lpc_sse.h"
|
||||
#endif
|
||||
|
||||
#define LPC_ORDER 24
|
||||
|
||||
void rnn_lpc(opus_val16 *_lpc, const opus_val32 *ac, int p);
|
||||
|
||||
int rnn_autocorr(const opus_val16 *x, opus_val32 *ac,
|
||||
const opus_val16 *window, int overlap, int lag, int n);
|
||||
|
||||
#endif /* PLC_H */
|
||||
56
src/modules/ZoomIt/ZoomIt/rnnoise/common.h
Normal file
56
src/modules/ZoomIt/ZoomIt/rnnoise/common.h
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
|
||||
#define RNN_INLINE inline
|
||||
#define OPUS_INLINE inline
|
||||
|
||||
|
||||
/** RNNoise wrapper for malloc(). To do your own dynamic allocation, all you need t
|
||||
o do is replace this function and rnnoise_free */
|
||||
#ifndef OVERRIDE_RNNOISE_ALLOC
|
||||
static RNN_INLINE void *rnnoise_alloc (size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** RNNoise wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function and rnnoise_alloc */
|
||||
#ifndef OVERRIDE_RNNOISE_FREE
|
||||
static RNN_INLINE void rnnoise_free (void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Copy n elements from src to dst. The 0* term provides compile-time type checking */
|
||||
#ifndef OVERRIDE_RNN_COPY
|
||||
#define RNN_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
|
||||
#endif
|
||||
|
||||
/** Copy n elements from src to dst, allowing overlapping regions. The 0* term
|
||||
provides compile-time type checking */
|
||||
#ifndef OVERRIDE_RNN_MOVE
|
||||
#define RNN_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
|
||||
#endif
|
||||
|
||||
/** Set n elements of dst to zero */
|
||||
#ifndef OVERRIDE_RNN_CLEAR
|
||||
#define RNN_CLEAR(dst, n) (memset((dst), 0, (n)*sizeof(*(dst))))
|
||||
#endif
|
||||
|
||||
# if !defined(OPUS_GNUC_PREREQ)
|
||||
# if defined(__GNUC__)&&defined(__GNUC_MINOR__)
|
||||
# define OPUS_GNUC_PREREQ(_maj,_min) \
|
||||
((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
|
||||
# else
|
||||
# define OPUS_GNUC_PREREQ(_maj,_min) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
|
||||
#endif
|
||||
53
src/modules/ZoomIt/ZoomIt/rnnoise/cpu_support.h
Normal file
53
src/modules/ZoomIt/ZoomIt/rnnoise/cpu_support.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* Copyright (c) 2010 Xiph.Org Foundation
|
||||
* Copyright (c) 2013 Parrot */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CPU_SUPPORT_H
|
||||
#define CPU_SUPPORT_H
|
||||
|
||||
#include "opus_types.h"
|
||||
#include "common.h"
|
||||
|
||||
#ifdef RNN_ENABLE_X86_RTCD
|
||||
|
||||
#include "x86/x86cpu.h"
|
||||
/* We currently support 5 x86 variants:
|
||||
* arch[0] -> sse2
|
||||
* arch[1] -> sse4.1
|
||||
* arch[2] -> avx2
|
||||
*/
|
||||
#define OPUS_ARCHMASK 3
|
||||
int rnn_select_arch(void);
|
||||
|
||||
#else
|
||||
#define OPUS_ARCHMASK 0
|
||||
|
||||
static OPUS_INLINE int rnn_select_arch(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
505
src/modules/ZoomIt/ZoomIt/rnnoise/denoise.c
Normal file
505
src/modules/ZoomIt/ZoomIt/rnnoise/denoise.c
Normal file
@@ -0,0 +1,505 @@
|
||||
/* Copyright (c) 2024 Jean-Marc Valin
|
||||
* Copyright (c) 2018 Gregor Richards
|
||||
* Copyright (c) 2017 Mozilla */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "kiss_fft.h"
|
||||
#include "common.h"
|
||||
#include "denoise.h"
|
||||
#include <math.h>
|
||||
#include "rnnoise.h"
|
||||
#include "pitch.h"
|
||||
#include "arch.h"
|
||||
#include "rnn.h"
|
||||
#include "cpu_support.h"
|
||||
|
||||
#define SQUARE(x) ((x)*(x))
|
||||
|
||||
|
||||
#ifndef TRAINING
|
||||
#define TRAINING 0
|
||||
#endif
|
||||
|
||||
|
||||
/* ERB bandwidths going in reverse from 20 kHz and then replacing the 700 and 800
|
||||
with just 750 because having 32 bands is convenient for the DNN.
|
||||
B(1)=400;
|
||||
for k=2:35
|
||||
B(k) = B(k-1) - max(2, round(24.7*(4.37*B(k-1)/20+1)/50));
|
||||
end
|
||||
printf("%d, ", B(end:-1:1));
|
||||
printf("\n")
|
||||
*/
|
||||
const int eband20ms[NB_BANDS+2] = {
|
||||
/*0 100 200 300 400 500 600 750 900 1.1 1.2 1.4 1.6 1.8 2.1 2.4 2.7 3.0 3.4 3.9 4.4 4.9 5.5 6.2 7.0 7.9 8.8 9.9 11.2 12.6 14.1 15.9 17.8 20.0*/
|
||||
0, 2, 4, 6, 8, 10, 12, 15, 18, 21, 24, 28, 32, 36, 41, 47, 53, 60, 68, 77, 87, 98, 110, 124, 140, 157, 176, 198, 223, 251, 282, 317, 356, 400};
|
||||
|
||||
|
||||
struct DenoiseState {
|
||||
RNNoise model;
|
||||
#if !TRAINING
|
||||
int arch;
|
||||
#endif
|
||||
float analysis_mem[FRAME_SIZE];
|
||||
int memid;
|
||||
float synthesis_mem[FRAME_SIZE];
|
||||
float pitch_buf[PITCH_BUF_SIZE];
|
||||
float pitch_enh_buf[PITCH_BUF_SIZE];
|
||||
float last_gain;
|
||||
int last_period;
|
||||
float mem_hp_x[2];
|
||||
float lastg[NB_BANDS];
|
||||
RNNState rnn;
|
||||
kiss_fft_cpx delayed_X[FREQ_SIZE];
|
||||
kiss_fft_cpx delayed_P[FREQ_SIZE];
|
||||
float delayed_Ex[NB_BANDS], delayed_Ep[NB_BANDS];
|
||||
float delayed_Exp[NB_BANDS];
|
||||
|
||||
};
|
||||
|
||||
static void compute_band_energy(float *bandE, const kiss_fft_cpx *X) {
|
||||
int i;
|
||||
float sum[NB_BANDS+2] = {0};
|
||||
for (i=0;i<NB_BANDS+1;i++)
|
||||
{
|
||||
int j;
|
||||
int band_size;
|
||||
band_size = eband20ms[i+1]-eband20ms[i];
|
||||
for (j=0;j<band_size;j++) {
|
||||
float tmp;
|
||||
float frac = (float)j/band_size;
|
||||
tmp = SQUARE(X[eband20ms[i] + j].r);
|
||||
tmp += SQUARE(X[eband20ms[i] + j].i);
|
||||
sum[i] += (1-frac)*tmp;
|
||||
sum[i+1] += frac*tmp;
|
||||
}
|
||||
}
|
||||
sum[1] = (sum[0]+sum[1])*2/3;
|
||||
sum[NB_BANDS] = (sum[NB_BANDS]+sum[NB_BANDS+1])*2/3;
|
||||
for (i=0;i<NB_BANDS;i++)
|
||||
{
|
||||
bandE[i] = sum[i+1];
|
||||
}
|
||||
}
|
||||
|
||||
static void compute_band_corr(float *bandE, const kiss_fft_cpx *X, const kiss_fft_cpx *P) {
|
||||
int i;
|
||||
float sum[NB_BANDS+2] = {0};
|
||||
for (i=0;i<NB_BANDS+1;i++)
|
||||
{
|
||||
int j;
|
||||
int band_size;
|
||||
band_size = eband20ms[i+1]-eband20ms[i];
|
||||
for (j=0;j<band_size;j++) {
|
||||
float tmp;
|
||||
float frac = (float)j/band_size;
|
||||
tmp = X[eband20ms[i] + j].r * P[eband20ms[i] + j].r;
|
||||
tmp += X[eband20ms[i] + j].i * P[eband20ms[i] + j].i;
|
||||
sum[i] += (1-frac)*tmp;
|
||||
sum[i+1] += frac*tmp;
|
||||
}
|
||||
}
|
||||
sum[1] = (sum[0]+sum[1])*2/3;
|
||||
sum[NB_BANDS] = (sum[NB_BANDS]+sum[NB_BANDS+1])*2/3;
|
||||
for (i=0;i<NB_BANDS;i++)
|
||||
{
|
||||
bandE[i] = sum[i+1];
|
||||
}
|
||||
}
|
||||
|
||||
static void interp_band_gain(float *g, const float *bandE) {
|
||||
int i,j;
|
||||
memset(g, 0, FREQ_SIZE);
|
||||
for (i=1;i<NB_BANDS;i++)
|
||||
{
|
||||
int band_size;
|
||||
band_size = eband20ms[i+1]-eband20ms[i];
|
||||
for (j=0;j<band_size;j++) {
|
||||
float frac = (float)j/band_size;
|
||||
g[eband20ms[i] + j] = (1-frac)*bandE[i-1] + frac*bandE[i];
|
||||
}
|
||||
}
|
||||
for (j=0;j<eband20ms[1];j++) g[j] = bandE[0];
|
||||
for (j=eband20ms[NB_BANDS];j<eband20ms[NB_BANDS+1];j++) g[j] = bandE[NB_BANDS-1];
|
||||
}
|
||||
|
||||
extern const float rnn_dct_table[];
|
||||
extern const kiss_fft_state rnn_kfft;
|
||||
extern const float rnn_half_window[];
|
||||
|
||||
static void dct(float *out, const float *in) {
|
||||
int i;
|
||||
for (i=0;i<NB_BANDS;i++) {
|
||||
int j;
|
||||
float sum = 0;
|
||||
for (j=0;j<NB_BANDS;j++) {
|
||||
sum += in[j] * rnn_dct_table[j*NB_BANDS + i];
|
||||
}
|
||||
out[i] = sum*sqrt(2./22);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void idct(float *out, const float *in) {
|
||||
int i;
|
||||
for (i=0;i<NB_BANDS;i++) {
|
||||
int j;
|
||||
float sum = 0;
|
||||
for (j=0;j<NB_BANDS;j++) {
|
||||
sum += in[j] * rnn_dct_table[i*NB_BANDS + j];
|
||||
}
|
||||
out[i] = sum*sqrt(2./22);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void forward_transform(kiss_fft_cpx *out, const float *in) {
|
||||
int i;
|
||||
kiss_fft_cpx x[WINDOW_SIZE];
|
||||
kiss_fft_cpx y[WINDOW_SIZE];
|
||||
for (i=0;i<WINDOW_SIZE;i++) {
|
||||
x[i].r = in[i];
|
||||
x[i].i = 0;
|
||||
}
|
||||
rnn_fft(&rnn_kfft, x, y, 0);
|
||||
for (i=0;i<FREQ_SIZE;i++) {
|
||||
out[i] = y[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void inverse_transform(float *out, const kiss_fft_cpx *in) {
|
||||
int i;
|
||||
kiss_fft_cpx x[WINDOW_SIZE];
|
||||
kiss_fft_cpx y[WINDOW_SIZE];
|
||||
for (i=0;i<FREQ_SIZE;i++) {
|
||||
x[i] = in[i];
|
||||
}
|
||||
for (;i<WINDOW_SIZE;i++) {
|
||||
x[i].r = x[WINDOW_SIZE - i].r;
|
||||
x[i].i = -x[WINDOW_SIZE - i].i;
|
||||
}
|
||||
rnn_fft(&rnn_kfft, x, y, 0);
|
||||
/* output in reverse order for IFFT. */
|
||||
out[0] = WINDOW_SIZE*y[0].r;
|
||||
for (i=1;i<WINDOW_SIZE;i++) {
|
||||
out[i] = WINDOW_SIZE*y[WINDOW_SIZE - i].r;
|
||||
}
|
||||
}
|
||||
|
||||
static void apply_window(float *x) {
|
||||
int i;
|
||||
for (i=0;i<FRAME_SIZE;i++) {
|
||||
x[i] *= rnn_half_window[i];
|
||||
x[WINDOW_SIZE - 1 - i] *= rnn_half_window[i];
|
||||
}
|
||||
}
|
||||
|
||||
struct RNNModel {
|
||||
/* Set either blob or const_blob. */
|
||||
const void *const_blob;
|
||||
void *blob;
|
||||
int blob_len;
|
||||
FILE *file;
|
||||
};
|
||||
|
||||
RNNModel *rnnoise_model_from_buffer(const void *ptr, int len) {
|
||||
RNNModel *model;
|
||||
model = malloc(sizeof(*model));
|
||||
model->blob = NULL;
|
||||
model->const_blob = ptr;
|
||||
model->blob_len = len;
|
||||
return model;
|
||||
}
|
||||
|
||||
RNNModel *rnnoise_model_from_filename(const char *filename) {
|
||||
RNNModel *model;
|
||||
FILE *f = fopen(filename, "rb");
|
||||
model = rnnoise_model_from_file(f);
|
||||
model->file = f;
|
||||
return model;
|
||||
}
|
||||
|
||||
RNNModel *rnnoise_model_from_file(FILE *f) {
|
||||
RNNModel *model;
|
||||
model = malloc(sizeof(*model));
|
||||
model->file = NULL;
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
model->blob_len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
model->const_blob = NULL;
|
||||
model->blob = malloc(model->blob_len);
|
||||
if (fread(model->blob, model->blob_len, 1, f) != 1)
|
||||
{
|
||||
rnnoise_model_free(model);
|
||||
return NULL;
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
void rnnoise_model_free(RNNModel *model) {
|
||||
if (model->file != NULL) fclose(model->file);
|
||||
if (model->blob != NULL) free(model->blob);
|
||||
free(model);
|
||||
}
|
||||
|
||||
int rnnoise_get_size(void) {
|
||||
return sizeof(DenoiseState);
|
||||
}
|
||||
|
||||
int rnnoise_get_frame_size(void) {
|
||||
return FRAME_SIZE;
|
||||
}
|
||||
|
||||
int rnnoise_init(DenoiseState *st, RNNModel *model) {
|
||||
memset(st, 0, sizeof(*st));
|
||||
#if !TRAINING
|
||||
if (model != NULL) {
|
||||
WeightArray *list;
|
||||
int ret = 1;
|
||||
parse_weights(&list, model->blob ? model->blob : model->const_blob, model->blob_len);
|
||||
if (list != NULL) {
|
||||
ret = init_rnnoise(&st->model, list);
|
||||
opus_free(list);
|
||||
}
|
||||
if (ret != 0) return -1;
|
||||
}
|
||||
#ifndef USE_WEIGHTS_FILE
|
||||
else {
|
||||
int ret = init_rnnoise(&st->model, rnnoise_arrays);
|
||||
if (ret != 0) return -1;
|
||||
}
|
||||
#endif
|
||||
st->arch = rnn_select_arch();
|
||||
#else
|
||||
(void)model;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
DenoiseState *rnnoise_create(RNNModel *model) {
|
||||
int ret;
|
||||
DenoiseState *st;
|
||||
st = malloc(rnnoise_get_size());
|
||||
ret = rnnoise_init(st, model);
|
||||
if (ret != 0) {
|
||||
free(st);
|
||||
return NULL;
|
||||
}
|
||||
return st;
|
||||
}
|
||||
|
||||
void rnnoise_destroy(DenoiseState *st) {
|
||||
free(st);
|
||||
}
|
||||
|
||||
#if TRAINING
|
||||
extern int lowpass;
|
||||
extern int band_lp;
|
||||
#endif
|
||||
|
||||
void rnn_frame_analysis(DenoiseState *st, kiss_fft_cpx *X, float *Ex, const float *in) {
|
||||
int i;
|
||||
float x[WINDOW_SIZE];
|
||||
RNN_COPY(x, st->analysis_mem, FRAME_SIZE);
|
||||
for (i=0;i<FRAME_SIZE;i++) x[FRAME_SIZE + i] = in[i];
|
||||
RNN_COPY(st->analysis_mem, in, FRAME_SIZE);
|
||||
apply_window(x);
|
||||
forward_transform(X, x);
|
||||
#if TRAINING
|
||||
for (i=lowpass;i<FREQ_SIZE;i++)
|
||||
X[i].r = X[i].i = 0;
|
||||
#endif
|
||||
compute_band_energy(Ex, X);
|
||||
}
|
||||
|
||||
int rnn_compute_frame_features(DenoiseState *st, kiss_fft_cpx *X, kiss_fft_cpx *P,
|
||||
float *Ex, float *Ep, float *Exp, float *features, const float *in) {
|
||||
int i;
|
||||
float E = 0;
|
||||
float Ly[NB_BANDS];
|
||||
float p[WINDOW_SIZE];
|
||||
float pitch_buf[PITCH_BUF_SIZE>>1];
|
||||
int pitch_index;
|
||||
float gain;
|
||||
float *(pre[1]);
|
||||
float follow, logMax;
|
||||
rnn_frame_analysis(st, X, Ex, in);
|
||||
RNN_MOVE(st->pitch_buf, &st->pitch_buf[FRAME_SIZE], PITCH_BUF_SIZE-FRAME_SIZE);
|
||||
RNN_COPY(&st->pitch_buf[PITCH_BUF_SIZE-FRAME_SIZE], in, FRAME_SIZE);
|
||||
pre[0] = &st->pitch_buf[0];
|
||||
rnn_pitch_downsample(pre, pitch_buf, PITCH_BUF_SIZE, 1);
|
||||
rnn_pitch_search(pitch_buf+(PITCH_MAX_PERIOD>>1), pitch_buf, PITCH_FRAME_SIZE,
|
||||
PITCH_MAX_PERIOD-3*PITCH_MIN_PERIOD, &pitch_index);
|
||||
pitch_index = PITCH_MAX_PERIOD-pitch_index;
|
||||
|
||||
gain = rnn_remove_doubling(pitch_buf, PITCH_MAX_PERIOD, PITCH_MIN_PERIOD,
|
||||
PITCH_FRAME_SIZE, &pitch_index, st->last_period, st->last_gain);
|
||||
st->last_period = pitch_index;
|
||||
st->last_gain = gain;
|
||||
for (i=0;i<WINDOW_SIZE;i++)
|
||||
p[i] = st->pitch_buf[PITCH_BUF_SIZE-WINDOW_SIZE-pitch_index+i];
|
||||
apply_window(p);
|
||||
forward_transform(P, p);
|
||||
compute_band_energy(Ep, P);
|
||||
compute_band_corr(Exp, X, P);
|
||||
for (i=0;i<NB_BANDS;i++) Exp[i] = Exp[i]/sqrt(.001+Ex[i]*Ep[i]);
|
||||
dct(&features[NB_BANDS], Exp);
|
||||
features[2*NB_BANDS] = .01*(pitch_index-300);
|
||||
logMax = -2;
|
||||
follow = -2;
|
||||
for (i=0;i<NB_BANDS;i++) {
|
||||
Ly[i] = log10(1e-2+Ex[i]);
|
||||
Ly[i] = MAX16(logMax-7, MAX16(follow-1.5, Ly[i]));
|
||||
logMax = MAX16(logMax, Ly[i]);
|
||||
follow = MAX16(follow-1.5, Ly[i]);
|
||||
E += Ex[i];
|
||||
}
|
||||
if (!TRAINING && E < 0.04) {
|
||||
/* If there's no audio, avoid messing up the state. */
|
||||
RNN_CLEAR(features, NB_FEATURES);
|
||||
return 1;
|
||||
}
|
||||
dct(features, Ly);
|
||||
features[0] -= 12;
|
||||
features[1] -= 4;
|
||||
return TRAINING && E < 0.1;
|
||||
}
|
||||
|
||||
static void frame_synthesis(DenoiseState *st, float *out, const kiss_fft_cpx *y) {
|
||||
float x[WINDOW_SIZE];
|
||||
int i;
|
||||
inverse_transform(x, y);
|
||||
apply_window(x);
|
||||
for (i=0;i<FRAME_SIZE;i++) out[i] = x[i] + st->synthesis_mem[i];
|
||||
RNN_COPY(st->synthesis_mem, &x[FRAME_SIZE], FRAME_SIZE);
|
||||
}
|
||||
|
||||
void rnn_biquad(float *y, float mem[2], const float *x, const float *b, const float *a, int N) {
|
||||
int i;
|
||||
for (i=0;i<N;i++) {
|
||||
float xi, yi;
|
||||
xi = x[i];
|
||||
yi = x[i] + mem[0];
|
||||
mem[0] = mem[1] + (b[0]*(double)xi - a[0]*(double)yi);
|
||||
mem[1] = (b[1]*(double)xi - a[1]*(double)yi);
|
||||
y[i] = yi;
|
||||
}
|
||||
}
|
||||
|
||||
void rnn_pitch_filter(kiss_fft_cpx *X, const kiss_fft_cpx *P, const float *Ex, const float *Ep,
|
||||
const float *Exp, const float *g) {
|
||||
int i;
|
||||
float r[NB_BANDS];
|
||||
float rf[FREQ_SIZE] = {0};
|
||||
float newE[NB_BANDS];
|
||||
float norm[NB_BANDS];
|
||||
float normf[FREQ_SIZE]={0};
|
||||
for (i=0;i<NB_BANDS;i++) {
|
||||
#if 0
|
||||
if (Exp[i]>g[i]) r[i] = 1;
|
||||
else r[i] = Exp[i]*(1-g[i])/(.001 + g[i]*(1-Exp[i]));
|
||||
r[i] = MIN16(1, MAX16(0, r[i]));
|
||||
#else
|
||||
if (Exp[i]>g[i]) r[i] = 1;
|
||||
else r[i] = SQUARE(Exp[i])*(1-SQUARE(g[i]))/(.001 + SQUARE(g[i])*(1-SQUARE(Exp[i])));
|
||||
r[i] = sqrt(MIN16(1, MAX16(0, r[i])));
|
||||
#endif
|
||||
r[i] *= sqrt(Ex[i]/(1e-8+Ep[i]));
|
||||
}
|
||||
interp_band_gain(rf, r);
|
||||
for (i=0;i<FREQ_SIZE;i++) {
|
||||
X[i].r += rf[i]*P[i].r;
|
||||
X[i].i += rf[i]*P[i].i;
|
||||
}
|
||||
compute_band_energy(newE, X);
|
||||
for (i=0;i<NB_BANDS;i++) {
|
||||
norm[i] = sqrt(Ex[i]/(1e-8+newE[i]));
|
||||
}
|
||||
interp_band_gain(normf, norm);
|
||||
for (i=0;i<FREQ_SIZE;i++) {
|
||||
X[i].r *= normf[i];
|
||||
X[i].i *= normf[i];
|
||||
}
|
||||
}
|
||||
|
||||
float rnnoise_process_frame(DenoiseState *st, float *out, const float *in) {
|
||||
int i;
|
||||
kiss_fft_cpx X[FREQ_SIZE];
|
||||
kiss_fft_cpx P[FREQ_SIZE];
|
||||
float x[FRAME_SIZE];
|
||||
float Ex[NB_BANDS], Ep[NB_BANDS];
|
||||
float Exp[NB_BANDS];
|
||||
float features[NB_FEATURES];
|
||||
float g[NB_BANDS];
|
||||
float gf[FREQ_SIZE]={1};
|
||||
float vad_prob = 0;
|
||||
int silence;
|
||||
static const float a_hp[2] = {-1.99599, 0.99600};
|
||||
static const float b_hp[2] = {-2, 1};
|
||||
rnn_biquad(x, st->mem_hp_x, in, b_hp, a_hp, FRAME_SIZE);
|
||||
silence = rnn_compute_frame_features(st, X, P, Ex, Ep, Exp, features, x);
|
||||
|
||||
if (!silence) {
|
||||
#if !TRAINING
|
||||
compute_rnn(&st->model, &st->rnn, g, &vad_prob, features, st->arch);
|
||||
#endif
|
||||
rnn_pitch_filter(st->delayed_X, st->delayed_P, st->delayed_Ex, st->delayed_Ep, st->delayed_Exp, g);
|
||||
for (i=0;i<NB_BANDS;i++) {
|
||||
float alpha = .6f;
|
||||
/* Cap the decay at 0.6 per frame, corresponding to an RT60 of 135 ms.
|
||||
That avoids unnaturally quick attenuation. */
|
||||
g[i] = MAX16(g[i], alpha*st->lastg[i]);
|
||||
/* Compensate for energy change across frame when computing the threshold gain.
|
||||
Avoids leaking noise when energy increases (e.g. transient noise). */
|
||||
st->lastg[i] = MIN16(1.f, g[i]*(st->delayed_Ex[i]+1e-3)/(Ex[i]+1e-3));
|
||||
}
|
||||
interp_band_gain(gf, g);
|
||||
#if 1
|
||||
for (i=0;i<FREQ_SIZE;i++) {
|
||||
st->delayed_X[i].r *= gf[i];
|
||||
st->delayed_X[i].i *= gf[i];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
frame_synthesis(st, out, st->delayed_X);
|
||||
|
||||
RNN_COPY(st->delayed_X, X, FREQ_SIZE);
|
||||
RNN_COPY(st->delayed_P, P, FREQ_SIZE);
|
||||
RNN_COPY(st->delayed_Ex, Ex, NB_BANDS);
|
||||
RNN_COPY(st->delayed_Ep, Ep, NB_BANDS);
|
||||
RNN_COPY(st->delayed_Exp, Exp, NB_BANDS);
|
||||
return vad_prob;
|
||||
}
|
||||
|
||||
56
src/modules/ZoomIt/ZoomIt/rnnoise/denoise.h
Normal file
56
src/modules/ZoomIt/ZoomIt/rnnoise/denoise.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/* Copyright (c) 2017 Mozilla */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "rnnoise.h"
|
||||
#include "kiss_fft.h"
|
||||
#include "nnet.h"
|
||||
|
||||
#define FRAME_SIZE 480
|
||||
#define WINDOW_SIZE (2*FRAME_SIZE)
|
||||
#define FREQ_SIZE (FRAME_SIZE + 1)
|
||||
#define NB_BANDS 32
|
||||
#define NB_FEATURES (2*NB_BANDS+1)
|
||||
|
||||
|
||||
#define PITCH_MIN_PERIOD 60
|
||||
#define PITCH_MAX_PERIOD 768
|
||||
#define PITCH_FRAME_SIZE 960
|
||||
#define PITCH_BUF_SIZE (PITCH_MAX_PERIOD+PITCH_FRAME_SIZE)
|
||||
|
||||
extern const WeightArray rnnoise_arrays[];
|
||||
|
||||
extern const int eband20ms[];
|
||||
|
||||
|
||||
void rnn_biquad(float *y, float mem[2], const float *x, const float *b, const float *a, int N);
|
||||
|
||||
void rnn_pitch_filter(kiss_fft_cpx *X, const kiss_fft_cpx *P, const float *Ex, const float *Ep,
|
||||
const float *Exp, const float *g);
|
||||
|
||||
void rnn_frame_analysis(DenoiseState *st, kiss_fft_cpx *X, float *Ex, const float *in);
|
||||
|
||||
int rnn_compute_frame_features(DenoiseState *st, kiss_fft_cpx *X, kiss_fft_cpx *P,
|
||||
float *Ex, float *Ep, float *Exp, float *features, const float *in);
|
||||
601
src/modules/ZoomIt/ZoomIt/rnnoise/kiss_fft.c
Normal file
601
src/modules/ZoomIt/ZoomIt/rnnoise/kiss_fft.c
Normal file
@@ -0,0 +1,601 @@
|
||||
/*Copyright (c) 2003-2004, Mark Borgerding
|
||||
Lots of modifications by Jean-Marc Valin
|
||||
Copyright (c) 2005-2007, Xiph.Org Foundation
|
||||
Copyright (c) 2008, Xiph.Org Foundation, CSIRO
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.*/
|
||||
|
||||
/* This code is originally from Mark Borgerding's KISS-FFT but has been
|
||||
heavily modified to better suit Opus */
|
||||
|
||||
#ifndef SKIP_CONFIG_H
|
||||
# ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "_kiss_fft_guts.h"
|
||||
#define CUSTOM_MODES
|
||||
|
||||
/* The guts header contains all the multiplication and addition macros that are defined for
|
||||
complex numbers. It also declares the kf_ internal functions.
|
||||
*/
|
||||
|
||||
static void kf_bfly2(
|
||||
kiss_fft_cpx * Fout,
|
||||
int m,
|
||||
int N
|
||||
)
|
||||
{
|
||||
kiss_fft_cpx * Fout2;
|
||||
int i;
|
||||
(void)m;
|
||||
#ifdef CUSTOM_MODES
|
||||
if (m==1)
|
||||
{
|
||||
celt_assert(m==1);
|
||||
for (i=0;i<N;i++)
|
||||
{
|
||||
kiss_fft_cpx t;
|
||||
Fout2 = Fout + 1;
|
||||
t = *Fout2;
|
||||
C_SUB( *Fout2 , *Fout , t );
|
||||
C_ADDTO( *Fout , t );
|
||||
Fout += 2;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
opus_val16 tw;
|
||||
tw = QCONST16(0.7071067812f, 15);
|
||||
/* We know that m==4 here because the radix-2 is just after a radix-4 */
|
||||
celt_assert(m==4);
|
||||
for (i=0;i<N;i++)
|
||||
{
|
||||
kiss_fft_cpx t;
|
||||
Fout2 = Fout + 4;
|
||||
t = Fout2[0];
|
||||
C_SUB( Fout2[0] , Fout[0] , t );
|
||||
C_ADDTO( Fout[0] , t );
|
||||
|
||||
t.r = S_MUL(ADD32_ovflw(Fout2[1].r, Fout2[1].i), tw);
|
||||
t.i = S_MUL(SUB32_ovflw(Fout2[1].i, Fout2[1].r), tw);
|
||||
C_SUB( Fout2[1] , Fout[1] , t );
|
||||
C_ADDTO( Fout[1] , t );
|
||||
|
||||
t.r = Fout2[2].i;
|
||||
t.i = -Fout2[2].r;
|
||||
C_SUB( Fout2[2] , Fout[2] , t );
|
||||
C_ADDTO( Fout[2] , t );
|
||||
|
||||
t.r = S_MUL(SUB32_ovflw(Fout2[3].i, Fout2[3].r), tw);
|
||||
t.i = S_MUL(NEG32_ovflw(ADD32_ovflw(Fout2[3].i, Fout2[3].r)), tw);
|
||||
C_SUB( Fout2[3] , Fout[3] , t );
|
||||
C_ADDTO( Fout[3] , t );
|
||||
Fout += 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void kf_bfly4(
|
||||
kiss_fft_cpx * Fout,
|
||||
const size_t fstride,
|
||||
const kiss_fft_state *st,
|
||||
int m,
|
||||
int N,
|
||||
int mm
|
||||
)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (m==1)
|
||||
{
|
||||
/* Degenerate case where all the twiddles are 1. */
|
||||
for (i=0;i<N;i++)
|
||||
{
|
||||
kiss_fft_cpx scratch0, scratch1;
|
||||
|
||||
C_SUB( scratch0 , *Fout, Fout[2] );
|
||||
C_ADDTO(*Fout, Fout[2]);
|
||||
C_ADD( scratch1 , Fout[1] , Fout[3] );
|
||||
C_SUB( Fout[2], *Fout, scratch1 );
|
||||
C_ADDTO( *Fout , scratch1 );
|
||||
C_SUB( scratch1 , Fout[1] , Fout[3] );
|
||||
|
||||
Fout[1].r = ADD32_ovflw(scratch0.r, scratch1.i);
|
||||
Fout[1].i = SUB32_ovflw(scratch0.i, scratch1.r);
|
||||
Fout[3].r = SUB32_ovflw(scratch0.r, scratch1.i);
|
||||
Fout[3].i = ADD32_ovflw(scratch0.i, scratch1.r);
|
||||
Fout+=4;
|
||||
}
|
||||
} else {
|
||||
int j;
|
||||
kiss_fft_cpx scratch[6];
|
||||
const kiss_twiddle_cpx *tw1,*tw2,*tw3;
|
||||
const int m2=2*m;
|
||||
const int m3=3*m;
|
||||
kiss_fft_cpx * Fout_beg = Fout;
|
||||
for (i=0;i<N;i++)
|
||||
{
|
||||
Fout = Fout_beg + i*mm;
|
||||
tw3 = tw2 = tw1 = st->twiddles;
|
||||
/* m is guaranteed to be a multiple of 4. */
|
||||
for (j=0;j<m;j++)
|
||||
{
|
||||
C_MUL(scratch[0],Fout[m] , *tw1 );
|
||||
C_MUL(scratch[1],Fout[m2] , *tw2 );
|
||||
C_MUL(scratch[2],Fout[m3] , *tw3 );
|
||||
|
||||
C_SUB( scratch[5] , *Fout, scratch[1] );
|
||||
C_ADDTO(*Fout, scratch[1]);
|
||||
C_ADD( scratch[3] , scratch[0] , scratch[2] );
|
||||
C_SUB( scratch[4] , scratch[0] , scratch[2] );
|
||||
C_SUB( Fout[m2], *Fout, scratch[3] );
|
||||
tw1 += fstride;
|
||||
tw2 += fstride*2;
|
||||
tw3 += fstride*3;
|
||||
C_ADDTO( *Fout , scratch[3] );
|
||||
|
||||
Fout[m].r = ADD32_ovflw(scratch[5].r, scratch[4].i);
|
||||
Fout[m].i = SUB32_ovflw(scratch[5].i, scratch[4].r);
|
||||
Fout[m3].r = SUB32_ovflw(scratch[5].r, scratch[4].i);
|
||||
Fout[m3].i = ADD32_ovflw(scratch[5].i, scratch[4].r);
|
||||
++Fout;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifndef RADIX_TWO_ONLY
|
||||
|
||||
static void kf_bfly3(
|
||||
kiss_fft_cpx * Fout,
|
||||
const size_t fstride,
|
||||
const kiss_fft_state *st,
|
||||
int m,
|
||||
int N,
|
||||
int mm
|
||||
)
|
||||
{
|
||||
int i;
|
||||
size_t k;
|
||||
const size_t m2 = 2*m;
|
||||
const kiss_twiddle_cpx *tw1,*tw2;
|
||||
kiss_fft_cpx scratch[5];
|
||||
kiss_twiddle_cpx epi3;
|
||||
|
||||
kiss_fft_cpx * Fout_beg = Fout;
|
||||
#ifdef FIXED_POINT
|
||||
/*epi3.r = -16384;*/ /* Unused */
|
||||
epi3.i = -28378;
|
||||
#else
|
||||
epi3 = st->twiddles[fstride*m];
|
||||
#endif
|
||||
for (i=0;i<N;i++)
|
||||
{
|
||||
Fout = Fout_beg + i*mm;
|
||||
tw1=tw2=st->twiddles;
|
||||
/* For non-custom modes, m is guaranteed to be a multiple of 4. */
|
||||
k=m;
|
||||
do {
|
||||
|
||||
C_MUL(scratch[1],Fout[m] , *tw1);
|
||||
C_MUL(scratch[2],Fout[m2] , *tw2);
|
||||
|
||||
C_ADD(scratch[3],scratch[1],scratch[2]);
|
||||
C_SUB(scratch[0],scratch[1],scratch[2]);
|
||||
tw1 += fstride;
|
||||
tw2 += fstride*2;
|
||||
|
||||
Fout[m].r = SUB32_ovflw(Fout->r, HALF_OF(scratch[3].r));
|
||||
Fout[m].i = SUB32_ovflw(Fout->i, HALF_OF(scratch[3].i));
|
||||
|
||||
C_MULBYSCALAR( scratch[0] , epi3.i );
|
||||
|
||||
C_ADDTO(*Fout,scratch[3]);
|
||||
|
||||
Fout[m2].r = ADD32_ovflw(Fout[m].r, scratch[0].i);
|
||||
Fout[m2].i = SUB32_ovflw(Fout[m].i, scratch[0].r);
|
||||
|
||||
Fout[m].r = SUB32_ovflw(Fout[m].r, scratch[0].i);
|
||||
Fout[m].i = ADD32_ovflw(Fout[m].i, scratch[0].r);
|
||||
|
||||
++Fout;
|
||||
} while(--k);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifndef OVERRIDE_kf_bfly5
|
||||
static void kf_bfly5(
|
||||
kiss_fft_cpx * Fout,
|
||||
const size_t fstride,
|
||||
const kiss_fft_state *st,
|
||||
int m,
|
||||
int N,
|
||||
int mm
|
||||
)
|
||||
{
|
||||
kiss_fft_cpx *Fout0,*Fout1,*Fout2,*Fout3,*Fout4;
|
||||
int i, u;
|
||||
kiss_fft_cpx scratch[13];
|
||||
const kiss_twiddle_cpx *tw;
|
||||
kiss_twiddle_cpx ya,yb;
|
||||
kiss_fft_cpx * Fout_beg = Fout;
|
||||
|
||||
#ifdef FIXED_POINT
|
||||
ya.r = 10126;
|
||||
ya.i = -31164;
|
||||
yb.r = -26510;
|
||||
yb.i = -19261;
|
||||
#else
|
||||
ya = st->twiddles[fstride*m];
|
||||
yb = st->twiddles[fstride*2*m];
|
||||
#endif
|
||||
tw=st->twiddles;
|
||||
|
||||
for (i=0;i<N;i++)
|
||||
{
|
||||
Fout = Fout_beg + i*mm;
|
||||
Fout0=Fout;
|
||||
Fout1=Fout0+m;
|
||||
Fout2=Fout0+2*m;
|
||||
Fout3=Fout0+3*m;
|
||||
Fout4=Fout0+4*m;
|
||||
|
||||
/* For non-custom modes, m is guaranteed to be a multiple of 4. */
|
||||
for ( u=0; u<m; ++u ) {
|
||||
scratch[0] = *Fout0;
|
||||
|
||||
C_MUL(scratch[1] ,*Fout1, tw[u*fstride]);
|
||||
C_MUL(scratch[2] ,*Fout2, tw[2*u*fstride]);
|
||||
C_MUL(scratch[3] ,*Fout3, tw[3*u*fstride]);
|
||||
C_MUL(scratch[4] ,*Fout4, tw[4*u*fstride]);
|
||||
|
||||
C_ADD( scratch[7],scratch[1],scratch[4]);
|
||||
C_SUB( scratch[10],scratch[1],scratch[4]);
|
||||
C_ADD( scratch[8],scratch[2],scratch[3]);
|
||||
C_SUB( scratch[9],scratch[2],scratch[3]);
|
||||
|
||||
Fout0->r = ADD32_ovflw(Fout0->r, ADD32_ovflw(scratch[7].r, scratch[8].r));
|
||||
Fout0->i = ADD32_ovflw(Fout0->i, ADD32_ovflw(scratch[7].i, scratch[8].i));
|
||||
|
||||
scratch[5].r = ADD32_ovflw(scratch[0].r, ADD32_ovflw(S_MUL(scratch[7].r,ya.r), S_MUL(scratch[8].r,yb.r)));
|
||||
scratch[5].i = ADD32_ovflw(scratch[0].i, ADD32_ovflw(S_MUL(scratch[7].i,ya.r), S_MUL(scratch[8].i,yb.r)));
|
||||
|
||||
scratch[6].r = ADD32_ovflw(S_MUL(scratch[10].i,ya.i), S_MUL(scratch[9].i,yb.i));
|
||||
scratch[6].i = NEG32_ovflw(ADD32_ovflw(S_MUL(scratch[10].r,ya.i), S_MUL(scratch[9].r,yb.i)));
|
||||
|
||||
C_SUB(*Fout1,scratch[5],scratch[6]);
|
||||
C_ADD(*Fout4,scratch[5],scratch[6]);
|
||||
|
||||
scratch[11].r = ADD32_ovflw(scratch[0].r, ADD32_ovflw(S_MUL(scratch[7].r,yb.r), S_MUL(scratch[8].r,ya.r)));
|
||||
scratch[11].i = ADD32_ovflw(scratch[0].i, ADD32_ovflw(S_MUL(scratch[7].i,yb.r), S_MUL(scratch[8].i,ya.r)));
|
||||
scratch[12].r = SUB32_ovflw(S_MUL(scratch[9].i,ya.i), S_MUL(scratch[10].i,yb.i));
|
||||
scratch[12].i = SUB32_ovflw(S_MUL(scratch[10].r,yb.i), S_MUL(scratch[9].r,ya.i));
|
||||
|
||||
C_ADD(*Fout2,scratch[11],scratch[12]);
|
||||
C_SUB(*Fout3,scratch[11],scratch[12]);
|
||||
|
||||
++Fout0;++Fout1;++Fout2;++Fout3;++Fout4;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* OVERRIDE_kf_bfly5 */
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CUSTOM_MODES
|
||||
|
||||
static
|
||||
void compute_bitrev_table(
|
||||
int Fout,
|
||||
opus_int32 *f,
|
||||
const size_t fstride,
|
||||
int in_stride,
|
||||
opus_int16 * factors,
|
||||
const kiss_fft_state *st
|
||||
)
|
||||
{
|
||||
const int p=*factors++; /* the radix */
|
||||
const int m=*factors++; /* stage's fft length/p */
|
||||
|
||||
/*printf ("fft %d %d %d %d %d %d\n", p*m, m, p, s2, fstride*in_stride, N);*/
|
||||
if (m==1)
|
||||
{
|
||||
int j;
|
||||
for (j=0;j<p;j++)
|
||||
{
|
||||
*f = Fout+j;
|
||||
f += fstride*in_stride;
|
||||
}
|
||||
} else {
|
||||
int j;
|
||||
for (j=0;j<p;j++)
|
||||
{
|
||||
compute_bitrev_table( Fout , f, fstride*p, in_stride, factors,st);
|
||||
f += fstride*in_stride;
|
||||
Fout += m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* facbuf is populated by p1,m1,p2,m2, ...
|
||||
where
|
||||
p[i] * m[i] = m[i-1]
|
||||
m0 = n */
|
||||
static
|
||||
int kf_factor(int n,opus_int16 * facbuf)
|
||||
{
|
||||
int p=4;
|
||||
int i;
|
||||
int stages=0;
|
||||
int nbak = n;
|
||||
|
||||
/*factor out powers of 4, powers of 2, then any remaining primes */
|
||||
do {
|
||||
while (n % p) {
|
||||
switch (p) {
|
||||
case 4: p = 2; break;
|
||||
case 2: p = 3; break;
|
||||
default: p += 2; break;
|
||||
}
|
||||
if (p>32000 || (opus_int32)p*(opus_int32)p > n)
|
||||
p = n; /* no more factors, skip to end */
|
||||
}
|
||||
n /= p;
|
||||
#ifdef RADIX_TWO_ONLY
|
||||
if (p!=2 && p != 4)
|
||||
#else
|
||||
if (p>5)
|
||||
#endif
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
facbuf[2*stages] = p;
|
||||
if (p==2 && stages > 1)
|
||||
{
|
||||
facbuf[2*stages] = 4;
|
||||
facbuf[2] = 2;
|
||||
}
|
||||
stages++;
|
||||
} while (n > 1);
|
||||
n = nbak;
|
||||
/* Reverse the order to get the radix 4 at the end, so we can use the
|
||||
fast degenerate case. It turns out that reversing the order also
|
||||
improves the noise behaviour. */
|
||||
for (i=0;i<stages/2;i++)
|
||||
{
|
||||
int tmp;
|
||||
tmp = facbuf[2*i];
|
||||
facbuf[2*i] = facbuf[2*(stages-i-1)];
|
||||
facbuf[2*(stages-i-1)] = tmp;
|
||||
}
|
||||
for (i=0;i<stages;i++)
|
||||
{
|
||||
n /= facbuf[2*i];
|
||||
facbuf[2*i+1] = n;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void compute_twiddles(kiss_twiddle_cpx *twiddles, int nfft)
|
||||
{
|
||||
int i;
|
||||
#ifdef FIXED_POINT
|
||||
for (i=0;i<nfft;++i) {
|
||||
opus_val32 phase = -i;
|
||||
kf_cexp2(twiddles+i, DIV32(SHL32(phase,17),nfft));
|
||||
}
|
||||
#else
|
||||
for (i=0;i<nfft;++i) {
|
||||
const double pi=3.14159265358979323846264338327;
|
||||
double phase = ( -2*pi /nfft ) * i;
|
||||
kf_cexp(twiddles+i, phase );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int rnn_fft_alloc_arch_c(kiss_fft_state *st) {
|
||||
(void)st;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Allocates all necessary storage space for the fft and ifft.
|
||||
* The return value is a contiguous block of memory. As such,
|
||||
* It can be freed with free().
|
||||
* */
|
||||
kiss_fft_state *rnn_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem,
|
||||
const kiss_fft_state *base, int arch)
|
||||
{
|
||||
kiss_fft_state *st=NULL;
|
||||
size_t memneeded = sizeof(struct kiss_fft_state); /* twiddle factors*/
|
||||
|
||||
if ( lenmem==NULL ) {
|
||||
st = ( kiss_fft_state*)KISS_FFT_MALLOC( memneeded );
|
||||
}else{
|
||||
if (mem != NULL && *lenmem >= memneeded)
|
||||
st = (kiss_fft_state*)mem;
|
||||
*lenmem = memneeded;
|
||||
}
|
||||
if (st) {
|
||||
opus_int32 *bitrev;
|
||||
kiss_twiddle_cpx *twiddles;
|
||||
|
||||
st->nfft=nfft;
|
||||
#ifdef FIXED_POINT
|
||||
st->scale_shift = celt_ilog2(st->nfft);
|
||||
if (st->nfft == 1<<st->scale_shift)
|
||||
st->scale = Q15ONE;
|
||||
else
|
||||
st->scale = (1073741824+st->nfft/2)/st->nfft>>(15-st->scale_shift);
|
||||
#else
|
||||
st->scale = 1.f/nfft;
|
||||
#endif
|
||||
if (base != NULL)
|
||||
{
|
||||
st->twiddles = base->twiddles;
|
||||
st->shift = 0;
|
||||
while (st->shift < 32 && nfft<<st->shift != base->nfft)
|
||||
st->shift++;
|
||||
if (st->shift>=32)
|
||||
goto fail;
|
||||
} else {
|
||||
st->twiddles = twiddles = (kiss_twiddle_cpx*)KISS_FFT_MALLOC(sizeof(kiss_twiddle_cpx)*nfft);
|
||||
compute_twiddles(twiddles, nfft);
|
||||
st->shift = -1;
|
||||
}
|
||||
if (!kf_factor(nfft,st->factors))
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* bitrev */
|
||||
st->bitrev = bitrev = (opus_int32*)KISS_FFT_MALLOC(sizeof(opus_int32)*nfft);
|
||||
if (st->bitrev==NULL)
|
||||
goto fail;
|
||||
compute_bitrev_table(0, bitrev, 1,1, st->factors,st);
|
||||
|
||||
/* Initialize architecture specific fft parameters */
|
||||
if (rnn_fft_alloc_arch(st, arch))
|
||||
goto fail;
|
||||
}
|
||||
return st;
|
||||
fail:
|
||||
rnn_fft_free(st, arch);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
kiss_fft_state *rnn_fft_alloc(int nfft,void * mem,size_t * lenmem, int arch)
|
||||
{
|
||||
return rnn_fft_alloc_twiddles(nfft, mem, lenmem, NULL, arch);
|
||||
}
|
||||
|
||||
void rnn_fft_free_arch_c(kiss_fft_state *st) {
|
||||
(void)st;
|
||||
}
|
||||
|
||||
void rnn_fft_free(const kiss_fft_state *cfg, int arch)
|
||||
{
|
||||
if (cfg)
|
||||
{
|
||||
rnn_fft_free_arch((kiss_fft_state *)cfg, arch);
|
||||
opus_free((opus_int32*)cfg->bitrev);
|
||||
if (cfg->shift < 0)
|
||||
opus_free((kiss_twiddle_cpx*)cfg->twiddles);
|
||||
opus_free((kiss_fft_state*)cfg);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CUSTOM_MODES */
|
||||
|
||||
void rnn_fft_impl(const kiss_fft_state *st,kiss_fft_cpx *fout)
|
||||
{
|
||||
int m2, m;
|
||||
int p;
|
||||
int L;
|
||||
int fstride[MAXFACTORS];
|
||||
int i;
|
||||
int shift;
|
||||
|
||||
/* st->shift can be -1 */
|
||||
shift = st->shift>0 ? st->shift : 0;
|
||||
|
||||
fstride[0] = 1;
|
||||
L=0;
|
||||
do {
|
||||
p = st->factors[2*L];
|
||||
m = st->factors[2*L+1];
|
||||
fstride[L+1] = fstride[L]*p;
|
||||
L++;
|
||||
} while(m!=1);
|
||||
m = st->factors[2*L-1];
|
||||
for (i=L-1;i>=0;i--)
|
||||
{
|
||||
if (i!=0)
|
||||
m2 = st->factors[2*i-1];
|
||||
else
|
||||
m2 = 1;
|
||||
switch (st->factors[2*i])
|
||||
{
|
||||
case 2:
|
||||
kf_bfly2(fout, m, fstride[i]);
|
||||
break;
|
||||
case 4:
|
||||
kf_bfly4(fout,fstride[i]<<shift,st,m, fstride[i], m2);
|
||||
break;
|
||||
#ifndef RADIX_TWO_ONLY
|
||||
case 3:
|
||||
kf_bfly3(fout,fstride[i]<<shift,st,m, fstride[i], m2);
|
||||
break;
|
||||
case 5:
|
||||
kf_bfly5(fout,fstride[i]<<shift,st,m, fstride[i], m2);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
m = m2;
|
||||
}
|
||||
}
|
||||
|
||||
void rnn_fft_c(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
|
||||
{
|
||||
int i;
|
||||
opus_val16 scale;
|
||||
#ifdef FIXED_POINT
|
||||
/* Allows us to scale with MULT16_32_Q16(), which is faster than
|
||||
MULT16_32_Q15() on ARM. */
|
||||
int scale_shift = st->scale_shift-1;
|
||||
#endif
|
||||
scale = st->scale;
|
||||
|
||||
celt_assert2 (fin != fout, "In-place FFT not supported");
|
||||
/* Bit-reverse the input */
|
||||
for (i=0;i<st->nfft;i++)
|
||||
{
|
||||
kiss_fft_cpx x = fin[i];
|
||||
fout[st->bitrev[i]].r = SHR32(MULT16_32_Q16(scale, x.r), scale_shift);
|
||||
fout[st->bitrev[i]].i = SHR32(MULT16_32_Q16(scale, x.i), scale_shift);
|
||||
}
|
||||
rnn_fft_impl(st, fout);
|
||||
}
|
||||
|
||||
|
||||
void rnn_ifft_c(const kiss_fft_state *st,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
|
||||
{
|
||||
int i;
|
||||
celt_assert2 (fin != fout, "In-place FFT not supported");
|
||||
/* Bit-reverse the input */
|
||||
for (i=0;i<st->nfft;i++)
|
||||
fout[st->bitrev[i]] = fin[i];
|
||||
for (i=0;i<st->nfft;i++)
|
||||
fout[i].i = -fout[i].i;
|
||||
rnn_fft_impl(st, fout);
|
||||
for (i=0;i<st->nfft;i++)
|
||||
fout[i].i = -fout[i].i;
|
||||
}
|
||||
203
src/modules/ZoomIt/ZoomIt/rnnoise/kiss_fft.h
Normal file
203
src/modules/ZoomIt/ZoomIt/rnnoise/kiss_fft.h
Normal file
@@ -0,0 +1,203 @@
|
||||
/*Copyright (c) 2003-2004, Mark Borgerding
|
||||
Lots of modifications by Jean-Marc Valin
|
||||
Copyright (c) 2005-2007, Xiph.Org Foundation
|
||||
Copyright (c) 2008, Xiph.Org Foundation, CSIRO
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.*/
|
||||
|
||||
#ifndef KISS_FFT_H
|
||||
#define KISS_FFT_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "arch.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#define opus_alloc(x) malloc(x)
|
||||
#define opus_free(x) free(x)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef USE_SIMD
|
||||
# include <xmmintrin.h>
|
||||
# define kiss_fft_scalar __m128
|
||||
#define KISS_FFT_MALLOC(nbytes) memalign(16,nbytes)
|
||||
#else
|
||||
#define KISS_FFT_MALLOC opus_alloc
|
||||
#endif
|
||||
|
||||
#ifdef FIXED_POINT
|
||||
#include "arch.h"
|
||||
|
||||
# define kiss_fft_scalar opus_int32
|
||||
# define kiss_twiddle_scalar opus_int16
|
||||
|
||||
|
||||
#else
|
||||
# ifndef kiss_fft_scalar
|
||||
/* default is float */
|
||||
# define kiss_fft_scalar float
|
||||
# define kiss_twiddle_scalar float
|
||||
# define KF_SUFFIX _celt_single
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
kiss_fft_scalar r;
|
||||
kiss_fft_scalar i;
|
||||
}kiss_fft_cpx;
|
||||
|
||||
typedef struct {
|
||||
kiss_twiddle_scalar r;
|
||||
kiss_twiddle_scalar i;
|
||||
}kiss_twiddle_cpx;
|
||||
|
||||
#define MAXFACTORS 8
|
||||
/* e.g. an fft of length 128 has 4 factors
|
||||
as far as kissfft is concerned
|
||||
4*4*4*2
|
||||
*/
|
||||
|
||||
typedef struct arch_fft_state{
|
||||
int is_supported;
|
||||
void *priv;
|
||||
} arch_fft_state;
|
||||
|
||||
typedef struct kiss_fft_state{
|
||||
int nfft;
|
||||
opus_val16 scale;
|
||||
#ifdef FIXED_POINT
|
||||
int scale_shift;
|
||||
#endif
|
||||
int shift;
|
||||
opus_int16 factors[2*MAXFACTORS];
|
||||
const opus_int32 *bitrev;
|
||||
const kiss_twiddle_cpx *twiddles;
|
||||
arch_fft_state *arch_fft;
|
||||
} kiss_fft_state;
|
||||
|
||||
#if defined(HAVE_ARM_NE10)
|
||||
#include "arm/fft_arm.h"
|
||||
#endif
|
||||
|
||||
/*typedef struct kiss_fft_state* kiss_fft_cfg;*/
|
||||
|
||||
/**
|
||||
* opus_fft_alloc
|
||||
*
|
||||
* Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
|
||||
*
|
||||
* typical usage: kiss_fft_cfg mycfg=opus_fft_alloc(1024,0,NULL,NULL);
|
||||
*
|
||||
* The return value from fft_alloc is a cfg buffer used internally
|
||||
* by the fft routine or NULL.
|
||||
*
|
||||
* If lenmem is NULL, then opus_fft_alloc will allocate a cfg buffer using malloc.
|
||||
* The returned value should be free()d when done to avoid memory leaks.
|
||||
*
|
||||
* The state can be placed in a user supplied buffer 'mem':
|
||||
* If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
|
||||
* then the function places the cfg in mem and the size used in *lenmem
|
||||
* and returns mem.
|
||||
*
|
||||
* If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
|
||||
* then the function returns NULL and places the minimum cfg
|
||||
* buffer size in *lenmem.
|
||||
* */
|
||||
|
||||
kiss_fft_state *rnn_fft_alloc_twiddles(int nfft,void * mem,size_t * lenmem, const kiss_fft_state *base, int arch);
|
||||
|
||||
kiss_fft_state *rnn_fft_alloc(int nfft,void * mem,size_t * lenmem, int arch);
|
||||
|
||||
/**
|
||||
* opus_fft(cfg,in_out_buf)
|
||||
*
|
||||
* Perform an FFT on a complex input buffer.
|
||||
* for a forward FFT,
|
||||
* fin should be f[0] , f[1] , ... ,f[nfft-1]
|
||||
* fout will be F[0] , F[1] , ... ,F[nfft-1]
|
||||
* Note that each element is complex and can be accessed like
|
||||
f[k].r and f[k].i
|
||||
* */
|
||||
void rnn_fft_c(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
|
||||
void rnn_ifft_c(const kiss_fft_state *cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
|
||||
|
||||
void rnn_fft_impl(const kiss_fft_state *st,kiss_fft_cpx *fout);
|
||||
void rnn_ifft_impl(const kiss_fft_state *st,kiss_fft_cpx *fout);
|
||||
|
||||
void rnn_fft_free(const kiss_fft_state *cfg, int arch);
|
||||
|
||||
|
||||
void rnn_fft_free_arch_c(kiss_fft_state *st);
|
||||
int rnn_fft_alloc_arch_c(kiss_fft_state *st);
|
||||
|
||||
#if !defined(OVERRIDE_OPUS_FFT)
|
||||
/* Is run-time CPU detection enabled on this platform? */
|
||||
#if defined(OPUS_HAVE_RTCD) && (defined(HAVE_ARM_NE10))
|
||||
|
||||
extern int (*const OPUS_FFT_ALLOC_ARCH_IMPL[OPUS_ARCHMASK+1])(
|
||||
kiss_fft_state *st);
|
||||
|
||||
#define opus_fft_alloc_arch(_st, arch) \
|
||||
((*OPUS_FFT_ALLOC_ARCH_IMPL[(arch)&OPUS_ARCHMASK])(_st))
|
||||
|
||||
extern void (*const OPUS_FFT_FREE_ARCH_IMPL[OPUS_ARCHMASK+1])(
|
||||
kiss_fft_state *st);
|
||||
#define opus_fft_free_arch(_st, arch) \
|
||||
((*OPUS_FFT_FREE_ARCH_IMPL[(arch)&OPUS_ARCHMASK])(_st))
|
||||
|
||||
extern void (*const OPUS_FFT[OPUS_ARCHMASK+1])(const kiss_fft_state *cfg,
|
||||
const kiss_fft_cpx *fin, kiss_fft_cpx *fout);
|
||||
#define opus_fft(_cfg, _fin, _fout, arch) \
|
||||
((*OPUS_FFT[(arch)&OPUS_ARCHMASK])(_cfg, _fin, _fout))
|
||||
|
||||
extern void (*const OPUS_IFFT[OPUS_ARCHMASK+1])(const kiss_fft_state *cfg,
|
||||
const kiss_fft_cpx *fin, kiss_fft_cpx *fout);
|
||||
#define opus_ifft(_cfg, _fin, _fout, arch) \
|
||||
((*OPUS_IFFT[(arch)&OPUS_ARCHMASK])(_cfg, _fin, _fout))
|
||||
|
||||
#else /* else for if defined(OPUS_HAVE_RTCD) && (defined(HAVE_ARM_NE10)) */
|
||||
|
||||
#define rnn_fft_alloc_arch(_st, arch) \
|
||||
((void)(arch), rnn_fft_alloc_arch_c(_st))
|
||||
|
||||
#define rnn_fft_free_arch(_st, arch) \
|
||||
((void)(arch), rnn_fft_free_arch_c(_st))
|
||||
|
||||
#define rnn_fft(_cfg, _fin, _fout, arch) \
|
||||
((void)(arch), rnn_fft_c(_cfg, _fin, _fout))
|
||||
|
||||
#define rnn_ifft(_cfg, _fin, _fout, arch) \
|
||||
((void)(arch), rnn_ifft_c(_cfg, _fin, _fout))
|
||||
|
||||
#endif /* end if defined(OPUS_HAVE_RTCD) && (defined(HAVE_ARM_NE10)) */
|
||||
#endif /* end if !defined(OVERRIDE_OPUS_FFT) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
123
src/modules/ZoomIt/ZoomIt/rnnoise/nnet.c
Normal file
123
src/modules/ZoomIt/ZoomIt/rnnoise/nnet.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/* Copyright (c) 2018 Mozilla
|
||||
2008-2011 Octasic Inc.
|
||||
2012-2017 Jean-Marc Valin */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "opus_types.h"
|
||||
#include "arch.h"
|
||||
#include "nnet.h"
|
||||
#include "common.h"
|
||||
#include "vec.h"
|
||||
|
||||
#ifdef ENABLE_OSCE
|
||||
#include "osce.h"
|
||||
#endif
|
||||
|
||||
#ifdef NO_OPTIMIZATIONS
|
||||
#if defined(_MSC_VER)
|
||||
#pragma message ("Compiling without any vectorization. This code will be very slow")
|
||||
#else
|
||||
#warning Compiling without any vectorization. This code will be very slow
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#define SOFTMAX_HACK
|
||||
|
||||
|
||||
void compute_generic_dense(const LinearLayer *layer, float *output, const float *input, int activation, int arch)
|
||||
{
|
||||
compute_linear(layer, output, input, arch);
|
||||
compute_activation(output, output, layer->nb_outputs, activation, arch);
|
||||
}
|
||||
|
||||
#define MAX_RNN_NEURONS_ALL 1024
|
||||
|
||||
void compute_generic_gru(const LinearLayer *input_weights, const LinearLayer *recurrent_weights, float *state, const float *in, int arch)
|
||||
{
|
||||
int i;
|
||||
int N;
|
||||
float zrh[3*MAX_RNN_NEURONS_ALL];
|
||||
float recur[3*MAX_RNN_NEURONS_ALL];
|
||||
float *z;
|
||||
float *r;
|
||||
float *h;
|
||||
celt_assert(3*recurrent_weights->nb_inputs == recurrent_weights->nb_outputs);
|
||||
celt_assert(input_weights->nb_outputs == recurrent_weights->nb_outputs);
|
||||
N = recurrent_weights->nb_inputs;
|
||||
z = zrh;
|
||||
r = &zrh[N];
|
||||
h = &zrh[2*N];
|
||||
celt_assert(recurrent_weights->nb_outputs <= 3*MAX_RNN_NEURONS_ALL);
|
||||
celt_assert(in != state);
|
||||
compute_linear(input_weights, zrh, in, arch);
|
||||
compute_linear(recurrent_weights, recur, state, arch);
|
||||
for (i=0;i<2*N;i++)
|
||||
zrh[i] += recur[i];
|
||||
compute_activation(zrh, zrh, 2*N, ACTIVATION_SIGMOID, arch);
|
||||
for (i=0;i<N;i++)
|
||||
h[i] += recur[2*N+i]*r[i];
|
||||
compute_activation(h, h, N, ACTIVATION_TANH, arch);
|
||||
for (i=0;i<N;i++)
|
||||
h[i] = z[i]*state[i] + (1-z[i])*h[i];
|
||||
for (i=0;i<N;i++)
|
||||
state[i] = h[i];
|
||||
}
|
||||
|
||||
void compute_glu(const LinearLayer *layer, float *output, const float *input, int arch)
|
||||
{
|
||||
int i;
|
||||
float act2[MAX_INPUTS];
|
||||
celt_assert(layer->nb_inputs == layer->nb_outputs);
|
||||
compute_linear(layer, act2, input, arch);
|
||||
compute_activation(act2, act2, layer->nb_outputs, ACTIVATION_SIGMOID, arch);
|
||||
if (input == output) {
|
||||
/* Give a vectorization hint to the compiler for the in-place case. */
|
||||
for (i=0;i<layer->nb_outputs;i++) output[i] = output[i]*act2[i];
|
||||
} else {
|
||||
for (i=0;i<layer->nb_outputs;i++) output[i] = input[i]*act2[i];
|
||||
}
|
||||
}
|
||||
|
||||
#define MAX_CONV_INPUTS_ALL 1024
|
||||
|
||||
void compute_generic_conv1d(const LinearLayer *layer, float *output, float *mem, const float *input, int input_size, int activation, int arch)
|
||||
{
|
||||
float tmp[MAX_CONV_INPUTS_ALL];
|
||||
celt_assert(input != output);
|
||||
celt_assert(layer->nb_inputs <= MAX_CONV_INPUTS_ALL);
|
||||
if (layer->nb_inputs!=input_size) RNN_COPY(tmp, mem, layer->nb_inputs-input_size);
|
||||
RNN_COPY(&tmp[layer->nb_inputs-input_size], input, input_size);
|
||||
compute_linear(layer, output, tmp, arch);
|
||||
compute_activation(output, output, layer->nb_outputs, activation, arch);
|
||||
if (layer->nb_inputs!=input_size) RNN_COPY(mem, &tmp[input_size], layer->nb_inputs-input_size);
|
||||
}
|
||||
169
src/modules/ZoomIt/ZoomIt/rnnoise/nnet.h
Normal file
169
src/modules/ZoomIt/ZoomIt/rnnoise/nnet.h
Normal file
@@ -0,0 +1,169 @@
|
||||
/* Copyright (c) 2018 Mozilla
|
||||
Copyright (c) 2017 Jean-Marc Valin */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef NNET_H_
|
||||
#define NNET_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include "opus_types.h"
|
||||
|
||||
#define ACTIVATION_LINEAR 0
|
||||
#define ACTIVATION_SIGMOID 1
|
||||
#define ACTIVATION_TANH 2
|
||||
#define ACTIVATION_RELU 3
|
||||
#define ACTIVATION_SOFTMAX 4
|
||||
#define ACTIVATION_SWISH 5
|
||||
|
||||
#define WEIGHT_BLOB_VERSION 0
|
||||
#define WEIGHT_BLOCK_SIZE 64
|
||||
typedef struct {
|
||||
const char *name;
|
||||
int type;
|
||||
int size;
|
||||
const void *data;
|
||||
} WeightArray;
|
||||
|
||||
#define WEIGHT_TYPE_float 0
|
||||
#define WEIGHT_TYPE_int 1
|
||||
#define WEIGHT_TYPE_qweight 2
|
||||
#define WEIGHT_TYPE_int8 3
|
||||
|
||||
typedef struct {
|
||||
char head[4];
|
||||
int version;
|
||||
int type;
|
||||
int size;
|
||||
int block_size;
|
||||
char name[44];
|
||||
} WeightHead;
|
||||
|
||||
/* Generic sparse affine transformation. */
|
||||
typedef struct {
|
||||
const float *bias;
|
||||
const float *subias;
|
||||
const opus_int8 *weights;
|
||||
const float *float_weights;
|
||||
const int *weights_idx;
|
||||
const float *diag;
|
||||
const float *scale;
|
||||
int nb_inputs;
|
||||
int nb_outputs;
|
||||
} LinearLayer;
|
||||
|
||||
/* Generic sparse affine transformation. */
|
||||
typedef struct {
|
||||
const float *bias;
|
||||
const float *float_weights;
|
||||
int in_channels;
|
||||
int out_channels;
|
||||
int ktime;
|
||||
int kheight;
|
||||
} Conv2dLayer;
|
||||
|
||||
|
||||
/* Changes some symbol names to add the rnn_ prefix so we don't get conflicts with Opus. */
|
||||
#define linear_init rnn_linear_init
|
||||
#define conv2d_init rnn_conv2d_init
|
||||
#define compute_generic_dense rnn_compute_generic_dense
|
||||
#define compute_generic_gru rnn_compute_generic_gru
|
||||
#define compute_generic_conv1d rnn_compute_generic_conv1d
|
||||
#define compute_glu rnn_compute_glu
|
||||
|
||||
#define parse_weights rnn_parse_weights
|
||||
|
||||
#define compute_linear_c rnn_compute_linear_c
|
||||
#define compute_activation_c rnn_compute_activation_c
|
||||
#define compute_conv2d_c rnn_compute_conv2d_c
|
||||
#define compute_linear_sse4_1 rnn_compute_linear_sse4_1
|
||||
#define compute_activation_sse4_1 rnn_compute_activation_sse4_1
|
||||
#define compute_conv2d_sse4_1 rnn_compute_conv2d_sse4_1
|
||||
#define compute_linear_avx2 rnn_compute_linear_avx2
|
||||
#define compute_activation_avx2 rnn_compute_activation_avx2
|
||||
#define compute_conv2d_avx2 rnn_compute_conv2d_avx2
|
||||
|
||||
|
||||
void compute_generic_dense(const LinearLayer *layer, float *output, const float *input, int activation, int arch);
|
||||
void compute_generic_gru(const LinearLayer *input_weights, const LinearLayer *recurrent_weights, float *state, const float *in, int arch);
|
||||
void compute_generic_conv1d(const LinearLayer *layer, float *output, float *mem, const float *input, int input_size, int activation, int arch);
|
||||
void compute_glu(const LinearLayer *layer, float *output, const float *input, int arch);
|
||||
|
||||
|
||||
int parse_weights(WeightArray **list, const void *data, int len);
|
||||
|
||||
|
||||
|
||||
int linear_init(LinearLayer *layer, const WeightArray *arrays,
|
||||
const char *bias,
|
||||
const char *subias,
|
||||
const char *weights,
|
||||
const char *float_weights,
|
||||
const char *weights_idx,
|
||||
const char *diag,
|
||||
const char *scale,
|
||||
int nb_inputs,
|
||||
int nb_outputs);
|
||||
|
||||
int conv2d_init(Conv2dLayer *layer, const WeightArray *arrays,
|
||||
const char *bias,
|
||||
const char *float_weights,
|
||||
int in_channels,
|
||||
int out_channels,
|
||||
int ktime,
|
||||
int kheight);
|
||||
|
||||
|
||||
void compute_linear_c(const LinearLayer *linear, float *out, const float *in);
|
||||
void compute_activation_c(float *output, const float *input, int N, int activation);
|
||||
void compute_conv2d_c(const Conv2dLayer *conv, float *out, float *mem, const float *in, int height, int hstride, int activation);
|
||||
|
||||
#ifdef RNN_ENABLE_X86_RTCD
|
||||
#include "x86/dnn_x86.h"
|
||||
#endif
|
||||
|
||||
#ifndef OVERRIDE_COMPUTE_LINEAR
|
||||
#define compute_linear(linear, out, in, arch) ((void)(arch),compute_linear_c(linear, out, in))
|
||||
#endif
|
||||
|
||||
#ifndef OVERRIDE_COMPUTE_ACTIVATION
|
||||
#define compute_activation(output, input, N, activation, arch) ((void)(arch),compute_activation_c(output, input, N, activation))
|
||||
#endif
|
||||
|
||||
#ifndef OVERRIDE_COMPUTE_CONV2D
|
||||
#define compute_conv2d(conv, out, mem, in, height, hstride, activation, arch) ((void)(arch),compute_conv2d_c(conv, out, mem, in, height, hstride, activation))
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__) && !defined(RNN_ENABLE_X86_RTCD) && !defined(__AVX2__)
|
||||
#if defined(_MSC_VER)
|
||||
#pragma message ("Only SSE and SSE2 are available. On newer machines, enable SSSE3/AVX/AVX2 to get better performance")
|
||||
#else
|
||||
#warning "Only SSE and SSE2 are available. On newer machines, enable SSSE3/AVX/AVX2 using -march= to get better performance"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* NNET_H_ */
|
||||
257
src/modules/ZoomIt/ZoomIt/rnnoise/nnet_arch.h
Normal file
257
src/modules/ZoomIt/ZoomIt/rnnoise/nnet_arch.h
Normal file
@@ -0,0 +1,257 @@
|
||||
/* Copyright (c) 2018-2019 Mozilla
|
||||
2023 Amazon */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef NNET_ARCH_H
|
||||
#define NNET_ARCH_H
|
||||
|
||||
#include "nnet.h"
|
||||
#include "arch.h"
|
||||
#include "common.h"
|
||||
#include "vec.h"
|
||||
|
||||
#define CAT_SUFFIX2(a,b) a ## b
|
||||
#define CAT_SUFFIX(a,b) CAT_SUFFIX2(a, b)
|
||||
|
||||
#define RTCD_SUF(name) CAT_SUFFIX(name, RTCD_ARCH)
|
||||
|
||||
# if !defined(OPUS_GNUC_PREREQ)
|
||||
# if defined(__GNUC__)&&defined(__GNUC_MINOR__)
|
||||
# define OPUS_GNUC_PREREQ(_maj,_min) \
|
||||
((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
|
||||
# else
|
||||
# define OPUS_GNUC_PREREQ(_maj,_min) 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
|
||||
/* Force vectorization on for DNN code because some of the loops rely on
|
||||
compiler vectorization rather than explicitly using intrinsics. */
|
||||
#if OPUS_GNUC_PREREQ(5,1)
|
||||
#define GCC_POP_OPTIONS
|
||||
#pragma GCC push_options
|
||||
#pragma GCC optimize("tree-vectorize")
|
||||
#endif
|
||||
|
||||
|
||||
#define MAX_ACTIVATIONS (4096)
|
||||
|
||||
static OPUS_INLINE void vec_swish(float *y, const float *x, int N)
|
||||
{
|
||||
int i;
|
||||
float tmp[MAX_ACTIVATIONS];
|
||||
celt_assert(N <= MAX_ACTIVATIONS);
|
||||
vec_sigmoid(tmp, x, N);
|
||||
for (i=0;i<N;i++)
|
||||
y[i] = x[i]*tmp[i];
|
||||
}
|
||||
|
||||
static OPUS_INLINE float relu(float x)
|
||||
{
|
||||
return x < 0 ? 0 : x;
|
||||
}
|
||||
|
||||
/*#define HIGH_ACCURACY */
|
||||
|
||||
void RTCD_SUF(compute_activation_)(float *output, const float *input, int N, int activation)
|
||||
{
|
||||
int i;
|
||||
if (activation == ACTIVATION_SIGMOID) {
|
||||
#ifdef HIGH_ACCURACY
|
||||
for (int n=0; n<N; n++)
|
||||
{
|
||||
output[n] = 1.f / (1 + exp(-input[n]));
|
||||
}
|
||||
#else
|
||||
vec_sigmoid(output, input, N);
|
||||
#endif
|
||||
} else if (activation == ACTIVATION_TANH) {
|
||||
#ifdef HIGH_ACCURACY
|
||||
for (int n=0; n<N; n++)
|
||||
{
|
||||
output[n] = tanh(input[n]);
|
||||
}
|
||||
#else
|
||||
vec_tanh(output, input, N);
|
||||
#endif
|
||||
} else if (activation == ACTIVATION_SWISH) {
|
||||
vec_swish(output, input, N);
|
||||
} else if (activation == ACTIVATION_RELU) {
|
||||
for (i=0;i<N;i++)
|
||||
output[i] = relu(input[i]);
|
||||
} else if (activation == ACTIVATION_SOFTMAX) {
|
||||
#ifdef SOFTMAX_HACK
|
||||
RNN_COPY(output, input, N);
|
||||
/*for (i=0;i<N;i++)
|
||||
output[i] = input[i];*/
|
||||
#else
|
||||
float sum = 0;
|
||||
softmax(output, input, N);
|
||||
for (i=0;i<N;i++) {
|
||||
sum += output[i];
|
||||
}
|
||||
sum = 1.f/(sum+1e-30);
|
||||
for (i=0;i<N;i++)
|
||||
output[i] = sum*output[i];
|
||||
#endif
|
||||
} else {
|
||||
celt_assert(activation == ACTIVATION_LINEAR);
|
||||
if (input != output) {
|
||||
for (i=0;i<N;i++)
|
||||
output[i] = input[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RTCD_SUF(compute_linear_) (const LinearLayer *linear, float *out, const float *in)
|
||||
{
|
||||
int i, M, N;
|
||||
const float *bias;
|
||||
celt_assert(in != out);
|
||||
bias = linear->bias;
|
||||
M = linear->nb_inputs;
|
||||
N = linear->nb_outputs;
|
||||
if (linear->float_weights != NULL) {
|
||||
if (linear->weights_idx != NULL) sparse_sgemv8x4(out, linear->float_weights, linear->weights_idx, N, in);
|
||||
else sgemv(out, linear->float_weights, N, M, N, in);
|
||||
} else if (linear->weights != NULL) {
|
||||
if (linear->weights_idx != NULL) sparse_cgemv8x4(out, linear->weights, linear->weights_idx, linear->scale, N, M, in);
|
||||
else cgemv8x4(out, linear->weights, linear->scale, N, M, in);
|
||||
/* Only use SU biases on for integer matrices on SU archs. */
|
||||
#ifdef USE_SU_BIAS
|
||||
bias = linear->subias;
|
||||
#endif
|
||||
}
|
||||
else RNN_CLEAR(out, N);
|
||||
if (bias != NULL) {
|
||||
for (i=0;i<N;i++) out[i] += bias[i];
|
||||
}
|
||||
if (linear->diag) {
|
||||
/* Diag is only used for GRU recurrent weights. */
|
||||
celt_assert(3*M == N);
|
||||
for (i=0;i<M;i++) {
|
||||
out[i] += linear->diag[i]*in[i];
|
||||
out[i+M] += linear->diag[i+M]*in[i];
|
||||
out[i+2*M] += linear->diag[i+2*M]*in[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Computes non-padded convolution for input [ ksize1 x in_channels x (len2+ksize2) ],
|
||||
kernel [ out_channels x in_channels x ksize1 x ksize2 ],
|
||||
storing the output as [ out_channels x len2 ].
|
||||
We assume that the output dimension along the ksize1 axis is 1,
|
||||
i.e. processing one frame at a time. */
|
||||
static void conv2d_float(float *out, const float *weights, int in_channels, int out_channels, int ktime, int kheight, const float *in, int height, int hstride)
|
||||
{
|
||||
int i;
|
||||
int in_stride;
|
||||
in_stride = height+kheight-1;
|
||||
for (i=0;i<out_channels;i++) {
|
||||
int m;
|
||||
RNN_CLEAR(&out[i*hstride], height);
|
||||
for (m=0;m<in_channels;m++) {
|
||||
int t;
|
||||
for (t=0;t<ktime;t++) {
|
||||
int h;
|
||||
for (h=0;h<kheight;h++) {
|
||||
int j;
|
||||
for (j=0;j<height;j++) {
|
||||
out[i*hstride + j] += weights[i*in_channels*ktime*kheight + m*ktime*kheight + t*kheight + h] *
|
||||
in[t*in_channels*in_stride + m*in_stride + j + h];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* There's no intrinsics in this function (or the one above) because the gcc (and hopefully other compiler) auto-vectorizer is smart enough to
|
||||
produce the right code by itself based on the compile flags. */
|
||||
static void conv2d_3x3_float(float *out, const float *weights, int in_channels, int out_channels, const float *in, int height, int hstride)
|
||||
{
|
||||
int i;
|
||||
int in_stride;
|
||||
int kheight, ktime;
|
||||
kheight = ktime = 3;
|
||||
in_stride = height+kheight-1;
|
||||
for (i=0;i<out_channels;i++) {
|
||||
int m;
|
||||
RNN_CLEAR(&out[i*hstride], height);
|
||||
for (m=0;m<in_channels;m++) {
|
||||
int j;
|
||||
for (j=0;j<height;j++) {
|
||||
/* Unrolled version of previous function -- compiler will figure out the indexing simplifications. */
|
||||
out[i*hstride + j] += weights[i*in_channels*ktime*kheight + m*ktime*kheight + 0*kheight + 0]*in[0*in_channels*in_stride + m*in_stride + j + 0]
|
||||
+ weights[i*in_channels*ktime*kheight + m*ktime*kheight + 0*kheight + 1]*in[0*in_channels*in_stride + m*in_stride + j + 1]
|
||||
+ weights[i*in_channels*ktime*kheight + m*ktime*kheight + 0*kheight + 2]*in[0*in_channels*in_stride + m*in_stride + j + 2]
|
||||
+ weights[i*in_channels*ktime*kheight + m*ktime*kheight + 1*kheight + 0]*in[1*in_channels*in_stride + m*in_stride + j + 0]
|
||||
+ weights[i*in_channels*ktime*kheight + m*ktime*kheight + 1*kheight + 1]*in[1*in_channels*in_stride + m*in_stride + j + 1]
|
||||
+ weights[i*in_channels*ktime*kheight + m*ktime*kheight + 1*kheight + 2]*in[1*in_channels*in_stride + m*in_stride + j + 2]
|
||||
+ weights[i*in_channels*ktime*kheight + m*ktime*kheight + 2*kheight + 0]*in[2*in_channels*in_stride + m*in_stride + j + 0]
|
||||
+ weights[i*in_channels*ktime*kheight + m*ktime*kheight + 2*kheight + 1]*in[2*in_channels*in_stride + m*in_stride + j + 1]
|
||||
+ weights[i*in_channels*ktime*kheight + m*ktime*kheight + 2*kheight + 2]*in[2*in_channels*in_stride + m*in_stride + j + 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MAX_CONV2D_INPUTS 8192
|
||||
|
||||
void RTCD_SUF(compute_conv2d_)(const Conv2dLayer *conv, float *out, float *mem, const float *in, int height, int hstride, int activation)
|
||||
{
|
||||
int i;
|
||||
const float *bias;
|
||||
float in_buf[MAX_CONV2D_INPUTS];
|
||||
int time_stride;
|
||||
celt_assert(in != out);
|
||||
time_stride = conv->in_channels*(height+conv->kheight-1);
|
||||
celt_assert(conv->ktime*time_stride <= MAX_CONV2D_INPUTS);
|
||||
RNN_COPY(in_buf, mem, (conv->ktime-1)*time_stride);
|
||||
RNN_COPY(&in_buf[(conv->ktime-1)*time_stride], in, time_stride);
|
||||
RNN_COPY(mem, &in_buf[time_stride], (conv->ktime-1)*time_stride);
|
||||
bias = conv->bias;
|
||||
if (conv->kheight == 3 && conv->ktime == 3)
|
||||
conv2d_3x3_float(out, conv->float_weights, conv->in_channels, conv->out_channels, in_buf, height, hstride);
|
||||
else
|
||||
conv2d_float(out, conv->float_weights, conv->in_channels, conv->out_channels, conv->ktime, conv->kheight, in_buf, height, hstride);
|
||||
if (bias != NULL) {
|
||||
for (i=0;i<conv->out_channels;i++) {
|
||||
int j;
|
||||
for (j=0;j<height;j++) out[i*hstride+j] += bias[i];
|
||||
}
|
||||
}
|
||||
for (i=0;i<conv->out_channels;i++) {
|
||||
RTCD_SUF(compute_activation_)(&out[i*hstride], &out[i*hstride], height, activation);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef GCC_POP_OPTIONS
|
||||
#pragma GCC pop_options
|
||||
#endif
|
||||
|
||||
#endif
|
||||
35
src/modules/ZoomIt/ZoomIt/rnnoise/nnet_default.c
Normal file
35
src/modules/ZoomIt/ZoomIt/rnnoise/nnet_default.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* Copyright (c) 2018-2019 Mozilla
|
||||
2023 Amazon */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define RTCD_ARCH c
|
||||
|
||||
#include "nnet_arch.h"
|
||||
159
src/modules/ZoomIt/ZoomIt/rnnoise/opus_types.h
Normal file
159
src/modules/ZoomIt/ZoomIt/rnnoise/opus_types.h
Normal file
@@ -0,0 +1,159 @@
|
||||
/* (C) COPYRIGHT 1994-2002 Xiph.Org Foundation */
|
||||
/* Modified by Jean-Marc Valin */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/* opus_types.h based on ogg_types.h from libogg */
|
||||
|
||||
/**
|
||||
@file opus_types.h
|
||||
@brief Opus reference implementation types
|
||||
*/
|
||||
#ifndef OPUS_TYPES_H
|
||||
#define OPUS_TYPES_H
|
||||
|
||||
/* Use the real stdint.h if it's there (taken from Paul Hsieh's pstdint.h) */
|
||||
#if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) || defined (HAVE_STDINT_H))
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int16_t opus_int16;
|
||||
typedef uint16_t opus_uint16;
|
||||
typedef int32_t opus_int32;
|
||||
typedef uint32_t opus_uint32;
|
||||
#elif defined(_WIN32)
|
||||
|
||||
# if defined(__CYGWIN__)
|
||||
# include <_G_config.h>
|
||||
typedef _G_int32_t opus_int32;
|
||||
typedef _G_uint32_t opus_uint32;
|
||||
typedef _G_int16 opus_int16;
|
||||
typedef _G_uint16 opus_uint16;
|
||||
# elif defined(__MINGW32__)
|
||||
typedef short opus_int16;
|
||||
typedef unsigned short opus_uint16;
|
||||
typedef int opus_int32;
|
||||
typedef unsigned int opus_uint32;
|
||||
# elif defined(__MWERKS__)
|
||||
typedef int opus_int32;
|
||||
typedef unsigned int opus_uint32;
|
||||
typedef short opus_int16;
|
||||
typedef unsigned short opus_uint16;
|
||||
# else
|
||||
/* MSVC/Borland */
|
||||
typedef __int32 opus_int32;
|
||||
typedef unsigned __int32 opus_uint32;
|
||||
typedef __int16 opus_int16;
|
||||
typedef unsigned __int16 opus_uint16;
|
||||
# endif
|
||||
|
||||
#elif defined(__MACOS__)
|
||||
|
||||
# include <sys/types.h>
|
||||
typedef SInt16 opus_int16;
|
||||
typedef UInt16 opus_uint16;
|
||||
typedef SInt32 opus_int32;
|
||||
typedef UInt32 opus_uint32;
|
||||
|
||||
#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */
|
||||
|
||||
# include <sys/types.h>
|
||||
typedef int16_t opus_int16;
|
||||
typedef u_int16_t opus_uint16;
|
||||
typedef int32_t opus_int32;
|
||||
typedef u_int32_t opus_uint32;
|
||||
|
||||
#elif defined(__BEOS__)
|
||||
|
||||
/* Be */
|
||||
# include <inttypes.h>
|
||||
typedef int16 opus_int16;
|
||||
typedef u_int16 opus_uint16;
|
||||
typedef int32_t opus_int32;
|
||||
typedef u_int32_t opus_uint32;
|
||||
|
||||
#elif defined (__EMX__)
|
||||
|
||||
/* OS/2 GCC */
|
||||
typedef short opus_int16;
|
||||
typedef unsigned short opus_uint16;
|
||||
typedef int opus_int32;
|
||||
typedef unsigned int opus_uint32;
|
||||
|
||||
#elif defined (DJGPP)
|
||||
|
||||
/* DJGPP */
|
||||
typedef short opus_int16;
|
||||
typedef unsigned short opus_uint16;
|
||||
typedef int opus_int32;
|
||||
typedef unsigned int opus_uint32;
|
||||
|
||||
#elif defined(R5900)
|
||||
|
||||
/* PS2 EE */
|
||||
typedef int opus_int32;
|
||||
typedef unsigned opus_uint32;
|
||||
typedef short opus_int16;
|
||||
typedef unsigned short opus_uint16;
|
||||
|
||||
#elif defined(__SYMBIAN32__)
|
||||
|
||||
/* Symbian GCC */
|
||||
typedef signed short opus_int16;
|
||||
typedef unsigned short opus_uint16;
|
||||
typedef signed int opus_int32;
|
||||
typedef unsigned int opus_uint32;
|
||||
|
||||
#elif defined(CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
|
||||
|
||||
typedef short opus_int16;
|
||||
typedef unsigned short opus_uint16;
|
||||
typedef long opus_int32;
|
||||
typedef unsigned long opus_uint32;
|
||||
|
||||
#elif defined(CONFIG_TI_C6X)
|
||||
|
||||
typedef short opus_int16;
|
||||
typedef unsigned short opus_uint16;
|
||||
typedef int opus_int32;
|
||||
typedef unsigned int opus_uint32;
|
||||
|
||||
#else
|
||||
|
||||
/* Give up, take a reasonable guess */
|
||||
typedef short opus_int16;
|
||||
typedef unsigned short opus_uint16;
|
||||
typedef int opus_int32;
|
||||
typedef unsigned int opus_uint32;
|
||||
|
||||
#endif
|
||||
|
||||
#define opus_int int /* used for counters etc; at least 16 bits */
|
||||
#define opus_int64 long long
|
||||
#define opus_int8 signed char
|
||||
|
||||
#define opus_uint unsigned int /* used for counters etc; at least 16 bits */
|
||||
#define opus_uint64 unsigned long long
|
||||
#define opus_uint8 unsigned char
|
||||
|
||||
#endif /* OPUS_TYPES_H */
|
||||
237
src/modules/ZoomIt/ZoomIt/rnnoise/parse_lpcnet_weights.c
Normal file
237
src/modules/ZoomIt/ZoomIt/rnnoise/parse_lpcnet_weights.c
Normal file
@@ -0,0 +1,237 @@
|
||||
/* Copyright (c) 2023 Amazon */
|
||||
/*
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "nnet.h"
|
||||
|
||||
#define SPARSE_BLOCK_SIZE 32
|
||||
|
||||
static int parse_record(const void **data, int *len, WeightArray *array) {
|
||||
WeightHead *h = (WeightHead *)*data;
|
||||
if (*len < WEIGHT_BLOCK_SIZE) return -1;
|
||||
if (h->block_size < h->size) return -1;
|
||||
if (h->block_size > *len-WEIGHT_BLOCK_SIZE) return -1;
|
||||
if (h->name[sizeof(h->name)-1] != 0) return -1;
|
||||
if (h->size < 0) return -1;
|
||||
array->name = h->name;
|
||||
array->type = h->type;
|
||||
array->size = h->size;
|
||||
array->data = (void*)((unsigned char*)(*data)+WEIGHT_BLOCK_SIZE);
|
||||
|
||||
*data = (void*)((unsigned char*)*data + h->block_size+WEIGHT_BLOCK_SIZE);
|
||||
*len -= h->block_size+WEIGHT_BLOCK_SIZE;
|
||||
return array->size;
|
||||
}
|
||||
|
||||
int parse_weights(WeightArray **list, const void *data, int len)
|
||||
{
|
||||
int nb_arrays=0;
|
||||
int capacity=20;
|
||||
*list = calloc(capacity*sizeof(WeightArray), 1);
|
||||
while (len > 0) {
|
||||
int ret;
|
||||
WeightArray array = {NULL, 0, 0, 0};
|
||||
ret = parse_record(&data, &len, &array);
|
||||
if (ret > 0) {
|
||||
if (nb_arrays+1 >= capacity) {
|
||||
/* Make sure there's room for the ending NULL element too. */
|
||||
capacity = capacity*3/2;
|
||||
*list = realloc(*list, capacity*sizeof(WeightArray));
|
||||
}
|
||||
(*list)[nb_arrays++] = array;
|
||||
} else {
|
||||
free(*list);
|
||||
*list = NULL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
(*list)[nb_arrays].name=NULL;
|
||||
return nb_arrays;
|
||||
}
|
||||
|
||||
static const void *find_array_entry(const WeightArray *arrays, const char *name) {
|
||||
while (arrays->name && strcmp(arrays->name, name) != 0) arrays++;
|
||||
return arrays;
|
||||
}
|
||||
|
||||
static const void *find_array_check(const WeightArray *arrays, const char *name, int size) {
|
||||
const WeightArray *a = find_array_entry(arrays, name);
|
||||
if (a->name && a->size == size) return a->data;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
static const void *opt_array_check(const WeightArray *arrays, const char *name, int size, int *error) {
|
||||
const WeightArray *a = find_array_entry(arrays, name);
|
||||
*error = (a->name != NULL && a->size != size);
|
||||
if (a->name && a->size == size) return a->data;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
static const void *find_idx_check(const WeightArray *arrays, const char *name, int nb_in, int nb_out, int *total_blocks) {
|
||||
int remain;
|
||||
const int *idx;
|
||||
const WeightArray *a = find_array_entry(arrays, name);
|
||||
*total_blocks = 0;
|
||||
if (a == NULL) return NULL;
|
||||
idx = a->data;
|
||||
remain = a->size/sizeof(int);
|
||||
while (remain > 0) {
|
||||
int nb_blocks;
|
||||
int i;
|
||||
nb_blocks = *idx++;
|
||||
if (remain < nb_blocks+1) return NULL;
|
||||
for (i=0;i<nb_blocks;i++) {
|
||||
int pos = *idx++;
|
||||
if (pos+3 >= nb_in || (pos&0x3)) return NULL;
|
||||
}
|
||||
nb_out -= 8;
|
||||
remain -= nb_blocks+1;
|
||||
*total_blocks += nb_blocks;
|
||||
}
|
||||
if (nb_out != 0) return NULL;
|
||||
return a->data;
|
||||
}
|
||||
|
||||
int linear_init(LinearLayer *layer, const WeightArray *arrays,
|
||||
const char *bias,
|
||||
const char *subias,
|
||||
const char *weights,
|
||||
const char *float_weights,
|
||||
const char *weights_idx,
|
||||
const char *diag,
|
||||
const char *scale,
|
||||
int nb_inputs,
|
||||
int nb_outputs)
|
||||
{
|
||||
int err;
|
||||
layer->bias = NULL;
|
||||
layer->subias = NULL;
|
||||
layer->weights = NULL;
|
||||
layer->float_weights = NULL;
|
||||
layer->weights_idx = NULL;
|
||||
layer->diag = NULL;
|
||||
layer->scale = NULL;
|
||||
if (bias != NULL) {
|
||||
if ((layer->bias = find_array_check(arrays, bias, nb_outputs*sizeof(layer->bias[0]))) == NULL) return 1;
|
||||
}
|
||||
if (subias != NULL) {
|
||||
if ((layer->subias = find_array_check(arrays, subias, nb_outputs*sizeof(layer->subias[0]))) == NULL) return 1;
|
||||
}
|
||||
if (weights_idx != NULL) {
|
||||
int total_blocks;
|
||||
if ((layer->weights_idx = find_idx_check(arrays, weights_idx, nb_inputs, nb_outputs, &total_blocks)) == NULL) return 1;
|
||||
if (weights != NULL) {
|
||||
if ((layer->weights = find_array_check(arrays, weights, SPARSE_BLOCK_SIZE*total_blocks*sizeof(layer->weights[0]))) == NULL) return 1;
|
||||
}
|
||||
if (float_weights != NULL) {
|
||||
layer->float_weights = opt_array_check(arrays, float_weights, SPARSE_BLOCK_SIZE*total_blocks*sizeof(layer->float_weights[0]), &err);
|
||||
if (err) return 1;
|
||||
}
|
||||
} else {
|
||||
if (weights != NULL) {
|
||||
if ((layer->weights = find_array_check(arrays, weights, nb_inputs*nb_outputs*sizeof(layer->weights[0]))) == NULL) return 1;
|
||||
}
|
||||
if (float_weights != NULL) {
|
||||
layer->float_weights = opt_array_check(arrays, float_weights, nb_inputs*nb_outputs*sizeof(layer->float_weights[0]), &err);
|
||||
if (err) return 1;
|
||||
}
|
||||
}
|
||||
if (diag != NULL) {
|
||||
if ((layer->diag = find_array_check(arrays, diag, nb_outputs*sizeof(layer->diag[0]))) == NULL) return 1;
|
||||
}
|
||||
if (weights != NULL) {
|
||||
if ((layer->scale = find_array_check(arrays, scale, nb_outputs*sizeof(layer->scale[0]))) == NULL) return 1;
|
||||
}
|
||||
layer->nb_inputs = nb_inputs;
|
||||
layer->nb_outputs = nb_outputs;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int conv2d_init(Conv2dLayer *layer, const WeightArray *arrays,
|
||||
const char *bias,
|
||||
const char *float_weights,
|
||||
int in_channels,
|
||||
int out_channels,
|
||||
int ktime,
|
||||
int kheight)
|
||||
{
|
||||
int err;
|
||||
layer->bias = NULL;
|
||||
layer->float_weights = NULL;
|
||||
if (bias != NULL) {
|
||||
if ((layer->bias = find_array_check(arrays, bias, out_channels*sizeof(layer->bias[0]))) == NULL) return 1;
|
||||
}
|
||||
if (float_weights != NULL) {
|
||||
layer->float_weights = opt_array_check(arrays, float_weights, in_channels*out_channels*ktime*kheight*sizeof(layer->float_weights[0]), &err);
|
||||
if (err) return 1;
|
||||
}
|
||||
layer->in_channels = in_channels;
|
||||
layer->out_channels = out_channels;
|
||||
layer->ktime = ktime;
|
||||
layer->kheight = kheight;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int fd;
|
||||
void *data;
|
||||
int len;
|
||||
int nb_arrays;
|
||||
int i;
|
||||
WeightArray *list;
|
||||
struct stat st;
|
||||
const char *filename = "weights_blob.bin";
|
||||
stat(filename, &st);
|
||||
len = st.st_size;
|
||||
fd = open(filename, O_RDONLY);
|
||||
data = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0);
|
||||
printf("size is %d\n", len);
|
||||
nb_arrays = parse_weights(&list, data, len);
|
||||
for (i=0;i<nb_arrays;i++) {
|
||||
printf("found %s: size %d\n", list[i].name, list[i].size);
|
||||
}
|
||||
printf("%p\n", list[i].name);
|
||||
free(list);
|
||||
munmap(data, len);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user