Repository navigation
Expand file tree
/
Copy pathapp.rs
More file actions
572 lines (528 loc) · 20 KB
/
Copy pathapp.rs
File metadata and controls
572 lines (528 loc) · 20 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
//! GUI native (Win32) : preview/playback du compositing + export avec barre de
//! progression et bilan (temps + fps). Rapproche le POC d'une intégration app :
//! le compositeur/pipeline mesuré alimente une vraie boucle de rendu interactive.
//!
//! Architecture :
//! - une fenêtre hôte, un enfant "preview" portant une swapchain DXGI flip sur le
//! device D3D11 partagé (blit zéro-copie du RT composité → backbuffer) ;
//! - des contrôles Win32 natifs (combo preset, Play/Pause, Export, barre, label) —
//! aucun rendu de texte maison ;
//! - un modèle mono-thread coopératif : WM_TIMER cadence la playback à 60 fps ;
//! l'export tourne sur le thread UI et rafraîchit la barre entre frames.
use openscreen_compositor::compositor::{Compositor, FIXTURE_FRAMES, OUT_H, OUT_W};
use openscreen_compositor::config::{self, Cfg};
use openscreen_compositor::cursor::CursorTrack;
use openscreen_compositor::d3d::Gpu;
use openscreen_compositor::live::Player;
use openscreen_compositor::pipeline;
use anyhow::Result;
use std::ffi::c_void;
use std::time::Instant;
use windows::core::{Interface, PCWSTR};
use windows::Win32::Foundation::{HWND, LPARAM, LRESULT, RECT, WPARAM};
use windows::Win32::Graphics::Direct3D11::ID3D11RenderTargetView;
use windows::Win32::Graphics::Dxgi::Common::{
DXGI_ALPHA_MODE_IGNORE, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_SAMPLE_DESC,
};
use windows::Win32::Graphics::Dxgi::{
IDXGIAdapter, IDXGIDevice, IDXGIFactory2, IDXGISwapChain1, DXGI_PRESENT,
DXGI_SCALING_STRETCH, DXGI_SWAP_CHAIN_DESC1, DXGI_SWAP_EFFECT_FLIP_DISCARD,
DXGI_USAGE_RENDER_TARGET_OUTPUT,
};
use windows::Win32::Graphics::Gdi::{
CreateFontW, GetSysColorBrush, UpdateWindow, COLOR_BTNFACE, HFONT,
};
use windows::Win32::System::LibraryLoader::GetModuleHandleW;
use windows::Win32::UI::Input::KeyboardAndMouse::EnableWindow;
use windows::Win32::UI::Controls::{
InitCommonControlsEx, ICC_PROGRESS_CLASS, ICC_STANDARD_CLASSES, INITCOMMONCONTROLSEX,
PBM_SETPOS, PBM_SETRANGE32,
};
use windows::Win32::UI::WindowsAndMessaging::*;
const PREVIEW_W: i32 = 1280;
const PREVIEW_H: i32 = 720;
const STRIP_H: i32 = 64;
const CLIENT_W: i32 = PREVIEW_W;
const CLIENT_H: i32 = PREVIEW_H + STRIP_H;
const ID_COMBO: isize = 101;
const ID_PLAY: isize = 102;
const ID_EXPORT: isize = 103;
const ID_PROGRESS: isize = 104;
const ID_STATUS: isize = 105;
const TIMER_TICK: usize = 1;
/// Chaîne UTF-16 terminée par NUL (durée de vie tenue par l'appelant).
fn wide(s: &str) -> Vec<u16> {
s.encode_utf16().chain(std::iter::once(0)).collect()
}
/// Plus grand rectangle 16:9 centré dans `(cw, ch)` → viewport letterbox de la preview.
fn letterbox(cw: f32, ch: f32) -> (f32, f32, f32, f32) {
let ar = OUT_W as f32 / OUT_H as f32;
let (mut w, mut h) = (cw, ch);
if cw / ch > ar {
w = ch * ar;
} else {
h = cw / ar;
}
((cw - w) * 0.5, (ch - h) * 0.5, w, h)
}
/// État applicatif complet (possédé par la fenêtre via GWLP_USERDATA).
struct App {
gpu: Gpu,
comp: Compositor,
player: Player,
cfgs: Vec<Cfg>,
cur: usize,
playing: bool,
exporting: bool,
total_frames: u64,
screen: String,
webcam: String,
out: String,
// win32
preview: HWND,
combo: HWND,
play_btn: HWND,
export_btn: HWND,
progress: HWND,
status: HWND,
// dxgi (preview)
swap: Option<IDXGISwapChain1>,
bb_rtv: Option<ID3D11RenderTargetView>,
// cadence playback
last: Instant,
acc: f64,
}
impl App {
/// Compose + affiche la 1re frame, avant l'ouverture de la fenêtre. Cible `INFINITY` :
/// on veut cette toute première frame quel que soit son pts, la notion de "due" n'a pas
/// encore de sens avant le premier tick réel (cf. `Player::step`, sémantique de hold).
unsafe fn init_first_frame(&mut self) {
let cfg = self.cfgs[self.cur].clone();
let _ = self.player.step(&self.comp, &cfg, f64::INFINITY);
let _ = self.render();
self.update_ready_status();
self.last = Instant::now();
}
/// Cadence 60 fps par horloge murale (accumulateur), avec garde anti-spirale.
///
/// `self.acc` est une CIBLE de temps source (mis à l'échelle par le temps réel écoulé),
/// pas un compte de frames à décoder — `Player::step` n'adopte une frame que si son pts
/// est réellement dû, sinon il tient la frame courante (hold). Sans ça, ce harnais
/// consommerait une frame réelle par 1/60s de temps réel même quand la source n'en livre
/// pas autant (cf. la doc de `Player::step` côté lib, même bug que la preview Electron).
unsafe fn on_tick(&mut self) -> Result<()> {
if self.exporting || !self.playing {
return Ok(());
}
let now = Instant::now();
let dt = (now - self.last).as_secs_f64().min(0.1);
self.last = now;
self.acc += dt;
let cfg = self.cfgs[self.cur].clone();
let mut stepped = false;
let mut n = 0;
loop {
let before = self.player.screen_time_sec();
let target = before + self.acc;
if !self.player.step(&self.comp, &cfg, target)? {
break; // rien de dû pour l'instant : `self.acc` reste tel quel.
}
stepped = true;
let after = self.player.screen_time_sec();
self.acc = if after >= before {
(self.acc - (after - before)).max(0.0)
} else {
0.0 // reboucle sur l'EOF (temps qui recule) : accumulateur remis à zéro.
};
n += 1;
if n >= 3 {
self.acc = 0.0; // largue le retard accumulé (fenêtre masquée, etc.)
break;
}
}
if stepped {
self.render()?;
}
Ok(())
}
/// Blit du RT composité vers le backbuffer, letterboxé, puis Present (vsync).
unsafe fn render(&mut self) -> Result<()> {
let (Some(swap), Some(rtv)) = (self.swap.as_ref(), self.bb_rtv.as_ref()) else {
return Ok(());
};
let mut rc = RECT::default();
let _ = GetClientRect(self.preview, &mut rc);
let cw = (rc.right - rc.left).max(1) as f32;
let ch = (rc.bottom - rc.top).max(1) as f32;
let (x, y, w, h) = letterbox(cw, ch);
self.gpu.context.ClearRenderTargetView(rtv, &[0.02, 0.02, 0.03, 1.0]);
self.comp.blit_to(rtv, x, y, w, h);
let _ = swap.Present(1, DXGI_PRESENT(0));
Ok(())
}
unsafe fn on_command(&mut self, wp: WPARAM) -> Result<()> {
let id = (wp.0 & 0xffff) as isize;
let code = ((wp.0 >> 16) & 0xffff) as u32;
match id {
ID_PLAY => self.toggle_play(),
ID_EXPORT => self.run_export()?,
ID_COMBO if code == CBN_SELCHANGE => {
let sel = SendMessageW(self.combo, CB_GETCURSEL, WPARAM(0), LPARAM(0)).0;
if sel >= 0 && (sel as usize) < self.cfgs.len() {
self.cur = sel as usize;
if !self.playing {
let cfg = self.cfgs[self.cur].clone();
let _ = self.player.recompose(&self.comp, &cfg);
let _ = self.render();
}
self.update_ready_status();
}
}
_ => {}
}
Ok(())
}
unsafe fn toggle_play(&mut self) {
self.playing = !self.playing;
let label = wide(if self.playing { "Pause" } else { "Play" });
let _ = SetWindowTextW(self.play_btn, PCWSTR(label.as_ptr()));
self.last = Instant::now();
self.acc = 0.0;
}
/// Export coopératif (thread UI) : la barre avance via SendMessage+UpdateWindow sur le
/// contrôle (pas de re-pompage du message-loop → aucune réentrance dans notre wndproc).
/// La mesure fps reste enveloppante (§10) dans `run_composited`.
unsafe fn run_export(&mut self) -> Result<()> {
if self.exporting {
return Ok(());
}
self.exporting = true;
self.playing = false;
let pl = wide("Play");
let _ = SetWindowTextW(self.play_btn, PCWSTR(pl.as_ptr()));
let _ = EnableWindow(self.export_btn, false);
let _ = EnableWindow(self.play_btn, false);
let _ = EnableWindow(self.combo, false);
SendMessageW(self.progress, PBM_SETRANGE32, WPARAM(0), LPARAM(self.total_frames as isize));
SendMessageW(self.progress, PBM_SETPOS, WPARAM(0), LPARAM(0));
let cfg = self.cfgs[self.cur].clone();
let s = wide(&format!("Exporting {} — {} …", cfg.name, cfg.desc));
let _ = SetWindowTextW(self.status, PCWSTR(s.as_ptr()));
let _ = UpdateWindow(self.status);
let _ = UpdateWindow(self.progress);
// sonde de progression : SendMessage throttlé au pourcent (µs, cf. §10).
let prog = self.progress;
let total = self.total_frames.max(1);
let mut last_pct: i64 = -1;
let mut cb = move |done: u64| {
let pct = (done as i64 * 100) / total as i64;
if pct != last_pct {
last_pct = pct;
SendMessageW(prog, PBM_SETPOS, WPARAM(done as usize), LPARAM(0));
let _ = UpdateWindow(prog);
}
};
let r = pipeline::run_composited(
&self.screen, &self.webcam, &self.out, &self.gpu, &self.comp, &cfg, &mut cb,
);
self.comp.clear_srv_cache();
let _ = EnableWindow(self.export_btn, true);
let _ = EnableWindow(self.play_btn, true);
let _ = EnableWindow(self.combo, true);
self.exporting = false;
match r {
Ok(st) => {
SendMessageW(self.progress, PBM_SETPOS, WPARAM(st.frames as usize), LPARAM(0));
let msg = format!(
"Done — {} · {} frames · {:.2}s · {:.1} fps -> {}",
cfg.name, st.frames, st.wall_s, st.fps, self.out
);
let w = wide(&msg);
let _ = SetWindowTextW(self.status, PCWSTR(w.as_ptr()));
}
Err(e) => {
let w = wide(&format!("Export failed: {e}"));
let _ = SetWindowTextW(self.status, PCWSTR(w.as_ptr()));
}
}
// reprise de la playback
self.playing = true;
let pb = wide("Pause");
let _ = SetWindowTextW(self.play_btn, PCWSTR(pb.as_ptr()));
self.last = Instant::now();
self.acc = 0.0;
Ok(())
}
unsafe fn update_ready_status(&self) {
let cfg = &self.cfgs[self.cur];
let s = wide(&format!(
"Ready - {} · {} ({} frames · export -> {})",
cfg.name, cfg.desc, self.total_frames, self.out
));
let _ = SetWindowTextW(self.status, PCWSTR(s.as_ptr()));
}
unsafe fn report_err(&self, e: &anyhow::Error) {
let w = wide(&format!("error: {e}"));
let _ = SetWindowTextW(self.status, PCWSTR(w.as_ptr()));
eprintln!("[app] error: {e:#}");
}
}
/// Police Segoe UI 9pt ClearType — les contrôles créés par CreateWindowEx héritent sinon
/// d'une vieille police bitmap système. Fuit un HFONT (durée de vie = process).
unsafe fn ui_font() -> HFONT {
let face = wide("Segoe UI");
// (height=-12 ≈ 9pt @96dpi, weight=400, charset=DEFAULT(1), quality=CLEARTYPE(5))
CreateFontW(-12, 0, 0, 0, 400, 0, 0, 0, 1, 0, 0, 5, 0, PCWSTR(face.as_ptr()))
}
/// Crée l'enfant preview + les contrôles natifs. Renvoie leurs HWND.
unsafe fn create_children(
parent: HWND,
hinst: windows::Win32::Foundation::HINSTANCE,
cfgs: &[Cfg],
) -> Result<(HWND, HWND, HWND, HWND, HWND, HWND)> {
let btn_cls = wide("BUTTON");
let combo_cls = wide("COMBOBOX");
let static_cls = wide("STATIC");
let prog_cls = wide("msctls_progress32");
let prev_cls = wide("PocD3DPreview");
let preview = CreateWindowExW(
WINDOW_EX_STYLE(0),
PCWSTR(prev_cls.as_ptr()),
PCWSTR::null(),
WS_CHILD | WS_VISIBLE,
0, 0, PREVIEW_W, PREVIEW_H,
parent,
HMENU::default(),
hinst,
None,
)?;
let y = PREVIEW_H + 18;
let combo_style =
WS_CHILD.0 | WS_VISIBLE.0 | WS_VSCROLL.0 | (CBS_DROPDOWNLIST as u32) | (CBS_HASSTRINGS as u32);
let combo = CreateWindowExW(
WINDOW_EX_STYLE(0),
PCWSTR(combo_cls.as_ptr()),
PCWSTR::null(),
WINDOW_STYLE(combo_style),
14, y - 3, 250, 340,
parent,
HMENU(ID_COMBO as *mut c_void),
hinst,
None,
)?;
for c in cfgs {
let item = wide(&format!("{} — {}", c.name, c.desc));
SendMessageW(combo, CB_ADDSTRING, WPARAM(0), LPARAM(item.as_ptr() as isize));
}
SendMessageW(combo, CB_SETCURSEL, WPARAM(cfgs.len() - 1), LPARAM(0));
let pl = wide("Pause");
let play_btn = CreateWindowExW(
WINDOW_EX_STYLE(0),
PCWSTR(btn_cls.as_ptr()),
PCWSTR(pl.as_ptr()),
WINDOW_STYLE(WS_CHILD.0 | WS_VISIBLE.0 | (BS_PUSHBUTTON as u32)),
278, y, 96, 30,
parent,
HMENU(ID_PLAY as *mut c_void),
hinst,
None,
)?;
let ex = wide("Export");
let export_btn = CreateWindowExW(
WINDOW_EX_STYLE(0),
PCWSTR(btn_cls.as_ptr()),
PCWSTR(ex.as_ptr()),
WINDOW_STYLE(WS_CHILD.0 | WS_VISIBLE.0 | (BS_PUSHBUTTON as u32)),
382, y, 96, 30,
parent,
HMENU(ID_EXPORT as *mut c_void),
hinst,
None,
)?;
let progress = CreateWindowExW(
WINDOW_EX_STYLE(0),
PCWSTR(prog_cls.as_ptr()),
PCWSTR::null(),
WS_CHILD | WS_VISIBLE,
494, y + 4, 300, 22,
parent,
HMENU(ID_PROGRESS as *mut c_void),
hinst,
None,
)?;
let st = wide("Ready");
let status = CreateWindowExW(
WINDOW_EX_STYLE(0),
PCWSTR(static_cls.as_ptr()),
PCWSTR(st.as_ptr()),
WS_CHILD | WS_VISIBLE,
808, y + 6, 458, 40,
parent,
HMENU(ID_STATUS as *mut c_void),
hinst,
None,
)?;
let font = ui_font();
for c in [combo, play_btn, export_btn, status] {
SendMessageW(c, WM_SETFONT, WPARAM(font.0 as usize), LPARAM(1));
}
Ok((combo, play_btn, export_btn, progress, status, preview))
}
/// Crée la swapchain flip + RTV du backbuffer sur le device D3D11 partagé.
unsafe fn create_swapchain(
device: &windows::Win32::Graphics::Direct3D11::ID3D11Device,
hwnd: HWND,
) -> Result<(IDXGISwapChain1, ID3D11RenderTargetView)> {
let dxdev: IDXGIDevice = device.cast()?;
let adapter: IDXGIAdapter = dxdev.GetAdapter()?;
let factory: IDXGIFactory2 = adapter.GetParent()?;
let desc = DXGI_SWAP_CHAIN_DESC1 {
Width: PREVIEW_W as u32,
Height: PREVIEW_H as u32,
Format: DXGI_FORMAT_R8G8B8A8_UNORM,
SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
BufferUsage: DXGI_USAGE_RENDER_TARGET_OUTPUT,
BufferCount: 2,
SwapEffect: DXGI_SWAP_EFFECT_FLIP_DISCARD,
Scaling: DXGI_SCALING_STRETCH,
AlphaMode: DXGI_ALPHA_MODE_IGNORE,
..Default::default()
};
let swap = factory.CreateSwapChainForHwnd(device, hwnd, &desc, None, None)?;
let bb: windows::Win32::Graphics::Direct3D11::ID3D11Texture2D = swap.GetBuffer(0)?;
let mut rtv: Option<ID3D11RenderTargetView> = None;
device.CreateRenderTargetView(&bb, None, Some(&mut rtv))?;
Ok((swap, rtv.unwrap()))
}
extern "system" fn wndproc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM) -> LRESULT {
unsafe {
let ptr = GetWindowLongPtrW(hwnd, GWLP_USERDATA) as *mut App;
if ptr.is_null() {
return DefWindowProcW(hwnd, msg, wp, lp);
}
let app = &mut *ptr;
match msg {
WM_TIMER => {
if let Err(e) = app.on_tick() {
app.report_err(&e);
}
LRESULT(0)
}
WM_COMMAND => {
if let Err(e) = app.on_command(wp) {
app.report_err(&e);
}
LRESULT(0)
}
WM_DESTROY => {
let _ = KillTimer(hwnd, TIMER_TICK);
PostQuitMessage(0);
LRESULT(0)
}
_ => DefWindowProcW(hwnd, msg, wp, lp),
}
}
}
/// Point d'entrée GUI (appelé par `main` quand aucun argument bench n'est passé).
pub fn run_gui(screen: &str, webcam: &str, cursor_json: &str, out_dir: &str) -> Result<()> {
unsafe { run_gui_inner(screen, webcam, cursor_json, out_dir) }
}
unsafe fn run_gui_inner(screen: &str, webcam: &str, cursor_json: &str, out_dir: &str) -> Result<()> {
std::fs::create_dir_all(out_dir).ok();
let out = format!("{out_dir}/export.mp4");
let gpu = Gpu::create(false)?;
println!("d3d11 device ok (feature_level 0x{:X})", gpu.feature_level.0 as u32);
let mut comp = Compositor::new(&gpu)?;
if let Ok(track) = CursorTrack::load(cursor_json, 100_000.0, 6.0) {
comp.set_cursor(track);
}
let player = Player::open(screen, webcam, &gpu)?;
let total_frames = pipeline::probe_frame_count(screen).unwrap_or(FIXTURE_FRAMES as u64);
let cfgs = config::all();
let cur = cfgs.len() - 1; // C8 (tous effets) par défaut
let hinst = windows::Win32::Foundation::HINSTANCE(GetModuleHandleW(None)?.0);
let icc = INITCOMMONCONTROLSEX {
dwSize: std::mem::size_of::<INITCOMMONCONTROLSEX>() as u32,
dwICC: ICC_PROGRESS_CLASS | ICC_STANDARD_CLASSES,
};
let _ = InitCommonControlsEx(&icc);
let main_cls = wide("PocD3DMain");
let prev_cls = wide("PocD3DPreview");
let cursor = LoadCursorW(None, IDC_ARROW)?;
let wc_main = WNDCLASSW {
style: CS_HREDRAW | CS_VREDRAW,
lpfnWndProc: Some(wndproc),
hInstance: hinst,
lpszClassName: PCWSTR(main_cls.as_ptr()),
hCursor: cursor,
hbrBackground: GetSysColorBrush(COLOR_BTNFACE),
..Default::default()
};
RegisterClassW(&wc_main);
let wc_prev = WNDCLASSW {
style: CS_HREDRAW | CS_VREDRAW,
lpfnWndProc: Some(wndproc), // USERDATA null sur l'enfant → DefWindowProcW
hInstance: hinst,
lpszClassName: PCWSTR(prev_cls.as_ptr()),
hCursor: cursor,
hbrBackground: windows::Win32::Graphics::Gdi::HBRUSH(std::ptr::null_mut()),
..Default::default()
};
RegisterClassW(&wc_prev);
let style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
let mut rc = RECT { left: 0, top: 0, right: CLIENT_W, bottom: CLIENT_H };
let _ = AdjustWindowRectEx(&mut rc, style, false, WINDOW_EX_STYLE(0));
let ww = rc.right - rc.left;
let wh = rc.bottom - rc.top;
let title = wide("OpenScreen — POC D3D11 compositor · preview + export");
let hwnd = CreateWindowExW(
WINDOW_EX_STYLE(0),
PCWSTR(main_cls.as_ptr()),
PCWSTR(title.as_ptr()),
style,
CW_USEDEFAULT, CW_USEDEFAULT, ww, wh,
HWND::default(),
HMENU::default(),
hinst,
None,
)?;
let (combo, play_btn, export_btn, progress, status, preview) =
create_children(hwnd, hinst, &cfgs)?;
let (swap, bb_rtv) = create_swapchain(&gpu.device, preview)?;
let app = Box::new(App {
gpu,
comp,
player,
cfgs,
cur,
playing: true,
exporting: false,
total_frames,
screen: screen.to_string(),
webcam: webcam.to_string(),
out,
preview,
combo,
play_btn,
export_btn,
progress,
status,
swap: Some(swap),
bb_rtv: Some(bb_rtv),
last: Instant::now(),
acc: 0.0,
});
let app_ptr = Box::into_raw(app);
SetWindowLongPtrW(hwnd, GWLP_USERDATA, app_ptr as isize);
(*app_ptr).init_first_frame();
let _ = ShowWindow(hwnd, SW_SHOW);
let _ = UpdateWindow(hwnd);
SetTimer(hwnd, TIMER_TICK, 15, None);
let mut msg = MSG::default();
while GetMessageW(&mut msg, HWND::default(), 0, 0).0 > 0 {
let _ = TranslateMessage(&msg);
DispatchMessageW(&msg);
}
drop(Box::from_raw(app_ptr));
Ok(())
}