- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# ISubPic.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 <atlbase.h>
    00025 #include <atlcoll.h>
    00026 #include "CoordGeom.h"
    00027
    00028 #pragma pack(push, 1)
    00029 struct SubPicDesc
    00030 {
    00031         int type;
    00032         int w, h, bpp, pitch, pitchUV;
    00033         void* bits;
    00034         BYTE* bitsU;
    00035         BYTE* bitsV;
    00036         RECT vidrect; // video rectangle
    00037
    00038         struct SubPicDesc() {type = 0; w = h = bpp = pitch = pitchUV = 0; bits = NULL; bitsU = bitsV = NULL;}
    00039 };
    00040 #pragma pack(pop)
    00041
    00042 //
    00043 // ISubPic
    00044 //
    00045
    00046 [uuid("449E11F3-52D1-4a27-AA61-E2733AC92CC0")]
    00047 interface ISubPic : public IUnknown
    00048 {
    00049         STDMETHOD_(void*, GetObject) () PURE;
    00050
    00051         STDMETHOD_(REFERENCE_TIME, GetStart) () PURE;
    00052         STDMETHOD_(REFERENCE_TIME, GetStop) () PURE;
    00053         STDMETHOD_(void, SetStart) (REFERENCE_TIME rtStart) PURE;
    00054         STDMETHOD_(void, SetStop) (REFERENCE_TIME rtStop) PURE;
    00055
    00056         STDMETHOD (GetDesc) (SubPicDesc& spd /*[out]*/) PURE;
    00057         STDMETHOD (CopyTo) (ISubPic* pSubPic /*[in]*/) PURE;
    00058
    00059         STDMETHOD (ClearDirtyRect) (DWORD color /*[in]*/) PURE;
    00060         STDMETHOD (GetDirtyRect) (RECT* pDirtyRect /*[out]*/) PURE;
    00061         STDMETHOD (SetDirtyRect) (RECT* pDirtyRect /*[in]*/) PURE;
    00062
    00063         STDMETHOD (GetMaxSize) (SIZE* pMaxSize /*[out]*/) PURE;
    00064         STDMETHOD (SetSize) (SIZE pSize /*[in]*/, RECT vidrect /*[in]*/) PURE;
    00065
    00066         STDMETHOD (Lock) (SubPicDesc& spd /*[out]*/) PURE;
    00067         STDMETHOD (Unlock) (RECT* pDirtyRect /*[in]*/) PURE;
    00068
    00069         STDMETHOD (AlphaBlt) (RECT* pSrc, RECT* pDst, SubPicDesc* pTarget = NULL /*[in]*/) PURE;
    00070 };
    00071
    00072 class ISubPicImpl : public CUnknown, public ISubPic
    00073 {
    00074 protected:
    00075         REFERENCE_TIME m_rtStart, m_rtStop;
    00076         CRect m_rcDirty;
    00077         CSize m_maxsize, m_size;
    00078         CRect m_vidrect;
    00079
    00080 public:
    00081         ISubPicImpl();
    00082
    00083         DECLARE_IUNKNOWN;
    00084         STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
    00085
    00086         // ISubPic
    00087
    00088         STDMETHODIMP_(REFERENCE_TIME) GetStart();
    00089         STDMETHODIMP_(REFERENCE_TIME) GetStop();
    00090         STDMETHODIMP_(void) SetStart(REFERENCE_TIME rtStart);
    00091         STDMETHODIMP_(void) SetStop(REFERENCE_TIME rtStop);
    00092
    00093         STDMETHODIMP GetDesc(SubPicDesc& spd) = 0;
    00094         STDMETHODIMP CopyTo(ISubPic* pSubPic);
    00095
    00096         STDMETHODIMP ClearDirtyRect(DWORD color) = 0;
    00097         STDMETHODIMP GetDirtyRect(RECT* pDirtyRect);
    00098         STDMETHODIMP SetDirtyRect(RECT* pDirtyRect);
    00099
    00100         STDMETHODIMP GetMaxSize(SIZE* pMaxSize);
    00101         STDMETHODIMP SetSize(SIZE size, RECT vidrect);
    00102
    00103         STDMETHODIMP Lock(SubPicDesc& spd) = 0;
    00104         STDMETHODIMP Unlock(RECT* pDirtyRect) = 0;
    00105
    00106         STDMETHODIMP AlphaBlt(RECT* pSrc, RECT* pDst, SubPicDesc* pTarget) = 0;
    00107 };
    00108
    00109 //
    00110 // ISubPicAllocator
    00111 //
    00112
    00113 [uuid("CF7C3C23-6392-4a42-9E72-0736CFF793CB")]
    00114 interface ISubPicAllocator : public IUnknown
    00115 {
    00116         STDMETHOD (SetCurSize) (SIZE size /*[in]*/) PURE;
    00117         STDMETHOD (SetCurVidRect) (RECT curvidrect) PURE;
    00118
    00119         STDMETHOD (GetStatic) (ISubPic** ppSubPic /*[out]*/) PURE;
    00120         STDMETHOD (AllocDynamic) (ISubPic** ppSubPic /*[out]*/) PURE;
    00121
    00122         STDMETHOD_(bool, IsDynamicWriteOnly) () PURE;
    00123
    00124         STDMETHOD (ChangeDevice) (IUnknown* pDev) PURE;
    00125 };
    00126
    00127
    00128 class ISubPicAllocatorImpl : public CUnknown, public ISubPicAllocator
    00129 {
    00130         CComPtr<ISubPic> m_pStatic;
    00131
    00132 private:
    00133         CSize m_cursize;
    00134         CRect m_curvidrect;
    00135         bool m_fDynamicWriteOnly;
    00136
    00137         virtual bool Alloc(bool fStatic, ISubPic** ppSubPic) = 0;
    00138
    00139 protected:
    00140         bool m_fPow2Textures;
    00141
    00142 public:
    00143         ISubPicAllocatorImpl(SIZE cursize, bool fDynamicWriteOnly, bool fPow2Textures);
    00144
    00145         DECLARE_IUNKNOWN;
    00146         STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
    00147
    00148         // ISubPicAllocator
    00149
    00150         STDMETHODIMP SetCurSize(SIZE cursize);
    00151         STDMETHODIMP SetCurVidRect(RECT curvidrect);
    00152         STDMETHODIMP GetStatic(ISubPic** ppSubPic);
    00153         STDMETHODIMP AllocDynamic(ISubPic** ppSubPic);
    00154         STDMETHODIMP_(bool) IsDynamicWriteOnly();
    00155         STDMETHODIMP ChangeDevice(IUnknown* pDev);
    00156 };
    00157
    00158 //
    00159 // ISubPicProvider
    00160 //
    00161
    00162 [uuid("D62B9A1A-879A-42db-AB04-88AA8F243CFD")]
    00163 interface ISubPicProvider : public IUnknown
    00164 {
    00165         STDMETHOD (Lock) () PURE;
    00166         STDMETHOD (Unlock) () PURE;
    00167
    00168         STDMETHOD_(POSITION, GetStartPosition) (REFERENCE_TIME rt, double fps) PURE;
    00169         STDMETHOD_(POSITION, GetNext) (POSITION pos) PURE;
    00170
    00171         STDMETHOD_(REFERENCE_TIME, GetStart) (POSITION pos, double fps) PURE;
    00172         STDMETHOD_(REFERENCE_TIME, GetStop) (POSITION pos, double fps) PURE;
    00173
    00174         STDMETHOD_(bool, IsAnimated) (POSITION pos) PURE;
    00175
    00176         STDMETHOD (Render) (SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox) PURE;
    00177 };
    00178
    00179 class ISubPicProviderImpl : public CUnknown, public ISubPicProvider
    00180 {
    00181 protected:
    00182         CCritSec* m_pLock;
    00183
    00184 public:
    00185         ISubPicProviderImpl(CCritSec* pLock);
    00186         virtual ~ISubPicProviderImpl();
    00187
    00188         DECLARE_IUNKNOWN;
    00189         STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
    00190
    00191         // ISubPicProvider
    00192
    00193         STDMETHODIMP Lock();
    00194         STDMETHODIMP Unlock();
    00195
    00196         STDMETHODIMP_(POSITION) GetStartPosition(REFERENCE_TIME rt, double fps) = 0;
    00197         STDMETHODIMP_(POSITION) GetNext(POSITION pos) = 0;
    00198
    00199         STDMETHODIMP_(REFERENCE_TIME) GetStart(POSITION pos, double fps) = 0;
    00200         STDMETHODIMP_(REFERENCE_TIME) GetStop(POSITION pos, double fps) = 0;
    00201
    00202         STDMETHODIMP Render(SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox) = 0;
    00203 };
    00204
    00205 //
    00206 // ISubPicQueue
    00207 //
    00208
    00209 [uuid("C8334466-CD1E-4ad1-9D2D-8EE8519BD180")]
    00210 interface ISubPicQueue : public IUnknown
    00211 {
    00212         STDMETHOD (SetSubPicProvider) (ISubPicProvider* pSubPicProvider /*[in]*/) PURE;
    00213         STDMETHOD (GetSubPicProvider) (ISubPicProvider** pSubPicProvider /*[out]*/) PURE;
    00214
    00215         STDMETHOD (SetFPS) (double fps /*[in]*/) PURE;
    00216         STDMETHOD (SetTime) (REFERENCE_TIME rtNow /*[in]*/) PURE;
    00217
    00218         STDMETHOD (Invalidate) (REFERENCE_TIME rtInvalidate = -1) PURE;
    00219         STDMETHOD_(bool, LookupSubPic) (REFERENCE_TIME rtNow /*[in]*/, ISubPic** ppSubPic /*[out]*/) PURE;
    00220
    00221         STDMETHOD (GetStats) (int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop /*[out]*/) PURE;
    00222         STDMETHOD (GetStats) (int nSubPic /*[in]*/, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop /*[out]*/) PURE;
    00223 };
    00224
    00225 class ISubPicQueueImpl : public CUnknown, public ISubPicQueue
    00226 {
    00227         CCritSec m_csSubPicProvider;
    00228         CComPtr<ISubPicProvider> m_pSubPicProvider;
    00229
    00230 protected:
    00231         double m_fps;
    00232         REFERENCE_TIME m_rtNow;
    00233
    00234         CComPtr<ISubPicAllocator> m_pAllocator;
    00235
    00236         HRESULT RenderTo(ISubPic* pSubPic, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, double fps);
    00237
    00238 public:
    00239         ISubPicQueueImpl(ISubPicAllocator* pAllocator, HRESULT* phr);
    00240         virtual ~ISubPicQueueImpl();
    00241
    00242         DECLARE_IUNKNOWN;
    00243         STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
    00244
    00245         // ISubPicQueue
    00246
    00247         STDMETHODIMP SetSubPicProvider(ISubPicProvider* pSubPicProvider);
    00248         STDMETHODIMP GetSubPicProvider(ISubPicProvider** pSubPicProvider);
    00249
    00250         STDMETHODIMP SetFPS(double fps);
    00251         STDMETHODIMP SetTime(REFERENCE_TIME rtNow);
    00252 /*
    00253         STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1) = 0;
    00254         STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME rtNow, ISubPic** ppSubPic) = 0;
    00255
    00256         STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop) = 0;
    00257         STDMETHODIMP GetStats(int nSubPics, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop) = 0;
    00258 */
    00259 };
    00260
    00261 class CSubPicQueue : public ISubPicQueueImpl, private CInterfaceList<ISubPic>, private CAMThread
    00262 {
    00263         int m_nMaxSubPic;
    00264
    00265         CCritSec m_csQueueLock; // for protecting CInterfaceList<ISubPic>
    00266         REFERENCE_TIME UpdateQueue();
    00267         void AppendQueue(ISubPic* pSubPic);
    00268
    00269         REFERENCE_TIME m_rtQueueStart, m_rtInvalidate;
    00270
    00271         // CAMThread
    00272
    00273         bool m_fBreakBuffering;
    00274         enum {EVENT_EXIT, EVENT_TIME, EVENT_COUNT}; // IMPORTANT: _EXIT must come before _TIME if we want to exit fast from the destructor
    00275         HANDLE m_ThreadEvents[EVENT_COUNT];
    00276     DWORD ThreadProc();
    00277
    00278 public:
    00279         CSubPicQueue(int nMaxSubPic, ISubPicAllocator* pAllocator, HRESULT* phr);
    00280         virtual ~CSubPicQueue();
    00281
    00282         // ISubPicQueue
    00283
    00284         STDMETHODIMP SetFPS(double fps);
    00285         STDMETHODIMP SetTime(REFERENCE_TIME rtNow);
    00286
    00287         STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1);
    00288         STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME rtNow, ISubPic** ppSubPic);
    00289
    00290         STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop);
    00291         STDMETHODIMP GetStats(int nSubPic, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop);
    00292 };
    00293
    00294 class CSubPicQueueNoThread : public ISubPicQueueImpl
    00295 {
    00296         CCritSec m_csLock;
    00297         CComPtr<ISubPic> m_pSubPic;
    00298
    00299 public:
    00300         CSubPicQueueNoThread(ISubPicAllocator* pAllocator, HRESULT* phr);
    00301         virtual ~CSubPicQueueNoThread();
    00302
    00303         // ISubPicQueue
    00304
    00305         STDMETHODIMP Invalidate(REFERENCE_TIME rtInvalidate = -1);
    00306         STDMETHODIMP_(bool) LookupSubPic(REFERENCE_TIME rtNow, ISubPic** ppSubPic);
    00307
    00308         STDMETHODIMP GetStats(int& nSubPics, REFERENCE_TIME& rtNow, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop);
    00309         STDMETHODIMP GetStats(int nSubPic, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop);
    00310 };
    00311
    00312 //
    00313 // ISubPicAllocatorPresenter
    00314 //
    00315
    00316 [uuid("CF75B1F0-535C-4074-8869-B15F177F944E")]
    00317 interface ISubPicAllocatorPresenter : public IUnknown
    00318 {
    00319         STDMETHOD (CreateRenderer) (IUnknown** ppRenderer) PURE;
    00320
    00321         STDMETHOD_(SIZE, GetVideoSize) (bool fCorrectAR = true) PURE;
    00322         STDMETHOD_(void, SetPosition) (RECT w, RECT v) PURE;
    00323         STDMETHOD_(bool, Paint) (bool fAll) PURE;
    00324
    00325         STDMETHOD_(void, SetTime) (REFERENCE_TIME rtNow) PURE;
    00326         STDMETHOD_(double, GetFPS) () PURE;
    00327
    00328         STDMETHOD_(void, SetSubPicProvider) (ISubPicProvider* pSubPicProvider) PURE;
    00329         STDMETHOD_(void, Invalidate) (REFERENCE_TIME rtInvalidate = -1) PURE;
    00330
    00331         STDMETHOD (GetDIB) (BYTE* lpDib, DWORD* size) PURE;
    00332
    00333         STDMETHOD (SetVideoAngle) (Vector v, bool fRepaint = true) PURE;
    00334         STDMETHOD (SetPixelShader) (LPCSTR pSrcData, LPCSTR pTarget) PURE;
    00335 };
    00336
    00337 class ISubPicAllocatorPresenterImpl
    00338         : public CUnknown
    00339         , public CCritSec
    00340         , public ISubPicAllocatorPresenter
    00341 {
    00342 protected:
    00343         HWND m_hWnd;
    00344         CSize m_spMaxSize; // TODO:
    00345         int m_spMaxQueued; // TODO:
    00346
    00347         CSize m_NativeVideoSize, m_AspectRatio;
    00348         CRect m_VideoRect, m_WindowRect;
    00349
    00350         REFERENCE_TIME m_rtNow;
    00351         double m_fps;
    00352
    00353         CComPtr<ISubPicAllocator> m_pAllocator;
    00354         CComPtr<ISubPicQueue> m_pSubPicQueue;
    00355
    00356         void AlphaBltSubPic(CSize size, SubPicDesc* pTarget = NULL);
    00357
    00358     XForm m_xform;
    00359         void Transform(CRect r, Vector v[4]);
    00360
    00361 public:
    00362         ISubPicAllocatorPresenterImpl(HWND hWnd);
    00363         virtual ~ISubPicAllocatorPresenterImpl();
    00364
    00365         DECLARE_IUNKNOWN;
    00366         STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
    00367
    00368         // ISubPicAllocatorPresenter
    00369
    00370         STDMETHODIMP CreateRenderer(IUnknown** ppRenderer) = 0;
    00371
    00372         STDMETHODIMP_(SIZE) GetVideoSize(bool fCorrectAR = true);
    00373         STDMETHODIMP_(void) SetPosition(RECT w, RECT v);
    00374         STDMETHODIMP_(bool) Paint(bool fAll) = 0;
    00375
    00376         STDMETHODIMP_(void) SetTime(REFERENCE_TIME rtNow);
    00377         STDMETHODIMP_(double) GetFPS();
    00378
    00379         STDMETHODIMP_(void) SetSubPicProvider(ISubPicProvider* pSubPicProvider);
    00380         STDMETHODIMP_(void) Invalidate(REFERENCE_TIME rtInvalidate = -1);
    00381
    00382         STDMETHODIMP GetDIB(BYTE* lpDib, DWORD* size) {return E_NOTIMPL;}
    00383
    00384         STDMETHODIMP SetVideoAngle(Vector v, bool fRepaint = true);
    00385         STDMETHODIMP SetPixelShader(LPCSTR pSrcData, LPCSTR pTarget) {return E_NOTIMPL;}
    00386 };
    00387
    00388 //
    00389 // ISubStream
    00390 //
    00391
    00392 [uuid("DE11E2FB-02D3-45e4-A174-6B7CE2783BDB")]
    00393 interface ISubStream : public IPersist
    00394 {
    00395         STDMETHOD_(int, GetStreamCount) () PURE;
    00396         STDMETHOD (GetStreamInfo) (int i, WCHAR** ppName, LCID* pLCID) PURE;
    00397         STDMETHOD_(int, GetStream) () PURE;
    00398         STDMETHOD (SetStream) (int iStream) PURE;
    00399         STDMETHOD (Reload) () PURE;
    00400
    00401         // TODO: get rid of IPersist to identify type and use only
    00402         // interface functions to modify the settings of the substream
    00403 };
    00404