MediaFormats.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 #include "stdafx.h"
00023 #include <atlbase.h>
00024 #include "MediaFormats.h"
00025 
00026 //
00027 // CMediaFormatCategory
00028 //
00029 
00030 CMediaFormatCategory::CMediaFormatCategory()
00031         : m_fAudioOnly(false)
00032 {
00033 }
00034 
00035 CMediaFormatCategory::CMediaFormatCategory(
00036         CString label, CList<CString>& exts, bool fAudioOnly,
00037         CString specreqnote, engine_t engine)
00038 {
00039         m_label = label;
00040         m_exts.AddTail(&exts);
00041         m_backupexts.AddTail(&m_exts);
00042         m_specreqnote = specreqnote;
00043         m_fAudioOnly = fAudioOnly;
00044         m_engine = engine;
00045 }
00046 
00047 CMediaFormatCategory::CMediaFormatCategory(
00048         CString label, CString exts, bool fAudioOnly,
00049         CString specreqnote, engine_t engine)
00050 {
00051         m_label = label;
00052         ExplodeMin(exts, m_exts, ' ');
00053         POSITION pos = m_exts.GetHeadPosition();
00054         while(pos) m_exts.GetNext(pos).TrimLeft('.');
00055 
00056         m_backupexts.AddTail(&m_exts);
00057         m_specreqnote = specreqnote;
00058         m_fAudioOnly = fAudioOnly;
00059         m_engine = engine;
00060 }
00061 
00062 CMediaFormatCategory::~CMediaFormatCategory()
00063 {
00064 }
00065 
00066 void CMediaFormatCategory::UpdateData(bool fSave)
00067 {
00068         if(fSave)
00069         {
00070                 AfxGetApp()->WriteProfileString(_T("FileFormats"), m_label, GetExts(true));
00071         }
00072         else
00073         {
00074                 SetExts(AfxGetApp()->GetProfileString(_T("FileFormats"), m_label, GetExts(true)));
00075         }
00076 }
00077 
00078 CMediaFormatCategory::CMediaFormatCategory(CMediaFormatCategory& mfc)
00079 {
00080         *this = mfc;
00081 }
00082 
00083 CMediaFormatCategory& CMediaFormatCategory::operator = (const CMediaFormatCategory& mfc)
00084 {
00085         m_label = mfc.m_label;
00086         m_specreqnote = mfc.m_specreqnote;
00087         m_exts.RemoveAll();
00088         m_exts.AddTail((CList<CString>*)&mfc.m_exts);
00089         m_backupexts.RemoveAll();
00090         m_backupexts.AddTail((CList<CString>*)&mfc.m_backupexts);
00091         m_fAudioOnly = mfc.m_fAudioOnly;
00092         m_engine = mfc.m_engine;
00093 
00094         return(*this);
00095 }
00096 
00097 void CMediaFormatCategory::RestoreDefaultExts()
00098 {
00099         m_exts.RemoveAll();
00100         m_exts.AddTail(&m_backupexts);
00101 }
00102 
00103 void CMediaFormatCategory::SetExts(CList<CString>& exts)
00104 {
00105         m_exts.RemoveAll();
00106         m_exts.AddTail(&exts);
00107 }
00108 
00109 void CMediaFormatCategory::SetExts(CString exts)
00110 {
00111         m_exts.RemoveAll();
00112         ExplodeMin(exts, m_exts, ' ');
00113         POSITION pos = m_exts.GetHeadPosition();
00114         while(pos)
00115         {
00116                 POSITION cur = pos;
00117                 CString& ext = m_exts.GetNext(pos);
00118                 if(ext[0] == '\\') {m_engine = (engine_t)_tcstol(ext.TrimLeft('\\'), NULL, 10); m_exts.RemoveAt(cur);}
00119                 else ext.TrimLeft('.');
00120         }
00121 }
00122 
00123 CString CMediaFormatCategory::GetFilter()
00124 {
00125         CString filter;
00126         POSITION pos = m_exts.GetHeadPosition();
00127         while(pos) filter += _T("*.") + m_exts.GetNext(pos) + _T(";");
00128         filter.TrimRight(_T(";")); // cheap...
00129         return(filter);
00130 }
00131 
00132 CString CMediaFormatCategory::GetExts(bool fAppendEngine)
00133 {
00134         CString exts = Implode(m_exts, ' ');
00135         if(fAppendEngine) exts += CString(_T(" \\")) + (TCHAR)(0x30 + (int)m_engine);
00136         return(exts);
00137 }
00138 
00139 CString CMediaFormatCategory::GetExtsWithPeriod(bool fAppendEngine)
00140 {
00141         CString exts;
00142         POSITION pos = m_exts.GetHeadPosition();
00143         while(pos) exts += _T(".") + m_exts.GetNext(pos) + _T(" ");
00144         exts.TrimRight(_T(" ")); // cheap...
00145         if(fAppendEngine) exts += CString(_T(" \\")) + (TCHAR)(0x30 + (int)m_engine);
00146         return(exts);
00147 }
00148 
00149 CString CMediaFormatCategory::GetBackupExtsWithPeriod(bool fAppendEngine)
00150 {
00151         CString exts;
00152         POSITION pos = m_backupexts.GetHeadPosition();
00153         while(pos) exts += _T(".") + m_backupexts.GetNext(pos) + _T(" ");
00154         exts.TrimRight(_T(" ")); // cheap...
00155         if(fAppendEngine) exts += CString(_T(" \\")) + (TCHAR)(0x30 + (int)m_engine);
00156         return(exts);
00157 }
00158 
00159 //
00160 //      CMediaFormats
00161 //
00162 
00163 CMediaFormats::CMediaFormats()
00164 {
00165 }
00166 
00167 CMediaFormats::~CMediaFormats()
00168 {
00169 }
00170 
00171 void CMediaFormats::UpdateData(bool fSave)
00172 {
00173         if(fSave)
00174         {
00175                 AfxGetApp()->WriteProfileString(_T("FileFormats"), NULL, NULL);
00176 
00177                 AfxGetApp()->WriteProfileInt(_T("FileFormats"), _T("RtspHandler"), m_iRtspHandler);
00178                 AfxGetApp()->WriteProfileInt(_T("FileFormats"), _T("RtspFileExtFirst"), m_fRtspFileExtFirst);
00179         }
00180         else
00181         {
00182                 RemoveAll();
00183 #define ADDFMT(f) Add(CMediaFormatCategory##f)
00184                 ADDFMT((_T("Windows Media file"), _T("wmv wmp wm asf")));
00185                 ADDFMT((_T("Windows Media Audio file"), _T("wma"), true));
00186                 ADDFMT((_T("Video file"), _T("avi")));
00187                 ADDFMT((_T("Audio file"), _T("wav"), true));
00188                 ADDFMT((_T("MPEG Media file "), _T("mpg mpeg mpe m1v m2v mpv2 mp2v dat ts tp tpr pva pss")));
00189                 ADDFMT((_T("MPEG Audio file"), _T("mpa mp2 m1a m2a"), true));
00190                 ADDFMT((_T("DVD file"), _T("vob ifo")));
00191                 ADDFMT((_T("DVD Audio file"), _T("ac3 dts"), true));
00192                 ADDFMT((_T("MP3 Format Sound"), _T("mp3"), true));
00193                 ADDFMT((_T("MIDI file"), _T("mid midi rmi"), true));
00194                 ADDFMT((_T("Indeo Video file"), _T("ivf")));
00195                 ADDFMT((_T("AIFF Format Sound"), _T("aif aifc aiff"), true));
00196                 ADDFMT((_T("AU Format Sound"), _T("au snd"), true));
00197                 ADDFMT((_T("Ogg Media file"), _T("ogm")));
00198                 ADDFMT((_T("Ogg Vorbis Audio file"), _T("ogg"), true));
00199                 ADDFMT((_T("CD Audio Track"), _T("cda"), true, _T("Windows 2000/XP or better")));
00200                 ADDFMT((_T("FLIC file"), _T("fli flc flic")));
00201                 ADDFMT((_T("DVD2AVI Project file"), _T("d2v")));
00202                 ADDFMT((_T("MPEG4 file "), _T("mp4 m4v m4p m4b 3gp 3gpp 3g2 3gp2")));
00203                 ADDFMT((_T("MPEG4 Audio file "), _T("m4a aac"), true));
00204                 ADDFMT((_T("Matroska Media file"), _T("mkv")));
00205                 ADDFMT((_T("Matroska Audio file"), _T("mka"), true));
00206                 ADDFMT((_T("Smacker/Bink Media file"), _T("smk bik"), false, _T("smackw32/binkw32.dll in dll path")));
00207                 ADDFMT((_T("ratdvd file"), _T("ratdvd"), false, _T("ratdvd media file")));
00208                 ADDFMT((_T("RoQ Media file"), _T("roq"), false));
00209                 ADDFMT((_T("Real Media file "), _T("rm ram rmvb rpm"), false, _T("RealOne or codec pack")));
00210                 ADDFMT((_T("Real Audio file "), _T("ra"), true, _T("RealOne or codec pack")));
00211                 ADDFMT((_T("Real Script file"), _T("rt rp smi smil"), false, _T("RealOne or codec pack"), RealMedia));
00212                 ADDFMT((_T("Dirac Video file"), _T("drc"), false));
00213                 ADDFMT((_T("DirectShow Media file"), _T("dsm dsv dsa dss")));
00214                 ADDFMT((_T("Shockwave Flash file"), _T("swf"), false, _T("ShockWave ActiveX control"), ShockWave));
00215                 ADDFMT((_T("Quicktime file "), _T("mov qt amr"), false, _T("QuickTime Player or codec pack"), QuickTime));
00216                 ADDFMT((_T("Image file"), _T("jpeg jpg bmp gif pic png dib tiff tif")));
00217                 ADDFMT((_T("Playlist file"), _T("asx m3u pls wvx wax wmx mpcpl")));
00218                 ADDFMT((_T("Other "), _T("divx vp6")));
00219 #undef ADDFMT
00220 
00221                 m_iRtspHandler = (engine_t)AfxGetApp()->GetProfileInt(_T("FileFormats"), _T("RtspHandler"), (int)RealMedia);
00222                 m_fRtspFileExtFirst = !!AfxGetApp()->GetProfileInt(_T("FileFormats"), _T("RtspFileExtFirst"), 1);
00223         }
00224 
00225         for(int i = 0; i < GetCount(); i++)
00226                 GetAt(i).UpdateData(fSave);
00227 }
00228 
00229 engine_t CMediaFormats::GetRtspHandler(bool& fRtspFileExtFirst)
00230 {
00231         fRtspFileExtFirst = m_fRtspFileExtFirst;
00232         return m_iRtspHandler;
00233 }
00234 
00235 void CMediaFormats::SetRtspHandler(engine_t e, bool fRtspFileExtFirst)
00236 {
00237         m_iRtspHandler = e;
00238         m_fRtspFileExtFirst = fRtspFileExtFirst;
00239 }
00240 
00241 bool CMediaFormats::IsUsingEngine(CString path, engine_t e)
00242 {
00243         return(GetEngine(path) == e);
00244 }
00245 
00246 engine_t CMediaFormats::GetEngine(CString path)
00247 {
00248         path.Trim().MakeLower();
00249 
00250         if(!m_fRtspFileExtFirst && path.Find(_T("rtsp://")) == 0)
00251                 return m_iRtspHandler;
00252 
00253         CString ext = CPath(path).GetExtension();
00254         ext.MakeLower();
00255         if(!ext.IsEmpty())
00256         {
00257                 if(path.Find(_T("rtsp://")) == 0)
00258                 {
00259                         if(ext == _T(".ram") || ext == _T(".rm") || ext == _T(".ra"))
00260                                 return RealMedia;
00261                         if(ext == _T(".qt") || ext == _T(".mov"))
00262                                 return QuickTime;
00263                 }
00264 
00265                 for(int i = 0; i < GetCount(); i++)
00266                 {
00267                         CMediaFormatCategory& mfc = GetAt(i);
00268                         if(mfc.FindExt(ext))
00269                                 return mfc.GetEngineType();
00270                 }
00271         }
00272 
00273         if(m_fRtspFileExtFirst && path.Find(_T("rtsp://")) == 0)
00274                 return m_iRtspHandler;
00275 
00276         return DirectShow;
00277 }
00278 
00279 bool CMediaFormats::FindExt(CString ext, bool fAudioOnly)
00280 {
00281         ext.TrimLeft(_T("."));
00282 
00283         if(!ext.IsEmpty())
00284         {
00285                 for(int i = 0; i < GetCount(); i++)
00286                 {
00287                         CMediaFormatCategory& mfc = GetAt(i);
00288                         if((!fAudioOnly || mfc.IsAudioOnly()) && mfc.FindExt(ext)) 
00289                                 return(true);
00290                 }
00291         }
00292 
00293         return(false);
00294 }

Generated on Tue Dec 13 14:46:55 2005 for guliverkli by  doxygen 1.4.5