-
Notifications
You must be signed in to change notification settings - Fork 94
/
DecPerformanceForm.cpp
568 lines (473 loc) · 16.8 KB
/
DecPerformanceForm.cpp
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
//-----------------------------------------------------------------------------
//
// MONOGRAM GraphStudio
//
// Author : Igor Janos
//
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "DecPerformanceForm.h"
#include "time_utils.h"
namespace
{
const int PASSES_MAX = 10000;
const int PASSES_DEFAULT = 10;
}
//-----------------------------------------------------------------------------
//
// CDecPerformanceForm class
//
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC(CDecPerformanceForm, CGraphStudioModelessDialog)
BEGIN_MESSAGE_MAP(CDecPerformanceForm, CGraphStudioModelessDialog)
ON_WM_SIZE()
ON_BN_CLICKED(IDC_BUTTON_BROWSE, &CDecPerformanceForm::OnBrowseClick)
ON_BN_CLICKED(IDC_BUTTON_PROPERTYPAGE, &CDecPerformanceForm::OnBnClickedButtonPropertypage)
ON_BN_CLICKED(IDC_BUTTON_START, &CDecPerformanceForm::OnStartClick)
ON_BN_CLICKED(IDC_BUTTON_STOP, &CDecPerformanceForm::OnStopClick)
ON_CBN_SELCHANGE(IDC_COMBO_TYPE, &CDecPerformanceForm::OnCbnSelChange)
ON_CBN_SELCHANGE(IDC_COMBO_DECODER, &CDecPerformanceForm::OnComboDecoderSelChange)
ON_BN_CLICKED(IDC_BUILDGRAPH, &CDecPerformanceForm::OnBuildGraphClick)
ON_COMMAND(IDOK, &CDecPerformanceForm::OnStartClick)
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
//
// CDecPerformanceForm class
//
//-----------------------------------------------------------------------------
CDecPerformanceForm::CDecPerformanceForm(CGraphView* parent_view) :
CGraphStudioModelessDialog(CDecPerformanceForm::IDD, parent_view)
{
view = parent_view;
running = false;
perf_operation = false;
null_renderer.clsid = DSUtil::CLSID_NullRenderer;
null_renderer.name = _T("Null Renderer");
null_renderer_dxva.clsid = __uuidof(DxvaNullRenderer);
null_renderer_dxva.name = _T("DXVA Null Renderer");
time_filter_template.clsid = __uuidof(TimeMeasureFilter);
time_filter_template.name = _T("Time Measure Filter");
}
CDecPerformanceForm::~CDecPerformanceForm()
{
}
void CDecPerformanceForm::DoDataExchange(CDataExchange* pDX)
{
__super::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TITLEBAR, title);
DDX_Control(pDX, IDC_COMBO_PRESETS, cb_presets);
DDX_Control(pDX, IDC_COMBO_FILE, cb_files);
DDX_Control(pDX, IDC_COMBO_DECODER, cb_decoders);
DDX_Control(pDX, IDC_COMBO_RENDERER, cb_renderers);
DDX_Control(pDX, IDC_BUTTON_SAVE, btn_save);
DDX_Control(pDX, IDC_BUTTON_CLEAR, btn_clear);
DDX_Control(pDX, IDC_BUTTON_START, btn_start);
DDX_Control(pDX, IDC_BUTTON_STOP, btn_stop);
DDX_Control(pDX, IDC_BUTTON_BROWSE, btn_browse);
DDX_Control(pDX, IDC_EDIT_PASSES, edit_passes);
DDX_Control(pDX, IDC_SPIN_PASSES, btn_spin);
DDX_Control(pDX, IDC_LIST_RESULTS, list_results);
DDX_Control(pDX, IDC_COMBO_TYPE, cb_type);
}
BOOL CDecPerformanceForm::DoCreateDialog(CWnd* parent)
{
BOOL ret = Create(IDD, parent);
if (!ret) return FALSE;
// prepare titlebar
title.ModifyStyle(0, WS_CLIPCHILDREN);
title.ModifyStyleEx(0, WS_EX_CONTROLPARENT);
OnInitialize();
return TRUE;
};
void CDecPerformanceForm::OnInitialize()
{
// Fill the filters & decoders & stuff ...
int i;
// load the file list
file_list.LoadList(_T("DecPerfFileList"));
cb_files.ResetContent();
for (i=0; i<file_list.GetCount(); i++) {
cb_files.AddString(file_list[i]);
}
// create the columns
DWORD ex_style = list_results.GetExtendedStyle();
ex_style = ex_style | LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_LABELTIP;
list_results.SetExtendedStyle(ex_style);
list_results.InsertColumn(0, _T("#"), LVCFMT_RIGHT, 36);
list_results.InsertColumn(1, _T("Work Time"), LVCFMT_LEFT, 80);
list_results.InsertColumn(2, _T("FPS"), LVCFMT_RIGHT, 100);
list_results.InsertColumn(3, _T("Rate"), LVCFMT_RIGHT, 100);
list_results.InsertColumn(4, _T("Real Time"), LVCFMT_LEFT, 80);
list_results.InsertColumn(5, _T("Frames"), LVCFMT_RIGHT, 80);
// now create the list of renderers
cb_type.AddString(_T("Audio"));
cb_type.AddString(_T("Video"));
cb_type.SetCurSel(1);
OnCbnSelChange();
phase_count = PASSES_DEFAULT;
CString str;
str.Format(_T("%d"), phase_count);
edit_passes.SetWindowText(str);
btn_spin.SetRange(1, PASSES_MAX);
btn_spin.SetPos(phase_count);
}
void CDecPerformanceForm::OnSize(UINT nType, int cx, int cy)
{
// resize our controls along...
CRect rc, rc2;
if (::IsWindow(title)) {
title.GetClientRect(&rc2);
title.SetWindowPos(NULL, 0, 0, cx, rc2.Height(), SWP_SHOWWINDOW | SWP_NOZORDER);
// invalidate all controls
title.Invalidate();
}
}
void CDecPerformanceForm::OnBrowseClick()
{
// nabrowsujeme subor
CString filter;
CString filename;
filter = _T("");
filter += _T("Audio Files |*.aac;*.ac3;*.mp3;*.wma;*.mka;*.ogg;*.mpc;*.flac;*.ape;*.wav;*.ra;*.wv;*.m4a;*.tta;*.dts;*.spx;*.mp2;*.ofr;*.ofs;*.mpa|");
filter += _T("Video Files |*.avi;*.mp4;*.mpg;*.mpeg;*.m2ts;*.mts;*.ts;*.mkv;*.ogg;*.ogm;*.pva;*.evo;*.flv;*.mov;*.hdmov;*.ifo;*.vob;*.rm;*.rmvb;*.wmv;*.asf|");
filter += _T("All Files|*.*|");
CFileDialog dlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT|OFN_ENABLESIZING|OFN_FILEMUSTEXIST,filter);
dlg.m_ofn.nFilterIndex = cb_type.GetCurSel() + 1;
INT_PTR ret = dlg.DoModal();
filename = dlg.GetPathName();
if (ret == IDOK) {
cb_files.SetWindowText(filename);
}
}
void CDecPerformanceForm::OnCbnSelChange()
{
cb_renderers.ResetContent();
cb_decoders.ResetContent();
DSUtil::FilterTemplates *renderers;
if(!cb_type.GetCurSel())
{
// Audio Renderer
renderers = &view->audio_renderers;
// create the list of Audio decoders
decoders.EnumerateAudioDecoder();
}
else
{
// Video Renderer
renderers = &view->video_renderers;
// create the list of Video decoders
decoders.EnumerateVideoDecoder();
}
// alten Decoder-Filter freigeben
cur_decoder = NULL;
int index = cb_renderers.AddString(_T("Null Renderer"));
cb_renderers.SetItemDataPtr(index, (void*)&null_renderer);
index = cb_renderers.AddString(_T("DXVA Null Renderer"));
cb_renderers.SetItemDataPtr(index, (void*)&null_renderer_dxva);
for (int i=0; i<renderers->filters.GetCount(); i++) {
index = cb_renderers.AddString(renderers->filters[i].name);
cb_renderers.SetItemDataPtr(index, (void*)&renderers->filters[i]);
}
cb_renderers.SetCurSel(0);
for (int i=0; i<decoders.filters.GetCount(); i++) {
index = cb_decoders.AddString(decoders.filters[i].name);
cb_decoders.SetItemDataPtr(index, (void*)&decoders.filters[i]);
}
if (decoders.filters.GetCount() > 0) {
cb_decoders.SetCurSel(0);
}
}
void CDecPerformanceForm::OnComboDecoderSelChange()
{
cur_decoder = NULL;
}
void CDecPerformanceForm::StartTiming()
{
if (perf_operation) return ;
// just to be sure
StopTiming();
// update number of passes from edit control
CString strPhaseCount;
edit_passes.GetWindowText(strPhaseCount);
phase_count = StrToInt(strPhaseCount);
phase_count = max(phase_count, 1);
phase_count = min(phase_count, PASSES_MAX);
// update the file list
CString source_file;
cb_files.GetWindowText(source_file);
file_list.UpdateList(source_file);
file_list.SaveList(_T("DecPerfFileList"));
cb_files.ResetContent();
for (int i=0; i<file_list.GetCount(); i++) { cb_files.AddString(file_list[i]); }
cb_files.SetWindowText(source_file);
list_results.DeleteAllItems();
// update view
view->UpdateGraphState();
view->graph.RefreshFilters();
view->graph.SmartPlacement(false);
view->Invalidate();
// reset the clock
// if this was done before the filters were refreshed, the graph was not reset for some reason :-/
// NB this may not be necessary after recent bug fixes to clock management
view->graph.SetClock(0 != IsDlgButtonChecked(IDC_CHECK_USE_CLOCK), NULL);
// update the display again
view->graph.RefreshFilters();
view->graph.SmartPlacement(false);
view->Invalidate();
// Find first time measure filter in graph and store a reference to it
for (int i=0; i<view->graph.filters.GetCount() && !time_filter; i++) {
if (view->graph.filters[i]->filter)
view->graph.filters[i]->filter->QueryInterface(__uuidof(ITimeMeasureFilter), (void**)&time_filter);
}
// run the graph
phase_cur = 0;
timings_min = Timings();
timings_max = Timings();
timings_avg = Timings();
running = true;
view->OnPlayClick();
}
void CDecPerformanceForm::StopTiming()
{
if (perf_operation) return ;
ShowSummaryStatistics();
phase_cur = 0;
// remember it was us who made the call...
perf_operation = true;
view->OnStopClick();
time_filter = NULL;
perf_operation = false;
running = false;
// enable controls again
}
void CDecPerformanceForm::OnPhaseComplete()
{
if (!running)
return ;
Timings timings; // Get current results of current phase
if (time_filter) {
time_filter->GetStats(&timings.runtime_ns, &timings.frames, &timings.realtime_ns);
} else {
timings.runtime_ns = view->last_stop_time_ns - view->last_start_time_ns; // no time measure filter but we can measure the total streaming time
}
if (timings.runtime_ns <= 0)
timings.runtime_ns = 1; // avoid division by zero.
timings_avg.runtime_ns += timings.runtime_ns; // update average timings
timings_avg.frames += timings.frames;
timings_avg.realtime_ns += timings.realtime_ns;
if (0 == phase_cur) { // update min/max timings
timings_min = timings;
timings_max = timings;
} else {
if (timings.runtime_ns < timings_min.runtime_ns)
timings_min = timings;
if (timings.runtime_ns > timings_max.runtime_ns)
timings_max = timings;
}
CString phase_idx_str; // display timings for the current phase
phase_idx_str.Format(_T("%d"), phase_cur+1);
InsertListItem(timings, phase_cur, phase_idx_str);
phase_cur ++;
if (phase_cur >= phase_count) { // if we're done
StopTiming();
} else {
view->OnStopClick(); // start the next run
view->OnPlayClick();
}
}
void CDecPerformanceForm::ShowSummaryStatistics()
{
// No point in showing summary statistics if only one or no results
if (phase_cur >= 2) {
timings_avg.frames /= phase_cur; // calculate average
timings_avg.realtime_ns /= phase_cur;
timings_avg.runtime_ns /= phase_cur;
int list_index = list_results.GetItemCount(); // display min/max/avg
InsertListItem(timings_min, list_index++, _T("Min."));
InsertListItem(timings_max, list_index++, _T("Max."));
InsertListItem(timings_avg, list_index++, _T("Avg."));
}
}
void CDecPerformanceForm::InsertListItem(const Timings& timings, int index, const CString& label)
{
CString runtime_str;
MakeNiceTimeMS(timings.runtime_ns/(1000*1000), runtime_str);
CString realtime_str;
MakeNiceTimeMS(timings.realtime_ns/(1000*1000), realtime_str);
const double fps = (timings.frames * 1000000000.0) / (double)timings.runtime_ns;
CString fps_str;
fps_str.Format(_T("%7.4f FPS"), (float)(fps));
CString rate_str;
rate_str.Format(_T("x%7.4f"), (double(timings.realtime_ns) / double(timings.runtime_ns)));
CString frames_str;
frames_str.Format(_T("%I64d"), timings.frames);
list_results.InsertItem(index, label);
list_results.EnsureVisible(index, FALSE); // scroll to item to make visible if necessary
list_results.SetItemText(index, 1, runtime_str);
if (timings.frames != 0) { // if we have per-frame info from time measure filter
list_results.SetItemText(index, 2, fps_str);
list_results.SetItemText(index, 3, rate_str);
list_results.SetItemText(index, 4, realtime_str);
list_results.SetItemText(index, 5, frames_str);
}
}
HRESULT CDecPerformanceForm::BuildPerformanceGraph(IGraphBuilder *gb)
{
HRESULT hr;
CComPtr<IBaseFilter> src;
CComPtr<IBaseFilter> time;
CComPtr<IBaseFilter> renderer;
time_filter = NULL;
do {
// 1. Try to create a source filter for the file
CString source_file;
CString short_name;
cb_files.GetWindowText(source_file);
CPath path(source_file);
path.StripPath();
short_name = CString(path);
hr = gb->AddSourceFilter(source_file.GetBuffer(), short_name.GetBuffer(), &src);
if (FAILED(hr)) {
DSUtil::ShowError(hr, _T("Can't add source filter"));
break;
}
// 2. Create the decoder instance
int idx = cb_decoders.GetCurSel();
if (idx < 0) {
hr = E_FAIL;
DSUtil::ShowError(_T("No decoder selcted"));
break;
}
DSUtil::FilterTemplate * const filter_template_decoder = (DSUtil::FilterTemplate*)cb_decoders.GetItemDataPtr(idx);
if (!filter_template_decoder) {
hr = E_FAIL;
DSUtil::ShowError(_T("Can't find decoder"));
break;
}
if (!cur_decoder)
{
hr = filter_template_decoder->CreateInstance(&cur_decoder);
if (FAILED(hr)) {
DSUtil::ShowError(hr, _T("Can't create decoder"));
break;
}
}
// and insert it into the graph
hr = gb->AddFilter(cur_decoder, filter_template_decoder->name.GetBuffer());
if (FAILED(hr)) {
DSUtil::ShowError(hr, _T("Can't add decoder"));
break;
}
// 3. Now connect the source with the decoder
hr = DSUtil::ConnectFilters(gb, src, cur_decoder);
if (FAILED(hr)) {
DSUtil::ShowError(hr, _T("Can't connect decoder"));
break;
}
// 4. Insert the time measure filter
hr = time_filter_template.CreateInstance(&time);
if (FAILED(hr)) {
DSUtil::ShowError(hr, _T("Can't create time filter"));
break;
}
hr = gb->AddFilter(time, time_filter_template.name);
if (FAILED(hr)) {
DSUtil::ShowError(hr, _T("Can't add time filter"));
break;
}
hr = DSUtil::ConnectFilters(gb, cur_decoder, time);
if (FAILED(hr)) {
DSUtil::ShowError(hr, _T("Can't connect time filter"));
break;
}
// 5. Insert the renderer filter
idx = cb_renderers.GetCurSel();
if (idx < 0) {
hr = E_FAIL;
DSUtil::ShowError(_T("No renderer selected"));
break;
}
DSUtil::FilterTemplate * const filter_template_renderer = (DSUtil::FilterTemplate*)cb_renderers.GetItemDataPtr(idx);
if (!filter_template_renderer) {
hr = E_FAIL;
DSUtil::ShowError(_T("Can't find renderer"));
break;
}
// and insert it into the graph
hr = filter_template_renderer->CreateInstance(&renderer);
if (FAILED(hr)) {
DSUtil::ShowError(hr, _T("Can't create renderer"));
break;
}
hr = gb->AddFilter(renderer, filter_template_renderer->name.GetBuffer());
if (FAILED(hr)) {
DSUtil::ShowError(hr, _T("Can't add renderer"));
break;
}
// connect the time filter
hr = DSUtil::ConnectFilters(gb, time, renderer);
if (FAILED(hr)) {
DSUtil::ShowError(hr, _T("Can't connect renderer"));
break;
}
hr = S_OK;
} while (0);
// done with the filters
renderer = NULL;
src = NULL;
time = NULL;
return hr;
}
void CDecPerformanceForm::OnBuildGraphClick()
{
time_filter = NULL;
view->OnNewClick(); // clear any existing graph
// just to be sure
StopTiming();
view->graph.params->MarkRender(true);
HRESULT hr = BuildPerformanceGraph(view->graph.gb); // errors displayed in here with context
view->graph.params->MarkRender(false);
view->OnRenderFinished();
view->graph.RefreshFilters();
view->graph.SmartPlacement();
view->Invalidate();
}
void CDecPerformanceForm::OnStartClick()
{
StartTiming();
}
void CDecPerformanceForm::OnStopClick()
{
StopTiming();
}
BOOL CDecPerformanceForm::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT *pResult)
{
return __super::OnNotify(wParam, lParam, pResult);
}
void CDecPerformanceForm::OnBnClickedButtonPropertypage()
{
int idx = cb_decoders.GetCurSel();
DSUtil::FilterTemplate *filter = (DSUtil::FilterTemplate*)cb_decoders.GetItemDataPtr(idx);
if (filter) {
// now create an instance of this filter
HRESULT hr;
if(!cur_decoder)
{
hr = filter->CreateInstance(&cur_decoder);
if (FAILED(hr)) {
// display error message
DSUtil::ShowError(hr, _T("Can't create decoder"));
return;
}
}
CString title = filter->name + _T(" Properties");
CPropertyForm *page = new CPropertyForm();
int ret = page->DisplayPages(cur_decoder, cur_decoder, title, view);
if (ret < 0) {
delete page;
return ;
}
// add to the list
view->property_pages.Add(page);
}
}