PPageFileInfoDetails.cpp

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 // PPageFileInfoDetails.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "PPageFileInfoDetails.h"
00028 #include <atlbase.h>
00029 #include "..\..\DSUtil\DSUtil.h"
00030 #include "d3d9.h"
00031 #include "Vmr9.h"
00032 #include "..\..\..\include\moreuuids.h"
00033 
00034 // CPPageFileInfoDetails dialog
00035 
00036 IMPLEMENT_DYNAMIC(CPPageFileInfoDetails, CPropertyPage)
00037 CPPageFileInfoDetails::CPPageFileInfoDetails(CString fn, IFilterGraph* pFG, ISubPicAllocatorPresenter* pCAP)
00038         : CPropertyPage(CPPageFileInfoDetails::IDD, CPPageFileInfoDetails::IDD)
00039         , m_fn(fn)
00040         , m_pFG(pFG)
00041         , m_pCAP(pCAP)
00042         , m_hIcon(NULL)
00043         , m_type(_T("Not known"))
00044         , m_size(_T("Not known"))
00045         , m_time(_T("Not known"))
00046         , m_res(_T("Not known"))
00047         , m_created(_T("Not known"))
00048 {
00049 }
00050 
00051 CPPageFileInfoDetails::~CPPageFileInfoDetails()
00052 {
00053         if(m_hIcon) DestroyIcon(m_hIcon);
00054 }
00055 
00056 void CPPageFileInfoDetails::DoDataExchange(CDataExchange* pDX)
00057 {
00058         __super::DoDataExchange(pDX);
00059         DDX_Control(pDX, IDC_DEFAULTICON, m_icon);
00060         DDX_Text(pDX, IDC_EDIT1, m_fn);
00061         DDX_Text(pDX, IDC_EDIT4, m_type);
00062         DDX_Text(pDX, IDC_EDIT3, m_size);
00063         DDX_Text(pDX, IDC_EDIT2, m_time);
00064         DDX_Text(pDX, IDC_EDIT5, m_res);
00065         DDX_Text(pDX, IDC_EDIT6, m_created);
00066         DDX_Control(pDX, IDC_EDIT7, m_encoding);
00067 }
00068 
00069 BEGIN_MESSAGE_MAP(CPPageFileInfoDetails, CPropertyPage)
00070 END_MESSAGE_MAP()
00071 
00072 inline int LNKO(int a, int b)
00073 {
00074         if(a == 0 || b == 0)
00075                 return(1);
00076 
00077         while(a != b)
00078         {
00079                 if(a < b) b -= a;
00080                 else if(a > b) a -= b;
00081         }
00082 
00083         return(a);
00084 }
00085 
00086 // CPPageFileInfoDetails message handlers
00087 
00088 BOOL CPPageFileInfoDetails::OnInitDialog()
00089 {
00090         __super::OnInitDialog();
00091 
00092         CString ext = m_fn.Left(m_fn.Find(_T("://"))+1).TrimRight(':');
00093         if(ext.IsEmpty() || !ext.CompareNoCase(_T("file")))
00094                 ext = _T(".") + m_fn.Mid(m_fn.ReverseFind('.')+1);
00095 
00096         if(m_hIcon = LoadIcon(m_fn, false))
00097                 m_icon.SetIcon(m_hIcon);
00098 
00099         if(!LoadType(ext, m_type))
00100                 m_type = _T("Not known");
00101 
00102         WIN32_FIND_DATA wfd;
00103         HANDLE hFind = FindFirstFile(m_fn, &wfd);
00104         if(hFind != INVALID_HANDLE_VALUE)
00105         {
00106                 FindClose(hFind);
00107 
00108                 __int64 size = (__int64(wfd.nFileSizeHigh)<<32)|wfd.nFileSizeLow;
00109                 __int64 shortsize = size;
00110                 CString measure = _T("B");
00111                 if(shortsize > 10240) shortsize /= 1024, measure = _T("KB");
00112                 if(shortsize > 10240) shortsize /= 1024, measure = _T("MB");
00113                 if(shortsize > 10240) shortsize /= 1024, measure = _T("GB");
00114                 m_size.Format(_T("%I64d%s (%I64d bytes)"), shortsize, measure, size);
00115 
00116                 SYSTEMTIME t;
00117                 FileTimeToSystemTime(&wfd.ftCreationTime, &t);
00118                 TCHAR buff[256];
00119                 GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &t, NULL, buff, 256);
00120                 m_created = buff;
00121                 m_created += _T(" ");
00122                 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &t, NULL, buff, 256);
00123                 m_created += buff;
00124         }
00125 
00126         REFERENCE_TIME rtDur = 0;
00127         CComQIPtr<IMediaSeeking> pMS = m_pFG;
00128         if(pMS && SUCCEEDED(pMS->GetDuration(&rtDur)) && rtDur > 0)
00129         {
00130                 m_time.Format(_T("%02d:%02d:%02d"), 
00131                         int(rtDur/10000000/60/60),
00132                         int((rtDur/10000000/60)%60),
00133                         int((rtDur/10000000)%60));
00134         }
00135 
00136         CSize wh(0, 0), arxy(0, 0);
00137         long fps = 0;
00138 
00139         if(m_pCAP)
00140         {
00141                 wh = m_pCAP->GetVideoSize(false);
00142                 arxy = m_pCAP->GetVideoSize(true);
00143         }
00144         else
00145         {
00146                 if(CComQIPtr<IBasicVideo> pBV = m_pFG)
00147                 {
00148                         if(SUCCEEDED(pBV->GetVideoSize(&wh.cx, &wh.cy)))
00149                         {
00150                                 if(CComQIPtr<IBasicVideo2> pBV2 = m_pFG)
00151                                         pBV2->GetPreferredAspectRatio(&arxy.cx, &arxy.cy);
00152                         }
00153                         else
00154                         {
00155                                 wh.SetSize(0, 0);
00156                         }
00157                 }
00158 
00159                 if(wh.cx == 0 && wh.cy == 0)
00160                 {
00161                         BeginEnumFilters(m_pFG, pEF, pBF)
00162                         {
00163                                 if(CComQIPtr<IBasicVideo> pBV = pBF)
00164                                 {
00165                                         pBV->GetVideoSize(&wh.cx, &wh.cy);
00166                                         if(CComQIPtr<IBasicVideo2> pBV2 = pBF)
00167                                                 pBV2->GetPreferredAspectRatio(&arxy.cx, &arxy.cy);
00168                                         break;
00169                                 }
00170                                 else if(CComQIPtr<IVMRWindowlessControl> pWC = pBF)
00171                                 {
00172                                         pWC->GetNativeVideoSize(&wh.cx, &wh.cy, &arxy.cx, &arxy.cy);
00173                                         break;
00174                                 }
00175                                 else if(CComQIPtr<IVMRWindowlessControl9> pWC = pBF)
00176                                 {
00177                                         pWC->GetNativeVideoSize(&wh.cx, &wh.cy, &arxy.cx, &arxy.cy);
00178                                         break;
00179                                 }
00180                         }
00181                         EndEnumFilters
00182                 }
00183         }
00184 
00185         if(wh.cx > 0 && wh.cy > 0)
00186         {
00187                 m_res.Format(_T("%d x %d"), wh.cx, wh.cy);
00188 
00189                 int lnko = 0;
00190                 do
00191                 {
00192                         lnko = LNKO(arxy.cx, arxy.cy);
00193                         if(lnko > 1) arxy.cx /= lnko, arxy.cy /= lnko;
00194                 }
00195                 while(lnko > 1);
00196 
00197                 if(arxy.cx > 0 && arxy.cy > 0 && arxy.cx*wh.cy != arxy.cy*wh.cx)
00198                 {
00199                         CString ar;
00200                         ar.Format(_T(" (AR %d:%d)"), arxy.cx, arxy.cy);
00201                         m_res += ar;
00202                 }
00203         }
00204 
00205         m_fn.TrimRight('/');
00206         m_fn.Replace('\\', '/');
00207         m_fn = m_fn.Mid(m_fn.ReverseFind('/')+1);
00208 
00209         UpdateData(FALSE);
00210 
00211         InitEncoding();
00212 
00213         m_pFG = NULL;
00214         m_pCAP = NULL;
00215 
00216         return TRUE;  // return TRUE unless you set the focus to a control
00217         // EXCEPTION: OCX Property Pages should return FALSE
00218 }
00219 
00220 void CPPageFileInfoDetails::InitEncoding()
00221 {
00222         CList<CString> sl;
00223 
00224         BeginEnumFilters(m_pFG, pEF, pBF)
00225         {
00226                 CComPtr<IBaseFilter> pUSBF = GetUpStreamFilter(pBF);
00227 
00228                 if(GetCLSID(pBF) == CLSID_NetShowSource)
00229                 {
00230                         continue;
00231                 }
00232                 else if(GetCLSID(pUSBF) != CLSID_NetShowSource)
00233                 {
00234                         if(IPin* pPin = GetFirstPin(pBF, PINDIR_INPUT))
00235                         {
00236                                 CMediaType mt;
00237                                 if(FAILED(pPin->ConnectionMediaType(&mt)) || mt.majortype != MEDIATYPE_Stream)
00238                                         continue;
00239                         }
00240 
00241                         if(IPin* pPin = GetFirstPin(pBF, PINDIR_OUTPUT))
00242                         {
00243                                 CMediaType mt;
00244                                 if(SUCCEEDED(pPin->ConnectionMediaType(&mt)) && mt.majortype == MEDIATYPE_Stream)
00245                                         continue;
00246                         }
00247                 }
00248 
00249                 BeginEnumPins(pBF, pEP, pPin)
00250                 {
00251                         CMediaTypeEx mt;
00252                         PIN_DIRECTION dir;
00253                         if(FAILED(pPin->QueryDirection(&dir)) || dir != PINDIR_OUTPUT
00254                         || FAILED(pPin->ConnectionMediaType(&mt)))
00255                                 continue;
00256 
00257                         CString str = mt.ToString();
00258                         
00259                         if(!str.IsEmpty())
00260                         {
00261                                 sl.AddTail(mt.ToString() + CString(L" [" + GetPinName(pPin) + L"]"));
00262                         }
00263                 }
00264                 EndEnumPins
00265         }
00266         EndEnumFilters
00267 
00268         CString text = Implode(sl, '\n');
00269         text.Replace(_T("\n"), _T("\r\n"));
00270         m_encoding.SetWindowText(text);
00271 }

Generated on Tue Dec 13 14:47:00 2005 for guliverkli by  doxygen 1.4.5