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
|
/*
* $Id$
*
* (C) 2003-2005 Gabest
*
* This file is part of mpcinfo.
*
* Mpcinfo 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.
*
* Mpcinfo 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/>.
*
*/
#include "stdafx.h"
#include "mpcinfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
// CmpcinfoApp
BEGIN_MESSAGE_MAP(CmpcinfoApp, CWinApp)
END_MESSAGE_MAP()
// CmpcinfoApp construction
CmpcinfoApp::CmpcinfoApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CmpcinfoApp object
CmpcinfoApp theApp;
// CmpcinfoApp initialization
BOOL CmpcinfoApp::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}
#include <dshow.h>
#include <streams.h>
#include <atlbase.h>
static bool GetFilterGraph(IFilterGraph** ppFG)
{
if(!ppFG) {
return(false);
}
CComPtr<IRunningObjectTable> pROT;
if(FAILED(GetRunningObjectTable(0, &pROT))) {
return 1;
}
CComPtr<IEnumMoniker> pEM;
if(FAILED(pROT->EnumRunning(&pEM))) {
return 1;
}
CComPtr<IBindCtx> pBindCtx;
CreateBindCtx(0, &pBindCtx);
for(CComPtr<IMoniker> pMoniker; S_OK == pEM->Next(1, &pMoniker, NULL); pMoniker = NULL) {
LPOLESTR pDispName = NULL;
if(FAILED(pMoniker->GetDisplayName(pBindCtx, NULL, &pDispName))) {
continue;
}
CStringW strw(pDispName);
CComPtr<IMalloc> pMalloc;
if(FAILED(CoGetMalloc(1, &pMalloc))) {
continue;
}
pMalloc->Free(pDispName);
if(strw.Find(L"(MPC)") < 0) {
continue;
}
CComPtr<IUnknown> pUnk;
if(S_OK != pROT->GetObject(pMoniker, &pUnk)) {
continue;
}
CComQIPtr<IFilterGraph> pFG = pUnk;
if(!pFG) {
continue;
}
*ppFG = pFG.Detach();
break;
}
return(!!*ppFG);
}
extern "C" int WINAPI file(HWND,HWND,char *data,char*,BOOL,BOOL)
{
CComPtr<IFilterGraph> pFG;
if(!GetFilterGraph(&pFG)) {
return 1;
}
CString fn;
CComPtr<IEnumFilters> pEF;
if(FAILED(pFG->EnumFilters(&pEF))) {
return 1;
}
ULONG cFetched = 0;
for(CComPtr<IBaseFilter> pBF; S_OK == pEF->Next(1, &pBF, &cFetched); pBF = NULL) {
if(CComQIPtr<IFileSourceFilter> pFSF = pBF) {
LPOLESTR pFileName = NULL;
AM_MEDIA_TYPE mt;
if(FAILED(pFSF->GetCurFile(&pFileName, &mt))) {
continue;
}
fn = CStringW(pFileName);
CoTaskMemFree(pFileName);
FreeMediaType(mt);
break;
}
}
if(fn.IsEmpty()) {
return 1;
}
size_t len = strlen(data);
sprintf_s(data,len+1, _T("%s"), fn);
return 3;
}
extern "C" int WINAPI size(HWND,HWND,char *data,char*,BOOL,BOOL)
{
if(file(0,0,data,0,0,0) != 3) {
return 1;
}
CString fn = CStringA(data);
data[0] = 0;
HANDLE hFile = CreateFile(fn, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL);
if(hFile == INVALID_HANDLE_VALUE) {
return 1;
}
LARGE_INTEGER size;
size.QuadPart = 0;
size.LowPart = GetFileSize(hFile, (DWORD*)&size.HighPart);
size_t len = strlen(data);
sprintf_s(data,len+1, _T("%I64d"), size.QuadPart);
CloseHandle(hFile);
return 3;
}
extern "C" int WINAPI pos(HWND,HWND,char *data,char*,BOOL,BOOL)
{
CComPtr<IFilterGraph> pFG;
if(!GetFilterGraph(&pFG)) {
return 1;
}
CComQIPtr<IMediaSeeking> pMS = pFG;
REFERENCE_TIME pos, dur;
if(FAILED(pMS->GetCurrentPosition(&pos)) || FAILED(pMS->GetDuration(&dur))) {
return 1;
}
size_t len = strlen(data);
if(dur > 10000000i64*60*60) {
sprintf_s(data,len+1, _T("%02d:%02d:%02d/%02d:%02d:%02d"),
(int)(pos/10000000/60/60), (int)(pos/10000000/60)%60, (int)(pos/10000000)%60,
(int)(dur/10000000/60/60), (int)(dur/10000000/60)%60, (int)(dur/10000000)%60);
} else {
sprintf_s(data,len+1, _T("%02d:%02d/%02d:%02d"),
(int)(pos/10000000/60)%60, (int)(pos/10000000)%60,
(int)(dur/10000000/60)%60, (int)(dur/10000000)%60);
}
return 3;
}
extern "C" int WINAPI info(HWND,HWND,char *data,char*,BOOL,BOOL)
{
CStringA ret;
if(file(0,0,data,0,0,0)!=3) {
return 1;
}
ret += data;
ret += ", ";
if(size(0,0,data,0,0,0)!=3) {
return 1;
}
ret += data;
ret += ", ";
if(pos(0,0,data,0,0,0)!=3) {
return 1;
}
ret += data;
size_t len = strlen(data) + 1;
strcpy_s(data,len, ret);
return 3;
}
extern "C" int WINAPI stopped(HWND,HWND,char *data,char*,BOOL,BOOL)
{
size_t len = strlen(data) +1;
sprintf_s(data,len+1, _T("2"));
CComPtr<IFilterGraph> pFG;
CComQIPtr<IMediaControl> pMC;
OAFilterState fs;
if(!GetFilterGraph(&pFG) || !(pMC = pFG) || FAILED(pMC->GetState(0, &fs))) {
return 3;
}
sprintf_s(data,len, _T("%d"), fs == State_Stopped ? 1 : 0);
return 3;
}
extern "C" int WINAPI paused(HWND,HWND,char *data,char*,BOOL,BOOL)
{
size_t len = strlen(data) +1;
sprintf_s(data,len, _T("2"));
CComPtr<IFilterGraph> pFG;
CComQIPtr<IMediaControl> pMC;
OAFilterState fs;
if(!GetFilterGraph(&pFG) || !(pMC = pFG) || FAILED(pMC->GetState(0, &fs))) {
return 3;
}
sprintf_s(data,len, _T("%d"), fs == State_Paused ? 1 : 0);
return 3;
}
extern "C" int WINAPI running(HWND,HWND,char *data,char*,BOOL,BOOL)
{
size_t len = strlen(data) +1;
sprintf_s(data,len, _T("2"));
CComPtr<IFilterGraph> pFG;
CComQIPtr<IMediaControl> pMC;
OAFilterState fs;
if(!GetFilterGraph(&pFG) || !(pMC = pFG) || FAILED(pMC->GetState(0, &fs))) {
return 3;
}
sprintf_s(data,len, _T("%d"), fs == State_Running ? 1 : 0);
return 3;
}
|