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
|
/*
* $Id$
*
* (C) 2003-2006 Gabest
* (C) 2006-2010 see AUTHORS
*
* This file is part of mplayerc.
*
* Mplayerc is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Mplayerc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "afxwin.h"
#include "afxcmn.h"
#include "..\..\filters\transform\bufferfilter\bufferfilter.h"
#include "FloatEdit.h"
//
template<class T>
class CFormatElem
{
public:
CMediaType mt;
T caps;
};
template<class T>
class CFormat : public CAutoPtrArray<CFormatElem<T> >
{
public:
CString name;
CFormat(CString name = _T("")) {this->name = name;}
virtual ~CFormat() {}
};
template<class T>
class CFormatArray : public CAutoPtrArray<CFormat<T> >
{
public:
virtual ~CFormatArray() {}
CFormat<T>* Find(CString name, bool fCreate = false)
{
for(int i = 0; i < (int)GetCount(); i++)
{
if(GetAt(i)->name == name)
return(GetAt(i));
}
if(fCreate)
{
CAutoPtr<CFormat<T> > pf(DNew CFormat<T>(name));
CFormat<T>* tmp = pf;
Add(pf);
return(tmp);
}
return(NULL);
}
bool FindFormat(AM_MEDIA_TYPE* pmt, CFormat<T>** ppf)
{
if(!pmt) return(false);
for(int i = 0; i < (int)GetCount(); i++)
{
CFormat<T>* pf = GetAt(i);
for(int j = 0; j < (int)pf->GetCount(); j++)
{
CFormatElem<T>* pfe = pf->GetAt(j);
if(!pmt || (pfe->mt.majortype == pmt->majortype && pfe->mt.subtype == pmt->subtype))
{
if(ppf) *ppf = pf;
return(true);
}
}
}
return(false);
}
bool FindFormat(AM_MEDIA_TYPE* pmt, T* pcaps, CFormat<T>** ppf, CFormatElem<T>** ppfe)
{
if(!pmt && !pcaps) return(false);
for(int i = 0; i < (int)GetCount(); i++)
{
CFormat<T>* pf = GetAt(i);
for(int j = 0; j < (int)pf->GetCount(); j++)
{
CFormatElem<T>* pfe = pf->GetAt(j);
if((!pmt || pfe->mt == *pmt) && (!pcaps || !memcmp(pcaps, &pfe->caps, sizeof(T))))
{
if(ppf) *ppf = pf;
if(ppfe) *ppfe = pfe;
return(true);
}
}
}
return(false);
}
bool AddFormat(AM_MEDIA_TYPE* pmt, T caps)
{
if(!pmt) return(false);
if(FindFormat(pmt, NULL, NULL, NULL)) {DeleteMediaType(pmt); return(false);}
// if(pmt->formattype == FORMAT_VideoInfo2) {DeleteMediaType(pmt); return(false);} // TODO
CFormat<T>* pf = Find(MakeFormatName(pmt), true);
if(!pf) {DeleteMediaType(pmt); return(false);}
CAutoPtr<CFormatElem<T> > pfe(DNew CFormatElem<T>());
pfe->mt = *pmt;
pfe->caps = caps;
pf->Add(pfe);
return(true);
}
bool AddFormat(AM_MEDIA_TYPE* pmt, void* pcaps, int size)
{
if(!pcaps) return false;
ASSERT(size == sizeof(T));
return AddFormat(pmt, *(T*)pcaps);
}
virtual CString MakeFormatName(AM_MEDIA_TYPE* pmt) = 0;
virtual CString MakeDimensionName(CFormatElem<T>* pfe) = 0;
};
typedef CFormatElem<VIDEO_STREAM_CONFIG_CAPS> CVidFormatElem;
typedef CFormat<VIDEO_STREAM_CONFIG_CAPS> CVidFormat;
class CVidFormatArray : public CFormatArray<VIDEO_STREAM_CONFIG_CAPS>
{
public:
CString MakeFormatName(AM_MEDIA_TYPE* pmt)
{
CString str(_T("Default"));
if(!pmt) return(str);
BITMAPINFOHEADER* bih = (pmt->formattype == FORMAT_VideoInfo)
? &((VIDEOINFOHEADER*)pmt->pbFormat)->bmiHeader
: (pmt->formattype == FORMAT_VideoInfo2)
? &((VIDEOINFOHEADER2*)pmt->pbFormat)->bmiHeader
: NULL;
if(!bih)
{
// it may have a fourcc in the mediasubtype, let's check that
WCHAR guid[100];
memset(guid, 0, 100*sizeof(WCHAR));
StringFromGUID2(pmt->subtype, guid, 100);
if(CStringW(guid).MakeUpper().Find(L"0000-0010-8000-00AA00389B71") >= 0)
{
str.Format(_T("%c%c%c%c"),
(TCHAR)((pmt->subtype.Data1>>0)&0xff), (TCHAR)((pmt->subtype.Data1>>8)&0xff),
(TCHAR)((pmt->subtype.Data1>>16)&0xff), (TCHAR)((pmt->subtype.Data1>>24)&0xff));
}
return(str);
}
switch(bih->biCompression)
{
case BI_RGB: str.Format(_T("RGB%d"), bih->biBitCount); break;
case BI_RLE8: str = _T("RLE8"); break;
case BI_RLE4: str = _T("RLE4"); break;
case BI_BITFIELDS: str.Format(_T("BITF%d"), bih->biBitCount); break;
case BI_JPEG: str = _T("JPEG"); break;
case BI_PNG: str = _T("PNG"); break;
default:
str.Format(_T("%c%c%c%c"),
(TCHAR)((bih->biCompression>>0)&0xff), (TCHAR)((bih->biCompression>>8)&0xff),
(TCHAR)((bih->biCompression>>16)&0xff), (TCHAR)((bih->biCompression>>24)&0xff));
break;
}
return(str);
}
CString MakeDimensionName(CVidFormatElem* pfe)
{
CString str(_T("Default"));
if(!pfe) return(str);
BITMAPINFOHEADER* bih = (pfe->mt.formattype == FORMAT_VideoInfo)
? &((VIDEOINFOHEADER*)pfe->mt.pbFormat)->bmiHeader
: (pfe->mt.formattype == FORMAT_VideoInfo2)
? &((VIDEOINFOHEADER2*)pfe->mt.pbFormat)->bmiHeader
: NULL;
if(bih == NULL) return(str);
str.Format(_T("%dx%d %.2f"), bih->biWidth, bih->biHeight, (float)10000000/((VIDEOINFOHEADER*)pfe->mt.pbFormat)->AvgTimePerFrame);
if(pfe->mt.formattype == FORMAT_VideoInfo2)
{
VIDEOINFOHEADER2* vih2 = (VIDEOINFOHEADER2*)pfe->mt.pbFormat;
CString str2;
str2.Format(_T(" i%02x %d:%d"), vih2->dwInterlaceFlags, vih2->dwPictAspectRatioX, vih2->dwPictAspectRatioY);
str += str2;
}
return(str);
}
};
typedef CFormatElem<AUDIO_STREAM_CONFIG_CAPS> CAudFormatElem;
typedef CFormat<AUDIO_STREAM_CONFIG_CAPS> CAudFormat;
class CAudFormatArray : public CFormatArray<AUDIO_STREAM_CONFIG_CAPS>
{
public:
CString MakeFormatName(AM_MEDIA_TYPE* pmt)
{
CString str(_T("Unknown"));
if(!pmt) return(str);
WAVEFORMATEX* wfe = (pmt->formattype == FORMAT_WaveFormatEx)
? (WAVEFORMATEX*)pmt->pbFormat
: NULL;
if(!wfe)
{
WCHAR guid[100];
memset(guid, 0, 100*sizeof(WCHAR));
StringFromGUID2(pmt->subtype, guid, 100);
if(CStringW(guid).MakeUpper().Find(L"0000-0010-8000-00AA00389B71") >= 0)
{
str.Format(_T("0x%04x"), pmt->subtype.Data1);
}
return(str);
}
switch(wfe->wFormatTag)
{
case 1: str = _T("PCM "); break;
default: str.Format(_T("0x%03x "), wfe->wFormatTag); break;
}
return(str);
}
CString MakeDimensionName(CAudFormatElem* pfe)
{
CString str(_T("Unknown"));
if(!pfe) return(str);
WAVEFORMATEX* wfe = (pfe->mt.formattype == FORMAT_WaveFormatEx)
? (WAVEFORMATEX*)pfe->mt.pbFormat
: NULL;
if(!wfe) return(str);
str.Empty();
CString str2;
str2.Format(_T("%6dKHz "), wfe->nSamplesPerSec); str += str2;
str2.Format(_T("%dbps "), wfe->wBitsPerSample); str += str2;
switch(wfe->nChannels)
{
case 1: str += _T("mono "); break;
case 2: str += _T("stereo "); break;
default: str2.Format(_T("%d channels "), wfe->nChannels); str += str2; break;
}
str2.Format(_T("%3dkbps "), wfe->nAvgBytesPerSec*8/1000); str += str2;
return(str);
}
};
//
typedef struct
{
CComPtr<IMoniker> pMoniker;
CComPtr<IBaseFilter> pBF;
CString FriendlyName;
CComBSTR DisplayName;
} Codec;
typedef CAtlArray<Codec> CCodecArray;
// CPlayerCaptureDialog dialog
class CPlayerCaptureDialog : public CResizableDialog //CDialog
{
//DECLARE_DYNAMIC(CPlayerCaptureDialog)
// video input
CStringW m_VidDisplayName;
CComPtr<IAMStreamConfig> m_pAMVSC;
CComPtr<IAMCrossbar> m_pAMXB;
CComPtr<IAMTVTuner> m_pAMTuner;
CComPtr<IAMVfwCaptureDialogs> m_pAMVfwCD;
CVidFormatArray m_vfa;
// audio input
CStringW m_AudDisplayName;
CComPtr<IAMStreamConfig> m_pAMASC;
CInterfaceArray<IAMAudioInputMixer> m_pAMAIM;
CAudFormatArray m_afa;
// video codec
CCodecArray m_pVidEncArray;
CVidFormatArray m_vcfa;
// audio codec
CCodecArray m_pAudEncArray;
CAudFormatArray m_acfa;
void EmptyVideo();
void EmptyAudio();
void UpdateMediaTypes();
void UpdateUserDefinableControls();
void UpdateVideoCodec();
void UpdateAudioCodec();
void UpdateMuxer();
void UpdateOutputControls();
void UpdateGraph();
CMap<HWND, HWND&, BOOL, BOOL&> m_wndenabledmap;
void EnableControls(CWnd* pWnd, bool fEnable);
bool m_fEnableOgm;
public:
CPlayerCaptureDialog(); // standard constructor
virtual ~CPlayerCaptureDialog();
BOOL Create(CWnd* pParent = NULL);
// Dialog Data
enum { IDD = IDD_CAPTURE_DLG };
CComboBox m_vidinput;
CComboBox m_vidtype;
CComboBox m_viddimension;
CSpinButtonCtrl m_vidhor;
CSpinButtonCtrl m_vidver;
CEdit m_vidhoredit;
CEdit m_vidveredit;
CFloatEdit m_vidfpsedit;
float m_vidfps;
CButton m_vidsetres;
CComboBox m_audinput;
CComboBox m_audtype;
CComboBox m_auddimension;
CComboBox m_vidcodec;
CComboBox m_vidcodectype;
CComboBox m_vidcodecdimension;
BOOL m_fVidOutput;
CButton m_vidoutput;
int m_fVidPreview;
CButton m_vidpreview;
CComboBox m_audcodec;
CComboBox m_audcodectype;
CComboBox m_audcodecdimension;
BOOL m_fAudOutput;
CButton m_audoutput;
int m_fAudPreview;
CButton m_audpreview;
int m_nVidBuffers;
int m_nAudBuffers;
CString m_file;
CButton m_recordbtn;
BOOL m_fSepAudio;
int m_muxtype;
CComboBox m_muxctrl;
CMediaType m_mtv, m_mta, m_mtcv, m_mtca;
CComPtr<IBaseFilter> m_pVidEnc, m_pAudEnc, m_pMux, m_pDst, m_pAudMux, m_pAudDst;
CComPtr<IMoniker> m_pVidEncMoniker, m_pAudEncMoniker;
CComPtr<IBaseFilter> m_pVidBuffer, m_pAudBuffer;
public:
void SetupVideoControls(CStringW DisplayName, CComPtr<IAMStreamConfig> pAMSC, CComPtr<IAMCrossbar> pAMXB, CComPtr<IAMTVTuner> pAMTuner);
void SetupVideoControls(CStringW DisplayName, CComPtr<IAMStreamConfig> pAMSC, CComPtr<IAMVfwCaptureDialogs> pAMVfwCD);
void SetupAudioControls(CStringW DisplayName, CComPtr<IAMStreamConfig> pAMSC, CInterfaceArray<IAMAudioInputMixer>& pAMAIM);
bool IsTunerActive();
bool SetVideoInput(int input);
bool SetVideoChannel(int channel);
bool SetAudioInput(int input);
int GetVideoInput();
int GetVideoChannel();
int GetAudioInput();
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL PreTranslateMessage(MSG* pMsg);
virtual BOOL OnInitDialog();
virtual void OnOK() {}
virtual void OnCancel() {}
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnDestroy();
afx_msg void OnVideoInput();
afx_msg void OnVideoType();
afx_msg void OnVideoDimension();
afx_msg void OnOverrideVideoDimension();
afx_msg void OnAudioInput();
afx_msg void OnAudioType();
afx_msg void OnAudioDimension();
afx_msg void OnRecordVideo();
afx_msg void OnVideoCodec();
afx_msg void OnVideoCodecType();
afx_msg void OnVideoCodecDimension();
afx_msg void OnRecordAudio();
afx_msg void OnAudioCodec();
afx_msg void OnAudioCodecType();
afx_msg void OnAudioCodecDimension();
afx_msg void OnOpenFile();
afx_msg void OnRecord();
afx_msg void OnEnChangeEdit9();
afx_msg void OnEnChangeEdit12();
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg void OnBnClickedVidAudPreview();
afx_msg void OnBnClickedCheck7();
afx_msg void OnCbnSelchangeCombo14();
};
|