X64 transport [Part 5] (Update plugins.cpp)
[xy_vsfilter.git] / src / apps / mplayerc / PPageFileInfoDetails.cpp
blob4067bb3b08a5d019f8f320073a60f5de29f1f5ca
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // PPageFileInfoDetails.cpp : implementation file
25 #include "stdafx.h"
26 #include "mplayerc.h"
27 #include "PPageFileInfoDetails.h"
28 #include <atlbase.h>
29 #include "..\..\DSUtil\DSUtil.h"
30 #include "d3d9.h"
31 #include "Vmr9.h"
32 #include "..\..\..\include\moreuuids.h"
34 // CPPageFileInfoDetails dialog
36 IMPLEMENT_DYNAMIC(CPPageFileInfoDetails, CPropertyPage)
37 CPPageFileInfoDetails::CPPageFileInfoDetails(CString fn, IFilterGraph* pFG, ISubPicAllocatorPresenter* pCAP)
38 : CPropertyPage(CPPageFileInfoDetails::IDD, CPPageFileInfoDetails::IDD)
39 , m_fn(fn)
40 , m_pFG(pFG)
41 , m_pCAP(pCAP)
42 , m_hIcon(NULL)
43 , m_type(_T("Not known"))
44 , m_size(_T("Not known"))
45 , m_time(_T("Not known"))
46 , m_res(_T("Not known"))
47 , m_created(_T("Not known"))
51 CPPageFileInfoDetails::~CPPageFileInfoDetails()
53 if(m_hIcon) DestroyIcon(m_hIcon);
56 void CPPageFileInfoDetails::DoDataExchange(CDataExchange* pDX)
58 __super::DoDataExchange(pDX);
59 DDX_Control(pDX, IDC_DEFAULTICON, m_icon);
60 DDX_Text(pDX, IDC_EDIT1, m_fn);
61 DDX_Text(pDX, IDC_EDIT4, m_type);
62 DDX_Text(pDX, IDC_EDIT3, m_size);
63 DDX_Text(pDX, IDC_EDIT2, m_time);
64 DDX_Text(pDX, IDC_EDIT5, m_res);
65 DDX_Text(pDX, IDC_EDIT6, m_created);
66 DDX_Control(pDX, IDC_EDIT7, m_encoding);
69 BEGIN_MESSAGE_MAP(CPPageFileInfoDetails, CPropertyPage)
70 END_MESSAGE_MAP()
72 inline int LNKO(int a, int b)
74 if(a == 0 || b == 0)
75 return(1);
77 while(a != b)
79 if(a < b) b -= a;
80 else if(a > b) a -= b;
83 return(a);
86 // CPPageFileInfoDetails message handlers
88 static bool GetProperty(IFilterGraph* pFG, LPCOLESTR propName, VARIANT* vt)
90 BeginEnumFilters(pFG, pEF, pBF)
92 if(CComQIPtr<IPropertyBag> pPB = pBF)
93 if(SUCCEEDED(pPB->Read(propName, vt, NULL)))
94 return true;
96 EndEnumFilters
98 return false;
101 static CString FormatDateTime(FILETIME tm)
103 SYSTEMTIME t;
104 FileTimeToSystemTime(&tm, &t);
105 TCHAR buff[256];
106 GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &t, NULL, buff, 256);
107 CString ret(buff);
108 ret += _T(" ");
109 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &t, NULL, buff, 256);
110 ret += buff;
111 return ret;
114 BOOL CPPageFileInfoDetails::OnInitDialog()
116 __super::OnInitDialog();
118 CString ext = m_fn.Left(m_fn.Find(_T("://"))+1).TrimRight(':');
119 if(ext.IsEmpty() || !ext.CompareNoCase(_T("file")))
120 ext = _T(".") + m_fn.Mid(m_fn.ReverseFind('.')+1);
122 if(m_hIcon = LoadIcon(m_fn, false))
123 m_icon.SetIcon(m_hIcon);
125 if(!LoadType(ext, m_type))
126 m_type = _T("Not known");
128 CComVariant vt;
129 if(::GetProperty(m_pFG, L"CurFile.TimeCreated", &vt))
131 if(V_VT(&vt) == VT_UI8)
133 ULARGE_INTEGER uli;
134 uli.QuadPart = V_UI8(&vt);
136 FILETIME ft;
137 ft.dwLowDateTime = uli.LowPart;
138 ft.dwHighDateTime = uli.HighPart;
140 m_created = FormatDateTime(ft);
144 WIN32_FIND_DATA wfd;
145 HANDLE hFind = FindFirstFile(m_fn, &wfd);
146 if(hFind != INVALID_HANDLE_VALUE)
148 FindClose(hFind);
150 __int64 size = (__int64(wfd.nFileSizeHigh)<<32)|wfd.nFileSizeLow;
151 __int64 shortsize = size;
152 CString measure = _T("B");
153 if(shortsize > 10240) shortsize /= 1024, measure = _T("KB");
154 if(shortsize > 10240) shortsize /= 1024, measure = _T("MB");
155 if(shortsize > 10240) shortsize /= 1024, measure = _T("GB");
156 m_size.Format(_T("%I64d%s (%I64d bytes)"), shortsize, measure, size);
158 if(m_created.IsEmpty())
160 m_created = FormatDateTime(wfd.ftCreationTime);
164 REFERENCE_TIME rtDur = 0;
165 CComQIPtr<IMediaSeeking> pMS = m_pFG;
166 if(pMS && SUCCEEDED(pMS->GetDuration(&rtDur)) && rtDur > 0)
168 m_time.Format(_T("%02d:%02d:%02d"),
169 int(rtDur/10000000/60/60),
170 int((rtDur/10000000/60)%60),
171 int((rtDur/10000000)%60));
174 CSize wh(0, 0), arxy(0, 0);
175 long fps = 0;
177 if(m_pCAP)
179 wh = m_pCAP->GetVideoSize(false);
180 arxy = m_pCAP->GetVideoSize(true);
182 else
184 if(CComQIPtr<IBasicVideo> pBV = m_pFG)
186 if(SUCCEEDED(pBV->GetVideoSize(&wh.cx, &wh.cy)))
188 if(CComQIPtr<IBasicVideo2> pBV2 = m_pFG)
189 pBV2->GetPreferredAspectRatio(&arxy.cx, &arxy.cy);
191 else
193 wh.SetSize(0, 0);
197 if(wh.cx == 0 && wh.cy == 0)
199 BeginEnumFilters(m_pFG, pEF, pBF)
201 if(CComQIPtr<IBasicVideo> pBV = pBF)
203 pBV->GetVideoSize(&wh.cx, &wh.cy);
204 if(CComQIPtr<IBasicVideo2> pBV2 = pBF)
205 pBV2->GetPreferredAspectRatio(&arxy.cx, &arxy.cy);
206 break;
208 else if(CComQIPtr<IVMRWindowlessControl> pWC = pBF)
210 pWC->GetNativeVideoSize(&wh.cx, &wh.cy, &arxy.cx, &arxy.cy);
211 break;
213 else if(CComQIPtr<IVMRWindowlessControl9> pWC = pBF)
215 pWC->GetNativeVideoSize(&wh.cx, &wh.cy, &arxy.cx, &arxy.cy);
216 break;
219 EndEnumFilters
223 if(wh.cx > 0 && wh.cy > 0)
225 m_res.Format(_T("%d x %d"), wh.cx, wh.cy);
227 int lnko = 0;
230 lnko = LNKO(arxy.cx, arxy.cy);
231 if(lnko > 1) arxy.cx /= lnko, arxy.cy /= lnko;
233 while(lnko > 1);
235 if(arxy.cx > 0 && arxy.cy > 0 && arxy.cx*wh.cy != arxy.cy*wh.cx)
237 CString ar;
238 ar.Format(_T(" (AR %d:%d)"), arxy.cx, arxy.cy);
239 m_res += ar;
243 m_fn.TrimRight('/');
244 m_fn.Replace('\\', '/');
245 m_fn = m_fn.Mid(m_fn.ReverseFind('/')+1);
247 UpdateData(FALSE);
249 InitEncoding();
251 m_pFG = NULL;
252 m_pCAP = NULL;
254 return TRUE; // return TRUE unless you set the focus to a control
255 // EXCEPTION: OCX Property Pages should return FALSE
258 void CPPageFileInfoDetails::InitEncoding()
260 CAtlList<CString> sl;
262 BeginEnumFilters(m_pFG, pEF, pBF)
264 CComPtr<IBaseFilter> pUSBF = GetUpStreamFilter(pBF);
266 if(GetCLSID(pBF) == CLSID_NetShowSource)
268 continue;
270 else if(GetCLSID(pUSBF) != CLSID_NetShowSource)
272 if(IPin* pPin = GetFirstPin(pBF, PINDIR_INPUT))
274 CMediaType mt;
275 if(FAILED(pPin->ConnectionMediaType(&mt)) || mt.majortype != MEDIATYPE_Stream)
276 continue;
279 if(IPin* pPin = GetFirstPin(pBF, PINDIR_OUTPUT))
281 CMediaType mt;
282 if(SUCCEEDED(pPin->ConnectionMediaType(&mt)) && mt.majortype == MEDIATYPE_Stream)
283 continue;
287 BeginEnumPins(pBF, pEP, pPin)
289 CMediaTypeEx mt;
290 PIN_DIRECTION dir;
291 if(FAILED(pPin->QueryDirection(&dir)) || dir != PINDIR_OUTPUT
292 || FAILED(pPin->ConnectionMediaType(&mt)))
293 continue;
295 CString str = mt.ToString();
297 if(!str.IsEmpty())
299 sl.AddTail(mt.ToString() + CString(L" [" + GetPinName(pPin) + L"]"));
302 EndEnumPins
304 EndEnumFilters
306 CString text = Implode(sl, '\n');
307 text.Replace(_T("\n"), _T("\r\n"));
308 m_encoding.SetWindowText(text);