VobSubFile.h

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 #pragma once
00023 
00024 #include <afxtempl.h>
00025 #include "VobSubImage.h"
00026 #include "..\SubPic\ISubPic.h"
00027 
00028 #define VOBSUBIDXVER 7
00029 
00030 extern CString FindLangFromId(WORD id);
00031 
00032 class CVobSubSettings
00033 {
00034 protected:
00035         HRESULT Render(SubPicDesc& spd, RECT& bbox);
00036 
00037 public:
00038         CSize m_size;
00039         int m_x, m_y;
00040         CPoint m_org;
00041         int m_scale_x, m_scale_y;       // % (don't set it to unsigned because as a side effect it will mess up negative coordinates in GetDestrect())
00042         int m_alpha;                            // %
00043         int m_fSmooth;                          // 0: OFF, 1: ON, 2: OLD (means no filtering at all)
00044         int m_fadein, m_fadeout;        // ms
00045         bool m_fAlign;
00046         int m_alignhor, m_alignver; // 0: left/top, 1: center, 2: right/bottom
00047         unsigned int m_toff;                            // ms
00048         bool m_fOnlyShowForcedSubs;
00049         bool m_fCustomPal;
00050         int m_tridx;
00051         RGBQUAD m_orgpal[16], m_cuspal[4];
00052 
00053         CVobSubImage m_img;
00054 
00055         CVobSubSettings() {InitSettings();}
00056         void InitSettings();
00057 
00058         bool GetCustomPal(RGBQUAD* cuspal, int& tridx);
00059     void SetCustomPal(RGBQUAD* cuspal, int tridx);
00060 
00061         void GetDestrect(CRect& r); // destrect of m_img, considering the current alignment mode
00062         void GetDestrect(CRect& r, int w, int h); // this will scale it to the frame size of (w, h)
00063 
00064         void SetAlignment(bool fAlign, int x, int y, int hor, int ver);
00065 };
00066 
00067 [uuid("998D4C9A-460F-4de6-BDCD-35AB24F94ADF")]
00068 class CVobSubFile : public CVobSubSettings, public ISubStream, public ISubPicProviderImpl
00069 {
00070 protected:
00071         CString m_title;
00072 
00073         void TrimExtension(CString& fn);
00074         bool ReadIdx(CString fn, int& ver), ReadSub(CString fn), ReadRar(CString fn), ReadIfo(CString fn);
00075         bool WriteIdx(CString fn), WriteSub(CString fn);
00076 
00077         CMemFile m_sub;
00078 
00079         BYTE* GetPacket(int idx, int& packetsize, int& datasize, int iLang = -1);
00080         bool GetFrame(int idx, int iLang = -1);
00081         bool GetFrameByTimeStamp(__int64 time);
00082         int GetFrameIdxByTimeStamp(__int64 time);
00083 
00084         bool SaveVobSub(CString fn);
00085         bool SaveWinSubMux(CString fn);
00086         bool SaveScenarist(CString fn);
00087         bool SaveMaestro(CString fn);
00088 
00089 public:
00090         typedef struct
00091         {
00092                 __int64 filepos;
00093                 __int64 start, stop;
00094                 bool fForced;
00095                 char vobid, cellid;
00096                 __int64 celltimestamp;
00097                 bool fValid;
00098         } SubPos;
00099 
00100         typedef struct
00101         {
00102                 int id;
00103                 CString name, alt;
00104                 CArray<SubPos> subpos;
00105         } SubLang;
00106 
00107         int m_iLang;
00108         SubLang m_langs[32];
00109 
00110 public:
00111         CVobSubFile(CCritSec* pLock);
00112         virtual ~CVobSubFile();
00113 
00114         bool Copy(CVobSubFile& vsf);
00115 
00116         typedef enum {None,VobSub,WinSubMux,Scenarist,Maestro} SubFormat;
00117 
00118         bool Open(CString fn);
00119         bool Save(CString fn, SubFormat sf = VobSub);
00120         void Close();
00121 
00122         CString GetTitle() {return(m_title);}
00123 
00124         DECLARE_IUNKNOWN
00125     STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
00126 
00127         // ISubPicProvider
00128         STDMETHODIMP_(POSITION) GetStartPosition(REFERENCE_TIME rt, double fps);
00129         STDMETHODIMP_(POSITION) GetNext(POSITION pos);
00130         STDMETHODIMP_(REFERENCE_TIME) GetStart(POSITION pos, double fps);
00131         STDMETHODIMP_(REFERENCE_TIME) GetStop(POSITION pos, double fps);
00132         STDMETHODIMP_(bool) IsAnimated(POSITION pos);
00133         STDMETHODIMP Render(SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox);
00134 
00135         // IPersist
00136         STDMETHODIMP GetClassID(CLSID* pClassID);
00137 
00138         // ISubStream
00139         STDMETHODIMP_(int) GetStreamCount();
00140         STDMETHODIMP GetStreamInfo(int i, WCHAR** ppName, LCID* pLCID);
00141         STDMETHODIMP_(int) GetStream();
00142         STDMETHODIMP SetStream(int iStream);
00143         STDMETHODIMP Reload();
00144 };
00145 
00146 [uuid("D7FBFB45-2D13-494F-9B3D-FFC9557D5C45")]
00147 class CVobSubStream : public CVobSubSettings, public ISubStream, public ISubPicProviderImpl
00148 {
00149         CString m_name;
00150 
00151         CCritSec m_csSubPics;
00152         struct SubPic {REFERENCE_TIME tStart, tStop; CArray<BYTE> pData;};
00153         CAutoPtrList<SubPic> m_subpics;
00154 
00155 public:
00156         CVobSubStream(CCritSec* pLock);
00157         virtual ~CVobSubStream();
00158 
00159         void Open(CString name, BYTE* pData, int len);
00160 
00161     void Add(REFERENCE_TIME tStart, REFERENCE_TIME tStop, BYTE* pData, int len);
00162         void RemoveAll();
00163 
00164         DECLARE_IUNKNOWN
00165     STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
00166 
00167         // ISubPicProvider
00168         STDMETHODIMP_(POSITION) GetStartPosition(REFERENCE_TIME rt, double fps);
00169         STDMETHODIMP_(POSITION) GetNext(POSITION pos);
00170         STDMETHODIMP_(REFERENCE_TIME) GetStart(POSITION pos, double fps);
00171         STDMETHODIMP_(REFERENCE_TIME) GetStop(POSITION pos, double fps);
00172         STDMETHODIMP_(bool) IsAnimated(POSITION pos);
00173         STDMETHODIMP Render(SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox);
00174 
00175         // IPersist
00176         STDMETHODIMP GetClassID(CLSID* pClassID);
00177 
00178         // ISubStream
00179         STDMETHODIMP_(int) GetStreamCount();
00180         STDMETHODIMP GetStreamInfo(int i, WCHAR** ppName, LCID* pLCID);
00181         STDMETHODIMP_(int) GetStream();
00182         STDMETHODIMP SetStream(int iStream);
00183         STDMETHODIMP Reload() {return E_NOTIMPL;}
00184 };

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