00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdafx.h"
00026 #include "mpcinfo.h"
00027
00028 #ifdef _DEBUG
00029 #define new DEBUG_NEW
00030 #endif
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 BEGIN_MESSAGE_MAP(CmpcinfoApp, CWinApp)
00062 END_MESSAGE_MAP()
00063
00064
00065
00066
00067 CmpcinfoApp::CmpcinfoApp()
00068 {
00069
00070
00071 }
00072
00073
00074
00075
00076 CmpcinfoApp theApp;
00077
00078
00079
00080
00081 BOOL CmpcinfoApp::InitInstance()
00082 {
00083 CWinApp::InitInstance();
00084
00085 return TRUE;
00086 }
00087
00088 #include <dshow.h>
00089 #include <streams.h>
00090 #include <atlbase.h>
00091
00092 static bool GetFilterGraph(IFilterGraph** ppFG)
00093 {
00094 if(!ppFG) return(false);
00095
00096 CComPtr<IRunningObjectTable> pROT;
00097 if(FAILED(GetRunningObjectTable(0, &pROT)))
00098 return 1;
00099
00100 CComPtr<IEnumMoniker> pEM;
00101 if(FAILED(pROT->EnumRunning(&pEM)))
00102 return 1;
00103
00104 CComPtr<IBindCtx> pBindCtx;
00105 CreateBindCtx(0, &pBindCtx);
00106
00107 for(CComPtr<IMoniker> pMoniker; S_OK == pEM->Next(1, &pMoniker, NULL); pMoniker = NULL)
00108 {
00109 LPOLESTR pDispName = NULL;
00110 if(FAILED(pMoniker->GetDisplayName(pBindCtx, NULL, &pDispName)))
00111 continue;
00112
00113 CStringW strw(pDispName);
00114
00115 CComPtr<IMalloc> pMalloc;
00116 if(FAILED(CoGetMalloc(1, &pMalloc)))
00117 continue;
00118 pMalloc->Free(pDispName);
00119
00120 if(strw.Find(L"(MPC)") < 0)
00121 continue;
00122
00123 CComPtr<IUnknown> pUnk;
00124 if(S_OK != pROT->GetObject(pMoniker, &pUnk))
00125 continue;
00126
00127 CComQIPtr<IFilterGraph> pFG = pUnk;
00128 if(!pFG)
00129 continue;
00130
00131 *ppFG = pFG.Detach();
00132
00133 break;
00134 }
00135
00136 return(!!*ppFG);
00137 }
00138
00139 extern "C" int WINAPI file(HWND,HWND,char *data,char*,BOOL,BOOL)
00140 {
00141 CComPtr<IFilterGraph> pFG;
00142 if(!GetFilterGraph(&pFG))
00143 return 1;
00144
00145 CString fn;
00146
00147 CComPtr<IEnumFilters> pEF;
00148 if(FAILED(pFG->EnumFilters(&pEF)))
00149 return 1;
00150
00151 ULONG cFetched = 0;
00152 for(CComPtr<IBaseFilter> pBF; S_OK == pEF->Next(1, &pBF, &cFetched); pBF = NULL)
00153 {
00154 if(CComQIPtr<IFileSourceFilter> pFSF = pBF)
00155 {
00156 LPOLESTR pFileName = NULL;
00157 AM_MEDIA_TYPE mt;
00158 if(FAILED(pFSF->GetCurFile(&pFileName, &mt)))
00159 continue;
00160
00161 fn = CStringW(pFileName);
00162
00163 CoTaskMemFree(pFileName);
00164 FreeMediaType(mt);
00165
00166 break;
00167 }
00168 }
00169
00170 if(fn.IsEmpty())
00171 return 1;
00172
00173 sprintf(data, _T("%s"), fn);
00174
00175 return 3;
00176 }
00177
00178 extern "C" int WINAPI size(HWND,HWND,char *data,char*,BOOL,BOOL)
00179 {
00180 if(file(0,0,data,0,0,0) != 3)
00181 return 1;
00182
00183 CString fn = CStringA(data);
00184 data[0] = 0;
00185
00186 HANDLE hFile = CreateFile(fn, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL);
00187 if(hFile == INVALID_HANDLE_VALUE)
00188 return 1;
00189
00190 LARGE_INTEGER size;
00191 size.QuadPart = 0;
00192 size.LowPart = GetFileSize(hFile, (DWORD*)&size.HighPart);
00193
00194 sprintf(data, _T("%I64d"), size.QuadPart);
00195
00196 CloseHandle(hFile);
00197
00198 return 3;
00199 }
00200
00201 extern "C" int WINAPI pos(HWND,HWND,char *data,char*,BOOL,BOOL)
00202 {
00203 CComPtr<IFilterGraph> pFG;
00204 if(!GetFilterGraph(&pFG))
00205 return 1;
00206
00207 CComQIPtr<IMediaSeeking> pMS = pFG;
00208 REFERENCE_TIME pos, dur;
00209 if(FAILED(pMS->GetCurrentPosition(&pos)) || FAILED(pMS->GetDuration(&dur)))
00210 return 1;
00211
00212 if(dur > 10000000i64*60*60)
00213 {
00214 sprintf(data, _T("%02d:%02d:%02d/%02d:%02d:%02d"),
00215 (int)(pos/10000000/60/60), (int)(pos/10000000/60)%60, (int)(pos/10000000)%60,
00216 (int)(dur/10000000/60/60), (int)(dur/10000000/60)%60, (int)(dur/10000000)%60);
00217 }
00218 else
00219 {
00220 sprintf(data, _T("%02d:%02d/%02d:%02d"),
00221 (int)(pos/10000000/60)%60, (int)(pos/10000000)%60,
00222 (int)(dur/10000000/60)%60, (int)(dur/10000000)%60);
00223 }
00224
00225 return 3;
00226 }
00227
00228 extern "C" int WINAPI info(HWND,HWND,char *data,char*,BOOL,BOOL)
00229 {
00230 CStringA ret;
00231 if(file(0,0,data,0,0,0)!=3) return 1;
00232 ret += data;
00233 ret += ", ";
00234 if(size(0,0,data,0,0,0)!=3) return 1;
00235 ret += data;
00236 ret += ", ";
00237 if(pos(0,0,data,0,0,0)!=3) return 1;
00238 ret += data;
00239
00240 strcpy(data, ret);
00241
00242 return 3;
00243 }
00244
00245 extern "C" int WINAPI stopped(HWND,HWND,char *data,char*,BOOL,BOOL)
00246 {
00247 sprintf(data, _T("2"));
00248
00249 CComPtr<IFilterGraph> pFG;
00250 CComQIPtr<IMediaControl> pMC;
00251 OAFilterState fs;
00252 if(!GetFilterGraph(&pFG) || !(pMC = pFG) || FAILED(pMC->GetState(0, &fs)))
00253 return 3;
00254
00255 sprintf(data, _T("%d"), fs == State_Stopped ? 1 : 0);
00256
00257 return 3;
00258 }
00259
00260 extern "C" int WINAPI paused(HWND,HWND,char *data,char*,BOOL,BOOL)
00261 {
00262 sprintf(data, _T("2"));
00263
00264 CComPtr<IFilterGraph> pFG;
00265 CComQIPtr<IMediaControl> pMC;
00266 OAFilterState fs;
00267 if(!GetFilterGraph(&pFG) || !(pMC = pFG) || FAILED(pMC->GetState(0, &fs)))
00268 return 3;
00269
00270 sprintf(data, _T("%d"), fs == State_Paused ? 1 : 0);
00271
00272 return 3;
00273 }
00274
00275 extern "C" int WINAPI running(HWND,HWND,char *data,char*,BOOL,BOOL)
00276 {
00277 sprintf(data, _T("2"));
00278
00279 CComPtr<IFilterGraph> pFG;
00280 CComQIPtr<IMediaControl> pMC;
00281 OAFilterState fs;
00282 if(!GetFilterGraph(&pFG) || !(pMC = pFG) || FAILED(pMC->GetState(0, &fs)))
00283 return 3;
00284
00285 sprintf(data, _T("%d"), fs == State_Running ? 1 : 0);
00286
00287 return 3;
00288 }